diff --git a/config.h b/config.h index eca2d55..0878f9e 100644 --- a/config.h +++ b/config.h @@ -5,7 +5,7 @@ /* appearance */ static const unsigned int borderpx = 3; /* border pixel of windows */ static const unsigned int snap = 32; /* snap pixel */ -static const int swallowfloating = 1; /* 1 means swallow floating windows by default */ +static const int swallowfloating = 0; /* 1 means swallow floating windows by default */ static const int showbar = 1; /* 0 means no bar */ static const int topbar = 1; /* 0 means bottom bar */ static const char *fonts[] = { "IosevkaTerm Nerd Font:size=12", "Noto Color Emoji" }; diff --git a/dwm b/dwm index 7fd863d..7808c7b 100755 Binary files a/dwm and b/dwm differ diff --git a/dwm.c b/dwm.c index 2204e7d..79942d5 100644 --- a/dwm.c +++ b/dwm.c @@ -251,6 +251,8 @@ static void zoom(const Arg *arg); static pid_t getparentprocess(pid_t p); static int isdescprocess(pid_t p, pid_t c); +static int istmuxserver(pid_t p); +static long gettmuxclientpid(long shellpid); static Client *swallowingclient(Window w); static Client *termforwin(const Client *c); static pid_t winpid(Window w); @@ -2441,7 +2443,7 @@ getparentprocess(pid_t p) if (!(f = fopen(buf, "r"))) return 0; - fscanf(f, "%*u %*s %*c %u", &v); + fscanf(f, "%*u (%*[^)]) %*c %u", &v); fclose(f); #endif /* __linux__*/ @@ -2464,12 +2466,45 @@ getparentprocess(pid_t p) int isdescprocess(pid_t p, pid_t c) { - while (p != c && c != 0) - c = getparentprocess(c); - + pid_t p_tmp; + while (p != c && c != 0) { + p_tmp = getparentprocess(c); + if (istmuxserver(p_tmp)) + c = gettmuxclientpid(c); + else + c = p_tmp; + } return (int)c; } +int +istmuxserver(pid_t p) +{ + char path[256]; + char name[15]; + FILE* stat; + + snprintf(path, sizeof(path) - 1, "/proc/%u/stat", (unsigned)p); + if (!(stat = fopen(path, "r"))) + return 0; + fscanf(stat, "%*u (%12[^)])", name); + fclose(stat); + return (strcmp(name, "tmux: server") == 0); +} + +long +gettmuxclientpid(long shellpid) +{ + long volatile panepid, clientpid; + FILE* list = popen("tmux list-clients -F '#{pane_pid} #{client_pid}'", "r"); + if (!list) + return 0; + while (!feof(list) && panepid != shellpid) + fscanf(list, "%ld %ld\n", &panepid, &clientpid); + pclose(list); + return clientpid; +} + Client * termforwin(const Client *w) {