From 37c83d5c6de42c36f0cf46c602dbcd95b845a681 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Mon, 18 Dec 2017 09:59:59 -0500 Subject: [PATCH] misc keyboard fixes --- types/wlr_keyboard.c | 13 +++++++++++++ types/wlr_seat.c | 15 ++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index c494b45d..5da290f5 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -133,7 +133,11 @@ void wlr_keyboard_led_update(struct wlr_keyboard *kb, uint32_t leds) { void wlr_keyboard_set_keymap(struct wlr_keyboard *kb, struct xkb_keymap *keymap) { wlr_log(L_DEBUG, "Keymap set"); + if (kb->keymap) { + xkb_keymap_unref(kb->keymap); + } kb->keymap = keymap; + xkb_keymap_ref(keymap); assert(kb->xkb_state = xkb_state_new(kb->keymap)); const char *led_names[WLR_LED_COUNT] = { @@ -163,9 +167,18 @@ void wlr_keyboard_set_keymap(struct wlr_keyboard *kb, char *keymap_str = xkb_keymap_get_as_string(kb->keymap, XKB_KEYMAP_FORMAT_TEXT_V1); kb->keymap_size = strlen(keymap_str) + 1; + if (kb->keymap_fd) { + close(kb->keymap_fd); + } kb->keymap_fd = os_create_anonymous_file(kb->keymap_size); + if (kb->keymap_fd < 0) { + wlr_log(L_ERROR, "creating a keymap file for %lu bytes failed", kb->keymap_size); + } void *ptr = mmap(NULL, kb->keymap_size, PROT_READ | PROT_WRITE, MAP_SHARED, kb->keymap_fd, 0); + if (ptr == (void*)-1) { + wlr_log(L_ERROR, "failed to mmap() %lu bytes", kb->keymap_size); + } strcpy(ptr, keymap_str); free(keymap_str); diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 2a931241..25b1fcd4 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -710,8 +710,11 @@ static void handle_keyboard_keymap(struct wl_listener *listener, void *data) { struct wlr_seat_keyboard_state *state = wl_container_of(listener, state, keyboard_keymap); struct wlr_seat_client *client; - wl_list_for_each(client, &state->seat->clients, link) { - seat_client_send_keymap(client, state->keyboard); + struct wlr_keyboard *keyboard = data; + if (keyboard == state->keyboard) { + wl_list_for_each(client, &state->seat->clients, link) { + seat_client_send_keymap(client, state->keyboard); + } } } @@ -736,7 +739,8 @@ void wlr_seat_set_keyboard(struct wlr_seat *seat, // TODO call this on device key event before the event reaches the // compositor and set a pending keyboard and then send the new keyboard // state on the next keyboard notify event. - if (seat->keyboard_state.keyboard == device->keyboard) { + struct wlr_keyboard *keyboard = (device ? device->keyboard : NULL); + if (seat->keyboard_state.keyboard == keyboard) { return; } @@ -747,7 +751,7 @@ void wlr_seat_set_keyboard(struct wlr_seat *seat, seat->keyboard_state.keyboard = NULL; } - if (device) { + if (keyboard) { assert(device->type == WLR_INPUT_DEVICE_KEYBOARD); wl_signal_add(&device->events.destroy, @@ -767,8 +771,9 @@ void wlr_seat_set_keyboard(struct wlr_seat *seat, seat_client_send_repeat_info(client, device->keyboard); } - seat->keyboard_state.keyboard = device->keyboard; } + + seat->keyboard_state.keyboard = keyboard; } void wlr_seat_keyboard_start_grab(struct wlr_seat *wlr_seat,