2021-09-24 21:45:48 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2020-09-30 17:18:20 +01:00
|
|
|
/*
|
|
|
|
|
* layers.c - layer-shell implementation
|
|
|
|
|
*
|
2022-12-22 21:58:55 +00:00
|
|
|
* Based on https://github.com/swaywm/sway
|
2020-09-30 17:18:20 +01:00
|
|
|
* Copyright (C) 2019 Drew DeVault and Sway developers
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
2022-12-22 21:58:55 +00:00
|
|
|
#include <stdbool.h>
|
2020-09-30 17:18:20 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <wayland-server.h>
|
|
|
|
|
#include <wlr/types/wlr_layer_shell_v1.h>
|
2021-07-23 21:15:55 +01:00
|
|
|
#include <wlr/util/log.h>
|
2022-10-05 08:43:56 +02:00
|
|
|
#include "common/list.h"
|
2022-09-16 18:41:02 -04:00
|
|
|
#include "common/mem.h"
|
2020-09-30 17:18:20 +01:00
|
|
|
#include "layers.h"
|
|
|
|
|
#include "labwc.h"
|
2022-03-02 21:07:04 +00:00
|
|
|
#include "node.h"
|
2020-09-30 17:18:20 +01:00
|
|
|
|
2022-12-22 21:58:55 +00:00
|
|
|
static void
|
|
|
|
|
arrange_one_layer(struct output *output, const struct wlr_box *full_area,
|
|
|
|
|
struct wlr_box *usable_area, struct wlr_scene_tree *tree,
|
|
|
|
|
bool exclusive)
|
|
|
|
|
{
|
|
|
|
|
struct wlr_scene_node *node;
|
|
|
|
|
wl_list_for_each(node, &tree->children, link) {
|
|
|
|
|
struct lab_layer_surface *surface = node_layer_surface_from_node(node);
|
|
|
|
|
struct wlr_scene_layer_surface_v1 *scene = surface->scene_layer_surface;
|
|
|
|
|
if (!!scene->layer_surface->current.exclusive_zone != exclusive) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
wlr_scene_layer_surface_v1_configure(scene, full_area, usable_area);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-20 13:15:58 +00:00
|
|
|
void
|
2022-03-02 20:29:29 +00:00
|
|
|
layers_arrange(struct output *output)
|
2020-09-30 17:18:20 +01:00
|
|
|
{
|
2022-12-30 01:37:32 +01:00
|
|
|
assert(output);
|
2020-09-30 17:18:20 +01:00
|
|
|
struct wlr_box full_area = { 0 };
|
2022-02-20 13:15:58 +00:00
|
|
|
wlr_output_effective_resolution(output->wlr_output,
|
2022-02-26 21:15:52 +00:00
|
|
|
&full_area.width, &full_area.height);
|
2022-02-20 13:15:58 +00:00
|
|
|
struct wlr_box usable_area = full_area;
|
2022-07-01 00:55:15 +02:00
|
|
|
struct wlr_box old_usable_area = output->usable_area;
|
2022-02-20 13:15:58 +00:00
|
|
|
|
2022-03-02 20:21:57 +00:00
|
|
|
struct server *server = output->server;
|
|
|
|
|
struct wlr_scene_output *scene_output =
|
|
|
|
|
wlr_scene_get_scene_output(server->scene, output->wlr_output);
|
|
|
|
|
if (!scene_output) {
|
|
|
|
|
wlr_log(WLR_DEBUG, "no wlr_scene_output");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-28 17:01:22 +00:00
|
|
|
int nr_layers = sizeof(output->layer_tree) / sizeof(output->layer_tree[0]);
|
2022-03-02 20:39:46 +00:00
|
|
|
for (int i = 0; i < nr_layers; i++) {
|
2022-12-22 21:58:55 +00:00
|
|
|
struct wlr_scene_tree *layer = output->layer_tree[i];
|
2022-06-28 22:47:48 +03:00
|
|
|
|
|
|
|
|
/*
|
2022-12-22 21:58:55 +00:00
|
|
|
* Process exclusive-zone clients before non-exclusive-zone
|
|
|
|
|
* clients, so that the latter give way to the former regardless
|
|
|
|
|
* of the order in which they were launched.
|
2022-06-28 22:47:48 +03:00
|
|
|
*/
|
2022-12-22 21:58:55 +00:00
|
|
|
arrange_one_layer(output, &full_area, &usable_area, layer, true);
|
|
|
|
|
arrange_one_layer(output, &full_area, &usable_area, layer, false);
|
2022-06-28 22:47:48 +03:00
|
|
|
|
2022-12-22 21:58:55 +00:00
|
|
|
/* Set node position to account for output layout change */
|
|
|
|
|
wlr_scene_node_set_position(&layer->node, scene_output->x,
|
|
|
|
|
scene_output->y);
|
2022-02-20 13:15:58 +00:00
|
|
|
}
|
2020-09-30 17:18:20 +01:00
|
|
|
|
2023-01-01 18:26:25 +01:00
|
|
|
output->usable_area = usable_area;
|
2020-09-30 17:18:20 +01:00
|
|
|
|
|
|
|
|
/* Find topmost keyboard interactive layer, if such a layer exists */
|
2022-12-28 17:16:17 +00:00
|
|
|
uint32_t layers_above_views[] = {
|
2020-09-30 17:18:20 +01:00
|
|
|
ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY,
|
|
|
|
|
ZWLR_LAYER_SHELL_V1_LAYER_TOP,
|
|
|
|
|
};
|
2022-12-28 17:16:17 +00:00
|
|
|
size_t nlayers = sizeof(layers_above_views) / sizeof(layers_above_views[0]);
|
2022-12-28 17:01:22 +00:00
|
|
|
struct lab_layer_surface *topmost = NULL;
|
|
|
|
|
struct wlr_scene_node *node;
|
2020-09-30 17:18:20 +01:00
|
|
|
for (size_t i = 0; i < nlayers; ++i) {
|
2022-12-28 17:01:22 +00:00
|
|
|
struct wlr_scene_tree *tree = output->layer_tree[layers_above_views[i]];
|
|
|
|
|
/* Iterate in reverse to give most recent node preference */
|
|
|
|
|
wl_list_for_each_reverse(node, &tree->children, link) {
|
|
|
|
|
struct lab_layer_surface *surface = node_layer_surface_from_node(node);
|
|
|
|
|
struct wlr_scene_layer_surface_v1 *scene = surface->scene_layer_surface;
|
|
|
|
|
if (scene->layer_surface->current.keyboard_interactive) {
|
|
|
|
|
topmost = surface;
|
2020-09-30 17:18:20 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-28 20:49:26 +00:00
|
|
|
if (topmost) {
|
2020-09-30 17:18:20 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-31 15:09:13 +00:00
|
|
|
struct seat *seat = &output->server->seat;
|
2020-10-28 20:49:26 +00:00
|
|
|
if (topmost) {
|
2022-02-20 13:15:58 +00:00
|
|
|
seat_set_focus_layer(seat,
|
|
|
|
|
topmost->scene_layer_surface->layer_surface);
|
2020-10-31 15:09:13 +00:00
|
|
|
} else if (seat->focused_layer &&
|
|
|
|
|
!seat->focused_layer->current.keyboard_interactive) {
|
|
|
|
|
seat_set_focus_layer(seat, NULL);
|
2020-10-28 20:49:26 +00:00
|
|
|
}
|
2022-06-30 20:02:24 +02:00
|
|
|
|
|
|
|
|
/* Finally re-arrange all views based on usable_area */
|
2023-01-01 18:26:25 +01:00
|
|
|
if (!wlr_box_equal(&old_usable_area, &usable_area)) {
|
2022-07-01 00:55:15 +02:00
|
|
|
desktop_arrange_all_views(server);
|
|
|
|
|
}
|
2022-12-22 21:58:55 +00:00
|
|
|
cursor_update_focus(output->server);
|
2020-10-28 20:49:26 +00:00
|
|
|
}
|
|
|
|
|
|
2020-09-30 17:18:20 +01:00
|
|
|
static void
|
2022-12-28 18:22:27 +00:00
|
|
|
handle_output_destroy(struct wl_listener *listener, void *data)
|
2020-09-30 17:18:20 +01:00
|
|
|
{
|
|
|
|
|
struct lab_layer_surface *layer =
|
|
|
|
|
wl_container_of(listener, layer, output_destroy);
|
2022-04-24 22:24:47 +01:00
|
|
|
layer->scene_layer_surface->layer_surface->output = NULL;
|
2020-09-30 17:18:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2022-12-28 18:22:27 +00:00
|
|
|
handle_surface_commit(struct wl_listener *listener, void *data)
|
2020-09-30 17:18:20 +01:00
|
|
|
{
|
|
|
|
|
struct lab_layer_surface *layer =
|
|
|
|
|
wl_container_of(listener, layer, surface_commit);
|
2022-02-20 13:15:58 +00:00
|
|
|
struct wlr_layer_surface_v1 *layer_surface =
|
|
|
|
|
layer->scene_layer_surface->layer_surface;
|
|
|
|
|
struct wlr_output *wlr_output =
|
|
|
|
|
layer->scene_layer_surface->layer_surface->output;
|
2021-10-15 19:14:07 +01:00
|
|
|
|
|
|
|
|
if (!wlr_output) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-22 21:58:55 +00:00
|
|
|
uint32_t committed = layer_surface->current.committed;
|
|
|
|
|
struct output *output = (struct output *)wlr_output->data;
|
|
|
|
|
|
|
|
|
|
/* Process layer change */
|
|
|
|
|
if (committed & WLR_LAYER_SURFACE_V1_STATE_LAYER) {
|
|
|
|
|
wlr_scene_node_reparent(&layer->scene_layer_surface->tree->node,
|
|
|
|
|
output->layer_tree[layer_surface->current.layer]);
|
2021-10-15 19:14:07 +01:00
|
|
|
}
|
2020-09-30 17:18:20 +01:00
|
|
|
|
2022-12-22 21:58:55 +00:00
|
|
|
if (committed || layer->mapped != layer_surface->mapped) {
|
|
|
|
|
layer->mapped = layer_surface->mapped;
|
|
|
|
|
layers_arrange(output);
|
2020-10-31 15:09:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-30 17:18:20 +01:00
|
|
|
static void
|
2022-12-28 18:22:27 +00:00
|
|
|
handle_node_destroy(struct wl_listener *listener, void *data)
|
2020-09-30 17:18:20 +01:00
|
|
|
{
|
2022-12-22 21:58:55 +00:00
|
|
|
struct lab_layer_surface *layer =
|
|
|
|
|
wl_container_of(listener, layer, node_destroy);
|
2022-02-20 13:15:58 +00:00
|
|
|
|
2020-09-30 17:18:20 +01:00
|
|
|
wl_list_remove(&layer->map.link);
|
2022-02-26 21:15:52 +00:00
|
|
|
wl_list_remove(&layer->unmap.link);
|
2020-09-30 17:18:20 +01:00
|
|
|
wl_list_remove(&layer->surface_commit.link);
|
2022-12-30 01:14:46 +01:00
|
|
|
wl_list_remove(&layer->new_popup.link);
|
2022-12-22 21:58:55 +00:00
|
|
|
wl_list_remove(&layer->output_destroy.link);
|
|
|
|
|
wl_list_remove(&layer->node_destroy.link);
|
2020-09-30 17:18:20 +01:00
|
|
|
free(layer);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-31 15:09:13 +00:00
|
|
|
static void
|
2022-12-28 18:22:27 +00:00
|
|
|
handle_unmap(struct wl_listener *listener, void *data)
|
2020-10-31 15:09:13 +00:00
|
|
|
{
|
2022-12-22 21:58:55 +00:00
|
|
|
struct lab_layer_surface *layer = wl_container_of(listener, layer, unmap);
|
2022-12-30 01:37:32 +01:00
|
|
|
struct wlr_layer_surface_v1 *layer_surface =
|
|
|
|
|
layer->scene_layer_surface->layer_surface;
|
|
|
|
|
if (layer_surface->output) {
|
|
|
|
|
layers_arrange(layer_surface->output->data);
|
|
|
|
|
}
|
2022-12-22 21:58:55 +00:00
|
|
|
struct seat *seat = &layer->server->seat;
|
2022-12-30 01:37:32 +01:00
|
|
|
if (seat->focused_layer == layer_surface) {
|
2022-12-22 21:58:55 +00:00
|
|
|
seat_set_focus_layer(seat, NULL);
|
|
|
|
|
}
|
2020-10-31 15:09:13 +00:00
|
|
|
}
|
|
|
|
|
|
2020-09-30 17:18:20 +01:00
|
|
|
static void
|
2022-12-28 18:22:27 +00:00
|
|
|
handle_map(struct wl_listener *listener, void *data)
|
2020-09-30 17:18:20 +01:00
|
|
|
{
|
2022-12-22 21:58:55 +00:00
|
|
|
struct lab_layer_surface *layer = wl_container_of(listener, layer, map);
|
|
|
|
|
layers_arrange(layer->scene_layer_surface->layer_surface->output->data);
|
|
|
|
|
/*
|
|
|
|
|
* Since moving to the wlroots scene-graph API, there is no need to
|
|
|
|
|
* call wlr_surface_send_enter() from here since that will be done
|
|
|
|
|
* automatically based on the position of the surface and outputs in
|
|
|
|
|
* the scene. See wlr_scene_surface_create() documentation.
|
|
|
|
|
*/
|
2022-02-26 21:15:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
popup_handle_destroy(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct lab_layer_popup *popup =
|
|
|
|
|
wl_container_of(listener, popup, destroy);
|
|
|
|
|
wl_list_remove(&popup->destroy.link);
|
|
|
|
|
wl_list_remove(&popup->new_popup.link);
|
|
|
|
|
free(popup);
|
2020-09-30 17:18:20 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-26 21:15:52 +00:00
|
|
|
static void popup_handle_new_popup(struct wl_listener *listener, void *data);
|
|
|
|
|
|
|
|
|
|
static struct lab_layer_popup *
|
2022-06-05 15:17:35 +02:00
|
|
|
create_popup(struct wlr_xdg_popup *wlr_popup, struct wlr_scene_tree *parent,
|
2022-03-06 16:48:39 +00:00
|
|
|
struct wlr_box *output_toplevel_sx_box)
|
2022-02-26 21:15:52 +00:00
|
|
|
{
|
2022-09-18 15:22:26 -04:00
|
|
|
struct lab_layer_popup *popup = znew(*popup);
|
2022-02-26 21:15:52 +00:00
|
|
|
popup->wlr_popup = wlr_popup;
|
2022-06-05 15:17:35 +02:00
|
|
|
popup->scene_tree =
|
2022-02-26 21:15:52 +00:00
|
|
|
wlr_scene_xdg_surface_create(parent, wlr_popup->base);
|
2022-06-05 15:17:35 +02:00
|
|
|
if (!popup->scene_tree) {
|
2022-02-26 21:15:52 +00:00
|
|
|
free(popup);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2022-06-05 15:17:35 +02:00
|
|
|
node_descriptor_create(&popup->scene_tree->node,
|
2022-02-26 21:15:52 +00:00
|
|
|
LAB_NODE_DESC_LAYER_POPUP, popup);
|
|
|
|
|
|
|
|
|
|
popup->destroy.notify = popup_handle_destroy;
|
|
|
|
|
wl_signal_add(&wlr_popup->base->events.destroy, &popup->destroy);
|
|
|
|
|
popup->new_popup.notify = popup_handle_new_popup;
|
|
|
|
|
wl_signal_add(&wlr_popup->base->events.new_popup, &popup->new_popup);
|
|
|
|
|
|
2022-03-06 16:48:39 +00:00
|
|
|
wlr_xdg_popup_unconstrain_from_box(wlr_popup, output_toplevel_sx_box);
|
2022-02-26 21:15:52 +00:00
|
|
|
return popup;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-06 16:48:39 +00:00
|
|
|
/* This popup's parent is a layer popup */
|
2022-02-26 21:15:52 +00:00
|
|
|
static void
|
|
|
|
|
popup_handle_new_popup(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct lab_layer_popup *lab_layer_popup =
|
|
|
|
|
wl_container_of(listener, lab_layer_popup, new_popup);
|
|
|
|
|
struct wlr_xdg_popup *wlr_popup = data;
|
2022-03-06 16:48:39 +00:00
|
|
|
struct lab_layer_popup *new_popup = create_popup(wlr_popup,
|
2022-06-05 15:17:35 +02:00
|
|
|
lab_layer_popup->scene_tree,
|
2022-03-06 16:48:39 +00:00
|
|
|
&lab_layer_popup->output_toplevel_sx_box);
|
|
|
|
|
new_popup->output_toplevel_sx_box =
|
|
|
|
|
lab_layer_popup->output_toplevel_sx_box;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We move popups from the bottom to the top layer so that they are
|
|
|
|
|
* rendered above views.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
move_popup_to_top_layer(struct lab_layer_surface *toplevel,
|
|
|
|
|
struct lab_layer_popup *popup)
|
|
|
|
|
{
|
|
|
|
|
struct server *server = toplevel->server;
|
|
|
|
|
struct wlr_output *wlr_output =
|
|
|
|
|
toplevel->scene_layer_surface->layer_surface->output;
|
2022-12-28 17:40:34 +00:00
|
|
|
struct output *output = (struct output *)wlr_output->data;
|
2022-03-06 16:48:39 +00:00
|
|
|
struct wlr_box box = { 0 };
|
|
|
|
|
wlr_output_layout_get_box(server->output_layout, wlr_output, &box);
|
2022-06-05 15:55:18 +02:00
|
|
|
int lx = toplevel->scene_layer_surface->tree->node.x + box.x;
|
|
|
|
|
int ly = toplevel->scene_layer_surface->tree->node.y + box.y;
|
2022-03-06 16:48:39 +00:00
|
|
|
|
2022-06-05 15:17:35 +02:00
|
|
|
struct wlr_scene_node *node = &popup->scene_tree->node;
|
|
|
|
|
wlr_scene_node_reparent(node, output->layer_popup_tree);
|
|
|
|
|
/* FIXME: verify the whole tree should be repositioned */
|
2022-03-06 16:48:39 +00:00
|
|
|
wlr_scene_node_set_position(&output->layer_popup_tree->node, lx, ly);
|
2022-02-26 21:15:52 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-06 16:48:39 +00:00
|
|
|
/* This popup's parent is a shell-layer surface */
|
2022-02-26 21:15:52 +00:00
|
|
|
static void
|
2022-12-28 18:22:27 +00:00
|
|
|
handle_new_popup(struct wl_listener *listener, void *data)
|
2022-02-26 21:15:52 +00:00
|
|
|
{
|
2022-03-06 16:48:39 +00:00
|
|
|
struct lab_layer_surface *toplevel =
|
|
|
|
|
wl_container_of(listener, toplevel, new_popup);
|
2022-02-26 21:15:52 +00:00
|
|
|
struct wlr_xdg_popup *wlr_popup = data;
|
2022-06-17 02:41:34 +02:00
|
|
|
|
|
|
|
|
int lx, ly;
|
|
|
|
|
struct server *server = toplevel->server;
|
|
|
|
|
struct wlr_scene_layer_surface_v1 *surface = toplevel->scene_layer_surface;
|
|
|
|
|
wlr_scene_node_coords(&surface->tree->node, &lx, &ly);
|
|
|
|
|
|
|
|
|
|
if (!surface->layer_surface->output) {
|
|
|
|
|
/* Work-around for moving layer shell surfaces on output destruction */
|
|
|
|
|
struct wlr_output *wlr_output;
|
|
|
|
|
wlr_output = wlr_output_layout_output_at(server->output_layout, lx, ly);
|
|
|
|
|
surface->layer_surface->output = wlr_output;
|
|
|
|
|
}
|
|
|
|
|
struct output *output = surface->layer_surface->output->data;
|
2022-03-03 17:56:38 +00:00
|
|
|
|
2022-03-06 16:48:39 +00:00
|
|
|
struct wlr_box output_box = { 0 };
|
2022-06-17 02:41:34 +02:00
|
|
|
wlr_output_layout_get_box(server->output_layout,
|
2022-03-06 16:48:39 +00:00
|
|
|
output->wlr_output, &output_box);
|
2022-03-03 17:56:38 +00:00
|
|
|
|
2022-03-06 16:48:39 +00:00
|
|
|
/*
|
|
|
|
|
* Output geometry expressed in the coordinate system of the toplevel
|
|
|
|
|
* parent of popup. We store this struct the lab_layer_popup struct
|
|
|
|
|
* to make it easier to unconstrain children when we move popups from
|
|
|
|
|
* the bottom to the top layer.
|
|
|
|
|
*/
|
|
|
|
|
struct wlr_box output_toplevel_sx_box = {
|
|
|
|
|
.x = output_box.x - lx,
|
|
|
|
|
.y = output_box.y - ly,
|
|
|
|
|
.width = output_box.width,
|
|
|
|
|
.height = output_box.height,
|
|
|
|
|
};
|
|
|
|
|
struct lab_layer_popup *popup = create_popup(wlr_popup,
|
2022-06-17 02:41:34 +02:00
|
|
|
surface->tree, &output_toplevel_sx_box);
|
2022-03-06 16:48:39 +00:00
|
|
|
popup->output_toplevel_sx_box = output_toplevel_sx_box;
|
|
|
|
|
|
2022-06-17 02:41:34 +02:00
|
|
|
if (surface->layer_surface->current.layer
|
2022-03-06 16:48:39 +00:00
|
|
|
== ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM) {
|
|
|
|
|
move_popup_to_top_layer(toplevel, popup);
|
|
|
|
|
}
|
2022-02-26 21:15:52 +00:00
|
|
|
}
|
2021-10-20 22:32:46 +01:00
|
|
|
|
2020-10-28 20:49:26 +00:00
|
|
|
static void
|
2022-12-28 18:22:27 +00:00
|
|
|
handle_new_layer_surface(struct wl_listener *listener, void *data)
|
2020-09-30 17:18:20 +01:00
|
|
|
{
|
|
|
|
|
struct server *server = wl_container_of(
|
|
|
|
|
listener, server, new_layer_surface);
|
|
|
|
|
struct wlr_layer_surface_v1 *layer_surface = data;
|
2020-10-28 20:49:26 +00:00
|
|
|
|
2020-09-30 17:18:20 +01:00
|
|
|
if (!layer_surface->output) {
|
|
|
|
|
struct wlr_output *output = wlr_output_layout_output_at(
|
2020-10-02 21:19:56 +01:00
|
|
|
server->output_layout, server->seat.cursor->x,
|
|
|
|
|
server->seat.cursor->y);
|
2022-12-26 23:11:01 +01:00
|
|
|
if (!output) {
|
|
|
|
|
wlr_log(WLR_INFO,
|
|
|
|
|
"No output available to assign layer surface");
|
|
|
|
|
wlr_layer_surface_v1_destroy(layer_surface);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-30 17:18:20 +01:00
|
|
|
layer_surface->output = output;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 15:22:26 -04:00
|
|
|
struct lab_layer_surface *surface = znew(*surface);
|
2020-09-30 17:18:20 +01:00
|
|
|
|
2022-02-20 13:15:58 +00:00
|
|
|
struct output *output = layer_surface->output->data;
|
2021-10-20 22:32:46 +01:00
|
|
|
|
2022-02-20 13:15:58 +00:00
|
|
|
struct wlr_scene_tree *selected_layer =
|
|
|
|
|
output->layer_tree[layer_surface->current.layer];
|
|
|
|
|
|
|
|
|
|
surface->scene_layer_surface = wlr_scene_layer_surface_v1_create(
|
2022-06-05 15:17:35 +02:00
|
|
|
selected_layer, layer_surface);
|
2022-04-24 22:24:47 +01:00
|
|
|
if (!surface->scene_layer_surface) {
|
|
|
|
|
wlr_layer_surface_v1_destroy(layer_surface);
|
|
|
|
|
wlr_log(WLR_ERROR, "could not create layer surface");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-05 15:17:35 +02:00
|
|
|
node_descriptor_create(&surface->scene_layer_surface->tree->node,
|
2022-02-26 21:15:52 +00:00
|
|
|
LAB_NODE_DESC_LAYER_SURFACE, surface);
|
2021-10-20 22:32:46 +01:00
|
|
|
|
|
|
|
|
surface->server = server;
|
2022-02-20 13:15:58 +00:00
|
|
|
surface->scene_layer_surface->layer_surface = layer_surface;
|
|
|
|
|
|
2022-12-28 18:22:27 +00:00
|
|
|
surface->surface_commit.notify = handle_surface_commit;
|
2022-12-22 21:58:55 +00:00
|
|
|
wl_signal_add(&layer_surface->surface->events.commit,
|
|
|
|
|
&surface->surface_commit);
|
|
|
|
|
|
2022-12-28 18:22:27 +00:00
|
|
|
surface->map.notify = handle_map;
|
2022-12-22 21:58:55 +00:00
|
|
|
wl_signal_add(&layer_surface->events.map, &surface->map);
|
|
|
|
|
|
2022-12-28 18:22:27 +00:00
|
|
|
surface->unmap.notify = handle_unmap;
|
2022-12-22 21:58:55 +00:00
|
|
|
wl_signal_add(&layer_surface->events.unmap, &surface->unmap);
|
|
|
|
|
|
2022-12-28 18:22:27 +00:00
|
|
|
surface->new_popup.notify = handle_new_popup;
|
2022-12-22 21:58:55 +00:00
|
|
|
wl_signal_add(&layer_surface->events.new_popup, &surface->new_popup);
|
|
|
|
|
|
2022-12-28 18:22:27 +00:00
|
|
|
surface->output_destroy.notify = handle_output_destroy;
|
2021-10-20 22:32:46 +01:00
|
|
|
wl_signal_add(&layer_surface->output->events.destroy,
|
|
|
|
|
&surface->output_destroy);
|
|
|
|
|
|
2022-12-28 18:22:27 +00:00
|
|
|
surface->node_destroy.notify = handle_node_destroy;
|
2022-12-22 21:58:55 +00:00
|
|
|
wl_signal_add(&surface->scene_layer_surface->tree->node.events.destroy,
|
|
|
|
|
&surface->node_destroy);
|
|
|
|
|
|
2020-09-30 17:18:20 +01:00
|
|
|
/*
|
2021-09-24 20:51:12 +01:00
|
|
|
* Temporarily set the layer's current state to pending so that
|
2020-09-30 17:18:20 +01:00
|
|
|
* it can easily be arranged.
|
|
|
|
|
*/
|
|
|
|
|
struct wlr_layer_surface_v1_state old_state = layer_surface->current;
|
2021-09-24 20:51:12 +01:00
|
|
|
layer_surface->current = layer_surface->pending;
|
2022-03-02 20:29:29 +00:00
|
|
|
layers_arrange(output);
|
2020-09-30 17:18:20 +01:00
|
|
|
layer_surface->current = old_state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
layers_init(struct server *server)
|
|
|
|
|
{
|
|
|
|
|
server->layer_shell = wlr_layer_shell_v1_create(server->wl_display);
|
2022-12-28 18:22:27 +00:00
|
|
|
server->new_layer_surface.notify = handle_new_layer_surface;
|
2020-09-30 17:18:20 +01:00
|
|
|
wl_signal_add(&server->layer_shell->events.new_surface,
|
|
|
|
|
&server->new_layer_surface);
|
|
|
|
|
}
|