|
|
@ -2,16 +2,12 @@
|
|
|
|
#include <assert.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <wayland-server.h>
|
|
|
|
#include <wayland-server.h>
|
|
|
|
#include <wlr/interfaces/wlr_keyboard.h>
|
|
|
|
#include <wlr/interfaces/wlr_keyboard.h>
|
|
|
|
#include <wlr/types/wlr_keyboard.h>
|
|
|
|
#include <wlr/types/wlr_keyboard.h>
|
|
|
|
#include <wlr/util/log.h>
|
|
|
|
#include <wlr/util/log.h>
|
|
|
|
#include "util/signal.h"
|
|
|
|
#include "util/signal.h"
|
|
|
|
|
|
|
|
|
|
|
|
int os_create_anonymous_file(off_t size);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void keyboard_led_update(struct wlr_keyboard *keyboard) {
|
|
|
|
static void keyboard_led_update(struct wlr_keyboard *keyboard) {
|
|
|
|
if (keyboard->xkb_state == NULL) {
|
|
|
|
if (keyboard->xkb_state == NULL) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -126,7 +122,6 @@ void wlr_keyboard_init(struct wlr_keyboard *kb,
|
|
|
|
wl_signal_init(&kb->events.modifiers);
|
|
|
|
wl_signal_init(&kb->events.modifiers);
|
|
|
|
wl_signal_init(&kb->events.keymap);
|
|
|
|
wl_signal_init(&kb->events.keymap);
|
|
|
|
wl_signal_init(&kb->events.repeat_info);
|
|
|
|
wl_signal_init(&kb->events.repeat_info);
|
|
|
|
kb->keymap_fd = -1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Sane defaults
|
|
|
|
// Sane defaults
|
|
|
|
kb->repeat_info.rate = 25;
|
|
|
|
kb->repeat_info.rate = 25;
|
|
|
@ -139,9 +134,7 @@ void wlr_keyboard_destroy(struct wlr_keyboard *kb) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xkb_state_unref(kb->xkb_state);
|
|
|
|
xkb_state_unref(kb->xkb_state);
|
|
|
|
xkb_keymap_unref(kb->keymap);
|
|
|
|
xkb_keymap_unref(kb->keymap);
|
|
|
|
if (kb->keymap_fd >= 0) {
|
|
|
|
free(kb->keymap_string);
|
|
|
|
close(kb->keymap_fd);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kb->impl && kb->impl->destroy) {
|
|
|
|
if (kb->impl && kb->impl->destroy) {
|
|
|
|
kb->impl->destroy(kb);
|
|
|
|
kb->impl->destroy(kb);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -158,8 +151,6 @@ void wlr_keyboard_led_update(struct wlr_keyboard *kb, uint32_t leds) {
|
|
|
|
|
|
|
|
|
|
|
|
void wlr_keyboard_set_keymap(struct wlr_keyboard *kb,
|
|
|
|
void wlr_keyboard_set_keymap(struct wlr_keyboard *kb,
|
|
|
|
struct xkb_keymap *keymap) {
|
|
|
|
struct xkb_keymap *keymap) {
|
|
|
|
char *keymap_str = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xkb_keymap_unref(kb->keymap);
|
|
|
|
xkb_keymap_unref(kb->keymap);
|
|
|
|
kb->keymap = xkb_keymap_ref(keymap);
|
|
|
|
kb->keymap = xkb_keymap_ref(keymap);
|
|
|
|
|
|
|
|
|
|
|
@ -194,26 +185,15 @@ void wlr_keyboard_set_keymap(struct wlr_keyboard *kb,
|
|
|
|
kb->mod_indexes[i] = xkb_map_mod_get_index(kb->keymap, mod_names[i]);
|
|
|
|
kb->mod_indexes[i] = xkb_map_mod_get_index(kb->keymap, mod_names[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
keymap_str = xkb_keymap_get_as_string(kb->keymap,
|
|
|
|
char *tmp_keymap_string = xkb_keymap_get_as_string(kb->keymap,
|
|
|
|
XKB_KEYMAP_FORMAT_TEXT_V1);
|
|
|
|
XKB_KEYMAP_FORMAT_TEXT_V1);
|
|
|
|
kb->keymap_size = strlen(keymap_str) + 1;
|
|
|
|
if (tmp_keymap_string == NULL) {
|
|
|
|
if (kb->keymap_fd >= 0) {
|
|
|
|
wlr_log(WLR_ERROR, "Failed to get string version of keymap");
|
|
|
|
close(kb->keymap_fd);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
kb->keymap_fd = os_create_anonymous_file(kb->keymap_size);
|
|
|
|
|
|
|
|
if (kb->keymap_fd < 0) {
|
|
|
|
|
|
|
|
wlr_log(WLR_ERROR, "creating a keymap file for %zu bytes failed", kb->keymap_size);
|
|
|
|
|
|
|
|
goto err;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void *ptr = mmap(NULL, kb->keymap_size,
|
|
|
|
free(kb->keymap_string);
|
|
|
|
PROT_READ | PROT_WRITE, MAP_SHARED, kb->keymap_fd, 0);
|
|
|
|
kb->keymap_string = tmp_keymap_string;
|
|
|
|
if (ptr == (void*)-1) {
|
|
|
|
kb->keymap_size = strlen(kb->keymap_string) + 1;
|
|
|
|
wlr_log(WLR_ERROR, "failed to mmap() %zu bytes", kb->keymap_size);
|
|
|
|
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(ptr, keymap_str);
|
|
|
|
|
|
|
|
free(keymap_str);
|
|
|
|
|
|
|
|
munmap(ptr, kb->keymap_size);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < kb->num_keycodes; ++i) {
|
|
|
|
for (size_t i = 0; i < kb->num_keycodes; ++i) {
|
|
|
|
xkb_keycode_t keycode = kb->keycodes[i] + 8;
|
|
|
|
xkb_keycode_t keycode = kb->keycodes[i] + 8;
|
|
|
@ -230,11 +210,8 @@ err:
|
|
|
|
kb->xkb_state = NULL;
|
|
|
|
kb->xkb_state = NULL;
|
|
|
|
xkb_keymap_unref(keymap);
|
|
|
|
xkb_keymap_unref(keymap);
|
|
|
|
kb->keymap = NULL;
|
|
|
|
kb->keymap = NULL;
|
|
|
|
if (kb->keymap_fd >= 0) {
|
|
|
|
free(kb->keymap_string);
|
|
|
|
close(kb->keymap_fd);
|
|
|
|
kb->keymap_string = NULL;
|
|
|
|
kb->keymap_fd = -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
free(keymap_str);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wlr_keyboard_set_repeat_info(struct wlr_keyboard *kb, int32_t rate,
|
|
|
|
void wlr_keyboard_set_repeat_info(struct wlr_keyboard *kb, int32_t rate,
|
|
|
|