background: Use higher resolution thumbnails on HiDpi displays
https://bugzilla.gnome.org/show_bug.cgi?id=731713
This commit is contained in:
parent
b950a69f3b
commit
a3247e73a4
9 changed files with 126 additions and 27 deletions
|
@ -54,15 +54,22 @@ struct {
|
|||
};
|
||||
|
||||
static void
|
||||
bg_colors_source_init (BgColorsSource *self)
|
||||
bg_colors_source_constructed (GObject *object)
|
||||
{
|
||||
BgColorsSource *self = BG_COLORS_SOURCE (object);
|
||||
GnomeDesktopThumbnailFactory *thumb_factory;
|
||||
guint i;
|
||||
GtkListStore *store;
|
||||
gint thumbnail_height;
|
||||
gint thumbnail_width;
|
||||
|
||||
G_OBJECT_CLASS (bg_colors_source_parent_class)->constructed (object);
|
||||
|
||||
store = bg_source_get_liststore (BG_SOURCE (self));
|
||||
|
||||
thumb_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
|
||||
thumbnail_height = bg_source_get_thumbnail_height (BG_SOURCE (self));
|
||||
thumbnail_width = bg_source_get_thumbnail_width (BG_SOURCE (self));
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (items); i++)
|
||||
{
|
||||
|
@ -91,7 +98,7 @@ bg_colors_source_init (BgColorsSource *self)
|
|||
/* insert the item into the liststore */
|
||||
pixbuf = cc_background_item_get_thumbnail (item,
|
||||
thumb_factory,
|
||||
THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
|
||||
thumbnail_width, thumbnail_height);
|
||||
gtk_list_store_insert_with_values (store, NULL, 0,
|
||||
0, pixbuf,
|
||||
1, item,
|
||||
|
@ -104,14 +111,21 @@ bg_colors_source_init (BgColorsSource *self)
|
|||
g_object_unref (thumb_factory);
|
||||
}
|
||||
|
||||
bg_colors_source_init (BgColorsSource *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
bg_colors_source_class_init (BgColorsSourceClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->constructed = bg_colors_source_constructed;
|
||||
}
|
||||
|
||||
BgColorsSource *
|
||||
bg_colors_source_new (void)
|
||||
bg_colors_source_new (GtkWindow *window)
|
||||
{
|
||||
return g_object_new (BG_TYPE_COLORS_SOURCE, NULL);
|
||||
return g_object_new (BG_TYPE_COLORS_SOURCE, "window", window, NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ struct _BgColorsSourceClass
|
|||
|
||||
GType bg_colors_source_get_type (void) G_GNUC_CONST;
|
||||
|
||||
BgColorsSource *bg_colors_source_new (void);
|
||||
BgColorsSource *bg_colors_source_new (GtkWindow *window);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -224,6 +224,8 @@ picture_opened_for_read (GObject *source_object,
|
|||
CcBackgroundItem *item;
|
||||
GFileInputStream *stream;
|
||||
GError *error = NULL;
|
||||
gint thumbnail_height;
|
||||
gint thumbnail_width;
|
||||
|
||||
item = g_object_get_data (source_object, "item");
|
||||
stream = g_file_read_finish (G_FILE (source_object), res, &error);
|
||||
|
@ -246,9 +248,11 @@ picture_opened_for_read (GObject *source_object,
|
|||
*/
|
||||
bg_source = BG_PICTURES_SOURCE (user_data);
|
||||
|
||||
thumbnail_height = bg_source_get_thumbnail_height (BG_SOURCE (bg_source));
|
||||
thumbnail_width = bg_source_get_thumbnail_width (BG_SOURCE (bg_source));
|
||||
g_object_set_data_full (G_OBJECT (stream), "item", g_object_ref (item), g_object_unref);
|
||||
gdk_pixbuf_new_from_stream_at_scale_async (G_INPUT_STREAM (stream),
|
||||
THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT,
|
||||
thumbnail_width, thumbnail_height,
|
||||
TRUE,
|
||||
bg_source->priv->cancellable,
|
||||
picture_scaled, bg_source);
|
||||
|
@ -914,9 +918,9 @@ bg_pictures_source_init (BgPicturesSource *self)
|
|||
}
|
||||
|
||||
BgPicturesSource *
|
||||
bg_pictures_source_new (void)
|
||||
bg_pictures_source_new (GtkWindow *window)
|
||||
{
|
||||
return g_object_new (BG_TYPE_PICTURES_SOURCE, NULL);
|
||||
return g_object_new (BG_TYPE_PICTURES_SOURCE, "window", window, NULL);
|
||||
}
|
||||
|
||||
const char * const *
|
||||
|
|
|
@ -69,7 +69,7 @@ struct _BgPicturesSourceClass
|
|||
|
||||
GType bg_pictures_source_get_type (void) G_GNUC_CONST;
|
||||
|
||||
BgPicturesSource *bg_pictures_source_new (void);
|
||||
BgPicturesSource *bg_pictures_source_new (GtkWindow *window);
|
||||
char *bg_pictures_source_get_cache_path (void);
|
||||
char *bg_pictures_source_get_unique_path(const char *uri);
|
||||
gboolean bg_pictures_source_add (BgPicturesSource *bg_source,
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
#include "bg-source.h"
|
||||
#include "cc-background-item.h"
|
||||
|
||||
#define THUMBNAIL_WIDTH 256
|
||||
#define THUMBNAIL_HEIGHT (THUMBNAIL_WIDTH * 3 / 4)
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE (BgSource, bg_source, G_TYPE_OBJECT)
|
||||
|
||||
#define SOURCE_PRIVATE(o) \
|
||||
|
@ -29,14 +32,46 @@ G_DEFINE_ABSTRACT_TYPE (BgSource, bg_source, G_TYPE_OBJECT)
|
|||
struct _BgSourcePrivate
|
||||
{
|
||||
GtkListStore *store;
|
||||
GtkWidget *window;
|
||||
gint thumbnail_height;
|
||||
gint thumbnail_width;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_LISTSTORE = 1
|
||||
PROP_LISTSTORE = 1,
|
||||
PROP_WINDOW
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
bg_source_calculate_thumbnail_dimensions (BgSource *source)
|
||||
{
|
||||
BgSourcePrivate *priv = source->priv;
|
||||
gint scale_factor;
|
||||
|
||||
priv->thumbnail_height = THUMBNAIL_HEIGHT;
|
||||
priv->thumbnail_width = THUMBNAIL_WIDTH;
|
||||
|
||||
if (priv->window == NULL)
|
||||
return;
|
||||
|
||||
scale_factor = gtk_widget_get_scale_factor (priv->window);
|
||||
if (scale_factor > 1)
|
||||
{
|
||||
priv->thumbnail_height *= scale_factor;
|
||||
priv->thumbnail_width *= scale_factor;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
bg_source_constructed (GObject *object)
|
||||
{
|
||||
G_OBJECT_CLASS (bg_source_parent_class)->constructed (object);
|
||||
|
||||
bg_source_calculate_thumbnail_dimensions (BG_SOURCE (object));
|
||||
}
|
||||
|
||||
static void
|
||||
bg_source_get_property (GObject *object,
|
||||
guint property_id,
|
||||
|
@ -62,8 +97,14 @@ bg_source_set_property (GObject *object,
|
|||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
BgSourcePrivate *priv = BG_SOURCE (object)->priv;
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_WINDOW:
|
||||
priv->window = GTK_WIDGET (g_value_get_object (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
}
|
||||
|
@ -87,6 +128,7 @@ bg_source_class_init (BgSourceClass *klass)
|
|||
|
||||
g_type_class_add_private (klass, sizeof (BgSourcePrivate));
|
||||
|
||||
object_class->constructed = bg_source_constructed;
|
||||
object_class->get_property = bg_source_get_property;
|
||||
object_class->set_property = bg_source_set_property;
|
||||
object_class->dispose = bg_source_dispose;
|
||||
|
@ -97,6 +139,13 @@ bg_source_class_init (BgSourceClass *klass)
|
|||
GTK_TYPE_LIST_STORE,
|
||||
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
||||
g_object_class_install_property (object_class, PROP_LISTSTORE, pspec);
|
||||
|
||||
pspec = g_param_spec_object ("window",
|
||||
"Window",
|
||||
"Toplevel window used to view the source",
|
||||
GTK_TYPE_WINDOW,
|
||||
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
|
||||
g_object_class_install_property (object_class, PROP_WINDOW, pspec);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -116,3 +165,19 @@ bg_source_get_liststore (BgSource *source)
|
|||
|
||||
return source->priv->store;
|
||||
}
|
||||
|
||||
gint
|
||||
bg_source_get_thumbnail_height (BgSource *source)
|
||||
{
|
||||
g_return_val_if_fail (BG_IS_SOURCE (source), THUMBNAIL_HEIGHT);
|
||||
|
||||
return source->priv->thumbnail_height;
|
||||
}
|
||||
|
||||
gint
|
||||
bg_source_get_thumbnail_width (BgSource *source)
|
||||
{
|
||||
g_return_val_if_fail (BG_IS_SOURCE (source), THUMBNAIL_WIDTH);
|
||||
|
||||
return source->priv->thumbnail_width;
|
||||
}
|
||||
|
|
|
@ -25,9 +25,6 @@
|
|||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define THUMBNAIL_WIDTH 256
|
||||
#define THUMBNAIL_HEIGHT (THUMBNAIL_WIDTH * 3 / 4)
|
||||
|
||||
#define BG_TYPE_SOURCE bg_source_get_type()
|
||||
|
||||
#define BG_SOURCE(obj) \
|
||||
|
@ -70,6 +67,10 @@ GType bg_source_get_type (void) G_GNUC_CONST;
|
|||
|
||||
GtkListStore* bg_source_get_liststore (BgSource *source);
|
||||
|
||||
gint bg_source_get_thumbnail_height (BgSource *source);
|
||||
|
||||
gint bg_source_get_thumbnail_width (BgSource *source);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _BG_SOURCE_H */
|
||||
|
|
|
@ -50,6 +50,8 @@ load_wallpapers (gchar *key,
|
|||
GIcon *pixbuf;
|
||||
GtkListStore *store = bg_source_get_liststore (BG_SOURCE (source));
|
||||
gboolean deleted;
|
||||
gint thumbnail_height;
|
||||
gint thumbnail_width;
|
||||
|
||||
g_object_get (G_OBJECT (item), "is-deleted", &deleted, NULL);
|
||||
|
||||
|
@ -58,8 +60,10 @@ load_wallpapers (gchar *key,
|
|||
|
||||
gtk_list_store_append (store, &iter);
|
||||
|
||||
thumbnail_height = bg_source_get_thumbnail_height (BG_SOURCE (source));
|
||||
thumbnail_width = bg_source_get_thumbnail_width (BG_SOURCE (source));
|
||||
pixbuf = cc_background_item_get_thumbnail (item, priv->thumb_factory,
|
||||
THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
|
||||
thumbnail_width, thumbnail_height);
|
||||
|
||||
gtk_list_store_set (store, &iter,
|
||||
0, pixbuf,
|
||||
|
@ -110,6 +114,23 @@ load_default_bg (BgWallpapersSource *self)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
bg_wallpapers_source_constructed (GObject *object)
|
||||
{
|
||||
BgWallpapersSource *self = BG_WALLPAPERS_SOURCE (object);
|
||||
BgWallpapersSourcePrivate *priv = self->priv;
|
||||
|
||||
G_OBJECT_CLASS (bg_wallpapers_source_parent_class)->constructed (object);
|
||||
|
||||
g_signal_connect (G_OBJECT (priv->xml), "added",
|
||||
G_CALLBACK (item_added), self);
|
||||
|
||||
/* Try adding the default background first */
|
||||
load_default_bg (self);
|
||||
|
||||
cc_background_xml_load_list_async (priv->xml, NULL, list_load_cb, self);
|
||||
}
|
||||
|
||||
static void
|
||||
bg_wallpapers_source_dispose (GObject *object)
|
||||
{
|
||||
|
@ -131,13 +152,6 @@ bg_wallpapers_source_init (BgWallpapersSource *self)
|
|||
priv->thumb_factory =
|
||||
gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
|
||||
priv->xml = cc_background_xml_new ();
|
||||
g_signal_connect (G_OBJECT (priv->xml), "added",
|
||||
G_CALLBACK (item_added), self);
|
||||
|
||||
/* Try adding the default background first */
|
||||
load_default_bg (self);
|
||||
|
||||
cc_background_xml_load_list_async (priv->xml, NULL, list_load_cb, self);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -147,12 +161,13 @@ bg_wallpapers_source_class_init (BgWallpapersSourceClass *klass)
|
|||
|
||||
g_type_class_add_private (klass, sizeof (BgWallpapersSourcePrivate));
|
||||
|
||||
object_class->constructed = bg_wallpapers_source_constructed;
|
||||
object_class->dispose = bg_wallpapers_source_dispose;
|
||||
}
|
||||
|
||||
BgWallpapersSource *
|
||||
bg_wallpapers_source_new (void)
|
||||
bg_wallpapers_source_new (GtkWindow *window)
|
||||
{
|
||||
return g_object_new (BG_TYPE_WALLPAPERS_SOURCE, NULL);
|
||||
return g_object_new (BG_TYPE_WALLPAPERS_SOURCE, "window", window, NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ struct _BgWallpapersSourceClass
|
|||
|
||||
GType bg_wallpapers_source_get_type (void) G_GNUC_CONST;
|
||||
|
||||
BgWallpapersSource *bg_wallpapers_source_new (void);
|
||||
BgWallpapersSource *bg_wallpapers_source_new (GtkWindow *window);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -275,9 +275,9 @@ cc_background_chooser_dialog_init (CcBackgroundChooserDialog *chooser)
|
|||
chooser->priv = CC_CHOOSER_DIALOG_GET_PRIVATE (chooser);
|
||||
priv = chooser->priv;
|
||||
|
||||
priv->wallpapers_source = bg_wallpapers_source_new ();
|
||||
priv->pictures_source = bg_pictures_source_new ();
|
||||
priv->colors_source = bg_colors_source_new ();
|
||||
priv->wallpapers_source = bg_wallpapers_source_new (GTK_WINDOW (chooser));
|
||||
priv->pictures_source = bg_pictures_source_new (GTK_WINDOW (chooser));
|
||||
priv->colors_source = bg_colors_source_new (GTK_WINDOW (chooser));
|
||||
|
||||
priv->row_inserted_id = 0;
|
||||
priv->row_deleted_id = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue