wvkbd

git clone https://git.tarina.org/wvkbd
Log | Files | Refs | README | LICENSE

commit da06f514df730a6a5a994954d17b970a2f6c1f1e
parent 2fd0cfc89c188701d9385edd103b1fd1a84c1e21
Author: Maarten van Gompel <proycon@anaproy.nl>
Date:   Tue, 24 Aug 2021 14:09:35 +0200

implemented printing to stdout

Diffstat:
Mkeyboard.h | 45+++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+), 0 deletions(-)

diff --git a/keyboard.h b/keyboard.h @@ -96,6 +96,7 @@ static void kbd_init_layout(struct layout *l, uint32_t width, uint32_t height); static struct key *kbd_get_key(struct kbd *kb, uint32_t x, uint32_t y); static void kbd_unpress_key(struct kbd *kb, uint32_t time); static void kbd_press_key(struct kbd *kb, struct key *k, uint32_t time); +static void kbd_print_key_stdout(struct kbd *kb, struct key *k); static void kbd_draw_key(struct kbd *kb, struct key *k, bool pressed); static void kbd_draw_layout(struct kbd *kb); static void kbd_resize(struct kbd *kb, uint32_t w, uint32_t h, @@ -256,6 +257,8 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) { kbd_draw_key(kb, k, true); zwp_virtual_keyboard_v1_key(kb->vkbd, time, kb->last_press->code, WL_KEYBOARD_KEY_STATE_PRESSED); + if (kb->print) + kbd_print_key_stdout(kb, k); if (compose) { fprintf(stderr, "pressing composed key\n"); compose++; @@ -304,6 +307,8 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) { zwp_virtual_keyboard_v1_modifiers(kb->vkbd, kb->mods, 0, 0, 0); zwp_virtual_keyboard_v1_key(kb->vkbd, time, 127, // COMP key WL_KEYBOARD_KEY_STATE_PRESSED); + if (kb->print) + kbd_print_key_stdout(kb, k); break; default: break; @@ -312,6 +317,46 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) { kb->surf->dirty = true; } + +void +kbd_print_key_stdout(struct kbd *kb, struct key *k) { + /* 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) + * */ + + bool handled = true; + if (k->type == Code) { + switch (k->code) { + case KEY_SPACE: + printf(" "); + break; + case KEY_ENTER: + printf("\n"); + break; + case KEY_BACKSPACE: + printf("\b"); + break; + case KEY_TAB: + printf("\t"); + break; + default: + handled = false; + break; + } + } else if (k->type != Copy) { + return; + } + + if (!handled) { + if ((kb->mods & Shift) || (kb->mods & CapsLock)) + printf("%s", k->shift_label); + else if (!(kb->mods & Ctrl) && !(kb->mods & Alt) && (!kb->mods & Super)) + printf("%s", k->label); + } + fflush(stdout); +} + void kbd_draw_key(struct kbd *kb, struct key *k, bool pressed) { struct drwsurf *d = kb->surf;