mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-11-24 06:59:45 -05:00
Merge pull request #852 from Laaas/master
Implement pointer-constraints-unstable-v1 protocol
This commit is contained in:
commit
5e9959daaa
30 changed files with 1238 additions and 58 deletions
|
|
@ -39,6 +39,7 @@ lib_wlr_types = static_library(
|
|||
'wlr_output_layout.c',
|
||||
'wlr_output.c',
|
||||
'wlr_pointer.c',
|
||||
'wlr_pointer_constraints_v1.c',
|
||||
'wlr_primary_selection.c',
|
||||
'wlr_region.c',
|
||||
'wlr_screenshooter.c',
|
||||
|
|
|
|||
|
|
@ -225,6 +225,8 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) {
|
|||
seat->pointer_state.default_grab = pointer_grab;
|
||||
seat->pointer_state.grab = pointer_grab;
|
||||
|
||||
wl_signal_init(&seat->pointer_state.events.focus_change);
|
||||
|
||||
// keyboard state
|
||||
struct wlr_seat_keyboard_grab *keyboard_grab =
|
||||
calloc(1, sizeof(struct wlr_seat_keyboard_grab));
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ static void pointer_send_frame(struct wl_resource *resource) {
|
|||
|
||||
static const struct wl_pointer_interface pointer_impl;
|
||||
|
||||
static struct wlr_seat_client *seat_client_from_pointer_resource(
|
||||
struct wlr_seat_client *wlr_seat_client_from_pointer_resource(
|
||||
struct wl_resource *resource) {
|
||||
assert(wl_resource_instance_of(resource, &wl_pointer_interface,
|
||||
&pointer_impl));
|
||||
|
|
@ -69,7 +69,7 @@ static void pointer_set_cursor(struct wl_client *client,
|
|||
struct wl_resource *surface_resource,
|
||||
int32_t hotspot_x, int32_t hotspot_y) {
|
||||
struct wlr_seat_client *seat_client =
|
||||
seat_client_from_pointer_resource(pointer_resource);
|
||||
wlr_seat_client_from_pointer_resource(pointer_resource);
|
||||
if (seat_client == NULL) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -146,7 +146,7 @@ void wlr_seat_pointer_enter(struct wlr_seat *wlr_seat,
|
|||
uint32_t serial = wl_display_next_serial(wlr_seat->display);
|
||||
struct wl_resource *resource;
|
||||
wl_resource_for_each(resource, &focused_client->pointers) {
|
||||
if (seat_client_from_pointer_resource(resource) == NULL) {
|
||||
if (wlr_seat_client_from_pointer_resource(resource) == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -160,7 +160,7 @@ void wlr_seat_pointer_enter(struct wlr_seat *wlr_seat,
|
|||
uint32_t serial = wl_display_next_serial(wlr_seat->display);
|
||||
struct wl_resource *resource;
|
||||
wl_resource_for_each(resource, &client->pointers) {
|
||||
if (seat_client_from_pointer_resource(resource) == NULL) {
|
||||
if (wlr_seat_client_from_pointer_resource(resource) == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -183,7 +183,14 @@ void wlr_seat_pointer_enter(struct wlr_seat *wlr_seat,
|
|||
wlr_seat->pointer_state.focused_client = client;
|
||||
wlr_seat->pointer_state.focused_surface = surface;
|
||||
|
||||
// TODO: send focus change event
|
||||
struct wlr_seat_pointer_focus_change_event event = {
|
||||
.seat = wlr_seat,
|
||||
.new_surface = surface,
|
||||
.old_surface = focused_surface,
|
||||
.sx = sx,
|
||||
.sy = sy,
|
||||
};
|
||||
wlr_signal_emit_safe(&wlr_seat->pointer_state.events.focus_change, &event);
|
||||
}
|
||||
|
||||
void wlr_seat_pointer_clear_focus(struct wlr_seat *wlr_seat) {
|
||||
|
|
@ -199,7 +206,7 @@ void wlr_seat_pointer_send_motion(struct wlr_seat *wlr_seat, uint32_t time,
|
|||
|
||||
struct wl_resource *resource;
|
||||
wl_resource_for_each(resource, &client->pointers) {
|
||||
if (seat_client_from_pointer_resource(resource) == NULL) {
|
||||
if (wlr_seat_client_from_pointer_resource(resource) == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -219,7 +226,7 @@ uint32_t wlr_seat_pointer_send_button(struct wlr_seat *wlr_seat, uint32_t time,
|
|||
uint32_t serial = wl_display_next_serial(wlr_seat->display);
|
||||
struct wl_resource *resource;
|
||||
wl_resource_for_each(resource, &client->pointers) {
|
||||
if (seat_client_from_pointer_resource(resource) == NULL) {
|
||||
if (wlr_seat_client_from_pointer_resource(resource) == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -239,7 +246,7 @@ void wlr_seat_pointer_send_axis(struct wlr_seat *wlr_seat, uint32_t time,
|
|||
|
||||
struct wl_resource *resource;
|
||||
wl_resource_for_each(resource, &client->pointers) {
|
||||
if (seat_client_from_pointer_resource(resource) == NULL) {
|
||||
if (wlr_seat_client_from_pointer_resource(resource) == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -349,7 +356,7 @@ void seat_client_create_pointer(struct wlr_seat_client *seat_client,
|
|||
|
||||
void seat_client_destroy_pointer(struct wl_resource *resource) {
|
||||
struct wlr_seat_client *seat_client =
|
||||
seat_client_from_pointer_resource(resource);
|
||||
wlr_seat_client_from_pointer_resource(resource);
|
||||
if (seat_client == NULL) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,3 +143,12 @@ void wlr_box_rotated_bounds(const struct wlr_box *box, float rotation,
|
|||
dest->y = floor(fmin(y1, y2));
|
||||
dest->height = ceil(fmax(y1, y2) - fmin(y1, y2));
|
||||
}
|
||||
|
||||
void wlr_box_from_pixman_box32(const pixman_box32_t box, struct wlr_box *dest) {
|
||||
*dest = (struct wlr_box){
|
||||
.x = box.x1,
|
||||
.y = box.y1,
|
||||
.width = box.x2 - box.x1,
|
||||
.height = box.y2 - box.y1,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ bool wlr_cursor_warp(struct wlr_cursor *cur, struct wlr_input_device *dev,
|
|||
return result;
|
||||
}
|
||||
|
||||
static void cursor_warp_closest(struct wlr_cursor *cur,
|
||||
void wlr_cursor_warp_closest(struct wlr_cursor *cur,
|
||||
struct wlr_input_device *dev, double lx, double ly) {
|
||||
struct wlr_box *mapping = get_mapping(cur, dev);
|
||||
if (mapping) {
|
||||
|
|
@ -286,7 +286,7 @@ void wlr_cursor_warp_absolute(struct wlr_cursor *cur,
|
|||
double lx, ly;
|
||||
wlr_cursor_absolute_to_layout_coords(cur, dev, x, y, &lx, &ly);
|
||||
|
||||
cursor_warp_closest(cur, dev, lx, ly);
|
||||
wlr_cursor_warp_closest(cur, dev, lx, ly);
|
||||
}
|
||||
|
||||
void wlr_cursor_move(struct wlr_cursor *cur, struct wlr_input_device *dev,
|
||||
|
|
@ -296,7 +296,7 @@ void wlr_cursor_move(struct wlr_cursor *cur, struct wlr_input_device *dev,
|
|||
double lx = !isnan(delta_x) ? cur->x + delta_x : cur->x;
|
||||
double ly = !isnan(delta_y) ? cur->y + delta_y : cur->y;
|
||||
|
||||
cursor_warp_closest(cur, dev, lx, ly);
|
||||
wlr_cursor_warp_closest(cur, dev, lx, ly);
|
||||
}
|
||||
|
||||
void wlr_cursor_set_image(struct wlr_cursor *cur, const uint8_t *pixels,
|
||||
|
|
|
|||
372
types/wlr_pointer_constraints_v1.c
Normal file
372
types/wlr_pointer_constraints_v1.c
Normal file
|
|
@ -0,0 +1,372 @@
|
|||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <pixman.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/types/wlr_pointer_constraints_v1.h>
|
||||
#include <wlr/types/wlr_region.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "util/signal.h"
|
||||
|
||||
static const struct zwp_locked_pointer_v1_interface locked_pointer_impl;
|
||||
static const struct zwp_confined_pointer_v1_interface confined_pointer_impl;
|
||||
static const struct zwp_pointer_constraints_v1_interface pointer_constraints_impl;
|
||||
static void pointer_constraint_destroy(struct wlr_pointer_constraint_v1 *constraint);
|
||||
|
||||
static struct wlr_pointer_constraint_v1 *pointer_constraint_from_resource(
|
||||
struct wl_resource *resource) {
|
||||
assert(
|
||||
wl_resource_instance_of(
|
||||
resource, &zwp_confined_pointer_v1_interface,
|
||||
&confined_pointer_impl) ||
|
||||
wl_resource_instance_of(
|
||||
resource, &zwp_locked_pointer_v1_interface,
|
||||
&locked_pointer_impl));
|
||||
return wl_resource_get_user_data(resource);
|
||||
}
|
||||
|
||||
static struct wlr_pointer_constraints_v1 *pointer_constraints_from_resource(
|
||||
struct wl_resource *resource) {
|
||||
assert(wl_resource_instance_of(resource, &zwp_pointer_constraints_v1_interface,
|
||||
&pointer_constraints_impl));
|
||||
return wl_resource_get_user_data(resource);
|
||||
}
|
||||
|
||||
static void resource_destroy(struct wl_client *client,
|
||||
struct wl_resource *resource) {
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
|
||||
static void pointer_constraint_destroy(struct wlr_pointer_constraint_v1 *constraint) {
|
||||
if (constraint == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
wlr_log(WLR_DEBUG, "destroying constraint %p", constraint);
|
||||
|
||||
wlr_signal_emit_safe(&constraint->events.destroy, constraint);
|
||||
|
||||
wl_resource_set_user_data(constraint->resource, NULL);
|
||||
wl_list_remove(&constraint->link);
|
||||
wl_list_remove(&constraint->surface_commit.link);
|
||||
wl_list_remove(&constraint->surface_destroy.link);
|
||||
wl_list_remove(&constraint->seat_destroy.link);
|
||||
pixman_region32_fini(&constraint->current.region);
|
||||
pixman_region32_fini(&constraint->pending.region);
|
||||
pixman_region32_fini(&constraint->region);
|
||||
free(constraint);
|
||||
}
|
||||
|
||||
static void pointer_constraint_destroy_resource(struct wl_resource *resource) {
|
||||
struct wlr_pointer_constraint_v1 *constraint =
|
||||
pointer_constraint_from_resource(resource);
|
||||
|
||||
pointer_constraint_destroy(constraint);
|
||||
}
|
||||
|
||||
static void pointer_constraint_set_region(
|
||||
struct wlr_pointer_constraint_v1 *constraint,
|
||||
struct wl_resource *region_resource) {
|
||||
pixman_region32_clear(&constraint->pending.region);
|
||||
|
||||
if (region_resource) {
|
||||
pixman_region32_t *region = wlr_region_from_resource(region_resource);
|
||||
pixman_region32_copy(&constraint->pending.region, region);
|
||||
}
|
||||
|
||||
constraint->pending.committed |= WLR_POINTER_CONSTRAINT_V1_STATE_REGION;
|
||||
}
|
||||
|
||||
static void pointer_constraint_handle_set_region(struct wl_client *client,
|
||||
struct wl_resource *resource, struct wl_resource *region_resource) {
|
||||
struct wlr_pointer_constraint_v1 *constraint =
|
||||
pointer_constraint_from_resource(resource);
|
||||
if (constraint == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
pointer_constraint_set_region(constraint, region_resource);
|
||||
}
|
||||
|
||||
static void pointer_constraint_set_cursor_position_hint(struct wl_client *client,
|
||||
struct wl_resource *resource, wl_fixed_t x, wl_fixed_t y) {
|
||||
struct wlr_pointer_constraint_v1 *constraint =
|
||||
pointer_constraint_from_resource(resource);
|
||||
if (constraint == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
constraint->pending.cursor_hint.x = wl_fixed_to_double(x);
|
||||
constraint->pending.cursor_hint.y = wl_fixed_to_double(y);
|
||||
constraint->pending.committed |= WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT;
|
||||
}
|
||||
|
||||
static void pointer_constraint_commit(
|
||||
struct wlr_pointer_constraint_v1 *constraint) {
|
||||
if (constraint->pending.committed &
|
||||
WLR_POINTER_CONSTRAINT_V1_STATE_REGION) {
|
||||
pixman_region32_copy(&constraint->current.region,
|
||||
&constraint->pending.region);
|
||||
}
|
||||
if (constraint->pending.committed &
|
||||
WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT) {
|
||||
constraint->current.cursor_hint = constraint->pending.cursor_hint;
|
||||
}
|
||||
constraint->current.committed |= constraint->pending.committed;
|
||||
|
||||
constraint->pending.committed = 0;
|
||||
|
||||
pixman_region32_clear(&constraint->region);
|
||||
if (pixman_region32_not_empty(&constraint->current.region)) {
|
||||
pixman_region32_intersect(&constraint->region,
|
||||
&constraint->surface->input_region, &constraint->current.region);
|
||||
} else {
|
||||
pixman_region32_copy(&constraint->region,
|
||||
&constraint->surface->input_region);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_surface_commit(struct wl_listener *listener, void *data) {
|
||||
struct wlr_pointer_constraint_v1 *constraint =
|
||||
wl_container_of(listener, constraint, surface_commit);
|
||||
|
||||
pointer_constraint_commit(constraint);
|
||||
}
|
||||
|
||||
static void handle_surface_destroy(struct wl_listener *listener, void *data) {
|
||||
struct wlr_pointer_constraint_v1 *constraint =
|
||||
wl_container_of(listener, constraint, surface_destroy);
|
||||
|
||||
pointer_constraint_destroy(constraint);
|
||||
}
|
||||
|
||||
static void handle_seat_destroy(struct wl_listener *listener, void *data) {
|
||||
struct wlr_pointer_constraint_v1 *constraint =
|
||||
wl_container_of(listener, constraint, seat_destroy);
|
||||
|
||||
pointer_constraint_destroy(constraint);
|
||||
}
|
||||
|
||||
static const struct zwp_confined_pointer_v1_interface confined_pointer_impl = {
|
||||
.destroy = resource_destroy,
|
||||
.set_region = pointer_constraint_handle_set_region,
|
||||
};
|
||||
|
||||
static const struct zwp_locked_pointer_v1_interface locked_pointer_impl = {
|
||||
.destroy = resource_destroy,
|
||||
.set_region = pointer_constraint_handle_set_region,
|
||||
.set_cursor_position_hint = pointer_constraint_set_cursor_position_hint,
|
||||
};
|
||||
|
||||
static void pointer_constraint_create(struct wl_client *client,
|
||||
struct wl_resource *pointer_constraints_resource, uint32_t id,
|
||||
struct wl_resource *surface_resource,
|
||||
struct wl_resource *pointer_resource,
|
||||
struct wl_resource *region_resource,
|
||||
enum zwp_pointer_constraints_v1_lifetime lifetime,
|
||||
enum wlr_pointer_constraint_v1_type type) {
|
||||
struct wlr_pointer_constraints_v1 *pointer_constraints =
|
||||
pointer_constraints_from_resource(pointer_constraints_resource);
|
||||
|
||||
struct wlr_surface *surface = wlr_surface_from_resource(surface_resource);
|
||||
struct wlr_seat *seat =
|
||||
wlr_seat_client_from_pointer_resource(pointer_resource)->seat;
|
||||
|
||||
if (wlr_pointer_constraints_v1_constraint_for_surface(pointer_constraints,
|
||||
surface, seat)) {
|
||||
wl_resource_post_error(pointer_constraints_resource,
|
||||
ZWP_POINTER_CONSTRAINTS_V1_ERROR_ALREADY_CONSTRAINED,
|
||||
"a pointer constraint with a wl_pointer of the same wl_seat"
|
||||
" is already on this surface");
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t version = wl_resource_get_version(pointer_constraints_resource);
|
||||
|
||||
bool locked_pointer = type == WLR_POINTER_CONSTRAINT_V1_LOCKED;
|
||||
|
||||
struct wl_resource *resource = locked_pointer ?
|
||||
wl_resource_create(client, &zwp_locked_pointer_v1_interface, version, id) :
|
||||
wl_resource_create(client, &zwp_confined_pointer_v1_interface, version, id);
|
||||
if (resource == NULL) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
|
||||
struct wlr_pointer_constraint_v1 *constraint = calloc(1, sizeof(*constraint));
|
||||
if (constraint == NULL) {
|
||||
wl_resource_destroy(resource);
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
|
||||
constraint->resource = resource;
|
||||
constraint->surface = surface;
|
||||
constraint->seat = seat;
|
||||
constraint->lifetime = lifetime;
|
||||
constraint->type = type;
|
||||
constraint->pointer_constraints = pointer_constraints;
|
||||
|
||||
wl_signal_init(&constraint->events.destroy);
|
||||
|
||||
pixman_region32_init(&constraint->region);
|
||||
|
||||
pixman_region32_init(&constraint->pending.region);
|
||||
pixman_region32_init(&constraint->current.region);
|
||||
|
||||
pointer_constraint_set_region(constraint, region_resource);
|
||||
pointer_constraint_commit(constraint);
|
||||
|
||||
constraint->surface_commit.notify = handle_surface_commit;
|
||||
wl_signal_add(&surface->events.commit, &constraint->surface_commit);
|
||||
|
||||
constraint->surface_destroy.notify = handle_surface_destroy;
|
||||
wl_signal_add(&surface->events.destroy, &constraint->surface_destroy);
|
||||
|
||||
constraint->seat_destroy.notify = handle_seat_destroy;
|
||||
wl_signal_add(&seat->events.destroy, &constraint->seat_destroy);
|
||||
|
||||
void *impl = locked_pointer ?
|
||||
(void *)&locked_pointer_impl : (void *)&confined_pointer_impl;
|
||||
wl_resource_set_implementation(constraint->resource, impl, constraint,
|
||||
pointer_constraint_destroy_resource);
|
||||
|
||||
wlr_log(WLR_DEBUG, "new %s_pointer %p (res %p)",
|
||||
locked_pointer ? "locked" : "confined",
|
||||
constraint, constraint->resource);
|
||||
|
||||
wl_list_insert(&pointer_constraints->constraints, &constraint->link);
|
||||
|
||||
wlr_signal_emit_safe(&pointer_constraints->events.new_constraint,
|
||||
constraint);
|
||||
}
|
||||
|
||||
static void pointer_constraints_lock_pointer(struct wl_client *client,
|
||||
struct wl_resource *cons_resource, uint32_t id,
|
||||
struct wl_resource *surface, struct wl_resource *pointer,
|
||||
struct wl_resource *region, enum zwp_pointer_constraints_v1_lifetime lifetime) {
|
||||
pointer_constraint_create(client, cons_resource, id, surface, pointer,
|
||||
region, lifetime, WLR_POINTER_CONSTRAINT_V1_LOCKED);
|
||||
}
|
||||
|
||||
static void pointer_constraints_confine_pointer(struct wl_client *client,
|
||||
struct wl_resource *cons_resource, uint32_t id,
|
||||
struct wl_resource *surface, struct wl_resource *pointer,
|
||||
struct wl_resource *region,
|
||||
enum zwp_pointer_constraints_v1_lifetime lifetime) {
|
||||
pointer_constraint_create(client, cons_resource, id, surface, pointer,
|
||||
region, lifetime, WLR_POINTER_CONSTRAINT_V1_CONFINED);
|
||||
}
|
||||
|
||||
static const struct zwp_pointer_constraints_v1_interface
|
||||
pointer_constraints_impl = {
|
||||
.destroy = resource_destroy,
|
||||
.lock_pointer = pointer_constraints_lock_pointer,
|
||||
.confine_pointer = pointer_constraints_confine_pointer,
|
||||
};
|
||||
|
||||
static void pointer_constraints_destroy(struct wl_resource *resource) {
|
||||
wl_list_remove(wl_resource_get_link(resource));
|
||||
}
|
||||
|
||||
static void pointer_constraints_bind(struct wl_client *client, void *data,
|
||||
uint32_t version, uint32_t id) {
|
||||
struct wlr_pointer_constraints_v1 *pointer_constraints = data;
|
||||
assert(client && pointer_constraints);
|
||||
|
||||
struct wl_resource *resource = wl_resource_create(client,
|
||||
&zwp_pointer_constraints_v1_interface, version, id);
|
||||
if (resource == NULL) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
|
||||
wl_list_insert(&pointer_constraints->resources,
|
||||
wl_resource_get_link(resource));
|
||||
wl_resource_set_implementation(resource, &pointer_constraints_impl,
|
||||
pointer_constraints, pointer_constraints_destroy);
|
||||
}
|
||||
|
||||
struct wlr_pointer_constraints_v1 *wlr_pointer_constraints_v1_create(
|
||||
struct wl_display *display) {
|
||||
struct wlr_pointer_constraints_v1 *pointer_constraints =
|
||||
calloc(1, sizeof(*pointer_constraints));
|
||||
|
||||
if (!pointer_constraints) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct wl_global *wl_global = wl_global_create(display,
|
||||
&zwp_pointer_constraints_v1_interface, 1, pointer_constraints,
|
||||
pointer_constraints_bind);
|
||||
if (!wl_global) {
|
||||
free(pointer_constraints);
|
||||
return NULL;
|
||||
}
|
||||
pointer_constraints->global = wl_global;
|
||||
|
||||
wl_list_init(&pointer_constraints->resources);
|
||||
wl_list_init(&pointer_constraints->constraints);
|
||||
wl_signal_init(&pointer_constraints->events.new_constraint);
|
||||
|
||||
return pointer_constraints;
|
||||
}
|
||||
|
||||
void wlr_pointer_constraints_v1_destroy(
|
||||
struct wlr_pointer_constraints_v1 *pointer_constraints) {
|
||||
struct wl_resource *resource, *_tmp_res;
|
||||
wl_resource_for_each_safe(resource, _tmp_res,
|
||||
&pointer_constraints->resources) {
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
|
||||
struct wlr_pointer_constraint_v1 *constraint, *_tmp_cons;
|
||||
wl_list_for_each_safe(constraint, _tmp_cons,
|
||||
&pointer_constraints->constraints, link) {
|
||||
wl_resource_destroy(constraint->resource);
|
||||
}
|
||||
|
||||
wl_global_destroy(pointer_constraints->global);
|
||||
free(pointer_constraints);
|
||||
}
|
||||
|
||||
struct wlr_pointer_constraint_v1 *
|
||||
wlr_pointer_constraints_v1_constraint_for_surface(
|
||||
struct wlr_pointer_constraints_v1 *pointer_constraints,
|
||||
struct wlr_surface *surface, struct wlr_seat *seat) {
|
||||
struct wlr_pointer_constraint_v1 *constraint;
|
||||
wl_list_for_each(constraint, &pointer_constraints->constraints, link) {
|
||||
if (constraint->surface == surface && constraint->seat == seat) {
|
||||
return constraint;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void wlr_pointer_constraint_v1_send_activated(
|
||||
struct wlr_pointer_constraint_v1 *constraint) {
|
||||
wlr_log(WLR_DEBUG, "constrained %p", constraint);
|
||||
if (constraint->type == WLR_POINTER_CONSTRAINT_V1_LOCKED) {
|
||||
zwp_locked_pointer_v1_send_locked(constraint->resource);
|
||||
} else {
|
||||
zwp_confined_pointer_v1_send_confined(constraint->resource);
|
||||
}
|
||||
}
|
||||
|
||||
void wlr_pointer_constraint_v1_send_deactivated(
|
||||
struct wlr_pointer_constraint_v1 *constraint) {
|
||||
wlr_log(WLR_DEBUG, "unconstrained %p", constraint);
|
||||
if (constraint->type == WLR_POINTER_CONSTRAINT_V1_LOCKED) {
|
||||
zwp_locked_pointer_v1_send_unlocked(constraint->resource);
|
||||
} else {
|
||||
zwp_confined_pointer_v1_send_unconfined(constraint->resource);
|
||||
}
|
||||
|
||||
if (constraint->lifetime ==
|
||||
ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT) {
|
||||
pointer_constraint_destroy(constraint);
|
||||
}
|
||||
}
|
||||
|
|
@ -113,9 +113,6 @@ static void surface_set_opaque_region(struct wl_client *client,
|
|||
struct wl_resource *resource,
|
||||
struct wl_resource *region_resource) {
|
||||
struct wlr_surface *surface = wlr_surface_from_resource(resource);
|
||||
if ((surface->pending.committed & WLR_SURFACE_STATE_OPAQUE_REGION)) {
|
||||
pixman_region32_clear(&surface->pending.opaque);
|
||||
}
|
||||
surface->pending.committed |= WLR_SURFACE_STATE_OPAQUE_REGION;
|
||||
if (region_resource) {
|
||||
pixman_region32_t *region = wlr_region_from_resource(region_resource);
|
||||
|
|
@ -126,7 +123,8 @@ static void surface_set_opaque_region(struct wl_client *client,
|
|||
}
|
||||
|
||||
static void surface_set_input_region(struct wl_client *client,
|
||||
struct wl_resource *resource, struct wl_resource *region_resource) {
|
||||
struct wl_resource *resource,
|
||||
struct wl_resource *region_resource) {
|
||||
struct wlr_surface *surface = wlr_surface_from_resource(resource);
|
||||
surface->pending.committed |= WLR_SURFACE_STATE_INPUT_REGION;
|
||||
if (region_resource) {
|
||||
|
|
@ -353,9 +351,14 @@ static void surface_update_opaque_region(struct wlr_surface *surface) {
|
|||
return;
|
||||
}
|
||||
|
||||
pixman_region32_copy(&surface->opaque_region, &surface->current.opaque);
|
||||
pixman_region32_intersect_rect(&surface->opaque_region,
|
||||
&surface->opaque_region,
|
||||
&surface->current.opaque,
|
||||
0, 0, surface->current.width, surface->current.height);
|
||||
}
|
||||
|
||||
static void surface_update_input_region(struct wlr_surface *surface) {
|
||||
pixman_region32_intersect_rect(&surface->input_region,
|
||||
&surface->current.input,
|
||||
0, 0, surface->current.width, surface->current.height);
|
||||
}
|
||||
|
||||
|
|
@ -380,6 +383,7 @@ static void surface_commit_pending(struct wlr_surface *surface) {
|
|||
surface_apply_damage(surface);
|
||||
}
|
||||
surface_update_opaque_region(surface);
|
||||
surface_update_input_region(surface);
|
||||
|
||||
// commit subsurface order
|
||||
struct wlr_subsurface *subsurface;
|
||||
|
|
@ -587,6 +591,7 @@ static void surface_handle_resource_destroy(struct wl_resource *resource) {
|
|||
surface_state_finish(&surface->previous);
|
||||
pixman_region32_fini(&surface->buffer_damage);
|
||||
pixman_region32_fini(&surface->opaque_region);
|
||||
pixman_region32_fini(&surface->input_region);
|
||||
wlr_buffer_unref(surface->buffer);
|
||||
free(surface);
|
||||
}
|
||||
|
|
@ -633,6 +638,7 @@ struct wlr_surface *wlr_surface_create(struct wl_client *client,
|
|||
wl_list_init(&surface->subsurface_pending_list);
|
||||
pixman_region32_init(&surface->buffer_damage);
|
||||
pixman_region32_init(&surface->opaque_region);
|
||||
pixman_region32_init(&surface->input_region);
|
||||
|
||||
wl_signal_add(&renderer->events.destroy, &surface->renderer_destroy);
|
||||
surface->renderer_destroy.notify = surface_handle_renderer_destroy;
|
||||
|
|
@ -937,7 +943,7 @@ bool wlr_surface_point_accepts_input(struct wlr_surface *surface,
|
|||
double sx, double sy) {
|
||||
return sx >= 0 && sx < surface->current.width &&
|
||||
sy >= 0 && sy < surface->current.height &&
|
||||
pixman_region32_contains_point(&surface->current.input, sx, sy, NULL);
|
||||
pixman_region32_contains_point(&surface->current.input, floor(sx), floor(sy), NULL);
|
||||
}
|
||||
|
||||
struct wlr_surface *wlr_surface_surface_at(struct wlr_surface *surface,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue