gtkfilechooser: improve preview and thumbnail responsiveness
This commit is contained in:
parent
2ccdfc445d
commit
95a727c219
2 changed files with 113 additions and 7 deletions
|
|
@ -1004,6 +1004,29 @@ typedef struct
|
|||
static gboolean thumbnail_cache_path_is_sufficient (const gchar *path,
|
||||
gint icon_size);
|
||||
|
||||
static gint
|
||||
thumbnail_queue_get_cache_size (GtkFileChooserDefault *impl)
|
||||
{
|
||||
gint icon_size;
|
||||
|
||||
icon_size = thumbnail_queue_get_icon_size (impl);
|
||||
|
||||
/* Request the next freedesktop thumbnail cache size before the
|
||||
* visible icon reaches the previous cache limit. This avoids
|
||||
* upscaling 128px thumbnails at larger icon-view zoom levels.
|
||||
*/
|
||||
if (icon_size >= (FILECHOOSER_THUMBNAIL_X_LARGE_SIZE * 5) / 8)
|
||||
return FILECHOOSER_THUMBNAIL_XX_LARGE_SIZE;
|
||||
|
||||
if (icon_size >= (FILECHOOSER_THUMBNAIL_LARGE_SIZE * 5) / 8)
|
||||
return FILECHOOSER_THUMBNAIL_X_LARGE_SIZE;
|
||||
|
||||
if (icon_size >= (FILECHOOSER_THUMBNAIL_NORMAL_SIZE * 5) / 8)
|
||||
return FILECHOOSER_THUMBNAIL_LARGE_SIZE;
|
||||
|
||||
return FILECHOOSER_THUMBNAIL_NORMAL_SIZE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
thumbnail_queue_should_enqueue (GtkFileChooserDefault *impl,
|
||||
GFile *file,
|
||||
|
|
@ -1013,7 +1036,7 @@ thumbnail_queue_should_enqueue (GtkFileChooserDefault *impl,
|
|||
const gchar *content_type;
|
||||
const gchar *thumbnail_path;
|
||||
goffset size;
|
||||
gint icon_size;
|
||||
gint cache_size;
|
||||
gint thumbnail_size;
|
||||
|
||||
if (!impl->show_thumbnails)
|
||||
|
|
@ -1022,11 +1045,11 @@ thumbnail_queue_should_enqueue (GtkFileChooserDefault *impl,
|
|||
if (file == NULL || info == NULL)
|
||||
return FALSE;
|
||||
|
||||
icon_size = thumbnail_queue_get_icon_size (impl);
|
||||
cache_size = thumbnail_queue_get_cache_size (impl);
|
||||
|
||||
thumbnail_path = g_file_info_get_attribute_byte_string (info,
|
||||
G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
|
||||
if (thumbnail_path && thumbnail_cache_path_is_sufficient (thumbnail_path, icon_size))
|
||||
if (thumbnail_path && thumbnail_cache_path_is_sufficient (thumbnail_path, cache_size))
|
||||
return FALSE;
|
||||
|
||||
if (g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED))
|
||||
|
|
@ -1039,7 +1062,7 @@ thumbnail_queue_should_enqueue (GtkFileChooserDefault *impl,
|
|||
FILECHOOSER_GENERATED_THUMBNAIL_SIZE);
|
||||
thumbnail = g_file_info_get_attribute_object (info,
|
||||
FILECHOOSER_GENERATED_THUMBNAIL);
|
||||
if (thumbnail && thumbnail_size == icon_size)
|
||||
if (thumbnail && thumbnail_size >= cache_size)
|
||||
return FALSE;
|
||||
|
||||
content_type = g_file_info_get_content_type (info);
|
||||
|
|
@ -1408,7 +1431,7 @@ thumbnail_worker_start (GtkFileChooserDefault *impl,
|
|||
job->file = file; /* takes ownership of the queue reference */
|
||||
job->cancellable = g_object_ref (impl->thumbnail_cancellable);
|
||||
job->generation_serial = impl->thumbnail_generation_serial;
|
||||
job->icon_size = thumbnail_queue_get_icon_size (impl);
|
||||
job->icon_size = thumbnail_queue_get_cache_size (impl);
|
||||
|
||||
#if GLIB_CHECK_VERSION (2, 32, 0)
|
||||
thread = g_thread_new ("gtk-filechooser-thumbnail",
|
||||
|
|
@ -1535,6 +1558,12 @@ gtk_file_chooser_default_finalize (GObject *object)
|
|||
impl->icon_tooltip_text = NULL;
|
||||
|
||||
|
||||
if (impl->preview_panel_update_timeout_id)
|
||||
{
|
||||
g_source_remove (impl->preview_panel_update_timeout_id);
|
||||
impl->preview_panel_update_timeout_id = 0;
|
||||
}
|
||||
|
||||
if (impl->preview_panel_resize_timeout_id)
|
||||
{
|
||||
g_source_remove (impl->preview_panel_resize_timeout_id);
|
||||
|
|
@ -6471,6 +6500,31 @@ update_preview_panel (GtkFileChooserDefault *impl)
|
|||
g_object_unref (closure.info);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
preview_panel_update_timeout_cb (gpointer data)
|
||||
{
|
||||
GtkFileChooserDefault *impl = GTK_FILE_CHOOSER_DEFAULT (data);
|
||||
|
||||
impl->preview_panel_update_timeout_id = 0;
|
||||
|
||||
update_preview_panel (impl);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
preview_panel_queue_update (GtkFileChooserDefault *impl)
|
||||
{
|
||||
if (!impl->preview_panel_active)
|
||||
return;
|
||||
|
||||
if (impl->preview_panel_update_timeout_id)
|
||||
g_source_remove (impl->preview_panel_update_timeout_id);
|
||||
|
||||
impl->preview_panel_update_timeout_id =
|
||||
gdk_threads_add_timeout (75, preview_panel_update_timeout_cb, impl);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
preview_panel_resize_timeout_cb (gpointer data)
|
||||
{
|
||||
|
|
@ -6479,6 +6533,12 @@ preview_panel_resize_timeout_cb (gpointer data)
|
|||
|
||||
impl->preview_panel_resize_timeout_id = 0;
|
||||
|
||||
if (impl->preview_panel_update_timeout_id)
|
||||
{
|
||||
g_source_remove (impl->preview_panel_update_timeout_id);
|
||||
impl->preview_panel_update_timeout_id = 0;
|
||||
}
|
||||
|
||||
if (!impl->preview_panel_active || !impl->preview_panel_image)
|
||||
return FALSE;
|
||||
|
||||
|
|
@ -6532,6 +6592,12 @@ preview_panel_set_active (GtkFileChooserDefault *impl,
|
|||
{
|
||||
impl->preview_panel_active = active;
|
||||
|
||||
if (!active && impl->preview_panel_update_timeout_id)
|
||||
{
|
||||
g_source_remove (impl->preview_panel_update_timeout_id);
|
||||
impl->preview_panel_update_timeout_id = 0;
|
||||
}
|
||||
|
||||
if (!active && impl->preview_panel_resize_timeout_id)
|
||||
{
|
||||
g_source_remove (impl->preview_panel_resize_timeout_id);
|
||||
|
|
@ -11845,6 +11911,42 @@ file_system_model_got_thumbnail (GObject *object, GAsyncResult *res, gpointer da
|
|||
GDK_THREADS_LEAVE ();
|
||||
}
|
||||
|
||||
static GdkPixbuf *
|
||||
file_system_model_scale_pixbuf_to_fit (GdkPixbuf *pixbuf,
|
||||
gint size)
|
||||
{
|
||||
GdkPixbuf *scaled;
|
||||
gint width;
|
||||
gint height;
|
||||
gint scaled_width;
|
||||
gint scaled_height;
|
||||
gdouble scale;
|
||||
|
||||
if (pixbuf == NULL)
|
||||
return NULL;
|
||||
|
||||
width = gdk_pixbuf_get_width (pixbuf);
|
||||
height = gdk_pixbuf_get_height (pixbuf);
|
||||
|
||||
if (width <= 0 || height <= 0)
|
||||
return pixbuf;
|
||||
|
||||
if (width <= size && height <= size)
|
||||
return pixbuf;
|
||||
|
||||
scale = MIN ((gdouble) size / width, (gdouble) size / height);
|
||||
scaled_width = MAX (1, (gint) (width * scale + 0.5));
|
||||
scaled_height = MAX (1, (gint) (height * scale + 0.5));
|
||||
|
||||
scaled = gdk_pixbuf_scale_simple (pixbuf,
|
||||
scaled_width,
|
||||
scaled_height,
|
||||
GDK_INTERP_BILINEAR);
|
||||
g_object_unref (pixbuf);
|
||||
|
||||
return scaled;
|
||||
}
|
||||
|
||||
static GdkPixbuf *
|
||||
file_system_model_render_icon (GtkFileChooserDefault *impl,
|
||||
GFileInfo *info,
|
||||
|
|
@ -11862,8 +11964,9 @@ file_system_model_render_icon (GtkFileChooserDefault *impl,
|
|||
thumbnail_size = g_file_info_get_attribute_int32 (info,
|
||||
FILECHOOSER_GENERATED_THUMBNAIL_SIZE);
|
||||
|
||||
if (thumbnail && GDK_IS_PIXBUF (thumbnail) && thumbnail_size == icon_size)
|
||||
return GDK_PIXBUF (g_object_ref (thumbnail));
|
||||
if (thumbnail && GDK_IS_PIXBUF (thumbnail) && thumbnail_size >= icon_size)
|
||||
return file_system_model_scale_pixbuf_to_fit (GDK_PIXBUF (g_object_ref (thumbnail)),
|
||||
icon_size);
|
||||
}
|
||||
|
||||
if (impl->show_thumbnails ||
|
||||
|
|
@ -15321,6 +15424,8 @@ list_selection_changed (void *selection,
|
|||
path_bar_update (impl);
|
||||
|
||||
check_preview_change (impl);
|
||||
|
||||
preview_panel_queue_update (impl);
|
||||
bookmarks_check_add_sensitivity (impl);
|
||||
|
||||
g_signal_emit_by_name (impl, "selection-changed", 0);
|
||||
|
|
|
|||
|
|
@ -252,6 +252,7 @@ struct _GtkFileChooserDefault
|
|||
GtkWidget *preview_panel_title_label;
|
||||
GtkWidget *preview_panel_info_label;
|
||||
guint preview_panel_resize_timeout_id;
|
||||
guint preview_panel_update_timeout_id;
|
||||
gint preview_panel_last_image_size;
|
||||
GtkWidget *extra_align;
|
||||
GtkWidget *extra_widget;
|
||||
|
|
|
|||
Loading…
Reference in a new issue