Skip to content

Commit

Permalink
Added helper function to get a wlr_layer_surface from a wlr_surface
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikReider committed May 22, 2023
1 parent 49fd0f4 commit 08d4626
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 68 deletions.
4 changes: 4 additions & 0 deletions include/sway/layers.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ struct sway_layer_subsurface {
};

struct sway_output;

struct wlr_layer_surface_v1 *toplevel_layer_surface_from_surface(
struct wlr_surface *surface);

void arrange_layers(struct sway_output *output);

struct sway_layer_surface *layer_from_wlr_layer_surface_v1(
Expand Down
35 changes: 34 additions & 1 deletion sway/desktop/layer_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,39 @@
#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_popup = NULL;
if ((xdg_popup = wlr_xdg_surface_try_from_wlr_surface(surface)) &&
xdg_popup->role == WLR_XDG_SURFACE_ROLE_POPUP) {
if (!xdg_popup->popup->parent) {
return NULL;
}
surface = wlr_surface_get_root_surface(xdg_popup->popup->parent);
continue;
}

// Return early if the surface is not a layer/xdg_popup/sub surface
return NULL;
} while (true);
}

static void apply_exclusive(struct wlr_box *usable_area,
uint32_t anchor, int32_t exclusive,
int32_t margin_top, int32_t margin_right,
Expand Down Expand Up @@ -232,12 +265,12 @@ void arrange_layers(struct sway_output *output) {

struct sway_seat *seat;
wl_list_for_each(seat, &server.input->seats, link) {
seat->exclusive_layer = NULL;
if (topmost != NULL) {
seat_set_focus_layer(seat, topmost->layer_surface);
} else if (seat->focused_layer &&
seat->focused_layer->current.keyboard_interactive
!= ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE) {
seat->exclusive_layer = NULL;
seat_set_focus_layer(seat, NULL);
}
}
Expand Down
73 changes: 6 additions & 67 deletions sway/input/seatop_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "sway/input/cursor.h"
#include "sway/input/seat.h"
#include "sway/input/tablet.h"
#include "sway/layers.h"
#include "sway/output.h"
#include "sway/tree/view.h"
#include "sway/tree/workspace.h"
Expand Down Expand Up @@ -367,49 +368,14 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
return;
}

// Handle clicking a layer surface
struct wlr_surface *layer_surface = surface;
struct wlr_layer_surface_v1 *layer;
if (layer_surface &&
(layer = wlr_layer_surface_v1_try_from_wlr_surface(layer_surface))) {
// 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(seat, NULL);
seat_set_focus_layer(seat, layer);
transaction_commit_dirty();
}
if (state == WLR_BUTTON_PRESSED) {
seatop_begin_down_on_surface(seat, layer_surface, sx, sy);
}
seat_pointer_notify_button(seat, time_msec, button, state);
return;
}
// Handle clicking a layer subsurface
struct wlr_subsurface * subsurface = NULL;
if (surface &&
(subsurface = wlr_subsurface_try_from_wlr_surface(surface)) &&
(layer_surface = subsurface->parent) &&
(layer = wlr_layer_surface_v1_try_from_wlr_surface(layer_surface)) &&
layer->current.keyboard_interactive) {
seat_set_focus(seat, NULL);
seat_set_focus_layer(seat, layer);
transaction_commit_dirty();
if (state == WLR_BUTTON_PRESSED) {
seatop_begin_down_on_surface(seat, surface, sx, sy);
}
seat_pointer_notify_button(seat, time_msec, button, state);
return;
}
// Handle clicking a layer surface popup
struct wlr_xdg_surface * xdg_popup = NULL;
if (surface &&
(xdg_popup = wlr_xdg_surface_try_from_wlr_surface(surface)) &&
xdg_popup->role == WLR_XDG_SURFACE_ROLE_POPUP &&
(layer_surface = xdg_popup->popup->parent) &&
(layer = wlr_layer_surface_v1_try_from_wlr_surface(layer_surface)) &&
layer->current.keyboard_interactive) {
seat_set_focus(seat, NULL);
seat_set_focus_layer(seat, layer);
transaction_commit_dirty();
if (state == WLR_BUTTON_PRESSED) {
seatop_begin_down_on_surface(seat, surface, sx, sy);
}
Expand Down Expand Up @@ -598,35 +564,8 @@ static void check_focus_follows_mouse(struct sway_seat *seat,
&surface, &sx, &sy);

// Focus topmost layer surface
struct wlr_surface *layer_surface = surface;
struct wlr_layer_surface_v1 *layer;
if (layer_surface &&
(layer = wlr_layer_surface_v1_try_from_wlr_surface(layer_surface))
&& layer->current.keyboard_interactive) {
seat_set_focus(seat, NULL);
seat_set_focus_layer(seat, layer);
transaction_commit_dirty();
return;
}
// Focus topmost layer subsurface
struct wlr_subsurface * subsurface = NULL;
if (surface &&
(subsurface = wlr_subsurface_try_from_wlr_surface(surface)) &&
(layer_surface = subsurface->parent) &&
(layer = wlr_layer_surface_v1_try_from_wlr_surface(layer_surface)) &&
layer->current.keyboard_interactive) {
seat_set_focus(seat, NULL);
seat_set_focus_layer(seat, layer);
transaction_commit_dirty();
return;
}
// Focus topmost layer surface popup
struct wlr_xdg_surface * xdg_popup = NULL;
if (surface &&
(xdg_popup = wlr_xdg_surface_try_from_wlr_surface(surface)) &&
xdg_popup->role == WLR_XDG_SURFACE_ROLE_POPUP &&
(layer_surface = xdg_popup->popup->parent) &&
(layer = wlr_layer_surface_v1_try_from_wlr_surface(layer_surface)) &&
struct wlr_layer_surface_v1 *layer = NULL;
if ((layer = toplevel_layer_surface_from_surface(surface)) &&
layer->current.keyboard_interactive) {
seat_set_focus(seat, NULL);
seat_set_focus_layer(seat, layer);
Expand Down

0 comments on commit 08d4626

Please sign in to comment.