mirror of
https://github.com/cage-kiosk/cage.git
synced 2025-10-29 05:40:19 -04:00
Implement xdg-decoration
This commit adds a commandline switch (-d) to disable client side decorations, if possible. In this case, Cage will not draw any decorations of its own, in order to maximize screen real estate. The default behavior remains the same, i.e., if -d is not passed, clients will draw their client side decorations, if any. Fixes #32
This commit is contained in:
parent
996f641cf0
commit
2166fbdcfb
4 changed files with 76 additions and 6 deletions
20
cage.c
20
cage.c
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Cage: A Wayland kiosk.
|
* Cage: A Wayland kiosk.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2018-2019 Jente Hidskes
|
* Copyright (C) 2018-2019 Jente Hidskes
|
||||||
*
|
*
|
||||||
* See the LICENSE file accompanying this file.
|
* See the LICENSE file accompanying this file.
|
||||||
|
|
@ -27,6 +27,7 @@
|
||||||
#if CAGE_HAS_XWAYLAND
|
#if CAGE_HAS_XWAYLAND
|
||||||
#include <wlr/types/wlr_xcursor_manager.h>
|
#include <wlr/types/wlr_xcursor_manager.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <wlr/types/wlr_xdg_decoration_v1.h>
|
||||||
#include <wlr/types/wlr_xdg_shell.h>
|
#include <wlr/types/wlr_xdg_shell.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#if CAGE_HAS_XWAYLAND
|
#if CAGE_HAS_XWAYLAND
|
||||||
|
|
@ -84,6 +85,7 @@ usage(FILE *file, const char *cage)
|
||||||
{
|
{
|
||||||
fprintf(file, "Usage: %s APPLICATION\n"
|
fprintf(file, "Usage: %s APPLICATION\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
" -d\t Don't draw client side decorations, when possible\n"
|
||||||
" -D\t Turn on damage tracking debugging\n"
|
" -D\t Turn on damage tracking debugging\n"
|
||||||
" -h\t Display this help message\n",
|
" -h\t Display this help message\n",
|
||||||
cage);
|
cage);
|
||||||
|
|
@ -93,8 +95,11 @@ static bool
|
||||||
parse_args(struct cg_server *server, int argc, char *argv[])
|
parse_args(struct cg_server *server, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
while ((c = getopt(argc, argv, "hD")) != -1) {
|
while ((c = getopt(argc, argv, "dDh")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
case 'd':
|
||||||
|
server->xdg_decoration = true;
|
||||||
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
server->debug_damage_tracking = true;
|
server->debug_damage_tracking = true;
|
||||||
break;
|
break;
|
||||||
|
|
@ -123,6 +128,7 @@ main(int argc, char *argv[])
|
||||||
struct wlr_renderer *renderer = NULL;
|
struct wlr_renderer *renderer = NULL;
|
||||||
struct wlr_compositor *compositor = NULL;
|
struct wlr_compositor *compositor = NULL;
|
||||||
struct wlr_data_device_manager *data_device_mgr = NULL;
|
struct wlr_data_device_manager *data_device_mgr = NULL;
|
||||||
|
struct wlr_xdg_decoration_manager_v1 *xdg_decoration_manager = NULL;
|
||||||
struct wlr_xdg_shell *xdg_shell = NULL;
|
struct wlr_xdg_shell *xdg_shell = NULL;
|
||||||
#if CAGE_HAS_XWAYLAND
|
#if CAGE_HAS_XWAYLAND
|
||||||
struct wlr_xwayland *xwayland = NULL;
|
struct wlr_xwayland *xwayland = NULL;
|
||||||
|
|
@ -160,6 +166,8 @@ main(int argc, char *argv[])
|
||||||
renderer = wlr_backend_get_renderer(server.backend);
|
renderer = wlr_backend_get_renderer(server.backend);
|
||||||
wlr_renderer_init_wl_display(renderer, server.wl_display);
|
wlr_renderer_init_wl_display(renderer, server.wl_display);
|
||||||
|
|
||||||
|
wl_list_init(&server.views);
|
||||||
|
|
||||||
server.output_layout = wlr_output_layout_create();
|
server.output_layout = wlr_output_layout_create();
|
||||||
if (!server.output_layout) {
|
if (!server.output_layout) {
|
||||||
wlr_log(WLR_ERROR, "Unable to create output layout");
|
wlr_log(WLR_ERROR, "Unable to create output layout");
|
||||||
|
|
@ -210,17 +218,20 @@ main(int argc, char *argv[])
|
||||||
server.new_idle_inhibitor_v1.notify = handle_idle_inhibitor_v1_new;
|
server.new_idle_inhibitor_v1.notify = handle_idle_inhibitor_v1_new;
|
||||||
wl_signal_add(&server.idle_inhibit_v1->events.new_inhibitor, &server.new_idle_inhibitor_v1);
|
wl_signal_add(&server.idle_inhibit_v1->events.new_inhibitor, &server.new_idle_inhibitor_v1);
|
||||||
wl_list_init(&server.inhibitors);
|
wl_list_init(&server.inhibitors);
|
||||||
|
|
||||||
xdg_shell = wlr_xdg_shell_create(server.wl_display);
|
xdg_shell = wlr_xdg_shell_create(server.wl_display);
|
||||||
if (!xdg_shell) {
|
if (!xdg_shell) {
|
||||||
wlr_log(WLR_ERROR, "Unable to create the XDG shell interface");
|
wlr_log(WLR_ERROR, "Unable to create the XDG shell interface");
|
||||||
ret = 1;
|
ret = 1;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
wl_list_init(&server.views);
|
|
||||||
server.new_xdg_shell_surface.notify = handle_xdg_shell_surface_new;
|
server.new_xdg_shell_surface.notify = handle_xdg_shell_surface_new;
|
||||||
wl_signal_add(&xdg_shell->events.new_surface, &server.new_xdg_shell_surface);
|
wl_signal_add(&xdg_shell->events.new_surface, &server.new_xdg_shell_surface);
|
||||||
|
|
||||||
|
xdg_decoration_manager = wlr_xdg_decoration_manager_v1_create(server.wl_display);
|
||||||
|
wl_signal_add(&xdg_decoration_manager->events.new_toplevel_decoration, &server.xdg_toplevel_decoration);
|
||||||
|
server.xdg_toplevel_decoration.notify = handle_xdg_toplevel_decoration;
|
||||||
|
|
||||||
#if CAGE_HAS_XWAYLAND
|
#if CAGE_HAS_XWAYLAND
|
||||||
xwayland = wlr_xwayland_create(server.wl_display, compositor, true);
|
xwayland = wlr_xwayland_create(server.wl_display, compositor, true);
|
||||||
if (!xwayland) {
|
if (!xwayland) {
|
||||||
|
|
@ -293,6 +304,7 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
end:
|
end:
|
||||||
seat_destroy(server.seat);
|
seat_destroy(server.seat);
|
||||||
|
wlr_xdg_decoration_manager_v1_destroy(xdg_decoration_manager);
|
||||||
wlr_xdg_shell_destroy(xdg_shell);
|
wlr_xdg_shell_destroy(xdg_shell);
|
||||||
wlr_idle_inhibit_v1_destroy(server.idle_inhibit_v1);
|
wlr_idle_inhibit_v1_destroy(server.idle_inhibit_v1);
|
||||||
if (server.idle) {
|
if (server.idle) {
|
||||||
|
|
|
||||||
6
server.h
6
server.h
|
|
@ -8,6 +8,7 @@
|
||||||
#include <wlr/types/wlr_idle.h>
|
#include <wlr/types/wlr_idle.h>
|
||||||
#include <wlr/types/wlr_idle_inhibit_v1.h>
|
#include <wlr/types/wlr_idle_inhibit_v1.h>
|
||||||
#include <wlr/types/wlr_output_layout.h>
|
#include <wlr/types/wlr_output_layout.h>
|
||||||
|
#include <wlr/types/wlr_xdg_decoration_v1.h>
|
||||||
#if CAGE_HAS_XWAYLAND
|
#if CAGE_HAS_XWAYLAND
|
||||||
#include <wlr/xwayland.h>
|
#include <wlr/xwayland.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -19,8 +20,6 @@
|
||||||
struct cg_server {
|
struct cg_server {
|
||||||
struct wl_display *wl_display;
|
struct wl_display *wl_display;
|
||||||
struct wlr_backend *backend;
|
struct wlr_backend *backend;
|
||||||
|
|
||||||
struct wl_listener new_xdg_shell_surface;
|
|
||||||
struct wl_list views;
|
struct wl_list views;
|
||||||
|
|
||||||
struct cg_seat *seat;
|
struct cg_seat *seat;
|
||||||
|
|
@ -33,10 +32,13 @@ struct cg_server {
|
||||||
struct cg_output *output;
|
struct cg_output *output;
|
||||||
struct wl_listener new_output;
|
struct wl_listener new_output;
|
||||||
|
|
||||||
|
struct wl_listener xdg_toplevel_decoration;
|
||||||
|
struct wl_listener new_xdg_shell_surface;
|
||||||
#if CAGE_HAS_XWAYLAND
|
#if CAGE_HAS_XWAYLAND
|
||||||
struct wl_listener new_xwayland_surface;
|
struct wl_listener new_xwayland_surface;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool xdg_decoration;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
bool debug_damage_tracking;
|
bool debug_damage_tracking;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
46
xdg_shell.c
46
xdg_shell.c
|
|
@ -17,6 +17,30 @@
|
||||||
#include "view.h"
|
#include "view.h"
|
||||||
#include "xdg_shell.h"
|
#include "xdg_shell.h"
|
||||||
|
|
||||||
|
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);
|
||||||
|
wl_list_remove(&xdg_decoration->request_mode.link);
|
||||||
|
free(xdg_decoration);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xdg_popup_destroy(struct cg_view_child *child)
|
xdg_popup_destroy(struct cg_view_child *child)
|
||||||
{
|
{
|
||||||
|
|
@ -304,3 +328,25 @@ handle_xdg_shell_surface_new(struct wl_listener *listener, void *data)
|
||||||
xdg_shell_view->new_popup.notify = handle_new_xdg_popup;
|
xdg_shell_view->new_popup.notify = handle_new_xdg_popup;
|
||||||
wl_signal_add(&xdg_surface->events.new_popup, &xdg_shell_view->new_popup);
|
wl_signal_add(&xdg_surface->events.new_popup, &xdg_shell_view->new_popup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
xdg_decoration->request_mode.notify = xdg_decoration_handle_request_mode;
|
||||||
|
wl_signal_add(&wlr_decoration->events.request_mode, &xdg_decoration->request_mode);
|
||||||
|
|
||||||
|
xdg_decoration_handle_request_mode(&xdg_decoration->request_mode, wlr_decoration);
|
||||||
|
}
|
||||||
|
|
|
||||||
10
xdg_shell.h
10
xdg_shell.h
|
|
@ -2,6 +2,7 @@
|
||||||
#define CG_XDG_SHELL_H
|
#define CG_XDG_SHELL_H
|
||||||
|
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
|
#include <wlr/types/wlr_xdg_decoration_v1.h>
|
||||||
#include <wlr/types/wlr_xdg_shell.h>
|
#include <wlr/types/wlr_xdg_shell.h>
|
||||||
|
|
||||||
#include "view.h"
|
#include "view.h"
|
||||||
|
|
@ -28,6 +29,15 @@ struct cg_xdg_popup {
|
||||||
struct wl_listener new_popup;
|
struct wl_listener new_popup;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct cg_xdg_decoration {
|
||||||
|
struct wlr_xdg_toplevel_decoration_v1 *wlr_decoration;
|
||||||
|
struct cg_server *server;
|
||||||
|
struct wl_listener destroy;
|
||||||
|
struct wl_listener request_mode;
|
||||||
|
};
|
||||||
|
|
||||||
void handle_xdg_shell_surface_new(struct wl_listener *listener, void *data);
|
void handle_xdg_shell_surface_new(struct wl_listener *listener, void *data);
|
||||||
|
|
||||||
|
void handle_xdg_toplevel_decoration(struct wl_listener *listener, void *data);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue