2021-09-24 21:45:48 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2023-01-07 17:50:33 -05:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
2020-09-28 20:53:59 +01:00
|
|
|
#include <assert.h>
|
2023-01-07 17:50:33 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <wlr/xwayland.h>
|
2022-09-16 18:41:02 -04:00
|
|
|
#include "common/mem.h"
|
2019-12-26 21:37:31 +00:00
|
|
|
#include "labwc.h"
|
2022-03-02 21:07:04 +00:00
|
|
|
#include "node.h"
|
2021-03-21 20:54:55 +00:00
|
|
|
#include "ssd.h"
|
2022-11-21 10:10:39 -05:00
|
|
|
#include "view.h"
|
2023-02-05 19:29:24 +00:00
|
|
|
#include "view-impl-common.h"
|
2023-04-28 21:41:41 +01:00
|
|
|
#include "window-rules.h"
|
2022-06-15 02:02:50 +02:00
|
|
|
#include "workspaces.h"
|
2023-01-07 17:50:33 -05:00
|
|
|
#include "xwayland.h"
|
2019-12-26 21:37:31 +00:00
|
|
|
|
2023-01-04 04:18:00 +01:00
|
|
|
static int
|
|
|
|
|
round_to_increment(int val, int base, int inc)
|
|
|
|
|
{
|
|
|
|
|
if (base < 0 || inc <= 0)
|
|
|
|
|
return val;
|
|
|
|
|
return base + (val - base + inc / 2) / inc * inc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
xwayland_apply_size_hints(struct view *view, int *w, int *h)
|
|
|
|
|
{
|
2023-01-07 17:50:33 -05:00
|
|
|
assert(view);
|
2023-01-04 04:18:00 +01:00
|
|
|
if (view->type == LAB_XWAYLAND_VIEW) {
|
|
|
|
|
xcb_size_hints_t *hints =
|
|
|
|
|
xwayland_surface_from_view(view)->size_hints;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Honor size increments from WM_SIZE_HINTS. Typically, X11
|
|
|
|
|
* terminal emulators will use WM_SIZE_HINTS to make sure that
|
|
|
|
|
* the terminal is resized to a width/height evenly divisible by
|
|
|
|
|
* the cell (character) size.
|
|
|
|
|
*/
|
|
|
|
|
if (hints) {
|
|
|
|
|
*w = round_to_increment(*w, hints->base_width,
|
|
|
|
|
hints->width_inc);
|
|
|
|
|
*h = round_to_increment(*h, hints->base_height,
|
|
|
|
|
hints->height_inc);
|
|
|
|
|
|
|
|
|
|
*w = MAX(*w, MAX(1, hints->min_width));
|
|
|
|
|
*h = MAX(*h, MAX(1, hints->min_height));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-07 17:50:33 -05:00
|
|
|
static struct wlr_xwayland_surface *
|
|
|
|
|
top_parent_of(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
struct wlr_xwayland_surface *s = xwayland_surface_from_view(view);
|
|
|
|
|
while (s->parent) {
|
|
|
|
|
s = s->parent;
|
|
|
|
|
}
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-22 20:13:06 +00:00
|
|
|
static struct xwayland_view *
|
|
|
|
|
xwayland_view_from_view(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
assert(view->type == LAB_XWAYLAND_VIEW);
|
|
|
|
|
return (struct xwayland_view *)view;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 13:41:12 -05:00
|
|
|
struct wlr_xwayland_surface *
|
|
|
|
|
xwayland_surface_from_view(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
struct xwayland_view *xwayland_view = xwayland_view_from_view(view);
|
|
|
|
|
assert(xwayland_view->xwayland_surface);
|
|
|
|
|
return xwayland_view->xwayland_surface;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-07 21:12:56 -05:00
|
|
|
static void
|
2023-02-03 14:45:04 -05:00
|
|
|
ensure_initial_geometry_and_output(struct view *view)
|
2023-02-07 21:12:56 -05:00
|
|
|
{
|
2023-02-08 23:19:14 -05:00
|
|
|
if (wlr_box_empty(&view->current)) {
|
2023-02-07 21:12:56 -05:00
|
|
|
struct wlr_xwayland_surface *xwayland_surface =
|
|
|
|
|
xwayland_surface_from_view(view);
|
2023-02-08 23:19:14 -05:00
|
|
|
view->current.x = xwayland_surface->x;
|
|
|
|
|
view->current.y = xwayland_surface->y;
|
|
|
|
|
view->current.width = xwayland_surface->width;
|
|
|
|
|
view->current.height = xwayland_surface->height;
|
2023-02-07 21:12:56 -05:00
|
|
|
/*
|
|
|
|
|
* If there is no pending move/resize yet, then set
|
|
|
|
|
* current values (used in map()).
|
|
|
|
|
*/
|
2023-02-08 23:19:14 -05:00
|
|
|
if (wlr_box_empty(&view->pending)) {
|
|
|
|
|
view->pending = view->current;
|
2023-02-07 21:12:56 -05:00
|
|
|
}
|
|
|
|
|
}
|
2023-02-03 14:45:04 -05:00
|
|
|
if (!view->output) {
|
|
|
|
|
/*
|
|
|
|
|
* Just use the cursor output since we don't know yet
|
|
|
|
|
* whether the surface position is meaningful.
|
|
|
|
|
*/
|
2023-02-28 11:46:48 -05:00
|
|
|
view_set_output(view, output_nearest_to_cursor(view->server));
|
2023-02-03 14:45:04 -05:00
|
|
|
}
|
2023-02-07 21:12:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
want_deco(struct wlr_xwayland_surface *xwayland_surface)
|
|
|
|
|
{
|
2023-04-28 21:41:41 +01:00
|
|
|
struct view *view = (struct view *)xwayland_surface->data;
|
|
|
|
|
|
|
|
|
|
/* Window-rules take priority if they exist for this view */
|
|
|
|
|
switch (window_rules_get_property(view, "serverDecoration")) {
|
|
|
|
|
case LAB_PROP_TRUE:
|
|
|
|
|
return true;
|
|
|
|
|
case LAB_PROP_FALSE:
|
|
|
|
|
return false;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-07 21:12:56 -05:00
|
|
|
return xwayland_surface->decorations ==
|
|
|
|
|
WLR_XWAYLAND_SURFACE_DECORATIONS_ALL;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
handle_commit(struct wl_listener *listener, void *data)
|
2020-08-31 08:12:44 +01:00
|
|
|
{
|
|
|
|
|
struct view *view = wl_container_of(listener, view, commit);
|
2022-11-11 15:54:26 -05:00
|
|
|
assert(data && data == view->surface);
|
2020-08-31 08:12:44 +01:00
|
|
|
|
|
|
|
|
/* Must receive commit signal before accessing surface->current* */
|
2022-02-25 21:31:21 +01:00
|
|
|
struct wlr_surface_state *state = &view->surface->current;
|
2023-02-08 23:19:14 -05:00
|
|
|
struct wlr_box *current = &view->current;
|
2022-02-25 21:31:21 +01:00
|
|
|
|
2023-02-25 12:05:22 -05:00
|
|
|
/*
|
|
|
|
|
* If there is a pending move/resize, wait until the surface
|
|
|
|
|
* size changes to update geometry. The hope is to update both
|
|
|
|
|
* the position and the size of the view at the same time,
|
|
|
|
|
* reducing visual glitches.
|
|
|
|
|
*/
|
|
|
|
|
if (current->width != state->width || current->height != state->height) {
|
|
|
|
|
view_impl_apply_geometry(view, state->width, state->height);
|
2020-12-23 18:36:40 +00:00
|
|
|
}
|
2020-08-31 08:12:44 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-17 17:11:41 +00:00
|
|
|
static void
|
|
|
|
|
handle_request_move(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* This event is raised when a client would like to begin an interactive
|
|
|
|
|
* move, typically because the user clicked on their client-side
|
|
|
|
|
* decorations. Note that a more sophisticated compositor should check
|
2023-02-25 12:05:22 -05:00
|
|
|
* the provided serial against a list of button press serials sent to
|
2022-03-28 20:51:59 +01:00
|
|
|
* this client, to prevent the client from requesting this whenever they
|
2021-10-17 17:11:41 +00:00
|
|
|
* want.
|
|
|
|
|
*/
|
|
|
|
|
struct view *view = wl_container_of(listener, view, request_move);
|
|
|
|
|
interactive_begin(view, LAB_INPUT_STATE_MOVE, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-17 17:12:51 +00:00
|
|
|
static void
|
|
|
|
|
handle_request_resize(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* This event is raised when a client would like to begin an interactive
|
|
|
|
|
* resize, typically because the user clicked on their client-side
|
|
|
|
|
* decorations. Note that a more sophisticated compositor should check
|
2023-02-25 12:05:22 -05:00
|
|
|
* the provided serial against a list of button press serials sent to
|
2022-03-28 20:51:59 +01:00
|
|
|
* this client, to prevent the client from requesting this whenever they
|
2021-10-17 17:12:51 +00:00
|
|
|
* want.
|
|
|
|
|
*/
|
|
|
|
|
struct wlr_xwayland_resize_event *event = data;
|
|
|
|
|
struct view *view = wl_container_of(listener, view, request_resize);
|
|
|
|
|
interactive_begin(view, LAB_INPUT_STATE_RESIZE, event->edges);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
handle_map(struct wl_listener *listener, void *data)
|
2019-12-27 21:22:45 +00:00
|
|
|
{
|
2019-12-27 20:48:58 +00:00
|
|
|
struct view *view = wl_container_of(listener, view, map);
|
2020-09-03 20:50:35 +01:00
|
|
|
view->impl->map(view);
|
2019-12-26 21:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
handle_unmap(struct wl_listener *listener, void *data)
|
2019-12-27 21:22:45 +00:00
|
|
|
{
|
2019-12-27 20:48:58 +00:00
|
|
|
struct view *view = wl_container_of(listener, view, unmap);
|
2020-09-03 20:50:35 +01:00
|
|
|
view->impl->unmap(view);
|
2022-05-17 18:10:29 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Some xwayland clients leave unmapped child views around, typically
|
|
|
|
|
* when a dialog window is closed. Although handle_destroy() is not
|
|
|
|
|
* called for these, we have to deal with them as such in terms of the
|
|
|
|
|
* foreign-toplevel protocol to avoid panels and the like still showing
|
|
|
|
|
* them.
|
|
|
|
|
*/
|
2023-02-01 09:27:25 +01:00
|
|
|
if (view->toplevel.handle) {
|
|
|
|
|
wlr_foreign_toplevel_handle_v1_destroy(view->toplevel.handle);
|
|
|
|
|
view->toplevel.handle = NULL;
|
2022-05-17 18:10:29 +01:00
|
|
|
}
|
2019-12-26 21:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-04 01:32:12 +02:00
|
|
|
static void
|
|
|
|
|
handle_surface_destroy(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct view *view = wl_container_of(listener, view, surface_destroy);
|
2022-11-11 15:54:26 -05:00
|
|
|
assert(data && data == view->surface);
|
2022-09-04 01:32:12 +02:00
|
|
|
|
|
|
|
|
view->surface = NULL;
|
|
|
|
|
wl_list_remove(&view->surface_destroy.link);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
handle_destroy(struct wl_listener *listener, void *data)
|
2019-12-27 21:22:45 +00:00
|
|
|
{
|
2019-12-27 20:48:58 +00:00
|
|
|
struct view *view = wl_container_of(listener, view, destroy);
|
2022-11-25 13:41:12 -05:00
|
|
|
struct xwayland_view *xwayland_view = xwayland_view_from_view(view);
|
|
|
|
|
assert(data && data == xwayland_view->xwayland_surface);
|
|
|
|
|
assert(xwayland_view->xwayland_surface->data == view);
|
2022-04-23 03:44:41 +02:00
|
|
|
|
2022-09-04 01:32:12 +02:00
|
|
|
if (view->surface) {
|
|
|
|
|
/*
|
|
|
|
|
* We got the destroy signal from
|
|
|
|
|
* wlr_xwayland_surface before the
|
|
|
|
|
* destroy signal from wlr_surface.
|
|
|
|
|
*/
|
|
|
|
|
wl_list_remove(&view->surface_destroy.link);
|
|
|
|
|
}
|
|
|
|
|
view->surface = NULL;
|
2022-11-11 15:54:26 -05:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Break view <-> xsurface association. Note that the xsurface
|
|
|
|
|
* may not actually be destroyed at this point; it may become an
|
|
|
|
|
* "unmanaged" surface instead.
|
|
|
|
|
*/
|
2022-11-25 13:41:12 -05:00
|
|
|
xwayland_view->xwayland_surface->data = NULL;
|
|
|
|
|
xwayland_view->xwayland_surface = NULL;
|
2022-04-23 03:44:41 +02:00
|
|
|
|
2023-02-24 21:45:03 +00:00
|
|
|
/* Remove XWayland view specific listeners */
|
2023-02-24 21:27:11 +00:00
|
|
|
wl_list_remove(&xwayland_view->request_activate.link);
|
2022-11-22 20:13:06 +00:00
|
|
|
wl_list_remove(&xwayland_view->request_configure.link);
|
|
|
|
|
wl_list_remove(&xwayland_view->set_app_id.link);
|
|
|
|
|
wl_list_remove(&xwayland_view->set_decorations.link);
|
|
|
|
|
wl_list_remove(&xwayland_view->override_redirect.link);
|
|
|
|
|
|
2022-04-23 03:44:41 +02:00
|
|
|
view_destroy(view);
|
2019-12-26 21:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
2022-07-17 23:42:04 -04:00
|
|
|
static void
|
2023-02-06 20:01:18 +00:00
|
|
|
xwayland_view_configure(struct view *view, struct wlr_box geo)
|
2022-07-17 23:42:04 -04:00
|
|
|
{
|
2023-02-08 23:19:14 -05:00
|
|
|
view->pending = geo;
|
2022-11-25 13:41:12 -05:00
|
|
|
wlr_xwayland_surface_configure(xwayland_surface_from_view(view),
|
|
|
|
|
geo.x, geo.y, geo.width, geo.height);
|
2022-07-17 23:42:04 -04:00
|
|
|
|
|
|
|
|
/* If not resizing, process the move immediately */
|
2023-02-08 23:19:14 -05:00
|
|
|
if (view->current.width == geo.width
|
|
|
|
|
&& view->current.height == geo.height) {
|
|
|
|
|
view->current.x = geo.x;
|
|
|
|
|
view->current.y = geo.y;
|
2022-07-17 23:42:04 -04:00
|
|
|
view_moved(view);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
handle_request_configure(struct wl_listener *listener, void *data)
|
2019-12-27 21:22:45 +00:00
|
|
|
{
|
2022-11-22 20:13:06 +00:00
|
|
|
struct xwayland_view *xwayland_view =
|
|
|
|
|
wl_container_of(listener, xwayland_view, request_configure);
|
|
|
|
|
struct view *view = &xwayland_view->base;
|
2019-12-26 21:37:31 +00:00
|
|
|
struct wlr_xwayland_surface_configure_event *event = data;
|
2021-10-20 20:34:47 +01:00
|
|
|
|
2022-04-02 21:34:51 -04:00
|
|
|
int width = event->width;
|
|
|
|
|
int height = event->height;
|
|
|
|
|
view_adjust_size(view, &width, &height);
|
2021-10-17 18:34:49 +00:00
|
|
|
|
2023-02-06 20:01:18 +00:00
|
|
|
xwayland_view_configure(view,
|
|
|
|
|
(struct wlr_box){event->x, event->y, width, height});
|
2019-12-26 21:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-31 02:58:55 +00:00
|
|
|
static void
|
|
|
|
|
handle_request_activate(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
2023-02-24 21:27:11 +00:00
|
|
|
struct xwayland_view *xwayland_view =
|
|
|
|
|
wl_container_of(listener, xwayland_view, request_activate);
|
|
|
|
|
struct view *view = &xwayland_view->base;
|
2021-12-31 02:58:55 +00:00
|
|
|
desktop_focus_and_activate_view(&view->server->seat, view);
|
2023-04-01 14:06:52 -04:00
|
|
|
view_move_to_front(view);
|
2021-12-31 02:58:55 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-31 02:45:19 +00:00
|
|
|
static void
|
|
|
|
|
handle_request_minimize(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct wlr_xwayland_minimize_event *event = data;
|
|
|
|
|
struct view *view = wl_container_of(listener, view, request_minimize);
|
|
|
|
|
view_minimize(view, event->minimize);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-05 12:18:10 +01:00
|
|
|
static void
|
|
|
|
|
handle_request_maximize(struct wl_listener *listener, void *data)
|
2021-02-27 17:10:53 -05:00
|
|
|
{
|
|
|
|
|
struct view *view = wl_container_of(listener, view, request_maximize);
|
2023-02-03 14:45:04 -05:00
|
|
|
if (!view->mapped) {
|
|
|
|
|
ensure_initial_geometry_and_output(view);
|
2023-02-07 21:12:56 -05:00
|
|
|
/*
|
|
|
|
|
* Set decorations early to avoid changing geometry
|
|
|
|
|
* after maximize (reduces visual glitches).
|
|
|
|
|
*/
|
|
|
|
|
view_set_decorations(view,
|
|
|
|
|
want_deco(xwayland_surface_from_view(view)));
|
|
|
|
|
}
|
2021-08-02 16:49:41 +01:00
|
|
|
view_toggle_maximize(view);
|
2021-02-27 17:10:53 -05:00
|
|
|
}
|
|
|
|
|
|
2021-08-23 22:05:30 +01:00
|
|
|
static void
|
|
|
|
|
handle_request_fullscreen(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct view *view = wl_container_of(listener, view, request_fullscreen);
|
2022-11-25 13:41:12 -05:00
|
|
|
bool fullscreen = xwayland_surface_from_view(view)->fullscreen;
|
2023-02-03 14:45:04 -05:00
|
|
|
if (!view->mapped) {
|
|
|
|
|
ensure_initial_geometry_and_output(view);
|
2023-02-07 21:12:56 -05:00
|
|
|
}
|
2023-02-20 13:36:15 -05:00
|
|
|
view_set_fullscreen(view, fullscreen);
|
2021-08-23 22:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-05 12:18:10 +01:00
|
|
|
static void
|
|
|
|
|
handle_set_title(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct view *view = wl_container_of(listener, view, set_title);
|
|
|
|
|
view_update_title(view);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-16 21:50:56 +01:00
|
|
|
static void
|
|
|
|
|
handle_set_class(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
2022-11-22 20:13:06 +00:00
|
|
|
struct xwayland_view *xwayland_view =
|
|
|
|
|
wl_container_of(listener, xwayland_view, set_app_id);
|
|
|
|
|
struct view *view = &xwayland_view->base;
|
2021-10-16 21:50:56 +01:00
|
|
|
view_update_app_id(view);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
2023-02-06 20:01:18 +00:00
|
|
|
xwayland_view_close(struct view *view)
|
2020-09-02 21:00:28 +01:00
|
|
|
{
|
2022-11-25 13:41:12 -05:00
|
|
|
wlr_xwayland_surface_close(xwayland_surface_from_view(view));
|
2020-09-02 20:20:52 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-05 12:18:10 +01:00
|
|
|
static const char *
|
2023-02-06 20:01:18 +00:00
|
|
|
xwayland_view_get_string_prop(struct view *view, const char *prop)
|
2021-08-05 12:18:10 +01:00
|
|
|
{
|
2022-11-25 13:41:12 -05:00
|
|
|
struct wlr_xwayland_surface *xwayland_surface =
|
|
|
|
|
xwayland_surface_from_view(view);
|
2021-08-05 12:18:10 +01:00
|
|
|
if (!strcmp(prop, "title")) {
|
2022-11-25 13:41:12 -05:00
|
|
|
return xwayland_surface->title;
|
2021-08-05 12:18:10 +01:00
|
|
|
}
|
2021-08-16 07:16:56 +01:00
|
|
|
if (!strcmp(prop, "class")) {
|
2022-11-25 13:41:12 -05:00
|
|
|
return xwayland_surface->class;
|
2021-08-16 07:16:56 +01:00
|
|
|
}
|
2021-10-16 21:26:57 +01:00
|
|
|
/* We give 'class' for wlr_foreign_toplevel_handle_v1_set_app_id() */
|
|
|
|
|
if (!strcmp(prop, "app_id")) {
|
2022-11-25 13:41:12 -05:00
|
|
|
return xwayland_surface->class;
|
2021-10-16 21:26:57 +01:00
|
|
|
}
|
2021-08-16 07:16:56 +01:00
|
|
|
return "";
|
2021-08-05 12:18:10 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-20 16:06:32 +00:00
|
|
|
static void
|
2021-11-13 21:45:12 +00:00
|
|
|
handle_set_decorations(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
2022-11-22 20:13:06 +00:00
|
|
|
struct xwayland_view *xwayland_view =
|
|
|
|
|
wl_container_of(listener, xwayland_view, set_decorations);
|
|
|
|
|
struct view *view = &xwayland_view->base;
|
2022-11-25 13:41:12 -05:00
|
|
|
assert(data && data == xwayland_view->xwayland_surface);
|
|
|
|
|
|
|
|
|
|
view_set_decorations(view, want_deco(xwayland_view->xwayland_surface));
|
2021-10-20 16:06:32 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-03 19:44:31 +01:00
|
|
|
static void
|
|
|
|
|
handle_override_redirect(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
2022-11-22 20:13:06 +00:00
|
|
|
struct xwayland_view *xwayland_view =
|
|
|
|
|
wl_container_of(listener, xwayland_view, override_redirect);
|
|
|
|
|
struct view *view = &xwayland_view->base;
|
2022-05-03 19:44:31 +01:00
|
|
|
struct wlr_xwayland_surface *xsurface = data;
|
2022-11-25 13:41:12 -05:00
|
|
|
assert(xsurface && xsurface == xwayland_view->xwayland_surface);
|
|
|
|
|
|
2022-05-03 19:44:31 +01:00
|
|
|
struct server *server = view->server;
|
|
|
|
|
bool mapped = xsurface->mapped;
|
|
|
|
|
if (mapped) {
|
2022-11-11 15:54:26 -05:00
|
|
|
handle_unmap(&view->unmap, xsurface);
|
2022-05-03 19:44:31 +01:00
|
|
|
}
|
2022-11-11 15:54:26 -05:00
|
|
|
handle_destroy(&view->destroy, xsurface);
|
|
|
|
|
/* view is invalid after this point */
|
2023-01-07 17:50:33 -05:00
|
|
|
xwayland_unmanaged_create(server, xsurface, mapped);
|
2022-05-03 19:44:31 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-04 21:45:03 -04:00
|
|
|
static void
|
2022-11-25 13:41:12 -05:00
|
|
|
set_initial_position(struct view *view,
|
|
|
|
|
struct wlr_xwayland_surface *xwayland_surface)
|
2022-09-04 21:45:03 -04:00
|
|
|
{
|
|
|
|
|
/* Don't center views with position explicitly specified */
|
2022-11-25 13:41:12 -05:00
|
|
|
bool has_position = xwayland_surface->size_hints &&
|
2023-01-31 11:43:45 +01:00
|
|
|
(xwayland_surface->size_hints->flags & (
|
|
|
|
|
XCB_ICCCM_SIZE_HINT_US_POSITION |
|
|
|
|
|
XCB_ICCCM_SIZE_HINT_P_POSITION));
|
2022-09-04 21:45:03 -04:00
|
|
|
|
|
|
|
|
if (has_position) {
|
|
|
|
|
/* Just make sure the view is on-screen */
|
|
|
|
|
view_adjust_for_layout_change(view);
|
|
|
|
|
} else {
|
2023-02-20 16:23:53 -05:00
|
|
|
view_center(view, NULL);
|
2022-09-04 21:45:03 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
top_left_edge_boundary_check(struct view *view)
|
2020-09-17 21:11:54 +01:00
|
|
|
{
|
2021-03-20 14:41:39 +00:00
|
|
|
struct wlr_box deco = ssd_max_extents(view);
|
2020-09-28 20:41:41 +01:00
|
|
|
if (deco.x < 0) {
|
2023-02-08 23:19:14 -05:00
|
|
|
view->current.x -= deco.x;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
|
|
|
|
if (deco.y < 0) {
|
2023-02-08 23:19:14 -05:00
|
|
|
view->current.y -= deco.y;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2023-02-08 23:19:14 -05:00
|
|
|
view->impl->configure(view, view->current);
|
2020-09-17 21:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
2023-02-06 20:01:18 +00:00
|
|
|
xwayland_view_map(struct view *view)
|
2020-09-03 20:50:35 +01:00
|
|
|
{
|
2022-02-23 01:32:07 +01:00
|
|
|
if (view->mapped) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-03 20:50:35 +01:00
|
|
|
view->mapped = true;
|
2023-02-03 14:45:04 -05:00
|
|
|
ensure_initial_geometry_and_output(view);
|
2022-02-23 01:32:07 +01:00
|
|
|
wlr_scene_node_set_enabled(&view->scene_tree->node, true);
|
2022-11-25 13:41:12 -05:00
|
|
|
struct wlr_xwayland_surface *xwayland_surface =
|
|
|
|
|
xwayland_surface_from_view(view);
|
|
|
|
|
if (!view->fullscreen && xwayland_surface->fullscreen) {
|
2023-02-20 13:36:15 -05:00
|
|
|
view_set_fullscreen(view, true);
|
2022-01-29 10:44:15 -05:00
|
|
|
}
|
2022-02-11 23:12:45 +00:00
|
|
|
|
2022-11-25 13:41:12 -05:00
|
|
|
if (view->surface != xwayland_surface->surface) {
|
2022-09-04 01:32:12 +02:00
|
|
|
if (view->surface) {
|
|
|
|
|
wl_list_remove(&view->surface_destroy.link);
|
|
|
|
|
}
|
2022-11-25 13:41:12 -05:00
|
|
|
view->surface = xwayland_surface->surface;
|
2022-09-04 01:32:12 +02:00
|
|
|
|
|
|
|
|
/* Required to set the surface to NULL when destroyed by the client */
|
|
|
|
|
view->surface_destroy.notify = handle_surface_destroy;
|
|
|
|
|
wl_signal_add(&view->surface->events.destroy, &view->surface_destroy);
|
|
|
|
|
|
|
|
|
|
/* Will be free'd automatically once the surface is being destroyed */
|
2022-06-05 15:17:35 +02:00
|
|
|
struct wlr_scene_tree *tree = wlr_scene_subsurface_tree_create(
|
|
|
|
|
view->scene_tree, view->surface);
|
|
|
|
|
if (!tree) {
|
2022-02-23 01:32:07 +01:00
|
|
|
/* TODO: might need further clean up */
|
|
|
|
|
wl_resource_post_no_memory(view->surface->resource);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-06-05 15:17:35 +02:00
|
|
|
view->scene_node = &tree->node;
|
2022-02-11 23:12:45 +00:00
|
|
|
}
|
|
|
|
|
|
2023-02-01 09:27:25 +01:00
|
|
|
if (!view->toplevel.handle) {
|
2022-05-17 18:10:29 +01:00
|
|
|
foreign_toplevel_handle_create(view);
|
|
|
|
|
}
|
2020-09-15 20:41:01 +01:00
|
|
|
|
2022-05-17 18:10:29 +01:00
|
|
|
if (!view->been_mapped) {
|
2022-11-25 13:41:12 -05:00
|
|
|
view_set_decorations(view, want_deco(xwayland_surface));
|
2020-09-15 20:41:01 +01:00
|
|
|
|
2023-02-09 16:06:07 -05:00
|
|
|
if (view_is_floating(view)) {
|
2022-11-25 13:41:12 -05:00
|
|
|
set_initial_position(view, xwayland_surface);
|
2022-01-24 17:57:35 -05:00
|
|
|
}
|
2021-11-13 12:32:01 -05:00
|
|
|
|
2023-02-07 21:12:56 -05:00
|
|
|
/*
|
|
|
|
|
* When mapping the view for the first time, visual
|
|
|
|
|
* artifacts are reduced if we display it immediately at
|
|
|
|
|
* the final intended position/size rather than waiting
|
|
|
|
|
* for handle_commit().
|
|
|
|
|
*/
|
2023-02-08 23:19:14 -05:00
|
|
|
view->current = view->pending;
|
2022-09-04 22:47:54 -04:00
|
|
|
view_moved(view);
|
2022-03-11 06:23:08 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-09 16:06:07 -05:00
|
|
|
if (view->ssd_enabled && view_is_floating(view)) {
|
2021-10-17 01:39:19 +00:00
|
|
|
top_left_edge_boundary_check(view);
|
|
|
|
|
}
|
2020-09-03 20:50:35 +01:00
|
|
|
|
2020-09-04 20:25:20 +01:00
|
|
|
/* Add commit here, as xwayland map/unmap can change the wlr_surface */
|
2022-11-25 13:41:12 -05:00
|
|
|
wl_signal_add(&xwayland_surface->surface->events.commit, &view->commit);
|
2020-09-03 20:50:35 +01:00
|
|
|
view->commit.notify = handle_commit;
|
|
|
|
|
|
2021-10-16 21:26:57 +01:00
|
|
|
view_impl_map(view);
|
2023-04-28 21:41:41 +01:00
|
|
|
view->been_mapped = true;
|
2020-09-03 20:50:35 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
2023-02-06 20:01:18 +00:00
|
|
|
xwayland_view_unmap(struct view *view)
|
2020-09-03 20:50:35 +01:00
|
|
|
{
|
2022-05-17 18:10:29 +01:00
|
|
|
if (!view->mapped) {
|
|
|
|
|
return;
|
2021-12-11 23:24:44 +00:00
|
|
|
}
|
2022-05-17 18:10:29 +01:00
|
|
|
view->mapped = false;
|
|
|
|
|
wl_list_remove(&view->commit.link);
|
|
|
|
|
wlr_scene_node_set_enabled(&view->scene_tree->node, false);
|
|
|
|
|
desktop_focus_topmost_mapped_view(view->server);
|
2020-09-03 20:50:35 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-27 17:10:53 -05:00
|
|
|
static void
|
2023-02-06 20:01:18 +00:00
|
|
|
xwayland_view_maximize(struct view *view, bool maximized)
|
2021-02-27 17:10:53 -05:00
|
|
|
{
|
2022-11-25 13:41:12 -05:00
|
|
|
wlr_xwayland_surface_set_maximized(xwayland_surface_from_view(view),
|
|
|
|
|
maximized);
|
2021-02-27 17:10:53 -05:00
|
|
|
}
|
|
|
|
|
|
2023-03-25 16:38:43 +00:00
|
|
|
enum z_direction {
|
|
|
|
|
LAB_TO_FRONT,
|
|
|
|
|
LAB_TO_BACK,
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-05 19:29:24 +00:00
|
|
|
static void
|
2023-03-25 16:38:43 +00:00
|
|
|
move_sub_views(struct view *parent, enum z_direction z_direction)
|
2023-02-05 19:29:24 +00:00
|
|
|
{
|
|
|
|
|
assert(parent);
|
|
|
|
|
|
|
|
|
|
if (parent->type != LAB_XWAYLAND_VIEW) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wlr_xwayland_surface *parent_xwayland_surface =
|
|
|
|
|
xwayland_surface_from_view(parent);
|
|
|
|
|
struct view *view, *next;
|
|
|
|
|
wl_list_for_each_reverse_safe(view, next, &parent->server->views, link)
|
|
|
|
|
{
|
|
|
|
|
/* need to stop here, otherwise loops keeps going forever */
|
|
|
|
|
if (view == parent) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (view->type != LAB_XWAYLAND_VIEW) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!view->mapped && !view->minimized) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (top_parent_of(view) != parent_xwayland_surface) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2023-03-25 16:38:43 +00:00
|
|
|
if (z_direction == LAB_TO_FRONT) {
|
|
|
|
|
view_impl_move_to_front(view);
|
|
|
|
|
} else if (z_direction == LAB_TO_BACK) {
|
|
|
|
|
view_impl_move_to_back(view);
|
|
|
|
|
}
|
2023-02-05 19:29:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2023-02-06 20:01:18 +00:00
|
|
|
xwayland_view_move_to_front(struct view *view)
|
2023-02-05 19:29:24 +00:00
|
|
|
{
|
|
|
|
|
view_impl_move_to_front(view);
|
2023-03-25 16:38:43 +00:00
|
|
|
move_sub_views(view, LAB_TO_FRONT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
xwayland_view_move_to_back(struct view *view)
|
|
|
|
|
{
|
|
|
|
|
view_impl_move_to_back(view);
|
|
|
|
|
move_sub_views(view, LAB_TO_BACK);
|
2023-02-05 19:29:24 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-16 19:24:26 +01:00
|
|
|
static void
|
2023-02-06 20:01:18 +00:00
|
|
|
xwayland_view_set_activated(struct view *view, bool activated)
|
2021-10-16 19:24:26 +01:00
|
|
|
{
|
2022-11-25 13:41:12 -05:00
|
|
|
struct wlr_xwayland_surface *xwayland_surface =
|
|
|
|
|
xwayland_surface_from_view(view);
|
2021-10-16 19:24:26 +01:00
|
|
|
|
2022-11-25 13:41:12 -05:00
|
|
|
if (activated && xwayland_surface->minimized) {
|
|
|
|
|
wlr_xwayland_surface_set_minimized(xwayland_surface, false);
|
2021-10-16 19:24:26 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-25 13:41:12 -05:00
|
|
|
wlr_xwayland_surface_activate(xwayland_surface, activated);
|
2022-03-12 11:49:05 +01:00
|
|
|
if (activated) {
|
2022-11-25 13:41:12 -05:00
|
|
|
wlr_xwayland_surface_restack(xwayland_surface,
|
|
|
|
|
NULL, XCB_STACK_MODE_ABOVE);
|
2022-09-01 14:33:42 -04:00
|
|
|
/* Restack unmanaged surfaces on top */
|
|
|
|
|
struct xwayland_unmanaged *u;
|
|
|
|
|
struct wl_list *list = &view->server->unmanaged_surfaces;
|
2022-11-03 19:58:21 +00:00
|
|
|
wl_list_for_each(u, list, link) {
|
2022-11-25 13:41:12 -05:00
|
|
|
wlr_xwayland_surface_restack(u->xwayland_surface,
|
|
|
|
|
NULL, XCB_STACK_MODE_ABOVE);
|
2022-09-01 14:33:42 -04:00
|
|
|
}
|
2022-03-12 11:49:05 +01:00
|
|
|
}
|
2021-10-16 19:24:26 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-23 22:05:30 +01:00
|
|
|
static void
|
2023-02-06 20:01:18 +00:00
|
|
|
xwayland_view_set_fullscreen(struct view *view, bool fullscreen)
|
2021-08-23 22:05:30 +01:00
|
|
|
{
|
2022-11-25 13:41:12 -05:00
|
|
|
wlr_xwayland_surface_set_fullscreen(xwayland_surface_from_view(view),
|
|
|
|
|
fullscreen);
|
2021-08-23 22:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-06 20:01:18 +00:00
|
|
|
static const struct view_impl xwayland_view_impl = {
|
|
|
|
|
.configure = xwayland_view_configure,
|
|
|
|
|
.close = xwayland_view_close,
|
|
|
|
|
.get_string_prop = xwayland_view_get_string_prop,
|
|
|
|
|
.map = xwayland_view_map,
|
|
|
|
|
.set_activated = xwayland_view_set_activated,
|
|
|
|
|
.set_fullscreen = xwayland_view_set_fullscreen,
|
|
|
|
|
.unmap = xwayland_view_unmap,
|
|
|
|
|
.maximize = xwayland_view_maximize,
|
|
|
|
|
.move_to_front = xwayland_view_move_to_front,
|
2023-03-25 16:38:43 +00:00
|
|
|
.move_to_back = xwayland_view_move_to_back,
|
2020-09-02 20:20:52 +01:00
|
|
|
};
|
|
|
|
|
|
2023-04-19 18:10:07 -04:00
|
|
|
void
|
|
|
|
|
xwayland_view_create(struct server *server,
|
|
|
|
|
struct wlr_xwayland_surface *xsurface, bool mapped)
|
2019-12-27 21:22:45 +00:00
|
|
|
{
|
2022-11-22 20:13:06 +00:00
|
|
|
struct xwayland_view *xwayland_view = znew(*xwayland_view);
|
|
|
|
|
struct view *view = &xwayland_view->base;
|
|
|
|
|
|
2019-12-26 21:37:31 +00:00
|
|
|
view->server = server;
|
|
|
|
|
view->type = LAB_XWAYLAND_VIEW;
|
2023-02-06 20:01:18 +00:00
|
|
|
view->impl = &xwayland_view_impl;
|
2022-11-11 15:54:26 -05:00
|
|
|
|
|
|
|
|
/*
|
2023-04-17 17:02:11 +01:00
|
|
|
* Set two-way view <-> xsurface association. Usually the association
|
|
|
|
|
* remains until the xsurface is destroyed (which also destroys the
|
|
|
|
|
* view). The only exception is caused by setting override-redirect on
|
|
|
|
|
* the xsurface, which removes it from the view (destroying the view)
|
|
|
|
|
* and makes it an "unmanaged" surface.
|
2022-11-11 15:54:26 -05:00
|
|
|
*/
|
2022-11-25 13:41:12 -05:00
|
|
|
xwayland_view->xwayland_surface = xsurface;
|
2022-11-11 15:54:26 -05:00
|
|
|
xsurface->data = view;
|
2019-12-26 21:37:31 +00:00
|
|
|
|
2022-06-15 02:02:50 +02:00
|
|
|
view->workspace = server->workspace_current;
|
|
|
|
|
view->scene_tree = wlr_scene_tree_create(view->workspace->tree);
|
2023-04-17 17:02:11 +01:00
|
|
|
node_descriptor_create(&view->scene_tree->node, LAB_NODE_DESC_VIEW, view);
|
2021-10-20 16:02:39 +00:00
|
|
|
|
2020-09-03 21:40:27 +01:00
|
|
|
view->map.notify = handle_map;
|
2020-09-04 20:25:20 +01:00
|
|
|
wl_signal_add(&xsurface->events.map, &view->map);
|
2020-09-03 21:40:27 +01:00
|
|
|
view->unmap.notify = handle_unmap;
|
2020-09-04 20:25:20 +01:00
|
|
|
wl_signal_add(&xsurface->events.unmap, &view->unmap);
|
2020-09-03 21:40:27 +01:00
|
|
|
view->destroy.notify = handle_destroy;
|
2020-09-04 20:25:20 +01:00
|
|
|
wl_signal_add(&xsurface->events.destroy, &view->destroy);
|
2021-12-31 02:45:19 +00:00
|
|
|
view->request_minimize.notify = handle_request_minimize;
|
|
|
|
|
wl_signal_add(&xsurface->events.request_minimize, &view->request_minimize);
|
2021-02-27 17:10:53 -05:00
|
|
|
view->request_maximize.notify = handle_request_maximize;
|
|
|
|
|
wl_signal_add(&xsurface->events.request_maximize, &view->request_maximize);
|
2021-08-23 22:05:30 +01:00
|
|
|
view->request_fullscreen.notify = handle_request_fullscreen;
|
2021-12-31 02:42:17 +00:00
|
|
|
wl_signal_add(&xsurface->events.request_fullscreen, &view->request_fullscreen);
|
2021-10-17 17:11:41 +00:00
|
|
|
view->request_move.notify = handle_request_move;
|
2021-12-31 02:42:17 +00:00
|
|
|
wl_signal_add(&xsurface->events.request_move, &view->request_move);
|
2021-10-17 17:12:51 +00:00
|
|
|
view->request_resize.notify = handle_request_resize;
|
2021-12-31 02:42:17 +00:00
|
|
|
wl_signal_add(&xsurface->events.request_resize, &view->request_resize);
|
2021-10-16 21:50:56 +01:00
|
|
|
|
2021-08-05 12:18:10 +01:00
|
|
|
view->set_title.notify = handle_set_title;
|
|
|
|
|
wl_signal_add(&xsurface->events.set_title, &view->set_title);
|
2020-09-07 19:34:11 +01:00
|
|
|
|
2022-11-22 20:13:06 +00:00
|
|
|
/* Events specific to XWayland views */
|
2023-02-24 21:27:11 +00:00
|
|
|
xwayland_view->request_activate.notify = handle_request_activate;
|
2023-04-17 17:02:11 +01:00
|
|
|
wl_signal_add(&xsurface->events.request_activate, &xwayland_view->request_activate);
|
2023-02-24 21:27:11 +00:00
|
|
|
|
2022-11-22 20:13:06 +00:00
|
|
|
xwayland_view->request_configure.notify = handle_request_configure;
|
2023-04-17 17:02:11 +01:00
|
|
|
wl_signal_add(&xsurface->events.request_configure, &xwayland_view->request_configure);
|
2022-11-22 20:13:06 +00:00
|
|
|
|
|
|
|
|
xwayland_view->set_app_id.notify = handle_set_class;
|
|
|
|
|
wl_signal_add(&xsurface->events.set_class, &xwayland_view->set_app_id);
|
2021-10-16 21:50:56 +01:00
|
|
|
|
2022-11-22 20:13:06 +00:00
|
|
|
xwayland_view->set_decorations.notify = handle_set_decorations;
|
2023-04-17 17:02:11 +01:00
|
|
|
wl_signal_add(&xsurface->events.set_decorations, &xwayland_view->set_decorations);
|
2021-10-20 16:06:32 +00:00
|
|
|
|
2022-11-22 20:13:06 +00:00
|
|
|
xwayland_view->override_redirect.notify = handle_override_redirect;
|
2023-04-17 17:02:11 +01:00
|
|
|
wl_signal_add(&xsurface->events.set_override_redirect, &xwayland_view->override_redirect);
|
2022-05-03 19:44:31 +01:00
|
|
|
|
2020-09-07 19:34:11 +01:00
|
|
|
wl_list_insert(&view->server->views, &view->link);
|
2023-04-19 18:10:07 -04:00
|
|
|
|
|
|
|
|
if (mapped) {
|
|
|
|
|
xwayland_view_map(view);
|
|
|
|
|
}
|
2023-04-17 17:02:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
handle_new_surface(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct server *server =
|
|
|
|
|
wl_container_of(listener, server, xwayland_new_surface);
|
|
|
|
|
struct wlr_xwayland_surface *xsurface = data;
|
|
|
|
|
wlr_xwayland_surface_ping(xsurface);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We do not create 'views' for xwayland override_redirect surfaces,
|
|
|
|
|
* but add them to server.unmanaged_surfaces so that we can render them
|
|
|
|
|
*/
|
|
|
|
|
if (xsurface->override_redirect) {
|
|
|
|
|
xwayland_unmanaged_create(server, xsurface, /* mapped */ false);
|
2023-04-19 18:10:07 -04:00
|
|
|
} else {
|
|
|
|
|
xwayland_view_create(server, xsurface, /* mapped */ false);
|
2023-04-17 17:02:11 +01:00
|
|
|
}
|
2019-12-26 21:37:31 +00:00
|
|
|
}
|
2023-01-07 17:50:33 -05:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
handle_ready(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct server *server =
|
|
|
|
|
wl_container_of(listener, server, xwayland_ready);
|
|
|
|
|
wlr_xwayland_set_seat(server->xwayland, server->seat.seat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
xwayland_server_init(struct server *server, struct wlr_compositor *compositor)
|
|
|
|
|
{
|
|
|
|
|
server->xwayland =
|
|
|
|
|
wlr_xwayland_create(server->wl_display, compositor, true);
|
|
|
|
|
if (!server->xwayland) {
|
|
|
|
|
wlr_log(WLR_ERROR, "cannot create xwayland server");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
server->xwayland_new_surface.notify = handle_new_surface;
|
|
|
|
|
wl_signal_add(&server->xwayland->events.new_surface,
|
2023-01-31 11:43:45 +01:00
|
|
|
&server->xwayland_new_surface);
|
2023-01-07 17:50:33 -05:00
|
|
|
|
|
|
|
|
server->xwayland_ready.notify = handle_ready;
|
|
|
|
|
wl_signal_add(&server->xwayland->events.ready,
|
|
|
|
|
&server->xwayland_ready);
|
|
|
|
|
|
|
|
|
|
if (setenv("DISPLAY", server->xwayland->display_name, true) < 0) {
|
|
|
|
|
wlr_log_errno(WLR_ERROR, "unable to set DISPLAY for xwayland");
|
|
|
|
|
} else {
|
|
|
|
|
wlr_log(WLR_DEBUG, "xwayland is running on display %s",
|
|
|
|
|
server->xwayland->display_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wlr_xcursor *xcursor;
|
2023-01-31 11:43:45 +01:00
|
|
|
xcursor = wlr_xcursor_manager_get_xcursor(
|
|
|
|
|
server->seat.xcursor_manager, XCURSOR_DEFAULT, 1);
|
2023-01-07 17:50:33 -05:00
|
|
|
if (xcursor) {
|
|
|
|
|
struct wlr_xcursor_image *image = xcursor->images[0];
|
|
|
|
|
wlr_xwayland_set_cursor(server->xwayland, image->buffer,
|
2023-01-31 11:43:45 +01:00
|
|
|
image->width * 4, image->width,
|
|
|
|
|
image->height, image->hotspot_x,
|
|
|
|
|
image->hotspot_y);
|
2023-01-07 17:50:33 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
xwayland_server_finish(struct server *server)
|
|
|
|
|
{
|
|
|
|
|
wlr_xwayland_destroy(server->xwayland);
|
|
|
|
|
server->xwayland = NULL;
|
|
|
|
|
}
|