Add modifiers signal, remove wlr_keyboard_update_modifiers

master
emersion 7 years ago
parent d71344bcdd
commit 521e893528
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

@ -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,
uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched,
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,

@ -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_update_state(struct wlr_keyboard *keyboard,
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

@ -49,6 +49,7 @@ struct wlr_keyboard {
struct {
struct wl_signal key;
struct wl_signal modifiers;
struct wl_signal keymap;
} events;

@ -37,6 +37,7 @@ struct wlr_seat_keyboard {
struct wlr_seat *seat;
struct wlr_keyboard *keyboard;
struct wl_listener key;
struct wl_listener modifiers;
struct wl_listener keymap;
struct wl_listener destroy;
struct wl_list link;

@ -21,19 +21,28 @@ static void keyboard_led_update(struct wlr_keyboard *keyboard) {
wlr_keyboard_led_update(keyboard, leds);
}
void wlr_keyboard_update_modifiers(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 &&
static void keyboard_modifier_update(struct wlr_keyboard *keyboard) {
xkb_mod_mask_t depressed = xkb_state_serialize_mods(keyboard->xkb_state,
XKB_STATE_MODS_DEPRESSED);
xkb_mod_mask_t latched = xkb_state_serialize_mods(keyboard->xkb_state,
XKB_STATE_MODS_LATCHED);
xkb_mod_mask_t locked = xkb_state_serialize_mods(keyboard->xkb_state,
XKB_STATE_MODS_LOCKED);
xkb_mod_mask_t group = xkb_state_serialize_layout(keyboard->xkb_state,
XKB_STATE_LAYOUT_EFFECTIVE);
if (depressed == keyboard->modifiers.depressed &&
latched == keyboard->modifiers.latched &&
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.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,
@ -42,17 +51,7 @@ void wlr_keyboard_update_state(struct wlr_keyboard *keyboard,
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_STATE_MODS_DEPRESSED);
xkb_mod_mask_t latched = xkb_state_serialize_mods(keyboard->xkb_state,
XKB_STATE_MODS_LATCHED);
xkb_mod_mask_t locked = xkb_state_serialize_mods(keyboard->xkb_state,
XKB_STATE_MODS_LOCKED);
xkb_mod_mask_t group = xkb_state_serialize_layout(keyboard->xkb_state,
XKB_STATE_LAYOUT_EFFECTIVE);
wlr_keyboard_update_modifiers(keyboard, depressed, latched, locked, group);
keyboard_modifier_update(keyboard);
wl_signal_emit(&keyboard->events.key, event);
}
@ -60,6 +59,7 @@ void wlr_keyboard_init(struct wlr_keyboard *kb,
struct wlr_keyboard_impl *impl) {
kb->impl = impl;
wl_signal_init(&kb->events.key);
wl_signal_init(&kb->events.modifiers);
wl_signal_init(&kb->events.keymap);
}

@ -376,23 +376,16 @@ void wlr_seat_pointer_send_axis(struct wlr_seat *wlr_seat, uint32_t time,
wl_pointer_send_frame(pointer);
}
static void keyboard_key_notify(struct wl_listener *listener, void *data) {
struct wlr_seat_keyboard *seat_kb = wl_container_of(
listener, seat_kb, key);
struct wlr_seat *seat = seat_kb->seat;
struct wlr_seat_handle *handle = seat->keyboard_state.focused_handle;
if (!handle || !handle->keyboard) {
static void keyboard_switch_seat_keyboard(struct wlr_seat_handle *handle,
struct wlr_seat_keyboard *seat_kb) {
if (handle->seat_keyboard == seat_kb) {
return;
}
struct wlr_keyboard *keyboard = seat_kb->keyboard;
struct wlr_event_keyboard_key *event = data;
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,
WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, seat_kb->keyboard->keymap_fd,
seat_kb->keyboard->keymap_size);
if (wl_resource_get_version(handle->keyboard) >= 2) {
@ -400,15 +393,44 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) {
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) {
struct wlr_seat_keyboard *seat_kb = wl_container_of(listener, seat_kb, key);
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_event_keyboard_key *event = data;
enum wlr_key_state key_state = event->state;
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_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);
wl_keyboard_send_modifiers(handle->keyboard, modifiers_serial,
keyboard->modifiers.depressed, keyboard->modifiers.latched,
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) {
@ -434,6 +456,9 @@ void wlr_seat_attach_keyboard(struct wlr_seat *seat,
wl_list_init(&seat_kb->key.link);
seat_kb->key.notify = keyboard_key_notify;
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);
seat_kb->keymap.notify = keyboard_keymap_notify;
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) {
wl_list_remove(&seat_kb->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->destroy.link);
free(seat_kb);

Loading…
Cancel
Save