suggestion picker: a persistent layer to complement virtual keyboards like wvkbd
Diffstat (limited to 'keyboard.c')
-rw-r--r--keyboard.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/keyboard.c b/keyboard.c
index 5de8d6b..a02d5a2 100644
--- a/keyboard.c
+++ b/keyboard.c
@@ -15,9 +15,9 @@ void
kbd_init(struct kbd *kb) {
fprintf(stderr, "Initializing keyboard\n");
- kb->suggs[0].label = strdup("Hello");
- kb->suggs[1].label = strdup("Sugar");
- kb->suggs[2].label = strdup("Pie");
+ kb->suggs[0].label = strdup("Hey");
+ kb->suggs[1].label = strdup("Honey");
+ kb->suggs[2].label = strdup("Bunches");
kb->suggs[3].label = NULL;
}
@@ -74,16 +74,25 @@ kbd_unpress_key(struct kbd *kb) {
void
kbd_release_key(struct kbd *kb) {
- kbd_unpress_key(kb);
- printf("\n");
- // Important so autocompleted words get typed in time
- fflush(stdout);
- kbd_draw_layout(kb);
+ if (kb->last_press) {
+ printf("%s\n", kb->last_press->label);
+ // Important so autocompleted words get typed in time
+ fflush(stdout);
+ kbd_unpress_key(kb);
+ kbd_draw_layout(kb);
+ }
}
void
kbd_motion_key(struct kbd *kb, uint32_t x, uint32_t y) {
-
+ struct key *next_key;
+ next_key = kbd_get_key(kb, x, y);
+ if (next_key != kb->last_press) {
+ kbd_unpress_key(kb);
+ if (next_key) {
+ kbd_press_key(kb, next_key);
+ }
+ }
}
void
@@ -91,8 +100,6 @@ kbd_press_key(struct kbd *kb, struct key *k) {
if (k->label) {
kb->last_press = k;
kbd_draw_key(kb, k, Press);
- printf("%s", k->label);
- fflush(stdout);
}
}