mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-12-15 08:56:26 -05:00
backend/libinput: add assertions
This commit is contained in:
parent
bc34486c04
commit
7bcf0d9599
6 changed files with 94 additions and 52 deletions
|
|
@ -12,35 +12,43 @@ struct wlr_libinput_keyboard {
|
|||
struct libinput_device *libinput_dev;
|
||||
};
|
||||
|
||||
static const struct wlr_keyboard_impl impl;
|
||||
|
||||
static struct wlr_libinput_keyboard *get_libinput_keyboard_from_keyboard(
|
||||
struct wlr_keyboard *wlr_kb) {
|
||||
assert(wlr_kb->impl == &impl);
|
||||
return (struct wlr_libinput_keyboard *)wlr_kb;
|
||||
}
|
||||
|
||||
static void keyboard_set_leds(struct wlr_keyboard *wlr_kb, uint32_t leds) {
|
||||
struct wlr_libinput_keyboard *wlr_libinput_kb =
|
||||
(struct wlr_libinput_keyboard *)wlr_kb;
|
||||
libinput_device_led_update(wlr_libinput_kb->libinput_dev, leds);
|
||||
struct wlr_libinput_keyboard *kb =
|
||||
get_libinput_keyboard_from_keyboard(wlr_kb);
|
||||
libinput_device_led_update(kb->libinput_dev, leds);
|
||||
}
|
||||
|
||||
static void keyboard_destroy(struct wlr_keyboard *wlr_kb) {
|
||||
struct wlr_libinput_keyboard *wlr_libinput_kb =
|
||||
(struct wlr_libinput_keyboard *)wlr_kb;
|
||||
libinput_device_unref(wlr_libinput_kb->libinput_dev);
|
||||
free(wlr_libinput_kb);
|
||||
struct wlr_libinput_keyboard *kb =
|
||||
get_libinput_keyboard_from_keyboard(wlr_kb);
|
||||
libinput_device_unref(kb->libinput_dev);
|
||||
free(kb);
|
||||
}
|
||||
|
||||
struct wlr_keyboard_impl impl = {
|
||||
static const struct wlr_keyboard_impl impl = {
|
||||
.destroy = keyboard_destroy,
|
||||
.led_update = keyboard_set_leds
|
||||
};
|
||||
|
||||
struct wlr_keyboard *create_libinput_keyboard(
|
||||
struct libinput_device *libinput_dev) {
|
||||
assert(libinput_dev);
|
||||
struct wlr_libinput_keyboard *wlr_libinput_kb;
|
||||
if (!(wlr_libinput_kb= calloc(1, sizeof(struct wlr_libinput_keyboard)))) {
|
||||
struct wlr_libinput_keyboard *kb =
|
||||
calloc(1, sizeof(struct wlr_libinput_keyboard));
|
||||
if (kb == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
wlr_libinput_kb->libinput_dev = libinput_dev;
|
||||
kb->libinput_dev = libinput_dev;
|
||||
libinput_device_ref(libinput_dev);
|
||||
libinput_device_led_update(libinput_dev, 0);
|
||||
struct wlr_keyboard *wlr_kb = &wlr_libinput_kb->wlr_keyboard;
|
||||
struct wlr_keyboard *wlr_kb = &kb->wlr_keyboard;
|
||||
wlr_keyboard_init(wlr_kb, &impl);
|
||||
return wlr_kb;
|
||||
}
|
||||
|
|
@ -50,7 +58,8 @@ void handle_keyboard_key(struct libinput_event *event,
|
|||
struct wlr_input_device *wlr_dev =
|
||||
get_appropriate_device(WLR_INPUT_DEVICE_KEYBOARD, libinput_dev);
|
||||
if (!wlr_dev) {
|
||||
wlr_log(WLR_DEBUG, "Got a keyboard event for a device with no keyboards?");
|
||||
wlr_log(WLR_DEBUG,
|
||||
"Got a keyboard event for a device with no keyboards?");
|
||||
return;
|
||||
}
|
||||
struct libinput_event_keyboard *kbevent =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue