| 1 | //cxx . . $ `<file>/src/rime/gear/ascii_composer.cc`/ |
| 2 | // Copyright RIME Developers |
| 3 | // Distributed under the BSD License |
| 4 | // |
| 5 | // 2011-12-18 GONG Chen <[email protected]> |
| 6 | // |
| 7 | #include <rime/common.h>cxx . . $ `<file>/src/rime/common.h`/ |
| 8 | #include <rime/composition.h>cxx . . $ `<file>/src/rime/composition.h`/ |
| 9 | #include <rime/config.h>cxx . . $ `<file>/src/rime/config.h`/ |
| 10 | #include <rime/context.h>cxx . . $ `<file>/src/rime/context.h`/ |
| 11 | #include <rime/engine.h>cxx . . $ `<file>/src/rime/engine.h`/ |
| 12 | #include <rime/key_event.h>cxx . . $ `<file>/src/rime/key_event.h`/ |
| 13 | #include <rime/schema.h>cxx . . $ `<file>/src/rime/schema.h`/ |
| 14 | #include <rime/gear/ascii_composer.h>cxx . . $ `<file>/src/rime/gear/ascii_composer.h`/ |
| 15 | |
| 16 | namespace rimecxx . . $ rime/ { |
| 17 | |
| 18 | static struct AsciiModeSwitchStyleDefinitioncxx . . $ rime/AsciiModeSwitchStyleDefinition# { |
| 19 | const char* reprcxx . . $ rime/AsciiModeSwitchStyleDefinition#repr.; |
| 20 | AsciiModeSwitchStylecxx . . $ rime/AsciiModeSwitchStyle# stylecxx . . $ rime/AsciiModeSwitchStyleDefinition#style.; |
| 21 | } ascii_mode_switch_stylescxx . . $ rime/ascii_mode_switch_styles.[] = {{"inline_ascii", kAsciiModeSwitchInlinecxx . . $ rime/kAsciiModeSwitchInline.}, |
| 22 | {"commit_text", kAsciiModeSwitchCommitTextcxx . . $ rime/kAsciiModeSwitchCommitText.}, |
| 23 | {"commit_code", kAsciiModeSwitchCommitCodecxx . . $ rime/kAsciiModeSwitchCommitCode.}, |
| 24 | {"clear", kAsciiModeSwitchClearcxx . . $ rime/kAsciiModeSwitchClear.}, |
| 25 | {"set_ascii_mode", kAsciiModeSetcxx . . $ rime/kAsciiModeSet.}, |
| 26 | {"unset_ascii_mode", kAsciiModeUnsetcxx . . $ rime/kAsciiModeUnset.}, |
| 27 | {NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, kAsciiModeSwitchNoopcxx . . $ rime/kAsciiModeSwitchNoop.}}; |
| 28 | |
| 29 | static void load_bindingscxx . . $ rime/load_bindings(b71f7dba03d730fd).(const ancxx . . $ rime/an#<ConfigMapcxx . . $ rime/ConfigMap#>& src, |
| 30 | AsciiModeSwitchKeyBindingscxx . . $ rime/AsciiModeSwitchKeyBindings#* dest) { |
| 31 | if (!src) |
| 32 | return; |
| 33 | for (auto it = src->cxx . . $ std/__shared_ptr_access#`operator->`(34d6acfd341ba7ab).begincxx . . $ rime/ConfigMap#begin(78562b0aceef1ba5).(); it !=cxx . . $ std/`operator!=`(be6a71a859368080). src->cxx . . $ std/__shared_ptr_access#`operator->`(34d6acfd341ba7ab).endcxx . . $ rime/ConfigMap#end(78562b0aceef1ba5).(); ++cxx . . $ std/_Rb_tree_iterator#operator++(5b825426e5b44d2c).it) { |
| 34 | auto value = Ascxx . . $ rime/As(f7ae99698a17f8b6).<ConfigValuecxx . . $ rime/ConfigValue#>(it->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second.); |
| 35 | if (!value) |
| 36 | continue; |
| 37 | auto* p = ascii_mode_switch_stylescxx . . $ rime/ascii_mode_switch_styles.; |
| 38 | while (p->reprcxx . . $ rime/AsciiModeSwitchStyleDefinition#repr. && p->reprcxx . . $ rime/AsciiModeSwitchStyleDefinition#repr. !=cxx . . $ std/`operator!=`(3a786e8ce7e53c2c). value->cxx . . $ std/__shared_ptr_access#`operator->`(34d6acfd341ba7ab).strcxx . . $ rime/ConfigValue#str(f4fff0029955a25f).()) |
| 39 | ++p; |
| 40 | if (p->stylecxx . . $ rime/AsciiModeSwitchStyleDefinition#style. == kAsciiModeSwitchNoopcxx . . $ rime/kAsciiModeSwitchNoop.) |
| 41 | continue; |
| 42 | KeyEventcxx . . $ rime/KeyEvent# kecxx . . $ rime/KeyEvent#KeyEvent(ced63f7c635d850d).; |
| 43 | if (!ke.Parsecxx . . $ rime/KeyEvent#Parse(7c222eea44a24d43).(it->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).firstcxx . . $ std/pair#first.) || ke.modifiercxx . . $ rime/KeyEvent#modifier(455f465bc33b4cdf).() != 0) { |
| 44 | LOGcxx . . $ `<external>/8254875247241458228/logging.h:610:9`!(WARNING) <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "invalid ascii mode switch key: " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). it->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).firstcxx . . $ std/pair#first.; |
| 45 | continue; |
| 46 | } |
| 47 | // save binding |
| 48 | (*dest)[cxx . . $ std/map#`operator[]`(da459db78e6e18a3).ke.keycodecxx . . $ rime/KeyEvent#keycode(455f465bc33b4cdf).()] = p->stylecxx . . $ rime/AsciiModeSwitchStyleDefinition#style.; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | AsciiComposercxx . . $ rime/AsciiComposer#::AsciiComposercxx . . $ rime/AsciiComposer#AsciiComposer(1b3cee102caa60c1).(const Ticketcxx . . $ rime/Ticket#& ticket) : Processorcxx . . $ rime/Processor#(ticket) { |
| 53 | LoadConfigcxx . . $ rime/AsciiComposer#LoadConfig(75c8beea00e18a29).(ticket.schemacxx . . $ rime/Ticket#schema.); |
| 54 | } |
| 55 | |
| 56 | AsciiComposercxx . . $ rime/AsciiComposer#::~cxx . . $ rime/AsciiComposer#`~AsciiComposer`(ced63f7c635d850d).AsciiComposercxx . . $ rime/AsciiComposer#() { |
| 57 | connection_cxx . . $ rime/AsciiComposer#connection_..disconnectcxx . . $ boost/signals2/connection#disconnect(83f5f38750778ac8).(); |
| 58 | } |
| 59 | |
| 60 | ProcessResultcxx . . $ rime/ProcessResult# AsciiComposercxx . . $ rime/AsciiComposer#::ProcessKeyEventcxx . . $ rime/AsciiComposer#ProcessKeyEvent(fb7b9b413336ca09).(const KeyEventcxx . . $ rime/KeyEvent#& key_event) { |
| 61 | if (key_event.shiftcxx . . $ rime/KeyEvent#shift(50ce9a9e25b4a850).() + key_event.ctrlcxx . . $ rime/KeyEvent#ctrl(50ce9a9e25b4a850).() + key_event.altcxx . . $ rime/KeyEvent#alt(50ce9a9e25b4a850).() + |
| 62 | key_event.supercxx . . $ rime/KeyEvent#super(50ce9a9e25b4a850).() > |
| 63 | 1) { |
| 64 | shift_key_pressed_cxx . . $ rime/AsciiComposer#shift_key_pressed_. = ctrl_key_pressed_cxx . . $ rime/AsciiComposer#ctrl_key_pressed_. = alt_key_pressed_cxx . . $ rime/AsciiComposer#alt_key_pressed_. = |
| 65 | super_key_pressed_cxx . . $ rime/AsciiComposer#super_key_pressed_. = false; |
| 66 | return kNoopcxx . . $ rime/kNoop.; |
| 67 | } |
| 68 | if (caps_lock_switch_style_cxx . . $ rime/AsciiComposer#caps_lock_switch_style_. != kAsciiModeSwitchNoopcxx . . $ rime/kAsciiModeSwitchNoop.) { |
| 69 | ProcessResultcxx . . $ rime/ProcessResult# result = ProcessCapsLockcxx . . $ rime/AsciiComposer#ProcessCapsLock(fb7b9b413336ca09).(key_event); |
| 70 | if (result != kNoopcxx . . $ rime/kNoop.) |
| 71 | return result; |
| 72 | } |
| 73 | int ch = key_event.keycodecxx . . $ rime/KeyEvent#keycode(455f465bc33b4cdf).(); |
| 74 | if (ch == XK_Eisu_togglecxx . . $ `include/X11/keysymdef.h:163:9`!) { // Alphanumeric toggle |
| 75 | if (!key_event.releasecxx . . $ rime/KeyEvent#release(50ce9a9e25b4a850).()) { |
| 76 | shift_key_pressed_cxx . . $ rime/AsciiComposer#shift_key_pressed_. = ctrl_key_pressed_cxx . . $ rime/AsciiComposer#ctrl_key_pressed_. = false; |
| 77 | ToggleAsciiModeWithKeycxx . . $ rime/AsciiComposer#ToggleAsciiModeWithKey(83c267b20bac841a).(ch); |
| 78 | return kAcceptedcxx . . $ rime/kAccepted.; |
| 79 | } else { |
| 80 | return kRejectedcxx . . $ rime/kRejected.; |
| 81 | } |
| 82 | } |
| 83 | bool is_shift = (ch == XK_Shift_Lcxx . . $ `include/X11/keysymdef.h:315:9`! || ch == XK_Shift_Rcxx . . $ `include/X11/keysymdef.h:316:9`!); |
| 84 | bool is_ctrl = (ch == XK_Control_Lcxx . . $ `include/X11/keysymdef.h:317:9`! || ch == XK_Control_Rcxx . . $ `include/X11/keysymdef.h:318:9`!); |
| 85 | bool is_alt = (ch == XK_Alt_Lcxx . . $ `include/X11/keysymdef.h:324:9`! || ch == XK_Alt_Rcxx . . $ `include/X11/keysymdef.h:325:9`!); |
| 86 | bool is_super = (ch == XK_Super_Lcxx . . $ `include/X11/keysymdef.h:326:9`! || ch == XK_Super_Rcxx . . $ `include/X11/keysymdef.h:327:9`!); |
| 87 | if (is_shift || is_ctrl || is_alt || is_super) { |
| 88 | if (key_event.releasecxx . . $ rime/KeyEvent#release(50ce9a9e25b4a850).()) { |
| 89 | if (shift_key_pressed_cxx . . $ rime/AsciiComposer#shift_key_pressed_. || ctrl_key_pressed_cxx . . $ rime/AsciiComposer#ctrl_key_pressed_. || alt_key_pressed_cxx . . $ rime/AsciiComposer#alt_key_pressed_. || |
| 90 | super_key_pressed_cxx . . $ rime/AsciiComposer#super_key_pressed_.) { |
| 91 | auto now = stdcxx . . $ std/::chronocxx . . $ std/chrono/::steady_clockcxx . . $ std/chrono/_V2/steady_clock#::nowcxx . . $ std/chrono/_V2/steady_clock#now(edffc6b45db65c20).(); |
| 92 | if (((is_shift && shift_key_pressed_cxx . . $ rime/AsciiComposer#shift_key_pressed_.) || |
| 93 | (is_ctrl && ctrl_key_pressed_cxx . . $ rime/AsciiComposer#ctrl_key_pressed_.) || (is_alt && alt_key_pressed_cxx . . $ rime/AsciiComposer#alt_key_pressed_.) || |
| 94 | (is_super && super_key_pressed_cxx . . $ rime/AsciiComposer#super_key_pressed_.)) && |
| 95 | now <cxx . . $ std/chrono/`operator<`(b733d9f18a96a496). toggle_expired_cxx . . $ rime/AsciiComposer#toggle_expired_.) { |
| 96 | ToggleAsciiModeWithKeycxx . . $ rime/AsciiComposer#ToggleAsciiModeWithKey(83c267b20bac841a).(ch); |
| 97 | } |
| 98 | shift_key_pressed_cxx . . $ rime/AsciiComposer#shift_key_pressed_. = ctrl_key_pressed_cxx . . $ rime/AsciiComposer#ctrl_key_pressed_. = alt_key_pressed_cxx . . $ rime/AsciiComposer#alt_key_pressed_. = |
| 99 | super_key_pressed_cxx . . $ rime/AsciiComposer#super_key_pressed_. = false; |
| 100 | return kNoopcxx . . $ rime/kNoop.; |
| 101 | } |
| 102 | } else if (!(shift_key_pressed_cxx . . $ rime/AsciiComposer#shift_key_pressed_. || ctrl_key_pressed_cxx . . $ rime/AsciiComposer#ctrl_key_pressed_. || alt_key_pressed_cxx . . $ rime/AsciiComposer#alt_key_pressed_. || |
| 103 | super_key_pressed_cxx . . $ rime/AsciiComposer#super_key_pressed_.)) { |
| 104 | // first key down |
| 105 | if (is_shift) |
| 106 | shift_key_pressed_cxx . . $ rime/AsciiComposer#shift_key_pressed_. = true; |
| 107 | else if (is_ctrl) |
| 108 | ctrl_key_pressed_cxx . . $ rime/AsciiComposer#ctrl_key_pressed_. = true; |
| 109 | else if (is_alt) |
| 110 | alt_key_pressed_cxx . . $ rime/AsciiComposer#alt_key_pressed_. = true; |
| 111 | else if (is_super) |
| 112 | super_key_pressed_cxx . . $ rime/AsciiComposer#super_key_pressed_. = true; |
| 113 | // will not toggle unless the toggle key is released shortly |
| 114 | const auto toggle_duration_limit = stdcxx . . $ std/::chronocxx . . $ std/chrono/::millisecondscxx . . $ std/chrono/milliseconds#(500); |
| 115 | auto now = stdcxx . . $ std/::chronocxx . . $ std/chrono/::steady_clockcxx . . $ std/chrono/_V2/steady_clock#::nowcxx . . $ std/chrono/_V2/steady_clock#now(edffc6b45db65c20).(); |
| 116 | toggle_expired_cxx . . $ rime/AsciiComposer#toggle_expired_. =cxx . . $ std/chrono/time_point#`operator=`(8cf69a9a2c3bd270). now +cxx . . $ std/chrono/operator+(ddf880cf2436a4d3). toggle_duration_limit; |
| 117 | } |
| 118 | return kNoopcxx . . $ rime/kNoop.; |
| 119 | } |
| 120 | // other keys |
| 121 | shift_key_pressed_cxx . . $ rime/AsciiComposer#shift_key_pressed_. = ctrl_key_pressed_cxx . . $ rime/AsciiComposer#ctrl_key_pressed_. = alt_key_pressed_cxx . . $ rime/AsciiComposer#alt_key_pressed_. = |
| 122 | super_key_pressed_cxx . . $ rime/AsciiComposer#super_key_pressed_. = false; |
| 123 | // possible key binding: Control+x, Shift+space |
| 124 | if (key_event.ctrlcxx . . $ rime/KeyEvent#ctrl(50ce9a9e25b4a850).() || key_event.altcxx . . $ rime/KeyEvent#alt(50ce9a9e25b4a850).() || key_event.supercxx . . $ rime/KeyEvent#super(50ce9a9e25b4a850).() || |
| 125 | (key_event.shiftcxx . . $ rime/KeyEvent#shift(50ce9a9e25b4a850).() && ch == XK_spacecxx . . $ `include/X11/keysymdef.h:527:9`!)) { |
| 126 | return kNoopcxx . . $ rime/kNoop.; |
| 127 | } |
| 128 | Contextcxx . . $ rime/Context#* ctx = engine_cxx . . $ rime/Processor#engine_.->contextcxx . . $ rime/Engine#context(8ec6c0085ff2c2ef).(); |
| 129 | bool ascii_mode = ctx->get_optioncxx . . $ rime/Context#get_option(13a55b95a0133754).("ascii_mode"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 130 | if (ascii_mode) { |
| 131 | if (!ctx->IsComposingcxx . . $ rime/Context#IsComposing(50ce9a9e25b4a850).()) { |
| 132 | return kRejectedcxx . . $ rime/kRejected.; // direct commit |
| 133 | } |
| 134 | // edit inline ascii string |
| 135 | if (!key_event.releasecxx . . $ rime/KeyEvent#release(50ce9a9e25b4a850).() && ch >= 0x20 && ch < 0x80) { |
| 136 | ctx->PushInputcxx . . $ rime/Context#PushInput(b5fd09639b7a0261).(ch); |
| 137 | return kAcceptedcxx . . $ rime/kAccepted.; |
| 138 | } |
| 139 | } |
| 140 | return kNoopcxx . . $ rime/kNoop.; |
| 141 | } |
| 142 | |
| 143 | ProcessResultcxx . . $ rime/ProcessResult# AsciiComposercxx . . $ rime/AsciiComposer#::ProcessCapsLockcxx . . $ rime/AsciiComposer#ProcessCapsLock(fb7b9b413336ca09).(const KeyEventcxx . . $ rime/KeyEvent#& key_event) { |
| 144 | int ch = key_event.keycodecxx . . $ rime/KeyEvent#keycode(455f465bc33b4cdf).(); |
| 145 | if (ch == XK_Caps_Lockcxx . . $ `include/X11/keysymdef.h:319:9`!) { |
| 146 | if (!key_event.releasecxx . . $ rime/KeyEvent#release(50ce9a9e25b4a850).()) { |
| 147 | shift_key_pressed_cxx . . $ rime/AsciiComposer#shift_key_pressed_. = ctrl_key_pressed_cxx . . $ rime/AsciiComposer#ctrl_key_pressed_. = alt_key_pressed_cxx . . $ rime/AsciiComposer#alt_key_pressed_. = |
| 148 | super_key_pressed_cxx . . $ rime/AsciiComposer#super_key_pressed_. = false; |
| 149 | // temporarily disable good-old (uppercase) Caps Lock as mode switch key |
| 150 | // in case the user switched to ascii mode with other keys, eg. with Shift |
| 151 | if (good_old_caps_lock_cxx . . $ rime/AsciiComposer#good_old_caps_lock_. && !toggle_with_caps_cxx . . $ rime/AsciiComposer#toggle_with_caps_.) { |
| 152 | Contextcxx . . $ rime/Context#* ctx = engine_cxx . . $ rime/Processor#engine_.->contextcxx . . $ rime/Engine#context(8ec6c0085ff2c2ef).(); |
| 153 | bool ascii_mode = ctx->get_optioncxx . . $ rime/Context#get_option(13a55b95a0133754).("ascii_mode"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 154 | if (ascii_mode) { |
| 155 | return kRejectedcxx . . $ rime/kRejected.; |
| 156 | } |
| 157 | } |
| 158 | toggle_with_caps_cxx . . $ rime/AsciiComposer#toggle_with_caps_. = !key_event.capscxx . . $ rime/KeyEvent#caps(50ce9a9e25b4a850).(); |
| 159 | // NOTE: for Linux, Caps Lock modifier is clear when we are about to |
| 160 | // turn it on; for Windows it is the opposite: |
| 161 | // Caps Lock modifier has been set before we process VK_CAPITAL. |
| 162 | // here we assume IBus' behavior and invert caps with ! operation. |
| 163 | SwitchAsciiModecxx . . $ rime/AsciiComposer#SwitchAsciiMode(e07271bd48dfd8d0).(!key_event.capscxx . . $ rime/KeyEvent#caps(50ce9a9e25b4a850).(), caps_lock_switch_style_cxx . . $ rime/AsciiComposer#caps_lock_switch_style_.); |
| 164 | // When good_old_caps_lock is enabled, allow the key event to pass |
| 165 | // through the input method to toggle the Caps Lock state. |
| 166 | return good_old_caps_lock_cxx . . $ rime/AsciiComposer#good_old_caps_lock_. ? kRejectedcxx . . $ rime/kRejected. : kAcceptedcxx . . $ rime/kAccepted.; |
| 167 | } else { |
| 168 | return kRejectedcxx . . $ rime/kRejected.; |
| 169 | } |
| 170 | } |
| 171 | if (key_event.capscxx . . $ rime/KeyEvent#caps(50ce9a9e25b4a850).()) { |
| 172 | if (!good_old_caps_lock_cxx . . $ rime/AsciiComposer#good_old_caps_lock_. && !key_event.releasecxx . . $ rime/KeyEvent#release(50ce9a9e25b4a850).() && !key_event.ctrlcxx . . $ rime/KeyEvent#ctrl(50ce9a9e25b4a850).() && |
| 173 | !key_event.altcxx . . $ rime/KeyEvent#alt(50ce9a9e25b4a850).() && !key_event.supercxx . . $ rime/KeyEvent#super(50ce9a9e25b4a850).() && isascii(ch) && isalpha(ch)) { |
| 174 | // output ascii characters ignoring Caps Lock |
| 175 | if (islower(ch)) |
| 176 | ch = toupper(ch); |
| 177 | else if (isupper(ch)) |
| 178 | ch = tolower(ch); |
| 179 | engine_cxx . . $ rime/Processor#engine_.->CommitTextcxx . . $ rime/Engine#CommitText(8d4ab0a187bf9331).(stringcxx . . $ std/__cxx11/basic_string#basic_string(57f9c416bbf2a7d6).(1, ch)); |
| 180 | return kAcceptedcxx . . $ rime/kAccepted.; |
| 181 | } else { |
| 182 | return kRejectedcxx . . $ rime/kRejected.; |
| 183 | } |
| 184 | } |
| 185 | return kNoopcxx . . $ rime/kNoop.; |
| 186 | } |
| 187 | |
| 188 | void AsciiComposercxx . . $ rime/AsciiComposer#::LoadConfigcxx . . $ rime/AsciiComposer#LoadConfig(75c8beea00e18a29).(Schemacxx . . $ rime/Schema#* schema) { |
| 189 | bindings_cxx . . $ rime/AsciiComposer#bindings_..clearcxx . . $ std/map#clear(ced63f7c635d850d).(); |
| 190 | caps_lock_switch_style_cxx . . $ rime/AsciiComposer#caps_lock_switch_style_. = kAsciiModeSwitchNoopcxx . . $ rime/kAsciiModeSwitchNoop.; |
| 191 | good_old_caps_lock_cxx . . $ rime/AsciiComposer#good_old_caps_lock_. = false; |
| 192 | if (!schema) |
| 193 | return; |
| 194 | Configcxx . . $ rime/Config#* config = schema->configcxx . . $ rime/Schema#config(3034fcb362c179ef).(); |
| 195 | thecxx . . $ rime/the#<Configcxx . . $ rime/Config#> preset_configcxx . . $ std/unique_ptr#unique_ptr(c8c3025d73122d7d).(Configcxx . . $ rime/Config#::Requirecxx . . $ rime/Class#Require(bfaad7a7398b071d).("config"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).)->Createcxx . . $ rime/Class#Component#Create(12bf399c05f63248).("default"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).)); |
| 196 | if (!config->GetBoolcxx . . $ rime/Config#GetBool(5b96d491e20283ea).("ascii_composer/good_old_caps_lock"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., |
| 197 | &good_old_caps_lock_cxx . . $ rime/AsciiComposer#good_old_caps_lock_.)) { |
| 198 | if (preset_config) { |
| 199 | preset_config->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).GetBoolcxx . . $ rime/Config#GetBool(5b96d491e20283ea).("ascii_composer/good_old_caps_lock"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., |
| 200 | &good_old_caps_lock_cxx . . $ rime/AsciiComposer#good_old_caps_lock_.); |
| 201 | } |
| 202 | } |
| 203 | if (auto bindings = config->GetMapcxx . . $ rime/Config#GetMap(75306b78ac454b69).("ascii_composer/switch_key"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).)) { |
| 204 | load_bindingscxx . . $ rime/load_bindings(b71f7dba03d730fd).(bindings, &bindings_cxx . . $ rime/AsciiComposer#bindings_.); |
| 205 | } else if (auto bindings = preset_config ? preset_config->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).GetMapcxx . . $ rime/Config#GetMap(75306b78ac454b69).( |
| 206 | "ascii_composer/switch_key"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) |
| 207 | : nullptrcxx . . $ std/shared_ptr#shared_ptr(6d988fd07f070dfc).) { |
| 208 | load_bindingscxx . . $ rime/load_bindings(b71f7dba03d730fd).(bindings, &bindings_cxx . . $ rime/AsciiComposer#bindings_.); |
| 209 | } else { |
| 210 | LOGcxx . . $ `<external>/8254875247241458228/logging.h:610:9`!(ERROR) <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Missing ascii bindings."; |
| 211 | return; |
| 212 | } |
| 213 | auto it = bindings_cxx . . $ rime/AsciiComposer#bindings_..findcxx . . $ std/map#find(36f8d56706583706).(XK_Caps_Lockcxx . . $ `include/X11/keysymdef.h:319:9`!); |
| 214 | if (it !=cxx . . $ std/`operator!=`(be6a71a859368080). bindings_cxx . . $ rime/AsciiComposer#bindings_..endcxx . . $ std/map#end(7e4de33083b6e738).()) { |
| 215 | caps_lock_switch_style_cxx . . $ rime/AsciiComposer#caps_lock_switch_style_. = it->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second.; |
| 216 | if (caps_lock_switch_style_cxx . . $ rime/AsciiComposer#caps_lock_switch_style_. == kAsciiModeSwitchInlinecxx . . $ rime/kAsciiModeSwitchInline. || |
| 217 | caps_lock_switch_style_cxx . . $ rime/AsciiComposer#caps_lock_switch_style_. == kAsciiModeSetcxx . . $ rime/kAsciiModeSet. || |
| 218 | caps_lock_switch_style_cxx . . $ rime/AsciiComposer#caps_lock_switch_style_. == kAsciiModeUnsetcxx . . $ rime/kAsciiModeUnset.) { |
| 219 | // can't do that |
| 220 | caps_lock_switch_style_cxx . . $ rime/AsciiComposer#caps_lock_switch_style_. = kAsciiModeSwitchClearcxx . . $ rime/kAsciiModeSwitchClear.; |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | bool AsciiComposercxx . . $ rime/AsciiComposer#::ToggleAsciiModeWithKeycxx . . $ rime/AsciiComposer#ToggleAsciiModeWithKey(83c267b20bac841a).(int key_code) { |
| 226 | auto it = bindings_cxx . . $ rime/AsciiComposer#bindings_..findcxx . . $ std/map#find(36f8d56706583706).(key_code); |
| 227 | if (it ==cxx . . $ std/`operator==`(be6a71a859368080). bindings_cxx . . $ rime/AsciiComposer#bindings_..endcxx . . $ std/map#end(7e4de33083b6e738).()) |
| 228 | return false; |
| 229 | AsciiModeSwitchStylecxx . . $ rime/AsciiModeSwitchStyle# style = it->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second.; |
| 230 | Contextcxx . . $ rime/Context#* ctx = engine_cxx . . $ rime/Processor#engine_.->contextcxx . . $ rime/Engine#context(8ec6c0085ff2c2ef).(); |
| 231 | bool old_mode = ctx->get_optioncxx . . $ rime/Context#get_option(13a55b95a0133754).("ascii_mode"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 232 | bool new_mode = (style == kAsciiModeSetcxx . . $ rime/kAsciiModeSet.) ? true |
| 233 | : (style == kAsciiModeUnsetcxx . . $ rime/kAsciiModeUnset.) ? false |
| 234 | : !old_mode; |
| 235 | if (old_mode == new_mode) { |
| 236 | return false; |
| 237 | } |
| 238 | SwitchAsciiModecxx . . $ rime/AsciiComposer#SwitchAsciiMode(e07271bd48dfd8d0).(new_mode, style); |
| 239 | toggle_with_caps_cxx . . $ rime/AsciiComposer#toggle_with_caps_. = (key_code == XK_Caps_Lockcxx . . $ `include/X11/keysymdef.h:319:9`!); |
| 240 | return true; |
| 241 | } |
| 242 | |
| 243 | void AsciiComposercxx . . $ rime/AsciiComposer#::SwitchAsciiModecxx . . $ rime/AsciiComposer#SwitchAsciiMode(e07271bd48dfd8d0).(bool ascii_mode, |
| 244 | AsciiModeSwitchStylecxx . . $ rime/AsciiModeSwitchStyle# style) { |
| 245 | DLOGcxx . . $ `<external>/8254875247241458228/logging.h:1330:9`!(INFO) <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "ascii mode: " <<cxx . . $ std/basic_ostream#`operator<<`(511cbee2d2e28827). ascii_mode <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", switch style: " <<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57). style; |
| 246 | Contextcxx . . $ rime/Context#* ctx = engine_cxx . . $ rime/Processor#engine_.->contextcxx . . $ rime/Engine#context(8ec6c0085ff2c2ef).(); |
| 247 | if (ctx->IsComposingcxx . . $ rime/Context#IsComposing(50ce9a9e25b4a850).()) { |
| 248 | connection_cxx . . $ rime/AsciiComposer#connection_..disconnectcxx . . $ boost/signals2/connection#disconnect(83f5f38750778ac8).(); |
| 249 | // temporary ascii mode in desired manner |
| 250 | if (style == kAsciiModeSwitchInlinecxx . . $ rime/kAsciiModeSwitchInline.) { |
| 251 | LOGcxx . . $ `<external>/8254875247241458228/logging.h:610:9`!(INFO) <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "converting current composition to " |
| 252 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). (ascii_mode ? "ascii" : "non-ascii") <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " mode."; |
| 253 | if (ascii_mode) { |
| 254 | connection_cxx . . $ rime/AsciiComposer#connection_. =cxx . . $ boost/signals2/connection#`operator=`(b5fd643942a075fa). ctx->update_notifiercxx . . $ rime/Context#update_notifier(8686f0606cb7cf65).().connectcxx . . $ boost/signals2/signal#connect(ee62ba580b9ca126).( |
| 255 | [cxx . . $ boost/signals2/slot#slot(edcd8b2679e9bd1a).this](Contextcxx . . $ rime/Context#* ctx) { OnContextUpdatecxx . . $ rime/AsciiComposer#OnContextUpdate(7157cea0da45bf75).(ctx); }); |
| 256 | } |
| 257 | } else if (style == kAsciiModeSwitchCommitTextcxx . . $ rime/kAsciiModeSwitchCommitText.) { |
| 258 | ctx->ConfirmCurrentSelectioncxx . . $ rime/Context#ConfirmCurrentSelection(c9857a73d68e59ba).(); |
| 259 | } else if (style == kAsciiModeSwitchCommitCodecxx . . $ rime/kAsciiModeSwitchCommitCode.) { |
| 260 | ctx->ClearNonConfirmedCompositioncxx . . $ rime/Context#ClearNonConfirmedComposition(c9857a73d68e59ba).(); |
| 261 | ctx->Commitcxx . . $ rime/Context#Commit(c9857a73d68e59ba).(); |
| 262 | } else if (style == kAsciiModeSwitchClearcxx . . $ rime/kAsciiModeSwitchClear. || style == kAsciiModeSetcxx . . $ rime/kAsciiModeSet. || |
| 263 | style == kAsciiModeUnsetcxx . . $ rime/kAsciiModeUnset.) { |
| 264 | ctx->Clearcxx . . $ rime/Context#Clear(49f6e7a06ebc5aa8).(); |
| 265 | } |
| 266 | } |
| 267 | // refresh non-confirmed composition with new mode |
| 268 | ctx->set_optioncxx . . $ rime/Context#set_option(a3b17e0268c60856).("ascii_mode"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., ascii_mode); |
| 269 | } |
| 270 | |
| 271 | void AsciiComposercxx . . $ rime/AsciiComposer#::OnContextUpdatecxx . . $ rime/AsciiComposer#OnContextUpdate(7157cea0da45bf75).(Contextcxx . . $ rime/Context#* ctx) { |
| 272 | if (!ctx->IsComposingcxx . . $ rime/Context#IsComposing(50ce9a9e25b4a850).()) { |
| 273 | connection_cxx . . $ rime/AsciiComposer#connection_..disconnectcxx . . $ boost/signals2/connection#disconnect(83f5f38750778ac8).(); |
| 274 | // quit temporary ascii mode |
| 275 | ctx->set_optioncxx . . $ rime/Context#set_option(a3b17e0268c60856).("ascii_mode"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., false); |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | } // namespace rime |