From 9daffd37236469e8089e3c12207c449b4db09e92 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Mon, 5 Jan 2026 00:37:13 -0700 Subject: [feat] add focusing and better dragging. --- rt/src/util.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'rt/src') diff --git a/rt/src/util.c b/rt/src/util.c index 6576770..66a2b20 100644 --- a/rt/src/util.c +++ b/rt/src/util.c @@ -2,6 +2,7 @@ #include "wl.h" #include +#include static struct montis_server *server_from_ctx(void *ctx) { @@ -61,3 +62,37 @@ void montis_plugin_set_toplevel_position(void *toplevel, double x, double y) struct montis_toplevel *tl = toplevel; wlr_scene_node_set_position(&tl->scene_tree->node, (int)x, (int)y); } + +void montis_plugin_focus_toplevel(void *toplevel) +{ + if (!toplevel) { + return; + } + struct montis_toplevel *tl = toplevel; + struct montis_server *server = tl->server; + struct wlr_seat *seat = server->seat; + struct wlr_surface *surface = tl->xdg_toplevel->base->surface; + struct wlr_surface *prev_surface = seat->keyboard_state.focused_surface; + + if (prev_surface == surface) { + return; + } + if (prev_surface) { + struct wlr_xdg_toplevel *prev_toplevel = + wlr_xdg_toplevel_try_from_wlr_surface(prev_surface); + if (prev_toplevel != NULL) { + wlr_xdg_toplevel_set_activated(prev_toplevel, false); + } + } + + struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat); + wlr_scene_node_raise_to_top(&tl->scene_tree->node); + wl_list_remove(&tl->link); + wl_list_insert(&server->toplevels, &tl->link); + wlr_xdg_toplevel_set_activated(tl->xdg_toplevel, true); + if (keyboard != NULL) { + wlr_seat_keyboard_notify_enter(seat, surface, keyboard->keycodes, + keyboard->num_keycodes, + &keyboard->modifiers); + } +} -- cgit