Implement setting NumLock and CapsLock status

After setting the keymap, try to enable NumLock and disable CapsLock.
This only works if sway has the xkb master state and controls the keyboard.
Prepare configuration settings for later use as well.
This commit is contained in:
ProgAndy 2018-07-22 21:16:19 +02:00
parent 6a8d1e5044
commit 2166dbe2e4
3 changed files with 29 additions and 0 deletions

View file

@ -101,6 +101,9 @@ struct input_config {
char *xkb_rules; char *xkb_rules;
char *xkb_variant; char *xkb_variant;
int xkb_numlock;
int xkb_capslock;
struct input_config_mapped_from_region *mapped_from_region; struct input_config_mapped_from_region *mapped_from_region;
char *mapped_to_output; char *mapped_to_output;

View file

@ -33,6 +33,8 @@ struct input_config *new_input_config(const char* identifier) {
input->left_handed = INT_MIN; input->left_handed = INT_MIN;
input->repeat_delay = INT_MIN; input->repeat_delay = INT_MIN;
input->repeat_rate = INT_MIN; input->repeat_rate = INT_MIN;
input->xkb_numlock = INT_MIN;
input->xkb_capslock = INT_MIN;
return input; return input;
} }
@ -104,6 +106,12 @@ void merge_input_config(struct input_config *dst, struct input_config *src) {
free(dst->xkb_variant); free(dst->xkb_variant);
dst->xkb_variant = strdup(src->xkb_variant); dst->xkb_variant = strdup(src->xkb_variant);
} }
if (src->xkb_numlock != INT_MIN) {
dst->xkb_numlock = src->xkb_numlock;
}
if (src->xkb_capslock != INT_MIN) {
dst->xkb_capslock = src->xkb_capslock;
}
if (src->mapped_from_region) { if (src->mapped_from_region) {
free(dst->mapped_from_region); free(dst->mapped_from_region);
dst->mapped_from_region = dst->mapped_from_region =

View file

@ -3,6 +3,7 @@
#include <wlr/backend/multi.h> #include <wlr/backend/multi.h>
#include <wlr/backend/session.h> #include <wlr/backend/session.h>
#include <wlr/types/wlr_idle.h> #include <wlr/types/wlr_idle.h>
#include <wlr/interfaces/wlr_keyboard.h>
#include "sway/commands.h" #include "sway/commands.h"
#include "sway/desktop/transaction.h" #include "sway/desktop/transaction.h"
#include "sway/input/input-manager.h" #include "sway/input/input-manager.h"
@ -385,6 +386,23 @@ void sway_keyboard_configure(struct sway_keyboard *keyboard) {
keyboard->keymap = keymap; keyboard->keymap = keymap;
wlr_keyboard_set_keymap(wlr_device->keyboard, keyboard->keymap); wlr_keyboard_set_keymap(wlr_device->keyboard, keyboard->keymap);
xkb_mod_mask_t locked_mods = 0;
if (!input_config || input_config->xkb_numlock != 0) {
xkb_mod_index_t mod_index = xkb_map_mod_get_index(keymap, XKB_MOD_NAME_NUM);
if (mod_index != XKB_MOD_INVALID) {
locked_mods |= (uint32_t)1 << mod_index;
}
}
if (input_config && input_config->xkb_capslock > 0) {
xkb_mod_index_t mod_index = xkb_map_mod_get_index(keymap, XKB_MOD_NAME_CAPS);
if (mod_index != XKB_MOD_INVALID) {
locked_mods |= (uint32_t)1 << mod_index;
}
}
if (locked_mods) {
wlr_keyboard_notify_modifiers(wlr_device->keyboard, 0, 0, locked_mods, 0);
}
if (input_config && input_config->repeat_delay != INT_MIN if (input_config && input_config->repeat_delay != INT_MIN
&& input_config->repeat_rate != INT_MIN) { && input_config->repeat_rate != INT_MIN) {
wlr_keyboard_set_repeat_info(wlr_device->keyboard, wlr_keyboard_set_repeat_info(wlr_device->keyboard,