From 7e7fab861a7e5baae9182419f7f320af36ce1ec4 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Wed, 29 Sep 2021 12:59:39 -0700 Subject: Feat(wm): prepararation for layout mechanism --- sys/cmd/wm/client.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'sys/cmd/wm/client.c') diff --git a/sys/cmd/wm/client.c b/sys/cmd/wm/client.c index 33dfcb1..2a8c0c0 100644 --- a/sys/cmd/wm/client.c +++ b/sys/cmd/wm/client.c @@ -9,8 +9,8 @@ focus(Client *client, struct wlr_surface *new) struct wlr_keyboard *keyboard; if(client) { - wl_list_remove(&client->link); - wl_list_insert(&server.clients, &client->link); + wl_list_remove(&client->stack); + wl_list_insert(&server.client.stack, &client->stack); } seat = server.input.seat; @@ -61,7 +61,7 @@ Client* client_at(double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { Client *it; - wl_list_for_each(it, &server.clients, link) { + wl_list_for_each(it, &server.client.list, link) { if(client_has(it, lx, ly, surface, sx, sy)) return it; } @@ -100,3 +100,38 @@ setinteractive(Client *client, int mode, uint32 edges) { server.resize = edges; } } + +static +void +apply_bounds(Client *client, struct wlr_box *box) +{ + client->geo.width = MAX(1, client->geo.width); + client->geo.height = MAX(1, client->geo.height); + + if(client->geo.x >= box->x + box->width) + client->geo.x = box->x + box->width - client->geo.width; + if(client->geo.y >= box->y + box->height) + client->geo.y = box->y + box->height - client->geo.height; + if(client->geo.x + client->geo.width + 2*client->border <= box->x) + client->geo.x = box->x; + if(client->geo.y + client->geo.height + 2*client->border <= box->y) + client->geo.y = box->y; +} + +void +resize(Client *client, int x, int y, int w, int h, int interact) +{ + struct wlr_box *box = interact ? &server.monitor.geometry : &client->monitor->window; + + client->geo.x = x; + client->geo.y = y; + client->geo.width = w; + client->geo.height = h; + + apply_bounds(client, box); + + client->resize = wlr_xdg_toplevel_set_size(client->xdg, + client->geo.width - 2*client->border, + client->geo.height - 2*client->border + ); +} -- cgit v1.2.1