2026-01-02 22:53:34 +07:00
|
|
|
#include <wayland-server-core.h>
|
|
|
|
|
|
|
|
|
|
#include "types.h"
|
2026-01-11 03:22:05 +07:00
|
|
|
#include "absinthe-toplevel.h"
|
2026-01-02 22:53:34 +07:00
|
|
|
|
|
|
|
|
void focus_toplevel(struct absinthe_toplevel *toplevel)
|
|
|
|
|
{
|
2026-01-07 20:35:41 +07:00
|
|
|
if (!toplevel)
|
2026-01-02 22:53:34 +07:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
struct absinthe_server *server = toplevel->server;
|
|
|
|
|
struct wlr_seat *seat = server->seat;
|
|
|
|
|
struct wlr_surface *prev_surface = seat->keyboard_state.focused_surface;
|
|
|
|
|
struct wlr_surface *surface = toplevel->xdg_toplevel->base->surface;
|
|
|
|
|
|
2026-01-07 20:35:41 +07:00
|
|
|
if (surface == prev_surface)
|
2026-01-02 22:53:34 +07:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (prev_surface) {
|
|
|
|
|
struct wlr_xdg_toplevel *prev_toplevel = wlr_xdg_toplevel_try_from_wlr_surface(prev_surface);
|
2026-01-11 03:22:05 +07:00
|
|
|
if (prev_toplevel) {
|
|
|
|
|
wlr_xdg_toplevel_set_activated(prev_toplevel, false);
|
|
|
|
|
absinthe_toplevel_set_border_color(prev_toplevel->base->data, unfocused_border_color);
|
|
|
|
|
}
|
2026-01-02 22:53:34 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat);
|
|
|
|
|
wlr_scene_node_raise_to_top(&toplevel->scene_tree->node);
|
|
|
|
|
wl_list_remove(&toplevel->link);
|
|
|
|
|
wl_list_insert(&server->toplevels, &toplevel->link);
|
|
|
|
|
wlr_xdg_toplevel_set_activated(toplevel->xdg_toplevel, true);
|
2026-01-11 03:22:05 +07:00
|
|
|
absinthe_toplevel_set_border_color(toplevel, focused_border_color);
|
2026-01-02 22:53:34 +07:00
|
|
|
|
2026-01-07 20:35:41 +07:00
|
|
|
if (keyboard)
|
2026-01-02 22:53:34 +07:00
|
|
|
wlr_seat_keyboard_notify_enter(seat, surface, keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers);
|
|
|
|
|
}
|