aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Alexander Orzechowski <alex@ozal.ski>2024-01-18 10:02:41 -0500
committerLibravatar Kirill Primak <vyivel@eclair.cafe>2024-01-18 18:36:54 +0300
commit6e5fc4c2aafd211323c6037aa868c075852bfe15 (patch)
treebff87217414fa981d48244c5bc1b253817646783
parentscene_graph: Port xdg_shell (diff)
downloadsway-6e5fc4c2aafd211323c6037aa868c075852bfe15.tar.gz
sway-6e5fc4c2aafd211323c6037aa868c075852bfe15.tar.zst
sway-6e5fc4c2aafd211323c6037aa868c075852bfe15.zip
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 ea5d8f47..e2023306 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,
141 struct sway_view *view, sway_surface_iterator_func_t iterator, 141 struct sway_view *view, sway_surface_iterator_func_t iterator,
142 void *user_data); 142 void *user_data);
143 143
144#if HAVE_XWAYLAND
145void output_unmanaged_for_each_surface(struct sway_output *output,
146 struct wl_list *unmanaged, sway_surface_iterator_func_t iterator,
147 void *user_data);
148#endif
149
150void output_for_each_workspace(struct sway_output *output, 144void output_for_each_workspace(struct sway_output *output,
151 void (*f)(struct sway_workspace *ws, void *data), void *data); 145 void (*f)(struct sway_workspace *ws, void *data), void *data);
152 146
diff --git a/include/sway/scene_descriptor.h b/include/sway/scene_descriptor.h
index 43991f77..2649d7c2 100644
--- a/include/sway/scene_descriptor.h
+++ b/include/sway/scene_descriptor.h
@@ -16,6 +16,7 @@ enum sway_scene_descriptor_type {
16 SWAY_SCENE_DESC_CONTAINER, 16 SWAY_SCENE_DESC_CONTAINER,
17 SWAY_SCENE_DESC_VIEW, 17 SWAY_SCENE_DESC_VIEW,
18 SWAY_SCENE_DESC_LAYER_SHELL, 18 SWAY_SCENE_DESC_LAYER_SHELL,
19 SWAY_SCENE_DESC_XWAYLAND_UNMANAGED,
19 SWAY_SCENE_DESC_POPUP, 20 SWAY_SCENE_DESC_POPUP,
20 SWAY_SCENE_DESC_DRAG_ICON, 21 SWAY_SCENE_DESC_DRAG_ICON,
21}; 22};
diff --git a/include/sway/tree/root.h b/include/sway/tree/root.h
index 2f717bae..15df0f55 100644
--- a/include/sway/tree/root.h
+++ b/include/sway/tree/root.h
@@ -47,16 +47,15 @@ struct sway_root {
47 struct wlr_scene_tree *shell_top; 47 struct wlr_scene_tree *shell_top;
48 struct wlr_scene_tree *fullscreen; 48 struct wlr_scene_tree *fullscreen;
49 struct wlr_scene_tree *fullscreen_global; 49 struct wlr_scene_tree *fullscreen_global;
50#if HAVE_XWAYLAND
51 struct wlr_scene_tree *unmanaged;
52#endif
50 struct wlr_scene_tree *shell_overlay; 53 struct wlr_scene_tree *shell_overlay;
51 struct wlr_scene_tree *popup; 54 struct wlr_scene_tree *popup;
52 struct wlr_scene_tree *seat; 55 struct wlr_scene_tree *seat;
53 struct wlr_scene_tree *session_lock; 56 struct wlr_scene_tree *session_lock;
54 } layers; 57 } layers;
55 58
56#if HAVE_XWAYLAND
57 struct wl_list xwayland_unmanaged; // sway_xwayland_unmanaged::link
58#endif
59
60 // Includes disabled outputs 59 // Includes disabled outputs
61 struct wl_list all_outputs; // sway_output::link 60 struct wl_list all_outputs; // sway_output::link
62 61
diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h
index 467d912f..8493958e 100644
--- a/include/sway/tree/view.h
+++ b/include/sway/tree/view.h
@@ -147,6 +147,8 @@ struct sway_xdg_shell_view {
147struct sway_xwayland_view { 147struct sway_xwayland_view {
148 struct sway_view view; 148 struct sway_view view;
149 149
150 struct wlr_scene_tree *surface_tree;
151
150 struct wl_listener commit; 152 struct wl_listener commit;
151 struct wl_listener request_move; 153 struct wl_listener request_move;
152 struct wl_listener request_resize; 154 struct wl_listener request_resize;
@@ -168,18 +170,18 @@ struct sway_xwayland_view {
168 struct wl_listener unmap; 170 struct wl_listener unmap;
169 struct wl_listener destroy; 171 struct wl_listener destroy;
170 struct wl_listener override_redirect; 172 struct wl_listener override_redirect;
173
174 struct wl_listener surface_tree_destroy;
171}; 175};
172 176
173struct sway_xwayland_unmanaged { 177struct sway_xwayland_unmanaged {
174 struct wlr_xwayland_surface *wlr_xwayland_surface; 178 struct wlr_xwayland_surface *wlr_xwayland_surface;
175 struct wl_list link;
176 179
177 int lx, ly; 180 struct wlr_scene_surface *surface_scene;
178 181
179 struct wl_listener request_activate; 182 struct wl_listener request_activate;
180 struct wl_listener request_configure; 183 struct wl_listener request_configure;
181 struct wl_listener request_fullscreen; 184 struct wl_listener request_fullscreen;
182 struct wl_listener commit;
183 struct wl_listener set_geometry; 185 struct wl_listener set_geometry;
184 struct wl_listener associate; 186 struct wl_listener associate;
185 struct wl_listener dissociate; 187 struct wl_listener dissociate;
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index a5184484..36c8f52c 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,
182 view_for_each_popup_surface(view, output_for_each_surface_iterator, &data); 182 view_for_each_popup_surface(view, output_for_each_surface_iterator, &data);
183} 183}
184 184
185#if HAVE_XWAYLAND
186void output_unmanaged_for_each_surface(struct sway_output *output,
187 struct wl_list *unmanaged, sway_surface_iterator_func_t iterator,
188 void *user_data) {
189 struct sway_xwayland_unmanaged *unmanaged_surface;
190 wl_list_for_each(unmanaged_surface, unmanaged, link) {
191 struct wlr_xwayland_surface *xsurface =
192 unmanaged_surface->wlr_xwayland_surface;
193 double ox = unmanaged_surface->lx - output->lx;
194 double oy = unmanaged_surface->ly - output->ly;
195
196 output_surface_for_each_surface(output, xsurface->surface, ox, oy,
197 iterator, user_data);
198 }
199}
200#endif
201
202static int scale_length(int length, int offset, float scale) { 185static int scale_length(int length, int offset, float scale) {
203 return roundf((offset + length) * scale) - roundf(offset * scale); 186 return roundf((offset + length) * scale) - roundf(offset * scale);
204} 187}
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c
index 8f79b5e7..183bdba2 100644
--- a/sway/desktop/xwayland.c
+++ b/sway/desktop/xwayland.c
@@ -6,15 +6,16 @@
6#include <wlr/types/wlr_output_layout.h> 6#include <wlr/types/wlr_output_layout.h>
7#include <wlr/types/wlr_output.h> 7#include <wlr/types/wlr_output.h>
8#include <wlr/types/wlr_xdg_activation_v1.h> 8#include <wlr/types/wlr_xdg_activation_v1.h>
9#include <wlr/types/wlr_scene.h>
9#include <wlr/xwayland.h> 10#include <wlr/xwayland.h>
10#include <xcb/xcb_icccm.h> 11#include <xcb/xcb_icccm.h>
11#include "log.h" 12#include "log.h"
12#include "sway/desktop.h"
13#include "sway/desktop/transaction.h" 13#include "sway/desktop/transaction.h"
14#include "sway/input/cursor.h" 14#include "sway/input/cursor.h"
15#include "sway/input/input-manager.h" 15#include "sway/input/input-manager.h"
16#include "sway/input/seat.h" 16#include "sway/input/seat.h"
17#include "sway/output.h" 17#include "sway/output.h"
18#include "sway/scene_descriptor.h"
18#include "sway/tree/arrange.h" 19#include "sway/tree/arrange.h"
19#include "sway/tree/container.h" 20#include "sway/tree/container.h"
20#include "sway/server.h" 21#include "sway/server.h"
@@ -45,29 +46,12 @@ static void unmanaged_handle_request_configure(struct wl_listener *listener,
45 ev->width, ev->height); 46 ev->width, ev->height);
46} 47}
47 48
48static void unmanaged_handle_commit(struct wl_listener *listener, void *data) {
49 struct sway_xwayland_unmanaged *surface =
50 wl_container_of(listener, surface, commit);
51 struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface;
52
53 desktop_damage_surface(xsurface->surface, surface->lx, surface->ly,
54 false);
55}
56
57static void unmanaged_handle_set_geometry(struct wl_listener *listener, void *data) { 49static void unmanaged_handle_set_geometry(struct wl_listener *listener, void *data) {
58 struct sway_xwayland_unmanaged *surface = 50 struct sway_xwayland_unmanaged *surface =
59 wl_container_of(listener, surface, set_geometry); 51 wl_container_of(listener, surface, set_geometry);
60 struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface; 52 struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface;
61 53
62 if (xsurface->x != surface->lx || xsurface->y != surface->ly) { 54 wlr_scene_node_set_position(&surface->surface_scene->buffer->node, xsurface->x, xsurface->y);
63 // Surface has moved
64 desktop_damage_surface(xsurface->surface, surface->lx, surface->ly,
65 true);
66 surface->lx = xsurface->x;
67 surface->ly = xsurface->y;
68 desktop_damage_surface(xsurface->surface, surface->lx, surface->ly,
69 true);
70 }
71} 55}
72 56
73static void unmanaged_handle_map(struct wl_listener *listener, void *data) { 57static 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) {
75 wl_container_of(listener, surface, map); 59 wl_container_of(listener, surface, map);
76 struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface; 60 struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface;
77 61
78 wl_list_insert(root->xwayland_unmanaged.prev, &surface->link); 62 surface->surface_scene = wlr_scene_surface_create(root->layers.unmanaged,
63 xsurface->surface);
79 64
80 wl_signal_add(&xsurface->events.set_geometry, &surface->set_geometry); 65 if (surface->surface_scene) {
81 surface->set_geometry.notify = unmanaged_handle_set_geometry; 66 scene_descriptor_assign(&surface->surface_scene->buffer->node,
67 SWAY_SCENE_DESC_XWAYLAND_UNMANAGED, surface);
68 wlr_scene_node_set_position(&surface->surface_scene->buffer->node,
69 xsurface->x, xsurface->y);
82 70
83 wl_signal_add(&xsurface->surface->events.commit, &surface->commit); 71 wl_signal_add(&xsurface->events.set_geometry, &surface->set_geometry);
84 surface->commit.notify = unmanaged_handle_commit; 72 surface->set_geometry.notify = unmanaged_handle_set_geometry;
85 73 }
86 surface->lx = xsurface->x;
87 surface->ly = xsurface->y;
88 desktop_damage_surface(xsurface->surface, surface->lx, surface->ly, true);
89 74
90 if (wlr_xwayland_or_surface_wants_focus(xsurface)) { 75 if (wlr_xwayland_or_surface_wants_focus(xsurface)) {
91 struct sway_seat *seat = input_manager_current_seat(); 76 struct sway_seat *seat = input_manager_current_seat();
@@ -99,10 +84,13 @@ static void unmanaged_handle_unmap(struct wl_listener *listener, void *data) {
99 struct sway_xwayland_unmanaged *surface = 84 struct sway_xwayland_unmanaged *surface =
100 wl_container_of(listener, surface, unmap); 85 wl_container_of(listener, surface, unmap);
101 struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface; 86 struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface;
102 desktop_damage_surface(xsurface->surface, xsurface->x, xsurface->y, true); 87
103 wl_list_remove(&surface->link); 88 if (surface->surface_scene) {
104 wl_list_remove(&surface->set_geometry.link); 89 wl_list_remove(&surface->set_geometry.link);
105 wl_list_remove(&surface->commit.link); 90
91 wlr_scene_node_destroy(&surface->surface_scene->buffer->node);
92 surface->surface_scene = NULL;
93 }
106 94
107 struct sway_seat *seat = input_manager_current_seat(); 95 struct sway_seat *seat = input_manager_current_seat();
108 if (seat->wlr_seat->keyboard_state.focused_surface == xsurface->surface) { 96 if (seat->wlr_seat->keyboard_state.focused_surface == xsurface->surface) {
@@ -455,7 +443,6 @@ static void handle_commit(struct wl_listener *listener, void *data) {
455 // The client changed its surface size in this commit. For floating 443 // The client changed its surface size in this commit. For floating
456 // containers, we resize the container to match. For tiling containers, 444 // containers, we resize the container to match. For tiling containers,
457 // we only recenter the surface. 445 // we only recenter the surface.
458 desktop_damage_view(view);
459 memcpy(&view->geometry, &new_geo, sizeof(struct wlr_box)); 446 memcpy(&view->geometry, &new_geo, sizeof(struct wlr_box));
460 if (container_is_floating(view->container)) { 447 if (container_is_floating(view->container)) {
461 view_update_size(view); 448 view_update_size(view);
@@ -463,15 +450,12 @@ static void handle_commit(struct wl_listener *listener, void *data) {
463 } else { 450 } else {
464 view_center_surface(view); 451 view_center_surface(view);
465 } 452 }
466 desktop_damage_view(view);
467 } 453 }
468 454
469 if (view->container->node.instruction) { 455 if (view->container->node.instruction) {
470 transaction_notify_view_ready_by_geometry(view, 456 transaction_notify_view_ready_by_geometry(view,
471 xsurface->x, xsurface->y, state->width, state->height); 457 xsurface->x, xsurface->y, state->width, state->height);
472 } 458 }
473
474 view_damage_from(view);
475} 459}
476 460
477static void handle_destroy(struct wl_listener *listener, void *data) { 461static void handle_destroy(struct wl_listener *listener, void *data) {
@@ -515,9 +499,21 @@ static void handle_unmap(struct wl_listener *listener, void *data) {
515 return; 499 return;
516 } 500 }
517 501
502 wl_list_remove(&xwayland_view->commit.link);
503 wl_list_remove(&xwayland_view->surface_tree_destroy.link);
504
505 if (xwayland_view->surface_tree) {
506 wlr_scene_node_destroy(&xwayland_view->surface_tree->node);
507 xwayland_view->surface_tree = NULL;
508 }
509
518 view_unmap(view); 510 view_unmap(view);
511}
519 512
520 wl_list_remove(&xwayland_view->commit.link); 513static void handle_surface_tree_destroy(struct wl_listener *listener, void *data) {
514 struct sway_xwayland_view *xwayland_view = wl_container_of(listener, xwayland_view,
515 surface_tree_destroy);
516 xwayland_view->surface_tree = NULL;
521} 517}
522 518
523static void handle_map(struct wl_listener *listener, void *data) { 519static void handle_map(struct wl_listener *listener, void *data) {
@@ -537,6 +533,15 @@ static void handle_map(struct wl_listener *listener, void *data) {
537 // Put it back into the tree 533 // Put it back into the tree
538 view_map(view, xsurface->surface, xsurface->fullscreen, NULL, false); 534 view_map(view, xsurface->surface, xsurface->fullscreen, NULL, false);
539 535
536 xwayland_view->surface_tree = wlr_scene_subsurface_tree_create(
537 xwayland_view->view.content_tree, xsurface->surface);
538
539 if (xwayland_view->surface_tree) {
540 xwayland_view->surface_tree_destroy.notify = handle_surface_tree_destroy;
541 wl_signal_add(&xwayland_view->surface_tree->node.events.destroy,
542 &xwayland_view->surface_tree_destroy);
543 }
544
540 transaction_commit_dirty(); 545 transaction_commit_dirty();
541} 546}
542 547
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index fd8f50d4..404c1eed 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -107,6 +107,12 @@ struct sway_node *node_at_coords(
107 return NULL; 107 return NULL;
108 } 108 }
109 109
110#if HAVE_XWAYLAND
111 if (scene_descriptor_try_get(current, SWAY_SCENE_DESC_XWAYLAND_UNMANAGED)) {
112 return NULL;
113 }
114#endif
115
110 if (!current->parent) { 116 if (!current->parent) {
111 break; 117 break;
112 } 118 }
diff --git a/sway/tree/root.c b/sway/tree/root.c
index 7c8f9ea6..e9cea5e2 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) {
54 root->layers.shell_top = alloc_scene_tree(root->layer_tree, &failed); 54 root->layers.shell_top = alloc_scene_tree(root->layer_tree, &failed);
55 root->layers.fullscreen = alloc_scene_tree(root->layer_tree, &failed); 55 root->layers.fullscreen = alloc_scene_tree(root->layer_tree, &failed);
56 root->layers.fullscreen_global = alloc_scene_tree(root->layer_tree, &failed); 56 root->layers.fullscreen_global = alloc_scene_tree(root->layer_tree, &failed);
57#if HAVE_XWAYLAND
58 root->layers.unmanaged = alloc_scene_tree(root->layer_tree, &failed);
59#endif
57 root->layers.shell_overlay = alloc_scene_tree(root->layer_tree, &failed); 60 root->layers.shell_overlay = alloc_scene_tree(root->layer_tree, &failed);
58 root->layers.popup = alloc_scene_tree(root->layer_tree, &failed); 61 root->layers.popup = alloc_scene_tree(root->layer_tree, &failed);
59 root->layers.seat = alloc_scene_tree(root->layer_tree, &failed); 62 root->layers.seat = alloc_scene_tree(root->layer_tree, &failed);
@@ -74,9 +77,6 @@ struct sway_root *root_create(struct wl_display *wl_display) {
74 77
75 root->output_layout = wlr_output_layout_create(wl_display); 78 root->output_layout = wlr_output_layout_create(wl_display);
76 wl_list_init(&root->all_outputs); 79 wl_list_init(&root->all_outputs);
77#if HAVE_XWAYLAND
78 wl_list_init(&root->xwayland_unmanaged);
79#endif
80 wl_signal_init(&root->events.new_node); 80 wl_signal_init(&root->events.new_node);
81 root->outputs = create_list(); 81 root->outputs = create_list();
82 root->non_desktop_outputs = create_list(); 82 root->non_desktop_outputs = create_list();