diff --git a/src/config/ConfigDescriptions.hpp b/src/config/ConfigDescriptions.hpp index f2d384b2..a3a6e1b0 100644 --- a/src/config/ConfigDescriptions.hpp +++ b/src/config/ConfigDescriptions.hpp @@ -683,9 +683,9 @@ inline static const std::vector CONFIG_OPTIONS = { SConfigOptionDescription{ .value = "input:virtualkeyboard:share_states", - .description = "Unify key down states and modifier states with other keyboards", - .type = CONFIG_OPTION_BOOL, - .data = SConfigOptionDescription::SBoolData{false}, + .description = "Unify key down states and modifier states with other keyboards. 0 -> no, 1 -> yes, 2 -> yes unless IME client", + .type = CONFIG_OPTION_INT, + .data = SConfigOptionDescription::SRangeData{2, 0, 2}, }, SConfigOptionDescription{ .value = "input:virtualkeyboard:release_pressed_on_close", diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index bf94152d..db0dd596 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -690,7 +690,7 @@ CConfigManager::CConfigManager() { registerConfigVar("input:touchdevice:transform", Hyprlang::INT{-1}); registerConfigVar("input:touchdevice:output", {"[[Auto]]"}); registerConfigVar("input:touchdevice:enabled", Hyprlang::INT{1}); - registerConfigVar("input:virtualkeyboard:share_states", Hyprlang::INT{0}); + registerConfigVar("input:virtualkeyboard:share_states", Hyprlang::INT{2}); registerConfigVar("input:virtualkeyboard:release_pressed_on_close", Hyprlang::INT{0}); registerConfigVar("input:tablet:transform", Hyprlang::INT{0}); registerConfigVar("input:tablet:output", {STRVAL_EMPTY}); diff --git a/src/devices/IKeyboard.cpp b/src/devices/IKeyboard.cpp index 7e6320e2..20292176 100644 --- a/src/devices/IKeyboard.cpp +++ b/src/devices/IKeyboard.cpp @@ -447,3 +447,8 @@ bool IKeyboard::getPressed(uint32_t key) { bool IKeyboard::shareStates() { return m_shareStates; } + +void IKeyboard::setShareStatesAuto(bool shareStates) { + if (m_shareStatesAuto) + m_shareStates = shareStates; +} diff --git a/src/devices/IKeyboard.hpp b/src/devices/IKeyboard.hpp index eb213254..6f34063a 100644 --- a/src/devices/IKeyboard.hpp +++ b/src/devices/IKeyboard.hpp @@ -79,6 +79,7 @@ class IKeyboard : public IHID { void updateKeymapFD(); bool getPressed(uint32_t key); bool shareStates(); + void setShareStatesAuto(bool shareStates); bool m_active = false; bool m_enabled = true; @@ -131,5 +132,6 @@ class IKeyboard : public IHID { protected: bool updatePressed(uint32_t key, bool pressed); - bool m_shareStates = true; + bool m_shareStates = true; + bool m_shareStatesAuto = true; }; diff --git a/src/devices/VirtualKeyboard.cpp b/src/devices/VirtualKeyboard.cpp index 97b7626a..2951f36a 100644 --- a/src/devices/VirtualKeyboard.cpp +++ b/src/devices/VirtualKeyboard.cpp @@ -44,8 +44,11 @@ CVirtualKeyboard::CVirtualKeyboard(SP keeb_) : m_key m_keyboardEvents.keymap.emit(event); }); - m_deviceName = keeb_->m_name; - m_shareStates = g_pConfigManager->getDeviceInt(m_deviceName, "share_states", "input:virtualkeyboard:share_states"); + m_deviceName = keeb_->m_name; + + const auto SHARESTATES = g_pConfigManager->getDeviceInt(m_deviceName, "share_states", "input:virtualkeyboard:share_states"); + m_shareStates = SHARESTATES != 0; + m_shareStatesAuto = SHARESTATES == 2; } bool CVirtualKeyboard::isVirtual() { diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index ea164842..fa7efb6a 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1479,6 +1479,7 @@ void CInputManager::onKeyboardMod(SP pKeyboard) { auto MODS = pKeyboard->m_modifiersState; const auto ALLMODS = shareModsFromAllKBs(MODS.depressed); MODS.depressed = ALLMODS; + m_lastMods = MODS.depressed; const auto IME = m_relay.m_inputMethod.lock(); @@ -1488,7 +1489,6 @@ void CInputManager::onKeyboardMod(SP pKeyboard) { } else { g_pSeatManager->setKeyboard(pKeyboard); g_pSeatManager->sendKeyboardMods(MODS.depressed, MODS.latched, MODS.locked, MODS.group); - m_lastMods = MODS.depressed; } updateKeyboardsLeds(pKeyboard); @@ -1506,12 +1506,20 @@ void CInputManager::onKeyboardMod(SP pKeyboard) { } bool CInputManager::shouldIgnoreVirtualKeyboard(SP pKeyboard) { + if (!pKeyboard) + return true; + if (!pKeyboard->isVirtual()) return false; - auto client = pKeyboard->getClient(); + const auto CLIENT = pKeyboard->getClient(); - return !pKeyboard || (client && !m_relay.m_inputMethod.expired() && m_relay.m_inputMethod->grabClient() == client); + const auto DISALLOWACTION = CLIENT && !m_relay.m_inputMethod.expired() && m_relay.m_inputMethod->grabClient() == CLIENT; + + if (DISALLOWACTION) + pKeyboard->setShareStatesAuto(false); + + return DISALLOWACTION; } void CInputManager::refocus(std::optional overridePos) {