Skip to content

Commit a367578

Browse files
authored
get current im id for switching back on update (#309)
1 parent f84026d commit a367578

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

assets/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
add_executable(get_im get_im.swift)
12
add_executable(switch_im switch_im.swift)
23

34
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/fcitx.icns"
@@ -33,6 +34,7 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/menu_icon_15.pdf"
3334
# Preserve execution permission
3435
install(PROGRAMS "${CMAKE_CURRENT_SOURCE_DIR}/uninstall.sh"
3536
"${CMAKE_CURRENT_SOURCE_DIR}/update.sh"
37+
"${CMAKE_CURRENT_BINARY_DIR}/get_im"
3638
"${CMAKE_CURRENT_BINARY_DIR}/switch_im"
3739
DESTINATION "${CMAKE_INSTALL_PREFIX}/Resources"
3840
)

assets/get_im.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Carbon
2+
3+
let enId = "org.fcitx.inputmethod.Fcitx5.fcitx5"
4+
5+
let inputSource = TISCopyCurrentKeyboardInputSource().takeRetainedValue()
6+
let id = TISGetInputSourceProperty(inputSource, kTISPropertyInputSourceID)
7+
if let id = id {
8+
print(Unmanaged<AnyObject>.fromOpaque(id).takeUnretainedValue() as? String ?? enId)
9+
} else {
10+
print(enId)
11+
}

assets/update.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ xattr -dr com.apple.quarantine "$APP_DIR"
2626
codesign --force --sign - --deep "$APP_DIR"
2727

2828
cd "$RESOURCES_DIR"
29+
im=$(su -m "$user" -c "./get_im")
2930
# Switching out is necessary, otherwise it doesn't show menu
3031
# Not sure which one so try both.
3132
su -m "$user" -c "./switch_im com.apple.keylayout.ABC"
@@ -53,6 +54,5 @@ killall Fcitx5
5354
# org.fcitx.inputmethod.Fcitx5 is our CFBundleIdentifier;
5455
# The rest is the keys under tsInputModeListKey trimming the org.fcitx.inputmethod.
5556

56-
# Not sure which one so try both.
57-
su -m "$user" -c "./switch_im org.fcitx.inputmethod.Fcitx5.fcitx5"
58-
su -m "$user" -c "./switch_im org.fcitx.inputmethod.Fcitx5.zhHans"
57+
# Switch back.
58+
su -m "$user" -c "./switch_im $im"

0 commit comments

Comments
 (0)