Keep the event mask across window recreates. Close the display, I did not mean to remove that.

This commit is contained in:
Steve Checkoway
2006-12-07 12:54:24 +00:00
parent 32e20beefc
commit d1d9f1762e
2 changed files with 14 additions and 37 deletions
+11 -22
View File
@@ -4,7 +4,6 @@
// 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;
@@ -35,39 +34,29 @@ void X11Helper::Stop()
{
// The window should have been shut down
DEBUG_ASSERT( Win == None );
XCloseDisplay( Dpy );
Dpy = NULL; // For sanity's sake
}
}
void X11Helper::OpenMask( unsigned long mask )
{
g_iMask |= mask;
if( Dpy && Win )
XSelectInput( Dpy, Win, g_iMask );
}
void X11Helper::CloseMask( unsigned long mask )
{
g_iMask &= ~mask;
if( Dpy && Win )
XSelectInput( Dpy, Win, g_iMask );
}
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 );
XSetWindowAttributes winAttribs;
winAttribs.border_pixel = 0;
winAttribs.event_mask = g_iMask;
winAttribs.event_mask = 0L;
if( win )
{
// Preserve the event mask.
XWindowAttributes attribs;
XGetWindowAttributes( Dpy, win, &attribs );
winAttribs.event_mask = attribs.your_event_mask;
XDestroyWindow( Dpy, win );
}
// XXX: Error catching/handling?
winAttribs.colormap = XCreateColormap( Dpy, RootWindow(Dpy, screenNum), visual, AllocNone );
unsigned long mask = CWBorderPixel | CWColormap | CWEventMask;
@@ -113,7 +102,7 @@ int FatalCallback( Display *d )
}
/*
* (c) 2005 Ben Anderson
* (c) 2005, 2006 Ben Anderson, Steve Checkoway
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
+3 -15
View File
@@ -20,30 +20,18 @@ namespace X11Helper
// Go().
extern Display *Dpy;
// Get the current open window. Initialized by the first call to
// MakeWindow().
// The Window used by LowLevelWindow_X11 as the main window.
extern Window Win;
// (Re)create the window on the screen of this number with this depth,
// 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.
// (Re)create the Window win.
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( 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( unsigned long mask );
};
#endif
/*
* (c) 2005 Ben Anderson
* (c) 2005, 2006 Ben Anderson, Steve Checkoway
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a