From 525b48ede795effb6ef61b7caf6ad333393cfd64 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Thu, 27 Feb 2020 17:55:55 -0800 Subject: Adjust focus order to match rendering order of layer shell popups. --- sway/input/cursor.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'sway/input/cursor.c') diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 470bb996..11a2de85 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -52,6 +52,30 @@ static struct wlr_surface *layer_surface_at(struct sway_output *output, return NULL; } +static bool surface_is_xdg_popup(struct wlr_surface *surface) { + if (wlr_surface_is_xdg_surface(surface)) { + struct wlr_xdg_surface *xdg_surface = + wlr_xdg_surface_from_wlr_surface(surface); + return xdg_surface->role == WLR_XDG_SURFACE_ROLE_POPUP; + } + return false; +} + +static struct wlr_surface *layer_surface_popup_at(struct sway_output *output, + struct wl_list *layer, double ox, double oy, double *sx, double *sy) { + struct sway_layer_surface *sway_layer; + wl_list_for_each_reverse(sway_layer, layer, link) { + double _sx = ox - sway_layer->geo.x; + double _sy = oy - sway_layer->geo.y; + struct wlr_surface *sub = wlr_layer_surface_v1_surface_at( + sway_layer->layer_surface, _sx, _sy, sx, sy); + if (sub && surface_is_xdg_popup(sub)) { + return sub; + } + } + return NULL; +} + /** * Returns the node at the cursor's position. If there is a surface at that * location, it is stored in **surface (it may not be a view). @@ -132,6 +156,21 @@ struct sway_node *node_at_coords( } return NULL; } + if ((*surface = layer_surface_popup_at(output, + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], + ox, oy, sx, sy))) { + return NULL; + } + if ((*surface = layer_surface_popup_at(output, + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], + ox, oy, sx, sy))) { + return NULL; + } + if ((*surface = layer_surface_popup_at(output, + &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], + ox, oy, sx, sy))) { + return NULL; + } if ((*surface = layer_surface_at(output, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], ox, oy, sx, sy))) { -- cgit v1.2.3-54-g00ecf