mirror of
https://github.com/cage-kiosk/cage.git
synced 2026-02-05 04:06:24 -05:00
Add support for wlr-foreign-toplevel-management
This commit is contained in:
parent
f9626f7951
commit
19db25a3a1
6 changed files with 85 additions and 7 deletions
8
cage.c
8
cage.c
|
|
@ -24,6 +24,7 @@
|
|||
#include <wlr/types/wlr_compositor.h>
|
||||
#include <wlr/types/wlr_data_device.h>
|
||||
#include <wlr/types/wlr_export_dmabuf_v1.h>
|
||||
#include <wlr/types/wlr_foreign_toplevel_management_v1.h>
|
||||
#include <wlr/types/wlr_gamma_control_v1.h>
|
||||
#include <wlr/types/wlr_idle_inhibit_v1.h>
|
||||
#include <wlr/types/wlr_idle_notify_v1.h>
|
||||
|
|
@ -527,6 +528,13 @@ main(int argc, char *argv[])
|
|||
goto end;
|
||||
}
|
||||
|
||||
server.foreign_toplevel_manager = wlr_foreign_toplevel_manager_v1_create(server.wl_display);
|
||||
if (!server.foreign_toplevel_manager) {
|
||||
wlr_log(WLR_ERROR, "Unable to create the foreign toplevel manager");
|
||||
ret = 1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
#if CAGE_HAS_XWAYLAND
|
||||
struct wlr_xcursor_manager *xcursor_manager = NULL;
|
||||
struct wlr_xwayland *xwayland = wlr_xwayland_create(server.wl_display, compositor, true);
|
||||
|
|
|
|||
2
server.h
2
server.h
|
|
@ -61,6 +61,8 @@ struct cg_server {
|
|||
|
||||
struct wlr_relative_pointer_manager_v1 *relative_pointer_manager;
|
||||
|
||||
struct wlr_foreign_toplevel_manager_v1 *foreign_toplevel_manager;
|
||||
|
||||
bool xdg_decoration;
|
||||
bool allow_vt_switch;
|
||||
bool return_app_code;
|
||||
|
|
|
|||
43
view.c
43
view.c
|
|
@ -13,6 +13,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wayland-server-core.h>
|
||||
#include <wlr/types/wlr_foreign_toplevel_management_v1.h>
|
||||
#include <wlr/types/wlr_output.h>
|
||||
#include <wlr/types/wlr_scene.h>
|
||||
|
||||
|
|
@ -50,6 +51,7 @@ void
|
|||
view_activate(struct cg_view *view, bool activate)
|
||||
{
|
||||
view->impl->activate(view, activate);
|
||||
wlr_foreign_toplevel_handle_v1_set_activated(view->foreign_toplevel_handle, activate);
|
||||
}
|
||||
|
||||
static bool
|
||||
|
|
@ -115,20 +117,39 @@ view_unmap(struct cg_view *view)
|
|||
{
|
||||
wl_list_remove(&view->link);
|
||||
|
||||
wl_list_remove(&view->request_activate.link);
|
||||
wl_list_remove(&view->request_close.link);
|
||||
wlr_foreign_toplevel_handle_v1_destroy(view->foreign_toplevel_handle);
|
||||
view->foreign_toplevel_handle = NULL;
|
||||
|
||||
wlr_scene_node_destroy(&view->scene_tree->node);
|
||||
|
||||
view->wlr_surface->data = NULL;
|
||||
view->wlr_surface = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
handle_surface_request_activate(struct wl_listener *listener, void *data)
|
||||
{
|
||||
struct cg_view *view = wl_container_of(listener, view, request_activate);
|
||||
|
||||
wlr_scene_node_raise_to_top(&view->scene_tree->node);
|
||||
seat_set_focus(view->server->seat, view);
|
||||
}
|
||||
|
||||
void
|
||||
handle_surface_request_close(struct wl_listener *listener, void *data)
|
||||
{
|
||||
struct cg_view *view = wl_container_of(listener, view, request_close);
|
||||
view->impl->close(view);
|
||||
}
|
||||
|
||||
void
|
||||
view_map(struct cg_view *view, struct wlr_surface *surface)
|
||||
{
|
||||
view->scene_tree = wlr_scene_subsurface_tree_create(&view->server->scene->tree, surface);
|
||||
if (!view->scene_tree) {
|
||||
wl_resource_post_no_memory(surface->resource);
|
||||
return;
|
||||
}
|
||||
if (!view->scene_tree)
|
||||
goto fail;
|
||||
view->scene_tree->node.data = view;
|
||||
|
||||
view->wlr_surface = surface;
|
||||
|
|
@ -144,7 +165,21 @@ view_map(struct cg_view *view, struct wlr_surface *surface)
|
|||
}
|
||||
|
||||
wl_list_insert(&view->server->views, &view->link);
|
||||
|
||||
view->foreign_toplevel_handle = wlr_foreign_toplevel_handle_v1_create(view->server->foreign_toplevel_manager);
|
||||
if (!view->foreign_toplevel_handle)
|
||||
goto fail;
|
||||
|
||||
view->request_activate.notify = handle_surface_request_activate;
|
||||
wl_signal_add(&view->foreign_toplevel_handle->events.request_activate, &view->request_activate);
|
||||
view->request_close.notify = handle_surface_request_close;
|
||||
wl_signal_add(&view->foreign_toplevel_handle->events.request_close, &view->request_close);
|
||||
|
||||
seat_set_focus(view->server->seat, view);
|
||||
return;
|
||||
|
||||
fail:
|
||||
wl_resource_post_no_memory(surface->resource);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
5
view.h
5
view.h
|
|
@ -32,6 +32,10 @@ struct cg_view {
|
|||
|
||||
enum cg_view_type type;
|
||||
const struct cg_view_impl *impl;
|
||||
|
||||
struct wlr_foreign_toplevel_handle_v1 *foreign_toplevel_handle;
|
||||
struct wl_listener request_activate;
|
||||
struct wl_listener request_close;
|
||||
};
|
||||
|
||||
struct cg_view_impl {
|
||||
|
|
@ -41,6 +45,7 @@ struct cg_view_impl {
|
|||
bool (*is_transient_for)(struct cg_view *child, struct cg_view *parent);
|
||||
void (*activate)(struct cg_view *view, bool activate);
|
||||
void (*maximize)(struct cg_view *view, int output_width, int output_height);
|
||||
void (*close)(struct cg_view *view);
|
||||
void (*destroy)(struct cg_view *view);
|
||||
};
|
||||
|
||||
|
|
|
|||
19
xdg_shell.c
19
xdg_shell.c
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <wayland-server-core.h>
|
||||
#include <wlr/types/wlr_foreign_toplevel_management_v1.h>
|
||||
#include <wlr/types/wlr_scene.h>
|
||||
#include <wlr/types/wlr_xdg_shell.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
|
@ -183,10 +184,18 @@ destroy(struct cg_view *view)
|
|||
free(xdg_shell_view);
|
||||
}
|
||||
|
||||
static void
|
||||
close(struct cg_view *view)
|
||||
{
|
||||
struct cg_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view);
|
||||
wlr_xdg_toplevel_send_close(xdg_shell_view->xdg_toplevel);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_xdg_toplevel_request_fullscreen(struct wl_listener *listener, void *data)
|
||||
{
|
||||
struct cg_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, request_fullscreen);
|
||||
bool fullscreen = xdg_shell_view->xdg_toplevel->requested.fullscreen;
|
||||
|
||||
/**
|
||||
* Certain clients do not like figuring out their own window geometry if they
|
||||
|
|
@ -195,9 +204,8 @@ handle_xdg_toplevel_request_fullscreen(struct wl_listener *listener, void *data)
|
|||
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);
|
||||
|
||||
wlr_xdg_toplevel_set_fullscreen(xdg_shell_view->xdg_toplevel,
|
||||
xdg_shell_view->xdg_toplevel->requested.fullscreen);
|
||||
wlr_xdg_toplevel_set_fullscreen(xdg_shell_view->xdg_toplevel, fullscreen);
|
||||
wlr_foreign_toplevel_handle_v1_set_fullscreen(xdg_shell_view->view.foreign_toplevel_handle, fullscreen);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -216,6 +224,10 @@ handle_xdg_toplevel_map(struct wl_listener *listener, void *data)
|
|||
struct cg_view *view = &xdg_shell_view->view;
|
||||
|
||||
view_map(view, xdg_shell_view->xdg_toplevel->base->surface);
|
||||
|
||||
wlr_foreign_toplevel_handle_v1_set_title(view->foreign_toplevel_handle, xdg_shell_view->xdg_toplevel->title);
|
||||
wlr_foreign_toplevel_handle_v1_set_app_id(view->foreign_toplevel_handle, xdg_shell_view->xdg_toplevel->app_id);
|
||||
/* Activation state will be set by seat_set_focus */
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -258,6 +270,7 @@ static const struct cg_view_impl xdg_shell_view_impl = {
|
|||
.activate = activate,
|
||||
.maximize = maximize,
|
||||
.destroy = destroy,
|
||||
.close = close,
|
||||
};
|
||||
|
||||
void
|
||||
|
|
|
|||
15
xwayland.c
15
xwayland.c
|
|
@ -9,6 +9,7 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <wayland-server-core.h>
|
||||
#include <wlr/types/wlr_foreign_toplevel_management_v1.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include <wlr/xwayland.h>
|
||||
|
||||
|
|
@ -102,12 +103,21 @@ destroy(struct cg_view *view)
|
|||
free(xwayland_view);
|
||||
}
|
||||
|
||||
static void
|
||||
close(struct cg_view *view)
|
||||
{
|
||||
struct cg_xwayland_view *xwayland_view = xwayland_view_from_view(view);
|
||||
wlr_xwayland_surface_close(xwayland_view->xwayland_surface);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_xwayland_surface_request_fullscreen(struct wl_listener *listener, void *data)
|
||||
{
|
||||
struct cg_xwayland_view *xwayland_view = wl_container_of(listener, xwayland_view, request_fullscreen);
|
||||
struct wlr_xwayland_surface *xwayland_surface = xwayland_view->xwayland_surface;
|
||||
wlr_xwayland_surface_set_fullscreen(xwayland_view->xwayland_surface, xwayland_surface->fullscreen);
|
||||
wlr_foreign_toplevel_handle_v1_set_fullscreen(xwayland_view->view.foreign_toplevel_handle,
|
||||
xwayland_surface->fullscreen);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -131,6 +141,10 @@ handle_xwayland_surface_map(struct wl_listener *listener, void *data)
|
|||
}
|
||||
|
||||
view_map(view, xwayland_view->xwayland_surface->surface);
|
||||
|
||||
wlr_foreign_toplevel_handle_v1_set_title(view->foreign_toplevel_handle, xwayland_view->xwayland_surface->title);
|
||||
wlr_foreign_toplevel_handle_v1_set_app_id(view->foreign_toplevel_handle,
|
||||
xwayland_view->xwayland_surface->class);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -154,6 +168,7 @@ static const struct cg_view_impl xwayland_view_impl = {
|
|||
.activate = activate,
|
||||
.maximize = maximize,
|
||||
.destroy = destroy,
|
||||
.close = close,
|
||||
};
|
||||
|
||||
void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue