From 0b82968c0f530f28a1c60e261a6e67e38d1c4de2 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Wed, 7 Feb 2024 08:45:14 +1100 Subject: [PATCH] Add option to disable min/max windows buttons This commit introduces the functionality to disable the minimise and maximise buttons on windows. These options have been added to the `application.WebviewWindowOptions` and integrated in the Windows application logic. Effectively, developers can now control the availability of these buttons in their windows applications. --- v3/examples/window/main.go | 29 +++++++++++++++++++ .../application/options_webview_window_win.go | 6 ++++ v3/pkg/application/webview_window_windows.go | 4 +++ 3 files changed, 39 insertions(+) diff --git a/v3/examples/window/main.go b/v3/examples/window/main.go index d930399dc..dc911173c 100644 --- a/v3/examples/window/main.go +++ b/v3/examples/window/main.go @@ -60,6 +60,35 @@ func main() { Show() windowCounter++ }) + if runtime.GOOS != "linux" { + myMenu.Add("New WebviewWindow (Disable Minimise)"). + OnClick(func(ctx *application.Context) { + app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + Windows: application.WindowsWindow{ + DisableMinimiseButton: true, + }, + }). + SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)). + SetRelativePosition(rand.Intn(1000), rand.Intn(800)). + SetURL("https://wails.io"). + Show() + windowCounter++ + }) + myMenu.Add("New WebviewWindow (Disable Maximise)"). + OnClick(func(ctx *application.Context) { + app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + Windows: application.WindowsWindow{ + DisableMaximiseButton: true, + }, + }). + SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)). + SetRelativePosition(rand.Intn(1000), rand.Intn(800)). + SetURL("https://wails.io"). + Show() + windowCounter++ + }) + + } myMenu.Add("New WebviewWindow (Hides on Close one time)"). SetAccelerator("CmdOrCtrl+H"). OnClick(func(ctx *application.Context) { diff --git a/v3/pkg/application/options_webview_window_win.go b/v3/pkg/application/options_webview_window_win.go index 1533aa234..9c51219a4 100644 --- a/v3/pkg/application/options_webview_window_win.go +++ b/v3/pkg/application/options_webview_window_win.go @@ -117,6 +117,12 @@ type WindowsWindow struct { // Permissions map for WebView2. If empty, default permissions will be granted. Permissions map[CoreWebView2PermissionKind]CoreWebView2PermissionState + + // Disables the minimise button + DisableMinimiseButton bool + + // Disables the maximise button + DisableMaximiseButton bool } type Theme int diff --git a/v3/pkg/application/webview_window_windows.go b/v3/pkg/application/webview_window_windows.go index 8e04dd851..642feef28 100644 --- a/v3/pkg/application/webview_window_windows.go +++ b/v3/pkg/application/webview_window_windows.go @@ -237,6 +237,10 @@ func (w *windowsWebviewWindow) run() { w.setSize(options.Width, options.Height) + // Min/max buttons + w.setStyle(!options.Windows.DisableMinimiseButton, w32.WS_MINIMIZEBOX) + w.setStyle(!options.Windows.DisableMaximiseButton, w32.WS_MAXIMIZEBOX) + // Register the window with the application getNativeApplication().registerWindow(w)