xscreen

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

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

fix BadMatch error with XGetImage when capturing a focused GTK window

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

diff --git a/xscreen.c b/xscreen.c @@ -244,6 +244,27 @@ 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) { @@ -251,6 +272,7 @@ capture(Window win, struct screenshot *img) XWindowAttributes attr; XImage *ximg; + win = get_toplevel_parent(win); XGetWindowAttributes(disp, win, &attr); img->width = attr.width;