[gnome-control-center/wip/jsparber/background: 16/45] background: add icon for with time changing wallpapers
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/jsparber/background: 16/45] background: add icon for with time changing wallpapers
- Date: Wed, 7 Feb 2018 12:53:56 +0000 (UTC)
commit e7da3e6340be0f0caf3664403c133ae2b3d686fa
Author: Julian Sparber <julian sparber net>
Date: Sat Nov 11 23:57:35 2017 +0100
background: add icon for with time changing wallpapers
https://bugzilla.gnome.org/show_bug.cgi?id=788515
panels/background/cc-background-panel.c | 173 ++++++++++++++++++-------------
1 files changed, 102 insertions(+), 71 deletions(-)
---
diff --git a/panels/background/cc-background-panel.c b/panels/background/cc-background-panel.c
index dd76ab0..ff4d491 100644
--- a/panels/background/cc-background-panel.c
+++ b/panels/background/cc-background-panel.c
@@ -57,7 +57,6 @@ struct _CcBackgroundPanel
CcBackgroundItem *current_background;
CcBackgroundStore *store;
- gint gallery_size;
GCancellable *copy_cancellable;
@@ -184,15 +183,93 @@ get_save_path (CcBackgroundPanel *panel, GSettings *settings)
NULL);
}
+static void
+add_slideshow_emblem (GdkPixbuf *pixbuf,
+ gint w,
+ gint h,
+ gint scale_factor)
+{
+ GdkPixbuf *slideshow_emblem;
+ GIcon *icon = NULL;
+ GtkIconInfo *icon_info = NULL;
+ GError *error = NULL;
+ GtkIconTheme *theme;
+
+ int eh;
+ int ew;
+ //int h;
+ //int w;
+ int x;
+ int y;
+
+ icon = g_themed_icon_new ("slideshow-emblem");
+ theme = gtk_icon_theme_get_default ();
+ icon_info = gtk_icon_theme_lookup_by_gicon_for_scale (theme,
+ icon,
+ 16,
+ scale_factor,
+ GTK_ICON_LOOKUP_FORCE_SIZE |
+ GTK_ICON_LOOKUP_USE_BUILTIN);
+ if (icon_info == NULL) {
+ g_warning ("Your icon theme is missing the slideshow-emblem icon, "
+ "please file a bug against it");
+ }
+ else {
+
+ slideshow_emblem = gtk_icon_info_load_icon (icon_info, &error);
+ if (slideshow_emblem == NULL) {
+ g_warning ("Failed to load slideshow emblem: %s", error->message);
+ g_error_free (error);
+ }
+ else {
+ eh = gdk_pixbuf_get_height (slideshow_emblem);
+ ew = gdk_pixbuf_get_width (slideshow_emblem);
+ //h = gdk_pixbuf_get_height (pixbuf);
+ //w = gdk_pixbuf_get_width (pixbuf);
+ x = w - ew - 5;
+ y = h - eh - 5;
+
+ gdk_pixbuf_composite (slideshow_emblem, pixbuf, x, y, ew, eh, x, y, 1.0, 1.0, GDK_INTERP_BILINEAR,
255);
+ }
+ }
+
+ g_clear_object (&icon_info);
+ g_clear_object (&icon);
+}
+
+
+
+static GdkPixbuf*
+get_or_create_cached_pixbuf_with_size (CcBackgroundPanel *panel,
+ const gint width,
+ const gint height,
+ CcBackgroundItem *item)
+{
+ gint scale_factor;
+ GdkPixbuf *pixbuf;
+
+ pixbuf = g_object_get_data (G_OBJECT (item), "pixbuf");
+ if (pixbuf == NULL ||
+ gdk_pixbuf_get_width (pixbuf) != width ||
+ gdk_pixbuf_get_height (pixbuf) != height) {
+ scale_factor = gtk_widget_get_scale_factor (panel);
+ pixbuf = cc_background_item_get_frame_thumbnail (item,
+ panel->thumb_factory,
+ width,
+ height,
+ scale_factor,
+ -2, TRUE);
+ g_object_set_data_full (G_OBJECT (item), "pixbuf", pixbuf, g_object_unref);
+ }
+
+ return pixbuf;
+}
+
static GdkPixbuf*
get_or_create_cached_pixbuf (CcBackgroundPanel *panel,
GtkWidget *widget,
CcBackgroundItem *background)
{
- GtkAllocation allocation;
-
- //const gint preview_width = 310; //309
- //const gint preview_height = 174; //168
gint scale_factor;
GdkPixbuf *pixbuf;
const gint preview_width = gtk_widget_get_allocated_width (widget);
@@ -202,8 +279,6 @@ get_or_create_cached_pixbuf (CcBackgroundPanel *panel,
if (pixbuf == NULL ||
gdk_pixbuf_get_width (pixbuf) != preview_width ||
gdk_pixbuf_get_height (pixbuf) != preview_height) {
-
- gtk_widget_get_allocation (widget, &allocation);
scale_factor = gtk_widget_get_scale_factor (widget);
pixbuf = cc_background_item_get_frame_thumbnail (background,
panel->thumb_factory,
@@ -335,10 +410,12 @@ on_gallery_item_draw (GtkWidget *widget,
cairo_t *cr,
GdkPixbuf *pixbuf)
{
+ //GdkPixbuf *pixbuf;
const gint space_width = gtk_widget_get_allocated_width (widget);
const gint space_height = gtk_widget_get_allocated_height ( (widget));
const gint pixbuf_width = gdk_pixbuf_get_width (pixbuf);
const gint pixbuf_height = gdk_pixbuf_get_height (pixbuf);
+ const gint scale_factor = gtk_widget_get_scale_factor (widget);
gint new_width;
gint new_height;
@@ -351,14 +428,26 @@ on_gallery_item_draw (GtkWidget *widget,
new_height = space_height;
}
+ /* pixbuf = get_or_create_cached_pixbuf_with_size (panel,
+ new_width,
+ new_height,
+ cc_background_grid_item_get_ref (gtk_widget_get_parent(widget)));
+
+*/
+
pixbuf = gdk_pixbuf_scale_simple (pixbuf,
new_width,
new_height,
GDK_INTERP_BILINEAR);
+ if (cc_background_item_changes_with_time (cc_background_grid_item_get_ref
(gtk_widget_get_parent(widget)))) {
+ add_slideshow_emblem (pixbuf, (space_width + new_width) / 2, (space_height + new_height)/2,
scale_factor);
+ }
+
gdk_cairo_set_source_pixbuf (cr,
pixbuf,
- -(new_width - space_width)/2, -(new_height - space_height)/2);
+ (space_width - new_width) / 2,
+ (space_height - new_height) / 2);
cairo_paint (cr);
return TRUE;
@@ -379,10 +468,6 @@ on_panel_resize (GtkWidget *widget,
else {
gtk_widget_set_size_request (preview, -1, 150);
}
-
- if (allocation->width < 400) {
- panel->gallery_size = 10;
- }
}
static void
@@ -844,58 +929,6 @@ is_gnome_photos_installed ()
return TRUE;
}
-static void
-add_slideshow_emblem (GdkPixbuf *pixbuf,
- gint scale_factor)
-{
- GdkPixbuf *slideshow_emblem;
- GIcon *icon = NULL;
- GtkIconInfo *icon_info = NULL;
- GError *error = NULL;
- GtkIconTheme *theme;
-
- int eh;
- int ew;
- int h;
- int w;
- int x;
- int y;
-
- icon = g_themed_icon_new ("slideshow-emblem");
- theme = gtk_icon_theme_get_default ();
- icon_info = gtk_icon_theme_lookup_by_gicon_for_scale (theme,
- icon,
- 16,
- scale_factor,
- GTK_ICON_LOOKUP_FORCE_SIZE |
- GTK_ICON_LOOKUP_USE_BUILTIN);
- if (icon_info == NULL) {
- g_warning ("Your icon theme is missing the slideshow-emblem icon, "
- "please file a bug against it");
- }
- else {
-
- slideshow_emblem = gtk_icon_info_load_icon (icon_info, &error);
- if (slideshow_emblem == NULL) {
- g_warning ("Failed to load slideshow emblem: %s", error->message);
- g_error_free (error);
- }
- else {
- eh = gdk_pixbuf_get_height (slideshow_emblem);
- ew = gdk_pixbuf_get_width (slideshow_emblem);
- h = gdk_pixbuf_get_height (pixbuf);
- w = gdk_pixbuf_get_width (pixbuf);
- x = w - ew - 5;
- y = h - eh - 5;
-
- gdk_pixbuf_composite (slideshow_emblem, pixbuf, x, y, ew, eh, x, y, 1.0, 1.0, GDK_INTERP_BILINEAR,
255);
- }
- }
-
- g_clear_object (&icon_info);
- g_clear_object (&icon);
-}
-
static GtkWidget *
create_gallery_item (gpointer item,
@@ -904,12 +937,11 @@ create_gallery_item (gpointer item,
CcBackgroundPanel *panel = user_data;
GtkWidget *flow;
GtkWidget *widget;
- GtkWidget *frame;
GdkPixbuf *pixbuf;
CcBackgroundItem *self = item;
gint scale_factor;
- const gint preview_width = 800;//panel->gallery_size;//309;
- const gint preview_height = 800 * 9 / 16; //panel->gallery_size * 9/16;//168;
+ const gint preview_width = 400;
+ const gint preview_height = 400 * 9 / 16;
scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (panel));
@@ -920,11 +952,11 @@ create_gallery_item (gpointer item,
scale_factor,
-2, TRUE);
- if (cc_background_item_changes_with_time (self)) {
+ /*if (cc_background_item_changes_with_time (self)) {
add_slideshow_emblem (pixbuf, scale_factor);
- }
+ }
+ */
widget = gtk_drawing_area_new ();
- gtk_widget_set_size_request (widget, 250, 250 * 9/16);
gtk_widget_set_hexpand(widget, TRUE);
gtk_widget_set_vexpand(widget, TRUE);
g_signal_connect (G_OBJECT (widget), "draw",
@@ -952,7 +984,6 @@ cc_background_panel_init (CcBackgroundPanel *panel)
/* Create wallpapers store */
panel->store = cc_background_store_new ();
- panel->gallery_size = 300;
panel->connection = g_application_get_dbus_connection (g_application_get_default ());
g_resources_register (cc_background_get_resource ());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]