[MPlayer-users] Little patch to get the -geometry option working on 0.90rc2 (and others) II

Henk henk at god.dyndns.org
Mon Dec 30 03:53:03 CET 2002


These patches make the -geometry option now X-window compliant:

geometry can now be in [WxH][+X+Y] or in [X[%%]:Y[%%]] format (to be
backwards compatible) we can lose the -x -y options.

As before it fixes a feature in the vo_xv driver as posted in earlier
mails.



Kind Regards,


Henk
-------------- next part --------------
--- MPlayer-0.90rc2/libvo/geometry.c.orig	Mon Dec 30 01:12:12 2002
+++ MPlayer-0.90rc2/libvo/geometry.c	Mon Dec 30 03:41:23 2002
@@ -6,78 +6,57 @@
 #include <string.h>
 #include <stdlib.h> /* strtol */
 
-/* A string of the form xpos[%]:ypos[%] */
+/* A string of the form [WxH][+X+Y] or xpos[%]:ypos[%] */
 char *vo_geometry = NULL;
 
 int geometry_error()
 {
-	mp_msg(MSGT_VO, MSGL_ERR, "-geometry option format incorrect (%s)\n", vo_geometry);
+	mp_msg(MSGT_VO, MSGL_ERR, "-geometry must be in [WxH][+X+Y] | [X[%%]:Y[%%]] format, incorrect (%s)\n", vo_geometry);
 	exit_player(NULL);		/* ????? what else could we do ? */
 	return 0;
 }
 
-int get_num(char *s, int *num, char *end)
+// A little kludge as to not to have to update all drivers
+// Only the vo_xv driver supports now the full [WxH][+X+Y] option
+int geometryFull(int *pwidth, int *pheight, int *xpos, int *ypos, int scrw, int scrh, int vidw, int vidh, int fs)
 {
-	char *e;
-	long int t;
+        int width, height, xoff, yoff;
+	int xper, yper;
 
-	t = strtol(s, &e, 10);
+	width = height = xoff = yoff = -1;
 
-	if(e != end)
-		return 0;
-
-	*num = t;
+	/* no need to save a few extra cpu cycles here ;) */
+        if(vo_geometry != NULL) {
+          if((sscanf(vo_geometry, "%ix%i+%i+%i", &width, &height, &xoff, &yoff)) != 4)
+            if((sscanf(vo_geometry, "%ix%i", &width, &height)) != 2)
+              if((sscanf(vo_geometry, "+%i+%i", &xoff, &yoff)) != 2)
+	       /* old compatibility format x:y below */
+               if((sscanf(vo_geometry, "%i:%i", &xoff, &yoff)) != 2)
+                 if((sscanf(vo_geometry, "%i:%i%%", &xper, &yper)) != 2)
+                 if((sscanf(vo_geometry, "%i%%:%i", &xper, &yper)) != 2)
+                 if((sscanf(vo_geometry, "%i%%:%i%%", &xper, &yper)) == 2) {
+		   xoff = (scrw - vidw) * ((float)xper / 100.0);
+		   yoff = (scrh - vidh) * ((float)yper / 100.0);
+		 } else
+		   return geometry_error();
+
+        }
+	if(width < 0 || width > 4095) width = vidw;
+	if(height < 0 || height > 4095) height = vidh;
+	if(xoff < 0 || xoff > 4095) xoff = (width - vidw) / 2;
+	if(yoff < 0 || yoff > 4095) yoff = (height - vidh) / 2;
+
+	if(xpos) *xpos = xoff;
+	if(ypos) *ypos = yoff;
+	if(pwidth) *pwidth = width;
+	if(pheight) *pheight = height;
 	return 1;
 }
 
+// compatibility function
+// only libvo working with full geometry options.
 int geometry(int *xpos, int *ypos, int scrw, int scrh, int vidw, int vidh, int fs)
 {
-	int xper = 0, yper = 0;
-	int glen;
-	char *colpos;
-
-	*xpos = 0; *ypos = 0;
-
-	if(vo_geometry == NULL)
-		return 1;
-
-	glen = strlen(vo_geometry);
-	colpos = strchr(vo_geometry, ':');
-	if(colpos == NULL)
-		colpos = (char *)(vo_geometry + glen);
-
-	/* Parse the x bit */
-	if(colpos[-1] == '%') {
-		if(!get_num(vo_geometry, &xper, colpos - 1))
-			return geometry_error();
-	} else {
-		if(!get_num(vo_geometry, xpos, colpos))
-			return geometry_error();
-	}
-
-	if(*colpos != '\0') {
-		if(vo_geometry[glen - 1] == '%') {
-			if(!get_num(colpos + 1, &yper, vo_geometry + glen - 1))
-				return geometry_error();
-		} else {
-			if(!get_num(colpos + 1, ypos, vo_geometry + glen))
-				return geometry_error();
-		}
-	}
-
-	if(xper)
-		*xpos = (scrw - vidw) * ((float)xper / 100.0);
-	if(yper)
-		*ypos = (scrh - vidh) * ((float)yper / 100.0);
-
-	if(*xpos + vidw > scrw) {
-		mp_msg(MSGT_VO, MSGL_ERR, "X position is too large\n");
-		return geometry_error();
-	}
-	if(*ypos + vidh > scrh) {
-		mp_msg(MSGT_VO, MSGL_ERR, "Y position is too large\n");
-		return geometry_error();
-	}
-
-	return 1;
+  int width, height;
+  return geometryFull(&width, &height, xpos, ypos, scrw, scrh, vidw, vidh, fs);
 }
-------------- next part --------------
--- MPlayer-0.90rc2/mplayer.c.orig	Mon Dec 23 02:54:58 2002
+++ MPlayer-0.90rc2/mplayer.c	Mon Dec 30 03:28:40 2002
@@ -109,6 +109,8 @@
 //             Config
 //**************************************************************************//
 
+#include "libvo/geometry.h"
+
 m_config_t* mconfig;
 
 #ifdef NEW_CONFIG
@@ -657,6 +659,9 @@
     if(m_config_parse_command_line(mconfig, argc, argv) < 0) exit(1); // error parsing cmdline
 #endif
 
+    geometryFull(&opt_screen_size_x, &opt_screen_size_y, NULL, NULL,
+	vo_screenwidth, vo_screenheight, vo_screenwidth, vo_screenheight, 0);
+
     playtree = play_tree_cleanup(playtree);
     if(playtree) {
       playtree_iter = play_tree_iter_new(playtree,mconfig);
-------------- next part --------------
--- MPlayer-0.90rc2/libvo/vo_xv.c.orig	Sun Dec 29 23:07:21 2002
+++ MPlayer-0.90rc2/libvo/vo_xv.c	Mon Dec 30 02:09:56 2002
@@ -281,7 +281,8 @@
  
  vo_mouse_autohide=1;
 
- vo_dx=( vo_screenwidth - d_width ) / 2; vo_dy=( vo_screenheight - d_height ) / 2;
+ // Quick fix for handling the geometry option.
+ geometry(&vo_dx, &vo_dy, vo_screenwidth, vo_screenheight, d_width, d_height,0);
  vo_dwidth=d_width; vo_dheight=d_height;
      
 #ifdef HAVE_XF86VM


More information about the MPlayer-users mailing list