changeset 23655:00aa61cde84a

Make X11 window creation and (with -fixed-vo) management simpler and more consistent by introducing a new function that handles most of the ugly things. Changes of behaviour with some vos is unavoidable, bug reports welcome.
author reimar
date Wed, 27 Jun 2007 10:26:13 +0000
parents c80995bd18b9
children 8443a81e4ae3
files libvo/vo_dxr3.c libvo/vo_gl.c libvo/vo_gl2.c libvo/vo_x11.c libvo/vo_xmga.c libvo/vo_xover.c libvo/vo_xv.c libvo/vo_xvidix.c libvo/vo_xvmc.c libvo/x11_common.c libvo/x11_common.h
diffstat 11 files changed, 89 insertions(+), 265 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/vo_dxr3.c	Wed Jun 27 10:08:21 2007 +0000
+++ b/libvo/vo_dxr3.c	Wed Jun 27 10:26:13 2007 +0000
@@ -616,22 +616,13 @@
 				depth = 24;
 			}
 			XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo);
+			vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy,
+				d_width, d_height, flags,
+				CopyFromParent, "Viewing Window", title);
 			xswa.background_pixel = KEY_COLOR;
 			xswa.border_pixel = 0;
 			xswamask = CWBackPixel | CWBorderPixel;
-			hint.y = vo_dy;
-			hint.x = vo_dx;
-			hint.base_width = hint.width = vo_dwidth;
-			hint.base_height = hint.height = vo_dheight;
-			hint.flags = PPosition | PSize;
-			vo_window = XCreateWindow(mDisplay, mRootWin, hint.x, hint.y, hint.width, hint.height, 0, depth, CopyFromParent, vinfo.visual, xswamask, &xswa);
-			vo_x11_classhint(mDisplay, vo_window, "Viewing Window");
-			vo_hidecursor(mDisplay, vo_window);
-			vo_x11_selectinput_witherr(mDisplay, vo_window, StructureNotifyMask | KeyPressMask | PropertyChangeMask);
-			XSetStandardProperties(mDisplay, vo_window, "DXR3 Overlay", "DXR3 Overlay", None, NULL, 0, &hint);
-			XSetWMNormalHints(mDisplay, vo_window, &hint);
-			XMapWindow(mDisplay, vo_window);
-			XSync(mDisplay, False);
+			XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
 		}
 		
 		/* Start setting up overlay */
--- a/libvo/vo_gl.c	Wed Jun 27 10:08:21 2007 +0000
+++ b/libvo/vo_gl.c	Wed Jun 27 10:26:13 2007 +0000
@@ -470,65 +470,18 @@
              ButtonPressMask | ButtonReleaseMask | ExposureMask);
     goto glconfig;
   }
-  if ( vo_window == None ) {
-    unsigned int fg, bg;
-    XSizeHints hint;
-    XVisualInfo *vinfo;
-    XEvent xev;
-
-    vo_fs = VO_FALSE;
-
-    hint.x = vo_dx;
-    hint.y = vo_dy;
-    hint.width = d_width;
-    hint.height = d_height;
-    hint.flags = PPosition | PSize;
-
-    /* Get some colors */
-    bg = WhitePixel(mDisplay, mScreen);
-    fg = BlackPixel(mDisplay, mScreen);
-
-    /* Make the window */
-    vinfo=glXChooseVisual( mDisplay,mScreen,wsGLXAttrib );
+  {
+    XVisualInfo *vinfo=glXChooseVisual( mDisplay,mScreen,wsGLXAttrib );
     if (vinfo == NULL)
     {
       mp_msg(MSGT_VO, MSGL_ERR, "[gl] no GLX support present\n");
       return -1;
     }
 
-    vo_window = vo_x11_create_smooth_window(mDisplay, mRootWin, vinfo->visual,
-                  hint.x, hint.y, hint.width, hint.height, vinfo->depth,
-                  XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocNone));
-
-    vo_x11_classhint( mDisplay,vo_window,"gl" );
-    vo_hidecursor(mDisplay,vo_window);
-
-    XSelectInput(mDisplay, vo_window, StructureNotifyMask);
-    /* Tell other applications about this window */
-    XSetStandardProperties(mDisplay, vo_window, title, title, None, NULL, 0, &hint);
-    /* Set the size hints. */
-    vo_x11_sizehint(hint.x, hint.y, hint.width, hint.height, 0);
-    /* Map window. */
-    XMapWindow(mDisplay, vo_window);
-
-    /* Wait for map. */
-    do {
-      XNextEvent(mDisplay, &xev);
-    } while (xev.type != MapNotify || xev.xmap.event != vo_window);
-
-    XSelectInput(mDisplay, vo_window, NoEventMask);
-
-    XSync(mDisplay, False);
-
-    vo_x11_selectinput_witherr(mDisplay, vo_window,
-        StructureNotifyMask | KeyPressMask | PointerMotionMask |
-        ButtonPressMask | ButtonReleaseMask | ExposureMask);
+    vo_x11_create_vo_window(vinfo, vo_dx, vo_dy, d_width, d_height, flags,
+            XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocNone),
+            "gl", title);
   }
