about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--config.def.h2
-rw-r--r--drw.c23
-rw-r--r--drw.h4
-rw-r--r--keyboard.c46
-rw-r--r--keyboard.h7
5 files changed, 68 insertions, 14 deletions
diff --git a/config.def.h b/config.def.h
index 5202221..947a75e 100644
--- a/config.def.h
+++ b/config.def.h
@@ -8,6 +8,7 @@ struct clr_scheme scheme = {
   .bg = {.bgra = {15, 15, 15, 225}},
   .fg = {.bgra = {45, 45, 45, 225}},
   .high = {.bgra = {100, 100, 100, 225}},
+  .swipe = {.bgra = {100, 255, 100, 64}},
   .text = {.color = UINT32_MAX},
 };
 struct clr_scheme scheme1 = {
@@ -15,6 +16,7 @@ struct clr_scheme scheme1 = {
   .bg = {.bgra = {15, 15, 15, 225}},
   .fg = {.bgra = {32, 32, 32, 225}},
   .high = {.bgra = {100, 100, 100, 225}},
+  .swipe = {.bgra = {100, 255, 100, 64}},
   .text = {.color = UINT32_MAX},
 };
 
diff --git a/drw.c b/drw.c
index fec4a50..89cb100 100644
--- a/drw.c
+++ b/drw.c
@@ -69,11 +69,15 @@ drw_draw_text(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
 }
 
 void
-drw_fill_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
-                   uint32_t w, uint32_t h) {
+drw_do_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
+                 uint32_t w, uint32_t h, bool over) {
 	cairo_save(d->cairo);
 
-	cairo_set_operator(d->cairo, CAIRO_OPERATOR_SOURCE);
+	if (over) {
+		cairo_set_operator(d->cairo, CAIRO_OPERATOR_OVER);
+	} else {
+		cairo_set_operator(d->cairo, CAIRO_OPERATOR_SOURCE);
+	}
 
 	cairo_rectangle(d->cairo, x, y, w, h);
 	cairo_set_source_rgba(
@@ -81,11 +85,24 @@ drw_fill_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
 	  color.bgra[0] / (double)255, color.bgra[3] / (double)255);
 	cairo_fill(d->cairo);
 
+
 	cairo_restore(d->cairo);
 
 	wl_surface_damage(d->surf, x, y, w, h);
 }
 
+void
+drw_fill_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
+                   uint32_t w, uint32_t h) {
+	drw_do_rectangle(d, color, x, y, w, h, false);
+}
+
+void
+drw_over_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
+                   uint32_t w, uint32_t h) {
+	drw_do_rectangle(d, color, x, y, w, h, true);
+}
+
 uint32_t
 setup_buffer(struct drwsurf *drwsurf) {
 	int stride = drwsurf->width * 4;
diff --git a/drw.h b/drw.h
index 69c0aa9..fb3df1c 100644
--- a/drw.h
+++ b/drw.h
@@ -31,8 +31,12 @@ typedef union {
 	uint32_t color;
 } Color;
 
+void drw_do_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
+                      uint32_t w, uint32_t h, bool fill);
 void drw_fill_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
                         uint32_t w, uint32_t h);
+void drw_over_rectangle(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
+                        uint32_t w, uint32_t h);
 
 void drw_draw_text(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
                    uint32_t w, uint32_t h, const char *label);
