mirror of
https://github.com/jjsullivan5196/wvkbd.git
synced 2026-04-09 14:42:30 +02:00
Fix keys with multi-character labels causing issues with swiping
Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
This commit is contained in:
committed by
Maarten van Gompel
parent
e67a5afce9
commit
7b782d8f7d
33
keyboard.c
33
keyboard.c
@@ -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)
|
||||
{
|
||||
|
||||
@@ -141,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);
|
||||
|
||||
Reference in New Issue
Block a user