changeset 33539:5bdc088113f7

Cosmetic: Format to MPlayer coding style.
author ib
date Thu, 16 Jun 2011 12:31:42 +0000
parents 64e43eb13ebf
children 0dec83e053cc
files gui/wm/ws.c gui/wm/ws.h
diffstat 2 files changed, 1274 insertions(+), 994 deletions(-) [+]
line wrap: on
line diff
--- a/gui/wm/ws.c	Thu Jun 16 12:30:24 2011 +0000
+++ b/gui/wm/ws.c	Thu Jun 16 12:31:42 2011 +0000
@@ -67,72 +67,74 @@
 
 #undef ENABLE_DPMS
 
-typedef struct
-{
- unsigned long flags;
- unsigned long functions;
- unsigned long decorations;
- long input_mode;
- unsigned long status;
+typedef struct {
+    unsigned long flags;
+    unsigned long functions;
+    unsigned long decorations;
+    long input_mode;
+    unsigned long status;
 } MotifWmHints;
 
-Atom                 wsMotifHints;
+Atom wsMotifHints;
 
-int                  wsMaxX         = 0; // Screen width.
-int                  wsMaxY         = 0; // Screen height.
-int                  wsOrgX         = 0; // Screen origin x.
-int                  wsOrgY         = 0; // Screen origin y.
+int wsMaxX = 0;                          // Screen width.
+int wsMaxY = 0;                          // Screen height.
+int wsOrgX = 0;                          // Screen origin x.
+int wsOrgY = 0;                          // Screen origin y.
 
-Display            * wsDisplay;
-int                  wsScreen;
-Window               wsRootWin;
-XEvent               wsEvent;
-int                  wsWindowDepth;
-GC                   wsHGC;
-MotifWmHints         wsMotifWmHints;
-Atom                 wsTextProperlyAtom = None;
-int		     wsLayer = 0;
+Display *wsDisplay;
+int wsScreen;
+Window wsRootWin;
+XEvent wsEvent;
+int wsWindowDepth;
+GC wsHGC;
+MotifWmHints wsMotifWmHints;
+Atom wsTextProperlyAtom = None;
+int wsLayer = 0;
 
-int                  wsDepthOnScreen = 0;
-int                  wsRedMask = 0;
-int                  wsGreenMask = 0;
-int                  wsBlueMask = 0;
-int                  wsOutMask = 0;
-int                  wsNonNativeOrder = 0;
+int wsDepthOnScreen  = 0;
+int wsRedMask        = 0;
+int wsGreenMask      = 0;
+int wsBlueMask       = 0;
+int wsOutMask        = 0;
+int wsNonNativeOrder = 0;
 
-int                  wsTrue    = True;
+int wsTrue = True;
 
-#define	wsWLCount 5
-wsTWindow          * wsWindowList[wsWLCount] = { NULL,NULL,NULL,NULL,NULL };
+#define wsWLCount 5
+wsTWindow *wsWindowList[wsWLCount] = { NULL, NULL, NULL, NULL, NULL };
+
+unsigned long wsKeyTable[512];
 
-unsigned long        wsKeyTable[512];
+int wsUseXShm   = 1;
+int wsUseXShape = 1;
 
-int                  wsUseXShm = 1;
-int                  wsUseXShape = 1;
+static int wsSearch(Window win)
+{
+    int i;
 
-static int wsSearch( Window win )
-{
- int i;
- for ( i=0;i<wsWLCount;i++ ) if ( wsWindowList[i] && wsWindowList[i]->WindowID == win ) return i;
- return -1;
+    for (i = 0; i < wsWLCount; i++)
+        if (wsWindowList[i] && wsWindowList[i]->WindowID == win)
+            return i;
+
+    return -1;
 }
 
-
 // ---
 
-#define PACK_RGB16(r,g,b,pixel) pixel=(b>>3);\
-                                pixel<<=6;\
-                                pixel|=(g>>2);\
-                                pixel<<=5;\
-                                pixel|=(r>>3)
+#define PACK_RGB16(r, g, b, pixel) pixel = (b >> 3); \
+    pixel <<= 6; \
+    pixel  |= (g >> 2); \
+    pixel <<= 5; \
+    pixel  |= (r >> 3)
 
-#define PACK_RGB15(r,g,b,pixel) pixel=(b>>3);\
-                                pixel<<=5;\
-                                pixel|=(g>>3);\
-                                pixel<<=5;\
-	                        pixel|=(r>>3)
+#define PACK_RGB15(r, g, b, pixel) pixel = (b >> 3); \
+    pixel <<= 5; \
+    pixel  |= (g >> 3); \
+    pixel <<= 5; \
+    pixel  |= (r >> 3)
 
-struct SwsContext *sws_ctx = NULL;
+struct SwsContext *sws_ctx   = NULL;
 enum PixelFormat out_pix_fmt = PIX_FMT_NONE;
 
 // ---
@@ -163,160 +165,184 @@
 #define MWM_INPUT_FULL_APPLICATION_MODAL 3
 #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL
 
-#define MWM_TEAROFF_WINDOW      (1L<<0)
+#define MWM_TEAROFF_WINDOW      (1L << 0)
 
-void wsWindowDecoration( wsTWindow * win,long d )
+void wsWindowDecoration(wsTWindow *win, long d)
 {
- wsMotifHints=XInternAtom( wsDisplay,"_MOTIF_WM_HINTS",0 );
- if ( wsMotifHints == None ) return;
+    wsMotifHints = XInternAtom(wsDisplay, "_MOTIF_WM_HINTS", 0);
+
+    if (wsMotifHints == None)
+        return;
 
- memset( &wsMotifWmHints,0,sizeof( MotifWmHints ) );
- wsMotifWmHints.flags=MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
- if ( d )
-  {
-   wsMotifWmHints.functions=MWM_FUNC_MOVE | MWM_FUNC_CLOSE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE | MWM_FUNC_RESIZE;
-   wsMotifWmHints.decorations=MWM_DECOR_ALL;
-  }
- XChangeProperty( wsDisplay,win->WindowID,wsMotifHints,wsMotifHints,32,
-                  PropModeReplace,(unsigned char *)&wsMotifWmHints,5 );
+    memset(&wsMotifWmHints, 0, sizeof(MotifWmHints));
+    wsMotifWmHints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
+
+    if (d) {
+        wsMotifWmHints.functions   = MWM_FUNC_MOVE | MWM_FUNC_CLOSE | MWM_FUNC_MINIMIZE | MWM_FUNC_MAXIMIZE | MWM_FUNC_RESIZE;
+        wsMotifWmHints.decorations = MWM_DECOR_ALL;
+    }
+
+    XChangeProperty(wsDisplay, win->WindowID, wsMotifHints, wsMotifHints, 32,
+                    PropModeReplace, (unsigned char *)&wsMotifWmHints, 5);
 }
 
 // ----------------------------------------------------------------------------------------------
 //   Init X Window System.
 // ----------------------------------------------------------------------------------------------
 
-static int wsErrorHandler( Display * dpy, XErrorEvent * Event )
+static int wsErrorHandler(Display *dpy, XErrorEvent *Event)
 {
- char type[128];
- XGetErrorText( wsDisplay,Event->error_code,type,128 );
- fprintf(stderr,"[ws] Error in display.\n");
- fprintf(stderr,"[ws]  Error code: %d ( %s )\n",Event->error_code,type );
- fprintf(stderr,"[ws]  Request code: %d\n",Event->request_code );
- fprintf(stderr,"[ws]  Minor code: %d\n",Event->minor_code );
- fprintf(stderr,"[ws]  Modules: %s\n",current_module?current_module:"(NULL)" );
- return 0;
+    char type[128];
+
+    XGetErrorText(wsDisplay, Event->error_code, type, 128);
+    fprintf(stderr, "[ws] Error in display.\n");
+    fprintf(stderr, "[ws]  Error code: %d ( %s )\n", Event->error_code, type);
+    fprintf(stderr, "[ws]  Request code: %d\n", Event->request_code);
+    fprintf(stderr, "[ws]  Minor code: %d\n", Event->minor_code);
+    fprintf(stderr, "[ws]  Modules: %s\n", current_module ? current_module : "(NULL)");
+    return 0;
 }
 
-void wsXInit( Display* mDisplay )
+void wsXInit(Display *mDisplay)
 {
- int    eventbase;
- int    errorbase;
+    int eventbase;
+    int errorbase;
 
- // NOTE TO MYSELF: Use global mDisplay, get rid of wsDisplay.
- wsDisplay=mDisplay;
+    // NOTE TO MYSELF: Use global mDisplay, get rid of wsDisplay.
+    wsDisplay = mDisplay;
 
- XSetErrorHandler( wsErrorHandler );
+    XSetErrorHandler(wsErrorHandler);
 
 /* enable DND atoms */
-wsXDNDInitialize();
+    wsXDNDInitialize();
+
+    { /* on remote display XShm will be disabled - LGB */
+        char *dispname = DisplayString(wsDisplay);
+        int localdisp  = 1;
 
-{ /* on remote display XShm will be disabled - LGB */
- char *dispname=DisplayString(wsDisplay);
- int localdisp=1;
- if (dispname&&*dispname!=':') {
-    localdisp=0;
-    wsUseXShm=0;
- }
- mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[ws] display name: %s => %s display.\n",dispname,localdisp?"local":"REMOTE");
- if (!localdisp) mp_msg( MSGT_GPLAYER,MSGL_V,MSGTR_WS_RemoteDisplay );
-}
+        if (dispname && *dispname != ':') {
+            localdisp = 0;
+            wsUseXShm = 0;
+        }
+
+        mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[ws] display name: %s => %s display.\n", dispname, localdisp ? "local" : "REMOTE");
 
- if ( !XShmQueryExtension( wsDisplay ) )
-  {
-   mp_msg( MSGT_GPLAYER,MSGL_ERR,MSGTR_WS_NoXshm );
-   wsUseXShm=0;
-  }
+        if (!localdisp)
+            mp_msg(MSGT_GPLAYER, MSGL_V, MSGTR_WS_RemoteDisplay);
+    }
+
+    if (!XShmQueryExtension(wsDisplay)) {
+        mp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_WS_NoXshm);
+        wsUseXShm = 0;
+    }
+
 #ifdef CONFIG_XSHAPE
-  if ( !XShapeQueryExtension( wsDisplay,&eventbase,&errorbase ) )
-   {
-    mp_msg( MSGT_GPLAYER,MSGL_ERR,MSGTR_WS_NoXshape );
-    wsUseXShape=0;
-   }
+
+    if (!XShapeQueryExtension(wsDisplay, &eventbase, &errorbase)) {
+        mp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_WS_NoXshape);
+        wsUseXShape = 0;
+    }
+
 #else
-  wsUseXShape=0;
+    wsUseXShape = 0;
 #endif
 
- XSynchronize( wsDisplay,True );
+    XSynchronize(wsDisplay, True);
 
- wsScreen=DefaultScreen( wsDisplay );
- wsRootWin=RootWindow( wsDisplay,wsScreen );
+    wsScreen  = DefaultScreen(wsDisplay);
+    wsRootWin = RootWindow(wsDisplay, wsScreen);
 #ifdef CONFIG_XF86VM
     {
-      int clock;
-      XF86VidModeModeLine modeline;
+        int clock;
+        XF86VidModeModeLine modeline;
 
-      XF86VidModeGetModeLine( wsDisplay,wsScreen,&clock ,&modeline );
-      wsMaxX=modeline.hdisplay;
-      wsMaxY=modeline.vdisplay;
+        XF86VidModeGetModeLine(wsDisplay, wsScreen, &clock, &modeline);
+        wsMaxX = modeline.hdisplay;
+        wsMaxY = modeline.vdisplay;
     }
 #endif
- {
- wsOrgX = wsOrgY = 0;
- if ( !wsMaxX )
- wsMaxX=DisplayWidth( wsDisplay,wsScreen );
- if ( !wsMaxY )
- wsMaxY=DisplayHeight( wsDisplay,wsScreen );
- }
-  vo_screenwidth = wsMaxX; vo_screenheight = wsMaxY;
-  xinerama_x = wsOrgX; xinerama_y = wsOrgY;
-  update_xinerama_info();
-  wsMaxX = vo_screenwidth; wsMaxY = vo_screenheight;
-  wsOrgX = xinerama_x; wsOrgY = xinerama_y;
+    {
+        wsOrgX = wsOrgY = 0;
 
- wsGetDepthOnScreen();
-#ifdef DEBUG
-  {
-   int minor,major,shp;
-   mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] Screen depth: %d\n",wsDepthOnScreen );
-   mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws]  size: %dx%d\n",wsMaxX,wsMaxY );
-#ifdef CONFIG_XINERAMA
-   mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws]  origin: +%d+%d\n",wsOrgX,wsOrgY );
-#endif
-   mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws]  red mask: 0x%x\n",wsRedMask );
-   mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws]  green mask: 0x%x\n",wsGreenMask );
-   mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws]  blue mask: 0x%x\n",wsBlueMask );
-   if ( wsUseXShm )
-    {
-     XShmQueryVersion( wsDisplay,&major,&minor,&shp );
-     mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] XShm version is %d.%d\n",major,minor );
+        if (!wsMaxX)
+            wsMaxX = DisplayWidth(wsDisplay, wsScreen);
+
+        if (!wsMaxY)
+            wsMaxY = DisplayHeight(wsDisplay, wsScreen);
     }
