commit 0c7e49a

wf  ·  2026-03-28 15:42:06 +0000 UTC
parent 6db1ccc
Fix IPC bug
4 files changed,  +34, -12
M README
M ipc.c
M README
+0, -1
1@@ -13,7 +13,6 @@ dependencies
2 todo
3 ----
4 
5- - fix client segfault
6  - document IPC interface
7 
8 [1]: https://git.sr.ht/~shrub900/neuswc
+3, -6
 1@@ -49,20 +49,17 @@ main(int argc, char **argv) {
 2 		return 1;
 3 	}
 4 
 5-	int u_argc = argc - 2;
 6-	char **u_argv = argv + 2;
 7-
 8 	for (int i = 0; i < (sizeof commands / sizeof commands[0]); i++) {
 9 		if (strcmp(commands[i].name, argv[1]) == 0) {
10-			if (commands[i].argc != u_argc) {
11+			if (commands[i].argc != argc - 2) {
12 				fprintf(stderr, "wrong number of arguments for %s (need %d)\n", commands[i].name, commands[i].argc);
13 				return 1;
14 			}
15-			ipc_msg(u_argv);
16+			ipc_msg(argv + 1);
17 			return 0;
18 		}
19 	}
20 	
21-	fprintf(stderr, "no such command %s", argv[0]);
22+	fprintf(stderr, "no such command %s\n", argv[1]);
23 	return 1;
24 }
+1, -1
1@@ -22,7 +22,7 @@ extern int ipc_focus_color(char **);
2 extern int ipc_unfocus_color(char **);
3 extern int ipc_border_width(char **);
4 
5-static const struct command commands[MAXSIZE] = {
6+static const struct command commands[] = {
7 	{ "move",      2,  false,  do_move      },
8 	{ "resize",    2,  false,  do_resize    },
9 	{ "teleport",  4,  false,  do_teleport  },
M ipc.c
+30, -4
 1@@ -15,7 +15,15 @@ int
 2 do_move(char **arg) {
 3 	if (arg[0] == NULL || arg[1] == NULL) return 1;
 4 
 5-	swc_window_set_position(wm.cur->win, atoi(arg[0]), atoi(arg[1]));
 6+	struct swc_rectangle geom;
 7+	if (swc_window_get_geometry(wm.cur->win, &geom)) {
 8+		wm.cur->x = geom.x;
 9+		wm.cur->y = geom.y;
10+		wm.cur->width = geom.width;
11+		wm.cur->height = geom.height;
12+	}
13+
14+	swc_window_set_position(wm.cur->win, wm.cur->x + atoi(arg[0]), wm.cur->y + atoi(arg[1]));
15 	return 0;
16 }
17 
18@@ -23,7 +31,15 @@ int
19 do_resize(char **arg) {
20 	if (arg[0] == NULL || arg[1] == NULL) return 1;
21 
22-	swc_window_set_size(wm.cur->win, strtoul(arg[0], NULL, 0), strtoul(arg[1], NULL, 0));
23+	struct swc_rectangle geom;
24+	if (swc_window_get_geometry(wm.cur->win, &geom)) {
25+		wm.cur->x = geom.x;
26+		wm.cur->y = geom.y;
27+		wm.cur->width = geom.width;
28+		wm.cur->height = geom.height;
29+	}
30+
31+	swc_window_set_size(wm.cur->win, wm.cur->width + strtoul(arg[0], NULL, 0), wm.cur->height + strtoul(arg[1], NULL, 0));
32 	return 0;
33 }
34 
35@@ -38,6 +54,7 @@ do_teleport(char **arg) {
36 		.width  = strtoul(arg[2], NULL, 0),
37 		.height = strtoul(arg[3], NULL, 0)
38 	};
39+
40 	swc_window_set_geometry(wm.cur->win, &rect);
41 	return 0;
42 }
43@@ -46,10 +63,18 @@ int
44 do_center(char **arg) {
45 	UNUSED(arg);
46 
47+	struct swc_rectangle geom;
48+	if (swc_window_get_geometry(wm.cur->win, &geom)) {
49+		wm.cur->x = geom.x;
50+		wm.cur->y = geom.y;
51+		wm.cur->width = geom.width;
52+		wm.cur->height = geom.height;
53+	}
54+
55 	swc_window_set_position(
56 		wm.cur->win,
57-		(wm.scr->width - wm.cur->width)  / 2,
58-		(wm.scr->height - wm.cur->height) / 2
59+		wm.scr->width / 2 - wm.cur->width / 2,
60+		wm.scr->height / 2 - wm.cur->height / 2
61 	);
62 	return 0;
63 }
64@@ -89,6 +114,7 @@ get_geometry(char **arg) {
65 	struct swc_rectangle geom;
66 	if (swc_window_get_geometry(wm.cur->win, &geom)) {
67 		printf("%d %d %u %u\n", geom.x, geom.y, geom.width, geom.height);  
68+		fflush(stdout);
69 		return 0;
70 	}
71 	return 1;