scene_graph: Port xwayland

This commit is contained in:
Alexander Orzechowski 2022-05-21 14:09:01 -04:00 committed by Kirill Primak
parent c3615a8b57
commit 6fcd702c97
8 changed files with 34 additions and 69 deletions

View file

@ -143,12 +143,6 @@ void output_view_for_each_popup_surface(struct sway_output *output,
struct sway_view *view, sway_surface_iterator_func_t iterator, struct sway_view *view, sway_surface_iterator_func_t iterator,
void *user_data); 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 output_for_each_workspace(struct sway_output *output,
void (*f)(struct sway_workspace *ws, void *data), void *data); void (*f)(struct sway_workspace *ws, void *data), void *data);

View file

@ -7,6 +7,7 @@ enum sway_scene_descriptor_type {
SWAY_SCENE_DESC_NON_INTERACTIVE, SWAY_SCENE_DESC_NON_INTERACTIVE,
SWAY_SCENE_DESC_CONTAINER, SWAY_SCENE_DESC_CONTAINER,
SWAY_SCENE_DESC_LAYER_SHELL, SWAY_SCENE_DESC_LAYER_SHELL,
SWAY_SCENE_DESC_XWAYLAND_UNMANAGED,
SWAY_SCENE_DESC_POPUP, SWAY_SCENE_DESC_POPUP,
SWAY_SCENE_DESC_DRAG_ICON, SWAY_SCENE_DESC_DRAG_ICON,
}; };

View file

@ -42,16 +42,15 @@ struct sway_root {
struct wlr_scene_tree *shell_top; struct wlr_scene_tree *shell_top;
struct wlr_scene_tree *fullscreen; struct wlr_scene_tree *fullscreen;
struct wlr_scene_tree *fullscreen_global; 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 *shell_overlay;
struct wlr_scene_tree *popup; struct wlr_scene_tree *popup;
struct wlr_scene_tree *seat; struct wlr_scene_tree *seat;
struct wlr_scene_tree *session_lock; struct wlr_scene_tree *session_lock;
} layers; } layers;
#if HAVE_XWAYLAND
struct wl_list xwayland_unmanaged; // sway_xwayland_unmanaged::link
#endif
// Includes disabled outputs // Includes disabled outputs
struct wl_list all_outputs; // sway_output::link struct wl_list all_outputs; // sway_output::link

View file

