6
6
*/
7
7
8
8
#include " bamboo.h"
9
+ #include " bambooconfig.h"
10
+ #include < algorithm>
11
+ #include < cstdint>
12
+ #include < cstdlib>
9
13
#include < fcitx-config/iniparser.h>
14
+ #include < fcitx-config/rawconfig.h>
15
+ #include < fcitx-utils/capabilityflags.h>
10
16
#include < fcitx-utils/charutils.h>
17
+ #include < fcitx-utils/i18n.h>
11
18
#include < fcitx-utils/keysymgen.h>
19
+ #include < fcitx-utils/log.h>
20
+ #include < fcitx-utils/macros.h>
21
+ #include < fcitx-utils/misc.h>
12
22
#include < fcitx-utils/standardpath.h>
23
+ #include < fcitx-utils/stringutils.h>
13
24
#include < fcitx-utils/textformatflags.h>
14
25
#include < fcitx-utils/utf8.h>
26
+ #include < fcitx/action.h>
27
+ #include < fcitx/addoninstance.h>
28
+ #include < fcitx/event.h>
15
29
#include < fcitx/inputcontext.h>
16
30
#include < fcitx/inputcontextmanager.h>
31
+ #include < fcitx/inputmethodentry.h>
17
32
#include < fcitx/inputpanel.h>
18
33
#include < fcitx/menu.h>
19
34
#include < fcitx/statusarea.h>
35
+ #include < fcitx/text.h>
20
36
#include < fcitx/userinterface.h>
21
37
#include < fcitx/userinterfacemanager.h>
22
38
#include < fcntl.h>
39
+ #include < memory>
23
40
#include < optional>
24
41
#include < stdexcept>
42
+ #include < string>
43
+ #include < string_view>
44
+ #include < utility>
45
+ #include < vector>
25
46
26
47
namespace fcitx {
27
48
@@ -32,6 +53,8 @@ constexpr std::string_view InputMethodActionPrefix = "bamboo-input-method-";
32
53
constexpr std::string_view CharsetActionPrefix = " bamboo-charset-" ;
33
54
const std::string CustomKeymapFile = " conf/bamboo-custom-keymap.conf" ;
34
55
56
+ FCITX_DEFINE_LOG_CATEGORY (bamboo, " bamboo" );
57
+
35
58
std::string macroFile (std::string_view imName) {
36
59
return stringutils::concat (" conf/bamboo-macro-" , imName, " .conf" );
37
60
}
@@ -48,9 +71,18 @@ uintptr_t newMacroTable(const BambooMacroTable ¯oTable) {
48
71
return NewMacroTable (charArray.data ());
49
72
}
50
73
74
+ std::vector<std::string> convertToStringList (char **array) {
75
+ std::vector<std::string> result;
76
+ for (int i = 0 ; array[i]; i++) {
77
+ result.push_back (array[i]);
78
+ free (array[i]);
79
+ }
80
+ free (array);
81
+ return result;
82
+ }
83
+
51
84
} // namespace
52
85
53
- FCITX_DEFINE_LOG_CATEGORY (bamboo, " bamboo" );
54
86
#define FCITX_BAMBOO_DEBUG () FCITX_LOGC(bamboo, Debug)
55
87
56
88
class BambooState final : public InputContextProperty {
@@ -117,7 +149,8 @@ class BambooState final : public InputContextProperty {
117
149
118
150
if (keyEvent.key ().checkKeyList (*engine_->config ().restoreKeyStroke )) {
119
151
EngineSetRestoreKeyStroke (bambooEngine_.handle ());
120
- return keyEvent.filterAndAccept ();
152
+ keyEvent.filterAndAccept ();
153
+ return ;
121
154
}
122
155
123
156
if (EngineProcessKeyEvent (bambooEngine_.handle (),
@@ -189,16 +222,6 @@ class BambooState final : public InputContextProperty {
189
222
CGoObject bambooEngine_;
190
223
};
191
224
192
- std::vector<std::string> convertToStringList (char **array) {
193
- std::vector<std::string> result;
194
- for (int i = 0 ; array[i]; i++) {
195
- result.push_back (array[i]);
196
- free (array[i]);
197
- }
198
- free (array);
199
- return result;
200
- }
201
-
202
225
BambooEngine::BambooEngine (Instance *instance)
203
226
: instance_(instance), factory_([this ](InputContext &ic) {
204
227
return new BambooState (this , &ic);
@@ -233,7 +256,7 @@ BambooEngine::BambooEngine(Instance *instance)
233
256
inputMethodAction_->setMenu (inputMethodMenu_.get ());
234
257
for (const auto &imName : imNames_) {
235
258
inputMethodSubAction_.emplace_back (std::make_unique<SimpleAction>());
236
- auto action = inputMethodSubAction_.back ().get ();
259
+ auto * action = inputMethodSubAction_.back ().get ();
237
260
action->setShortText (imName);
238
261
action->setCheckable (true );
239
262
uiManager.registerAction (
@@ -262,7 +285,7 @@ BambooEngine::BambooEngine(Instance *instance)
262
285
auto charsets = convertToStringList (GetCharsetNames ());
263
286
for (const auto &charset : charsets) {
264
287
charsetSubAction_.emplace_back (std::make_unique<SimpleAction>());
265
- auto action = charsetSubAction_.back ().get ();
288
+ auto * action = charsetSubAction_.back ().get ();
266
289
action->setShortText (charset);
267
290
action->setCheckable (true );
268
291
connections_.emplace_back (action->connect <SimpleAction::Activated>(
@@ -324,13 +347,13 @@ void BambooEngine::reloadConfig() {
324
347
const Configuration *BambooEngine::getSubConfig (const std::string &path) const {
325
348
if (path == " custom_keymap" ) {
326
349
return &customKeymap_;
327
- } else if (stringutils::startsWith (path, MacroPrefix)) {
350
+ }
351
+ if (stringutils::startsWith (path, MacroPrefix)) {
328
352
const auto imName = path.substr (MacroPrefix.size ());
329
353
if (auto iter = macroTables_.find (imName); iter != macroTables_.end ()) {
330
354
return &iter->second ;
331
- } else {
332
- return nullptr ;
333
355
}
356
+ return nullptr ;
334
357
}
335
358
return nullptr ;
336
359
}
@@ -367,8 +390,8 @@ void BambooEngine::setSubConfig(const std::string &path,
367
390
}
368
391
}
369
392
370
- std::string BambooEngine::subMode (const fcitx::InputMethodEntry &,
371
- fcitx::InputContext &) {
393
+ std::string BambooEngine::subMode (const fcitx::InputMethodEntry & /* entry */ ,
394
+ fcitx::InputContext & /* inputContext */ ) {
372
395
return *config_.inputMethod ;
373
396
}
374
397
@@ -392,7 +415,7 @@ void BambooEngine::activate(const InputMethodEntry &entry,
392
415
void BambooEngine::deactivate (const InputMethodEntry &entry,
393
416
InputContextEvent &event) {
394
417
FCITX_UNUSED (entry);
395
- auto state = event.inputContext ()->propertyFor (&factory_);
418
+ auto * state = event.inputContext ()->propertyFor (&factory_);
396
419
if (event.type () != EventType::InputContextFocusOut) {
397
420
state->commitBuffer ();
398
421
} else {
@@ -402,15 +425,15 @@ void BambooEngine::deactivate(const InputMethodEntry &entry,
402
425
403
426
void BambooEngine::keyEvent (const InputMethodEntry &entry, KeyEvent &keyEvent) {
404
427
FCITX_UNUSED (entry);
405
- auto state = keyEvent.inputContext ()->propertyFor (&factory_);
428
+ auto * state = keyEvent.inputContext ()->propertyFor (&factory_);
406
429
407
430
state->keyEvent (keyEvent);
408
431
}
409
432
410
433
void BambooEngine::reset (const InputMethodEntry &entry,
411
434
InputContextEvent &event) {
412
435
FCITX_UNUSED (entry);
413
- auto state = event.inputContext ()->propertyFor (&factory_);
436
+ auto * state = event.inputContext ()->propertyFor (&factory_);
414
437
state->reset ();
415
438
}
416
439
@@ -421,7 +444,7 @@ void BambooEngine::refreshEngine() {
421
444
}
422
445
423
446
instance_->inputContextManager ().foreach ([this ](InputContext *ic) {
424
- auto state = ic->propertyFor (&factory_);
447
+ auto * state = ic->propertyFor (&factory_);
425
448
state->setEngine ();
426
449
if (ic->hasFocus ()) {
427
450
state->reset ();
@@ -435,7 +458,7 @@ void BambooEngine::refreshOption() {
435
458
return ;
436
459
}
437
460
instance_->inputContextManager ().foreach ([this ](InputContext *ic) {
438
- auto state = ic->propertyFor (&factory_);
461
+ auto * state = ic->propertyFor (&factory_);
439
462
state->setOption ();
440
463
if (ic->hasFocus ()) {
441
464
state->reset ();
@@ -487,4 +510,4 @@ void BambooEngine::updateCharsetAction(InputContext *ic) {
487
510
488
511
} // namespace fcitx
489
512
490
- FCITX_ADDON_FACTORY ( fcitx::BambooFactory)
513
+ FCITX_ADDON_FACTORY_V2 (bamboo, fcitx::BambooFactory)
0 commit comments