-  if (vo_ontop) vo_x11_setlayer(mDisplay, vo_window, vo_ontop);
-
-  vo_x11_nofs_sizepos(vo_dx, vo_dy, d_width, d_height);
-  if (vo_fs ^ (flags & VOFLAG_FULLSCREEN))
-    vo_x11_fullscreen();
 #endif
 
 glconfig:
--- a/libvo/vo_gl2.c	Wed Jun 27 10:08:21 2007 +0000
+++ b/libvo/vo_gl2.c	Wed Jun 27 10:26:13 2007 +0000
@@ -518,6 +518,7 @@
 }
 
 static int config_glx(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) {
+  XVisualInfo *vinfo, vinfo_buf;
   if (WinID >= 0) {
     vo_window = WinID ? (Window)WinID : mRootWin;
     vo_x11_selectinput_witherr(mDisplay, vo_window,
@@ -525,56 +526,14 @@
              ButtonPressMask | ButtonReleaseMask | ExposureMask);
     return 0;
   }
-  if ( vo_window == None ) {
-    XSizeHints hint;
-    XVisualInfo *vinfo, vinfo_buf;
-    XEvent xev;
-
-    hint.x = vo_dx;
-    hint.y = vo_dy;
-    hint.width = d_width;
-    hint.height = d_height;
-    hint.flags = PPosition | PSize;
-
-    /* Make the window */
     vinfo = choose_glx_visual(mDisplay,mScreen,&vinfo_buf) < 0 ? NULL : &vinfo_buf;
     if (vinfo == NULL) {
       mp_msg(MSGT_VO, MSGL_FATAL, "[gl2] no GLX support present\n");
       return -1;
     }
 
-    vo_fs = VO_FALSE;
-    vo_window = vo_x11_create_smooth_window(mDisplay, RootWindow(mDisplay,mScreen),
-                            vinfo->visual, hint.x, hint.y, hint.width, hint.height, vinfo->depth, vo_x11_create_colormap(vinfo));
-
-    vo_x11_classhint( mDisplay,vo_window,"gl2" );
-    vo_hidecursor(mDisplay,vo_window);
-
-    XSelectInput(mDisplay, vo_window, StructureNotifyMask);
-
-    /* Tell other applications about this window */
-
-    XSetStandardProperties(mDisplay, vo_window, title, title, None, NULL, 0, &hint);
-
-    /* Map window. */
-    XMapWindow(mDisplay, vo_window);
-    vo_x11_sizehint( hint.x, hint.y, hint.width, hint.height,0 );
-    XClearWindow(mDisplay,vo_window);
-
-    /* Wait for map. */
-    do {
-      XNextEvent(mDisplay, &xev);
-    } while (xev.type != MapNotify || xev.xmap.event != vo_window);
-
-    XSync(mDisplay, False);
-
-    //XSelectInput(mDisplay, vo_window, StructureNotifyMask); // !!!!
-    vo_x11_selectinput_witherr(mDisplay, vo_window, StructureNotifyMask | KeyPressMask | PointerMotionMask |
-                               ButtonPressMask | ButtonReleaseMask | ExposureMask);
-  }
-  vo_x11_nofs_sizepos(vo_dx, vo_dy, d_width, d_height);
-  if (vo_fs ^ (flags & VOFLAG_FULLSCREEN))
-    vo_x11_fullscreen();
+  vo_x11_create_vo_window(vinfo, vo_dx, vo_dy, d_width, d_height,
+          flags, vo_x11_create_colormap(vinfo), "gl2", title);
 
   return 0;
 }
