diff --git a/v2/internal/ffenestri/ffenestri.go b/v2/internal/ffenestri/ffenestri.go index a448e7ce0..2d5b7330f 100644 --- a/v2/internal/ffenestri/ffenestri.go +++ b/v2/internal/ffenestri/ffenestri.go @@ -167,7 +167,7 @@ func (a *Application) Run(incomingDispatcher Dispatcher, bindings string) error } if a.config.Colour != 0 { - r, b, g, alpha := intToColour(a.config.Colour) + r, g, b, alpha := intToColour(a.config.Colour) C.SetColour(a.app, r, g, b, alpha) } diff --git a/v2/internal/ffenestri/ffenestri_client.go b/v2/internal/ffenestri/ffenestri_client.go index 7af51d87f..de1ad5c94 100644 --- a/v2/internal/ffenestri/ffenestri_client.go +++ b/v2/internal/ffenestri/ffenestri_client.go @@ -115,7 +115,7 @@ func (c *Client) WindowSize(width int, height int) { // WindowSetColour sets the window colour func (c *Client) WindowSetColour(colour int) { - r, b, g, a := intToColour(colour) + r, g, b, a := intToColour(colour) C.SetColour(c.app.app, r, g, b, a) } diff --git a/v2/internal/ffenestri/ffenestri_darwin.c b/v2/internal/ffenestri/ffenestri_darwin.c index 526c7e611..9fca02cbf 100644 --- a/v2/internal/ffenestri/ffenestri_darwin.c +++ b/v2/internal/ffenestri/ffenestri_darwin.c @@ -158,11 +158,27 @@ void UseToolbar(struct Application *app) { app->useToolBar = 1; } +void applyWindowColour(struct Application *app) { + // Apply the colour only if the window has been created + if( app->mainWindow != NULL ) { + ON_MAIN_THREAD( + id colour = msg(c("NSColor"), s("colorWithCalibratedRed:green:blue:alpha:"), + (float)app->red / 255.0, + (float)app->green / 255.0, + (float)app->blue / 255.0, + (float)app->alpha / 255.0); + msg(app->mainWindow, s("setBackgroundColor:"), colour); + ) + } +} + void SetColour(struct Application *app, int red, int green, int blue, int alpha) { app->red = red; app->green = green; app->blue = blue; app->alpha = alpha; + + applyWindowColour(app); } void FullSizeContent(struct Application *app) { @@ -225,6 +241,8 @@ void* NewApplication(const char *title, int width, int height, int resizable, in result->maximised = 0; result->minimised = 0; + result->mainWindow = NULL; + // Features result->frame = 1; result->hideTitle = 0; @@ -234,7 +252,6 @@ void* NewApplication(const char *title, int width, int height, int resizable, in result->hideToolbarSeparator = 0; result->titlebarAppearsTransparent = 0; - printf("[l] setTitlebarAppearsTransparent %d\n", result->titlebarAppearsTransparent); result->sendMessageToBackend = (ffenestriCallback) messageFromWindowCallback; @@ -727,12 +744,7 @@ void Run(void *applicationPointer, int argc, char **argv) { msg(mainWindow, s("setStyleMask:"), decorations); // Set Colour - id colour = msg(c("NSColor"), s("colorWithCalibratedRed:green:blue:alpha:"), - (float)app->red / 255.0, - (float)app->green / 255.0, - (float)app->blue / 255.0, - (float)app->alpha / 255.0); - msg(mainWindow, s("setBackgroundColor:"), colour); + applyWindowColour(app); // Setup webview diff --git a/v2/internal/runtime/goruntime/window.go b/v2/internal/runtime/goruntime/window.go index e7e4c06c5..7c478da7f 100644 --- a/v2/internal/runtime/goruntime/window.go +++ b/v2/internal/runtime/goruntime/window.go @@ -16,7 +16,7 @@ type Window interface { SetTitle(title string) Fullscreen() UnFullscreen() - SetColour(colour string) + SetColour(colour int) } // Window exposes the Windows interface @@ -54,8 +54,8 @@ func (w *window) UnFullscreen() { w.bus.Publish("window:unfullscreen", "") } -// SetColour sets the window colour to the given string -func (w *window) SetColour(colour string) { +// SetColour sets the window colour to the given int +func (w *window) SetColour(colour int) { w.bus.Publish("window:setcolour", colour) } diff --git a/v2/test/runtime/runtime.go b/v2/test/runtime/runtime.go index 4399b821d..fefb576c7 100644 --- a/v2/test/runtime/runtime.go +++ b/v2/test/runtime/runtime.go @@ -62,7 +62,7 @@ func (r *RuntimeTest) UnFullscreen() { } // SetColour will call the Runtime.UnFullscreen method -func (r *RuntimeTest) SetColour(colour string) { +func (r *RuntimeTest) SetColour(colour int) { r.runtime.Window.SetColour(colour) }