8 #include "globalconfig.h" 13 #include "fcitx-config/configuration.h" 14 #include "fcitx-config/enum.h" 15 #include "fcitx-config/iniparser.h" 16 #include "fcitx-config/option.h" 17 #include "fcitx-config/rawconfig.h" 18 #include "fcitx-utils/eventloopinterface.h" 19 #include "fcitx-utils/i18n.h" 21 #include "fcitx-utils/macros.h" 22 #include "fcitx-utils/misc.h" 24 #include "inputcontextmanager.h" 30 #ifdef ENABLE_KEYBOARD 31 constexpr
bool hasKeyboard =
true;
33 constexpr
bool hasKeyboard =
false;
36 FCITX_CONFIG_ENUM_I18N_ANNOTATION(PropertyPropagatePolicy, N_(
"All"),
37 N_(
"Program"), N_(
"No"));
41 KeyListOption triggerKeys{
44 _(
"Toggle Input Method"),
45 {isApple() ? Key(
"Control+Shift_L") : Key(
"Control+space"),
46 Key(
"Zenkaku_Hankaku"), Key(
"Hangul")},
47 KeyListConstrain({KeyConstrainFlag::AllowModifierLess,
48 KeyConstrainFlag::AllowModifierOnly})};
49 OptionWithAnnotation<bool, ToolTipAnnotation> enumerateWithTriggerKeys{{
51 .path{
"EnumerateWithTriggerKeys"},
52 .description{_(
"Enumerate when holding modifier of Toggle key")},
55 _(
"For example, if Control+Space is the toggle key, after pressing " 56 "Control+Space for the first time, if Control is held, following " 57 "key press of Space will enumerate the input method.")},
59 KeyListOption activateKeys{
62 _(
"Activate Input Method"),
66 KeyListConstrain({KeyConstrainFlag::AllowModifierLess,
67 KeyConstrainFlag::AllowModifierOnly})};
68 KeyListOption deactivateKeys{
71 _(
"Deactivate Input Method"),
72 {Key(
"Hangul_Romaja")},
73 KeyListConstrain({KeyConstrainFlag::AllowModifierLess,
74 KeyConstrainFlag::AllowModifierOnly})};
75 KeyListOptionWithAnnotation<ToolTipAnnotation> altTriggerKeys{
77 .path{
"AltTriggerKeys"},
78 .description{_(
"Temporarily Toggle Input Method")},
79 .defaultValue{{Key(
"Shift_L")}},
80 .constrain{KeyListConstrain({KeyConstrainFlag::AllowModifierLess,
81 KeyConstrainFlag::AllowModifierOnly})},
83 "This key can only be used if current state is active, or is " 84 "deactivated with this key. For example, you have two input " 85 "methods: English as the inactive state, Pinyin as the active " 86 "state. It can be used to switch from Pinyin back to English, and " 87 "switch back to Pinyin again afterwards. If the initial state is " 88 "English will do nothing. This key can be configured to be some " 89 "simple single modifier key like Shift, so it can be used with " 90 "just a single key press, but won't be triggered by accident if " 91 "you never activate input method.")}}};
92 KeyListOption enumerateForwardKeys{
94 "EnumerateForwardKeys",
95 _(
"Enumerate Input Method Forward"),
97 KeyListConstrain({KeyConstrainFlag::AllowModifierLess,
98 KeyConstrainFlag::AllowModifierOnly})};
99 KeyListOption enumerateBackwardKeys{
101 "EnumerateBackwardKeys",
102 _(
"Enumerate Input Method Backward"),
104 KeyListConstrain({KeyConstrainFlag::AllowModifierLess,
105 KeyConstrainFlag::AllowModifierOnly})};
106 Option<bool> enumerateSkipFirst{
107 this,
"EnumerateSkipFirst",
108 _(
"Skip first input method while enumerating"),
false};
109 KeyListOption enumerateGroupForwardKeys{
111 "EnumerateGroupForwardKeys",
112 _(
"Enumerate Input Method Group Forward"),
113 {Key(
"Super+space")},
114 KeyListConstrain({KeyConstrainFlag::AllowModifierLess,
115 KeyConstrainFlag::AllowModifierOnly})};
116 KeyListOption enumerateGroupBackwardKeys{
118 "EnumerateGroupBackwardKeys",
119 _(
"Enumerate Input Method Group Backward"),
120 {Key(
"Super+Shift+space")},
121 KeyListConstrain({KeyConstrainFlag::AllowModifierLess,
122 KeyConstrainFlag::AllowModifierOnly})};
123 Option<KeyList, ListConstrain<KeyConstrain>, DefaultMarshaller<KeyList>,
128 .description{_(
"Fallback Previous page")},
129 .defaultValue{{Key(
"Up")}},
130 .constrain{{KeyConstrainFlag::AllowModifierLess}},
131 .annotation{_(
"Input methods may have different setup in their " 132 "own configuration. This is commonly used by " 133 "modules like clipboard or quickphrase.")},
136 Option<KeyList, ListConstrain<KeyConstrain>, DefaultMarshaller<KeyList>,
138 defaultNextPage{
this,
140 _(
"Fallback Next page"),
142 KeyListConstrain({KeyConstrainFlag::AllowModifierLess}),
144 {_(
"Input methods may have different setup in their " 145 "own configuration. This is commonly used by " 146 "modules like clipboard or quickphrase.")}};
147 KeyListOption defaultPrevCandidate{
150 _(
"Fallback Previous Candidate"),
152 KeyListConstrain({KeyConstrainFlag::AllowModifierLess})};
153 KeyListOption defaultNextCandidate{
156 _(
"Fallback Next Candidate"),
158 KeyListConstrain({KeyConstrainFlag::AllowModifierLess})};
159 KeyListOption togglePreedit{
this,
161 _(
"Toggle embedded preedit"),
162 {Key(
"Control+Alt+P")},
164 Option<int, IntConstrain, DefaultMarshaller<int>, ToolTipAnnotation>
165 modifierOnlyKeyTimeout{
167 "ModifierOnlyKeyTimeout",
168 _(
"Time limit in milliseconds for triggering modifier key " 171 IntConstrain{-1, 5000},
174 _(
"When using modifier only hotkey, the action may " 175 "only be triggered if the modifier key is released within " 176 "the timeout. -1 means there is no limit.")}};);
179 BehaviorConfig, Option<bool> activeByDefault{
this,
"ActiveByDefault",
180 _(
"Active By Default")};
181 OptionWithAnnotation<PropertyPropagatePolicy,
182 PropertyPropagatePolicyI18NAnnotation>
183 resetStateWhenFocusIn{
this,
"resetStateWhenFocusIn",
184 _(
"Reset state on Focus In"),
185 PropertyPropagatePolicy::No};
186 OptionWithAnnotation<PropertyPropagatePolicy,
187 PropertyPropagatePolicyI18NAnnotation>
188 shareState{
this,
"ShareInputState", _(
"Share Input State"),
189 isAndroid() ? PropertyPropagatePolicy::All
190 : PropertyPropagatePolicy::No};
191 Option<bool> preeditEnabledByDefault{
this,
"PreeditEnabledByDefault",
192 _(
"Show preedit in application"),
194 Option<bool> showInputMethodInformation{
195 this,
"ShowInputMethodInformation",
196 _(
"Show Input Method Information when switch input method"),
true};
197 Option<bool> showInputMethodInformationWhenFocusIn{
198 this,
"showInputMethodInformationWhenFocusIn",
199 _(
"Show Input Method Information when changing focus"),
false};
200 Option<bool> compactInputMethodInformation{
201 this,
"CompactInputMethodInformation",
202 _(
"Show compact input method information"),
true};
203 Option<bool> showFirstInputMethodInformation{
204 this,
"ShowFirstInputMethodInformation",
205 _(
"Show first input method information"),
true};
206 Option<int, IntConstrain> defaultPageSize{
this,
"DefaultPageSize",
207 _(
"Default page size"), 5,
208 IntConstrain(1, 10)};
209 ConditionalHidden<!hasKeyboard,
210 OptionWithAnnotation<bool, ToolTipAnnotation>>
214 _(
"Override XKB Option"),
218 {_(
"Whether to override the XKB option from display server. It " 219 "will not affect the XKB option send to display, but just the " 220 "XKB options for custom XKB layout. This is a workaround when " 221 "there is no way to get the current XKB option from Wayland " 223 ConditionalHidden<!hasKeyboard, Option<std::string>> customXkbOption{
224 this,
"CustomXkbOption", _(
"Custom XKB Option"),
""};
225 HiddenOption<std::vector<std::string>> enabledAddons{
226 this,
"EnabledAddons",
"Force Enabled Addons"};
227 HiddenOption<std::vector<std::string>> disabledAddons{
228 this,
"DisabledAddons",
"Force Disabled Addons"};
229 HiddenOption<bool> preloadInputMethod{
230 this,
"PreloadInputMethod",
231 "Preload input method to be used by default",
true};
232 Option<bool> allowInputMethodForPassword{
233 this,
"AllowInputMethodForPassword",
234 _(
"Allow input method in the password field"),
false};
235 Option<bool> showPreeditForPassword{
236 this,
"ShowPreeditForPassword",
237 _(
"Show preedit text when typing password"),
false};
238 Option<int, IntConstrain, DefaultMarshaller<int>, ToolTipAnnotation>
241 _(
"Interval of saving user data in minutes"),
243 IntConstrain(0, 1440),
245 {_(
"If value is 0, the user data may only be saved when " 246 "fcitx quits (e.g. logout).")}};);
248 FCITX_CONFIGURATION(GlobalConfig,
249 Option<HotkeyConfig> hotkey{
this,
"Hotkey", _(
"Hotkey")};
250 Option<BehaviorConfig> behavior{
this,
"Behavior",
256 GlobalConfig::GlobalConfig() : d_ptr(std::make_unique<GlobalConfigPrivate>()) {}
258 GlobalConfig::~GlobalConfig() {}
260 void GlobalConfig::load(
const RawConfig &rawConfig,
bool partial) {
262 d->load(rawConfig, partial);
265 void GlobalConfig::save(
RawConfig &config)
const {
270 bool GlobalConfig::safeSave(
const std::string &path)
const {
272 return safeSaveAsIni(*d, path);
275 const KeyList &GlobalConfig::triggerKeys()
const {
277 return *d->hotkey->triggerKeys;
280 bool GlobalConfig::enumerateWithTriggerKeys()
const {
282 return *d->hotkey->enumerateWithTriggerKeys;
285 const KeyList &GlobalConfig::altTriggerKeys()
const {
287 return *d->hotkey->altTriggerKeys;
290 const KeyList &GlobalConfig::activateKeys()
const {
292 return *d->hotkey->activateKeys;
295 const KeyList &GlobalConfig::deactivateKeys()
const {
297 return d->hotkey->deactivateKeys.value();
300 const KeyList &GlobalConfig::enumerateForwardKeys()
const {
302 return d->hotkey->enumerateForwardKeys.value();
305 const KeyList &GlobalConfig::enumerateBackwardKeys()
const {
307 return d->hotkey->enumerateBackwardKeys.value();
310 bool GlobalConfig::enumerateSkipFirst()
const {
312 return *d->hotkey->enumerateSkipFirst;
315 const KeyList &GlobalConfig::enumerateGroupForwardKeys()
const {
317 return *d->hotkey->enumerateGroupForwardKeys;
320 const KeyList &GlobalConfig::enumerateGroupBackwardKeys()
const {
322 return *d->hotkey->enumerateGroupBackwardKeys;
325 const KeyList &GlobalConfig::togglePreeditKeys()
const {
327 return *d->hotkey->togglePreedit;
330 bool GlobalConfig::activeByDefault()
const {
332 return d->behavior->activeByDefault.value();
337 return d->behavior->resetStateWhenFocusIn.value();
340 bool GlobalConfig::showInputMethodInformation()
const {
342 return d->behavior->showInputMethodInformation.value();
345 bool GlobalConfig::showInputMethodInformationWhenFocusIn()
const {
347 return d->behavior->showInputMethodInformationWhenFocusIn.value();
350 bool GlobalConfig::compactInputMethodInformation()
const {
352 return d->behavior->compactInputMethodInformation.value();
355 bool GlobalConfig::showFirstInputMethodInformation()
const {
357 return d->behavior->showFirstInputMethodInformation.value();
360 PropertyPropagatePolicy GlobalConfig::shareInputState()
const {
362 return d->behavior->shareState.value();
365 bool GlobalConfig::preeditEnabledByDefault()
const {
367 return d->behavior->preeditEnabledByDefault.value();
370 const KeyList &GlobalConfig::defaultPrevPage()
const {
372 return d->hotkey->defaultPrevPage.value();
375 const KeyList &GlobalConfig::defaultNextPage()
const {
377 return d->hotkey->defaultNextPage.value();
380 const KeyList &GlobalConfig::defaultPrevCandidate()
const {
382 return d->hotkey->defaultPrevCandidate.value();
385 const KeyList &GlobalConfig::defaultNextCandidate()
const {
387 return d->hotkey->defaultNextCandidate.value();
390 int GlobalConfig::defaultPageSize()
const {
392 return d->behavior->defaultPageSize.value();
397 return d->behavior->overrideXkbOption.value();
402 return d->behavior->customXkbOption.value();
405 const std::vector<std::string> &GlobalConfig::enabledAddons()
const {
407 return *d->behavior->enabledAddons;
410 const std::vector<std::string> &GlobalConfig::disabledAddons()
const {
412 return *d->behavior->disabledAddons;
415 void GlobalConfig::setEnabledAddons(
const std::vector<std::string> &addons) {
417 d->behavior.mutableValue()->enabledAddons.setValue(addons);
420 void GlobalConfig::setDisabledAddons(
const std::vector<std::string> &addons) {
422 d->behavior.mutableValue()->disabledAddons.setValue(addons);
425 bool GlobalConfig::preloadInputMethod()
const {
427 return *d->behavior->preloadInputMethod;
432 return *d->behavior->allowInputMethodForPassword;
437 return *d->behavior->showPreeditForPassword;
442 return *d->behavior->autoSavePeriod;
447 return *d->hotkey->modifierOnlyKeyTimeout;
451 const auto timeout = modifierOnlyKeyTimeout();
455 return now(CLOCK_MONOTONIC) <=
456 (lastPressedTime +
static_cast<uint64_t
>(timeout) * 1000ULL);
int autoSavePeriod() const
Number of minutes that fcitx will automatically save user data.
const std::string & customXkbOption() const
The enforce the xkb option for custom xkb state.
int modifierOnlyKeyTimeout() const
Number of milliseconds that modifier only key can be triggered with key release.
bool showPreeditForPassword() const
Show preedit when typing in password field.
PropertyPropagatePolicy resetStateWhenFocusIn() const
Reset active state to the value of activeByDefault on Focus In.
bool overrideXkbOption() const
Override the xkb option from display.
bool allowInputMethodForPassword() const
Allow use input method in password field.
bool checkModifierOnlyKeyTimeout(uint64_t lastPressedTime) const
Helper function to check whether the modifier only key should be triggered.
Class to represent a key.