Add some more keyboard handling for wayland clients

This commit is contained in:
Drew DeVault 2015-12-12 12:53:55 -05:00
parent 19fd979af4
commit 029e0c7a2c
4 changed files with 58 additions and 55 deletions

View File

@ -49,7 +49,7 @@ Run these commands:
mkdir build
cd build
cmake ..
cmake -DCMAKE_BUILD_TYPE=Release ..
make
sudo make install

View File

@ -8,26 +8,26 @@
#include "list.h"
enum mod_bit {
MOD_SHIFT = 1<<0,
MOD_CAPS = 1<<1,
MOD_CTRL = 1<<2,
MOD_ALT = 1<<3,
MOD_MOD2 = 1<<4,
MOD_MOD3 = 1<<5,
MOD_LOGO = 1<<6,
MOD_MOD5 = 1<<7,
MOD_SHIFT = 1<<0,
MOD_CAPS = 1<<1,
MOD_CTRL = 1<<2,
MOD_ALT = 1<<3,
MOD_MOD2 = 1<<4,
MOD_MOD3 = 1<<5,
MOD_LOGO = 1<<6,
MOD_MOD5 = 1<<7,
};
enum mask {
MASK_SHIFT,
MASK_CAPS,
MASK_CTRL,
MASK_ALT,
MASK_MOD2,
MASK_MOD3,
MASK_LOGO,
MASK_MOD5,
MASK_LAST
MASK_SHIFT,
MASK_CAPS,
MASK_CTRL,
MASK_ALT,
MASK_MOD2,
MASK_MOD3,
MASK_LOGO,
MASK_MOD5,
MASK_LAST
};
struct output_state {
@ -44,26 +44,14 @@ struct xkb {
};
struct input {
int *repeat_fd;
struct xkb xkb;
struct xkb xkb;
xkb_keysym_t sym;
uint32_t code;
uint32_t last_code;
uint32_t modifiers;
xkb_keysym_t sym;
uint32_t code;
uint32_t last_code;
uint32_t modifiers;
xkb_keysym_t repeat_sym;
uint32_t repeat_key;
int32_t repeat_rate_sec;
int32_t repeat_rate_nsec;
int32_t repeat_delay_sec;
int32_t repeat_delay_nsec;
struct {
void (*key)(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code);
} notify;
void (*notify)(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code);
};
struct registry {

View File

@ -34,9 +34,9 @@ int main(int argc, char **argv) {
surfaces = create_list();
registry = registry_poll();
if (!registry->swaylock) {
/*if (!registry->swaylock) {
sway_abort("swaylock requires the compositor to support the swaylock extension.");
}
}*/
int i;
for (i = 0; i < registry->outputs->length; ++i) {
@ -45,7 +45,7 @@ int main(int argc, char **argv) {
if (!window) {
sway_abort("Failed to create surfaces.");
}
lock_set_lock_surface(registry->swaylock, output->output, window->surface);
//lock_set_lock_surface(registry->swaylock, output->output, window->surface);
list_add(surfaces, window);
}

View File

@ -43,25 +43,25 @@ static const struct wl_output_listener output_listener = {
};
const char *XKB_MASK_NAMES[MASK_LAST] = {
XKB_MOD_NAME_SHIFT,
XKB_MOD_NAME_CAPS,
XKB_MOD_NAME_CTRL,
XKB_MOD_NAME_ALT,
"Mod2",
"Mod3",
XKB_MOD_NAME_LOGO,
"Mod5",
XKB_MOD_NAME_SHIFT,
XKB_MOD_NAME_CAPS,
XKB_MOD_NAME_CTRL,
XKB_MOD_NAME_ALT,
"Mod2",
"Mod3",
XKB_MOD_NAME_LOGO,
"Mod5",
};
const enum mod_bit XKB_MODS[MASK_LAST] = {
MOD_SHIFT,
MOD_CAPS,
MOD_CTRL,
MOD_ALT,
MOD_MOD2,
MOD_MOD3,
MOD_LOGO,
MOD_MOD5
MOD_SHIFT,
MOD_CAPS,
MOD_CTRL,
MOD_ALT,
MOD_MOD2,
MOD_MOD3,
MOD_LOGO,
MOD_MOD5
};
static void keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
@ -113,14 +113,29 @@ static void keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
static void keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
uint32_t serial, struct wl_surface *surface, struct wl_array *keys) {
// this space intentionally left blank
}
static void keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
uint32_t serial, struct wl_surface *surface) {
// this space intentionally left blank
}
static void keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
uint32_t serial, uint32_t time, uint32_t key, uint32_t state_w) {
struct registry *registry = data;
enum wl_keyboard_key_state state = state_w;
if (!input->xkb.state) {
return;
}
xkb_keysym_t sym = xkb_state_key_get_one_sym(input->xkb.state, key + 8);
registry->input->sym = (state == WL_KEYBOARD_KEY_STATE_PRESSED ? sym : XKB_KEY_NoSymbol);
registry->input->code = (state == WL_KEYBOARD_KEY_STATE_PRESSED ? key + 8 : 0);
if (registry->input->notify) {
registry->input->notify(state, sym, key);
}
}
static void keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,