-   #ifdef CONFIG_XSHAPE
-    if ( wsUseXShape )
-     {
-      XShapeQueryVersion( wsDisplay,&major,&minor );
-      mp_msg( MSGT_GPLAYER,MSGL_DBG2,"[ws] XShape version is %d.%d\n",major,minor );
-     }
-   #endif
-  }
+    vo_screenwidth  = wsMaxX;
+    vo_screenheight = wsMaxY;
+    xinerama_x      = wsOrgX;
+    xinerama_y      = wsOrgY;
+    update_xinerama_info();
+    wsMaxX = vo_screenwidth;
+    wsMaxY = vo_screenheight;
+    wsOrgX = xinerama_x;
+    wsOrgY = xinerama_y;
+
+    wsGetDepthOnScreen();
+#ifdef DEBUG
+    {
+        int minor, major, shp;
+        mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] Screen depth: %d\n", wsDepthOnScreen);
+        mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws]  size: %dx%d\n", wsMaxX, wsMaxY);
+#ifdef CONFIG_XINERAMA
+        mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws]  origin: +%d+%d\n", wsOrgX, wsOrgY);
+#endif
+        mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws]  red mask: 0x%x\n", wsRedMask);
+        mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws]  green mask: 0x%x\n", wsGreenMask);
+        mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws]  blue mask: 0x%x\n", wsBlueMask);
+
+        if (wsUseXShm) {
+            XShmQueryVersion(wsDisplay, &major, &minor, &shp);
+            mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] XShm version is %d.%d\n", major, minor);
+        }
+
+#ifdef CONFIG_XSHAPE
+
+        if (wsUseXShape) {
+            XShapeQueryVersion(wsDisplay, &major, &minor);
+            mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[ws] XShape version is %d.%d\n", major, minor);
+        }
+
 #endif
- wsOutMask=wsGetOutMask();
- switch ( wsOutMask )
-  {
-   case wsRGB32:
-     out_pix_fmt = PIX_FMT_RGB32;
-     break;
-   case wsBGR32:
-     out_pix_fmt = PIX_FMT_BGR32;
-     break;
-   case wsRGB24:
-     out_pix_fmt = PIX_FMT_RGB24;
-     break;
-   case wsBGR24:
-     out_pix_fmt = PIX_FMT_BGR24;
-     break;
-   case wsRGB16:
-     out_pix_fmt = PIX_FMT_RGB565;
-     break;
-   case wsBGR16:
-     out_pix_fmt = PIX_FMT_BGR565;
-     break;
-   case wsRGB15:
-     out_pix_fmt = PIX_FMT_RGB555;
-     break;
-   case wsBGR15:
-     out_pix_fmt = PIX_FMT_BGR555;
-     break;
-  }
+    }
+#endif
+    wsOutMask = wsGetOutMask();
+
+    switch (wsOutMask) {
+    case wsRGB32:
+        out_pix_fmt = PIX_FMT_RGB32;
+        break;
+
+    case wsBGR32:
+        out_pix_fmt = PIX_FMT_BGR32;
+        break;
+
+    case wsRGB24:
+        out_pix_fmt = PIX_FMT_RGB24;
+        break;
+
+    case wsBGR24:
+        out_pix_fmt = PIX_FMT_BGR24;
+        break;
+
+    case wsRGB16:
+        out_pix_fmt = PIX_FMT_RGB565;
+        break;
+
+    case wsBGR16:
+        out_pix_fmt = PIX_FMT_BGR565;
+        break;
+
+    case wsRGB15:
+        out_pix_fmt = PIX_FMT_RGB555;
+        break;
+
+    case wsBGR15:
+        out_pix_fmt = PIX_FMT_BGR555;
+        break;
+    }
 }
 
 // ----------------------------------------------------------------------------------------------
@@ -329,202 +355,241 @@
 //     sR    : screen ratio
 // ----------------------------------------------------------------------------------------------
 
-XClassHint           wsClassHint;
-XTextProperty        wsTextProperty;
-Window               LeaderWindow;
+XClassHint wsClassHint;
+XTextProperty wsTextProperty;
+Window LeaderWindow;
 
-void wsCreateWindow( wsTWindow * win,int X,int Y,int wX,int hY,int bW,int cV,unsigned char D,char * label )
+void wsCreateWindow(wsTWindow *win, int X, int Y, int wX, int hY, int bW, int cV, unsigned char D, char *label)
 {
- int depth;
+    int depth;
+
+    win->Property = D;
 
- win->Property=D;
- if ( D & wsShowFrame ) win->Decorations=1;
- wsHGC=DefaultGC( wsDisplay,wsScreen );
+    if (D & wsShowFrame)
+        win->Decorations = 1;
+
+    wsHGC = DefaultGC(wsDisplay, wsScreen);
+
 // The window position and size.
- switch ( X )
-  {
-   case -1: win->X=( wsMaxX / 2 ) - ( wX / 2 ) + wsOrgX; break;
-   case -2: win->X=wsMaxX - wX - 1 + wsOrgX; break;
-   default: win->X=X; break;
-  }
- switch ( Y )
-  {
-   case -1: win->Y=( wsMaxY / 2 ) - ( hY / 2 ) + wsOrgY; break;
-   case -2: win->Y=wsMaxY - hY - 1 + wsOrgY; break;
-   default: win->Y=Y; break;
-  }
- win->Width=wX;
- win->Height=hY;
- win->OldX=win->X;
- win->OldY=win->Y;
- win->OldWidth=win->Width;
- win->OldHeight=win->Height;
+    switch (X) {
+    case -1:
+        win->X = (wsMaxX / 2) - (wX / 2) + wsOrgX;
+        break;
+
+    case -2:
+        win->X = wsMaxX - wX - 1 + wsOrgX;
+        break;
+
+    default:
+        win->X = X;
+        break;
+    }
+
+    switch (Y) {
+    case -1:
+        win->Y = (wsMaxY / 2) - (hY / 2) + wsOrgY;
+        break;
+
+    case -2:
+        win->Y = wsMaxY - hY - 1 + wsOrgY;
+        break;
+
+    default:
+        win->Y = Y;
+        break;
+    }
+
+    win->Width     = wX;
+    win->Height    = hY;
+    win->OldX      = win->X;
+    win->OldY      = win->Y;
+    win->OldWidth  = win->Width;
+    win->OldHeight = win->Height;
 
 // Border size for window.
- win->BorderWidth=bW;
+    win->BorderWidth = bW;
 // Hide Mouse Cursor
- win->wsCursor=None;
- win->wsMouseEventType=cV;
- win->wsCursorData[0]=0;
- 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 );
+    win->wsCursor = None;
+    win->wsMouseEventType = cV;
+    win->wsCursorData[0]  = 0;
+    win->wsCursorPixmap   = XCreateBitmapFromData(wsDisplay, wsRootWin, win->wsCursorData, 1, 1);
 
- depth = vo_find_depth_from_visuals( wsDisplay,wsScreen,NULL );
- if ( depth < 15 )
-  {
-   mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_WS_ColorDepthTooLow );
-   guiExit( EXIT_ERROR );
-  }
- XMatchVisualInfo( wsDisplay,wsScreen,depth,TrueColor,&win->VisualInfo );
+    if (!(cV & wsShowMouseCursor))
+        win->wsCursor = XCreatePixmapCursor(wsDisplay, win->wsCursorPixmap, win->wsCursorPixmap, &win->wsColor, &win->wsColor, 0, 0);
+
+    depth = vo_find_depth_from_visuals(wsDisplay, wsScreen, NULL);
+
+    if (depth < 15) {
+        mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ColorDepthTooLow);
+        guiExit(EXIT_ERROR);
+    }
+
+    XMatchVisualInfo(wsDisplay, wsScreen, depth, TrueColor, &win->VisualInfo);
 
 // ---
- win->AtomLeaderClient=XInternAtom( wsDisplay,"WM_CLIENT_LEADER",False );
- win->AtomDeleteWindow=XInternAtom( wsDisplay,"WM_DELETE_WINDOW",False );
- win->AtomTakeFocus=XInternAtom( wsDisplay,"WM_TAKE_FOCUS",False );
- win->AtomRolle=XInternAtom( wsDisplay,"WM_WINDOW_ROLE",False );
- win->AtomWMSizeHint=XInternAtom( wsDisplay,"WM_SIZE_HINT",False );
- win->AtomWMNormalHint=XInternAtom( wsDisplay,"WM_NORMAL_HINT",False );
- win->AtomProtocols=XInternAtom( wsDisplay,"WM_PROTOCOLS",False );
- win->AtomsProtocols[0]=win->AtomDeleteWindow;
- win->AtomsProtocols[1]=win->AtomTakeFocus;
- win->AtomsProtocols[2]=win->AtomRolle;
+    win->AtomLeaderClient = XInternAtom(wsDisplay, "WM_CLIENT_LEADER", False);
+    win->AtomDeleteWindow = XInternAtom(wsDisplay, "WM_DELETE_WINDOW", False);
+    win->AtomTakeFocus    = XInternAtom(wsDisplay, "WM_TAKE_FOCUS", False);
+    win->AtomRolle         = XInternAtom(wsDisplay, "WM_WINDOW_ROLE", False);
+    win->AtomWMSizeHint    = XInternAtom(wsDisplay, "WM_SIZE_HINT", False);
+    win->AtomWMNormalHint  = XInternAtom(wsDisplay, "WM_NORMAL_HINT", False);
+    win->AtomProtocols     = XInternAtom(wsDisplay, "WM_PROTOCOLS", False);
+    win->AtomsProtocols[0] = win->AtomDeleteWindow;
+    win->AtomsProtocols[1] = win->AtomTakeFocus;
+    win->AtomsProtocols[2] = win->AtomRolle;
 // ---
 
- win->WindowAttrib.background_pixel=BlackPixel( wsDisplay,wsScreen );
- win->WindowAttrib.border_pixel=WhitePixel( wsDisplay,wsScreen );
- win->WindowAttrib.colormap=XCreateColormap( wsDisplay,wsRootWin,win->VisualInfo.visual,AllocNone );
- win->WindowAttrib.event_mask=StructureNotifyMask | FocusChangeMask |
-                              ExposureMask | PropertyChangeMask |
-                              EnterWindowMask | LeaveWindowMask |
-                              VisibilityChangeMask |
-                              KeyPressMask | KeyReleaseMask;
- if ( ( cV & wsHandleMouseButton ) ) win->WindowAttrib.event_mask|=ButtonPressMask | ButtonReleaseMask;
- if ( ( cV & wsHandleMouseMove ) ) win->WindowAttrib.event_mask|=PointerMotionMask;
- win->WindowAttrib.cursor=win->wsCursor;
- win->WindowAttrib.override_redirect=False;
- if ( D & wsOverredirect ) win->WindowAttrib.override_redirect=True;
+    win->WindowAttrib.background_pixel = BlackPixel(wsDisplay, wsScreen);
+    win->WindowAttrib.border_pixel     = WhitePixel(wsDisplay, wsScreen);
+    win->WindowAttrib.colormap   = XCreateColormap(wsDisplay, wsRootWin, win->VisualInfo.visual, AllocNone);
+    win->WindowAttrib.event_mask = StructureNotifyMask | FocusChangeMask |
+                                   ExposureMask | PropertyChangeMask |
+                                   EnterWindowMask | LeaveWindowMask |
+                                   VisibilityChangeMask |
+                                   KeyPressMask | KeyReleaseMask;
 
- win->WindowMask=CWBackPixel | CWBorderPixel |
-                 CWColormap | CWEventMask | CWCursor |
-                 CWOverrideRedirect;
+    if ((cV & wsHandleMouseButton))
+        win->WindowAttrib.event_mask |= ButtonPressMask | ButtonReleaseMask;
+
+    if ((cV & wsHandleMouseMove))
+        win->WindowAttrib.event_mask |= PointerMotionMask;
+
+    win->WindowAttrib.cursor = win->wsCursor;
+    win->WindowAttrib.override_redirect = False;
+
+    if (D & wsOverredirect)
+        win->WindowAttrib.override_redirect = True;
 
- win->WindowID=XCreateWindow( wsDisplay,
-  (win->Parent != 0?win->Parent:wsRootWin),
-  win->X,win->Y,win->Width,win->Height,win->BorderWidth,
-  win->VisualInfo.depth,
-  InputOutput,
-  win->VisualInfo.visual,
-  win->WindowMask,&win->WindowAttrib );
+    win->WindowMask = CWBackPixel | CWBorderPixel |
+                      CWColormap | CWEventMask | CWCursor |
+                      CWOverrideRedirect;
 
- wsClassHint.res_name="MPlayer";
-
- wsClassHint.res_class="MPlayer";
- XSetClassHint( wsDisplay,win->WindowID,&wsClassHint );
+    win->WindowID = XCreateWindow(wsDisplay,
+                                  (win->Parent != 0 ? win->Parent : wsRootWin),
+                                  win->X, win->Y, win->Width, win->Height, win->BorderWidth,
+                                  win->VisualInfo.depth,
+                                  InputOutput,
+                                  win->VisualInfo.visual,
+                                  win->WindowMask, &win->WindowAttrib);
 
- win->SizeHint.flags=PPosition | PSize | PResizeInc | PWinGravity;// | PBaseSize;
- win->SizeHint.x=win->X;
- win->SizeHint.y=win->Y;
- win->SizeHint.width=win->Width;
- win->SizeHint.height=win->Height;
+    wsClassHint.res_name = "MPlayer";
+
+    wsClassHint.res_class = "MPlayer";
+    XSetClassHint(wsDisplay, win->WindowID, &wsClassHint);
+
+    win->SizeHint.flags  = PPosition | PSize | PResizeInc | PWinGravity; // | PBaseSize;
+    win->SizeHint.x      = win->X;
+    win->SizeHint.y      = win->Y;
+    win->SizeHint.width  = win->Width;
+    win->SizeHint.height = win->Height;
 
