commit 633b4c0
Michael Forney
·
2014-02-27 05:03:02 +0000 UTC
parent 6d459f0
Add button bindings
3 files changed,
+32,
-5
+29,
-4
1@@ -25,6 +25,7 @@
2 #include "bindings.h"
3 #include "internal.h"
4 #include "keyboard.h"
5+#include "pointer.h"
6 #include "seat.h"
7 #include "util.h"
8
9@@ -41,14 +42,22 @@ struct binding
10 static bool handle_key(struct keyboard * keyboard, uint32_t time,
11 struct press * press, uint32_t state);
12
13-static struct keyboard_handler binding_handler = {
14- .key = &handle_key,
15+static struct keyboard_handler key_binding_handler = {
16+ .key = &handle_key
17 };
18
19-static struct wl_array key_bindings;
20+static bool handle_button(struct pointer_handler * handler, uint32_t time,
21+ struct press * press, uint32_t state);
22+
23+static struct pointer_handler button_binding_handler = {
24+ .button = &handle_button
25+};
26+
27+static struct wl_array key_bindings, button_bindings;
28
29 const struct swc_bindings swc_bindings = {
30- .keyboard_handler = &binding_handler
31+ .keyboard_handler = &key_binding_handler,
32+ .pointer_handler = &button_binding_handler
33 };
34
35 static struct binding * find_binding(struct wl_array * bindings,
36@@ -97,6 +106,11 @@ static struct binding * find_key_binding(uint32_t modifiers, uint32_t key)
37 return binding;
38 }
39
40+static struct binding * find_button_binding(uint32_t modifiers, uint32_t value)
41+{
42+ return find_binding(&button_bindings, modifiers, value);
43+}
44+
45 static bool handle_binding
46 (uint32_t time, struct press * press, uint32_t state,
47 struct binding * (* find_binding)(uint32_t, uint32_t))
48@@ -126,9 +140,16 @@ bool handle_key(struct keyboard * keyboard, uint32_t time,
49 return handle_binding(time, key, state, &find_key_binding);
50 }
51
52+bool handle_button(struct pointer_handler * handler, uint32_t time,
53+ struct press * button, uint32_t state)
54+{
55+ return handle_binding(time, button, state, &find_button_binding);
56+}
57+
58 bool swc_bindings_initialize()
59 {
60 wl_array_init(&key_bindings);
61+ wl_array_init(&button_bindings);
62
63 return true;
64 }
65@@ -136,6 +157,7 @@ bool swc_bindings_initialize()
66 void swc_bindings_finalize()
67 {
68 wl_array_release(&key_bindings);
69+ wl_array_release(&button_bindings);
70 }
71
72 EXPORT
73@@ -151,6 +173,9 @@ void swc_add_binding(enum swc_binding_type type,
74 case SWC_BINDING_KEY:
75 bindings = &key_bindings;
76 break;
77+ case SWC_BINDING_BUTTON:
78+ bindings = &button_bindings;
79+ break;
80 }
81
82 binding = wl_array_add(bindings, sizeof *binding);
+1,
-0
1@@ -29,6 +29,7 @@
2 struct swc_bindings
3 {
4 struct keyboard_handler * keyboard_handler;
5+ struct pointer_handler * pointer_handler;
6 };
7
8 bool swc_bindings_initialize();
+2,
-1
1@@ -224,7 +224,8 @@ enum
2
3 enum swc_binding_type
4 {
5- SWC_BINDING_KEY
6+ SWC_BINDING_KEY,
7+ SWC_BINDING_BUTTON,
8 };
9
10 typedef void (* swc_binding_handler_t)(void * data, uint32_t time,