diff --git a/keyboard.c b/keyboard.c
index 33df2f8..ca7844c 100644
--- a/keyboard.c
+++ b/keyboard.c
@@ -167,7 +167,7 @@ kbd_get_key(struct kbd *kb, uint32_t x, uint32_t y) {
 void
 kbd_unpress_key(struct kbd *kb, uint32_t time) {
 	if (kb->last_press) {
-		kbd_draw_key(kb, kb->last_press, false);
+		kbd_draw_press(kb, kb->last_press, false);
 		if (kb->last_press->type == Copy) {
 			zwp_virtual_keyboard_v1_key(kb->vkbd, time, 127, // COMP key
 			                            WL_KEYBOARD_KEY_STATE_RELEASED);
@@ -195,6 +195,7 @@ void kbd_release_key(struct kbd *kb, uint32_t time) {
 		printf("\n");
 		// Important so autocompleted words get typed in time
 		fflush(stdout);
+		kbd_draw_layout(kb);
 		kb->last_swipe = NULL;
 	}
 }
@@ -203,15 +204,22 @@ void kbd_motion_key(struct kbd *kb, uint32_t time, uint32_t x, uint32_t y) {
 	// Output intersecting keys
 	// (for external 'swiping'-based accelerators).
 	if (kb->print_intersect) {
+		if (kb->last_press) {
+			kbd_unpress_key(kb, time);
+			// Redraw last press as a swipe.
+			kbd_draw_swipe(kb, kb->last_swipe);
+		}
 		struct key *intersect_key;
 		intersect_key = kbd_get_key(kb, x, y);
 		if (intersect_key &&
 		    (! kb->last_swipe || intersect_key->label != kb->last_swipe->label)) {
 			kbd_print_key_stdout(kb, intersect_key);
 			kb->last_swipe = intersect_key;
+			kbd_draw_swipe(kb, kb->last_swipe);
 		}
+	} else {
+		kbd_unpress_key(kb, time);
 	}
-	kbd_unpress_key(kb, time);
 }
 
 void
@@ -238,7 +246,7 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
 			zwp_virtual_keyboard_v1_modifiers(kb->vkbd, kb->mods, 0, 0, 0);
 		}
 		kb->last_swipe = kb->last_press = k;
-		kbd_draw_key(kb, k, true);
+		kbd_draw_press(kb, k, true);
 		zwp_virtual_keyboard_v1_key(kb->vkbd, time, kb->last_press->code,
 		                            WL_KEYBOARD_KEY_STATE_PRESSED);
 		if (kb->print || kb->print_intersect)
@@ -254,7 +262,7 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
 		if (k->code == Shift) {
 			kbd_draw_layout(kb);
 		}
-		kbd_draw_key(kb, k, kb->mods & k->code);
+		kbd_draw_press(kb, k, kb->mods & k->code);
 		zwp_virtual_keyboard_v1_modifiers(kb->vkbd, kb->mods, 0, 0, 0);
 		break;
 	case Layout:
@@ -268,7 +276,7 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
 		} else {
 			kb->compose = 0;
 		}
-		kbd_draw_key(kb, k, (bool)kb->compose);
+		kbd_draw_press(kb, k, (bool)kb->compose);
 		break;
 	case NextLayer:
 		// switch to the next layout in the layer sequence
@@ -297,7 +305,7 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
 	case Copy:
 		// copy code as unicode chr by setting a temporary keymap
 		kb->last_swipe = kb->last_press = k;
-		kbd_draw_key(kb, k, true);
+		kbd_draw_press(kb, k, true);
 		if (kb->debug)
 			fprintf(stderr, "pressing copy key\n");
 		create_and_upload_keymap(kb, kb->layout->keymap_name, k->code, k->code_mod);
@@ -352,17 +360,29 @@ kbd_print_key_stdout(struct kbd *kb, struct key *k) {
 }
 
 void
-kbd_draw_key(struct kbd *kb, struct key *k, bool pressed) {
+kbd_draw_key(struct kbd *kb, struct key *k, bool pressed, bool swiped) {
 	struct drwsurf *d = kb->surf;
 	const char *label = (kb->mods & Shift) ? k->shift_label : k->label;
 	if (kb->debug)
 		fprintf(stderr, "Draw key +%d+%d %dx%d -> %s\n", k->x, k->y, k->w, k->h,
 		        label);
 	struct clr_scheme *scheme = (k->scheme == 0) ? &(kb->scheme) : &(kb->scheme1);
-	Color *fill = pressed ? &scheme->high : &scheme->fg;
-	draw_inset(d, k->x, k->y, k->w, k->h, KBD_KEY_BORDER, *fill);
+	if (swiped) {
+		Color *fill = &scheme->swipe;
+		draw_over_inset(d, k->x, k->y, k->w, k->h, KBD_KEY_BORDER, *fill);
+	} else {
+		Color *fill = pressed ? &scheme->high : &scheme->fg;
+		draw_inset(d, k->x, k->y, k->w, k->h, KBD_KEY_BORDER, *fill);
+	}
 	drw_draw_text(d, scheme->text, k->x, k->y, k->w, k->h, label);
 }
+void
+kbd_draw_press(struct kbd *kb, struct key *k, bool pressed) {
+	kbd_draw_key(kb, k, pressed, false);
+}
+void kbd_draw_swipe(struct kbd *kb, struct key *k) {
+	kbd_draw_key(kb, k, false, true);
+}
 
 void
 kbd_draw_layout(struct kbd *kb) {
@@ -380,7 +400,7 @@ kbd_draw_layout(struct kbd *kb) {
 			continue;
 		}
 		pressed = next_key->type == Mod && kb->mods & next_key->code;
-		kbd_draw_key(kb, next_key, pressed);
+		kbd_draw_press(kb, next_key, pressed);
 		next_key++;
 	}
 }
@@ -405,6 +425,12 @@ draw_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
 	drw_fill_rectangle(ds, color, x + border, y + border, width - border,
 	                   height - border);
 }
+void
+draw_over_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
+                uint32_t height, uint32_t border, Color color) {
+	drw_over_rectangle(ds, color, x + border, y + border, width - border,
+	                   height - border);
+}
 
 void
 create_and_upload_keymap(struct kbd *kb, const char *name, uint32_t comp_unichr,
diff --git a/keyboard.h b/keyboard.h
index cdb5dd8..5610f38 100644
--- a/keyboard.h
+++ b/keyboard.h
@@ -45,6 +45,7 @@ struct clr_scheme {
 	Color fg;
 	Color bg;
 	Color high;
+	Color swipe;
 	Color text;
 };
 
@@ -105,6 +106,8 @@ struct kbd {
 
 void draw_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
                 uint32_t height, uint32_t border, Color color);
+void draw_over_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
+                     uint32_t height, uint32_t border, Color color);
 
 void kbd_init(struct kbd *kb, struct layout *layouts, char *layer_names_list);
 void kbd_init_layout(struct layout *l, uint32_t width, uint32_t height);
@@ -114,7 +117,9 @@ void kbd_release_key(struct kbd *kb, uint32_t time);
 void 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);
 void kbd_print_key_stdout(struct kbd *kb, struct key *k);
-void kbd_draw_key(struct kbd *kb, struct key *k, bool pressed);
+void kbd_draw_key(struct kbd *kb, struct key *k, bool pressed, bool swiped);
+void kbd_draw_press(struct kbd *kb, struct key *k, bool pressed);
+void kbd_draw_swipe(struct kbd *kb, struct key *k);
 void kbd_draw_layout(struct kbd *kb);
 void kbd_resize(struct kbd *kb, struct layout *layouts, uint8_t layoutcount);
 uint8_t kbd_get_rows(struct layout *l);