- if ( D & wsMinSize )
-  {
-   win->SizeHint.flags|=PMinSize;
-   win->SizeHint.min_width=win->Width;
-   win->SizeHint.min_height=win->Height;
-  }
- if ( D & wsMaxSize )
-  {
-   win->SizeHint.flags|=PMaxSize;
-   win->SizeHint.max_width=win->Width;
-   win->SizeHint.max_height=win->Height;
-  }
+    if (D & wsMinSize) {
+        win->SizeHint.flags     |= PMinSize;
+        win->SizeHint.min_width  = win->Width;
+        win->SizeHint.min_height = win->Height;
+    }
+
+    if (D & wsMaxSize) {
+        win->SizeHint.flags     |= PMaxSize;
+        win->SizeHint.max_width  = win->Width;
+        win->SizeHint.max_height = win->Height;
+    }
 
- win->SizeHint.height_inc=1;
- win->SizeHint.width_inc=1;
- win->SizeHint.base_width=win->Width;
- win->SizeHint.base_height=win->Height;
- win->SizeHint.win_gravity=StaticGravity;
- XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint );
+    win->SizeHint.height_inc  = 1;
+    win->SizeHint.width_inc   = 1;
+    win->SizeHint.base_width  = win->Width;
+    win->SizeHint.base_height = win->Height;
+    win->SizeHint.win_gravity = StaticGravity;
+    XSetWMNormalHints(wsDisplay, win->WindowID, &win->SizeHint);
 
- win->WMHints.flags=InputHint | StateHint;
- win->WMHints.input=True;
- win->WMHints.initial_state=NormalState;
- XSetWMHints( wsDisplay,win->WindowID,&win->WMHints );
+    win->WMHints.flags = InputHint | StateHint;
+    win->WMHints.input = True;
+    win->WMHints.initial_state = NormalState;
+    XSetWMHints(wsDisplay, win->WindowID, &win->WMHints);
 
- wsWindowDecoration( win,win->Decorations );
- XStoreName( wsDisplay,win->WindowID,label );
- XmbSetWMProperties( wsDisplay,win->WindowID,label,label,NULL,0,NULL,NULL,NULL );
+    wsWindowDecoration(win, win->Decorations);
+    XStoreName(wsDisplay, win->WindowID, label);
+    XmbSetWMProperties(wsDisplay, win->WindowID, label, label, NULL, 0, NULL, NULL, NULL);
 
- XSetWMProtocols( wsDisplay,win->WindowID,win->AtomsProtocols,3 );
- XChangeProperty( wsDisplay,win->WindowID,
-                  win->AtomLeaderClient,
-                  XA_WINDOW,32,PropModeReplace,
-                  (unsigned char *)&LeaderWindow,1 );
+    XSetWMProtocols(wsDisplay, win->WindowID, win->AtomsProtocols, 3);
+    XChangeProperty(wsDisplay, win->WindowID,
+                    win->AtomLeaderClient,
+                    XA_WINDOW, 32, PropModeReplace,
+                    (unsigned char *)&LeaderWindow, 1);
 
- wsTextProperty.value=label;
- wsTextProperty.encoding=XA_STRING;
- wsTextProperty.format=8;
- wsTextProperty.nitems=strlen( label );
- XSetWMIconName( wsDisplay,win->WindowID,&wsTextProperty );
+    wsTextProperty.value    = label;
+    wsTextProperty.encoding = XA_STRING;
+    wsTextProperty.format   = 8;
+    wsTextProperty.nitems   = strlen(label);
+    XSetWMIconName(wsDisplay, win->WindowID, &wsTextProperty);
+
+    win->wGC = XCreateGC(wsDisplay, win->WindowID,
+                         GCForeground | GCBackground,
+                         &win->wGCV);
 
- win->wGC=XCreateGC( wsDisplay,win->WindowID,
-  GCForeground | GCBackground,
-  &win->wGCV );
+    win->Visible = 0;
+    win->Focused = 0;
+    win->Mapped  = 0;
+    win->Rolled  = 0;
 
- win->Visible=0;
- win->Focused=0;
- win->Mapped=0;
- win->Rolled=0;
- if ( D & wsShowWindow ) XMapWindow( wsDisplay,win->WindowID );
+    if (D & wsShowWindow)
+        XMapWindow(wsDisplay, win->WindowID);
 
- wsCreateImage( win,win->Width,win->Height );
+    wsCreateImage(win, win->Width, win->Height);
 // --- End of creating --------------------------------------------------------------------------
 
- {
-  int i;
-  for ( i=0;i < wsWLCount;i++ )
-   if ( wsWindowList[i] == NULL ) break;
-  if ( i == wsWLCount )
-   {  mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_WS_TooManyOpenWindows ); guiExit( EXIT_ERROR ); }
-  wsWindowList[i]=win;
- }
+    {
+        int i;
+
+        for (i = 0; i < wsWLCount; i++)
+            if (wsWindowList[i] == NULL)
+                break;
+
+        if (i == wsWLCount) {
+            mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_TooManyOpenWindows);
+            guiExit(EXIT_ERROR);
+        }
 
- XFlush( wsDisplay );
- XSync( wsDisplay,False );
+        wsWindowList[i] = win;
+    }
+
+    XFlush(wsDisplay);
+    XSync(wsDisplay, False);
 
- win->ReDraw=NULL;
- win->ReSize=NULL;
- win->Idle=NULL;
- win->MouseHandler=NULL;
- win->KeyHandler=NULL;
- mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[ws] window is created. ( %s ).\n",label );
+    win->ReDraw       = NULL;
+    win->ReSize       = NULL;
+    win->Idle         = NULL;
+    win->MouseHandler = NULL;
+    win->KeyHandler   = NULL;
+    mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[ws] window is created. ( %s ).\n", label);
 }
 
-void wsDestroyWindow( wsTWindow * win )
+void wsDestroyWindow(wsTWindow *win)
 {
- int l;
- l=wsSearch( win->WindowID );
- wsWindowList[l]=NULL;
- if ( win->wsCursor != None )
-   {
-    XFreeCursor( wsDisplay,win->wsCursor );
-    win->wsCursor=None;
-   }
- XFreeGC( wsDisplay,win->wGC );
- XUnmapWindow( wsDisplay,win->WindowID );
- wsDestroyImage( win );
- XDestroyWindow( wsDisplay,win->WindowID );
+    int l;
+
+    l = wsSearch(win->WindowID);
+    wsWindowList[l] = NULL;
+
+    if (win->wsCursor != None) {
+        XFreeCursor(wsDisplay, win->wsCursor);
+        win->wsCursor = None;
+    }
+
+    XFreeGC(wsDisplay, win->wGC);
+    XUnmapWindow(wsDisplay, win->WindowID);
+    wsDestroyImage(win);
+    XDestroyWindow(wsDisplay, win->WindowID);
 #if 0
- win->ReDraw=NULL;
- win->ReSize=NULL;
- win->Idle=NULL;
- win->MouseHandler=NULL;
- win->KeyHandler=NULL;
- win->Visible=0;
- win->Focused=0;
- win->Mapped=0;
- win->Rolled=0;
+    win->ReDraw       = NULL;
+    win->ReSize       = NULL;
+    win->Idle         = NULL;
+    win->MouseHandler = NULL;
+    win->KeyHandler   = NULL;
+    win->Visible      = 0;
+    win->Focused      = 0;
+    win->Mapped       = 0;
+    win->Rolled       = 0;
 #endif
 }
 
@@ -532,182 +597,273 @@
 //   Handle events.
 // ----------------------------------------------------------------------------------------------
 
