4 Commits

Author SHA1 Message Date
Maarten van Gompel
4fd182a583 ci: fix for clang-format 2026-03-06 15:30:20 +01:00
Maarten van Gompel
47dadbee23 version bump 2026-03-06 15:12:40 +01:00
Justin Lovinger
7b782d8f7d Fix keys with multi-character labels causing issues with swiping
Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
2026-03-06 15:11:35 +01:00
Pachulke
e67a5afce9 Add arguments to define different text color for pressed and swiped keys
Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
2026-03-06 15:11:35 +01:00
6 changed files with 84 additions and 9 deletions

View File

@@ -6,7 +6,7 @@ packages:
- libxkbcommon-dev
- pango-dev
- scdoc
- clang21-extra-tools # needed for formatting
- clang22-extra-tools # needed for formatting
sources:
- https://git.sr.ht/~proycon/wvkbd
triggers:

View File

@@ -1,4 +1,4 @@
VERSION = 0.19.4
VERSION = 0.20
CFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=700
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man

View File

@@ -14,6 +14,8 @@ struct clr_scheme schemes[] = {
.high = {.bgra = {100, 100, 100, transparency}},
.swipe = {.bgra = {100, 255, 100, 64}},
.text = {.color = UINT32_MAX},
.text_press = {.color = UINT32_MAX},
.text_swipe = {.color = UINT32_MAX},
.font = DEFAULT_FONT,
.rounding = DEFAULT_ROUNDING,
},
@@ -23,6 +25,8 @@ struct clr_scheme schemes[] = {
.fg = {.bgra = {32, 32, 32, transparency}},
.high = {.bgra = {100, 100, 100, transparency}},
.swipe = {.bgra = {100, 255, 100, 64}},
.text_press = {.color = UINT32_MAX},
.text_swipe = {.color = UINT32_MAX},
.text = {.color = UINT32_MAX},
.font = DEFAULT_FONT,
.rounding = DEFAULT_ROUNDING,

View File

@@ -553,9 +553,13 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time)
void
kbd_print_key_stdout(struct kbd *kb, struct key *k)
{
/* printed keys may slightly differ from the actual output
/* Printed keys may slightly differ from the actual output
* we generally print what is on the key LABEL and only support the normal
* and shift layers. Other modifiers produce no output (Ctrl,Alt)
* and shift layers. Other modifiers produce no output (Ctrl,Alt).
* If a label has more than one character,
* only the first character is printed,
* because downpipe programs otherwise have no way of differentiating a swipe
* from a single keypress.
* */
bool handled = true;
@@ -584,13 +588,34 @@ kbd_print_key_stdout(struct kbd *kb, struct key *k)
if (!handled) {
if ((kb->mods & Shift) ||
((kb->mods & CapsLock) & (strlen(k->label) == 1 && isalpha(k->label[0]))))
printf("%s", k->shift_label);
kbd_print_first_utf8_char_stdout(k->shift_label);
else if (!(kb->mods & Ctrl) && !(kb->mods & Alt) && !(kb->mods & Super))
printf("%s", k->label);
kbd_print_first_utf8_char_stdout(k->label);
}
fflush(stdout);
}
void kbd_print_first_utf8_char_stdout(const char *str) {
unsigned char c = (unsigned char)str[0];
int len;
if ((c & 0x80) == 0) {
len = 1;
} else if ((c & 0xE0) == 0xC0) {
len = 2;
} else if ((c & 0xF0) == 0xE0) {
len = 3;
} else if ((c & 0xF8) == 0xF0) {
len = 4;
} else {
len = 1; // Invalid UTF-8
}
for (int i = 0; i < len && str[i] != '\0'; i++) {
putchar(str[i]);
}
}
void
kbd_clear_last_popup(struct kbd *kb)
{
@@ -616,19 +641,26 @@ kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type)
case Unpress:
draw_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER,
scheme->fg, scheme->rounding);
drw_draw_text(kb->surf, scheme->text, k->x, k->y, k->w, k->h,
KBD_KEY_BORDER, label, scheme->font_description);
break;
case Press:
draw_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER,
scheme->high, scheme->rounding);
drw_draw_text(kb->surf, scheme->text_press, k->x, k->y, k->w, k->h,
KBD_KEY_BORDER, label, scheme->font_description);
break;
case Swipe:
draw_over_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER,
scheme->swipe, scheme->rounding);
drw_draw_text(kb->surf, scheme->text_swipe, k->x, k->y, k->w, k->h,
KBD_KEY_BORDER, label, scheme->font_description);
break;
default:
drw_draw_text(kb->surf, scheme->text, k->x, k->y, k->w, k->h,
KBD_KEY_BORDER, label, scheme->font_description);
}
drw_draw_text(kb->surf, scheme->text, k->x, k->y, k->w, k->h,
KBD_KEY_BORDER, label, scheme->font_description);
if (type == Press || type == Unpress) {
kbd_clear_last_popup(kb);
@@ -642,7 +674,7 @@ kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type)
kb->last_popup_y, k->w, k->h, scheme->rounding);
draw_inset(kb->popup_surf, k->x, kb->last_popup_y, k->w, k->h,
KBD_KEY_BORDER, scheme->high, scheme->rounding);
drw_draw_text(kb->popup_surf, scheme->text, k->x, kb->last_popup_y,
drw_draw_text(kb->popup_surf, scheme->text_press, k->x, kb->last_popup_y,
k->w, k->h, KBD_KEY_BORDER, label,
scheme->font_description);
}