--- a/libvo/vo_x11.c	Wed Jun 27 10:08:21 2007 +0000
+++ b/libvo/vo_x11.c	Wed Jun 27 10:26:13 2007 +0000
@@ -440,38 +440,12 @@
                 XSelectInput(mDisplay, vo_window, ExposureMask);
         } else
         {
-            if (vo_window == None)
-            {
-                vo_window =
-                    vo_x11_create_smooth_window(mDisplay, mRootWin,
-                                                vinfo.visual, vo_dx, vo_dy,
-                                                vo_dwidth, vo_dheight,
-                                                depth, theCmap);
-
-                vo_x11_classhint(mDisplay, vo_window, "x11");
-                vo_hidecursor(mDisplay, vo_window);
-                vo_x11_sizehint(vo_dx, vo_dy, vo_dwidth, vo_dheight, 0);
-                XSelectInput(mDisplay, vo_window, StructureNotifyMask);
-                XStoreName(mDisplay, vo_window, title);
-                XMapWindow(mDisplay, vo_window);
-//      if(WinID!=0)
-                do
-                {
-                    XNextEvent(mDisplay, &xev);
-                }
-                while (xev.type != MapNotify
-                       || xev.xmap.event != vo_window);
-
-                vo_x11_nofs_sizepos(vo_dx, vo_dy, vo_dwidth, vo_dheight);
-                if (fullscreen)
-                    vo_x11_fullscreen();
-            } else
-                vo_x11_nofs_sizepos(vo_dx, vo_dy, vo_dwidth, vo_dheight);
+            vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height,
+                    flags, theCmap, "x11", title);
         }
 
         XSync(mDisplay, False);
 
-        // we cannot grab mouse events on root window :(
         vo_x11_selectinput_witherr(mDisplay, vo_window,
                                    StructureNotifyMask | KeyPressMask |
                                    PropertyChangeMask | ExposureMask |
--- a/libvo/vo_xmga.c	Wed Jun 27 10:08:21 2007 +0000
+++ b/libvo/vo_xmga.c	Wed Jun 27 10:26:13 2007 +0000
@@ -220,31 +220,8 @@
 
         } else
         {
-
-            if (vo_window == None)
-            {
-                vo_window = XCreateWindow(mDisplay, mRootWin,
-                                          vo_dx, vo_dy,
-                                          vo_dwidth, vo_dheight,
-                                          xWAttribs.border_pixel,
-                                          mDepth,
-                                          InputOutput,
-                                          vinfo.visual, xswamask,
-                                          &xWAttribs);
-
-                vo_x11_classhint(mDisplay, vo_window, "xmga");
-                vo_hidecursor(mDisplay, vo_window);
-                vo_x11_sizehint(vo_dx, vo_dy, vo_dwidth, vo_dheight, 0);
-
-                XStoreName(mDisplay, vo_window, mTitle);
-                XMapWindow(mDisplay, vo_window);
-                vo_x11_nofs_sizepos(vo_dx, vo_dy, vo_dwidth, vo_dheight);
-
-                if (flags & VOFLAG_FULLSCREEN)
-                    vo_x11_fullscreen();
-
-            } else
-                vo_x11_nofs_sizepos(vo_dx, vo_dy, vo_dwidth, vo_dheight);
+            vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height,
+                    flags, InputOutput, "xmga", title);
         }
 
         if (vo_gc != None)
--- a/libvo/vo_xover.c	Wed Jun 27 10:08:21 2007 +0000
+++ b/libvo/vo_xover.c	Wed Jun 27 10:26:13 2007 +0000
@@ -300,22 +300,10 @@
 	}
       else
 	{
-	  if ( vo_window == None )
-	    {
-	      vo_window = XCreateWindow(mDisplay, RootWindow(mDisplay, mScreen),
-					vo_dx, vo_dy, window_width, window_height, xswa.border_pixel,
-					vinfo.depth, InputOutput, vinfo.visual, xswamask, &xswa);
-
-	      vo_x11_classhint(mDisplay, vo_window, "xvidix");
-	      vo_hidecursor(mDisplay, vo_window);
-	      vo_x11_sizehint( vo_dx,vo_dy,vo_dwidth,vo_dheight,0 );
-
-	      XStoreName(mDisplay, vo_window, title);
-	      XMapWindow(mDisplay, vo_window);
-    
-	      if ( flags&VOFLAG_FULLSCREEN ) vo_x11_fullscreen();
-    
-	    } else if ( !(flags&VOFLAG_FULLSCREEN) ) XMoveResizeWindow( mDisplay,vo_window,vo_dx,vo_dy,vo_dwidth,vo_dheight );
+	    vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy,
+                  window_width, window_height, flags,
+	          InputOutput, "xvidix", title);
+	    XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
 	}
 	 
       if ( vo_gc != None ) XFreeGC( mDisplay,vo_gc );
--- a/libvo/vo_xv.c	Wed Jun 27 10:08:21 2007 +0000
+++ b/libvo/vo_xv.c	Wed Jun 27 10:26:13 2007 +0000
@@ -301,48 +301,13 @@
                 if (vo_dheight <= 0) vo_dheight = d_height;
                 aspect_save_prescale(vo_dwidth, vo_dheight);
             }
-        } else if (vo_window == None)
-        {
-            vo_window =
-                vo_x11_create_smooth_window(mDisplay, mRootWin,
-                                            vinfo.visual, hint.x, hint.y,
-                                            hint.width, hint.height, depth,
-                                            CopyFromParent);
-            XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
-
-            vo_x11_classhint(mDisplay, vo_window, "xv");
-            vo_hidecursor(mDisplay, vo_window);
-
-            vo_x11_selectinput_witherr(mDisplay, vo_window,
-                                       StructureNotifyMask | KeyPressMask |
-                                       PropertyChangeMask | ((WinID == 0) ?
-                                                             0
-                                                             :
-                                                             (PointerMotionMask
-                                                              |
-                                                              ButtonPressMask
-                                                              |
-                                                              ButtonReleaseMask
-                                                              |
-                                                              ExposureMask)));
-            XSetStandardProperties(mDisplay, vo_window, hello, hello, None,
-                                   NULL, 0, &hint);
-            vo_x11_sizehint(hint.x, hint.y, hint.width, hint.height, 0);
-            XMapWindow(mDisplay, vo_window);
-            vo_x11_nofs_sizepos(hint.x, hint.y, hint.width, hint.height);
-            if (flags & VOFLAG_FULLSCREEN)
-                vo_x11_fullscreen();
         } else
         {
-            // vo_fs set means we were already at fullscreen
-            vo_x11_sizehint(hint.x, hint.y, hint.width, hint.height, 0);
-            vo_x11_nofs_sizepos(hint.x, hint.y, hint.width, hint.height);
-            if (flags & VOFLAG_FULLSCREEN && !vo_fs)
-                vo_x11_fullscreen();    // handle -fs on non-first file
+            vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height,
+                   flags, CopyFromParent, "xv", title);
+            XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
         }
 
