diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-09-27 17:03:06 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-11-01 16:26:16 +0100 |
| commit | 980858186149651df5543b6fc99a4f7db0cdd089 (patch) | |
| tree | d347200b0a562d84df505097651ad0642f207fdd /src/input | |
| parent | 39f50e601d395bbd2d78d0147ac530b756da2fff (diff) | |
| download | jancity-980858186149651df5543b6fc99a4f7db0cdd089.tar.gz | |
WIP
Diffstat (limited to 'src/input')
| -rw-r--r-- | src/input/inc/input.h | 2 | ||||
| -rw-r--r-- | src/input/src/input.c | 50 |
2 files changed, 32 insertions, 20 deletions
diff --git a/src/input/inc/input.h b/src/input/inc/input.h index 2dd401b..5780000 100644 --- a/src/input/inc/input.h +++ b/src/input/inc/input.h @@ -22,7 +22,7 @@ struct input void *user; unsigned char t; bool repeat; - struct keyboard_combo prev; + struct keyboard_input prev; }; void input_update(struct input *in, const union peripheral *p); diff --git a/src/input/src/input.c b/src/input/src/input.c index 26116c8..ee6d4b7 100644 --- a/src/input/src/input.c +++ b/src/input/src/input.c @@ -8,8 +8,7 @@ #include <stddef.h> #include <string.h> -static void send_input(struct input *const in, const struct keyboard *const k, - const enum keyboard_key key) +static void send_key(struct input *const in, const enum keyboard_key key) { if (key != KEYBOARD_KEY_NONE) { @@ -24,28 +23,44 @@ static void send_input(struct input *const in, const struct keyboard *const k, break; default: - { - const char ch = keyboard_to_char(k, key); - - if (isprint(ch)) - in->cb(ch, in->user); - } break; } } } +static void send_input(struct input *const in, + const struct keyboard_input *const ki) +{ + { + const struct keyboard_combo *const c = &ki->combo; + + for (size_t i = 0; i < sizeof c->keys / sizeof *c->keys; i++) + send_key(in, c->keys[i]); + } + + { + const struct keyboard_chars *const c = &ki->chars; + + for (size_t i = 0; i < sizeof c->c / sizeof *c->c; i++) + { + const char ch = c->c[i]; + + if (ch) + in->cb(ch, in->user); + } + } +} + static void update_keyboard(struct input *const in, const struct keyboard *const k) { - struct keyboard_combo c; + struct keyboard_input ki; - if (keyboard_any_justpressed(k, &c)) - for (size_t i = 0; i < sizeof c.keys / sizeof *c.keys; i++) - send_input(in, k, c.keys[i]); - else if (keyboard_any_pressed(k, &c)) + if (keyboard_any_justpressed(k, &ki)) + send_input(in, &ki); + else if (keyboard_any_pressed(k, &ki)) { - if (memcmp(&c, &in->prev, sizeof c)) + if (memcmp(&ki, &in->prev, sizeof ki)) { in->repeat = false; in->t = 0; @@ -61,15 +76,12 @@ static void update_keyboard(struct input *const in, } else if (++in->t >= SHORT_INTERVAL) { - for (size_t i = 0; - i < sizeof c.keys / sizeof *c.keys; i++) - send_input(in, k, c.keys[i]); - + send_input(in, &ki); in->t = 0; } } - in->prev = c; + in->prev = ki; } else { |
