2018-07-13 14:40:56 +02:00
|
|
|
/*
|
|
|
|
* This an unstable interface of wlroots. No guarantees are made regarding the
|
|
|
|
* future consistency of this API.
|
|
|
|
*/
|
|
|
|
#ifndef WLR_USE_UNSTABLE
|
|
|
|
#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features"
|
|
|
|
#endif
|
|
|
|
|
2017-09-23 10:26:01 +02:00
|
|
|
#ifndef WLR_TYPES_WLR_KEYBOARD_H
|
|
|
|
#define WLR_TYPES_WLR_KEYBOARD_H
|
|
|
|
|
2017-10-09 03:55:59 +02:00
|
|
|
#include <stdbool.h>
|
2018-02-12 21:29:23 +01:00
|
|
|
#include <stdint.h>
|
2019-07-27 10:53:54 +02:00
|
|
|
#include <wayland-server-core.h>
|
2020-10-21 17:21:23 +02:00
|
|
|
#include <wayland-server-protocol.h>
|
2022-01-28 19:55:28 +01:00
|
|
|
#include <wlr/types/wlr_input_device.h>
|
2017-09-24 20:12:56 +02:00
|
|
|
#include <xkbcommon/xkbcommon.h>
|
2017-06-20 00:41:02 +02:00
|
|
|
|
2017-10-02 20:21:47 +02:00
|
|
|
#define WLR_LED_COUNT 3
|
|
|
|
|
2017-10-02 19:23:30 +02:00
|
|
|
enum wlr_keyboard_led {
|
2020-10-31 23:05:39 +01:00
|
|
|
WLR_LED_NUM_LOCK = 1 << 0,
|
|
|
|
WLR_LED_CAPS_LOCK = 1 << 1,
|
|
|
|
WLR_LED_SCROLL_LOCK = 1 << 2,
|
2017-06-20 00:41:02 +02:00
|
|
|
};
|
|
|
|
|
2017-10-02 20:21:47 +02:00
|
|
|
#define WLR_MODIFIER_COUNT 8
|
|
|
|
|
2017-10-02 19:23:30 +02:00
|
|
|
enum wlr_keyboard_modifier {
|
2020-10-31 23:05:39 +01:00
|
|
|
WLR_MODIFIER_SHIFT = 1 << 0,
|
|
|
|
WLR_MODIFIER_CAPS = 1 << 1,
|
|
|
|
WLR_MODIFIER_CTRL = 1 << 2,
|
|
|
|
WLR_MODIFIER_ALT = 1 << 3,
|
|
|
|
WLR_MODIFIER_MOD2 = 1 << 4,
|
|
|
|
WLR_MODIFIER_MOD3 = 1 << 5,
|
|
|
|
WLR_MODIFIER_LOGO = 1 << 6,
|
|
|
|
WLR_MODIFIER_MOD5 = 1 << 7,
|
2017-10-02 19:23:30 +02:00
|
|
|
};
|
|
|
|
|
2017-11-05 17:09:00 +01:00
|
|
|
#define WLR_KEYBOARD_KEYS_CAP 32
|
|
|
|
|
2017-06-20 00:41:02 +02:00
|
|
|
struct wlr_keyboard_impl;
|
|
|
|
|
2018-01-05 13:00:50 +01:00
|
|
|
struct wlr_keyboard_modifiers {
|
|
|
|
xkb_mod_mask_t depressed;
|
|
|
|
xkb_mod_mask_t latched;
|
|
|
|
xkb_mod_mask_t locked;
|
|
|
|
xkb_mod_mask_t group;
|
|
|
|
};
|
|
|
|
|
2017-06-20 00:41:02 +02:00
|
|
|
struct wlr_keyboard {
|
2022-01-28 19:55:28 +01:00
|
|
|
struct wlr_input_device base;
|
|
|
|
|
2018-04-28 13:55:36 +02:00
|
|
|
const struct wlr_keyboard_impl *impl;
|
Introduce wlr_keyboard_group
A wlr_keyboard_group allows for multiple keyboard devices to be
combined into one logical keyboard. Each keyboard device can only be
added to one keyboard group. This helps with the situation where one
physical keyboard is exposed as multiple keyboard devices. It is up to
the compositors on how they group keyboards together, if at all.
Since a wlr_keyboard_group is one logical keyboard, the keys are a set.
This means that if a key is pressed on multiple keyboard devices, the
key event will only be emitted once, but the internal state will count
the number of devices that the key is pressed on. Likewise, the key
release will not be emitted until the key is released from all devices.
If the compositor wants access to which keys are pressed and released
on each keyboard device, the events for those devices can be listened
to, as they currently are, in addition to the group keyboard's events.
Also, all keyboard devices in the group must share the same keymap. If
the keymap's differ, the keyboard device will not be able to be added
to the group. Once in the group, if the keymap or effective layout for
one keyboard device changes, it will be synced to all keyboard devices
in the group. The repeat info and keyboard modifiers are also synced
2019-11-03 20:18:41 +01:00
|
|
|
struct wlr_keyboard_group *group;
|
2017-09-24 20:12:56 +02:00
|
|
|
|
2018-09-18 00:17:33 +02:00
|
|
|
char *keymap_string;
|
2017-09-24 20:12:56 +02:00
|
|
|
size_t keymap_size;
|
2021-08-07 13:48:04 +02:00
|
|
|
int keymap_fd;
|
2017-09-24 20:12:56 +02:00
|
|
|
struct xkb_keymap *keymap;
|
|
|
|
struct xkb_state *xkb_state;
|
2017-10-02 20:21:47 +02:00
|
|
|
xkb_led_index_t led_indexes[WLR_LED_COUNT];
|
|
|
|
xkb_mod_index_t mod_indexes[WLR_MODIFIER_COUNT];
|
2017-10-02 19:23:30 +02:00
|
|
|
|
2022-11-19 07:52:31 +01:00
|
|
|
uint32_t leds;
|
2017-11-05 17:09:00 +01:00
|
|
|
uint32_t keycodes[WLR_KEYBOARD_KEYS_CAP];
|
2017-12-28 00:58:43 +01:00
|
|
|
size_t num_keycodes;
|
2018-01-17 14:31:15 +01:00
|
|
|
struct wlr_keyboard_modifiers modifiers;
|
2017-06-20 00:41:02 +02:00
|
|
|
|
2017-12-08 17:03:05 +01:00
|
|
|
struct {
|
|
|
|
int32_t rate;
|
|
|
|
int32_t delay;
|
|
|
|
} repeat_info;
|
|
|
|
|
2017-06-20 00:41:02 +02:00
|
|
|
struct {
|
2018-05-26 17:32:45 +02:00
|
|
|
/**
|
2022-06-27 22:56:02 +02:00
|
|
|
* The `key` event signals with a struct wlr_keyboard_key_event that a
|
|
|
|
* key has been pressed or released on the keyboard. This event is
|
2018-05-26 17:32:45 +02:00
|
|
|
* emitted before the xkb state of the keyboard has been updated
|
|
|
|
* (including modifiers).
|
|
|
|
*/
|
2017-06-20 00:41:02 +02:00
|
|
|
struct wl_signal key;
|
2018-05-26 17:32:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The `modifiers` event signals that the modifier state of the
|
2022-05-24 18:46:59 +02:00
|
|
|
* struct wlr_keyboard has been updated. At this time, you can read the
|
|
|
|
* modifier state of the struct wlr_keyboard and handle the updated
|
|
|
|
* state by sending it to clients.
|
2018-05-26 17:32:45 +02:00
|
|
|
*/
|
2017-10-03 14:03:26 +02:00
|
|
|
struct wl_signal modifiers;
|
2017-09-24 20:12:56 +02:00
|
|
|
struct wl_signal keymap;
|
2017-12-08 17:03:05 +01:00
|
|
|
struct wl_signal repeat_info;
|
2017-06-20 00:41:02 +02:00
|
|
|
} events;
|
2017-08-11 20:23:53 +02:00
|
|
|
|
|
|
|
void *data;
|
2017-06-20 00:41:02 +02:00
|
|
|
};
|
|
|
|
|
2022-03-09 21:05:12 +01:00
|
|
|
struct wlr_keyboard_key_event {
|
2017-10-30 11:40:06 +01:00
|
|
|
uint32_t time_msec;
|
2017-06-20 00:41:02 +02:00
|
|
|
uint32_t keycode;
|
2018-06-03 14:18:57 +02:00
|
|
|
bool update_state; // if backend doesn't update modifiers on its own
|
2020-10-21 17:21:23 +02:00
|
|
|
enum wl_keyboard_key_state state;
|
2017-06-20 00:41:02 +02:00
|
|
|
};
|
|
|
|
|
2022-06-20 16:57:29 +02:00
|
|
|
/**
|
|
|
|
* Get a struct wlr_keyboard from a struct wlr_input_device.
|
|
|
|
*
|
|
|
|
* Asserts that the input device is a keyboard.
|
|
|
|
*/
|
|
|
|
struct wlr_keyboard *wlr_keyboard_from_input_device(
|
|
|
|
struct wlr_input_device *input_device);
|
|
|
|
|
2020-03-24 00:18:18 +01:00
|
|
|
bool wlr_keyboard_set_keymap(struct wlr_keyboard *kb,
|
2017-10-02 19:23:30 +02:00
|
|
|
struct xkb_keymap *keymap);
|
2020-05-08 04:15:26 +02:00
|
|
|
|
|
|
|
bool wlr_keyboard_keymaps_match(struct xkb_keymap *km1, struct xkb_keymap *km2);
|
|
|
|
|
2017-12-08 17:06:31 +01:00
|
|
|
/**
|
2022-12-14 17:09:48 +01:00
|
|
|
* Set the keyboard repeat info.
|
|
|
|
*
|
|
|
|
* rate is in key repeats/second and delay is in milliseconds.
|
|
|
|
*/
|
|
|
|
void wlr_keyboard_set_repeat_info(struct wlr_keyboard *kb, int32_t rate_hz,
|
|
|
|
int32_t delay_ms);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the LEDs on the device, if any.
|
|
|
|
*
|
|
|
|
* leds is a bitmask of enum wlr_keyboard_led.
|
|
|
|
*
|
|
|
|
* If the device doesn't have the provided LEDs, this function is a no-op.
|
2017-12-08 17:06:31 +01:00
|
|
|
*/
|
2017-10-02 20:21:47 +02:00
|
|
|
void wlr_keyboard_led_update(struct wlr_keyboard *keyboard, uint32_t leds);
|
2022-12-14 17:09:48 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the set of currently depressed or latched modifiers.
|
|
|
|
*
|
|
|
|
* A bitmask of enum wlr_keyboard_modifier is returned.
|
|
|
|
*/
|
2017-10-02 20:21:47 +02:00
|
|
|
uint32_t wlr_keyboard_get_modifiers(struct wlr_keyboard *keyboard);
|
2017-09-24 20:12:56 +02:00
|
|
|
|
2017-06-20 00:41:02 +02:00
|
|
|
#endif
|