aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/wm/client.c
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2021-09-28 14:34:34 -0700
committerNicholas Noll <nbnoll@eml.cc>2021-09-28 14:34:34 -0700
commitb9a07a67b85e9192faa0e285b4419bd5ef242a03 (patch)
tree6b3426363e22da403967c6d4cbb0b98f39be4b38 /sys/cmd/wm/client.c
parentb58f62d4ef7f6e2442bdf8170f8652ba1e08bd12 (diff)
feat: reorganized code to be more modular
Diffstat (limited to 'sys/cmd/wm/client.c')
-rw-r--r--sys/cmd/wm/client.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/sys/cmd/wm/client.c b/sys/cmd/wm/client.c
new file mode 100644
index 0000000..7d828a0
--- /dev/null
+++ b/sys/cmd/wm/client.c
@@ -0,0 +1,95 @@
+#include "wm.h"
+
+void
+focus(Client *client, struct wlr_surface *new)
+{
+ struct wlr_seat *seat;
+ struct wlr_surface *old;
+ struct wlr_xdg_surface *xdg;
+ struct wlr_keyboard *keyboard;
+
+ if(!client)
+ return;
+
+ seat = server.input.seat;
+ old = seat->keyboard_state.focused_surface;
+ if(old == new)
+ return;
+
+ if(old) {
+ xdg = wlr_xdg_surface_from_wlr_surface(seat->keyboard_state.focused_surface);
+ wlr_xdg_toplevel_set_activated(xdg, false);
+ }
+
+ keyboard = wlr_seat_get_keyboard(seat);
+
+ wl_list_remove(&client->link);
+ wl_list_insert(&server.clients, &client->link);
+
+ wlr_xdg_toplevel_set_activated(client->xdg, true);
+ wlr_seat_keyboard_notify_enter(seat, client->xdg->surface,
+ keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers);
+}
+
+int
+clienthas(Client *client, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy)
+{
+ double x, y, vsx = lx - client->x, vsy = ly - client->y;
+ struct wlr_surface *find = nil;
+
+ find = wlr_xdg_surface_surface_at(client->xdg, vsx, vsy, &x, &y);
+ if(find) {
+ *sx = x;
+ *sy = y;
+ *surface = find;
+ return true;
+ }
+
+ return false;
+}
+
+Client*
+clientat(double lx, double ly, struct wlr_surface **surface, double *sx, double *sy)
+{
+ Client *it;
+ wl_list_for_each(it, &server.clients, link) {
+ if(clienthas(it, lx, ly, surface, sx, sy))
+ return it;
+ }
+
+ return nil;
+}
+
+void
+setinteractive(Client *client, int mode, uint32 edges) {
+ double bx, by;
+ struct wlr_box box;
+ struct wlr_surface *focused = server.input.seat->pointer_state.focused_surface;
+
+ if(client->xdg->surface != focused)
+ return;
+
+ server.grab.client = client;
+ server.cursor.mode = mode;
+
+ if(mode == CursorMove) {
+ server.grab.x = server.cursor.dot->x - client->x;
+ server.grab.y = server.cursor.dot->y - client->y;
+ } else {
+ wlr_xdg_surface_get_geometry(client->xdg, &box);
+
+ bx = (client->x + box.x) + ((edges & WLR_EDGE_RIGHT) ? box.width : 0);
+ by = (client->y + box.y) + ((edges & WLR_EDGE_BOTTOM) ? box.height : 0);
+
+ server.grab.x = server.cursor.dot->x - bx;
+ server.grab.y = server.cursor.dot->y - by;
+
+ server.grab.box = box;
+ server.grab.box.x += client->x;
+ server.grab.box.y += client->y;
+
+ server.resize = edges;
+ }
+}
+
+