Skip to content

Visual Studio Code, rebuilt in Rust

Rust

fix(menubar): set the translated Window menu as AppKit's windows menu

rokarturf08ebe0a5dad
diff --git a/native/crates/app/src/workbench/menubar.rs b/native/crates/app/src/workbench/menubar.rs
index c4b88ec0cf2..2f5df0cc239 100644
--- a/native/crates/app/src/workbench/menubar.rs
+++ b/native/crates/app/src/workbench/menubar.rs
@@ -342,9 +342,7 @@ fn native_menus(menubar: &Menubar, cx: &App) -> (Vec<Menu>, Vec<KeyBinding>) {
native_command("workbench.action.quit", &main_label("miQuit", "Quit {0}").replace("{0}", name), true, false, menubar, &mut key_equivalents, cx),
]);
let mut menus = vec![Menu::new(name).items(app_items)];
- // menubar.ts `setMacWindowMenu`: fix_up_app_kit_menus adds the AppKit role items around these.
- // shortcut: gpui-fast's gpui_macos makes the menu titled "Window" the windows menu (Wu took `Menu::window_menu`), so a
- // translated title loses the open-window list; flag it in gpui_macos when a language pack is verified.
+ // menubar.ts `setMacWindowMenu`: fix_up_app_kit_menus makes it the windows menu and adds the AppKit role items.
let window_menu = |key_equivalents: &mut Vec<KeyBinding>| {
Menu::new(main_label("mWindow", "Window")).items([
native_command("workbench.action.toggleWindowAlwaysOnTop", &main_label("mAlwaysOnTop", "Always on Top"), true, menubar.always_on_top, menubar, key_equivalents, cx),
@@ -477,8 +475,19 @@ fn fix_up_app_kit_menus() {
{
item.setTitle(&NSString::from_str(&native_label(&main_label("miPreferences", "&&Preferences"))));
}
+ // Electron's `role: 'window'`; gpui_macos makes only a menu titled "Window" the windows menu.
+ let title = NSString::from_str(&main_label("mWindow", "Window"));
+ let Some(window_menu) = app.mainMenu().and_then(|menu| menu.itemWithTitle(&title)).and_then(|item| item.submenu()) else { return };
+ if app.windowsMenu().as_ref() != Some(&window_menu) {
+ app.setWindowsMenu(Some(&window_menu));
+ // Set once the menu is in the menu bar, AppKit lists only the windows ordered in after it.
+ for window in app.windows() {
+ if window.isVisible() && !window.isExcludedFromWindowsMenu() {
+ app.addWindowsItem_title_filename(&window, &window.title(), false);
+ }
+ }
+ }
// menubar.ts `setMacWindowMenu` roles. AppKit adds its Move & Resize and tiling items after `performZoom:`.
- let Some(window_menu) = app.windowsMenu() else { return };
// SAFETY: each `action` is a selector NSWindow or NSApplication answers; `mtm` proves the main thread.
let item = |title: &str, action, key: &str| unsafe {
NSMenuItem::initWithTitle_action_keyEquivalent(mtm.alloc(), &NSString::from_str(title), Some(action), &NSString::from_str(key))
diff --git a/port/notes.md b/port/notes.md
index 1ecc9aaa566..1fe931e7b20 100644
--- a/port/notes.md
+++ b/port/notes.md
@@ -1109,7 +1109,8 @@ Work the port does at another time than 1.147.0, accepted with a measured same r
- Risks: one company's experimental fork; Retained Mode shows a stale view wherever the port changes state without `cx.notify()` (Wu repainted everything each frame, so a missing notify went unseen); gpui-fast's `view.rs` drops upstream's cache-by-bounds for `fast::retained` (its docs/upstream-sync.md), and `workbench/part_view.rs` (`AnyView::cached`) is the port's one cached view; the Chromium-fidelity patches below land in files gpui-fast rewrote (`taffy.rs` is a dead file behind `#[path = "fast/taffy.rs"]`, text and list layout go through `fast/`), so they are re-ports, not cherry-picks; the README's benchmark baseline changes with the GPUI. Retained Mode off for a comparison: `GPUI_VIEW_RETENTION=0`, or `Window::set_view_retention(false)` in tests.
- Sync: read gpui-fast's `UPSTREAM` and `script/check-upstream`, bump the rev in `native/Cargo.toml` and the vendored copy in one commit, reapply the port's vendor commits, rerun the M26 gate. Rollback: `main` is on Wu; dropping the branch undoes everything.
- Forced API changes (the build had 11 errors in `app` and 18 more in its tests, 0 on Wu; now 0 and 0):
- - Missing from gpui-fast, so the call sites fall back to plain paint, each with a `shortcut:` comment, until the patch is ported: `Window::paint_backdrop_blur` (Wu's own; `quick_input_view.rs` `frosted_glass` paints the tint without blur, `corner_lab.rs` too), `Window::layout_subpixel_x` and `TextStyleRefinement::strut_size` (189efc4c454; the `file_icons.rs` glyph at x 0, `icon_label.rs` without the 13px strut), `ListState::with_whole_pixel_item_heights` (40f47558cba; `settings_editor_view.rs`), `Menu::window_menu` (gpui-fast's gpui_macos makes the menu titled "Window" the windows menu; a translated title loses it).
+ - Missing from gpui-fast, so the call sites fall back to plain paint, each with a `shortcut:` comment, until the patch is ported: `Window::paint_backdrop_blur` (Wu's own; `quick_input_view.rs` `frosted_glass` paints the tint without blur, `corner_lab.rs` too), `Window::layout_subpixel_x` and `TextStyleRefinement::strut_size` (189efc4c454; the `file_icons.rs` glyph at x 0, `icon_label.rs` without the 13px strut), `ListState::with_whole_pixel_item_heights` (40f47558cba; `settings_editor_view.rs`).
+ - `Menu::window_menu` (Wu's own) is gone: gpui-fast's gpui_macos makes only the menu titled "Window" the windows menu (zed's rule). `menubar.rs` `fix_up_app_kit_menus` sets the translated one with `setWindowsMenu` and lists the open windows with `addWindowsItem` (set after the menu is in the menu bar, AppKit lists only windows ordered in later), as tauri-apps/muda `set_as_windows_menu_for_nsapp` does (MIT/Apache-2.0); vendoring gpui_macos for a flag was the other choice. Checked with the German language pack (`--locale de`): "Fenster" holds AppKit's Minimize, Zoom and tiling items and the window, as "Window" does in English; without the change it held only the port's three items.
- `chromium_baseline` (189efc4c454) is pure math: now a local function in `file_icons.rs`.
- `Window::paint_drop_shadows` lost Wu's `opaque_background` argument; the terminal passed `false`, which is what gpui-fast always does.
- `Keystroke::parse` and `KeyBinding::new` take `&'static str`, `Keystroke::unparse` an `OperatingSystem`: runtime strings go through `crate::parse_keystroke` (`parse_with_os` with `crate::host_os()`, Wu's `secondary-` rule) and the menu bar's key equivalents through `KeyBinding::load` with the `App`, so `native_menus` takes `cx`.