commit f9fedd5
wf
·
2026-05-03 17:44:00 +0000 UTC
parent 706fe0e
Fix segfault on quit, add window title handler
4 files changed,
+34,
-13
+1,
-0
1@@ -86,6 +86,7 @@ struct wm {
2 struct grab grab;
3 uint8_t ws;
4 uint32_t last_id;
5+ bool running;
6 };
7
8 #endif /* TYPES_H */
+23,
-11
1@@ -19,6 +19,7 @@ static void new_screen(struct swc_screen *);
2 static void new_window(struct swc_window *);
3 static void on_win_destroy(void *);
4 static void on_win_entered(void *);
5+static void on_win_title(void *);
6 static void on_scr_destroy(void *);
7 static void on_scr_geometry(void *);
8 static bool is_ws_client(const struct client *, const struct screen *);
9@@ -62,7 +63,8 @@ static struct swc_manager mgr = {
10
11 static struct swc_window_handler win_handler = {
12 .destroy = on_win_destroy,
13- .entered = on_win_entered
14+ .entered = on_win_entered,
15+ .title_changed = on_win_title
16 };
17
18 static struct swc_screen_handler scr_handler = {
19@@ -122,7 +124,7 @@ ipc_handler(int fd, uint32_t mask, void *data) {
20 int afd = accept(sfd, NULL, NULL);
21 if (afd == -1) {
22 _wrn("couldn't accept incoming connection on IPC socket: %s", strerror(errno));
23- goto ipcerr;
24+ goto end;
25 }
26
27 char buf[MAXSIZE];
28@@ -131,13 +133,13 @@ ipc_handler(int fd, uint32_t mask, void *data) {
29 if ((n = read(afd, buf, sizeof(buf) - 1)) < 0) {
30 /* read error */
31 _wrn("couldn't read from IPC socket: %s", strerror(errno));
32- goto ipcerr;
33+ goto end;
34 }
35
36 if (n == 0) {
37 /* EOF */
38 _wrn("unexpected EOF on IPC socket: %s", strerror(errno));
39- goto ipcerr;
40+ goto end;
41 }
42
43 if (n > 0) {
44@@ -156,20 +158,20 @@ ipc_handler(int fd, uint32_t mask, void *data) {
45 argv[argc] = NULL;
46
47 if (argc == 0)
48- goto ipcerr;
49+ goto end;
50
51 int cmd = atoi(argv[0]);
52 if (cmd < 0 || cmd > cmd_last) {
53 _wrn("IPC command index out of bounds");
54- goto ipcerr;
55+ goto end;
56 }
57
58 /* TODO: this is hard to debug */
59 if (!cmd_handler[cmd]) {
60 _wrn("no such command #%d", cmd);
61- goto ipcerr;
62+ goto end;
63 }
64-
65+
66 status s = cmd_handler[cmd](argv);
67 char answer[MAXSIZE];
68 snprintf(answer, MAXSIZE * sizeof(char), "%d %s", s.ok, s.msg);
69@@ -177,7 +179,7 @@ ipc_handler(int fd, uint32_t mask, void *data) {
70 if (send(afd, answer, strlen(answer), 0) == -1)
71 _wrn("couldn't send answer to client");
72 }
73-ipcerr:
74+end:
75 close(afd);
76 return 0;
77 }
78@@ -273,6 +275,8 @@ setup(void) {
79 signal(SIGINT, sig_handler);
80 signal(SIGTERM, sig_handler);
81 signal(SIGQUIT, sig_handler);
82+
83+ wm.running = true;
84 }
85
86 void
87@@ -299,7 +303,6 @@ cleanup(void) {
88
89 free(decor);
90
91- wl_display_terminate(wm.dpy);
92 close(sfd);
93 unlink(SOCK_PATH);
94 }
95@@ -679,6 +682,14 @@ on_win_destroy(void *data) {
96 focus(next);
97 }
98
99+
100+static void
101+on_win_title(void *data) {
102+ struct client *c = data;
103+
104+ decorate(c, (c == wm.cur));
105+}
106+
107 static void
108 on_scr_destroy(void *data) {
109 struct screen *s = data;
110@@ -775,7 +786,8 @@ main(int argc, char **argv) {
111 }
112
113 wl_display_run(wm.dpy);
114- cleanup();
115+ if (!wm.running)
116+ cleanup();
117
118 free(conf_path);
119 return 1;
+2,
-1
1@@ -518,6 +518,7 @@ ipc_config(char **arg) {
2 status
3 ipc_quit(char **arg) {
4 UNUSED(arg);
5- cleanup();
6+ wm.running = false;
7+ wl_display_terminate(wm.dpy);
8 return (status){ true, "" }; /* NOTREACHED */
9 }
+8,
-1
1@@ -2,10 +2,15 @@
2 #include <stdlib.h>
3 #include <stdarg.h>
4
5+#include <wayland-server.h>
6+
7 #include "howl.h"
8+#include "types.h"
9
10 extern void cleanup(void);
11
12+extern struct wm wm;
13+
14 void
15 _inf(const char *msg, ...) {
16 va_list list;
17@@ -47,6 +52,8 @@ _err(int ret, const char *msg, ...) {
18 fputc('\n', stderr);
19 fflush(stderr);
20
21- cleanup();
22+ wm.running = false;
23+ if (wm.dpy)
24+ wl_display_terminate(wm.dpy);
25 exit(ret);
26 }