commit c3e48a9

Michael Forney  ·  2014-02-09 12:24:44 +0000 UTC
parent 59faad0
bindings: Add state parameter

This way, bindings can respond to key/button presses, releases, or both.
4 files changed,  +28, -24
+4, -1
 1@@ -260,10 +260,13 @@ static void new_screen(struct swc_screen * swc)
 2 
 3 const struct swc_manager manager = { &new_window, &new_screen };
 4 
 5-static void spawn(void * data, uint32_t time, uint32_t value)
 6+static void spawn(void * data, uint32_t time, uint32_t value, uint32_t state)
 7 {
 8     char * const * command = data;
 9 
10+    if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
11+        return;
12+
13     if (fork() == 0)
14     {
15         execvp(command[0], command);
+15, -18
 1@@ -50,7 +50,7 @@ const struct swc_bindings swc_bindings = {
 2 };
 3 
 4 static bool handle_binding(struct wl_array * bindings, uint32_t time,
 5-                           uint32_t modifiers, uint32_t value)
 6+                           uint32_t modifiers, uint32_t value, uint32_t state)
 7 {
 8     struct binding * binding;
 9 
10@@ -60,7 +60,7 @@ static bool handle_binding(struct wl_array * bindings, uint32_t time,
11             && (binding->modifiers == modifiers
12                 || binding->modifiers == SWC_MOD_ANY))
13         {
14-            binding->handler(binding->data, time, value);
15+            binding->handler(binding->data, time, value, state);
16             return true;
17         }
18     }
19@@ -71,27 +71,24 @@ static bool handle_binding(struct wl_array * bindings, uint32_t time,
20 bool handle_key(struct swc_keyboard * keyboard, uint32_t time,
21                 uint32_t key, uint32_t state)
22 {
23-    if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
24-    {
25-        xkb_keysym_t keysym;
26+    xkb_keysym_t keysym;
27 
28-        keysym = xkb_state_key_get_one_sym(keyboard->xkb.state, XKB_KEY(key));
29+    keysym = xkb_state_key_get_one_sym(keyboard->xkb.state, XKB_KEY(key));
30 
31-        if (handle_binding(&key_bindings, time, keyboard->modifiers, keysym))
32-            return true;
33+    if (handle_binding(&key_bindings, time, keyboard->modifiers, keysym, state))
34+        return true;
35 
36-        xkb_layout_index_t layout;
37-        const xkb_keysym_t * keysyms;
38+    xkb_layout_index_t layout;
39+    const xkb_keysym_t * keysyms;
40 
41-        layout = xkb_state_key_get_layout(keyboard->xkb.state, XKB_KEY(key));
42-        xkb_keymap_key_get_syms_by_level(keyboard->xkb.keymap.map, XKB_KEY(key),
43-                                         layout, 0, &keysyms);
44+    layout = xkb_state_key_get_layout(keyboard->xkb.state, XKB_KEY(key));
45+    xkb_keymap_key_get_syms_by_level(keyboard->xkb.keymap.map, XKB_KEY(key),
46+                                     layout, 0, &keysyms);
47 
48-        if (keysyms && handle_binding(&key_bindings, time,
49-                                      keyboard->modifiers, keysyms[0]))
50-        {
51-            return true;
52-        }
53+    if (keysyms && handle_binding(&key_bindings, time,
54+                                  keyboard->modifiers, keysyms[0], state))
55+    {
56+        return true;
57     }
58 
59     return false;
+8, -4
 1@@ -785,16 +785,20 @@ bool handle_motion(struct swc_pointer * pointer, uint32_t time)
 2     return false;
 3 }
 4 
 5-static void handle_terminate(void * data, uint32_t time, uint32_t value)
 6+static void handle_terminate(void * data, uint32_t time,
 7+                             uint32_t value, uint32_t state)
 8 {
 9-    wl_display_terminate(swc.display);
10+    if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
11+        wl_display_terminate(swc.display);
12 }
13 
14-static void handle_switch_vt(void * data, uint32_t time, uint32_t value)
15+static void handle_switch_vt(void * data, uint32_t time,
16+                             uint32_t value, uint32_t state)
17 {
18     uint8_t vt = value - XKB_KEY_XF86Switch_VT_1 + 1;
19 
20-    swc_launch_activate_vt(vt);
21+    if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
22+        swc_launch_activate_vt(vt);
23 }
24 
25 static void handle_launch_event(struct wl_listener * listener, void * data)
+1, -1
1@@ -189,7 +189,7 @@ enum swc_binding_type
2 };
3 
4 typedef void (* swc_binding_handler_t)(void * data, uint32_t time,
5-                                       uint32_t value);
6+                                       uint32_t value, uint32_t state);
7 
8 void swc_add_binding(enum swc_binding_type type,
9                      uint32_t modifiers, uint32_t value,