diff options
| -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); |
