5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 07:10:40 +08:00

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.
This commit is contained in:
Cristian Bilu 2024-03-02 06:47:59 +02:00 committed by GitHub
parent e714dd92a8
commit 5d22da4126
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 25 additions and 9 deletions

View File

@ -17,7 +17,7 @@
#define WindowStartsMinimised 2 #define WindowStartsMinimised 2
#define WindowStartsFullscreen 3 #define WindowStartsFullscreen 3
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); 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);
void Run(void*, const char* url); void Run(void*, const char* url);
void SetTitle(void* ctx, const char *title); void SetTitle(void* ctx, const char *title);

View File

@ -14,7 +14,7 @@
#import "WailsMenu.h" #import "WailsMenu.h"
#import "WailsMenuItem.h" #import "WailsMenuItem.h"
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) { 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) {
[NSApplication sharedApplication]; [NSApplication sharedApplication];
@ -27,7 +27,7 @@ WailsContext* Create(const char* title, int width, int height, int frameless, in
fullscreen = 1; fullscreen = 1;
} }
[result CreateWindow:width :height :frameless :resizable :fullscreen :fullSizeContent :hideTitleBar :titlebarAppearsTransparent :hideTitle :useToolbar :hideToolbarSeparator :webviewIsTransparent :hideWindowOnClose :safeInit(appearance) :windowIsTranslucent :minWidth :minHeight :maxWidth :maxHeight :fraudulentWebsiteWarningEnabled :preferences]; [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];
[result SetTitle:safeInit(title)]; [result SetTitle:safeInit(title)];
[result Center]; [result Center];

View File

