88
99#include < fcntl.h>
1010#include < unistd.h>
11+ #include < algorithm>
12+ #include < array>
13+ #include < cassert>
1114#include < csignal>
1215#include < cstdint>
13- #include < ctime>
16+ #include < cstdlib>
17+ #include < filesystem>
1418#include < functional>
19+ #include < iostream>
20+ #include < iterator>
1521#include < memory>
22+ #include < optional>
1623#include < stdexcept>
1724#include < string>
25+ #include < string_view>
26+ #include < tuple>
1827#include < unordered_map>
28+ #include < unordered_set>
1929#include < utility>
30+ #include < vector>
2031#include < getopt.h>
32+ #include " fcitx-config/configuration.h"
2133#include " fcitx-config/iniparser.h"
34+ #include " fcitx-config/option.h"
2235#include " fcitx-utils/capabilityflags.h"
36+ #include " fcitx-utils/cutf8.h"
2337#include " fcitx-utils/environ.h"
2438#include " fcitx-utils/event.h"
2539#include " fcitx-utils/eventdispatcher.h"
2640#include " fcitx-utils/eventloopinterface.h"
41+ #include " fcitx-utils/fs.h"
42+ #include " fcitx-utils/handlertable.h"
2743#include " fcitx-utils/i18n.h"
2844#include " fcitx-utils/key.h"
45+ #include " fcitx-utils/keysym.h"
2946#include " fcitx-utils/log.h"
3047#include " fcitx-utils/macros.h"
3148#include " fcitx-utils/misc.h"
3249#include " fcitx-utils/misc_p.h"
3350#include " fcitx-utils/standardpaths.h"
3451#include " fcitx-utils/stringutils.h"
52+ #include " fcitx-utils/textformatflags.h"
3553#include " fcitx-utils/utf8.h"
3654#include " ../../modules/notifications/notifications_public.h"
3755#include " addonmanager.h"
4765#include " instance.h"
4866#include " instance_p.h"
4967#include " misc_p.h"
68+ #include " statusarea.h"
69+ #include " text.h"
70+ #include " userinterface.h"
5071#include " userinterfacemanager.h"
5172
5273#ifdef HAVE_SYS_WAIT_H
@@ -264,7 +285,8 @@ void InstancePrivate::buildDefaultGroup() {
264285 // / Figure out XKB layout information from system.
265286 auto *defaultGroup = q_func ()->defaultFocusGroup ();
266287 bool infoFound = false ;
267- std::string layouts, variants;
288+ std::string layouts;
289+ std::string variants;
268290 auto guessLayout = [this , &layouts, &variants,
269291 &infoFound](FocusGroup *focusGroup) {
270292 // For now we can only do this on X11.
@@ -746,36 +768,37 @@ Instance::Instance(int argc, char **argv) {
746768 std::function<bool ()> check;
747769 std::function<void (bool )> trigger;
748770 } 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+ }},
779802 };
780803
781804 auto *inputState = ic->propertyFor (&d->inputStateFactory_ );
@@ -833,13 +856,15 @@ Instance::Instance(int argc, char **argv) {
833856 now (CLOCK_MONOTONIC);
834857 // don't forward to input method, but make it pass
835858 // through to client.
836- return keyEvent.filter ();
859+ keyEvent.filter ();
860+ return ;
837861 }
838862 keyHandler.trigger (inputState->totallyReleased_ );
839863 if (origKey.hasModifier ()) {
840864 inputState->totallyReleased_ = false ;
841865 }
842- return keyEvent.filterAndAccept ();
866+ keyEvent.filterAndAccept ();
867+ return ;
843868 }
844869 idx++;
845870 }
@@ -906,7 +931,7 @@ Instance::Instance(int argc, char **argv) {
906931 auto newSym = xkb_state_key_get_one_sym (
907932 xkbState, keyEvent.rawKey ().code ());
908933 auto newModifier = KeyStates (effective);
909- auto keymap = xkb_state_get_keymap (xkbState);
934+ auto * keymap = xkb_state_get_keymap (xkbState);
910935 if (keyEvent.rawKey ().states ().test (KeyState::Repeat) &&
911936 xkb_keymap_key_repeats (keymap, keyEvent.rawKey ().code ())) {
912937 newModifier |= KeyState::Repeat;
@@ -1417,7 +1442,7 @@ void Instance::initialize() {
14171442 }
14181443 // Preload first input method.
14191444 if (!d->imManager_ .currentGroup ().inputMethodList ().empty ()) {
1420- if (auto entry =
1445+ if (const auto * entry =
14211446 d->imManager_ .entry (d->imManager_ .currentGroup ()
14221447 .inputMethodList ()[0 ]
14231448 .name ())) {
@@ -1426,7 +1451,7 @@ void Instance::initialize() {
14261451 }
14271452 // Preload default input method.
14281453 if (!d->imManager_ .currentGroup ().defaultInputMethod ().empty ()) {
1429- if (auto entry = d->imManager_ .entry (
1454+ if (const auto * entry = d->imManager_ .entry (
14301455 d->imManager_ .currentGroup ().defaultInputMethod ())) {
14311456 d->addonManager_ .addon (entry->addon (), true );
14321457 }
@@ -1542,7 +1567,7 @@ bool Instance::canRestart() const {
15421567 return d->binaryMode_ &&
15431568 std::all_of (addonNames.begin (), addonNames.end (),
15441569 [d](const std::string &name) {
1545- auto addon = d->addonManager_ .lookupAddon (name);
1570+ auto * addon = d->addonManager_ .lookupAddon (name);
15461571 if (!addon) {
15471572 return true ;
15481573 }
@@ -1606,7 +1631,7 @@ bool Instance::postEvent(Event &event) const {
16061631 }
16071632 auto iter = d->eventHandlers_ .find (event.type ());
16081633 if (iter != d->eventHandlers_ .end ()) {
1609- auto &handlers = iter->second ;
1634+ const auto &handlers = iter->second ;
16101635 EventWatcherPhase phaseOrder[] = {
16111636 EventWatcherPhase::ReservedFirst, EventWatcherPhase::PreInputMethod,
16121637 EventWatcherPhase::InputMethod, EventWatcherPhase::PostInputMethod,
@@ -1692,7 +1717,7 @@ std::string Instance::inputMethod(InputContext *ic) {
16921717 return inputState->overrideDeactivateIM_ ;
16931718 }
16941719
1695- auto &group = d->imManager_ .currentGroup ();
1720+ const auto &group = d->imManager_ .currentGroup ();
16961721 if (ic->capabilityFlags ().test (CapabilityFlag::Disable) ||
16971722 (ic->capabilityFlags ().test (CapabilityFlag::Password) &&
16981723 !d->globalConfig_ .allowInputMethodForPassword ())) {
@@ -1813,9 +1838,8 @@ uint32_t Instance::processCompose(InputContext *ic, KeySym keysym) {
18131838 return FCITX_INVALID_COMPOSE_RESULT;
18141839 }
18151840
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 ;
18191843 }
18201844 if (status == XKB_COMPOSE_CANCELLED) {
18211845 xkb_compose_state_reset (xkbComposeState);
@@ -1863,8 +1887,8 @@ std::optional<std::string> Instance::processComposeString(InputContext *ic,
18631887 return std::nullopt ;
18641888 }
18651889
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);
18681892 if (utf8::validate (bufferBegin, bufferEnd)) {
18691893 return std::string (bufferBegin, bufferEnd);
18701894 }
@@ -1942,9 +1966,9 @@ void Instance::configure() {
19421966 {StandardPaths::fcitxPath (" bindir" , " fcitx5-configtool" ).string ()});
19431967}
19441968
1945- void Instance::configureAddon (const std::string &) {}
1969+ void Instance::configureAddon (const std::string & /* unused */ ) {}
19461970
1947- void Instance::configureInputMethod (const std::string &) {}
1971+ void Instance::configureInputMethod (const std::string & /* unused */ ) {}
19481972
19491973std::string Instance::currentInputMethod () {
19501974 if (auto *ic = mostRecentInputContext ()) {
@@ -2275,10 +2299,10 @@ bool Instance::enumerate(InputContext *ic, bool forward) {
22752299
22762300 auto currentIM = inputMethod (ic);
22772301
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+ });
22822306 if (iter == imList.end ()) {
22832307 return false ;
22842308 }
@@ -2515,7 +2539,8 @@ void Instance::showCustomInputMethodInformation(InputContext *ic,
25152539
25162540bool Instance::checkUpdate () const {
25172541 FCITX_D ();
2518- return (isInFlatpak () && fs::isreg (" /app/.updated" )) ||
2542+ return (isInFlatpak () &&
2543+ std::filesystem::is_regular_file (" /app/.updated" )) ||
25192544 d->addonManager_ .checkUpdate () || d->imManager_ .checkUpdate () ||
25202545 postEvent (CheckUpdateEvent ());
25212546}
@@ -2543,7 +2568,7 @@ void Instance::setXkbParameters(const std::string &display,
25432568 d->keymapCache_ [display].clear ();
25442569 d->icManager_ .foreach ([d, &display](InputContext *ic) {
25452570 if (ic->display () == display ||
2546- d->xkbParams_ .count (ic->display ()) == 0 ) {
2571+ ! d->xkbParams_ .contains (ic->display ())) {
25472572 auto *inputState = ic->propertyFor (&d->inputStateFactory_ );
25482573 inputState->resetXkbState ();
25492574 }
0 commit comments