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.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-01-24 14:14:15 +01:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
|
|
2018-12-31 00:12:33 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stdlib.h>
|
2019-01-24 14:14:15 +01:00
|
|
|
#include <string.h>
|
2018-12-31 00:12:33 +01:00
|
|
|
#include <wayland-server.h>
|
|
|
|
|
#include <wlr/types/wlr_box.h>
|
|
|
|
|
#include <wlr/types/wlr_output.h>
|
|
|
|
|
#include <wlr/types/wlr_surface.h>
|
|
|
|
|
|
|
|
|
|
#include "output.h"
|
|
|
|
|
#include "seat.h"
|
|
|
|
|
#include "server.h"
|
|
|
|
|
#include "view.h"
|
|
|
|
|
|
2019-01-24 14:14:15 +01:00
|
|
|
char *
|
|
|
|
|
view_get_title(struct cg_view *view)
|
|
|
|
|
{
|
|
|
|
|
const char *title = view->get_title(view);
|
|
|
|
|
return strndup(title, strlen(title));
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-31 00:12:33 +01:00
|
|
|
void
|
|
|
|
|
view_activate(struct cg_view *view, bool activate)
|
|
|
|
|
{
|
|
|
|
|
view->activate(view, activate);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 15:57:23 +01:00
|
|
|
static void
|
2018-12-31 00:12:33 +01:00
|
|
|
view_maximize(struct cg_view *view)
|
|
|
|
|
{
|
|
|
|
|
struct cg_output *output = view->server->output;
|
|
|
|
|
int output_width, output_height;
|
|
|
|
|
|
2019-01-20 14:11:52 +01:00
|
|
|
wlr_output_transformed_resolution(output->wlr_output, &output_width, &output_height);
|
2018-12-31 00:12:33 +01:00
|
|
|
view->maximize(view, output_width, output_height);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 15:57:23 +01:00
|
|
|
static void
|
2018-12-31 00:12:33 +01:00
|
|
|
view_center(struct cg_view *view)
|
|
|
|
|
{
|
2019-01-10 15:57:53 +01:00
|
|
|
struct wlr_output *output = view->server->output->wlr_output;
|
2018-12-31 00:12:33 +01:00
|
|
|
|
|
|
|
|
int output_width, output_height;
|
2019-01-20 14:11:52 +01:00
|
|
|
wlr_output_transformed_resolution(output, &output_width, &output_height);
|
2018-12-31 00:12:33 +01:00
|
|
|
|
2018-12-31 20:44:20 +01:00
|
|
|
int width, height;
|
|
|
|
|
view->get_geometry(view, &width, &height);
|
2018-12-31 00:12:33 +01:00
|
|
|
|
2018-12-31 20:44:20 +01:00
|
|
|
view->x = (output_width - width) / 2;
|
|
|
|
|
view->y = (output_height - height) / 2;
|
2018-12-31 00:12:33 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-02 21:23:16 +01:00
|
|
|
void
|
|
|
|
|
view_for_each_surface(struct cg_view *view, wlr_surface_iterator_func_t iterator,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
view->for_each_surface(view, iterator, data);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-02 21:31:30 +01:00
|
|
|
struct wlr_surface *
|
|
|
|
|
view_wlr_surface_at(struct cg_view *view, double sx, double sy, double *sub_x, double *sub_y)
|
|
|
|
|
{
|
|
|
|
|
return view->wlr_surface_at(view, sx, sy, sub_x, sub_y);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-31 00:12:33 +01:00
|
|
|
bool
|
|
|
|
|
view_is_primary(struct cg_view *view)
|
|
|
|
|
{
|
|
|
|
|
return view->is_primary(view);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-12 17:51:17 +01:00
|
|
|
bool
|
|
|
|
|
view_has_children(struct cg_server *server, struct cg_view *parent)
|
|
|
|
|
{
|
|
|
|
|
struct cg_view *child;
|
|
|
|
|
wl_list_for_each(child, &server->views, link) {
|
|
|
|
|
if (parent != child && parent->is_parent(parent, child)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 15:50:31 +01:00
|
|
|
void
|
|
|
|
|
view_position(struct cg_view *view)
|
|
|
|
|
{
|
|
|
|
|
if (view_is_primary(view)) {
|
|
|
|
|
view_maximize(view);
|
|
|
|
|
} else {
|
|
|
|
|
view_center(view);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-31 19:52:47 +01:00
|
|
|
void
|
|
|
|
|
view_unmap(struct cg_view *view)
|
|
|
|
|
{
|
|
|
|
|
wl_list_remove(&view->link);
|
|
|
|
|
view->wlr_surface = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-31 00:12:33 +01:00
|
|
|
void
|
|
|
|
|
view_map(struct cg_view *view, struct wlr_surface *surface)
|
|
|
|
|
{
|
|
|
|
|
view->wlr_surface = surface;
|
|
|
|
|
|
2019-01-10 15:50:31 +01:00
|
|
|
view_position(view);
|
2018-12-31 00:12:33 +01:00
|
|
|
|
2018-12-31 19:52:47 +01:00
|
|
|
wl_list_insert(&view->server->views, &view->link);
|
2018-12-31 00:12:33 +01:00
|
|
|
seat_set_focus(view->server->seat, view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
view_destroy(struct cg_view *view)
|
|
|
|
|
{
|
|
|
|
|
struct cg_server *server = view->server;
|
view: test whether XWayland surfaces have been mapped
This is to work around "misbehaving" (for lack of a better term)
clients. At the moment, Firefox Nightly and Google Chrome/Chromium are
known to be suchs client:
When XWayland support is enabled, Firefox first creates an XWayland
surface, closes this (before mapping it) and then opens an XDG toplevel
surface. Cage tries to manage the first XWayland surface, but when it
closes, Cage has no surfaces left and hence closes as well.
Hence, Cage terminates before it picks up on Firefox's XDG toplevel, and
Firefox (rightly) prints it cannot read the Wayland pipe.
In Chromium's case, it simply opens an XWayland surface which it
immediately closes, before opening the "real" XWayland surface.
The workaround is to track whether an XWayland surface has been mapped
and, if it hasn't, to not exit when we have no views left.
Firefox's behavior and the workaround are discussed in #18.
This commit fixes #18 and is part of the fix for #19.
2019-01-18 16:37:15 +01:00
|
|
|
bool mapped = true;
|
|
|
|
|
|
|
|
|
|
#if CAGE_HAS_XWAYLAND
|
|
|
|
|
/* Some applications that aren't yet Wayland-native or
|
|
|
|
|
otherwise "special" (e.g. Firefox Nightly and Google
|
|
|
|
|
Chrome/Chromium) spawn an XWayland surface upon startup
|
|
|
|
|
that is almost immediately closed again. This makes Cage
|
|
|
|
|
think there are no views left, which results in it
|
|
|
|
|
exiting. However, after this initial (unmapped) surface,
|
|
|
|
|
the "real" application surface is opened. This leads to
|
|
|
|
|
these applications' startup sequences being interrupted by
|
|
|
|
|
Cage exiting. Hence, to work around this issue, Cage checks
|
|
|
|
|
whether an XWayland surface has been mapped and exits only
|
|
|
|
|
if 1) the XWayland surface has been mapped and 2) this was
|
|
|
|
|
the last surface Cage manages. */
|
|
|
|
|
if (view->type == CAGE_XWAYLAND_VIEW) {
|
|
|
|
|
mapped = view->xwayland_surface->mapped;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2018-12-31 00:12:33 +01:00
|
|
|
|
2019-01-04 17:24:42 +01:00
|
|
|
if (view->wlr_surface != NULL) {
|
|
|
|
|
view_unmap(view);
|
|
|
|
|
}
|
2018-12-31 00:12:33 +01:00
|
|
|
free(view);
|
|
|
|
|
|
view: test whether XWayland surfaces have been mapped
This is to work around "misbehaving" (for lack of a better term)
clients. At the moment, Firefox Nightly and Google Chrome/Chromium are
known to be suchs client:
When XWayland support is enabled, Firefox first creates an XWayland
surface, closes this (before mapping it) and then opens an XDG toplevel
surface. Cage tries to manage the first XWayland surface, but when it
closes, Cage has no surfaces left and hence closes as well.
Hence, Cage terminates before it picks up on Firefox's XDG toplevel, and
Firefox (rightly) prints it cannot read the Wayland pipe.
In Chromium's case, it simply opens an XWayland surface which it
immediately closes, before opening the "real" XWayland surface.
The workaround is to track whether an XWayland surface has been mapped
and, if it hasn't, to not exit when we have no views left.
Firefox's behavior and the workaround are discussed in #18.
This commit fixes #18 and is part of the fix for #19.
2019-01-18 16:37:15 +01:00
|
|
|
/* If there is a previous view in the list, focus that. */
|
|
|
|
|
bool empty = wl_list_empty(&server->views);
|
|
|
|
|
if (!empty) {
|
2019-01-04 17:25:32 +01:00
|
|
|
struct cg_view *prev = wl_container_of(server->views.next, prev, link);
|
|
|
|
|
seat_set_focus(server->seat, prev);
|
view: test whether XWayland surfaces have been mapped
This is to work around "misbehaving" (for lack of a better term)
clients. At the moment, Firefox Nightly and Google Chrome/Chromium are
known to be suchs client:
When XWayland support is enabled, Firefox first creates an XWayland
surface, closes this (before mapping it) and then opens an XDG toplevel
surface. Cage tries to manage the first XWayland surface, but when it
closes, Cage has no surfaces left and hence closes as well.
Hence, Cage terminates before it picks up on Firefox's XDG toplevel, and
Firefox (rightly) prints it cannot read the Wayland pipe.
In Chromium's case, it simply opens an XWayland surface which it
immediately closes, before opening the "real" XWayland surface.
The workaround is to track whether an XWayland surface has been mapped
and, if it hasn't, to not exit when we have no views left.
Firefox's behavior and the workaround are discussed in #18.
This commit fixes #18 and is part of the fix for #19.
2019-01-18 16:37:15 +01:00
|
|
|
} else if (mapped) {
|
|
|
|
|
/* The list is empty and the last view has been
|
|
|
|
|
mapped, so we can safely exit. */
|
|
|
|
|
wl_display_terminate(server->wl_display);
|
2018-12-31 00:12:33 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct cg_view *
|
|
|
|
|
cg_view_create(struct cg_server *server)
|
|
|
|
|
{
|
|
|
|
|
struct cg_view *view = calloc(1, sizeof(struct cg_view));
|
|
|
|
|
|
|
|
|
|
view->server = server;
|
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct cg_view *
|
|
|
|
|
cg_view_from_wlr_surface(struct cg_server *server, struct wlr_surface *surface)
|
|
|
|
|
{
|
|
|
|
|
struct cg_view *view;
|
|
|
|
|
wl_list_for_each(view, &server->views, link) {
|
|
|
|
|
if (view->wlr_surface == surface) {
|
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|