Browse Source

feat: update ime

master
Ein Verne 3 weeks ago
parent
commit
c3e6d794fa
  1. 77
      hammerspoon/ime.lua
  2. 210
      hammerspoon/init.lua

77
hammerspoon/ime.lua

@ -1,7 +1,9 @@
log = hs.logger.new('ime', 'debug')
-- you can find the source id by running `hs.keycodes.currentSourceID()`
local function zh()
hs.keycodes.currentSourceID("im.rime.inputmethod.Squirrel.Rime")
hs.keycodes.currentSourceID("im.rime.inputmethod.Squirrel.Hans")
end
local function en()
@ -17,45 +19,54 @@ local function jp()
end
-- app to expected ime config
local app2Ime = {
{'/System/Library/CoreServices/Finder.app', 'zh'},
{'/Applications/Alfred 4.app', 'zh'},
{'/Applications/Bitwarden.app', 'zh'},
{'/Applications/Dash.app', 'zh'},
{'/Applications/iTerm.app', 'zh'},
{'/Applications/Xcode.app', 'zh'},
{'/Applications/GoldenDict.app', 'zh'},
{'/Applications/Google Chrome.app', 'zh'},
{'/Applications/KakaoTalk.app', 'zh'},
{'/Applications/kitty.app', 'zh'},
{'/Applications/NeteaseMusic.app', 'zh'},
{'/Applications/System Preferences.app', 'zh'},
{'/Applications/MindNode.app', 'zh'},
{'/Applications/Obsidian.app', 'zh'},
{'/Applications/wechatwebdevtools.app', 'zh'},
{'/Applications/Warp.app', 'en'}, -- 添加这一行
{'/Applications/WeChat.app', 'zh'},
{'/Users/einverne/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app', 'zh'},
{'/Users/einverne/Applications/JetBrains Toolbox/PyCharm Professional.app', 'zh'},
local appName2Ime = {
{ 'Finder', 'en' },
{ 'Bitwarden', 'en' },
{ 'Code', 'en' },
{ 'Dash', 'zh' },
{ 'iTerm', 'zh' },
{ 'GoldenDict', 'zh' },
{ 'GoldenDict-ng', 'zh' },
{ 'Google Chrome', 'zh' },
{ 'IntelliJ IDEA', 'en' },
{ 'KakaoTalk', 'ko' },
{ 'kitty', 'en' },
{ 'NeteaseMusic', 'zh' },
{ 'MacVim', 'en' },
{ 'Raycast', 'en' },
{ 'System Preferences', 'en' },
{ 'SmartGit', 'en' },
{ 'MindNode', 'zh' },
{ 'Obsidian', 'zh' },
{ 'Postman', 'en' },
{ 'PyCharm', 'en' },
{ 'Vivaldi', 'zh' },
{ 'wechatwebdevtools', 'zh' },
{ 'Warp', 'en' },
{ 'WeChat', 'zh' },
{ 'Whistle', 'en' },
{ 'Xcode', 'zh' },
}
function updateFocusAppInputMethod()
local focusAppPath = hs.window.frontmostWindow():application():path()
log.d(focusAppPath)
local focusAppName = hs.window.frontmostWindow():application():name()
if focusAppName == nil then
return
end
-- hs.alert.show(focusAppPath)
for index, app in pairs(app2Ime) do
local appPath = app[1]
for index, app in pairs(appName2Ime) do
local appName = app[1]
local expectedIme = app[2]
if focusAppPath == appPath then
if focusAppName == appName then
if expectedIme == 'en' then
en()
elseif expectedIme == 'zh' then
zh()
elseif expectedIme == 'ko' then
ko()
elseif expectedIme == 'jp' then
jp()
else
ko()
zh()
end
break
end
@ -70,16 +81,16 @@ hs.hotkey.bind({'ctrl', 'cmd'}, ".", function()
.. "App name: "
.. hs.window.focusedWindow():application():name()
.. "\n"
.. "Bundle ID: "
.. hs.window.focusedWindow():application():bundleID()
.. "\n"
.. "IM source id: "
.. hs.keycodes.currentSourceID())
end)
-- Handle cursor focus and application's screen manage.
function applicationWatcher(appName, eventType, appObject)
log.i(eventType)
log.i("tet")
log.i(hs.application.watcher.activated)
if eventType == hs.application.watcher.activated then
if (eventType == hs.application.watcher.activated or eventType == hs.application.watcher.launched) then
updateFocusAppInputMethod()
end
end

