changeset 922:db06ae8967eb

Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
author lgb
date Thu, 31 May 2001 22:32:58 +0000
parents 6b02113cd41a
children 424601152621
files DOCS/AUTHORS cfg-mplayer.h libvo/vo_x11.c libvo/vo_xmga.c libvo/vo_xv.c libvo/x11_common.c libvo/x11_common.h
diffstat 7 files changed, 82 insertions(+), 88 deletions(-) [+]
line wrap: on
line diff
--- a/DOCS/AUTHORS	Thu May 31 18:08:24 2001 +0000
+++ b/DOCS/AUTHORS	Thu May 31 22:32:58 2001 +0000
@@ -32,6 +32,7 @@
 - Makefile improvements
 - prelimenary DVD support
 - another GUI code (is that so..?)
+- various X11 cleanups and fixes
 
 Gábor Bérczi (Gabucino):  <gabucino@k2.jozsef.kando.hu>
 - documentation maintainer
--- a/cfg-mplayer.h	Thu May 31 18:08:24 2001 +0000
+++ b/cfg-mplayer.h	Thu May 31 22:32:58 2001 +0000
@@ -26,6 +26,10 @@
 extern int osd_level;
 extern int sub_unicode;
 
+#ifdef HAVE_X11
+extern char *mDisplayName;
+#endif
+
 struct config conf[]={
 	/* name, pointer, type, flags, min, max */
 	{"include", cfg_include, CONF_TYPE_FUNC_PARAM, 0, 0, 0}, /* this must be the first!!! */
@@ -34,6 +38,9 @@
 	{"vo", &video_driver, CONF_TYPE_STRING, 0, 0, 0},
 	{"dsp", &dsp, CONF_TYPE_STRING, 0, 0, 0},
         {"mixer", &mixer_device, CONF_TYPE_STRING, 0, 0, 0},
+#ifdef HAVE_X11
+	{"display", &mDisplayName, CONF_TYPE_STRING, 0, 0, 0},
+#endif
         {"master", &mixer_usemaster, CONF_TYPE_FLAG, 0, 0, 1},
 	{"osdlevel", &osd_level, CONF_TYPE_INT, CONF_RANGE, 0, 2 },
 #ifdef HAVE_LIBCSS
--- a/libvo/vo_x11.c	Thu May 31 18:08:24 2001 +0000
+++ b/libvo/vo_x11.c	Thu May 31 22:32:58 2001 +0000
@@ -61,7 +61,7 @@
 #endif
 
 /* X11 related variables */
-static Display *mDisplay;
+//static Display *mDisplay;
 static Window mywindow;
 static GC mygc;
 static XImage *myximage;
@@ -120,7 +120,7 @@
  int interval, prefer_blank, allow_exp, nothing;
  unsigned int fg,bg;
  char *hello=( title == NULL ) ? "X11 render" : title;
- char *name=":0.0";
+// char *name=":0.0";
  XSizeHints hint;
  XVisualInfo vinfo;
  XEvent xev;
@@ -136,17 +136,6 @@
  if ( X_already_started ) return -1;
  if( !vo_init() ) return 0; // Can't open X11
 
- if( getenv( "DISPLAY" ) ) name=getenv( "DISPLAY" );
-
- mDisplay=XOpenDisplay( name );
-
- if ( mDisplay == NULL )
-  {
-   printf( "Can not open display\n" );
-   return -1;
-  }
- screen=DefaultScreen( mDisplay );
-
  hint.x=0;
  hint.y=0;
  hint.width=image_width;
@@ -172,7 +161,7 @@
 
     if (have_vm) {
       if (vidmodes==NULL)
-        XF86VidModeGetAllModeLines(mDisplay,screen,&modecount,&vidmodes);
+        XF86VidModeGetAllModeLines(mDisplay,mScreen,&modecount,&vidmodes);
       j=0;
       modeline_width=vidmodes[0]->hdisplay;
       modeline_height=vidmodes[0]->vdisplay;
@@ -191,12 +180,12 @@
           }
 
       printf("XF86VM: Selected video mode %dx%d for image size %dx%d.\n",modeline_width, modeline_height, image_width, image_height);
-      XF86VidModeLockModeSwitch(mDisplay,screen,0);
-      XF86VidModeSwitchToMode(mDisplay,screen,vidmodes[j]);
-      XF86VidModeSwitchToMode(mDisplay,screen,vidmodes[j]);
+      XF86VidModeLockModeSwitch(mDisplay,mScreen,0);
+      XF86VidModeSwitchToMode(mDisplay,mScreen,vidmodes[j]);
+      XF86VidModeSwitchToMode(mDisplay,mScreen,vidmodes[j]);
       X=(vo_screenwidth-modeline_width)/2;
       Y=(vo_screenheight-modeline_height)/2;
-      XF86VidModeSetViewPort(mDisplay,screen,X,Y);
+      XF86VidModeSetViewPort(mDisplay,mScreen,X,Y);
     }
   }
 #endif
@@ -211,16 +200,16 @@
  vo_dheight=hint.height;
  hint.flags=PPosition | PSize;
 
- bg=WhitePixel( mDisplay,screen );
- fg=BlackPixel( mDisplay,screen );
+ bg=WhitePixel( mDisplay,mScreen );
+ fg=BlackPixel( mDisplay,mScreen );
 
  XGetWindowAttributes( mDisplay,DefaultRootWindow( mDisplay ),&attribs );
  depth=attribs.depth;
 
  if ( depth != 15 && depth != 16 && depth != 24 && depth != 32 ) depth=24;
- XMatchVisualInfo( mDisplay,screen,depth,TrueColor,&vinfo );
+ XMatchVisualInfo( mDisplay,mScreen,depth,TrueColor,&vinfo );
 
- theCmap  =XCreateColormap( mDisplay,RootWindow( mDisplay,screen ),
+ theCmap  =XCreateColormap( mDisplay,RootWindow( mDisplay,mScreen ),
  vinfo.visual,AllocNone );
 
  xswa.background_pixel=0;
@@ -228,7 +217,7 @@
  xswa.colormap=theCmap;
  xswamask=CWBackPixel | CWBorderPixel |CWColormap;
 
- mywindow=XCreateWindow( mDisplay,RootWindow( mDisplay,screen ),
+ mywindow=XCreateWindow( mDisplay,RootWindow( mDisplay,mScreen ),
                          hint.x,hint.y,
                          hint.width,hint.height,
                          xswa.border_pixel,depth,CopyFromParent,vinfo.visual,xswamask,&xswa );
@@ -248,7 +237,7 @@
  mygc=XCreateGC( mDisplay,mywindow,0L,&xgcv );
 
 #ifdef SH_MEM
- if ( XShmQueryExtension( mDisplay ) ) Shmem_Flag=1;
+ if ( mLocalDisplay && XShmQueryExtension( mDisplay ) ) Shmem_Flag=1;
   else
    {
     Shmem_Flag=0;
--- a/libvo/vo_xmga.c	Thu May 31 18:08:24 2001 +0000
+++ b/libvo/vo_xmga.c	Thu May 31 22:32:58 2001 +0000
@@ -62,7 +62,7 @@
  ""
 };
 
-static Display              * mDisplay;
+//static Display              * mDisplay;
 static Window                 mWindow;
 static GC                     mGC;
 static XGCValues              wGCV;
@@ -225,17 +225,7 @@
 
  if ( X_already_started ) return -1;
 
- vo_init();
-
- if ( getenv( "DISPLAY" ) ) name=getenv( "DISPLAY" );
- mDisplay=XOpenDisplay(name);
- if ( mDisplay == NULL )
-  {
-   printf( "Can not open X11 display\n" );
-   return -1;
-  }
-
- mScreen=DefaultScreen( mDisplay );
+ if (!vo_init()) return -1;
 
  mvWidth=width; mvHeight=height;
 
--- a/libvo/vo_xv.c	Thu May 31 18:08:24 2001 +0000
+++ b/libvo/vo_xv.c	Thu May 31 22:32:58 2001 +0000
@@ -48,7 +48,7 @@
 static unsigned char *ImageData;
 
 /* X11 related variables */
-static Display *mydisplay;
+//static Display *mydisplay;
 static Window mywindow;
 static GC mygc;
 static XImage *myximage;
@@ -95,9 +95,9 @@
  */
 static uint32_t init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
 {
- int screen;
+// int screen;
  char *hello = (title == NULL) ? "Xv render" : title;
- char *name = ":0.0";
+// char *name = ":0.0";
  XSizeHints hint;
  XVisualInfo vinfo;
  XEvent xev;
@@ -112,18 +112,8 @@
 
  mFullscreen=flags&1;
  dwidth=d_width; dheight=d_height;
-
- if(getenv("DISPLAY")) name = getenv("DISPLAY");
-
- mydisplay = XOpenDisplay(name);
-
- if (mydisplay == NULL)
-  {
-   printf("Can't open display\n");
-   return -1;
-  }
-
- screen = DefaultScreen(mydisplay);
+ 
+ if (!vo_init()) return -1;
 
 #ifdef HAVE_GUI
  if ( vo_window == None )
@@ -139,26 +129,26 @@
      hint.height=vo_screenheight;
     }
    hint.flags = PPosition | PSize;
-   XGetWindowAttributes(mydisplay, DefaultRootWindow(mydisplay), &attribs);
+   XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs);
    depth=attribs.depth;
    if (depth != 15 && depth != 16 && depth != 24 && depth != 32) depth = 24;
-   XMatchVisualInfo(mydisplay, screen, depth, TrueColor, &vinfo);
+   XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo);
 
    xswa.background_pixel = 0;
    xswa.border_pixel     = 0;
    xswamask = CWBackPixel | CWBorderPixel;
 
