From a5ad186a663c15d1d3cf3832a3c2ee95417ee917 Mon Sep 17 00:00:00 2001 From: Mitchell Stokes Date: Sat, 8 Dec 2018 17:21:59 -0800 Subject: [PATCH] x11display: Do not grab the mouse in confined mode when the window does not have focus --- panda/src/x11display/x11GraphicsWindow.cxx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/panda/src/x11display/x11GraphicsWindow.cxx b/panda/src/x11display/x11GraphicsWindow.cxx index caaacc4a9c..ad0f8e44dd 100644 --- a/panda/src/x11display/x11GraphicsWindow.cxx +++ b/panda/src/x11display/x11GraphicsWindow.cxx @@ -508,6 +508,26 @@ process_events() { changed_properties = true; } + if (properties.has_foreground() && _properties.get_mouse_mode() == WindowProperties::M_confined) { + // Focus has changed, let's let go of the pointer if we've grabbed or re-grab it if needed + if (properties.get_foreground()) { + // Window is going to the foreground, re-grab the pointer + X11_Cursor cursor = None; + if (_properties.get_cursor_hidden()) { + x11GraphicsPipe *x11_pipe; + DCAST_INTO_V(x11_pipe, _pipe); + cursor = x11_pipe->get_hidden_cursor(); + } + + XGrabPointer(_display, _xwindow, True, 0, GrabModeAsync, GrabModeAsync, + _xwindow, cursor, CurrentTime); + } + else { + // window is leaving the foreground, ungrab the pointer + XUngrabPointer(_display, CurrentTime); + } + } + if (changed_properties) { system_changed_properties(properties); }