commit 2859b0b

Michael Forney  ·  2013-06-21 08:47:31 +0000 UTC
parent 415910c
Add pointer handler
2 files changed,  +45, -1
+44, -0
 1@@ -105,7 +105,50 @@ struct swc_keyboard_handler keyboard_handler = {
 2     .key = &handle_key,
 3 };
 4 
 5+static void handle_focus(struct swc_pointer * pointer)
 6+{
 7+    struct swc_seat * seat;
 8+    struct swc_compositor * compositor;
 9+    struct swc_surface * surface;
10+    int32_t surface_x, surface_y;
11+
12+    wl_list_for_each(surface, &compositor->surfaces, link)
13+    {
14+        pixman_region32_t region;
15+
16+        pixman_region32_init_rect
17+            (&region, surface->geometry.x, surface->geometry.y,
18+             surface->geometry.width, surface->geometry.height);
19+
20+        surface_x = wl_fixed_to_int(pointer->x) - surface->geometry.x;
21+        surface_y = wl_fixed_to_int(pointer->y) - surface->geometry.y;
22+
23+        if (pixman_region32_contains_point(&surface->state.input,
24+                                           surface_x, surface_y, NULL))
25+        {
26+            swc_pointer_set_focus(pointer, surface);
27+            return;
28+        }
29+    }
30 
31+    swc_pointer_set_focus(pointer, NULL);
32+}
33+
34+static bool handle_motion(struct swc_pointer * pointer, uint32_t time)
35+{
36+    struct swc_seat * seat;
37+    struct swc_compositor * compositor;
38+
39+    seat = wl_container_of(pointer, seat, pointer);
40+    compositor = wl_container_of(seat, compositor, seat);
41+
42+    return false;
43+}
44+
45+struct swc_pointer_handler pointer_handler = {
46+    .focus = &handle_focus,
47+    .motion = &handle_motion
48+};
49 
50 /* XXX: maybe this should go in swc_drm */
51 static void handle_tty_event(struct wl_listener * listener, void * data)
52@@ -319,6 +362,7 @@ bool swc_compositor_initialize(struct swc_compositor * compositor,
53 
54     swc_seat_add_event_sources(&compositor->seat, event_loop);
55     compositor->seat.keyboard.handler = &keyboard_handler;
56+    compositor->seat.pointer.handler = &pointer_handler;
57 
58     /* TODO: configurable seat */
59     if (!swc_drm_initialize(&compositor->drm, compositor->udev, default_seat))
+1, -1
1@@ -11,7 +11,7 @@ struct swc_pointer;
2 struct swc_pointer_handler
3 {
4     void (* focus)(struct swc_pointer * pointer);
5-    void (* motion)(struct swc_pointer * pointer, uint32_t time);
6+    bool (* motion)(struct swc_pointer * pointer, uint32_t time);
7     void (* button)(struct swc_pointer * pointer, uint32_t time,
8                     uint32_t button, uint32_t state);
9 };