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.")}};);
180 Option<bool> activeByDefault{
this,
"ActiveByDefault",
181 _(
"Activate input method by default")};
182 OptionWithAnnotation<PropertyPropagatePolicy,
183 PropertyPropagatePolicyI18NAnnotation>
184 resetStateWhenFocusIn{
this,
"resetStateWhenFocusIn",
185 _(
"Reset state on Focus In"),
186 PropertyPropagatePolicy::No};
187 OptionWithAnnotation<PropertyPropagatePolicy,
188 PropertyPropagatePolicyI18NAnnotation>
189 shareState{
this,
"ShareInputState", _(
"Share Input State"),
190 isAndroid() ? PropertyPropagatePolicy::All
191 : PropertyPropagatePolicy::No};
192 Option<bool> preeditEnabledByDefault{
this,
"PreeditEnabledByDefault",
193 _(
"Show preedit in application"),
195 Option<bool> showInputMethodInformation{
196 this,
"ShowInputMethodInformation",
197 _(
"Show Input Method Information when switch input method"),
true};
198 Option<bool> showInputMethodInformationWhenFocusIn{
199 this,
"showInputMethodInformationWhenFocusIn",
200 _(
"Show Input Method Information when changing focus"),
false};
201 Option<bool> compactInputMethodInformation{
202 this,
"CompactInputMethodInformation",
203 _(
"Show compact input method information"),
true};
204 Option<bool> showFirstInputMethodInformation{
205 this,
"ShowFirstInputMethodInformation",
206 _(
"Show first input method information"),
true};
207 Option<int, IntConstrain> defaultPageSize{
this,
"DefaultPageSize",
208 _(
"Default Candidates per page"),
209 5, IntConstrain(1, 10)};
210 ConditionalHidden<!hasKeyboard,
211 OptionWithAnnotation<bool, ToolTipAnnotation>>
215 _(
"Override XKB Option"),
219 {_(
"Override the XKB option from display server. It " 220 "will not affect the XKB option send to display, but just the " 221 "XKB options for custom XKB layout. This is a workaround when " 222 "there is no way to get the current XKB option from Wayland " 224 ConditionalHidden<!hasKeyboard, Option<std::string>> customXkbOption{
225 this,
"CustomXkbOption", _(
"Custom XKB Option"),
""};
226 HiddenOption<std::vector<std::string>> enabledAddons{
227 this,
"EnabledAddons",
"Force Enabled Addons"};
228 HiddenOption<std::vector<std::string>> disabledAddons{
229 this,
"DisabledAddons",
"Force Disabled Addons"};
230 HiddenOption<bool> preloadInputMethod{
231 this,
"PreloadInputMethod",
232 "Preload input method to be used by default",
true};
233 Option<bool> allowInputMethodForPassword{
234 this,
"AllowInputMethodForPassword",
235 _(
"Allow input method in the password field"),
false};
236 Option<bool> showPreeditForPassword{
237 this,
"ShowPreeditForPassword",
238 _(
"Show preedit text when typing password"),
false};
239 Option<int, IntConstrain, DefaultMarshaller<int>, ToolTipAnnotation>
242 _(
"Interval of saving user data in minutes"),
244 IntConstrain(0, 1440),
246 {_(
"If value is 0, the user data may only be saved when " 247 "fcitx quits (e.g. logout).")}};);
249 FCITX_CONFIGURATION(GlobalConfig,
250 Option<HotkeyConfig> hotkey{
this,
"Hotkey", _(
"Hotkey")};
251 Option<BehaviorConfig> behavior{
this,
"Behavior",
257 GlobalConfig::GlobalConfig() : d_ptr(std::make_unique<GlobalConfigPrivate>()) {}
259 GlobalConfig::~GlobalConfig() {}
261 void GlobalConfig::load(
const RawConfig &rawConfig,
bool partial) {
263 d->load(rawConfig, partial);
266 void GlobalConfig::save(
RawConfig &config)
const {
271 bool GlobalConfig::safeSave(
const std::string &path)
const {
273 return safeSaveAsIni(*d, path);
276 const KeyList &GlobalConfig::triggerKeys()
const {
278 return *d->hotkey->triggerKeys;
281 bool GlobalConfig::enumerateWithTriggerKeys()
const {
283 return *d->hotkey->enumerateWithTriggerKeys;
286 const KeyList &GlobalConfig::altTriggerKeys()
const {
288 return *d->hotkey->altTriggerKeys;
291 const KeyList &GlobalConfig::activateKeys()
const {
293 return *d->hotkey->activateKeys;
296 const KeyList &GlobalConfig::deactivateKeys()
const {
298 return d->hotkey->deactivateKeys.value();
301 const KeyList &GlobalConfig::enumerateForwardKeys()
const {
303 return d->hotkey->enumerateForwardKeys.value();
306 const KeyList &GlobalConfig::enumerateBackwardKeys()
const {
308 return d->hotkey->enumerateBackwardKeys.value();
311 bool GlobalConfig::enumerateSkipFirst()
const {
313 return *d->hotkey->enumerateSkipFirst;
316 const KeyList &GlobalConfig::enumerateGroupForwardKeys()
const {
318 return *d->hotkey->enumerateGroupForwardKeys;
321 const KeyList &GlobalConfig::enumerateGroupBackwardKeys()
const {
323 return *d->hotkey->enumerateGroupBackwardKeys;
326 const KeyList &GlobalConfig::togglePreeditKeys()
const {
328 return *d->hotkey->togglePreedit;
331 bool GlobalConfig::activeByDefault()
const {
333 return d->behavior->activeByDefault.value();
338 return d->behavior->resetStateWhenFocusIn.value();
341 bool GlobalConfig::showInputMethodInformation()
const {
343 return d->behavior->showInputMethodInformation.value();
346 bool GlobalConfig::showInputMethodInformationWhenFocusIn()
const {
348 return d->behavior->showInputMethodInformationWhenFocusIn.value();
351 bool GlobalConfig::compactInputMethodInformation()
const {
353 return d->behavior->compactInputMethodInformation.value();
356 bool GlobalConfig::showFirstInputMethodInformation()
const {
358 return d->behavior->showFirstInputMethodInformation.value();
361 PropertyPropagatePolicy GlobalConfig::shareInputState()
const {
363 return d->behavior->shareState.value();
366 bool GlobalConfig::preeditEnabledByDefault()
const {
368 return d->behavior->preeditEnabledByDefault.value();
371 const KeyList &GlobalConfig::defaultPrevPage()
const {
373 return d->hotkey->defaultPrevPage.value();
376 const KeyList &GlobalConfig::defaultNextPage()
const {
378 return d->hotkey->defaultNextPage.value();
381 const KeyList &GlobalConfig::defaultPrevCandidate()
const {
383 return d->hotkey->defaultPrevCandidate.value();
386 const KeyList &GlobalConfig::defaultNextCandidate()
const {
388 return d->hotkey->defaultNextCandidate.value();
391 int GlobalConfig::defaultPageSize()
const {
393 return d->behavior->defaultPageSize.value();
398 return d->behavior->overrideXkbOption.value();
403 return d->behavior->customXkbOption.value();
406 const std::vector<std::string> &GlobalConfig::enabledAddons()
const {
408 return *d->behavior->enabledAddons;
411 const std::vector<std::string> &GlobalConfig::disabledAddons()
const {
413 return *d->behavior->disabledAddons;
416 void GlobalConfig::setEnabledAddons(
const std::vector<std::string> &addons) {
418 d->behavior.mutableValue()->enabledAddons.setValue(addons);
421 void GlobalConfig::setDisabledAddons(
const std::vector<std::string> &addons) {
423 d->behavior.mutableValue()->disabledAddons.setValue(addons);
426 bool GlobalConfig::preloadInputMethod()
const {
428 return *d->behavior->preloadInputMethod;
433 return *d->behavior->allowInputMethodForPassword;
438 return *d->behavior->showPreeditForPassword;
443 return *d->behavior->autoSavePeriod;
448 return *d->hotkey->modifierOnlyKeyTimeout;
452 const auto timeout = modifierOnlyKeyTimeout();
456 return now(CLOCK_MONOTONIC) <=
457 (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.