From a91ed7b87806774889bb6defe20c318125cd1567 Mon Sep 17 00:00:00 2001 From: liulinsong Date: Sat, 6 Jul 2024 15:26:28 +0800 Subject: [PATCH] The virtual keyboard should show or hide automatically if enabled 1. When the user interacts with some applications rather than the virtual keyboard itself, the virtual keyboard should show or hide if it is enabled. 2. For example, if the user clicks a window and the window has a text input control which has the focus and accepts the input from the keyboard, then the virtual keyboard should show automatically if the auto show switch is enabled. 3. Then, if the window loses the focus, the virtual keyboard should hide automatically if the auto hide switch is enabled. --- src/lib/fcitx/instance.cpp | 17 +++++++---------- src/lib/fcitx/instance_p.h | 4 ++-- src/lib/fcitx/userinterfacemanager.cpp | 10 ++++++++++ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/lib/fcitx/instance.cpp b/src/lib/fcitx/instance.cpp index d2e9aa23f..4215bf3fc 100644 --- a/src/lib/fcitx/instance.cpp +++ b/src/lib/fcitx/instance.cpp @@ -1042,11 +1042,9 @@ Instance::Instance(int argc, char **argv) { activateInputMethod(icEvent); - if (virtualKeyboardAutoShow()) { - auto *inputContext = icEvent.inputContext(); - if (!inputContext->clientControlVirtualkeyboardShow()) { - inputContext->showVirtualKeyboard(); - } + auto *inputContext = icEvent.inputContext(); + if (!inputContext->clientControlVirtualkeyboardShow()) { + inputContext->showVirtualKeyboard(); } if (!d->globalConfig_.showInputMethodInformationWhenFocusIn() || @@ -1091,11 +1089,10 @@ Instance::Instance(int argc, char **argv) { d->lastUnFocusedProgram_ = icEvent.inputContext()->program(); d->lastUnFocusedIc_ = icEvent.inputContext()->watch(); deactivateInputMethod(icEvent); - if (virtualKeyboardAutoHide()) { - auto *inputContext = icEvent.inputContext(); - if (!inputContext->clientControlVirtualkeyboardHide()) { - inputContext->hideVirtualKeyboard(); - } + + auto *inputContext = icEvent.inputContext(); + if (!inputContext->clientControlVirtualkeyboardHide()) { + inputContext->hideVirtualKeyboard(); } })); d->eventWatchers_.emplace_back(d->watchEvent( diff --git a/src/lib/fcitx/instance_p.h b/src/lib/fcitx/instance_p.h index 4676d89a4..541a976c9 100644 --- a/src/lib/fcitx/instance_p.h +++ b/src/lib/fcitx/instance_p.h @@ -219,9 +219,9 @@ class InstancePrivate : public QPtrHolder { std::string lastGroup_; - bool virtualKeyboardAutoShow_ = true; + bool virtualKeyboardAutoShow_ = false; - bool virtualKeyboardAutoHide_ = true; + bool virtualKeyboardAutoHide_ = false; VirtualKeyboardFunctionMode virtualKeyboardFunctionMode_ = VirtualKeyboardFunctionMode::Full; diff --git a/src/lib/fcitx/userinterfacemanager.cpp b/src/lib/fcitx/userinterfacemanager.cpp index fa9e2698e..19178b09a 100644 --- a/src/lib/fcitx/userinterfacemanager.cpp +++ b/src/lib/fcitx/userinterfacemanager.cpp @@ -333,6 +333,11 @@ bool UserInterfaceManager::isVirtualKeyboardVisible() const { void UserInterfaceManager::showVirtualKeyboard() const { FCITX_D(); + auto *instance = d->addonManager_->instance(); + if (!instance->virtualKeyboardAutoShow()) { + return; + } + auto *ui = d->ui_; if (ui == nullptr || ui->addonInfo() == nullptr || ui->addonInfo()->uiType() != UIType::OnScreenKeyboard) { @@ -346,6 +351,11 @@ void UserInterfaceManager::showVirtualKeyboard() const { void UserInterfaceManager::hideVirtualKeyboard() const { FCITX_D(); + auto *instance = d->addonManager_->instance(); + if (!instance->virtualKeyboardAutoHide()) { + return; + } + auto *ui = d->ui_; if (ui == nullptr || ui->addonInfo() == nullptr || ui->addonInfo()->uiType() != UIType::OnScreenKeyboard) {