From 7b8070f02c01f8eb74487c4e61acf98f5b076cfc Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Wed, 4 Sep 2024 14:24:07 +0200 Subject: [PATCH] jevent: conveniences for testing for keys --- include/justui/jevent.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/justui/jevent.h b/include/justui/jevent.h index 9893915..f204336 100644 --- a/include/justui/jevent.h +++ b/include/justui/jevent.h @@ -9,6 +9,7 @@ #include #include +#include /* jevent: GUI event @@ -49,4 +50,20 @@ typedef struct { } jevent; +/* Check if an event is a key press of the specified key with modifiers. */ +GINLINE static bool jevent_is_press_mods( + jevent e, int key, bool shift, bool alpha) { + return e.type == JWIDGET_KEY + && (e.key.type == KEYEV_DOWN || e.key.type == KEYEV_HOLD) + && e.key.key == key + && e.key.shift == shift + && e.key.alpha == alpha; +} + +#define jevent_is_press(E, KEY) jevent_is_press_mods(E, KEY, false, false) +#define jevent_is_shift_press(E, KEY) jevent_is_press_mods(E, KEY, true, false) +#define jevent_is_alpha_press(E, KEY) jevent_is_press_mods(E, KEY, false, true) +#define jevent_is_shift_alpha_press(E, KEY) \ + jevent_is_press_mods(E, KEY, true, true) + #endif /* _J_EVENT */