Skip to content

Commit dddc6ab

Browse files
committed
GPU Display: Release keys / mouse buttons when focus lost
1 parent e252e41 commit dddc6ab

6 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontend.cxx‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ GPUDisplayFrontend* createGPUDisplayFrontendWayland();
4040

4141
#include "GPULogging.h"
4242
#include <cstring>
43+
#include <algorithm>
44+
#include <iterator>
4345
#include <thread>
4446

4547
#ifdef GPUCA_BUILD_EVENT_DISPLAY_QT
@@ -201,6 +203,13 @@ void GPUDisplayFrontend::setWindowState(bool fullScreen, bool maximized)
201203
mDisplay->mCfgR.maximized = maximized;
202204
}
203205

206+
void GPUDisplayFrontend::focusLost()
207+
{
208+
std::fill(std::begin(mKeys), std::end(mKeys), false);
209+
std::fill(std::begin(mKeysShift), std::end(mKeysShift), false);
210+
mMouseDn = mMouseDnR = false;
211+
}
212+
204213
void GPUDisplayFrontend::applyInitialWindowState()
205214
{
206215
if (mDisplay->cfgR().fullScreen) {

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontend.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class GPUDisplayFrontend : public GPUDisplayFrontendInterface
152152
void ExitDisplay(); // Callback to clean up the GL Display
153153
int32_t& drawTextFontSize();
154154
void setWindowState(bool fullScreen, bool maximized); // Sync the settings if the window manager changed the window state
155+
void focusLost(); // Release all keys and mouse buttons when the window loses focus, since the release events go to another window
155156
void applyInitialWindowState(); // Switch to fullscreen / maximize at startup according to the settings
156157
};
157158
} // namespace o2::gpu

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontendGlfw.cxx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ void GPUDisplayFrontendGlfw::cursorPos_callback(GLFWwindow* window, double x, do
229229

230230
void GPUDisplayFrontendGlfw::resize_callback(GLFWwindow* window, int32_t width, int32_t height) { me->ResizeScene(width, height); }
231231

232+
void GPUDisplayFrontendGlfw::focus_callback(GLFWwindow* window, int32_t focused)
233+
{
234+
if (!focused) {
235+
me->focusLost();
236+
}
237+
}
238+
232239
void GPUDisplayFrontendGlfw::maximize_callback(GLFWwindow* window, int32_t maximized) { me->setWindowState(glfwGetWindowMonitor(window) != nullptr, maximized); }
233240

234241
#ifndef GPUCA_STANDALONE
@@ -279,6 +286,7 @@ int32_t GPUDisplayFrontendGlfw::FrontendMain()
279286
glfwSetCursorPosCallback(mWindow, cursorPos_callback);
280287
glfwSetWindowSizeCallback(mWindow, resize_callback);
281288
glfwSetWindowMaximizeCallback(mWindow, maximize_callback);
289+
glfwSetWindowFocusCallback(mWindow, focus_callback);
282290
applyInitialWindowState();
283291
if (backend()->backendType() == GPUDisplayBackend::TYPE_OPENGL) {
284292
glfwSwapInterval(1);

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontendGlfw.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class GPUDisplayFrontendGlfw : public GPUDisplayFrontend
5050
static void cursorPos_callback(GLFWwindow* mWindow, double x, double y);
5151
static void resize_callback(GLFWwindow* mWindow, int32_t width, int32_t height);
5252
static void maximize_callback(GLFWwindow* mWindow, int32_t maximized);
53+
static void focus_callback(GLFWwindow* mWindow, int32_t focused);
5354
static int32_t GetKey(int32_t key);
5455
static void GetKey(int32_t keyin, int32_t scancode, int32_t mods, int32_t& keyOut, int32_t& keyPressOut);
5556

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontendWayland.cxx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ int32_t GPUDisplayFrontendWayland::FrontendMain()
156156
auto pointer_enter = [](void* data, wl_pointer* wl_pointer, uint32_t serial, wl_surface* surface, wl_fixed_t surface_x, wl_fixed_t surface_y) {
157157
};
158158
auto pointer_leave = [](void* data, wl_pointer* wl_pointer, uint32_t serial, wl_surface* wl_surface) {
159+
GPUDisplayFrontendWayland* me = (GPUDisplayFrontendWayland*)data;
160+
me->mMouseDn = me->mMouseDnR = false;
159161
};
160162
auto pointer_motion = [](void* data, wl_pointer* wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
161163
GPUDisplayFrontendWayland* me = (GPUDisplayFrontendWayland*)data;
@@ -192,7 +194,7 @@ int32_t GPUDisplayFrontendWayland::FrontendMain()
192194
};
193195
auto pointer_axis_source = [](void* data, wl_pointer* wl_pointer, uint32_t axis_source) {};
194196
auto pointer_axis_stop = [](void* data, wl_pointer* wl_pointer, uint32_t time, uint32_t axis) {};
195-
auto pointer_axis_discrete = [](void* data, wl_pointer* wl_pointer, uint32_t axis, int32_t discrete) {}; // Only sent for seat versions 5 to 7, superseded by axis_value120
197+
auto pointer_axis_discrete = [](void* data, wl_pointer* wl_pointer, uint32_t axis, int32_t discrete) {};
196198
#ifdef WL_POINTER_AXIS_VALUE120_SINCE_VERSION
197199
auto pointer_axis_value120 = [](void* data, wl_pointer* wl_pointer, uint32_t axis, int32_t value120) {
198200
GPUDisplayFrontendWayland* me = (GPUDisplayFrontendWayland*)data;
@@ -223,7 +225,11 @@ int32_t GPUDisplayFrontendWayland::FrontendMain()
223225
close(fd);
224226
};
225227
auto keyboard_enter = [](void* data, wl_keyboard* wl_keyboard, uint32_t serial, wl_surface* surface, wl_array* keys) {};
226-
auto keyboard_leave = [](void* data, wl_keyboard* wl_keyboard, uint32_t serial, wl_surface* surface) {};
228+
auto keyboard_leave = [](void* data, wl_keyboard* wl_keyboard, uint32_t serial, wl_surface* surface) {
229+
GPUDisplayFrontendWayland* me = (GPUDisplayFrontendWayland*)data;
230+
me->focusLost();
231+
me->mRepeatKeyCode = -1;
232+
};
227233
auto keyboard_key = [](void* data, wl_keyboard* wl_keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) {
228234
GPUDisplayFrontendWayland* me = (GPUDisplayFrontendWayland*)data;
229235
int32_t symbol = me->GetKey(key, state);

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontendX11.cxx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,11 @@ int32_t GPUDisplayFrontendX11::FrontendMain()
392392
break;
393393
}
394394

395+
case FocusOut: {
396+
focusLost();
397+
break;
398+
}
399+
395400
case PropertyNotify: {
396401
if (event.xproperty.atom == XInternAtom(mXDisplay, "_NET_WM_STATE", False)) {
397402
updateWindowState();

0 commit comments

Comments
 (0)