diff options
| author | uint <72694427+uint23@users.noreply.github.com> | 2025-09-30 14:47:25 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-30 14:47:25 +0100 |
| commit | b331a194c8928b2f017f4b63638ecbfdba17272e (patch) | |
| tree | 33c284fd0e810c13abbe943bd6cc569892b36534 | |
| parent | 0933c8325cea0d5cea51af578fb7573be9d2c4d0 (diff) | |
| parent | 39a0565346f6b1a2001528af58603be834302b86 (diff) | |
Merge pull request #232 from l0wigh/fix_window_swallowing
Fix Window swallowing to target the parent window and not any swallower
| -rw-r--r-- | src/sxwm.c | 31 |
1 files changed, 29 insertions, 2 deletions
@@ -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); @@ -425,6 +427,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); @@ -660,6 +670,23 @@ int get_monitor_for(Client *c) return 0; } +pid_t get_parent_process(pid_t c) +{ + pid_t v = -1; + FILE *f; + char buf[256]; + + snprintf(buf, sizeof(buf), "/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; @@ -1219,8 +1246,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); |
