vkeyboard: update cached mods before IME; add share_states = 2 config option (#11720)

This commit is contained in:
JS Deck 2025-09-20 12:57:39 -03:00 committed by Vaxry
parent 941f35c8b7
commit c2ea4f4389
Signed by: vaxry
GPG key ID: 665806380871D640
6 changed files with 28 additions and 10 deletions

View file

@ -683,9 +683,9 @@ inline static const std::vector<SConfigOptionDescription> 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",

View file

@ -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});

View file

@ -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;
}

View file

@ -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;
};

View file

@ -44,8 +44,11 @@ CVirtualKeyboard::CVirtualKeyboard(SP<CVirtualKeyboardV1Resource> 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() {

View file

@ -1480,6 +1480,7 @@ void CInputManager::onKeyboardMod(SP<IKeyboard> 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<IKeyboard> 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<IKeyboard> pKeyboard) {
}
bool CInputManager::shouldIgnoreVirtualKeyboard(SP<IKeyboard> 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<Vector2D> overridePos) {