-   mywindow = XCreateWindow(mydisplay, RootWindow(mydisplay,screen),
+   mywindow = XCreateWindow(mDisplay, RootWindow(mDisplay,mScreen),
    hint.x, hint.y, hint.width, hint.height,
    0, depth,CopyFromParent,vinfo.visual,xswamask,&xswa);
-   vo_hidecursor(mydisplay,mywindow);
+   vo_hidecursor(mDisplay,mywindow);
 
-   XSelectInput(mydisplay, mywindow, StructureNotifyMask | KeyPressMask );
-   XSetStandardProperties(mydisplay, mywindow, hello, hello, None, NULL, 0, &hint);
-   if ( mFullscreen ) vo_x11_decoration( mydisplay,mywindow,0 );
-   XMapWindow(mydisplay, mywindow);
-   XFlush(mydisplay);
-   XSync(mydisplay, False);
+   XSelectInput(mDisplay, mywindow, StructureNotifyMask | KeyPressMask );
+   XSetStandardProperties(mDisplay, mywindow, hello, hello, None, NULL, 0, &hint);
+   if ( mFullscreen ) vo_x11_decoration( mDisplay,mywindow,0 );
+   XMapWindow(mDisplay, mywindow);
+   XFlush(mDisplay);
+   XSync(mDisplay, False);
 #ifdef HAVE_GUI
   }
   else
@@ -167,20 +157,20 @@
      mygc=vo_gc;
      if ( vo_screenwidth != d_width )
       {
-       XMoveWindow( mydisplay,mywindow,( vo_screenwidth - d_width ) / 2,( vo_screenheight - d_height ) / 2 );
-       XResizeWindow( mydisplay,mywindow,d_width,d_height );
+       XMoveWindow( mDisplay,mywindow,( vo_screenwidth - d_width ) / 2,( vo_screenheight - d_height ) / 2 );
+       XResizeWindow( mDisplay,mywindow,d_width,d_height );
       }
       else mFullscreen=1;
     }
 #endif
 
