mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-22 20:45:59 +01:00
config: Add option to resolve keybinds by sym instead of code (#4851)
This commit adds the new configuration option 'resolve_binds_by_sym' which can be set globally or per-device. It is off by default, which preserves the current behavior. This setting only affects the behavior of keybinds that are defined via key symbols, not those defined via keycode. Binds defined by symbols currently activate if the keycode pressed would generate the specified symbol on the first layout specified in the input section. If enabled, keys pressed on the relevant device will instead match keybinds by the symbols they produce with their current layout. Closes #1881.
This commit is contained in:
parent
e3373669e5
commit
489ac40abd
4 changed files with 18 additions and 7 deletions
|
@ -448,6 +448,7 @@ CConfigManager::CConfigManager() {
|
||||||
m_pConfig->addConfigValue("input:repeat_delay", {600L});
|
m_pConfig->addConfigValue("input:repeat_delay", {600L});
|
||||||
m_pConfig->addConfigValue("input:natural_scroll", {0L});
|
m_pConfig->addConfigValue("input:natural_scroll", {0L});
|
||||||
m_pConfig->addConfigValue("input:numlock_by_default", {0L});
|
m_pConfig->addConfigValue("input:numlock_by_default", {0L});
|
||||||
|
m_pConfig->addConfigValue("input:resolve_binds_by_sym", {0L});
|
||||||
m_pConfig->addConfigValue("input:force_no_accel", {0L});
|
m_pConfig->addConfigValue("input:force_no_accel", {0L});
|
||||||
m_pConfig->addConfigValue("input:float_switch_override_focus", {1L});
|
m_pConfig->addConfigValue("input:float_switch_override_focus", {1L});
|
||||||
m_pConfig->addConfigValue("input:left_handed", {0L});
|
m_pConfig->addConfigValue("input:left_handed", {0L});
|
||||||
|
@ -533,6 +534,7 @@ CConfigManager::CConfigManager() {
|
||||||
m_pConfig->addSpecialConfigValue("device", "natural_scroll", {0L});
|
m_pConfig->addSpecialConfigValue("device", "natural_scroll", {0L});
|
||||||
m_pConfig->addSpecialConfigValue("device", "tap_button_map", {STRVAL_EMPTY});
|
m_pConfig->addSpecialConfigValue("device", "tap_button_map", {STRVAL_EMPTY});
|
||||||
m_pConfig->addSpecialConfigValue("device", "numlock_by_default", {0L});
|
m_pConfig->addSpecialConfigValue("device", "numlock_by_default", {0L});
|
||||||
|
m_pConfig->addSpecialConfigValue("device", "resolve_binds_by_sym", {0L});
|
||||||
m_pConfig->addSpecialConfigValue("device", "disable_while_typing", {1L});
|
m_pConfig->addSpecialConfigValue("device", "disable_while_typing", {1L});
|
||||||
m_pConfig->addSpecialConfigValue("device", "clickfinger_behavior", {0L});
|
m_pConfig->addSpecialConfigValue("device", "clickfinger_behavior", {0L});
|
||||||
m_pConfig->addSpecialConfigValue("device", "middle_button_emulation", {0L});
|
m_pConfig->addSpecialConfigValue("device", "middle_button_emulation", {0L});
|
||||||
|
|
|
@ -128,6 +128,7 @@ struct SKeyboard {
|
||||||
bool enabled = true;
|
bool enabled = true;
|
||||||
|
|
||||||
xkb_layout_index_t activeLayout = 0;
|
xkb_layout_index_t activeLayout = 0;
|
||||||
|
xkb_state* xkbTranslationState = nullptr;
|
||||||
|
|
||||||
std::string name = "";
|
std::string name = "";
|
||||||
std::string xkbFilePath = "";
|
std::string xkbFilePath = "";
|
||||||
|
@ -136,6 +137,7 @@ struct SKeyboard {
|
||||||
int repeatRate = 0;
|
int repeatRate = 0;
|
||||||
int repeatDelay = 0;
|
int repeatDelay = 0;
|
||||||
int numlockOn = -1;
|
int numlockOn = -1;
|
||||||
|
bool resolveBindsBySym = false;
|
||||||
|
|
||||||
// For the list lookup
|
// For the list lookup
|
||||||
bool operator==(const SKeyboard& rhs) const {
|
bool operator==(const SKeyboard& rhs) const {
|
||||||
|
|
|
@ -304,7 +304,7 @@ bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard
|
||||||
|
|
||||||
const auto KEYCODE = e->keycode + 8; // Because to xkbcommon it's +8 from libinput
|
const auto KEYCODE = e->keycode + 8; // Because to xkbcommon it's +8 from libinput
|
||||||
|
|
||||||
const xkb_keysym_t keysym = xkb_state_key_get_one_sym(m_pXKBTranslationState, KEYCODE);
|
const xkb_keysym_t keysym = xkb_state_key_get_one_sym(pKeyboard->resolveBindsBySym ? pKeyboard->xkbTranslationState : m_pXKBTranslationState, KEYCODE);
|
||||||
const xkb_keysym_t internalKeysym = xkb_state_key_get_one_sym(wlr_keyboard_from_input_device(pKeyboard->keyboard)->xkb_state, KEYCODE);
|
const xkb_keysym_t internalKeysym = xkb_state_key_get_one_sym(wlr_keyboard_from_input_device(pKeyboard->keyboard)->xkb_state, KEYCODE);
|
||||||
|
|
||||||
if (handleInternalKeybinds(internalKeysym))
|
if (handleInternalKeybinds(internalKeysym))
|
||||||
|
|
|
@ -824,6 +824,7 @@ void CInputManager::applyConfigToKeyboard(SKeyboard* pKeyboard) {
|
||||||
const auto REPEATDELAY = g_pConfigManager->getDeviceInt(devname, "repeat_delay", "input:repeat_delay");
|
const auto REPEATDELAY = g_pConfigManager->getDeviceInt(devname, "repeat_delay", "input:repeat_delay");
|
||||||
|
|
||||||
const auto NUMLOCKON = g_pConfigManager->getDeviceInt(devname, "numlock_by_default", "input:numlock_by_default");
|
const auto NUMLOCKON = g_pConfigManager->getDeviceInt(devname, "numlock_by_default", "input:numlock_by_default");
|
||||||
|
const auto RESOLVEBINDSBYSYM = g_pConfigManager->getDeviceInt(devname, "resolve_binds_by_sym", "input:resolve_binds_by_sym");
|
||||||
|
|
||||||
const auto FILEPATH = g_pConfigManager->getDeviceString(devname, "kb_file", "input:kb_file");
|
const auto FILEPATH = g_pConfigManager->getDeviceString(devname, "kb_file", "input:kb_file");
|
||||||
const auto RULES = g_pConfigManager->getDeviceString(devname, "kb_rules", "input:kb_rules");
|
const auto RULES = g_pConfigManager->getDeviceString(devname, "kb_rules", "input:kb_rules");
|
||||||
|
@ -835,6 +836,7 @@ void CInputManager::applyConfigToKeyboard(SKeyboard* pKeyboard) {
|
||||||
const auto ENABLED = HASCONFIG ? g_pConfigManager->getDeviceInt(devname, "enabled") : true;
|
const auto ENABLED = HASCONFIG ? g_pConfigManager->getDeviceInt(devname, "enabled") : true;
|
||||||
|
|
||||||
pKeyboard->enabled = ENABLED;
|
pKeyboard->enabled = ENABLED;
|
||||||
|
pKeyboard->resolveBindsBySym = RESOLVEBINDSBYSYM;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (NUMLOCKON == pKeyboard->numlockOn && REPEATDELAY == pKeyboard->repeatDelay && REPEATRATE == pKeyboard->repeatRate && RULES != "" &&
|
if (NUMLOCKON == pKeyboard->numlockOn && REPEATDELAY == pKeyboard->repeatDelay && REPEATRATE == pKeyboard->repeatRate && RULES != "" &&
|
||||||
|
@ -906,6 +908,9 @@ void CInputManager::applyConfigToKeyboard(SKeyboard* pKeyboard) {
|
||||||
KEYMAP = xkb_keymap_new_from_names(CONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS);
|
KEYMAP = xkb_keymap_new_from_names(CONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xkb_state_unref(pKeyboard->xkbTranslationState);
|
||||||
|
pKeyboard->xkbTranslationState = xkb_state_new(KEYMAP);
|
||||||
|
|
||||||
wlr_keyboard_set_keymap(wlr_keyboard_from_input_device(pKeyboard->keyboard), KEYMAP);
|
wlr_keyboard_set_keymap(wlr_keyboard_from_input_device(pKeyboard->keyboard), KEYMAP);
|
||||||
|
|
||||||
wlr_keyboard_modifiers wlrMods = {0};
|
wlr_keyboard_modifiers wlrMods = {0};
|
||||||
|
@ -1127,6 +1132,8 @@ void CInputManager::destroyKeyboard(SKeyboard* pKeyboard) {
|
||||||
pKeyboard->hyprListener_keyboardMod.removeCallback();
|
pKeyboard->hyprListener_keyboardMod.removeCallback();
|
||||||
pKeyboard->hyprListener_keyboardKey.removeCallback();
|
pKeyboard->hyprListener_keyboardKey.removeCallback();
|
||||||
|
|
||||||
|
xkb_state_unref(pKeyboard->xkbTranslationState);
|
||||||
|
|
||||||
if (pKeyboard->active) {
|
if (pKeyboard->active) {
|
||||||
m_lKeyboards.remove(*pKeyboard);
|
m_lKeyboards.remove(*pKeyboard);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue