mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-03-05 01:41:03 -05:00
merge in upstream
This commit is contained in:
commit
3576eec3cf
154 changed files with 4860 additions and 4410 deletions
|
|
@ -11,11 +11,6 @@ wlr_files += files(
|
|||
'tablet_v2/wlr_tablet_v2_tablet.c',
|
||||
'tablet_v2/wlr_tablet_v2_tool.c',
|
||||
'tablet_v2/wlr_tablet_v2.c',
|
||||
'xdg_shell_v6/wlr_xdg_popup_v6.c',
|
||||
'xdg_shell_v6/wlr_xdg_positioner_v6.c',
|
||||
'xdg_shell_v6/wlr_xdg_shell_v6.c',
|
||||
'xdg_shell_v6/wlr_xdg_surface_v6.c',
|
||||
'xdg_shell_v6/wlr_xdg_toplevel_v6.c',
|
||||
'xdg_shell/wlr_xdg_popup.c',
|
||||
'xdg_shell/wlr_xdg_positioner.c',
|
||||
'xdg_shell/wlr_xdg_shell.c',
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ void wlr_seat_keyboard_enter(struct wlr_seat *seat,
|
|||
for (size_t i = 0; i < num_keycodes; ++i) {
|
||||
uint32_t *p = wl_array_add(&keys, sizeof(uint32_t));
|
||||
if (!p) {
|
||||
wlr_log(WLR_ERROR, "Cannot allocate memory, skipping keycode: %d\n",
|
||||
wlr_log(WLR_ERROR, "Cannot allocate memory, skipping keycode: %" PRIu32 "\n",
|
||||
keycodes[i]);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -449,7 +449,7 @@ void seat_client_create_keyboard(struct wlr_seat_client *seat_client,
|
|||
for (size_t i = 0; i < num_keycodes; ++i) {
|
||||
uint32_t *p = wl_array_add(&keys, sizeof(uint32_t));
|
||||
if (!p) {
|
||||
wlr_log(WLR_ERROR, "Cannot allocate memory, skipping keycode: %d\n",
|
||||
wlr_log(WLR_ERROR, "Cannot allocate memory, skipping keycode: %" PRIu32 "\n",
|
||||
keycodes[i]);
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include <types/wlr_tablet_v2.h>
|
||||
#include <wayland-util.h>
|
||||
#include <wlr/types/wlr_tablet_tool.h>
|
||||
#include <wlr/types/wlr_tablet_pad.h>
|
||||
#include <wlr/types/wlr_tablet_v2.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -96,10 +96,18 @@ bool wlr_resource_get_buffer_size(struct wl_resource *resource,
|
|||
|
||||
static const struct wlr_buffer_impl client_buffer_impl;
|
||||
|
||||
struct wlr_client_buffer *wlr_client_buffer_get(struct wlr_buffer *buffer) {
|
||||
if (buffer->impl != &client_buffer_impl) {
|
||||
return NULL;
|
||||
}
|
||||
return (struct wlr_client_buffer *)buffer;
|
||||
}
|
||||
|
||||
static struct wlr_client_buffer *client_buffer_from_buffer(
|
||||
struct wlr_buffer *buffer) {
|
||||
assert(buffer->impl == &client_buffer_impl);
|
||||
return (struct wlr_client_buffer *) buffer;
|
||||
struct wlr_client_buffer *client_buffer = wlr_client_buffer_get(buffer);
|
||||
assert(client_buffer != NULL);
|
||||
return client_buffer;
|
||||
}
|
||||
|
||||
static void client_buffer_destroy(struct wlr_buffer *_buffer) {
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ static void subcompositor_handle_get_subsurface(struct wl_client *client,
|
|||
if (surface == parent) {
|
||||
wl_resource_post_error(resource,
|
||||
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
|
||||
"%s%d: wl_surface@%d cannot be its own parent",
|
||||
"%s%" PRIu32 ": wl_surface@%" PRIu32 " cannot be its own parent",
|
||||
msg, id, wl_resource_get_id(surface_resource));
|
||||
return;
|
||||
}
|
||||
|
|
@ -48,7 +48,7 @@ static void subcompositor_handle_get_subsurface(struct wl_client *client,
|
|||
wlr_subsurface_from_wlr_surface(surface) != NULL) {
|
||||
wl_resource_post_error(resource,
|
||||
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
|
||||
"%s%d: wl_surface@%d is already a sub-surface",
|
||||
"%s%" PRIu32 ": wl_surface@%" PRIu32 " is already a sub-surface",
|
||||
msg, id, wl_resource_get_id(surface_resource));
|
||||
return;
|
||||
}
|
||||
|
|
@ -56,7 +56,7 @@ static void subcompositor_handle_get_subsurface(struct wl_client *client,
|
|||
if (wlr_surface_get_root_surface(parent) == surface) {
|
||||
wl_resource_post_error(resource,
|
||||
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
|
||||
"%s%d: wl_surface@%d is an ancestor of parent",
|
||||
"%s%" PRIu32 ": wl_surface@%" PRIu32 " is an ancestor of parent",
|
||||
msg, id, wl_resource_get_id(surface_resource));
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@
|
|||
#include <wlr/types/wlr_input_device.h>
|
||||
#include <wlr/types/wlr_output_layout.h>
|
||||
#include <wlr/types/wlr_output.h>
|
||||
#include <wlr/types/wlr_pointer.h>
|
||||
#include <wlr/types/wlr_tablet_tool.h>
|
||||
#include <wlr/types/wlr_touch.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "util/signal.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -41,8 +41,7 @@ static void frame_destroy(struct wlr_export_dmabuf_frame_v1 *frame) {
|
|||
}
|
||||
}
|
||||
wl_list_remove(&frame->link);
|
||||
wl_list_remove(&frame->output_precommit.link);
|
||||
wlr_dmabuf_attributes_finish(&frame->attribs);
|
||||
wl_list_remove(&frame->output_commit.link);
|
||||
// Make the frame resource inert
|
||||
wl_resource_set_user_data(frame->resource, NULL);
|
||||
free(frame);
|
||||
|
|
@ -53,18 +52,41 @@ static void frame_handle_resource_destroy(struct wl_resource *resource) {
|
|||
frame_destroy(frame);
|
||||
}
|
||||
|
||||
static void frame_output_handle_precommit(struct wl_listener *listener,
|
||||
static void frame_output_handle_commit(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_export_dmabuf_frame_v1 *frame =
|
||||
wl_container_of(listener, frame, output_precommit);
|
||||
struct wlr_output_event_precommit *event = data;
|
||||
wl_container_of(listener, frame, output_commit);
|
||||
struct wlr_output_event_commit *event = data;
|
||||
|
||||
if (!(event->output->pending.committed & WLR_OUTPUT_STATE_BUFFER)) {
|
||||
if (!(event->committed & WLR_OUTPUT_STATE_BUFFER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
wl_list_remove(&frame->output_precommit.link);
|
||||
wl_list_init(&frame->output_precommit.link);
|
||||
wl_list_remove(&frame->output_commit.link);
|
||||
wl_list_init(&frame->output_commit.link);
|
||||
|
||||
struct wlr_dmabuf_attributes attribs = {0};
|
||||
if (!wlr_output_export_dmabuf(frame->output, &attribs)) {
|
||||
zwlr_export_dmabuf_frame_v1_send_cancel(frame->resource,
|
||||
ZWLR_EXPORT_DMABUF_FRAME_V1_CANCEL_REASON_TEMPORARY);
|
||||
frame_destroy(frame);
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t frame_flags = ZWLR_EXPORT_DMABUF_FRAME_V1_FLAGS_TRANSIENT;
|
||||
uint32_t mod_high = attribs.modifier >> 32;
|
||||
uint32_t mod_low = attribs.modifier & 0xFFFFFFFF;
|
||||
zwlr_export_dmabuf_frame_v1_send_frame(frame->resource,
|
||||
attribs.width, attribs.height, 0, 0, attribs.flags, frame_flags,
|
||||
attribs.format, mod_high, mod_low, attribs.n_planes);
|
||||
|
||||
for (int i = 0; i < attribs.n_planes; ++i) {
|
||||
off_t size = lseek(attribs.fd[i], 0, SEEK_END);
|
||||
zwlr_export_dmabuf_frame_v1_send_object(frame->resource, i,
|
||||
attribs.fd[i], size, attribs.offset[i], attribs.stride[i], i);
|
||||
}
|
||||
|
||||
wlr_dmabuf_attributes_finish(&attribs);
|
||||
|
||||
time_t tv_sec = event->when->tv_sec;
|
||||
uint32_t tv_sec_hi = (sizeof(tv_sec) > 4) ? tv_sec >> 32 : 0;
|
||||
|
|
@ -98,7 +120,7 @@ static void manager_handle_capture_output(struct wl_client *client,
|
|||
return;
|
||||
}
|
||||
frame->manager = manager;
|
||||
wl_list_init(&frame->output_precommit.link);
|
||||
wl_list_init(&frame->output_commit.link);
|
||||
|
||||
uint32_t version = wl_resource_get_version(manager_resource);
|
||||
frame->resource = wl_resource_create(client,
|
||||
|
|
@ -120,14 +142,6 @@ static void manager_handle_capture_output(struct wl_client *client,
|
|||
return;
|
||||
}
|
||||
|
||||
struct wlr_dmabuf_attributes *attribs = &frame->attribs;
|
||||
if (!wlr_output_export_dmabuf(output, attribs)) {
|
||||
zwlr_export_dmabuf_frame_v1_send_cancel(frame->resource,
|
||||
ZWLR_EXPORT_DMABUF_FRAME_V1_CANCEL_REASON_TEMPORARY);
|
||||
frame_destroy(frame);
|
||||
return;
|
||||
}
|
||||
|
||||
frame->output = output;
|
||||
|
||||
wlr_output_lock_attach_render(frame->output, true);
|
||||
|
|
@ -136,26 +150,11 @@ static void manager_handle_capture_output(struct wl_client *client,
|
|||
frame->cursor_locked = true;
|
||||
}
|
||||
|
||||
uint32_t frame_flags = ZWLR_EXPORT_DMABUF_FRAME_V1_FLAGS_TRANSIENT;
|
||||
uint32_t mod_high = attribs->modifier >> 32;
|
||||
uint32_t mod_low = attribs->modifier & 0xFFFFFFFF;
|
||||
|
||||
zwlr_export_dmabuf_frame_v1_send_frame(frame->resource,
|
||||
output->width, output->height, 0, 0, attribs->flags, frame_flags,
|
||||
attribs->format, mod_high, mod_low, attribs->n_planes);
|
||||
|
||||
for (int i = 0; i < attribs->n_planes; ++i) {
|
||||
off_t size = lseek(attribs->fd[i], 0, SEEK_END);
|
||||
|
||||
zwlr_export_dmabuf_frame_v1_send_object(frame->resource, i,
|
||||
attribs->fd[i], size, attribs->offset[i], attribs->stride[i], i);
|
||||
}
|
||||
wl_list_remove(&frame->output_commit.link);
|
||||
wl_signal_add(&output->events.commit, &frame->output_commit);
|
||||
frame->output_commit.notify = frame_output_handle_commit;
|
||||
|
||||
wlr_output_schedule_frame(output);
|
||||
|
||||
wl_list_remove(&frame->output_precommit.link);
|
||||
wl_signal_add(&output->events.precommit, &frame->output_precommit);
|
||||
frame->output_precommit.notify = frame_output_handle_precommit;
|
||||
}
|
||||
|
||||
static void manager_handle_destroy(struct wl_client *client,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
#include "util/signal.h"
|
||||
#include "wlr-foreign-toplevel-management-unstable-v1-protocol.h"
|
||||
|
||||
#define FOREIGN_TOPLEVEL_MANAGEMENT_V1_VERSION 2
|
||||
#define FOREIGN_TOPLEVEL_MANAGEMENT_V1_VERSION 3
|
||||
|
||||
static const struct zwlr_foreign_toplevel_handle_v1_interface toplevel_handle_impl;
|
||||
|
||||
|
|
@ -405,6 +405,41 @@ void wlr_foreign_toplevel_handle_v1_set_fullscreen(
|
|||
toplevel_send_state(toplevel);
|
||||
}
|
||||
|
||||
static void toplevel_resource_send_parent(
|
||||
struct wl_resource *toplevel_resource,
|
||||
struct wlr_foreign_toplevel_handle_v1 *parent) {
|
||||
if (wl_resource_get_version(toplevel_resource) <
|
||||
ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_PARENT_SINCE_VERSION) {
|
||||
return;
|
||||
}
|
||||
struct wl_client *client = wl_resource_get_client(toplevel_resource);
|
||||
struct wl_resource *parent_resource = NULL;
|
||||
if (parent) {
|
||||
parent_resource = wl_resource_find_for_client(&parent->resources, client);
|
||||
if (!parent_resource) {
|
||||
/* don't send an event if this client destroyed the parent handle */
|
||||
return;
|
||||
}
|
||||
}
|
||||
zwlr_foreign_toplevel_handle_v1_send_parent(toplevel_resource,
|
||||
parent_resource);
|
||||
}
|
||||
|
||||
void wlr_foreign_toplevel_handle_v1_set_parent(
|
||||
struct wlr_foreign_toplevel_handle_v1 *toplevel,
|
||||
struct wlr_foreign_toplevel_handle_v1 *parent) {
|
||||
if (parent == toplevel->parent) {
|
||||
/* only send parent event to the clients if there was a change */
|
||||
return;
|
||||
}
|
||||
struct wl_resource *toplevel_resource, *tmp;
|
||||
wl_resource_for_each_safe(toplevel_resource, tmp, &toplevel->resources) {
|
||||
toplevel_resource_send_parent(toplevel_resource, parent);
|
||||
}
|
||||
toplevel->parent = parent;
|
||||
toplevel_update_idle_source(toplevel);
|
||||
}
|
||||
|
||||
void wlr_foreign_toplevel_handle_v1_destroy(
|
||||
struct wlr_foreign_toplevel_handle_v1 *toplevel) {
|
||||
if (!toplevel) {
|
||||
|
|
@ -432,6 +467,19 @@ void wlr_foreign_toplevel_handle_v1_destroy(
|
|||
|
||||
wl_list_remove(&toplevel->link);
|
||||
|
||||
/* need to ensure no other toplevels hold a pointer to this one as
|
||||
* a parent, so that a later call to foreign_toplevel_manager_bind()
|
||||
* will not result in a segfault */
|
||||
struct wlr_foreign_toplevel_handle_v1 *tl, *tmp3;
|
||||
wl_list_for_each_safe(tl, tmp3, &toplevel->manager->toplevels, link) {
|
||||
if (tl->parent == toplevel) {
|
||||
/* Note: we send a parent signal to all clients in this case;
|
||||
* the caller should first destroy the child handles if it
|
||||
* wishes to avoid this behavior. */
|
||||
wlr_foreign_toplevel_handle_v1_set_parent(tl, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
free(toplevel->title);
|
||||
free(toplevel->app_id);
|
||||
free(toplevel);
|
||||
|
|
@ -542,6 +590,8 @@ static void toplevel_send_details_to_toplevel_resource(
|
|||
zwlr_foreign_toplevel_handle_v1_send_state(resource, &states);
|
||||
wl_array_release(&states);
|
||||
|
||||
toplevel_resource_send_parent(resource, toplevel->parent);
|
||||
|
||||
zwlr_foreign_toplevel_handle_v1_send_done(resource);
|
||||
}
|
||||
|
||||
|
|
@ -560,9 +610,17 @@ static void foreign_toplevel_manager_bind(struct wl_client *client, void *data,
|
|||
wl_list_insert(&manager->resources, wl_resource_get_link(resource));
|
||||
|
||||
struct wlr_foreign_toplevel_handle_v1 *toplevel, *tmp;
|
||||
/* First loop: create a handle for all toplevels for all clients.
|
||||
* Separation into two loops avoid the case where a child handle
|
||||
* is created before a parent handle, so the parent relationship
|
||||
* could not be sent to a client. */
|
||||
wl_list_for_each_safe(toplevel, tmp, &manager->toplevels, link) {
|
||||
create_toplevel_resource_for_resource(toplevel, resource);
|
||||
}
|
||||
/* Second loop: send details about each toplevel. */
|
||||
wl_list_for_each_safe(toplevel, tmp, &manager->toplevels, link) {
|
||||
struct wl_resource *toplevel_resource =
|
||||
create_toplevel_resource_for_resource(toplevel, resource);
|
||||
wl_resource_find_for_client(&toplevel->resources, client);
|
||||
toplevel_send_details_to_toplevel_resource(toplevel,
|
||||
toplevel_resource);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,9 @@ static void gamma_control_destroy(struct wlr_gamma_control_v1 *gamma_control) {
|
|||
wlr_output_set_gamma(gamma_control->output, 0, NULL, NULL, NULL);
|
||||
wl_resource_set_user_data(gamma_control->resource, NULL);
|
||||
wl_list_remove(&gamma_control->output_destroy_listener.link);
|
||||
wl_list_remove(&gamma_control->output_commit_listener.link);
|
||||
wl_list_remove(&gamma_control->link);
|
||||
free(gamma_control->table);
|
||||
free(gamma_control);
|
||||
}
|
||||
|
||||
|
|
@ -34,6 +36,22 @@ static void gamma_control_send_failed(
|
|||
gamma_control_destroy(gamma_control);
|
||||
}
|
||||
|
||||
static void gamma_control_apply(struct wlr_gamma_control_v1 *gamma_control) {
|
||||
uint16_t *r = gamma_control->table;
|
||||
uint16_t *g = gamma_control->table + gamma_control->ramp_size;
|
||||
uint16_t *b = gamma_control->table + 2 * gamma_control->ramp_size;
|
||||
|
||||
wlr_output_set_gamma(gamma_control->output, gamma_control->ramp_size, r, g, b);
|
||||
if (!wlr_output_test(gamma_control->output)) {
|
||||
wlr_output_rollback(gamma_control->output);
|
||||
gamma_control_send_failed(gamma_control);
|
||||
return;
|
||||
}
|
||||
|
||||
// Gamma LUT will be applied on next output commit
|
||||
wlr_output_schedule_frame(gamma_control->output);
|
||||
}
|
||||
|
||||
static const struct zwlr_gamma_control_v1_interface gamma_control_impl;
|
||||
|
||||
static struct wlr_gamma_control_v1 *gamma_control_from_resource(
|
||||
|
|
@ -56,6 +74,17 @@ static void gamma_control_handle_output_destroy(struct wl_listener *listener,
|
|||
gamma_control_destroy(gamma_control);
|
||||
}
|
||||
|
||||
static void gamma_control_handle_output_commit(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_gamma_control_v1 *gamma_control =
|
||||
wl_container_of(listener, gamma_control, output_commit_listener);
|
||||
struct wlr_output_event_commit *event = data;
|
||||
if ((event->committed & WLR_OUTPUT_STATE_ENABLED) &&
|
||||
gamma_control->output->enabled) {
|
||||
gamma_control_apply(gamma_control);
|
||||
}
|
||||
}
|
||||
|
||||
static void gamma_control_handle_set_gamma(struct wl_client *client,
|
||||
struct wl_resource *gamma_control_resource, int fd) {
|
||||
struct wlr_gamma_control_v1 *gamma_control =
|
||||
|
|
@ -101,19 +130,13 @@ static void gamma_control_handle_set_gamma(struct wl_client *client,
|
|||
close(fd);
|
||||
fd = -1;
|
||||
|
||||
uint16_t *r = table;
|
||||
uint16_t *g = table + ramp_size;
|
||||
uint16_t *b = table + 2 * ramp_size;
|
||||
free(gamma_control->table);
|
||||
gamma_control->table = table;
|
||||
gamma_control->ramp_size = ramp_size;
|
||||
|
||||
wlr_output_set_gamma(gamma_control->output, ramp_size, r, g, b);
|
||||
if (!wlr_output_test(gamma_control->output)) {
|
||||
gamma_control_send_failed(gamma_control);
|
||||
goto error_table;
|
||||
if (gamma_control->output->enabled) {
|
||||
gamma_control_apply(gamma_control);
|
||||
}
|
||||
free(table);
|
||||
|
||||
// Gamma LUT will be applied on next output commit
|
||||
wlr_output_schedule_frame(gamma_control->output);
|
||||
|
||||
return;
|
||||
|
||||
|
|
@ -176,6 +199,11 @@ static void gamma_control_manager_get_gamma_control(struct wl_client *client,
|
|||
gamma_control->output_destroy_listener.notify =
|
||||
gamma_control_handle_output_destroy;
|
||||
|
||||
wl_signal_add(&output->events.commit,
|
||||
&gamma_control->output_commit_listener);
|
||||
gamma_control->output_commit_listener.notify =
|
||||
gamma_control_handle_output_commit;
|
||||
|
||||
wl_list_init(&gamma_control->link);
|
||||
|
||||
size_t gamma_size = wlr_output_get_gamma_size(output);
|
||||
|
|
|
|||
|
|
@ -259,6 +259,9 @@ void wlr_input_method_keyboard_grab_v2_set_keyboard(
|
|||
handle_keyboard_destroy;
|
||||
wl_signal_add(&keyboard->events.destroy,
|
||||
&keyboard_grab->keyboard_destroy);
|
||||
|
||||
wlr_input_method_keyboard_grab_v2_send_modifiers(keyboard_grab,
|
||||
&keyboard->modifiers);
|
||||
}
|
||||
|
||||
keyboard_grab->keyboard = keyboard;
|
||||
|
|
|
|||
|
|
@ -58,11 +58,11 @@ bool keyboard_modifier_update(struct wlr_keyboard *keyboard) {
|
|||
|
||||
void keyboard_key_update(struct wlr_keyboard *keyboard,
|
||||
struct wlr_event_keyboard_key *event) {
|
||||
if (event->state == WLR_KEY_PRESSED) {
|
||||
if (event->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
||||
set_add(keyboard->keycodes, &keyboard->num_keycodes,
|
||||
WLR_KEYBOARD_KEYS_CAP, event->keycode);
|
||||
}
|
||||
if (event->state == WLR_KEY_RELEASED) {
|
||||
if (event->state == WL_KEYBOARD_KEY_STATE_RELEASED) {
|
||||
set_remove(keyboard->keycodes, &keyboard->num_keycodes,
|
||||
WLR_KEYBOARD_KEYS_CAP, event->keycode);
|
||||
}
|
||||
|
|
@ -99,7 +99,7 @@ void wlr_keyboard_notify_key(struct wlr_keyboard *keyboard,
|
|||
if (event->update_state) {
|
||||
uint32_t keycode = event->keycode + 8;
|
||||
xkb_state_update_key(keyboard->xkb_state, keycode,
|
||||
event->state == WLR_KEY_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP);
|
||||
event->state == WL_KEYBOARD_KEY_STATE_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP);
|
||||
}
|
||||
|
||||
bool updated = keyboard_modifier_update(keyboard);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <wayland-server-core.h>
|
||||
#include <wayland-server-protocol.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
#include "types/wlr_keyboard.h"
|
||||
#include "util/signal.h"
|
||||
|
|
@ -95,11 +96,11 @@ static bool process_key(struct keyboard_group_device *group_device,
|
|||
if (key->keycode != event->keycode) {
|
||||
continue;
|
||||
}
|
||||
if (event->state == WLR_KEY_PRESSED) {
|
||||
if (event->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
||||
key->count++;
|
||||
return false;
|
||||
}
|
||||
if (event->state == WLR_KEY_RELEASED) {
|
||||
if (event->state == WL_KEYBOARD_KEY_STATE_RELEASED) {
|
||||
key->count--;
|
||||
if (key->count > 0) {
|
||||
return false;
|
||||
|
|
@ -110,7 +111,7 @@ static bool process_key(struct keyboard_group_device *group_device,
|
|||
break;
|
||||
}
|
||||
|
||||
if (event->state == WLR_KEY_PRESSED) {
|
||||
if (event->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
||||
struct keyboard_group_key *key =
|
||||
calloc(1, sizeof(struct keyboard_group_key));
|
||||
if (!key) {
|
||||
|
|
@ -199,7 +200,7 @@ static void handle_keyboard_repeat_info(struct wl_listener *listener,
|
|||
}
|
||||
|
||||
static void refresh_state(struct keyboard_group_device *device,
|
||||
enum wlr_key_state state) {
|
||||
enum wl_keyboard_key_state state) {
|
||||
struct wl_array keys;
|
||||
wl_array_init(&keys);
|
||||
|
||||
|
|
@ -229,7 +230,7 @@ static void refresh_state(struct keyboard_group_device *device,
|
|||
|
||||
// If there are any unique keys, emit the enter/leave event
|
||||
if (keys.size > 0) {
|
||||
if (state == WLR_KEY_PRESSED) {
|
||||
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
||||
wlr_signal_emit_safe(&device->keyboard->group->events.enter, &keys);
|
||||
} else {
|
||||
wlr_signal_emit_safe(&device->keyboard->group->events.leave, &keys);
|
||||
|
|
@ -240,7 +241,7 @@ static void refresh_state(struct keyboard_group_device *device,
|
|||
}
|
||||
|
||||
static void remove_keyboard_group_device(struct keyboard_group_device *device) {
|
||||
refresh_state(device, WLR_KEY_RELEASED);
|
||||
refresh_state(device, WL_KEYBOARD_KEY_STATE_RELEASED);
|
||||
device->keyboard->group = NULL;
|
||||
wl_list_remove(&device->link);
|
||||
wl_list_remove(&device->key.link);
|
||||
|
|
@ -312,7 +313,7 @@ bool wlr_keyboard_group_add_keyboard(struct wlr_keyboard_group *group,
|
|||
group_kb->repeat_info.delay);
|
||||
}
|
||||
|
||||
refresh_state(device, WLR_KEY_PRESSED);
|
||||
refresh_state(device, WL_KEYBOARD_KEY_STATE_PRESSED);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ static void layer_surface_handle_ack_configure(struct wl_client *client,
|
|||
if (!found) {
|
||||
wl_resource_post_error(resource,
|
||||
ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_SURFACE_STATE,
|
||||
"wrong configure serial: %u", serial);
|
||||
"wrong configure serial: %" PRIu32, serial);
|
||||
return;
|
||||
}
|
||||
// Then remove old configures from the list
|
||||
|
|
@ -114,7 +114,7 @@ static void layer_surface_handle_set_anchor(struct wl_client *client,
|
|||
if (anchor > max_anchor) {
|
||||
wl_resource_post_error(resource,
|
||||
ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_ANCHOR,
|
||||
"invalid anchor %d", anchor);
|
||||
"invalid anchor %" PRIu32, anchor);
|
||||
}
|
||||
struct wlr_layer_surface_v1 *surface = layer_surface_from_resource(resource);
|
||||
|
||||
|
|
@ -187,7 +187,7 @@ static void layer_surface_set_layer(struct wl_client *client,
|
|||
if (layer > ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY) {
|
||||
wl_resource_post_error(surface->resource,
|
||||
ZWLR_LAYER_SHELL_V1_ERROR_INVALID_LAYER,
|
||||
"Invalid layer %d", layer);
|
||||
"Invalid layer %" PRIu32, layer);
|
||||
return;
|
||||
}
|
||||
surface->client_pending.layer = layer;
|
||||
|
|
@ -307,6 +307,26 @@ static void layer_surface_role_commit(struct wlr_surface *wlr_surface) {
|
|||
return;
|
||||
}
|
||||
|
||||
const uint32_t horiz = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
|
||||
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
|
||||
if (surface->client_pending.desired_width == 0 &&
|
||||
(surface->client_pending.anchor & horiz) != horiz) {
|
||||
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;
|
||||
if (surface->client_pending.desired_height == 0 &&
|
||||
(surface->client_pending.anchor & vert) != vert) {
|
||||
wl_resource_post_error(surface->resource,
|
||||
ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_SIZE,
|
||||
"height 0 requested without setting top and bottom anchors");
|
||||
return;
|
||||
}
|
||||
|
||||
if (surface->closed) {
|
||||
// Ignore commits after the compositor has closed it
|
||||
return;
|
||||
|
|
@ -403,7 +423,7 @@ static void layer_shell_handle_get_layer_surface(struct wl_client *wl_client,
|
|||
free(surface);
|
||||
wl_resource_post_error(client_resource,
|
||||
ZWLR_LAYER_SHELL_V1_ERROR_INVALID_LAYER,
|
||||
"Invalid layer %d", layer);
|
||||
"Invalid layer %" PRIu32, layer);
|
||||
return;
|
||||
}
|
||||
surface->namespace = strdup(namespace);
|
||||
|
|
@ -534,16 +554,20 @@ static void xdg_surface_for_each_surface(struct wlr_xdg_surface *surface,
|
|||
}
|
||||
}
|
||||
|
||||
static void layer_surface_for_each_surface(struct wlr_layer_surface_v1 *surface,
|
||||
int x, int y, wlr_surface_iterator_func_t iterator, void *user_data) {
|
||||
void wlr_layer_surface_v1_for_each_surface(struct wlr_layer_surface_v1 *surface,
|
||||
wlr_surface_iterator_func_t iterator, void *user_data) {
|
||||
struct layer_surface_iterator_data data = {
|
||||
.user_iterator = iterator,
|
||||
.user_data = user_data,
|
||||
.x = x, .y = y,
|
||||
.x = 0, .y = 0,
|
||||
};
|
||||
wlr_surface_for_each_surface(surface->surface,
|
||||
layer_surface_iterator, &data);
|
||||
wlr_layer_surface_v1_for_each_popup(surface, iterator, user_data);
|
||||
}
|
||||
|
||||
void wlr_layer_surface_v1_for_each_popup(struct wlr_layer_surface_v1 *surface,
|
||||
wlr_surface_iterator_func_t iterator, void *user_data){
|
||||
struct wlr_xdg_popup *popup_state;
|
||||
wl_list_for_each(popup_state, &surface->popups, link) {
|
||||
struct wlr_xdg_surface *popup = popup_state->base;
|
||||
|
|
@ -560,11 +584,6 @@ static void layer_surface_for_each_surface(struct wlr_layer_surface_v1 *surface,
|
|||
}
|
||||
}
|
||||
|
||||
void wlr_layer_surface_v1_for_each_surface(struct wlr_layer_surface_v1 *surface,
|
||||
wlr_surface_iterator_func_t iterator, void *user_data) {
|
||||
layer_surface_for_each_surface(surface, 0, 0, iterator, user_data);
|
||||
}
|
||||
|
||||
struct wlr_surface *wlr_layer_surface_v1_surface_at(
|
||||
struct wlr_layer_surface_v1 *surface, double sx, double sy,
|
||||
double *sub_x, double *sub_y) {
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ static void params_create_common(struct wl_client *client,
|
|||
if (buffer->attributes.offset[i] > size) {
|
||||
wl_resource_post_error(params_resource,
|
||||
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
|
||||
"invalid offset %i for plane %d",
|
||||
"invalid offset %" PRIu32 " for plane %d",
|
||||
buffer->attributes.offset[i], i);
|
||||
goto err_out;
|
||||
}
|
||||
|
|
@ -219,7 +219,7 @@ static void params_create_common(struct wl_client *client,
|
|||
buffer->attributes.stride[i] == 0) {
|
||||
wl_resource_post_error(params_resource,
|
||||
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
|
||||
"invalid stride %i for plane %d",
|
||||
"invalid stride %" PRIu32 " for plane %d",
|
||||
buffer->attributes.stride[i], i);
|
||||
goto err_out;
|
||||
}
|
||||
|
|
@ -389,7 +389,7 @@ static void linux_dmabuf_send_formats(struct wlr_linux_dmabuf_v1 *linux_dmabuf,
|
|||
struct wl_resource *resource, uint32_t version) {
|
||||
uint64_t modifier_invalid = DRM_FORMAT_MOD_INVALID;
|
||||
const struct wlr_drm_format_set *formats =
|
||||
wlr_renderer_get_dmabuf_formats(linux_dmabuf->renderer);
|
||||
wlr_renderer_get_dmabuf_texture_formats(linux_dmabuf->renderer);
|
||||
if (formats == NULL) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,6 +93,13 @@ static void output_bind(struct wl_client *wl_client, void *data,
|
|||
send_current_mode(resource);
|
||||
send_scale(resource);
|
||||
send_done(resource);
|
||||
|
||||
struct wlr_output_event_bind evt = {
|
||||
.output = output,
|
||||
.resource = resource,
|
||||
};
|
||||
|
||||
wlr_signal_emit_safe(&output->events.bind, &evt);
|
||||
}
|
||||
|
||||
void wlr_output_create_global(struct wlr_output *output) {
|
||||
|
|
@ -342,6 +349,7 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
|
|||
wl_signal_init(&output->events.precommit);
|
||||
wl_signal_init(&output->events.commit);
|
||||
wl_signal_init(&output->events.present);
|
||||
wl_signal_init(&output->events.bind);
|
||||
wl_signal_init(&output->events.enable);
|
||||
wl_signal_init(&output->events.mode);
|
||||
wl_signal_init(&output->events.scale);
|
||||
|
|
@ -359,8 +367,6 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
|
|||
|
||||
output->display_destroy.notify = handle_display_destroy;
|
||||
wl_display_add_destroy_listener(display, &output->display_destroy);
|
||||
|
||||
output->frame_pending = true;
|
||||
}
|
||||
|
||||
void wlr_output_destroy(struct wlr_output *output) {
|
||||
|
|
@ -519,6 +525,7 @@ static bool output_basic_test(struct wlr_output *output) {
|
|||
|
||||
if (output->pending.buffer_type == WLR_OUTPUT_STATE_BUFFER_SCANOUT) {
|
||||
if (output->attach_render_locks > 0) {
|
||||
wlr_log(WLR_DEBUG, "Direct scan-out disabled by lock");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -528,6 +535,8 @@ static bool output_basic_test(struct wlr_output *output) {
|
|||
wl_list_for_each(cursor, &output->cursors, link) {
|
||||
if (cursor->enabled && cursor->visible &&
|
||||
cursor != output->hardware_cursor) {
|
||||
wlr_log(WLR_DEBUG,
|
||||
"Direct scan-out disabled by software cursor");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -538,6 +547,7 @@ static bool output_basic_test(struct wlr_output *output) {
|
|||
output_pending_resolution(output, &pending_width, &pending_height);
|
||||
if (output->pending.buffer->width != pending_width ||
|
||||
output->pending.buffer->height != pending_height) {
|
||||
wlr_log(WLR_DEBUG, "Direct scan-out buffer size mismatch");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -560,6 +570,10 @@ static bool output_basic_test(struct wlr_output *output) {
|
|||
wlr_log(WLR_DEBUG, "Tried to enable adaptive sync on a disabled output");
|
||||
return false;
|
||||
}
|
||||
if (!enabled && output->pending.committed & WLR_OUTPUT_STATE_GAMMA_LUT) {
|
||||
wlr_log(WLR_DEBUG, "Tried to set the gamma lut on a disabled output");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -573,7 +587,7 @@ bool wlr_output_test(struct wlr_output *output) {
|
|||
|
||||
bool wlr_output_commit(struct wlr_output *output) {
|
||||
if (!output_basic_test(output)) {
|
||||
wlr_log(WLR_ERROR, "Basic output test failed");
|
||||
wlr_log(WLR_ERROR, "Basic output test failed for %s", output->name);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -586,11 +600,11 @@ bool wlr_output_commit(struct wlr_output *output) {
|
|||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
|
||||
struct wlr_output_event_precommit event = {
|
||||
struct wlr_output_event_precommit pre_event = {
|
||||
.output = output,
|
||||
.when = &now,
|
||||
};
|
||||
wlr_signal_emit_safe(&output->events.precommit, &event);
|
||||
wlr_signal_emit_safe(&output->events.precommit, &pre_event);
|
||||
|
||||
if (!output->impl->commit(output)) {
|
||||
output_state_clear(&output->pending);
|
||||
|
|
@ -609,7 +623,12 @@ bool wlr_output_commit(struct wlr_output *output) {
|
|||
|
||||
output->commit_seq++;
|
||||
|
||||
wlr_signal_emit_safe(&output->events.commit, output);
|
||||
struct wlr_output_event_commit event = {
|
||||
.output = output,
|
||||
.committed = output->pending.committed,
|
||||
.when = &now,
|
||||
};
|
||||
wlr_signal_emit_safe(&output->events.commit, &event);
|
||||
|
||||
bool scale_updated = output->pending.committed & WLR_OUTPUT_STATE_SCALE;
|
||||
if (scale_updated) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#include "util/signal.h"
|
||||
#include "wlr-output-management-unstable-v1-protocol.h"
|
||||
|
||||
#define OUTPUT_MANAGER_VERSION 1
|
||||
#define OUTPUT_MANAGER_VERSION 2
|
||||
|
||||
enum {
|
||||
HEAD_STATE_ENABLED = 1 << 0,
|
||||
|
|
@ -118,6 +118,9 @@ struct wlr_output_configuration_head_v1 *
|
|||
struct wlr_output_configuration_v1 *config, struct wlr_output *output) {
|
||||
struct wlr_output_configuration_head_v1 *config_head =
|
||||
config_head_create(config, output);
|
||||
if (config_head == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
config_head->state.enabled = output->enabled;
|
||||
config_head->state.mode = output->current_mode;
|
||||
config_head->state.custom_mode.width = output->width;
|
||||
|
|
@ -680,6 +683,9 @@ static void head_send_state(struct wlr_output_head_v1 *head,
|
|||
|
||||
if (state & HEAD_STATE_ENABLED) {
|
||||
zwlr_output_head_v1_send_enabled(head_resource, head->state.enabled);
|
||||
// On enabling we send all current data since clients have not been
|
||||
// notified about potential data changes while the head was disabled.
|
||||
state = HEAD_STATE_ALL;
|
||||
}
|
||||
|
||||
if (!head->state.enabled) {
|
||||
|
|
@ -761,6 +767,16 @@ static void manager_send_head(struct wlr_output_manager_v1 *manager,
|
|||
output->phys_width, output->phys_height);
|
||||
}
|
||||
|
||||
if (version >= ZWLR_OUTPUT_HEAD_V1_MAKE_SINCE_VERSION && output->make[0] != '\0') {
|
||||
zwlr_output_head_v1_send_make(head_resource, output->make);
|
||||
}
|
||||
if (version >= ZWLR_OUTPUT_HEAD_V1_MODEL_SINCE_VERSION && output->model[0] != '\0') {
|
||||
zwlr_output_head_v1_send_model(head_resource, output->model);
|
||||
}
|
||||
if (version >= ZWLR_OUTPUT_HEAD_V1_SERIAL_NUMBER_SINCE_VERSION && output->serial[0] != '\0') {
|
||||
zwlr_output_head_v1_send_serial_number(head_resource, output->serial);
|
||||
}
|
||||
|
||||
struct wlr_output_mode *mode;
|
||||
wl_list_for_each(mode, &output->modes, link) {
|
||||
head_send_mode(head, head_resource, mode);
|
||||
|
|
@ -803,6 +819,26 @@ static bool manager_update_head(struct wlr_output_manager_v1 *manager,
|
|||
state |= HEAD_STATE_SCALE;
|
||||
}
|
||||
|
||||
// If a mode was added to wlr_output.modes we need to add the new mode
|
||||
// to the wlr_output_head
|
||||
struct wlr_output_mode *mode;
|
||||
wl_list_for_each(mode, &head->state.output->modes, link) {
|
||||
bool found = false;
|
||||
struct wl_resource *mode_resource;
|
||||
wl_resource_for_each(mode_resource, &head->mode_resources) {
|
||||
if (mode_from_resource(mode_resource) == mode) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
struct wl_resource *resource;
|
||||
wl_resource_for_each(resource, &head->resources) {
|
||||
head_send_mode(head, resource, mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (state != 0) {
|
||||
*current = *next;
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ static void output_power_destroy(struct wlr_output_power_v1 *output_power) {
|
|||
}
|
||||
wl_resource_set_user_data(output_power->resource, NULL);
|
||||
wl_list_remove(&output_power->output_destroy_listener.link);
|
||||
wl_list_remove(&output_power->output_enable_listener.link);
|
||||
wl_list_remove(&output_power->output_commit_listener.link);
|
||||
wl_list_remove(&output_power->link);
|
||||
free(output_power);
|
||||
}
|
||||
|
|
@ -58,11 +58,14 @@ static void output_power_v1_send_mode(struct wlr_output_power_v1 *output_power)
|
|||
zwlr_output_power_v1_send_mode(output_power->resource, mode);
|
||||
}
|
||||
|
||||
static void output_power_handle_output_enable(struct wl_listener *listener,
|
||||
static void output_power_handle_output_commit(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_output_power_v1 *output_power =
|
||||
wl_container_of(listener, output_power, output_enable_listener);
|
||||
output_power_v1_send_mode(output_power);
|
||||
wl_container_of(listener, output_power, output_commit_listener);
|
||||
struct wlr_output_event_commit *event = data;
|
||||
if (event->committed & WLR_OUTPUT_STATE_ENABLED) {
|
||||
output_power_v1_send_mode(output_power);
|
||||
}
|
||||
}
|
||||
|
||||
static void output_power_handle_set_mode(struct wl_client *client,
|
||||
|
|
@ -147,10 +150,10 @@ static void output_power_manager_get_output_power(struct wl_client *client,
|
|||
&output_power->output_destroy_listener);
|
||||
output_power->output_destroy_listener.notify =
|
||||
output_power_handle_output_destroy;
|
||||
wl_signal_add(&output->events.enable,
|
||||
&output_power->output_enable_listener);
|
||||
output_power->output_enable_listener.notify =
|
||||
output_power_handle_output_enable;
|
||||
wl_signal_add(&output->events.commit,
|
||||
&output_power->output_commit_listener);
|
||||
output_power->output_commit_listener.notify =
|
||||
output_power_handle_output_commit;
|
||||
|
||||
struct wlr_output_power_v1 *mgmt;
|
||||
wl_list_for_each(mgmt, &manager->output_powers, link) {
|
||||
|
|
|
|||
|
|
@ -48,9 +48,18 @@ static void screencopy_damage_accumulate(struct screencopy_damage *damage) {
|
|||
return;
|
||||
}
|
||||
|
||||
pixman_region32_union(region, region, &output->pending.damage);
|
||||
pixman_region32_intersect_rect(region, region, 0, 0, output->width,
|
||||
output->height);
|
||||
if (output->pending.committed & WLR_OUTPUT_STATE_DAMAGE) {
|
||||
// If the compositor submitted damage, copy it over
|
||||
pixman_region32_union(region, region, &output->pending.damage);
|
||||
pixman_region32_intersect_rect(region, region, 0, 0,
|
||||
output->width, output->height);
|
||||
} else if (output->pending.committed & WLR_OUTPUT_STATE_BUFFER) {
|
||||
// If the compositor did not submit damage but did submit a buffer
|
||||
// damage everything
|
||||
pixman_region32_union_rect(region, region, 0, 0,
|
||||
output->width, output->height);
|
||||
}
|
||||
|
||||
damage->last_commit_seq = output->commit_seq;
|
||||
}
|
||||
|
||||
|
|
@ -143,6 +152,7 @@ static void frame_destroy(struct wlr_screencopy_frame_v1 *frame) {
|
|||
}
|
||||
wl_list_remove(&frame->link);
|
||||
wl_list_remove(&frame->output_precommit.link);
|
||||
wl_list_remove(&frame->output_commit.link);
|
||||
wl_list_remove(&frame->output_destroy.link);
|
||||
wl_list_remove(&frame->output_enable.link);
|
||||
wl_list_remove(&frame->buffer_destroy.link);
|
||||
|
|
@ -152,6 +162,41 @@ static void frame_destroy(struct wlr_screencopy_frame_v1 *frame) {
|
|||
free(frame);
|
||||
}
|
||||
|
||||
static void frame_send_damage(struct wlr_screencopy_frame_v1 *frame) {
|
||||
if (!frame->with_damage) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct screencopy_damage *damage =
|
||||
screencopy_damage_get_or_create(frame->client, frame->output);
|
||||
if (damage == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: send fine-grained damage events
|
||||
struct pixman_box32 *damage_box =
|
||||
pixman_region32_extents(&damage->damage);
|
||||
|
||||
int damage_x = damage_box->x1;
|
||||
int damage_y = damage_box->y1;
|
||||
int damage_width = damage_box->x2 - damage_box->x1;
|
||||
int damage_height = damage_box->y2 - damage_box->y1;
|
||||
|
||||
zwlr_screencopy_frame_v1_send_damage(frame->resource,
|
||||
damage_x, damage_y, damage_width, damage_height);
|
||||
|
||||
pixman_region32_clear(&damage->damage);
|
||||
}
|
||||
|
||||
static void frame_send_ready(struct wlr_screencopy_frame_v1 *frame,
|
||||
struct timespec *when) {
|
||||
time_t tv_sec = when->tv_sec;
|
||||
uint32_t tv_sec_hi = (sizeof(tv_sec) > 4) ? tv_sec >> 32 : 0;
|
||||
uint32_t tv_sec_lo = tv_sec & 0xFFFFFFFF;
|
||||
zwlr_screencopy_frame_v1_send_ready(frame->resource,
|
||||
tv_sec_hi, tv_sec_lo, when->tv_nsec);
|
||||
}
|
||||
|
||||
static void frame_handle_output_precommit(struct wl_listener *listener,
|
||||
void *_data) {
|
||||
struct wlr_screencopy_frame_v1 *frame =
|
||||
|
|
@ -165,9 +210,14 @@ static void frame_handle_output_precommit(struct wl_listener *listener,
|
|||
return;
|
||||
}
|
||||
|
||||
struct screencopy_damage *damage = NULL;
|
||||
struct wl_shm_buffer *shm_buffer = frame->shm_buffer;
|
||||
if (shm_buffer == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (frame->with_damage) {
|
||||
damage = screencopy_damage_get_or_create(frame->client, output);
|
||||
struct screencopy_damage *damage =
|
||||
screencopy_damage_get_or_create(frame->client, output);
|
||||
if (damage) {
|
||||
screencopy_damage_accumulate(damage);
|
||||
if (!pixman_region32_not_empty(&damage->damage)) {
|
||||
|
|
@ -182,36 +232,19 @@ static void frame_handle_output_precommit(struct wl_listener *listener,
|
|||
int x = frame->box.x;
|
||||
int y = frame->box.y;
|
||||
|
||||
bool ok = false;
|
||||
uint32_t flags = 0;
|
||||
enum wl_shm_format fmt = wl_shm_buffer_get_format(shm_buffer);
|
||||
int32_t width = wl_shm_buffer_get_width(shm_buffer);
|
||||
int32_t height = wl_shm_buffer_get_height(shm_buffer);
|
||||
int32_t stride = wl_shm_buffer_get_stride(shm_buffer);
|
||||
|
||||
struct wl_shm_buffer *shm_buffer = frame->shm_buffer;
|
||||
struct wlr_dmabuf_v1_buffer *dma_buffer = frame->dma_buffer;
|
||||
assert(shm_buffer || dma_buffer);
|
||||
|
||||
if (shm_buffer) {
|
||||
enum wl_shm_format fmt = wl_shm_buffer_get_format(shm_buffer);
|
||||
int32_t width = wl_shm_buffer_get_width(shm_buffer);
|
||||
int32_t height = wl_shm_buffer_get_height(shm_buffer);
|
||||
int32_t stride = wl_shm_buffer_get_stride(shm_buffer);
|
||||
|
||||
wl_shm_buffer_begin_access(shm_buffer);
|
||||
void *data = wl_shm_buffer_get_data(shm_buffer);
|
||||
uint32_t renderer_flags = 0;
|
||||
ok = wlr_renderer_read_pixels(renderer, fmt, &renderer_flags,
|
||||
stride, width, height, x, y, 0, 0, data);
|
||||
flags |= renderer_flags & WLR_RENDERER_READ_PIXELS_Y_INVERT ?
|
||||
ZWLR_SCREENCOPY_FRAME_V1_FLAGS_Y_INVERT : 0;
|
||||
wl_shm_buffer_end_access(shm_buffer);
|
||||
} else if (dma_buffer) {
|
||||
struct wlr_dmabuf_attributes attr = { 0 };
|
||||
ok = wlr_output_export_dmabuf(frame->output, &attr);
|
||||
ok = ok && wlr_renderer_blit_dmabuf(renderer,
|
||||
&dma_buffer->attributes, &attr);
|
||||
flags |= dma_buffer->attributes.flags & WLR_DMABUF_ATTRIBUTES_FLAGS_Y_INVERT ?
|
||||
ZWLR_SCREENCOPY_FRAME_V1_FLAGS_Y_INVERT : 0;
|
||||
wlr_dmabuf_attributes_finish(&attr);
|
||||
}
|
||||
wl_shm_buffer_begin_access(shm_buffer);
|
||||
void *data = wl_shm_buffer_get_data(shm_buffer);
|
||||
uint32_t renderer_flags = 0;
|
||||
bool ok = wlr_renderer_read_pixels(renderer, fmt, &renderer_flags,
|
||||
stride, width, height, x, y, 0, 0, data);
|
||||
uint32_t flags = renderer_flags & WLR_RENDERER_READ_PIXELS_Y_INVERT ?
|
||||
ZWLR_SCREENCOPY_FRAME_V1_FLAGS_Y_INVERT : 0;
|
||||
wl_shm_buffer_end_access(shm_buffer);
|
||||
|
||||
if (!ok) {
|
||||
zwlr_screencopy_frame_v1_send_failed(frame->resource);
|
||||
|
|
@ -220,29 +253,66 @@ static void frame_handle_output_precommit(struct wl_listener *listener,
|
|||
}
|
||||
|
||||
zwlr_screencopy_frame_v1_send_flags(frame->resource, flags);
|
||||
frame_send_damage(frame);
|
||||
frame_send_ready(frame, event->when);
|
||||
frame_destroy(frame);
|
||||
}
|
||||
|
||||
// TODO: send fine-grained damage events
|
||||
if (damage) {
|
||||
struct pixman_box32 *damage_box =
|
||||
pixman_region32_extents(&damage->damage);
|
||||
static void frame_handle_output_commit(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_screencopy_frame_v1 *frame =
|
||||
wl_container_of(listener, frame, output_commit);
|
||||
struct wlr_output_event_commit *event = data;
|
||||
struct wlr_output *output = frame->output;
|
||||
struct wlr_renderer *renderer = wlr_backend_get_renderer(output->backend);
|
||||
assert(renderer);
|
||||
|
||||
int damage_x = damage_box->x1;
|
||||
int damage_y = damage_box->y1;
|
||||
int damage_width = damage_box->x2 - damage_box->x1;
|
||||
int damage_height = damage_box->y2 - damage_box->y1;
|
||||
|
||||
zwlr_screencopy_frame_v1_send_damage(frame->resource,
|
||||
damage_x, damage_y, damage_width, damage_height);
|
||||
|
||||
pixman_region32_clear(&damage->damage);
|
||||
if (!(event->committed & WLR_OUTPUT_STATE_BUFFER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
time_t tv_sec = event->when->tv_sec;
|
||||
uint32_t tv_sec_hi = (sizeof(tv_sec) > 4) ? tv_sec >> 32 : 0;
|
||||
uint32_t tv_sec_lo = tv_sec & 0xFFFFFFFF;
|
||||
zwlr_screencopy_frame_v1_send_ready(frame->resource,
|
||||
tv_sec_hi, tv_sec_lo, event->when->tv_nsec);
|
||||
struct wlr_dmabuf_v1_buffer *dma_buffer = frame->dma_buffer;
|
||||
if (dma_buffer == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (frame->with_damage) {
|
||||
struct screencopy_damage *damage =
|
||||
screencopy_damage_get_or_create(frame->client, output);
|
||||
if (damage && !pixman_region32_not_empty(&damage->damage)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
wl_list_remove(&frame->output_commit.link);
|
||||
wl_list_init(&frame->output_commit.link);
|
||||
|
||||
// TODO: add support for copying regions with DMA-BUFs
|
||||
if (frame->box.x != 0 || frame->box.y != 0 ||
|
||||
output->width != frame->box.width ||
|
||||
output->height != frame->box.height) {
|
||||
zwlr_screencopy_frame_v1_send_failed(frame->resource);
|
||||
frame_destroy(frame);
|
||||
return;
|
||||
}
|
||||
|
||||
struct wlr_dmabuf_attributes attr = { 0 };
|
||||
bool ok = wlr_output_export_dmabuf(output, &attr);
|
||||
ok = ok && wlr_renderer_blit_dmabuf(renderer,
|
||||
&dma_buffer->attributes, &attr);
|
||||
uint32_t flags = dma_buffer->attributes.flags & WLR_DMABUF_ATTRIBUTES_FLAGS_Y_INVERT ?
|
||||
ZWLR_SCREENCOPY_FRAME_V1_FLAGS_Y_INVERT : 0;
|
||||
wlr_dmabuf_attributes_finish(&attr);
|
||||
|
||||
if (!ok) {
|
||||
zwlr_screencopy_frame_v1_send_failed(frame->resource);
|
||||
frame_destroy(frame);
|
||||
return;
|
||||
}
|
||||
|
||||
zwlr_screencopy_frame_v1_send_flags(frame->resource, flags);
|
||||
frame_send_damage(frame);
|
||||
frame_send_ready(frame, event->when);
|
||||
frame_destroy(frame);
|
||||
}
|
||||
|
||||
|
|
@ -364,6 +434,9 @@ static void frame_handle_copy(struct wl_client *wl_client,
|
|||
wl_signal_add(&output->events.precommit, &frame->output_precommit);
|
||||
frame->output_precommit.notify = frame_handle_output_precommit;
|
||||
|
||||
wl_signal_add(&output->events.commit, &frame->output_commit);
|
||||
frame->output_commit.notify = frame_handle_output_commit;
|
||||
|
||||
wl_signal_add(&output->events.destroy, &frame->output_enable);
|
||||
frame->output_enable.notify = frame_handle_output_enable;
|
||||
|
||||
|
|
@ -374,7 +447,6 @@ static void frame_handle_copy(struct wl_client *wl_client,
|
|||
frame->buffer_destroy.notify = frame_handle_buffer_destroy;
|
||||
|
||||
// Schedule a buffer commit
|
||||
output->needs_frame = true;
|
||||
wlr_output_schedule_frame(output);
|
||||
|
||||
wlr_output_lock_attach_render(output, true);
|
||||
|
|
@ -467,6 +539,7 @@ static void capture_output(struct wl_client *wl_client,
|
|||
wl_list_insert(&client->manager->frames, &frame->link);
|
||||
|
||||
wl_list_init(&frame->output_precommit.link);
|
||||
wl_list_init(&frame->output_commit.link);
|
||||
wl_list_init(&frame->output_enable.link);
|
||||
wl_list_init(&frame->output_destroy.link);
|
||||
wl_list_init(&frame->buffer_destroy.link);
|
||||
|
|
|
|||
|
|
@ -616,9 +616,16 @@ static void subsurface_destroy(struct wlr_subsurface *subsurface) {
|
|||
free(subsurface);
|
||||
}
|
||||
|
||||
static void surface_output_destroy(struct wlr_surface_output *surface_output);
|
||||
|
||||
static void surface_handle_resource_destroy(struct wl_resource *resource) {
|
||||
struct wlr_surface_output *surface_output, *tmp;
|
||||
struct wlr_surface *surface = wlr_surface_from_resource(resource);
|
||||
|
||||
wl_list_for_each_safe(surface_output, tmp, &surface->current_outputs, link) {
|
||||
surface_output_destroy(surface_output);
|
||||
}
|
||||
|
||||
wlr_signal_emit_safe(&surface->events.destroy, surface);
|
||||
|
||||
wl_list_remove(wl_resource_get_link(surface->resource));
|
||||
|
|
@ -676,6 +683,7 @@ struct wlr_surface *wlr_surface_create(struct wl_client *client,
|
|||
wl_signal_init(&surface->events.new_subsurface);
|
||||
wl_list_init(&surface->subsurfaces);
|
||||
wl_list_init(&surface->subsurface_pending_list);
|
||||
wl_list_init(&surface->current_outputs);
|
||||
pixman_region32_init(&surface->buffer_damage);
|
||||
pixman_region32_init(&surface->opaque_region);
|
||||
pixman_region32_init(&surface->input_region);
|
||||
|
|
@ -712,7 +720,7 @@ bool wlr_surface_set_role(struct wlr_surface *surface,
|
|||
if (surface->role != NULL && surface->role != role) {
|
||||
if (error_resource != NULL) {
|
||||
wl_resource_post_error(error_resource, error_code,
|
||||
"Cannot assign role %s to wl_surface@%d, already has role %s\n",
|
||||
"Cannot assign role %s to wl_surface@%" PRIu32 ", already has role %s\n",
|
||||
role->name, wl_resource_get_id(surface->resource),
|
||||
surface->role->name);
|
||||
}
|
||||
|
|
@ -720,7 +728,7 @@ bool wlr_surface_set_role(struct wlr_surface *surface,
|
|||
}
|
||||
if (surface->role_data != NULL && surface->role_data != role_data) {
|
||||
wl_resource_post_error(error_resource, error_code,
|
||||
"Cannot reassign role %s to wl_surface@%d,"
|
||||
"Cannot reassign role %s to wl_surface@%" PRIu32 ","
|
||||
"role object still exists", role->name,
|
||||
wl_resource_get_id(surface->resource));
|
||||
return false;
|
||||
|
|
@ -791,7 +799,7 @@ static void subsurface_handle_place_above(struct wl_client *client,
|
|||
if (!sibling) {
|
||||
wl_resource_post_error(subsurface->resource,
|
||||
WL_SUBSURFACE_ERROR_BAD_SURFACE,
|
||||
"%s: wl_surface@%d is not a parent or sibling",
|
||||
"%s: wl_surface@%" PRIu32 "is not a parent or sibling",
|
||||
"place_above", wl_resource_get_id(sibling_surface->resource));
|
||||
return;
|
||||
}
|
||||
|
|
@ -818,7 +826,7 @@ static void subsurface_handle_place_below(struct wl_client *client,
|
|||
if (!sibling) {
|
||||
wl_resource_post_error(subsurface->resource,
|
||||
WL_SUBSURFACE_ERROR_BAD_SURFACE,
|
||||
"%s: wl_surface@%d is not a parent or sibling",
|
||||
"%s: wl_surface@%" PRIu32 " is not a parent or sibling",
|
||||
"place_below", wl_resource_get_id(sibling_surface->resource));
|
||||
return;
|
||||
}
|
||||
|
|
@ -1091,10 +1099,59 @@ struct wlr_surface *wlr_surface_surface_at(struct wlr_surface *surface,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void surface_output_destroy(struct wlr_surface_output *surface_output) {
|
||||
wl_list_remove(&surface_output->bind.link);
|
||||
wl_list_remove(&surface_output->destroy.link);
|
||||
wl_list_remove(&surface_output->link);
|
||||
|
||||
free(surface_output);
|
||||
}
|
||||
|
||||
static void surface_handle_output_bind(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_output_event_bind *evt = data;
|
||||
struct wlr_surface_output *surface_output =
|
||||
wl_container_of(listener, surface_output, bind);
|
||||
struct wl_client *client = wl_resource_get_client(
|
||||
surface_output->surface->resource);
|
||||
if (client == wl_resource_get_client(evt->resource)) {
|
||||
wl_surface_send_enter(surface_output->surface->resource, evt->resource);
|
||||
}
|
||||
}
|
||||
|
||||
static void surface_handle_output_destroy(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_surface_output *surface_output =
|
||||
wl_container_of(listener, surface_output, destroy);
|
||||
surface_output_destroy(surface_output);
|
||||
}
|
||||
|
||||
void wlr_surface_send_enter(struct wlr_surface *surface,
|
||||
struct wlr_output *output) {
|
||||
struct wl_client *client = wl_resource_get_client(surface->resource);
|
||||
struct wlr_surface_output *surface_output;
|
||||
struct wl_resource *resource;
|
||||
|
||||
wl_list_for_each(surface_output, &surface->current_outputs, link) {
|
||||
if (surface_output->output == output) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
surface_output = calloc(1, sizeof(struct wlr_surface_output));
|
||||
if (surface_output == NULL) {
|
||||
return;
|
||||
}
|
||||
surface_output->bind.notify = surface_handle_output_bind;
|
||||
surface_output->destroy.notify = surface_handle_output_destroy;
|
||||
|
||||
wl_signal_add(&output->events.bind, &surface_output->bind);
|
||||
wl_signal_add(&output->events.destroy, &surface_output->destroy);
|
||||
|
||||
surface_output->surface = surface;
|
||||
surface_output->output = output;
|
||||
wl_list_insert(&surface->current_outputs, &surface_output->link);
|
||||
|
||||
wl_resource_for_each(resource, &output->resources) {
|
||||
if (client == wl_resource_get_client(resource)) {
|
||||
wl_surface_send_enter(surface->resource, resource);
|
||||
|
|
@ -1105,10 +1162,19 @@ void wlr_surface_send_enter(struct wlr_surface *surface,
|
|||
void wlr_surface_send_leave(struct wlr_surface *surface,
|
||||
struct wlr_output *output) {
|
||||
struct wl_client *client = wl_resource_get_client(surface->resource);
|
||||
struct wlr_surface_output *surface_output, *tmp;
|
||||
struct wl_resource *resource;
|
||||
wl_resource_for_each(resource, &output->resources) {
|
||||
if (client == wl_resource_get_client(resource)) {
|
||||
wl_surface_send_leave(surface->resource, resource);
|
||||
|
||||
wl_list_for_each_safe(surface_output, tmp,
|
||||
&surface->current_outputs, link) {
|
||||
if (surface_output->output == output) {
|
||||
surface_output_destroy(surface_output);
|
||||
wl_resource_for_each(resource, &output->resources) {
|
||||
if (client == wl_resource_get_client(resource)) {
|
||||
wl_surface_send_leave(surface->resource, resource);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#define _POSIX_C_SOURCE 199309L
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <wlr/types/wlr_seat.h>
|
||||
#include <wlr/types/wlr_virtual_keyboard_v1.h>
|
||||
|
|
@ -72,12 +73,14 @@ static void virtual_keyboard_keymap(struct wl_client *client,
|
|||
keyboard->has_keymap = true;
|
||||
xkb_keymap_unref(keymap);
|
||||
xkb_context_unref(context);
|
||||
close(fd);
|
||||
return;
|
||||
keymap_fail:
|
||||
fd_fail:
|
||||
xkb_context_unref(context);
|
||||
context_fail:
|
||||
wl_client_post_no_memory(client);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static void virtual_keyboard_key(struct wl_client *client,
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ static void virtual_pointer_axis(struct wl_client *client,
|
|||
if (axis > WL_POINTER_AXIS_HORIZONTAL_SCROLL) {
|
||||
wl_resource_post_error(resource,
|
||||
ZWLR_VIRTUAL_POINTER_V1_ERROR_INVALID_AXIS,
|
||||
"Invalid enumeration value %d", axis);
|
||||
"Invalid enumeration value %" PRIu32, axis);
|
||||
return;
|
||||
}
|
||||
struct wlr_virtual_pointer_v1 *pointer =
|
||||
|
|
@ -103,7 +103,8 @@ static void virtual_pointer_axis(struct wl_client *client,
|
|||
return;
|
||||
}
|
||||
struct wlr_input_device *wlr_dev = &pointer->input_device;
|
||||
pointer->axis_valid[axis] = true;
|
||||
pointer->axis = axis;
|
||||
pointer->axis_valid[pointer->axis] = true;
|
||||
pointer->axis_event[pointer->axis].device = wlr_dev;
|
||||
pointer->axis_event[pointer->axis].time_msec = time;
|
||||
pointer->axis_event[pointer->axis].orientation = axis;
|
||||
|
|
@ -139,7 +140,7 @@ static void virtual_pointer_axis_source(struct wl_client *client,
|
|||
if (source > WL_POINTER_AXIS_SOURCE_WHEEL_TILT) {
|
||||
wl_resource_post_error(resource,
|
||||
ZWLR_VIRTUAL_POINTER_V1_ERROR_INVALID_AXIS_SOURCE,
|
||||
"Invalid enumeration value %d", source);
|
||||
"Invalid enumeration value %" PRIu32, source);
|
||||
return;
|
||||
}
|
||||
struct wlr_virtual_pointer_v1 *pointer =
|
||||
|
|
@ -157,7 +158,7 @@ static void virtual_pointer_axis_stop(struct wl_client *client,
|
|||
if (axis > WL_POINTER_AXIS_HORIZONTAL_SCROLL) {
|
||||
wl_resource_post_error(resource,
|
||||
ZWLR_VIRTUAL_POINTER_V1_ERROR_INVALID_AXIS,
|
||||
"Invalid enumeration value %d", axis);
|
||||
"Invalid enumeration value %" PRIu32, axis);
|
||||
return;
|
||||
}
|
||||
struct wlr_virtual_pointer_v1 *pointer =
|
||||
|
|
@ -181,7 +182,7 @@ static void virtual_pointer_axis_discrete(struct wl_client *client,
|
|||
if (axis > WL_POINTER_AXIS_HORIZONTAL_SCROLL) {
|
||||
wl_resource_post_error(resource,
|
||||
ZWLR_VIRTUAL_POINTER_V1_ERROR_INVALID_AXIS,
|
||||
"Invalid enumeration value %d", axis);
|
||||
"Invalid enumeration value %" PRIu32, axis);
|
||||
return;
|
||||
}
|
||||
struct wlr_virtual_pointer_v1 *pointer =
|
||||
|
|
|
|||
|
|
@ -336,7 +336,9 @@ static void xdg_surface_handle_surface_commit(struct wl_listener *listener,
|
|||
return;
|
||||
}
|
||||
|
||||
if (surface->role == WLR_XDG_SURFACE_ROLE_NONE) {
|
||||
// surface->role might be NONE for inert popups
|
||||
// So we check surface->surface->role
|
||||
if (surface->surface->role == NULL) {
|
||||
wl_resource_post_error(surface->resource,
|
||||
XDG_SURFACE_ERROR_NOT_CONSTRUCTED,
|
||||
"xdg_surface must have a role");
|
||||
|
|
@ -361,7 +363,8 @@ void handle_xdg_surface_commit(struct wlr_surface *wlr_surface) {
|
|||
|
||||
switch (surface->role) {
|
||||
case WLR_XDG_SURFACE_ROLE_NONE:
|
||||
assert(false);
|
||||
// inert toplevel or popup
|
||||
return;
|
||||
case WLR_XDG_SURFACE_ROLE_TOPLEVEL:
|
||||
handle_xdg_surface_toplevel_committed(surface);
|
||||
break;
|
||||
|
|
@ -494,7 +497,7 @@ void reset_xdg_surface(struct wlr_xdg_surface *xdg_surface) {
|
|||
break;
|
||||
case WLR_XDG_SURFACE_ROLE_POPUP:
|
||||
wl_resource_set_user_data(xdg_surface->popup->resource, NULL);
|
||||
xdg_surface->toplevel->resource = NULL;
|
||||
xdg_surface->popup->resource = NULL;
|
||||
|
||||
wl_list_remove(&xdg_surface->popup->link);
|
||||
|
||||
|
|
|
|||
|
|
@ -13,60 +13,44 @@ void handle_xdg_toplevel_ack_configure(
|
|||
assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL);
|
||||
assert(configure->toplevel_state != NULL);
|
||||
|
||||
surface->toplevel->current.maximized =
|
||||
configure->toplevel_state->maximized;
|
||||
surface->toplevel->current.fullscreen =
|
||||
configure->toplevel_state->fullscreen;
|
||||
surface->toplevel->current.resizing =
|
||||
configure->toplevel_state->resizing;
|
||||
surface->toplevel->current.activated =
|
||||
configure->toplevel_state->activated;
|
||||
surface->toplevel->current.tiled =
|
||||
configure->toplevel_state->tiled;
|
||||
surface->toplevel->last_acked = *configure->toplevel_state;
|
||||
}
|
||||
|
||||
bool compare_xdg_surface_toplevel_state(struct wlr_xdg_toplevel *state) {
|
||||
struct {
|
||||
struct wlr_xdg_toplevel_state state;
|
||||
uint32_t width, height;
|
||||
} configured;
|
||||
|
||||
// is pending state different from current state?
|
||||
if (!state->base->configured) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct wlr_xdg_toplevel_state *configured = NULL;
|
||||
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.height;
|
||||
// There are currently no pending configures, so check against the last
|
||||
// state acked by the client.
|
||||
configured = &state->last_acked;
|
||||
} else {
|
||||
struct wlr_xdg_surface_configure *configure =
|
||||
wl_container_of(state->base->configure_list.prev, configure, link);
|
||||
configured.state = *configure->toplevel_state;
|
||||
configured.width = configure->toplevel_state->width;
|
||||
configured.height = configure->toplevel_state->height;
|
||||
configured = configure->toplevel_state;
|
||||
}
|
||||
|
||||
if (state->server_pending.activated != configured.state.activated) {
|
||||
if (state->server_pending.activated != configured->activated) {
|
||||
return false;
|
||||
}
|
||||
if (state->server_pending.fullscreen != configured.state.fullscreen) {
|
||||
if (state->server_pending.fullscreen != configured->fullscreen) {
|
||||
return false;
|
||||
}
|
||||
if (state->server_pending.maximized != configured.state.maximized) {
|
||||
if (state->server_pending.maximized != configured->maximized) {
|
||||
return false;
|
||||
}
|
||||
if (state->server_pending.resizing != configured.state.resizing) {
|
||||
if (state->server_pending.resizing != configured->resizing) {
|
||||
return false;
|
||||
}
|
||||
if (state->server_pending.tiled != configured.state.tiled) {
|
||||
if (state->server_pending.tiled != configured->tiled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (state->server_pending.width == configured.width &&
|
||||
state->server_pending.height == configured.height) {
|
||||
if (state->server_pending.width == configured->width &&
|
||||
state->server_pending.height == configured->height) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -187,7 +171,10 @@ void handle_xdg_surface_toplevel_committed(struct wlr_xdg_surface *surface) {
|
|||
return;
|
||||
}
|
||||
|
||||
// update state that doesn't need compositor approval
|
||||
// apply state from the last acked configure now that the client committed
|
||||
surface->toplevel->current = surface->toplevel->last_acked;
|
||||
|
||||
// update state from the client that doesn't need compositor approval
|
||||
surface->toplevel->current.max_width =
|
||||
surface->toplevel->client_pending.max_width;
|
||||
surface->toplevel->current.min_width =
|
||||
|
|
|
|||
|
|
@ -1,585 +0,0 @@
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "types/wlr_xdg_shell_v6.h"
|
||||
#include "util/signal.h"
|
||||
|
||||
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_popup_grab_end(struct wlr_xdg_popup_grab_v6 *popup_grab) {
|
||||
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(popup_grab->seat);
|
||||
wlr_seat_keyboard_end_grab(popup_grab->seat);
|
||||
wlr_seat_touch_end_grab(popup_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_clear_focus(struct wlr_seat_pointer_grab *grab) {
|
||||
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_popup_grab_end(grab->data);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void xdg_pointer_grab_axis(struct wlr_seat_pointer_grab *grab,
|
||||
uint32_t time, enum wlr_axis_orientation orientation, double value,
|
||||
int32_t value_discrete, enum wlr_axis_source source) {
|
||||
wlr_seat_pointer_send_axis(grab->seat, time, orientation, value,
|
||||
value_discrete, source);
|
||||
}
|
||||
|
||||
static void xdg_pointer_grab_frame(struct wlr_seat_pointer_grab *grab) {
|
||||
wlr_seat_pointer_send_frame(grab->seat);
|
||||
}
|
||||
|
||||
static void xdg_pointer_grab_cancel(struct wlr_seat_pointer_grab *grab) {
|
||||
xdg_popup_grab_end(grab->data);
|
||||
}
|
||||
|
||||
static const struct wlr_pointer_grab_interface xdg_pointer_grab_impl = {
|
||||
.enter = xdg_pointer_grab_enter,
|
||||
.clear_focus = xdg_pointer_grab_clear_focus,
|
||||
.motion = xdg_pointer_grab_motion,
|
||||
.button = xdg_pointer_grab_button,
|
||||
.cancel = xdg_pointer_grab_cancel,
|
||||
.axis = xdg_pointer_grab_axis,
|
||||
.frame = xdg_pointer_grab_frame,
|
||||
};
|
||||
|
||||
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) {
|
||||
// keyboard focus should remain on the popup
|
||||
}
|
||||
|
||||
static void xdg_keyboard_grab_clear_focus(struct wlr_seat_keyboard_grab *grab) {
|
||||
// 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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static void xdg_keyboard_grab_cancel(struct wlr_seat_keyboard_grab *grab) {
|
||||
wlr_seat_pointer_end_grab(grab->seat);
|
||||
}
|
||||
|
||||
static const struct wlr_keyboard_grab_interface xdg_keyboard_grab_impl = {
|
||||
.enter = xdg_keyboard_grab_enter,
|
||||
.clear_focus = xdg_keyboard_grab_clear_focus,
|
||||
.key = xdg_keyboard_grab_key,
|
||||
.modifiers = xdg_keyboard_grab_modifiers,
|
||||
.cancel = xdg_keyboard_grab_cancel,
|
||||
};
|
||||
|
||||
static uint32_t xdg_touch_grab_down(struct wlr_seat_touch_grab *grab,
|
||||
uint32_t time, struct wlr_touch_point *point) {
|
||||
struct wlr_xdg_popup_grab_v6 *popup_grab = grab->data;
|
||||
|
||||
if (wl_resource_get_client(point->surface->resource) != popup_grab->client) {
|
||||
xdg_popup_grab_end(grab->data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return wlr_seat_touch_send_down(grab->seat, point->surface, time,
|
||||
point->touch_id, point->sx, point->sy);
|
||||
}
|
||||
|
||||
static void xdg_touch_grab_up(struct wlr_seat_touch_grab *grab,
|
||||
uint32_t time, struct wlr_touch_point *point) {
|
||||
wlr_seat_touch_send_up(grab->seat, time, point->touch_id);
|
||||
}
|
||||
|
||||
static void xdg_touch_grab_motion(struct wlr_seat_touch_grab *grab,
|
||||
uint32_t time, struct wlr_touch_point *point) {
|
||||
wlr_seat_touch_send_motion(grab->seat, time, point->touch_id, point->sx,
|
||||
point->sy);
|
||||
}
|
||||
|
||||
static void xdg_touch_grab_enter(struct wlr_seat_touch_grab *grab,
|
||||
uint32_t time, struct wlr_touch_point *point) {
|
||||
}
|
||||
|
||||
static void xdg_touch_grab_cancel(struct wlr_seat_touch_grab *grab) {
|
||||
wlr_seat_touch_end_grab(grab->seat);
|
||||
}
|
||||
|
||||
static const struct wlr_touch_grab_interface xdg_touch_grab_impl = {
|
||||
.down = xdg_touch_grab_down,
|
||||
.up = xdg_touch_grab_up,
|
||||
.motion = xdg_touch_grab_motion,
|
||||
.enter = xdg_touch_grab_enter,
|
||||
.cancel = xdg_touch_grab_cancel
|
||||
};
|
||||
|
||||
static void xdg_popup_grab_handle_seat_destroy(
|
||||
struct wl_listener *listener, void *data) {
|
||||
struct wlr_xdg_popup_grab_v6 *xdg_grab =
|
||||
wl_container_of(listener, xdg_grab, seat_destroy);
|
||||
|
||||
wl_list_remove(&xdg_grab->seat_destroy.link);
|
||||
|
||||
struct wlr_xdg_popup_v6 *popup, *next;
|
||||
wl_list_for_each_safe(popup, next, &xdg_grab->popups, grab_link) {
|
||||
destroy_xdg_surface_v6(popup->base);
|
||||
}
|
||||
|
||||
wl_list_remove(&xdg_grab->link);
|
||||
free(xdg_grab);
|
||||
}
|
||||
|
||||
struct wlr_xdg_popup_grab_v6 *get_xdg_shell_v6_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;
|
||||
xdg_grab->keyboard_grab.data = xdg_grab;
|
||||
xdg_grab->keyboard_grab.interface = &xdg_keyboard_grab_impl;
|
||||
xdg_grab->touch_grab.data = xdg_grab;
|
||||
xdg_grab->touch_grab.interface = &xdg_touch_grab_impl;
|
||||
|
||||
wl_list_init(&xdg_grab->popups);
|
||||
|
||||
wl_list_insert(&shell->popup_grabs, &xdg_grab->link);
|
||||
xdg_grab->seat = seat;
|
||||
|
||||
xdg_grab->seat_destroy.notify = xdg_popup_grab_handle_seat_destroy;
|
||||
wl_signal_add(&seat->events.destroy, &xdg_grab->seat_destroy);
|
||||
|
||||
return xdg_grab;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void destroy_xdg_popup_v6(struct wlr_xdg_surface_v6 *surface) {
|
||||
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP);
|
||||
unmap_xdg_surface_v6(surface);
|
||||
|
||||
wl_resource_set_user_data(surface->popup->resource, NULL);
|
||||
wl_list_remove(&surface->popup->link);
|
||||
free(surface->popup);
|
||||
surface->popup = NULL;
|
||||
|
||||
surface->role = WLR_XDG_SURFACE_V6_ROLE_NONE;
|
||||
}
|
||||
|
||||
static void xdg_popup_handle_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) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (surface->popup->committed) {
|
||||
wl_resource_post_error(surface->popup->resource,
|
||||
ZXDG_POPUP_V6_ERROR_INVALID_GRAB,
|
||||
"xdg_popup is already mapped");
|
||||
return;
|
||||
}
|
||||
|
||||
struct wlr_xdg_popup_grab_v6 *popup_grab =
|
||||
get_xdg_shell_v6_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->parent->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL;
|
||||
|
||||
if ((topmost == NULL && !parent_is_toplevel) ||
|
||||
(topmost != NULL && topmost != surface->popup->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->seat = seat_client->seat;
|
||||
|
||||
wl_list_insert(&popup_grab->popups, &surface->popup->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);
|
||||
wlr_seat_touch_start_grab(seat_client->seat,
|
||||
&popup_grab->touch_grab);
|
||||
}
|
||||
|
||||
static void xdg_popup_handle_destroy(struct wl_client *client,
|
||||
struct wl_resource *resource) {
|
||||
struct wlr_xdg_surface_v6 *surface =
|
||||
xdg_surface_from_xdg_popup_resource(resource);
|
||||
|
||||
if (surface && !wl_list_empty(&surface->popups)) {
|
||||
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");
|
||||
return;
|
||||
}
|
||||
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
|
||||
static const struct zxdg_popup_v6_interface zxdg_popup_v6_implementation = {
|
||||
.destroy = xdg_popup_handle_destroy,
|
||||
.grab = xdg_popup_handle_grab,
|
||||
};
|
||||
|
||||
static void xdg_popup_handle_resource_destroy(struct wl_resource *resource) {
|
||||
struct wlr_xdg_surface_v6 *surface =
|
||||
xdg_surface_from_xdg_popup_resource(resource);
|
||||
if (surface != NULL) {
|
||||
destroy_xdg_popup_v6(surface);
|
||||
}
|
||||
}
|
||||
|
||||
void handle_xdg_surface_v6_popup_committed(struct wlr_xdg_surface_v6 *surface) {
|
||||
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP);
|
||||
|
||||
if (!surface->popup->committed) {
|
||||
schedule_xdg_surface_v6_configure(surface);
|
||||
surface->popup->committed = true;
|
||||
}
|
||||
}
|
||||
|
||||
const struct wlr_surface_role xdg_popup_v6_surface_role = {
|
||||
.name = "xdg_popup_v6",
|
||||
.commit = handle_xdg_surface_v6_commit,
|
||||
.precommit = handle_xdg_surface_v6_precommit,
|
||||
};
|
||||
|
||||
void create_xdg_popup_v6(struct wlr_xdg_surface_v6 *xdg_surface,
|
||||
struct wlr_xdg_surface_v6 *parent,
|
||||
struct wlr_xdg_positioner_v6_resource *positioner, int32_t id) {
|
||||
if (positioner->attrs.size.width == 0 ||
|
||||
positioner->attrs.anchor_rect.width == 0) {
|
||||
wl_resource_post_error(xdg_surface->resource,
|
||||
ZXDG_SHELL_V6_ERROR_INVALID_POSITIONER,
|
||||
"positioner object is not complete");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!wlr_surface_set_role(xdg_surface->surface, &xdg_popup_v6_surface_role,
|
||||
xdg_surface, xdg_surface->resource, ZXDG_SHELL_V6_ERROR_ROLE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
xdg_surface->popup = calloc(1, sizeof(struct wlr_xdg_popup_v6));
|
||||
if (!xdg_surface->popup) {
|
||||
wl_resource_post_no_memory(xdg_surface->resource);
|
||||
return;
|
||||
}
|
||||
|
||||
xdg_surface->popup->resource =
|
||||
wl_resource_create(xdg_surface->client->client, &zxdg_popup_v6_interface,
|
||||
wl_resource_get_version(xdg_surface->resource), id);
|
||||
if (xdg_surface->popup->resource == NULL) {
|
||||
free(xdg_surface->popup);
|
||||
wl_resource_post_no_memory(xdg_surface->resource);
|
||||
return;
|
||||
}
|
||||
wl_resource_set_implementation(xdg_surface->popup->resource,
|
||||
&zxdg_popup_v6_implementation, xdg_surface,
|
||||
xdg_popup_handle_resource_destroy);
|
||||
|
||||
xdg_surface->role = WLR_XDG_SURFACE_V6_ROLE_POPUP;
|
||||
xdg_surface->popup->base = xdg_surface;
|
||||
xdg_surface->popup->parent = parent;
|
||||
xdg_surface->popup->geometry =
|
||||
wlr_xdg_positioner_v6_get_geometry(&positioner->attrs);
|
||||
|
||||
// positioner properties
|
||||
memcpy(&xdg_surface->popup->positioner, &positioner->attrs,
|
||||
sizeof(struct wlr_xdg_positioner_v6));
|
||||
|
||||
wl_list_insert(&parent->popups, &xdg_surface->popup->link);
|
||||
|
||||
wlr_signal_emit_safe(&parent->events.new_popup, xdg_surface->popup);
|
||||
}
|
||||
|
||||
void wlr_xdg_popup_v6_get_anchor_point(struct wlr_xdg_popup_v6 *popup,
|
||||
int *root_sx, int *root_sy) {
|
||||
struct wlr_box rect = popup->positioner.anchor_rect;
|
||||
enum zxdg_positioner_v6_anchor anchor = popup->positioner.anchor;
|
||||
int sx = 0, sy = 0;
|
||||
|
||||
if (anchor == ZXDG_POSITIONER_V6_ANCHOR_NONE) {
|
||||
sx = (rect.x + rect.width) / 2;
|
||||
sy = (rect.y + rect.height) / 2;
|
||||
} else if (anchor == ZXDG_POSITIONER_V6_ANCHOR_TOP) {
|
||||
sx = (rect.x + rect.width) / 2;
|
||||
sy = rect.y;
|
||||
} else if (anchor == ZXDG_POSITIONER_V6_ANCHOR_BOTTOM) {
|
||||
sx = (rect.x + rect.width) / 2;
|
||||
sy = rect.y + rect.height;
|
||||
} else if (anchor == ZXDG_POSITIONER_V6_ANCHOR_LEFT) {
|
||||
sx = rect.x;
|
||||
sy = (rect.y + rect.height) / 2;
|
||||
} else if (anchor == ZXDG_POSITIONER_V6_ANCHOR_RIGHT) {
|
||||
sx = rect.x + rect.width;
|
||||
sy = (rect.y + rect.height) / 2;
|
||||
} else if (anchor == (ZXDG_POSITIONER_V6_ANCHOR_TOP |
|
||||
ZXDG_POSITIONER_V6_ANCHOR_LEFT)) {
|
||||
sx = rect.x;
|
||||
sy = rect.y;
|
||||
} else if (anchor == (ZXDG_POSITIONER_V6_ANCHOR_TOP |
|
||||
ZXDG_POSITIONER_V6_ANCHOR_RIGHT)) {
|
||||
sx = rect.x + rect.width;
|
||||
sy = rect.y;
|
||||
} else if (anchor == (ZXDG_POSITIONER_V6_ANCHOR_BOTTOM |
|
||||
ZXDG_POSITIONER_V6_ANCHOR_LEFT)) {
|
||||
sx = rect.x;
|
||||
sy = rect.y + rect.height;
|
||||
} else if (anchor == (ZXDG_POSITIONER_V6_ANCHOR_BOTTOM |
|
||||
ZXDG_POSITIONER_V6_ANCHOR_RIGHT)) {
|
||||
sx = rect.x + rect.width;
|
||||
sy = rect.y + rect.height;
|
||||
}
|
||||
|
||||
*root_sx = sx;
|
||||
*root_sy = sy;
|
||||
}
|
||||
|
||||
void wlr_xdg_popup_v6_get_toplevel_coords(struct wlr_xdg_popup_v6 *popup,
|
||||
int popup_sx, int popup_sy, int *toplevel_sx, int *toplevel_sy) {
|
||||
struct wlr_xdg_surface_v6 *parent = popup->parent;
|
||||
while (parent != NULL && parent->role == WLR_XDG_SURFACE_V6_ROLE_POPUP) {
|
||||
popup_sx += parent->popup->geometry.x;
|
||||
popup_sy += parent->popup->geometry.y;
|
||||
parent = parent->popup->parent;
|
||||
}
|
||||
assert(parent);
|
||||
|
||||
*toplevel_sx = popup_sx + parent->geometry.x;
|
||||
*toplevel_sy = popup_sy + parent->geometry.y;
|
||||
}
|
||||
|
||||
static void xdg_popup_v6_box_constraints(struct wlr_xdg_popup_v6 *popup,
|
||||
struct wlr_box *toplevel_sx_box, int *offset_x, int *offset_y) {
|
||||
int popup_width = popup->geometry.width;
|
||||
int popup_height = popup->geometry.height;
|
||||
int anchor_sx = 0, anchor_sy = 0;
|
||||
wlr_xdg_popup_v6_get_anchor_point(popup, &anchor_sx, &anchor_sy);
|
||||
int popup_sx = 0, popup_sy = 0;
|
||||
wlr_xdg_popup_v6_get_toplevel_coords(popup, popup->geometry.x,
|
||||
popup->geometry.y, &popup_sx, &popup_sy);
|
||||
*offset_x = 0, *offset_y = 0;
|
||||
|
||||
if (popup_sx < toplevel_sx_box->x) {
|
||||
*offset_x = toplevel_sx_box->x - popup_sx;
|
||||
} else if (popup_sx + popup_width >
|
||||
toplevel_sx_box->x + toplevel_sx_box->width) {
|
||||
*offset_x = toplevel_sx_box->x + toplevel_sx_box->width -
|
||||
(popup_sx + popup_width);
|
||||
}
|
||||
|
||||
if (popup_sy < toplevel_sx_box->y) {
|
||||
*offset_y = toplevel_sx_box->y - popup_sy;
|
||||
} else if (popup_sy + popup_height >
|
||||
toplevel_sx_box->y + toplevel_sx_box->height) {
|
||||
*offset_y = toplevel_sx_box->y + toplevel_sx_box->height -
|
||||
(popup_sy + popup_height);
|
||||
}
|
||||
}
|
||||
|
||||
static bool xdg_popup_v6_unconstrain_flip(struct wlr_xdg_popup_v6 *popup,
|
||||
struct wlr_box *toplevel_sx_box) {
|
||||
int offset_x = 0, offset_y = 0;
|
||||
xdg_popup_v6_box_constraints(popup, toplevel_sx_box,
|
||||
&offset_x, &offset_y);
|
||||
|
||||
if (!offset_x && !offset_y) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool flip_x = offset_x &&
|
||||
(popup->positioner.constraint_adjustment &
|
||||
ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_X);
|
||||
|
||||
bool flip_y = offset_y &&
|
||||
(popup->positioner.constraint_adjustment &
|
||||
ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_FLIP_Y);
|
||||
|
||||
if (flip_x) {
|
||||
wlr_positioner_v6_invert_x(&popup->positioner);
|
||||
}
|
||||
if (flip_y) {
|
||||
wlr_positioner_v6_invert_y(&popup->positioner);
|
||||
}
|
||||
|
||||
popup->geometry =
|
||||
wlr_xdg_positioner_v6_get_geometry(&popup->positioner);
|
||||
|
||||
xdg_popup_v6_box_constraints(popup, toplevel_sx_box,
|
||||
&offset_x, &offset_y);
|
||||
|
||||
if (!offset_x && !offset_y) {
|
||||
// no longer constrained
|
||||
return true;
|
||||
}
|
||||
|
||||
// revert the positioner back if it didn't fix it and go to the next part
|
||||
if (offset_x && flip_x) {
|
||||
wlr_positioner_v6_invert_x(&popup->positioner);
|
||||
}
|
||||
if (offset_y && flip_y) {
|
||||
wlr_positioner_v6_invert_y(&popup->positioner);
|
||||
}
|
||||
|
||||
popup->geometry =
|
||||
wlr_xdg_positioner_v6_get_geometry(&popup->positioner);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool xdg_popup_v6_unconstrain_slide(struct wlr_xdg_popup_v6 *popup,
|
||||
struct wlr_box *toplevel_sx_box) {
|
||||
int offset_x = 0, offset_y = 0;
|
||||
xdg_popup_v6_box_constraints(popup, toplevel_sx_box,
|
||||
&offset_x, &offset_y);
|
||||
|
||||
if (!offset_x && !offset_y) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool slide_x = offset_x &&
|
||||
(popup->positioner.constraint_adjustment &
|
||||
ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_X);
|
||||
|
||||
bool slide_y = offset_y &&
|
||||
(popup->positioner.constraint_adjustment &
|
||||
ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_Y);
|
||||
|
||||
if (slide_x) {
|
||||
popup->geometry.x += offset_x;
|
||||
}
|
||||
|
||||
if (slide_y) {
|
||||
popup->geometry.y += offset_y;
|
||||
}
|
||||
|
||||
int toplevel_x = 0, toplevel_y = 0;
|
||||
wlr_xdg_popup_v6_get_toplevel_coords(popup, popup->geometry.x,
|
||||
popup->geometry.y, &toplevel_x, &toplevel_y);
|
||||
|
||||
if (slide_x && toplevel_x < toplevel_sx_box->x) {
|
||||
popup->geometry.x += toplevel_sx_box->x - toplevel_x;
|
||||
}
|
||||
if (slide_y && toplevel_y < toplevel_sx_box->y) {
|
||||
popup->geometry.y += toplevel_sx_box->y - toplevel_y;
|
||||
}
|
||||
|
||||
xdg_popup_v6_box_constraints(popup, toplevel_sx_box,
|
||||
&offset_x, &offset_y);
|
||||
|
||||
return !offset_x && !offset_y;
|
||||
}
|
||||
|
||||
static bool xdg_popup_v6_unconstrain_resize(struct wlr_xdg_popup_v6 *popup,
|
||||
struct wlr_box *toplevel_sx_box) {
|
||||
int offset_x, offset_y;
|
||||
xdg_popup_v6_box_constraints(popup, toplevel_sx_box,
|
||||
&offset_x, &offset_y);
|
||||
|
||||
if (!offset_x && !offset_y) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool resize_x = offset_x &&
|
||||
(popup->positioner.constraint_adjustment &
|
||||
ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_X);
|
||||
|
||||
bool resize_y = offset_y &&
|
||||
(popup->positioner.constraint_adjustment &
|
||||
ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_Y);
|
||||
|
||||
if (resize_x) {
|
||||
popup->geometry.width -= offset_x;
|
||||
}
|
||||
if (resize_y) {
|
||||
popup->geometry.height -= offset_y;
|
||||
}
|
||||
|
||||
xdg_popup_v6_box_constraints(popup, toplevel_sx_box,
|
||||
&offset_x, &offset_y);
|
||||
|
||||
return !offset_x && !offset_y;
|
||||
}
|
||||
|
||||
void wlr_xdg_popup_v6_unconstrain_from_box(struct wlr_xdg_popup_v6 *popup,
|
||||
struct wlr_box *toplevel_sx_box) {
|
||||
if (xdg_popup_v6_unconstrain_flip(popup, toplevel_sx_box)) {
|
||||
return;
|
||||
}
|
||||
if (xdg_popup_v6_unconstrain_slide(popup, toplevel_sx_box)) {
|
||||
return;
|
||||
}
|
||||
if (xdg_popup_v6_unconstrain_resize(popup, toplevel_sx_box)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,230 +0,0 @@
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include "types/wlr_xdg_shell_v6.h"
|
||||
|
||||
static const struct zxdg_positioner_v6_interface
|
||||
zxdg_positioner_v6_implementation;
|
||||
|
||||
struct wlr_xdg_positioner_v6_resource *get_xdg_positioner_v6_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);
|
||||
}
|
||||
|
||||
static void xdg_positioner_destroy(struct wl_resource *resource) {
|
||||
struct wlr_xdg_positioner_v6_resource *positioner =
|
||||
get_xdg_positioner_v6_from_resource(resource);
|
||||
free(positioner);
|
||||
}
|
||||
|
||||
static void xdg_positioner_handle_destroy(struct wl_client *client,
|
||||
struct wl_resource *resource) {
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
|
||||
static void xdg_positioner_handle_set_size(struct wl_client *client,
|
||||
struct wl_resource *resource, int32_t width, int32_t height) {
|
||||
struct wlr_xdg_positioner_v6_resource *positioner =
|
||||
get_xdg_positioner_v6_from_resource(resource);
|
||||
|
||||
if (width < 1 || height < 1) {
|
||||
wl_resource_post_error(resource,
|
||||
ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT,
|
||||
"width and height must be positive and non-zero");
|
||||
return;
|
||||
}
|
||||
|
||||
positioner->attrs.size.width = width;
|
||||
positioner->attrs.size.height = height;
|
||||
}
|
||||
|
||||
static void xdg_positioner_handle_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_resource *positioner =
|
||||
get_xdg_positioner_v6_from_resource(resource);
|
||||
|
||||
if (width < 1 || height < 1) {
|
||||
wl_resource_post_error(resource,
|
||||
ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT,
|
||||
"width and height must be positive and non-zero");
|
||||
return;
|
||||
}
|
||||
|
||||
positioner->attrs.anchor_rect.x = x;
|
||||
positioner->attrs.anchor_rect.y = y;
|
||||
positioner->attrs.anchor_rect.width = width;
|
||||
positioner->attrs.anchor_rect.height = height;
|
||||
}
|
||||
|
||||
static void xdg_positioner_handle_set_anchor(struct wl_client *client,
|
||||
struct wl_resource *resource, uint32_t anchor) {
|
||||
struct wlr_xdg_positioner_v6_resource *positioner =
|
||||
get_xdg_positioner_v6_from_resource(resource);
|
||||
|
||||
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->attrs.anchor = anchor;
|
||||
}
|
||||
|
||||
static void xdg_positioner_handle_set_gravity(struct wl_client *client,
|
||||
struct wl_resource *resource, uint32_t gravity) {
|
||||
struct wlr_xdg_positioner_v6_resource *positioner =
|
||||
get_xdg_positioner_v6_from_resource(resource);
|
||||
|
||||
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->attrs.gravity = gravity;
|
||||
}
|
||||
|
||||
static void xdg_positioner_handle_set_constraint_adjustment(
|
||||
struct wl_client *client, struct wl_resource *resource,
|
||||
uint32_t constraint_adjustment) {
|
||||
struct wlr_xdg_positioner_v6_resource *positioner =
|
||||
get_xdg_positioner_v6_from_resource(resource);
|
||||
|
||||
positioner->attrs.constraint_adjustment = constraint_adjustment;
|
||||
}
|
||||
|
||||
static void xdg_positioner_handle_set_offset(struct wl_client *client,
|
||||
struct wl_resource *resource, int32_t x, int32_t y) {
|
||||
struct wlr_xdg_positioner_v6_resource *positioner =
|
||||
get_xdg_positioner_v6_from_resource(resource);
|
||||
|
||||
positioner->attrs.offset.x = x;
|
||||
positioner->attrs.offset.y = y;
|
||||
}
|
||||
|
||||
static const struct zxdg_positioner_v6_interface
|
||||
zxdg_positioner_v6_implementation = {
|
||||
.destroy = xdg_positioner_handle_destroy,
|
||||
.set_size = xdg_positioner_handle_set_size,
|
||||
.set_anchor_rect = xdg_positioner_handle_set_anchor_rect,
|
||||
.set_anchor = xdg_positioner_handle_set_anchor,
|
||||
.set_gravity = xdg_positioner_handle_set_gravity,
|
||||
.set_constraint_adjustment =
|
||||
xdg_positioner_handle_set_constraint_adjustment,
|
||||
.set_offset = xdg_positioner_handle_set_offset,
|
||||
};
|
||||
|
||||
struct wlr_box wlr_xdg_positioner_v6_get_geometry(
|
||||
struct wlr_xdg_positioner_v6 *positioner) {
|
||||
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.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.width / 2;
|
||||
}
|
||||
|
||||
if (positioner->constraint_adjustment ==
|
||||
ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_NONE) {
|
||||
return geometry;
|
||||
}
|
||||
|
||||
return geometry;
|
||||
}
|
||||
|
||||
void wlr_positioner_v6_invert_x(struct wlr_xdg_positioner_v6 *positioner) {
|
||||
if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_LEFT) {
|
||||
positioner->anchor &= ~ZXDG_POSITIONER_V6_ANCHOR_LEFT;
|
||||
positioner->anchor |= ZXDG_POSITIONER_V6_ANCHOR_RIGHT;
|
||||
} else if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_RIGHT) {
|
||||
positioner->anchor &= ~ZXDG_POSITIONER_V6_ANCHOR_RIGHT;
|
||||
positioner->anchor |= ZXDG_POSITIONER_V6_ANCHOR_LEFT;
|
||||
}
|
||||
|
||||
if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_RIGHT) {
|
||||
positioner->gravity &= ~ZXDG_POSITIONER_V6_GRAVITY_RIGHT;
|
||||
positioner->gravity |= ZXDG_POSITIONER_V6_GRAVITY_LEFT;
|
||||
} else if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_LEFT) {
|
||||
positioner->gravity &= ~ZXDG_POSITIONER_V6_GRAVITY_LEFT;
|
||||
positioner->gravity |= ZXDG_POSITIONER_V6_GRAVITY_RIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
void wlr_positioner_v6_invert_y(
|
||||
struct wlr_xdg_positioner_v6 *positioner) {
|
||||
if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_TOP) {
|
||||
positioner->anchor &= ~ZXDG_POSITIONER_V6_ANCHOR_TOP;
|
||||
positioner->anchor |= ZXDG_POSITIONER_V6_ANCHOR_BOTTOM;
|
||||
} else if (positioner->anchor & ZXDG_POSITIONER_V6_ANCHOR_BOTTOM) {
|
||||
positioner->anchor &= ~ZXDG_POSITIONER_V6_ANCHOR_BOTTOM;
|
||||
positioner->anchor |= ZXDG_POSITIONER_V6_ANCHOR_TOP;
|
||||
}
|
||||
|
||||
if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_TOP) {
|
||||
positioner->gravity &= ~ZXDG_POSITIONER_V6_GRAVITY_TOP;
|
||||
positioner->gravity |= ZXDG_POSITIONER_V6_GRAVITY_BOTTOM;
|
||||
} else if (positioner->gravity & ZXDG_POSITIONER_V6_GRAVITY_BOTTOM) {
|
||||
positioner->gravity &= ~ZXDG_POSITIONER_V6_GRAVITY_BOTTOM;
|
||||
positioner->gravity |= ZXDG_POSITIONER_V6_GRAVITY_TOP;
|
||||
}
|
||||
}
|
||||
|
||||
void create_xdg_positioner_v6(struct wlr_xdg_client_v6 *client, uint32_t id) {
|
||||
struct wlr_xdg_positioner_v6_resource *positioner =
|
||||
calloc(1, sizeof(struct wlr_xdg_positioner_v6_resource));
|
||||
if (positioner == NULL) {
|
||||
wl_client_post_no_memory(client->client);
|
||||
return;
|
||||
}
|
||||
|
||||
positioner->resource = wl_resource_create(client->client,
|
||||
&zxdg_positioner_v6_interface,
|
||||
wl_resource_get_version(client->resource), id);
|
||||
if (positioner->resource == NULL) {
|
||||
free(positioner);
|
||||
wl_client_post_no_memory(client->client);
|
||||
return;
|
||||
}
|
||||
wl_resource_set_implementation(positioner->resource,
|
||||
&zxdg_positioner_v6_implementation, positioner, xdg_positioner_destroy);
|
||||
}
|
||||
|
|
@ -1,168 +0,0 @@
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include "types/wlr_xdg_shell_v6.h"
|
||||
#include "util/signal.h"
|
||||
|
||||
#define SHELL_VERSION 1
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static void xdg_shell_handle_create_positioner(struct wl_client *wl_client,
|
||||
struct wl_resource *resource, uint32_t id) {
|
||||
struct wlr_xdg_client_v6 *client =
|
||||
xdg_client_from_resource(resource);
|
||||
create_xdg_positioner_v6(client, id);
|
||||
}
|
||||
|
||||
static void xdg_shell_handle_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 =
|
||||
xdg_client_from_resource(client_resource);
|
||||
struct wlr_surface *surface = wlr_surface_from_resource(surface_resource);
|
||||
create_xdg_surface_v6(client, surface, id);
|
||||
}
|
||||
|
||||
static void xdg_shell_handle_pong(struct wl_client *wl_client,
|
||||
struct wl_resource *resource, uint32_t serial) {
|
||||
struct wlr_xdg_client_v6 *client = xdg_client_from_resource(resource);
|
||||
|
||||
if (client->ping_serial != serial) {
|
||||
return;
|
||||
}
|
||||
|
||||
wl_event_source_timer_update(client->ping_timer, 0);
|
||||
client->ping_serial = 0;
|
||||
}
|
||||
|
||||
static void xdg_shell_handle_destroy(struct wl_client *wl_client,
|
||||
struct wl_resource *resource) {
|
||||
struct wlr_xdg_client_v6 *client = xdg_client_from_resource(resource);
|
||||
|
||||
if (!wl_list_empty(&client->surfaces)) {
|
||||
wl_resource_post_error(client->resource,
|
||||
ZXDG_SHELL_V6_ERROR_DEFUNCT_SURFACES,
|
||||
"xdg_wm_base was destroyed before children");
|
||||
return;
|
||||
}
|
||||
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
|
||||
static const struct zxdg_shell_v6_interface xdg_shell_impl = {
|
||||
.destroy = xdg_shell_handle_destroy,
|
||||
.create_positioner = xdg_shell_handle_create_positioner,
|
||||
.get_xdg_surface = xdg_shell_handle_get_xdg_surface,
|
||||
.pong = xdg_shell_handle_pong,
|
||||
};
|
||||
|
||||
static void xdg_client_v6_handle_resource_destroy(
|
||||
struct wl_resource *resource) {
|
||||
struct wlr_xdg_client_v6 *client = xdg_client_from_resource(resource);
|
||||
|
||||
struct wlr_xdg_surface_v6 *surface, *tmp = NULL;
|
||||
wl_list_for_each_safe(surface, tmp, &client->surfaces, link) {
|
||||
wl_resource_destroy(surface->resource);
|
||||
}
|
||||
|
||||
if (client->ping_timer != NULL) {
|
||||
wl_event_source_remove(client->ping_timer);
|
||||
}
|
||||
|
||||
wl_list_remove(&client->link);
|
||||
free(client);
|
||||
}
|
||||
|
||||
static int 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) {
|
||||
wlr_signal_emit_safe(&surface->events.ping_timeout, surface);
|
||||
}
|
||||
|
||||
client->ping_serial = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void xdg_shell_bind(struct wl_client *wl_client, void *data,
|
||||
uint32_t version, uint32_t id) {
|
||||
struct wlr_xdg_shell_v6 *xdg_shell = data;
|
||||
assert(wl_client && xdg_shell);
|
||||
|
||||
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);
|
||||
if (client->resource == NULL) {
|
||||
free(client);
|
||||
wl_client_post_no_memory(wl_client);
|
||||
return;
|
||||
}
|
||||
client->client = wl_client;
|
||||
client->shell = xdg_shell;
|
||||
|
||||
wl_resource_set_implementation(client->resource, &xdg_shell_impl, client,
|
||||
xdg_client_v6_handle_resource_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,
|
||||
xdg_client_v6_ping_timeout, client);
|
||||
if (client->ping_timer == NULL) {
|
||||
wl_client_post_no_memory(client->client);
|
||||
}
|
||||
}
|
||||
|
||||
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_signal_emit_safe(&xdg_shell->events.destroy, xdg_shell);
|
||||
wl_list_remove(&xdg_shell->display_destroy.link);
|
||||
wl_global_destroy(xdg_shell->global);
|
||||
free(xdg_shell);
|
||||
}
|
||||
|
||||
struct wlr_xdg_shell_v6 *wlr_xdg_shell_v6_create(struct wl_display *display) {
|
||||
struct wlr_xdg_shell_v6 *xdg_shell =
|
||||
calloc(1, sizeof(struct wlr_xdg_shell_v6));
|
||||
if (!xdg_shell) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
xdg_shell->ping_timeout = 10000;
|
||||
|
||||
wl_list_init(&xdg_shell->clients);
|
||||
wl_list_init(&xdg_shell->popup_grabs);
|
||||
|
||||
struct wl_global *global = wl_global_create(display,
|
||||
&zxdg_shell_v6_interface, SHELL_VERSION, xdg_shell, xdg_shell_bind);
|
||||
if (!global) {
|
||||
free(xdg_shell);
|
||||
return NULL;
|
||||
}
|
||||
xdg_shell->global = global;
|
||||
|
||||
wl_signal_init(&xdg_shell->events.new_surface);
|
||||
wl_signal_init(&xdg_shell->events.destroy);
|
||||
|
||||
xdg_shell->display_destroy.notify = handle_display_destroy;
|
||||
wl_display_add_destroy_listener(display, &xdg_shell->display_destroy);
|
||||
|
||||
return xdg_shell;
|
||||
}
|
||||
|
|
@ -1,606 +0,0 @@
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "types/wlr_xdg_shell_v6.h"
|
||||
#include "util/signal.h"
|
||||
|
||||
bool wlr_surface_is_xdg_surface_v6(struct wlr_surface *surface) {
|
||||
return surface->role == &xdg_toplevel_v6_surface_role ||
|
||||
surface->role == &xdg_popup_v6_surface_role;
|
||||
}
|
||||
|
||||
struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_from_wlr_surface(
|
||||
struct wlr_surface *surface) {
|
||||
assert(wlr_surface_is_xdg_surface_v6(surface));
|
||||
return (struct wlr_xdg_surface_v6 *)surface->role_data;
|
||||
}
|
||||
|
||||
static const struct zxdg_surface_v6_interface zxdg_surface_v6_implementation;
|
||||
|
||||
static struct wlr_xdg_surface_v6 *xdg_surface_from_resource(
|
||||
struct wl_resource *resource) {
|
||||
assert(wl_resource_instance_of(resource, &zxdg_surface_v6_interface,
|
||||
&zxdg_surface_v6_implementation));
|
||||
return wl_resource_get_user_data(resource);
|
||||
}
|
||||
|
||||
static void xdg_surface_configure_destroy(
|
||||
struct wlr_xdg_surface_v6_configure *configure) {
|
||||
if (configure == NULL) {
|
||||
return;
|
||||
}
|
||||
wl_list_remove(&configure->link);
|
||||
free(configure->toplevel_state);
|
||||
free(configure);
|
||||
}
|
||||
|
||||
void unmap_xdg_surface_v6(struct wlr_xdg_surface_v6 *surface) {
|
||||
assert(surface->role != WLR_XDG_SURFACE_V6_ROLE_NONE);
|
||||
|
||||
// TODO: probably need to ungrab before this event
|
||||
if (surface->mapped) {
|
||||
wlr_signal_emit_safe(&surface->events.unmap, surface);
|
||||
}
|
||||
|
||||
switch (surface->role) {
|
||||
case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL:
|
||||
free(surface->toplevel->title);
|
||||
surface->toplevel->title = NULL;
|
||||
free(surface->toplevel->app_id);
|
||||
surface->toplevel->app_id = NULL;
|
||||
break;
|
||||
case WLR_XDG_SURFACE_V6_ROLE_POPUP:
|
||||
if (surface->popup->seat != NULL) {
|
||||
struct wlr_xdg_popup_grab_v6 *grab =
|
||||
get_xdg_shell_v6_popup_grab_from_seat(surface->client->shell,
|
||||
surface->popup->seat);
|
||||
|
||||
wl_list_remove(&surface->popup->grab_link);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
surface->popup->seat = NULL;
|
||||
}
|
||||
break;
|
||||
case WLR_XDG_SURFACE_V6_ROLE_NONE:
|
||||
assert(false && "not reached");
|
||||
}
|
||||
|
||||
struct wlr_xdg_surface_v6_configure *configure, *tmp;
|
||||
wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) {
|
||||
xdg_surface_configure_destroy(configure);
|
||||
}
|
||||
|
||||
surface->configured = surface->mapped = false;
|
||||
surface->configure_serial = 0;
|
||||
if (surface->configure_idle) {
|
||||
wl_event_source_remove(surface->configure_idle);
|
||||
surface->configure_idle = NULL;
|
||||
}
|
||||
surface->configure_next_serial = 0;
|
||||
|
||||
surface->has_next_geometry = false;
|
||||
memset(&surface->geometry, 0, sizeof(struct wlr_box));
|
||||
memset(&surface->next_geometry, 0, sizeof(struct wlr_box));
|
||||
}
|
||||
|
||||
void destroy_xdg_surface_v6(struct wlr_xdg_surface_v6 *surface) {
|
||||
if (surface->role != WLR_XDG_SURFACE_V6_ROLE_NONE) {
|
||||
unmap_xdg_surface_v6(surface);
|
||||
}
|
||||
|
||||
wlr_signal_emit_safe(&surface->events.destroy, surface);
|
||||
|
||||
struct wlr_xdg_popup_v6 *popup_state, *next;
|
||||
wl_list_for_each_safe(popup_state, next, &surface->popups, link) {
|
||||
zxdg_popup_v6_send_popup_done(popup_state->resource);
|
||||
destroy_xdg_popup_v6(popup_state->base);
|
||||
}
|
||||
|
||||
switch (surface->role) {
|
||||
case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL:
|
||||
destroy_xdg_toplevel_v6(surface);
|
||||
break;
|
||||
case WLR_XDG_SURFACE_V6_ROLE_POPUP:
|
||||
destroy_xdg_popup_v6(surface);
|
||||
break;
|
||||
case WLR_XDG_SURFACE_V6_ROLE_NONE:
|
||||
// This space is intentionally left blank
|
||||
break;
|
||||
}
|
||||
|
||||
wl_resource_set_user_data(surface->resource, NULL);
|
||||
surface->surface->role_data = NULL;
|
||||
wl_list_remove(&surface->link);
|
||||
wl_list_remove(&surface->surface_destroy.link);
|
||||
wl_list_remove(&surface->surface_commit.link);
|
||||
free(surface);
|
||||
}
|
||||
|
||||
static void xdg_surface_handle_get_toplevel(struct wl_client *client,
|
||||
struct wl_resource *resource, uint32_t id) {
|
||||
struct wlr_xdg_surface_v6 *xdg_surface = xdg_surface_from_resource(resource);
|
||||
create_xdg_toplevel_v6(xdg_surface, id);
|
||||
}
|
||||
|
||||
static void xdg_surface_handle_get_popup(struct wl_client *wl_client,
|
||||
struct wl_resource *resource, uint32_t id,
|
||||
struct wl_resource *parent_resource,
|
||||
struct wl_resource *positioner_resource) {
|
||||
struct wlr_xdg_surface_v6 *xdg_surface =
|
||||
xdg_surface_from_resource(resource);
|
||||
struct wlr_xdg_surface_v6 *parent =
|
||||
xdg_surface_from_resource(parent_resource);
|
||||
struct wlr_xdg_positioner_v6_resource *positioner =
|
||||
get_xdg_positioner_v6_from_resource(positioner_resource);
|
||||
|
||||
create_xdg_popup_v6(xdg_surface, parent, positioner, id);
|
||||
}
|
||||
|
||||
static void xdg_surface_handle_ack_configure(struct wl_client *client,
|
||||
struct wl_resource *resource, uint32_t serial) {
|
||||
struct wlr_xdg_surface_v6 *surface = xdg_surface_from_resource(resource);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// First find the ack'ed configure
|
||||
bool found = false;
|
||||
struct wlr_xdg_surface_v6_configure *configure, *tmp;
|
||||
wl_list_for_each(configure, &surface->configure_list, link) {
|
||||
if (configure->serial == serial) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
wl_resource_post_error(surface->client->resource,
|
||||
ZXDG_SHELL_V6_ERROR_INVALID_SURFACE_STATE,
|
||||
"wrong configure serial: %u", serial);
|
||||
return;
|
||||
}
|
||||
// Then remove old configures from the list
|
||||
wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) {
|
||||
if (configure->serial == serial) {
|
||||
break;
|
||||
}
|
||||
xdg_surface_configure_destroy(configure);
|
||||
}
|
||||
|
||||
switch (surface->role) {
|
||||
case WLR_XDG_SURFACE_V6_ROLE_NONE:
|
||||
assert(0 && "not reached");
|
||||
break;
|
||||
case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL:
|
||||
handle_xdg_toplevel_v6_ack_configure(surface, configure);
|
||||
break;
|
||||
case WLR_XDG_SURFACE_V6_ROLE_POPUP:
|
||||
break;
|
||||
}
|
||||
|
||||
surface->configured = true;
|
||||
surface->configure_serial = serial;
|
||||
|
||||
xdg_surface_configure_destroy(configure);
|
||||
}
|
||||
|
||||
static void xdg_surface_handle_set_window_geometry(struct wl_client *client,
|
||||
struct wl_resource *resource, int32_t x, int32_t y, int32_t width,
|
||||
int32_t height) {
|
||||
struct wlr_xdg_surface_v6 *surface = xdg_surface_from_resource(resource);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (width <= 0 || height <= 0) {
|
||||
wlr_log(WLR_ERROR, "Client tried to set invalid geometry");
|
||||
wl_resource_post_error(resource, -1, "Tried to set invalid xdg-surface geometry");
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static void xdg_surface_handle_destroy(struct wl_client *client,
|
||||
struct wl_resource *resource) {
|
||||
struct wlr_xdg_surface_v6 *surface = xdg_surface_from_resource(resource);
|
||||
|
||||
if (surface->role != WLR_XDG_SURFACE_V6_ROLE_NONE) {
|
||||
wlr_log(WLR_ERROR, "Tried to destroy an xdg_surface before its role "
|
||||
"object");
|
||||
return;
|
||||
}
|
||||
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
|
||||
static const struct zxdg_surface_v6_interface zxdg_surface_v6_implementation = {
|
||||
.destroy = xdg_surface_handle_destroy,
|
||||
.get_toplevel = xdg_surface_handle_get_toplevel,
|
||||
.get_popup = xdg_surface_handle_get_popup,
|
||||
.ack_configure = xdg_surface_handle_ack_configure,
|
||||
.set_window_geometry = xdg_surface_handle_set_window_geometry,
|
||||
};
|
||||
|
||||
static void 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));
|
||||
if (configure == NULL) {
|
||||
wl_client_post_no_memory(surface->client->client);
|
||||
return;
|
||||
}
|
||||
|
||||
wl_list_insert(surface->configure_list.prev, &configure->link);
|
||||
configure->serial = surface->configure_next_serial;
|
||||
|
||||
switch (surface->role) {
|
||||
case WLR_XDG_SURFACE_V6_ROLE_NONE:
|
||||
assert(0 && "not reached");
|
||||
break;
|
||||
case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL:
|
||||
send_xdg_toplevel_v6_configure(surface, configure);
|
||||
break;
|
||||
case WLR_XDG_SURFACE_V6_ROLE_POPUP:
|
||||
zxdg_popup_v6_send_configure(surface->popup->resource,
|
||||
surface->popup->geometry.x,
|
||||
surface->popup->geometry.y,
|
||||
surface->popup->geometry.width,
|
||||
surface->popup->geometry.height);
|
||||
break;
|
||||
}
|
||||
|
||||
zxdg_surface_v6_send_configure(surface->resource, configure->serial);
|
||||
}
|
||||
|
||||
uint32_t schedule_xdg_surface_v6_configure(struct wlr_xdg_surface_v6 *surface) {
|
||||
struct wl_display *display = wl_client_get_display(surface->client->client);
|
||||
struct wl_event_loop *loop = wl_display_get_event_loop(display);
|
||||
bool pending_same = false;
|
||||
|
||||
switch (surface->role) {
|
||||
case WLR_XDG_SURFACE_V6_ROLE_NONE:
|
||||
assert(0 && "not reached");
|
||||
break;
|
||||
case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL:
|
||||
pending_same =
|
||||
compare_xdg_surface_v6_toplevel_state(surface->toplevel);
|
||||
break;
|
||||
case WLR_XDG_SURFACE_V6_ROLE_POPUP:
|
||||
break;
|
||||
}
|
||||
|
||||
if (surface->configure_idle != NULL) {
|
||||
if (!pending_same) {
|
||||
// configure request already scheduled
|
||||
return surface->configure_next_serial;
|
||||
}
|
||||
|
||||
// configure request not necessary anymore
|
||||
wl_event_source_remove(surface->configure_idle);
|
||||
surface->configure_idle = NULL;
|
||||
return 0;
|
||||
} else {
|
||||
if (pending_same) {
|
||||
// configure request not necessary
|
||||
return 0;
|
||||
}
|
||||
|
||||
surface->configure_next_serial = wl_display_next_serial(display);
|
||||
surface->configure_idle = wl_event_loop_add_idle(loop,
|
||||
xdg_surface_send_configure, surface);
|
||||
return surface->configure_next_serial;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void wlr_xdg_surface_v6_send_close(struct wlr_xdg_surface_v6 *surface) {
|
||||
switch (surface->role) {
|
||||
case WLR_XDG_SURFACE_V6_ROLE_NONE:
|
||||
assert(0 && "not reached");
|
||||
break;
|
||||
case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL:
|
||||
if (surface->toplevel) {
|
||||
zxdg_toplevel_v6_send_close(surface->toplevel->resource);
|
||||
}
|
||||
break;
|
||||
case WLR_XDG_SURFACE_V6_ROLE_POPUP:
|
||||
if (surface->popup) {
|
||||
zxdg_popup_v6_send_popup_done(surface->popup->resource);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void xdg_surface_handle_surface_destroy(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_xdg_surface_v6 *xdg_surface =
|
||||
wl_container_of(listener, xdg_surface, surface_destroy);
|
||||
destroy_xdg_surface_v6(xdg_surface);
|
||||
}
|
||||
|
||||
static void xdg_surface_handle_surface_commit(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_xdg_surface_v6 *surface =
|
||||
wl_container_of(listener, surface, surface_commit);
|
||||
|
||||
if (wlr_surface_has_buffer(surface->surface) && !surface->configured) {
|
||||
wl_resource_post_error(surface->resource,
|
||||
ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER,
|
||||
"xdg_surface has never been configured");
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void handle_xdg_surface_v6_commit(struct wlr_surface *wlr_surface) {
|
||||
struct wlr_xdg_surface_v6 *surface =
|
||||
wlr_xdg_surface_v6_from_wlr_surface(wlr_surface);
|
||||
if (surface == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
switch (surface->role) {
|
||||
case WLR_XDG_SURFACE_V6_ROLE_NONE:
|
||||
assert(false);
|
||||
case WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL:
|
||||
handle_xdg_surface_v6_toplevel_committed(surface);
|
||||
break;
|
||||
case WLR_XDG_SURFACE_V6_ROLE_POPUP:
|
||||
handle_xdg_surface_v6_popup_committed(surface);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!surface->added) {
|
||||
surface->added = true;
|
||||
wlr_signal_emit_safe(&surface->client->shell->events.new_surface,
|
||||
surface);
|
||||
}
|
||||
if (surface->configured && wlr_surface_has_buffer(surface->surface) &&
|
||||
!surface->mapped) {
|
||||
surface->mapped = true;
|
||||
wlr_signal_emit_safe(&surface->events.map, surface);
|
||||
}
|
||||
}
|
||||
|
||||
void handle_xdg_surface_v6_precommit(struct wlr_surface *wlr_surface) {
|
||||
struct wlr_xdg_surface_v6 *surface =
|
||||
wlr_xdg_surface_v6_from_wlr_surface(wlr_surface);
|
||||
if (surface == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (wlr_surface->pending.committed & WLR_SURFACE_STATE_BUFFER &&
|
||||
wlr_surface->pending.buffer_resource == NULL) {
|
||||
// This is a NULL commit
|
||||
if (surface->configured && surface->mapped) {
|
||||
unmap_xdg_surface_v6(surface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void xdg_surface_handle_resource_destroy(struct wl_resource *resource) {
|
||||
struct wlr_xdg_surface_v6 *surface = xdg_surface_from_resource(resource);
|
||||
if (surface != NULL) {
|
||||
destroy_xdg_surface_v6(surface);
|
||||
}
|
||||
}
|
||||
|
||||
struct wlr_xdg_surface_v6 *create_xdg_surface_v6(
|
||||
struct wlr_xdg_client_v6 *client, struct wlr_surface *surface,
|
||||
uint32_t id) {
|
||||
if (wlr_surface_has_buffer(surface)) {
|
||||
wl_resource_post_error(client->resource,
|
||||
ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER,
|
||||
"xdg_surface must not have a buffer at creation");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct wlr_xdg_surface_v6 *xdg_surface =
|
||||
calloc(1, sizeof(struct wlr_xdg_surface_v6));
|
||||
if (xdg_surface == NULL) {
|
||||
wl_client_post_no_memory(client->client);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
xdg_surface->client = client;
|
||||
xdg_surface->role = WLR_XDG_SURFACE_V6_ROLE_NONE;
|
||||
xdg_surface->surface = surface;
|
||||
xdg_surface->resource = wl_resource_create(client->client,
|
||||
&zxdg_surface_v6_interface, wl_resource_get_version(client->resource),
|
||||
id);
|
||||
if (xdg_surface->resource == NULL) {
|
||||
free(xdg_surface);
|
||||
wl_client_post_no_memory(client->client);
|
||||
return NULL;
|
||||
}
|
||||
wl_resource_set_implementation(xdg_surface->resource,
|
||||
&zxdg_surface_v6_implementation, xdg_surface,
|
||||
xdg_surface_handle_resource_destroy);
|
||||
|
||||
wl_list_init(&xdg_surface->configure_list);
|
||||
wl_list_init(&xdg_surface->popups);
|
||||
|
||||
wl_signal_init(&xdg_surface->events.destroy);
|
||||
wl_signal_init(&xdg_surface->events.ping_timeout);
|
||||
wl_signal_init(&xdg_surface->events.new_popup);
|
||||
wl_signal_init(&xdg_surface->events.map);
|
||||
wl_signal_init(&xdg_surface->events.unmap);
|
||||
|
||||
wl_signal_add(&xdg_surface->surface->events.destroy,
|
||||
&xdg_surface->surface_destroy);
|
||||
xdg_surface->surface_destroy.notify = xdg_surface_handle_surface_destroy;
|
||||
|
||||
wl_signal_add(&xdg_surface->surface->events.commit,
|
||||
&xdg_surface->surface_commit);
|
||||
xdg_surface->surface_commit.notify = xdg_surface_handle_surface_commit;
|
||||
|
||||
wlr_log(WLR_DEBUG, "new xdg_surface %p (res %p)", xdg_surface,
|
||||
xdg_surface->resource);
|
||||
wl_list_insert(&client->surfaces, &xdg_surface->link);
|
||||
|
||||
return xdg_surface;
|
||||
}
|
||||
|
||||
static void xdg_popup_v6_get_position(struct wlr_xdg_popup_v6 *popup,
|
||||
double *popup_sx, double *popup_sy) {
|
||||
struct wlr_xdg_surface_v6 *parent = popup->parent;
|
||||
struct wlr_box parent_geo;
|
||||
wlr_xdg_surface_v6_get_geometry(parent, &parent_geo);
|
||||
*popup_sx = parent_geo.x + popup->geometry.x -
|
||||
popup->base->geometry.x;
|
||||
*popup_sy = parent_geo.y + popup->geometry.y -
|
||||
popup->base->geometry.y;
|
||||
}
|
||||
|
||||
struct wlr_surface *wlr_xdg_surface_v6_surface_at(
|
||||
struct wlr_xdg_surface_v6 *surface, double sx, double sy,
|
||||
double *sub_x, double *sub_y) {
|
||||
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;
|
||||
|
||||
double popup_sx, popup_sy;
|
||||
xdg_popup_v6_get_position(popup_state, &popup_sx, &popup_sy);
|
||||
|
||||
struct wlr_surface *sub = wlr_xdg_surface_v6_surface_at(popup,
|
||||
sx - popup_sx,
|
||||
sy - popup_sy,
|
||||
sub_x, sub_y);
|
||||
if (sub != NULL) {
|
||||
return sub;
|
||||
}
|
||||
}
|
||||
|
||||
return wlr_surface_surface_at(surface->surface, sx, sy, sub_x, sub_y);
|
||||
}
|
||||
|
||||
struct xdg_surface_v6_iterator_data {
|
||||
wlr_surface_iterator_func_t user_iterator;
|
||||
void *user_data;
|
||||
int x, y;
|
||||
};
|
||||
|
||||
static void xdg_surface_v6_iterator(struct wlr_surface *surface,
|
||||
int sx, int sy, void *data) {
|
||||
struct xdg_surface_v6_iterator_data *iter_data = data;
|
||||
iter_data->user_iterator(surface, iter_data->x + sx, iter_data->y + sy,
|
||||
iter_data->user_data);
|
||||
}
|
||||
|
||||
static void xdg_surface_v6_for_each_surface(struct wlr_xdg_surface_v6 *surface,
|
||||
int x, int y, wlr_surface_iterator_func_t iterator, void *user_data) {
|
||||
struct xdg_surface_v6_iterator_data data = {
|
||||
.user_iterator = iterator,
|
||||
.user_data = user_data,
|
||||
.x = x, .y = y,
|
||||
};
|
||||
wlr_surface_for_each_surface(surface->surface, xdg_surface_v6_iterator,
|
||||
&data);
|
||||
|
||||
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;
|
||||
if (!popup->configured) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double popup_sx, popup_sy;
|
||||
xdg_popup_v6_get_position(popup_state, &popup_sx, &popup_sy);
|
||||
|
||||
xdg_surface_v6_for_each_surface(popup,
|
||||
x + popup_sx,
|
||||
y + popup_sy,
|
||||
iterator, user_data);
|
||||
}
|
||||
}
|
||||
|
||||
static void xdg_surface_v6_for_each_popup(struct wlr_xdg_surface_v6 *surface,
|
||||
int x, int y, wlr_surface_iterator_func_t iterator, void *user_data) {
|
||||
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;
|
||||
if (!popup->configured) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double popup_sx, popup_sy;
|
||||
xdg_popup_v6_get_position(popup_state, &popup_sx, &popup_sy);
|
||||
iterator(popup->surface, x + popup_sx, y + popup_sy, user_data);
|
||||
|
||||
xdg_surface_v6_for_each_popup(popup,
|
||||
x + popup_sx,
|
||||
y + popup_sy,
|
||||
iterator, user_data);
|
||||
}
|
||||
}
|
||||
|
||||
void wlr_xdg_surface_v6_for_each_surface(struct wlr_xdg_surface_v6 *surface,
|
||||
wlr_surface_iterator_func_t iterator, void *user_data) {
|
||||
xdg_surface_v6_for_each_surface(surface, 0, 0, iterator, user_data);
|
||||
}
|
||||
|
||||
void wlr_xdg_surface_v6_for_each_popup(struct wlr_xdg_surface_v6 *surface,
|
||||
wlr_surface_iterator_func_t iterator, void *user_data) {
|
||||
xdg_surface_v6_for_each_popup(surface, 0, 0, iterator, user_data);
|
||||
}
|
||||
|
||||
void wlr_xdg_surface_v6_get_geometry(struct wlr_xdg_surface_v6 *surface, struct wlr_box *box) {
|
||||
wlr_surface_get_extends(surface->surface, box);
|
||||
/* The client never set the geometry */
|
||||
if (!surface->geometry.width) {
|
||||
return;
|
||||
}
|
||||
|
||||
wlr_box_intersection(box, &surface->geometry, box);
|
||||
}
|
||||
|
|
@ -1,536 +0,0 @@
|
|||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "types/wlr_xdg_shell_v6.h"
|
||||
#include "util/signal.h"
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void destroy_xdg_toplevel_v6(struct wlr_xdg_surface_v6 *surface) {
|
||||
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
|
||||
unmap_xdg_surface_v6(surface);
|
||||
|
||||
if (surface->toplevel->client_pending.fullscreen_output) {
|
||||
struct wlr_xdg_toplevel_v6_state *client_pending =
|
||||
&surface->toplevel->client_pending;
|
||||
wl_list_remove(&client_pending->fullscreen_output_destroy.link);
|
||||
}
|
||||
wl_resource_set_user_data(surface->toplevel->resource, NULL);
|
||||
free(surface->toplevel);
|
||||
surface->toplevel = NULL;
|
||||
|
||||
surface->role = WLR_XDG_SURFACE_V6_ROLE_NONE;
|
||||
}
|
||||
|
||||
static void xdg_toplevel_handle_destroy(struct wl_client *client,
|
||||
struct wl_resource *resource) {
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
|
||||
static void xdg_toplevel_handle_set_parent(struct wl_client *client,
|
||||
struct wl_resource *resource, struct wl_resource *parent_resource) {
|
||||
struct wlr_xdg_surface_v6 *surface =
|
||||
xdg_surface_from_xdg_toplevel_resource(resource);
|
||||
|
||||
struct wlr_xdg_surface_v6 *parent = NULL;
|
||||
if (parent_resource != NULL) {
|
||||
parent = xdg_surface_from_xdg_toplevel_resource(parent_resource);
|
||||
}
|
||||
|
||||
surface->toplevel->parent = parent;
|
||||
wlr_signal_emit_safe(&surface->toplevel->events.set_parent, surface);
|
||||
}
|
||||
|
||||
static void xdg_toplevel_handle_set_title(struct wl_client *client,
|
||||
struct wl_resource *resource, const char *title) {
|
||||
struct wlr_xdg_surface_v6 *surface =
|
||||
xdg_surface_from_xdg_toplevel_resource(resource);
|
||||
|
||||
char *tmp = strdup(title);
|
||||
if (tmp == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
free(surface->toplevel->title);
|
||||
surface->toplevel->title = tmp;
|
||||
wlr_signal_emit_safe(&surface->toplevel->events.set_title, surface);
|
||||
}
|
||||
|
||||
static void xdg_toplevel_handle_set_app_id(struct wl_client *client,
|
||||
struct wl_resource *resource, const char *app_id) {
|
||||
struct wlr_xdg_surface_v6 *surface =
|
||||
xdg_surface_from_xdg_toplevel_resource(resource);
|
||||
|
||||
char *tmp = strdup(app_id);
|
||||
if (tmp == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
free(surface->toplevel->app_id);
|
||||
surface->toplevel->app_id = tmp;
|
||||
wlr_signal_emit_safe(&surface->toplevel->events.set_app_id, surface);
|
||||
}
|
||||
|
||||
static void xdg_toplevel_handle_show_window_menu(struct wl_client *client,
|
||||
struct wl_resource *resource, struct wl_resource *seat_resource,
|
||||
uint32_t serial, int32_t x, int32_t y) {
|
||||
struct wlr_xdg_surface_v6 *surface =
|
||||
xdg_surface_from_xdg_toplevel_resource(resource);
|
||||
struct wlr_seat_client *seat =
|
||||
wlr_seat_client_from_resource(seat_resource);
|
||||
|
||||
if (!surface->configured) {
|
||||
wl_resource_post_error(surface->toplevel->resource,
|
||||
ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
|
||||
"surface has not been configured yet");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!wlr_seat_validate_grab_serial(seat->seat, serial)) {
|
||||
wlr_log(WLR_DEBUG, "invalid serial for grab");
|
||||
return;
|
||||
}
|
||||
|
||||
struct wlr_xdg_toplevel_v6_show_window_menu_event event = {
|
||||
.surface = surface,
|
||||
.seat = seat,
|
||||
.serial = serial,
|
||||
.x = x,
|
||||
.y = y,
|
||||
};
|
||||
|
||||
wlr_signal_emit_safe(&surface->toplevel->events.request_show_window_menu,
|
||||
&event);
|
||||
}
|
||||
|
||||
static void xdg_toplevel_handle_move(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_toplevel_resource(resource);
|
||||
struct wlr_seat_client *seat =
|
||||
wlr_seat_client_from_resource(seat_resource);
|
||||
|
||||
if (!surface->configured) {
|
||||
wl_resource_post_error(surface->toplevel->resource,
|
||||
ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
|
||||
"surface has not been configured yet");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!wlr_seat_validate_grab_serial(seat->seat, serial)) {
|
||||
wlr_log(WLR_DEBUG, "invalid serial for grab");
|
||||
return;
|
||||
}
|
||||
|
||||
struct wlr_xdg_toplevel_v6_move_event event = {
|
||||
.surface = surface,
|
||||
.seat = seat,
|
||||
.serial = serial,
|
||||
};
|
||||
|
||||
wlr_signal_emit_safe(&surface->toplevel->events.request_move, &event);
|
||||
}
|
||||
|
||||
static void xdg_toplevel_handle_resize(struct wl_client *client,
|
||||
struct wl_resource *resource, struct wl_resource *seat_resource,
|
||||
uint32_t serial, uint32_t edges) {
|
||||
struct wlr_xdg_surface_v6 *surface =
|
||||
xdg_surface_from_xdg_toplevel_resource(resource);
|
||||
struct wlr_seat_client *seat =
|
||||
wlr_seat_client_from_resource(seat_resource);
|
||||
|
||||
if (!surface->configured) {
|
||||
wl_resource_post_error(surface->toplevel->resource,
|
||||
ZXDG_SURFACE_V6_ERROR_NOT_CONSTRUCTED,
|
||||
"surface has not been configured yet");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!wlr_seat_validate_grab_serial(seat->seat, serial)) {
|
||||
wlr_log(WLR_DEBUG, "invalid serial for grab");
|
||||
return;
|
||||
}
|
||||
|
||||
struct wlr_xdg_toplevel_v6_resize_event event = {
|
||||
.surface = surface,
|
||||
.seat = seat,
|
||||
.serial = serial,
|
||||
.edges = edges,
|
||||
};
|
||||
|
||||
wlr_signal_emit_safe(&surface->toplevel->events.request_resize, &event);
|
||||
}
|
||||
|
||||
static void xdg_toplevel_handle_set_max_size(struct wl_client *client,
|
||||
struct wl_resource *resource, int32_t width, int32_t height) {
|
||||
struct wlr_xdg_surface_v6 *surface =
|
||||
xdg_surface_from_xdg_toplevel_resource(resource);
|
||||
surface->toplevel->client_pending.max_width = width;
|
||||
surface->toplevel->client_pending.max_height = height;
|
||||
}
|
||||
|
||||
static void xdg_toplevel_handle_set_min_size(struct wl_client *client,
|
||||
struct wl_resource *resource, int32_t width, int32_t height) {
|
||||
struct wlr_xdg_surface_v6 *surface =
|
||||
xdg_surface_from_xdg_toplevel_resource(resource);
|
||||
surface->toplevel->client_pending.min_width = width;
|
||||
surface->toplevel->client_pending.min_height = height;
|
||||
}
|
||||
|
||||
static void xdg_toplevel_handle_set_maximized(struct wl_client *client,
|
||||
struct wl_resource *resource) {
|
||||
struct wlr_xdg_surface_v6 *surface =
|
||||
xdg_surface_from_xdg_toplevel_resource(resource);
|
||||
surface->toplevel->client_pending.maximized = true;
|
||||
wlr_signal_emit_safe(&surface->toplevel->events.request_maximize, surface);
|
||||
}
|
||||
|
||||
static void xdg_toplevel_handle_unset_maximized(struct wl_client *client,
|
||||
struct wl_resource *resource) {
|
||||
struct wlr_xdg_surface_v6 *surface =
|
||||
xdg_surface_from_xdg_toplevel_resource(resource);
|
||||
surface->toplevel->client_pending.maximized = false;
|
||||
wlr_signal_emit_safe(&surface->toplevel->events.request_maximize, surface);
|
||||
}
|
||||
|
||||
static void handle_fullscreen_output_destroy(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_xdg_toplevel_v6_state *state =
|
||||
wl_container_of(listener, state, fullscreen_output_destroy);
|
||||
state->fullscreen_output = NULL;
|
||||
wl_list_remove(&state->fullscreen_output_destroy.link);
|
||||
}
|
||||
|
||||
static void store_fullscreen_pending(struct wlr_xdg_surface_v6 *surface,
|
||||
bool fullscreen, struct wlr_output *output) {
|
||||
struct wlr_xdg_toplevel_v6_state *state =
|
||||
&surface->toplevel->client_pending;
|
||||
state->fullscreen = fullscreen;
|
||||
if (state->fullscreen_output) {
|
||||
wl_list_remove(&state->fullscreen_output_destroy.link);
|
||||
}
|
||||
state->fullscreen_output = output;
|
||||
if (state->fullscreen_output) {
|
||||
state->fullscreen_output_destroy.notify =
|
||||
handle_fullscreen_output_destroy;
|
||||
wl_signal_add(&state->fullscreen_output->events.destroy,
|
||||
&state->fullscreen_output_destroy);
|
||||
}
|
||||
}
|
||||
|
||||
static void xdg_toplevel_handle_set_fullscreen(struct wl_client *client,
|
||||
struct wl_resource *resource, struct wl_resource *output_resource) {
|
||||
struct wlr_xdg_surface_v6 *surface =
|
||||
xdg_surface_from_xdg_toplevel_resource(resource);
|
||||
|
||||
struct wlr_output *output = NULL;
|
||||
if (output_resource != NULL) {
|
||||
output = wlr_output_from_resource(output_resource);
|
||||
}
|
||||
|
||||
store_fullscreen_pending(surface, true, output);
|
||||
|
||||
struct wlr_xdg_toplevel_v6_set_fullscreen_event event = {
|
||||
.surface = surface,
|
||||
.fullscreen = true,
|
||||
.output = output,
|
||||
};
|
||||
|
||||
wlr_signal_emit_safe(&surface->toplevel->events.request_fullscreen, &event);
|
||||
}
|
||||
|
||||
static void xdg_toplevel_handle_unset_fullscreen(struct wl_client *client,
|
||||
struct wl_resource *resource) {
|
||||
struct wlr_xdg_surface_v6 *surface =
|
||||
xdg_surface_from_xdg_toplevel_resource(resource);
|
||||
|
||||
store_fullscreen_pending(surface, false, NULL);
|
||||
|
||||
struct wlr_xdg_toplevel_v6_set_fullscreen_event event = {
|
||||
.surface = surface,
|
||||
.fullscreen = false,
|
||||
.output = NULL,
|
||||
};
|
||||
|
||||
wlr_signal_emit_safe(&surface->toplevel->events.request_fullscreen, &event);
|
||||
}
|
||||
|
||||
static void xdg_toplevel_handle_set_minimized(struct wl_client *client,
|
||||
struct wl_resource *resource) {
|
||||
struct wlr_xdg_surface_v6 *surface =
|
||||
xdg_surface_from_xdg_toplevel_resource(resource);
|
||||
wlr_signal_emit_safe(&surface->toplevel->events.request_minimize, surface);
|
||||
}
|
||||
|
||||
static const struct zxdg_toplevel_v6_interface
|
||||
zxdg_toplevel_v6_implementation = {
|
||||
.destroy = xdg_toplevel_handle_destroy,
|
||||
.set_parent = xdg_toplevel_handle_set_parent,
|
||||
.set_title = xdg_toplevel_handle_set_title,
|
||||
.set_app_id = xdg_toplevel_handle_set_app_id,
|
||||
.show_window_menu = xdg_toplevel_handle_show_window_menu,
|
||||
.move = xdg_toplevel_handle_move,
|
||||
.resize = xdg_toplevel_handle_resize,
|
||||
.set_max_size = xdg_toplevel_handle_set_max_size,
|
||||
.set_min_size = xdg_toplevel_handle_set_min_size,
|
||||
.set_maximized = xdg_toplevel_handle_set_maximized,
|
||||
.unset_maximized = xdg_toplevel_handle_unset_maximized,
|
||||
.set_fullscreen = xdg_toplevel_handle_set_fullscreen,
|
||||
.unset_fullscreen = xdg_toplevel_handle_unset_fullscreen,
|
||||
.set_minimized = xdg_toplevel_handle_set_minimized,
|
||||
};
|
||||
|
||||
void handle_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);
|
||||
assert(configure->toplevel_state != NULL);
|
||||
|
||||
surface->toplevel->current.maximized =
|
||||
configure->toplevel_state->maximized;
|
||||
surface->toplevel->current.fullscreen =
|
||||
configure->toplevel_state->fullscreen;
|
||||
surface->toplevel->current.resizing =
|
||||
configure->toplevel_state->resizing;
|
||||
surface->toplevel->current.activated =
|
||||
configure->toplevel_state->activated;
|
||||
}
|
||||
|
||||
bool compare_xdg_surface_v6_toplevel_state(struct wlr_xdg_toplevel_v6 *state) {
|
||||
struct {
|
||||
struct wlr_xdg_toplevel_v6_state state;
|
||||
uint32_t width, height;
|
||||
} configured;
|
||||
|
||||
// is pending state different from current state?
|
||||
if (!state->base->configured) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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.height;
|
||||
} else {
|
||||
struct wlr_xdg_surface_v6_configure *configure =
|
||||
wl_container_of(state->base->configure_list.prev, configure, link);
|
||||
configured.state = *configure->toplevel_state;
|
||||
configured.width = configure->toplevel_state->width;
|
||||
configured.height = configure->toplevel_state->height;
|
||||
}
|
||||
|
||||
if (state->server_pending.activated != configured.state.activated) {
|
||||
return false;
|
||||
}
|
||||
if (state->server_pending.fullscreen != configured.state.fullscreen) {
|
||||
return false;
|
||||
}
|
||||
if (state->server_pending.maximized != configured.state.maximized) {
|
||||
return false;
|
||||
}
|
||||
if (state->server_pending.resizing != configured.state.resizing) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (state->server_pending.width == configured.width &&
|
||||
state->server_pending.height == configured.height) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (state->server_pending.width == 0 && state->server_pending.height == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void send_xdg_toplevel_v6_configure(struct wlr_xdg_surface_v6 *surface,
|
||||
struct wlr_xdg_surface_v6_configure *configure) {
|
||||
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
|
||||
|
||||
configure->toplevel_state = malloc(sizeof(*configure->toplevel_state));
|
||||
if (configure->toplevel_state == NULL) {
|
||||
wlr_log(WLR_ERROR, "Allocation failed");
|
||||
wl_resource_post_no_memory(surface->toplevel->resource);
|
||||
return;
|
||||
}
|
||||
*configure->toplevel_state = surface->toplevel->server_pending;
|
||||
|
||||
uint32_t *s;
|
||||
struct wl_array states;
|
||||
wl_array_init(&states);
|
||||
if (surface->toplevel->server_pending.maximized) {
|
||||
s = wl_array_add(&states, sizeof(uint32_t));
|
||||
if (!s) {
|
||||
wlr_log(WLR_ERROR,
|
||||
"Could not allocate state for maximized xdg_toplevel");
|
||||
goto error_out;
|
||||
}
|
||||
*s = ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED;
|
||||
}
|
||||
if (surface->toplevel->server_pending.fullscreen) {
|
||||
s = wl_array_add(&states, sizeof(uint32_t));
|
||||
if (!s) {
|
||||
wlr_log(WLR_ERROR,
|
||||
"Could not allocate state for fullscreen xdg_toplevel");
|
||||
goto error_out;
|
||||
}
|
||||
*s = ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN;
|
||||
}
|
||||
if (surface->toplevel->server_pending.resizing) {
|
||||
s = wl_array_add(&states, sizeof(uint32_t));
|
||||
if (!s) {
|
||||
wlr_log(WLR_ERROR,
|
||||
"Could not allocate state for resizing xdg_toplevel");
|
||||
goto error_out;
|
||||
}
|
||||
*s = ZXDG_TOPLEVEL_V6_STATE_RESIZING;
|
||||
}
|
||||
if (surface->toplevel->server_pending.activated) {
|
||||
s = wl_array_add(&states, sizeof(uint32_t));
|
||||
if (!s) {
|
||||
wlr_log(WLR_ERROR,
|
||||
"Could not allocate state for activated xdg_toplevel");
|
||||
goto error_out;
|
||||
}
|
||||
*s = ZXDG_TOPLEVEL_V6_STATE_ACTIVATED;
|
||||
}
|
||||
|
||||
uint32_t width = surface->toplevel->server_pending.width;
|
||||
uint32_t height = surface->toplevel->server_pending.height;
|
||||
zxdg_toplevel_v6_send_configure(surface->toplevel->resource, width,
|
||||
height, &states);
|
||||
|
||||
wl_array_release(&states);
|
||||
return;
|
||||
|
||||
error_out:
|
||||
wl_array_release(&states);
|
||||
wl_resource_post_no_memory(surface->toplevel->resource);
|
||||
}
|
||||
|
||||
void handle_xdg_surface_v6_toplevel_committed(struct wlr_xdg_surface_v6 *surface) {
|
||||
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
|
||||
|
||||
if (!surface->toplevel->added) {
|
||||
// on the first commit, send a configure request to tell the client it
|
||||
// is added
|
||||
schedule_xdg_surface_v6_configure(surface);
|
||||
surface->toplevel->added = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// update state that doesn't need compositor approval
|
||||
surface->toplevel->current.max_width =
|
||||
surface->toplevel->client_pending.max_width;
|
||||
surface->toplevel->current.min_width =
|
||||
surface->toplevel->client_pending.min_width;
|
||||
surface->toplevel->current.max_height =
|
||||
surface->toplevel->client_pending.max_height;
|
||||
surface->toplevel->current.min_height =
|
||||
surface->toplevel->client_pending.min_height;
|
||||
}
|
||||
|
||||
static void xdg_toplevel_handle_resource_destroy(struct wl_resource *resource) {
|
||||
struct wlr_xdg_surface_v6 *surface =
|
||||
xdg_surface_from_xdg_toplevel_resource(resource);
|
||||
if (surface != NULL) {
|
||||
destroy_xdg_toplevel_v6(surface);
|
||||
}
|
||||
}
|
||||
|
||||
const struct wlr_surface_role xdg_toplevel_v6_surface_role = {
|
||||
.name = "xdg_toplevel_v6",
|
||||
.commit = handle_xdg_surface_v6_commit,
|
||||
.precommit = handle_xdg_surface_v6_precommit,
|
||||
};
|
||||
|
||||
void create_xdg_toplevel_v6(struct wlr_xdg_surface_v6 *xdg_surface,
|
||||
uint32_t id) {
|
||||
if (!wlr_surface_set_role(xdg_surface->surface, &xdg_toplevel_v6_surface_role,
|
||||
xdg_surface, xdg_surface->resource, ZXDG_SHELL_V6_ERROR_ROLE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
xdg_surface->toplevel = calloc(1, sizeof(struct wlr_xdg_toplevel_v6));
|
||||
if (xdg_surface->toplevel == NULL) {
|
||||
wl_resource_post_no_memory(xdg_surface->resource);
|
||||
return;
|
||||
}
|
||||
wl_signal_init(&xdg_surface->toplevel->events.request_maximize);
|
||||
wl_signal_init(&xdg_surface->toplevel->events.request_fullscreen);
|
||||
wl_signal_init(&xdg_surface->toplevel->events.request_minimize);
|
||||
wl_signal_init(&xdg_surface->toplevel->events.request_move);
|
||||
wl_signal_init(&xdg_surface->toplevel->events.request_resize);
|
||||
wl_signal_init(&xdg_surface->toplevel->events.request_show_window_menu);
|
||||
wl_signal_init(&xdg_surface->toplevel->events.set_parent);
|
||||
wl_signal_init(&xdg_surface->toplevel->events.set_title);
|
||||
wl_signal_init(&xdg_surface->toplevel->events.set_app_id);
|
||||
|
||||
xdg_surface->role = WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL;
|
||||
xdg_surface->toplevel->base = xdg_surface;
|
||||
|
||||
struct wl_resource *toplevel_resource = wl_resource_create(
|
||||
xdg_surface->client->client, &zxdg_toplevel_v6_interface,
|
||||
wl_resource_get_version(xdg_surface->resource), id);
|
||||
if (toplevel_resource == NULL) {
|
||||
free(xdg_surface->toplevel);
|
||||
wl_resource_post_no_memory(xdg_surface->resource);
|
||||
return;
|
||||
}
|
||||
xdg_surface->toplevel->resource = toplevel_resource;
|
||||
wl_resource_set_implementation(toplevel_resource,
|
||||
&zxdg_toplevel_v6_implementation, xdg_surface,
|
||||
xdg_toplevel_handle_resource_destroy);
|
||||
}
|
||||
|
||||
uint32_t wlr_xdg_toplevel_v6_set_size(struct wlr_xdg_surface_v6 *surface,
|
||||
uint32_t width, uint32_t height) {
|
||||
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
|
||||
surface->toplevel->server_pending.width = width;
|
||||
surface->toplevel->server_pending.height = height;
|
||||
|
||||
return schedule_xdg_surface_v6_configure(surface);
|
||||
}
|
||||
|
||||
uint32_t wlr_xdg_toplevel_v6_set_activated(struct wlr_xdg_surface_v6 *surface,
|
||||
bool activated) {
|
||||
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
|
||||
surface->toplevel->server_pending.activated = activated;
|
||||
|
||||
return schedule_xdg_surface_v6_configure(surface);
|
||||
}
|
||||
|
||||
uint32_t wlr_xdg_toplevel_v6_set_maximized(struct wlr_xdg_surface_v6 *surface,
|
||||
bool maximized) {
|
||||
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
|
||||
surface->toplevel->server_pending.maximized = maximized;
|
||||
|
||||
return schedule_xdg_surface_v6_configure(surface);
|
||||
}
|
||||
|
||||
uint32_t wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface,
|
||||
bool fullscreen) {
|
||||
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
|
||||
surface->toplevel->server_pending.fullscreen = fullscreen;
|
||||
|
||||
return schedule_xdg_surface_v6_configure(surface);
|
||||
}
|
||||
|
||||
uint32_t wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface,
|
||||
bool resizing) {
|
||||
assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL);
|
||||
surface->toplevel->server_pending.resizing = resizing;
|
||||
|
||||
return schedule_xdg_surface_v6_configure(surface);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue