[v3 mac] Add DisableWindowShadow option

This commit is contained in:
Lea Anthony 2023-05-16 17:54:34 +10:00 committed by Misite Bao
commit 6a2343a1a0
4 changed files with 34 additions and 1 deletions

View file

@ -273,7 +273,11 @@ func main() {
app.InfoDialog().SetTitle(fmt.Sprintf("Screen %s", screen.ID)).SetMessage(msg).Show()
})
})
app.NewWebviewWindow()
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
Mac: application.MacWindow{
DisableWindowShadow: true,
},
})
app.SetMenu(menu)
err := app.Run()

View file

@ -44,6 +44,7 @@ const (
// MacWindow contains macOS specific options
type MacWindow struct {
Backdrop MacBackdrop
DisableWindowShadow bool
TitleBar MacTitleBar
Appearance MacAppearanceType
InvisibleTitleBarHeight int

View file

@ -642,6 +642,17 @@ void windowDestroy(void* nsWindow) {
});
}
// Remove drop shadow from window
void windowSetShadow(void* nsWindow, bool hasShadow) {
// Remove shadow on main thread
dispatch_async(dispatch_get_main_queue(), ^{
// get main window
WebviewWindow* window = (WebviewWindow*)nsWindow;
// set shadow
[window setHasShadow:hasShadow];
});
}
// windowClose closes the current window
static void windowClose(void *window) {
@ -841,6 +852,10 @@ func (w *macosWebviewWindow) setFrameless(frameless bool) {
}
}
func (w *macosWebviewWindow) setHasShadow(hasShadow bool) {
C.windowSetShadow(w.nsWindow, C.bool(hasShadow))
}
func (w *macosWebviewWindow) getScreen() (*Screen, error) {
return getScreenForWindow(w)
}
@ -1161,7 +1176,16 @@ func (w *macosWebviewWindow) run() {
}
if w.parent.options.Hidden == false {
C.windowShow(w.nsWindow)
w.setHasShadow(!w.parent.options.Mac.DisableWindowShadow)
} else {
// We have to wait until the window is shown before we can remove the shadow
var cancel func()
cancel = w.parent.On(events.Mac.WindowDidBecomeKey, func(_ *WindowEventContext) {
w.setHasShadow(!w.parent.options.Mac.DisableWindowShadow)
cancel()
})
}
})
}

View file

@ -1,11 +1,14 @@
//go:build darwin
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import "webview_window_darwin.h"
#import "../events/events.h"
extern void processMessage(unsigned int, const char*);
extern void processURLRequest(unsigned int, void *);
extern bool hasListeners(unsigned int);
@implementation WebviewWindow
- (WebviewWindow*) initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation;
{
@ -47,6 +50,7 @@ extern bool hasListeners(unsigned int);
[super dealloc];
}
@end
@implementation WebviewWindowDelegate
- (BOOL)windowShouldClose:(NSWindow *)sender {
if( self.hideOnClose ) {