mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
Add control to disable window buttons on Mac
Three new options have been introduced in the application options for MacOS to disable the minimize, maximize, and close buttons on the window. Corresponding functionality has been added in the webview window for darwin to handle these new options. These changes have been showcased in the window example main.go file.
This commit is contained in:
@@ -67,6 +67,9 @@ func main() {
|
||||
Windows: application.WindowsWindow{
|
||||
DisableMinimiseButton: true,
|
||||
},
|
||||
Mac: application.MacWindow{
|
||||
DisableMinimiseButton: true,
|
||||
},
|
||||
}).
|
||||
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
|
||||
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
|
||||
@@ -80,6 +83,24 @@ func main() {
|
||||
Windows: application.WindowsWindow{
|
||||
DisableMaximiseButton: true,
|
||||
},
|
||||
Mac: application.MacWindow{
|
||||
DisableMaximiseButton: true,
|
||||
},
|
||||
}).
|
||||
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
|
||||
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetURL("https://wails.io").
|
||||
Show()
|
||||
windowCounter++
|
||||
})
|
||||
}
|
||||
if runtime.GOOS == "darwin" {
|
||||
myMenu.Add("New WebviewWindow (Disable Close)").
|
||||
OnClick(func(ctx *application.Context) {
|
||||
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
||||
Mac: application.MacWindow{
|
||||
DisableCloseButton: true,
|
||||
},
|
||||
}).
|
||||
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
|
||||
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
|
||||
@@ -89,6 +110,7 @@ func main() {
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
myMenu.Add("New WebviewWindow (Hides on Close one time)").
|
||||
SetAccelerator("CmdOrCtrl+H").
|
||||
OnClick(func(ctx *application.Context) {
|
||||
|
||||
@@ -52,6 +52,15 @@ type MacWindow struct {
|
||||
|
||||
// WebviewPreferences contains preferences for the webview
|
||||
WebviewPreferences MacWebviewPreferences
|
||||
|
||||
// Disables the minimise button
|
||||
DisableMinimiseButton bool
|
||||
|
||||
// Disables the maximise button
|
||||
DisableMaximiseButton bool
|
||||
|
||||
// Disables the close button
|
||||
DisableCloseButton bool
|
||||
}
|
||||
|
||||
// MacWebviewPreferences contains preferences for the Mac webview
|
||||
|
||||
@@ -634,6 +634,24 @@ static void windowHide(void *window) {
|
||||
[(WebviewWindow*)window orderOut:nil];
|
||||
}
|
||||
|
||||
static void enableMinimiseButton(void *window, bool enabled) {
|
||||
WebviewWindow* nsWindow = (WebviewWindow*)window;
|
||||
NSButton *minimiseButton = [nsWindow standardWindowButton:NSWindowMiniaturizeButton];
|
||||
minimiseButton.enabled = enabled;
|
||||
}
|
||||
|
||||
static void enableMaximiseButton(void *window, bool enabled) {
|
||||
WebviewWindow* nsWindow = (WebviewWindow*)window;
|
||||
NSButton *maximiseButton = [nsWindow standardWindowButton:NSWindowZoomButton];
|
||||
maximiseButton.enabled = enabled;
|
||||
}
|
||||
|
||||
static void enableCloseButton(void *window, bool enabled) {
|
||||
WebviewWindow* nsWindow = (WebviewWindow*)window;
|
||||
NSButton *closeButton = [nsWindow standardWindowButton:NSWindowCloseButton];
|
||||
closeButton.enabled = enabled;
|
||||
}
|
||||
|
||||
// windowShowMenu opens an NSMenu at the given coordinates
|
||||
static void windowShowMenu(void *window, void *menu, int x, int y) {
|
||||
NSMenu* nsMenu = (NSMenu*)menu;
|
||||
@@ -1108,6 +1126,16 @@ func (w *macosWebviewWindow) run() {
|
||||
case MacBackdropNormal:
|
||||
}
|
||||
|
||||
if macOptions.DisableMinimiseButton {
|
||||
C.enableMinimiseButton(w.nsWindow, C.bool(false))
|
||||
}
|
||||
if macOptions.DisableMaximiseButton {
|
||||
C.enableMaximiseButton(w.nsWindow, C.bool(false))
|
||||
}
|
||||
if macOptions.DisableCloseButton {
|
||||
C.enableCloseButton(w.nsWindow, C.bool(false))
|
||||
}
|
||||
|
||||
if options.IgnoreMouseEvents {
|
||||
C.windowIgnoreMouseEvents(w.nsWindow, C.bool(true))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user