-Bool wsEvents( Display * display,XEvent * Event,XPointer arg )
+Bool wsEvents(Display *display, XEvent *Event, XPointer arg)
 {
- unsigned long i = 0;
- int           l;
- int           x,y;
- Window        child_window = 0;
+    unsigned long i = 0;
+    int l;
+    int x, y;
+    Window child_window = 0;
+
+    l = wsSearch(Event->xany.window);
+
+    if (l == -1)
+        return !wsTrue;
+
+    wsWindowList[l]->State = 0;
+
+    switch (Event->type) {
+    case ClientMessage:
 
- l=wsSearch( Event->xany.window );
- if ( l == -1 ) return !wsTrue;
- wsWindowList[l]->State=0;
- switch( Event->type )
-  {
-   case ClientMessage:
-        if ( Event->xclient.message_type == wsWindowList[l]->AtomProtocols )
-         {
-          if ( (Atom)Event->xclient.data.l[0] == wsWindowList[l]->AtomDeleteWindow )
-           { i=wsWindowClosed; goto expose; }
-          if ( (Atom)Event->xclient.data.l[0] == wsWindowList[l]->AtomTakeFocus )
-           { i=wsWindowFocusIn;  wsWindowList[l]->Focused=wsFocused; goto expose; }
-          if ( (Atom)Event->xclient.data.l[0] == wsWindowList[l]->AtomRolle )
-           { mp_msg( MSGT_GPLAYER,MSGL_V,"[ws] role set.\n" ); }
-         } else {
-	   /* try to process DND events */
-	   wsXDNDProcessClientMessage(wsWindowList[l],&Event->xclient);
-	 }
+        if (Event->xclient.message_type == wsWindowList[l]->AtomProtocols) {
+            if ((Atom)Event->xclient.data.l[0] == wsWindowList[l]->AtomDeleteWindow) {
+                i = wsWindowClosed;
+                goto expose;
+            }
+
+            if ((Atom)Event->xclient.data.l[0] == wsWindowList[l]->AtomTakeFocus) {
+                i = wsWindowFocusIn;
+                wsWindowList[l]->Focused = wsFocused;
+                goto expose;
+            }
+
+            if ((Atom)Event->xclient.data.l[0] == wsWindowList[l]->AtomRolle) {
+                mp_msg(MSGT_GPLAYER, MSGL_V, "[ws] role set.\n");
+            }
+        } else {
+            /* try to process DND events */
+            wsXDNDProcessClientMessage(wsWindowList[l], &Event->xclient);
+        }
+
         break;
 
-   case MapNotify:   i=wsWindowMapped;   wsWindowList[l]->Mapped=wsMapped;   goto expose;
-   case UnmapNotify: i=wsWindowUnmapped; wsWindowList[l]->Mapped=wsNone;     goto expose;
-   case FocusIn:
-        if ( wsWindowList[l]->Focused == wsFocused ) break;
-        i=wsWindowFocusIn;
-        wsWindowList[l]->Focused=wsFocused;
+    case MapNotify:
+        i = wsWindowMapped;
+        wsWindowList[l]->Mapped = wsMapped;
+        goto expose;
+
+    case UnmapNotify:
+        i = wsWindowUnmapped;
+        wsWindowList[l]->Mapped = wsNone;
+        goto expose;
+
+    case FocusIn:
+
+        if (wsWindowList[l]->Focused == wsFocused)
+            break;
+
+        i = wsWindowFocusIn;
+        wsWindowList[l]->Focused = wsFocused;
+        goto expose;
+
+    case FocusOut:
+
+        if (wsWindowList[l]->Focused == wsNone)
+            break;
+
+        i = wsWindowFocusOut;
+        wsWindowList[l]->Focused = wsNone;
         goto expose;
-   case FocusOut:
-        if ( wsWindowList[l]->Focused == wsNone ) break;
-        i=wsWindowFocusOut;
-        wsWindowList[l]->Focused=wsNone;
-        goto expose;
-   case VisibilityNotify:
-        switch( Event->xvisibility.state )
-         {
-          case VisibilityUnobscured:        i=wsWindowVisible;        wsWindowList[l]->Visible=wsVisible;    goto expose;
-          case VisibilityFullyObscured:     i=wsWindowNotVisible;     wsWindowList[l]->Visible=wsNotVisible; goto expose;
-          case VisibilityPartiallyObscured: i=wsWindowPartialVisible; wsWindowList[l]->Visible=wsPVisible;   goto expose;
-         }
+
+    case VisibilityNotify:
+
+        switch (Event->xvisibility.state) {
+        case VisibilityUnobscured:
+            i = wsWindowVisible;
+            wsWindowList[l]->Visible = wsVisible;
+            goto expose;
+
+        case VisibilityFullyObscured:
+            i = wsWindowNotVisible;
+            wsWindowList[l]->Visible = wsNotVisible;
+            goto expose;
+
+        case VisibilityPartiallyObscured:
+            i = wsWindowPartialVisible;
+            wsWindowList[l]->Visible = wsPVisible;
+            goto expose;
+        }
+
 expose:
-        wsWindowList[l]->State=i;
-        if ( wsWindowList[l]->ReDraw ) wsWindowList[l]->ReDraw();
+        wsWindowList[l]->State = i;
+
+        if (wsWindowList[l]->ReDraw)
+            wsWindowList[l]->ReDraw();
+
         break;
 
-   case Expose:
-        wsWindowList[l]->State=wsWindowExpose;
-        if ( ( wsWindowList[l]->ReDraw )&&( !Event->xexpose.count ) ) wsWindowList[l]->ReDraw();
+    case Expose:
+        wsWindowList[l]->State = wsWindowExpose;
+
+        if ((wsWindowList[l]->ReDraw) && (!Event->xexpose.count))
+            wsWindowList[l]->ReDraw();
+
         break;
 
-   case ConfigureNotify:
-        XTranslateCoordinates( wsDisplay,wsWindowList[l]->WindowID,wsRootWin,0,0,&x,&y,&child_window );
-        if ( ( wsWindowList[l]->X != x )||( wsWindowList[l]->Y != y )||( wsWindowList[l]->Width != Event->xconfigure.width )||( wsWindowList[l]->Height != Event->xconfigure.height ) )
-          {
-           wsWindowList[l]->X=x; wsWindowList[l]->Y=y;
-           wsWindowList[l]->Width=Event->xconfigure.width; wsWindowList[l]->Height=Event->xconfigure.height;
-           if ( wsWindowList[l]->ReSize ) wsWindowList[l]->ReSize( wsWindowList[l]->X,wsWindowList[l]->Y,wsWindowList[l]->Width,wsWindowList[l]->Height );
-          }
+    case ConfigureNotify:
+        XTranslateCoordinates(wsDisplay, wsWindowList[l]->WindowID, wsRootWin, 0, 0, &x, &y, &child_window);
+
+        if ((wsWindowList[l]->X != x) || (wsWindowList[l]->Y != y) || (wsWindowList[l]->Width != Event->xconfigure.width) || (wsWindowList[l]->Height != Event->xconfigure.height)) {
+            wsWindowList[l]->X      = x;
+            wsWindowList[l]->Y      = y;
+            wsWindowList[l]->Width  = Event->xconfigure.width;
+            wsWindowList[l]->Height = Event->xconfigure.height;
 
-        wsWindowList[l]->Rolled=wsNone;
-        if ( Event->xconfigure.y < 0 )
-          { i=wsWindowRolled; wsWindowList[l]->Rolled=wsRolled; goto expose; }
+            if (wsWindowList[l]->ReSize)
+                wsWindowList[l]->ReSize(wsWindowList[l]->X, wsWindowList[l]->Y, wsWindowList[l]->Width, wsWindowList[l]->Height);
+        }
+
+        wsWindowList[l]->Rolled = wsNone;
+
+        if (Event->xconfigure.y < 0) {
+            i = wsWindowRolled;
+            wsWindowList[l]->Rolled = wsRolled;
+            goto expose;
+        }
 
         break;
 
-   case KeyPress:   i=wsKeyPressed;  goto keypressed;
-   case KeyRelease: i=wsKeyReleased;
+    case KeyPress:
+        i = wsKeyPressed;
+        goto keypressed;
+
+    case KeyRelease:
+        i = wsKeyReleased;
 keypressed:
-        wsWindowList[l]->Alt=0;
-        wsWindowList[l]->Shift=0;
-        wsWindowList[l]->NumLock=0;
-        wsWindowList[l]->Control=0;
-        wsWindowList[l]->CapsLock=0;
-        if ( Event->xkey.state & Mod1Mask ) wsWindowList[l]->Alt=1;
-        if ( Event->xkey.state & Mod2Mask ) wsWindowList[l]->NumLock=1;
-        if ( Event->xkey.state & ControlMask ) wsWindowList[l]->Control=1;
-        if ( Event->xkey.state & ShiftMask ) wsWindowList[l]->Shift=1;
-        if ( Event->xkey.state & LockMask ) wsWindowList[l]->CapsLock=1;
+        wsWindowList[l]->Alt      = 0;
+        wsWindowList[l]->Shift    = 0;
+        wsWindowList[l]->NumLock  = 0;
+        wsWindowList[l]->Control  = 0;
+        wsWindowList[l]->CapsLock = 0;
+
+        if (Event->xkey.state & Mod1Mask)
+            wsWindowList[l]->Alt = 1;
+
+        if (Event->xkey.state & Mod2Mask)
+            wsWindowList[l]->NumLock = 1;
+
+        if (Event->xkey.state & ControlMask)
+            wsWindowList[l]->Control = 1;
+
+        if (Event->xkey.state & ShiftMask)
+            wsWindowList[l]->Shift = 1;
+
+        if (Event->xkey.state & LockMask)
+            wsWindowList[l]->CapsLock = 1;
+
 #if 0
         {
-	 KeySym        keySym;
-         keySym=XKeycodeToKeysym( wsDisplay,Event->xkey.keycode,0 );
-         if ( keySym != NoSymbol )
-          {
-           keySym=( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) );
-           wsKeyTable[ keySym ]=i;
-           if ( wsWindowList[l]->KeyHandler )
-             wsWindowList[l]->KeyHandler( Event->xkey.state,i,keySym );
-          }
-	}
+            KeySym keySym;
+            keySym = XKeycodeToKeysym(wsDisplay, Event->xkey.keycode, 0);
+
+            if (keySym != NoSymbol) {
+                keySym = ((keySym & 0xff00) != 0 ? ((keySym & 0x00ff) + 256) : (keySym));
+                wsKeyTable[keySym] = i;
+
+                if (wsWindowList[l]->KeyHandler)
+                    wsWindowList[l]->KeyHandler(Event->xkey.state, i, keySym);
+            }
+        }
 #else
-	{
-        	int    		key;
-		char   		buf[100];
-		KeySym 		keySym;
-	 static XComposeStatus  stat;
+        {
+            int key;
+            char buf[100];
+            KeySym keySym;
+            static XComposeStatus stat;
 
-	 XLookupString( &Event->xkey,buf,sizeof(buf),&keySym,&stat );
-	 key=( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) );
-	 wsKeyTable[ key ]=i;
-	 if ( wsWindowList[l]->KeyHandler ) wsWindowList[l]->KeyHandler( Event->xkey.keycode,i,key );
-	}
+            XLookupString(&Event->xkey, buf, sizeof(buf), &keySym, &stat);
+            key = ((keySym & 0xff00) != 0 ? ((keySym & 0x00ff) + 256) : (keySym));
+            wsKeyTable[key] = i;
+
+            if (wsWindowList[l]->KeyHandler)
+                wsWindowList[l]->KeyHandler(Event->xkey.keycode, i, key);
+        }
 #endif
         break;
 
-   case MotionNotify:
-     i=wsMoveMouse;
-     {
-       /* pump all motion events from the display queue:
-	  this way it works faster when moving the window */
-      static XEvent e;
-      if ( Event->xmotion.state )
-       {
-        while(XCheckTypedWindowEvent(display,Event->xany.window,MotionNotify,&e)){
-	 /* FIXME: need to make sure we didn't release/press the button in between...*/
-	 /* FIXME: do we need some timeout here to make sure we don't spend too much time
-	    removing events from the queue? */
-	 Event = &e;
+    case MotionNotify:
+        i = wsMoveMouse;
+        {
+            /* pump all motion events from the display queue:
+             * this way it works faster when moving the window */
+            static XEvent e;
+
+            if (Event->xmotion.state) {
+                while (XCheckTypedWindowEvent(display, Event->xany.window, MotionNotify, &e)) {
+                    /* FIXME: need to make sure we didn't release/press the button in between...*/
+                    /* FIXME: do we need some timeout here to make sure we don't spend too much time
+                     * removing events from the queue? */
+                    Event = &e;
+                }
+            }
         }
-       }
-     }
-     goto buttonreleased;
-   case ButtonRelease: i=Event->xbutton.button + 128; goto buttonreleased;
-   case ButtonPress:   i=Event->xbutton.button;       goto buttonreleased;
-   case EnterNotify:   i=wsEnterWindow;               goto buttonreleased;
-   case LeaveNotify:   i=wsLeaveWindow;
+        goto buttonreleased;
+
+    case ButtonRelease:
+        i = Event->xbutton.button + 128;
+        goto buttonreleased;
+
+    case ButtonPress:
+        i = Event->xbutton.button;
+        goto buttonreleased;
+
+    case EnterNotify:
+        i = wsEnterWindow;
+        goto buttonreleased;
+
+    case LeaveNotify:
+        i = wsLeaveWindow;
 buttonreleased:
-        if ( wsWindowList[l]->MouseHandler )
-          wsWindowList[l]->MouseHandler( i,Event->xbutton.x,Event->xbutton.y,Event->xmotion.x_root,Event->xmotion.y_root );
+
+        if (wsWindowList[l]->MouseHandler)
+            wsWindowList[l]->MouseHandler(i, Event->xbutton.x, Event->xbutton.y, Event->xmotion.x_root, Event->xmotion.y_root);
+
         break;
 
-   case SelectionNotify:
-     /* Handle DandD */
-     wsXDNDProcessSelection(wsWindowList[l],Event);
-     break;
-  }
- XFlush( wsDisplay );
- XSync( wsDisplay,False );
- return !wsTrue;
+    case SelectionNotify:
+        /* Handle DandD */
+        wsXDNDProcessSelection(wsWindowList[l], Event);
+        break;
+    }
+
+    XFlush(wsDisplay);
+    XSync(wsDisplay, False);
+    return !wsTrue;
 }
 
-void wsHandleEvents( void ){
- // handle pending events
- while ( XPending(wsDisplay) ){
-   XNextEvent( wsDisplay,&wsEvent );
+void wsHandleEvents(void)
+{
+    // handle pending events
+    while (XPending(wsDisplay)) {
+        XNextEvent(wsDisplay, &wsEvent);
 //   printf("### X event: %d  [%d]\n",wsEvent.type,delay);
-   wsEvents( wsDisplay,&wsEvent,NULL );
- }
+        wsEvents(wsDisplay, &wsEvent, NULL);
+    }
 }
 
-void wsMainLoop( void )
+void wsMainLoop(void)
 {
- int delay=20;
- mp_msg( MSGT_GPLAYER,MSGL_V,"[ws] init threads: %d\n",XInitThreads() );
- XSynchronize( wsDisplay,False );
- XLockDisplay( wsDisplay );
+    int delay = 20;
+
+    mp_msg(MSGT_GPLAYER, MSGL_V, "[ws] init threads: %d\n", XInitThreads());
+    XSynchronize(wsDisplay, False);
+    XLockDisplay(wsDisplay);
 // XIfEvent( wsDisplay,&wsEvent,wsEvents,NULL );
 
-while(wsTrue){
- // handle pending events
- while ( XPending(wsDisplay) ){
-   XNextEvent( wsDisplay,&wsEvent );
-   wsEvents( wsDisplay,&wsEvent,NULL );
-   delay=0;
- }
- usleep(delay*1000); // FIXME!
- if(delay<10*20) delay+=20; // pump up delay up to 0.2 sec (low activity)
-}
+    while (wsTrue) {
+        // handle pending events
+        while (XPending(wsDisplay)) {
+            XNextEvent(wsDisplay, &wsEvent);
+            wsEvents(wsDisplay, &wsEvent, NULL);
+            delay = 0;
+        }
 
- XUnlockDisplay( wsDisplay );
+        usleep(delay * 1000); // FIXME!
+
+        if (delay < 10 * 20)
+            delay += 20;               // pump up delay up to 0.2 sec (low activity)
+    }
+
+    XUnlockDisplay(wsDisplay);
 }
 
 // ----------------------------------------------------------------------------------------------
@@ -718,557 +874,682 @@
 #define WIN_LAYER_NORMAL                 4
 #define WIN_LAYER_ONTOP                 10
 
-void wsSetLayer( Display * wsDisplay, Window win, int layer )
-{ vo_x11_setlayer( wsDisplay,win,layer ); }
+void wsSetLayer(Display *wsDisplay, Window win, int layer)
+{
+    vo_x11_setlayer(wsDisplay, win, layer);
+}
 
 // ----------------------------------------------------------------------------------------------
 //    Switch to fullscreen.
 // ----------------------------------------------------------------------------------------------
-void wsFullScreen( wsTWindow * win )
+void wsFullScreen(wsTWindow *win)
 {
- int decoration = 0;
+    int decoration = 0;
+
+    if (win->isFullScreen) {
+        vo_x11_ewmh_fullscreen(_NET_WM_STATE_REMOVE); // removes fullscreen state if wm supports EWMH
 
- if ( win->isFullScreen )
-  {
-   vo_x11_ewmh_fullscreen( _NET_WM_STATE_REMOVE ); // removes fullscreen state if wm supports EWMH
-   if ( ! (vo_fs_type & vo_wm_FULLSCREEN) ) // shouldn't be needed with EWMH fs
-    {
-     win->X=win->OldX;
-     win->Y=win->OldY;
-     win->Width=win->OldWidth;
-     win->Height=win->OldHeight;
-     decoration=win->Decorations;
-    }
+        if (!(vo_fs_type & vo_wm_FULLSCREEN)) { // shouldn't be needed with EWMH fs
+            win->X      = win->OldX;
+            win->Y      = win->OldY;
+            win->Width  = win->OldWidth;
+            win->Height = win->OldHeight;
+            decoration  = win->Decorations;
+        }
 
 #ifdef ENABLE_DPMS
-   wsScreenSaverOn( wsDisplay );
+        wsScreenSaverOn(wsDisplay);
 #endif
 
-   win->isFullScreen=False;
-  }
-  else
-   {
-    if ( ! (vo_fs_type & vo_wm_FULLSCREEN) ) // shouldn't be needed with EWMH fs
-     {
-      win->OldX=win->X; win->OldY=win->Y;
-      win->OldWidth=win->Width; win->OldHeight=win->Height;
-      vo_dx = win->X; vo_dy = win->Y;
-      vo_dwidth = win->Width; vo_dheight = win->Height;
-      vo_screenwidth = wsMaxX; vo_screenheight = wsMaxY;
-      xinerama_x = wsOrgX; xinerama_y = wsOrgY;
-      update_xinerama_info();
-      wsMaxX = vo_screenwidth; wsMaxY = vo_screenheight;
-      wsOrgX = xinerama_x; wsOrgY = xinerama_y;
-      win->X=wsOrgX; win->Y=wsOrgY;
-      win->Width=wsMaxX; win->Height=wsMaxY;
-     }
+        win->isFullScreen = False;
+    } else {
+        if (!(vo_fs_type & vo_wm_FULLSCREEN)) { // shouldn't be needed with EWMH fs
+            win->OldX      = win->X;
+            win->OldY      = win->Y;
+            win->OldWidth  = win->Width;
+            win->OldHeight = win->Height;
+            vo_dx           = win->X;
+            vo_dy           = win->Y;
+            vo_dwidth       = win->Width;
+            vo_dheight      = win->Height;
+            vo_screenwidth  = wsMaxX;
+            vo_screenheight = wsMaxY;
+            xinerama_x      = wsOrgX;
+            xinerama_y      = wsOrgY;
+            update_xinerama_info();
+            wsMaxX      = vo_screenwidth;
+            wsMaxY      = vo_screenheight;
+            wsOrgX      = xinerama_x;
+            wsOrgY      = xinerama_y;
+            win->X      = wsOrgX;
+            win->Y      = wsOrgY;
+            win->Width  = wsMaxX;
+            win->Height = wsMaxY;
+        }
 
-    win->isFullScreen=True;
+        win->isFullScreen = True;
 #ifdef ENABLE_DPMS
-    wsScreenSaverOff( wsDisplay );
+        wsScreenSaverOff(wsDisplay);
 #endif
 
-     vo_x11_ewmh_fullscreen( _NET_WM_STATE_ADD ); // adds fullscreen state if wm supports EWMH
-   }
+        vo_x11_ewmh_fullscreen(_NET_WM_STATE_ADD); // adds fullscreen state if wm supports EWMH
+    }
 
-  if ( ! (vo_fs_type & vo_wm_FULLSCREEN) ) // shouldn't be needed with EWMH fs
-   {
-    vo_x11_decoration( wsDisplay,win->WindowID,decoration );
-    vo_x11_sizehint( win->X,win->Y,win->Width,win->Height,0 );
-    vo_x11_setlayer( wsDisplay,win->WindowID,win->isFullScreen );
+    if (!(vo_fs_type & vo_wm_FULLSCREEN)) { // shouldn't be needed with EWMH fs
+        vo_x11_decoration(wsDisplay, win->WindowID, decoration);
+        vo_x11_sizehint(win->X, win->Y, win->Width, win->Height, 0);
+        vo_x11_setlayer(wsDisplay, win->WindowID, win->isFullScreen);
 
-    if ((!(win->isFullScreen)) & vo_ontop) vo_x11_setlayer(wsDisplay, win->WindowID,1);
+        if ((!(win->isFullScreen)) & vo_ontop)
+            vo_x11_setlayer(wsDisplay, win->WindowID, 1);
 
-    XMoveResizeWindow( wsDisplay,win->WindowID,win->X,win->Y,win->Width,win->Height );
-   }
+        XMoveResizeWindow(wsDisplay, win->WindowID, win->X, win->Y, win->Width, win->Height);
+    }
 
- if ( vo_wm_type == 0 && !(vo_fsmode&16) )
-  {
-   XWithdrawWindow( wsDisplay,win->WindowID,wsScreen );
-  }
+    if (vo_wm_type == 0 && !(vo_fsmode & 16)) {
+        XWithdrawWindow(wsDisplay, win->WindowID, wsScreen);
+    }
 
-
- XMapRaised( wsDisplay,win->WindowID );
- XRaiseWindow( wsDisplay,win->WindowID );
- XFlush( wsDisplay );
+    XMapRaised(wsDisplay, win->WindowID);
+    XRaiseWindow(wsDisplay, win->WindowID);
+    XFlush(wsDisplay);
 }
 
 // ----------------------------------------------------------------------------------------------
 //    Redraw screen.
 // ----------------------------------------------------------------------------------------------
-void wsPostRedisplay( wsTWindow * win )
+void wsPostRedisplay(wsTWindow *win)
 {
- if ( win->ReDraw )
-  {
-   win->State=wsWindowExpose;
-   win->ReDraw();
-   XFlush( wsDisplay );
-  }
+    if (win->ReDraw) {
+        win->State = wsWindowExpose;
+        win->ReDraw();
+        XFlush(wsDisplay);
+    }
 }
 
 // ----------------------------------------------------------------------------------------------
 //    Do Exit.
 // ----------------------------------------------------------------------------------------------
-void wsDoExit( void )
-{ wsTrue=False; wsResizeWindow( wsWindowList[0],32,32 ); }
+void wsDoExit(void)
+{
+    wsTrue = False;
+    wsResizeWindow(wsWindowList[0], 32, 32);
+}
 
 // ----------------------------------------------------------------------------------------------
 //    Put 'Image' to window.
 // ----------------------------------------------------------------------------------------------
-void wsConvert( wsTWindow * win,unsigned char * Image,unsigned int Size )
+void wsConvert(wsTWindow *win, unsigned char *Image, unsigned int Size)
 {
-  const uint8_t *src[4] = { Image, NULL, NULL, NULL };
-  int src_stride[4] = { 4 * win->xImage->width, 0, 0, 0 };
-  uint8_t *dst[4] = { win->ImageData, NULL, NULL, NULL };
-  int dst_stride[4];
-  int i;
-  sws_ctx = sws_getCachedContext(sws_ctx, win->xImage->width, win->xImage->height, PIX_FMT_RGB32,
-                                          win->xImage->width, win->xImage->height, out_pix_fmt,
-                                          SWS_POINT, NULL, NULL, NULL);
-  av_image_fill_linesizes(dst_stride, out_pix_fmt, win->xImage->width);
-  sws_scale(sws_ctx, src, src_stride, 0, win->xImage->height, dst, dst_stride);
-  if (!wsNonNativeOrder) return;
-  switch (win->xImage->bits_per_pixel) {
+    const uint8_t *src[4] = { Image, NULL, NULL, NULL };
+    int src_stride[4]     = { 4 * win->xImage->width, 0, 0, 0 };
+    uint8_t *dst[4]       = { win->ImageData, NULL, NULL, NULL };
+    int dst_stride[4];
+    int i;
+
+    sws_ctx = sws_getCachedContext(sws_ctx, win->xImage->width, win->xImage->height, PIX_FMT_RGB32,
+                                   win->xImage->width, win->xImage->height, out_pix_fmt,
+                                   SWS_POINT, NULL, NULL, NULL);
+    av_image_fill_linesizes(dst_stride, out_pix_fmt, win->xImage->width);
+    sws_scale(sws_ctx, src, src_stride, 0, win->xImage->height, dst, dst_stride);
+
+    if (!wsNonNativeOrder)
+        return;
+
+    switch (win->xImage->bits_per_pixel) {
     case 32:
     {
-      uint32_t *d = (uint32_t *) win->ImageData;
-      for (i = 0; i < win->xImage->width * win->xImage->height; i++)
-        d[i] = bswap_32(d[i]);
-      break;
+        uint32_t *d = (uint32_t *)win->ImageData;
+
+        for (i = 0; i < win->xImage->width * win->xImage->height; i++)
+            d[i] = bswap_32(d[i]);
+
+        break;
     }
+
     case 16:
     case 15:
     {
-      uint16_t *d = (uint16_t *) win->ImageData;
-      for (i = 0; i < win->xImage->width * win->xImage->height; i++)
-        d[i] = bswap_16(d[i]);
-      break;
+        uint16_t *d = (uint16_t *)win->ImageData;
+
+        for (i = 0; i < win->xImage->width * win->xImage->height; i++)
+            d[i] = bswap_16(d[i]);
+
+        break;
     }
-  }
+    }
 }
 
-void wsPutImage( wsTWindow * win )
+void wsPutImage(wsTWindow *win)
 {
- if ( wsUseXShm )
-  {
-   XShmPutImage( wsDisplay,win->WindowID,win->wGC,win->xImage,
-    0,0,
-    ( win->Width - win->xImage->width ) / 2,( win->Height - win->xImage->height ) / 2,
-    win->xImage->width,win->xImage->height,0 );
-  }
-  else
-   {
-    XPutImage( wsDisplay,win->WindowID,win->wGC,win->xImage,
-    0,0,
-    ( win->Width - win->xImage->width ) / 2,( win->Height - win->xImage->height ) / 2,
-    win->xImage->width,win->xImage->height );
-   }
+    if (wsUseXShm) {
+        XShmPutImage(wsDisplay, win->WindowID, win->wGC, win->xImage,
+                     0, 0,
+                     (win->Width - win->xImage->width) / 2, (win->Height - win->xImage->height) / 2,
+                     win->xImage->width, win->xImage->height, 0);
+    } else {
+        XPutImage(wsDisplay, win->WindowID, win->wGC, win->xImage,
+                  0, 0,
+                  (win->Width - win->xImage->width) / 2, (win->Height - win->xImage->height) / 2,
+                  win->xImage->width, win->xImage->height);
+    }
 }
 
 // ----------------------------------------------------------------------------------------------
 //    Move window to x, y.
 // ----------------------------------------------------------------------------------------------
-void wsMoveWindow( wsTWindow * win,int b,int x, int y )
+void wsMoveWindow(wsTWindow *win, int b, int x, int y)
 {
- if ( b )
-  {
-   switch ( x )
-    {
-     case -1: win->X=( wsMaxX / 2 ) - ( win->Width / 2 ) + wsOrgX; break;
-     case -2: win->X=wsMaxX - win->Width + wsOrgX; break;
-     default: win->X=x; break;
+    if (b) {
+        switch (x) {
+        case -1:
+            win->X = (wsMaxX / 2) - (win->Width / 2) + wsOrgX;
+            break;
+
+        case -2:
+            win->X = wsMaxX - win->Width + wsOrgX;
+            break;
+
+        default:
+            win->X = x;
+            break;
+        }
+
+        switch (y) {
+        case -1:
+            win->Y = (wsMaxY / 2) - (win->Height / 2) + wsOrgY;
+            break;
+
+        case -2:
+            win->Y = wsMaxY - win->Height + wsOrgY;
+            break;
+
+        default:
+            win->Y = y;
+            break;
+        }
+    } else {
+        win->X = x;
+        win->Y = y;
     }
-   switch ( y )
-    {
-     case -1: win->Y=( wsMaxY / 2 ) - ( win->Height / 2 ) + wsOrgY; break;
-     case -2: win->Y=wsMaxY - win->Height + wsOrgY; break;
-     default: win->Y=y; break;
-    }
-  }
-  else { win->X=x; win->Y=y; }
 
- win->SizeHint.flags=PPosition | PWinGravity;
- win->SizeHint.x=win->X;
- win->SizeHint.y=win->Y;
- win->SizeHint.win_gravity=StaticGravity;
- XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint );
+    win->SizeHint.flags       = PPosition | PWinGravity;
+    win->SizeHint.x           = win->X;
+    win->SizeHint.y           = win->Y;
+    win->SizeHint.win_gravity = StaticGravity;
+    XSetWMNormalHints(wsDisplay, win->WindowID, &win->SizeHint);
 
- XMoveWindow( wsDisplay,win->WindowID,win->X,win->Y );
- if ( win->ReSize ) win->ReSize( win->X,win->Y,win->Width,win->Height );
+    XMoveWindow(wsDisplay, win->WindowID, win->X, win->Y);
+
+    if (win->ReSize)
+        win->ReSize(win->X, win->Y, win->Width, win->Height);
 }
 
 // ----------------------------------------------------------------------------------------------
 //    Resize window to sx, sy.
 // ----------------------------------------------------------------------------------------------
-void wsResizeWindow( wsTWindow * win,int sx, int sy )
+void wsResizeWindow(wsTWindow *win, int sx, int sy)
 {
- win->Width=sx;
- win->Height=sy;
+    win->Width  = sx;
+    win->Height = sy;
 
- win->SizeHint.flags=PPosition | PSize | PWinGravity;// | PBaseSize;
- win->SizeHint.x=win->X;
- win->SizeHint.y=win->Y;
- win->SizeHint.width=win->Width;
- win->SizeHint.height=win->Height;
+    win->SizeHint.flags  = PPosition | PSize | PWinGravity; // | PBaseSize;
+    win->SizeHint.x      = win->X;
+    win->SizeHint.y      = win->Y;
+    win->SizeHint.width  = win->Width;
+    win->SizeHint.height = win->Height;
+
+    if (win->Property & wsMinSize) {
+        win->SizeHint.flags     |= PMinSize;
+        win->SizeHint.min_width  = win->Width;
+        win->SizeHint.min_height = win->Height;
+    }
 
- if ( win->Property & wsMinSize )
-  {
-   win->SizeHint.flags|=PMinSize;
-   win->SizeHint.min_width=win->Width;
-   win->SizeHint.min_height=win->Height;
-  }
- if ( win->Property & wsMaxSize )
-  {
-   win->SizeHint.flags|=PMaxSize;
-   win->SizeHint.max_width=win->Width;
-   win->SizeHint.max_height=win->Height;
-  }
+    if (win->Property & wsMaxSize) {
+        win->SizeHint.flags     |= PMaxSize;
+        win->SizeHint.max_width  = win->Width;
+        win->SizeHint.max_height = win->Height;
+    }
+
+    win->SizeHint.win_gravity = StaticGravity;
+    win->SizeHint.base_width  = sx;
+    win->SizeHint.base_height = sy;
 
- win->SizeHint.win_gravity=StaticGravity;
- win->SizeHint.base_width=sx; win->SizeHint.base_height=sy;
-
- if ( vo_wm_type == 0 ) XUnmapWindow( wsDisplay,win->WindowID );
+    if (vo_wm_type == 0)
+        XUnmapWindow(wsDisplay, win->WindowID);
 
- XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint );
- XResizeWindow( wsDisplay,win->WindowID,sx,sy );
- XMapRaised( wsDisplay,win->WindowID );
- if ( win->ReSize ) win->ReSize( win->X,win->Y,win->Width,win->Height );
+    XSetWMNormalHints(wsDisplay, win->WindowID, &win->SizeHint);
+    XResizeWindow(wsDisplay, win->WindowID, sx, sy);
+    XMapRaised(wsDisplay, win->WindowID);
+
+    if (win->ReSize)
+        win->ReSize(win->X, win->Y, win->Width, win->Height);
 }
 
 // ----------------------------------------------------------------------------------------------
 //    Iconify window.
 // ----------------------------------------------------------------------------------------------
