5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 04:59:38 +08:00

set the background color for window (#2853)

* set the background color for window

* update changelog for #2853
This commit is contained in:
Zámbó, Levente 2023-08-24 23:27:52 +01:00 committed by GitHub
parent 9085e1edbb
commit 5a4eae968f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 0 deletions

View File

@ -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)

View File

@ -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)) })

View File

@ -55,6 +55,7 @@ typedef struct RGBAOptions
uint8_t b;
uint8_t a;
void *webview;
void *window;
} RGBAOptions;
typedef struct SetTitleArgs

View File

@ -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