2026-01-02 22:53:34 +07:00
|
|
|
#include <wayland-server-core.h>
|
2026-01-07 20:35:41 +07:00
|
|
|
#include <wlr/util/log.h>
|
2026-01-02 22:53:34 +07:00
|
|
|
|
|
|
|
|
#include "types.h"
|
2026-01-06 21:55:52 +07:00
|
|
|
#include "xdg-toplevel.h"
|
2026-01-02 22:53:34 +07:00
|
|
|
|
|
|
|
|
struct absinthe_toplevel *absinthe_toplevel_at(struct absinthe_server *server, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy)
|
|
|
|
|
{
|
|
|
|
|
struct wlr_scene_node *node = wlr_scene_node_at(&server->scene->tree.node, lx, ly, sx, sy);
|
|
|
|
|
if (!node || node->type != WLR_SCENE_NODE_BUFFER) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wlr_scene_buffer *scene_buffer = wlr_scene_buffer_from_node(node);
|
|
|
|
|
struct wlr_scene_surface *scene_surface = wlr_scene_surface_try_from_buffer(scene_buffer);
|
|
|
|
|
if (!scene_surface) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*surface = scene_surface->surface;
|
|
|
|
|
struct wlr_scene_tree *tree = node->parent;
|
|
|
|
|
while (tree != NULL && tree->node.data == NULL) {
|
|
|
|
|
tree = tree->node.parent;
|
|
|
|
|
}
|
|
|
|
|
return tree->node.data;
|
|
|
|
|
}
|
2026-01-06 01:41:46 +07:00
|
|
|
|
2026-01-07 01:20:24 +07:00
|
|
|
void absinthe_toplevel_set_position(struct absinthe_toplevel *toplevel, int32_t x, int32_t y)
|
|
|
|
|
{
|
|
|
|
|
wlr_scene_node_set_position(&toplevel->scene_tree->node, x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void absinthe_toplevel_set_size(struct absinthe_toplevel *toplevel, int32_t width, int32_t height)
|
|
|
|
|
{
|
2026-01-10 23:16:46 +07:00
|
|
|
int32_t bw = toplevel->border_width;
|
2026-01-07 01:20:24 +07:00
|
|
|
|
2026-01-07 20:35:41 +07:00
|
|
|
if (width < 0 || height < 0)
|
2026-01-07 01:20:24 +07:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
wlr_xdg_toplevel_set_size(toplevel->xdg_toplevel, width, height);
|
2026-01-10 23:16:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void absinthe_toplevel_set_fullscreen(struct absinthe_toplevel *toplevel, bool fullscreen)
|
|
|
|
|
{
|
|
|
|
|
if (!toplevel || toplevel->fullscreen == fullscreen)
|
|
|
|
|
return;
|
|
|
|
|
|
2026-01-11 22:38:28 +07:00
|
|
|
struct absinthe_output *output = toplevel->server->focused_output;
|
2026-01-10 23:16:46 +07:00
|
|
|
toplevel->fullscreen = fullscreen;
|
|
|
|
|
wlr_xdg_toplevel_set_fullscreen(toplevel->xdg_toplevel, fullscreen);
|
|
|
|
|
|
|
|
|
|
if (fullscreen) {
|
|
|
|
|
toplevel->prev_geometry = toplevel->geometry;
|
|
|
|
|
toplevel->geometry = output->geometry;
|
|
|
|
|
toplevel->border_width = 0;
|
|
|
|
|
absinthe_toplevel_set_size(toplevel, toplevel->geometry.width, toplevel->geometry.height);
|
|
|
|
|
} else {
|
|
|
|
|
toplevel->geometry = toplevel->prev_geometry;
|
|
|
|
|
toplevel->border_width = ABSINTHE_WINDOW_BORDER_WIDTH;
|
|
|
|
|
absinthe_toplevel_set_size(toplevel, toplevel->geometry.width, toplevel->geometry.height);
|
|
|
|
|
}
|
2026-01-07 01:20:24 +07:00
|
|
|
}
|
|
|
|
|
|
2026-01-06 01:41:46 +07:00
|
|
|
void absinthe_toplevel_set_border_color(struct absinthe_toplevel *toplevel, const float color[4])
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
|
wlr_scene_rect_set_color(toplevel->border[i], color);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-07 20:35:41 +07:00
|
|
|
|
|
|
|
|
void absinthe_toplevel_update_borders_geometry(struct absinthe_toplevel *toplevel)
|
|
|
|
|
{
|
2026-01-10 23:16:46 +07:00
|
|
|
int32_t bw = toplevel->border_width;
|
2026-01-07 20:35:41 +07:00
|
|
|
|
|
|
|
|
if (toplevel->geometry.width - 2 * bw < 0 || toplevel->geometry.height - 2 * bw < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
wlr_scene_node_set_position(&toplevel->scene_tree->node, toplevel->geometry.x, toplevel->geometry.y);
|
|
|
|
|
wlr_scene_node_set_position(&toplevel->scene_surface->node, bw, bw);
|
|
|
|
|
|
|
|
|
|
wlr_scene_rect_set_size(toplevel->border[0], toplevel->geometry.width - 2 * bw, bw);
|
|
|
|
|
wlr_scene_rect_set_size(toplevel->border[1], toplevel->geometry.width - 2 * bw, bw);
|
|
|
|
|
wlr_scene_rect_set_size(toplevel->border[2], bw, toplevel->geometry.height);
|
|
|
|
|
wlr_scene_rect_set_size(toplevel->border[3], bw, toplevel->geometry.height);
|
|
|
|
|
|
|
|
|
|
wlr_scene_node_set_position(&toplevel->border[0]->node, bw, 0);
|
|
|
|
|
wlr_scene_node_set_position(&toplevel->border[1]->node, bw, toplevel->geometry.height - bw);
|
|
|
|
|
wlr_scene_node_set_position(&toplevel->border[2]->node, 0, 0);
|
|
|
|
|
wlr_scene_node_set_position(&toplevel->border[3]->node, toplevel->geometry.width - bw, 0);
|
|
|
|
|
}
|