Skip to content

Commit 5d22da4

Browse files
authored
Add disable zoom on mac (#3289)
* Add disable zoom on mac * Add changelog line * Add zommable in main.m I see this file is ignore, but i think it's better to keep it up-to-date so if we ever unignore it will work correctly.
1 parent e714dd9 commit 5d22da4

File tree

9 files changed

+25
-9
lines changed

9 files changed

+25
-9
lines changed

v2/internal/frontend/desktop/darwin/Application.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#define WindowStartsMinimised 2
1818
#define WindowStartsFullscreen 3
1919

20-
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int devtoolsEnabled, int defaultContextMenuEnabled, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled, struct Preferences preferences, int singleInstanceEnabled, const char* singleInstanceUniqueId);
20+
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int zoomable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int devtoolsEnabled, int defaultContextMenuEnabled, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled, struct Preferences preferences, int singleInstanceEnabled, const char* singleInstanceUniqueId);
2121
void Run(void*, const char* url);
2222

2323
void SetTitle(void* ctx, const char *title);

v2/internal/frontend/desktop/darwin/Application.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#import "WailsMenu.h"
1515
#import "WailsMenuItem.h"
1616

17-
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int devtoolsEnabled, int defaultContextMenuEnabled, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled, struct Preferences preferences, int singleInstanceLockEnabled, const char* singleInstanceUniqueId) {
17+
WailsContext* Create(const char* title, int width, int height, int frameless, int resizable, int zoomable, int fullscreen, int fullSizeContent, int hideTitleBar, int titlebarAppearsTransparent, int hideTitle, int useToolbar, int hideToolbarSeparator, int webviewIsTransparent, int alwaysOnTop, int hideWindowOnClose, const char *appearance, int windowIsTranslucent, int devtoolsEnabled, int defaultContextMenuEnabled, int windowStartState, int startsHidden, int minWidth, int minHeight, int maxWidth, int maxHeight, bool fraudulentWebsiteWarningEnabled, struct Preferences preferences, int singleInstanceLockEnabled, const char* singleInstanceUniqueId) {
1818

1919
[NSApplication sharedApplication];
2020

@@ -27,7 +27,7 @@
2727
fullscreen = 1;
2828
}
2929

30-
[result CreateWindow:width :height :frameless :resizable :fullscreen :fullSizeContent :hideTitleBar :titlebarAppearsTransparent :hideTitle :useToolbar :hideToolbarSeparator :webviewIsTransparent :hideWindowOnClose :safeInit(appearance) :windowIsTranslucent :minWidth :minHeight :maxWidth :maxHeight :fraudulentWebsiteWarningEnabled :preferences];
30+
[result CreateWindow:width :height :frameless :resizable :zoomable :fullscreen :fullSizeContent :hideTitleBar :titlebarAppearsTransparent :hideTitle :useToolbar :hideToolbarSeparator :webviewIsTransparent :hideWindowOnClose :safeInit(appearance) :windowIsTranslucent :minWidth :minHeight :maxWidth :maxHeight :fraudulentWebsiteWarningEnabled :preferences];
3131
[result SetTitle:safeInit(title)];
3232
[result Center];
3333

v2/internal/frontend/desktop/darwin/WailsContext.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct Preferences {
6464
bool *fullscreenEnabled;
6565
};
6666

67-
- (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString *)appearance :(bool)windowIsTranslucent :(int)minWidth :(int)minHeight :(int)maxWidth :(int)maxHeight :(bool)fraudulentWebsiteWarningEnabled :(struct Preferences)preferences;
67+
- (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)zoomable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString *)appearance :(bool)windowIsTranslucent :(int)minWidth :(int)minHeight :(int)maxWidth :(int)maxHeight :(bool)fraudulentWebsiteWarningEnabled :(struct Preferences)preferences;
6868
- (void) SetSize:(int)width :(int)height;
6969
- (void) SetPosition:(int)x :(int) y;
7070
- (void) SetMinSize:(int)minWidth :(int)minHeight;

v2/internal/frontend/desktop/darwin/WailsContext.m

+5-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ - (BOOL) isFullscreen {
136136
return NO;
137137
}
138138

