From be6fc786ca3387a4b76d5fcf0a27982a917a99c8 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sat, 31 Jul 2021 15:49:47 +0200 Subject: [PATCH] Add a function for getting the active modifiers --- src/wine-host/editor.cpp | 17 ++++++++++++++++- src/wine-host/editor.h | 10 +++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/wine-host/editor.cpp b/src/wine-host/editor.cpp index acb930b5..1e0b70b3 100644 --- a/src/wine-host/editor.cpp +++ b/src/wine-host/editor.cpp @@ -854,7 +854,22 @@ void Editor::run_timer_proc() { idle_timer_proc(); } -std::optional Editor::get_current_pointer_position() const { +std::optional Editor::get_active_modifiers() const noexcept { + xcb_generic_error_t* error = nullptr; + const xcb_query_pointer_cookie_t query_pointer_cookie = + xcb_query_pointer(x11_connection.get(), wine_window); + const std::unique_ptr query_pointer_reply( + xcb_query_pointer_reply(x11_connection.get(), query_pointer_cookie, + &error)); + if (error) { + free(error); + return std::nullopt; + } + + return query_pointer_reply->mask; +} + +std::optional Editor::get_current_pointer_position() const noexcept { xcb_generic_error_t* error = nullptr; const xcb_query_pointer_cookie_t query_pointer_cookie = xcb_query_pointer(x11_connection.get(), wine_window); diff --git a/src/wine-host/editor.h b/src/wine-host/editor.h index 4848f60a..001c98dd 100644 --- a/src/wine-host/editor.h +++ b/src/wine-host/editor.h @@ -263,6 +263,14 @@ class Editor { const bool use_xembed; private: + /** + * Get the X11 event mask containing the current keyboard modifiers. Because + * we don't want to link with `xcb-xkb` and we also can't really use + * key/motion events for this, we'll do this by querying the pointer + * position instead. Will return a nullopt if that query fails. + */ + std::optional get_active_modifiers() const noexcept; + /** * Get the current cursor position, in Win32 screen coordinates. This is * needed for our `LeaveNotify` handling because `GetCursorPos()` only @@ -273,7 +281,7 @@ class Editor { * * If we cannot obtain the X11 cursor position, then this returns a nullopt. */ - std::optional get_current_pointer_position() const; + std::optional get_current_pointer_position() const noexcept; /** * Returns `true` if the currently active window (as per