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:
parent
9085e1edbb
commit
5a4eae968f
@ -139,11 +139,31 @@ void SetWindowTransparency(GtkWidget *widget)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GtkCssProvider *windowCssProvider = NULL;
|
||||||
|
|
||||||
void SetBackgroundColour(void *data)
|
void SetBackgroundColour(void *data)
|
||||||
{
|
{
|
||||||
|
// set webview's background color
|
||||||
RGBAOptions *options = (RGBAOptions *)data;
|
RGBAOptions *options = (RGBAOptions *)data;
|
||||||
GdkRGBA colour = {options->r / 255.0, options->g / 255.0, options->b / 255.0, options->a / 255.0};
|
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);
|
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)
|
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),
|
b: C.uchar(b),
|
||||||
a: C.uchar(a),
|
a: C.uchar(a),
|
||||||
webview: w.webview,
|
webview: w.webview,
|
||||||
|
window: w.gtkWindow,
|
||||||
}
|
}
|
||||||
invokeOnMainThread(func() { C.SetBackgroundColour(unsafe.Pointer(&data)) })
|
invokeOnMainThread(func() { C.SetBackgroundColour(unsafe.Pointer(&data)) })
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ typedef struct RGBAOptions
|
|||||||
uint8_t b;
|
uint8_t b;
|
||||||
uint8_t a;
|
uint8_t a;
|
||||||
void *webview;
|
void *webview;
|
||||||
|
void *window;
|
||||||
} RGBAOptions;
|
} RGBAOptions;
|
||||||
|
|
||||||
typedef struct SetTitleArgs
|
typedef struct SetTitleArgs
|
||||||
|
@ -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)
|
- 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 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
|
### Added
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user