changeset 7802:037982e833a7

Choose a good visual from the list of supported visuals on the X11 server, instead of using the attributes from the root window. A framebuffer in a Sun often runs using a default visual of 8-bit pseudocolor, yet a better 24 or 32 bit truecolor visual is available.
author jkeil
date Sat, 19 Oct 2002 19:54:59 +0000
parents 48b7d7fd7075
children 172ee2b4612f
files Gui/wm/ws.c Gui/wm/ws.h
diffstat 2 files changed, 40 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/Gui/wm/ws.c	Sat Oct 19 19:47:16 2002 +0000
+++ b/Gui/wm/ws.c	Sat Oct 19 19:54:59 2002 +0000
@@ -262,7 +262,6 @@
  mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[ws] Display name: %s => %s display.\n",dispname,localdisp?"local":"REMOTE");
  if (!localdisp) mp_msg( MSGT_GPLAYER,MSGL_STATUS,"[ws] Remote display, disabling XMITSHM\n");
 }
-
  if ( !XShmQueryExtension( wsDisplay ) )
   {
    mp_msg( MSGT_GPLAYER,MSGL_ERR,"[ws] sorry, your system is not supported X shared memory extension.\n" );
@@ -367,6 +366,8 @@
 
 void wsCreateWindow( wsTWindow * win,int X,int Y,int wX,int hY,int bW,int cV,unsigned char D,char * label )
 {
+ int depth;
+
  win->Property=D;
  if ( D & wsShowFrame ) win->Decorations=1;
  wsHGC=DefaultGC( wsDisplay,wsScreen );
@@ -399,13 +400,13 @@
  win->wsCursorPixmap=XCreateBitmapFromData( wsDisplay,wsRootWin,win->wsCursorData,1,1 );
  if ( !(cV & wsShowMouseCursor) ) win->wsCursor=XCreatePixmapCursor( wsDisplay,win->wsCursorPixmap,win->wsCursorPixmap,&win->wsColor,&win->wsColor,0,0 );
 
- XGetWindowAttributes( wsDisplay,wsRootWin,&win->Attribs );
- if ( win->Attribs.depth < 15 )
+ depth = vo_find_depth_from_visuals( wsDisplay,wsScreen,NULL );
+ if ( depth < 15 )
   {
    mp_msg( MSGT_GPLAYER,MSGL_FATAL,"[ws] sorry, this color depth is not enough.\n" );
    exit( 0 );
   }
- XMatchVisualInfo( wsDisplay,wsScreen,win->Attribs.depth,TrueColor,&win->VisualInfo );
+ XMatchVisualInfo( wsDisplay,wsScreen,depth,TrueColor,&win->VisualInfo );
 
 // ---
  win->AtomLeaderClient=XInternAtom( wsDisplay,"WM_CLIENT_LEADER",False );
@@ -1139,24 +1140,40 @@
 
 int wsGetDepthOnScreen( void )
 {
- int                 bpp,ibpp;
- XImage            * mXImage;
- XWindowAttributes   attribs;
-
- mXImage=XGetImage( wsDisplay,wsRootWin,0,0,1,1,AllPlanes,ZPixmap );
- bpp=mXImage->bits_per_pixel;
+ int depth;
+ XImage * mXImage;
+ Visual * visual;
 
- XGetWindowAttributes( wsDisplay,wsRootWin,&attribs );
- ibpp=attribs.depth;
- mXImage=XGetImage( wsDisplay,wsRootWin,0,0,1,1,AllPlanes,ZPixmap );
- bpp=mXImage->bits_per_pixel;
- if ( ( ibpp + 7 ) / 8 != ( bpp + 7 ) / 8 ) ibpp=bpp;
- wsDepthOnScreen=ibpp;
- wsRedMask=mXImage->red_mask;
- wsGreenMask=mXImage->green_mask;
- wsBlueMask=mXImage->blue_mask;
- XDestroyImage( mXImage );
- return ibpp;
+ if( (depth = vo_find_depth_from_visuals( wsDisplay,wsScreen,&visual )) > 0 )
+  {
+   mXImage = XCreateImage( wsDisplay,visual,depth,ZPixmap,0,NULL,
+			   1,1,32,0 );
+   wsDepthOnScreen = mXImage->bits_per_pixel;
+   wsRedMask=mXImage->red_mask;
+   wsGreenMask=mXImage->green_mask;
+   wsBlueMask=mXImage->blue_mask;
+   XDestroyImage( mXImage );
+  }
+ else
+  {
+   int                 bpp,ibpp;
+   XWindowAttributes   attribs;
+
+   mXImage=XGetImage( wsDisplay,wsRootWin,0,0,1,1,AllPlanes,ZPixmap );
+   bpp=mXImage->bits_per_pixel;
+
+   XGetWindowAttributes( wsDisplay,wsRootWin,&attribs );
+   ibpp=attribs.depth;
+   mXImage=XGetImage( wsDisplay,wsRootWin,0,0,1,1,AllPlanes,ZPixmap );
+   bpp=mXImage->bits_per_pixel;
+   if ( ( ibpp + 7 ) / 8 != ( bpp + 7 ) / 8 ) ibpp=bpp;
+   wsDepthOnScreen=ibpp;
+   wsRedMask=mXImage->red_mask;
+   wsGreenMask=mXImage->green_mask;
+   wsBlueMask=mXImage->blue_mask;
+   XDestroyImage( mXImage );
+  }
+ return wsDepthOnScreen;
 }
 
 void wsXDone( void )
@@ -1195,7 +1212,7 @@
   {
    CompletionType=XShmGetEventBase( wsDisplay ) + ShmCompletion;
    win->xImage=XShmCreateImage( wsDisplay,win->VisualInfo.visual,
-                   win->Attribs.depth,ZPixmap,NULL,&win->Shminfo,Width,Height );
+                   win->VisualInfo.depth,ZPixmap,NULL,&win->Shminfo,Width,Height );
    if ( win->xImage == NULL )
     {
      mp_msg( MSGT_GPLAYER,MSGL_FATAL,"[ws] shared memory extension error.\n" );
@@ -1224,7 +1241,7 @@
   }
   else
    {
-    win->xImage=XCreateImage( wsDisplay,win->VisualInfo.visual,win->Attribs.depth,
+    win->xImage=XCreateImage( wsDisplay,win->VisualInfo.visual,win->VisualInfo.depth,
                               ZPixmap,0,0,Width,Height,
                               (wsDepthOnScreen == 3) ? 32 : wsDepthOnScreen,
                               0 );
--- a/Gui/wm/ws.h	Sat Oct 19 19:47:16 2002 +0000
+++ b/Gui/wm/ws.h	Sat Oct 19 19:54:59 2002 +0000
@@ -155,7 +155,6 @@
  XGCValues            wGCV;
  unsigned long        WindowMask;
  XVisualInfo          VisualInfo;
- XWindowAttributes    Attribs;
  XSetWindowAttributes WindowAttrib;
  XSizeHints           SizeHint;
  XWMHints             WMHints;