diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-09-20 12:34:35 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-09-20 13:52:14 +0200 |
| commit | 14df82ee4db71509f4ec4968df439d4659ca1ac3 (patch) | |
| tree | a1e210e2f553f758bd568d724fa84e99853dae22 /src/input/inc | |
| parent | a01b22de747de67adfaa1e8ba221c94588963163 (diff) | |
| download | jancity-14df82ee4db71509f4ec4968df439d4659ca1ac3.tar.gz | |
Implement input component
It is required to redirect keyboard input (both physical or not) when
a GUI line edit is focused. This means other components cannot be
activated on key presses.
Therefore, this new component is meant as a higher-level abstraction
compared to the `keyboard`/`pad`/`mouse` components, which:
- Implements the same APIs provided by `keyboard`, `mouse` and `pad`.
- Returns the same results as the APIs above if no GUI element is
focused, no input otherwise.
Note: replacing calls to `keyboard`/`pad`/`mouse` with `input` will be
implemented in a future commit.
Diffstat (limited to 'src/input/inc')
| -rw-r--r-- | src/input/inc/input.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/input/inc/input.h b/src/input/inc/input.h new file mode 100644 index 0000000..2dd401b --- /dev/null +++ b/src/input/inc/input.h @@ -0,0 +1,56 @@ +#ifndef INPUT_H +#define INPUT_H + +#include <keyboard.h> +#include <mouse.h> +#include <pad.h> +#include <peripheral.h> +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef void (*input_ch)(char ch, void *user); +typedef void (*input_erase)(void *user); + +struct input +{ + input_ch cb; + input_erase erase; + void *user; + unsigned char t; + bool repeat; + struct keyboard_combo prev; +}; + +void input_update(struct input *in, const union peripheral *p); +int input_render(const struct input *in, const union peripheral *p); +bool input_keyboard_justpressed(const struct input *in, + const struct keyboard *k, + const struct keyboard_combo *c); +bool input_keyboard_pressed(const struct input *in, + const struct keyboard *k, + const struct keyboard_combo *c); +bool input_keyboard_justreleased(const struct input *in, + const struct keyboard *k, + const struct keyboard_combo *c); +bool input_pad_pressed(const struct input *in, const struct pad *p, + enum pad_key k); +bool input_pad_justpressed(const struct input *in, const struct pad *p, + enum pad_key k); +bool input_pad_released(const struct input *in, const struct pad *p, + enum pad_key k); +bool input_mouse_pressed(const struct input *in, const struct mouse *m, + enum mouse_button b); +bool input_mouse_justpressed(const struct input *in, const struct mouse *m, + enum mouse_button b); +bool input_mouse_justreleased(const struct input *in, const struct mouse *m, + enum mouse_button b); + +#ifdef __cplusplus +} +#endif + +#endif /* INPUT_H */ |
