summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Orzechowski <alex@ozal.ski>2024-01-18 10:02:41 -0500
committerKirill Primak <vyivel@eclair.cafe>2024-01-18 18:36:54 +0300
commit6e5fc4c2aafd211323c6037aa868c075852bfe15 (patch)
treebff87217414fa981d48244c5bc1b253817646783
parentb38ed8b4792928dca3e1580e8160792ea41e25c4 (diff)
scene_graph: Port xwayland
-rw-r--r--include/sway/output.h6
-rw-r--r--include/sway/scene_descriptor.h1
-rw-r--r--include/sway/tree/root.h7
-rw-r--r--include/sway/tree/view.h8
-rw-r--r--sway/desktop/output.c17
-rw-r--r--sway/desktop/xwayland.c79
-rw-r--r--sway/input/cursor.c6
-rw-r--r--sway/tree/root.c6
8 files changed, 60 insertions, 70 deletions
diff --git a/include/sway/output.h b/include/sway/output.h
index ea5d8f47e..e20233061 100644
--- a/include/sway/output.h
+++ b/include/sway/output.h
@@ -141,12 +141,6 @@ void output_view_for_each_popup_surface(struct sway_output *output,
struct sway_view *view, sway_surface_iterator_func_t iterator,
void *user_data);
-#if HAVE_XWAYLAND
-void output_unmanaged_for_each_surface(struct sway_output *output,
- struct wl_list *unmanaged, sway_surface_iterator_func_t iterator,
- void *user_data);
-#endif
-
void output_for_each_workspace(struct sway_output *output,
void (*f)(struct sway_workspace *ws, void *data), void *data);
diff --git a/include/sway/scene_descriptor.h b/include/sway/scene_descriptor.h
index 43991f771..2649d7c29 100644
--- a/include/sway/scene_descriptor.h
+++ b/include/sway/scene_descriptor.h
@@ -16,6 +16,7 @@ enum sway_scene_descriptor_type {
SWAY_SCENE_DESC_CONTAINER,
SWAY_SCENE_DESC_VIEW,
SWAY_SCENE_DESC_LAYER_SHELL,
+ SWAY_SCENE_DESC_XWAYLAND_UNMANAGED,
SWAY_SCENE_DESC_POPUP,
SWAY_SCENE_DESC_DRAG_ICON,
};
diff --git a/include/sway/tree/root.h b/include/sway/tree/root.h
index 2f717baea..15df0f551 100644
--- a/include/sway/tree/root.h
+++ b/include/sway/tree/root.h
@@ -47,16 +47,15 @@ struct sway_root {
struct wlr_scene_tree *shell_top;
struct wlr_scene_tree *fullscreen;
struct wlr_scene_tree *fullscreen_global;
+#if HAVE_XWAYLAND
+ struct wlr_scene_tree *unmanaged;
+#endif
struct wlr_scene_tree *shell_overlay;
struct wlr_scene_tree *popup;
struct wlr_scene_tree *seat;
struct wlr_scene_tree *session_lock;
} layers;
-#if HAVE_XWAYLAND
- struct wl_list xwayland_unmanaged; // sway_xwayland_unmanaged::link
-#endif
-
// Includes disabled outputs
struct wl_list all_outputs; // sway_output::link
diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h
index 467d912f9..8493958e4 100644
--- a/include/sway/tree/view.h
+++ b/include/sway/tree/view.h
@@ -147,6 +147,8 @@ struct sway_xdg_shell_view {
struct sway_xwayland_view {
struct sway_view view;
+ struct wlr_scene_tree *surface_tree;
+
struct wl_listener commit;
struct wl_listener request_move;
struct wl_listener request_resize;
@@ -168,18 +170,18 @@ struct sway_xwayland_view {
struct wl_listener unmap;
struct wl_listener destroy;
struct wl_listener override_redirect;
+
+ struct wl_listener surface_tree_destroy;
};
struct sway_xwayland_unmanaged {
struct wlr_xwayland_surface *wlr_xwayland_surface;
- struct wl_list link;
- int lx, ly;
+ struct wlr_scene_surface *surface_scene;
struct wl_listener request_activate;
struct wl_listener request_configure;
struct wl_listener request_fullscreen;
- struct wl_listener commit;
struct wl_listener set_geometry;
struct wl_listener associate;
struct wl_listener dissociate;
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index a51844847..36c8f52ce 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -182,23 +182,6 @@ void output_view_for_each_popup_surface(struct sway_output *output,
view_for_each_popup_surface(view, output_for_each_surface_iterator, &data);
}
-#if HAVE_XWAYLAND
-void output_unmanaged_for_each_surface(struct sway_output *output,
- struct wl_list *unmanaged, sway_surface_iterator_func_t iterator,
- void *user_data) {
- struct sway_xwayland_unmanaged *unmanaged_surface;
- wl_list_for_each(unmanaged_surface, unmanaged, link) {
- struct wlr_xwayland_surface *xsurface =
- unmanaged_surface->wlr_xwayland_surface;
- double ox = unmanaged_surface->lx - output->lx;
- double oy = unmanaged_surface->ly - output->ly;
-
- output_surface_for_each_surface(output, xsurface->surface, ox, oy,
- iterator, user_data);
- }
-}
-#endif
-
static int scale_length(int length, int offset, float scale) {
return roundf((offset + length) * scale) - roundf(offset * scale);
}
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c
index 8f79b5e79..183bdba2c 100644
--- a/sway/desktop/xwayland.c
+++ b/sway/desktop/xwayland.c
@@ -6,15 +6,16 @@
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_xdg_activation_v1.h>
+#include <wlr/types/wlr_scene.h>
#include <wlr/xwayland.h>
#include <xcb/xcb_icccm.h>
#include "log.h"
-#include "sway/desktop.h"
#include "sway/desktop/transaction.h"
#include "sway/input/cursor.h"
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
#include "sway/output.h"
+#include "sway/scene_descriptor.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
#include "sway/server.h"
@@ -45,29 +46,12 @@ static void unmanaged_handle_request_configure(struct wl_listener *listener,
ev->width, ev->height);
}
-static void unmanaged_handle_commit(struct wl_listener *listener, void *data) {
- struct sway_xwayland_unmanaged *surface =
- wl_container_of(listener, surface, commit);
- struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface;
-
- desktop_damage_surface(xsurface->surface, surface->lx, surface->ly,
- false);
-}
-
static void unmanaged_handle_set_geometry(struct wl_listener *listener, void *data) {
struct sway_xwayland_unmanaged *surface =
wl_container_of(listener, surface, set_geometry);
struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface;
- if (xsurface->x != surface->lx || xsurface->y != surface->ly) {
- // Surface has moved
- desktop_damage_surface(xsurface->surface, surface->lx, surface->ly,
- true);
- surface->lx = xsurface->x;
- surface->ly = xsurface->y;
- desktop_damage_surface(xsurface->surface, surface->lx, surface->ly,
- true);
- }
+ wlr_scene_node_set_position(&surface->surface_scene->buffer->node, xsurface->x, xsurface->y);
}
static void unmanaged_handle_map(struct wl_listener *listener, void *data) {
@@ -75,17 +59,18 @@ static void unmanaged_handle_map(struct wl_listener *listener, void *data) {
wl_container_of(listener, surface, map);
struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface;
- wl_list_insert(root->xwayland_unmanaged.prev, &surface->link);
+ surface->surface_scene = wlr_scene_surface_create(root->layers.unmanaged,
+ xsurface->surface);
- wl_signal_add(&xsurface->events.set_geometry, &surface->set_geometry);
- surface->set_geometry.notify = unmanaged_handle_set_geometry;
+ if (surface->surface_scene) {
+ scene_descriptor_assign(&surface->surface_scene->buffer->node,
+ SWAY_SCENE_DESC_XWAYLAND_UNMANAGED, surface);
+ wlr_scene_node_set_position(&surface->surface_scene->buffer->node,
+ xsurface->x, xsurface->y);
- wl_signal_add(&xsurface->surface->events.commit, &surface->commit);
- surface->commit.notify = unmanaged_handle_commit;
-
- surface->lx = xsurface->x;
- surface->ly = xsurface->y;
- desktop_damage_surface(xsurface->surface, surface->lx, surface->ly, true);
+ wl_signal_add(&xsurface->events.set_geometry, &surface->set_geometry);
+ surface->set_geometry.notify = unmanaged_handle_set_geometry;
+ }
if (wlr_xwayland_or_surface_wants_focus(xsurface)) {
struct sway_seat *seat = input_manager_current_seat();
@@ -99,10 +84,13 @@ static void unmanaged_handle_unmap(struct wl_listener *listener, void *data) {
struct sway_xwayland_unmanaged *surface =
wl_container_of(listener, surface, unmap);
struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface;
- desktop_damage_surface(xsurface->surface, xsurface->x, xsurface->y, true);
- wl_list_remove(&surface->link);
- wl_list_remove(&surface->set_geometry.link);
- wl_list_remove(&surface->commit.link);
+
+ if (surface->surface_scene) {
+ wl_list_remove(&surface->set_geometry.link);
+
+ wlr_scene_node_destroy(&surface->surface_scene->buffer->node);
+ surface->surface_scene = NULL;
+ }
struct sway_seat *seat = input_manager_current_seat();
if (seat->wlr_seat->keyboard_state.focused_surface == xsurface->surface) {
@@ -455,7 +443,6 @@ static void handle_commit(struct wl_listener *listener, void *data) {
// The client changed its surface size in this commit. For floating
// containers, we resize the container to match. For tiling containers,
// we only recenter the surface.
- desktop_damage_view(view);
memcpy(&view->geometry, &new_geo, sizeof(struct wlr_box));
if (container_is_floating(view->container)) {
view_update_size(view);
@@ -463,15 +450,12 @@ static void handle_commit(struct wl_listener *listener, void *data) {
} else {
view_center_surface(view);
}
- desktop_damage_view(view);
}
if (view->container->node.instruction) {
transaction_notify_view_ready_by_geometry(view,
xsurface->x, xsurface->y, state->width, state->height);
}
-
- view_damage_from(view);
}
static void handle_destroy(struct wl_listener *listener, void *data) {
@@ -515,9 +499,21 @@ static void handle_unmap(struct wl_listener *listener, void *data) {
return;
}
+ wl_list_remove(&xwayland_view->commit.link);
+ wl_list_remove(&xwayland_view->surface_tree_destroy.link);
+
+ if (xwayland_view->surface_tree) {
+ wlr_scene_node_destroy(&xwayland_view->surface_tree->node);
+ xwayland_view->surface_tree = NULL;
+ }
+
view_unmap(view);
+}
- wl_list_remove(&xwayland_view->commit.link);
+static void handle_surface_tree_destroy(struct wl_listener *listener, void *data) {
+ struct sway_xwayland_view *xwayland_view = wl_container_of(listener, xwayland_view,
+ surface_tree_destroy);
+ xwayland_view->surface_tree = NULL;
}
static void handle_map(struct wl_listener *listener, void *data) {
@@ -537,6 +533,15 @@ static void handle_map(struct wl_listener *listener, void *data) {
// Put it back into the tree
view_map(view, xsurface->surface, xsurface->fullscreen, NULL, false);
+ xwayland_view->surface_tree = wlr_scene_subsurface_tree_create(
+ xwayland_view->view.content_tree, xsurface->surface);
+
+ if (xwayland_view->surface_tree) {
+ xwayland_view->surface_tree_destroy.notify = handle_surface_tree_destroy;
+ wl_signal_add(&xwayland_view->surface_tree->node.events.destroy,
+ &xwayland_view->surface_tree_destroy);
+ }
+
transaction_commit_dirty();
}
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index fd8f50d45..404c1eed5 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -107,6 +107,12 @@ struct sway_node *node_at_coords(
return NULL;
}
+#if HAVE_XWAYLAND
+ if (scene_descriptor_try_get(current, SWAY_SCENE_DESC_XWAYLAND_UNMANAGED)) {
+ return NULL;
+ }
+#endif
+
if (!current->parent) {
break;
}
diff --git a/sway/tree/root.c b/sway/tree/root.c
index 7c8f9ea69..e9cea5e22 100644
--- a/sway/tree/root.c
+++ b/sway/tree/root.c
@@ -54,6 +54,9 @@ struct sway_root *root_create(struct wl_display *wl_display) {
root->layers.shell_top = alloc_scene_tree(root->layer_tree, &failed);
root->layers.fullscreen = alloc_scene_tree(root->layer_tree, &failed);
root->layers.fullscreen_global = alloc_scene_tree(root->layer_tree, &failed);
+#if HAVE_XWAYLAND
+ root->layers.unmanaged = alloc_scene_tree(root->layer_tree, &failed);
+#endif
root->layers.shell_overlay = alloc_scene_tree(root->layer_tree, &failed);
root->layers.popup = alloc_scene_tree(root->layer_tree, &failed);
root->layers.seat = alloc_scene_tree(root->layer_tree, &failed);
@@ -74,9 +77,6 @@ struct sway_root *root_create(struct wl_display *wl_display) {
root->output_layout = wlr_output_layout_create(wl_display);
wl_list_init(&root->all_outputs);
-#if HAVE_XWAYLAND
- wl_list_init(&root->xwayland_unmanaged);
-#endif
wl_signal_init(&root->events.new_node);
root->outputs = create_list();
root->non_desktop_outputs = create_list();