-void wsIconify( wsTWindow win )
-{ XIconifyWindow( wsDisplay,win.WindowID,0 ); }
+void wsIconify(wsTWindow win)
+{
+    XIconifyWindow(wsDisplay, win.WindowID, 0);
+}
 
 // ----------------------------------------------------------------------------------------------
 //    Move top the window.
 // ----------------------------------------------------------------------------------------------
-void wsMoveTopWindow( Display * wsDisplay,Window win )
+void wsMoveTopWindow(Display *wsDisplay, Window win)
 {
 // XUnmapWindow( wsDisplay,win );
 // XMapWindow( wsDisplay,win );
- XMapRaised( wsDisplay,win );
- XRaiseWindow( wsDisplay,win );
+    XMapRaised(wsDisplay, win);
+    XRaiseWindow(wsDisplay, win);
 }
 
 // ----------------------------------------------------------------------------------------------
 //    Set window background to 'color'.
 // ----------------------------------------------------------------------------------------------
-void wsSetBackground( wsTWindow * win,int color )
-{ XSetWindowBackground( wsDisplay,win->WindowID,color ); }
-
-void wsSetBackgroundRGB( wsTWindow * win,int r,int g,int b )
+void wsSetBackground(wsTWindow *win, int color)
 {
- int color = 0;
- switch ( wsOutMask )
-  {
-   case wsRGB32:
-   case wsRGB24: color=( r << 16 ) + ( g << 8 ) + b;  break;
-   case wsBGR32:
-   case wsBGR24: color=( b << 16 ) + ( g << 8 ) + r;  break;
-   case wsRGB16: PACK_RGB16( b,g,r,color ); break;
-   case wsBGR16: PACK_RGB16( r,g,b,color ); break;
-   case wsRGB15: PACK_RGB15( b,g,r,color ); break;
-   case wsBGR15: PACK_RGB15( r,g,b,color ); break;
-  }
- XSetWindowBackground( wsDisplay,win->WindowID,color );
+    XSetWindowBackground(wsDisplay, win->WindowID, color);
 }
 
-void wsSetForegroundRGB( wsTWindow * win,int r,int g,int b )
+void wsSetBackgroundRGB(wsTWindow *win, int r, int g, int b)
 {
- int color = 0;
- switch ( wsOutMask )
-  {
-   case wsRGB32:
-   case wsRGB24: color=( r << 16 ) + ( g << 8 ) + b;  break;
-   case wsBGR32:
-   case wsBGR24: color=( b << 16 ) + ( g << 8 ) + r;  break;
-   case wsRGB16: PACK_RGB16( b,g,r,color ); break;
-   case wsBGR16: PACK_RGB16( r,g,b,color ); break;
-   case wsRGB15: PACK_RGB15( b,g,r,color ); break;
-   case wsBGR15: PACK_RGB15( r,g,b,color ); break;
-  }
- XSetForeground( wsDisplay,win->wGC,color );
+    int color = 0;
+
+    switch (wsOutMask) {
+    case wsRGB32:
+    case wsRGB24:
+        color = (r << 16) + (g << 8) + b;
+        break;
+
+    case wsBGR32:
+    case wsBGR24:
+        color = (b << 16) + (g << 8) + r;
+        break;
+
+    case wsRGB16:
+        PACK_RGB16(b, g, r, color);
+        break;
+
+    case wsBGR16:
+        PACK_RGB16(r, g, b, color);
+        break;
+
+    case wsRGB15:
+        PACK_RGB15(b, g, r, color);
+        break;
+
+    case wsBGR15:
+        PACK_RGB15(r, g, b, color);
+        break;
+    }
+
+    XSetWindowBackground(wsDisplay, win->WindowID, color);
+}
+
+void wsSetForegroundRGB(wsTWindow *win, int r, int g, int b)
+{
+    int color = 0;
+
+    switch (wsOutMask) {
+    case wsRGB32:
+    case wsRGB24:
+        color = (r << 16) + (g << 8) + b;
+        break;
+
+    case wsBGR32:
+    case wsBGR24:
+        color = (b << 16) + (g << 8) + r;
+        break;
+
+    case wsRGB16:
+        PACK_RGB16(b, g, r, color);
+        break;
+
+    case wsBGR16:
+        PACK_RGB16(r, g, b, color);
+        break;
+
+    case wsRGB15:
+        PACK_RGB15(b, g, r, color);
+        break;
+
+    case wsBGR15:
+        PACK_RGB15(r, g, b, color);
+        break;
+    }
+
+    XSetForeground(wsDisplay, win->wGC, color);
 }
 
 // ----------------------------------------------------------------------------------------------
 //    Draw string at x,y with fc ( foreground color ) and bc ( background color ).
 // ----------------------------------------------------------------------------------------------
-void wsDrawString( wsTWindow win,int x,int y,char * str,int fc,int bc )
+void wsDrawString(wsTWindow win, int x, int y, char *str, int fc, int bc)
 {
- XSetForeground( wsDisplay,win.wGC,bc );
- XFillRectangle( wsDisplay,win.WindowID,win.wGC,x,y,
-   XTextWidth( win.Font,str,strlen( str ) ) + 20,
-   win.FontHeight + 2 );
- XSetForeground( wsDisplay,win.wGC,fc );
- XDrawString( wsDisplay,win.WindowID,win.wGC,x + 10,y + 13,str,strlen( str ) );
+    XSetForeground(wsDisplay, win.wGC, bc);
+    XFillRectangle(wsDisplay, win.WindowID, win.wGC, x, y,
+                   XTextWidth(win.Font, str, strlen(str)) + 20,
+                   win.FontHeight + 2);
+    XSetForeground(wsDisplay, win.wGC, fc);
+    XDrawString(wsDisplay, win.WindowID, win.wGC, x + 10, y + 13, str, strlen(str));
 }
 
 // ----------------------------------------------------------------------------------------------
 //    Calculation string width.
 // ----------------------------------------------------------------------------------------------
-int wsTextWidth( wsTWindow win,char * str )
-{ return XTextWidth( win.Font,str,strlen( str ) ) + 20; }
+int wsTextWidth(wsTWindow win, char *str)
+{
+    return XTextWidth(win.Font, str, strlen(str)) + 20;
+}
 
 // ----------------------------------------------------------------------------------------------
 //    Show / hide mouse cursor.
 // ----------------------------------------------------------------------------------------------
-void wsVisibleMouse( wsTWindow * win,int m )
+void wsVisibleMouse(wsTWindow *win, int m)
 {
- switch ( m )
-  {
-   case wsShowMouseCursor:
-    if ( win->wsCursor != None )
-     {
-      XFreeCursor( wsDisplay,win->wsCursor );
-      win->wsCursor=None;
-     }
-    XDefineCursor( wsDisplay,win->WindowID,0 );
-    break;
-   case wsHideMouseCursor:
-    win->wsCursor=XCreatePixmapCursor( wsDisplay,win->wsCursorPixmap,win->wsCursorPixmap,&win->wsColor,&win->wsColor,0,0 );
-    XDefineCursor( wsDisplay,win->WindowID,win->wsCursor );
-    break;
-  }
- XFlush( wsDisplay );
+    switch (m) {
+    case wsShowMouseCursor:
+
+        if (win->wsCursor != None) {
+            XFreeCursor(wsDisplay, win->wsCursor);
+            win->wsCursor = None;
+        }
+
+        XDefineCursor(wsDisplay, win->WindowID, 0);
+        break;
+
+    case wsHideMouseCursor:
+        win->wsCursor = XCreatePixmapCursor(wsDisplay, win->wsCursorPixmap, win->wsCursorPixmap, &win->wsColor, &win->wsColor, 0, 0);
+        XDefineCursor(wsDisplay, win->WindowID, win->wsCursor);
+        break;
+    }
+
+    XFlush(wsDisplay);
 }
 
-int wsGetDepthOnScreen( void )
+int wsGetDepthOnScreen(void)
 {
- int depth;
- XImage * mXImage;
- Visual * visual;
+    int depth;
+    XImage *mXImage;
+    Visual *visual;
 
- 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;
+    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;
 #if HAVE_BIGENDIAN
-   wsNonNativeOrder = mXImage->byte_order == LSBFirst;
+        wsNonNativeOrder = mXImage->byte_order == LSBFirst;
 #else
-   wsNonNativeOrder = mXImage->byte_order == MSBFirst;
+        wsNonNativeOrder = mXImage->byte_order == MSBFirst;
 #endif
-   XDestroyImage( mXImage );
-  }
- else
-  {
-   int                 bpp,ibpp;
-   XWindowAttributes   attribs;
+        XDestroyImage(mXImage);
+    } else {
+        int bpp, ibpp;
+        XWindowAttributes attribs;
 
-   mXImage=XGetImage( wsDisplay,wsRootWin,0,0,1,1,AllPlanes,ZPixmap );
-   bpp=mXImage->bits_per_pixel;
+        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;
+        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 )
+void wsXDone(void)
 {
- XCloseDisplay( wsDisplay );
+    XCloseDisplay(wsDisplay);
 }
 
-void wsVisibleWindow( wsTWindow * win,int show )
+void wsVisibleWindow(wsTWindow *win, int show)
 {
- switch( show )
-  {
-   case wsShowWindow: XMapRaised( wsDisplay,win->WindowID ); break;
-   case wsHideWindow: XUnmapWindow( wsDisplay,win->WindowID ); break;
-  }
- XFlush( wsDisplay );
+    switch (show) {
+    case wsShowWindow:
+        XMapRaised(wsDisplay, win->WindowID);
+        break;
+
+    case wsHideWindow:
+        XUnmapWindow(wsDisplay, win->WindowID);
+        break;
+    }
+
+    XFlush(wsDisplay);
 }
 
-void wsDestroyImage( wsTWindow * win )
+void wsDestroyImage(wsTWindow *win)
 {
- if ( win->xImage )
-  {
-   XDestroyImage( win->xImage );
-   if ( wsUseXShm )
-    {
-     XShmDetach( wsDisplay,&win->Shminfo );
-     shmdt( win->Shminfo.shmaddr );
+    if (win->xImage) {
+        XDestroyImage(win->xImage);
+
+        if (wsUseXShm) {
+            XShmDetach(wsDisplay, &win->Shminfo);
+            shmdt(win->Shminfo.shmaddr);
+        }
     }
-  }
- win->xImage=NULL;
+
+    win->xImage = NULL;
 }
 
-void wsCreateImage( wsTWindow * win,int Width,int Height )
+void wsCreateImage(wsTWindow *win, int Width, int Height)
 {
- if ( wsUseXShm )
-  {
-   win->xImage=XShmCreateImage( wsDisplay,win->VisualInfo.visual,
-                   win->VisualInfo.depth,ZPixmap,NULL,&win->Shminfo,Width,Height );
-   if ( win->xImage == NULL )
-    {
-     mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_WS_ShmError );
-     guiExit( EXIT_ERROR );
-    }
-   win->Shminfo.shmid=shmget( IPC_PRIVATE,win->xImage->bytes_per_line * win->xImage->height,IPC_CREAT|0777 );
-   if ( win->Shminfo.shmid < 0 )
-    {
-     XDestroyImage( win->xImage );
-     mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_WS_ShmError );
-     guiExit( EXIT_ERROR );
-    }
-   win->Shminfo.shmaddr=(char *)shmat( win->Shminfo.shmid,0,0 );
+    if (wsUseXShm) {
+        win->xImage = XShmCreateImage(wsDisplay, win->VisualInfo.visual,
+                                      win->VisualInfo.depth, ZPixmap, NULL, &win->Shminfo, Width, Height);
+
+        if (win->xImage == NULL) {
+            mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError);
+            guiExit(EXIT_ERROR);
+        }
+
+        win->Shminfo.shmid = shmget(IPC_PRIVATE, win->xImage->bytes_per_line * win->xImage->height, IPC_CREAT | 0777);
+
+        if (win->Shminfo.shmid < 0) {
+            XDestroyImage(win->xImage);
+            mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError);
+            guiExit(EXIT_ERROR);
+        }
+
+        win->Shminfo.shmaddr = (char *)shmat(win->Shminfo.shmid, 0, 0);
+
+        if (win->Shminfo.shmaddr == ((char *)-1)) {
+            XDestroyImage(win->xImage);
 
-   if ( win->Shminfo.shmaddr == ((char *) -1) )
-    {
-     XDestroyImage( win->xImage );
-     if ( win->Shminfo.shmaddr != ((char *) -1) ) shmdt( win->Shminfo.shmaddr );
-     mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_WS_ShmError );
-     guiExit( EXIT_ERROR );
+            if (win->Shminfo.shmaddr != ((char *)-1))
+                shmdt(win->Shminfo.shmaddr);
+
+            mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_ShmError);
+            guiExit(EXIT_ERROR);
+        }
+
+        win->xImage->data     = win->Shminfo.shmaddr;
+        win->Shminfo.readOnly = 0;
+        XShmAttach(wsDisplay, &win->Shminfo);
+        XSync(wsDisplay, False);
+        shmctl(win->Shminfo.shmid, IPC_RMID, 0);
+    } else {
+        win->xImage = XCreateImage(wsDisplay, win->VisualInfo.visual, win->VisualInfo.depth,
+                                   ZPixmap, 0, 0, Width, Height,
+                                   (wsDepthOnScreen == 3) ? 32 : wsDepthOnScreen,
+                                   0);
+
+        if ((win->xImage->data = malloc(win->xImage->bytes_per_line * win->xImage->height)) == NULL) {
+            mp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_WS_NotEnoughMemoryDrawBuffer);
+            guiExit(EXIT_ERROR);
+        }
     }