139-
- (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString*)appearance :(bool)windowIsTranslucent :(int)minWidth :(int)minHeight :(int)maxWidth :(int)maxHeight :(bool)fraudulentWebsiteWarningEnabled :(struct Preferences)preferences {
139+
- (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable :(bool)zoomable :(bool)fullscreen :(bool)fullSizeContent :(bool)hideTitleBar :(bool)titlebarAppearsTransparent :(bool)hideTitle :(bool)useToolbar :(bool)hideToolbarSeparator :(bool)webviewIsTransparent :(bool)hideWindowOnClose :(NSString*)appearance :(bool)windowIsTranslucent :(int)minWidth :(int)minHeight :(int)maxWidth :(int)maxHeight :(bool)fraudulentWebsiteWarningEnabled :(struct Preferences)preferences {
140140
NSWindowStyleMask styleMask = 0;
141141

142142
if( !frameless ) {
@@ -158,7 +158,6 @@ - (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable
158158

159159
self.mainWindow = [[WailsWindow alloc] initWithContentRect:NSMakeRect(0, 0, width, height)
160160
styleMask:styleMask backing:NSBackingStoreBuffered defer:NO];
161-
162161
if (!frameless && useToolbar) {
163162
id toolbar = [[NSToolbar alloc] initWithIdentifier:@"wails.toolbar"];
164163
[toolbar autorelease];
@@ -188,6 +187,10 @@ - (void) CreateWindow:(int)width :(int)height :(bool)frameless :(bool)resizable
188187
[self.mainWindow setAppearance:nsAppearance];
189188
}
190189

190+
if (!zoomable && resizable) {
191+
NSButton *button = [self.mainWindow standardWindowButton:NSWindowZoomButton];
192+
[button setEnabled: NO];
193+
}
191194

192195
NSSize minSize = { minWidth, minHeight };
193196
NSSize maxSize = { maxWidth, maxHeight };

v2/internal/frontend/desktop/darwin/main.m

+2-1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ int main(int argc, const char * argv[]) {
203203
// insert code here...
204204
int frameless = 0;
205205
int resizable = 1;
206+
int zoomable = 0;
206207
int fullscreen = 1;
207208
int fullSizeContent = 1;
208209
int hideTitleBar = 0;
@@ -219,7 +220,7 @@ int main(int argc, const char * argv[]) {
219220
int defaultContextMenuEnabled = 1;
220221
int windowStartState = 0;
221222
int startsHidden = 0;
222-
WailsContext *result = Create("OI OI!",400,400, frameless, resizable, fullscreen, fullSizeContent, hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent, alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, devtoolsEnabled, defaultContextMenuEnabled, windowStartState,
223+
WailsContext *result = Create("OI OI!",400,400, frameless, resizable, zoomable, fullscreen, fullSizeContent, hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent, alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, devtoolsEnabled, defaultContextMenuEnabled, windowStartState,
223224
startsHidden, 400, 400, 600, 600, false);
224225
SetBackgroundColour(result, 255, 0, 0, 255);
225226
void *m = NewMenu("");

v2/internal/frontend/desktop/darwin/window.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func NewWindow(frontendOptions *options.App, debug bool, devtools bool) *Window
6060
defaultContextMenuEnabled := bool2Cint(debug || frontendOptions.EnableDefaultContextMenu)
6161
singleInstanceEnabled := bool2Cint(frontendOptions.SingleInstanceLock != nil)
6262

63-
var fullSizeContent, hideTitleBar, hideTitle, useToolbar, webviewIsTransparent C.int
63+
var fullSizeContent, hideTitleBar, zoomable, hideTitle, useToolbar, webviewIsTransparent C.int
6464
var titlebarAppearsTransparent, hideToolbarSeparator, windowIsTranslucent C.int
6565
var appearance, title *C.char
6666
var preferences C.struct_Preferences
@@ -108,12 +108,14 @@ func NewWindow(frontendOptions *options.App, debug bool, devtools bool) *Window
108108
}
109109
}
110110

111+
zoomable = bool2Cint(!frontendOptions.Mac.DisableZoom)
112+
111113
windowIsTranslucent = bool2Cint(mac.WindowIsTranslucent)
112114
webviewIsTransparent = bool2Cint(mac.WebviewIsTransparent)
113115

114116
appearance = c.String(string(mac.Appearance))
115117
}
116-
var context *C.WailsContext = C.Create(title, width, height, frameless, resizable, fullscreen, fullSizeContent,
118+
var context *C.WailsContext = C.Create(title, width, height, frameless, resizable, zoomable, fullscreen, fullSizeContent,
117119
hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent,
118120
alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, devtoolsEnabled, defaultContextMenuEnabled,
119121
windowStartState, startsHidden, minWidth, minHeight, maxWidth, maxHeight, enableFraudulentWebsiteWarnings,

v2/pkg/options/mac/mac.go

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type Options struct {
2121
WebviewIsTransparent bool
2222
WindowIsTranslucent bool
2323
Preferences *Preferences
24+
DisableZoom bool
2425
// ActivationPolicy ActivationPolicy
2526
About *AboutInfo
2627
OnFileOpen func(filePath string) `json:"-"`

website/src/pages/changelog.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
## [Unreleased]
1616
- Added docs to help fix NixOs/Wayland font-size css issue. Added by @atterpac in [PR](https://github.com/wailsapp/wails/pull/3268)
1717
- Added -m (skip `go mod tidy`) flag to dev command by @te5se in [PR](https://github.com/wailsapp/wails/pull/3275)
18+
- Added mac option `DisableZoom` to remove zoom button. Added by @wizzymore in [PR](https://github.com/wailsapp/wails/pull/3289)
1819

1920
## v2.8.0 - 2024-02-08
2021

website/versioned_docs/version-v2.8.0/reference/options.mdx

+8
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func main() {
109109
Appearance: mac.NSAppearanceNameDarkAqua,
110110
WebviewIsTransparent: true,
111111
WindowIsTranslucent: false,
112+
DisableZoom: false,
112113
About: &mac.AboutInfo{
113114
Title: "My Application",
114115
Message: "© 2021 Me",
@@ -897,6 +898,13 @@ Mac: &mac.Options{
897898
}
898899
```
899900

901+
#### DisableZoom
902+
903+
By default, the window is zoomable. Setting this to `true` will disable the zoom button (green button).
904+
905+
Name: DisableZoom<br/>
906+
Type: `bool`
907+
900908
#### About
901909

902910
This configuration lets you set the title, message and icon for the "About" menu item in the app menu created by the "AppMenu" role.

0 commit comments

Comments
 (0)