From 90188f0e5fce3948dde3d89a409804c492f8375b Mon Sep 17 00:00:00 2001 From: reimar Date: Wed, 3 Mar 2010 20:57:56 +0000 Subject: [PATCH] Add support for specifying window position relative to right and bottom screen borders with -geometry. Based on patch by Melchior FRANZ [melchior franz gmail com]. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@30822 b3059339-0415-0410-9bf9-f77b7e298cf2 --- DOCS/man/en/mplayer.1 | 7 +++++-- libvo/geometry.c | 15 ++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/DOCS/man/en/mplayer.1 b/DOCS/man/en/mplayer.1 index 0f3bfb1e95..cf89c3ba70 100644 --- a/DOCS/man/en/mplayer.1 +++ b/DOCS/man/en/mplayer.1 @@ -3143,13 +3143,16 @@ Fixes fullscreen switching on OpenBox 1.x. .PD 1 . .TP -.B \-geometry x[%][:y[%]] or [WxH][+x+y] +.B \-geometry x[%][:y[%]] or [WxH][+-x+-y] Adjust where the output is on the screen initially. The x and y specifications are in pixels measured from the top-left of the screen to the top-left of the image being displayed, however if a percentage sign is given after the argument it turns the value into a percentage of the screen size in that direction. -It also supports the standard X11 \-geometry option format. +It also supports the standard X11 \-geometry option format, in which e.g. ++10-50 means "place 10 pixels from the left border and 50 pixels from the lower +border" and "--20+-10" means "place 20 pixels beyond the right and 10 pixels +beyond the top border". If an external window is specified using the \-wid option, then the x and y coordinates are relative to the top-left corner of the window rather than the screen. diff --git a/libvo/geometry.c b/libvo/geometry.c index 7576f9feb4..6653373976 100644 --- a/libvo/geometry.c +++ b/libvo/geometry.c @@ -36,20 +36,23 @@ int geometry_xy_changed; int geometry(int *xpos, int *ypos, int *widw, int *widh, int scrw, int scrh) { if(vo_geometry != NULL) { + char xsign[2], ysign[2]; int width, height, xoff, yoff, xper, yper; int i; int ok = 0; for (i = 0; !ok && i < 8; i++) { width = height = xoff = yoff = xper = yper = INT_MIN; + strcpy(xsign, "+"); + strcpy(ysign, "+"); switch (i) { case 0: - ok = sscanf(vo_geometry, "%ix%i+%i+%i", &width, &height, &xoff, &yoff) == 4; + ok = sscanf(vo_geometry, "%ix%i%1[+-]%i%1[+-]%i", &width, &height, xsign, &xoff, ysign, &yoff) == 6; break; case 1: ok = sscanf(vo_geometry, "%ix%i", &width, &height) == 2; break; case 2: - ok = sscanf(vo_geometry, "+%i+%i", &xoff, &yoff) == 2; + ok = sscanf(vo_geometry, "%1[+-]%i%1[+-]%i", xsign, &xoff, ysign, &yoff) == 4; break; case 3: ok = sscanf(vo_geometry, "%i%%:%i%%", &xper, &yper) == 2; @@ -70,14 +73,16 @@ int geometry(int *xpos, int *ypos, int *widw, int *widh, int scrw, int scrh) } if (!ok) { mp_msg(MSGT_VO, MSGL_ERR, - "-geometry must be in [WxH][+X+Y] | [X[%%]:[Y[%%]]] format, incorrect (%s)\n", vo_geometry); + "-geometry must be in [WxH][[+-]X[+-]Y] | [X[%%]:[Y[%%]]] format, incorrect (%s)\n", vo_geometry); return 0; } mp_msg(MSGT_VO, MSGL_V,"geometry set to width: %i," - "height: %i, xoff: %i, yoff: %i, xper: %i, yper: %i\n", - width, height, xoff, yoff, xper, yper); + "height: %i, xoff: %s%i, yoff: %s%i, xper: %i, yper: %i\n", + width, height, xsign, xoff, ysign, yoff, xper, yper); + if(xoff != INT_MIN && xsign[0] == '-') xoff = scrw - *widw - xoff; + if(yoff != INT_MIN && ysign[0] == '-') yoff = scrh - *widh - yoff; if(xper >= 0 && xper <= 100) xoff = (scrw - *widw) * ((float)xper / 100.0); if(yper >= 0 && yper <= 100) yoff = (scrh - *widh) * ((float)yper / 100.0);