summary refs log tree commit diff
path: root/keyboard.c
diff options
context:
space:
mode:
authorZach DeCook <zachdecook@librem.one>2022-01-21 10:38:04 -0500
committerZach DeCook <zachdecook@librem.one>2022-01-21 10:38:04 -0500
commit870d8db9bc3291bf5e4e9d2cb85d7d7b6c56952f (patch)
tree358e4aca8a19d0d024e3a14b5bbaea7c5c94440c /keyboard.c
parentb47bac490ec77a4870c344e576dc8a72f7af8e05 (diff)
downloadsuggpicker-870d8db9bc3291bf5e4e9d2cb85d7d7b6c56952f.tar.gz
layout: remove type
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++;
 	}