-   win->xImage->data=win->Shminfo.shmaddr;
-   win->Shminfo.readOnly=0;
-   XShmAttach( wsDisplay,&win->Shminfo );
-   XSync(wsDisplay, False);
-   shmctl( win->Shminfo.shmid,IPC_RMID,0 );
-  }
-  else
-   {
-    win->xImage=XCreateImage( wsDisplay,win->VisualInfo.visual,win->VisualInfo.depth,
-                              ZPixmap,0,0,Width,Height,
-                              (wsDepthOnScreen == 3) ? 32 : wsDepthOnScreen,
-                              0 );
-    if ( ( win->xImage->data=malloc( win->xImage->bytes_per_line * win->xImage->height ) ) == NULL )
-     {
-      mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_WS_NotEnoughMemoryDrawBuffer );
-      guiExit( EXIT_ERROR );
-     }
-   }
- win->ImageData=(unsigned char *)win->xImage->data;
- win->ImageDataw=(unsigned short int *)win->xImage->data;
- win->ImageDatadw=(unsigned int *)win->xImage->data;
+
+    win->ImageData   = (unsigned char *)win->xImage->data;
+    win->ImageDataw  = (unsigned short int *)win->xImage->data;
+    win->ImageDatadw = (unsigned int *)win->xImage->data;
 }
 
-void wsResizeImage( wsTWindow * win,int Width,int Height )
-{ wsDestroyImage( win ); wsCreateImage( win,Width,Height ); }
+void wsResizeImage(wsTWindow *win, int Width, int Height)
+{
+    wsDestroyImage(win);
+    wsCreateImage(win, Width, Height);
+}
 
-int wsGetOutMask( void )
+int wsGetOutMask(void)
 {
- if ( ( wsDepthOnScreen == 32 )&&( wsRedMask == 0xff0000 )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0x0000ff ) ) return wsRGB32;
- if ( ( wsDepthOnScreen == 32 )&&( wsRedMask == 0x0000ff )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0xff0000 ) ) return wsBGR32;
- if ( ( wsDepthOnScreen == 24 )&&( wsRedMask == 0xff0000 )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0x0000ff ) ) return wsRGB24;
- if ( ( wsDepthOnScreen == 24 )&&( wsRedMask == 0x0000ff )&&( wsGreenMask == 0x00ff00 )&&( wsBlueMask == 0xff0000 ) ) return wsBGR24;
- if ( ( wsDepthOnScreen == 16 )&&( wsRedMask == 0xf800 )&&( wsGreenMask == 0x7e0 )&&( wsBlueMask ==   0x1f ) ) return wsRGB16;
- if ( ( wsDepthOnScreen == 16 )&&( wsRedMask ==   0x1f )&&( wsGreenMask == 0x7e0 )&&( wsBlueMask == 0xf800 ) ) return wsBGR16;
- if ( ( wsDepthOnScreen == 15 )&&( wsRedMask == 0x7c00 )&&( wsGreenMask == 0x3e0 )&&( wsBlueMask ==   0x1f ) ) return wsRGB15;
- if ( ( wsDepthOnScreen == 15 )&&( wsRedMask ==   0x1f )&&( wsGreenMask == 0x3e0 )&&( wsBlueMask == 0x7c00 ) ) return wsBGR15;
- return 0;
+    if ((wsDepthOnScreen == 32) && (wsRedMask == 0xff0000) && (wsGreenMask == 0x00ff00) && (wsBlueMask == 0x0000ff))
+        return wsRGB32;
+
+    if ((wsDepthOnScreen == 32) && (wsRedMask == 0x0000ff) && (wsGreenMask == 0x00ff00) && (wsBlueMask == 0xff0000))
+        return wsBGR32;
+
+    if ((wsDepthOnScreen == 24) && (wsRedMask == 0xff0000) && (wsGreenMask == 0x00ff00) && (wsBlueMask == 0x0000ff))
+        return wsRGB24;
+
+    if ((wsDepthOnScreen == 24) && (wsRedMask == 0x0000ff) && (wsGreenMask == 0x00ff00) && (wsBlueMask == 0xff0000))
+        return wsBGR24;
+
+    if ((wsDepthOnScreen == 16) && (wsRedMask == 0xf800) && (wsGreenMask == 0x7e0) && (wsBlueMask == 0x1f))
+        return wsRGB16;
+
+    if ((wsDepthOnScreen == 16) && (wsRedMask == 0x1f) && (wsGreenMask == 0x7e0) && (wsBlueMask == 0xf800))
+        return wsBGR16;
+
+    if ((wsDepthOnScreen == 15) && (wsRedMask == 0x7c00) && (wsGreenMask == 0x3e0) && (wsBlueMask == 0x1f))
+        return wsRGB15;
+
+    if ((wsDepthOnScreen == 15) && (wsRedMask == 0x1f) && (wsGreenMask == 0x3e0) && (wsBlueMask == 0x7c00))
+        return wsBGR15;
+
+    return 0;
 }
 
-void wsSetTitle( wsTWindow * win,char * name )
-{ XStoreName( wsDisplay,win->WindowID,name ); }
+void wsSetTitle(wsTWindow *win, char *name)
+{
+    XStoreName(wsDisplay, win->WindowID, name);
+}
 
-void wsSetMousePosition( wsTWindow * win,int x, int y )
-{ XWarpPointer( wsDisplay,wsRootWin,win->WindowID,0,0,0,0,x,y ); }
+void wsSetMousePosition(wsTWindow *win, int x, int y)
+{
+    XWarpPointer(wsDisplay, wsRootWin, win->WindowID, 0, 0, 0, 0, x, y);
+}
 
 #ifdef ENABLE_DPMS
-static int dpms_disabled=0;
-static int timeout_save=0;
+static int dpms_disabled = 0;
+static int timeout_save  = 0;
 
-void wsScreenSaverOn( Display *mDisplay )
+void wsScreenSaverOn(Display *mDisplay)
 {
- int nothing;
+    int nothing;
+
 #ifdef CONFIG_XDPMS
- if ( dpms_disabled )
-  {
-   if ( DPMSQueryExtension( mDisplay,&nothing,&nothing ) )
-    {
-     if ( !DPMSEnable( mDisplay ) ) mp_msg( MSGT_GPLAYER,MSGL_ERR,MSGTR_WS_DpmsUnavailable ); // restoring power saving settings
-      else
-       {
-        // DPMS does not seem to be enabled unless we call DPMSInfo
+
+    if (dpms_disabled) {
+        if (DPMSQueryExtension(mDisplay, &nothing, &nothing)) {
+            if (!DPMSEnable(mDisplay))
+                mp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_WS_DpmsUnavailable);                     // restoring power saving settings
+            else {
+                // DPMS does not seem to be enabled unless we call DPMSInfo
+                BOOL onoff;
+                CARD16 state;
+                DPMSInfo(mDisplay, &state, &onoff);
+
+                if (onoff)
+                    mp_msg(MSGT_GPLAYER, MSGL_V, "Successfully enabled DPMS.\n");
+                else
+                    mp_msg(MSGT_GPLAYER, MSGL_STATUS, MSGTR_WS_DpmsNotEnabled);
+            }
+        }
+    }
+
+#endif
+
+    if (timeout_save) {
+        int dummy, interval, prefer_blank, allow_exp;
+        XGetScreenSaver(mDisplay, &dummy, &interval, &prefer_blank, &allow_exp);
+        XSetScreenSaver(mDisplay, timeout_save, interval, prefer_blank, allow_exp);
+        XGetScreenSaver(mDisplay, &timeout_save, &interval, &prefer_blank, &allow_exp);
+    }
+}
+
+void wsScreenSaverOff(Display *mDisplay)
+{
+    int interval, prefer_blank, allow_exp, nothing;
+
+#ifdef CONFIG_XDPMS
+
+    if (DPMSQueryExtension(mDisplay, &nothing, &nothing)) {
         BOOL onoff;
         CARD16 state;
-        DPMSInfo( mDisplay,&state,&onoff );
-        if ( onoff ) mp_msg( MSGT_GPLAYER,MSGL_V,"Successfully enabled DPMS.\n" );
-         else mp_msg( MSGT_GPLAYER,MSGL_STATUS,MSGTR_WS_DpmsNotEnabled );
-       }
+        DPMSInfo(mDisplay, &state, &onoff);
+
+        if (onoff) {
+            Status stat;
+            mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "Disabling DPMS.\n");
+            dpms_disabled = 1;
+            stat = DPMSDisable(mDisplay); // monitor powersave off
+            mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "stat: %d.\n", stat);
+        }
     }
-  }
+
 #endif
- if ( timeout_save )
-  {
-   int dummy, interval, prefer_blank, allow_exp;
-   XGetScreenSaver( mDisplay,&dummy,&interval,&prefer_blank,&allow_exp );
-   XSetScreenSaver( mDisplay,timeout_save,interval,prefer_blank,allow_exp );
-   XGetScreenSaver( mDisplay,&timeout_save,&interval,&prefer_blank,&allow_exp );
-  }
+    XGetScreenSaver(mDisplay, &timeout_save, &interval, &prefer_blank, &allow_exp);
+
+    if (timeout_save)
+        XSetScreenSaver(mDisplay, 0, interval, prefer_blank, allow_exp);              // turning off screensaver
 }
 
-void wsScreenSaverOff( Display * mDisplay )
-{
- int interval,prefer_blank,allow_exp,nothing;
-#ifdef CONFIG_XDPMS
- if ( DPMSQueryExtension( mDisplay,&nothing,&nothing ) )
-  {
-   BOOL onoff;
-   CARD16 state;
-   DPMSInfo( mDisplay,&state,&onoff );
-   if ( onoff )
-    {
-      Status stat;
-      mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"Disabling DPMS.\n" );
-      dpms_disabled=1;
-      stat=DPMSDisable( mDisplay );  // monitor powersave off
-      mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"stat: %d.\n",stat );
-   }
-  }
-#endif
- XGetScreenSaver( mDisplay,&timeout_save,&interval,&prefer_blank,&allow_exp );
- if ( timeout_save ) XSetScreenSaver( mDisplay,0,interval,prefer_blank,allow_exp ); // turning off screensaver
-}
 #endif
 
-void wsSetShape( wsTWindow * win,char * data )
+void wsSetShape(wsTWindow *win, char *data)
 {
 #ifdef CONFIG_XSHAPE
- if ( !wsUseXShape ) return;
- if ( data )
-  {
-   win->Mask=XCreateBitmapFromData( wsDisplay,win->WindowID,data,win->Width,win->Height );
-   XShapeCombineMask( wsDisplay,win->WindowID,ShapeBounding,0,0,win->Mask,ShapeSet );
-   XFreePixmap( wsDisplay,win->Mask );
-  }
-  else XShapeCombineMask( wsDisplay,win->WindowID,ShapeBounding,0,0,None,ShapeSet );
+
+    if (!wsUseXShape)
+        return;
+
+    if (data) {
+        win->Mask = XCreateBitmapFromData(wsDisplay, win->WindowID, data, win->Width, win->Height);
+        XShapeCombineMask(wsDisplay, win->WindowID, ShapeBounding, 0, 0, win->Mask, ShapeSet);
+        XFreePixmap(wsDisplay, win->Mask);
+    } else
+        XShapeCombineMask(wsDisplay, win->WindowID, ShapeBounding, 0, 0, None, ShapeSet);
+
 #endif
 }
 
