Add modifiers signal, remove wlr_keyboard_update_modifiers
This commit is contained in:
parent
d71344bcdd
commit
521e893528
|
@ -155,11 +155,7 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard,
|
||||||
static void keyboard_handle_modifiers(void *data, struct wl_keyboard *wl_keyboard,
|
static void keyboard_handle_modifiers(void *data, struct wl_keyboard *wl_keyboard,
|
||||||
uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched,
|
uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched,
|
||||||
uint32_t mods_locked, uint32_t group) {
|
uint32_t mods_locked, uint32_t group) {
|
||||||
struct wlr_input_device *dev = data;
|
|
||||||
assert(dev && dev->keyboard);
|
|
||||||
|
|
||||||
wlr_keyboard_update_modifiers(dev->keyboard, mods_depressed, mods_latched,
|
|
||||||
mods_locked, group);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void keyboard_handle_repeat_info(void *data, struct wl_keyboard *wl_keyboard,
|
static void keyboard_handle_repeat_info(void *data, struct wl_keyboard *wl_keyboard,
|
||||||
|
|
|
@ -13,8 +13,5 @@ void wlr_keyboard_init(struct wlr_keyboard *keyboard, struct wlr_keyboard_impl *
|
||||||
void wlr_keyboard_destroy(struct wlr_keyboard *keyboard);
|
void wlr_keyboard_destroy(struct wlr_keyboard *keyboard);
|
||||||
void wlr_keyboard_update_state(struct wlr_keyboard *keyboard,
|
void wlr_keyboard_update_state(struct wlr_keyboard *keyboard,
|
||||||
struct wlr_event_keyboard_key *event);
|
struct wlr_event_keyboard_key *event);
|
||||||
void wlr_keyboard_update_modifiers(struct wlr_keyboard *keyboard,
|
|
||||||
uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked,
|
|
||||||
uint32_t group);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -49,6 +49,7 @@ struct wlr_keyboard {
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
struct wl_signal key;
|
struct wl_signal key;
|
||||||
|
struct wl_signal modifiers;
|
||||||
struct wl_signal keymap;
|
struct wl_signal keymap;
|
||||||
} events;
|
} events;
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ struct wlr_seat_keyboard {
|
||||||
struct wlr_seat *seat;
|
struct wlr_seat *seat;
|
||||||
struct wlr_keyboard *keyboard;
|
struct wlr_keyboard *keyboard;
|
||||||
struct wl_listener key;
|
struct wl_listener key;
|
||||||
|
struct wl_listener modifiers;
|
||||||
struct wl_listener keymap;
|
struct wl_listener keymap;
|
||||||
struct wl_listener destroy;
|
struct wl_listener destroy;
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
|
|
|
@ -21,28 +21,7 @@ static void keyboard_led_update(struct wlr_keyboard *keyboard) {
|
||||||
wlr_keyboard_led_update(keyboard, leds);
|
wlr_keyboard_led_update(keyboard, leds);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wlr_keyboard_update_modifiers(struct wlr_keyboard *keyboard,
|
static void keyboard_modifier_update(struct wlr_keyboard *keyboard) {
|
||||||
uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked,
|
|
||||||
uint32_t group) {
|
|
||||||
if (mods_depressed == keyboard->modifiers.depressed &&
|
|
||||||
mods_latched == keyboard->modifiers.latched &&
|
|
||||||
mods_locked == keyboard->modifiers.locked &&
|
|
||||||
group == keyboard->modifiers.group) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
keyboard->modifiers.depressed = mods_depressed;
|
|
||||||
keyboard->modifiers.latched = mods_latched;
|
|
||||||
keyboard->modifiers.locked = mods_locked;
|
|
||||||
keyboard->modifiers.group = group;
|
|
||||||
}
|
|
||||||
|
|
||||||
void wlr_keyboard_update_state(struct wlr_keyboard *keyboard,
|
|
||||||
struct wlr_event_keyboard_key *event) {
|
|
||||||
uint32_t keycode = event->keycode + 8;
|
|
||||||
xkb_state_update_key(keyboard->xkb_state, keycode,
|
|
||||||
event->state == WLR_KEY_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP);
|
|
||||||
keyboard_led_update(keyboard);
|
|
||||||
|
|
||||||
xkb_mod_mask_t depressed = xkb_state_serialize_mods(keyboard->xkb_state,
|
xkb_mod_mask_t depressed = xkb_state_serialize_mods(keyboard->xkb_state,
|
||||||
XKB_STATE_MODS_DEPRESSED);
|
XKB_STATE_MODS_DEPRESSED);
|
||||||
xkb_mod_mask_t latched = xkb_state_serialize_mods(keyboard->xkb_state,
|
xkb_mod_mask_t latched = xkb_state_serialize_mods(keyboard->xkb_state,
|
||||||
|
@ -51,8 +30,28 @@ void wlr_keyboard_update_state(struct wlr_keyboard *keyboard,
|
||||||
XKB_STATE_MODS_LOCKED);
|
XKB_STATE_MODS_LOCKED);
|
||||||
xkb_mod_mask_t group = xkb_state_serialize_layout(keyboard->xkb_state,
|
xkb_mod_mask_t group = xkb_state_serialize_layout(keyboard->xkb_state,
|
||||||
XKB_STATE_LAYOUT_EFFECTIVE);
|
XKB_STATE_LAYOUT_EFFECTIVE);
|
||||||
wlr_keyboard_update_modifiers(keyboard, depressed, latched, locked, group);
|
if (depressed == keyboard->modifiers.depressed &&
|
||||||
|
latched == keyboard->modifiers.latched &&
|
||||||
|
locked == keyboard->modifiers.locked &&
|
||||||
|
group == keyboard->modifiers.group) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
keyboard->modifiers.depressed = depressed;
|
||||||
|
keyboard->modifiers.latched = latched;
|
||||||
|
keyboard->modifiers.locked = locked;
|
||||||
|
keyboard->modifiers.group = group;
|
||||||
|
|
||||||
|
wl_signal_emit(&keyboard->events.modifiers, keyboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wlr_keyboard_update_state(struct wlr_keyboard *keyboard,
|
||||||
|
struct wlr_event_keyboard_key *event) {
|
||||||
|
uint32_t keycode = event->keycode + 8;
|
||||||
|
xkb_state_update_key(keyboard->xkb_state, keycode,
|
||||||
|
event->state == WLR_KEY_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP);
|
||||||
|
keyboard_led_update(keyboard);
|
||||||
|
keyboard_modifier_update(keyboard);
|
||||||
wl_signal_emit(&keyboard->events.key, event);
|
wl_signal_emit(&keyboard->events.key, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +59,7 @@ void wlr_keyboard_init(struct wlr_keyboard *kb,
|
||||||
struct wlr_keyboard_impl *impl) {
|
struct wlr_keyboard_impl *impl) {
|
||||||
kb->impl = impl;
|
kb->impl = impl;
|
||||||
wl_signal_init(&kb->events.key);
|
wl_signal_init(&kb->events.key);
|
||||||
|
wl_signal_init(&kb->events.modifiers);
|
||||||
wl_signal_init(&kb->events.keymap);
|
wl_signal_init(&kb->events.keymap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -376,39 +376,61 @@ void wlr_seat_pointer_send_axis(struct wlr_seat *wlr_seat, uint32_t time,
|
||||||
wl_pointer_send_frame(pointer);
|
wl_pointer_send_frame(pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void keyboard_switch_seat_keyboard(struct wlr_seat_handle *handle,
|
||||||
|
struct wlr_seat_keyboard *seat_kb) {
|
||||||
|
if (handle->seat_keyboard == seat_kb) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: We should probably lift all of the keys set by the other
|
||||||
|
// keyboard
|
||||||
|
wl_keyboard_send_keymap(handle->keyboard,
|
||||||
|
WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, seat_kb->keyboard->keymap_fd,
|
||||||
|
seat_kb->keyboard->keymap_size);
|
||||||
|
|
||||||
|
if (wl_resource_get_version(handle->keyboard) >= 2) {
|
||||||
|
// TODO: Make this better
|
||||||
|
wl_keyboard_send_repeat_info(handle->keyboard, 25, 600);
|
||||||
|
}
|
||||||
|
handle->seat_keyboard = seat_kb;
|
||||||
|
}
|
||||||
|
|
||||||
static void keyboard_key_notify(struct wl_listener *listener, void *data) {
|
static void keyboard_key_notify(struct wl_listener *listener, void *data) {
|
||||||
struct wlr_seat_keyboard *seat_kb = wl_container_of(
|
struct wlr_seat_keyboard *seat_kb = wl_container_of(listener, seat_kb, key);
|
||||||
listener, seat_kb, key);
|
|
||||||
struct wlr_seat *seat = seat_kb->seat;
|
struct wlr_seat *seat = seat_kb->seat;
|
||||||
struct wlr_seat_handle *handle = seat->keyboard_state.focused_handle;
|
struct wlr_seat_handle *handle = seat->keyboard_state.focused_handle;
|
||||||
if (!handle || !handle->keyboard) {
|
if (!handle || !handle->keyboard) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
struct wlr_keyboard *keyboard = seat_kb->keyboard;
|
|
||||||
|
keyboard_switch_seat_keyboard(handle, seat_kb);
|
||||||
|
|
||||||
struct wlr_event_keyboard_key *event = data;
|
struct wlr_event_keyboard_key *event = data;
|
||||||
enum wlr_key_state key_state = event->state;
|
enum wlr_key_state key_state = event->state;
|
||||||
if (handle->seat_keyboard != seat_kb) {
|
|
||||||
// TODO: We should probably lift all of the keys set by the other
|
|
||||||
// keyboard
|
|
||||||
wl_keyboard_send_keymap(handle->keyboard,
|
|
||||||
WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
|
|
||||||
seat_kb->keyboard->keymap_fd,
|
|
||||||
seat_kb->keyboard->keymap_size);
|
|
||||||
|
|
||||||
if (wl_resource_get_version(handle->keyboard) >= 2) {
|
uint32_t key_serial = wl_display_next_serial(seat->display);
|
||||||
// TODO: Make this better
|
wl_keyboard_send_key(handle->keyboard, key_serial,
|
||||||
wl_keyboard_send_repeat_info(handle->keyboard, 25, 600);
|
(uint32_t)event->time_usec, event->keycode, key_state);
|
||||||
}
|
}
|
||||||
handle->seat_keyboard = seat_kb;
|
|
||||||
|
static void keyboard_modifiers_notify(struct wl_listener *listener,
|
||||||
|
void *data) {
|
||||||
|
struct wlr_seat_keyboard *seat_kb = wl_container_of(listener, seat_kb,
|
||||||
|
modifiers);
|
||||||
|
struct wlr_seat *seat = seat_kb->seat;
|
||||||
|
struct wlr_seat_handle *handle = seat->keyboard_state.focused_handle;
|
||||||
|
if (!handle || !handle->keyboard) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keyboard_switch_seat_keyboard(handle, seat_kb);
|
||||||
|
|
||||||
|
struct wlr_keyboard *keyboard = seat_kb->keyboard;
|
||||||
|
|
||||||
uint32_t modifiers_serial = wl_display_next_serial(seat->display);
|
uint32_t modifiers_serial = wl_display_next_serial(seat->display);
|
||||||
wl_keyboard_send_modifiers(handle->keyboard, modifiers_serial,
|
wl_keyboard_send_modifiers(handle->keyboard, modifiers_serial,
|
||||||
keyboard->modifiers.depressed, keyboard->modifiers.latched,
|
keyboard->modifiers.depressed, keyboard->modifiers.latched,
|
||||||
keyboard->modifiers.locked, keyboard->modifiers.group);
|
keyboard->modifiers.locked, keyboard->modifiers.group);
|
||||||
uint32_t key_serial = wl_display_next_serial(seat->display);
|
|
||||||
wl_keyboard_send_key(handle->keyboard, key_serial,
|
|
||||||
(uint32_t)event->time_usec, event->keycode, key_state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void keyboard_keymap_notify(struct wl_listener *listener, void *data) {
|
static void keyboard_keymap_notify(struct wl_listener *listener, void *data) {
|
||||||
|
@ -434,6 +456,9 @@ void wlr_seat_attach_keyboard(struct wlr_seat *seat,
|
||||||
wl_list_init(&seat_kb->key.link);
|
wl_list_init(&seat_kb->key.link);
|
||||||
seat_kb->key.notify = keyboard_key_notify;
|
seat_kb->key.notify = keyboard_key_notify;
|
||||||
wl_signal_add(&kb->events.key, &seat_kb->key);
|
wl_signal_add(&kb->events.key, &seat_kb->key);
|
||||||
|
wl_list_init(&seat_kb->modifiers.link);
|
||||||
|
seat_kb->modifiers.notify = keyboard_modifiers_notify;
|
||||||
|
wl_signal_add(&kb->events.modifiers, &seat_kb->modifiers);
|
||||||
wl_list_init(&seat_kb->keymap.link);
|
wl_list_init(&seat_kb->keymap.link);
|
||||||
seat_kb->keymap.notify = keyboard_keymap_notify;
|
seat_kb->keymap.notify = keyboard_keymap_notify;
|
||||||
wl_signal_add(&kb->events.keymap, &seat_kb->keymap);
|
wl_signal_add(&kb->events.keymap, &seat_kb->keymap);
|
||||||
|
@ -450,6 +475,7 @@ void wlr_seat_detach_keyboard(struct wlr_seat *seat, struct wlr_keyboard *kb) {
|
||||||
if (seat_kb->keyboard == kb) {
|
if (seat_kb->keyboard == kb) {
|
||||||
wl_list_remove(&seat_kb->link);
|
wl_list_remove(&seat_kb->link);
|
||||||
wl_list_remove(&seat_kb->key.link);
|
wl_list_remove(&seat_kb->key.link);
|
||||||
|
wl_list_remove(&seat_kb->modifiers.link);
|
||||||
wl_list_remove(&seat_kb->keymap.link);
|
wl_list_remove(&seat_kb->keymap.link);
|
||||||
wl_list_remove(&seat_kb->destroy.link);
|
wl_list_remove(&seat_kb->destroy.link);
|
||||||
free(seat_kb);
|
free(seat_kb);
|
||||||
|
|
Loading…
Reference in New Issue