commit 70c6001723841b593880f73b67e5bda99cd466d1
parent 6a928895864f766363cf3b6ad851d9efd8e85335
Author: shrub <maybeshrub@gmail.com>
Date: Fri, 8 May 2026 12:34:00 +0000
layer shell: stack layers properly
Diffstat:
3 files changed, 100 insertions(+), 8 deletions(-)
diff --git a/libswc/compositor.c b/libswc/compositor.c
@@ -1027,6 +1027,40 @@ static const struct view_impl view_impl = {
.move = move,
};
+static void
+restack_view_for_layer(struct compositor_view *view, bool raise)
+{
+ struct compositor_view *other;
+ struct wl_list *insert_after = compositor.views.prev;
+
+ wl_list_for_each(other, &compositor.views, link)
+ {
+ if (other == view) {
+ continue;
+ }
+
+ if (other->stack_layer > view->stack_layer) {
+ insert_after = &other->link;
+ continue;
+ }
+
+ if (other->stack_layer == view->stack_layer) {
+ if (raise) {
+ insert_after = other->link.prev;
+ } else {
+ insert_after = &other->link;
+ }
+ break;
+ }
+
+ insert_after = other->link.prev;
+ break;
+ }
+
+ wl_list_remove(&view->link);
+ wl_list_insert(insert_after, &view->link);
+}
+
static struct compositor_view *
view_at(int32_t x, int32_t y)
{
@@ -1101,11 +1135,16 @@ raise_window(struct compositor_view *view)
continue;
}
- if (other->always_top) {
+ if (other->stack_layer > STACK_LAYER_NORMAL ||
+ other->always_top) {
insert_after = &other->link;
continue;
}
+ if (other->stack_layer < STACK_LAYER_NORMAL) {
+ break;
+ }
+
if (other->window) {
top_window = other;
break;
@@ -1133,8 +1172,28 @@ raise_window(struct compositor_view *view)
void
raise_window_top(struct compositor_view *view)
{
- wl_list_remove(&view->link);
- wl_list_insert(&compositor.views, &view->link);
+ view->stack_layer = STACK_LAYER_OVERLAY;
+ restack_view_for_layer(view, true);
+ damage_view(view);
+ schedule_updates(view->base.screens);
+}
+
+void
+compositor_view_set_stack_layer(struct compositor_view *view, uint32_t layer,
+ bool raise)
+{
+ if (view->stack_layer == layer) {
+ if (raise) {
+ restack_view_for_layer(view, true);
+ damage_view(view);
+ schedule_updates(view->base.screens);
+ }
+ return;
+ }
+
+ damage_view(view);
+ view->stack_layer = layer;
+ restack_view_for_layer(view, raise);
damage_view(view);
schedule_updates(view->base.screens);
}
@@ -1267,6 +1326,7 @@ compositor_create_view(struct surface *surface)
view->buffer_offset_y = 0;
view->visible = false;
view->always_top = false;
+ view->stack_layer = STACK_LAYER_NORMAL;
view->extents.x1 = 0;
view->extents.y1 = 0;
view->extents.x2 = 0;
diff --git a/libswc/compositor.h b/libswc/compositor.h
@@ -75,6 +75,9 @@ struct compositor_view {
/* Whether or not to make it always be on top of other windows */
bool always_top;
+ /* Global stacking layer for this view */
+ uint32_t stack_layer;
+
/* The box that the surface covers (including it's border). */
pixman_box32_t extents;
@@ -166,4 +169,16 @@ raise_window(struct compositor_view *view);
void
raise_window_top(struct compositor_view *view);
+enum compositor_stack_layer {
+ STACK_LAYER_BACKGROUND = 0,
+ STACK_LAYER_BOTTOM = 1,
+ STACK_LAYER_NORMAL = 2,
+ STACK_LAYER_TOP = 3,
+ STACK_LAYER_OVERLAY = 4,
+};
+
+void
+compositor_view_set_stack_layer(struct compositor_view *view, uint32_t layer,
+ bool raise);
+
#endif
diff --git a/libswc/layer_shell.c b/libswc/layer_shell.c
@@ -153,13 +153,30 @@ update_usable_geometry(struct layer_surface *surface)
static void
restack_layer(struct layer_surface *surface)
{
- bool always_top = surface->current.layer == ZWLR_LAYER_SHELL_V1_LAYER_TOP ||
- surface->current.layer == ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY;
+ uint32_t stack_layer = STACK_LAYER_NORMAL;
+ bool always_top = false;
- surface->view->always_top = always_top;
- if (always_top) {
- raise_window_top(surface->view);
+ switch (surface->current.layer) {
+ case ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND:
+ stack_layer = STACK_LAYER_BACKGROUND;
+ break;
+ case ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM:
+ stack_layer = STACK_LAYER_BOTTOM;
+ break;
+ case ZWLR_LAYER_SHELL_V1_LAYER_TOP:
+ stack_layer = STACK_LAYER_TOP;
+ always_top = true;
+ break;
+ case ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY:
+ stack_layer = STACK_LAYER_OVERLAY;
+ always_top = true;
+ break;
+ default:
+ break;
}
+
+ surface->view->always_top = always_top;
+ compositor_view_set_stack_layer(surface->view, stack_layer, true);
}
static void