diff options
-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"; |