Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions libswc/compositor.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,45 @@ 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;
bool found_same = false;

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) {
found_same = true;
insert_after = raise ? other->link.prev : &other->link;
break;
}

insert_after = other->link.prev;
break;
}

if (!found_same && !raise && insert_after == &compositor.views) {
insert_after = compositor.views.prev;
if (insert_after == &view->link)
insert_after = insert_after->prev;
}

if (insert_after == &view->link)
insert_after = insert_after->prev;

wl_list_remove(&view->link);
wl_list_insert(insert_after, &view->link);
}

struct compositor_view *
compositor_create_view(struct surface *surface)
{
Expand All @@ -450,6 +489,8 @@ compositor_create_view(struct surface *surface)
view->window = NULL;
view->parent = NULL;
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;
Expand All @@ -461,6 +502,7 @@ compositor_create_view(struct surface *surface)
wl_signal_init(&view->destroy_signal);
surface_set_view(surface, &view->base);
wl_list_insert(&compositor.views, &view->link);
restack_view_for_layer(view, true);

return view;
}
Expand Down Expand Up @@ -538,6 +580,34 @@ compositor_view_hide(struct compositor_view *view)
}
}

void
raise_window_top(struct compositor_view *view)
{
view->stack_layer = STACK_LAYER_OVERLAY;
restack_view_for_layer(view, true);
damage_view(view);
update(&view->base);
}

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);
update(&view->base);
}
return;
}

damage_view(view);
view->stack_layer = layer;
restack_view_for_layer(view, raise);
damage_view(view);
update(&view->base);
}

void
compositor_view_set_border_width(struct compositor_view *view, uint32_t width)
{
Expand Down
14 changes: 14 additions & 0 deletions libswc/compositor.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ struct compositor_view {

/* Whether or not the view is visible (mapped). */
bool visible;
bool always_top;
uint32_t stack_layer;

/* The box that the surface covers (including it's border). */
pixman_box32_t extents;
Expand Down Expand Up @@ -87,6 +89,18 @@ void compositor_view_set_parent(struct compositor_view *view, struct compositor_
void compositor_view_show(struct compositor_view *view);
void compositor_view_hide(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);

void compositor_view_set_border_color(struct compositor_view *view, uint32_t color);
void compositor_view_set_border_width(struct compositor_view *view, uint32_t width);

Expand Down
1 change: 1 addition & 0 deletions libswc/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct swc {
struct swc_drm *const drm;
struct wl_global *data_device_manager;
struct wl_global *kde_decoration_manager;
struct wl_global *layer_shell;
struct wl_global *panel_manager;
struct wl_global *shell;
struct wl_global *subcompositor;
Expand Down
Loading