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-25 08:27:52 +10:00
committed by GitHub
parent 9085e1edbb
commit 5a4eae968f
4 changed files with 23 additions and 0 deletions
@@ -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)
@@ -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)) })
@@ -55,6 +55,7 @@ typedef struct RGBAOptions
uint8_t b;
uint8_t a;
void *webview;
void *window;
} RGBAOptions;
typedef struct SetTitleArgs