Skip to content

Commit

Permalink
The virtual keyboard should show or hide automatically if enabled
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kingysu committed Jul 28, 2024
1 parent c453e95 commit de2cffe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/lib/fcitx/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ||
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions src/lib/fcitx/userinterfacemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit de2cffe

Please sign in to comment.