commit 5f2cbc2

Michael Forney  ·  2013-09-13 08:42:03 +0000 UTC
parent 33c7846
Finish implementing pointer events
4 files changed,  +97, -2
+22, -0
 1@@ -13,6 +13,8 @@
 2 #define TEST_BIT(var, n) \
 3     (((var)[(n)/((sizeof (var)[0])*8)] >> ((n)%((sizeof (var)[0])*8))) & 1)
 4 
 5+#define AXIS_STEP_DISTANCE 10
 6+
 7 static inline uint32_t timeval_to_msec(struct timeval * time)
 8 {
 9     return time->tv_sec * 1000 + time->tv_usec / 1000;
10@@ -49,6 +51,12 @@ static void handle_key_event(struct swc_evdev_device * device,
11 static void handle_rel_event(struct swc_evdev_device * device,
12                              struct input_event * input_event)
13 {
14+    struct swc_event event;
15+    struct swc_evdev_device_event_data data;
16+
17+    event.data = &data;
18+    data.time = timeval_to_msec(&input_event->time);
19+
20     switch (input_event->code)
21     {
22         case REL_X:
23@@ -59,6 +67,20 @@ static void handle_rel_event(struct swc_evdev_device * device,
24             device->motion.rel.dy += input_event->value;
25             device->motion.rel.pending = true;
26             break;
27+        case REL_WHEEL:
28+            event.type = SWC_EVDEV_DEVICE_EVENT_AXIS_MOTION;
29+            data.axis_motion.axis = WL_POINTER_AXIS_VERTICAL_SCROLL;
30+            data.axis_motion.amount
31+                = -AXIS_STEP_DISTANCE * wl_fixed_from_int(input_event->value);
32+            wl_signal_emit(&device->event_signal, &event);
33+            break;
34+        case REL_HWHEEL:
35+            event.type = SWC_EVDEV_DEVICE_EVENT_AXIS_MOTION;
36+            data.axis_motion.axis = WL_POINTER_AXIS_HORIZONTAL_SCROLL;
37+            data.axis_motion.amount
38+                = AXIS_STEP_DISTANCE * wl_fixed_from_int(input_event->value);
39+            wl_signal_emit(&device->event_signal, &event);
40+            break;
41     }
42 }
43 
+8, -1
 1@@ -11,7 +11,8 @@ enum swc_evdev_device_event_type
 2     SWC_EVDEV_DEVICE_EVENT_KEY,
 3     SWC_EVDEV_DEVICE_EVENT_BUTTON,
 4     SWC_EVDEV_DEVICE_EVENT_RELATIVE_MOTION,
 5-    SWC_EVDEV_DEVICE_EVENT_ABSOLUTE_MOTION
 6+    SWC_EVDEV_DEVICE_EVENT_ABSOLUTE_MOTION,
 7+    SWC_EVDEV_DEVICE_EVENT_AXIS_MOTION
 8 };
 9 
10 struct swc_evdev_device_event_data
11@@ -24,6 +25,12 @@ struct swc_evdev_device_event_data
12             wl_fixed_t dx, dy;
13         } relative_motion;
14 
15+        struct
16+        {
17+            wl_fixed_t amount;
18+            enum wl_pointer_axis axis;
19+        } axis_motion;
20+
21         struct
22         {
23             uint32_t key;
+3, -1
 1@@ -12,8 +12,10 @@ struct swc_pointer_handler
 2 {
 3     void (* focus)(struct swc_pointer * pointer);
 4     bool (* motion)(struct swc_pointer * pointer, uint32_t time);
 5-    void (* button)(struct swc_pointer * pointer, uint32_t time,
 6+    bool (* button)(struct swc_pointer * pointer, uint32_t time,
 7                     uint32_t button, uint32_t state);
 8+    bool (* axis)(struct swc_pointer * pointer, uint32_t time,
 9+                  enum wl_pointer_axis axis, wl_fixed_t amount);
10 };
11 
12 enum swc_pointer_event_type
+64, -0
 1@@ -141,11 +141,70 @@ static void handle_key(struct swc_seat * seat, uint32_t time, uint32_t key,
 2 static void handle_button(struct swc_seat * seat, uint32_t time,
 3                           uint32_t button, uint32_t state)
 4 {
 5+    struct swc_pointer * pointer = &seat->pointer;
 6+
 7+    if ((!pointer->handler || !pointer->handler->button
 8+         || !pointer->handler->button(pointer, time, button, state))
 9+        && pointer->focus.resource)
10+    {
11+        struct wl_client * client
12+            = wl_resource_get_client(pointer->focus.resource);
13+        struct wl_display * display = wl_client_get_display(client);
14+        uint32_t serial = wl_display_next_serial(display);
15+
16+        wl_pointer_send_button(pointer->focus.resource, serial, time,
17+                               button, state);
18+    }
19 }
20 
21 static void handle_relative_motion(struct swc_seat * seat, uint32_t time,
22                                    wl_fixed_t dx, wl_fixed_t dy)
23 {
24+    struct swc_pointer * pointer = &seat->pointer;
25+
26+    clip_position(seat, pointer->x + dx, pointer->y + dy);
27+
28+    if (pointer->handler && pointer->handler->focus)
29+        pointer->handler->focus(pointer);
30+
31+    if ((!pointer->handler || !pointer->handler->motion
32+         || !pointer->handler->motion(pointer, time))
33+        && pointer->focus.resource)
34+    {
35+        wl_fixed_t surface_x, surface_y;
36+        surface_x = pointer->x
37+            - wl_fixed_from_int(pointer->focus.surface->geometry.x);
38+        surface_y = pointer->y
39+            - wl_fixed_from_int(pointer->focus.surface->geometry.y);
40+
41+        wl_pointer_send_motion(pointer->focus.resource, time,
42+                               surface_x, surface_y);
43+
44+        if (pointer->cursor.surface)
45+        {
46+            swc_surface_move
47+                (pointer->cursor.surface,
48+                 wl_fixed_to_int(pointer->x) - pointer->cursor.hotspot_x,
49+                 wl_fixed_to_int(pointer->y) - pointer->cursor.hotspot_y);
50+        }
51+    }
52+}
53+
54+static void handle_axis_motion(struct swc_seat * seat, uint32_t time,
55+                               enum wl_pointer_axis axis, wl_fixed_t amount)
56+{
57+    struct swc_pointer * pointer = &seat->pointer;
58+
59+    if ((!pointer->handler || !pointer->handler->axis
60+         || !pointer->handler->axis(pointer, time, axis, amount))
61+        && pointer->focus.resource)
62+    {
63+        struct wl_client * client
64+            = wl_resource_get_client(pointer->focus.resource);
65+        struct wl_display * display = wl_client_get_display(client);
66+
67+        wl_pointer_send_axis(pointer->focus.resource, time, axis, amount);
68+    }
69 }
70 
71 static void handle_evdev_event(struct wl_listener * listener, void * data)
72@@ -173,6 +232,11 @@ static void handle_evdev_event(struct wl_listener * listener, void * data)
73             break;
74         case SWC_EVDEV_DEVICE_EVENT_ABSOLUTE_MOTION:
75             break;
76+        case SWC_EVDEV_DEVICE_EVENT_AXIS_MOTION:
77+            handle_axis_motion(entry->seat, evdev_data->time,
78+                               evdev_data->axis_motion.axis,
79+                               evdev_data->axis_motion.amount);
80+            break;
81     }
82 }
83