Use macOS cooperative app activation to activate app to foreground
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 38/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- macos, swift
调研方向
从列出的 activateIgnoringOtherApps 调用点开始,包括 addVimController、mvim 脚本、由 Makefile 驱动的 XCTest 执行以及 foreground()。确认 macOS 的激活行为,并决定哪些路径需要协作式 yielding。完成意味着替换已弃用的激活路径,同时保留 dock 和文件打开行为,并记录 foreground() 的限制。
由索引模型根据 Issue 内容生成。
描述
macOS 14 Sonoma deprecated the NSApplication API activateIgnoringOtherApps, and provides a new activate API along with a cooperative yieldActivation command that can be called by the host app. We should switch to using this API.
One issue is that calling activate requires the foreground app to cooperate and willingly yield. There are a few usages of activateIgnoringOtherApps right now:
- Using the "New Window" menu item on the Dock icon. I think this actually works automatically and the activate call may be superfluous.
- Opening a new Vim from the
mvimscript so the new Vim window would be in foreground. This wouldn't work as the terminal has foreground. Calling:guifrom non-GUI mode works similarly. (Note that currently directly invokingMacVim.app/Contents/MacOS/MacVimdoes not activate the app because of how the logic inaddVimControllerbut it's ok as it's not a normal path) - Invoking
:call foreground()in Vim. This also wouldn't just work as Vim does not have the right to gain activation when it's in background under this API model. - When opening a file by dragging it to the dock, etc. This should work as MacVim should gain focus when that happens.
- Running the new XCTest test cases. This also wouldn't just work if running the tests from terminal (e.g. in CI we just run
make -C src macvim-tests) as MacVim will fail to gain foreground this way. Running from Xcode will be fine though as Xcode will yield.
To fix 2/3/5, we probably need to run a simple Swift script that calls NSApplication.shared.yieldActivation(toApplicationWithBundleIdentifier: "org.vim.MacVim") to manually force the terminal to yield to MacVim. For 2 and 5, we can call them as part of the mvim script and Makefile, respectively.
For 3, it's a little tricky. If the foreground request is invoked as a remote call using the --remote family of commands, it would work, but MacVim will lose the ability to randomly bring itself to the foreground at will (e.g. running :sleep 2 | call foreground() would not work). This is probably ok as the foreground() API doesn't work on Win32 too and in general it's best to let the foreground app has agency over when focus unless the user manually clicked away.
Currently, in macOS 14, the activateIgnoringOtherApps API is only deprecated but it still works so there's no reason to do anything. Just keep this in mind for now. If macOS 15 formally breaks it, we will implement the fix along with the manual yielding from terminal so that calling mvim from terminal, running tests etc would still work. We don't really want to do anything until this API breaks because even fixing it "properly" we will still lose case (3) where call foreground() will stop working if not called using --remote.
- 主要语言
- Vim Script
- 星标
- 7.9k
- 派生
- 691
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
macvim-dev/macvim 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
macvim-dev/macvim#1697 · 4 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 76/100
macvim-dev/macvim#1658 ·
-
难度 2/5 1-3 小时 新手友好度 76/100
macvim-dev/macvim#1657 ·
-
难度 2/5 1-3 小时 新手友好度 76/100
macvim-dev/macvim#1655 ·
-
难度 2/5 半天 新手友好度 72/100
macvim-dev/macvim#1653 ·
查看 macvim-dev/macvim 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
farion1231/cc-switch#7638 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
PolyMeilex/rfd#334 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
-
area:general bug P1 security
难度 2/5 1-3 小时 新手友好度 75/100
uttrflow/uttrflow-swift#1333 ·
-
难度 2/5 1-3 小时 新手友好度 75/100