210
hammerspoon/init.lua

@ -26,11 +26,15 @@ end
k = hs.hotkey.modal.new({}, "F17")
-- Enter Hyper Mode when F18 (Hyper/Capslock) is pressed
pressedF18 = function() k:enter() end
pressedF18 = function()
k:enter()
end
-- Leave Hyper Mode when F18 (Hyper/Capslock) is pressed,
-- send ESCAPE if no other keys are pressed.
releasedF18 = function() k:exit() end
releasedF18 = function()
k:exit()
end
f18 = hs.hotkey.bind({}, 'F18', pressedF18, releasedF18)
@ -69,8 +73,6 @@ end
hs.hotkey.bind(hyper, 'N', movieWinBetweenMonitors('next'))
hs.hotkey.bind(hyper, 'P', movieWinBetweenMonitors('previous'))
local grid = require 'hs.grid'
hs.hotkey.bind(hyper, ",", grid.show)
@ -109,7 +111,7 @@ homeSSID = "PhRouter_5G"
homeDDID1 = "EinVerne_5G"
lastSSID = hs.wifi.currentNetwork()
workSSID = "MIOffice-5G"
workSSID = "XXX-5G"
function selectKarabinerProfile(profile)
hs.execute("'/Library/Application Support/org.pqrs/Karabiner-Elements/bin/karabiner_cli' --select-profile '" .. profile .. "'")
@ -184,7 +186,6 @@ hs.network.reachability.forAddress(homeDNS):setCallback(function(self, flags)
end
end):start()
hs.hotkey.alertDuration = 0
hs.hints.showTitleThresh = 0
hs.window.animationDuration = 0
@ -212,8 +213,6 @@ else
end
end
function reloadConfig()
hs.reload()
hs.execute("/bin/launchctl kickstart -k \"gui/${UID}/homebrew.mxcl.yabai\"")
@ -240,7 +239,7 @@ if not hspoon_list then
"HCalendar",
--"HSaria2",
"WinWin",
"WifiNotifier",
--"WifiNotifier",
"WinRectangle",
"Caffeine",
"PomodoroTimer",
@ -285,9 +284,15 @@ end
-- appM modal environment
spoon.ModalMgr:new("appM")
local cmodal = spoon.ModalMgr.modal_list["appM"]
cmodal:bind('', 'escape', 'Deactivate appM', function() spoon.ModalMgr:deactivate({"appM"}) end)
cmodal:bind('', 'Q', 'Deactivate appM', function() spoon.ModalMgr:deactivate({"appM"}) end)
cmodal:bind('', 'tab', 'Toggle Cheatsheet', function() spoon.ModalMgr:toggleCheatsheet() end)
cmodal:bind('', 'escape', 'Deactivate appM', function()
spoon.ModalMgr:deactivate({ "appM" })
end)
cmodal:bind('', 'Q', 'Deactivate appM', function()
spoon.ModalMgr:deactivate({ "appM" })
end)
cmodal:bind('', 'tab', 'Toggle Cheatsheet', function()
spoon.ModalMgr:toggleCheatsheet()
end)
if not hsapp_list then
hsapp_list = {
{ key = 'f', name = 'Finder' },
@ -393,7 +398,9 @@ if spoon.HSaria2 then
hsaria2_keys = hsaria2_keys or { "alt", "D" }
if string.len(hsaria2_keys[2]) > 0 then
spoon.ModalMgr.supervisor:bind(hsaria2_keys[1], hsaria2_keys[2], 'Toggle aria2 Panel', function() spoon.HSaria2:togglePanel() end)
spoon.ModalMgr.supervisor:bind(hsaria2_keys[1], hsaria2_keys[2], 'Toggle aria2 Panel', function()
spoon.HSaria2:togglePanel()
end)
end
end
@ -414,9 +421,15 @@ end
if spoon.CountDown then
spoon.ModalMgr:new("countdownM")
local cmodal = spoon.ModalMgr.modal_list["countdownM"]
cmodal:bind('', 'escape', 'Deactivate countdownM', function() spoon.ModalMgr:deactivate({"countdownM"}) end)
cmodal:bind('', 'Q', 'Deactivate countdownM', function() spoon.ModalMgr:deactivate({"countdownM"}) end)
cmodal:bind('', 'tab', 'Toggle Cheatsheet', function() spoon.ModalMgr:toggleCheatsheet() end)
cmodal:bind('', 'escape', 'Deactivate countdownM', function()
spoon.ModalMgr:deactivate({ "countdownM" })
end)
cmodal:bind('', 'Q', 'Deactivate countdownM', function()
spoon.ModalMgr:deactivate({ "countdownM" })
end)
cmodal:bind('', 'tab', 'Toggle Cheatsheet', function()
spoon.ModalMgr:toggleCheatsheet()
end)
cmodal:bind('', '0', '5 Minutes Countdown', function()
spoon.CountDown:startFor(5)
spoon.ModalMgr:deactivate({ "countdownM" })
@ -452,37 +465,134 @@ end
if spoon.WinWin then
spoon.ModalMgr:new("resizeM")
local cmodal = spoon.ModalMgr.modal_list["resizeM"]
cmodal:bind('', 'escape', 'Deactivate resizeM', function() spoon.ModalMgr:deactivate({"resizeM"}) end)
cmodal:bind('', 'Q', 'Deactivate resizeM', function() spoon.ModalMgr:deactivate({"resizeM"}) end)
cmodal:bind('', 'tab', 'Toggle Cheatsheet', function() spoon.ModalMgr:toggleCheatsheet() end)
cmodal:bind('', 'A', 'Move Leftward', function() spoon.WinWin:stepMove("left") end, nil, function() spoon.WinWin:stepMove("left") end)
cmodal:bind('', 'D', 'Move Rightward', function() spoon.WinWin:stepMove("right") end, nil, function() spoon.WinWin:stepMove("right") end)
cmodal:bind('', 'W', 'Move Upward', function() spoon.WinWin:stepMove("up") end, nil, function() spoon.WinWin:stepMove("up") end)
cmodal:bind('', 'S', 'Move Downward', function() spoon.WinWin:stepMove("down") end, nil, function() spoon.WinWin:stepMove("down") end)
cmodal:bind('', 'H', 'Lefthalf of Screen', function() spoon.WinWin:stash() spoon.WinWin:moveAndResize("halfleft") end)
cmodal:bind('', 'L', 'Righthalf of Screen', function() spoon.WinWin:stash() spoon.WinWin:moveAndResize("halfright") end)
cmodal:bind('', 'K', 'Uphalf of Screen', function() spoon.WinWin:stash() spoon.WinWin:moveAndResize("halfup") end)
cmodal:bind('', 'J', 'Downhalf of Screen', function() spoon.WinWin:stash() spoon.WinWin:moveAndResize("halfdown") end)
cmodal:bind('', 'Y', 'NorthWest Corner', function() spoon.WinWin:stash() spoon.WinWin:moveAndResize("cornerNW") end)
cmodal:bind('', 'O', 'NorthEast Corner', function() spoon.WinWin:stash() spoon.WinWin:moveAndResize("cornerNE") end)
cmodal:bind('', 'U', 'SouthWest Corner', function() spoon.WinWin:stash() spoon.WinWin:moveAndResize("cornerSW") end)
cmodal:bind('', 'I', 'SouthEast Corner', function() spoon.WinWin:stash() spoon.WinWin:moveAndResize("cornerSE") end)
cmodal:bind('', 'F', 'Fullscreen', function() spoon.WinWin:stash() spoon.WinWin:moveAndResize("fullscreen") end)
cmodal:bind('', 'C', 'Center Window', function() spoon.WinWin:stash() spoon.WinWin:moveAndResize("center") end)
cmodal:bind('', '=', 'Stretch Outward', function() spoon.WinWin:moveAndResize("expand") end, nil, function() spoon.WinWin:moveAndResize("expand") end)
cmodal:bind('', '-', 'Shrink Inward', function() spoon.WinWin:moveAndResize("shrink") end, nil, function() spoon.WinWin:moveAndResize("shrink") end)
cmodal:bind('shift', 'H', 'Move Leftward', function() spoon.WinWin:stepResize("left") end, nil, function() spoon.WinWin:stepResize("left") end)
cmodal:bind('shift', 'L', 'Move Rightward', function() spoon.WinWin:stepResize("right") end, nil, function() spoon.WinWin:stepResize("right") end)
cmodal:bind('shift', 'K', 'Move Upward', function() spoon.WinWin:stepResize("up") end, nil, function() spoon.WinWin:stepResize("up") end)
cmodal:bind('shift', 'J', 'Move Downward', function() spoon.WinWin:stepResize("down") end, nil, function() spoon.WinWin:stepResize("down") end)
cmodal:bind('', 'left', 'Move to Left Monitor', function() spoon.WinWin:stash() spoon.WinWin:moveToScreen("left") end)
cmodal:bind('', 'right', 'Move to Right Monitor', function() spoon.WinWin:stash() spoon.WinWin:moveToScreen("right") end)
cmodal:bind('', 'up', 'Move to Above Monitor', function() spoon.WinWin:stash() spoon.WinWin:moveToScreen("up") end)
cmodal:bind('', 'down', 'Move to Below Monitor', function() spoon.WinWin:stash() spoon.WinWin:moveToScreen("down") end)
cmodal:bind('', 'space', 'Move to Next Monitor', function() spoon.WinWin:stash() spoon.WinWin:moveToScreen("next") end)
cmodal:bind('', '[', 'Undo Window Manipulation', function() spoon.WinWin:undo() end)
cmodal:bind('', ']', 'Redo Window Manipulation', function() spoon.WinWin:redo() end)
cmodal:bind('', '`', 'Center Cursor', function() spoon.WinWin:centerCursor() end)
cmodal:bind('', 'escape', 'Deactivate resizeM', function()
spoon.ModalMgr:deactivate({ "resizeM" })
end)
cmodal:bind('', 'Q', 'Deactivate resizeM', function()
spoon.ModalMgr:deactivate({ "resizeM" })
end)
cmodal:bind('', 'tab', 'Toggle Cheatsheet', function()
spoon.ModalMgr:toggleCheatsheet()
end)
cmodal:bind('', 'A', 'Move Leftward', function()
spoon.WinWin:stepMove("left")
end, nil, function()
spoon.WinWin:stepMove("left")
end)
cmodal:bind('', 'D', 'Move Rightward', function()
spoon.WinWin:stepMove("right")
end, nil, function()
spoon.WinWin:stepMove("right")
end)
cmodal:bind('', 'W', 'Move Upward', function()
spoon.WinWin:stepMove("up")
end, nil, function()
spoon.WinWin:stepMove("up")
end)
cmodal:bind('', 'S', 'Move Downward', function()
spoon.WinWin:stepMove("down")
end, nil, function()
spoon.WinWin:stepMove("down")
end)
cmodal:bind('', 'H', 'Lefthalf of Screen', function()
spoon.WinWin:stash()
spoon.WinWin:moveAndResize("halfleft")
end)
cmodal:bind('', 'L', 'Righthalf of Screen', function()
spoon.WinWin:stash()
spoon.WinWin:moveAndResize("halfright")
end)
cmodal:bind('', 'K', 'Uphalf of Screen', function()
spoon.WinWin:stash()
spoon.WinWin:moveAndResize("halfup")
end)
cmodal:bind('', 'J', 'Downhalf of Screen', function()
spoon.WinWin:stash()
spoon.WinWin:moveAndResize("halfdown")
end)
cmodal:bind('', 'Y', 'NorthWest Corner', function()
spoon.WinWin:stash()
spoon.WinWin:moveAndResize("cornerNW")
end)
cmodal:bind('', 'O', 'NorthEast Corner', function()
spoon.WinWin:stash()
spoon.WinWin:moveAndResize("cornerNE")
end)
cmodal:bind('', 'U', 'SouthWest Corner', function()
spoon.WinWin:stash()
spoon.WinWin:moveAndResize("cornerSW")
end)
cmodal:bind('', 'I', 'SouthEast Corner', function()
spoon.WinWin:stash()
spoon.WinWin:moveAndResize("cornerSE")
end)
cmodal:bind('', 'F', 'Fullscreen', function()
spoon.WinWin:stash()
spoon.WinWin:moveAndResize("fullscreen")
end)
cmodal:bind('', 'C', 'Center Window', function()
spoon.WinWin:stash()
spoon.WinWin:moveAndResize("center")
end)
cmodal:bind('', '=', 'Stretch Outward', function()
spoon.WinWin:moveAndResize("expand")
end, nil, function()
spoon.WinWin:moveAndResize("expand")
end)
cmodal:bind('', '-', 'Shrink Inward', function()
spoon.WinWin:moveAndResize("shrink")
end, nil, function()
spoon.WinWin:moveAndResize("shrink")
end)
cmodal:bind('shift', 'H', 'Move Leftward', function()
spoon.WinWin:stepResize("left")
end, nil, function()
spoon.WinWin:stepResize("left")
end)
cmodal:bind('shift', 'L', 'Move Rightward', function()
spoon.WinWin:stepResize("right")
end, nil, function()
spoon.WinWin:stepResize("right")
end)
cmodal:bind('shift', 'K', 'Move Upward', function()
spoon.WinWin:stepResize("up")
end, nil, function()
spoon.WinWin:stepResize("up")
end)
cmodal:bind('shift', 'J', 'Move Downward', function()
spoon.WinWin:stepResize("down")
end, nil, function()
spoon.WinWin:stepResize("down")
end)
cmodal:bind('', 'left', 'Move to Left Monitor', function()
spoon.WinWin:stash()
spoon.WinWin:moveToScreen("left")
end)
cmodal:bind('', 'right', 'Move to Right Monitor', function()
spoon.WinWin:stash()
spoon.WinWin:moveToScreen("right")
end)
cmodal:bind('', 'up', 'Move to Above Monitor', function()
spoon.WinWin:stash()
spoon.WinWin:moveToScreen("up")
end)
cmodal:bind('', 'down', 'Move to Below Monitor', function()
spoon.WinWin:stash()
spoon.WinWin:moveToScreen("down")
end)
cmodal:bind('', 'space', 'Move to Next Monitor', function()
spoon.WinWin:stash()
spoon.WinWin:moveToScreen("next")
end)
cmodal:bind('', '[', 'Undo Window Manipulation', function()
spoon.WinWin:undo()
end)
cmodal:bind('', ']', 'Redo Window Manipulation', function()
spoon.WinWin:redo()
end)
cmodal:bind('', '`', 'Center Cursor', function()
spoon.WinWin:centerCursor()
end)
-- Register resizeM with modal supervisor
hsresizeM_keys = hsresizeM_keys or { "alt", "R" }
@ -540,9 +650,9 @@ end
-- spoon.Caffeine:start()
-- end
if spoon.wifiNotifier then
spoon.wifiNotifier:start()
end
--if spoon.wifiNotifier then
-- spoon.wifiNotifier:start()
--end
log.d("PomodoroTimer Spoon loaded successfully")
if spoon.PomodoroTimer then

Loading…
Cancel
Save