aboutsummaryrefslogtreecommitdiff
path: root/include/wlr
diff options
context:
space:
mode:
authorLas <las@protonmail.ch>2018-08-10 18:19:16 +0200
committerLas <las@protonmail.ch>2018-09-18 10:14:33 +0200
commitfa2e6e7d9d5ffbd782063c89e460a915b29d4a58 (patch)
tree219c3ff57b4430b7840e7b71684a5deec36bcf70 /include/wlr
parent437f5387728703aca859f6fcec021a700472be33 (diff)
Implement pointer-constraints protocol in wlroots and rootston
Diffstat (limited to 'include/wlr')
-rw-r--r--include/wlr/types/wlr_box.h3
-rw-r--r--include/wlr/types/wlr_cursor.h12
-rw-r--r--include/wlr/types/wlr_pointer_constraints_v1.h88
-rw-r--r--include/wlr/types/wlr_region.h3
-rw-r--r--include/wlr/util/region.h5
5 files changed, 109 insertions, 2 deletions
diff --git a/include/wlr/types/wlr_box.h b/include/wlr/types/wlr_box.h
index 11a53b56..8e25918b 100644
--- a/include/wlr/types/wlr_box.h
+++ b/include/wlr/types/wlr_box.h
@@ -9,6 +9,7 @@
#ifndef WLR_TYPES_WLR_BOX_H
#define WLR_TYPES_WLR_BOX_H
+#include <pixman.h>
#include <stdbool.h>
#include <wayland-server.h>
@@ -40,4 +41,6 @@ void wlr_box_transform(const struct wlr_box *box,
void wlr_box_rotated_bounds(const struct wlr_box *box, float rotation,
struct wlr_box *dest);
+void wlr_box_from_pixman_box32(const pixman_box32_t box, struct wlr_box *dest);
+
#endif
diff --git a/include/wlr/types/wlr_cursor.h b/include/wlr/types/wlr_cursor.h
index ba582be9..44ced1f0 100644
--- a/include/wlr/types/wlr_cursor.h
+++ b/include/wlr/types/wlr_cursor.h
@@ -91,6 +91,18 @@ bool wlr_cursor_warp(struct wlr_cursor *cur, struct wlr_input_device *dev,
void wlr_cursor_absolute_to_layout_coords(struct wlr_cursor *cur,
struct wlr_input_device *dev, double x, double y, double *lx, double *ly);
+
+/**
+ * Warp the cursor to the given x and y coordinates. If the given point is out
+ * of the layout boundaries or constraints, the closest point will be used.
+ * If one coordinate is NAN, it will be ignored.
+ *
+ * `dev` may be passed to respect device mapping constraints. If `dev` is NULL,
+ * device mapping constraints will be ignored.
+ */
+void wlr_cursor_warp_closest(struct wlr_cursor *cur,
+ struct wlr_input_device *dev, double x, double y);
+
/**
* Warp the cursor to the given x and y in absolute 0..1 coordinates. If the
* given point is out of the layout boundaries or constraints, the closest point
diff --git a/include/wlr/types/wlr_pointer_constraints_v1.h b/include/wlr/types/wlr_pointer_constraints_v1.h
new file mode 100644
index 00000000..b8015a57
--- /dev/null
+++ b/include/wlr/types/wlr_pointer_constraints_v1.h
@@ -0,0 +1,88 @@
+#ifndef WLR_TYPES_WLR_POINTER_CONSTRAINTS_V1_H
+#define WLR_TYPES_WLR_POINTER_CONSTRAINTS_V1_H
+
+#include <stdint.h>
+#include <wayland-server.h>
+#include <pixman.h>
+#include <wlr/types/wlr_box.h>
+#include <wlr/types/wlr_seat.h>
+#include "pointer-constraints-unstable-v1-protocol.h"
+
+struct wlr_seat;
+
+enum wlr_pointer_constraint_v1_type {
+ WLR_POINTER_CONSTRAINT_V1_LOCKED,
+ WLR_POINTER_CONSTRAINT_V1_CONFINED,
+};
+
+struct wlr_pointer_constraint_v1_state {
+ pixman_region32_t *region;
+
+ // only valid for locked_pointer
+ struct {
+ double x, y;
+ bool valid;
+ } cursor_hint;
+};
+
+struct wlr_pointer_constraint_v1 {
+ struct wlr_pointer_constraints_v1 *pointer_constraints;
+
+ struct wl_resource *resource;
+ struct wlr_surface *surface;
+ struct wlr_seat *seat;
+ enum zwp_pointer_constraints_v1_lifetime lifetime;
+ enum wlr_pointer_constraint_v1_type type;
+ pixman_region32_t region;
+
+ struct wlr_pointer_constraint_v1_state current, pending;
+
+ struct wl_listener surface_commit;
+ struct wl_listener surface_destroy;
+ struct wl_listener seat_destroy;
+
+ struct wl_list link; // wlr_pointer_constraints_v1::constraints
+
+ void *data;
+};
+
+struct wlr_pointer_constraints_v1 {
+ struct wl_list wl_resources; // wl_resource_get_link
+ struct wl_global *wl_global;
+
+ struct {
+ /**
+ * Called when a new pointer constraint is created.
+ *
+ * data: wlr_pointer_constraint_v1*
+ */
+ struct wl_signal constraint_create;
+ /**
+ * Called when a pointer constraint is destroyed.
+ *
+ * data: wlr_pointer_constraint_v1*
+ */
+ struct wl_signal constraint_destroy;
+ } events;
+
+ struct wl_list constraints; // wlr_pointer_constraint_v1::link
+
+ void *data;
+};
+
+struct wlr_pointer_constraints_v1 *wlr_pointer_constraints_v1_create(
+ struct wl_display *display);
+void wlr_pointer_constraints_v1_destroy(
+ struct wlr_pointer_constraints_v1 *wlr_pointer_constraints_v1);
+
+struct wlr_pointer_constraint_v1 *wlr_pointer_constraints_v1_constraint_for_surface(
+ struct wlr_pointer_constraints_v1 *wlr_pointer_constraints_v1,
+ struct wlr_surface *surface, struct wlr_seat *seat);
+
+void wlr_pointer_constraint_v1_send_activated(
+ struct wlr_pointer_constraint_v1 *constraint);
+void wlr_pointer_constraint_v1_send_deactivated(
+ struct wlr_pointer_constraint_v1 *constraint);
+
+
+#endif
diff --git a/include/wlr/types/wlr_region.h b/include/wlr/types/wlr_region.h
index 3c4a0532..ec7f73aa 100644
--- a/include/wlr/types/wlr_region.h
+++ b/include/wlr/types/wlr_region.h
@@ -10,8 +10,7 @@
#define WLR_TYPES_WLR_REGION_H
#include <pixman.h>
-
-struct wl_resource;
+#include <wayland-server-protocol.h>
/*
* Creates a new region resource with the provided new ID. If `resource_list` is
diff --git a/include/wlr/util/region.h b/include/wlr/util/region.h
index 32387bfb..4aca07e1 100644
--- a/include/wlr/util/region.h
+++ b/include/wlr/util/region.h
@@ -16,6 +16,8 @@
#ifndef WLR_UTIL_REGION_H
#define WLR_UTIL_REGION_H
+
+#include <stdbool.h>
#include <pixman.h>
#include <wayland-server.h>
@@ -48,4 +50,7 @@ void wlr_region_expand(pixman_region32_t *dst, pixman_region32_t *src,
void wlr_region_rotated_bounds(pixman_region32_t *dst, pixman_region32_t *src,
float rotation, int ox, int oy);
+bool wlr_region_confine(pixman_region32_t *region, double x1, double y1, double x2,
+ double y2, double *x2_out, double *y2_out);
+
#endif