diff options
author | dec05eba <dec05eba@protonmail.com> | 2025-02-10 18:22:21 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2025-02-10 18:22:21 +0100 |
commit | f4e44cbef5dbbc2a2b71e7b9b70ee72d30b7c6a6 (patch) | |
tree | fba7a409ad73abc4b233c9dfd960f014c2df6b69 /src/WindowUtils.cpp | |
parent | 3d6354c642244cde272c328a31c72a0adba54999 (diff) |
Prepare for sound. Fix game name being gsr-ui on wayland in some cases when saving video when the ui is open
Diffstat (limited to 'src/WindowUtils.cpp')
-rw-r--r-- | src/WindowUtils.cpp | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/src/WindowUtils.cpp b/src/WindowUtils.cpp index d8e3508..3d3a6a6 100644 --- a/src/WindowUtils.cpp +++ b/src/WindowUtils.cpp @@ -105,8 +105,7 @@ namespace gsr { 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); - if(window) - *window = window_get_target_window_child(dpy, *window); + *window = window_get_target_window_child(dpy, *window); return root_pos; } @@ -236,6 +235,44 @@ namespace gsr { return result; } + std::string get_window_name_at_position(Display *dpy, mgl::vec2i position, Window ignore_window) { + std::string result; + + Window root; + Window parent; + Window *children = nullptr; + unsigned int num_children = 0; + if(!XQueryTree(dpy, DefaultRootWindow(dpy), &root, &parent, &children, &num_children) || !children) + return result; + + for(int i = (int)num_children - 1; i >= 0; --i) { + if(children[i] == ignore_window) + continue; + + XWindowAttributes attr; + memset(&attr, 0, sizeof(attr)); + XGetWindowAttributes(dpy, children[i], &attr); + if(attr.override_redirect || attr.c_class != InputOutput) + continue; + + if(position.x >= attr.x && position.x <= attr.x + attr.width && position.y >= attr.y && position.y <= attr.y + attr.height && window_is_user_program(dpy, children[i])) { + const std::optional<std::string> window_title = get_window_title(dpy, children[i]); + if(window_title) + result = strip(window_title.value()); + break; + } + } + + XFree(children); + return result; + } + + std::string get_window_name_at_cursor_position(Display *dpy, Window ignore_window) { + Window cursor_window; + const mgl::vec2i cursor_position = get_cursor_position(dpy, &cursor_window); + return get_window_name_at_position(dpy, cursor_position, ignore_window); + } + typedef struct { unsigned long flags; unsigned long functions; |