commit 58b84ec

wf  ·  2026-04-06 09:40:48 +0000 UTC
parent 588bd94
Fix SIGCHLD bug and clean up code
3 files changed,  +36, -97
M howl.c
+0, -1
1@@ -12,7 +12,6 @@ TODO
2 
3  * Expose compositor internals through the client
4  * Eyecandy: titlebars and double borders
5- * Clean up the codebase
6 
7 CREDITS
8 -------
+3, -2
 1@@ -77,6 +77,7 @@ ipc_msg(const struct command *cmd, int argc, char **argv) {
 2 		data[0] = b0;
 3 	}
 4 
 5+	/* XXX: this is a horrible mess */
 6 	int o = cmd->config ? 2 : 1;
 7 	for (int i = 0; i < argc - 2; i++)
 8 		data[i + o] = argv[i + 2];
 9@@ -105,7 +106,7 @@ main(int argc, char **argv) {
10 	for (int i = 0; i < (sizeof commands / sizeof commands[0]); i++) {
11 		if (strcmp(commands[i].name, argv[1]) == 0) {
12 			if (commands[i].argc != argc - 2) {
13-				fprintf(stderr, "wrong number of arguments for %s (need %d)\n", commands[i].name, commands[i].argc);
14+				fprintf(stderr, "Wrong number of arguments for %s (need %d)\n", commands[i].name, commands[i].argc);
15 				return 1;
16 			}
17 			ipc_msg(&commands[i], argc, argv);
18@@ -113,6 +114,6 @@ main(int argc, char **argv) {
19 		}
20 	}
21 	
22-	fprintf(stderr, "no such command %s\n", argv[1]);
23+	fprintf(stderr, "No such command: %s\n", argv[1]);
24 	return 1;
25 }
M howl.c
+33, -94
  1@@ -21,8 +21,6 @@ static void on_win_destroy(void *);
  2 static void on_win_entered(void *);
  3 static void on_scr_destroy(void *);
  4 static bool is_ws_client(const struct client *, const struct screen *);
  5-static void mouse_move(void *, uint32_t, uint32_t, uint32_t);
  6-static void mouse_resize(void *, uint32_t, uint32_t, uint32_t);
  7 
  8 extern void ipc_move(char **);
  9 extern void ipc_move_absolute(char **);
 10@@ -179,39 +177,6 @@ setup_ipc(void) {
 11 	_inf("set up IPC socket");
 12 }
 13 
 14-static void
 15-sig_handler(int s) {
 16-	_wrn("caught deadly signal, exiting!");
 17-	if (wm.dpy) {		
 18-		swc_finalize();
 19-		wl_display_terminate(wm.dpy);
 20-	}
 21-}
 22-
 23-static void
 24-load_config(char *conf_path) {
 25-	if (fork() == 0) {
 26-		setsid();
 27-		execl("/bin/sh", "sh", conf_path, NULL);
 28-	}
 29-}
 30-
 31-void
 32-bind_handler(void *data, uint32_t time, uint32_t value, uint32_t state) {
 33-	UNUSED(time);
 34-	UNUSED(value);
 35-
 36-	if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
 37-		return;
 38-
 39-	char *const *cmd = (char *const *)data;
 40-	if (fork() == 0) {
 41-		setsid();
 42-		execvp(cmd[0], cmd);
 43-		_exit(127);
 44-	}
 45-}
 46-
 47 static void
 48 setup(void) {
 49 	char *conf_path = malloc(MAXSIZE * sizeof(char));
 50@@ -254,6 +219,15 @@ setup(void) {
 51 	signal(SIGQUIT, sig_handler);
 52 }
 53 
 54+static void
 55+sig_handler(int s) {
 56+	_wrn("caught deadly signal, exiting!");
 57+	if (wm.dpy) {		
 58+		swc_finalize();
 59+		wl_display_terminate(wm.dpy);
 60+	}
 61+}
 62+
 63 void
 64 cleanup(void) {
 65 	wl_display_terminate(wm.dpy);
 66@@ -261,6 +235,30 @@ cleanup(void) {
 67 	unlink(SOCK_PATH);
 68 }
 69 
 70+static void
 71+load_config(char *conf_path) {
 72+	if (fork() == 0) {
 73+		setsid();
 74+		execl("/bin/sh", "sh", conf_path, NULL);
 75+	}
 76+}
 77+
 78+void
 79+bind_handler(void *data, uint32_t time, uint32_t value, uint32_t state) {
 80+	UNUSED(time);
 81+	UNUSED(value);
 82+
 83+	if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
 84+		return;
 85+
 86+	char *const *cmd = (char *const *)data;
 87+	if (fork() == 0) {
 88+		setsid();
 89+		execvp(cmd[0], cmd);
 90+		_exit(127);
 91+	}
 92+}
 93+
 94 static void
 95 focus(struct client *c) {
 96 	if (wm.cur)
 97@@ -344,65 +342,6 @@ ws_move_to(uint8_t ws) {
 98 	focus(next);
 99 }
100 
101-static void
102-mouse_move(void *data, uint32_t time, uint32_t value, uint32_t state) {
103-	UNUSED(data);
104-	UNUSED(time);
105-	UNUSED(value);
106-
107-	if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
108-		if (!wm.cur)
109-			return;
110-
111-		_inf("I am moving with my mouse");
112-
113-		wm.grab.active = true;
114-		wm.grab.resize = false;
115-		wm.grab.client = wm.cur;
116-
117-		swc_window_begin_move(wm.grab.client->win);
118-	} else {
119-		if (!wm.grab.active || wm.grab.resize || !wm.grab.client)
120-			return;
121-
122-		_inf("I am no longer moving with my mouse.");
123-
124-		swc_window_end_move(wm.grab.client->win);
125-		wm.grab.active = false;
126-		wm.grab.client = NULL;
127-	}
128-}
129-
130-static void
131-mouse_resize(void *data, uint32_t time, uint32_t value, uint32_t state) {
132-	UNUSED(data);
133-	UNUSED(time);
134-	UNUSED(value);
135-
136-	if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
137-		if (!wm.cur)
138-			return;
139-
140-		wm.grab.active = true;
141-		wm.grab.resize = true;
142-		wm.grab.client = wm.cur;
143-
144-		swc_window_begin_resize(
145-			wm.grab.client->win,
146-			SWC_WINDOW_EDGE_RIGHT | SWC_WINDOW_EDGE_BOTTOM
147-		);
148-	} else {
149-		if (!wm.grab.active || !wm.grab.resize || !wm.grab.client)
150-			return;
151-
152-		swc_window_end_resize(wm.grab.client->win);
153-
154-		wm.grab.active = false;
155-		wm.grab.resize = false;
156-		wm.grab.client = NULL;
157-	}
158-}
159-
160 static void
161 new_screen(struct swc_screen *scr) {
162 	struct screen *s;