suggestion picker: a persistent layer to complement virtual keyboards like wvkbd
| -rw-r--r-- | keyboard.c | 29 | ||||
| -rw-r--r-- | main.c | 12 |
2 files changed, 20 insertions, 21 deletions
@@ -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); } } @@ -147,12 +147,7 @@ wl_touch_down(void *data, struct wl_touch *wl_touch, uint32_t serial, touch_x = wl_fixed_to_int(x); touch_y = wl_fixed_to_int(y); - kbd_unpress_key(&keyboard); - - next_key = kbd_get_key(&keyboard, touch_x, touch_y); - if (next_key) { - kbd_press_key(&keyboard, next_key); - } + kbd_motion_key(&keyboard, touch_x, touch_y); } void @@ -221,10 +216,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, uint32_t serial, } if (cur_press && cur_x >= 0 && cur_y >= 0) { - next_key = kbd_get_key(&keyboard, cur_x, cur_y); - if (next_key) { - kbd_press_key(&keyboard, next_key); - } + kbd_motion_key(&keyboard, cur_x, cur_y); } } |