Skip to content

Commit 0d373d6

Browse files
authored
register as English and enable password capability (#254)
This reverts commit 815e06c.
1 parent ba5bd5d commit 0d373d6

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

cmake/MacOSXBundleInfo.plist.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
<dict>
3434
<key>org.fcitx.inputmethod.fcitx5</key>
3535
<dict>
36-
<!-- register as Chinese to disable on login/Terminal sudo password input -->
37-
<key>TISIntendedLanguage</key>
38-
<string>zh-Hans</string>
3936
<key>tsInputModeMenuIconFileKey</key>
4037
<string>menu_icon.pdf</string>
4138
<key>tsInputModeAlternateMenuIconFileKey</key>

macosfrontend/macosfrontend-public.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ typedef std::array<uint8_t, 16> ICUUID;
88

99
// Though being UInt, 32b is enough for modifiers
1010
std::string process_key(ICUUID uuid, uint32_t unicode, uint32_t osxModifiers,
11-
uint16_t osxKeycode, bool isRelease) noexcept;
11+
uint16_t osxKeycode, bool isRelease,
12+
bool isPassword) noexcept;
1213

1314
ICUUID create_input_context(const char *appId, id client) noexcept;
1415
void destroy_input_context(ICUUID uuid) noexcept;

macosfrontend/macosfrontend.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,17 @@ void MacosFrontend::save() {
7878
safeSaveAsIni(config_, ConfPath);
7979
}
8080

81-
std::string MacosFrontend::keyEvent(ICUUID uuid, const Key &key,
82-
bool isRelease) {
81+
std::string MacosFrontend::keyEvent(ICUUID uuid, const Key &key, bool isRelease,
82+
bool isPassword) {
8383
auto *ic = this->findIC(uuid);
8484
if (!ic) {
8585
return "{}";
8686
}
87+
CapabilityFlags flags = CapabilityFlag::Preedit;
88+
if (isPassword) {
89+
flags |= CapabilityFlag::Password;
90+
}
91+
ic->setCapabilityFlags(flags);
8792
ic->focusIn();
8893
KeyEvent keyEvent(ic, key, isRelease);
8994
ic->isSyncEvent = true;
@@ -271,12 +276,13 @@ MacosInputContext::getCursorCoordinates(bool followCursor) {
271276
FCITX_ADDON_FACTORY_V2(macosfrontend, fcitx::MacosFrontendFactory);
272277

273278
std::string process_key(ICUUID uuid, uint32_t unicode, uint32_t osxModifiers,
274-
uint16_t osxKeycode, bool isRelease) noexcept {
279+
uint16_t osxKeycode, bool isRelease,
280+
bool isPassword) noexcept {
275281
const fcitx::Key parsedKey =
276282
osx_key_to_fcitx_key(unicode, osxModifiers, osxKeycode);
277283
return with_fcitx([=](Fcitx &fcitx) {
278284
auto that = dynamic_cast<fcitx::MacosFrontend *>(fcitx.frontend());
279-
return that->keyEvent(uuid, parsedKey, isRelease);
285+
return that->keyEvent(uuid, parsedKey, isRelease, isPassword);
280286
});
281287
}
282288

macosfrontend/macosfrontend.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
#define TERMINAL_USE_EN \
2424
R"JSON({"appPath": "/System/Applications/Utilities/Terminal.app", "appId": "com.apple.Terminal", "imName": "keyboard-us"})JSON"
2525

26-
// User deletes ABC to enable Fcitx5 on password input.
27-
#define PASSWORDS_USE_EN \
28-
R"JSON({"appPath": "/System/Applications/Passwords.app", "appId": "com.apple.Passwords", "imName": "keyboard-us"})JSON"
29-
3026
namespace fcitx {
3127

3228
class MacosInputContext;
@@ -42,10 +38,8 @@ struct AppIMAnnotation {
4238
FCITX_CONFIGURATION(
4339
MacosFrontendConfig,
4440
OptionWithAnnotation<std::vector<std::string>, AppIMAnnotation>
45-
appDefaultIM{this,
46-
"AppDefaultIM",
47-
_("App default IM"),
48-
{TERMINAL_USE_EN, PASSWORDS_USE_EN}};
41+
appDefaultIM{
42+
this, "AppDefaultIM", _("App default IM"), {TERMINAL_USE_EN}};
4943
Option<bool> simulateKeyRelease{this, "SimulateKeyRelease",
5044
_("Simulate key release")};
5145
Option<int, IntConstrain> simulateKeyReleaseDelay{
@@ -79,7 +73,8 @@ class MacosFrontend : public AddonInstance {
7973

8074
ICUUID createInputContext(const std::string &appId, id client);
8175
void destroyInputContext(ICUUID);
82-
std::string keyEvent(ICUUID, const Key &key, bool isRelease);
76+
std::string keyEvent(ICUUID, const Key &key, bool isRelease,
77+
bool isPassword);
8378
void focusIn(ICUUID);
8479
std::string focusOut(ICUUID);
8580

src/controller.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ class FcitxInputController: IMKInputController {
6868
guard let client = client as? IMKTextInput else {
6969
return false
7070
}
71-
let res = String(process_key(uuid, unicode, modsVal, code, isRelease))
71+
// It can change within an IMKInputController (e.g. sudo in Terminal), so must reevaluate before each key sent to IM.
72+
let isPassword = IsSecureEventInputEnabled()
73+
let res = String(process_key(uuid, unicode, modsVal, code, isRelease, isPassword))
7274
return processRes(client, res)
7375
}
7476

0 commit comments

Comments
 (0)