xscreen

X11 screenshot utility
git clone https://porkepik.fr/xscreen
Log | Files | Refs | README | LICENSE

commit 0472bb674434cd0c2a0eb9919f8ddc086b27d176
parent ef5be65fdf40616a9df29f51423daf4fe69638df
Author: Thomas Philippe <dev@porkepik.fr>
Date:   Tue, 30 Jul 2019 18:36:35 +0200

move get_toplevel_parent() to get_focused_window()

Diffstat:
Mxscreen.c | 44++++++++++++++++++++++----------------------
1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/xscreen.c b/xscreen.c @@ -135,6 +135,27 @@ get_root_window(void) return DefaultRootWindow(disp); } +Window +get_toplevel_parent(Window win) +{ + Window parent, root, *children; + unsigned int num_children; + int status; + + while (1) { + status = XQueryTree(disp, win, &root, &parent, + &children, &num_children); + if (!status) + errx(1, "XQueryTree error"); + if (children) + XFree(children); + if (win == root || parent == root) + return win; + else + win = parent; + } +} + static Window get_focused_window(void) { @@ -144,6 +165,7 @@ get_focused_window(void) XGetInputFocus(disp, &focused_win, &revert_to); if (!focused_win) errx(1, "No window is being focused."); + focused_win = get_toplevel_parent(focused_win); return focused_win; } @@ -244,27 +266,6 @@ delay(int delay_sec) printf("\n"); } -Window -get_toplevel_parent(Window win) -{ - Window parent, root, *children; - unsigned int num_children; - int status; - - while (1) { - status = XQueryTree(disp, win, &root, &parent, - &children, &num_children); - if (!status) - errx(1, "XQueryTree error"); - if (children) - XFree(children); - if (win == root || parent == root) - return win; - else - win = parent; - } -} - static void capture(Window win, struct screenshot *img) { @@ -272,7 +273,6 @@ capture(Window win, struct screenshot *img) XWindowAttributes attr; XImage *ximg; - win = get_toplevel_parent(win); XGetWindowAttributes(disp, win, &attr); img->width = attr.width;