From 5becdb32e03c937edabf9205d6b0bbf30a2ae950 Mon Sep 17 00:00:00 2001 From: L0Wigh Date: Thu, 11 Sep 2025 14:39:44 +0200 Subject: beginning of the window swallowing fix --- src/sxwm.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/sxwm.c b/src/sxwm.c index 8a16b11..ce936df 100644 --- a/src/sxwm.c +++ b/src/sxwm.c @@ -1192,6 +1192,7 @@ void hdl_map_req(XEvent *xev) } /* if window can be swallowed look for a potential swallower */ + // Should be swallowed by it's parent and not any windows that can swallow if (can_be_swallowed) { for (Client *p = workspaces[current_ws]; p; p = p->next) { if (p == c || p->swallowed || !p->mapped) { -- cgit v1.2.3 From faba2d069e4b7bcbfaf70866dc7302ec10db0da5 Mon Sep 17 00:00:00 2001 From: L0Wigh Date: Thu, 11 Sep 2025 14:57:13 +0200 Subject: fix window swallowing to target it's really parent window --- src/sxwm.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/sxwm.c b/src/sxwm.c index ce936df..6cb5007 100644 --- a/src/sxwm.c +++ b/src/sxwm.c @@ -43,6 +43,7 @@ Client *add_client(Window w, int ws); /* void centre_window(void); */ void change_workspace(int ws); +int check_parent(pid_t p, pid_t c); int clean_mask(int mask); /* void close_focused(void); */ /* void dec_gaps(void); */ @@ -53,6 +54,7 @@ Window find_toplevel(Window w); /* void focus_next_mon(void); */ /* void focus_prev_mon(void); */ int get_monitor_for(Client *c); +pid_t get_parent_process(pid_t c); pid_t get_pid(Window w); int get_workspace_for_window(Window w); void grab_button(Mask button, Mask mod, Window w, Bool owner_events, Mask masks); @@ -308,6 +310,23 @@ void centre_window(void) XMoveWindow(dpy, focused->win, x, y); } +pid_t get_parent_process(pid_t c) +{ + unsigned int v = 0; + FILE *f; + char buf[256]; + + snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)c); + if (!(f = fopen(buf, "r"))) { + return 0; + } + + int no_error = fscanf(f, "%*u %*s %*c %u", &v); + (void)no_error; + fclose(f); + return (pid_t)v; +} + void change_workspace(int ws) { if (ws >= NUM_WORKSPACES || ws == current_ws) { @@ -423,6 +442,14 @@ void change_workspace(int ws) in_ws_switch = False; } +int check_parent(pid_t p, pid_t c) +{ + while (p != c && c != 0) { + c = get_parent_process(c); + } + return (int)c; +} + int clean_mask(int mask) { return mask & ~(LockMask | numlock_mask | mode_switch_mask); @@ -1192,7 +1219,6 @@ void hdl_map_req(XEvent *xev) } /* if window can be swallowed look for a potential swallower */ - // Should be swallowed by it's parent and not any windows that can swallow if (can_be_swallowed) { for (Client *p = workspaces[current_ws]; p; p = p->next) { if (p == c || p->swallowed || !p->mapped) { @@ -1217,8 +1243,8 @@ void hdl_map_req(XEvent *xev) } /* check process relationship */ - if (can_swallow) { - /* we know class matches -> swallow now */ + if (can_swallow && check_parent(p->pid, c->pid)) { + /* we know class matches and the swallower is the parent -> swallow now */ swallow_window(p, c); XFree(pch.res_class); XFree(pch.res_name); -- cgit v1.2.3 From 360136d0b90ff6f9439c2f3c8c2df4b2e98735ce Mon Sep 17 00:00:00 2001 From: L0Wigh Date: Thu, 11 Sep 2025 15:13:48 +0200 Subject: cleaning the code to respect the guideline --- src/sxwm.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/sxwm.c b/src/sxwm.c index 6cb5007..702313e 100644 --- a/src/sxwm.c +++ b/src/sxwm.c @@ -310,23 +310,6 @@ void centre_window(void) XMoveWindow(dpy, focused->win, x, y); } -pid_t get_parent_process(pid_t c) -{ - unsigned int v = 0; - FILE *f; - char buf[256]; - - snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)c); - if (!(f = fopen(buf, "r"))) { - return 0; - } - - int no_error = fscanf(f, "%*u %*s %*c %u", &v); - (void)no_error; - fclose(f); - return (pid_t)v; -} - void change_workspace(int ws) { if (ws >= NUM_WORKSPACES || ws == current_ws) { @@ -685,6 +668,24 @@ int get_monitor_for(Client *c) return 0; } +pid_t get_parent_process(pid_t c) +{ + unsigned int v = 0; + FILE *f; + char buf[256]; + + snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)c); + if (!(f = fopen(buf, "r"))) { + return 0; + } + + int no_error = fscanf(f, "%*u %*s %*c %u", &v); + (void)no_error; + fclose(f); + return (pid_t)v; +} + + pid_t get_pid(Window w) { pid_t pid = 0; -- cgit v1.2.3 From 91bcb69254ece659e8cf4eba6c4235708955a8ad Mon Sep 17 00:00:00 2001 From: L0Wigh Date: Thu, 11 Sep 2025 15:14:33 +0200 Subject: more cleaning --- src/sxwm.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/sxwm.c b/src/sxwm.c index 702313e..91aeb8e 100644 --- a/src/sxwm.c +++ b/src/sxwm.c @@ -685,7 +685,6 @@ pid_t get_parent_process(pid_t c) return (pid_t)v; } - pid_t get_pid(Window w) { pid_t pid = 0; -- cgit v1.2.3 From 39a0565346f6b1a2001528af58603be834302b86 Mon Sep 17 00:00:00 2001 From: L0Wigh Date: Tue, 30 Sep 2025 15:10:10 +0200 Subject: modifying the fix to fit uint23 recommendations --- src/sxwm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/sxwm.c b/src/sxwm.c index 91aeb8e..65be8b9 100644 --- a/src/sxwm.c +++ b/src/sxwm.c @@ -670,11 +670,11 @@ int get_monitor_for(Client *c) pid_t get_parent_process(pid_t c) { - unsigned int v = 0; + pid_t v = -1; FILE *f; char buf[256]; - snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)c); + snprintf(buf, sizeof(buf), "/proc/%u/stat", (unsigned)c); if (!(f = fopen(buf, "r"))) { return 0; } -- cgit v1.2.3