| git.druid.rocks | index | militantprogrammer | astral_canvas | src/ | input/ | input.h |
src/input/input.h
#ifndef INPUT_H
#define INPUT_H
#include "event.h"
#include <stdbool.h>
#include <xkbcommon/xkbcommon.h>
#include <xkbcommon/xkbcommon-compose.h>
/*
* Shared xkbcommon state used by both backends to turn raw keycodes into
* keysyms, UTF-8, and MOD_* bits. context and the compose objects are created
* by input_xkb_init() from the process locale. keymap and state are
* replaced whenever the server sends a new keymap (X11 device change or
* Wayland wl_keyboard.keymap). compose is reset on keymap swap so a
* half-finished dead-key sequence cannot leak across layouts.
*/
typedef struct {
struct xkb_context *context; /* xkb library context; owns keymap compilation */
struct xkb_keymap *keymap; /* current layout; NULL until the first keymap arrives */
struct xkb_state *state; /* depressed/latched/locked mods + group */
struct xkb_compose_table *composeTable; /* locale dead-key / compose sequences; may be NULL */
struct xkb_compose_state *compose; /* in-flight compose sequence; NULL if table failed */
} InputXkb;
/* Build context + compose table from the locale. keymap/state still NULL. */
int inputXkbInit(InputXkb *input);
void inputXkbFinish(InputXkb *input);
/* Take ownership of keymap/state; reset compose. Unrefs the previous pair. */
void inputXkbSetKeymap(InputXkb *input, struct xkb_keymap *keymap, struct xkb_state *state);
/* MOD_* bitfield from the current xkb state. */
uint32_t inputModifiers(const InputXkb *input);
/* Fill KeyEvent (keysym, utf8, mods, name) for a press/release/repeat. */
void input_fill_key(const InputXkb *input, KeyEvent *event, xkb_keycode_t keyCode,
bool pressed, bool repeat);
/* Linux BTN_* → BUTTON_LEFT/MIDDLE/RIGHT/BACK/FORWARD, or 0. */
uint32_t linuxButtonToButton(uint32_t linuxCode);
#endif