jevent: conveniences for testing for keys

This commit is contained in:
Lephenixnoir 2024-09-04 14:24:07 +02:00
parent f32dcc69ce
commit 7b8070f02c
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495

View file

@ -9,6 +9,7 @@
#include <justui/jwidget.h>
#include <gint/keyboard.h>
#include <gint/defs/attributes.h>
/* 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 */