Browse Source

added tmux swallow patch by user github/soystemd

master
Sadoon AlBader 2 months ago
parent
commit
125e06a359
  1. 47
      dwm.c

47
dwm.c

@ -284,6 +284,8 @@ static void resource_load(XrmDatabase db, char *name, enum resource_type rtype,
static pid_t getparentprocess(pid_t p);
static int isdescprocess(pid_t p, pid_t c);
static int is_a_tmux_server(pid_t pid);
static long get_tmux_client_pid(long shell_pid);
static Client *swallowingclient(Window w);
static Client *termforwin(const Client *c);
static pid_t winpid(Window w);
@ -2428,7 +2430,7 @@ getparentprocess(pid_t p)
if (!(f = fopen(buf, "r")))
return (pid_t)0;
if (fscanf(f, "%*u %*s %*c %u", (unsigned *)&v) != 1)
if (fscanf(f, "%*u (%*[^)]) %*c %u", &v) != 1)
v = (pid_t)0;
fclose(f);
#elif defined(__FreeBSD__)
@ -2444,11 +2446,48 @@ getparentprocess(pid_t p)
int
isdescprocess(pid_t p, pid_t c)
{
pid_t p_tmp;
while (c != p && c != 0) {
p_tmp = getparentprocess(c);
if (is_a_tmux_server(p_tmp))
c = get_tmux_client_pid(c);
else
c = p_tmp;
}
return (int)c;
}
int
is_a_tmux_server(pid_t pid)
{
while (p != c && c != 0)
c = getparentprocess(c);
char path[256];
char name[15];
FILE* stat;
return (int)c;
snprintf(path, sizeof(path) - 1, "/proc/%u/stat", (unsigned)pid);
if (!(stat = fopen(path, "r")))
return 0;
fscanf(stat, "%*u (%12[^)])", name);
fclose(stat);
return (strcmp(name, "tmux: server") == 0);
}
/* parameter "shell_pid" is the pid of a direct child
* of the tmux's server process, which usually is a shell process. */
long
get_tmux_client_pid(long shell_pid)
{
long pane_pid, client_pid;
FILE* list = popen("tmux list-clients -F '#{pane_pid} #{client_pid}'", "r");
if (!list)
return 0;
while (!feof(list) && pane_pid != shell_pid)
fscanf(list, "%ld %ld\n", &pane_pid, &client_pid);
pclose(list);
return client_pid;
}
Client *

Loading…
Cancel
Save