[gnome-flashback] desktop: add dark css class if background is dark
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] desktop: add dark css class if background is dark
- Date: Thu, 31 Oct 2019 14:42:10 +0000 (UTC)
commit aa2db881eb13c8a2d162671076051a0fa1ae4962
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Wed Oct 30 13:28:27 2019 +0200
desktop: add dark css class if background is dark
gnome-flashback/libdesktop/gf-background.c | 21 +++++++++++++++++
gnome-flashback/libdesktop/gf-background.h | 4 +++-
gnome-flashback/libdesktop/gf-desktop-window.c | 31 ++++++++++++++++++++++++++
3 files changed, 55 insertions(+), 1 deletion(-)
---
diff --git a/gnome-flashback/libdesktop/gf-background.c b/gnome-flashback/libdesktop/gf-background.c
index 5e88c02..4e95bf6 100644
--- a/gnome-flashback/libdesktop/gf-background.c
+++ b/gnome-flashback/libdesktop/gf-background.c
@@ -66,6 +66,7 @@ static GParamSpec *background_properties[LAST_PROP] = { NULL };
enum
{
READY,
+ CHANGED,
LAST_SIGNAL
};
@@ -130,6 +131,8 @@ fade_cb (gpointer user_data)
screen = gtk_widget_get_screen (self->window);
gnome_bg_set_surface_as_root (screen, self->surface);
+ g_signal_emit (self, background_signals[CHANGED], 0);
+
return G_SOURCE_REMOVE;
}
@@ -179,6 +182,8 @@ change (GfBackground *self,
TRUE);
gnome_bg_set_surface_as_root (screen, self->surface);
+
+ g_signal_emit (self, background_signals[CHANGED], 0);
}
g_signal_emit (self, background_signals[READY], 0);
@@ -395,6 +400,10 @@ install_signals (void)
background_signals[READY] =
g_signal_new ("ready", GF_TYPE_BACKGROUND, G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL, G_TYPE_NONE, 0);
+
+ background_signals[CHANGED] =
+ g_signal_new ("changed", GF_TYPE_BACKGROUND, G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
}
static void
@@ -425,3 +434,15 @@ gf_background_new (GtkWidget *window)
"window", window,
NULL);
}
+
+gboolean
+gf_background_is_dark (GfBackground *self)
+{
+ int width;
+ int height;
+
+ width = gf_desktop_window_get_width (GF_DESKTOP_WINDOW (self->window));
+ height = gf_desktop_window_get_height (GF_DESKTOP_WINDOW (self->window));
+
+ return gnome_bg_is_dark (self->bg, width, height);
+}
diff --git a/gnome-flashback/libdesktop/gf-background.h b/gnome-flashback/libdesktop/gf-background.h
index a83593c..2aa466f 100644
--- a/gnome-flashback/libdesktop/gf-background.h
+++ b/gnome-flashback/libdesktop/gf-background.h
@@ -25,7 +25,9 @@ G_BEGIN_DECLS
#define GF_TYPE_BACKGROUND (gf_background_get_type ())
G_DECLARE_FINAL_TYPE (GfBackground, gf_background, GF, BACKGROUND, GObject)
-GfBackground *gf_background_new (GtkWidget *window);
+GfBackground *gf_background_new (GtkWidget *window);
+
+gboolean gf_background_is_dark (GfBackground *self);
G_END_DECLS
diff --git a/gnome-flashback/libdesktop/gf-desktop-window.c b/gnome-flashback/libdesktop/gf-desktop-window.c
index 1914099..b71a665 100644
--- a/gnome-flashback/libdesktop/gf-desktop-window.c
+++ b/gnome-flashback/libdesktop/gf-desktop-window.c
@@ -68,6 +68,25 @@ static guint window_signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (GfDesktopWindow, gf_desktop_window, GTK_TYPE_WINDOW)
+static void
+update_css_class (GfDesktopWindow *self)
+{
+ gboolean dark;
+ GtkStyleContext *context;
+
+ dark = FALSE;
+
+ if (self->background != NULL)
+ dark = gf_background_is_dark (self->background);
+
+ context = gtk_widget_get_style_context (GTK_WIDGET (self));
+
+ if (!dark)
+ gtk_style_context_remove_class (context, "dark");
+ else
+ gtk_style_context_add_class (context, "dark");
+}
+
static void
ensure_surface (GfDesktopWindow *self)
{
@@ -80,6 +99,7 @@ ensure_surface (GfDesktopWindow *self)
self->surface = gnome_bg_get_surface_from_root (screen);
gtk_widget_queue_draw (widget);
+ update_css_class (self);
}
static GdkFilterReturn
@@ -177,6 +197,13 @@ ready_cb (GfBackground *background,
emit_ready (self);
}
+static void
+changed_cb (GfBackground *background,
+ GfDesktopWindow *self)
+{
+ update_css_class (self);
+}
+
static void
draw_background_changed (GfDesktopWindow *self)
{
@@ -189,6 +216,10 @@ draw_background_changed (GfDesktopWindow *self)
self->background = gf_background_new (GTK_WIDGET (self));
g_signal_connect (self->background, "ready", G_CALLBACK (ready_cb), self);
+
+ g_signal_connect (self->background, "changed",
+ G_CALLBACK (changed_cb),
+ self);
}
else
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]