mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-23 02:19:49 +01:00
Merge pull request #221 from versusvoid/wayland-xkb_state_update_mask
Use xkb_state_update_mask() with Wayland backend
This commit is contained in:
commit
08ccc7f653
6 changed files with 29 additions and 9 deletions
|
@ -67,5 +67,6 @@ void handle_keyboard_key(struct libinput_event *event,
|
|||
wlr_event.state = WLR_KEY_PRESSED;
|
||||
break;
|
||||
}
|
||||
wlr_keyboard_update_state(wlr_dev->keyboard, &wlr_event);
|
||||
wlr_event.update_state = true;
|
||||
wlr_keyboard_notify_key(wlr_dev->keyboard, &wlr_event);
|
||||
}
|
||||
|
|
|
@ -149,13 +149,16 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard,
|
|||
wlr_event.state = state;
|
||||
wlr_event.time_sec = time / 1000;
|
||||
wlr_event.time_usec = time * 1000;
|
||||
wlr_keyboard_update_state(dev->keyboard, &wlr_event);
|
||||
wlr_keyboard_notify_key(dev->keyboard, &wlr_event);
|
||||
}
|
||||
|
||||
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_notify_modifiers(dev->keyboard, mods_depressed, mods_latched,
|
||||
mods_locked, group);
|
||||
}
|
||||
|
||||
static void keyboard_handle_repeat_info(void *data, struct wl_keyboard *wl_keyboard,
|
||||
|
|
|
@ -51,9 +51,11 @@ static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *e
|
|||
.keycode = ev->detail - 8,
|
||||
.state = event->response_type == XCB_KEY_PRESS ?
|
||||
WLR_KEY_PRESSED : WLR_KEY_RELEASED,
|
||||
.update_state = true,
|
||||
};
|
||||
|
||||
wl_signal_emit(&x11->keyboard.events.key, &key);
|
||||
// TODO use xcb-xkb for more precise modifiers state?
|
||||
wlr_keyboard_notify_key(&x11->keyboard, &key);
|
||||
x11->time = ev->time;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,10 @@ struct wlr_keyboard_impl {
|
|||
|
||||
void wlr_keyboard_init(struct wlr_keyboard *keyboard, struct wlr_keyboard_impl *impl);
|
||||
void wlr_keyboard_destroy(struct wlr_keyboard *keyboard);
|
||||
void wlr_keyboard_update_state(struct wlr_keyboard *keyboard,
|
||||
void wlr_keyboard_notify_key(struct wlr_keyboard *keyboard,
|
||||
struct wlr_event_keyboard_key *event);
|
||||
void wlr_keyboard_notify_modifiers(struct wlr_keyboard *keyboard,
|
||||
uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked,
|
||||
uint32_t group);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -65,6 +65,7 @@ struct wlr_event_keyboard_key {
|
|||
uint32_t time_sec;
|
||||
uint64_t time_usec;
|
||||
uint32_t keycode;
|
||||
bool update_state;
|
||||
enum wlr_key_state state;
|
||||
};
|
||||
|
||||
|
|
|
@ -45,11 +45,21 @@ static void keyboard_modifier_update(struct wlr_keyboard *keyboard) {
|
|||
wl_signal_emit(&keyboard->events.modifiers, keyboard);
|
||||
}
|
||||
|
||||
void wlr_keyboard_update_state(struct wlr_keyboard *keyboard,
|
||||
void wlr_keyboard_notify_modifiers(struct wlr_keyboard *keyboard,
|
||||
uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked,
|
||||
uint32_t group) {
|
||||
xkb_state_update_mask(keyboard->xkb_state, mods_depressed, mods_latched,
|
||||
mods_locked, 0, 0, group);
|
||||
keyboard_modifier_update(keyboard);
|
||||
}
|
||||
|
||||
void wlr_keyboard_notify_key(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);
|
||||
if (event->update_state) {
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue