This repository has been archived by the owner on Nov 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dwm.c.rej
280 lines (266 loc) · 6.39 KB
/
dwm.c.rej
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
--- dwm.c
+++ dwm.c
@@ -30,6 +30,7 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <sys/epoll.h>
#include <X11/cursorfont.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
@@ -67,9 +68,21 @@
enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
+typedef struct TagState TagState;
+struct TagState {
+ int selected;
+ int occupied;
+ int urgent;
+};
+
+typedef struct ClientState ClientState;
+struct ClientState {
+ int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
+};
+
typedef union {
- int i;
- unsigned int ui;
+ long i;
+ unsigned long ui;
float f;
const void *v;
} Arg;
@@ -97,6 +110,7 @@
Client *snext;
Monitor *mon;
Window win;
+ ClientState prevstate;
};
typedef struct {
@@ -111,8 +125,10 @@
void (*arrange)(Monitor *);
} Layout;
+
struct Monitor {
char ltsymbol[16];
+ char lastltsymbol[16];
float mfact;
int nmaster;
int num;
@@ -122,14 +138,17 @@
unsigned int seltags;
unsigned int sellt;
unsigned int tagset[2];
+ TagState tagstate;
int showbar;
int topbar;
Client *clients;
Client *sel;
+ Client *lastsel;
Client *stack;
Monitor *next;
Window barwin;
const Layout *lt[2];
+ const Layout *lastlt;
};
typedef struct {
@@ -175,6 +194,7 @@
static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
static void grabbuttons(Client *c, int focused);
static void grabkeys(void);
+static int handlexevent(struct epoll_event *ev);
static void incnmaster(const Arg *arg);
static void keypress(XEvent *e);
static void killclient(const Arg *arg);
@@ -201,8 +221,10 @@
static void setfocus(Client *c);
static void setfullscreen(Client *c, int fullscreen);
static void setlayout(const Arg *arg);
+static void setlayoutsafe(const Arg *arg);
static void setmfact(const Arg *arg);
static void setup(void);
+static void setupepoll(void);
static void seturgent(Client *c, int urg);
static void showhide(Client *c);
static void sigchld(int unused);
@@ -263,17 +285,27 @@
[UnmapNotify] = unmapnotify
};
static Atom wmatom[WMLast], netatom[NetLast];
+static int epoll_fd;
+static int dpy_fd;
static int running = 1;
static Cur *cursor[CurLast];
static Clr **scheme;
static Display *dpy;
static Drw *drw;
-static Monitor *mons, *selmon;
+static Monitor *mons, *selmon, *lastselmon;
static Window root, wmcheckwin;
+#include "ipc.h"
+
/* configuration, allows nested code to access above variables */
#include "config.h"
+#ifdef VERSION
+#include "IPCClient.c"
+#include "yajl_dumps.c"
+#include "ipc.c"
+#endif
+
/* compile-time check if all tags fit into an unsigned int bit array. */
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
@@ -492,6 +524,12 @@
XSync(dpy, False);
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
+
+ ipc_cleanup();
+
+ if (close(epoll_fd) < 0) {
+ fprintf(stderr, "Failed to close epoll file descriptor\n");
+ }
}
void
@@ -964,6 +1002,25 @@
}
}
+int
+handlexevent(struct epoll_event *ev)
+{
+ if (ev->events & EPOLLIN) {
+ XEvent ev;
+ while (running && XPending(dpy)) {
+ XNextEvent(dpy, &ev);
+ if (handler[ev.type]) {
+ handler[ev.type](&ev); /* call handler */
+ ipc_send_events(mons, &lastselmon, selmon);
+ }
+ }
+ } else if (ev-> events & EPOLLHUP) {
+ return -1;
+ }
+
+ return 0;
+}
+
void
incnmaster(const Arg *arg)
{
@@ -1373,12 +1430,40 @@
void
run(void)
{
- XEvent ev;
- /* main event loop */
+ int event_count = 0;
+ const int MAX_EVENTS = 10;
+ struct epoll_event events[MAX_EVENTS];
+
XSync(dpy, False);
- while (running && !XNextEvent(dpy, &ev))
- if (handler[ev.type])
- handler[ev.type](&ev); /* call handler */
+
+ /* main event loop */
+ while (running) {
+ event_count = epoll_wait(epoll_fd, events, MAX_EVENTS, -1);
+
+ for (int i = 0; i < event_count; i++) {
+ int event_fd = events[i].data.fd;
+ DEBUG("Got event from fd %d\n", event_fd);
+
+ if (event_fd == dpy_fd) {
+ // -1 means EPOLLHUP
+ if (handlexevent(events + i) == -1)
+ return;
+ } else if (event_fd == ipc_get_sock_fd()) {
+ ipc_handle_socket_epoll_event(events + i);
+ } else if (ipc_is_client_registered(event_fd)){
+ if (ipc_handle_client_epoll_event(events + i, mons, &lastselmon, selmon,
+ tags, LENGTH(tags), layouts, LENGTH(layouts)) < 0) {
+ fprintf(stderr, "Error handling IPC event on fd %d\n", event_fd);
+ }
+ } else {
+ fprintf(stderr, "Got event from unknown fd %d, ptr %p, u32 %d, u64 %lu",
+ event_fd, events[i].data.ptr, events[i].data.u32,
+ events[i].data.u64);
+ fprintf(stderr, " with events %d\n", events[i].events);
+ return;
+ }
+ }
+ }
}
void
@@ -1512,6 +1597,18 @@
drawbar(selmon);
}
+void
+setlayoutsafe(const Arg *arg)
+{
+ const Layout *ltptr = (Layout *)arg->v;
+ if (ltptr == 0)
+ setlayout(arg);
+ for (int i = 0; i < LENGTH(layouts); i++) {
+ if (ltptr == &layouts[i])
+ setlayout(arg);
+ }
+}
+
/* arg > 1.0 will set mfact absolutely */
void
setmfact(const Arg *arg)
@@ -1595,8 +1692,37 @@
XSelectInput(dpy, root, wa.event_mask);
grabkeys();
focus(NULL);
+ setupepoll();
}
+void
+setupepoll(void)
+{
+ epoll_fd = epoll_create1(0);
+ dpy_fd = ConnectionNumber(dpy);
+ struct epoll_event dpy_event;
+
+ // Initialize struct to 0
+ memset(&dpy_event, 0, sizeof(dpy_event));
+
+ DEBUG("Display socket is fd %d\n", dpy_fd);
+
+ if (epoll_fd == -1) {
+ fputs("Failed to create epoll file descriptor", stderr);
+ }
+
+ dpy_event.events = EPOLLIN;
+ dpy_event.data.fd = dpy_fd;
+ if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, dpy_fd, &dpy_event)) {
+ fputs("Failed to add display file descriptor to epoll", stderr);
+ close(epoll_fd);
+ exit(1);
+ }
+
+ if (ipc_init(ipcsockpath, epoll_fd, ipccommands, LENGTH(ipccommands)) < 0) {
+ fputs("Failed to initialize IPC\n", stderr);
+ }
+}
void
seturgent(Client *c, int urg)
@@ -1998,10 +2124,18 @@
void
updatetitle(Client *c)
{
+ char oldname[sizeof(c->name)];
+ strcpy(oldname, c->name);
+
if (!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name))
gettextprop(c->win, XA_WM_NAME, c->name, sizeof c->name);
if (c->name[0] == '\0') /* hack to mark broken clients */
strcpy(c->name, broken);
+
+ for (Monitor *m = mons; m; m = m->next) {
+ if (m->sel == c && strcmp(oldname, c->name) != 0)
+ ipc_focused_title_change_event(m->num, c->win, oldname, c->name);
+ }
}
void