[gnome-control-center/gnome-3-24] display: Load appropriate assets for the night light panel
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/gnome-3-24] display: Load appropriate assets for the night light panel
- Date: Mon, 10 Apr 2017 09:58:02 +0000 (UTC)
commit f1e8aebf219b470e163aa1b4a48dd42c97fcb012
Author: Emmanuele Bassi <ebassi gnome org>
Date: Fri Apr 7 12:46:09 2017 +0100
display: Load appropriate assets for the night light panel
We hard-code a 16x16 asset for sunrise and sunset icons, which makes
them look blurry at higher scaling factors.
Let's look in the icon theme to see if there's an icon for sunrise and
sunset; if not, we can still use the assets we ship, but we also attempt
to load them from different resource paths, depending on the scale
factor.
We will need to update the assets to include a 32x32 rendering of the
sunrise and sunset icons.
https://bugzilla.gnome.org/show_bug.cgi?id=781029
panels/display/Makefile.am | 6 +-
panels/display/cc-night-light-widget.c | 93 ++++++++++++++++++++++++--------
panels/display/display.gresource.xml | 4 +-
3 files changed, 75 insertions(+), 28 deletions(-)
---
diff --git a/panels/display/Makefile.am b/panels/display/Makefile.am
index e1a8cda..3168f77 100644
--- a/panels/display/Makefile.am
+++ b/panels/display/Makefile.am
@@ -20,11 +20,11 @@ libdisplay_la_SOURCES = \
libdisplay_la_LIBADD = $(PANEL_LIBS) $(DISPLAY_PANEL_LIBS) $(LIBM)
-resource_files = $(shell glib-compile-resources --sourcedir=$(srcdir) --sourcedir=$(srcdir)/icons/16x16
--generate-dependencies $(srcdir)/display.gresource.xml)
+resource_files = $(shell glib-compile-resources --sourcedir=$(srcdir) --sourcedir=$(srcdir)/icons
--generate-dependencies $(srcdir)/display.gresource.xml)
cc-display-resources.c: display.gresource.xml $(resource_files)
- $(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir)
--sourcedir=$(srcdir)/icons/16x16 --generate-source --c-name cc_display $<
+ $(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --sourcedir=$(srcdir)/icons
--generate-source --c-name cc_display $<
cc-display-resources.h: display.gresource.xml $(resource_files)
- $(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir)
--sourcedir=$(srcdir)/icons/16x16 --generate-header --c-name cc_display $<
+ $(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --sourcedir=$(srcdir)/icons
--generate-header --c-name cc_display $<
# You will need a recent intltool or the patch from this bug
# http://bugzilla.gnome.org/show_bug.cgi?id=462312
diff --git a/panels/display/cc-night-light-widget.c b/panels/display/cc-night-light-widget.c
index 5243444..8b5d600 100644
--- a/panels/display/cc-night-light-widget.c
+++ b/panels/display/cc-night-light-widget.c
@@ -69,26 +69,6 @@ cc_night_light_widget_set_mode (CcNightLightWidget *self,
gtk_widget_queue_draw (GTK_WIDGET (self));
}
-static void
-cc_night_light_widget_finalize (GObject *object)
-{
- CcNightLightWidget *self = CC_NIGHT_LIGHT_WIDGET (object);
-
- g_clear_pointer (&self->surface_sunrise, (GDestroyNotify) cairo_surface_destroy);
- g_clear_pointer (&self->surface_sunset, (GDestroyNotify) cairo_surface_destroy);
-
- G_OBJECT_CLASS (cc_night_light_widget_parent_class)->finalize (object);
-}
-
-static void
-cc_night_light_widget_class_init (CcNightLightWidgetClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- object_class->finalize = cc_night_light_widget_finalize;
- widget_class->draw = cc_night_light_widget_draw;
-}
-
static cairo_status_t
_png_read_func (void *closure, unsigned char *data, unsigned int length)
{
@@ -104,11 +84,23 @@ _png_read_func (void *closure, unsigned char *data, unsigned int length)
return CAIRO_STATUS_SUCCESS;
}
+static const char *scaled_sizes[] = {
+ NULL,
+ "16x16",
+};
+
static cairo_surface_t *
-read_surface_from_resource (const gchar *path)
+read_surface_from_resource (const gchar *dirname,
+ int scale_factor,
+ const gchar *basename)
{
+ /* Always ensure that we have a resource for the scale factor */
+ scale_factor = CLAMP (scale_factor, 1, G_N_ELEMENTS (scaled_sizes) - 1);
+
g_autoptr(GError) error = NULL;
g_autoptr(GInputStream) stream = NULL;
+ g_autofree char *path = g_build_filename (dirname, scaled_sizes[scale_factor], basename, NULL);
+
stream = g_resource_open_stream (cc_display_get_resource (), path,
G_RESOURCE_LOOKUP_FLAGS_NONE, &error);
if (stream == NULL)
@@ -120,13 +112,68 @@ read_surface_from_resource (const gchar *path)
}
static void
+cc_night_light_widget_style_updated (GtkWidget *widget)
+{
+ GTK_WIDGET_CLASS (cc_night_light_widget_parent_class)->style_updated (widget);
+
+ CcNightLightWidget *self = CC_NIGHT_LIGHT_WIDGET (widget);
+ GtkIconTheme *icon_theme = gtk_icon_theme_get_default ();
+
+ g_clear_pointer (&self->surface_sunrise, (GDestroyNotify) cairo_surface_destroy);
+ g_clear_pointer (&self->surface_sunset, (GDestroyNotify) cairo_surface_destroy);
+
+ self->surface_sunrise =
+ gtk_icon_theme_load_surface (icon_theme, "daytime-sunrise-symbolic",
+ 16,
+ gtk_widget_get_scale_factor (widget),
+ gtk_widget_get_window (widget),
+ 0,
+ NULL);
+ if (self->surface_sunrise == NULL)
+ self->surface_sunrise = read_surface_from_resource ("/org/gnome/control-center/display",
+ gtk_widget_get_scale_factor (widget),
+ "sunrise.png");
+
+ self->surface_sunset =
+ gtk_icon_theme_load_surface (icon_theme, "daytime-sunset-symbolic",
+ 16,
+ gtk_widget_get_scale_factor (widget),
+ gtk_widget_get_window (widget),
+ 0,
+ NULL);
+ if (self->surface_sunset == NULL)
+ self->surface_sunset = read_surface_from_resource ("/org/gnome/control-center/display",
+ gtk_widget_get_scale_factor (widget),
+ "sunset.png");
+}
+
+static void
+cc_night_light_widget_finalize (GObject *object)
+{
+ CcNightLightWidget *self = CC_NIGHT_LIGHT_WIDGET (object);
+
+ g_clear_pointer (&self->surface_sunrise, (GDestroyNotify) cairo_surface_destroy);
+ g_clear_pointer (&self->surface_sunset, (GDestroyNotify) cairo_surface_destroy);
+
+ G_OBJECT_CLASS (cc_night_light_widget_parent_class)->finalize (object);
+}
+
+static void
+cc_night_light_widget_class_init (CcNightLightWidgetClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ object_class->finalize = cc_night_light_widget_finalize;
+ widget_class->draw = cc_night_light_widget_draw;
+ widget_class->style_updated = cc_night_light_widget_style_updated;
+}
+
+static void
cc_night_light_widget_init (CcNightLightWidget *self)
{
self->to = 8;
self->from = 16;
self->now = 11;
- self->surface_sunrise = read_surface_from_resource ("/org/gnome/control-center/display/sunrise.png");
- self->surface_sunset = read_surface_from_resource ("/org/gnome/control-center/display/sunset.png");
}
static gboolean
diff --git a/panels/display/display.gresource.xml b/panels/display/display.gresource.xml
index 342ed1e..5712673 100644
--- a/panels/display/display.gresource.xml
+++ b/panels/display/display.gresource.xml
@@ -2,7 +2,7 @@
<gresources>
<gresource prefix="/org/gnome/control-center/display">
<file preprocess="xml-stripblanks">display.ui</file>
- <file>sunrise.png</file>
- <file>sunset.png</file>
+ <file>16x16/sunrise.png</file>
+ <file>16x16/sunset.png</file>
</gresource>
</gresources>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]