-//    vo_x11_sizehint( hint.x, hint.y, hint.width, hint.height,0 );   
-
         if (vo_gc != None)
             XFreeGC(mDisplay, vo_gc);
         vo_gc = XCreateGC(mDisplay, vo_window, 0L, &xgcv);
--- a/libvo/vo_xvidix.c	Wed Jun 27 10:08:21 2007 +0000
+++ b/libvo/vo_xvidix.c	Wed Jun 27 10:26:13 2007 +0000
@@ -335,28 +335,10 @@
                 XSelectInput(mDisplay, vo_window, ExposureMask);
         } else
         {
-            if (vo_window == None)
-            {
-                vo_window =
-                    XCreateWindow(mDisplay, RootWindow(mDisplay, mScreen),
-                                  vo_dx, vo_dy, window_width,
-                                  window_height, xswa.border_pixel,
-                                  vinfo.depth, InputOutput, vinfo.visual,
-                                  xswamask, &xswa);
-
-                vo_x11_classhint(mDisplay, vo_window, "xvidix");
-                vo_hidecursor(mDisplay, vo_window);
-                vo_x11_sizehint(vo_dx, vo_dy, vo_dwidth, vo_dheight, 0);
-
-                XStoreName(mDisplay, vo_window, title);
-                XMapWindow(mDisplay, vo_window);
-                vo_x11_nofs_sizepos(vo_dx, vo_dy, vo_dwidth, vo_dheight);
-
-                if (flags & VOFLAG_FULLSCREEN)
-                    vo_x11_fullscreen();
-
-            } else
-                vo_x11_nofs_sizepos(vo_dx, vo_dy, vo_dwidth, vo_dheight);
+            vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy,
+                    window_width, window_height, flags,
+                    CopyFromParent, "xvidix", title);
+            XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
         }
 
         if (vo_gc != None)
--- a/libvo/vo_xvmc.c	Wed Jun 27 10:08:21 2007 +0000
+++ b/libvo/vo_xvmc.c	Wed Jun 27 10:26:13 2007 +0000
@@ -695,33 +695,9 @@
          aspect_save_prescale(vo_dwidth, vo_dheight);
       }
    } else 
-      if ( vo_window == None ){
-         vo_window = XCreateWindow(mDisplay, mRootWin,
-              hint.x, hint.y, hint.width, hint.height,
-              0, depth,CopyFromParent,vinfo.visual,xswamask,&xswa);
-
-         vo_x11_classhint( mDisplay,vo_window,"xvmc" );
-         vo_hidecursor(mDisplay,vo_window);
-
-         vo_x11_selectinput_witherr(mDisplay, vo_window, StructureNotifyMask | KeyPressMask | PropertyChangeMask | ExposureMask |
-	      ((WinID==0) ? 0 : (PointerMotionMask
-		| ButtonPressMask | ButtonReleaseMask)) );
-         XSetStandardProperties(mDisplay, vo_window, hello, hello, None, NULL, 0, &hint);
-         XSetWMNormalHints( mDisplay,vo_window,&hint );
-	 XMapWindow(mDisplay, vo_window);
-	 vo_x11_nofs_sizepos(hint.x, hint.y, hint.width, hint.height);
-	 if ( flags&VOFLAG_FULLSCREEN ) vo_x11_fullscreen();
-	 else {
-	    vo_x11_sizehint( hint.x, hint.y, hint.width, hint.height,0 );
-	 }
-      } else {
-	// vo_fs set means we were already at fullscreen
-	 vo_x11_sizehint( hint.x, hint.y, hint.width, hint.height,0 );
-	 vo_x11_nofs_sizepos(hint.x, hint.y, hint.width, hint.height);
-	 if ( flags&VOFLAG_FULLSCREEN && !vo_fs ) vo_x11_fullscreen(); // handle -fs on non-first file
-      }
-
-//    vo_x11_sizehint( hint.x, hint.y, hint.width, hint.height,0 );   
+      vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height, flags,
+              CopyFromParent, "xvmc", title);
+      XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa);
 
       if ( vo_gc != None ) XFreeGC( mDisplay,vo_gc );
       vo_gc = XCreateGC(mDisplay, vo_window, GCForeground, &xgcv);
