layer_shell: Replace toplevel_layer_surface_from_surface with scene_descriptor_find

We can instead search the scene instead of hand rolling this logic
This commit is contained in:
Alexander Orzechowski 2024-08-26 16:55:59 -04:00
parent 1ee209dc56
commit eadc380a30
3 changed files with 15 additions and 50 deletions

View file

@ -36,9 +36,6 @@ struct sway_layer_popup {
struct sway_output; struct sway_output;
struct wlr_layer_surface_v1 *toplevel_layer_surface_from_surface(
struct wlr_surface *surface);
void arrange_layers(struct sway_output *output); void arrange_layers(struct sway_output *output);
#endif #endif

View file

@ -20,39 +20,6 @@
#include "sway/tree/arrange.h" #include "sway/tree/arrange.h"
#include "sway/tree/workspace.h" #include "sway/tree/workspace.h"
struct wlr_layer_surface_v1 *toplevel_layer_surface_from_surface(
struct wlr_surface *surface) {
struct wlr_layer_surface_v1 *layer;
do {
if (!surface) {
return NULL;
}
// Topmost layer surface
if ((layer = wlr_layer_surface_v1_try_from_wlr_surface(surface))) {
return layer;
}
// Layer subsurface
if (wlr_subsurface_try_from_wlr_surface(surface)) {
surface = wlr_surface_get_root_surface(surface);
continue;
}
// Layer surface popup
struct wlr_xdg_surface *xdg_surface = NULL;
if ((xdg_surface = wlr_xdg_surface_try_from_wlr_surface(surface)) &&
xdg_surface->role == WLR_XDG_SURFACE_ROLE_POPUP && xdg_surface->popup != NULL) {
if (!xdg_surface->popup->parent) {
return NULL;
}
surface = wlr_surface_get_root_surface(xdg_surface->popup->parent);
continue;
}
// Return early if the surface is not a layer/xdg_popup/sub surface
return NULL;
} while (true);
}
static void arrange_surface(struct sway_output *output, const struct wlr_box *full_area, static void arrange_surface(struct sway_output *output, const struct wlr_box *full_area,
struct wlr_box *usable_area, struct wlr_scene_tree *tree) { struct wlr_box *usable_area, struct wlr_scene_tree *tree) {
struct wlr_scene_node *node; struct wlr_scene_node *node;

View file

@ -334,10 +334,12 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
struct sway_cursor *cursor = seat->cursor; struct sway_cursor *cursor = seat->cursor;
// Determine what's under the cursor // Determine what's under the cursor
struct wlr_surface *surface = NULL;
double sx, sy; double sx, sy;
struct sway_node *node = node_at_coords( struct wlr_scene_node *scene_node =
cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); scene_node_at_coords(cursor->cursor->x, cursor->cursor->y, &sx, &sy);
struct wlr_surface *surface = scene_node ? surface_try_from_scene_node(scene_node) : NULL;
struct sway_node *node = sway_node_try_from_scene_node(scene_node,
cursor->cursor->x, cursor->cursor->y);
struct sway_container *cont = node && node->type == N_CONTAINER ? struct sway_container *cont = node && node->type == N_CONTAINER ?
node->sway_container : NULL; node->sway_container : NULL;
@ -372,10 +374,10 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
} }
// Handle clicking a layer surface and its popups/subsurfaces // Handle clicking a layer surface and its popups/subsurfaces
struct wlr_layer_surface_v1 *layer = NULL; struct sway_layer_surface *layer = NULL;
if ((layer = toplevel_layer_surface_from_surface(surface))) { if ((layer = scene_descriptor_find(scene_node, SWAY_SCENE_DESC_LAYER_SHELL))) {
if (layer->current.keyboard_interactive) { if (layer->layer_surface->current.keyboard_interactive) {
seat_set_focus_layer(seat, layer); seat_set_focus_layer(seat, layer->layer_surface);
transaction_commit_dirty(); transaction_commit_dirty();
} }
if (state == WL_POINTER_BUTTON_STATE_PRESSED) { if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
@ -550,15 +552,14 @@ static void check_focus_follows_mouse(struct sway_seat *seat,
return; return;
} }
struct wlr_surface *surface = NULL; struct wlr_scene_node *node = scene_node_at_coords(
double sx, sy; seat->cursor->cursor->x, seat->cursor->cursor->y, NULL, NULL);
node_at_coords(seat->cursor->cursor->x, seat->cursor->cursor->y, &surface, &sx, &sy);
// Focus topmost layer surface // Focus topmost layer surface
struct wlr_layer_surface_v1 *layer = NULL; struct sway_layer_surface *layer = NULL;
if ((layer = toplevel_layer_surface_from_surface(surface)) && if ((layer = scene_descriptor_find(node, SWAY_SCENE_DESC_LAYER_SHELL)) &&
layer->current.keyboard_interactive) { layer->layer_surface->current.keyboard_interactive) {
seat_set_focus_layer(seat, layer); seat_set_focus_layer(seat, layer->layer_surface);
transaction_commit_dirty(); transaction_commit_dirty();
return; return;
} }