commit 99ec8e9
0uppy
·
2026-03-13 20:04:31 +0000 UTC
parent 9459f36
Added a variadic macro to avoid keeping calling 2 to 4 lines of (void)blahblahblah; Thank you Seo (https://codeberg.org/wf) for the suggestion :)
1 files changed,
+389,
-424
+389,
-424
1@@ -1,4 +1,3 @@
2-#include <asm-generic/errno.h>
3 #include <signal.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6@@ -14,6 +13,8 @@
7 #include "include/util.h"
8 #include "include/slgro.h"
9
10+#define VOID(...) (void)(__VA_ARGS__)
11+
12 static void focus(struct client* c);
13 static struct client* first_client(struct screen* s);
14 static bool is_ws_client(const struct client* c, const struct screen* s);
15@@ -26,431 +27,409 @@ static void sync_window_visibility(void);
16
17 struct wm wm;
18 const struct swc_manager manager = {
19- .new_screen = new_screen, .new_window = new_window, .new_device = new_device,
20+.new_screen = new_screen, .new_window = new_window, .new_device = new_devic
21+e,
22 };
23 struct swc_window_handler window_handler = {
24- .destroy = on_win_destroy, .entered = on_win_entered,
25+.destroy = on_win_destroy, .entered = on_win_entered,
26 };
27 struct swc_screen_handler screen_handler = {
28- .destroy = on_screen_destroy,
29+.destroy = on_screen_destroy,
30 };
31
32 static void focus(struct client* c)
33 {
34- if (wm.sel_client)
35- swc_window_set_border(
36- wm.sel_client->win,
37- cfg.border_col_normal, cfg.border_width,
38- 0, 0
39- );
40-
41- if (c)
42- swc_window_set_border(
43- c->win,
44- cfg.border_col_active, cfg.border_width,
45- 0, 0
46- );
47-
48- swc_window_focus(c ? c->win : NULL);
49- wm.sel_client = c;
50+if (wm.sel_client)
51+swc_window_set_border(
52+wm.sel_client->win,
53+cfg.border_col_normal, cfg.border_width,
54+0, 0
55+);
56+
57+if (c)
58+swc_window_set_border(
59+c->win,
60+cfg.border_col_active, cfg.border_width,
61+0, 0
62+);
63+
64+swc_window_focus(c ? c->win : NULL);
65+wm.sel_client = c;
66 }
67
68 static struct client* first_client(struct screen* s)
69 {
70- struct client* c;
71+struct client* c;
72
73- wl_list_for_each(c, &wm.clients, link) {
74- if (is_ws_client(c, s))
75- return c;
76- }
77+wl_list_for_each(c, &wm.clients, link) {
78+if (is_ws_client(c, s))
79+return c;
80+}
81
82- return NULL;
83+return NULL;
84 }
85
86 static bool is_ws_client(const struct client* c, const struct screen* s)
87 {
88- return c && c->ws == wm.ws && (!s || c->scr == s);
89+return c && c->ws == wm.ws && (!s || c->scr == s);
90 }
91
92 static void on_screen_destroy(void* data)
93 {
94- struct screen* s = data;
95+struct screen* s = data;
96
97- if (!s)
98- return;
99+if (!s)
100+return;
101
102- wl_list_remove(&s->link);
103+wl_list_remove(&s->link);
104
105- if (wm.sel_screen == s) {
106- if (wl_list_empty(&wm.screens))
107- wm.sel_screen = NULL;
108- else
109- wm.sel_screen = wl_container_of(wm.screens.next, wm.sel_screen, link);
110- }
111+if (wm.sel_screen == s) {
112+if (wl_list_empty(&wm.screens))
113+wm.sel_screen = NULL;
114+else
115+wm.sel_screen = wl_container_of(wm.screens.next, wm.sel_scr
116+een, link);
117+}
118
119- free(s);
120+free(s);
121 }
122
123 static void on_win_destroy(void* data)
124 {
125- struct client* c = data;
126- struct client* next;
127+struct client* c = data;
128+struct client* next;
129
130- if (!c)
131- return;
132+if (!c)
133+return;
134
135- if (wm.grab.active && wm.grab.c == c) {
136- wm.grab.active = false;
137- wm.grab.c = NULL;
138- }
139+if (wm.grab.active && wm.grab.c == c) {
140+wm.grab.active = false;
141+wm.grab.c = NULL;
142+}
143
144- if (wm.sel_client == c) {
145- wm.sel_client = NULL;
146- }
147+if (wm.sel_client == c)
148+wm.sel_client = NULL;
149
150- wl_list_remove(&c->link);
151- free(c);
152+wl_list_remove(&c->link);
153+free(c);
154
155- next = first_client(wm.sel_screen);
156- if (!next)
157- next = first_client(NULL);
158- focus(next);
159+next = first_client(wm.sel_screen);
160+if (!next)
161+next = first_client(NULL);
162+focus(next);
163 }
164
165 static void on_win_entered(void* data)
166 {
167- if (wm.grab.active)
168- return;
169+if (wm.grab.active)
170+return;
171
172- struct client* c = data;
173- if (!is_ws_client(c, NULL))
174- return;
175+struct client* c = data;
176+if (!is_ws_client(c, NULL))
177+return;
178
179- focus(c);
180+focus(c);
181 }
182
183 static void setup(void)
184 {
185- /* display */
186- wm.dpy = wl_display_create();
187- if (!wm.dpy)
188- die(EXIT_FAILURE, "wl_display_create failed");
189-
190- /* variables */
191- wl_list_init(&wm.screens);
192- wl_list_init(&wm.clients);
193- wm.sel_client = NULL;
194- wm.sel_screen = NULL;
195- wm.grab.active = false;
196- wm.grab.resize = false;
197- wm.grab.c = NULL;
198- wm.ws = 1;
199-
200- /* event loop */
201- wm.ev_loop = wl_display_get_event_loop(wm.dpy);
202- if (!swc_initialize(wm.dpy, wm.ev_loop, &manager))
203- die(EXIT_FAILURE, "swc_initialize failed\n");
204-
205- setup_binds();
206-
207- /* display socket */
208- const char* sock;
209- sock = wl_display_add_socket_auto(wm.dpy);
210- if (!sock)
211- die(EXIT_FAILURE, "wl_display_add_socket_auto failed\n");
212- setenv("WAYLAND_DISPLAY", sock, 1);
213- _log(stderr, "WAYLAND_DISPLAY=%s\n", sock);
214-
215- /* signals */
216- signal(SIGINT, sig_handler);
217- signal(SIGTERM, sig_handler);
218- signal(SIGQUIT, sig_handler);
219+wm.dpy = wl_display_create();
220+if (!wm.dpy)
221+die(EXIT_FAILURE, "wl_display_create failed");
222+
223+wl_list_init(&wm.screens);
224+wl_list_init(&wm.clients);
225+wm.sel_client = NULL;
226+wm.sel_screen = NULL;
227+wm.grab.active = false;
228+wm.grab.resize = false;
229+wm.grab.c = NULL;
230+wm.ws = 1;
231+
232+wm.ev_loop = wl_display_get_event_loop(wm.dpy);
233+if (!swc_initialize(wm.dpy, wm.ev_loop, &manager))
234+die(EXIT_FAILURE, "swc_initialize failed\n");
235+
236+setup_binds();
237+
238+const char* sock;
239+sock = wl_display_add_socket_auto(wm.dpy);
240+if (!sock)
241+die(EXIT_FAILURE, "wl_display_add_socket_auto failed\n");
242+setenv("WAYLAND_DISPLAY", sock, 1);
243+_log(stderr, "WAYLAND_DISPLAY=%s\n", sock);
244+
245+signal(SIGINT, sig_handler);
246+signal(SIGTERM, sig_handler);
247+signal(SIGQUIT, sig_handler);
248 }
249
250 static void setup_binds(void)
251 {
252- for (size_t i = 0; i < LENGTH(binds); i++) {
253- const struct bind* b = &binds[i];
254- swc_add_binding(b->type, b->mods, b->ksym, b->fn, (void*)&b->arg);
255- }
256+for (size_t i = 0; i < LENGTH(binds); i++) {
257+const struct bind* b = &binds[i];
258+swc_add_binding(b->type, b->mods, b->ksym, b->fn, (void*)&b->arg);
259+}
260 }
261
262 static void sync_window_visibility(void)
263 {
264- struct client* c;
265+struct client* c;
266
267- wl_list_for_each(c, &wm.clients, link) {
268- if (c->ws == wm.ws)
269- swc_window_show(c->win);
270- else
271- swc_window_hide(c->win);
272- }
273+wl_list_for_each(c, &wm.clients, link) {
274+if (c->ws == wm.ws)
275+swc_window_show(c->win);
276+else
277+swc_window_hide(c->win);
278+}
279 }
280
281 void focus_next(void* data, uint32_t time, uint32_t value, uint32_t state)
282 {
283- (void)data;
284- (void)time;
285- (void)value;
286+VOID(data, time, value);
287
288- struct client* c = NULL;
289+struct client* c = NULL;
290
291- if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
292- return;
293+if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
294+return;
295
296- if (wl_list_empty(&wm.clients))
297- return;
298+if (wl_list_empty(&wm.clients))
299+return;
300
301- if (!wm.sel_client || !is_ws_client(wm.sel_client, wm.sel_screen)) {
302- c = first_client(wm.sel_screen);
303- if (!c)
304- c = first_client(NULL);
305- focus(c);
306- return;
307- }
308+if (!wm.sel_client || !is_ws_client(wm.sel_client, wm.sel_screen)) {
309+c = first_client(wm.sel_screen);
310+if (!c)
311+c = first_client(NULL);
312+focus(c);
313+return;
314+}
315
316- struct wl_list* start = wm.sel_client->link.next;
317- struct wl_list* it = start;
318+struct wl_list* start = wm.sel_client->link.next;
319+struct wl_list* it = start;
320
321- do {
322- if (it == &wm.clients)
323- it = wm.clients.next;
324- if (it == &wm.clients)
325- break;
326+do {
327+if (it == &wm.clients)
328+it = wm.clients.next;
329+if (it == &wm.clients)
330+break;
331
332- c = wl_container_of(it, c, link);
333- if (is_ws_client(c, wm.sel_screen)) {
334- focus(c);
335- return;
336- }
337- it = it->next;
338- } while (it != start);
339+c = wl_container_of(it, c, link);
340+if (is_ws_client(c, wm.sel_screen)) {
341+focus(c);
342+return;
343+}
344+it = it->next;
345+} while (it != start);
346
347- c = first_client(wm.sel_screen);
348- if (!c)
349- c = first_client(NULL);
350- focus(c);
351+c = first_client(wm.sel_screen);
352+if (!c)
353+c = first_client(NULL);
354+focus(c);
355 }
356
357 void focus_prev(void* data, uint32_t time, uint32_t value, uint32_t state)
358 {
359- struct client* c = NULL;
360+VOID(data, time, value);
361
362- (void)data;
363- (void)time;
364- (void)value;
365+struct client* c = NULL;
366
367- if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
368- return;
369+if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
370+return;
371
372- if (wl_list_empty(&wm.clients))
373- return;
374+if (wl_list_empty(&wm.clients))
375+return;
376
377- if (!wm.sel_client || !is_ws_client(wm.sel_client, wm.sel_screen)) {
378- c = first_client(wm.sel_screen);
379- if (!c)
380- c = first_client(NULL);
381- focus(c);
382- return;
383- }
384+if (!wm.sel_client || !is_ws_client(wm.sel_client, wm.sel_screen)) {
385+c = first_client(wm.sel_screen);
386+if (!c)
387+c = first_client(NULL);
388+focus(c);
389+return;
390+}
391
392- struct wl_list* start = wm.sel_client->link.prev;
393- struct wl_list* it = start;
394+struct wl_list* start = wm.sel_client->link.prev;
395+struct wl_list* it = start;
396
397- do {
398- if (it == &wm.clients)
399- it = wm.clients.prev;
400- if (it == &wm.clients)
401- break;
402+do {
403+if (it == &wm.clients)
404+it = wm.clients.prev;
405+if (it == &wm.clients)
406+break;
407
408- c = wl_container_of(it, c, link);
409- if (is_ws_client(c, wm.sel_screen)) {
410- focus(c);
411- return;
412- }
413- it = it->prev;
414- } while (it != start);
415+c = wl_container_of(it, c, link);
416+if (is_ws_client(c, wm.sel_screen)) {
417+focus(c);
418+return;
419+}
420+it = it->prev;
421+} while (it != start);
422
423- c = first_client(wm.sel_screen);
424- if (!c)
425- c = first_client(NULL);
426- focus(c);
427+c = first_client(wm.sel_screen);
428+if (!c)
429+c = first_client(NULL);
430+focus(c);
431 }
432
433 void kill_sel(void* data, uint32_t time, uint32_t value, uint32_t state)
434 {
435- (void)data;
436- (void)time;
437- (void)value;
438+VOID(data, time, value);
439
440- if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
441- return;
442+if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
443+return;
444
445- if (!wm.sel_client)
446- return;
447+if (!wm.sel_client)
448+return;
449
450- swc_window_close(wm.sel_client->win);
451+swc_window_close(wm.sel_client->win);
452 }
453
454 void fullscreen(void* data, uint32_t time, uint32_t value, uint32_t state)
455 {
456- struct swc_rectangle geom;
457+VOID(data, time, value);
458
459- (void)data;
460- (void)time;
461- (void)value;
462-
463- if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
464- return;
465+struct swc_rectangle geom;
466
467- if (!wm.sel_client)
468- return;
469+if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
470+return;
471
472- if (wm.sel_client->fullscreen) {
473- wm.sel_client->fullscreen = false;
474- swc_window_set_stacked(wm.sel_client->win);
475+if (!wm.sel_client)
476+return;
477
478- if (wm.sel_client->w > 0 && wm.sel_client->h > 0) {
479- geom.x = wm.sel_client->x;
480- geom.y = wm.sel_client->y;
481- geom.width = wm.sel_client->w;
482- geom.height = wm.sel_client->h;
483- swc_window_set_geometry(wm.sel_client->win, &geom);
484- }
485- return;
486- }
487+if (wm.sel_client->fullscreen) {
488+wm.sel_client->fullscreen = false;
489+swc_window_set_stacked(wm.sel_client->win);
490
491- if (!wm.sel_client->scr || !wm.sel_client->scr->scr)
492- return;
493+if (wm.sel_client->w > 0 && wm.sel_client->h > 0) {
494+geom.x = wm.sel_client->x;
495+geom.y = wm.sel_client->y;
496+geom.width = wm.sel_client->w;
497+geom.height = wm.sel_client->h;
498+swc_window_set_geometry(wm.sel_client->win, &geom);
499+}
500+return;
501+}
502
503- if (swc_window_get_geometry(wm.sel_client->win, &geom)) {
504- wm.sel_client->x = geom.x;
505- wm.sel_client->y = geom.y;
506- wm.sel_client->w = geom.width;
507- wm.sel_client->h = geom.height;
508- }
509+if (!wm.sel_client->scr || !wm.sel_client->scr->scr)
510+return;
511
512- wm.sel_client->fullscreen = true;
513- swc_window_set_fullscreen(wm.sel_client->win, wm.sel_client->scr->scr);
514+if (swc_window_get_geometry(wm.sel_client->win, &geom)) {
515+wm.sel_client->x = geom.x;
516+wm.sel_client->y = geom.y;
517+wm.sel_client->w = geom.width;
518+wm.sel_client->h = geom.height;
519 }
520
521-/* slgro - im sure i could have made this better but atleast this works rn so ig that's what matters,, ill work on simplifying this another time,.,.*/
522-void kb_move_x(void* data, uint32_t time, uint32_t value, uint32_t state) {
523-
524- (void)time;
525- (void)value;
526+wm.sel_client->fullscreen = true;
527+swc_window_set_fullscreen(wm.sel_client->win, wm.sel_client->scr->scr);
528+}
529
530- union arg* a = data;
531- struct swc_rectangle geom;
532+/* slgro - im sure i could have made this better but atleast this works rn so ig th
533+at's what matters,, ill work on simplifying this another time,.,.*/
534+void kb_move_x(void* data, uint32_t time, uint32_t value, uint32_t state)
535+{
536+VOID(time, value);
537
538- if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
539- return;
540+union arg* a = data;
541+struct swc_rectangle geom;
542
543- if (!wm.sel_client)
544- return;
545+if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
546+return;
547
548- if (swc_window_get_geometry(wm.sel_client->win, &geom)) {
549- geom.x += a->i;
550- swc_window_set_geometry(wm.sel_client->win, &geom);
551- }
552+if (!wm.sel_client)
553+return;
554
555+if (swc_window_get_geometry(wm.sel_client->win, &geom)) {
556+geom.x += a->i;
557+swc_window_set_geometry(wm.sel_client->win, &geom);
558+}
559 }
560
561-void kb_move_y(void* data, uint32_t time, uint32_t value, uint32_t state) {
562-
563- (void)time;
564- (void)value;
565-
566- union arg* a = data;
567- struct swc_rectangle geom;
568+void kb_move_y(void* data, uint32_t time, uint32_t value, uint32_t state)
569+{
570+VOID(time, value);
571
572- if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
573- return;
574+union arg* a = data;
575+struct swc_rectangle geom;
576
577- if (!wm.sel_client)
578- return;
579+if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
580+return;
581
582- if (swc_window_get_geometry(wm.sel_client->win, &geom)) {
583- geom.y += a->i;
584- swc_window_set_geometry(wm.sel_client->win, &geom);
585- }
586+if (!wm.sel_client)
587+return;
588
589+if (swc_window_get_geometry(wm.sel_client->win, &geom)) {
590+geom.y += a->i;
591+swc_window_set_geometry(wm.sel_client->win, &geom);
592+}
593 }
594
595-/* slgro - same thing here, ill figure out how to simplify this into one function another time, just focusing on making this work to begin with for now*/
596-void kb_resize_width(void* data, uint32_t time, uint32_t value, uint32_t state) {
597-
598- (void)time;
599- (void)value;
600-
601- union arg* a = data;
602- struct swc_rectangle geom;
603+/* slgro - same thing here, ill figure out how to simplify this into one function a
604+nother time, just focusing on making this work to begin with for now*/
605+void kb_resize_width(void* data, uint32_t time, uint32_t value, uint32_t state)
606+{
607+VOID(time, value);
608
609- if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
610- return;
611+union arg* a = data;
612+struct swc_rectangle geom;
613
614- if (!wm.sel_client)
615- return;
616+if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
617+return;
618
619- if (swc_window_get_geometry(wm.sel_client->win, &geom)) {
620- geom.width += a->i;
621- swc_window_set_geometry(wm.sel_client->win, &geom);
622- }
623+if (!wm.sel_client)
624+return;
625
626+if (swc_window_get_geometry(wm.sel_client->win, &geom)) {
627+geom.width += a->i;
628+swc_window_set_geometry(wm.sel_client->win, &geom);
629+}
630 }
631
632-void kb_resize_height(void* data, uint32_t time, uint32_t value, uint32_t state) {
633-
634- (void)time;
635- (void)value;
636-
637- union arg* a = data;
638- struct swc_rectangle geom;
639+void kb_resize_height(void* data, uint32_t time, uint32_t value, uint32_t state)
640+{
641+VOID(time, value);
642
643- if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
644- return;
645+union arg* a = data;
646+struct swc_rectangle geom;
647
648- if (!wm.sel_client)
649- return;
650+if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
651+return;
652
653- if (swc_window_get_geometry(wm.sel_client->win, &geom)) {
654- geom.height += a->i;
655- swc_window_set_geometry(wm.sel_client->win, &geom);
656- }
657+if (!wm.sel_client)
658+return;
659
660+if (swc_window_get_geometry(wm.sel_client->win, &geom)) {
661+geom.height += a->i;
662+swc_window_set_geometry(wm.sel_client->win, &geom);
663+}
664 }
665
666-/* slgro - idk if this is THAT useful but its kinda useful for me so that's what matters i suppose,,*/
667-void center_window(void* data, uint32_t time, uint32_t value, uint32_t state) {
668-
669- (void)data;
670- (void)value;
671- (void)state;
672- (void)time;
673-
674- struct swc_rectangle geom;
675+/* slgro - idk if this is THAT useful but its kinda useful for me so that's what ma
676+tters i suppose,,*/
677+void center_window(void* data, uint32_t time, uint32_t value, uint32_t state)
678+{
679+VOID(data, time, value);
680
681- if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
682- return;
683+struct swc_rectangle geom;
684
685- if (!wm.sel_client)
686- return;
687+if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
688+return;
689
690- if (swc_window_get_geometry(wm.sel_client->win, &geom)) {
691- geom.x = (wm.sel_client->scr->scr->usable_geometry.width / 2) - (geom.width / 2);
692- geom.y = (wm.sel_client->scr->scr->usable_geometry.height / 2) - (geom.height / 2);
693- swc_window_set_geometry(wm.sel_client->win, &geom);
694- }
695+if (!wm.sel_client)
696+return;
697
698+if (swc_window_get_geometry(wm.sel_client->win, &geom)) {
699+geom.x = (wm.sel_client->scr->scr->usable_geometry.width / 2) - (ge
700+om.width / 2);
701+geom.y = (wm.sel_client->scr->scr->usable_geometry.height / 2) - (g
702+eom.height / 2);
703+swc_window_set_geometry(wm.sel_client->win, &geom);
704+}
705 }
706
707-/* slgro - very experimental snapping, will prob refactor this at some point */
708-void snap_left_half(void* data, uint32_t time, uint32_t value, uint32_t state) {
709-
710-(void)data;
711-(void)value;
712-(void)state;
713-(void)time;
714+/* slgro - very experimental snapping, will prob refactor this at some point */
715+void snap_left_half(void* data, uint32_t time, uint32_t value, uint32_t state)
716+{
717+VOID(data, time, value);
718
719 struct swc_rectangle geom;
720
721@@ -460,20 +439,16 @@ return;
722 if (!wm.sel_client)
723 return;
724
725- geom.x = wm.sel_client->scr->scr->usable_geometry.x;
726- geom.y = wm.sel_client->scr->scr->usable_geometry.y;
727- geom.width = wm.sel_client->scr->scr->usable_geometry.width / 2;
728- geom.height = wm.sel_client->scr->scr->usable_geometry.height;
729- swc_window_set_geometry(wm.sel_client->win, &geom);
730-
731+geom.x = wm.sel_client->scr->scr->usable_geometry.x;
732+geom.y = wm.sel_client->scr->scr->usable_geometry.y;
733+geom.width = wm.sel_client->scr->scr->usable_geometry.width / 2;
734+geom.height = wm.sel_client->scr->scr->usable_geometry.height;
735+swc_window_set_geometry(wm.sel_client->win, &geom);
736 }
737
738-void snap_right_half(void* data, uint32_t time, uint32_t value, uint32_t state) {
739-
740-(void)data;
741-(void)value;
742-(void)state;
743-(void)time;
744+void snap_right_half(void* data, uint32_t time, uint32_t value, uint32_t state)
745+{
746+VOID(data, time, value);
747
748 struct swc_rectangle geom;
749
750@@ -488,170 +463,160 @@ geom.y = wm.sel_client->scr->scr->usable_geometry.y;
751 geom.width = wm.sel_client->scr->scr->usable_geometry.width / 2;
752 geom.height = wm.sel_client->scr->scr->usable_geometry.height;
753 swc_window_set_geometry(wm.sel_client->win, &geom);
754-
755 }
756
757 void new_screen(struct swc_screen* scr)
758 {
759- struct screen* s;
760-
761- s = malloc(sizeof(*s));
762- if (!s)
763- die(EXIT_FAILURE, "new screen calloc failed");
764-
765- s->scr = scr;
766+struct screen* s;
767
768- s->x = 0;
769- s->y = 0;
770- s->w = 0;
771- s->h = 0;
772+s = malloc(sizeof(*s));
773+if (!s)
774+die(EXIT_FAILURE, "new screen calloc failed");
775
776- wl_list_insert(&wm.screens, &s->link);
777+s->scr = scr;
778+s->x = 0;
779+s->y = 0;
780+s->w = 0;
781+s->h = 0;
782
783- if (!wm.sel_screen)
784- wm.sel_screen = s;
785+wl_list_insert(&wm.screens, &s->link);
786
787- swc_screen_set_handler(scr, &screen_handler, s);
788+if (!wm.sel_screen)
789+wm.sel_screen = s;
790
791- _log(stderr, "new_screen=%p\n", (void*)scr);
792+swc_screen_set_handler(scr, &screen_handler, s);
793+_log(stderr, "new_screen=%p\n", (void*)scr);
794 }
795
796 void new_window(struct swc_window* win)
797 {
798- struct client* c;
799-
800- c = malloc(sizeof(*c));
801- if (!c)
802- die(EXIT_FAILURE, "malloc client failed");
803-
804- win->motion_throttle_ms = 1000 / cfg.motion_throttle_hz;
805- win->min_width = 1;
806- win->min_height = 1;
807- win->max_width = 0;
808- win->max_height = 0;
809-
810- c->win = win;
811- c->scr = wm.sel_screen;
812- c->mapped = 0;
813- c->floating = true;
814- c->fullscreen = 0;
815- c->ws = wm.ws;
816- c->x = 0;
817- c->y = 0;
818- c->w = 0;
819- c->h = 0;
820-
821- wl_list_insert(&wm.clients, &c->link);
822- swc_window_set_handler(win, &window_handler, c);
823- swc_window_set_stacked(win);
824- {
825- /* swc reports cursor coordinates in wl_fixed_t (24.8) units */
826- int32_t cx_fixed = 0;
827- int32_t cy_fixed = 0;
828-
829- if (swc_cursor_position(&cx_fixed, &cy_fixed))
830- swc_window_set_position(win, cx_fixed / 256, cy_fixed / 256);
831- }
832- swc_window_show(win);
833- focus(c);
834-
835- _log(stderr, "new_window=%p\n", (void*)win);
836+struct client* c;
837+
838+c = malloc(sizeof(*c));
839+if (!c)
840+die(EXIT_FAILURE, "malloc client failed");
841+
842+win->motion_throttle_ms = 1000 / cfg.motion_throttle_hz;
843+win->min_width = 1;
844+win->min_height = 1;
845+win->max_width = 0;
846+win->max_height = 0;
847+
848+c->win = win;
849+c->scr = wm.sel_screen;
850+c->mapped = 0;
851+c->floating = true;
852+c->fullscreen = 0;
853+c->ws = wm.ws;
854+c->x = 0;
855+c->y = 0;
856+c->w = 0;
857+c->h = 0;
858+
859+wl_list_insert(&wm.clients, &c->link);
860+swc_window_set_handler(win, &window_handler, c);
861+swc_window_set_stacked(win);
862+{
863+/* swc reports cursor coordinates in wl_fixed_t (24.8) units */
864+int32_t cx_fixed = 0;
865+int32_t cy_fixed = 0;
866+
867+if (swc_cursor_position(&cx_fixed, &cy_fixed))
868+swc_window_set_position(win, cx_fixed / 256, cy_fixed / 256
869+);
870+}
871+swc_window_show(win);
872+focus(c);
873+_log(stderr, "new_window=%p\n", (void*)win);
874 }
875
876 void new_device(struct libinput_device* dev)
877 {
878- (void)dev;
879+(void)dev;
880 }
881
882 void quit(void* data, uint32_t time, uint32_t value, uint32_t state)
883 {
884- (void)data;
885- (void)time;
886- (void)value;
887- (void)state;
888-
889- wl_display_terminate(wm.dpy);
890+VOID(data, time, value, state);
891+wl_display_terminate(wm.dpy);
892 }
893
894 void spawn(void* data, uint32_t time, uint32_t value, uint32_t state)
895 {
896- union arg* a = data;
897- char* const* cmd = (char* const*)a->v;
898+VOID(time, value);
899
900- (void)time;
901- (void)value;
902+union arg* a = data;
903+char* const* cmd = (char* const*)a->v;
904
905- if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
906- return;
907+if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
908+return;
909
910- if (fork() == 0) {
911- execvp(cmd[0], cmd);
912- _exit(127);
913- }
914+if (fork() == 0) {
915+execvp(cmd[0], cmd);
916+_exit(127);
917+}
918 }
919
920 void workspace_goto(void* data, uint32_t time, uint32_t value, uint32_t state)
921 {
922- union arg* a = data;
923- struct client* c;
924+VOID(time, value);
925
926- (void)time;
927- (void)value;
928+union arg* a = data;
929+struct client* c;
930
931- if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
932- return;
933+if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
934+return;
935
936- if (a->ui < 1 || a->ui > 9 || a->ui == wm.ws)
937- return;
938+if (a->ui < 1 || a->ui > 9 || a->ui == wm.ws)
939+return;
940
941- wm.ws = a->ui;
942- sync_window_visibility();
943+wm.ws = a->ui;
944+sync_window_visibility();
945
946- c = first_client(wm.sel_screen);
947- if (!c)
948- c = first_client(NULL);
949- focus(c);
950+c = first_client(wm.sel_screen);
951+if (!c)
952+c = first_client(NULL);
953+focus(c);
954 }
955
956 void workspace_moveto(void* data, uint32_t time, uint32_t value, uint32_t state)
957 {
958- union arg* a = data;
959- struct client* c;
960- struct client* next;
961+VOID(time, value);
962
963- (void)time;
964- (void)value;
965+union arg* a = data;
966+struct client* c;
967+struct client* next;
968
969- if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
970- return;
971+if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
972+return;
973
974- if (!wm.sel_client)
975- return;
976+if (!wm.sel_client)
977+return;
978
979- if (a->ui < 1 || a->ui > 9)
980- return;
981+if (a->ui < 1 || a->ui > 9)
982+return;
983
984- c = wm.sel_client;
985- if (c->ws == a->ui)
986- return;
987+c = wm.sel_client;
988+if (c->ws == a->ui)
989+return;
990
991- c->ws = a->ui;
992- if (c->ws == wm.ws)
993- swc_window_show(c->win);
994- else
995- swc_window_hide(c->win);
996+c->ws = a->ui;
997+if (c->ws == wm.ws)
998+swc_window_show(c->win);
999+else
1000+swc_window_hide(c->win);
1001
1002- next = first_client(wm.sel_screen);
1003- if (!next)
1004- next = first_client(NULL);
1005- focus(next);
1006+next = first_client(wm.sel_screen);
1007+if (!next)
1008+next = first_client(NULL);
1009+focus(next);
1010 }
1011
1012 int main(void)
1013 {
1014- setup();
1015- wl_display_run(wm.dpy);
1016- swc_finalize();
1017- wl_display_destroy(wm.dpy);
1018- return EXIT_SUCCESS;
1019-}
1020+setup();
1021+wl_display_run(wm.dpy);
1022+swc_finalize();
1023+wl_display_destroy(wm.dpy);
1024+return EXIT_SUCCESS;
1025+}