macvim-dev / macvim-dev/macvim

Use macOS cooperative app activation to activate app to foreground

オープン
#1,456 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

14.0 Sonoma
主要言語
Vim Script
スター
7.9k
フォーク
691
PR マージ指標
30日以内にマージされた PR はありません

説明

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:

  1. Using the "New Window" menu item on the Dock icon. I think this actually works automatically and the activate call may be superfluous.
  2. Opening a new Vim from the mvim script so the new Vim window would be in foreground. This wouldn't work as the terminal has foreground. Calling :gui from non-GUI mode works similarly. (Note that currently directly invoking MacVim.app/Contents/MacOS/MacVim does not activate the app because of how the logic in addVimController but it's ok as it's not a normal path)
  3. 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.
  4. When opening a file by dragging it to the dock, etc. This should work as MacVim should gain focus when that happens.
  5. 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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

一覧にある activateIgnoringOtherApps の呼び出し箇所から始めます。addVimController、mvim スクリプト、Makefile 駆動の XCTest 実行、foreground() が含まれます。macOS のアクティベーション動作を確認し、どの経路で協調的な yield が必要かを判断します。完了の条件は、Dock とファイルを開く動作を維持しながら非推奨のアクティベーション経路を置き換え、foreground() の制限を文書化することです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
macos, swift
領域
desktop, operating-systems
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。