Add a function for getting the active modifiers

This commit is contained in:
Robbert van der Helm
2021-07-31 15:49:47 +02:00
parent c98a9519fe
commit be6fc786ca
2 changed files with 25 additions and 2 deletions
+16 -1
View File
@@ -854,7 +854,22 @@ void Editor::run_timer_proc() {
idle_timer_proc();
}
std::optional<POINT> Editor::get_current_pointer_position() const {
std::optional<uint16_t> 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<xcb_query_pointer_reply_t> 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<POINT> 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);
+9 -1
View File
@@ -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<uint16_t> 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<POINT> get_current_pointer_position() const;
std::optional<POINT> get_current_pointer_position() const noexcept;
/**
* Returns `true` if the currently active window (as per