diff --git a/include/wlr/types/wlr_keyboard.h b/include/wlr/types/wlr_keyboard.h index 90464936..23ca006a 100644 --- a/include/wlr/types/wlr_keyboard.h +++ b/include/wlr/types/wlr_keyboard.h @@ -115,6 +115,23 @@ bool wlr_keyboard_set_keymap(struct wlr_keyboard *kb, bool wlr_keyboard_keymaps_match(struct xkb_keymap *km1, struct xkb_keymap *km2); +/** + * Interpret pointer button key symbols. + * + * Returns a button code (BTN_*) if the key symbol is a pointer button + * (XKB_KEY_Pointer_Button*), 0 otherwise. + */ +uint32_t wlr_keyboard_keysym_to_pointer_button(xkb_keysym_t keysym); + +/** + * Interpret pointer motion key symbols. + * + * Sets dx and dy to horizontal and vertical motion deltas (0, 1 or -1) if the + * key symbol is a pointer motion (XKB_KEY_Pointer_*). Otherwise, sets both dx + * and dy to 0. + */ +void wlr_keyboard_keysym_to_pointer_motion(xkb_keysym_t keysym, int *dx, int *dy); + /** * Set the keyboard repeat info. * diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index 366f4218..81d45a62 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -304,3 +305,46 @@ bool wlr_keyboard_keymaps_match(struct xkb_keymap *km1, free(km2_str); return result; } + +uint32_t wlr_keyboard_keysym_to_pointer_button(xkb_keysym_t keysym) { + switch (keysym) { + case XKB_KEY_Pointer_Button1: + return BTN_LEFT; + case XKB_KEY_Pointer_Button2: + return BTN_MIDDLE; + case XKB_KEY_Pointer_Button3: + return BTN_RIGHT; + default: + return 0; + } +} + +void wlr_keyboard_keysym_to_pointer_motion(xkb_keysym_t keysym, int *dx, int *dy) { + *dx = 0; + switch (keysym) { + case XKB_KEY_Pointer_Right: + case XKB_KEY_Pointer_DownRight: + case XKB_KEY_Pointer_UpRight: + *dx = 1; + break; + case XKB_KEY_Pointer_Left: + case XKB_KEY_Pointer_DownLeft: + case XKB_KEY_Pointer_UpLeft: + *dx = -1; + break; + } + + *dy = 0; + switch (keysym) { + case XKB_KEY_Pointer_Down: + case XKB_KEY_Pointer_DownLeft: + case XKB_KEY_Pointer_DownRight: + *dy = 1; + break; + case XKB_KEY_Pointer_Up: + case XKB_KEY_Pointer_UpLeft: + case XKB_KEY_Pointer_UpRight: + *dy = -1; + break; + } +}