From d290b13871fa18dcad6cd90d9ee93e7205742124 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sat, 7 Aug 2021 13:48:49 +0200 Subject: seat: avoid copying the keymap for each client We can just send a read-only file descriptor instead. --- types/seat/wlr_seat_keyboard.c | 35 ++--------------------------------- 1 file 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 #include -#include -#include #include -#include #include #include #include #include #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); } } -- cgit v1.2.3