diff options
author | Simon Ser <contact@emersion.fr> | 2021-08-07 13:48:49 +0200 |
---|---|---|
committer | Kenny Levinsen <kl@kl.wtf> | 2021-09-05 22:06:25 +0200 |
commit | d290b13871fa18dcad6cd90d9ee93e7205742124 (patch) | |
tree | 11fa6a3884c3110b5afa39099a7caee48c34a6d1 | |
parent | 62924cc52385357f9c865379ee9883107d0f7d63 (diff) |
seat: avoid copying the keymap for each client
We can just send a read-only file descriptor instead.
-rw-r--r-- | types/seat/wlr_seat_keyboard.c | 35 |
1 files changed, 2 insertions, 33 deletions
diff --git a/types/seat/wlr_seat_keyboard.c b/types/seat/wlr_seat_keyboard.c index f41ef880..e97b4825 100644 --- a/types/seat/wlr_seat_keyboard.c +++ b/types/seat/wlr_seat_keyboard.c @@ -1,17 +1,13 @@ #define _POSIX_C_SOURCE 200809L #include <assert.h> #include <stdlib.h> -#include <string.h> -#include <sys/mman.h> #include <time.h> -#include <unistd.h> #include <wayland-server-core.h> #include <wlr/types/wlr_data_device.h> #include <wlr/types/wlr_input_device.h> #include <wlr/util/log.h> #include "types/wlr_data_device.h" #include "types/wlr_seat.h" -#include "util/shm.h" #include "util/signal.h" static void default_keyboard_enter(struct wlr_seat_keyboard_grab *grab, @@ -364,35 +360,8 @@ static void seat_client_send_keymap(struct wlr_seat_client *client, continue; } - int keymap_fd = allocate_shm_file(keyboard->keymap_size); - if (keymap_fd < 0) { - wlr_log(WLR_ERROR, "creating a keymap file for %zu bytes failed", keyboard->keymap_size); - continue; - } - - if (keyboard->keymap == NULL) { - wl_keyboard_send_keymap(resource, - WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP, keymap_fd, 0); - close(keymap_fd); - continue; - } - - void *ptr = mmap(NULL, keyboard->keymap_size, PROT_READ | PROT_WRITE, - MAP_SHARED, keymap_fd, 0); - if (ptr == MAP_FAILED) { - wlr_log(WLR_ERROR, "failed to mmap() %zu bytes", keyboard->keymap_size); - close(keymap_fd); - continue; - } - - strcpy(ptr, keyboard->keymap_string); - munmap(ptr, keyboard->keymap_size); - - wl_keyboard_send_keymap(resource, - WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keymap_fd, - keyboard->keymap_size); - - close(keymap_fd); + wl_keyboard_send_keymap(resource, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, + keyboard->keymap_fd, keyboard->keymap_size); } } |