--- a/libvo/x11_common.c	Wed Jun 27 10:08:21 2007 +0000
+++ b/libvo/x11_common.c	Wed Jun 27 10:26:13 2007 +0000
@@ -1265,6 +1265,62 @@
     return ret_win;
 }
 
+/**
+ * \brief create and setup a window suitable for display
+ * \param vis Visual to use for creating the window
+ * \param x x position of window
+ * \param y y position of window
+ * \param width width of window
+ * \param height height of window
+ * \param flags flags for window creation.
+ *              Only VOFLAG_FULLSCREEN is supported so far.
+ * \param col_map Colourmap for window
+ * \param classname name to use for the classhint
+ * \param title title for the window
+ *
+ * This also does the grunt-work like setting Window Manager hints etc.
+ * If vo_window is already set it just moves and resizes it.
+ */
+void vo_x11_create_vo_window(XVisualInfo *vis, int x, int y,
+                             unsigned int width, unsigned int height, int flags,
+                             Colormap col_map,
+                             const char *classname, const char *title)
+{
+  if (vo_window == None) {
+    XSizeHints hint;
+    XEvent xev;
+    vo_fs = 0;
+    vo_dwidth = width;
+    vo_dheight = height;
+    vo_window = vo_x11_create_smooth_window(mDisplay, mRootWin, vis->visual,
+                      x, y, width, height, vis->depth, col_map);
+    vo_x11_classhint(mDisplay, vo_window, classname);
+    XStoreName(mDisplay, vo_window, title);
+    vo_hidecursor(mDisplay, vo_window);
+    XSelectInput(mDisplay, vo_window, StructureNotifyMask);
+    hint.x = x; hint.y = y;
+    hint.width = width; hint.height = height;
+    hint.flags = PPosition | PSize;
+    XSetStandardProperties(mDisplay, vo_window, title, title, None, NULL, 0, &hint);
+    vo_x11_sizehint(x, y, width, height, 0);
+    // map window
+    XMapWindow(mDisplay, vo_window);
+    XClearWindow(mDisplay, vo_window);
+    // wait for map
+    do {
+      XNextEvent(mDisplay, &xev);
+    } while (xev.type != MapNotify || xev.xmap.event != vo_window);
+    XSelectInput(mDisplay, vo_window, NoEventMask);
+    XSync(mDisplay, False);
+    vo_x11_selectinput_witherr(mDisplay, vo_window,
+          StructureNotifyMask | KeyPressMask | PointerMotionMask |
+          ButtonPressMask | ButtonReleaseMask | ExposureMask);
+  }
+  if (vo_ontop) vo_x11_setlayer(mDisplay, vo_window, vo_ontop);
+  vo_x11_nofs_sizepos(vo_dx, vo_dy, width, height);
+  if (!!vo_fs != !!(flags & VOFLAG_FULLSCREEN))
+    vo_x11_fullscreen();
+}
 
 void vo_x11_clearwindow_part(Display * mDisplay, Window vo_window,
                              int img_width, int img_height, int use_fs)
--- a/libvo/x11_common.h	Wed Jun 27 10:08:21 2007 +0000
+++ b/libvo/x11_common.h	Wed Jun 27 10:26:13 2007 +0000
@@ -55,6 +55,9 @@
 extern Window vo_x11_create_smooth_window( Display *mDisplay, Window mRoot,
 	Visual *vis, int x, int y, unsigned int width, unsigned int height,
 	int depth, Colormap col_map);
+extern void vo_x11_create_vo_window(XVisualInfo *vis, int x, int y,
+	unsigned int width, unsigned int height, int flags,
+	Colormap col_map, const char *classname, const char *title);
 extern void vo_x11_clearwindow_part(Display *mDisplay, Window vo_window,
 	int img_width, int img_height, int use_fs);
 extern void vo_x11_clearwindow( Display *mDisplay, Window vo_window );