From 9788f21e0e1a8dbcbcc713b6fceb6e6eaa2b7d12 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 19 Jan 2021 00:52:49 +0100 Subject: [PATCH] Fix rare hanging issue on Bitwig related to focus On Bitwig grabbing input focus this way would trigger many more FocusIn events, which in certain situations could cause the interface to hang while everything was being processed. --- src/wine-host/editor.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/wine-host/editor.cpp b/src/wine-host/editor.cpp index 676c4c94..293810aa 100644 --- a/src/wine-host/editor.cpp +++ b/src/wine-host/editor.cpp @@ -295,6 +295,12 @@ HWND Editor::get_win32_handle() const { } void Editor::handle_x11_events() const { + // Calling `set_input_focus(true)` can trigger another `FocusIn` event, + // which will then once again call `set_input_focus(true)`. To work around + // this we prevent successive keyboard focus grabs within a single call of + // this function. + bool have_requested_input_focus = false; + xcb_generic_event_t* generic_event; while ((generic_event = xcb_poll_for_event(x11_connection.get())) != nullptr) { @@ -338,8 +344,10 @@ void Editor::handle_x11_events() const { // In case the WM somehow does not support `_NET_ACTIVE_WINDOW`, // a more naive focus grabbing method implemented in the // `WM_PARENTNOTIFY` handler will be used. - if (supports_ewmh_active_window() && is_wine_window_active()) { + if (!have_requested_input_focus && + supports_ewmh_active_window() && is_wine_window_active()) { set_input_focus(true); + have_requested_input_focus = true; } break; // When the user moves their mouse away from the Wine window _while @@ -365,6 +373,7 @@ void Editor::handle_x11_events() const { if (event->detail != XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL && supports_ewmh_active_window() && is_wine_window_active()) { set_input_focus(false); + have_requested_input_focus = false; } } break; }