Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions assets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_executable(get_im get_im.swift)
add_executable(switch_im switch_im.swift)

install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/fcitx.icns"
Expand Down Expand Up @@ -33,6 +34,7 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/menu_icon_15.pdf"
# Preserve execution permission
install(PROGRAMS "${CMAKE_CURRENT_SOURCE_DIR}/uninstall.sh"
"${CMAKE_CURRENT_SOURCE_DIR}/update.sh"
"${CMAKE_CURRENT_BINARY_DIR}/get_im"
"${CMAKE_CURRENT_BINARY_DIR}/switch_im"
DESTINATION "${CMAKE_INSTALL_PREFIX}/Resources"
)
Expand Down
11 changes: 11 additions & 0 deletions assets/get_im.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Carbon

let enId = "org.fcitx.inputmethod.Fcitx5.fcitx5"

let inputSource = TISCopyCurrentKeyboardInputSource().takeRetainedValue()
let id = TISGetInputSourceProperty(inputSource, kTISPropertyInputSourceID)
if let id = id {
print(Unmanaged<AnyObject>.fromOpaque(id).takeUnretainedValue() as? String ?? enId)
} else {
print(enId)
}
6 changes: 3 additions & 3 deletions assets/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ xattr -dr com.apple.quarantine "$APP_DIR"
codesign --force --sign - --deep "$APP_DIR"

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

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