mirror of
https://github.com/swaywm/sway.git
synced 2024-11-25 17:31:28 +00:00
basic keyboard
This commit is contained in:
parent
6339c4f161
commit
609f63934a
13
include/sway/input/keyboard.h
Normal file
13
include/sway/input/keyboard.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include "sway/input/seat.h"
|
||||
|
||||
struct sway_keyboard {
|
||||
struct sway_seat *seat;
|
||||
struct wlr_input_device *device;
|
||||
struct wl_list link; // sway_seat::keyboards
|
||||
|
||||
struct wl_listener keyboard_key;
|
||||
struct wl_listener keyboard_modifiers;
|
||||
};
|
||||
|
||||
struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat,
|
||||
struct wlr_input_device *device);
|
|
@ -10,6 +10,8 @@ struct sway_seat {
|
|||
struct sway_input_manager *input;
|
||||
swayc_t *focus;
|
||||
|
||||
struct wl_list keyboards;
|
||||
|
||||
struct wl_listener focus_destroy;
|
||||
};
|
||||
|
||||
|
|
57
sway/input/keyboard.c
Normal file
57
sway/input/keyboard.c
Normal file
|
@ -0,0 +1,57 @@
|
|||
#include "sway/input/seat.h"
|
||||
#include "sway/input/keyboard.h"
|
||||
#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);
|
||||
struct wlr_event_keyboard_key *event = data;
|
||||
wlr_seat_set_keyboard(keyboard->seat->seat, keyboard->device);
|
||||
wlr_seat_keyboard_notify_key(keyboard->seat->seat, event->time_msec,
|
||||
event->keycode, event->state);
|
||||
}
|
||||
|
||||
static void handle_keyboard_modifiers(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct sway_keyboard *keyboard =
|
||||
wl_container_of(listener, keyboard, keyboard_modifiers);
|
||||
wlr_seat_set_keyboard(keyboard->seat->seat, keyboard->device);
|
||||
wlr_seat_keyboard_notify_modifiers(keyboard->seat->seat);
|
||||
}
|
||||
|
||||
struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat,
|
||||
struct wlr_input_device *device) {
|
||||
struct sway_keyboard *keyboard =
|
||||
calloc(1, sizeof(struct sway_keyboard));
|
||||
if (!sway_assert(keyboard, "could not allocate sway keyboard")) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
keyboard->device = device;
|
||||
keyboard->seat = seat;
|
||||
|
||||
// TODO keyboard config
|
||||
struct xkb_rule_names rules;
|
||||
memset(&rules, 0, sizeof(rules));
|
||||
rules.rules = getenv("XKB_DEFAULT_RULES");
|
||||
rules.model = getenv("XKB_DEFAULT_MODEL");
|
||||
rules.layout = getenv("XKB_DEFAULT_LAYOUT");
|
||||
rules.variant = getenv("XKB_DEFAULT_VARIANT");
|
||||
rules.options = getenv("XKB_DEFAULT_OPTIONS");
|
||||
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||
if (!sway_assert(context, "cannot create XKB context")) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wlr_keyboard_set_keymap(device->keyboard, xkb_map_new_from_names(context,
|
||||
&rules, XKB_KEYMAP_COMPILE_NO_FLAGS));
|
||||
xkb_context_unref(context);
|
||||
|
||||
wl_signal_add(&device->keyboard->events.key, &keyboard->keyboard_key);
|
||||
keyboard->keyboard_key.notify = handle_keyboard_key;
|
||||
|
||||
wl_signal_add(&device->keyboard->events.modifiers, &keyboard->keyboard_modifiers);
|
||||
keyboard->keyboard_modifiers.notify = handle_keyboard_modifiers;
|
||||
|
||||
return keyboard;
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
#include "sway/input/seat.h"
|
||||
#include "sway/input/cursor.h"
|
||||
#include "sway/input/input-manager.h"
|
||||
#include "sway/input/keyboard.h"
|
||||
#include "sway/output.h"
|
||||
#include "sway/view.h"
|
||||
#include "log.h"
|
||||
|
@ -36,6 +37,8 @@ struct sway_seat *sway_seat_create(struct sway_input_manager *input,
|
|||
|
||||
sway_seat_configure_xcursor(seat);
|
||||
|
||||
wl_list_init(&seat->keyboards);
|
||||
|
||||
return seat;
|
||||
}
|
||||
|
||||
|
@ -45,6 +48,13 @@ static void seat_add_pointer(struct sway_seat *seat,
|
|||
wlr_cursor_attach_input_device(seat->cursor->cursor, device);
|
||||
}
|
||||
|
||||
static void seat_add_keyboard(struct sway_seat *seat,
|
||||
struct wlr_input_device *device) {
|
||||
struct sway_keyboard *keyboard = sway_keyboard_create(seat, device);
|
||||
wl_list_insert(&seat->keyboards, &keyboard->link);
|
||||
wlr_seat_set_keyboard(seat->seat, device);
|
||||
}
|
||||
|
||||
void sway_seat_add_device(struct sway_seat *seat,
|
||||
struct wlr_input_device *device) {
|
||||
sway_log(L_DEBUG, "input add: %s", device->name);
|
||||
|
@ -53,6 +63,8 @@ void sway_seat_add_device(struct sway_seat *seat,
|
|||
seat_add_pointer(seat, device);
|
||||
break;
|
||||
case WLR_INPUT_DEVICE_KEYBOARD:
|
||||
seat_add_keyboard(seat, device);
|
||||
break;
|
||||
case WLR_INPUT_DEVICE_TOUCH:
|
||||
case WLR_INPUT_DEVICE_TABLET_PAD:
|
||||
case WLR_INPUT_DEVICE_TABLET_TOOL:
|
||||
|
@ -138,7 +150,7 @@ void sway_seat_set_focus(struct sway_seat *seat, swayc_t *container) {
|
|||
view->iface.set_activated(view, true);
|
||||
wl_signal_add(&container->events.destroy, &seat->focus_destroy);
|
||||
seat->focus_destroy.notify = handle_focus_destroy;
|
||||
// TODO give keyboard focus
|
||||
wlr_seat_keyboard_notify_enter(seat->seat, view->surface);
|
||||
}
|
||||
|
||||
seat->focus = container;
|
||||
|
|
|
@ -5,6 +5,7 @@ sway_sources = files(
|
|||
'input/input-manager.c',
|
||||
'input/seat.c',
|
||||
'input/cursor.c',
|
||||
'input/keyboard.c',
|
||||
'commands/exit.c',
|
||||
'commands/exec.c',
|
||||
'commands/exec_always.c',
|
||||
|
@ -30,6 +31,7 @@ sway_deps = [
|
|||
libcap,
|
||||
math,
|
||||
libinput,
|
||||
xkbcommon,
|
||||
]
|
||||
|
||||
executable(
|
||||
|
|
Loading…
Reference in a new issue