macvim-dev / macvim

Vim - the text editor - for macOS
https://macvim.org
Vim License
7.47k stars 680 forks source link

Add zoomLeft: / zoomRight: / macOS 13 Stage Manager actions #1330

Closed ychin closed 1 year ago

ychin commented 1 year ago

New zoomLeft/Right actions let the user easily pin the MacVim window to the left/right of the screen using the private APIs _zoomLeft: / _zoomRight:. This is similar to Windows' Aero Snap mode, and the functionality has been in macOS since 10.15. Unfortunately there isn't a public API for calling this.

Note that this could already be done if the user went to the Keyboard settings and added a shortcut key to the Window -> "Move Window to Right Side of Screen" menu, but I doubt a lot of people do that, and it's nicer to have script-level control of this. The other likely option users would have adopted is to use a third-party tool. This change mostly makes it possible to easily snap the windows without needing to use them.

Also, add new macOS 13 Ventura hooks for interfacing with Stage Manager. Expose the _removeWindowFromStageManagerSet:, which is the private API behind the new "Remove Window from Set" menu item, which removes the window from a mixed application set in Stage Manager. Similar to _zoomLeft:, this is a UI-only feature, and hence no public API is avaialble. Also, expose the collections API so that we can call join/unjoinAllStageManagerSets: to have MacVim windows float among all Stage Manager sets, which is useful for windows that need to show up next to other windows (e.g. a copy-and-paste scratchpad file).

Also add a new separator to the Window menu because macOS injects all the window/Stage Manager related menu items right after the "Zoom" item, and it kind of expects a separator to be right after it for the new items to be categorized right.

ychin commented 1 year ago

In case people want some default keybinds, this is what I put in my vimrc to make Cmd-Option-Left (right) quickly pin the MacVim to left (right) side of the screen.

if has("gui_macvim") && has("gui_running")
    noremap <M-D-Left> <Cmd>maca zoomLeft:<CR>
    noremap! <M-D-Left> <Cmd>maca zoomLeft:<CR>
    tnoremap <M-D-Left> <Cmd>maca zoomLeft:<CR>
    noremap <M-D-Right> <Cmd>maca zoomRight:<CR>
    noremap! <M-D-Right> <Cmd>maca zoomRight:<CR>
    tnoremap <M-D-Right> <Cmd>maca zoomRight:<CR>
endif