2018-12-31 00:12:33 +01:00
|
|
|
/*
|
|
|
|
|
* Cage: A Wayland kiosk.
|
|
|
|
|
*
|
2019-01-02 21:23:16 +01:00
|
|
|
* Copyright (C) 2018-2019 Jente Hidskes
|
2018-12-31 00:12:33 +01:00
|
|
|
*
|
|
|
|
|
* See the LICENSE file accompanying this file.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-10-27 16:19:06 +02:00
|
|
|
#include <assert.h>
|
2018-12-31 00:12:33 +01:00
|
|
|
#include <stdbool.h>
|
2019-01-30 17:01:16 +01:00
|
|
|
#include <stdlib.h>
|
2019-12-20 17:16:53 +01:00
|
|
|
#include <wayland-server-core.h>
|
2021-08-09 20:06:57 +02:00
|
|
|
#include <wlr/types/wlr_scene.h>
|
2018-12-31 00:12:33 +01:00
|
|
|
#include <wlr/types/wlr_xdg_shell.h>
|
2019-01-30 17:01:16 +01:00
|
|
|
#include <wlr/util/log.h>
|
2018-12-31 00:12:33 +01:00
|
|
|
|
|
|
|
|
#include "server.h"
|
|
|
|
|
#include "view.h"
|
2019-01-25 20:34:11 +01:00
|
|
|
#include "xdg_shell.h"
|
2018-12-31 00:12:33 +01:00
|
|
|
|
2024-08-24 15:46:11 +02:00
|
|
|
static void
|
|
|
|
|
xdg_decoration_set_mode(struct cg_xdg_decoration *xdg_decoration)
|
|
|
|
|
{
|
|
|
|
|
enum wlr_xdg_toplevel_decoration_v1_mode mode;
|
|
|
|
|
if (xdg_decoration->server->xdg_decoration) {
|
|
|
|
|
mode = WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE;
|
|
|
|
|
} else {
|
|
|
|
|
mode = WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE;
|
|
|
|
|
}
|
|
|
|
|
wlr_xdg_toplevel_decoration_v1_set_mode(xdg_decoration->wlr_decoration, mode);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-17 22:17:11 +01:00
|
|
|
static void
|
|
|
|
|
xdg_decoration_handle_destroy(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct cg_xdg_decoration *xdg_decoration = wl_container_of(listener, xdg_decoration, destroy);
|
|
|
|
|
|
|
|
|
|
wl_list_remove(&xdg_decoration->destroy.link);
|
2024-08-24 15:46:11 +02:00
|
|
|
wl_list_remove(&xdg_decoration->commit.link);
|
2019-02-17 22:17:11 +01:00
|
|
|
wl_list_remove(&xdg_decoration->request_mode.link);
|
|
|
|
|
free(xdg_decoration);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-24 15:46:11 +02:00
|
|
|
static void
|
|
|
|
|
xdg_decoration_handle_commit(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct cg_xdg_decoration *xdg_decoration = wl_container_of(listener, xdg_decoration, commit);
|
|
|
|
|
|
|
|
|
|
if (xdg_decoration->wlr_decoration->toplevel->base->initial_commit) {
|
|
|
|
|
xdg_decoration_set_mode(xdg_decoration);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-17 22:17:11 +01:00
|
|
|
static void
|
|
|
|
|
xdg_decoration_handle_request_mode(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct cg_xdg_decoration *xdg_decoration = wl_container_of(listener, xdg_decoration, request_mode);
|
|
|
|
|
|
2024-08-24 15:46:11 +02:00
|
|
|
if (xdg_decoration->wlr_decoration->toplevel->base->initialized) {
|
|
|
|
|
xdg_decoration_set_mode(xdg_decoration);
|
2019-02-17 22:17:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-27 16:19:06 +02:00
|
|
|
static struct cg_view *
|
|
|
|
|
popup_get_view(struct wlr_xdg_popup *popup)
|
2019-02-13 18:14:20 +01:00
|
|
|
{
|
2021-10-27 16:19:06 +02:00
|
|
|
while (true) {
|
2023-09-30 13:40:21 +02:00
|
|
|
if (popup->parent == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
struct wlr_xdg_surface *xdg_surface = wlr_xdg_surface_try_from_wlr_surface(popup->parent);
|
|
|
|
|
if (xdg_surface == NULL) {
|
2021-10-27 16:19:06 +02:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
switch (xdg_surface->role) {
|
|
|
|
|
case WLR_XDG_SURFACE_ROLE_TOPLEVEL:
|
|
|
|
|
return xdg_surface->data;
|
|
|
|
|
case WLR_XDG_SURFACE_ROLE_POPUP:
|
|
|
|
|
popup = xdg_surface->popup;
|
|
|
|
|
break;
|
|
|
|
|
case WLR_XDG_SURFACE_ROLE_NONE:
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2021-08-09 20:06:57 +02:00
|
|
|
}
|
2019-02-13 18:14:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2024-08-30 18:50:11 +02:00
|
|
|
popup_unconstrain(struct wlr_xdg_popup *popup)
|
2019-02-13 18:14:20 +01:00
|
|
|
{
|
2024-08-30 18:50:11 +02:00
|
|
|
struct cg_view *view = popup_get_view(popup);
|
|
|
|
|
if (view == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-21 16:10:11 +01:00
|
|
|
struct cg_server *server = view->server;
|
2022-10-12 04:00:33 -04:00
|
|
|
struct wlr_box *popup_box = &popup->current.geometry;
|
2019-02-13 18:14:20 +01:00
|
|
|
|
2019-12-21 16:10:11 +01:00
|
|
|
struct wlr_output_layout *output_layout = server->output_layout;
|
2020-02-17 19:49:47 +01:00
|
|
|
struct wlr_output *wlr_output =
|
|
|
|
|
wlr_output_layout_output_at(output_layout, view->lx + popup_box->x, view->ly + popup_box->y);
|
2022-10-12 04:05:33 -04:00
|
|
|
struct wlr_box output_box;
|
|
|
|
|
wlr_output_layout_get_box(output_layout, wlr_output, &output_box);
|
2019-02-13 18:14:20 +01:00
|
|
|
|
|
|
|
|
struct wlr_box output_toplevel_box = {
|
2022-10-12 04:05:33 -04:00
|
|
|
.x = output_box.x - view->lx,
|
|
|
|
|
.y = output_box.y - view->ly,
|
|
|
|
|
.width = output_box.width,
|
|
|
|
|
.height = output_box.height,
|
2019-02-13 18:14:20 +01:00
|
|
|
};
|
|
|
|
|
|
2021-10-27 16:19:06 +02:00
|
|
|
wlr_xdg_popup_unconstrain_from_box(popup, &output_toplevel_box);
|
2019-02-13 18:14:20 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-30 17:01:16 +01:00
|
|
|
static struct cg_xdg_shell_view *
|
|
|
|
|
xdg_shell_view_from_view(struct cg_view *view)
|
|
|
|
|
{
|
|
|
|
|
return (struct cg_xdg_shell_view *) view;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-24 14:14:15 +01:00
|
|
|
static char *
|
|
|
|
|
get_title(struct cg_view *view)
|
|
|
|
|
{
|
2019-01-30 17:01:16 +01:00
|
|
|
struct cg_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view);
|
2022-10-12 04:00:11 -04:00
|
|
|
return xdg_shell_view->xdg_toplevel->title;
|
2019-01-24 14:14:15 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-30 17:04:15 +01:00
|
|
|
static void
|
|
|
|
|
get_geometry(struct cg_view *view, int *width_out, int *height_out)
|
|
|
|
|
{
|
|
|
|
|
struct cg_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view);
|
2025-04-10 17:50:15 +02:00
|
|
|
struct wlr_xdg_surface *xdg_surface = xdg_shell_view->xdg_toplevel->base;
|
2019-01-30 17:04:15 +01:00
|
|
|
|
2025-04-10 17:50:15 +02:00
|
|
|
*width_out = xdg_surface->geometry.width;
|
|
|
|
|
*height_out = xdg_surface->geometry.height;
|
2019-01-30 17:04:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
is_primary(struct cg_view *view)
|
|
|
|
|
{
|
|
|
|
|
struct cg_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view);
|
2022-10-12 04:00:11 -04:00
|
|
|
struct wlr_xdg_toplevel *parent = xdg_shell_view->xdg_toplevel->parent;
|
2021-12-26 16:39:46 +01:00
|
|
|
|
2022-10-12 04:00:11 -04:00
|
|
|
return parent == NULL;
|
2019-01-30 17:04:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
2019-01-30 20:25:29 +01:00
|
|
|
is_transient_for(struct cg_view *child, struct cg_view *parent)
|
2019-01-30 17:04:15 +01:00
|
|
|
{
|
2019-01-30 20:25:29 +01:00
|
|
|
if (parent->type != CAGE_XDG_SHELL_VIEW) {
|
2019-01-30 17:04:15 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
struct cg_xdg_shell_view *_child = xdg_shell_view_from_view(child);
|
2022-10-12 04:00:11 -04:00
|
|
|
struct wlr_xdg_toplevel *xdg_toplevel = _child->xdg_toplevel;
|
2019-01-30 20:25:29 +01:00
|
|
|
struct cg_xdg_shell_view *_parent = xdg_shell_view_from_view(parent);
|
2022-10-12 04:00:11 -04:00
|
|
|
while (xdg_toplevel) {
|
|
|
|
|
if (xdg_toplevel->parent == _parent->xdg_toplevel) {
|
2019-01-30 20:25:29 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2022-10-12 04:00:11 -04:00
|
|
|
xdg_toplevel = xdg_toplevel->parent;
|
2019-01-30 20:25:29 +01:00
|
|
|
}
|
|
|
|
|
return false;
|
2019-01-30 17:04:15 +01:00
|
|
|
}
|
|
|
|
|
|
2018-12-31 00:12:33 +01:00
|
|
|
static void
|
|
|
|
|
activate(struct cg_view *view, bool activate)
|
|
|
|
|
{
|
2019-01-30 17:01:16 +01:00
|
|
|
struct cg_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view);
|
2022-10-12 04:00:11 -04:00
|
|
|
wlr_xdg_toplevel_set_activated(xdg_shell_view->xdg_toplevel, activate);
|
2018-12-31 00:12:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
maximize(struct cg_view *view, int output_width, int output_height)
|
|
|
|
|
{
|
2019-01-30 17:01:16 +01:00
|
|
|
struct cg_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view);
|
2022-10-12 04:00:11 -04:00
|
|
|
wlr_xdg_toplevel_set_size(xdg_shell_view->xdg_toplevel, output_width, output_height);
|
|
|
|
|
wlr_xdg_toplevel_set_maximized(xdg_shell_view->xdg_toplevel, true);
|
2019-01-30 17:01:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
destroy(struct cg_view *view)
|
|
|
|
|
{
|
|
|
|
|
struct cg_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view);
|
|
|
|
|
free(xdg_shell_view);
|
2018-12-31 00:12:33 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-14 11:38:29 +01:00
|
|
|
static void
|
2025-06-01 15:08:50 +02:00
|
|
|
handle_xdg_toplevel_request_fullscreen(struct wl_listener *listener, void *data)
|
2019-02-14 11:38:29 +01:00
|
|
|
{
|
|
|
|
|
struct cg_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, request_fullscreen);
|
2021-12-26 16:40:03 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Certain clients do not like figuring out their own window geometry if they
|
|
|
|
|
* display in fullscreen mode, so we set it here.
|
|
|
|
|
*/
|
2022-10-12 04:05:33 -04:00
|
|
|
struct wlr_box layout_box;
|
|
|
|
|
wlr_output_layout_get_box(xdg_shell_view->view.server->output_layout, NULL, &layout_box);
|
|
|
|
|
wlr_xdg_toplevel_set_size(xdg_shell_view->xdg_toplevel, layout_box.width, layout_box.height);
|
2021-12-26 16:40:03 +01:00
|
|
|
|
2022-12-16 05:42:52 -05:00
|
|
|
wlr_xdg_toplevel_set_fullscreen(xdg_shell_view->xdg_toplevel,
|
|
|
|
|
xdg_shell_view->xdg_toplevel->requested.fullscreen);
|
2019-02-14 11:38:29 +01:00
|
|
|
}
|
|
|
|
|
|
2018-12-31 19:52:47 +01:00
|
|
|
static void
|
2025-06-01 15:08:50 +02:00
|
|
|
handle_xdg_toplevel_unmap(struct wl_listener *listener, void *data)
|
2018-12-31 19:52:47 +01:00
|
|
|
{
|
2019-01-30 17:01:16 +01:00
|
|
|
struct cg_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, unmap);
|
|
|
|
|
struct cg_view *view = &xdg_shell_view->view;
|
|
|
|
|
|
2018-12-31 19:52:47 +01:00
|
|
|
view_unmap(view);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-31 00:12:33 +01:00
|
|
|
static void
|
2025-06-01 15:08:50 +02:00
|
|
|
handle_xdg_toplevel_map(struct wl_listener *listener, void *data)
|
2018-12-31 00:12:33 +01:00
|
|
|
{
|
2019-01-30 17:01:16 +01:00
|
|
|
struct cg_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, map);
|
|
|
|
|
struct cg_view *view = &xdg_shell_view->view;
|
|
|
|
|
|
2022-10-12 04:00:11 -04:00
|
|
|
view_map(view, xdg_shell_view->xdg_toplevel->base->surface);
|
2018-12-31 00:12:33 +01:00
|
|
|
}
|
|
|
|
|
|
2024-08-24 15:44:46 +02:00
|
|
|
static void
|
2025-06-01 15:08:50 +02:00
|
|
|
handle_xdg_toplevel_commit(struct wl_listener *listener, void *data)
|
2024-08-24 15:44:46 +02:00
|
|
|
{
|
|
|
|
|
struct cg_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, commit);
|
|
|
|
|
|
|
|
|
|
if (!xdg_shell_view->xdg_toplevel->base->initial_commit) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-01 15:13:55 +02:00
|
|
|
wlr_xdg_toplevel_set_wm_capabilities(xdg_shell_view->xdg_toplevel, XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN);
|
|
|
|
|
|
2024-08-24 15:44:46 +02:00
|
|
|
/* When an xdg_surface performs an initial commit, the compositor must
|
|
|
|
|
* reply with a configure so the client can map the surface. */
|
|
|
|
|
view_position(&xdg_shell_view->view);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-31 00:12:33 +01:00
|
|
|
static void
|
2025-06-01 15:08:50 +02:00
|
|
|
handle_xdg_toplevel_destroy(struct wl_listener *listener, void *data)
|
2018-12-31 00:12:33 +01:00
|
|
|
{
|
2019-01-30 17:01:16 +01:00
|
|
|
struct cg_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, destroy);
|
|
|
|
|
struct cg_view *view = &xdg_shell_view->view;
|
2019-01-20 13:41:35 +01:00
|
|
|
|
2024-08-24 15:44:46 +02:00
|
|
|
wl_list_remove(&xdg_shell_view->commit.link);
|
2019-01-30 17:01:16 +01:00
|
|
|
wl_list_remove(&xdg_shell_view->map.link);
|
|
|
|
|
wl_list_remove(&xdg_shell_view->unmap.link);
|
|
|
|
|
wl_list_remove(&xdg_shell_view->destroy.link);
|
2019-02-14 11:38:29 +01:00
|
|
|
wl_list_remove(&xdg_shell_view->request_fullscreen.link);
|
2022-10-12 04:00:11 -04:00
|
|
|
xdg_shell_view->xdg_toplevel = NULL;
|
2019-01-20 13:41:35 +01:00
|
|
|
|
2018-12-31 00:12:33 +01:00
|
|
|
view_destroy(view);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-30 17:01:16 +01:00
|
|
|
static const struct cg_view_impl xdg_shell_view_impl = {
|
|
|
|
|
.get_title = get_title,
|
|
|
|
|
.get_geometry = get_geometry,
|
|
|
|
|
.is_primary = is_primary,
|
2019-01-30 20:25:29 +01:00
|
|
|
.is_transient_for = is_transient_for,
|
2019-01-30 17:01:16 +01:00
|
|
|
.activate = activate,
|
|
|
|
|
.maximize = maximize,
|
|
|
|
|
.destroy = destroy,
|
|
|
|
|
};
|
|
|
|
|
|
2018-12-31 00:12:33 +01:00
|
|
|
void
|
2024-02-16 16:48:25 +01:00
|
|
|
handle_new_xdg_toplevel(struct wl_listener *listener, void *data)
|
2018-12-31 00:12:33 +01:00
|
|
|
{
|
2024-02-16 16:48:25 +01:00
|
|
|
struct cg_server *server = wl_container_of(listener, server, new_xdg_toplevel);
|
|
|
|
|
struct wlr_xdg_toplevel *toplevel = data;
|
2018-12-31 00:12:33 +01:00
|
|
|
|
2024-02-16 16:48:25 +01:00
|
|
|
struct cg_xdg_shell_view *xdg_shell_view = calloc(1, sizeof(struct cg_xdg_shell_view));
|
|
|
|
|
if (!xdg_shell_view) {
|
|
|
|
|
wlr_log(WLR_ERROR, "Failed to allocate XDG Shell view");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-01-04 12:20:14 +01:00
|
|
|
|
2024-02-16 16:48:25 +01:00
|
|
|
view_init(&xdg_shell_view->view, server, CAGE_XDG_SHELL_VIEW, &xdg_shell_view_impl);
|
|
|
|
|
xdg_shell_view->xdg_toplevel = toplevel;
|
2021-10-27 16:19:06 +02:00
|
|
|
|
2025-06-01 15:08:50 +02:00
|
|
|
xdg_shell_view->commit.notify = handle_xdg_toplevel_commit;
|
2024-08-24 15:44:46 +02:00
|
|
|
wl_signal_add(&toplevel->base->surface->events.commit, &xdg_shell_view->commit);
|
2025-06-01 15:08:50 +02:00
|
|
|
xdg_shell_view->map.notify = handle_xdg_toplevel_map;
|
2024-02-16 16:48:25 +01:00
|
|
|
wl_signal_add(&toplevel->base->surface->events.map, &xdg_shell_view->map);
|
2025-06-01 15:08:50 +02:00
|
|
|
xdg_shell_view->unmap.notify = handle_xdg_toplevel_unmap;
|
2024-02-16 16:48:25 +01:00
|
|
|
wl_signal_add(&toplevel->base->surface->events.unmap, &xdg_shell_view->unmap);
|
2025-06-01 15:08:50 +02:00
|
|
|
xdg_shell_view->destroy.notify = handle_xdg_toplevel_destroy;
|
2024-02-16 16:48:25 +01:00
|
|
|
wl_signal_add(&toplevel->events.destroy, &xdg_shell_view->destroy);
|
2025-06-01 15:08:50 +02:00
|
|
|
xdg_shell_view->request_fullscreen.notify = handle_xdg_toplevel_request_fullscreen;
|
2024-02-16 16:48:25 +01:00
|
|
|
wl_signal_add(&toplevel->events.request_fullscreen, &xdg_shell_view->request_fullscreen);
|
2021-10-27 16:19:06 +02:00
|
|
|
|
2024-02-16 16:48:25 +01:00
|
|
|
toplevel->base->data = xdg_shell_view;
|
|
|
|
|
}
|
2021-10-27 16:19:06 +02:00
|
|
|
|
2024-08-30 18:50:11 +02:00
|
|
|
static void
|
|
|
|
|
popup_handle_destroy(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct cg_xdg_popup *popup = wl_container_of(listener, popup, destroy);
|
|
|
|
|
wl_list_remove(&popup->destroy.link);
|
|
|
|
|
wl_list_remove(&popup->commit.link);
|
2025-06-01 15:05:37 +02:00
|
|
|
wl_list_remove(&popup->reposition.link);
|
2024-08-30 18:50:11 +02:00
|
|
|
free(popup);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
popup_handle_commit(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct cg_xdg_popup *popup = wl_container_of(listener, popup, commit);
|
|
|
|
|
|
|
|
|
|
if (popup->xdg_popup->base->initial_commit) {
|
|
|
|
|
popup_unconstrain(popup->xdg_popup);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-01 15:05:37 +02:00
|
|
|
static void
|
|
|
|
|
popup_handle_reposition(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct cg_xdg_popup *popup = wl_container_of(listener, popup, reposition);
|
|
|
|
|
|
|
|
|
|
popup_unconstrain(popup->xdg_popup);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-16 16:48:25 +01:00
|
|
|
void
|
|
|
|
|
handle_new_xdg_popup(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct cg_server *server = wl_container_of(listener, server, new_xdg_popup);
|
2024-08-30 18:50:11 +02:00
|
|
|
struct wlr_xdg_popup *wlr_popup = data;
|
2021-10-27 16:19:06 +02:00
|
|
|
|
2024-08-30 18:50:11 +02:00
|
|
|
struct cg_view *view = popup_get_view(wlr_popup);
|
2024-02-16 16:48:25 +01:00
|
|
|
if (view == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-10-27 16:19:06 +02:00
|
|
|
|
2024-02-16 16:48:25 +01:00
|
|
|
struct wlr_scene_tree *parent_scene_tree = NULL;
|
2024-08-30 18:50:11 +02:00
|
|
|
struct wlr_xdg_surface *parent = wlr_xdg_surface_try_from_wlr_surface(wlr_popup->parent);
|
2024-02-16 16:48:25 +01:00
|
|
|
if (parent == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (parent->role) {
|
|
|
|
|
case WLR_XDG_SURFACE_ROLE_TOPLEVEL:;
|
|
|
|
|
parent_scene_tree = view->scene_tree;
|
|
|
|
|
break;
|
|
|
|
|
case WLR_XDG_SURFACE_ROLE_POPUP:
|
|
|
|
|
parent_scene_tree = parent->data;
|
2021-10-27 16:19:06 +02:00
|
|
|
break;
|
|
|
|
|
case WLR_XDG_SURFACE_ROLE_NONE:
|
2024-02-16 16:48:25 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (parent_scene_tree == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-30 18:50:11 +02:00
|
|
|
struct cg_xdg_popup *popup = calloc(1, sizeof(*popup));
|
|
|
|
|
if (popup == NULL) {
|
|
|
|
|
wlr_log(WLR_ERROR, "Failed to allocate popup");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
popup->xdg_popup = wlr_popup;
|
|
|
|
|
|
|
|
|
|
popup->destroy.notify = popup_handle_destroy;
|
|
|
|
|
wl_signal_add(&wlr_popup->events.destroy, &popup->destroy);
|
|
|
|
|
|
|
|
|
|
popup->commit.notify = popup_handle_commit;
|
|
|
|
|
wl_signal_add(&wlr_popup->base->surface->events.commit, &popup->commit);
|
|
|
|
|
|
2025-06-01 15:05:37 +02:00
|
|
|
popup->reposition.notify = popup_handle_reposition;
|
|
|
|
|
wl_signal_add(&wlr_popup->events.reposition, &popup->reposition);
|
|
|
|
|
|
2024-08-30 18:50:11 +02:00
|
|
|
struct wlr_scene_tree *popup_scene_tree = wlr_scene_xdg_surface_create(parent_scene_tree, wlr_popup->base);
|
2024-02-16 16:48:25 +01:00
|
|
|
if (popup_scene_tree == NULL) {
|
|
|
|
|
wlr_log(WLR_ERROR, "Failed to allocate scene-graph node for XDG popup");
|
2024-08-30 18:50:11 +02:00
|
|
|
free(popup);
|
2024-02-16 16:48:25 +01:00
|
|
|
return;
|
2021-10-27 16:19:06 +02:00
|
|
|
}
|
2024-02-16 16:48:25 +01:00
|
|
|
|
2024-08-30 18:50:11 +02:00
|
|
|
wlr_popup->base->data = popup_scene_tree;
|
2018-12-31 00:12:33 +01:00
|
|
|
}
|
2019-02-17 22:17:11 +01:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
handle_xdg_toplevel_decoration(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct cg_server *server = wl_container_of(listener, server, xdg_toplevel_decoration);
|
|
|
|
|
struct wlr_xdg_toplevel_decoration_v1 *wlr_decoration = data;
|
|
|
|
|
|
|
|
|
|
struct cg_xdg_decoration *xdg_decoration = calloc(1, sizeof(struct cg_xdg_decoration));
|
|
|
|
|
if (!xdg_decoration) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xdg_decoration->wlr_decoration = wlr_decoration;
|
|
|
|
|
xdg_decoration->server = server;
|
|
|
|
|
|
|
|
|
|
xdg_decoration->destroy.notify = xdg_decoration_handle_destroy;
|
|
|
|
|
wl_signal_add(&wlr_decoration->events.destroy, &xdg_decoration->destroy);
|
2024-08-24 15:46:11 +02:00
|
|
|
xdg_decoration->commit.notify = xdg_decoration_handle_commit;
|
|
|
|
|
wl_signal_add(&wlr_decoration->toplevel->base->surface->events.commit, &xdg_decoration->commit);
|
2019-02-17 22:17:11 +01:00
|
|
|
xdg_decoration->request_mode.notify = xdg_decoration_handle_request_mode;
|
|
|
|
|
wl_signal_add(&wlr_decoration->events.request_mode, &xdg_decoration->request_mode);
|
|
|
|
|
}
|