suggestion picker: a persistent layer to complement virtual keyboards like wvkbd
Diffstat (limited to 'keyboard.c')
-rw-r--r--keyboard.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/keyboard.c b/keyboard.c
index 5de8d6b..293a2f6 100644
--- a/keyboard.c
+++ b/keyboard.c
@@ -2,7 +2,6 @@
#include <sys/mman.h>
#include "keyboard.h"
#include "drw.h"
-#include "os-compatibility.h"
#define KBD_KEY_BORDER 1
@@ -15,9 +14,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;
}
@@ -30,11 +29,16 @@ kbd_init_suggs(struct key *suggs, uint32_t width, uint32_t height) {
struct key *k = suggs;
double rowlength = kbd_get_row_length(k);
+ uint8_t i = 0;
while (k->label != NULL) {
k->x = x;
k->y = y;
k->w = width / rowlength;
x += k->w;
+ i++;
+ if (x < (width * i) / rowlength) {
+ k->w++; x++;
+ }
k->h = keyheight;
k++;
}
@@ -69,21 +73,30 @@ kbd_unpress_key(struct kbd *kb) {
if (kb->last_press) {
kbd_draw_key(kb, kb->last_press, Unpress);
kb->last_press = NULL;
+ drwsurf_flip(kb->surf);
}
}
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);
+ }
}
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 +104,7 @@ 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);
+ drwsurf_flip(kb->surf);
}
}