@ -64,7 +64,7 @@ struct Preferences {
bool *fullscreenEnabled; bool *fullscreenEnabled;
}; };
- (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; - (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;
- (void) SetSize:(int)width :(int)height; - (void) SetSize:(int)width :(int)height;
- (void) SetPosition:(int)x :(int) y; - (void) SetPosition:(int)x :(int) y;
- (void) SetMinSize:(int)minWidth :(int)minHeight; - (void) SetMinSize:(int)minWidth :(int)minHeight;

View File

@ -136,7 +136,7 @@ typedef void (^schemeTaskCaller)(id<WKURLSchemeTask>);
return NO; return NO;
} }
- (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 { - (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 {
NSWindowStyleMask styleMask = 0; NSWindowStyleMask styleMask = 0;
if( !frameless ) { if( !frameless ) {
@ -158,7 +158,6 @@ typedef void (^schemeTaskCaller)(id<WKURLSchemeTask>);
self.mainWindow = [[WailsWindow alloc] initWithContentRect:NSMakeRect(0, 0, width, height) self.mainWindow = [[WailsWindow alloc] initWithContentRect:NSMakeRect(0, 0, width, height)
styleMask:styleMask backing:NSBackingStoreBuffered defer:NO]; styleMask:styleMask backing:NSBackingStoreBuffered defer:NO];
if (!frameless && useToolbar) { if (!frameless && useToolbar) {
id toolbar = [[NSToolbar alloc] initWithIdentifier:@"wails.toolbar"]; id toolbar = [[NSToolbar alloc] initWithIdentifier:@"wails.toolbar"];
[toolbar autorelease]; [toolbar autorelease];
@ -188,6 +187,10 @@ typedef void (^schemeTaskCaller)(id<WKURLSchemeTask>);
[self.mainWindow setAppearance:nsAppearance]; [self.mainWindow setAppearance:nsAppearance];
} }
if (!zoomable && resizable) {
NSButton *button = [self.mainWindow standardWindowButton:NSWindowZoomButton];
[button setEnabled: NO];
}
NSSize minSize = { minWidth, minHeight }; NSSize minSize = { minWidth, minHeight };
NSSize maxSize = { maxWidth, maxHeight }; NSSize maxSize = { maxWidth, maxHeight };

View File

@ -203,6 +203,7 @@ int main(int argc, const char * argv[]) {
// insert code here... // insert code here...
int frameless = 0; int frameless = 0;
int resizable = 1; int resizable = 1;
int zoomable = 0;
int fullscreen = 1; int fullscreen = 1;
int fullSizeContent = 1; int fullSizeContent = 1;
int hideTitleBar = 0; int hideTitleBar = 0;
@ -219,7 +220,7 @@ int main(int argc, const char * argv[]) {
int defaultContextMenuEnabled = 1; int defaultContextMenuEnabled = 1;
int windowStartState = 0; int windowStartState = 0;
int startsHidden = 0; int startsHidden = 0;
WailsContext *result = Create("OI OI!",400,400, frameless, resizable, fullscreen, fullSizeContent, hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent, alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, devtoolsEnabled, defaultContextMenuEnabled, windowStartState, 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,
startsHidden, 400, 400, 600, 600, false); startsHidden, 400, 400, 600, 600, false);
SetBackgroundColour(result, 255, 0, 0, 255); SetBackgroundColour(result, 255, 0, 0, 255);
void *m = NewMenu(""); void *m = NewMenu("");

View File

@ -60,7 +60,7 @@ func NewWindow(frontendOptions *options.App, debug bool, devtools bool) *Window
defaultContextMenuEnabled := bool2Cint(debug || frontendOptions.EnableDefaultContextMenu) defaultContextMenuEnabled := bool2Cint(debug || frontendOptions.EnableDefaultContextMenu)
singleInstanceEnabled := bool2Cint(frontendOptions.SingleInstanceLock != nil) singleInstanceEnabled := bool2Cint(frontendOptions.SingleInstanceLock != nil)
var fullSizeContent, hideTitleBar, hideTitle, useToolbar, webviewIsTransparent C.int var fullSizeContent, hideTitleBar, zoomable, hideTitle, useToolbar, webviewIsTransparent C.int
var titlebarAppearsTransparent, hideToolbarSeparator, windowIsTranslucent C.int var titlebarAppearsTransparent, hideToolbarSeparator, windowIsTranslucent C.int
var appearance, title *C.char var appearance, title *C.char
var preferences C.struct_Preferences var preferences C.struct_Preferences
@ -108,12 +108,14 @@ func NewWindow(frontendOptions *options.App, debug bool, devtools bool) *Window
} }
} }
zoomable = bool2Cint(!frontendOptions.Mac.DisableZoom)
windowIsTranslucent = bool2Cint(mac.WindowIsTranslucent) windowIsTranslucent = bool2Cint(mac.WindowIsTranslucent)
webviewIsTransparent = bool2Cint(mac.WebviewIsTransparent) webviewIsTransparent = bool2Cint(mac.WebviewIsTransparent)
appearance = c.String(string(mac.Appearance)) appearance = c.String(string(mac.Appearance))
} }
var context *C.WailsContext = C.Create(title, width, height, frameless, resizable, fullscreen, fullSizeContent, var context *C.WailsContext = C.Create(title, width, height, frameless, resizable, zoomable, fullscreen, fullSizeContent,
hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent, hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent,
alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, devtoolsEnabled, defaultContextMenuEnabled, alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, devtoolsEnabled, defaultContextMenuEnabled,
windowStartState, startsHidden, minWidth, minHeight, maxWidth, maxHeight, enableFraudulentWebsiteWarnings, windowStartState, startsHidden, minWidth, minHeight, maxWidth, maxHeight, enableFraudulentWebsiteWarnings,

View File

@ -21,6 +21,7 @@ type Options struct {
WebviewIsTransparent bool WebviewIsTransparent bool
WindowIsTranslucent bool WindowIsTranslucent bool
Preferences *Preferences Preferences *Preferences
DisableZoom bool
// ActivationPolicy ActivationPolicy // ActivationPolicy ActivationPolicy
About *AboutInfo About *AboutInfo
OnFileOpen func(filePath string) `json:"-"` OnFileOpen func(filePath string) `json:"-"`

View File

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

View File

@ -109,6 +109,7 @@ func main() {
Appearance: mac.NSAppearanceNameDarkAqua, Appearance: mac.NSAppearanceNameDarkAqua,
WebviewIsTransparent: true, WebviewIsTransparent: true,
WindowIsTranslucent: false, WindowIsTranslucent: false,
DisableZoom: false,
About: &mac.AboutInfo{ About: &mac.AboutInfo{
Title: "My Application", Title: "My Application",
Message: "© 2021 Me", Message: "© 2021 Me",
@ -897,6 +898,13 @@ Mac: &mac.Options{
} }
``` ```
#### DisableZoom
By default, the window is zoomable. Setting this to `true` will disable the zoom button (green button).
Name: DisableZoom<br/>
Type: `bool`
#### About #### About
This configuration lets you set the title, message and icon for the "About" menu item in the app menu created by the "AppMenu" role. This configuration lets you set the title, message and icon for the "About" menu item in the app menu created by the "AppMenu" role.