commit d305f91
Michael Forney
·
2013-09-12 00:20:36 +0000 UTC
parent 4ea3e3f
seat: Add pointer region
3 files changed,
+54,
-0
+16,
-0
1@@ -384,6 +384,8 @@ bool swc_compositor_initialize(struct swc_compositor * compositor,
2 struct wl_event_loop * event_loop;
3 struct udev_device * drm_device;
4 struct wl_list * outputs;
5+ struct swc_output * output;
6+ pixman_region32_t pointer_region;
7 xkb_keysym_t keysym;
8
9 compositor->display = display;
10@@ -454,6 +456,20 @@ bool swc_compositor_initialize(struct swc_compositor * compositor,
11 goto error_renderer;
12 }
13
14+ /* Calculate pointer region */
15+ pixman_region32_init(&pointer_region);
16+
17+ wl_list_for_each(output, &compositor->outputs, link)
18+ {
19+ pixman_region32_union_rect(&pointer_region, &pointer_region,
20+ output->geometry.x, output->geometry.y,
21+ output->geometry.width,
22+ output->geometry.height);
23+ }
24+
25+ swc_seat_set_pointer_region(&compositor->seat, &pointer_region);
26+ pixman_region32_fini(&pointer_region);
27+
28 pixman_region32_init(&compositor->damage);
29 pixman_region32_init(&compositor->opaque);
30 wl_list_init(&compositor->surfaces);
+33,
-0
1@@ -8,6 +8,7 @@
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <string.h>
5+#include <assert.h>
6
7 struct evdev_device_entry
8 {
9@@ -17,6 +18,30 @@ struct evdev_device_entry
10 struct wl_list link;
11 };
12
13+static void clip_position(struct swc_seat * seat, wl_fixed_t fx, wl_fixed_t fy)
14+{
15+ int32_t x, y, last_x, last_y;
16+ pixman_box32_t box;
17+
18+ x = wl_fixed_to_int(fx);
19+ y = wl_fixed_to_int(fy);
20+ last_x = wl_fixed_to_int(seat->pointer.x);
21+ last_y = wl_fixed_to_int(seat->pointer.y);
22+
23+ if (!pixman_region32_contains_point(&seat->pointer_region, x, y, NULL))
24+ {
25+ assert(pixman_region32_contains_point(&seat->pointer_region,
26+ last_x, last_y, &box));
27+
28+ /* Do some clipping. */
29+ x = MAX(MIN(x, box.x2 - 1), box.x1);
30+ y = MAX(MIN(y, box.y2 - 1), box.y1);
31+ }
32+
33+ seat->pointer.x = wl_fixed_from_int(x);
34+ seat->pointer.y = wl_fixed_from_int(y);
35+}
36+
37 static void handle_key(struct swc_seat * seat, uint32_t time, uint32_t key,
38 uint32_t state)
39 {
40@@ -340,6 +365,7 @@ bool swc_seat_initialize(struct swc_seat * seat, struct udev * udev,
41
42 wl_list_init(&seat->resources);
43 wl_signal_init(&seat->destroy_signal);
44+ pixman_region32_init(&seat->pointer_region);
45 wl_list_init(&seat->devices);
46 swc_seat_add_devices(seat, udev);
47
48@@ -415,3 +441,10 @@ void swc_seat_add_devices(struct swc_seat * seat, struct udev * udev)
49 udev_enumerate_unref(enumerate);
50 }
51
52+void swc_seat_set_pointer_region(struct swc_seat * seat,
53+ pixman_region32_t * region)
54+{
55+ pixman_region32_copy(&seat->pointer_region, region);
56+ clip_position(seat, seat->pointer.x, seat->pointer.y);
57+}
58+
+5,
-0
1@@ -10,6 +10,7 @@
2 #include <stdbool.h>
3 #include <libudev.h>
4 #include <wayland-server.h>
5+#include <pixman.h>
6
7 struct swc_seat
8 {
9@@ -28,6 +29,7 @@ struct swc_seat
10 struct wl_listener keyboard_focus_listener;
11
12 struct swc_pointer pointer;
13+ pixman_region32_t pointer_region;
14
15 struct wl_list devices;
16 };
17@@ -44,5 +46,8 @@ void swc_seat_add_event_sources(struct swc_seat * seat,
18
19 void swc_seat_add_devices(struct swc_seat * seat, struct udev * udev);
20
21+void swc_seat_set_pointer_region(struct swc_seat * seat,
22+ pixman_region32_t * region);
23+
24 #endif
25