diff --git a/v2/internal/appoptions/default.go b/v2/internal/appoptions/default.go index d7753307..1c0d17b4 100644 --- a/v2/internal/appoptions/default.go +++ b/v2/internal/appoptions/default.go @@ -6,4 +6,5 @@ var Default = &Options{ Width: 1024, Height: 768, DevTools: true, + Colour: 0xFFFFFFFF, } diff --git a/v2/internal/appoptions/options.go b/v2/internal/appoptions/options.go index 4105578c..068ac516 100644 --- a/v2/internal/appoptions/options.go +++ b/v2/internal/appoptions/options.go @@ -14,6 +14,7 @@ type Options struct { MaxHeight int StartHidden bool DevTools bool + Colour int Mac MacOptions } diff --git a/v2/internal/ffenestri/ffenestri.go b/v2/internal/ffenestri/ffenestri.go index f355e098..a448e7ce 100644 --- a/v2/internal/ffenestri/ffenestri.go +++ b/v2/internal/ffenestri/ffenestri.go @@ -126,6 +126,14 @@ type DispatchClient interface { SendMessage(string) } +func intToColour(colour int) (C.int, C.int, C.int, C.int) { + var alpha = C.int(colour & 0xFF) + var blue = C.int((colour >> 8) & 0xFF) + var green = C.int((colour >> 16) & 0xFF) + var red = C.int((colour >> 24) & 0xFF) + return red, green, blue, alpha +} + // Run the application func (a *Application) Run(incomingDispatcher Dispatcher, bindings string) error { title := a.string2CString(a.config.Title) @@ -158,6 +166,11 @@ func (a *Application) Run(incomingDispatcher Dispatcher, bindings string) error C.DisableFrame(a.app) } + if a.config.Colour != 0 { + r, b, g, alpha := intToColour(a.config.Colour) + C.SetColour(a.app, r, g, b, alpha) + } + // Escape bindings so C doesn't freak out bindings = strings.ReplaceAll(bindings, `"`, `\"`) diff --git a/v2/internal/ffenestri/ffenestri.h b/v2/internal/ffenestri/ffenestri.h index e7f15326..da50b0d5 100644 --- a/v2/internal/ffenestri/ffenestri.h +++ b/v2/internal/ffenestri/ffenestri.h @@ -20,6 +20,7 @@ extern void ToggleMaximise(void *app); extern void Minimise(void *app); extern void Unminimise(void *app); extern void ToggleMinimise(void *app); +extern void SetColour(void *app, int red, int green, int blue, int alpha); extern void SetSize(void *app, int width, int height); extern void SetPosition(void *app, int x, int y); extern void Quit(void *app); @@ -27,7 +28,6 @@ extern void SetTitle(void *app, const char *title); extern void Fullscreen(void *app); extern void UnFullscreen(void *app); extern void ToggleFullscreen(void *app); -extern int SetColour(void *app, const char *colourString); extern void DisableFrame(void *app); extern char *SaveFileDialog(void *appPointer, char *title, char *filter); extern char *OpenFileDialog(void *appPointer, char *title, char *filter); diff --git a/v2/internal/ffenestri/ffenestri_client.go b/v2/internal/ffenestri/ffenestri_client.go index 5465865e..7af51d87 100644 --- a/v2/internal/ffenestri/ffenestri_client.go +++ b/v2/internal/ffenestri/ffenestri_client.go @@ -114,9 +114,9 @@ func (c *Client) WindowSize(width int, height int) { } // WindowSetColour sets the window colour -func (c *Client) WindowSetColour(colour string) bool { - result := C.SetColour(c.app.app, c.app.string2CString(colour)) - return result == 1 +func (c *Client) WindowSetColour(colour int) { + r, b, g, a := intToColour(colour) + C.SetColour(c.app.app, r, g, b, a) } // OpenFileDialog will open a file dialog with the given title diff --git a/v2/internal/ffenestri/ffenestri_darwin.c b/v2/internal/ffenestri/ffenestri_darwin.c index e50fbcac..526c7e61 100644 --- a/v2/internal/ffenestri/ffenestri_darwin.c +++ b/v2/internal/ffenestri/ffenestri_darwin.c @@ -7,7 +7,6 @@ // Macros to make it slightly more sane #define msg objc_msgSend -#define msg_stret objc_msgSend_stret #define c(str) (id)objc_getClass(str) #define s(str) sel_registerName(str) @@ -108,6 +107,10 @@ struct Application { int resizable; int devtools; int fullscreen; + int red; + int green; + int blue; + int alpha; // Features int frame; @@ -155,6 +158,13 @@ void UseToolbar(struct Application *app) { app->useToolBar = 1; } +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; +} + void FullSizeContent(struct Application *app) { app->fullSizeContent = 1; } @@ -482,23 +492,6 @@ char* OpenDirectoryDialog(void *appPointer, char *title) { return foldername; } - // SetColour sets the colour of the webview to the given colour string -int SetColour(void *appPointer, const char *colourString) { - Debug("SetColour Called with: %s", colourString); - - // struct Application *app = (struct Application*) appPointer; - // GdkRGBA rgba; - // gboolean result = gdk_rgba_parse(&rgba, colourString); - // if (result == FALSE) { - // return 0; - // } - // Debug("Setting webview colour to: %s", colourString); - // webkit_web_view_get_background_color((WebKitWebView*)(app->webView), &rgba); - // int c = NS_RGBA(1, 0, 0, 0.5); - - return 1; -} - const char *invoke = "window.external={invoke:function(x){window.webkit.messageHandlers.external.postMessage(x);}};"; // DisableFrame disables the window frame @@ -693,7 +686,6 @@ void Run(void *applicationPointer, int argc, char **argv) { } if( app->fullSizeContent || app->frame == 0) { - Debug("FULLSIZECONTENTT!!!!!!"); decorations |= NSWindowStyleMaskFullSizeContentView; } @@ -733,6 +725,14 @@ void Run(void *applicationPointer, int argc, char **argv) { // Set Style Mask 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); // Setup webview diff --git a/v2/internal/messagedispatcher/dispatchclient.go b/v2/internal/messagedispatcher/dispatchclient.go index 58097e7a..7f41968f 100644 --- a/v2/internal/messagedispatcher/dispatchclient.go +++ b/v2/internal/messagedispatcher/dispatchclient.go @@ -28,7 +28,7 @@ type Client interface { WindowSize(width int, height int) WindowFullscreen() WindowUnFullscreen() - WindowSetColour(colour string) bool + WindowSetColour(colour int) } // DispatchClient is what the frontends use to interface with the diff --git a/v2/internal/messagedispatcher/messagedispatcher.go b/v2/internal/messagedispatcher/messagedispatcher.go index 5787a472..3ed5ef82 100644 --- a/v2/internal/messagedispatcher/messagedispatcher.go +++ b/v2/internal/messagedispatcher/messagedispatcher.go @@ -231,7 +231,7 @@ func (d *Dispatcher) processWindowMessage(result *servicebus.Message) { client.frontend.WindowUnFullscreen() } case "setcolour": - colour, ok := result.Data().(string) + colour, ok := result.Data().(int) if !ok { d.logger.Error("Invalid colour for 'window:setcolour' : %#v", result.Data()) return diff --git a/v2/internal/webserver/websockets.go b/v2/internal/webserver/websockets.go index 004d2315..bb221a2b 100644 --- a/v2/internal/webserver/websockets.go +++ b/v2/internal/webserver/websockets.go @@ -59,8 +59,7 @@ func (wc *WebClient) WindowFullscreen() {} func (wc *WebClient) WindowUnFullscreen() {} // WindowSetColour is a noop in the webclient -func (wc *WebClient) WindowSetColour(colour string) bool { - return false +func (wc *WebClient) WindowSetColour(colour int) { } // Run processes messages from the remote webclient diff --git a/v2/test/runtime/main.go b/v2/test/runtime/main.go index 8645b2d9..e65d0df4 100644 --- a/v2/test/runtime/main.go +++ b/v2/test/runtime/main.go @@ -20,11 +20,12 @@ func main() { Height: 620, DisableResize: false, Fullscreen: false, + Colour: 0xFF000088, Mac: wails.MacOptions{ - HideTitle: true, + HideTitle: false, HideTitleBar: false, - TitlebarAppearsTransparent: false, - FullSizeContent: true, + TitlebarAppearsTransparent: true, + FullSizeContent: false, UseToolbar: true, HideToolbarSeparator: true, },