2017-12-10 19:59:04 +01:00
|
|
|
#include "sway/input/seat.h"
|
|
|
|
#include "sway/input/keyboard.h"
|
2017-12-15 11:22:51 +01:00
|
|
|
#include "sway/input/input-manager.h"
|
2017-12-10 19:59:04 +01:00
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
static void handle_keyboard_key(struct wl_listener *listener, void *data) {
|
|
|
|
struct sway_keyboard *keyboard =
|
|
|
|
wl_container_of(listener, keyboard, keyboard_key);
|
2017-12-14 17:11:56 +01:00
|
|
|
struct wlr_seat *wlr_seat = keyboard->seat_device->sway_seat->wlr_seat;
|
|
|
|
struct wlr_input_device *wlr_device =
|
|
|
|
keyboard->seat_device->input_device->wlr_device;
|
2017-12-10 19:59:04 +01:00
|
|
|
struct wlr_event_keyboard_key *event = data;
|
2017-12-14 17:11:56 +01:00
|
|
|
wlr_seat_set_keyboard(wlr_seat, wlr_device);
|
2017-12-15 11:57:28 +01:00
|
|
|
wlr_seat_keyboard_notify_key(wlr_seat, event->time_msec,
|
|
|
|
event->keycode, event->state);
|
2017-12-10 19:59:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_keyboard_modifiers(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct sway_keyboard *keyboard =
|
|
|
|
wl_container_of(listener, keyboard, keyboard_modifiers);
|
2017-12-14 17:11:56 +01:00
|
|
|
struct wlr_seat *wlr_seat = keyboard->seat_device->sway_seat->wlr_seat;
|
|
|
|
struct wlr_input_device *wlr_device =
|
|
|
|
keyboard->seat_device->input_device->wlr_device;
|
|
|
|
wlr_seat_set_keyboard(wlr_seat, wlr_device);
|
|
|
|
wlr_seat_keyboard_notify_modifiers(wlr_seat);
|
2017-12-10 19:59:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat,
|
2017-12-14 17:11:56 +01:00
|
|
|
struct sway_seat_device *device) {
|
2017-12-10 19:59:04 +01:00
|
|
|
struct sway_keyboard *keyboard =
|
|
|
|
calloc(1, sizeof(struct sway_keyboard));
|
|
|
|
if (!sway_assert(keyboard, "could not allocate sway keyboard")) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-12-14 17:11:56 +01:00
|
|
|
keyboard->seat_device = device;
|
|
|
|
device->keyboard = keyboard;
|
2017-12-10 19:59:04 +01:00
|
|
|
|
2017-12-14 17:11:56 +01:00
|
|
|
wl_list_init(&keyboard->keyboard_key.link);
|
|
|
|
wl_list_init(&keyboard->keyboard_modifiers.link);
|
|
|
|
|
|
|
|
return keyboard;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sway_keyboard_configure(struct sway_keyboard *keyboard) {
|
2017-12-10 19:59:04 +01:00
|
|
|
struct xkb_rule_names rules;
|
|
|
|
memset(&rules, 0, sizeof(rules));
|
2017-12-15 11:22:51 +01:00
|
|
|
struct input_config *input_config =
|
|
|
|
keyboard->seat_device->input_device->config;
|
2017-12-15 11:57:28 +01:00
|
|
|
struct wlr_input_device *wlr_device =
|
|
|
|
keyboard->seat_device->input_device->wlr_device;
|
2017-12-15 11:22:51 +01:00
|
|
|
|
|
|
|
if (input_config && input_config->xkb_layout) {
|
|
|
|
rules.layout = input_config->xkb_layout;
|
|
|
|
} else {
|
|
|
|
rules.layout = getenv("XKB_DEFAULT_LAYOUT");
|
|
|
|
}
|
|
|
|
if (input_config && input_config->xkb_model) {
|
|
|
|
rules.model = input_config->xkb_model;
|
|
|
|
} else {
|
|
|
|
rules.model = getenv("XKB_DEFAULT_MODEL");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input_config && input_config->xkb_options) {
|
|
|
|
rules.options = input_config->xkb_options;
|
|
|
|
} else {
|
|
|
|
rules.options = getenv("XKB_DEFAULT_OPTIONS");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input_config && input_config->xkb_rules) {
|
|
|
|
rules.rules = input_config->xkb_rules;
|
|
|
|
} else {
|
|
|
|
rules.rules = getenv("XKB_DEFAULT_RULES");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input_config && input_config->xkb_variant) {
|
|
|
|
rules.variant = input_config->xkb_variant;
|
|
|
|
} else {
|
|
|
|
rules.variant = getenv("XKB_DEFAULT_VARIANT");
|
|
|
|
}
|
2017-12-14 17:11:56 +01:00
|
|
|
|
2017-12-10 19:59:04 +01:00
|
|
|
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
|
|
|
if (!sway_assert(context, "cannot create XKB context")) {
|
2017-12-14 17:11:56 +01:00
|
|
|
return;
|
2017-12-10 19:59:04 +01:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:36:17 +01:00
|
|
|
struct xkb_keymap *keymap =
|
2017-12-14 17:11:56 +01:00
|
|
|
xkb_keymap_new_from_names(context, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS);
|
2017-12-19 11:36:17 +01:00
|
|
|
|
|
|
|
if (!keymap) {
|
|
|
|
sway_log(L_DEBUG, "cannot configure keyboard: keymap does not exist");
|
|
|
|
xkb_context_unref(context);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xkb_keymap_unref(keyboard->keymap);
|
|
|
|
keyboard->keymap = keymap;
|
2017-12-15 11:57:28 +01:00
|
|
|
wlr_keyboard_set_keymap(wlr_device->keyboard, keyboard->keymap);
|
2017-12-19 11:36:17 +01:00
|
|
|
|
2017-12-15 11:57:28 +01:00
|
|
|
wlr_keyboard_set_repeat_info(wlr_device->keyboard, 25, 600);
|
2017-12-10 19:59:04 +01:00
|
|
|
xkb_context_unref(context);
|
2017-12-18 16:44:51 +01:00
|
|
|
struct wlr_seat *seat = keyboard->seat_device->sway_seat->wlr_seat;
|
|
|
|
wlr_seat_set_keyboard(seat, wlr_device);
|
2017-12-10 19:59:04 +01:00
|
|
|
|
2017-12-14 17:11:56 +01:00
|
|
|
wl_list_remove(&keyboard->keyboard_key.link);
|
2017-12-15 11:57:28 +01:00
|
|
|
wl_signal_add(&wlr_device->keyboard->events.key, &keyboard->keyboard_key);
|
2017-12-10 19:59:04 +01:00
|
|
|
keyboard->keyboard_key.notify = handle_keyboard_key;
|
|
|
|
|
2017-12-14 17:11:56 +01:00
|
|
|
wl_list_remove(&keyboard->keyboard_modifiers.link);
|
2017-12-15 11:57:28 +01:00
|
|
|
wl_signal_add( &wlr_device->keyboard->events.modifiers,
|
2017-12-12 14:29:37 +01:00
|
|
|
&keyboard->keyboard_modifiers);
|
2017-12-10 19:59:04 +01:00
|
|
|
keyboard->keyboard_modifiers.notify = handle_keyboard_modifiers;
|
|
|
|
}
|
2017-12-10 21:37:17 +01:00
|
|
|
|
|
|
|
void sway_keyboard_destroy(struct sway_keyboard *keyboard) {
|
2017-12-17 01:16:00 +01:00
|
|
|
if (!keyboard) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-10 21:37:17 +01:00
|
|
|
wl_list_remove(&keyboard->keyboard_key.link);
|
|
|
|
wl_list_remove(&keyboard->keyboard_modifiers.link);
|
|
|
|
free(keyboard);
|
|
|
|
}
|