diff --git a/v2/internal/frontend/desktop/linux/window.c b/v2/internal/frontend/desktop/linux/window.c index 1e7d5aa73..82ab3b856 100644 --- a/v2/internal/frontend/desktop/linux/window.c +++ b/v2/internal/frontend/desktop/linux/window.c @@ -139,11 +139,31 @@ void SetWindowTransparency(GtkWidget *widget) } } +static GtkCssProvider *windowCssProvider = NULL; + void SetBackgroundColour(void *data) { + // set webview's background color RGBAOptions *options = (RGBAOptions *)data; GdkRGBA colour = {options->r / 255.0, options->g / 255.0, options->b / 255.0, options->a / 255.0}; webkit_web_view_set_background_color(WEBKIT_WEB_VIEW(options->webview), &colour); + + // set window's background color + GtkWidget *window = GTK_WIDGET(options->window); + gchar *str = g_strdup_printf("window {background-color: rgba(%d, %d, %d, %d);}", options->r, options->g, options->b, options->a); + + if (windowCssProvider == NULL) + { + windowCssProvider = gtk_css_provider_new(); + gtk_style_context_add_provider( + gtk_widget_get_style_context(window), + GTK_STYLE_PROVIDER(windowCssProvider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + g_object_unref(windowCssProvider); + } + + gtk_css_provider_load_from_data(windowCssProvider, str, -1, NULL); + g_free(str); } static gboolean setTitle(gpointer data) diff --git a/v2/internal/frontend/desktop/linux/window.go b/v2/internal/frontend/desktop/linux/window.go index 774594707..07237453e 100644 --- a/v2/internal/frontend/desktop/linux/window.go +++ b/v2/internal/frontend/desktop/linux/window.go @@ -271,6 +271,7 @@ func (w *Window) SetBackgroundColour(r uint8, g uint8, b uint8, a uint8) { b: C.uchar(b), a: C.uchar(a), webview: w.webview, + window: w.gtkWindow, } invokeOnMainThread(func() { C.SetBackgroundColour(unsafe.Pointer(&data)) }) diff --git a/v2/internal/frontend/desktop/linux/window.h b/v2/internal/frontend/desktop/linux/window.h index f02542feb..d600b6984 100644 --- a/v2/internal/frontend/desktop/linux/window.h +++ b/v2/internal/frontend/desktop/linux/window.h @@ -55,6 +55,7 @@ typedef struct RGBAOptions uint8_t b; uint8_t a; void *webview; + void *window; } RGBAOptions; typedef struct SetTitleArgs diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index 385cfb931..de16faf1f 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Avoid app crashing when the Linux GTK key is empty. Fixed by @aminya in [PR](https://github.com/wailsapp/wails/pull/2672) - Fixed a race condition when positioning the window on Linux. Added by @lyimmi in [PR](https://github.com/wailsapp/wails/pull/2850) +- Fixed `SetBackgroundColour` so it sets the window's background color to reduce resize flickering on Linux. Added by @lyimmi in [PR](https://github.com/wailsapp/wails/pull/2853) ### Added