about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZach DeCook <zachdecook@librem.one>2022-06-24 11:10:18 -0400
committerZach DeCook <zachdecook@librem.one>2022-06-24 11:10:18 -0400
commit213187bbf419e847c50d49d0d1299935cbcd087f (patch)
treec9b4d76edcbb8622c72e8af57cf99143edc0eca9
parent534808211f04779ef87848f2b67daee333420bb3 (diff)
downloadsuggpicker-213187bbf419e847c50d49d0d1299935cbcd087f.tar.gz
suggpicker: Allow changing mind about which one you want to pick
-rw-r--r--keyboard.c29
-rw-r--r--main.c12
2 files changed, 20 insertions, 21 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);
 	}
 }
 
diff --git a/main.c b/main.c
index cf2ed9f..8dd7810 100644
--- a/main.c
+++ b/main.c
@@ -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);
 	}
 }