diff options
author | dec05eba <dec05eba@protonmail.com> | 2025-01-02 19:07:41 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2025-01-02 19:07:41 +0100 |
commit | 3e81aca948b3fab1cfb7857db7f18fab318acada (patch) | |
tree | 332182cb3bb331679fc89fe3c6441346ca2a2cfd | |
parent | 48ac6b341fbd821b8e1c04a9775b989eb9c4102a (diff) |
Get focused monitor by cursor root position instead of window relative position
-rw-r--r-- | src/main.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp index 210e747..363aacf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -169,6 +169,16 @@ static const mgl_monitor* find_monitor_at_position(mgl::Window &window, mgl::vec return &win->monitors[0]; } +static mgl::vec2i get_cursor_position(Display *dpy) { + Window root_window = None; + Window window = None; + int dummy_i; + unsigned int dummy_u; + mgl::vec2i root_pos; + XQueryPointer(dpy, DefaultRootWindow(dpy), &root_window, &window, &root_pos.x, &root_pos.y, &dummy_i, &dummy_i, &dummy_u); + return root_pos; +} + static mgl::vec2i create_window_get_center_position(Display *display) { const int size = 16; XSetWindowAttributes window_attr; @@ -330,7 +340,7 @@ int main(int argc, char **argv) { } // The cursor position is wrong on wayland if an x11 window is not focused. On wayland we instead create a window and get the position where the wayland compositor puts it - const mgl::vec2i monitor_position_query_value = wayland ? create_window_get_center_position(display) : mgl::vec2i(win->cursor_position.x, win->cursor_position.y); + const mgl::vec2i monitor_position_query_value = wayland ? create_window_get_center_position(display) : get_cursor_position(display); const mgl_monitor *focused_monitor = find_monitor_at_position(window, monitor_position_query_value); const std::string noto_sans_bold_filepath = resources_path + "fonts/NotoSans-Bold.ttf"; |