2017-09-12 10:36:16 +00:00
|
|
|
#ifndef _POSIX_C_SOURCE
|
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
#endif
|
2017-08-08 12:09:14 +00:00
|
|
|
#include <assert.h>
|
2017-08-11 13:37:09 +00:00
|
|
|
#include <stdlib.h>
|
2017-09-12 10:36:16 +00:00
|
|
|
#include <string.h>
|
2017-08-08 12:09:14 +00:00
|
|
|
#include <wayland-server.h>
|
2017-12-27 13:37:55 +00:00
|
|
|
#include <wlr/config.h>
|
2017-09-16 12:31:08 +00:00
|
|
|
#include <wlr/types/wlr_seat.h>
|
2018-02-12 20:29:23 +00:00
|
|
|
#include <wlr/types/wlr_surface.h>
|
|
|
|
#include <wlr/types/wlr_xdg_shell_v6.h>
|
2017-08-08 12:09:14 +00:00
|
|
|
#include <wlr/util/log.h>
|
2018-02-12 18:45:58 +00:00
|
|
|
#include "util/signal.h"
|
2017-08-09 17:25:52 +00:00
|
|
|
#include "xdg-shell-unstable-v6-protocol.h"
|
2017-08-08 12:09:14 +00:00
|
|
|
|
2017-09-11 22:06:19 +00:00
|
|
|
static const char *wlr_desktop_xdg_toplevel_role = "xdg_toplevel";
|
2017-10-01 10:47:14 +00:00
|
|
|
static const char *wlr_desktop_xdg_popup_role = "xdg_popup";
|
2017-09-11 22:06:19 +00:00
|
|
|
|
2017-09-30 23:33:39 +00:00
|
|
|
struct wlr_xdg_positioner_v6 {
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
struct wlr_box anchor_rect;
|
|
|
|
enum zxdg_positioner_v6_anchor anchor;
|
|
|
|
enum zxdg_positioner_v6_gravity gravity;
|
|
|
|
enum zxdg_positioner_v6_constraint_adjustment constraint_adjustment;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
int32_t width, height;
|
|
|
|
} size;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
int32_t x, y;
|
|
|
|
} offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-09-11 20:26:51 +00:00
|
|
|
static void resource_destroy(struct wl_client *client,
|
|
|
|
struct wl_resource *resource) {
|
2017-08-09 16:23:38 +00:00
|
|
|
wl_resource_destroy(resource);
|
2017-08-08 21:22:11 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 12:41:43 +00:00
|
|
|
static struct wlr_xdg_surface_v6 *xdg_popup_grab_get_topmost(
|
|
|
|
struct wlr_xdg_popup_grab_v6 *grab) {
|
|
|
|
struct wlr_xdg_popup_v6 *popup;
|
|
|
|
wl_list_for_each(popup, &grab->popups, grab_link) {
|
|
|
|
return popup->base;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xdg_pointer_grab_end(struct wlr_seat_pointer_grab *grab) {
|
|
|
|
struct wlr_xdg_popup_grab_v6 *popup_grab = grab->data;
|
|
|
|
|
|
|
|
struct wlr_xdg_popup_v6 *popup, *tmp;
|
|
|
|
wl_list_for_each_safe(popup, tmp, &popup_grab->popups, grab_link) {
|
|
|
|
zxdg_popup_v6_send_popup_done(popup->resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_seat_pointer_end_grab(grab->seat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xdg_pointer_grab_enter(struct wlr_seat_pointer_grab *grab,
|
|
|
|
struct wlr_surface *surface, double sx, double sy) {
|
|
|
|
struct wlr_xdg_popup_grab_v6 *popup_grab = grab->data;
|
|
|
|
if (wl_resource_get_client(surface->resource) == popup_grab->client) {
|
|
|
|
wlr_seat_pointer_enter(grab->seat, surface, sx, sy);
|
|
|
|
} else {
|
|
|
|
wlr_seat_pointer_clear_focus(grab->seat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xdg_pointer_grab_motion(struct wlr_seat_pointer_grab *grab,
|
|
|
|
uint32_t time, double sx, double sy) {
|
|
|
|
wlr_seat_pointer_send_motion(grab->seat, time, sx, sy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t xdg_pointer_grab_button(struct wlr_seat_pointer_grab *grab,
|
|
|
|
uint32_t time, uint32_t button, uint32_t state) {
|
|
|
|
uint32_t serial =
|
|
|
|
wlr_seat_pointer_send_button(grab->seat, time, button, state);
|
|
|
|
if (serial) {
|
|
|
|
return serial;
|
|
|
|
} else {
|
|
|
|
xdg_pointer_grab_end(grab);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xdg_pointer_grab_axis(struct wlr_seat_pointer_grab *grab,
|
|
|
|
uint32_t time, enum wlr_axis_orientation orientation, double value) {
|
|
|
|
wlr_seat_pointer_send_axis(grab->seat, time, orientation, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xdg_pointer_grab_cancel(struct wlr_seat_pointer_grab *grab) {
|
|
|
|
xdg_pointer_grab_end(grab);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wlr_pointer_grab_interface xdg_pointer_grab_impl = {
|
|
|
|
.enter = xdg_pointer_grab_enter,
|
|
|
|
.motion = xdg_pointer_grab_motion,
|
|
|
|
.button = xdg_pointer_grab_button,
|
|
|
|
.cancel = xdg_pointer_grab_cancel,
|
|
|
|
.axis = xdg_pointer_grab_axis,
|
|
|
|
};
|
|
|
|
|
2018-01-06 16:06:09 +00:00
|
|
|
static void xdg_keyboard_grab_enter(struct wlr_seat_keyboard_grab *grab,
|
|
|
|
struct wlr_surface *surface, uint32_t keycodes[], size_t num_keycodes,
|
|
|
|
struct wlr_keyboard_modifiers *modifiers) {
|
2017-10-07 15:02:11 +00:00
|
|
|
// keyboard focus should remain on the popup
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xdg_keyboard_grab_key(struct wlr_seat_keyboard_grab *grab, uint32_t time,
|
|
|
|
uint32_t key, uint32_t state) {
|
|
|
|
wlr_seat_keyboard_send_key(grab->seat, time, key, state);
|
|
|
|
}
|
|
|
|
|
2018-01-05 12:00:50 +00:00
|
|
|
static void xdg_keyboard_grab_modifiers(struct wlr_seat_keyboard_grab *grab,
|
|
|
|
struct wlr_keyboard_modifiers *modifiers) {
|
|
|
|
wlr_seat_keyboard_send_modifiers(grab->seat, modifiers);
|
2017-10-07 15:02:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void xdg_keyboard_grab_cancel(struct wlr_seat_keyboard_grab *grab) {
|
|
|
|
wlr_seat_keyboard_end_grab(grab->seat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wlr_keyboard_grab_interface xdg_keyboard_grab_impl = {
|
|
|
|
.enter = xdg_keyboard_grab_enter,
|
|
|
|
.key = xdg_keyboard_grab_key,
|
|
|
|
.modifiers = xdg_keyboard_grab_modifiers,
|
|
|
|
.cancel = xdg_keyboard_grab_cancel,
|
|
|
|
};
|
|
|
|
|
2017-10-06 12:41:43 +00:00
|
|
|
static struct wlr_xdg_popup_grab_v6 *xdg_shell_popup_grab_from_seat(
|
|
|
|
struct wlr_xdg_shell_v6 *shell, struct wlr_seat *seat) {
|
|
|
|
struct wlr_xdg_popup_grab_v6 *xdg_grab;
|
|
|
|
wl_list_for_each(xdg_grab, &shell->popup_grabs, link) {
|
|
|
|
if (xdg_grab->seat == seat) {
|
|
|
|
return xdg_grab;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xdg_grab = calloc(1, sizeof(struct wlr_xdg_popup_grab_v6));
|
|
|
|
if (!xdg_grab) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
xdg_grab->pointer_grab.data = xdg_grab;
|
|
|
|
xdg_grab->pointer_grab.interface = &xdg_pointer_grab_impl;
|
2017-10-07 15:02:11 +00:00
|
|
|
xdg_grab->keyboard_grab.data = xdg_grab;
|
|
|
|
xdg_grab->keyboard_grab.interface = &xdg_keyboard_grab_impl;
|
2017-10-06 12:41:43 +00:00
|
|
|
|
|
|
|
wl_list_init(&xdg_grab->popups);
|
|
|
|
|
|
|
|
wl_list_insert(&shell->popup_grabs, &xdg_grab->link);
|
|
|
|
xdg_grab->seat = seat;
|
|
|
|
|
|
|
|
return xdg_grab;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-01 10:47:14 +00:00
|
|
|
static void xdg_surface_destroy(struct wlr_xdg_surface_v6 *surface) {
|
2017-10-07 15:02:11 +00:00
|
|
|
// TODO: probably need to ungrab before this event
|
2018-02-12 08:12:31 +00:00
|
|
|
wlr_signal_emit_safe(&surface->events.destroy, surface);
|
2017-10-01 10:47:14 +00:00
|
|
|
|
|
|
|
if (surface->configure_idle) {
|
|
|
|
wl_event_source_remove(surface->configure_idle);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_xdg_surface_v6_configure *configure, *tmp;
|
|
|
|
wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) {
|
|
|
|
free(configure);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
|
|
|
|
wl_resource_set_user_data(surface->toplevel_state->resource, NULL);
|
|
|
|
free(surface->toplevel_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP) {
|
|
|
|
wl_resource_set_user_data(surface->popup_state->resource, NULL);
|
2017-10-06 12:41:43 +00:00
|
|
|
|
|
|
|
if (surface->popup_state->seat) {
|
|
|
|
struct wlr_xdg_popup_grab_v6 *grab =
|
|
|
|
xdg_shell_popup_grab_from_seat(surface->client->shell,
|
|
|
|
surface->popup_state->seat);
|
|
|
|
|
|
|
|
struct wlr_xdg_surface_v6 *topmost =
|
|
|
|
xdg_popup_grab_get_topmost(grab);
|
|
|
|
|
|
|
|
if (topmost != surface) {
|
|
|
|
wl_resource_post_error(surface->client->resource,
|
|
|
|
ZXDG_SHELL_V6_ERROR_NOT_THE_TOPMOST_POPUP,
|
|
|
|
"xdg_popup was destroyed while it was not the topmost "
|
|
|
|
"popup.");
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_remove(&surface->popup_state->grab_link);
|
|
|
|
|
2017-10-07 15:02:11 +00:00
|
|
|
if (wl_list_empty(&grab->popups)) {
|
|
|
|
if (grab->seat->pointer_state.grab == &grab->pointer_grab) {
|
|
|
|
wlr_seat_pointer_end_grab(grab->seat);
|
|
|
|
}
|
|
|
|
if (grab->seat->keyboard_state.grab == &grab->keyboard_grab) {
|
|
|
|
wlr_seat_keyboard_end_grab(grab->seat);
|
|
|
|
}
|
2017-10-06 12:41:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-21 20:06:37 +00:00
|
|
|
wl_list_remove(&surface->popup_state->link);
|
2017-10-01 10:47:14 +00:00
|
|
|
free(surface->popup_state);
|
|
|
|
}
|
|
|
|
|
2017-10-06 12:41:43 +00:00
|
|
|
wl_resource_set_user_data(surface->resource, NULL);
|
2017-10-01 10:47:14 +00:00
|
|
|
wl_list_remove(&surface->link);
|
|
|
|
wl_list_remove(&surface->surface_destroy_listener.link);
|
2017-12-27 11:15:25 +00:00
|
|
|
wlr_surface_set_role_committed(surface->surface, NULL, NULL);
|
2017-10-01 10:47:14 +00:00
|
|
|
free(surface->geometry);
|
|
|
|
free(surface->next_geometry);
|
|
|
|
free(surface->title);
|
|
|
|
free(surface->app_id);
|
|
|
|
free(surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-13 22:48:46 +00:00
|
|
|
static const struct zxdg_positioner_v6_interface
|
|
|
|
zxdg_positioner_v6_implementation;
|
|
|
|
|
|
|
|
static struct wlr_xdg_positioner_v6 *xdg_positioner_from_resource(
|
|
|
|
struct wl_resource *resource) {
|
|
|
|
assert(wl_resource_instance_of(resource, &zxdg_positioner_v6_interface,
|
|
|
|
&zxdg_positioner_v6_implementation));
|
|
|
|
return wl_resource_get_user_data(resource);
|
|
|
|
}
|
|
|
|
|
2017-09-30 23:33:39 +00:00
|
|
|
static void xdg_positioner_destroy(struct wl_resource *resource) {
|
|
|
|
struct wlr_xdg_positioner_v6 *positioner =
|
2018-02-13 22:48:46 +00:00
|
|
|
xdg_positioner_from_resource(resource);
|
2017-09-30 23:33:39 +00:00
|
|
|
free(positioner);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xdg_positioner_protocol_set_size(struct wl_client *client,
|
|
|
|
struct wl_resource *resource, int32_t width, int32_t height) {
|
|
|
|
struct wlr_xdg_positioner_v6 *positioner =
|
2018-02-13 22:48:46 +00:00
|
|
|
xdg_positioner_from_resource(resource);
|
2017-09-30 23:33:39 +00:00
|
|
|
|
|
|
|
if (width < 1 || height < 1) {
|
|
|
|
wl_resource_post_error(resource,
|
|
|
|
ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT,
|
2018-02-15 11:26:20 +00:00
|
|
|
"width and height must be positive and non-zero");
|
2017-09-30 23:33:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
positioner->size.width = width;
|
|
|
|
positioner->size.height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xdg_positioner_protocol_set_anchor_rect(struct wl_client *client,
|
|
|
|
struct wl_resource *resource, int32_t x, int32_t y, int32_t width,
|
|
|
|
int32_t height) {
|
|
|
|
struct wlr_xdg_positioner_v6 *positioner =
|
2018-02-13 22:48:46 +00:00
|
|
|
xdg_positioner_from_resource(resource);
|
2017-09-30 23:33:39 +00:00
|
|
|
|
|
|
|
if (width < 1 || height < 1) {
|
|
|
|
wl_resource_post_error(resource,
|
|
|
|
ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT,
|
2018-02-15 11:26:20 +00:00
|
|
|
"width and height must be positive and non-zero");
|
2017-09-30 23:33:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
positioner->anchor_rect.x = x;
|
|
|
|
positioner->anchor_rect.y = y;
|
|
|
|
positioner->anchor_rect.width = width;
|
|
|
|
positioner->anchor_rect.height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xdg_positioner_protocol_set_anchor(struct wl_client *client,
|
|
|
|
struct wl_resource *resource, uint32_t anchor) {
|
|
|
|
struct wlr_xdg_positioner_v6 *positioner =
|
2018-02-13 22:48:46 +00:00
|
|
|
xdg_positioner_from_resource(resource);
|
2017-09-30 23:33:39 +00:00
|
|
|
|
|
|
|
if (((anchor & ZXDG_POSITIONER_V6_ANCHOR_TOP ) &&
|
|
|
|
(anchor & ZXDG_POSITIONER_V6_ANCHOR_BOTTOM)) ||
|
|
|
|
((anchor & ZXDG_POSITIONER_V6_ANCHOR_LEFT) &&
|
|
|
|
(anchor & ZXDG_POSITIONER_V6_ANCHOR_RIGHT))) {
|
|
|
|
wl_resource_post_error(resource,
|
|
|
|
ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT,
|
|
|
|
"same-axis values are not allowed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
positioner->anchor = anchor;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xdg_positioner_protocol_set_gravity(struct wl_client *client,
|
|
|
|
struct wl_resource *resource, uint32_t gravity) {
|
|
|
|
struct wlr_xdg_positioner_v6 *positioner =
|
2018-02-13 22:48:46 +00:00
|
|
|
xdg_positioner_from_resource(resource);
|
2017-09-30 23:33:39 +00:00
|
|
|
|
|
|
|
if (((gravity & ZXDG_POSITIONER_V6_GRAVITY_TOP) &&
|
|
|
|
(gravity & ZXDG_POSITIONER_V6_GRAVITY_BOTTOM)) ||
|
|
|
|
((gravity & ZXDG_POSITIONER_V6_GRAVITY_LEFT) &&
|
|
|
|
(gravity & ZXDG_POSITIONER_V6_GRAVITY_RIGHT))) {
|
|
|
|
wl_resource_post_error(resource,
|
|
|
|
ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT,
|
|
|
|
"same-axis values are not allowed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
positioner->gravity = gravity;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xdg_positioner_protocol_set_constraint_adjustment(
|
|
|
|
struct wl_client *client, struct wl_resource *resource,
|
|
|
|
uint32_t constraint_adjustment) {
|
|
|
|
struct wlr_xdg_positioner_v6 *positioner =
|
2018-02-13 22:48:46 +00:00
|
|
|
xdg_positioner_from_resource(resource);
|
2017-09-30 23:33:39 +00:00
|
|
|
|
|
|
|
positioner->constraint_adjustment = constraint_adjustment;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xdg_positioner_protocol_set_offset(struct wl_client *client,
|
|
|
|
struct wl_resource *resource, int32_t x, int32_t y) {
|
|
|
|
struct wlr_xdg_positioner_v6 *positioner =
|
2018-02-13 22:48:46 +00:00
|
|
|
xdg_positioner_from_resource(resource);
|
2017-09-30 23:33:39 +00:00
|
|
|
|
|
|
|
positioner->offset.x = x;
|
|
|
|
positioner->offset.y = y;
|
|
|
|
}
|
|
|
|
|
2017-10-06 11:52:18 +00:00
|
|
|
static const struct zxdg_positioner_v6_interface
|
|
|
|
zxdg_positioner_v6_implementation = {
|
2017-09-30 23:33:39 +00:00
|
|
|
.destroy = resource_destroy,
|
|
|
|
.set_size = xdg_positioner_protocol_set_size,
|
|
|
|
.set_anchor_rect = xdg_positioner_protocol_set_anchor_rect,
|
|
|
|
.set_anchor = xdg_positioner_protocol_set_anchor,
|
|
|
|
.set_gravity = xdg_positioner_protocol_set_gravity,
|
|
|
|
.set_constraint_adjustment =
|
|
|
|
xdg_positioner_protocol_set_constraint_adjustment,
|
|
|
|
.set_offset = xdg_positioner_protocol_set_offset,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void xdg_shell_create_positioner(struct wl_client *wl_client,
|
|
|
|
struct wl_resource *resource, uint32_t id) {
|
|
|
|
struct wlr_xdg_positioner_v6 *positioner =
|
|
|
|
calloc(1, sizeof(struct wlr_xdg_positioner_v6));
|
|
|
|
if (positioner == NULL) {
|
|
|
|
wl_client_post_no_memory(wl_client);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
positioner->resource = wl_resource_create(wl_client,
|
|
|
|
&zxdg_positioner_v6_interface,
|
|
|
|
wl_resource_get_version(resource),
|
|
|
|
id);
|
|
|
|
if (positioner->resource == NULL) {
|
|
|
|
free(positioner);
|
2017-11-02 22:14:24 +00:00
|
|
|
wl_client_post_no_memory(wl_client);
|
2017-09-30 23:33:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_resource_set_implementation(positioner->resource,
|
|
|
|
&zxdg_positioner_v6_implementation,
|
|
|
|
positioner, xdg_positioner_destroy);
|
|
|
|
}
|
|
|
|
|
2017-10-01 10:47:14 +00:00
|
|
|
static struct wlr_box xdg_positioner_get_geometry(
|
|
|
|
struct wlr_xdg_positioner_v6 *positioner,
|
|
|
|
struct wlr_xdg_surface_v6 *surface, struct wlr_xdg_surface_v6 *parent) {
|
|
|
|
struct wlr_box geometry = {
|
|
|
|
.x = positioner->offset.x,
|
|
|
|
.y = positioner->offset.y,
|
|
|
|
.width = positioner->size.width,
|
|
|
|
.height = positioner->size.height,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_TOP) {
|
|
|
|
geometry.y += positioner->anchor_rect.y;
|
|
|
|
} else if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_BOTTOM) {
|
|
|
|
geometry.y +=
|
|
|
|
positioner->anchor_rect.y + positioner->anchor_rect.height;
|
|
|
|
} else {
|
|
|
|
geometry.y +=
|
|
|
|
positioner->anchor_rect.y + positioner->anchor_rect.height / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_LEFT) {
|
|
|
|
geometry.x += positioner->anchor_rect.x;
|
|
|
|
} else if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_RIGHT) {
|
|
|
|
geometry.x += positioner->anchor_rect.x + positioner->anchor_rect.width;
|
|
|
|
} else {
|
|
|
|
geometry.x +=
|
|
|
|
positioner->anchor_rect.x + positioner->anchor_rect.width / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_TOP) {
|
|
|
|
geometry.y -= geometry.height;
|
|
|
|
} else if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_BOTTOM) {
|
|
|
|
geometry.y = geometry.y;
|
|
|
|
} else {
|
|
|
|
geometry.y -= geometry.height / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_LEFT) {
|
|
|
|
geometry.x -= geometry.width;
|
|
|
|
} else if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_RIGHT) {
|
|
|
|
geometry.x = geometry.x;
|
|
|
|
} else {
|
|
|
|
geometry.x -= geometry.width / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (positioner->constraint_adjustment ==
|
|
|
|
ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_NONE) {
|
|
|
|
return geometry;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: add compositor policy configuration and the code here
|
|
|
|
|
|
|
|
return geometry;
|
|
|
|
}
|
|
|
|
|
2018-02-13 22:48:46 +00:00
|
|
|
|
|
|
|
static const struct zxdg_popup_v6_interface zxdg_popup_v6_implementation;
|
|
|
|
|
|
|
|
static struct wlr_xdg_surface_v6 *xdg_surface_from_xdg_popup_resource(
|
|
|
|
struct wl_resource *resource) {
|
|
|
|
assert(wl_resource_instance_of(resource, &zxdg_popup_v6_interface,
|
|
|
|
&zxdg_popup_v6_implementation));
|
|
|
|
return wl_resource_get_user_data(resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xdg_popup_protocol_grab(struct wl_client *client,
|
|
|
|
struct wl_resource *resource, struct wl_resource *seat_resource,
|
|
|
|
uint32_t serial) {
|
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
xdg_surface_from_xdg_popup_resource(resource);
|
|
|
|
struct wlr_seat_client *seat_client =
|
|
|
|
wlr_seat_client_from_resource(seat_resource);
|
|
|
|
|
|
|
|
if (surface->popup_state->committed) {
|
|
|
|
wl_resource_post_error(surface->popup_state->resource,
|
|
|
|
ZXDG_POPUP_V6_ERROR_INVALID_GRAB,
|
|
|
|
"xdg_popup is already mapped");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_xdg_popup_grab_v6 *popup_grab =
|
|
|
|
xdg_shell_popup_grab_from_seat(surface->client->shell,
|
|
|
|
seat_client->seat);
|
|
|
|
|
|
|
|
struct wlr_xdg_surface_v6 *topmost = xdg_popup_grab_get_topmost(popup_grab);
|
|
|
|
bool parent_is_toplevel =
|
|
|
|
surface->popup_state->parent->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL;
|
|
|
|
|
|
|
|
if ((topmost == NULL && !parent_is_toplevel) ||
|
|
|
|
(topmost != NULL && topmost != surface->popup_state->parent)) {
|
|
|
|
wl_resource_post_error(surface->client->resource,
|
|
|
|
ZXDG_SHELL_V6_ERROR_NOT_THE_TOPMOST_POPUP,
|
|
|
|
"xdg_popup was not created on the topmost popup");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
popup_grab->client = surface->client->client;
|
|
|
|
surface->popup_state->seat = seat_client->seat;
|
|
|
|
|
|
|
|
wl_list_insert(&popup_grab->popups, &surface->popup_state->grab_link);
|
|
|
|
|
|
|
|
wlr_seat_pointer_start_grab(seat_client->seat,
|
|
|
|
&popup_grab->pointer_grab);
|
|
|
|
wlr_seat_keyboard_start_grab(seat_client->seat,
|
|
|
|
&popup_grab->keyboard_grab);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct zxdg_popup_v6_interface zxdg_popup_v6_implementation = {
|
|
|
|
.destroy = resource_destroy,
|
|
|
|
.grab = xdg_popup_protocol_grab,
|
|
|
|
};
|
|
|
|
|
2017-10-01 10:47:14 +00:00
|
|
|
static void xdg_popup_resource_destroy(struct wl_resource *resource) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
xdg_surface_from_xdg_popup_resource(resource);
|
2017-10-01 10:47:14 +00:00
|
|
|
if (surface != NULL) {
|
|
|
|
xdg_surface_destroy(surface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-13 22:48:46 +00:00
|
|
|
static const struct zxdg_surface_v6_interface zxdg_surface_v6_implementation;
|
|
|
|
|
2018-02-16 17:38:06 +00:00
|
|
|
static struct wlr_xdg_surface_v6 *xdg_surface_from_resource(
|
|
|
|
struct wl_resource *resource) {
|
2018-02-13 22:48:46 +00:00
|
|
|
assert(wl_resource_instance_of(resource, &zxdg_surface_v6_interface,
|
|
|
|
&zxdg_surface_v6_implementation));
|
|
|
|
return wl_resource_get_user_data(resource);
|
|
|
|
}
|
|
|
|
|
2017-10-01 10:47:14 +00:00
|
|
|
static void xdg_surface_get_popup(struct wl_client *client,
|
|
|
|
struct wl_resource *resource, uint32_t id,
|
|
|
|
struct wl_resource *parent_resource,
|
|
|
|
struct wl_resource *positioner_resource) {
|
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
2018-02-13 22:48:46 +00:00
|
|
|
xdg_surface_from_resource(resource);
|
2017-10-01 10:47:14 +00:00
|
|
|
struct wlr_xdg_surface_v6 *parent =
|
2018-02-13 22:48:46 +00:00
|
|
|
xdg_surface_from_resource(parent_resource);
|
2017-10-01 10:47:14 +00:00
|
|
|
struct wlr_xdg_positioner_v6 *positioner =
|
2018-02-13 22:48:46 +00:00
|
|
|
xdg_positioner_from_resource(positioner_resource);
|
2017-10-01 10:47:14 +00:00
|
|
|
|
|
|
|
if (positioner->size.width == 0 || positioner->anchor_rect.width == 0) {
|
|
|
|
wl_resource_post_error(resource,
|
|
|
|
ZXDG_SHELL_V6_ERROR_INVALID_POSITIONER,
|
|
|
|
"positioner object is not complete");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wlr_surface_set_role(surface->surface, wlr_desktop_xdg_popup_role,
|
2017-11-02 22:14:24 +00:00
|
|
|
resource, ZXDG_SHELL_V6_ERROR_ROLE)) {
|
2017-10-01 10:47:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
surface->popup_state = calloc(1, sizeof(struct wlr_xdg_popup_v6));
|
|
|
|
if (!surface->popup_state) {
|
2017-11-02 22:14:24 +00:00
|
|
|
wl_resource_post_no_memory(resource);
|
2017-10-01 10:47:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
surface->popup_state->resource =
|
|
|
|
wl_resource_create(client, &zxdg_popup_v6_interface,
|
|
|
|
wl_resource_get_version(resource), id);
|
|
|
|
if (surface->popup_state->resource == NULL) {
|
|
|
|
free(surface->popup_state);
|
2017-11-02 22:14:24 +00:00
|
|
|
wl_resource_post_no_memory(resource);
|
2017-10-01 10:47:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
surface->role = WLR_XDG_SURFACE_V6_ROLE_POPUP;
|
2017-10-06 12:41:43 +00:00
|
|
|
surface->popup_state->base = surface;
|
2017-10-01 10:47:14 +00:00
|
|
|
surface->popup_state->parent = parent;
|
|
|
|
surface->popup_state->geometry =
|
|
|
|
xdg_positioner_get_geometry(positioner, surface, parent);
|
2018-01-21 20:06:37 +00:00
|
|
|
wl_list_insert(&parent->popups, &surface->popup_state->link);
|
2017-10-01 10:47:14 +00:00
|
|
|
|
|
|
|
wl_resource_set_implementation(surface->popup_state->resource,
|
|
|
|
&zxdg_popup_v6_implementation, surface,
|
|
|
|
xdg_popup_resource_destroy);
|
2018-01-21 20:06:37 +00:00
|
|
|
|
2018-02-12 08:12:31 +00:00
|
|
|
wlr_signal_emit_safe(&parent->events.new_popup, surface->popup_state);
|
2017-10-01 10:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-13 22:48:46 +00:00
|
|
|
static const struct zxdg_toplevel_v6_interface zxdg_toplevel_v6_implementation;
|
|
|
|
|
|
|
|
static struct wlr_xdg_surface_v6 *xdg_surface_from_xdg_toplevel_resource(
|
|
|
|
struct wl_resource *resource) {
|
|
|
|
assert(wl_resource_instance_of(resource, &zxdg_toplevel_v6_interface,
|
|
|
|
&zxdg_toplevel_v6_implementation));
|
|
|
|
return wl_resource_get_user_data(resource);
|
|
|
|
}
|
|
|
|
|
2017-09-14 20:27:14 +00:00
|
|
|
static void xdg_toplevel_protocol_set_parent(struct wl_client *client,
|
2017-08-08 21:22:11 +00:00
|
|
|
struct wl_resource *resource, struct wl_resource *parent_resource) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
xdg_surface_from_xdg_toplevel_resource(resource);
|
2017-09-17 00:07:19 +00:00
|
|
|
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_surface_v6 *parent = NULL;
|
2017-09-17 00:07:19 +00:00
|
|
|
if (parent_resource != NULL) {
|
2018-02-13 22:48:46 +00:00
|
|
|
parent = xdg_surface_from_xdg_toplevel_resource(parent_resource);
|
2017-09-17 00:07:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
surface->toplevel_state->parent = parent;
|
2017-08-08 21:22:11 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 20:27:14 +00:00
|
|
|
static void xdg_toplevel_protocol_set_title(struct wl_client *client,
|
2017-08-08 21:22:11 +00:00
|
|
|
struct wl_resource *resource, const char *title) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
xdg_surface_from_xdg_toplevel_resource(resource);
|
2017-09-12 10:36:16 +00:00
|
|
|
|
2018-02-13 22:48:46 +00:00
|
|
|
char *tmp = strdup(title);
|
2017-09-12 10:36:16 +00:00
|
|
|
if (tmp == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(surface->title);
|
|
|
|
surface->title = tmp;
|
2017-08-08 21:22:11 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 20:27:14 +00:00
|
|
|
static void xdg_toplevel_protocol_set_app_id(struct wl_client *client,
|
2017-08-08 21:22:11 +00:00
|
|
|
struct wl_resource *resource, const char *app_id) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
xdg_surface_from_xdg_toplevel_resource(resource);
|
2017-09-12 10:36:16 +00:00
|
|
|
|
2018-02-13 22:48:46 +00:00
|
|
|
char *tmp = strdup(app_id);
|
2017-09-12 10:36:16 +00:00
|
|
|
if (tmp == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(surface->app_id);
|
|
|
|
surface->app_id = tmp;
|
2017-08-08 21:22:11 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 20:27:14 +00:00
|
|
|
static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client,
|
2017-09-16 12:31:08 +00:00
|
|
|
struct wl_resource *resource, struct wl_resource *seat_resource,
|
|
|
|
uint32_t serial, int32_t x, int32_t y) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
xdg_surface_from_xdg_toplevel_resource(resource);
|
2017-11-07 20:56:11 +00:00
|
|
|
struct wlr_seat_client *seat =
|
2018-02-13 22:48:46 +00:00
|
|
|
wlr_seat_client_from_resource(seat_resource);
|
2017-09-16 12:31:08 +00:00
|
|
|
|
2017-09-16 18:33:07 +00:00
|
|
|
if (!surface->configured) {
|
|
|
|
wl_resource_post_error(surface->toplevel_state->resource,
|
|
|
|
ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
|
|
|
|
"surface has not been configured yet");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-27 13:04:01 +00:00
|
|
|
if (!wlr_seat_validate_grab_serial(seat->seat, serial)) {
|
|
|
|
wlr_log(L_DEBUG, "invalid serial for grab");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-21 08:50:00 +00:00
|
|
|
struct wlr_xdg_toplevel_v6_show_window_menu_event event = {
|
|
|
|
.surface = surface,
|
|
|
|
.seat = seat,
|
|
|
|
.serial = serial,
|
|
|
|
.x = x,
|
|
|
|
.y = y,
|
|
|
|
};
|
2017-09-16 12:31:08 +00:00
|
|
|
|
2018-02-12 08:12:31 +00:00
|
|
|
wlr_signal_emit_safe(&surface->events.request_show_window_menu, &event);
|
2017-08-08 21:22:11 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 20:27:14 +00:00
|
|
|
static void xdg_toplevel_protocol_move(struct wl_client *client,
|
2017-08-09 16:23:38 +00:00
|
|
|
struct wl_resource *resource, struct wl_resource *seat_resource,
|
|
|
|
uint32_t serial) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
xdg_surface_from_xdg_toplevel_resource(resource);
|
2017-11-07 20:56:11 +00:00
|
|
|
struct wlr_seat_client *seat =
|
2018-02-13 22:48:46 +00:00
|
|
|
wlr_seat_client_from_resource(seat_resource);
|
2017-09-16 12:31:08 +00:00
|
|
|
|
2017-09-16 18:33:07 +00:00
|
|
|
if (!surface->configured) {
|
|
|
|
wl_resource_post_error(surface->toplevel_state->resource,
|
|
|
|
ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
|
|
|
|
"surface has not been configured yet");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-27 13:04:01 +00:00
|
|
|
if (!wlr_seat_validate_grab_serial(seat->seat, serial)) {
|
|
|
|
wlr_log(L_DEBUG, "invalid serial for grab");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-20 16:27:36 +00:00
|
|
|
struct wlr_xdg_toplevel_v6_move_event event = {
|
|
|
|
.surface = surface,
|
|
|
|
.seat = seat,
|
|
|
|
.serial = serial,
|
|
|
|
};
|
2017-09-16 12:31:08 +00:00
|
|
|
|
2018-02-12 08:12:31 +00:00
|
|
|
wlr_signal_emit_safe(&surface->events.request_move, &event);
|
2017-08-08 21:22:11 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 20:27:14 +00:00
|
|
|
static void xdg_toplevel_protocol_resize(struct wl_client *client,
|
2017-08-09 16:23:38 +00:00
|
|
|
struct wl_resource *resource, struct wl_resource *seat_resource,
|
|
|
|
uint32_t serial, uint32_t edges) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
xdg_surface_from_xdg_toplevel_resource(resource);
|
2017-11-07 20:56:11 +00:00
|
|
|
struct wlr_seat_client *seat =
|
2018-02-13 22:48:46 +00:00
|
|
|
wlr_seat_client_from_resource(seat_resource);
|
2017-09-16 12:31:08 +00:00
|
|
|
|
2017-09-16 18:33:07 +00:00
|
|
|
if (!surface->configured) {
|
|
|
|
wl_resource_post_error(surface->toplevel_state->resource,
|
|
|
|
ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
|
|
|
|
"surface has not been configured yet");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-27 13:04:01 +00:00
|
|
|
if (!wlr_seat_validate_grab_serial(seat->seat, serial)) {
|
|
|
|
wlr_log(L_DEBUG, "invalid serial for grab");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-20 16:27:36 +00:00
|
|
|
struct wlr_xdg_toplevel_v6_resize_event event = {
|
|
|
|
.surface = surface,
|
|
|
|
.seat = seat,
|
|
|
|
.serial = serial,
|
|
|
|
.edges = edges,
|
|
|
|
};
|
2017-09-16 12:31:08 +00:00
|
|
|
|
2018-02-12 08:12:31 +00:00
|
|
|
wlr_signal_emit_safe(&surface->events.request_resize, &event);
|
2017-08-08 21:22:11 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 20:27:14 +00:00
|
|
|
static void xdg_toplevel_protocol_set_max_size(struct wl_client *client,
|
2017-08-08 21:22:11 +00:00
|
|
|
struct wl_resource *resource, int32_t width, int32_t height) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
xdg_surface_from_xdg_toplevel_resource(resource);
|
2017-09-13 13:19:10 +00:00
|
|
|
surface->toplevel_state->next.max_width = width;
|
|
|
|
surface->toplevel_state->next.max_height = height;
|
2017-08-08 21:22:11 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 20:27:14 +00:00
|
|
|
static void xdg_toplevel_protocol_set_min_size(struct wl_client *client,
|
2017-08-08 21:22:11 +00:00
|
|
|
struct wl_resource *resource, int32_t width, int32_t height) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
xdg_surface_from_xdg_toplevel_resource(resource);
|
2017-09-13 13:19:10 +00:00
|
|
|
surface->toplevel_state->next.min_width = width;
|
|
|
|
surface->toplevel_state->next.min_height = height;
|
2017-08-08 21:22:11 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 20:27:14 +00:00
|
|
|
static void xdg_toplevel_protocol_set_maximized(struct wl_client *client,
|
2017-08-08 21:22:11 +00:00
|
|
|
struct wl_resource *resource) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
xdg_surface_from_xdg_toplevel_resource(resource);
|
2017-09-13 13:19:10 +00:00
|
|
|
surface->toplevel_state->next.maximized = true;
|
2018-02-12 08:12:31 +00:00
|
|
|
wlr_signal_emit_safe(&surface->events.request_maximize, surface);
|
2017-08-08 21:22:11 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 20:27:14 +00:00
|
|
|
static void xdg_toplevel_protocol_unset_maximized(struct wl_client *client,
|
2017-09-11 20:26:51 +00:00
|
|
|
struct wl_resource *resource) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
xdg_surface_from_xdg_toplevel_resource(resource);
|
2017-09-13 13:19:10 +00:00
|
|
|
surface->toplevel_state->next.maximized = false;
|
2018-02-12 08:12:31 +00:00
|
|
|
wlr_signal_emit_safe(&surface->events.request_maximize, surface);
|
2017-08-08 21:22:11 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 20:27:14 +00:00
|
|
|
static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client,
|
2017-09-11 20:26:51 +00:00
|
|
|
struct wl_resource *resource, struct wl_resource *output_resource) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
xdg_surface_from_xdg_toplevel_resource(resource);
|
2017-11-20 16:27:36 +00:00
|
|
|
|
|
|
|
struct wlr_output *output = NULL;
|
|
|
|
if (output_resource != NULL) {
|
2018-02-13 22:48:46 +00:00
|
|
|
output = wlr_output_from_resource(output_resource);
|
2017-11-20 16:27:36 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 13:19:10 +00:00
|
|
|
surface->toplevel_state->next.fullscreen = true;
|
2017-11-20 16:27:36 +00:00
|
|
|
|
|
|
|
struct wlr_xdg_toplevel_v6_set_fullscreen_event event = {
|
|
|
|
.surface = surface,
|
|
|
|
.fullscreen = true,
|
|
|
|
.output = output,
|
|
|
|
};
|
|
|
|
|
2018-02-12 08:12:31 +00:00
|
|
|
wlr_signal_emit_safe(&surface->events.request_fullscreen, &event);
|
2017-08-08 21:22:11 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 20:27:14 +00:00
|
|
|
static void xdg_toplevel_protocol_unset_fullscreen(struct wl_client *client,
|
2017-09-11 20:26:51 +00:00
|
|
|
struct wl_resource *resource) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
xdg_surface_from_xdg_toplevel_resource(resource);
|
2017-11-20 16:27:36 +00:00
|
|
|
|
2017-09-13 13:19:10 +00:00
|
|
|
surface->toplevel_state->next.fullscreen = false;
|
2017-11-20 16:27:36 +00:00
|
|
|
|
|
|
|
struct wlr_xdg_toplevel_v6_set_fullscreen_event event = {
|
|
|
|
.surface = surface,
|
|
|
|
.fullscreen = false,
|
|
|
|
.output = NULL,
|
|
|
|
};
|
|
|
|
|
2018-02-12 08:12:31 +00:00
|
|
|
wlr_signal_emit_safe(&surface->events.request_fullscreen, &event);
|
2017-08-08 21:22:11 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 20:27:14 +00:00
|
|
|
static void xdg_toplevel_protocol_set_minimized(struct wl_client *client,
|
2017-09-11 20:26:51 +00:00
|
|
|
struct wl_resource *resource) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
xdg_surface_from_xdg_toplevel_resource(resource);
|
2018-02-12 08:12:31 +00:00
|
|
|
wlr_signal_emit_safe(&surface->events.request_minimize, surface);
|
2017-08-08 21:22:11 +00:00
|
|
|
}
|
|
|
|
|
2017-09-11 20:26:51 +00:00
|
|
|
static const struct zxdg_toplevel_v6_interface zxdg_toplevel_v6_implementation =
|
|
|
|
{
|
2017-08-11 13:37:09 +00:00
|
|
|
.destroy = resource_destroy,
|
2017-09-14 20:27:14 +00:00
|
|
|
.set_parent = xdg_toplevel_protocol_set_parent,
|
|
|
|
.set_title = xdg_toplevel_protocol_set_title,
|
|
|
|
.set_app_id = xdg_toplevel_protocol_set_app_id,
|
|
|
|
.show_window_menu = xdg_toplevel_protocol_show_window_menu,
|
|
|
|
.move = xdg_toplevel_protocol_move,
|
|
|
|
.resize = xdg_toplevel_protocol_resize,
|
|
|
|
.set_max_size = xdg_toplevel_protocol_set_max_size,
|
|
|
|
.set_min_size = xdg_toplevel_protocol_set_min_size,
|
|
|
|
.set_maximized = xdg_toplevel_protocol_set_maximized,
|
|
|
|
.unset_maximized = xdg_toplevel_protocol_unset_maximized,
|
|
|
|
.set_fullscreen = xdg_toplevel_protocol_set_fullscreen,
|
|
|
|
.unset_fullscreen = xdg_toplevel_protocol_unset_fullscreen,
|
|
|
|
.set_minimized = xdg_toplevel_protocol_set_minimized
|
2017-08-08 21:22:11 +00:00
|
|
|
};
|
|
|
|
|
2017-09-11 21:24:55 +00:00
|
|
|
static void xdg_surface_resource_destroy(struct wl_resource *resource) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface = xdg_surface_from_resource(resource);
|
2017-09-11 21:24:55 +00:00
|
|
|
if (surface != NULL) {
|
|
|
|
xdg_surface_destroy(surface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-30 21:13:32 +00:00
|
|
|
static void xdg_toplevel_resource_destroy(struct wl_resource *resource) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface =
|
|
|
|
xdg_surface_from_xdg_toplevel_resource(resource);
|
2017-09-30 21:13:32 +00:00
|
|
|
if (surface != NULL) {
|
|
|
|
xdg_surface_destroy(surface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-08 12:09:14 +00:00
|
|
|
static void xdg_surface_get_toplevel(struct wl_client *client,
|
|
|
|
struct wl_resource *resource, uint32_t id) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface = xdg_surface_from_resource(resource);
|
2017-09-11 22:06:19 +00:00
|
|
|
|
2017-09-12 10:18:52 +00:00
|
|
|
if (wlr_surface_set_role(surface->surface, wlr_desktop_xdg_toplevel_role,
|
2017-09-11 22:06:19 +00:00
|
|
|
resource, ZXDG_SHELL_V6_ERROR_ROLE)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-17 00:31:34 +00:00
|
|
|
surface->toplevel_state = calloc(1, sizeof(struct wlr_xdg_toplevel_v6));
|
|
|
|
if (surface->toplevel_state == NULL) {
|
2017-11-02 22:14:24 +00:00
|
|
|
wl_resource_post_no_memory(resource);
|
2017-09-13 13:19:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-11 22:06:19 +00:00
|
|
|
surface->role = WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL;
|
2017-09-14 20:27:14 +00:00
|
|
|
surface->toplevel_state->base = surface;
|
2017-09-11 22:06:19 +00:00
|
|
|
|
2017-08-08 21:22:11 +00:00
|
|
|
struct wl_resource *toplevel_resource = wl_resource_create(client,
|
2017-08-09 16:23:38 +00:00
|
|
|
&zxdg_toplevel_v6_interface, wl_resource_get_version(resource), id);
|
2017-11-02 22:14:24 +00:00
|
|
|
if (toplevel_resource == NULL) {
|
|
|
|
free(surface->toplevel_state);
|
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-11 22:06:19 +00:00
|
|
|
|
2017-09-14 20:27:14 +00:00
|
|
|
surface->toplevel_state->resource = toplevel_resource;
|
|
|
|
|
2017-08-08 21:22:11 +00:00
|
|
|
wl_resource_set_implementation(toplevel_resource,
|
2017-09-30 21:13:32 +00:00
|
|
|
&zxdg_toplevel_v6_implementation, surface,
|
|
|
|
xdg_toplevel_resource_destroy);
|
2017-08-08 12:09:14 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 20:27:14 +00:00
|
|
|
static void wlr_xdg_toplevel_v6_ack_configure(
|
|
|
|
struct wlr_xdg_surface_v6 *surface,
|
|
|
|
struct wlr_xdg_surface_v6_configure *configure) {
|
|
|
|
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
|
2017-09-16 23:32:23 +00:00
|
|
|
surface->toplevel_state->next = configure->state;
|
|
|
|
surface->toplevel_state->pending.width = 0;
|
|
|
|
surface->toplevel_state->pending.height = 0;
|
2017-09-14 20:27:14 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 12:09:14 +00:00
|
|
|
static void xdg_surface_ack_configure(struct wl_client *client,
|
|
|
|
struct wl_resource *resource, uint32_t serial) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface = xdg_surface_from_resource(resource);
|
2017-09-14 20:27:14 +00:00
|
|
|
|
2017-09-16 18:33:07 +00:00
|
|
|
if (surface->role == WLR_XDG_SURFACE_V6_ROLE_NONE) {
|
|
|
|
wl_resource_post_error(surface->resource,
|
|
|
|
ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
|
|
|
|
"xdg_surface must have a role");
|
2017-09-14 20:27:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
struct wlr_xdg_surface_v6_configure *configure, *tmp;
|
|
|
|
wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) {
|
|
|
|
if (configure->serial < serial) {
|
|
|
|
wl_list_remove(&configure->link);
|
|
|
|
free(configure);
|
|
|
|
} else if (configure->serial == serial) {
|
|
|
|
wl_list_remove(&configure->link);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
2017-09-16 18:33:07 +00:00
|
|
|
wl_resource_post_error(surface->client->resource,
|
|
|
|
ZXDG_SHELL_V6_ERROR_INVALID_SURFACE_STATE,
|
|
|
|
"wrong configure serial: %u", serial);
|
2017-09-14 20:27:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-01 15:47:14 +00:00
|
|
|
switch (surface->role) {
|
|
|
|
case WLR_XDG_SURFACE_V6_ROLE_NONE:
|
|
|
|
assert(0 && "not reached");
|
|
|
|
break;
|
|
|
|
case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL:
|
2017-09-14 20:27:14 +00:00
|
|
|
wlr_xdg_toplevel_v6_ack_configure(surface, configure);
|
2017-10-01 15:47:14 +00:00
|
|
|
break;
|
|
|
|
case WLR_XDG_SURFACE_V6_ROLE_POPUP:
|
|
|
|
break;
|
2017-09-14 20:27:14 +00:00
|
|
|
}
|
|
|
|
|
2017-10-16 18:35:16 +00:00
|
|
|
surface->configured = true;
|
2017-11-17 22:52:42 +00:00
|
|
|
surface->configure_serial = serial;
|
2017-09-15 12:53:08 +00:00
|
|
|
|
2017-09-14 20:27:14 +00:00
|
|
|
free(configure);
|
2017-08-08 12:09:14 +00:00
|
|
|
}
|
2017-09-11 20:26:51 +00:00
|
|
|
|
2017-08-08 12:09:14 +00:00
|
|
|
static void xdg_surface_set_window_geometry(struct wl_client *client,
|
|
|
|
struct wl_resource *resource, int32_t x, int32_t y, int32_t width,
|
|
|
|
int32_t height) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface = xdg_surface_from_resource(resource);
|
2017-09-16 18:33:07 +00:00
|
|
|
|
|
|
|
if (surface->role == WLR_XDG_SURFACE_V6_ROLE_NONE) {
|
|
|
|
wl_resource_post_error(surface->resource,
|
|
|
|
ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
|
|
|
|
"xdg_surface must have a role");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-13 12:44:32 +00:00
|
|
|
surface->has_next_geometry = true;
|
|
|
|
surface->next_geometry->height = height;
|
|
|
|
surface->next_geometry->width = width;
|
|
|
|
surface->next_geometry->x = x;
|
|
|
|
surface->next_geometry->y = y;
|
2017-09-16 23:32:23 +00:00
|
|
|
|
2017-08-08 12:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct zxdg_surface_v6_interface zxdg_surface_v6_implementation = {
|
2017-08-11 13:37:09 +00:00
|
|
|
.destroy = resource_destroy,
|
2017-08-09 16:23:38 +00:00
|
|
|
.get_toplevel = xdg_surface_get_toplevel,
|
|
|
|
.get_popup = xdg_surface_get_popup,
|
|
|
|
.ack_configure = xdg_surface_ack_configure,
|
|
|
|
.set_window_geometry = xdg_surface_set_window_geometry,
|
2017-08-08 12:09:14 +00:00
|
|
|
};
|
|
|
|
|
2017-09-15 11:50:13 +00:00
|
|
|
static bool wlr_xdg_surface_v6_toplevel_state_compare(
|
|
|
|
struct wlr_xdg_toplevel_v6 *state) {
|
2017-10-19 14:15:56 +00:00
|
|
|
struct {
|
|
|
|
struct wlr_xdg_toplevel_v6_state state;
|
2018-02-16 17:38:06 +00:00
|
|
|
uint32_t width, height;
|
2017-10-19 14:15:56 +00:00
|
|
|
} configured;
|
|
|
|
|
2017-09-15 11:50:13 +00:00
|
|
|
// is pending state different from current state?
|
2017-10-17 13:22:50 +00:00
|
|
|
if (!state->base->configured) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-19 14:15:56 +00:00
|
|
|
if (wl_list_empty(&state->base->configure_list)) {
|
|
|
|
// last configure is actually the current state, just use it
|
|
|
|
configured.state = state->current;
|
|
|
|
configured.width = state->base->surface->current->width;
|
|
|
|
configured.height = state->base->surface->current->width;
|
|
|
|
} else {
|
|
|
|
struct wlr_xdg_surface_v6_configure *configure =
|
|
|
|
wl_container_of(state->base->configure_list.prev, configure, link);
|
|
|
|
configured.state = configure->state;
|
|
|
|
configured.width = configure->state.width;
|
|
|
|
configured.height = configure->state.height;
|
2017-10-18 09:05:21 +00:00
|
|
|
}
|
|
|
|
|
2017-10-19 14:15:56 +00:00
|
|
|
if (state->pending.activated != configured.state.activated) {
|
2017-09-15 11:50:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-10-19 14:15:56 +00:00
|
|
|
if (state->pending.fullscreen != configured.state.fullscreen) {
|
2017-09-15 11:50:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-10-19 14:15:56 +00:00
|
|
|
if (state->pending.maximized != configured.state.maximized) {
|
2017-09-15 11:50:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-10-19 14:15:56 +00:00
|
|
|
if (state->pending.resizing != configured.state.resizing) {
|
2017-09-15 11:50:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-19 14:15:56 +00:00
|
|
|
if (state->pending.width == configured.width &&
|
|
|
|
state->pending.height == configured.height) {
|
2017-09-15 11:50:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state->pending.width == 0 && state->pending.height == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wlr_xdg_toplevel_v6_send_configure(
|
|
|
|
struct wlr_xdg_surface_v6 *surface,
|
|
|
|
struct wlr_xdg_surface_v6_configure *configure) {
|
|
|
|
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
|
|
|
|
uint32_t *s;
|
|
|
|
struct wl_array states;
|
|
|
|
|
2017-09-16 23:32:23 +00:00
|
|
|
configure->state = surface->toplevel_state->pending;
|
2017-09-15 11:50:13 +00:00
|
|
|
|
|
|
|
wl_array_init(&states);
|
|
|
|
if (surface->toplevel_state->pending.maximized) {
|
|
|
|
s = wl_array_add(&states, sizeof(uint32_t));
|
2017-12-28 08:44:35 +00:00
|
|
|
if (!s) {
|
|
|
|
wlr_log(L_ERROR, "Could not allocate state for maximized xdg_toplevel");
|
2017-12-28 15:33:08 +00:00
|
|
|
goto error_out;
|
2017-12-28 08:44:35 +00:00
|
|
|
}
|
2017-12-28 15:08:45 +00:00
|
|
|
*s = ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED;
|
2017-09-15 11:50:13 +00:00
|
|
|
}
|
|
|
|
if (surface->toplevel_state->pending.fullscreen) {
|
|
|
|
s = wl_array_add(&states, sizeof(uint32_t));
|
2017-12-28 08:44:35 +00:00
|
|
|
if (!s) {
|
|
|
|
wlr_log(L_ERROR, "Could not allocate state for fullscreen xdg_toplevel");
|
2017-12-28 15:33:08 +00:00
|
|
|
goto error_out;
|
2017-12-28 08:44:35 +00:00
|
|
|
}
|
2017-12-28 15:08:45 +00:00
|
|
|
*s = ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN;
|
2017-09-15 11:50:13 +00:00
|
|
|
}
|
|
|
|
if (surface->toplevel_state->pending.resizing) {
|
|
|
|
s = wl_array_add(&states, sizeof(uint32_t));
|
2017-12-28 08:44:35 +00:00
|
|
|
if (!s) {
|
|
|
|
wlr_log(L_ERROR, "Could not allocate state for resizing xdg_toplevel");
|
2017-12-28 15:33:08 +00:00
|
|
|
goto error_out;
|
2017-12-28 08:44:35 +00:00
|
|
|
}
|
2017-12-28 15:08:45 +00:00
|
|
|
*s = ZXDG_TOPLEVEL_V6_STATE_RESIZING;
|
2017-09-15 11:50:13 +00:00
|
|
|
}
|
|
|
|
if (surface->toplevel_state->pending.activated) {
|
|
|
|
s = wl_array_add(&states, sizeof(uint32_t));
|
2017-12-28 08:44:35 +00:00
|
|
|
if (!s) {
|
|
|
|
wlr_log(L_ERROR, "Could not allocate state for activated xdg_toplevel");
|
2017-12-28 15:33:08 +00:00
|
|
|
goto error_out;
|
2017-12-28 08:44:35 +00:00
|
|
|
}
|
2017-12-28 15:08:45 +00:00
|
|
|
*s = ZXDG_TOPLEVEL_V6_STATE_ACTIVATED;
|
2017-09-15 11:50:13 +00:00
|
|
|
}
|
|
|
|
|
2017-09-16 23:32:23 +00:00
|
|
|
uint32_t width = surface->toplevel_state->pending.width;
|
|
|
|
uint32_t height = surface->toplevel_state->pending.height;
|
|
|
|
|
|
|
|
if (width == 0 || height == 0) {
|
|
|
|
width = surface->geometry->width;
|
|
|
|
height = surface->geometry->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
zxdg_toplevel_v6_send_configure(surface->toplevel_state->resource, width,
|
|
|
|
height, &states);
|
2017-09-15 11:50:13 +00:00
|
|
|
|
|
|
|
wl_array_release(&states);
|
2017-12-28 15:33:08 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
error_out:
|
|
|
|
wl_array_release(&states);
|
|
|
|
wl_resource_post_no_memory(surface->toplevel_state->resource);
|
2017-09-15 11:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void wlr_xdg_surface_send_configure(void *user_data) {
|
|
|
|
struct wlr_xdg_surface_v6 *surface = user_data;
|
|
|
|
|
|
|
|
surface->configure_idle = NULL;
|
|
|
|
|
|
|
|
struct wlr_xdg_surface_v6_configure *configure =
|
|
|
|
calloc(1, sizeof(struct wlr_xdg_surface_v6_configure));
|
2017-09-16 18:33:07 +00:00
|
|
|
if (configure == NULL) {
|
|
|
|
wl_client_post_no_memory(surface->client->client);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-15 11:50:13 +00:00
|
|
|
wl_list_insert(surface->configure_list.prev, &configure->link);
|
2017-11-17 22:52:42 +00:00
|
|
|
configure->serial = surface->configure_next_serial;
|
2017-09-15 11:50:13 +00:00
|
|
|
|
2017-10-01 15:47:14 +00:00
|
|
|
switch (surface->role) {
|
|
|
|
case WLR_XDG_SURFACE_V6_ROLE_NONE:
|
|
|
|
assert(0 && "not reached");
|
|
|
|
break;
|
|
|
|
case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL:
|
|
|
|
wlr_xdg_toplevel_v6_send_configure(surface, configure);
|
|
|
|
break;
|
|
|
|
case WLR_XDG_SURFACE_V6_ROLE_POPUP:
|
|
|
|
zxdg_popup_v6_send_configure(surface->popup_state->resource,
|
|
|
|
surface->popup_state->geometry.x,
|
|
|
|
surface->popup_state->geometry.y,
|
|
|
|
surface->popup_state->geometry.width,
|
|
|
|
surface->popup_state->geometry.height);
|
|
|
|
break;
|
|
|
|
}
|
2017-09-15 11:50:13 +00:00
|
|
|
|
|
|
|
zxdg_surface_v6_send_configure(surface->resource, configure->serial);
|
|
|
|
}
|
|
|
|
|
2017-11-17 22:52:42 +00:00
|
|
|
static uint32_t wlr_xdg_surface_v6_schedule_configure(
|
2017-10-18 09:05:21 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface) {
|
2017-09-16 16:35:49 +00:00
|
|
|
struct wl_display *display = wl_client_get_display(surface->client->client);
|
2017-09-15 11:50:13 +00:00
|
|
|
struct wl_event_loop *loop = wl_display_get_event_loop(display);
|
2017-10-01 15:47:14 +00:00
|
|
|
bool pending_same = false;
|
2017-09-15 11:50:13 +00:00
|
|
|
|
2017-10-01 15:47:14 +00:00
|
|
|
switch (surface->role) {
|
|
|
|
case WLR_XDG_SURFACE_V6_ROLE_NONE:
|
|
|
|
assert(0 && "not reached");
|
|
|
|
break;
|
|
|
|
case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL:
|
2017-10-18 09:05:21 +00:00
|
|
|
pending_same =
|
2017-10-01 15:47:14 +00:00
|
|
|
wlr_xdg_surface_v6_toplevel_state_compare(surface->toplevel_state);
|
|
|
|
break;
|
|
|
|
case WLR_XDG_SURFACE_V6_ROLE_POPUP:
|
|
|
|
break;
|
|
|
|
}
|
2017-09-15 11:50:13 +00:00
|
|
|
|
|
|
|
if (surface->configure_idle != NULL) {
|
|
|
|
if (!pending_same) {
|
|
|
|
// configure request already scheduled
|
2017-11-17 22:52:42 +00:00
|
|
|
return surface->configure_next_serial;
|
2017-09-15 11:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// configure request not necessary anymore
|
|
|
|
wl_event_source_remove(surface->configure_idle);
|
|
|
|
surface->configure_idle = NULL;
|
2017-11-17 22:52:42 +00:00
|
|
|
return 0;
|
2017-09-15 11:50:13 +00:00
|
|
|
} else {
|
|
|
|
if (pending_same) {
|
|
|
|
// configure request not necessary
|
2017-11-17 22:52:42 +00:00
|
|
|
return 0;
|
2017-09-15 11:50:13 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 22:52:42 +00:00
|
|
|
surface->configure_next_serial = wl_display_next_serial(display);
|
|
|
|
surface->configure_idle = wl_event_loop_add_idle(loop,
|
|
|
|
wlr_xdg_surface_send_configure, surface);
|
|
|
|
return surface->configure_next_serial;
|
2017-09-15 11:50:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-11 21:24:55 +00:00
|
|
|
static void handle_wlr_surface_destroyed(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct wlr_xdg_surface_v6 *xdg_surface =
|
|
|
|
wl_container_of(listener, xdg_surface, surface_destroy_listener);
|
|
|
|
xdg_surface_destroy(xdg_surface);
|
|
|
|
}
|
|
|
|
|
2017-09-13 13:19:10 +00:00
|
|
|
static void wlr_xdg_surface_v6_toplevel_committed(
|
|
|
|
struct wlr_xdg_surface_v6 *surface) {
|
2017-09-17 00:31:34 +00:00
|
|
|
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
|
|
|
|
|
2017-10-23 01:07:32 +00:00
|
|
|
if (!wlr_surface_has_buffer(surface->surface)
|
|
|
|
&& !surface->toplevel_state->added) {
|
2017-09-15 11:50:13 +00:00
|
|
|
// on the first commit, send a configure request to tell the client it
|
|
|
|
// is added
|
2017-10-18 09:05:21 +00:00
|
|
|
wlr_xdg_surface_v6_schedule_configure(surface);
|
2017-09-15 11:50:13 +00:00
|
|
|
surface->toplevel_state->added = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-23 01:07:32 +00:00
|
|
|
if (!wlr_surface_has_buffer(surface->surface)) {
|
2017-09-16 18:33:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-16 23:32:23 +00:00
|
|
|
surface->toplevel_state->current = surface->toplevel_state->next;
|
2017-09-13 13:19:10 +00:00
|
|
|
}
|
|
|
|
|
2017-10-01 15:47:14 +00:00
|
|
|
static void wlr_xdg_surface_v6_popup_committed(
|
|
|
|
struct wlr_xdg_surface_v6 *surface) {
|
|
|
|
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP);
|
|
|
|
|
|
|
|
if (!surface->popup_state->committed) {
|
2017-10-18 09:05:21 +00:00
|
|
|
wlr_xdg_surface_v6_schedule_configure(surface);
|
2017-10-01 15:47:14 +00:00
|
|
|
surface->popup_state->committed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-27 11:15:25 +00:00
|
|
|
static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface,
|
|
|
|
void *role_data) {
|
|
|
|
struct wlr_xdg_surface_v6 *surface = role_data;
|
2017-09-13 12:44:32 +00:00
|
|
|
|
2017-10-23 01:07:32 +00:00
|
|
|
if (wlr_surface_has_buffer(surface->surface) && !surface->configured) {
|
2017-09-16 18:33:07 +00:00
|
|
|
wl_resource_post_error(surface->resource,
|
|
|
|
ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER,
|
|
|
|
"xdg_surface has never been configured");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-13 12:44:32 +00:00
|
|
|
if (surface->has_next_geometry) {
|
|
|
|
surface->has_next_geometry = false;
|
|
|
|
surface->geometry->x = surface->next_geometry->x;
|
|
|
|
surface->geometry->y = surface->next_geometry->y;
|
|
|
|
surface->geometry->width = surface->next_geometry->width;
|
|
|
|
surface->geometry->height = surface->next_geometry->height;
|
|
|
|
}
|
2017-09-13 13:19:10 +00:00
|
|
|
|
2017-09-16 18:33:07 +00:00
|
|
|
switch (surface->role) {
|
|
|
|
case WLR_XDG_SURFACE_V6_ROLE_NONE:
|
|
|
|
wl_resource_post_error(surface->resource,
|
|
|
|
ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
|
|
|
|
"xdg_surface must have a role");
|
|
|
|
break;
|
|
|
|
case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL:
|
2017-09-13 13:19:10 +00:00
|
|
|
wlr_xdg_surface_v6_toplevel_committed(surface);
|
2017-09-16 18:33:07 +00:00
|
|
|
break;
|
|
|
|
case WLR_XDG_SURFACE_V6_ROLE_POPUP:
|
2017-10-01 15:47:14 +00:00
|
|
|
wlr_xdg_surface_v6_popup_committed(surface);
|
2017-09-16 18:33:07 +00:00
|
|
|
break;
|
2017-09-13 13:19:10 +00:00
|
|
|
}
|
2017-09-14 12:39:57 +00:00
|
|
|
|
2017-10-16 18:35:16 +00:00
|
|
|
if (surface->configured && !surface->added) {
|
|
|
|
surface->added = true;
|
2018-02-12 08:12:31 +00:00
|
|
|
wlr_signal_emit_safe(&surface->client->shell->events.new_surface, surface);
|
2017-10-16 18:35:16 +00:00
|
|
|
}
|
2017-09-12 10:18:52 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 22:48:46 +00:00
|
|
|
static const struct zxdg_shell_v6_interface xdg_shell_impl;
|
|
|
|
|
|
|
|
static struct wlr_xdg_client_v6 *xdg_client_from_resource(
|
|
|
|
struct wl_resource *resource) {
|
|
|
|
assert(wl_resource_instance_of(resource, &zxdg_shell_v6_interface,
|
|
|
|
&xdg_shell_impl));
|
|
|
|
return wl_resource_get_user_data(resource);
|
|
|
|
}
|
|
|
|
|
2017-09-16 16:35:49 +00:00
|
|
|
static void xdg_shell_get_xdg_surface(struct wl_client *wl_client,
|
|
|
|
struct wl_resource *client_resource, uint32_t id,
|
|
|
|
struct wl_resource *surface_resource) {
|
|
|
|
struct wlr_xdg_client_v6 *client =
|
2018-02-13 22:48:46 +00:00
|
|
|
xdg_client_from_resource(client_resource);
|
2017-09-16 18:33:07 +00:00
|
|
|
|
2017-08-15 05:56:47 +00:00
|
|
|
struct wlr_xdg_surface_v6 *surface;
|
|
|
|
if (!(surface = calloc(1, sizeof(struct wlr_xdg_surface_v6)))) {
|
2017-09-16 16:35:49 +00:00
|
|
|
wl_client_post_no_memory(wl_client);
|
2017-08-15 05:56:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-09-13 12:44:32 +00:00
|
|
|
|
|
|
|
if (!(surface->geometry = calloc(1, sizeof(struct wlr_box)))) {
|
|
|
|
free(surface);
|
2017-09-16 16:35:49 +00:00
|
|
|
wl_client_post_no_memory(wl_client);
|
2017-09-13 12:44:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(surface->next_geometry = calloc(1, sizeof(struct wlr_box)))) {
|
|
|
|
free(surface->geometry);
|
|
|
|
free(surface);
|
2017-09-16 16:35:49 +00:00
|
|
|
wl_client_post_no_memory(wl_client);
|
2017-09-13 12:44:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-14 20:27:14 +00:00
|
|
|
surface->client = client;
|
2017-09-11 22:06:19 +00:00
|
|
|
surface->role = WLR_XDG_SURFACE_V6_ROLE_NONE;
|
2018-02-13 22:48:46 +00:00
|
|
|
surface->surface = wlr_surface_from_resource(surface_resource);
|
2017-09-16 16:35:49 +00:00
|
|
|
surface->resource = wl_resource_create(wl_client,
|
|
|
|
&zxdg_surface_v6_interface, wl_resource_get_version(client_resource),
|
|
|
|
id);
|
2017-11-02 22:14:24 +00:00
|
|
|
if (surface->resource == NULL) {
|
|
|
|
free(surface->next_geometry);
|
|
|
|
free(surface->geometry);
|
|
|
|
free(surface);
|
|
|
|
wl_client_post_no_memory(wl_client);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-11 21:24:55 +00:00
|
|
|
|
2017-10-23 01:07:32 +00:00
|
|
|
if (wlr_surface_has_buffer(surface->surface)) {
|
2017-11-02 22:14:24 +00:00
|
|
|
wl_resource_destroy(surface->resource);
|
|
|
|
free(surface->next_geometry);
|
|
|
|
free(surface->geometry);
|
|
|
|
free(surface);
|
|
|
|
wl_resource_post_error(surface_resource,
|
2017-09-16 18:33:07 +00:00
|
|
|
ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER,
|
|
|
|
"xdg_surface must not have a buffer at creation");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-14 20:27:14 +00:00
|
|
|
wl_list_init(&surface->configure_list);
|
2017-10-02 13:15:21 +00:00
|
|
|
wl_list_init(&surface->popups);
|
2017-09-14 20:27:14 +00:00
|
|
|
|
2017-11-09 20:41:11 +00:00
|
|
|
wl_signal_init(&surface->events.request_maximize);
|
|
|
|
wl_signal_init(&surface->events.request_fullscreen);
|
2017-09-14 12:39:57 +00:00
|
|
|
wl_signal_init(&surface->events.request_minimize);
|
2017-09-16 12:31:08 +00:00
|
|
|
wl_signal_init(&surface->events.request_move);
|
|
|
|
wl_signal_init(&surface->events.request_resize);
|
|
|
|
wl_signal_init(&surface->events.request_show_window_menu);
|
2017-09-14 12:39:57 +00:00
|
|
|
wl_signal_init(&surface->events.destroy);
|
2017-09-16 16:35:49 +00:00
|
|
|
wl_signal_init(&surface->events.ping_timeout);
|
2018-01-21 20:06:37 +00:00
|
|
|
wl_signal_init(&surface->events.new_popup);
|
2017-09-14 12:39:57 +00:00
|
|
|
|
2017-10-08 17:12:28 +00:00
|
|
|
wl_signal_add(&surface->surface->events.destroy,
|
2017-09-11 21:24:55 +00:00
|
|
|
&surface->surface_destroy_listener);
|
|
|
|
surface->surface_destroy_listener.notify = handle_wlr_surface_destroyed;
|
|
|
|
|
2017-12-27 11:15:25 +00:00
|
|
|
wlr_surface_set_role_committed(surface->surface,
|
|
|
|
handle_wlr_surface_committed, surface);
|
2017-09-12 10:18:52 +00:00
|
|
|
|
2017-08-20 11:41:15 +00:00
|
|
|
wlr_log(L_DEBUG, "new xdg_surface %p (res %p)", surface, surface->resource);
|
2017-08-11 13:37:09 +00:00
|
|
|
wl_resource_set_implementation(surface->resource,
|
2017-09-11 21:24:55 +00:00
|
|
|
&zxdg_surface_v6_implementation, surface, xdg_surface_resource_destroy);
|
2017-09-16 16:35:49 +00:00
|
|
|
wl_list_insert(&client->surfaces, &surface->link);
|
2017-08-08 12:09:14 +00:00
|
|
|
}
|
|
|
|
|
2017-09-16 16:35:49 +00:00
|
|
|
static void xdg_shell_pong(struct wl_client *wl_client,
|
2017-08-11 13:37:09 +00:00
|
|
|
struct wl_resource *resource, uint32_t serial) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_client_v6 *client = xdg_client_from_resource(resource);
|
2017-09-16 16:35:49 +00:00
|
|
|
|
|
|
|
if (client->ping_serial != serial) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_event_source_timer_update(client->ping_timer, 0);
|
|
|
|
client->ping_serial = 0;
|
2017-08-08 12:09:14 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 22:48:46 +00:00
|
|
|
static const struct zxdg_shell_v6_interface xdg_shell_impl = {
|
2017-10-02 10:28:07 +00:00
|
|
|
.destroy = resource_destroy,
|
2017-08-09 21:30:22 +00:00
|
|
|
.create_positioner = xdg_shell_create_positioner,
|
|
|
|
.get_xdg_surface = xdg_shell_get_xdg_surface,
|
|
|
|
.pong = xdg_shell_pong,
|
2017-08-08 12:09:14 +00:00
|
|
|
};
|
|
|
|
|
2017-09-16 16:35:49 +00:00
|
|
|
static void wlr_xdg_client_v6_destroy(struct wl_resource *resource) {
|
2018-02-13 22:48:46 +00:00
|
|
|
struct wlr_xdg_client_v6 *client = xdg_client_from_resource(resource);
|
2017-09-17 13:42:27 +00:00
|
|
|
|
|
|
|
struct wlr_xdg_surface_v6 *surface, *tmp = NULL;
|
|
|
|
wl_list_for_each_safe(surface, tmp, &client->surfaces, link) {
|
2017-10-11 16:01:36 +00:00
|
|
|
xdg_surface_destroy(surface);
|
2017-09-16 16:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (client->ping_timer != NULL) {
|
|
|
|
wl_event_source_remove(client->ping_timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_remove(&client->link);
|
|
|
|
free(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wlr_xdg_client_v6_ping_timeout(void *user_data) {
|
|
|
|
struct wlr_xdg_client_v6 *client = user_data;
|
|
|
|
|
|
|
|
struct wlr_xdg_surface_v6 *surface;
|
|
|
|
wl_list_for_each(surface, &client->surfaces, link) {
|
2018-02-12 08:12:31 +00:00
|
|
|
wlr_signal_emit_safe(&surface->events.ping_timeout, surface);
|
2017-09-16 16:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
client->ping_serial = 0;
|
|
|
|
return 1;
|
2017-08-15 13:38:30 +00:00
|
|
|
}
|
|
|
|
|
2017-11-02 22:14:24 +00:00
|
|
|
static void xdg_shell_bind(struct wl_client *wl_client, void *data,
|
2017-08-08 12:09:14 +00:00
|
|
|
uint32_t version, uint32_t id) {
|
2017-11-02 22:14:24 +00:00
|
|
|
struct wlr_xdg_shell_v6 *xdg_shell = data;
|
2017-08-11 13:37:09 +00:00
|
|
|
assert(wl_client && xdg_shell);
|
2017-10-22 09:18:27 +00:00
|
|
|
|
2017-09-16 16:35:49 +00:00
|
|
|
struct wlr_xdg_client_v6 *client =
|
|
|
|
calloc(1, sizeof(struct wlr_xdg_client_v6));
|
|
|
|
if (client == NULL) {
|
|
|
|
wl_client_post_no_memory(wl_client);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_init(&client->surfaces);
|
|
|
|
|
|
|
|
client->resource =
|
|
|
|
wl_resource_create(wl_client, &zxdg_shell_v6_interface, version, id);
|
2017-11-02 22:14:24 +00:00
|
|
|
if (client->resource == NULL) {
|
|
|
|
free(client);
|
|
|
|
wl_client_post_no_memory(wl_client);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-16 16:35:49 +00:00
|
|
|
client->client = wl_client;
|
|
|
|
client->shell = xdg_shell;
|
|
|
|
|
|
|
|
wl_resource_set_implementation(client->resource, &xdg_shell_impl, client,
|
|
|
|
wlr_xdg_client_v6_destroy);
|
|
|
|
wl_list_insert(&xdg_shell->clients, &client->link);
|
|
|
|
|
|
|
|
struct wl_display *display = wl_client_get_display(client->client);
|
|
|
|
struct wl_event_loop *loop = wl_display_get_event_loop(display);
|
|
|
|
client->ping_timer = wl_event_loop_add_timer(loop,
|
|
|
|
wlr_xdg_client_v6_ping_timeout, client);
|
|
|
|
if (client->ping_timer == NULL) {
|
|
|
|
wl_client_post_no_memory(client->client);
|
|
|
|
}
|
2017-08-08 12:09:14 +00:00
|
|
|
}
|
|
|
|
|
2017-12-07 00:08:35 +00:00
|
|
|
static void handle_display_destroy(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_xdg_shell_v6 *xdg_shell =
|
|
|
|
wl_container_of(listener, xdg_shell, display_destroy);
|
|
|
|
wlr_xdg_shell_v6_destroy(xdg_shell);
|
|
|
|
}
|
|
|
|
|
2017-08-15 13:33:54 +00:00
|
|
|
struct wlr_xdg_shell_v6 *wlr_xdg_shell_v6_create(struct wl_display *display) {
|
2017-08-11 13:37:09 +00:00
|
|
|
struct wlr_xdg_shell_v6 *xdg_shell =
|
|
|
|
calloc(1, sizeof(struct wlr_xdg_shell_v6));
|
|
|
|
if (!xdg_shell) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-09-16 16:35:49 +00:00
|
|
|
|
|
|
|
xdg_shell->ping_timeout = 10000;
|
|
|
|
|
|
|
|
wl_list_init(&xdg_shell->clients);
|
2017-10-06 10:54:43 +00:00
|
|
|
wl_list_init(&xdg_shell->popup_grabs);
|
2017-09-16 16:35:49 +00:00
|
|
|
|
2017-08-08 12:09:14 +00:00
|
|
|
struct wl_global *wl_global = wl_global_create(display,
|
2017-08-11 13:37:09 +00:00
|
|
|
&zxdg_shell_v6_interface, 1, xdg_shell, xdg_shell_bind);
|
|
|
|
if (!wl_global) {
|
2017-08-15 13:33:54 +00:00
|
|
|
free(xdg_shell);
|
2017-08-11 13:37:09 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
xdg_shell->wl_global = wl_global;
|
2017-09-15 12:53:08 +00:00
|
|
|
|
|
|
|
wl_signal_init(&xdg_shell->events.new_surface);
|
|
|
|
|
2017-12-07 00:08:35 +00:00
|
|
|
xdg_shell->display_destroy.notify = handle_display_destroy;
|
|
|
|
wl_display_add_destroy_listener(display, &xdg_shell->display_destroy);
|
|
|
|
|
2017-08-11 13:37:09 +00:00
|
|
|
return xdg_shell;
|
2017-08-08 12:09:14 +00:00
|
|
|
}
|
2017-08-09 14:55:23 +00:00
|
|
|
|
2017-08-11 13:37:09 +00:00
|
|
|
void wlr_xdg_shell_v6_destroy(struct wlr_xdg_shell_v6 *xdg_shell) {
|
|
|
|
if (!xdg_shell) {
|
2017-08-09 14:55:23 +00:00
|
|
|
return;
|
2017-08-09 16:23:38 +00:00
|
|
|
}
|
2017-12-07 00:08:35 +00:00
|
|
|
wl_list_remove(&xdg_shell->display_destroy.link);
|
|
|
|
wl_global_destroy(xdg_shell->wl_global);
|
2017-08-11 13:37:09 +00:00
|
|
|
free(xdg_shell);
|
2017-08-09 14:55:23 +00:00
|
|
|
}
|
2017-09-14 20:27:14 +00:00
|
|
|
|
2017-09-16 16:35:49 +00:00
|
|
|
void wlr_xdg_surface_v6_ping(struct wlr_xdg_surface_v6 *surface) {
|
|
|
|
if (surface->client->ping_serial != 0) {
|
|
|
|
// already pinged
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
surface->client->ping_serial =
|
|
|
|
wl_display_next_serial(wl_client_get_display(surface->client->client));
|
|
|
|
wl_event_source_timer_update(surface->client->ping_timer,
|
|
|
|
surface->client->shell->ping_timeout);
|
|
|
|
zxdg_shell_v6_send_ping(surface->client->resource,
|
|
|
|
surface->client->ping_serial);
|
|
|
|
}
|
|
|
|
|
2017-11-17 22:52:42 +00:00
|
|
|
uint32_t wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface,
|
2017-09-14 20:27:14 +00:00
|
|
|
uint32_t width, uint32_t height) {
|
|
|
|
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
|
|
|
|
surface->toplevel_state->pending.width = width;
|
|
|
|
surface->toplevel_state->pending.height = height;
|
|
|
|
|
2017-11-17 22:52:42 +00:00
|
|
|
return wlr_xdg_surface_v6_schedule_configure(surface);
|
2017-09-14 20:27:14 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 22:52:42 +00:00
|
|
|
uint32_t wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface,
|
2017-09-14 20:27:14 +00:00
|
|
|
bool activated) {
|
|
|
|
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
|
|
|
|
surface->toplevel_state->pending.activated = activated;
|
|
|
|
|
2017-11-17 22:52:42 +00:00
|
|
|
return wlr_xdg_surface_v6_schedule_configure(surface);
|
2017-09-14 20:27:14 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 22:52:42 +00:00
|
|
|
uint32_t wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface,
|
2017-09-14 20:27:14 +00:00
|
|
|
bool maximized) {
|
|
|
|
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
|
|
|
|
surface->toplevel_state->pending.maximized = maximized;
|
|
|
|
|
2017-11-17 22:52:42 +00:00
|
|
|
return wlr_xdg_surface_v6_schedule_configure(surface);
|
2017-09-14 20:27:14 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 22:52:42 +00:00
|
|
|
uint32_t wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface,
|
2017-09-14 20:27:14 +00:00
|
|
|
bool fullscreen) {
|
|
|
|
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
|
|
|
|
surface->toplevel_state->pending.fullscreen = fullscreen;
|
|
|
|
|
2017-11-17 22:52:42 +00:00
|
|
|
return wlr_xdg_surface_v6_schedule_configure(surface);
|
2017-09-14 20:27:14 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 22:52:42 +00:00
|
|
|
uint32_t wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface,
|
2017-09-14 20:27:14 +00:00
|
|
|
bool resizing) {
|
|
|
|
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
|
2017-10-17 13:22:50 +00:00
|
|
|
surface->toplevel_state->pending.resizing = resizing;
|
2017-09-14 20:27:14 +00:00
|
|
|
|
2017-11-17 22:52:42 +00:00
|
|
|
return wlr_xdg_surface_v6_schedule_configure(surface);
|
2017-09-14 20:27:14 +00:00
|
|
|
}
|
2017-10-06 13:58:49 +00:00
|
|
|
|
|
|
|
void wlr_xdg_toplevel_v6_send_close(struct wlr_xdg_surface_v6 *surface) {
|
|
|
|
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
|
|
|
|
zxdg_toplevel_v6_send_close(surface->toplevel_state->resource);
|
|
|
|
}
|
2017-10-09 20:51:55 +00:00
|
|
|
|
2017-11-15 13:03:13 +00:00
|
|
|
void wlr_xdg_surface_v6_popup_get_position(struct wlr_xdg_surface_v6 *surface,
|
|
|
|
double *popup_sx, double *popup_sy) {
|
|
|
|
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP);
|
|
|
|
struct wlr_xdg_surface_v6 *parent = surface->popup_state->parent;
|
|
|
|
*popup_sx = parent->geometry->x + surface->popup_state->geometry.x -
|
|
|
|
surface->geometry->x;
|
|
|
|
*popup_sy = parent->geometry->y + surface->popup_state->geometry.y -
|
|
|
|
surface->geometry->y;
|
|
|
|
}
|
|
|
|
|
2017-10-09 20:51:55 +00:00
|
|
|
struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at(
|
|
|
|
struct wlr_xdg_surface_v6 *surface, double sx, double sy,
|
|
|
|
double *popup_sx, double *popup_sy) {
|
|
|
|
// XXX: I think this is so complicated because we're mixing geometry
|
|
|
|
// coordinates with surface coordinates. Input handling should only deal
|
|
|
|
// with surface coordinates.
|
2018-01-21 20:06:37 +00:00
|
|
|
struct wlr_xdg_popup_v6 *popup_state;
|
|
|
|
wl_list_for_each(popup_state, &surface->popups, link) {
|
|
|
|
struct wlr_xdg_surface_v6 *popup = popup_state->base;
|
|
|
|
|
2017-10-09 20:51:55 +00:00
|
|
|
double _popup_sx =
|
2018-01-21 20:06:37 +00:00
|
|
|
surface->geometry->x + popup_state->geometry.x;
|
2017-10-09 20:51:55 +00:00
|
|
|
double _popup_sy =
|
2018-01-21 20:06:37 +00:00
|
|
|
surface->geometry->y + popup_state->geometry.y;
|
|
|
|
int popup_width = popup_state->geometry.width;
|
|
|
|
int popup_height = popup_state->geometry.height;
|
2017-10-09 20:51:55 +00:00
|
|
|
|
|
|
|
struct wlr_xdg_surface_v6 *_popup =
|
|
|
|
wlr_xdg_surface_v6_popup_at(popup,
|
|
|
|
sx - _popup_sx + popup->geometry->x,
|
|
|
|
sy - _popup_sy + popup->geometry->y,
|
|
|
|
popup_sx, popup_sy);
|
|
|
|
if (_popup) {
|
|
|
|
*popup_sx = *popup_sx + _popup_sx - popup->geometry->x;
|
|
|
|
*popup_sy = *popup_sy + _popup_sy - popup->geometry->y;
|
|
|
|
return _popup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((sx > _popup_sx && sx < _popup_sx + popup_width) &&
|
|
|
|
(sy > _popup_sy && sy < _popup_sy + popup_height)) {
|
|
|
|
if (pixman_region32_contains_point(&popup->surface->current->input,
|
|
|
|
sx - _popup_sx + popup->geometry->x,
|
|
|
|
sy - _popup_sy + popup->geometry->y, NULL)) {
|
|
|
|
*popup_sx = _popup_sx - popup->geometry->x;
|
|
|
|
*popup_sy = _popup_sy - popup->geometry->y;
|
|
|
|
return popup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|