View File

@@ -54,6 +54,8 @@ struct clr_scheme {
Color high;
Color swipe;
Color text;
Color text_press;
Color text_swipe;
char *font;
int rounding;
PangoFontDescription *font_description;
@@ -139,6 +141,7 @@ 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_print_first_utf8_char_stdout(const char *str);
void kbd_clear_last_popup(struct kbd *kb);
void kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type);
void kbd_draw_layout(struct kbd *kb);

36
main.c
View File

@@ -618,6 +618,14 @@ usage(char *argv0)
fprintf(stderr, " --text [rrggbb|aa] - Set color of text on keys\n");
fprintf(stderr,
" --text-sp [rrggbb|aa] - Set color of text on special keys\n");
fprintf(stderr,
" --text-press [rrggbb|aa] - Set color of text on pressed keys\n");
fprintf(stderr,
" --text-press-sp [rrggbb|aa] - Set color of text on pressed special keys\n");
fprintf(stderr,
" --text-swipe [rrggbb|aa] - Set color of text on swiped keys\n");
fprintf(stderr,
" --text-swipe-sp [rrggbb|aa] - Set color of text on swiped special keys\n");
fprintf(stderr,
" --list-layers - Print the list of available layers\n");
fprintf(stderr,
@@ -902,6 +910,34 @@ main(int argc, char **argv)
exit(1);
}
set_kbd_colors(keyboard.schemes[1].text.bgra, argv[++i]);
} else if ((!strcmp(argv[i], "-text-press")) ||
(!strcmp(argv[i], "--text-press"))) {
if (i >= argc - 1) {
usage(argv[0]);
exit(1);
}
set_kbd_colors(keyboard.schemes[0].text_press.bgra, argv[++i]);
} else if ((!strcmp(argv[i], "-text-press-sp")) ||
(!strcmp(argv[i], "--text-press-sp"))) {
if (i >= argc - 1) {
usage(argv[0]);
exit(1);
}
set_kbd_colors(keyboard.schemes[1].text_press.bgra, argv[++i]);
} else if ((!strcmp(argv[i], "-text-swipe")) ||
(!strcmp(argv[i], "--text-swipe"))) {
if (i >= argc - 1) {
usage(argv[0]);
exit(1);
}
set_kbd_colors(keyboard.schemes[0].text_swipe.bgra, argv[++i]);
} else if ((!strcmp(argv[i], "-text-swipe-sp")) ||
(!strcmp(argv[i], "--text-swipe-sp"))) {
if (i >= argc - 1) {
usage(argv[0]);
exit(1);
}
set_kbd_colors(keyboard.schemes[1].text_swipe.bgra, argv[++i]);
} else if (!strcmp(argv[i], "-H")) {
if (i >= argc - 1) {
usage(argv[0]);