mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-23 01:25:58 +01:00
use a custom translation state in keybinds
This commit is contained in:
parent
5e1f2539cb
commit
0f63077a07
3 changed files with 45 additions and 1 deletions
|
@ -94,13 +94,51 @@ uint32_t CKeybindManager::stringToModMask(std::string mods) {
|
||||||
return modMask;
|
return modMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CKeybindManager::updateXKBTranslationState() {
|
||||||
|
if (m_pXKBTranslationState) {
|
||||||
|
xkb_keymap_unref(xkb_state_get_keymap(m_pXKBTranslationState));
|
||||||
|
xkb_state_unref(m_pXKBTranslationState);
|
||||||
|
|
||||||
|
m_pXKBTranslationState = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto FILEPATH = g_pConfigManager->getString("input:kb_file");
|
||||||
|
const auto RULES = g_pConfigManager->getString("input:kb_rules");
|
||||||
|
const auto MODEL = g_pConfigManager->getString("input:kb_model");
|
||||||
|
const auto LAYOUT = g_pConfigManager->getString("input:kb_layout");
|
||||||
|
const auto VARIANT = g_pConfigManager->getString("input:kb_variant");
|
||||||
|
const auto OPTIONS = g_pConfigManager->getString("input:kb_options");
|
||||||
|
|
||||||
|
xkb_rule_names rules = {
|
||||||
|
.rules = RULES.c_str(),
|
||||||
|
.model = MODEL.c_str(),
|
||||||
|
.layout = LAYOUT.c_str(),
|
||||||
|
.variant = VARIANT.c_str(),
|
||||||
|
.options = OPTIONS.c_str()};
|
||||||
|
|
||||||
|
const auto PCONTEXT = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||||
|
|
||||||
|
const auto PKEYMAP = FILEPATH == "" ? xkb_keymap_new_from_names(PCONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS) : xkb_keymap_new_from_file(PCONTEXT, fopen(FILEPATH.c_str(), "r"), XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||||
|
|
||||||
|
xkb_context_unref(PCONTEXT);
|
||||||
|
m_pXKBTranslationState = xkb_state_new(PKEYMAP);
|
||||||
|
}
|
||||||
|
|
||||||
bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard) {
|
bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard) {
|
||||||
if (pKeyboard->isVirtual)
|
if (pKeyboard->isVirtual)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (!m_pXKBTranslationState) {
|
||||||
|
Debug::log(ERR, "BUG THIS: m_pXKBTranslationState NULL!");
|
||||||
|
updateXKBTranslationState();
|
||||||
|
|
||||||
|
if (!m_pXKBTranslationState)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
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(wlr_keyboard_from_input_device(pKeyboard->keyboard)->xkb_state, KEYCODE);
|
const xkb_keysym_t keysym = xkb_state_key_get_one_sym(m_pXKBTranslationState, KEYCODE);
|
||||||
|
|
||||||
const auto MODS = g_pInputManager->accumulateModsFromAllKBs();
|
const auto MODS = g_pInputManager->accumulateModsFromAllKBs();
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,10 @@ private:
|
||||||
bool handleInternalKeybinds(xkb_keysym_t);
|
bool handleInternalKeybinds(xkb_keysym_t);
|
||||||
bool handleVT(xkb_keysym_t);
|
bool handleVT(xkb_keysym_t);
|
||||||
|
|
||||||
|
xkb_state* m_pXKBTranslationState = nullptr;
|
||||||
|
|
||||||
|
void updateXKBTranslationState();
|
||||||
|
|
||||||
// -------------- Dispatchers -------------- //
|
// -------------- Dispatchers -------------- //
|
||||||
static void killActive(std::string);
|
static void killActive(std::string);
|
||||||
static void spawn(std::string);
|
static void spawn(std::string);
|
||||||
|
|
|
@ -507,6 +507,8 @@ void CInputManager::newVirtualKeyboard(wlr_input_device* keyboard) {
|
||||||
void CInputManager::setKeyboardLayout() {
|
void CInputManager::setKeyboardLayout() {
|
||||||
for (auto& k : m_lKeyboards)
|
for (auto& k : m_lKeyboards)
|
||||||
applyConfigToKeyboard(&k);
|
applyConfigToKeyboard(&k);
|
||||||
|
|
||||||
|
g_pKeybindManager->updateXKBTranslationState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInputManager::applyConfigToKeyboard(SKeyboard* pKeyboard) {
|
void CInputManager::applyConfigToKeyboard(SKeyboard* pKeyboard) {
|
||||||
|
|
Loading…
Reference in a new issue