mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-11-22 06:59:44 -05:00
Merge branch 'master' into screencontent
This commit is contained in:
commit
57548b557a
43 changed files with 886 additions and 375 deletions
|
|
@ -44,7 +44,7 @@ static void drag_set_focus(struct wlr_drag *drag,
|
|||
|
||||
if (!drag->source &&
|
||||
wl_resource_get_client(surface->resource) !=
|
||||
wl_resource_get_client(drag->seat_client->wl_resource)) {
|
||||
drag->seat_client->client) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -98,6 +98,16 @@ static void drag_set_focus(struct wlr_drag *drag,
|
|||
wlr_signal_emit_safe(&drag->events.focus, drag);
|
||||
}
|
||||
|
||||
static void drag_icon_set_mapped(struct wlr_drag_icon *icon, bool mapped) {
|
||||
if (mapped && !icon->mapped) {
|
||||
icon->mapped = true;
|
||||
wlr_signal_emit_safe(&icon->events.map, icon);
|
||||
} else if (!mapped && icon->mapped) {
|
||||
icon->mapped = false;
|
||||
wlr_signal_emit_safe(&icon->events.unmap, icon);
|
||||
}
|
||||
}
|
||||
|
||||
static void drag_end(struct wlr_drag *drag) {
|
||||
if (!drag->cancelling) {
|
||||
drag->cancelling = true;
|
||||
|
|
@ -115,9 +125,8 @@ static void drag_end(struct wlr_drag *drag) {
|
|||
drag_set_focus(drag, NULL, 0, 0);
|
||||
|
||||
if (drag->icon) {
|
||||
drag->icon->mapped = false;
|
||||
wl_list_remove(&drag->icon_destroy.link);
|
||||
wlr_signal_emit_safe(&drag->icon->events.map, drag->icon);
|
||||
drag_icon_set_mapped(drag->icon, false);
|
||||
}
|
||||
|
||||
wlr_signal_emit_safe(&drag->events.destroy, drag);
|
||||
|
|
@ -310,9 +319,10 @@ static void drag_handle_drag_source_destroy(struct wl_listener *listener,
|
|||
|
||||
|
||||
static void drag_icon_destroy(struct wlr_drag_icon *icon) {
|
||||
if (!icon) {
|
||||
if (icon == NULL) {
|
||||
return;
|
||||
}
|
||||
drag_icon_set_mapped(icon, false);
|
||||
wlr_signal_emit_safe(&icon->events.destroy, icon);
|
||||
wlr_surface_set_role_committed(icon->surface, NULL, NULL);
|
||||
wl_list_remove(&icon->surface_destroy.link);
|
||||
|
|
@ -333,6 +343,8 @@ static void drag_icon_handle_surface_commit(struct wlr_surface *surface,
|
|||
struct wlr_drag_icon *icon = role_data;
|
||||
icon->sx += icon->surface->current->sx;
|
||||
icon->sy += icon->surface->current->sy;
|
||||
|
||||
drag_icon_set_mapped(icon, wlr_surface_has_buffer(surface));
|
||||
}
|
||||
|
||||
static void drag_icon_handle_seat_client_destroy(struct wl_listener *listener,
|
||||
|
|
@ -355,9 +367,9 @@ static struct wlr_drag_icon *drag_icon_create(
|
|||
icon->client = client;
|
||||
icon->is_pointer = is_pointer;
|
||||
icon->touch_id = touch_id;
|
||||
icon->mapped = true;
|
||||
|
||||
wl_signal_init(&icon->events.map);
|
||||
wl_signal_init(&icon->events.unmap);
|
||||
wl_signal_init(&icon->events.destroy);
|
||||
|
||||
wl_signal_add(&icon->surface->events.destroy, &icon->surface_destroy);
|
||||
|
|
@ -372,6 +384,10 @@ static struct wlr_drag_icon *drag_icon_create(
|
|||
wl_list_insert(&client->seat->drag_icons, &icon->link);
|
||||
wlr_signal_emit_safe(&client->seat->events.new_drag_icon, icon);
|
||||
|
||||
if (wlr_surface_has_buffer(icon_surface)) {
|
||||
drag_icon_set_mapped(icon, true);
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ lib_wlr_types = static_library(
|
|||
'xdg_shell_v6/wlr_xdg_surface_v6.c',
|
||||
'xdg_shell_v6/wlr_xdg_toplevel_v6.c',
|
||||
'wlr_box.c',
|
||||
'wlr_buffer.c',
|
||||
'wlr_compositor.c',
|
||||
'wlr_cursor.c',
|
||||
'wlr_export_dmabuf_v1.c',
|
||||
|
|
|
|||
|
|
@ -60,6 +60,12 @@ static void seat_client_handle_resource_destroy(
|
|||
struct wl_resource *seat_resource) {
|
||||
struct wlr_seat_client *client =
|
||||
wlr_seat_client_from_resource(seat_resource);
|
||||
|
||||
wl_list_remove(wl_resource_get_link(seat_resource));
|
||||
if (!wl_list_empty(&client->wl_resources)) {
|
||||
return;
|
||||
}
|
||||
|
||||
wlr_signal_emit_safe(&client->events.destroy, client);
|
||||
|
||||
if (client == client->seat->pointer_state.focused_client) {
|
||||
|
|
@ -108,34 +114,43 @@ static void seat_handle_bind(struct wl_client *client, void *_wlr_seat,
|
|||
struct wlr_seat *wlr_seat = _wlr_seat;
|
||||
assert(client && wlr_seat);
|
||||
|
||||
struct wlr_seat_client *seat_client =
|
||||
calloc(1, sizeof(struct wlr_seat_client));
|
||||
if (seat_client == NULL) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
seat_client->wl_resource =
|
||||
struct wl_resource *wl_resource =
|
||||
wl_resource_create(client, &wl_seat_interface, version, id);
|
||||
if (seat_client->wl_resource == NULL) {
|
||||
free(seat_client);
|
||||
if (wl_resource == NULL) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
seat_client->client = client;
|
||||
seat_client->seat = wlr_seat;
|
||||
wl_list_init(&seat_client->pointers);
|
||||
wl_list_init(&seat_client->keyboards);
|
||||
wl_list_init(&seat_client->touches);
|
||||
wl_list_init(&seat_client->data_devices);
|
||||
wl_list_init(&seat_client->primary_selection_devices);
|
||||
wl_resource_set_implementation(seat_client->wl_resource, &seat_impl,
|
||||
seat_client, seat_client_handle_resource_destroy);
|
||||
wl_list_insert(&wlr_seat->clients, &seat_client->link);
|
||||
if (version >= WL_SEAT_NAME_SINCE_VERSION) {
|
||||
wl_seat_send_name(seat_client->wl_resource, wlr_seat->name);
|
||||
|
||||
struct wlr_seat_client *seat_client =
|
||||
wlr_seat_client_for_wl_client(wlr_seat, client);
|
||||
if (seat_client == NULL) {
|
||||
seat_client = calloc(1, sizeof(struct wlr_seat_client));
|
||||
if (seat_client == NULL) {
|
||||
wl_resource_destroy(wl_resource);
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
|
||||
seat_client->client = client;
|
||||
seat_client->seat = wlr_seat;
|
||||
wl_list_init(&seat_client->wl_resources);
|
||||
wl_list_init(&seat_client->pointers);
|
||||
wl_list_init(&seat_client->keyboards);
|
||||
wl_list_init(&seat_client->touches);
|
||||
wl_list_init(&seat_client->data_devices);
|
||||
wl_list_init(&seat_client->primary_selection_devices);
|
||||
wl_signal_init(&seat_client->events.destroy);
|
||||
|
||||
wl_list_insert(&wlr_seat->clients, &seat_client->link);
|
||||
}
|
||||
wl_seat_send_capabilities(seat_client->wl_resource, wlr_seat->capabilities);
|
||||
wl_signal_init(&seat_client->events.destroy);
|
||||
|
||||
wl_resource_set_implementation(wl_resource, &seat_impl,
|
||||
seat_client, seat_client_handle_resource_destroy);
|
||||
wl_list_insert(&seat_client->wl_resources, wl_resource_get_link(wl_resource));
|
||||
if (version >= WL_SEAT_NAME_SINCE_VERSION) {
|
||||
wl_seat_send_name(wl_resource, wlr_seat->name);
|
||||
}
|
||||
wl_seat_send_capabilities(wl_resource, wlr_seat->capabilities);
|
||||
}
|
||||
|
||||
void wlr_seat_destroy(struct wlr_seat *seat) {
|
||||
|
|
@ -160,8 +175,11 @@ void wlr_seat_destroy(struct wlr_seat *seat) {
|
|||
|
||||
struct wlr_seat_client *client, *tmp;
|
||||
wl_list_for_each_safe(client, tmp, &seat->clients, link) {
|
||||
// will destroy other resources as well
|
||||
wl_resource_destroy(client->wl_resource);
|
||||
struct wl_resource *resource, *next_resource;
|
||||
wl_resource_for_each_safe(resource, next_resource, &client->wl_resources) {
|
||||
// will destroy other resources as well
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
}
|
||||
|
||||
wl_global_destroy(seat->wl_global);
|
||||
|
|
@ -308,7 +326,10 @@ void wlr_seat_set_capabilities(struct wlr_seat *wlr_seat,
|
|||
}
|
||||
}
|
||||
|
||||
wl_seat_send_capabilities(client->wl_resource, capabilities);
|
||||
struct wl_resource *resource;
|
||||
wl_resource_for_each(resource, &client->wl_resources) {
|
||||
wl_seat_send_capabilities(resource, capabilities);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -317,7 +338,10 @@ void wlr_seat_set_name(struct wlr_seat *wlr_seat, const char *name) {
|
|||
wlr_seat->name = strdup(name);
|
||||
struct wlr_seat_client *client;
|
||||
wl_list_for_each(client, &wlr_seat->clients, link) {
|
||||
wl_seat_send_name(client->wl_resource, name);
|
||||
struct wl_resource *resource;
|
||||
wl_resource_for_each(resource, &client->wl_resources) {
|
||||
wl_seat_send_name(resource, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ void wlr_box_closest_point(const struct wlr_box *box, double x, double y,
|
|||
// find the closest x point
|
||||
if (x < box->x) {
|
||||
*dest_x = box->x;
|
||||
} else if (x > box->x + box->width) {
|
||||
*dest_x = box->x + box->width;
|
||||
} else if (x >= box->x + box->width) {
|
||||
*dest_x = box->x + box->width - 1;
|
||||
} else {
|
||||
*dest_x = x;
|
||||
}
|
||||
|
|
@ -20,8 +20,8 @@ void wlr_box_closest_point(const struct wlr_box *box, double x, double y,
|
|||
// find closest y point
|
||||
if (y < box->y) {
|
||||
*dest_y = box->y;
|
||||
} else if (y > box->y + box->height) {
|
||||
*dest_y = box->y + box->height;
|
||||
} else if (y >= box->y + box->height) {
|
||||
*dest_y = box->y + box->height - 1;
|
||||
} else {
|
||||
*dest_y = y;
|
||||
}
|
||||
|
|
|
|||
193
types/wlr_buffer.c
Normal file
193
types/wlr_buffer.c
Normal file
|
|
@ -0,0 +1,193 @@
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <wlr/types/wlr_buffer.h>
|
||||
#include <wlr/types/wlr_linux_dmabuf.h>
|
||||
#include <wlr/render/wlr_renderer.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
||||
bool wlr_resource_is_buffer(struct wl_resource *resource) {
|
||||
return strcmp(wl_resource_get_class(resource), wl_buffer_interface.name) == 0;
|
||||
}
|
||||
|
||||
bool wlr_buffer_get_resource_size(struct wl_resource *resource,
|
||||
struct wlr_renderer *renderer, int *width, int *height) {
|
||||
assert(wlr_resource_is_buffer(resource));
|
||||
|
||||
struct wl_shm_buffer *shm_buf = wl_shm_buffer_get(resource);
|
||||
if (shm_buf != NULL) {
|
||||
*width = wl_shm_buffer_get_width(shm_buf);
|
||||
*height = wl_shm_buffer_get_height(shm_buf);
|
||||
} else if (wlr_renderer_resource_is_wl_drm_buffer(renderer,
|
||||
resource)) {
|
||||
wlr_renderer_wl_drm_buffer_get_size(renderer, resource,
|
||||
width, height);
|
||||
} else if (wlr_dmabuf_resource_is_buffer(resource)) {
|
||||
struct wlr_dmabuf_buffer *dmabuf =
|
||||
wlr_dmabuf_buffer_from_buffer_resource(resource);
|
||||
*width = dmabuf->attributes.width;
|
||||
*height = dmabuf->attributes.height;
|
||||
} else {
|
||||
*width = *height = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static void buffer_resource_handle_destroy(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_buffer *buffer =
|
||||
wl_container_of(listener, buffer, resource_destroy);
|
||||
wl_list_remove(&buffer->resource_destroy.link);
|
||||
wl_list_init(&buffer->resource_destroy.link);
|
||||
buffer->resource = NULL;
|
||||
|
||||
// At this point, if the wl_buffer comes from linux-dmabuf or wl_drm, we
|
||||
// still haven't released it (ie. we'll read it in the future) but the
|
||||
// client destroyed it. Reading the texture itself should be fine because
|
||||
// we still hold a reference to the DMA-BUF via the texture. However the
|
||||
// client could decide to re-use the same DMA-BUF for something else, in
|
||||
// which case we'll read garbage. We decide to accept this risk.
|
||||
}
|
||||
|
||||
struct wlr_buffer *wlr_buffer_create(struct wlr_renderer *renderer,
|
||||
struct wl_resource *resource) {
|
||||
assert(wlr_resource_is_buffer(resource));
|
||||
|
||||
struct wlr_texture *texture = NULL;
|
||||
bool released = false;
|
||||
|
||||
struct wl_shm_buffer *shm_buf = wl_shm_buffer_get(resource);
|
||||
if (shm_buf != NULL) {
|
||||
enum wl_shm_format fmt = wl_shm_buffer_get_format(shm_buf);
|
||||
int32_t stride = wl_shm_buffer_get_stride(shm_buf);
|
||||
int32_t width = wl_shm_buffer_get_width(shm_buf);
|
||||
int32_t height = wl_shm_buffer_get_height(shm_buf);
|
||||
|
||||
wl_shm_buffer_begin_access(shm_buf);
|
||||
void *data = wl_shm_buffer_get_data(shm_buf);
|
||||
texture = wlr_texture_from_pixels(renderer, fmt, stride,
|
||||
width, height, data);
|
||||
wl_shm_buffer_end_access(shm_buf);
|
||||
|
||||
// We have uploaded the data, we don't need to access the wl_buffer
|
||||
// anymore
|
||||
wl_buffer_send_release(resource);
|
||||
released = true;
|
||||
} else if (wlr_renderer_resource_is_wl_drm_buffer(renderer, resource)) {
|
||||
texture = wlr_texture_from_wl_drm(renderer, resource);
|
||||
} else if (wlr_dmabuf_resource_is_buffer(resource)) {
|
||||
struct wlr_dmabuf_buffer *dmabuf =
|
||||
wlr_dmabuf_buffer_from_buffer_resource(resource);
|
||||
texture = wlr_texture_from_dmabuf(renderer, &dmabuf->attributes);
|
||||
|
||||
// We have imported the DMA-BUF, but we need to prevent the client from
|
||||
// re-using the same DMA-BUF for the next frames, so we don't release
|
||||
// the buffer yet.
|
||||
} else {
|
||||
wlr_log(L_ERROR, "Cannot upload texture: unknown buffer type");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (texture == NULL) {
|
||||
wlr_log(L_ERROR, "Failed to upload texture");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct wlr_buffer *buffer = calloc(1, sizeof(struct wlr_buffer));
|
||||
if (buffer == NULL) {
|
||||
wlr_texture_destroy(texture);
|
||||
return NULL;
|
||||
}
|
||||
buffer->resource = resource;
|
||||
buffer->texture = texture;
|
||||
buffer->released = released;
|
||||
buffer->n_refs = 1;
|
||||
|
||||
wl_resource_add_destroy_listener(resource, &buffer->resource_destroy);
|
||||
buffer->resource_destroy.notify = buffer_resource_handle_destroy;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
struct wlr_buffer *wlr_buffer_ref(struct wlr_buffer *buffer) {
|
||||
buffer->n_refs++;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void wlr_buffer_unref(struct wlr_buffer *buffer) {
|
||||
if (buffer == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert(buffer->n_refs > 0);
|
||||
buffer->n_refs--;
|
||||
if (buffer->n_refs > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!buffer->released && buffer->resource != NULL) {
|
||||
wl_buffer_send_release(buffer->resource);
|
||||
}
|
||||
|
||||
wl_list_remove(&buffer->resource_destroy.link);
|
||||
wlr_texture_destroy(buffer->texture);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
struct wlr_buffer *wlr_buffer_apply_damage(struct wlr_buffer *buffer,
|
||||
struct wl_resource *resource, pixman_region32_t *damage) {
|
||||
assert(wlr_resource_is_buffer(resource));
|
||||
|
||||
if (buffer->n_refs > 1) {
|
||||
// Someone else still has a reference to the buffer
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct wl_shm_buffer *shm_buf = wl_shm_buffer_get(resource);
|
||||
if (shm_buf == NULL) {
|
||||
// Uploading only damaged regions only works for wl_shm buffers
|
||||
return NULL;
|
||||
}
|
||||
|
||||
enum wl_shm_format fmt = wl_shm_buffer_get_format(shm_buf);
|
||||
int32_t stride = wl_shm_buffer_get_stride(shm_buf);
|
||||
int32_t width = wl_shm_buffer_get_width(shm_buf);
|
||||
int32_t height = wl_shm_buffer_get_height(shm_buf);
|
||||
|
||||
int32_t texture_width, texture_height;
|
||||
wlr_texture_get_size(buffer->texture, &texture_width, &texture_height);
|
||||
if (width != texture_width || height != texture_height) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wl_shm_buffer_begin_access(shm_buf);
|
||||
void *data = wl_shm_buffer_get_data(shm_buf);
|
||||
|
||||
int n;
|
||||
pixman_box32_t *rects = pixman_region32_rectangles(damage, &n);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
pixman_box32_t *r = &rects[i];
|
||||
if (!wlr_texture_write_pixels(buffer->texture, fmt, stride,
|
||||
r->x2 - r->x1, r->y2 - r->y1, r->x1, r->y1,
|
||||
r->x1, r->y1, data)) {
|
||||
wl_shm_buffer_end_access(shm_buf);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
wl_shm_buffer_end_access(shm_buf);
|
||||
|
||||
// We have uploaded the data, we don't need to access the wl_buffer
|
||||
// anymore
|
||||
wl_buffer_send_release(resource);
|
||||
|
||||
wl_list_remove(&buffer->resource_destroy.link);
|
||||
wl_resource_add_destroy_listener(resource, &buffer->resource_destroy);
|
||||
buffer->resource_destroy.notify = buffer_resource_handle_destroy;
|
||||
|
||||
buffer->resource = resource;
|
||||
buffer->released = true;
|
||||
return buffer;
|
||||
}
|
||||
|
|
@ -176,7 +176,9 @@ static void layer_surface_unmap(struct wlr_layer_surface *surface) {
|
|||
}
|
||||
|
||||
static void layer_surface_destroy(struct wlr_layer_surface *surface) {
|
||||
layer_surface_unmap(surface);
|
||||
if (surface->configured && surface->mapped) {
|
||||
layer_surface_unmap(surface);
|
||||
}
|
||||
wlr_signal_emit_safe(&surface->events.destroy, surface);
|
||||
wl_resource_set_user_data(surface->resource, NULL);
|
||||
wl_list_remove(&surface->surface_destroy_listener.link);
|
||||
|
|
|
|||
|
|
@ -97,7 +97,8 @@ static void params_add(struct wl_client *client,
|
|||
if (buffer->has_modifier && modifier != buffer->attributes.modifier) {
|
||||
wl_resource_post_error(params_resource,
|
||||
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_FORMAT,
|
||||
"sent modifier %lu for plane %u, expected modifier %lu like other planes",
|
||||
"sent modifier %" PRIu64 " for plane %u, expected"
|
||||
" modifier %" PRIu64 " like other planes",
|
||||
modifier, plane_idx, buffer->attributes.modifier);
|
||||
close(fd);
|
||||
return;
|
||||
|
|
@ -117,6 +118,19 @@ static void buffer_handle_resource_destroy(struct wl_resource *buffer_resource)
|
|||
linux_dmabuf_buffer_destroy(buffer);
|
||||
}
|
||||
|
||||
static bool check_import_dmabuf(struct wlr_dmabuf_buffer *buffer) {
|
||||
struct wlr_texture *texture =
|
||||
wlr_texture_from_dmabuf(buffer->renderer, &buffer->attributes);
|
||||
if (texture == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We can import the image, good. No need to keep it since wlr_surface will
|
||||
// import it again on commit.
|
||||
wlr_texture_destroy(texture);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void params_create_common(struct wl_client *client,
|
||||
struct wl_resource *params_resource, uint32_t buffer_id, int32_t width,
|
||||
int32_t height, uint32_t format, uint32_t flags) {
|
||||
|
|
@ -190,7 +204,7 @@ static void params_create_common(struct wl_client *client,
|
|||
// Skip checks if kernel does no support seek on buffer
|
||||
continue;
|
||||
}
|
||||
if (buffer->attributes.offset[i] >= size) {
|
||||
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",
|
||||
|
|
@ -198,7 +212,8 @@ static void params_create_common(struct wl_client *client,
|
|||
goto err_out;
|
||||
}
|
||||
|
||||
if (buffer->attributes.offset[i] + buffer->attributes.stride[i] > size) {
|
||||
if (buffer->attributes.offset[i] + buffer->attributes.stride[i] > size ||
|
||||
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",
|
||||
|
|
@ -208,7 +223,7 @@ static void params_create_common(struct wl_client *client,
|
|||
|
||||
// planes > 0 might be subsampled according to fourcc format
|
||||
if (i == 0 && buffer->attributes.offset[i] +
|
||||
buffer->attributes.stride[i] * height >= size) {
|
||||
buffer->attributes.stride[i] * height > size) {
|
||||
wl_resource_post_error(params_resource,
|
||||
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
|
||||
"invalid buffer stride or height for plane %d", i);
|
||||
|
|
@ -225,8 +240,7 @@ static void params_create_common(struct wl_client *client,
|
|||
}
|
||||
|
||||
/* Check if dmabuf is usable */
|
||||
if (!wlr_renderer_check_import_dmabuf(buffer->renderer,
|
||||
&buffer->attributes)) {
|
||||
if (!check_import_dmabuf(buffer)) {
|
||||
goto err_failed;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -367,7 +367,8 @@ static void output_fullscreen_surface_render(struct wlr_output *output,
|
|||
struct wlr_renderer *renderer = wlr_backend_get_renderer(output->backend);
|
||||
assert(renderer);
|
||||
|
||||
if (!wlr_surface_has_buffer(surface)) {
|
||||
struct wlr_texture *texture = wlr_surface_get_texture(surface);
|
||||
if (texture == NULL) {
|
||||
wlr_renderer_clear(renderer, (float[]){0, 0, 0, 1});
|
||||
return;
|
||||
}
|
||||
|
|
@ -386,8 +387,7 @@ static void output_fullscreen_surface_render(struct wlr_output *output,
|
|||
for (int i = 0; i < nrects; ++i) {
|
||||
output_scissor(output, &rects[i]);
|
||||
wlr_renderer_clear(renderer, (float[]){0, 0, 0, 1});
|
||||
wlr_render_texture_with_matrix(surface->renderer, surface->texture,
|
||||
matrix, 1.0f);
|
||||
wlr_render_texture_with_matrix(surface->renderer, texture, matrix, 1.0f);
|
||||
}
|
||||
wlr_renderer_scissor(renderer, NULL);
|
||||
|
||||
|
|
@ -418,7 +418,7 @@ static void output_cursor_render(struct wlr_output_cursor *cursor,
|
|||
|
||||
struct wlr_texture *texture = cursor->texture;
|
||||
if (cursor->surface != NULL) {
|
||||
texture = cursor->surface->texture;
|
||||
texture = wlr_surface_get_texture(cursor->surface);
|
||||
}
|
||||
if (texture == NULL) {
|
||||
return;
|
||||
|
|
@ -713,7 +713,7 @@ static bool output_cursor_attempt_hardware(struct wlr_output_cursor *cursor) {
|
|||
enum wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
||||
struct wlr_texture *texture = cursor->texture;
|
||||
if (cursor->surface != NULL) {
|
||||
texture = cursor->surface->texture;
|
||||
texture = wlr_surface_get_texture(cursor->surface);
|
||||
scale = cursor->surface->current->scale;
|
||||
transform = cursor->surface->current->transform;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/render/egl.h>
|
||||
#include <wlr/render/interface.h>
|
||||
#include <wlr/types/wlr_buffer.h>
|
||||
#include <wlr/types/wlr_compositor.h>
|
||||
#include <wlr/types/wlr_linux_dmabuf.h>
|
||||
#include <wlr/types/wlr_matrix.h>
|
||||
#include <wlr/types/wlr_region.h>
|
||||
#include <wlr/types/wlr_surface.h>
|
||||
|
|
@ -16,6 +15,22 @@
|
|||
#define SURFACE_VERSION 4
|
||||
#define SUBSURFACE_VERSION 1
|
||||
|
||||
static int min(int fst, int snd) {
|
||||
if (fst < snd) {
|
||||
return fst;
|
||||
} else {
|
||||
return snd;
|
||||
}
|
||||
}
|
||||
|
||||
static int max(int fst, int snd) {
|
||||
if (fst > snd) {
|
||||
return fst;
|
||||
} else {
|
||||
return snd;
|
||||
}
|
||||
}
|
||||
|
||||
static void surface_state_reset_buffer(struct wlr_surface_state *state) {
|
||||
if (state->buffer) {
|
||||
wl_list_remove(&state->buffer_destroy_listener.link);
|
||||
|
|
@ -30,13 +45,6 @@ static void surface_handle_buffer_destroy(struct wl_listener *listener,
|
|||
surface_state_reset_buffer(state);
|
||||
}
|
||||
|
||||
static void surface_state_release_buffer(struct wlr_surface_state *state) {
|
||||
if (state->buffer) {
|
||||
wl_buffer_send_release(state->buffer);
|
||||
surface_state_reset_buffer(state);
|
||||
}
|
||||
}
|
||||
|
||||
static void surface_state_set_buffer(struct wlr_surface_state *state,
|
||||
struct wl_resource *buffer) {
|
||||
surface_state_reset_buffer(state);
|
||||
|
|
@ -159,24 +167,8 @@ static bool surface_update_size(struct wlr_surface *surface,
|
|||
int scale = state->scale;
|
||||
enum wl_output_transform transform = state->transform;
|
||||
|
||||
struct wl_shm_buffer *buf = wl_shm_buffer_get(state->buffer);
|
||||
if (buf != NULL) {
|
||||
state->buffer_width = wl_shm_buffer_get_width(buf);
|
||||
state->buffer_height = wl_shm_buffer_get_height(buf);
|
||||
} else if (wlr_renderer_resource_is_wl_drm_buffer(surface->renderer,
|
||||
state->buffer)) {
|
||||
wlr_renderer_wl_drm_buffer_get_size(surface->renderer, state->buffer,
|
||||
&state->buffer_width, &state->buffer_height);
|
||||
} else if (wlr_dmabuf_resource_is_buffer(state->buffer)) {
|
||||
struct wlr_dmabuf_buffer *dmabuf =
|
||||
wlr_dmabuf_buffer_from_buffer_resource(state->buffer);
|
||||
state->buffer_width = dmabuf->attributes.width;
|
||||
state->buffer_height = dmabuf->attributes.height;
|
||||
} else {
|
||||
wlr_log(L_ERROR, "Unknown buffer handle attached");
|
||||
state->buffer_width = 0;
|
||||
state->buffer_height = 0;
|
||||
}
|
||||
wlr_buffer_get_resource_size(state->buffer, surface->renderer,
|
||||
&state->buffer_width, &state->buffer_height);
|
||||
|
||||
int width = state->buffer_width / scale;
|
||||
int height = state->buffer_height / scale;
|
||||
|
|
@ -227,7 +219,6 @@ static void surface_move_state(struct wlr_surface *surface,
|
|||
update_size = true;
|
||||
}
|
||||
if ((next->invalid & WLR_SURFACE_INVALID_BUFFER)) {
|
||||
surface_state_release_buffer(state);
|
||||
surface_state_set_buffer(state, next->buffer);
|
||||
surface_state_reset_buffer(next);
|
||||
state->sx = next->sx;
|
||||
|
|
@ -335,86 +326,57 @@ static void surface_damage_subsurfaces(struct wlr_subsurface *subsurface) {
|
|||
}
|
||||
|
||||
static void surface_apply_damage(struct wlr_surface *surface,
|
||||
bool invalid_buffer, bool reupload_buffer) {
|
||||
bool invalid_buffer) {
|
||||
struct wl_resource *resource = surface->current->buffer;
|
||||
if (resource == NULL) {
|
||||
// NULL commit
|
||||
wlr_buffer_unref(surface->buffer);
|
||||
surface->buffer = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
struct wl_shm_buffer *buf = wl_shm_buffer_get(resource);
|
||||
if (buf != NULL) {
|
||||
wl_shm_buffer_begin_access(buf);
|
||||
if (surface->buffer != NULL && !surface->buffer->released &&
|
||||
!invalid_buffer) {
|
||||
// The buffer is still the same, no need to re-upload
|
||||
return;
|
||||
}
|
||||
|
||||
enum wl_shm_format fmt = wl_shm_buffer_get_format(buf);
|
||||
int32_t stride = wl_shm_buffer_get_stride(buf);
|
||||
int32_t width = wl_shm_buffer_get_width(buf);
|
||||
int32_t height = wl_shm_buffer_get_height(buf);
|
||||
void *data = wl_shm_buffer_get_data(buf);
|
||||
if (surface->buffer != NULL && surface->buffer->released) {
|
||||
pixman_region32_t damage;
|
||||
pixman_region32_init(&damage);
|
||||
pixman_region32_copy(&damage, &surface->current->buffer_damage);
|
||||
pixman_region32_intersect_rect(&damage, &damage, 0, 0,
|
||||
surface->current->buffer_width, surface->current->buffer_height);
|
||||
|
||||
if (surface->texture == NULL || reupload_buffer) {
|
||||
wlr_texture_destroy(surface->texture);
|
||||
surface->texture = wlr_texture_from_pixels(surface->renderer, fmt,
|
||||
stride, width, height, data);
|
||||
} else {
|
||||
pixman_region32_t damage;
|
||||
pixman_region32_init(&damage);
|
||||
pixman_region32_copy(&damage, &surface->current->buffer_damage);
|
||||
pixman_region32_intersect_rect(&damage, &damage, 0, 0,
|
||||
surface->current->buffer_width,
|
||||
surface->current->buffer_height);
|
||||
struct wlr_buffer *updated_buffer =
|
||||
wlr_buffer_apply_damage(surface->buffer, resource, &damage);
|
||||
|
||||
int n;
|
||||
pixman_box32_t *rects = pixman_region32_rectangles(&damage, &n);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
pixman_box32_t *r = &rects[i];
|
||||
if (!wlr_texture_write_pixels(surface->texture, fmt, stride,
|
||||
r->x2 - r->x1, r->y2 - r->y1, r->x1, r->y1,
|
||||
r->x1, r->y1, data)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
pixman_region32_fini(&damage);
|
||||
|
||||
pixman_region32_fini(&damage);
|
||||
}
|
||||
|
||||
wl_shm_buffer_end_access(buf);
|
||||
} else if (invalid_buffer || reupload_buffer) {
|
||||
wlr_texture_destroy(surface->texture);
|
||||
|
||||
if (wlr_renderer_resource_is_wl_drm_buffer(surface->renderer, resource)) {
|
||||
surface->texture =
|
||||
wlr_texture_from_wl_drm(surface->renderer, resource);
|
||||
} else if (wlr_dmabuf_resource_is_buffer(resource)) {
|
||||
struct wlr_dmabuf_buffer *dmabuf =
|
||||
wlr_dmabuf_buffer_from_buffer_resource(resource);
|
||||
surface->texture =
|
||||
wlr_texture_from_dmabuf(surface->renderer, &dmabuf->attributes);
|
||||
} else {
|
||||
surface->texture = NULL;
|
||||
wlr_log(L_ERROR, "Unknown buffer handle attached");
|
||||
if (updated_buffer != NULL) {
|
||||
surface->buffer = updated_buffer;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
surface_state_release_buffer(surface->current);
|
||||
wlr_buffer_unref(surface->buffer);
|
||||
surface->buffer = NULL;
|
||||
|
||||
struct wlr_buffer *buffer = wlr_buffer_create(surface->renderer, resource);
|
||||
if (buffer == NULL) {
|
||||
wlr_log(L_ERROR, "Failed to upload buffer");
|
||||
return;
|
||||
}
|
||||
|
||||
surface->buffer = buffer;
|
||||
}
|
||||
|
||||
static void surface_commit_pending(struct wlr_surface *surface) {
|
||||
int32_t oldw = surface->current->buffer_width;
|
||||
int32_t oldh = surface->current->buffer_height;
|
||||
|
||||
bool invalid_buffer = surface->pending->invalid & WLR_SURFACE_INVALID_BUFFER;
|
||||
bool null_buffer_commit = invalid_buffer && surface->pending->buffer == NULL;
|
||||
|
||||
surface_move_state(surface, surface->pending, surface->current);
|
||||
|
||||
if (null_buffer_commit) {
|
||||
wlr_texture_destroy(surface->texture);
|
||||
surface->texture = NULL;
|
||||
}
|
||||
|
||||
bool reupload_buffer = oldw != surface->current->buffer_width ||
|
||||
oldh != surface->current->buffer_height;
|
||||
surface_apply_damage(surface, invalid_buffer, reupload_buffer);
|
||||
surface_apply_damage(surface, invalid_buffer);
|
||||
|
||||
// commit subsurface order
|
||||
struct wlr_subsurface *subsurface;
|
||||
|
|
@ -636,10 +598,9 @@ static void surface_handle_resource_destroy(struct wl_resource *resource) {
|
|||
wl_list_remove(wl_resource_get_link(surface->resource));
|
||||
|
||||
wl_list_remove(&surface->renderer_destroy.link);
|
||||
wlr_texture_destroy(surface->texture);
|
||||
surface_state_destroy(surface->pending);
|
||||
surface_state_destroy(surface->current);
|
||||
|
||||
wlr_buffer_unref(surface->buffer);
|
||||
free(surface);
|
||||
}
|
||||
|
||||
|
|
@ -696,8 +657,15 @@ struct wlr_surface *wlr_surface_create(struct wl_client *client,
|
|||
return surface;
|
||||
}
|
||||
|
||||
struct wlr_texture *wlr_surface_get_texture(struct wlr_surface *surface) {
|
||||
if (surface->buffer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return surface->buffer->texture;
|
||||
}
|
||||
|
||||
bool wlr_surface_has_buffer(struct wlr_surface *surface) {
|
||||
return surface->texture != NULL;
|
||||
return wlr_surface_get_texture(surface) != NULL;
|
||||
}
|
||||
|
||||
int wlr_surface_set_role(struct wlr_surface *surface, const char *role,
|
||||
|
|
@ -789,7 +757,7 @@ static void subsurface_handle_place_above(struct wl_client *client,
|
|||
}
|
||||
|
||||
wl_list_remove(&subsurface->parent_pending_link);
|
||||
wl_list_insert(sibling->parent_pending_link.prev,
|
||||
wl_list_insert(&sibling->parent_pending_link,
|
||||
&subsurface->parent_pending_link);
|
||||
|
||||
subsurface->reordered = true;
|
||||
|
|
@ -816,7 +784,7 @@ static void subsurface_handle_place_below(struct wl_client *client,
|
|||
}
|
||||
|
||||
wl_list_remove(&subsurface->parent_pending_link);
|
||||
wl_list_insert(&sibling->parent_pending_link,
|
||||
wl_list_insert(sibling->parent_pending_link.prev,
|
||||
&subsurface->parent_pending_link);
|
||||
|
||||
subsurface->reordered = true;
|
||||
|
|
@ -917,8 +885,8 @@ struct wlr_subsurface *wlr_subsurface_create(struct wlr_surface *surface,
|
|||
subsurface->parent = parent;
|
||||
wl_signal_add(&parent->events.destroy, &subsurface->parent_destroy);
|
||||
subsurface->parent_destroy.notify = subsurface_handle_parent_destroy;
|
||||
wl_list_insert(&parent->subsurfaces, &subsurface->parent_link);
|
||||
wl_list_insert(&parent->subsurface_pending_list,
|
||||
wl_list_insert(parent->subsurfaces.prev, &subsurface->parent_link);
|
||||
wl_list_insert(parent->subsurface_pending_list.prev,
|
||||
&subsurface->parent_pending_link);
|
||||
|
||||
surface->role_data = subsurface;
|
||||
|
|
@ -940,7 +908,7 @@ struct wlr_surface *wlr_surface_get_root_surface(struct wlr_surface *surface) {
|
|||
while (wlr_surface_is_subsurface(surface)) {
|
||||
struct wlr_subsurface *subsurface =
|
||||
wlr_subsurface_from_surface(surface);
|
||||
surface = subsurface->surface;
|
||||
surface = subsurface->parent;
|
||||
}
|
||||
return surface;
|
||||
}
|
||||
|
|
@ -955,7 +923,7 @@ bool wlr_surface_point_accepts_input(struct wlr_surface *surface,
|
|||
struct wlr_surface *wlr_surface_surface_at(struct wlr_surface *surface,
|
||||
double sx, double sy, double *sub_x, double *sub_y) {
|
||||
struct wlr_subsurface *subsurface;
|
||||
wl_list_for_each(subsurface, &surface->subsurfaces, parent_link) {
|
||||
wl_list_for_each_reverse(subsurface, &surface->subsurfaces, parent_link) {
|
||||
double _sub_x = subsurface->surface->current->subsurface_position.x;
|
||||
double _sub_y = subsurface->surface->current->subsurface_position.y;
|
||||
struct wlr_surface *sub = wlr_surface_surface_at(subsurface->surface,
|
||||
|
|
@ -1036,3 +1004,35 @@ void wlr_surface_for_each_surface(struct wlr_surface *surface,
|
|||
wlr_surface_iterator_func_t iterator, void *user_data) {
|
||||
surface_for_each_surface(surface, 0, 0, iterator, user_data);
|
||||
}
|
||||
|
||||
struct bound_acc {
|
||||
int32_t min_x, min_y;
|
||||
int32_t max_x, max_y;
|
||||
};
|
||||
|
||||
static void handle_bounding_box_surface(struct wlr_surface *surface,
|
||||
int x, int y, void *data) {
|
||||
struct bound_acc *acc = data;
|
||||
|
||||
acc->min_x = min(x, acc->min_x);
|
||||
acc->min_y = min(y, acc->min_y);
|
||||
|
||||
acc->max_x = max(x + surface->current->width, acc->max_x);
|
||||
acc->max_y = max(y + surface->current->height, acc->max_y);
|
||||
}
|
||||
|
||||
void wlr_surface_get_extends(struct wlr_surface *surface, struct wlr_box *box) {
|
||||
struct bound_acc acc = {
|
||||
.min_x = 0,
|
||||
.min_y = 0,
|
||||
.max_x = surface->current->width,
|
||||
.max_y = surface->current->height,
|
||||
};
|
||||
|
||||
wlr_surface_for_each_surface(surface, handle_bounding_box_surface, &acc);
|
||||
|
||||
box->x = acc.min_x;
|
||||
box->y = acc.min_y;
|
||||
box->width = acc.max_x - acc.min_x;
|
||||
box->height = acc.max_y - acc.min_y;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -416,7 +416,7 @@ static bool xdg_popup_unconstrain_slide(struct wlr_xdg_popup *popup,
|
|||
(popup->positioner.constraint_adjustment &
|
||||
XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_X);
|
||||
|
||||
bool slide_y = offset_x &&
|
||||
bool slide_y = offset_y &&
|
||||
(popup->positioner.constraint_adjustment &
|
||||
XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_Y);
|
||||
|
||||
|
|
@ -459,7 +459,7 @@ static bool xdg_popup_unconstrain_resize(struct wlr_xdg_popup *popup,
|
|||
(popup->positioner.constraint_adjustment &
|
||||
XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_X);
|
||||
|
||||
bool resize_y = offset_x &&
|
||||
bool resize_y = offset_y &&
|
||||
(popup->positioner.constraint_adjustment &
|
||||
XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_Y);
|
||||
|
||||
|
|
@ -471,7 +471,7 @@ static bool xdg_popup_unconstrain_resize(struct wlr_xdg_popup *popup,
|
|||
}
|
||||
|
||||
xdg_popup_box_constraints(popup, toplevel_sx_box,
|
||||
&offset_y, &offset_y);
|
||||
&offset_x, &offset_y);
|
||||
|
||||
return !offset_x && !offset_y;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -256,6 +256,8 @@ static enum xdg_positioner_anchor positioner_anchor_invert_x(
|
|||
return XDG_POSITIONER_ANCHOR_LEFT;
|
||||
case XDG_POSITIONER_ANCHOR_TOP_LEFT:
|
||||
return XDG_POSITIONER_ANCHOR_TOP_RIGHT;
|
||||
case XDG_POSITIONER_ANCHOR_TOP_RIGHT:
|
||||
return XDG_POSITIONER_ANCHOR_TOP_LEFT;
|
||||
case XDG_POSITIONER_ANCHOR_BOTTOM_LEFT:
|
||||
return XDG_POSITIONER_ANCHOR_BOTTOM_RIGHT;
|
||||
case XDG_POSITIONER_ANCHOR_BOTTOM_RIGHT:
|
||||
|
|
|
|||
|
|
@ -251,6 +251,13 @@ static void xdg_surface_handle_set_window_geometry(struct wl_client *client,
|
|||
return;
|
||||
}
|
||||
|
||||
if (width <= 0 || height <= 0) {
|
||||
wlr_log(L_ERROR, "Client tried to set invalid geometry");
|
||||
//XXX: Switch to the proper error value once available
|
||||
wl_resource_post_error(resource, -1, "Tried to set invalid xdg-surface geometry");
|
||||
return;
|
||||
}
|
||||
|
||||
surface->has_next_geometry = true;
|
||||
surface->next_geometry.height = height;
|
||||
surface->next_geometry.width = width;
|
||||
|
|
@ -474,9 +481,11 @@ static void xdg_popup_get_position(struct wlr_xdg_popup *popup,
|
|||
double *popup_sx, double *popup_sy) {
|
||||
struct wlr_xdg_surface *parent =
|
||||
wlr_xdg_surface_from_wlr_surface(popup->parent);
|
||||
*popup_sx = parent->geometry.x + popup->geometry.x -
|
||||
struct wlr_box parent_geo;
|
||||
wlr_xdg_surface_get_geometry(parent, &parent_geo);
|
||||
*popup_sx = parent_geo.x + popup->geometry.x -
|
||||
popup->base->geometry.x;
|
||||
*popup_sy = parent->geometry.y + popup->geometry.y -
|
||||
*popup_sy = parent_geo.y + popup->geometry.y -
|
||||
popup->base->geometry.y;
|
||||
}
|
||||
|
||||
|
|
@ -546,3 +555,13 @@ void wlr_xdg_surface_for_each_surface(struct wlr_xdg_surface *surface,
|
|||
wlr_surface_iterator_func_t iterator, void *user_data) {
|
||||
xdg_surface_for_each_surface(surface, 0, 0, iterator, user_data);
|
||||
}
|
||||
|
||||
void wlr_xdg_surface_get_geometry(struct wlr_xdg_surface *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(&surface->geometry, box, box);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -218,6 +218,7 @@ static void xdg_toplevel_handle_set_parent(struct wl_client *client,
|
|||
}
|
||||
|
||||
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,
|
||||
|
|
@ -464,6 +465,7 @@ void create_xdg_toplevel(struct wlr_xdg_surface *xdg_surface,
|
|||
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);
|
||||
|
||||
xdg_surface->role = WLR_XDG_SURFACE_ROLE_TOPLEVEL;
|
||||
xdg_surface->toplevel->base = xdg_surface;
|
||||
|
|
|
|||
|
|
@ -443,7 +443,7 @@ static bool xdg_popup_v6_unconstrain_slide(struct wlr_xdg_popup_v6 *popup,
|
|||
(popup->positioner.constraint_adjustment &
|
||||
ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_X);
|
||||
|
||||
bool slide_y = offset_x &&
|
||||
bool slide_y = offset_y &&
|
||||
(popup->positioner.constraint_adjustment &
|
||||
ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_SLIDE_Y);
|
||||
|
||||
|
|
@ -486,7 +486,7 @@ static bool xdg_popup_v6_unconstrain_resize(struct wlr_xdg_popup_v6 *popup,
|
|||
(popup->positioner.constraint_adjustment &
|
||||
ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_X);
|
||||
|
||||
bool resize_y = offset_x &&
|
||||
bool resize_y = offset_y &&
|
||||
(popup->positioner.constraint_adjustment &
|
||||
ZXDG_POSITIONER_V6_CONSTRAINT_ADJUSTMENT_RESIZE_Y);
|
||||
|
||||
|
|
@ -498,7 +498,7 @@ static bool xdg_popup_v6_unconstrain_resize(struct wlr_xdg_popup_v6 *popup,
|
|||
}
|
||||
|
||||
xdg_popup_v6_box_constraints(popup, toplevel_sx_box,
|
||||
&offset_y, &offset_y);
|
||||
&offset_x, &offset_y);
|
||||
|
||||
return !offset_x && !offset_y;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -198,6 +198,12 @@ static void xdg_surface_handle_set_window_geometry(struct wl_client *client,
|
|||
return;
|
||||
}
|
||||
|
||||
if (width <= 0 || height <= 0) {
|
||||
wlr_log(L_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;
|
||||
|
|
@ -454,9 +460,11 @@ struct wlr_xdg_surface_v6 *create_xdg_surface_v6(
|
|||
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;
|
||||
*popup_sx = parent->geometry.x + popup->geometry.x -
|
||||
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->geometry.y + popup->geometry.y -
|
||||
*popup_sy = parent_geo.y + popup->geometry.y -
|
||||
popup->base->geometry.y;
|
||||
}
|
||||
|
||||
|
|
@ -526,3 +534,13 @@ 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_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(&surface->geometry, box, box);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ static void xdg_toplevel_handle_set_parent(struct wl_client *client,
|
|||
}
|
||||
|
||||
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,
|
||||
|
|
@ -434,6 +435,7 @@ void create_xdg_toplevel_v6(struct wlr_xdg_surface_v6 *xdg_surface,
|
|||
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);
|
||||
|
||||
xdg_surface->role = WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL;
|
||||
xdg_surface->toplevel->base = xdg_surface;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue