From: Jan Arne Petersen <[email protected]>

Add support for arrow keys on the virtual keyboard and make it possible
to move around the cursor in the editor example.
---
 clients/editor.c   | 19 ++++++++++++++++---
 clients/keyboard.c | 32 ++++++++++++++++++++++++++++----
 2 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/clients/editor.c b/clients/editor.c
index 301cbe2..5ad1aa2 100644
--- a/clients/editor.c
+++ b/clients/editor.c
@@ -288,13 +288,12 @@ text_model_key(void *data,
                uint32_t key,
                uint32_t state)
 {
+       struct text_entry *entry = data;
        const char *state_label;
-       const char *key_label;
+       const char *key_label = "released";
 
        if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
                state_label = "pressed";
-       } else {
-               state_label = "released";
        }
 
        switch (key) {
@@ -304,6 +303,20 @@ text_model_key(void *data,
                case XKB_KEY_KP_Enter:
                        key_label = "Enter";
                        break;
+               case XKB_KEY_Left:
+                       if (entry->cursor > 0) {
+                               entry->cursor--;
+                               entry->anchor = entry->cursor;
+                               widget_schedule_redraw(entry->widget);
+                       }
+                       break;
+               case XKB_KEY_Right:
+                       if (entry->cursor < strlen(entry->text)) {
+                               entry->cursor++;
+                               entry->anchor = entry->cursor;
+                               widget_schedule_redraw(entry->widget);
+                       }
+                       break;
                default:
                        key_label = "Unknown";
        }
diff --git a/clients/keyboard.c b/clients/keyboard.c
index c90c5b2..bf0e9f0 100644
--- a/clients/keyboard.c
+++ b/clients/keyboard.c
@@ -47,7 +47,11 @@ enum key_type {
        keytype_space,
        keytype_switch,
        keytype_symbols,
-       keytype_tab
+       keytype_tab,
+       keytype_arrow_up,
+       keytype_arrow_left,
+       keytype_arrow_right,
+       keytype_arrow_down
 };
 
 struct key {
@@ -96,9 +100,13 @@ static const struct key keys[] = {
        { keytype_default, ".", ".", 1},
        { keytype_switch, "ABC", "abc", 1},
 
-       { keytype_symbols, "?123", "?123", 2},
-       { keytype_space, "", "", 8},
-       { keytype_symbols, "?123", "?123", 2}
+       { keytype_symbols, "?123", "?123", 1},
+       { keytype_space, "", "", 6},
+       { keytype_arrow_up, "/\\", "/\\", 1},
+       { keytype_arrow_left, "<", "<", 1},
+       { keytype_arrow_right, ">", ">", 1},
+       { keytype_arrow_down, "\\/", "\\/", 1},
+       { keytype_symbols, "?123", "?123", 1}
 };
 
 static const unsigned int columns = 12;
@@ -255,6 +263,22 @@ keyboard_handle_key(struct keyboard *keyboard, const 
struct key *key)
                        input_method_context_key(keyboard->keyboard->context,
                                                 XKB_KEY_Tab, 
WL_KEYBOARD_KEY_STATE_PRESSED);
                        break;
+               case keytype_arrow_up:
+                       input_method_context_key(keyboard->keyboard->context,
+                                                XKB_KEY_Up, 
WL_KEYBOARD_KEY_STATE_PRESSED);
+                       break;
+               case keytype_arrow_left:
+                       input_method_context_key(keyboard->keyboard->context,
+                                                XKB_KEY_Left, 
WL_KEYBOARD_KEY_STATE_PRESSED);
+                       break;
+               case keytype_arrow_right:
+                       input_method_context_key(keyboard->keyboard->context,
+                                                XKB_KEY_Right, 
WL_KEYBOARD_KEY_STATE_PRESSED);
+                       break;
+               case keytype_arrow_down:
+                       input_method_context_key(keyboard->keyboard->context,
+                                                XKB_KEY_Down, 
WL_KEYBOARD_KEY_STATE_PRESSED);
+                       break;
        }
 }
 
-- 
1.7.11.4

_______________________________________________
wayland-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to