From a6016a9c03fbdae792058ad772536a9f6ee2b8d9 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Thu, 7 Dec 2006 10:51:17 +0000 Subject: [PATCH] Simplify. Only have a single window creation function. --- stepmania/src/archutils/Unix/X11Helper.cpp | 93 ++++++---------------- stepmania/src/archutils/Unix/X11Helper.h | 13 +-- 2 files changed, 28 insertions(+), 78 deletions(-) diff --git a/stepmania/src/archutils/Unix/X11Helper.cpp b/stepmania/src/archutils/Unix/X11Helper.cpp index 46cf7c8eeb..77a9cf6810 100644 --- a/stepmania/src/archutils/Unix/X11Helper.cpp +++ b/stepmania/src/archutils/Unix/X11Helper.cpp @@ -1,17 +1,10 @@ #include "global.h" #include "X11Helper.h" - -#include - #include "RageLog.h" -#include "RageDisplay.h" -#include "RageThreads.h" - -// Currently open masks: -static vector g_aiMasks; // Number of subsystems using the X connection: static int g_iRefCount = 0; +static unsigned long g_iMask = 0L; Display *X11Helper::Dpy = NULL; Window X11Helper::Win = None; @@ -40,106 +33,68 @@ void X11Helper::Stop() if( g_iRefCount == 0 ) { - XCloseDisplay( Dpy ); + // The window should have been shut down + DEBUG_ASSERT( Win == None ); Dpy = NULL; // For sanity's sake - g_aiMasks.clear(); } } -static void ApplyMasks(); - -void X11Helper::OpenMask( long mask ) +void X11Helper::OpenMask( unsigned long mask ) { - g_aiMasks.push_back(mask); - ApplyMasks(); + g_iMask |= mask; + if( Dpy && Win ) + XSelectInput( Dpy, Win, g_iMask ); } -void X11Helper::CloseMask( long mask ) +void X11Helper::CloseMask( unsigned long mask ) { - vector::iterator i = find( g_aiMasks.begin(), g_aiMasks.end(), mask ); - if( i == g_aiMasks.end() ) - return; - - g_aiMasks.erase( i ); - ApplyMasks(); + g_iMask &= ~mask; + if( Dpy && Win ) + XSelectInput( Dpy, Win, g_iMask ); } -static void ApplyMasks() -{ - if( X11Helper::Dpy == NULL || X11Helper::Win == None ) - return; - - LOG->Trace( "X11Helper: Reapplying event masks." ); - - long iMask = 0; - for( unsigned i = 0; i < g_aiMasks.size(); ++i ) - iMask |= g_aiMasks[i]; - - XSelectInput( X11Helper::Dpy, X11Helper::Win, iMask ); -} - -bool X11Helper::MakeWindow( int screenNum, int depth, Visual *visual, int width, int height, bool overrideRedirect ) +bool X11Helper::MakeWindow( Window &win, int screenNum, int depth, Visual *visual, int width, int height, bool overrideRedirect ) { if( g_iRefCount == 0 ) return false; - if( Win ) - { - XDestroyWindow( Dpy, Win ); - Win = None; - } - Win = CreateWindow( screenNum, depth, visual, width, height, overrideRedirect ); - return true; -} + if( win ) + XDestroyWindow( Dpy, win ); -Window X11Helper::CreateWindow( int screenNum, int depth, Visual *visual, int width, int height, bool overrideRedirect ) -{ - vector::iterator i; - XSetWindowAttributes winAttribs; winAttribs.border_pixel = 0; - winAttribs.event_mask = 0; - i = g_aiMasks.begin(); - while( i != g_aiMasks.end() ) - { - winAttribs.event_mask |= *i; - i++; - } + winAttribs.event_mask = g_iMask; // XXX: Error catching/handling? winAttribs.colormap = XCreateColormap( Dpy, RootWindow(Dpy, screenNum), visual, AllocNone ); + unsigned long mask = CWBorderPixel | CWColormap | CWEventMask; - Window Win; if( overrideRedirect ) { winAttribs.override_redirect = True; - Win = XCreateWindow( Dpy, RootWindow(Dpy, screenNum), 0, 0, width, - height, 0, depth, InputOutput, visual, - CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, &winAttribs ); - } - else - { - Win = XCreateWindow( Dpy, RootWindow(Dpy, screenNum), 0, 0, width, - height, 0, depth, InputOutput, visual, - CWBorderPixel | CWColormap | CWEventMask, &winAttribs ); + mask |= CWOverrideRedirect; } + win = XCreateWindow( Dpy, RootWindow(Dpy, screenNum), 0, 0, width, height, 0, + depth, InputOutput, visual, mask, &winAttribs ); + if( win == None ) + return false; /* Hide the mouse cursor. */ { const char pBlank[] = { 0,0,0,0,0,0,0,0 }; - Pixmap BlankBitmap = XCreateBitmapFromData( Dpy, Win, pBlank, 8, 8 ); + Pixmap BlankBitmap = XCreateBitmapFromData( Dpy, win, pBlank, 8, 8 ); XColor black = { 0, 0, 0, 0, 0, 0 }; Cursor pBlankPointer = XCreatePixmapCursor( Dpy, BlankBitmap, BlankBitmap, &black, &black, 0, 0 ); XFreePixmap( Dpy, BlankBitmap ); - XDefineCursor( Dpy, Win, pBlankPointer ); + XDefineCursor( Dpy, win, pBlankPointer ); XFreeCursor( Dpy, pBlankPointer ); } - return Win; + return true; } int ErrorCallback( Display *d, XErrorEvent *err ) diff --git a/stepmania/src/archutils/Unix/X11Helper.h b/stepmania/src/archutils/Unix/X11Helper.h index 9228fb3df0..84056b78ac 100644 --- a/stepmania/src/archutils/Unix/X11Helper.h +++ b/stepmania/src/archutils/Unix/X11Helper.h @@ -3,9 +3,6 @@ #define X11_HELPER_H #include // Window - -#include "RageDisplay.h" // RageDisplay - namespace X11Helper { // All functions in here that return a bool return true on success, and @@ -31,18 +28,16 @@ namespace X11Helper // this visual type, this width (optional -- you can resize the window // in your callback later), and this height (optional). // Also, whether to enable override redirect on the window. - bool MakeWindow(int screenNum, int depth, Visual *visual, - int width=32, int height=32, bool overrideRedirect=false); - - Window CreateWindow( int screenNum, int depth, Visual *visual, int width, int height, bool overrideRedirect ); + bool MakeWindow( Window &win, int screenNum, int depth, Visual *visual, + int width, int height, bool overrideRedirect ); // Unmask one X event type mask thingy (XSelectInput() arg 3) on the // current window. Masked/unmasked events will carry between windows. - void OpenMask( long mask ); + void OpenMask( unsigned long mask ); // (Re)mask one X event type mask thingy (XSelectInput() arg 3) on the // current window. Masked/unmasked events will carry between windows. - void CloseMask( long mask ); + void CloseMask( unsigned long mask ); }; #endif