@ -146,6 +146,8 @@ struct sway_xdg_shell_view {
struct sway_xwayland_view { struct sway_xwayland_view {
struct sway_view view; struct sway_view view;
struct wlr_scene_surface *surface_scene;
struct wl_listener commit; struct wl_listener commit;
struct wl_listener request_move; struct wl_listener request_move;
struct wl_listener request_resize; struct wl_listener request_resize;
@ -168,14 +170,12 @@ struct sway_xwayland_view {
struct sway_xwayland_unmanaged { struct sway_xwayland_unmanaged {
struct wlr_xwayland_surface *wlr_xwayland_surface; 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_activate;
struct wl_listener request_configure; struct wl_listener request_configure;
struct wl_listener request_fullscreen; struct wl_listener request_fullscreen;
struct wl_listener commit;
struct wl_listener set_geometry; struct wl_listener set_geometry;
struct wl_listener map; struct wl_listener map;
struct wl_listener unmap; struct wl_listener unmap;

View file

@ -169,23 +169,6 @@ void output_view_for_each_popup_surface(struct sway_output *output,
view_for_each_popup_surface(view, output_for_each_surface_iterator, &data); 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) { static int scale_length(int length, int offset, float scale) {
return round((offset + length) * scale) - round(offset * scale); return round((offset + length) * scale) - round(offset * scale);
} }

View file

@ -5,15 +5,16 @@
#include <wayland-server-core.h> #include <wayland-server-core.h>
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/xwayland.h> #include <wlr/xwayland.h>
#include <xcb/xcb_icccm.h> #include <xcb/xcb_icccm.h>
#include "log.h" #include "log.h"
#include "sway/desktop.h"
#include "sway/desktop/transaction.h" #include "sway/desktop/transaction.h"
#include "sway/input/cursor.h" #include "sway/input/cursor.h"
#include "sway/input/input-manager.h" #include "sway/input/input-manager.h"
#include "sway/input/seat.h" #include "sway/input/seat.h"
#include "sway/output.h" #include "sway/output.h"
#include "sway/scene_descriptor.h"
#include "sway/tree/arrange.h" #include "sway/tree/arrange.h"
#include "sway/tree/container.h" #include "sway/tree/container.h"
#include "sway/tree/view.h" #include "sway/tree/view.h"
@ -43,29 +44,12 @@ static void unmanaged_handle_request_configure(struct wl_listener *listener,
ev->width, ev->height); 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) { static void unmanaged_handle_set_geometry(struct wl_listener *listener, void *data) {
struct sway_xwayland_unmanaged *surface = struct sway_xwayland_unmanaged *surface =
wl_container_of(listener, surface, set_geometry); wl_container_of(listener, surface, set_geometry);
struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface; struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface;
if (xsurface->x != surface->lx || xsurface->y != surface->ly) { wlr_scene_node_set_position(&surface->surface_scene->buffer->node, xsurface->x, xsurface->y);
// 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);
}
} }
static void unmanaged_handle_map(struct wl_listener *listener, void *data) { static void unmanaged_handle_map(struct wl_listener *listener, void *data) {
@ -73,17 +57,18 @@ static void unmanaged_handle_map(struct wl_listener *listener, void *data) {
wl_container_of(listener, surface, map); wl_container_of(listener, surface, map);
struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface; 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); if (surface->surface_scene) {
surface->set_geometry.notify = unmanaged_handle_set_geometry; 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); wl_signal_add(&xsurface->events.set_geometry, &surface->set_geometry);
surface->commit.notify = unmanaged_handle_commit; surface->set_geometry.notify = unmanaged_handle_set_geometry;
}
surface->lx = xsurface->x;
surface->ly = xsurface->y;
desktop_damage_surface(xsurface->surface, surface->lx, surface->ly, true);
if (wlr_xwayland_or_surface_wants_focus(xsurface)) { if (wlr_xwayland_or_surface_wants_focus(xsurface)) {
struct sway_seat *seat = input_manager_current_seat(); struct sway_seat *seat = input_manager_current_seat();
@ -97,10 +82,10 @@ static void unmanaged_handle_unmap(struct wl_listener *listener, void *data) {
struct sway_xwayland_unmanaged *surface = struct sway_xwayland_unmanaged *surface =
wl_container_of(listener, surface, unmap); wl_container_of(listener, surface, unmap);
struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface; struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface;
desktop_damage_surface(xsurface->surface, xsurface->x, xsurface->y, true);
wl_list_remove(&surface->link); if (surface->surface_scene) {
wl_list_remove(&surface->set_geometry.link); wl_list_remove(&surface->set_geometry.link);
wl_list_remove(&surface->commit.link); }
struct sway_seat *seat = input_manager_current_seat(); struct sway_seat *seat = input_manager_current_seat();
if (seat->wlr_seat->keyboard_state.focused_surface == xsurface->surface) { if (seat->wlr_seat->keyboard_state.focused_surface == xsurface->surface) {
@ -425,7 +410,6 @@ static void handle_commit(struct wl_listener *listener, void *data) {
// The client changed its surface size in this commit. For floating // The client changed its surface size in this commit. For floating
// containers, we resize the container to match. For tiling containers, // containers, we resize the container to match. For tiling containers,
// we only recenter the surface. // we only recenter the surface.
desktop_damage_view(view);
memcpy(&view->geometry, &new_geo, sizeof(struct wlr_box)); memcpy(&view->geometry, &new_geo, sizeof(struct wlr_box));
if (container_is_floating(view->container)) { if (container_is_floating(view->container)) {
view_update_size(view); view_update_size(view);
@ -433,15 +417,12 @@ static void handle_commit(struct wl_listener *listener, void *data) {
} else { } else {
view_center_surface(view); view_center_surface(view);
} }
desktop_damage_view(view);
} }
if (view->container->node.instruction) { if (view->container->node.instruction) {
transaction_notify_view_ready_by_geometry(view, transaction_notify_view_ready_by_geometry(view,
xsurface->x, xsurface->y, state->width, state->height); xsurface->x, xsurface->y, state->width, state->height);
} }
view_damage_from(view);
} }
static void handle_destroy(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) {
@ -486,6 +467,8 @@ static void handle_unmap(struct wl_listener *listener, void *data) {
view_unmap(view); view_unmap(view);
xwayland_view->surface_scene = NULL;
wl_list_remove(&xwayland_view->commit.link); wl_list_remove(&xwayland_view->commit.link);
} }
@ -506,6 +489,9 @@ static void handle_map(struct wl_listener *listener, void *data) {
// Put it back into the tree // Put it back into the tree
view_map(view, xsurface->surface, xsurface->fullscreen, NULL, false); view_map(view, xsurface->surface, xsurface->fullscreen, NULL, false);
xwayland_view->surface_scene = wlr_scene_surface_create(
xwayland_view->view.content_tree, xsurface->surface);
transaction_commit_dirty(); transaction_commit_dirty();
} }

View file

@ -86,6 +86,11 @@ struct sway_node *node_at_coords(
struct sway_container *con = popup->child.view->container; struct sway_container *con = popup->child.view->container;
return &con->node; return &con->node;
} }
#if HAVE_XWAYLAND
else if (desc->type == SWAY_SCENE_DESC_XWAYLAND_UNMANAGED) {
return NULL;
}
#endif
} }
if (!current->parent) { if (!current->parent) {

View file

@ -67,9 +67,6 @@ struct sway_root *root_create(void) {
root->output_layout = wlr_output_layout_create(); root->output_layout = wlr_output_layout_create();
wl_list_init(&root->all_outputs); wl_list_init(&root->all_outputs);
#if HAVE_XWAYLAND
wl_list_init(&root->xwayland_unmanaged);
#endif
wl_signal_init(&root->events.new_node); wl_signal_init(&root->events.new_node);
root->outputs = create_list(); root->outputs = create_list();
root->non_desktop_outputs = create_list(); root->non_desktop_outputs = create_list();