From c2ea4f4389c0b9a3a9534c932028abe8f02fec21 Mon Sep 17 00:00:00 2001 From: JS Deck Date: Sat, 20 Sep 2025 12:57:39 -0300 Subject: [PATCH] vkeyboard: update cached mods before IME; add share_states = 2 config option (#11720) --- src/config/ConfigDescriptions.hpp | 6 +++--- src/config/ConfigManager.cpp | 2 +- src/devices/IKeyboard.cpp | 5 +++++ src/devices/IKeyboard.hpp | 4 +++- src/devices/VirtualKeyboard.cpp | 7 +++++-- src/managers/input/InputManager.cpp | 14 +++++++++++--- 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/config/ConfigDescriptions.hpp b/src/config/ConfigDescriptions.hpp index 20efb5a3e..1c9a79ef1 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 01f910d6e..aded7c270 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 ad9e40d8c..aed32a451 100644 --- a/src/devices/IKeyboard.cpp +++ b/src/devices/IKeyboard.cpp @@ -429,3 +429,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 c78325484..ca969bf92 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; @@ -128,5 +129,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 97b7626a1..2951f36ad 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 c803363f1..21b3fc892 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1480,6 +1480,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(); @@ -1489,7 +1490,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); @@ -1507,12 +1507,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) {