editor, keyboard: Add support for arrow keys

Add support for arrow keys on the virtual keyboard and make it possible
to move around the cursor in the editor example.
This commit is contained in:
Jan Arne Petersen 2012-09-17 15:28:07 +02:00 committed by Kristian Høgsberg
parent d7f282b84e
commit 8aba11d057
2 changed files with 44 additions and 7 deletions

View File

@ -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";
}

View File

@ -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;
}
}