mirror of
https://github.com/swaywm/sway.git
synced 2024-11-24 00:41:28 +00:00
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:
parent
1ee209dc56
commit
eadc380a30
|
@ -36,9 +36,6 @@ struct sway_layer_popup {
|
|||
|
||||
struct sway_output;
|
||||
|
||||
struct wlr_layer_surface_v1 *toplevel_layer_surface_from_surface(
|
||||
struct wlr_surface *surface);
|
||||
|
||||
void arrange_layers(struct sway_output *output);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -20,39 +20,6 @@
|
|||
#include "sway/tree/arrange.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,
|
||||
struct wlr_box *usable_area, struct wlr_scene_tree *tree) {
|
||||
struct wlr_scene_node *node;
|
||||
|
|
|
@ -334,10 +334,12 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
|
|||
struct sway_cursor *cursor = seat->cursor;
|
||||
|
||||
// Determine what's under the cursor
|
||||
struct wlr_surface *surface = NULL;
|
||||
double sx, sy;
|
||||
struct sway_node *node = node_at_coords(
|
||||
cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy);
|
||||
struct wlr_scene_node *scene_node =
|
||||
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 ?
|
||||
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
|
||||
struct wlr_layer_surface_v1 *layer = NULL;
|
||||
if ((layer = toplevel_layer_surface_from_surface(surface))) {
|
||||
if (layer->current.keyboard_interactive) {
|
||||
seat_set_focus_layer(seat, layer);
|
||||
struct sway_layer_surface *layer = NULL;
|
||||
if ((layer = scene_descriptor_find(scene_node, SWAY_SCENE_DESC_LAYER_SHELL))) {
|
||||
if (layer->layer_surface->current.keyboard_interactive) {
|
||||
seat_set_focus_layer(seat, layer->layer_surface);
|
||||
transaction_commit_dirty();
|
||||
}
|
||||
if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
||||
|
@ -550,15 +552,14 @@ static void check_focus_follows_mouse(struct sway_seat *seat,
|
|||
return;
|
||||
}
|
||||
|
||||
struct wlr_surface *surface = NULL;
|
||||
double sx, sy;
|
||||
node_at_coords(seat->cursor->cursor->x, seat->cursor->cursor->y, &surface, &sx, &sy);
|
||||
struct wlr_scene_node *node = scene_node_at_coords(
|
||||
seat->cursor->cursor->x, seat->cursor->cursor->y, NULL, NULL);
|
||||
|
||||
// Focus topmost layer surface
|
||||
struct wlr_layer_surface_v1 *layer = NULL;
|
||||
if ((layer = toplevel_layer_surface_from_surface(surface)) &&
|
||||
layer->current.keyboard_interactive) {
|
||||
seat_set_focus_layer(seat, layer);
|
||||
struct sway_layer_surface *layer = NULL;
|
||||
if ((layer = scene_descriptor_find(node, SWAY_SCENE_DESC_LAYER_SHELL)) &&
|
||||
layer->layer_surface->current.keyboard_interactive) {
|
||||
seat_set_focus_layer(seat, layer->layer_surface);
|
||||
transaction_commit_dirty();
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue