[MPlayer-users] Patch for -geometry

Ole Tange tange at tange.dk
Thu Jan 9 00:09:00 CET 2003


On Wed, 8 Jan 2003, Filip Kalinski wrote:

> XPareseGeometry is defined in <X11/Xlib.h>.

Great. That made the patch only 4 kb.

I hope we agree that reusing thoroughly tested code (as the X code
undoubtly is) is better than reinventing the wheel and make some kludgy
code (Let's avoid those sscanfs that do not have boundry checks).


/Ole

diff -Naur MPlayer-0.90rc2-org/libvo/geometry.c MPlayer-0.90rc2/libvo/geometry.c
--- MPlayer-0.90rc2-org/libvo/geometry.c	2002-11-23 11:58:07.000000000 +0100
+++ MPlayer-0.90rc2/libvo/geometry.c	2003-01-08 23:43:27.000000000 +0100
@@ -1,83 +1,16 @@
-/* This file (C) Mark Zealey <mark at zealos.org> 2002, released under GPL */
+/* This file (C) Ole Tange http://ole.tange.dk 2003, released under GPL */

-#include "geometry.h"
-#include "../mp_msg.h"
-#include "../mplayer.h" /* exit_player() */
-#include <string.h>
 #include <stdlib.h> /* strtol */
+#include <X11/Xlib.h>

 /* A string of the form xpos[%]:ypos[%] */
 char *vo_geometry = NULL;

-int geometry_error()
+int geometry(int *xpos, int *ypos, int scrw, int scrh, int *vidw, int *vidh, int fs)
 {
-	mp_msg(MSGT_VO, MSGL_ERR, "-geometry option 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)
-{
-	char *e;
-	long int t;
-
-	t = strtol(s, &e, 10);
-
-	if(e != end)
-		return 0;
-
-	*num = t;
-	return 1;
-}
-
-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;
+  if(vo_geometry == NULL)
+    return 1;
+  XParseGeometry (vo_geometry, xpos, ypos, vidw, vidh);
+  if(*xpos<0) { *xpos+=scrw-*vidw; }
+  if(*ypos<0) { *ypos+=scrh-*vidh; }
 }
diff -Naur MPlayer-0.90rc2-org/libvo/geometry.h MPlayer-0.90rc2/libvo/geometry.h
--- MPlayer-0.90rc2-org/libvo/geometry.h	2002-10-23 20:51:19.000000000 +0200
+++ MPlayer-0.90rc2/libvo/geometry.h	2003-01-08 18:00:48.000000000 +0100
@@ -1,8 +1,10 @@
 /* This file (C) Mark Zealey <mark at zealos.org 2002, released under GPL */
+/* This file (C) Ole Tange http://ole.tange.dk 2003, released under GPL */
+
 #ifndef __GEOMETRY_H
 #define __GEOMETRY_H

 extern char *vo_geometry;
-int geometry(int *xpos, int *ypos, int scrw, int scrh, int vidw, int vidh, int fs);
+int geometry(int *xpos, int *ypos, int scrw, int scrh, int *vidw, int *vidh, int fs);

 #endif /* !__GEOMETRY_H */
diff -Naur MPlayer-0.90rc2-org/libvo/vo_x11.c MPlayer-0.90rc2/libvo/vo_x11.c
--- MPlayer-0.90rc2-org/libvo/vo_x11.c	2002-11-11 16:20:26.000000000 +0100
+++ MPlayer-0.90rc2/libvo/vo_x11.c	2003-01-08 18:48:15.000000000 +0100
@@ -323,6 +323,7 @@
      {
       if ( vo_window == None )
        {
+	geometry(&vo_dx,&vo_dy,vo_screenwidth,vo_screenheight,&vo_dwidth,&vo_dheight,0);
         vo_window=XCreateWindow( mDisplay,mRootWin,
     			 vo_dx,vo_dy,
 			 vo_dwidth,vo_dheight,
diff -Naur MPlayer-0.90rc2-org/libvo/vo_xv.c MPlayer-0.90rc2/libvo/vo_xv.c
--- MPlayer-0.90rc2-org/libvo/vo_xv.c	2002-11-11 16:20:26.000000000 +0100
+++ MPlayer-0.90rc2/libvo/vo_xv.c	2003-01-08 18:49:06.000000000 +0100
@@ -366,6 +366,7 @@
        } else { drwX=vo_dx; drwY=vo_dy; }
     } else
     if ( vo_window == None ){
+        geometry(&hint.x,&hint.y,vo_screenwidth,vo_screenheight,&hint.width,&hint.height,0);
         vo_window = XCreateWindow(mDisplay, mRootWin,
           hint.x, hint.y, hint.width, hint.height,
           0, depth,CopyFromParent,vinfo.visual,xswamask,&xswa);



More information about the MPlayer-users mailing list