8
8
9
9
#include < fcntl.h>
10
10
#include < unistd.h>
11
+ #include < algorithm>
12
+ #include < array>
13
+ #include < cassert>
11
14
#include < csignal>
12
15
#include < cstdint>
13
- #include < ctime>
16
+ #include < cstdlib>
17
+ #include < filesystem>
14
18
#include < functional>
19
+ #include < iostream>
20
+ #include < iterator>
15
21
#include < memory>
22
+ #include < optional>
16
23
#include < stdexcept>
17
24
#include < string>
25
+ #include < string_view>
26
+ #include < tuple>
18
27
#include < unordered_map>
28
+ #include < unordered_set>
19
29
#include < utility>
30
+ #include < vector>
20
31
#include < getopt.h>
32
+ #include " fcitx-config/configuration.h"
21
33
#include " fcitx-config/iniparser.h"
34
+ #include " fcitx-config/option.h"
22
35
#include " fcitx-utils/capabilityflags.h"
36
+ #include " fcitx-utils/cutf8.h"
23
37
#include " fcitx-utils/environ.h"
24
38
#include " fcitx-utils/event.h"
25
39
#include " fcitx-utils/eventdispatcher.h"
26
40
#include " fcitx-utils/eventloopinterface.h"
41
+ #include " fcitx-utils/fs.h"
42
+ #include " fcitx-utils/handlertable.h"
27
43
#include " fcitx-utils/i18n.h"
28
44
#include " fcitx-utils/key.h"
45
+ #include " fcitx-utils/keysym.h"
29
46
#include " fcitx-utils/log.h"
30
47
#include " fcitx-utils/macros.h"
31
48
#include " fcitx-utils/misc.h"
32
49
#include " fcitx-utils/misc_p.h"
33
50
#include " fcitx-utils/standardpaths.h"
34
51
#include " fcitx-utils/stringutils.h"
52
+ #include " fcitx-utils/textformatflags.h"
35
53
#include " fcitx-utils/utf8.h"
36
54
#include " ../../modules/notifications/notifications_public.h"
37
55
#include " addonmanager.h"
47
65
#include " instance.h"
48
66
#include " instance_p.h"
49
67
#include " misc_p.h"
68
+ #include " statusarea.h"
69
+ #include " text.h"
70
+ #include " userinterface.h"
50
71
#include " userinterfacemanager.h"
51
72
52
73
#ifdef HAVE_SYS_WAIT_H
@@ -264,7 +285,8 @@ void InstancePrivate::buildDefaultGroup() {
264
285
// / Figure out XKB layout information from system.
265
286
auto *defaultGroup = q_func ()->defaultFocusGroup ();
266
287
bool infoFound = false ;
267
- std::string layouts, variants;
288
+ std::string layouts;
289
+ std::string variants;
268
290
auto guessLayout = [this , &layouts, &variants,
269
291
&infoFound](FocusGroup *focusGroup) {
270
292
// For now we can only do this on X11.
@@ -746,36 +768,37 @@ Instance::Instance(int argc, char **argv) {
746
768
std::function<bool ()> check;
747
769
std::function<void (bool )> trigger;
748
770
} keyHandlers[] = {
749
- {d->globalConfig_ .triggerKeys (),
750
- [this ]() { return canTrigger (); },
751
- [this , ic](bool totallyReleased) {
752
- return trigger (ic, totallyReleased);
753
- }},
754
- {d->globalConfig_ .altTriggerKeys (),
755
- [this , ic]() { return canAltTrigger (ic); },
756
- [this , ic](bool ) { return altTrigger (ic); }},
757
- {d->globalConfig_ .activateKeys (),
758
- [ic, d]() { return d->canActivate (ic); },
759
- [this , ic](bool ) { return activate (ic); }},
760
- {d->globalConfig_ .deactivateKeys (),
761
- [ic, d]() { return d->canDeactivate (ic); },
762
- [this , ic](bool ) { return deactivate (ic); }},
763
- {d->globalConfig_ .enumerateForwardKeys (),
764
- [this , ic]() { return canEnumerate (ic); },
765
- [this , ic](bool ) { return enumerate(ic, true ); }},
766
- {d->globalConfig_ .enumerateBackwardKeys (),
767
- [this , ic]() { return canEnumerate (ic); },
768
- [this , ic](bool ) { return enumerate(ic, false ); }},
769
- {d->globalConfig_ .enumerateGroupForwardKeys (),
770
- [this ]() { return canChangeGroup (); },
771
- [ic, d, origKey](bool ) {
772
- return d->navigateGroup (ic, origKey, true );
773
- }},
774
- {d->globalConfig_ .enumerateGroupBackwardKeys (),
775
- [this ]() { return canChangeGroup (); },
776
- [ic, d, origKey](bool ) {
777
- return d->navigateGroup (ic, origKey, false );
778
- }},
771
+ {.list = d->globalConfig_ .triggerKeys (),
772
+ .check = [this ]() { return canTrigger (); },
773
+ .trigger =
774
+ [this , ic](bool totallyReleased) {
775
+ return trigger (ic, totallyReleased);
776
+ }},
777
+ {.list = d->globalConfig_ .altTriggerKeys (),
778
+ .check = [this , ic]() { return canAltTrigger (ic); },
779
+ .trigger = [this , ic](bool ) { return altTrigger (ic); }},
780
+ {.list = d->globalConfig_ .activateKeys (),
781
+ .check = [ic, d]() { return d->canActivate (ic); },
782
+ .trigger = [this , ic](bool ) { return activate (ic); }},
783
+ {.list = d->globalConfig_ .deactivateKeys (),
784
+ .check = [ic, d]() { return d->canDeactivate (ic); },
785
+ .trigger = [this , ic](bool ) { return deactivate (ic); }},
786
+ {.list = d->globalConfig_ .enumerateForwardKeys (),
787
+ .check = [this , ic]() { return canEnumerate (ic); },
788
+ .trigger = [this , ic](bool ) { return enumerate(ic, true ); }},
789
+ {.list = d->globalConfig_ .enumerateBackwardKeys (),
790
+ .check = [this , ic]() { return canEnumerate (ic); },
791
+ .trigger = [this , ic](bool ) { return enumerate(ic, false ); }},
792
+ {.list = d->globalConfig_ .enumerateGroupForwardKeys (),
793
+ .check = [this ]() { return canChangeGroup (); },
794
+ .trigger = [ic, d, origKey](
795
+ bool ) { d->navigateGroup (ic, origKey, true ); }},
796
+ {.list = d->globalConfig_ .enumerateGroupBackwardKeys (),
797
+ .check = [this ]() { return canChangeGroup (); },
798
+ .trigger =
799
+ [ic, d, origKey](bool ) {
800
+ d->navigateGroup (ic, origKey, false );
801
+ }},
779
802
};
780
803
781
804
auto *inputState = ic->propertyFor (&d->inputStateFactory_ );
@@ -833,13 +856,15 @@ Instance::Instance(int argc, char **argv) {
833
856
now (CLOCK_MONOTONIC);
834
857
// don't forward to input method, but make it pass
835
858
// through to client.
836
- return keyEvent.filter ();
859
+ keyEvent.filter ();
860
+ return ;
837
861
}
838
862
keyHandler.trigger (inputState->totallyReleased_ );
839
863
if (origKey.hasModifier ()) {
840
864
inputState->totallyReleased_ = false ;
841
865
}
842
- return keyEvent.filterAndAccept ();
866
+ keyEvent.filterAndAccept ();
867
+ return ;
843
868
}
844
869
idx++;
845
870
}
@@ -906,7 +931,7 @@ Instance::Instance(int argc, char **argv) {
906
931
auto newSym = xkb_state_key_get_one_sym (
907
932
xkbState, keyEvent.rawKey ().code ());
908
933
auto newModifier = KeyStates (effective);
909
- auto keymap = xkb_state_get_keymap (xkbState);
934
+ auto * keymap = xkb_state_get_keymap (xkbState);
910
935
if (keyEvent.rawKey ().states ().test (KeyState::Repeat) &&
911
936
xkb_keymap_key_repeats (keymap, keyEvent.rawKey ().code ())) {
912
937
newModifier |= KeyState::Repeat;
@@ -1417,7 +1442,7 @@ void Instance::initialize() {
1417
1442
}
1418
1443
// Preload first input method.
1419
1444
if (!d->imManager_ .currentGroup ().inputMethodList ().empty ()) {
1420
- if (auto entry =
1445
+ if (const auto * entry =
1421
1446
d->imManager_ .entry (d->imManager_ .currentGroup ()
1422
1447
.inputMethodList ()[0 ]
1423
1448
.name ())) {
@@ -1426,7 +1451,7 @@ void Instance::initialize() {
1426
1451
}
1427
1452
// Preload default input method.
1428
1453
if (!d->imManager_ .currentGroup ().defaultInputMethod ().empty ()) {
1429
- if (auto entry = d->imManager_ .entry (
1454
+ if (const auto * entry = d->imManager_ .entry (
1430
1455
d->imManager_ .currentGroup ().defaultInputMethod ())) {
1431
1456
d->addonManager_ .addon (entry->addon (), true );
1432
1457
}
@@ -1542,7 +1567,7 @@ bool Instance::canRestart() const {
1542
1567
return d->binaryMode_ &&
1543
1568
std::all_of (addonNames.begin (), addonNames.end (),
1544
1569
[d](const std::string &name) {
1545
- auto addon = d->addonManager_ .lookupAddon (name);
1570
+ auto * addon = d->addonManager_ .lookupAddon (name);
1546
1571
if (!addon) {
1547
1572
return true ;
1548
1573
}
@@ -1606,7 +1631,7 @@ bool Instance::postEvent(Event &event) const {
1606
1631
}
1607
1632
auto iter = d->eventHandlers_ .find (event.type ());
1608
1633
if (iter != d->eventHandlers_ .end ()) {
1609
- auto &handlers = iter->second ;
1634
+ const auto &handlers = iter->second ;
1610
1635
EventWatcherPhase phaseOrder[] = {
1611
1636
EventWatcherPhase::ReservedFirst, EventWatcherPhase::PreInputMethod,
1612
1637
EventWatcherPhase::InputMethod, EventWatcherPhase::PostInputMethod,
@@ -1692,7 +1717,7 @@ std::string Instance::inputMethod(InputContext *ic) {
1692
1717
return inputState->overrideDeactivateIM_ ;
1693
1718
}
1694
1719
1695
- auto &group = d->imManager_ .currentGroup ();
1720
+ const auto &group = d->imManager_ .currentGroup ();
1696
1721
if (ic->capabilityFlags ().test (CapabilityFlag::Disable) ||
1697
1722
(ic->capabilityFlags ().test (CapabilityFlag::Password) &&
1698
1723
!d->globalConfig_ .allowInputMethodForPassword ())) {
@@ -1813,9 +1838,8 @@ uint32_t Instance::processCompose(InputContext *ic, KeySym keysym) {
1813
1838
return FCITX_INVALID_COMPOSE_RESULT;
1814
1839
}
1815
1840
1816
- uint32_t c = 0 ;
1817
- fcitx_utf8_get_char (buffer, &c);
1818
- return c;
1841
+ uint32_t c = utf8::getChar (buffer);
1842
+ return utf8::isValidChar (c) ? c : 0 ;
1819
1843
}
1820
1844
if (status == XKB_COMPOSE_CANCELLED) {
1821
1845
xkb_compose_state_reset (xkbComposeState);
@@ -1863,8 +1887,8 @@ std::optional<std::string> Instance::processComposeString(InputContext *ic,
1863
1887
return std::nullopt;
1864
1888
}
1865
1889
1866
- const auto bufferBegin = buffer.begin ();
1867
- const auto bufferEnd = std::next (bufferBegin, length);
1890
+ auto bufferBegin = buffer.begin ();
1891
+ auto bufferEnd = std::next (bufferBegin, length);
1868
1892
if (utf8::validate (bufferBegin, bufferEnd)) {
1869
1893
return std::string (bufferBegin, bufferEnd);
1870
1894
}
@@ -1942,9 +1966,9 @@ void Instance::configure() {
1942
1966
{StandardPaths::fcitxPath (" bindir" , " fcitx5-configtool" ).string ()});
1943
1967
}
1944
1968
1945
- void Instance::configureAddon (const std::string &) {}
1969
+ void Instance::configureAddon (const std::string & /* unused */ ) {}
1946
1970
1947
- void Instance::configureInputMethod (const std::string &) {}
1971
+ void Instance::configureInputMethod (const std::string & /* unused */ ) {}
1948
1972
1949
1973
std::string Instance::currentInputMethod () {
1950
1974
if (auto *ic = mostRecentInputContext ()) {
@@ -2275,10 +2299,10 @@ bool Instance::enumerate(InputContext *ic, bool forward) {
2275
2299
2276
2300
auto currentIM = inputMethod (ic);
2277
2301
2278
- auto iter = std::find_if (imList. begin (), imList. end (),
2279
- [¤tIM](const InputMethodGroupItem &item) {
2280
- return item.name () == currentIM;
2281
- });
2302
+ auto iter = std::ranges:: find_if (
2303
+ imList, [¤tIM](const InputMethodGroupItem &item) {
2304
+ return item.name () == currentIM;
2305
+ });
2282
2306
if (iter == imList.end ()) {
2283
2307
return false ;
2284
2308
}
@@ -2515,7 +2539,8 @@ void Instance::showCustomInputMethodInformation(InputContext *ic,
2515
2539
2516
2540
bool Instance::checkUpdate () const {
2517
2541
FCITX_D ();
2518
- return (isInFlatpak () && fs::isreg (" /app/.updated" )) ||
2542
+ return (isInFlatpak () &&
2543
+ std::filesystem::is_regular_file (" /app/.updated" )) ||
2519
2544
d->addonManager_ .checkUpdate () || d->imManager_ .checkUpdate () ||
2520
2545
postEvent (CheckUpdateEvent ());
2521
2546
}
@@ -2543,7 +2568,7 @@ void Instance::setXkbParameters(const std::string &display,
2543
2568
d->keymapCache_ [display].clear ();
2544
2569
d->icManager_ .foreach ([d, &display](InputContext *ic) {
2545
2570
if (ic->display () == display ||
2546
- d->xkbParams_ .count (ic->display ()) == 0 ) {
2571
+ ! d->xkbParams_ .contains (ic->display ())) {
2547
2572
auto *inputState = ic->propertyFor (&d->inputStateFactory_ );
2548
2573
inputState->resetXkbState ();
2549
2574
}
0 commit comments