From f6410abd433ecfc8f377caf0757c373727c1aa12 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 31 Dec 2012 22:15:49 -0500 Subject: [PATCH] X11: release all keys/buttons when window loses focus --- src/arch/InputHandler/InputHandler_X11.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/arch/InputHandler/InputHandler_X11.cpp b/src/arch/InputHandler/InputHandler_X11.cpp index 56f0febb74..26814180a8 100644 --- a/src/arch/InputHandler/InputHandler_X11.cpp +++ b/src/arch/InputHandler/InputHandler_X11.cpp @@ -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) );