- mygc = XCreateGC(mydisplay, mywindow, 0L, &xgcv);
+ mygc = XCreateGC(mDisplay, mywindow, 0L, &xgcv);
 
  xv_port = 0;
- if (Success == XvQueryExtension(mydisplay,&ver,&rel,&req,&ev,&err))
+ if (Success == XvQueryExtension(mDisplay,&ver,&rel,&req,&ev,&err))
   {
    /* check for Xvideo support */
-   if (Success != XvQueryAdaptors(mydisplay,DefaultRootWindow(mydisplay), &adaptors,&ai))
+   if (Success != XvQueryAdaptors(mDisplay,DefaultRootWindow(mDisplay), &adaptors,&ai))
     {
      printf("Xv: XvQueryAdaptors failed");
      return -1;
@@ -193,7 +183,7 @@
    /* check image formats */
    if (xv_port != 0)
     {
-     fo = XvListImageFormats(mydisplay, xv_port, (int*)&formats);
+     fo = XvListImageFormats(mDisplay, xv_port, (int*)&formats);
      xv_format=0;
      for(i = 0; i < formats; i++)
       {
@@ -216,9 +206,9 @@
 
      current_buf=0;
 
-     XGetGeometry( mydisplay,mywindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth );
+     XGetGeometry( mDisplay,mywindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth );
      drwX=0; drwY=0;
-     XTranslateCoordinates( mydisplay,mywindow,mRoot,0,0,&drwcX,&drwcY,&mRoot );
+     XTranslateCoordinates( mDisplay,mywindow,mRoot,0,0,&drwcX,&drwcY,&mRoot );
      printf( "[xv] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight );
 
      if ( mFullscreen )
@@ -232,7 +222,7 @@
        printf( "[xv-fs] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight );
       }
 
-     saver_off(mydisplay);  // turning off screen saver
+     saver_off(mDisplay);  // turning off screen saver
      return 0;
     }
   }
@@ -251,15 +241,15 @@
   * allocate XvImages.  FIXME: no error checking, without
   * mit-shm this will bomb...
   */
- xvimage[foo] = XvShmCreateImage(mydisplay, xv_port, xv_format, 0, image_width, image_height, &Shminfo[foo]);
+ xvimage[foo] = XvShmCreateImage(mDisplay, xv_port, xv_format, 0, image_width, image_height, &Shminfo[foo]);
 
  Shminfo[foo].shmid    = shmget(IPC_PRIVATE, xvimage[foo]->data_size, IPC_CREAT | 0777);
  Shminfo[foo].shmaddr  = (char *) shmat(Shminfo[foo].shmid, 0, 0);
  Shminfo[foo].readOnly = False;
 
  xvimage[foo]->data = Shminfo[foo].shmaddr;
- XShmAttach(mydisplay, &Shminfo[foo]);
- XSync(mydisplay, False);
+ XShmAttach(mDisplay, &Shminfo[foo]);
+ XSync(mDisplay, False);
  shmctl(Shminfo[foo].shmid, IPC_RMID, 0);
  memset(xvimage[foo]->data,128,xvimage[foo]->data_size);
  return;
@@ -267,12 +257,12 @@
 
 static void check_events(void)
 {
- int e=vo_x11_check_events(mydisplay);
+ int e=vo_x11_check_events(mDisplay);
  if(e&VO_EVENT_RESIZE)
   {
-   XGetGeometry( mydisplay,mywindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth );
+   XGetGeometry( mDisplay,mywindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth );
    drwX=0; drwY=0;
-   XTranslateCoordinates( mydisplay,mywindow,mRoot,0,0,&drwcX,&drwcY,&mRoot );
+   XTranslateCoordinates( mDisplay,mywindow,mRoot,0,0,&drwcX,&drwcY,&mRoot );
    printf( "[xv] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight );
 
    #ifdef HAVE_GUI
@@ -327,11 +317,11 @@
 {
  vo_draw_text(image_width,image_height,draw_alpha);
  check_events();
- XvShmPutImage(mydisplay, xv_port, mywindow, mygc, xvimage[current_buf],
+ XvShmPutImage(mDisplay, xv_port, mywindow, mygc, xvimage[current_buf],
          0, 0,  image_width, image_height,
          drwX,drwY,drwWidth,(mFullscreen?drwHeight - 1:drwHeight),
          False);
- XFlush(mydisplay);
+ XFlush(mDisplay);
  current_buf=(current_buf+1)%NUM_BUFFERS;
  return;
 }
@@ -436,7 +426,7 @@
 }
 
 static void uninit(void) {
-    saver_on(mydisplay); // screen saver back on
+    saver_on(mDisplay); // screen saver back on
 }
 
 
--- a/libvo/x11_common.c	Thu May 31 18:08:24 2001 +0000
+++ b/libvo/x11_common.c	Thu May 31 22:32:58 2001 +0000
@@ -22,6 +22,12 @@
 static int dpms_disabled=0;
 static int timeout_save=0;
 
+char* mDisplayName=NULL;
+Display* mDisplay;
+Window   mRootWin;
+int mScreen;
+int mLocalDisplay;
+
 
 void vo_hidecursor ( Display *disp , Window win )
 {
@@ -42,21 +48,24 @@
 int vo_init( void )
 {
  int       CompletionType = -1;
- int       mScreen;
+// int       mScreen;
  int bpp;
- char    * DisplayName = ":0.0";
- Display * mDisplay;
+// char    * DisplayName = ":0.0";
+// Display * mDisplay;
  XImage  * mXImage;
- Window    mRootWin;
+// Window    mRootWin;
  static XWindowAttributes attribs;
 
  if(vo_depthonscreen) return 1; // already called
 
- if ( getenv( "DISPLAY" ) ) DisplayName=getenv( "DISPLAY" );
- mDisplay=XOpenDisplay( DisplayName );
+ if (!mDisplayName)
+   if (!(mDisplayName=getenv("DISPLAY")))
+     mDisplayName=strdup(":0.0");
+
+ mDisplay=XOpenDisplay(mDisplayName);
  if ( !mDisplay )
   {
-   printf( "vo: couldn't open the X11 display!\n" );
+   printf( "vo: couldn't open the X11 display (%s)!\n",mDisplayName );
    return 0;
   }
  mScreen=DefaultScreen( mDisplay );     // Screen ID.
@@ -72,8 +81,10 @@
    bpp=mXImage->bits_per_pixel;
    XDestroyImage( mXImage );
  if((vo_depthonscreen+7)/8 != (bpp+7)/8) vo_depthonscreen=bpp; // by A'rpi
- XCloseDisplay( mDisplay );
- printf("X11 running at %dx%d depth: %d\n",vo_screenwidth,vo_screenheight,vo_depthonscreen);
+// XCloseDisplay( mDisplay );
+#warning Better local display detection method is needed. 
+ if (*mDisplayName==':') mLocalDisplay=1; else mLocalDisplay=0;
+ printf("X11 running at %dx%d depth: %d (\"%s\" => %s display)\n",vo_screenwidth,vo_screenheight,vo_depthonscreen,mDisplayName,mLocalDisplay?"local":"remote");
  return 1;
 }
 
--- a/libvo/x11_common.h	Thu May 31 18:08:24 2001 +0000
+++ b/libvo/x11_common.h	Thu May 31 22:32:58 2001 +0000
@@ -7,6 +7,12 @@
 extern int vo_dwidth;
 extern int vo_dheight;
 
+extern char *mDisplayName;
+extern Display *mDisplay;
+extern Window *mRootWin;
+extern int mScreen;
+extern int mLocalDisplay;
+
 int vo_init( void );
 int vo_hidecursor ( Display* , Window );
 void vo_x11_decoration( Display * vo_Display,Window w,int d );