Keyboard handling
commit ee1a46632dea614fcdf614299d4de6e22a9b0060 Author: buffet <dev@buffet.sh> Date: Sat Mar 16 16:29:33 2019 +0100 Fixed TTY switching commit 7cc8aae424c924035489c09c6d5337eb281f1e39 Author: buffet <dev@buffet.sh> Date: Fri Mar 15 16:55:13 2019 +0100 Started working on kb handling
This commit is contained in:
parent
ca8fa35bbc
commit
c092c8784b
7 changed files with 163 additions and 3 deletions
27
include/kiwmi/input/keyboard.h
Normal file
27
include/kiwmi/input/keyboard.h
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/* Copyright (c), Charlotte Meyer <dev@buffet.sh>
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
* You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef KIWMI_INPUT_KEYBOARD_H
|
||||||
|
#define KIWMI_INPUT_KEYBOARD_H
|
||||||
|
|
||||||
|
#include <wayland-server.h>
|
||||||
|
#include <wlr/types/wlr_input_device.h>
|
||||||
|
|
||||||
|
#include "kiwmi/server.h"
|
||||||
|
|
||||||
|
struct kiwmi_keyboard {
|
||||||
|
struct wl_list link;
|
||||||
|
struct kiwmi_server *server;
|
||||||
|
struct wlr_input_device *device;
|
||||||
|
struct wl_listener modifiers;
|
||||||
|
struct wl_listener key;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct kiwmi_keyboard *
|
||||||
|
keyboard_create(struct kiwmi_server *server, struct wlr_input_device *device);
|
||||||
|
|
||||||
|
#endif /* KIWMI_INPUT_KEYBOARD_H */
|
|
@ -23,6 +23,7 @@ struct kiwmi_server {
|
||||||
struct wlr_data_device_manager *data_device_manager;
|
struct wlr_data_device_manager *data_device_manager;
|
||||||
struct wlr_output_layout *output_layout;
|
struct wlr_output_layout *output_layout;
|
||||||
const char *socket;
|
const char *socket;
|
||||||
|
struct wl_list keyboards; // struct kiwmi_keyboard::link
|
||||||
struct wl_list outputs; // struct kiwmi_output::link
|
struct wl_list outputs; // struct kiwmi_output::link
|
||||||
struct wl_listener new_output;
|
struct wl_listener new_output;
|
||||||
struct kiwmi_cursor *cursor;
|
struct kiwmi_cursor *cursor;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <wlr/types/wlr_input_device.h>
|
#include <wlr/types/wlr_input_device.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
|
||||||
|
#include "kiwmi/input/keyboard.h"
|
||||||
#include "kiwmi/server.h"
|
#include "kiwmi/server.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -19,6 +20,17 @@ new_pointer(struct kiwmi_server *server, struct wlr_input_device *device)
|
||||||
wlr_cursor_attach_input_device(server->cursor->cursor, device);
|
wlr_cursor_attach_input_device(server->cursor->cursor, device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
new_keyboard(struct kiwmi_server *server, struct wlr_input_device *device)
|
||||||
|
{
|
||||||
|
struct kiwmi_keyboard *keyboard = keyboard_create(server, device);
|
||||||
|
if (!keyboard) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wl_list_insert(&server->keyboards, &keyboard->link);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
new_input_notify(struct wl_listener *listener, void *data)
|
new_input_notify(struct wl_listener *listener, void *data)
|
||||||
{
|
{
|
||||||
|
@ -31,6 +43,9 @@ new_input_notify(struct wl_listener *listener, void *data)
|
||||||
case WLR_INPUT_DEVICE_POINTER:
|
case WLR_INPUT_DEVICE_POINTER:
|
||||||
new_pointer(server, device);
|
new_pointer(server, device);
|
||||||
break;
|
break;
|
||||||
|
case WLR_INPUT_DEVICE_KEYBOARD:
|
||||||
|
new_keyboard(server, device);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
// NOT HANDLED
|
// NOT HANDLED
|
||||||
break;
|
break;
|
||||||
|
|
113
kiwmi/input/keyboard.c
Normal file
113
kiwmi/input/keyboard.c
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
/* Copyright (c), Charlotte Meyer <dev@buffet.sh>
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
* You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "kiwmi/input/keyboard.h"
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <wayland-server.h>
|
||||||
|
#include <wlr/backend/multi.h>
|
||||||
|
#include <wlr/backend/session.h>
|
||||||
|
#include <wlr/types/wlr_input_device.h>
|
||||||
|
#include <wlr/util/log.h>
|
||||||
|
#include <xkbcommon/xkbcommon.h>
|
||||||
|
|
||||||
|
#include "kiwmi/server.h"
|
||||||
|
|
||||||
|
static bool
|
||||||
|
switch_vt(const xkb_keysym_t *syms, int nsyms, struct wlr_backend *backend)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < nsyms; ++i) {
|
||||||
|
const xkb_keysym_t sym = syms[i];
|
||||||
|
|
||||||
|
if (sym >= XKB_KEY_XF86Switch_VT_1 && sym <= XKB_KEY_XF86Switch_VT_12) {
|
||||||
|
if (wlr_backend_is_multi(backend)) {
|
||||||
|
struct wlr_session *session = wlr_backend_get_session(backend);
|
||||||
|
if (session) {
|
||||||
|
unsigned vt = sym - XKB_KEY_XF86Switch_VT_1 + 1;
|
||||||
|
wlr_session_change_vt(session, vt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
keyboard_modifiers_notify(
|
||||||
|
struct wl_listener *UNUSED(listener),
|
||||||
|
void *UNUSED(data))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
keyboard_key_notify(struct wl_listener *listener, void *data)
|
||||||
|
{
|
||||||
|
struct kiwmi_keyboard *keyboard = wl_container_of(listener, keyboard, key);
|
||||||
|
struct kiwmi_server *server = keyboard->server;
|
||||||
|
struct wlr_event_keyboard_key *event = data;
|
||||||
|
|
||||||
|
uint32_t keycode = event->keycode + 8;
|
||||||
|
const xkb_keysym_t *syms;
|
||||||
|
int nsyms = xkb_state_key_get_syms(
|
||||||
|
keyboard->device->keyboard->xkb_state, keycode, &syms);
|
||||||
|
uint32_t modifiers = wlr_keyboard_get_modifiers(keyboard->device->keyboard);
|
||||||
|
|
||||||
|
bool handled = false;
|
||||||
|
|
||||||
|
if (event->state == WLR_KEY_PRESSED) {
|
||||||
|
handled = switch_vt(syms, nsyms, server->backend);
|
||||||
|
|
||||||
|
if (!handled && (modifiers & WLR_MODIFIER_LOGO)) {
|
||||||
|
for (int i = 0; i < nsyms; ++i) {
|
||||||
|
xkb_keysym_t sym = syms[i];
|
||||||
|
|
||||||
|
switch (sym) {
|
||||||
|
case XKB_KEY_Escape:
|
||||||
|
wl_display_terminate(server->wl_display);
|
||||||
|
handled = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct kiwmi_keyboard *
|
||||||
|
keyboard_create(struct kiwmi_server *server, struct wlr_input_device *device)
|
||||||
|
{
|
||||||
|
wlr_log(WLR_DEBUG, "Creating keyboard");
|
||||||
|
|
||||||
|
struct kiwmi_keyboard *keyboard = malloc(sizeof(*keyboard));
|
||||||
|
if (!keyboard) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
keyboard->server = server;
|
||||||
|
keyboard->device = device;
|
||||||
|
|
||||||
|
struct xkb_rule_names rules = {0};
|
||||||
|
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||||
|
struct xkb_keymap *keymap =
|
||||||
|
xkb_map_new_from_names(context, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||||
|
|
||||||
|
keyboard->modifiers.notify = keyboard_modifiers_notify;
|
||||||
|
wl_signal_add(&device->keyboard->events.modifiers, &keyboard->modifiers);
|
||||||
|
|
||||||
|
keyboard->key.notify = keyboard_key_notify;
|
||||||
|
wl_signal_add(&device->keyboard->events.key, &keyboard->key);
|
||||||
|
|
||||||
|
wlr_keyboard_set_keymap(device->keyboard, keymap);
|
||||||
|
xkb_keymap_unref(keymap);
|
||||||
|
xkb_context_unref(context);
|
||||||
|
wlr_keyboard_set_repeat_info(device->keyboard, 25, 600);
|
||||||
|
|
||||||
|
return keyboard;
|
||||||
|
}
|
|
@ -1,15 +1,17 @@
|
||||||
kiwmi_sources = files(
|
kiwmi_sources = files(
|
||||||
'main.c',
|
'main.c',
|
||||||
'server.c',
|
|
||||||
'input.c',
|
'input.c',
|
||||||
'output.c',
|
'output.c',
|
||||||
|
'server.c',
|
||||||
'desktop/output.c',
|
'desktop/output.c',
|
||||||
'input/cursor.c',
|
'input/cursor.c',
|
||||||
|
'input/keyboard.c',
|
||||||
)
|
)
|
||||||
|
|
||||||
kiwmi_deps = [
|
kiwmi_deps = [
|
||||||
wayland_server,
|
wayland_server,
|
||||||
wlroots,
|
wlroots,
|
||||||
|
xkbcommon,
|
||||||
]
|
]
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
|
|
|
@ -53,6 +53,7 @@ server_init(struct kiwmi_server *server)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wl_list_init(&server->keyboards);
|
||||||
wl_list_init(&server->outputs);
|
wl_list_init(&server->outputs);
|
||||||
|
|
||||||
server->new_output.notify = new_output_notify;
|
server->new_output.notify = new_output_notify;
|
||||||
|
|
|
@ -19,6 +19,7 @@ add_project_arguments(
|
||||||
git = find_program('git', required: false)
|
git = find_program('git', required: false)
|
||||||
wayland_server = dependency('wayland-server')
|
wayland_server = dependency('wayland-server')
|
||||||
wlroots = dependency('wlroots')
|
wlroots = dependency('wlroots')
|
||||||
|
xkbcommon = dependency('xkbcommon')
|
||||||
|
|
||||||
include = include_directories('include')
|
include = include_directories('include')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue