commit 68a3980

wf  ·  2026-04-17 12:35:14 +0000 UTC
parent 377191e
Utilize helper functions, fix resize_absolute
2 files changed,  +18, -12
M ipc.c
+1, -1
1@@ -20,7 +20,7 @@ static const struct command commands[] = {
2 	{ "move",                cmd_move,                2, false },
3 	{ "move_absolute",       cmd_move_absolute,       2, false },
4 	{ "resize",              cmd_resize,              2, false },
5-	{ "resize_absolute",     cmd_resize,              2, false },
6+	{ "resize_absolute",     cmd_resize_absolute,     2, false },
7 	{ "teleport",            cmd_teleport,            4, false },
8 	{ "center",              cmd_center,              0, false },
9 	{ "fullscreen",          cmd_fullscreen,          0, false },
M ipc.c
+17, -11
 1@@ -22,6 +22,11 @@ fn_int(char *s) {
 2 	return atoi(s);
 3 }
 4 
 5+static int
 6+fn_uint(char *s) {
 7+	return strtoul(s, NULL, 0);
 8+}
 9+
10 static uint32_t
11 fn_hex(char *s) {
12 	if (s[0] == '#') s++;
13@@ -82,7 +87,7 @@ ipc_move(char **arg) {
14 		wm.cur->height = geom.height;
15 	}
16 
17-	swc_window_set_position(wm.cur->win, wm.cur->x + atoi(arg[1]), wm.cur->y + atoi(arg[2]));
18+	swc_window_set_position(wm.cur->win, wm.cur->x + fn_int(arg[1]), wm.cur->y + fn_int(arg[2]));
19 
20 	return (status){ true, "" };
21 }
22@@ -92,7 +97,7 @@ ipc_move_absolute(char **arg) {
23 	if (arg[1] == NULL || arg[2] == NULL || !wm.cur)
24 		return (status){ false, "" };
25 
26-	swc_window_set_position(wm.cur->win, atoi(arg[1]), atoi(arg[2]));
27+	swc_window_set_position(wm.cur->win, fn_int(arg[1]), fn_int(arg[2]));
28 
29 	return (status){ true, "" };
30 }
31@@ -110,7 +115,7 @@ ipc_resize(char **arg) {
32 		wm.cur->height = geom.height;
33 	}
34 
35-	swc_window_set_size(wm.cur->win, wm.cur->width + strtoul(arg[1], NULL, 0), wm.cur->height + strtoul(arg[2], NULL, 0));
36+	swc_window_set_size(wm.cur->win, wm.cur->width + fn_uint(arg[1]), wm.cur->height + fn_uint(arg[2]));
37 
38 	return (status){ true, "" };
39 }
40@@ -120,7 +125,8 @@ ipc_resize_absolute(char **arg) {
41 	if (arg[1] == NULL || arg[2] == NULL || !wm.cur)
42 		return (status){ false, "" };
43 
44-	swc_window_set_size(wm.cur->win, strtoul(arg[1], NULL, 0), strtoul(arg[2], NULL, 0));
45+	_inf("Meow");
46+	swc_window_set_size(wm.cur->win, fn_uint(arg[1]), fn_uint(arg[2]));
47 
48 	return (status){ true, "" };
49 }
50@@ -132,10 +138,10 @@ ipc_teleport(char **arg) {
51 		return (status){ false, "" };
52 
53 	struct swc_rectangle rect = {
54-		.x      = atoi(arg[1]),
55-		.y      = atoi(arg[2]),
56-		.width  = strtoul(arg[3], NULL, 0),
57-		.height = strtoul(arg[4], NULL, 0)
58+		.x      = fn_int(arg[1]),
59+		.y      = fn_int(arg[2]),
60+		.width  = fn_uint(arg[3]),
61+		.height = fn_uint(arg[4])
62 	};
63 
64 	swc_window_set_geometry(wm.cur->win, &rect);
65@@ -283,7 +289,7 @@ ipc_workspace(char **arg) {
66 	if (arg[1] == NULL)
67 		return (status){ false, "" };
68 
69-	ws_go_to(atoi(arg[1]));
70+	ws_go_to(fn_int(arg[1]));
71 
72 	return (status){ true, "" };
73 }
74@@ -293,7 +299,7 @@ ipc_send_workspace(char **arg) {
75 	if (arg[1] == NULL || !wm.cur)
76 		return (status){ false, "" };
77 
78-	ws_move_to(atoi(arg[1]));
79+	ws_move_to(fn_int(arg[1]));
80 
81 	return (status){ true, "" };
82 }
83@@ -436,7 +442,7 @@ ipc_config(char **arg) {
84 	if (arg[1] == NULL || arg[2] == NULL)
85 		return (status){ false, "" };
86 
87-	enum cmd cmd = atoi(arg[1]);
88+	enum cmd cmd = fn_int(arg[1]);
89 	switch (cmd) {
90 		case cmd_modkey:
91 			; /* smh */