Skip to content

Commit

Permalink
The virtual keyboard should show or hide automatically if enabled (#1086
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 authored Dec 4, 2024
1 parent 39b2d94 commit 552f7d1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 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
4 changes: 2 additions & 2 deletions src/lib/fcitx/instance_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ class InstancePrivate : public QPtrHolder<Instance> {

std::string lastGroup_;

bool virtualKeyboardAutoShow_ = true;
bool virtualKeyboardAutoShow_ = false;

bool virtualKeyboardAutoHide_ = true;
bool virtualKeyboardAutoHide_ = false;

VirtualKeyboardFunctionMode virtualKeyboardFunctionMode_ =
VirtualKeyboardFunctionMode::Full;
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 552f7d1

Please sign in to comment.