diff options
Diffstat (limited to 'rt/src')
| -rw-r--r-- | rt/src/util.c | 35 |
1 files changed, 35 insertions, 0 deletions
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 <wlr/types/wlr_scene.h> +#include <wlr/types/wlr_xdg_shell.h> 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); + } +} |