-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdwm-swallowemacsclient-6.2.diff
104 lines (99 loc) · 2.4 KB
/
dwm-swallowemacsclient-6.2.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
diff --git a/config.def.h b/config.def.h
index 4c0b25c..bdbee04 100644
--- a/config.def.h
+++ b/config.def.h
@@ -19,6 +19,10 @@ static const char *colors[][3] = {
[SchemeSel] = { col_gray4, col_cyan, col_cyan },
};
+/* swallow emacs */
+static const char emacsclient[] = "emacsclient";
+static const char emacsname[] = "emacs@";
+
/* tagging */
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
diff --git a/dwm.c b/dwm.c
index ddeb2b9..329da8b 100644
--- a/dwm.c
+++ b/dwm.c
@@ -240,6 +240,9 @@ static int xerrordummy(Display *dpy, XErrorEvent *ee);
static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void zoom(const Arg *arg);
+static pid_t getchildprocess(pid_t p);
+static pid_t getyoungestchild(pid_t p);
+static int containsemacsclient(pid_t p);
static pid_t getparentprocess(pid_t p);
static int isdescprocess(pid_t p, pid_t c);
static Client *swallowingclient(Window w);
@@ -431,6 +434,63 @@ attachstack(Client *c)
c->mon->stack = c;
}
+pid_t
+getchildprocess(pid_t p)
+{
+ unsigned int v = 0;
+#ifdef __linux__
+ FILE *f;
+ char buf[256];
+ snprintf(buf, sizeof(buf) - 1, "pgrep -P %u", (unsigned) p);
+
+ if(!(f = popen(buf, "r")))
+ return 0;
+
+ fscanf(f, "%u", &v);
+ pclose(f);
+#endif
+
+ return (pid_t) v;
+}
+int
+containsemacsclient(pid_t p)
+{
+ unsigned int young = getyoungestchild(p);
+
+ if (!young)
+ return 0;
+
+ FILE *f;
+ char buf[256];
+
+ snprintf(buf, sizeof(buf) - 1, "ps -p %u -o command=", young);
+
+ if(!(f = popen(buf, "r")))
+ return 0;
+
+ char pidname[256];
+ fscanf(f, "%s", pidname);
+ pclose(f);
+
+ return strstr(pidname, emacsclient) != NULL;
+}
+
+pid_t
+getyoungestchild(pid_t p)
+{
+ unsigned int young = getchildprocess(p);
+ unsigned int tmp;
+
+ if (!young)
+ return 0;
+ while ((tmp = getchildprocess(young))) {
+ young = tmp;
+ }
+
+ return young;
+}
+
+
void
swallow(Client *p, Client *c)
{
@@ -2226,7 +2286,9 @@ termforwin(const Client *w)
for (m = mons; m; m = m->next) {
for (c = m->clients; c; c = c->next) {
- if (c->isterminal && !c->swallowing && c->pid && isdescprocess(c->pid, w->pid))
+ if (c->isterminal && !c->swallowing && c->pid &&
+ (isdescprocess(c->pid, w->pid) ||
+ (containsemacsclient(c->pid) && (strstr(w->name,emacsname)))))
return c;
}
}