commit d305f919485298557389679c8cbebf481fda36c5
parent 4ea3e3fc3332c4a7e3fc65220b98864f8bff37b0
Author: Michael Forney <mforney@mforney.org>
Date: Wed, 11 Sep 2013 17:20:36 -0700
seat: Add pointer region
Diffstat:
3 files changed, 54 insertions(+), 0 deletions(-)
diff --git a/libswc/compositor.c b/libswc/compositor.c
@@ -384,6 +384,8 @@ bool swc_compositor_initialize(struct swc_compositor * compositor,
struct wl_event_loop * event_loop;
struct udev_device * drm_device;
struct wl_list * outputs;
+ struct swc_output * output;
+ pixman_region32_t pointer_region;
xkb_keysym_t keysym;
compositor->display = display;
@@ -454,6 +456,20 @@ bool swc_compositor_initialize(struct swc_compositor * compositor,
goto error_renderer;
}
+ /* Calculate pointer region */
+ pixman_region32_init(&pointer_region);
+
+ wl_list_for_each(output, &compositor->outputs, link)
+ {
+ pixman_region32_union_rect(&pointer_region, &pointer_region,
+ output->geometry.x, output->geometry.y,
+ output->geometry.width,
+ output->geometry.height);
+ }
+
+ swc_seat_set_pointer_region(&compositor->seat, &pointer_region);
+ pixman_region32_fini(&pointer_region);
+
pixman_region32_init(&compositor->damage);
pixman_region32_init(&compositor->opaque);
wl_list_init(&compositor->surfaces);
diff --git a/libswc/seat.c b/libswc/seat.c
@@ -8,6 +8,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <assert.h>
struct evdev_device_entry
{
@@ -17,6 +18,30 @@ struct evdev_device_entry
struct wl_list link;
};
+static void clip_position(struct swc_seat * seat, wl_fixed_t fx, wl_fixed_t fy)
+{
+ int32_t x, y, last_x, last_y;
+ pixman_box32_t box;
+
+ x = wl_fixed_to_int(fx);
+ y = wl_fixed_to_int(fy);
+ last_x = wl_fixed_to_int(seat->pointer.x);
+ last_y = wl_fixed_to_int(seat->pointer.y);
+
+ if (!pixman_region32_contains_point(&seat->pointer_region, x, y, NULL))
+ {
+ assert(pixman_region32_contains_point(&seat->pointer_region,
+ last_x, last_y, &box));
+
+ /* Do some clipping. */
+ x = MAX(MIN(x, box.x2 - 1), box.x1);
+ y = MAX(MIN(y, box.y2 - 1), box.y1);
+ }
+
+ seat->pointer.x = wl_fixed_from_int(x);
+ seat->pointer.y = wl_fixed_from_int(y);
+}
+
static void handle_key(struct swc_seat * seat, uint32_t time, uint32_t key,
uint32_t state)
{
@@ -340,6 +365,7 @@ bool swc_seat_initialize(struct swc_seat * seat, struct udev * udev,
wl_list_init(&seat->resources);
wl_signal_init(&seat->destroy_signal);
+ pixman_region32_init(&seat->pointer_region);
wl_list_init(&seat->devices);
swc_seat_add_devices(seat, udev);
@@ -415,3 +441,10 @@ void swc_seat_add_devices(struct swc_seat * seat, struct udev * udev)
udev_enumerate_unref(enumerate);
}
+void swc_seat_set_pointer_region(struct swc_seat * seat,
+ pixman_region32_t * region)
+{
+ pixman_region32_copy(&seat->pointer_region, region);
+ clip_position(seat, seat->pointer.x, seat->pointer.y);
+}
+
diff --git a/libswc/seat.h b/libswc/seat.h
@@ -10,6 +10,7 @@
#include <stdbool.h>
#include <libudev.h>
#include <wayland-server.h>
+#include <pixman.h>
struct swc_seat
{
@@ -28,6 +29,7 @@ struct swc_seat
struct wl_listener keyboard_focus_listener;
struct swc_pointer pointer;
+ pixman_region32_t pointer_region;
struct wl_list devices;
};
@@ -44,5 +46,8 @@ void swc_seat_add_event_sources(struct swc_seat * seat,
void swc_seat_add_devices(struct swc_seat * seat, struct udev * udev);
+void swc_seat_set_pointer_region(struct swc_seat * seat,
+ pixman_region32_t * region);
+
#endif