Skip to content

Commit c0a272a

Browse files
committed
Add fcitx4's show input method status when focus in.
1 parent 1ff1571 commit c0a272a

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/lib/fcitx/globalconfig.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ FCITX_CONFIGURATION(
105105
Option<bool> showInputMethodInformation{
106106
this, "ShowInputMethodInformation",
107107
_("Show Input Method Information when switch input method"), true};
108+
Option<bool> showInputMethodInformationWhenFocusIn{
109+
this, "showInputMethodInformationWhenFocusIn",
110+
_("Show Input Method Information when changing focus"), false};
108111
Option<int, IntConstrain> defaultPageSize{this, "DefaultPageSize",
109112
_("Default page size"), 5,
110113
IntConstrain(1, 10)};
@@ -190,6 +193,11 @@ bool GlobalConfig::showInputMethodInformation() const {
190193
return d->behavior->showInputMethodInformation.value();
191194
}
192195

196+
bool GlobalConfig::showInputMethodInformationWhenFocusIn() const {
197+
FCITX_D();
198+
return d->behavior->showInputMethodInformationWhenFocusIn.value();
199+
}
200+
193201
const KeyList &GlobalConfig::defaultPrevPage() const {
194202
FCITX_D();
195203
return d->hotkey->defaultPrevPage.value();

src/lib/fcitx/globalconfig.h

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class FCITXCORE_EXPORT GlobalConfig {
4545
const KeyList &enumerateGroupBackwardKeys() const;
4646
bool activeByDefault() const;
4747
bool showInputMethodInformation() const;
48+
bool showInputMethodInformationWhenFocusIn() const;
4849

4950
const KeyList &defaultPrevPage() const;
5051
const KeyList &defaultNextPage() const;

src/lib/fcitx/instance.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ class InstancePrivate : public QPtrHolder<Instance> {
318318

319319
std::vector<ScopedConnection> connections_;
320320
std::unique_ptr<EventSourceTime> imGroupInfoTimer_;
321+
std::unique_ptr<EventSourceTime> focusInImInfoTimer_;
321322

322323
std::unordered_map<std::string,
323324
std::unordered_map<std::string, xkb_keymap_autoptr>>
@@ -643,9 +644,24 @@ Instance::Instance(int argc, char **argv) {
643644
}));
644645
d->eventWatchers_.emplace_back(d->watchEvent(
645646
EventType::InputContextFocusIn, EventWatcherPhase::ReservedFirst,
646-
[this](Event &event) {
647+
[this, d](Event &event) {
647648
auto &icEvent = static_cast<InputContextEvent &>(event);
648649
activateInputMethod(icEvent);
650+
if (!d->globalConfig_.showInputMethodInformationWhenFocusIn()) {
651+
return;
652+
}
653+
// Give some time because the cursor location may need some time
654+
// to be updated.
655+
d->focusInImInfoTimer_ = d->eventLoop_.addTimeEvent(
656+
CLOCK_MONOTONIC, now(CLOCK_MONOTONIC) + 30000, 0,
657+
[this, icRef = icEvent.inputContext()->watch()](
658+
EventSourceTime *, uint64_t) {
659+
// Check if ic is still valid and has focus.
660+
if (auto ic = icRef.get(); ic && ic->hasFocus()) {
661+
showInputMethodInformation(ic);
662+
}
663+
return true;
664+
});
649665
}));
650666
d->eventWatchers_.emplace_back(d->watchEvent(
651667
EventType::InputContextFocusOut, EventWatcherPhase::ReservedFirst,

0 commit comments

Comments
 (0)