2018-03-18 00:03:52 +01:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
2018-03-17 20:07:48 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
2018-03-18 00:03:52 +01:00
|
|
|
#include <string.h>
|
2019-07-27 10:53:54 +02:00
|
|
|
#include <wayland-server-core.h>
|
2022-01-13 09:55:09 +01:00
|
|
|
#include <wlr/types/wlr_compositor.h>
|
2018-09-14 19:32:33 +02:00
|
|
|
#include <wlr/types/wlr_layer_shell_v1.h>
|
2018-03-20 04:11:37 +01:00
|
|
|
#include <wlr/types/wlr_output.h>
|
2018-04-14 21:47:51 +02:00
|
|
|
#include <wlr/types/wlr_xdg_shell.h>
|
2018-03-18 00:03:52 +01:00
|
|
|
#include <wlr/util/log.h>
|
2018-03-17 20:07:48 +01:00
|
|
|
#include "wlr-layer-shell-unstable-v1-protocol.h"
|
|
|
|
|
2022-11-03 18:44:21 +01:00
|
|
|
// Note: zwlr_layer_surface_v1 becomes inert on wlr_layer_surface_v1_destroy()
|
|
|
|
|
2020-11-26 13:18:22 +01:00
|
|
|
#define LAYER_SHELL_VERSION 4
|
2021-01-07 12:04:32 +01:00
|
|
|
|
2018-03-18 00:03:52 +01:00
|
|
|
static void resource_handle_destroy(struct wl_client *client,
|
|
|
|
struct wl_resource *resource) {
|
|
|
|
wl_resource_destroy(resource);
|
2018-03-17 20:07:48 +01:00
|
|
|
}
|
|
|
|
|
2018-03-20 01:24:16 +01:00
|
|
|
static const struct zwlr_layer_shell_v1_interface layer_shell_implementation;
|
|
|
|
static const struct zwlr_layer_surface_v1_interface layer_surface_implementation;
|
2018-03-17 20:07:48 +01:00
|
|
|
|
2023-07-06 20:46:11 +02:00
|
|
|
static void layer_surface_destroy(struct wlr_layer_surface_v1 *surface) {
|
2023-07-26 22:07:28 +02:00
|
|
|
wlr_surface_unmap(surface->surface);
|
|
|
|
|
2023-07-06 20:46:11 +02:00
|
|
|
wl_signal_emit_mutable(&surface->events.destroy, surface);
|
|
|
|
wl_resource_set_user_data(surface->resource, NULL);
|
|
|
|
free(surface->namespace);
|
|
|
|
free(surface);
|
|
|
|
}
|
|
|
|
|
2018-09-14 19:32:33 +02:00
|
|
|
static struct wlr_layer_shell_v1 *layer_shell_from_resource(
|
2018-03-17 20:07:48 +01:00
|
|
|
struct wl_resource *resource) {
|
|
|
|
assert(wl_resource_instance_of(resource, &zwlr_layer_shell_v1_interface,
|
2018-03-20 01:24:16 +01:00
|
|
|
&layer_shell_implementation));
|
2018-03-17 20:07:48 +01:00
|
|
|
return wl_resource_get_user_data(resource);
|
|
|
|
}
|
|
|
|
|
2022-03-08 12:26:59 +01:00
|
|
|
struct wlr_layer_surface_v1 *wlr_layer_surface_v1_from_resource(
|
2018-03-18 00:03:52 +01:00
|
|
|
struct wl_resource *resource) {
|
|
|
|
assert(wl_resource_instance_of(resource, &zwlr_layer_surface_v1_interface,
|
2018-03-20 01:24:16 +01:00
|
|
|
&layer_surface_implementation));
|
2018-03-18 00:03:52 +01:00
|
|
|
return wl_resource_get_user_data(resource);
|
|
|
|
}
|
|
|
|
|
2018-07-07 23:45:16 +02:00
|
|
|
static const struct wlr_surface_role layer_surface_role;
|
|
|
|
|
2023-02-01 20:13:53 +01:00
|
|
|
struct wlr_layer_surface_v1 *wlr_layer_surface_v1_try_from_wlr_surface(
|
2018-04-03 02:39:33 +02:00
|
|
|
struct wlr_surface *surface) {
|
2023-06-23 14:23:27 +02:00
|
|
|
if (surface->role != &layer_surface_role || surface->role_resource == NULL) {
|
2023-02-01 20:13:53 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2023-06-23 14:23:27 +02:00
|
|
|
return wlr_layer_surface_v1_from_resource(surface->role_resource);
|
2018-04-03 02:39:33 +02:00
|
|
|
}
|
|
|
|
|
2018-03-18 00:11:14 +01:00
|
|
|
static void layer_surface_configure_destroy(
|
2018-09-14 19:32:33 +02:00
|
|
|
struct wlr_layer_surface_v1_configure *configure) {
|
2018-03-18 00:11:14 +01:00
|
|
|
if (configure == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wl_list_remove(&configure->link);
|
|
|
|
free(configure);
|
|
|
|
}
|
|
|
|
|
2018-03-18 00:03:52 +01:00
|
|
|
static void layer_surface_handle_ack_configure(struct wl_client *client,
|
|
|
|
struct wl_resource *resource, uint32_t serial) {
|
2022-03-08 12:26:59 +01:00
|
|
|
struct wlr_layer_surface_v1 *surface =
|
|
|
|
wlr_layer_surface_v1_from_resource(resource);
|
2018-03-18 00:11:14 +01:00
|
|
|
|
2021-08-12 21:30:58 +02:00
|
|
|
if (!surface) {
|
2019-07-16 14:44:50 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-06-24 15:18:00 +02:00
|
|
|
|
|
|
|
// First find the ack'ed configure
|
|
|
|
bool found = false;
|
|
|
|
struct wlr_layer_surface_v1_configure *configure, *tmp;
|
|
|
|
wl_list_for_each(configure, &surface->configure_list, link) {
|
|
|
|
if (configure->serial == serial) {
|
2018-03-18 00:11:14 +01:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
2018-03-27 23:18:16 +02:00
|
|
|
wl_resource_post_error(resource,
|
2018-03-18 00:11:14 +01:00
|
|
|
ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_SURFACE_STATE,
|
2020-06-04 14:33:32 +02:00
|
|
|
"wrong configure serial: %" PRIu32, serial);
|
2018-03-18 00:11:14 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-06-24 15:18:00 +02:00
|
|
|
// Then remove old configures from the list
|
|
|
|
wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) {
|
|
|
|
if (configure->serial == serial) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
layer_surface_configure_destroy(configure);
|
|
|
|
}
|
2018-03-18 00:11:14 +01:00
|
|
|
|
2021-09-18 10:32:23 +02:00
|
|
|
surface->pending.configure_serial = configure->serial;
|
|
|
|
surface->pending.actual_width = configure->width;
|
|
|
|
surface->pending.actual_height = configure->height;
|
|
|
|
|
|
|
|
surface->configured = true;
|
|
|
|
|
|
|
|
layer_surface_configure_destroy(configure);
|
2018-03-18 00:03:52 +01:00
|
|
|
}
|
|
|
|
|
2018-03-20 04:11:37 +01:00
|
|
|
static void layer_surface_handle_set_size(struct wl_client *client,
|
2018-03-27 00:12:31 +02:00
|
|
|
struct wl_resource *resource, uint32_t width, uint32_t height) {
|
2022-03-08 12:26:59 +01:00
|
|
|
struct wlr_layer_surface_v1 *surface =
|
|
|
|
wlr_layer_surface_v1_from_resource(resource);
|
2019-07-16 14:44:50 +02:00
|
|
|
|
|
|
|
if (!surface) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-14 18:09:31 +01:00
|
|
|
|
|
|
|
if (surface->current.desired_width == width
|
|
|
|
&& surface->current.desired_height == height) {
|
|
|
|
surface->pending.committed &= ~WLR_LAYER_SURFACE_V1_STATE_DESIRED_SIZE;
|
|
|
|
} else {
|
|
|
|
surface->pending.committed |= WLR_LAYER_SURFACE_V1_STATE_DESIRED_SIZE;
|
|
|
|
}
|
|
|
|
|
2021-09-18 10:32:23 +02:00
|
|
|
surface->pending.desired_width = width;
|
|
|
|
surface->pending.desired_height = height;
|
2018-03-20 04:11:37 +01:00
|
|
|
}
|
|
|
|
|
2018-03-18 00:03:52 +01:00
|
|
|
static void layer_surface_handle_set_anchor(struct wl_client *client,
|
|
|
|
struct wl_resource *resource, uint32_t anchor) {
|
2018-03-20 04:11:37 +01:00
|
|
|
const uint32_t max_anchor =
|
|
|
|
ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
|
|
|
|
ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM |
|
|
|
|
ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
|
|
|
|
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
|
|
|
|
if (anchor > max_anchor) {
|
|
|
|
wl_resource_post_error(resource,
|
|
|
|
ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_ANCHOR,
|
2020-06-04 14:33:32 +02:00
|
|
|
"invalid anchor %" PRIu32, anchor);
|
2018-03-20 04:11:37 +01:00
|
|
|
}
|
2022-03-08 12:26:59 +01:00
|
|
|
struct wlr_layer_surface_v1 *surface =
|
|
|
|
wlr_layer_surface_v1_from_resource(resource);
|
2019-07-16 14:44:50 +02:00
|
|
|
|
|
|
|
if (!surface) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-14 18:09:31 +01:00
|
|
|
|
|
|
|
if (surface->current.anchor == anchor) {
|
|
|
|
surface->pending.committed &= ~WLR_LAYER_SURFACE_V1_STATE_ANCHOR;
|
|
|
|
} else {
|
|
|
|
surface->pending.committed |= WLR_LAYER_SURFACE_V1_STATE_ANCHOR;
|
|
|
|
}
|
|
|
|
|
2021-09-18 10:32:23 +02:00
|
|
|
surface->pending.anchor = anchor;
|
2018-03-18 00:03:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void layer_surface_handle_set_exclusive_zone(struct wl_client *client,
|
2018-03-27 00:12:31 +02:00
|
|
|
struct wl_resource *resource, int32_t zone) {
|
2022-03-08 12:26:59 +01:00
|
|
|
struct wlr_layer_surface_v1 *surface = wlr_layer_surface_v1_from_resource(resource);
|
2019-07-16 14:44:50 +02:00
|
|
|
|
|
|
|
if (!surface) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-14 18:09:31 +01:00
|
|
|
|
|
|
|
if (surface->current.exclusive_zone == zone) {
|
|
|
|
surface->pending.committed &= ~WLR_LAYER_SURFACE_V1_STATE_EXCLUSIVE_ZONE;
|
|
|
|
} else {
|
|
|
|
surface->pending.committed |= WLR_LAYER_SURFACE_V1_STATE_EXCLUSIVE_ZONE;
|
|
|
|
}
|
|
|
|
|
2021-09-18 10:32:23 +02:00
|
|
|
surface->pending.exclusive_zone = zone;
|
2018-03-18 00:03:52 +01:00
|
|
|
}
|
|
|
|
|
2018-03-18 18:58:01 +01:00
|
|
|
static void layer_surface_handle_set_margin(
|
|
|
|
struct wl_client *client, struct wl_resource *resource,
|
|
|
|
int32_t top, int32_t right, int32_t bottom, int32_t left) {
|
2022-03-08 12:26:59 +01:00
|
|
|
struct wlr_layer_surface_v1 *surface =
|
|
|
|
wlr_layer_surface_v1_from_resource(resource);
|
2019-07-16 14:44:50 +02:00
|
|
|
|
|
|
|
if (!surface) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-14 18:09:31 +01:00
|
|
|
|
2021-12-15 16:30:32 +01:00
|
|
|
if (surface->current.margin.top == top
|
|
|
|
&& surface->current.margin.right == right
|
|
|
|
&& surface->current.margin.bottom == bottom
|
|
|
|
&& surface->current.margin.left == left) {
|
2021-12-14 18:09:31 +01:00
|
|
|
surface->pending.committed &= ~WLR_LAYER_SURFACE_V1_STATE_MARGIN;
|
|
|
|
} else {
|
|
|
|
surface->pending.committed |= WLR_LAYER_SURFACE_V1_STATE_MARGIN;
|
|
|
|
}
|
|
|
|
|
2021-09-18 10:32:23 +02:00
|
|
|
surface->pending.margin.top = top;
|
|
|
|
surface->pending.margin.right = right;
|
|
|
|
surface->pending.margin.bottom = bottom;
|
|
|
|
surface->pending.margin.left = left;
|
2018-03-18 00:03:52 +01:00
|
|
|
}
|
|
|
|
|
2018-03-18 18:58:01 +01:00
|
|
|
static void layer_surface_handle_set_keyboard_interactivity(
|
|
|
|
struct wl_client *client, struct wl_resource *resource,
|
|
|
|
uint32_t interactive) {
|
2022-03-08 12:26:59 +01:00
|
|
|
struct wlr_layer_surface_v1 *surface = wlr_layer_surface_v1_from_resource(resource);
|
2019-07-16 14:44:50 +02:00
|
|
|
|
|
|
|
if (!surface) {
|
|
|
|
return;
|
|
|
|
}
|
2020-11-26 13:18:22 +01:00
|
|
|
|
2021-09-24 06:58:59 +02:00
|
|
|
surface->pending.committed |= WLR_LAYER_SURFACE_V1_STATE_KEYBOARD_INTERACTIVITY;
|
2020-11-26 13:18:22 +01:00
|
|
|
if (wl_resource_get_version(resource) < ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND_SINCE_VERSION) {
|
2021-09-18 10:32:23 +02:00
|
|
|
surface->pending.keyboard_interactive = !!interactive;
|
2020-11-26 13:18:22 +01:00
|
|
|
} else {
|
|
|
|
if (interactive > ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND) {
|
|
|
|
wl_resource_post_error(resource,
|
|
|
|
ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_KEYBOARD_INTERACTIVITY,
|
|
|
|
"wrong keyboard interactivity value: %" PRIu32, interactive);
|
|
|
|
} else {
|
2021-09-18 10:32:23 +02:00
|
|
|
surface->pending.keyboard_interactive = interactive;
|
2020-11-26 13:18:22 +01:00
|
|
|
}
|
|
|
|
}
|
2018-03-18 00:03:52 +01:00
|
|
|
}
|
|
|
|
|
2018-03-18 18:58:01 +01:00
|
|
|
static void layer_surface_handle_get_popup(struct wl_client *client,
|
2018-04-14 21:47:51 +02:00
|
|
|
struct wl_resource *layer_resource,
|
|
|
|
struct wl_resource *popup_resource) {
|
2018-09-14 19:32:33 +02:00
|
|
|
struct wlr_layer_surface_v1 *parent =
|
2022-03-08 12:26:59 +01:00
|
|
|
wlr_layer_surface_v1_from_resource(layer_resource);
|
2022-01-08 20:52:52 +01:00
|
|
|
struct wlr_xdg_popup *popup =
|
|
|
|
wlr_xdg_popup_from_resource(popup_resource);
|
2018-04-14 21:47:51 +02:00
|
|
|
|
2019-07-16 14:44:50 +02:00
|
|
|
if (!parent) {
|
|
|
|
return;
|
|
|
|
}
|
2023-02-03 17:25:07 +01:00
|
|
|
if (popup->parent != NULL) {
|
|
|
|
wl_resource_post_error(layer_resource, -1, "xdg_popup already has a parent");
|
|
|
|
return;
|
|
|
|
}
|
2018-04-14 21:47:51 +02:00
|
|
|
popup->parent = parent->surface;
|
|
|
|
wl_list_insert(&parent->popups, &popup->link);
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&parent->events.new_popup, popup);
|
2018-03-18 00:03:52 +01:00
|
|
|
}
|
|
|
|
|
2019-10-03 22:06:46 +02:00
|
|
|
static void layer_surface_set_layer(struct wl_client *client,
|
|
|
|
struct wl_resource *surface_resource, uint32_t layer) {
|
|
|
|
struct wlr_layer_surface_v1 *surface =
|
2022-03-08 12:26:59 +01:00
|
|
|
wlr_layer_surface_v1_from_resource(surface_resource);
|
2019-10-03 22:06:46 +02:00
|
|
|
if (!surface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (layer > ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY) {
|
|
|
|
wl_resource_post_error(surface->resource,
|
|
|
|
ZWLR_LAYER_SHELL_V1_ERROR_INVALID_LAYER,
|
2020-06-04 14:33:32 +02:00
|
|
|
"Invalid layer %" PRIu32, layer);
|
2019-10-03 22:06:46 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-12-14 18:09:31 +01:00
|
|
|
|
|
|
|
if (surface->current.layer == layer) {
|
|
|
|
surface->pending.committed &= ~WLR_LAYER_SURFACE_V1_STATE_LAYER;
|
|
|
|
} else {
|
|
|
|
surface->pending.committed |= WLR_LAYER_SURFACE_V1_STATE_LAYER;
|
|
|
|
}
|
|
|
|
|
2021-09-18 10:32:23 +02:00
|
|
|
surface->pending.layer = layer;
|
2019-10-03 22:06:46 +02:00
|
|
|
}
|
|
|
|
|
2018-03-18 00:03:52 +01:00
|
|
|
static const struct zwlr_layer_surface_v1_interface layer_surface_implementation = {
|
|
|
|
.destroy = resource_handle_destroy,
|
|
|
|
.ack_configure = layer_surface_handle_ack_configure,
|
2018-03-20 04:11:37 +01:00
|
|
|
.set_size = layer_surface_handle_set_size,
|
2018-03-18 00:03:52 +01:00
|
|
|
.set_anchor = layer_surface_handle_set_anchor,
|
|
|
|
.set_exclusive_zone = layer_surface_handle_set_exclusive_zone,
|
|
|
|
.set_margin = layer_surface_handle_set_margin,
|
2018-03-18 18:58:01 +01:00
|
|
|
.set_keyboard_interactivity = layer_surface_handle_set_keyboard_interactivity,
|
2018-03-18 00:03:52 +01:00
|
|
|
.get_popup = layer_surface_handle_get_popup,
|
2019-10-03 22:06:46 +02:00
|
|
|
.set_layer = layer_surface_set_layer,
|
2018-03-18 00:03:52 +01:00
|
|
|
};
|
|
|
|
|
2021-09-18 10:32:23 +02:00
|
|
|
uint32_t wlr_layer_surface_v1_configure(struct wlr_layer_surface_v1 *surface,
|
2018-03-18 02:06:54 +01:00
|
|
|
uint32_t width, uint32_t height) {
|
2021-09-18 10:32:23 +02:00
|
|
|
struct wl_display *display =
|
|
|
|
wl_client_get_display(wl_resource_get_client(surface->resource));
|
2023-10-03 07:51:07 +02:00
|
|
|
struct wlr_layer_surface_v1_configure *configure = calloc(1, sizeof(*configure));
|
2021-09-18 10:32:23 +02:00
|
|
|
if (configure == NULL) {
|
|
|
|
wl_client_post_no_memory(wl_resource_get_client(surface->resource));
|
|
|
|
return surface->pending.configure_serial;
|
|
|
|
}
|
|
|
|
wl_list_insert(surface->configure_list.prev, &configure->link);
|
|
|
|
configure->width = width;
|
|
|
|
configure->height = height;
|
|
|
|
configure->serial = wl_display_next_serial(display);
|
|
|
|
zwlr_layer_surface_v1_send_configure(surface->resource,
|
|
|
|
configure->serial, configure->width,
|
|
|
|
configure->height);
|
|
|
|
return configure->serial;
|
2018-03-18 02:06:54 +01:00
|
|
|
}
|
|
|
|
|
2021-08-12 21:30:58 +02:00
|
|
|
void wlr_layer_surface_v1_destroy(struct wlr_layer_surface_v1 *surface) {
|
2023-10-09 21:08:34 +02:00
|
|
|
if (surface == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2018-03-24 23:00:01 +01:00
|
|
|
zwlr_layer_surface_v1_send_closed(surface->resource);
|
2023-07-06 20:46:11 +02:00
|
|
|
layer_surface_destroy(surface);
|
2018-03-24 23:00:01 +01:00
|
|
|
}
|
|
|
|
|
2018-07-07 23:45:16 +02:00
|
|
|
static void layer_surface_role_commit(struct wlr_surface *wlr_surface) {
|
2018-09-14 19:32:33 +02:00
|
|
|
struct wlr_layer_surface_v1 *surface =
|
2023-02-01 20:13:53 +01:00
|
|
|
wlr_layer_surface_v1_try_from_wlr_surface(wlr_surface);
|
2023-07-06 20:46:11 +02:00
|
|
|
if (surface == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2018-03-18 00:03:52 +01:00
|
|
|
|
2020-10-09 15:28:07 +02:00
|
|
|
const uint32_t horiz = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
|
|
|
|
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
|
2021-09-18 10:32:23 +02:00
|
|
|
if (surface->pending.desired_width == 0 &&
|
|
|
|
(surface->pending.anchor & horiz) != horiz) {
|
2020-10-09 15:28:07 +02:00
|
|
|
wl_resource_post_error(surface->resource,
|
|
|
|
ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_SIZE,
|
|
|
|
"width 0 requested without setting left and right anchors");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint32_t vert = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP |
|
|
|
|
ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
|
2021-09-18 10:32:23 +02:00
|
|
|
if (surface->pending.desired_height == 0 &&
|
|
|
|
(surface->pending.anchor & vert) != vert) {
|
2020-10-09 15:28:07 +02:00
|
|
|
wl_resource_post_error(surface->resource,
|
|
|
|
ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_SIZE,
|
|
|
|
"height 0 requested without setting top and bottom anchors");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-18 10:32:23 +02:00
|
|
|
surface->current = surface->pending;
|
2021-09-24 06:58:59 +02:00
|
|
|
surface->pending.committed = 0;
|
2018-03-28 04:50:55 +02:00
|
|
|
|
2018-03-18 00:03:52 +01:00
|
|
|
if (wlr_surface_has_buffer(surface->surface) && !surface->configured) {
|
|
|
|
wl_resource_post_error(surface->resource,
|
|
|
|
ZWLR_LAYER_SHELL_V1_ERROR_ALREADY_CONSTRUCTED,
|
|
|
|
"layer_surface has never been configured");
|
|
|
|
return;
|
|
|
|
}
|
2018-03-18 18:58:01 +01:00
|
|
|
|
2018-03-18 00:03:52 +01:00
|
|
|
if (!surface->added) {
|
|
|
|
surface->added = true;
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&surface->shell->events.new_surface, surface);
|
2021-08-12 21:30:58 +02:00
|
|
|
// Return early here as the compositor may have closed this layer surface
|
|
|
|
// in response to the new_surface event.
|
|
|
|
return;
|
2018-03-18 00:03:52 +01:00
|
|
|
}
|
2021-08-12 21:30:58 +02:00
|
|
|
|
2023-03-04 20:42:40 +01:00
|
|
|
if (surface->configured && wlr_surface_has_buffer(wlr_surface)) {
|
|
|
|
wlr_surface_map(wlr_surface);
|
2018-03-18 00:03:52 +01:00
|
|
|
}
|
2021-10-06 09:55:23 +02:00
|
|
|
}
|
|
|
|
|
2023-03-04 20:42:40 +01:00
|
|
|
static void layer_surface_role_unmap(struct wlr_surface *wlr_surface) {
|
2021-10-06 09:55:23 +02:00
|
|
|
struct wlr_layer_surface_v1 *surface =
|
2023-02-01 20:13:53 +01:00
|
|
|
wlr_layer_surface_v1_try_from_wlr_surface(wlr_surface);
|
2023-07-06 20:46:11 +02:00
|
|
|
if (surface == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2021-10-06 09:55:23 +02:00
|
|
|
|
2023-03-04 20:42:40 +01:00
|
|
|
surface->configured = false;
|
|
|
|
|
|
|
|
struct wlr_xdg_popup *popup, *popup_tmp;
|
|
|
|
wl_list_for_each_safe(popup, popup_tmp, &surface->popups, link) {
|
|
|
|
wlr_xdg_popup_destroy(popup);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_layer_surface_v1_configure *configure, *tmp;
|
|
|
|
wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) {
|
|
|
|
layer_surface_configure_destroy(configure);
|
2018-03-18 00:03:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-03 18:44:21 +01:00
|
|
|
static void layer_surface_role_destroy(struct wlr_surface *wlr_surface) {
|
|
|
|
struct wlr_layer_surface_v1 *surface =
|
2023-02-01 20:13:53 +01:00
|
|
|
wlr_layer_surface_v1_try_from_wlr_surface(wlr_surface);
|
2023-07-06 20:46:11 +02:00
|
|
|
if (surface == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2022-11-03 18:44:21 +01:00
|
|
|
|
2023-07-06 20:46:11 +02:00
|
|
|
layer_surface_destroy(surface);
|
2022-11-03 18:44:21 +01:00
|
|
|
}
|
|
|
|
|
2018-07-07 23:45:16 +02:00
|
|
|
static const struct wlr_surface_role layer_surface_role = {
|
|
|
|
.name = "zwlr_layer_surface_v1",
|
|
|
|
.commit = layer_surface_role_commit,
|
2023-03-04 20:42:40 +01:00
|
|
|
.unmap = layer_surface_role_unmap,
|
2022-11-03 18:44:21 +01:00
|
|
|
.destroy = layer_surface_role_destroy,
|
2018-07-07 23:45:16 +02:00
|
|
|
};
|
|
|
|
|
2018-03-18 00:03:52 +01:00
|
|
|
static void layer_shell_handle_get_layer_surface(struct wl_client *wl_client,
|
|
|
|
struct wl_resource *client_resource, uint32_t id,
|
|
|
|
struct wl_resource *surface_resource,
|
|
|
|
struct wl_resource *output_resource,
|
|
|
|
uint32_t layer, const char *namespace) {
|
2018-09-14 19:32:33 +02:00
|
|
|
struct wlr_layer_shell_v1 *shell =
|
2018-03-27 23:18:16 +02:00
|
|
|
layer_shell_from_resource(client_resource);
|
2018-03-28 05:08:41 +02:00
|
|
|
struct wlr_surface *wlr_surface =
|
|
|
|
wlr_surface_from_resource(surface_resource);
|
|
|
|
|
2023-10-03 07:51:07 +02:00
|
|
|
struct wlr_layer_surface_v1 *surface = calloc(1, sizeof(*surface));
|
2018-03-18 00:03:52 +01:00
|
|
|
if (surface == NULL) {
|
|
|
|
wl_client_post_no_memory(wl_client);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-22 14:05:34 +02:00
|
|
|
if (!wlr_surface_set_role(wlr_surface, &layer_surface_role,
|
2018-07-07 23:45:16 +02:00
|
|
|
client_resource, ZWLR_LAYER_SHELL_V1_ERROR_ROLE)) {
|
|
|
|
free(surface);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-27 23:18:16 +02:00
|
|
|
surface->shell = shell;
|
2018-03-28 05:08:41 +02:00
|
|
|
surface->surface = wlr_surface;
|
2018-04-22 18:57:45 +02:00
|
|
|
if (output_resource) {
|
|
|
|
surface->output = wlr_output_from_resource(output_resource);
|
|
|
|
}
|
2021-09-18 10:32:23 +02:00
|
|
|
surface->current.layer = surface->pending.layer = layer;
|
2018-03-20 01:24:16 +01:00
|
|
|
if (layer > ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY) {
|
2018-04-24 23:40:48 +02:00
|
|
|
free(surface);
|
2018-04-26 16:58:41 +02:00
|
|
|
wl_resource_post_error(client_resource,
|
2018-03-20 01:24:16 +01:00
|
|
|
ZWLR_LAYER_SHELL_V1_ERROR_INVALID_LAYER,
|
2020-06-04 14:33:32 +02:00
|
|
|
"Invalid layer %" PRIu32, layer);
|
2018-04-24 23:40:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
surface->namespace = strdup(namespace);
|
|
|
|
if (surface->namespace == NULL) {
|
2018-03-20 01:24:16 +01:00
|
|
|
free(surface);
|
2018-04-24 23:40:48 +02:00
|
|
|
wl_client_post_no_memory(wl_client);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
surface->resource = wl_resource_create(wl_client,
|
|
|
|
&zwlr_layer_surface_v1_interface,
|
|
|
|
wl_resource_get_version(client_resource),
|
|
|
|
id);
|
|
|
|
if (surface->resource == NULL) {
|
|
|
|
free(surface->namespace);
|
|
|
|
free(surface);
|
|
|
|
wl_client_post_no_memory(wl_client);
|
2018-03-20 01:24:16 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_init(&surface->configure_list);
|
2018-04-14 21:47:51 +02:00
|
|
|
wl_list_init(&surface->popups);
|
2018-03-18 00:03:52 +01:00
|
|
|
|
|
|
|
wl_signal_init(&surface->events.destroy);
|
2018-04-14 21:47:51 +02:00
|
|
|
wl_signal_init(&surface->events.new_popup);
|
2018-03-18 00:03:52 +01:00
|
|
|
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_DEBUG, "new layer_surface %p (res %p)",
|
2018-03-18 00:03:52 +01:00
|
|
|
surface, surface->resource);
|
|
|
|
wl_resource_set_implementation(surface->resource,
|
2023-06-23 14:33:26 +02:00
|
|
|
&layer_surface_implementation, surface, NULL);
|
2023-06-22 14:05:34 +02:00
|
|
|
|
2023-06-23 14:23:27 +02:00
|
|
|
wlr_surface_set_role_object(wlr_surface, surface->resource);
|
2018-03-18 00:03:52 +01:00
|
|
|
}
|
|
|
|
|
2018-03-20 01:24:16 +01:00
|
|
|
static const struct zwlr_layer_shell_v1_interface layer_shell_implementation = {
|
2018-03-18 00:03:52 +01:00
|
|
|
.get_layer_surface = layer_shell_handle_get_layer_surface,
|
2020-06-30 13:07:26 +02:00
|
|
|
.destroy = resource_handle_destroy,
|
2018-03-18 00:03:52 +01:00
|
|
|
};
|
|
|
|
|
2018-03-17 20:07:48 +01:00
|
|
|
static void layer_shell_bind(struct wl_client *wl_client, void *data,
|
|
|
|
uint32_t version, uint32_t id) {
|
2018-09-14 19:32:33 +02:00
|
|
|
struct wlr_layer_shell_v1 *layer_shell = data;
|
2018-03-17 20:07:48 +01:00
|
|
|
assert(wl_client && layer_shell);
|
|
|
|
|
2018-03-27 23:18:16 +02:00
|
|
|
struct wl_resource *resource = wl_resource_create(
|
2018-03-17 20:07:48 +01:00
|
|
|
wl_client, &zwlr_layer_shell_v1_interface, version, id);
|
2018-03-27 23:18:16 +02:00
|
|
|
if (resource == NULL) {
|
2018-03-17 20:07:48 +01:00
|
|
|
wl_client_post_no_memory(wl_client);
|
|
|
|
return;
|
|
|
|
}
|
2018-03-27 23:18:16 +02:00
|
|
|
wl_resource_set_implementation(resource,
|
2019-11-16 18:31:33 +01:00
|
|
|
&layer_shell_implementation, layer_shell, NULL);
|
2018-03-17 20:07:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_display_destroy(struct wl_listener *listener, void *data) {
|
2018-09-14 19:32:33 +02:00
|
|
|
struct wlr_layer_shell_v1 *layer_shell =
|
2018-03-17 20:07:48 +01:00
|
|
|
wl_container_of(listener, layer_shell, display_destroy);
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&layer_shell->events.destroy, layer_shell);
|
2019-11-16 18:31:33 +01:00
|
|
|
wl_list_remove(&layer_shell->display_destroy.link);
|
|
|
|
wl_global_destroy(layer_shell->global);
|
|
|
|
free(layer_shell);
|
2018-03-17 20:07:48 +01:00
|
|
|
}
|
|
|
|
|
2022-11-14 09:52:13 +01:00
|
|
|
struct wlr_layer_shell_v1 *wlr_layer_shell_v1_create(struct wl_display *display,
|
|
|
|
uint32_t version) {
|
|
|
|
assert(version <= LAYER_SHELL_VERSION);
|
|
|
|
|
2023-10-03 07:51:07 +02:00
|
|
|
struct wlr_layer_shell_v1 *layer_shell = calloc(1, sizeof(*layer_shell));
|
2018-03-17 20:07:48 +01:00
|
|
|
if (!layer_shell) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-07-08 20:21:31 +02:00
|
|
|
struct wl_global *global = wl_global_create(display,
|
2022-11-14 09:52:13 +01:00
|
|
|
&zwlr_layer_shell_v1_interface, version, layer_shell, layer_shell_bind);
|
2018-07-08 20:21:31 +02:00
|
|
|
if (!global) {
|
2018-03-17 20:07:48 +01:00
|
|
|
free(layer_shell);
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-07-08 20:21:31 +02:00
|
|
|
layer_shell->global = global;
|
2018-03-17 20:07:48 +01:00
|
|
|
|
|
|
|
wl_signal_init(&layer_shell->events.new_surface);
|
2018-08-27 18:21:36 +02:00
|
|
|
wl_signal_init(&layer_shell->events.destroy);
|
2018-03-17 20:07:48 +01:00
|
|
|
|
|
|
|
layer_shell->display_destroy.notify = handle_display_destroy;
|
|
|
|
wl_display_add_destroy_listener(display, &layer_shell->display_destroy);
|
|
|
|
|
|
|
|
return layer_shell;
|
|
|
|
}
|
|
|
|
|
2018-04-15 02:36:01 +02:00
|
|
|
struct layer_surface_iterator_data {
|
|
|
|
wlr_surface_iterator_func_t user_iterator;
|
|
|
|
void *user_data;
|
|
|
|
int x, y;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void layer_surface_iterator(struct wlr_surface *surface,
|
|
|
|
int sx, int sy, void *data) {
|
|
|
|
struct layer_surface_iterator_data *iter_data = data;
|
|
|
|
iter_data->user_iterator(surface, iter_data->x + sx, iter_data->y + sy,
|
|
|
|
iter_data->user_data);
|
|
|
|
}
|
|
|
|
|
2020-09-08 18:03:33 +02:00
|
|
|
void wlr_layer_surface_v1_for_each_surface(struct wlr_layer_surface_v1 *surface,
|
|
|
|
wlr_surface_iterator_func_t iterator, void *user_data) {
|
2021-01-08 12:50:55 +01:00
|
|
|
wlr_surface_for_each_surface(surface->surface, iterator, user_data);
|
2021-01-08 11:14:42 +01:00
|
|
|
wlr_layer_surface_v1_for_each_popup_surface(surface, iterator, user_data);
|
2020-09-08 18:03:33 +02:00
|
|
|
}
|
2018-04-15 02:36:01 +02:00
|
|
|
|
2021-01-08 11:14:42 +01:00
|
|
|
void wlr_layer_surface_v1_for_each_popup_surface(struct wlr_layer_surface_v1 *surface,
|
2023-03-04 20:14:50 +01:00
|
|
|
wlr_surface_iterator_func_t iterator, void *user_data) {
|
2022-04-13 19:22:14 +02:00
|
|
|
struct wlr_xdg_popup *popup;
|
|
|
|
wl_list_for_each(popup, &surface->popups, link) {
|
2023-03-04 20:14:50 +01:00
|
|
|
if (!popup->base->surface->mapped) {
|
2018-04-15 02:36:01 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
double popup_sx, popup_sy;
|
2022-04-13 19:22:14 +02:00
|
|
|
popup_sx = popup->current.geometry.x - popup->base->current.geometry.x;
|
|
|
|
popup_sy = popup->current.geometry.y - popup->base->current.geometry.y;
|
2018-04-15 02:36:01 +02:00
|
|
|
|
2021-01-08 12:50:55 +01:00
|
|
|
struct layer_surface_iterator_data data = {
|
|
|
|
.user_iterator = iterator,
|
|
|
|
.user_data = user_data,
|
|
|
|
.x = popup_sx, .y = popup_sy,
|
|
|
|
};
|
|
|
|
|
2022-04-13 19:22:14 +02:00
|
|
|
wlr_xdg_surface_for_each_surface(popup->base,
|
|
|
|
layer_surface_iterator, &data);
|
2018-04-15 02:36:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-14 19:32:33 +02:00
|
|
|
struct wlr_surface *wlr_layer_surface_v1_surface_at(
|
|
|
|
struct wlr_layer_surface_v1 *surface, double sx, double sy,
|
2018-05-08 15:19:31 +02:00
|
|
|
double *sub_x, double *sub_y) {
|
2021-01-07 15:11:29 +01:00
|
|
|
struct wlr_surface *sub = wlr_layer_surface_v1_popup_surface_at(surface,
|
|
|
|
sx, sy, sub_x, sub_y);
|
|
|
|
if (sub != NULL) {
|
|
|
|
return sub;
|
|
|
|
}
|
|
|
|
return wlr_surface_surface_at(surface->surface, sx, sy, sub_x, sub_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_surface *wlr_layer_surface_v1_popup_surface_at(
|
|
|
|
struct wlr_layer_surface_v1 *surface, double sx, double sy,
|
|
|
|
double *sub_x, double *sub_y) {
|
2022-04-13 19:22:14 +02:00
|
|
|
struct wlr_xdg_popup *popup;
|
|
|
|
wl_list_for_each(popup, &surface->popups, link) {
|
2023-03-04 20:14:50 +01:00
|
|
|
if (!popup->base->surface->mapped) {
|
2021-09-28 12:51:10 +02:00
|
|
|
continue;
|
|
|
|
}
|
2018-05-08 15:19:31 +02:00
|
|
|
|
2022-04-13 19:22:14 +02:00
|
|
|
double popup_sx, popup_sy;
|
|
|
|
popup_sx = popup->current.geometry.x - popup->base->current.geometry.x;
|
|
|
|
popup_sy = popup->current.geometry.y - popup->base->current.geometry.y;
|
2018-05-08 15:19:31 +02:00
|
|
|
|
2022-04-13 19:22:14 +02:00
|
|
|
struct wlr_surface *sub = wlr_xdg_surface_surface_at(
|
|
|
|
popup->base, sx - popup_sx, sy - popup_sy, sub_x, sub_y);
|
2018-05-08 15:19:31 +02:00
|
|
|
if (sub != NULL) {
|
|
|
|
return sub;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-07 15:11:29 +01:00
|
|
|
return NULL;
|
2018-05-08 15:19:31 +02:00
|
|
|
}
|