-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v3] Add option for showing the toolbar in fullscreen mode on macOS #3282
Changes from all commits
6115727
4405006
43bddb2
bea05cf
8679461
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Show macOS Toolbar Example | ||
|
||
This example is a demonstration of the macOS option `ShowToolbarWhenFullscreen`, which keeps | ||
the system toolbar visible when in fullscreen mode. | ||
|
||
## Running the example | ||
|
||
To run the example (on macOS), simply run the following command: | ||
|
||
```bash | ||
go run . | ||
``` | ||
|
||
# Status | ||
|
||
| Platform | Status | | ||
|----------|---------| | ||
| Mac | Working | | ||
| Windows | N/A | | ||
| Linux | N/A | |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package main | ||
|
||
import ( | ||
_ "embed" | ||
"log" | ||
|
||
"github.com/wailsapp/wails/v3/pkg/application" | ||
) | ||
|
||
func main() { | ||
app := application.New(application.Options{ | ||
Name: "Show macOS Toolbar", | ||
Description: "A demo of the ShowToolbarWhenFullscreen option", | ||
Mac: application.MacOptions{ | ||
ApplicationShouldTerminateAfterLastWindowClosed: true, | ||
}, | ||
}) | ||
|
||
// Create window | ||
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ | ||
Title: "Toolbar hidden (default behaviour)", | ||
HTML: "<html><body><h1>Switch this window to fullscreen: the toolbar will be hidden</h1></body></html>", | ||
CSS: `body { background-color: blue; color: white; height: 100vh; display: flex; justify-content: center; align-items: center; }`, | ||
Mac: application.MacWindow{ | ||
TitleBar: application.MacTitleBar{ | ||
UseToolbar: true, | ||
HideToolbarSeparator: true, | ||
}, | ||
}, | ||
}) | ||
|
||
// Create window | ||
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ | ||
Title: "Toolbar visible", | ||
HTML: "<html><body><h1>Switch this window to fullscreen: the toolbar will stay visible</h1></body></html>", | ||
CSS: `body { background-color: red; color: white; height: 100vh; display: flex; justify-content: center; align-items: center; }`, | ||
Mac: application.MacWindow{ | ||
TitleBar: application.MacTitleBar{ | ||
UseToolbar: true, | ||
HideToolbarSeparator: true, | ||
ShowToolbarWhenFullscreen: true, | ||
}, | ||
}, | ||
}) | ||
|
||
err := app.Run() | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -443,30 +443,28 @@ void windowSetHideTitle(void* nsWindow, bool hideTitle) { | |
} | ||
|
||
// Set Window use toolbar | ||
void windowSetUseToolbar(void* nsWindow, bool useToolbar, int toolbarStyle) { | ||
void windowSetUseToolbar(void* nsWindow, bool useToolbar) { | ||
WebviewWindow* window = (WebviewWindow*)nsWindow; | ||
if( useToolbar ) { | ||
NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier:@"wails.toolbar"]; | ||
[toolbar autorelease]; | ||
[window setToolbar:toolbar]; | ||
|
||
// If macos 11 or higher, set toolbar style | ||
if (@available(macOS 11.0, *)) { | ||
[window setToolbarStyle:toolbarStyle]; | ||
} | ||
|
||
} else { | ||
[window setToolbar:nil]; | ||
} | ||
} | ||
|
||
// Set window toolbar style | ||
void windowSetToolbarStyle(void* nsWindow, int style) { | ||
WebviewWindow* window = (WebviewWindow*)nsWindow; | ||
// use @available to check if the function is available | ||
// if not, return | ||
if (@available(macOS 11.0, *)) { | ||
NSToolbar* toolbar = [(WebviewWindow*)nsWindow toolbar]; | ||
[toolbar setShowsBaselineSeparator:style]; | ||
NSToolbar* toolbar = [window toolbar]; | ||
if ( toolbar == nil ) { | ||
return; | ||
} | ||
[window setToolbarStyle:style]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
} | ||
} | ||
|
||
|
@@ -479,6 +477,15 @@ void windowSetHideToolbarSeparator(void* nsWindow, bool hideSeparator) { | |
[toolbar setShowsBaselineSeparator:!hideSeparator]; | ||
} | ||
|
||
// Configure the toolbar auto-hide feature | ||
void windowSetShowToolbarWhenFullscreen(void* window, bool setting) { | ||
WebviewWindow* nsWindow = (WebviewWindow*)window; | ||
// Get delegate | ||
WebviewWindowDelegate* delegate = (WebviewWindowDelegate*)[nsWindow delegate]; | ||
// Set height | ||
delegate.showToolbarWhenFullscreen = setting; | ||
} | ||
|
||
// Set Window appearance type | ||
void windowSetAppearanceTypeByName(void* nsWindow, const char *appearanceName) { | ||
// set window appearance type by name | ||
|
@@ -745,11 +752,12 @@ void windowFocus(void *window) { | |
*/ | ||
import "C" | ||
import ( | ||
"github.com/wailsapp/wails/v3/internal/assetserver" | ||
"github.com/wailsapp/wails/v3/internal/runtime" | ||
"sync" | ||
"unsafe" | ||
|
||
"github.com/wailsapp/wails/v3/internal/assetserver" | ||
"github.com/wailsapp/wails/v3/internal/runtime" | ||
|
||
"github.com/wailsapp/wails/v3/pkg/events" | ||
) | ||
|
||
|
@@ -968,7 +976,6 @@ func (w *macosWebviewWindow) setEnabled(enabled bool) { | |
} | ||
|
||
func (w *macosWebviewWindow) execJS(js string) { | ||
|
||
InvokeAsync(func() { | ||
if globalApplication.performingShutdown { | ||
return | ||
|
@@ -1146,11 +1153,12 @@ func (w *macosWebviewWindow) run() { | |
C.windowSetHideTitleBar(w.nsWindow, C.bool(titleBarOptions.Hide)) | ||
C.windowSetHideTitle(w.nsWindow, C.bool(titleBarOptions.HideTitle)) | ||
C.windowSetFullSizeContent(w.nsWindow, C.bool(titleBarOptions.FullSizeContent)) | ||
if titleBarOptions.UseToolbar { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check has been removed as the involved methods work correctly in any case. |
||
C.windowSetUseToolbar(w.nsWindow, C.bool(titleBarOptions.UseToolbar), C.int(titleBarOptions.ToolbarStyle)) | ||
} | ||
C.windowSetUseToolbar(w.nsWindow, C.bool(titleBarOptions.UseToolbar)) | ||
C.windowSetToolbarStyle(w.nsWindow, C.int(titleBarOptions.ToolbarStyle)) | ||
C.windowSetShowToolbarWhenFullscreen(w.nsWindow, C.bool(titleBarOptions.ShowToolbarWhenFullscreen)) | ||
C.windowSetHideToolbarSeparator(w.nsWindow, C.bool(titleBarOptions.HideToolbarSeparator)) | ||
} | ||
|
||
if macOptions.Appearance != "" { | ||
C.windowSetAppearanceTypeByName(w.nsWindow, C.CString(string(macOptions.Appearance))) | ||
} | ||
|
@@ -1186,7 +1194,7 @@ func (w *macosWebviewWindow) run() { | |
if options.CSS != "" { | ||
C.windowInjectCSS(w.nsWindow, C.CString(options.CSS)) | ||
} | ||
if options.Hidden == false { | ||
if !options.Hidden { | ||
C.windowShow(w.nsWindow) | ||
w.setHasShadow(!options.Mac.DisableShadow) | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -241,6 +241,13 @@ - (void)webView:(nonnull WKWebView *)webView stopURLSchemeTask:(nonnull id<WKURL | |
} | ||
} | ||
} | ||
- (NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main change is here: a new property on the delegate interface is used as a flag to either keep the default presentation options, or enable the |
||
if (self.showToolbarWhenFullscreen) { | ||
return proposedOptions; | ||
} else { | ||
return proposedOptions | NSApplicationPresentationAutoHideToolbar; | ||
} | ||
} | ||
// GENERATED EVENTS START | ||
- (void)windowDidBecomeKey:(NSNotification *)notification { | ||
if( hasListeners(EventWindowDidBecomeKey) ) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The signature of this method has changed because the style configuration is now done through the
windowSetToolbarStyle
method, as per the comment at line 467.