commit 8f391ff
wf
·
2026-04-20 18:21:50 +0000 UTC
parent 68a3980
Add screen geometry handler, make return syntax consistent
1 files changed,
+48,
-11
M
howl.c
M
howl.c
+48,
-11
1@@ -20,6 +20,7 @@ static void new_window(struct swc_window *);
2 static void on_win_destroy(void *);
3 static void on_win_entered(void *);
4 static void on_scr_destroy(void *);
5+static void on_scr_geometry(void *);
6 static bool is_ws_client(const struct client *, const struct screen *);
7
8 extern status ipc_move(char **);
9@@ -63,7 +64,8 @@ static struct swc_window_handler win_handler = {
10 };
11
12 static struct swc_screen_handler scr_handler = {
13- .destroy = on_scr_destroy
14+ .destroy = on_scr_destroy,
15+ .usable_geometry_changed = on_scr_geometry
16 };
17
18 typedef status (*cmd_handler_t)(char **);
19@@ -218,7 +220,8 @@ sig_handler(int s) {
20 static void
21 setup(void) {
22 wm.dpy = wl_display_create();
23- if (!wm.dpy) _err(1, "couldn't create Wayland display");
24+ if (!wm.dpy)
25+ _err(1, "couldn't create Wayland display");
26
27 wl_list_init(&wm.screens);
28 wl_list_init(&wm.clients);
29@@ -351,7 +354,8 @@ ws_go_to(uint8_t ws) {
30 sync_windows();
31
32 c = first_client(wm.scr);
33- if (!c) c = first_client(NULL);
34+ if (!c)
35+ c = first_client(NULL);
36 focus(c);
37 }
38
39@@ -371,7 +375,8 @@ ws_move_to(uint8_t ws) {
40 swc_window_hide(c->win);
41
42 next = first_client(wm.scr);
43- if (!next) next = first_client(NULL);
44+ if (!next)
45+ next = first_client(NULL);
46 focus(next);
47 }
48
49@@ -406,7 +411,8 @@ focus_prev(void) {
50 } while (it != start);
51
52 c = first_client(wm.scr);
53- if (!c) c = first_client(NULL);
54+ if (!c)
55+ c = first_client(NULL);
56 focus(c);
57 }
58
59@@ -441,7 +447,8 @@ focus_next(void) {
60 } while (it != start);
61
62 c = first_client(wm.scr);
63- if (!c) c = first_client(NULL);
64+ if (!c)
65+ c = first_client(NULL);
66 focus(c);
67 }
68
69@@ -449,7 +456,8 @@ static void
70 new_screen(struct swc_screen *scr) {
71 struct screen *s;
72 s = malloc(sizeof(*s));
73- if (!s) _err(1, "couldn't allocate screen");
74+ if (!s)
75+ _err(1, "couldn't allocate screen");
76
77 s->scr = scr;
78 s->x = 0;
79@@ -467,7 +475,8 @@ static void
80 new_window(struct swc_window *win) {
81 struct client *c;
82 c = malloc(sizeof(*c));
83- if (!c) _err(1, "couldn't allocate client");
84+ if (!c)
85+ _err(1, "couldn't allocate client");
86
87 win->motion_throttle_ms = 1000 / 85;
88 win->min_width = 1;
89@@ -506,7 +515,8 @@ on_win_entered(void *data) {
90 if (wm.grab.active) return;
91
92 struct client *c = data;
93- if (!is_ws_client(c, NULL)) return;
94+ if (!is_ws_client(c, NULL))
95+ return;
96
97 focus(c);
98 }
99@@ -515,7 +525,8 @@ static void
100 on_win_destroy(void *data) {
101 struct client *c = data, *next;
102
103- if (!c) return;
104+ if (!c)
105+ return;
106 if (wm.grab.active && wm.grab.client == c) {
107 wm.grab.active = false;
108 wm.grab.client = NULL;
109@@ -532,7 +543,8 @@ on_win_destroy(void *data) {
110 static void
111 on_scr_destroy(void *data) {
112 struct screen *s = data;
113- if (!s) return;
114+ if (!s)
115+ return;
116
117 wl_list_remove(&s->link);
118 if (wm.scr == s) {
119@@ -544,6 +556,31 @@ on_scr_destroy(void *data) {
120 free(s);
121 }
122
123+static void
124+on_scr_geometry(void *data) {
125+ struct screen *s = data;
126+ if (!s)
127+ return;
128+
129+ int xoff = s->scr->usable_geometry.width - wm.scr->width;
130+ int yoff = s->scr->usable_geometry.height - wm.scr->height;
131+
132+ wm.scr->width = s->scr->usable_geometry.width;
133+ wm.scr->height = s->scr->usable_geometry.height;
134+
135+ if (!(wl_list_empty(&wm.clients))) {
136+ struct client *c;
137+ wl_list_for_each(c, &wm.clients, link) {
138+ struct swc_rectangle geom;
139+ if ((swc_window_get_geometry(c->win, &geom))) {
140+ c->x = geom.x;
141+ c->y = geom.y;
142+ }
143+ swc_window_set_position(c->win, c->x + xoff / 2, c->y + yoff / 2);
144+ }
145+ }
146+}
147+
148 int
149 main(int argc, char **argv) {
150 bool have_config = true;