diff --git a/v2/internal/ffenestri/ffenestri.go b/v2/internal/ffenestri/ffenestri.go index 8ec9d143d..41b213c95 100644 --- a/v2/internal/ffenestri/ffenestri.go +++ b/v2/internal/ffenestri/ffenestri.go @@ -139,8 +139,8 @@ func (a *Application) Run(incomingDispatcher Dispatcher, bindings string) error // C.DisableFrame(a.app) // } - if a.config.Colour != 0 { - r, g, b, alpha := intToColour(a.config.Colour) + if a.config.RGBA != 0 { + r, g, b, alpha := intToColour(a.config.RGBA) C.SetColour(a.app, r, g, b, alpha) } diff --git a/v2/internal/ffenestri/ffenestri_darwin.c b/v2/internal/ffenestri/ffenestri_darwin.c index 98cdfb28e..de670b1e3 100644 --- a/v2/internal/ffenestri/ffenestri_darwin.c +++ b/v2/internal/ffenestri/ffenestri_darwin.c @@ -119,6 +119,8 @@ struct Application { int green; int blue; int alpha; + int webviewIsTranparent; + const char *vibrancy; // Features int frame; @@ -148,7 +150,6 @@ struct Application { void TitlebarAppearsTransparent(struct Application* app) { app->titlebarAppearsTransparent = 1; - Debug("[x] setTitlebarAppearsTransparent %d", app->titlebarAppearsTransparent? YES:NO); } void HideTitle(struct Application *app) { @@ -167,6 +168,19 @@ void UseToolbar(struct Application *app) { app->useToolBar = 1; } +// WebviewIsTransparent will make the webview transparent +// revealing the Cocoa window underneath +void WebviewIsTransparent(struct Application *app) { + app->webviewIsTranparent = 1; +} + +// SetVibrancy will set the window's vibrancy to the +// given value +void SetVibrancy(struct Application *app, const char *vibrancy) { + app->vibrancy = vibrancy; +} + + void applyWindowColour(struct Application *app) { // Apply the colour only if the window has been created if( app->mainWindow != NULL ) { @@ -271,8 +285,10 @@ void* NewApplication(const char *title, int width, int height, int resizable, in result->fullSizeContent = 0; result->useToolBar = 0; result->hideToolbarSeparator = 0; + result->vibrancy = "NSAppearanceNameAqua"; result->titlebarAppearsTransparent = 0; + result->webviewIsTranparent = 0; result->sendMessageToBackend = (ffenestriCallback) messageFromWindowCallback; @@ -413,7 +429,6 @@ void SetSize(struct Application *app, int width, int height) { frame.origin.y = (frame.origin.y + frame.size.height) - (float)height; frame.size.width = (float)width; frame.size.height = (float)height; - dumpFrame("after", frame); msg(app->mainWindow, s("setFrame:display:animate:"), frame, 1, 0); ) @@ -837,6 +852,16 @@ void Run(void *applicationPointer, int argc, char **argv) { 1, 1)); + if( app->webviewIsTranparent == 1 ) { + msg(wkwebview, s("setValue:forKey:"), msg(c("NSNumber"), s("numberWithBool:"), 1), str("drawsTransparentBackground")); + } + + // Set Vibrancy + msg(mainWindow, s("setAppearance:"), + msg(c("NSAppearance"), s("appearanceNamed:"), str(app->vibrancy)) + ); + + // Finally call run Debug("Run called"); msg(application, s("run")); diff --git a/v2/internal/ffenestri/ffenestri_darwin.go b/v2/internal/ffenestri/ffenestri_darwin.go index d55a93eb1..340512cbb 100644 --- a/v2/internal/ffenestri/ffenestri_darwin.go +++ b/v2/internal/ffenestri/ffenestri_darwin.go @@ -11,6 +11,8 @@ extern void FullSizeContent(void *); extern void UseToolbar(void *); extern void HideToolbarSeparator(void *); extern void DisableFrame(void *); +extern void SetVibrancy(void *, const char *); +extern void WebviewIsTransparent(void *); */ import "C" @@ -51,4 +53,14 @@ func (a *Application) processPlatformSettings() { if titlebar.TitlebarAppearsTransparent && titlebar.HideTitle { C.DisableFrame(a.app) } + + // Process window vibrancy + if mac.Vibrancy != "" { + C.SetVibrancy(a.app, a.string2CString(string(mac.Vibrancy))) + } + + // Check if the webview should be transparent + if mac.WebviewIsTransparent { + C.WebviewIsTransparent(a.app) + } } diff --git a/v2/pkg/options/default.go b/v2/pkg/options/default.go index 847c53910..904a7e710 100644 --- a/v2/pkg/options/default.go +++ b/v2/pkg/options/default.go @@ -8,8 +8,10 @@ var Default = &App{ Width: 1024, Height: 768, DevTools: true, - Colour: 0xFFFFFFFF, + RGBA: 0xFFFFFFFF, Mac: &mac.Options{ - TitleBar: mac.TitleBarDefault(), + TitleBar: mac.TitleBarDefault(), + Vibrancy: mac.NSAppearanceNameAqua, + WebviewIsTransparent: false, }, } diff --git a/v2/pkg/options/mac/mac.go b/v2/pkg/options/mac/mac.go index dd365e65a..17dacc6b8 100644 --- a/v2/pkg/options/mac/mac.go +++ b/v2/pkg/options/mac/mac.go @@ -2,5 +2,7 @@ package mac // Options ae options speific to Mac type Options struct { - TitleBar *TitleBar + TitleBar *TitleBar + Vibrancy VibrancyType + WebviewIsTransparent bool } diff --git a/v2/pkg/options/mac/vibrancy.go b/v2/pkg/options/mac/vibrancy.go new file mode 100644 index 000000000..9759134fd --- /dev/null +++ b/v2/pkg/options/mac/vibrancy.go @@ -0,0 +1,21 @@ +package mac + +// VibrancyType is a type of vibrancy for Cocoa windows +type VibrancyType string + +const ( + // NSAppearanceNameAqua - The standard light system appearance. + NSAppearanceNameAqua VibrancyType = "NSAppearanceNameAqua" + // NSAppearanceNameDarkAqua - The standard dark system appearance. + NSAppearanceNameDarkAqua VibrancyType = "NSAppearanceNameDarkAqua" + // NSAppearanceNameVibrantLight - The light vibrant appearance + NSAppearanceNameVibrantLight VibrancyType = "NSAppearanceNameVibrantLight" + // NSAppearanceNameAccessibilityHighContrastAqua - A high-contrast version of the standard light system appearance. + NSAppearanceNameAccessibilityHighContrastAqua VibrancyType = "NSAppearanceNameAccessibilityHighContrastAqua" + // NSAppearanceNameAccessibilityHighContrastDarkAqua - A high-contrast version of the standard dark system appearance. + NSAppearanceNameAccessibilityHighContrastDarkAqua VibrancyType = "NSAppearanceNameAccessibilityHighContrastDarkAqua" + // NSAppearanceNameAccessibilityHighContrastVibrantLight - A high-contrast version of the light vibrant appearance. + NSAppearanceNameAccessibilityHighContrastVibrantLight VibrancyType = "NSAppearanceNameAccessibilityHighContrastVibrantLight" + // NSAppearanceNameAccessibilityHighContrastVibrantDark - A high-contrast version of the dark vibrant appearance. + NSAppearanceNameAccessibilityHighContrastVibrantDark VibrancyType = "NSAppearanceNameAccessibilityHighContrastVibrantDark" +) diff --git a/v2/pkg/options/options.go b/v2/pkg/options/options.go index e8494f955..1b54a000d 100644 --- a/v2/pkg/options/options.go +++ b/v2/pkg/options/options.go @@ -20,7 +20,7 @@ type App struct { MaxHeight int StartHidden bool DevTools bool - Colour int + RGBA int Mac *mac.Options } diff --git a/v2/test/runtime/frontend/src/assets/css/main.css b/v2/test/runtime/frontend/src/assets/css/main.css index 0877eb120..a7c00590b 100644 --- a/v2/test/runtime/frontend/src/assets/css/main.css +++ b/v2/test/runtime/frontend/src/assets/css/main.css @@ -3,6 +3,7 @@ body { font-family: 'Roboto'; min-height: 75rem; padding-top: 4.5rem; + background-color: #0000; } .form-check-label { diff --git a/v2/test/runtime/main.go b/v2/test/runtime/main.go index feb88410d..c480afcd6 100644 --- a/v2/test/runtime/main.go +++ b/v2/test/runtime/main.go @@ -22,11 +22,12 @@ func main() { Height: 620, DisableResize: false, Fullscreen: false, - Colour: 0xFF000088, + RGBA: 0xFF0000FF, Mac: &mac.Options{ // TitleBar: mac.TitleBarHidden(), // TitleBar: mac.TitleBarHiddenInset(), TitleBar: mac.TitleBarDefault(), + Vibrancy: mac.NSAppearanceNameDarkAqua, }, })