suggestion picker: a persistent layer to complement virtual keyboards like wvkbd
Diffstat (limited to 'keyboard.c')
-rw-r--r--keyboard.c37
1 files changed, 10 insertions, 27 deletions
diff --git a/keyboard.c b/keyboard.c
index a964c34..a2c40f3 100644
--- a/keyboard.c
+++ b/keyboard.c
@@ -39,17 +39,11 @@ kbd_init_layout(struct layout *l, uint32_t width, uint32_t height) {
struct key *k = l->keys;
double rowlength = kbd_get_row_length(k);
- while (k->type != Last) {
- if (k->type == EndRow) {
- y += l->keyheight;
- x = 0;
- rowlength = kbd_get_row_length(k + 1);
- } else if (k->type == Code) {
- k->x = x;
- k->y = y;
- k->w = width / rowlength;
- x += k->w;
- }
+ while (k->label != NULL) {
+ k->x = x;
+ k->y = y;
+ k->w = width / rowlength;
+ x += k->w;
k->h = l->keyheight;
k++;
}
@@ -58,7 +52,7 @@ kbd_init_layout(struct layout *l, uint32_t width, uint32_t height) {
double
kbd_get_row_length(struct key *k) {
double l = 0.0;
- while ((k->type != Last) && (k->type != EndRow)) {
+ while (k->label != NULL) {
l += 1.0;
k++;
}
@@ -71,9 +65,8 @@ kbd_get_key(struct kbd *kb, uint32_t x, uint32_t y) {
struct key *k = l->keys;
if (kb->debug)
fprintf(stderr, "get key: +%d+%d\n", x, y);
- while (k->type != Last) {
- if ((k->type != EndRow) && (k->type != Pad) && (k->type != Pad) &&
- (x >= k->x) && (y >= k->y) && (x < k->x + k->w) && (y < k->y + k->h)) {
+ while (k->label != NULL) {
+ if ((x >= k->x) && (y >= k->y) && (x < k->x + k->w) && (y < k->y + k->h)) {
return k;
}
k++;
@@ -105,16 +98,10 @@ kbd_motion_key(struct kbd *kb, uint32_t time, uint32_t x, uint32_t y) {
void
kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
-
-
- switch (k->type) {
- case Code:
+ if (k->label) {
kb->last_press = k;
kbd_draw_key(kb, k, Press);
kbd_print_key_stdout(kb, k);
- break;
- default:
- break;
}
}
@@ -156,11 +143,7 @@ kbd_draw_layout(struct kbd *kb) {
drw_fill_rectangle(d, kb->scheme.bg, 0, 0, kb->w, kb->h);
- while (next_key->type != Last) {
- if ((next_key->type == Pad) || (next_key->type == EndRow)) {
- next_key++;
- continue;
- }
+ while (next_key->label != NULL) {
kbd_draw_key(kb, next_key, Unpress);
next_key++;
}