diff --git a/v2/internal/frontend/desktop/darwin/Role.h b/v2/internal/frontend/desktop/darwin/Role.h index 20e670689..6b8877a09 100644 --- a/v2/internal/frontend/desktop/darwin/Role.h +++ b/v2/internal/frontend/desktop/darwin/Role.h @@ -12,5 +12,6 @@ typedef int Role; static const Role AppMenu = 1; static const Role EditMenu = 2; +static const Role WindowMenu = 3; #endif /* Role_h */ diff --git a/v2/internal/frontend/desktop/darwin/WailsMenu.m b/v2/internal/frontend/desktop/darwin/WailsMenu.m index af03ca6b9..66e5dd399 100644 --- a/v2/internal/frontend/desktop/darwin/WailsMenu.m +++ b/v2/internal/frontend/desktop/darwin/WailsMenu.m @@ -68,12 +68,20 @@ appName = [[NSProcessInfo processInfo] processName]; } WailsMenu *appMenu = [[[WailsMenu new] initWithNSTitle:appName] autorelease]; + + if (ctx.aboutTitle != nil) { + [appMenu addItem:[self newMenuItemWithContext :ctx :[@"About " stringByAppendingString:appName] :@selector(About) :nil :0]]; + [appMenu addItem:[NSMenuItem separatorItem]]; + } + + [appMenu addItem:[self newMenuItem:[@"Hide " stringByAppendingString:appName] :@selector(hide:) :@"h" :NSEventModifierFlagCommand]]; + [appMenu addItem:[self newMenuItem:@"Hide Others" :@selector(hideOtherApplications:) :@"h" :(NSEventModifierFlagOption | NSEventModifierFlagCommand)]]; + [appMenu addItem:[self newMenuItem:@"Show All" :@selector(unhideAllApplications:) :@""]]; + [appMenu addItem:[NSMenuItem separatorItem]]; + id quitTitle = [@"Quit " stringByAppendingString:appName]; NSMenuItem* quitMenuItem = [self newMenuItem:quitTitle :@selector(Quit) :@"q" :NSEventModifierFlagCommand]; quitMenuItem.target = ctx; - if (ctx.aboutTitle != nil) { - [appMenu addItem:[self newMenuItemWithContext :ctx :[@"About " stringByAppendingString:appName] :@selector(About) :nil :0]]; - } [appMenu addItem:quitMenuItem]; [self appendSubmenu:appMenu]; break; @@ -100,6 +108,17 @@ [editMenu appendSubmenu:speechMenu]; [self appendSubmenu:editMenu]; + break; + } + case WindowMenu: + { + WailsMenu *windowMenu = [[[WailsMenu new] initWithNSTitle:@"Window"] autorelease]; + [windowMenu addItem:[self newMenuItem:@"Minimize" :@selector(performMiniaturize:) :@"m" :NSEventModifierFlagCommand]]; + [windowMenu addItem:[self newMenuItem:@"Zoom" :@selector(performZoom:) :@""]]; + [windowMenu addItem:[NSMenuItem separatorItem]]; + [windowMenu addItem:[self newMenuItem:@"Full Screen" :@selector(enterFullScreenMode:) :@"f" :(NSEventModifierFlagControl | NSEventModifierFlagCommand)]]; + [self appendSubmenu:windowMenu]; + break; } } diff --git a/v2/pkg/menu/menuroles.go b/v2/pkg/menu/menuroles.go index 62a193c8e..e6b15b243 100644 --- a/v2/pkg/menu/menuroles.go +++ b/v2/pkg/menu/menuroles.go @@ -8,8 +8,9 @@ type Role int // These constants need to be kept in sync with `v2/internal/frontend/desktop/darwin/Role.h` const ( - AppMenuRole Role = 1 - EditMenuRole = 2 + AppMenuRole Role = 1 + EditMenuRole = 2 + WindowMenuRole = 3 //AboutRole Role = "about" //UndoRole Role = "undo" //RedoRole Role = "redo" @@ -142,14 +143,16 @@ func ViewMenu() *MenuItem { Role: ViewMenuRole, } } +*/ // WindowMenu provides a MenuItem with the whole default "Window" menu (Minimize, Zoom, etc.). +// On MacOS currently all options in there won't work if the window is frameless. func WindowMenu() *MenuItem { return &MenuItem{ Role: WindowMenuRole, } } -*/ + // These roles are Mac only // AppMenu provides a MenuItem with the whole default "App" menu (About, Services, etc.) diff --git a/v2/pkg/options/options.go b/v2/pkg/options/options.go index 204a267c6..74b2aef72 100644 --- a/v2/pkg/options/options.go +++ b/v2/pkg/options/options.go @@ -160,10 +160,14 @@ func processMenus(appoptions *App) { switch runtime.GOOS { case "darwin": if appoptions.Menu == nil { - appoptions.Menu = menu.NewMenuFromItems( - menu.AppMenu(), + items := []*menu.MenuItem{ menu.EditMenu(), - ) + } + if !appoptions.Frameless { + items = append(items, menu.WindowMenu()) // Current options in Window Menu only work if not frameless + } + + appoptions.Menu = menu.NewMenuFromItems(menu.AppMenu(), items...) } } } diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index 7b596377b..eb69875ff 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added Nodejs version in `wails doctor`. Added by @misitebao in [PR](https://github.com/wailsapp/wails/pull/2546) - Added support for WebKit2GTK 2.40+ on Linux. This brings additional features for the [AssetServer](/docs/reference/options#assetserver), like support for HTTP Request Bodies. The app must be compiled with the Go build tag `webkit2_40` to activate support for this features. This also bumps the minimum requirement of WebKit2GTK to 2.40 for your app. Added by @stffabi in this [PR](https://github.com/wailsapp/wails/pull/2592) +- macOS: Added Window menu role with well known shortcuts "Minimize, Full-Screen and Zoom". Added by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2586) +- macOS: Added "Hide, Hide Others, Show All“ to appmenu. Added by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2586) ### Changed