From ab02de0e72dcc454a1697fbbe9b56652889deb0b Mon Sep 17 00:00:00 2001 From: Abhinav Date: Sat, 7 Jun 2025 14:10:32 +0100 Subject: add find_toplevel function This function correctly handles windows like firefox by finding the root window so that clicking on it will focus the window --- src/sxwm.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src') diff --git a/src/sxwm.c b/src/sxwm.c index f42c138..fbf55e1 100644 --- a/src/sxwm.c +++ b/src/sxwm.c @@ -42,6 +42,7 @@ int clean_mask(int mask); /* void close_focused(void); */ /* void dec_gaps(void); */ void startup_exec(void); +Window find_toplevel(Window w); /* void focus_next(void); */ /* void focus_prev(void); */ int get_monitor_for(Client *c); @@ -323,6 +324,29 @@ void startup_exec(void) } } +Window find_toplevel(Window w) +{ + Window root = None; + Window parent; + Window *kids; + unsigned nkids; + + while (True) { + if (w == root) { + break; + } + if (XQueryTree(dpy, w, &root, &parent, &kids, &nkids) == 0) { + break; + } + XFree(kids); + if (parent == root || parent == None) { + break; + } + w = parent; + } + return w; +} + void focus_next(void) { if (!focused || !workspaces[current_ws]) { @@ -586,6 +610,8 @@ void hdl_button(XEvent *xev) { XButtonEvent *e = &xev->xbutton; Window w = (e->subwindow != None) ? e->subwindow : e->window; + w = find_toplevel(w); + XAllowEvents(dpy, ReplayPointer, e->time); if (!w) { return; -- cgit v1.2.3