-void wsSetIcon( Display * dsp,Window win,guiIcon_t * icon )
+void wsSetIcon(Display *dsp, Window win, guiIcon_t *icon)
 {
- XWMHints * wm;
- CARD32     data[2];
- Atom	    iconatom;
+    XWMHints *wm;
+    CARD32 data[2];
+    Atom iconatom;
 
- wm=XGetWMHints( dsp,win );
- if ( !wm ) wm=XAllocWMHints();
+    wm = XGetWMHints(dsp, win);
+
+    if (!wm)
+        wm = XAllocWMHints();
 
- wm->icon_pixmap=icon->normal;
- wm->icon_mask=icon->normal_mask;
- wm->flags|=IconPixmapHint | IconMaskHint;
+    wm->icon_pixmap = icon->normal;
+    wm->icon_mask   = icon->normal_mask;
+    wm->flags      |= IconPixmapHint | IconMaskHint;
 
- XSetWMHints( dsp,win,wm );
+    XSetWMHints(dsp, win, wm);
 
- data[0]=icon->normal;
- data[1]=icon->normal_mask;
- iconatom=XInternAtom( dsp,"KWM_WIN_ICON",0 );
- XChangeProperty( dsp,win,iconatom,iconatom,32,PropModeReplace,(unsigned char *)data,2 );
+    data[0]  = icon->normal;
+    data[1]  = icon->normal_mask;
+    iconatom = XInternAtom(dsp, "KWM_WIN_ICON", 0);
+    XChangeProperty(dsp, win, iconatom, iconatom, 32, PropModeReplace, (unsigned char *)data, 2);
 
- XFree( wm );
+    XFree(wm);
 }
--- a/gui/wm/ws.h	Thu Jun 16 12:30:24 2011 +0000
+++ b/gui/wm/ws.h	Thu Jun 16 12:31:42 2011 +0000
@@ -36,10 +36,10 @@
 #define  wsKeyReleased   0
 #define  wsKeyPressed    1
 
-#define  wsShift        (1L<<0)
-#define  wsLock         (1L<<1)
-#define  wsCtrl         (1L<<2)
-#define  wsAlt          (1L<<3)
+#define  wsShift        (1L << 0)
+#define  wsLock         (1L << 1)
+#define  wsCtrl         (1L << 2)
+#define  wsAlt          (1L << 3)
 
 #define  wsPLMouseButton 1
 #define  wsPMMouseButton 2
@@ -110,115 +110,114 @@
 #define wsWMIceWM    3
 #define wsWMWMaker   4
 
-typedef   void (*wsTReDraw)( void );
-typedef   void (*wsTReSize)( unsigned int X,unsigned int Y,unsigned int width,unsigned int height );
-typedef   void (*wsTIdle)( void );
-typedef   void (*wsTKeyHandler)( int KeyCode,int Type,int Key );
-typedef   void (*wsTMouseHandler)( int Button,int X,int Y,int RX,int RY  );
-typedef   void (*wsTDNDHandler)( int num,char ** str );
+typedef   void (*wsTReDraw)(void);
+typedef   void (*wsTReSize)(unsigned int X, unsigned int Y, unsigned int width, unsigned int height);
+typedef   void (*wsTIdle)(void);
+typedef   void (*wsTKeyHandler)(int KeyCode, int Type, int Key);
+typedef   void (*wsTMouseHandler)(int Button, int X, int Y, int RX, int RY);
+typedef   void (*wsTDNDHandler)(int num, char **str);
 
-typedef struct
-{
- Window               WindowID;
- Window               Parent;
- int                  X,Y,Width,Height;
- int                  OldX,OldY,OldWidth,OldHeight;
- int                  MaxX,MaxY;
- int                  isFullScreen;
- int                  BorderWidth;
- int                  Property;
- unsigned char *      bImage;
- XImage        *      xImage;
- Pixmap               Mask;
- int                  Decorations;
+typedef struct {
+    Window WindowID;
+    Window Parent;
+    int X, Y, Width, Height;
+    int OldX, OldY, OldWidth, OldHeight;
+    int MaxX, MaxY;
+    int isFullScreen;
+    int BorderWidth;
+    int Property;
+    unsigned char *bImage;
+    XImage *xImage;
+    Pixmap Mask;
+    int Decorations;
 
- int                  State;
- int                  Visible;
- int                  Mapped;
- int                  Focused;
- int                  Rolled;
+    int State;
+    int Visible;
+    int Mapped;
+    int Focused;
+    int Rolled;
 
- wsTReDraw            ReDraw;
- wsTReSize            ReSize;
- wsTIdle              Idle;
- wsTKeyHandler        KeyHandler;
- wsTMouseHandler      MouseHandler;
- wsTDNDHandler        DandDHandler;
+    wsTReDraw ReDraw;
+    wsTReSize ReSize;
+    wsTIdle Idle;
+    wsTKeyHandler KeyHandler;
+    wsTMouseHandler MouseHandler;
+    wsTDNDHandler DandDHandler;
 
- int                  Alt;
- int                  Shift;
- int                  Control;
- int                  NumLock;
- int                  CapsLock;
+    int Alt;
+    int Shift;
+    int Control;
+    int NumLock;
+    int CapsLock;
 // --- Misc -------------------------------------------------------------------------------------
 
- Atom                 AtomDeleteWindow;
- Atom                 AtomTakeFocus;
- Atom                 AtomRolle;
- Atom                 AtomProtocols;
- Atom                 AtomsProtocols[3];
- Atom                 AtomLeaderClient;
- Atom                 AtomRemote;
- Atom		      AtomWMSizeHint;
- Atom		      AtomWMNormalHint;
+    Atom AtomDeleteWindow;
+    Atom AtomTakeFocus;
+    Atom AtomRolle;
+    Atom AtomProtocols;
+    Atom AtomsProtocols[3];
+    Atom AtomLeaderClient;
+    Atom AtomRemote;
+    Atom AtomWMSizeHint;
+    Atom AtomWMNormalHint;
 
- XShmSegmentInfo      Shminfo;
- unsigned char      * ImageData;
- unsigned short int * ImageDataw;
- unsigned int       * ImageDatadw;
- GC                   wGC;
- XGCValues            wGCV;
- unsigned long        WindowMask;
- XVisualInfo          VisualInfo;
- XSetWindowAttributes WindowAttrib;
- XSizeHints           SizeHint;
- XWMHints             WMHints;
+    XShmSegmentInfo Shminfo;
+    unsigned char *ImageData;
+    unsigned short int *ImageDataw;
+    unsigned int *ImageDatadw;
+    GC wGC;
+    XGCValues wGCV;
+    unsigned long WindowMask;
+    XVisualInfo VisualInfo;
+    XSetWindowAttributes WindowAttrib;
+    XSizeHints SizeHint;
+    XWMHints WMHints;
 
- XFontStruct        * Font;
- int                  FontHeight;
+    XFontStruct *Font;
+    int FontHeight;
 
- Cursor               wsCursor;
- char                 wsCursorData[1];
- Pixmap               wsCursorPixmap;
- int                  wsMouseEventType;
- XColor               wsColor;
+    Cursor wsCursor;
+    char wsCursorData[1];
+    Pixmap wsCursorPixmap;
+    int wsMouseEventType;
+    XColor wsColor;
 } wsTWindow;
 
-extern int                  wsMaxX;
-extern int                  wsMaxY;
-extern int                  wsOrgX;
-extern int                  wsOrgY;
+extern int wsMaxX;
+extern int wsMaxY;
+extern int wsOrgX;
+extern int wsOrgY;
 
-extern Display            * wsDisplay;
-extern int                  wsScreen;
-extern Window               wsRootWin;
-extern int		    wsLayer;
+extern Display *wsDisplay;
+extern int wsScreen;
+extern Window wsRootWin;
+extern int wsLayer;
 
-extern unsigned char      * wsImageData;
+extern unsigned char *wsImageData;
 
-extern XEvent               wsEvent;
+extern XEvent wsEvent;
 
-extern int                  wsDepthOnScreen;
-extern int                  wsRedMask;
-extern int                  wsGreenMask;
-extern int                  wsBlueMask;
+extern int wsDepthOnScreen;
+extern int wsRedMask;
+extern int wsGreenMask;
+extern int wsBlueMask;
 
-extern int                  wsUseXShm;
+extern int wsUseXShm;
 
 // ----------------------------------------------------------------------------------------------
 //  wsKeyTable
 // ----------------------------------------------------------------------------------------------
-extern unsigned long        wsKeyTable[512];
+extern unsigned long wsKeyTable[512];
 
-void wsXDone( void );
-void wsXInit( Display* disp );
+void wsXDone(void);
+void wsXInit(Display *disp);
 
-int wsGetDepthOnScreen( void );
+int wsGetDepthOnScreen(void);
 
-void wsDoExit( void );
-void wsMainLoop( void );
-Bool wsEvents( Display * display, XEvent * Event, XPointer arg );
-void wsHandleEvents( void );
+void wsDoExit(void);
+void wsMainLoop(void);
+Bool wsEvents(Display *display, XEvent *Event, XPointer arg);
+void wsHandleEvents(void);
 
 // ----------------------------------------------------------------------------------------------
 //  wsCrateWindow: create a new window on the screen.
@@ -228,50 +227,50 @@
 //   cV    : mouse cursor visible
 //   D     : "decoration", visible titlebar, etc ...
 // ----------------------------------------------------------------------------------------------
-void wsCreateWindow( wsTWindow * win, int X, int Y, int wX, int hY, int bW, int cV, unsigned char D, char * label );
-void wsDestroyWindow( wsTWindow * win );
-void wsMoveWindow( wsTWindow * win, int b, int x, int y );
-void wsResizeWindow( wsTWindow * win, int sx, int sy );
-void wsIconify( wsTWindow win );
-void wsMoveTopWindow( Display * wsDisplay, Window win );
-void wsSetBackground( wsTWindow * win, int color );
-void wsSetForegroundRGB( wsTWindow * win, int r, int g, int b );
-void wsSetBackgroundRGB( wsTWindow * win, int r, int g, int b );
-#define wsClearWindow( win ) XClearWindow( wsDisplay, win.WindowID )
-void wsSetTitle( wsTWindow * win, char * name );
-void wsVisibleWindow( wsTWindow * win, int show );
-void wsWindowDecoration( wsTWindow * win, long d );
-void wsSetLayer( Display * wsDisplay, Window win, int layer );
-void wsFullScreen( wsTWindow * win );
-void wsPostRedisplay( wsTWindow * win );
-void wsSetShape( wsTWindow * win, char * data );
-void wsSetIcon( Display * dsp, Window win, guiIcon_t * icon );
+void wsCreateWindow(wsTWindow *win, int X, int Y, int wX, int hY, int bW, int cV, unsigned char D, char *label);
+void wsDestroyWindow(wsTWindow *win);
+void wsMoveWindow(wsTWindow *win, int b, int x, int y);
+void wsResizeWindow(wsTWindow *win, int sx, int sy);
+void wsIconify(wsTWindow win);
+void wsMoveTopWindow(Display *wsDisplay, Window win);
+void wsSetBackground(wsTWindow *win, int color);
+void wsSetForegroundRGB(wsTWindow *win, int r, int g, int b);
+void wsSetBackgroundRGB(wsTWindow *win, int r, int g, int b);
+#define wsClearWindow(win) XClearWindow(wsDisplay, win.WindowID)
+void wsSetTitle(wsTWindow *win, char *name);
+void wsVisibleWindow(wsTWindow *win, int show);
+void wsWindowDecoration(wsTWindow *win, long d);
+void wsSetLayer(Display *wsDisplay, Window win, int layer);
+void wsFullScreen(wsTWindow *win);
+void wsPostRedisplay(wsTWindow *win);
+void wsSetShape(wsTWindow *win, char *data);
+void wsSetIcon(Display *dsp, Window win, guiIcon_t *icon);
 
 // ----------------------------------------------------------------------------------------------
 //    Draw string at x,y with fc ( foreground color ) and bc ( background color ).
 // ----------------------------------------------------------------------------------------------
-void wsDrawString( wsTWindow win, int x, int y, char * str, int fc, int bc );
-int  wsTextWidth( wsTWindow win, char * str );
+void wsDrawString(wsTWindow win, int x, int y, char *str, int fc, int bc);
+int wsTextWidth(wsTWindow win, char *str);
 
 // ----------------------------------------------------------------------------------------------
 //    Show / hide mouse cursor.
 // ----------------------------------------------------------------------------------------------
-void wsVisibleMouse( wsTWindow * win, int m );
-void wsSetMousePosition( wsTWindow * win, int x, int y );
+void wsVisibleMouse(wsTWindow *win, int m);
+void wsSetMousePosition(wsTWindow *win, int x, int y);
 
 // ----------------------------------------------------------------------------------------------
 // Image handling
 // ----------------------------------------------------------------------------------------------
-void wsCreateImage( wsTWindow * win, int Width, int Height );
-void wsConvert( wsTWindow * win, unsigned char * Image, unsigned int Size );
-void wsPutImage( wsTWindow * win );
-void wsResizeImage( wsTWindow * win, int Width, int Height );
-void wsDestroyImage( wsTWindow * win );
-int  wsGetOutMask( void );
+void wsCreateImage(wsTWindow *win, int Width, int Height);
+void wsConvert(wsTWindow *win, unsigned char *Image, unsigned int Size);
+void wsPutImage(wsTWindow *win);
+void wsResizeImage(wsTWindow *win, int Width, int Height);
+void wsDestroyImage(wsTWindow *win);
+int wsGetOutMask(void);
 
-void wsScreenSaverOn( Display *mDisplay );
-void wsScreenSaverOff( Display * mDisplay );
+void wsScreenSaverOn(Display *mDisplay);
+void wsScreenSaverOff(Display *mDisplay);
 
-#define wgIsRect( X,Y,tX,tY,bX,bY ) ( ( (X) > (tX) )&&( (Y) > (tY) )&&( (X) < (bX) )&&( (Y) < (bY) ) )
+#define wgIsRect(X, Y, tX, tY, bX, bY) (((X) > (tX)) && ((Y) > (tY)) && ((X) < (bX)) && ((Y) < (bY)))
 
 #endif /* MPLAYER_GUI_WS_H */