Skip to content

Commit

Permalink
feat: toggle suspend in tray menu
Browse files Browse the repository at this point in the history
  • Loading branch information
amorphobia committed Sep 8, 2024
1 parent 7653d69 commit ca396ff
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
make -C ${JIANDAO_DIR}/deps/opencc-tonggui
cp ${JIANDAO_DIR}/deps/opencc-tonggui/opencc/* ${JIANDAO_DIR}/schema/opencc/
fi
rm ${JIANDAO_DIR}/schema/recipe.yaml
rm -f ${JIANDAO_DIR}/schema/recipe.yaml ${JIANDAO_DIR}/schema/rime.lua
mkdir -p ${WORK}/schemas/jiandao
cp -r ${JIANDAO_DIR}/schema/* ${WORK}/schemas/jiandao/
Expand Down
1 change: 1 addition & 0 deletions Lib/RabbitCommon.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ global RABBIT_FULL_MAINTENANCE := "2"

global TRAY_MENU_GRAYOUT := false
global STATUS_TOOLTIP := 2
global box := 0
global ASCII_MODE_FALSE_LABEL := "中文"
global ASCII_MODE_TRUE_LABEL := "西文"
global ASCII_MODE_FALSE_LABEL_ABBR := ""
Expand Down
16 changes: 14 additions & 2 deletions Lib/RabbitTrayMenu.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ A_TrayMenu.add()
A_TrayMenu.add("仓库主页", (*) => Run("https://github.com/amorphobia/rabbit"))
A_TrayMenu.add()
A_TrayMenu.add("重新部署", (*) => Deploy())
A_TrayMenu.add("禁用/启用玉兔毫", (*) => ToggleSuspend())
A_TrayMenu.add("退出玉兔毫", (*) => ExitApp())

Sync() {
Expand All @@ -46,6 +47,16 @@ Deploy() {
Run(A_AhkPath . " " . A_ScriptDir . "\RabbitDeployer.ahk deploy 1")
ExitApp()
}
ToggleSuspend() {
global rime, session_id, box, STATUS_TOOLTIP
ToolTip()
if box
box.Show("Hide")
rime.clear_composition(session_id)
Suspend(-1)
ToolTip(A_IsSuspended ? "禁用" : "启用", , , STATUS_TOOLTIP)
SetTimer(() => ToolTip(, , , STATUS_TOOLTIP), -2000)
}

if TRAY_MENU_GRAYOUT {
; A_TrayMenu.Disable("输入法设定")
Expand All @@ -58,7 +69,7 @@ if TRAY_MENU_GRAYOUT {
}

ClickHandler(wParam, lParam, msg, hWnd) {
if !rime || !IsSet(session_id) || !session_id
if !rime || !IsSet(session_id) || !session_id || A_IsSuspended
return
if lParam == WM_LBUTTONUP {
local old_ascii_mode := rime.get_option(session_id, "ascii_mode")
Expand All @@ -77,8 +88,9 @@ UpdateTrayTip(schema_name := TRAY_SCHEMA_NAME, ascii_mode := TRAY_ASCII_MODE, fu
TRAY_ASCII_MODE := !!ascii_mode
TRAY_FULL_SHAPE := !!full_shape
TRAY_ASCII_PUNCT := !!ascii_punct
local ss := A_IsSuspended ? "(禁用) " : ""
A_IconTip := Format(
"玉兔毫 {}`n左键切换模式,右键打开菜单`n{} | {} | {}", TRAY_SCHEMA_NAME,
"玉兔毫 {}{}`n左键切换模式,右键打开菜单`n{} | {} | {}", ss, TRAY_SCHEMA_NAME,
(TRAY_ASCII_MODE ? ASCII_MODE_TRUE_LABEL : ASCII_MODE_FALSE_LABEL),
(TRAY_FULL_SHAPE ? FULL_SHAPE_TRUE_LABEL : FULL_SHAPE_FALSE_LABEL),
(TRAY_ASCII_PUNCT ? ASCII_PUNCT_TRUE_LABEL : ASCII_PUNCT_FALSE_LABEL)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
- 因热键冲突而取消了一些按键注册
- 与某些软件适配较差
- 桌面版 QQ 的密码输入框无法使用:[QQ密码输入框(防键盘钩子)原理分析](https://blog.csdn.net/muyedongfeng/article/details/49308993)
[页面存档备份](https://web.archive.org/web/20240907052640/https://blog.csdn.net/muyedongfeng/article/details/49308993),存于互联网档案馆),请使用 <kbd>LCtrl</kbd> + <kbd>Space</kbd> 禁用 / 启用玉兔毫(左控制键加空格键,暂不支持自定义按键)
[页面存档备份](https://web.archive.org/web/20240907052640/https://blog.csdn.net/muyedongfeng/article/details/49308993),存于互联网档案馆),可右键点击任务栏图标选择禁用/启用玉兔毫,或是在 `rabbit.custom.yaml` 里设置 `suspend_hotkey` 指定快捷键来禁用/启用玉兔毫
7 changes: 1 addition & 6 deletions Rabbit.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,7 @@ ProcessKey(key, mask, this_hotkey) {
if (suspend_hotkey and suspend_hotkey_mask)
and (key = suspend_hotkey or SubStr(key, 2) = suspend_hotkey)
and (mask = suspend_hotkey_mask) {
ToolTip()
box.Show("Hide")
rime.clear_composition(session_id)
Suspend(-1)
ToolTip(A_IsSuspended ? "禁用" : "启用", , , STATUS_TOOLTIP)
SetTimer(() => ToolTip(, , , STATUS_TOOLTIP), -2000)
ToggleSuspend()
return
}

Expand Down

0 comments on commit ca396ff

Please sign in to comment.