X11: release all keys/buttons when window loses focus

This commit is contained in:
Devin J. Pohly
2012-12-31 22:15:49 -05:00
parent 655af974a6
commit f6410abd43
+14 -2
View File
@@ -145,6 +145,7 @@ InputHandler_X11::InputHandler_X11()
XSelectInput( Dpy, Win,
winAttrib.your_event_mask | KeyPressMask | KeyReleaseMask
| ButtonPressMask | ButtonReleaseMask | PointerMotionMask
| FocusChangeMask
);
}
@@ -152,12 +153,14 @@ InputHandler_X11::~InputHandler_X11()
{
if( Dpy == NULL || Win == None )
return;
// TODO: Determine if we even need to set this back (or is the window
// destroyed just after this?)
XWindowAttributes winAttrib;
XGetWindowAttributes( Dpy, Win, &winAttrib );
XSelectInput( Dpy, Win,
winAttrib.your_event_mask &
~(KeyPressMask|KeyReleaseMask|ButtonPressMask|ButtonReleaseMask|PointerMotionMask)
~(KeyPressMask|KeyReleaseMask|ButtonPressMask|ButtonReleaseMask|PointerMotionMask|FocusChangeMask)
);
}
@@ -173,10 +176,13 @@ void InputHandler_X11::Update()
DeviceButton lastDB = DeviceButton_Invalid;
lastEvent.type = 0;
// TODO: Rewrite to use XEventsQueued, XNextEvent, and XPeekEvent - this
// will likely make the logic simpler
// todo: add other masks? (like the ones for drag'n drop) -aj
while( XCheckWindowEvent(Dpy, Win,
KeyPressMask | KeyReleaseMask
| ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
| ButtonPressMask | ButtonReleaseMask | PointerMotionMask
| FocusChangeMask,
&event) )
{
const bool bKeyPress = event.type == KeyPress;
@@ -201,6 +207,12 @@ void InputHandler_X11::Update()
lastEvent.type = 0;
}
if( event.type == FocusOut )
{
// Release all buttons
INPUTFILTER->Reset();
}
// Get the first defined keysym for this event's key
lastDB = XSymToDeviceButton( XLookupKeysym(&event.xkey, 0) );