Compare commits

...
Author SHA1 Message Date
d666cf3f03 gtkfilesystem: bound the shared file icon cache
The per-icon-theme pixbuf cache used for themed file icons was never
evicted, so zooming through the icon view kept a rendered copy of every
icon at every size alive for the lifetime of the process.

Keep it as an LRU instead: at most 64 entries and 4 MiB of pixel data,
least recently used entries are dropped first, and the whole cache is
still cleared when the icon theme changes. 64 entries comfortably hold
the icons of one folder at two zoom levels, so scrolling and zooming
keep hitting the cache while memory stays bounded on small machines.

Valgrind zoom stress (icon view, all zoom levels, folder switches)
reports no errors in the new code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F6aiMGWu4tXHcuSSC9DHi2
2026-10-13 12:52:11 +02:00
3ebf5c3689 filechooser: schedule icon queries for visible rows, newest first
Each row that became visible started its own icon/thumbnail query right
away, without limit and without cancellation.  Scrolling through a large
folder queued hundreds of queries in GIO's shared thread pool; rows
scrolled past were still served before the rows now on screen.  On a
hung network share every such query blocks a pool thread, so after some
scrolling even listing a different folder had to wait for free threads.

Icon queries now go through a small scheduler:

- at most 16 queries run at a time (enough to serve a screenful in one
  round on a high-latency share, see below), further requests wait;
- waiting requests are served newest first, so rows on screen win over
  rows that were scrolled past;
- after scrolling (coalesced per main loop iteration) waiting requests
  for rows more than one page away are dropped and running ones are
  cancelled; such rows are queried again when they are shown;
- the queue holds at most 256 requests, and requests end when their
  model goes away (weak reference) or the chooser is disposed.

With 20 ms emulated latency per file system call, the visible rows after
fast scrolling get their icons as quickly as before (51 ms); lower limits
of 4 or 8 parallel queries made that 152 ms and 102 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F6aiMGWu4tXHcuSSC9DHi2
2026-10-13 12:52:11 +02:00
d5175e2f26 filechooser: show files while a folder is still loading
The file list stayed empty until the whole folder had been read, sorted
and filtered.  On a high-latency NFS share that can take many seconds
(20000 files at 1 ms per call: 24 s) with nothing to see.

GtkFileSystemModel now commits loaded entries incrementally when asked
to (_gtk_file_system_model_set_incremental):

- New entries collect in an unsorted tail.  The first commit happens
  after 100 ms, later ones at growing intervals up to once per second.
- A commit sorts the tail (resumable bottom-up merge sort) and merges it
  into the committed, sorted part in one O(n) pass, announcing new rows
  with row-inserted in ascending order.  Both steps run in short main
  loop slices; between slices, every GtkTreeModel query answers from the
  merged prefix plus the not yet merged old rows, so views stay
  consistent.  Operations that need one array (editable row, removals,
  cache clearing) finish a running merge first.
- Sorting or filtering changes during loading are applied to the rows
  already shown; up to two batches are read ahead.
- The old loading code was the same sort without the merge, so a folder
  that is not loaded incrementally takes the same path with a single
  final commit.

The file chooser uses this for the list view and attaches the model
right away.  GtkIconView inserts rows in O(n), so it keeps getting the
model when loading is done (switching views during loading follows
this).  This also fixes "Create Folder" during loading: it used to put
the model on hold while the view had no model, so editing never started
and the folder never finished loading.  The view now gets the model
first.  A selection made during loading is no longer replaced by the
first row when loading finishes.

Invisible nodes without a preceding visible row now report row 0 instead
of hitting an assertion.

Measured (list view): 20000 files with 1 ms emulated latency: first rows
after 0.13 s instead of 24 s; 100000 local files: first rows after
0.14 s, complete after 2.4 s, longest main loop stall 18 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F6aiMGWu4tXHcuSSC9DHi2
2026-10-13 12:52:11 +02:00
5ce6b4c104 gtkfilesystemmodel: read the next batch while integrating the current one
The next batch of directory entries was only requested after the current
batch had been integrated on the main thread.  The enumerator thread
idled while the main thread worked, and the main thread waited for I/O
afterwards, so I/O and CPU never overlapped.  That costs most on slow
CPUs, where integrating a batch takes a noticeable share of the time.

Now one further batch is requested as soon as fewer than one batch of
entries is queued, so at most two batches are in memory.  When the
enumerator reports the end of the folder (or an error) while entries are
still queued, loading finishes once they have been integrated.

100000 local files: 1718 ms instead of 1989 ms until the list is ready.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F6aiMGWu4tXHcuSSC9DHi2
2026-10-13 12:52:11 +02:00
b1f87233c2 filechooser: no blocking file system calls on folder changes
Opening a folder ran g_file_find_enclosing_mount() on the main thread to
decide how to show it in the shortcuts list.  That stats the folder and
its parents; on a slow or hung NFS share it freezes the whole dialog,
including the Cancel button.  Similar synchronous calls ran when
activating a bookmark, when reporting that a folder could not be read
(exactly when the share has problems) and when creating a new folder.

- The current-folder shortcut is added once an asynchronous
  g_file_find_enclosing_mount_async() finishes; a newer folder change
  cancels the pending lookup.  _gtk_file_system_volume_for_mount() maps
  the result to the same volume as before.
- Activating a file bookmark queries the location directly and only
  mounts the enclosing volume when the query reports G_IO_ERROR_NOT_MOUNTED,
  instead of looking up the volume synchronously first.
- The "could not read the contents" message uses g_file_get_parse_name()
  instead of querying the folder again.
- New folders are created with g_file_make_directory_async().

With the latency emulation, the main thread no longer touches the folder
at all (previously one blocking lstat per folder change).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F6aiMGWu4tXHcuSSC9DHi2
2026-10-13 12:52:11 +02:00
1f16f4e43c filechooser: list folders with fast-content-type, sniff only when needed
The folder was enumerated with standard::content-type.  For every file
whose type GIO cannot tell from its name, that opens the file and reads
its first bytes.  On a slow disk or a high-latency NFS share this costs
several round trips per file, while the content type is only used by
MIME-type file filters.

The folder is now listed with standard::fast-content-type, which only
looks at the name.  When a MIME filter needs the type of a file whose
name did not reveal it, the model detects the content type
asynchronously (at most two requests in flight, low priority) and
filters that file again once the result arrives.  Files sniffed while
the folder is still loading are filtered again when loading finishes.
Content types are read with g_file_info_has_attribute() first, so GLib
does not warn about attributes that were not queried.

With 20000 files and 1 ms emulated latency per file system call, the
folder now loads in 24.1 s instead of 31.6 s (21519 instead of 28105
calls).  An extensionless PDF still passes an application/pdf filter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F6aiMGWu4tXHcuSSC9DHi2
2026-10-13 12:52:11 +02:00
f830c3bac3 filechooser: use fixed-height mode with fixed column widths in the list
GtkTreeView measures every row of the model to size its columns and to
compute row heights.  For a large folder that means formatting and
measuring the size and date of every file, even of rows that are never
shown.

The file list now uses gtk_tree_view_set_fixed_height_mode() through the
public API.  For that all columns are switched to fixed sizing:

- Size and Modified get a width that fits the widest string the column
  can show in the current locale: g_format_size() for each unit, and the
  date formatter for today, yesterday, every weekday and one date in
  every month.  The column title (plus room for the sort arrow) is also
  taken into account.  Widths are recomputed on style changes, and the
  columns stay resizable.
- The name column keeps expanding into the remaining space.
- Size is right-aligned and both columns ellipsize instead of clipping.

Unlike forcing fixed-height mode on columns that still size themselves,
this does not clip sizes or dates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F6aiMGWu4tXHcuSSC9DHi2
2026-10-13 12:52:11 +02:00
2413f8bf13 filechooser, gtkiconview: stop quadratic work in the icon view
Opening a folder with 100000 files in icon view did not finish within
10 minutes, and with 20000 files every scroll step blocked for seconds.

- The file chooser computed the visible range for every icon cell it was
  asked for.  For GtkIconView that is a walk over all items, and the
  view asks for every item while laying out, so a layout was O(n^2).
  The chooser now caches the visible index range and recomputes it only
  after scrolling, resizing or a model change.

- gtk_icon_view_get_visible_range() and the expose handler stop at the
  first item below the visible area.  Items are laid out row by row, so
  the result is unchanged.

- Every relayout measured the cells of every item again in
  gtk_icon_view_calculate_item_size2(), and every loaded icon caused a
  relayout.  An icon view can now reuse a measured cell layout and just
  move it when only the item position changed.  This is internal and
  opt-in (_gtk_icon_view_set_cache_cell_layout), so applications keep
  the old behaviour; the file chooser enables it and invalidates the
  cache when zooming.  The cache is also dropped on style changes.

- Sequential row-changed notifications looked up their item with
  g_list_nth_data() and then walked the whole list in verify_items().
  Lookups now continue from the previous item, and verify_items() only
  runs in --enable-debug=yes builds.

Measured with 100000 files in icon view: longest main loop stall while
scrolling went from 5059 ms to 40 ms.  No public API or structure changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F6aiMGWu4tXHcuSSC9DHi2
2026-10-13 12:52:11 +02:00
37de695130 gtkfilesystemmodel: detect known files correctly and coalesce re-sorts
query_done used "files->len did not grow" to decide whether a queried file
was already part of the model.  Node slots of removed files are reused,
so a new file can take a free slot without growing the array; it was then
treated as a changed file and triggered a full sort.  Look the file up
before updating it instead.

Changed files (from late queries and from the directory monitor) can
change position when sorting by size or modification time.  The monitor
path never re-sorted, the query path sorted immediately for every file.
Both now queue one sort after 100 ms, so a burst of changes costs a
single sort.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F6aiMGWu4tXHcuSSC9DHi2
2026-10-13 12:52:11 +02:00
8 changed files with 1893 additions and 388 deletions

File diff suppressed because it is too large Load diff

View file

@ -234,6 +234,17 @@ struct _GtkFileChooserDefault
guint icon_view_scale_visible_timeout_id;
guint icon_view_scale_after_layout_id;
gint pending_icon_view_icon_size;
/* Cached index range of the rows shown in the current view. Computing
* it is O(n) for GtkIconView, so it must not be done per cell. */
gint visible_range_first;
gint visible_range_last;
guint visible_range_valid : 1;
/* Icon/thumbnail queries for visible rows (see icon_request_add) */
GQueue *icon_requests; /* waiting, newest first */
GList *icon_requests_running;
guint icon_requests_prune_id;
gint icon_view_scale_visible_overscan;
ViewMode view_mode;
@ -259,6 +270,7 @@ struct _GtkFileChooserDefault
GCancellable *file_exists_get_info_cancellable;
GCancellable *update_from_entry_cancellable;
GCancellable *shortcuts_activate_iter_cancellable;
GCancellable *shortcuts_current_folder_cancellable;
LoadState load_state;
ReloadState reload_state;

View file

@ -1077,6 +1077,19 @@ _gtk_file_system_set_bookmark_label (GtkFileSystem *file_system,
g_signal_emit_by_name (file_system, "bookmarks-changed", 0);
}
GtkFileSystemVolume *
_gtk_file_system_volume_for_mount (GFile *file,
GMount *mount)
{
if (!mount && g_file_is_native (file))
return (GtkFileSystemVolume *) root_volume_token;
return (GtkFileSystemVolume *) mount;
}
/* Note: this blocks (it stats @file and its parents); prefer
* g_file_find_enclosing_mount_async() plus _gtk_file_system_volume_for_mount()
* in code that runs on the main thread. */
GtkFileSystemVolume *
_gtk_file_system_get_volume_for_file (GtkFileSystem *file_system,
GFile *file)
@ -1626,18 +1639,105 @@ file_icon_cache_key_free (FileIconCacheKey *key)
g_slice_free (FileIconCacheKey, key);
}
static void
file_icon_cache_theme_changed_cb (GtkIconTheme *icon_theme,
GHashTable *cache)
/* The cache is bounded (least recently used entries go first) so zooming
* through many icon sizes does not keep every rendered size alive. */
#define FILE_ICON_CACHE_MAX_ENTRIES 64
#define FILE_ICON_CACHE_MAX_BYTES (4 * 1024 * 1024)
typedef struct
{
g_hash_table_remove_all (cache);
GHashTable *table; /* FileIconCacheKey -> FileIconCacheEntry */
GQueue lru; /* keys, most recently used first */
gsize bytes;
} FileIconCache;
typedef struct
{
GdkPixbuf *pixbuf;
GList *link; /* in FileIconCache.lru */
gsize bytes;
} FileIconCacheEntry;
static void
file_icon_cache_entry_free (FileIconCacheEntry *entry)
{
g_object_unref (entry->pixbuf);
g_slice_free (FileIconCacheEntry, entry);
}
static GHashTable *
static void
file_icon_cache_free (FileIconCache *cache)
{
g_queue_clear (&cache->lru);
g_hash_table_destroy (cache->table);
g_slice_free (FileIconCache, cache);
}
static void
file_icon_cache_theme_changed_cb (GtkIconTheme *icon_theme,
FileIconCache *cache)
{
g_queue_clear (&cache->lru);
g_hash_table_remove_all (cache->table);
cache->bytes = 0;
}
static GdkPixbuf *
file_icon_cache_lookup (FileIconCache *cache,
const FileIconCacheKey *key)
{
FileIconCacheEntry *entry = g_hash_table_lookup (cache->table, key);
if (entry == NULL)
return NULL;
/* Mark as most recently used. */
g_queue_unlink (&cache->lru, entry->link);
g_queue_push_head_link (&cache->lru, entry->link);
return entry->pixbuf;
}
static void
file_icon_cache_insert (FileIconCache *cache,
FileIconCacheKey *key,
GdkPixbuf *pixbuf)
{
FileIconCacheEntry *entry;
/* g_hash_table_insert() would free @key and keep the old one, leaving a
* dangling pointer in the LRU queue; keep the existing entry instead. */
if (g_hash_table_lookup (cache->table, key) != NULL)
{
file_icon_cache_key_free (key);
return;
}
entry = g_slice_new (FileIconCacheEntry);
entry->pixbuf = g_object_ref (pixbuf);
entry->bytes = (gsize) gdk_pixbuf_get_rowstride (pixbuf) * gdk_pixbuf_get_height (pixbuf);
g_queue_push_head (&cache->lru, key);
entry->link = cache->lru.head;
g_hash_table_insert (cache->table, key, entry);
cache->bytes += entry->bytes;
while (cache->lru.length > 1 &&
(cache->lru.length > FILE_ICON_CACHE_MAX_ENTRIES ||
cache->bytes > FILE_ICON_CACHE_MAX_BYTES))
{
FileIconCacheKey *old_key = g_queue_pop_tail (&cache->lru);
FileIconCacheEntry *old = g_hash_table_lookup (cache->table, old_key);
cache->bytes -= old->bytes;
g_hash_table_remove (cache->table, old_key);
}
}
static FileIconCache *
file_icon_cache_get_for_icon_theme (GtkIconTheme *icon_theme)
{
static GQuark quark_file_icon_cache = 0;
GHashTable *cache;
FileIconCache *cache;
if (G_UNLIKELY (quark_file_icon_cache == 0))
quark_file_icon_cache = g_quark_from_static_string ("gtk-file-icon-cache");
@ -1645,14 +1745,16 @@ file_icon_cache_get_for_icon_theme (GtkIconTheme *icon_theme)
cache = g_object_get_qdata (G_OBJECT (icon_theme), quark_file_icon_cache);
if (!cache)
{
cache = g_hash_table_new_full (file_icon_cache_key_hash,
file_icon_cache_key_equal,
(GDestroyNotify) file_icon_cache_key_free,
g_object_unref);
cache = g_slice_new0 (FileIconCache);
cache->table = g_hash_table_new_full (file_icon_cache_key_hash,
file_icon_cache_key_equal,
(GDestroyNotify) file_icon_cache_key_free,
(GDestroyNotify) file_icon_cache_entry_free);
g_queue_init (&cache->lru);
g_object_set_qdata_full (G_OBJECT (icon_theme),
quark_file_icon_cache,
cache,
(GDestroyNotify) g_hash_table_destroy);
(GDestroyNotify) file_icon_cache_free);
g_signal_connect (icon_theme, "changed",
G_CALLBACK (file_icon_cache_theme_changed_cb),
@ -1671,7 +1773,7 @@ get_pixbuf_from_gicon (GIcon *icon,
GdkScreen *screen;
GtkIconTheme *icon_theme;
GtkIconInfo *icon_info;
GHashTable *cache;
FileIconCache *cache;
FileIconCacheKey lookup_key;
FileIconCacheKey *cache_key;
GdkPixbuf *pixbuf;
@ -1695,7 +1797,7 @@ get_pixbuf_from_gicon (GIcon *icon,
lookup_key.icon = icon;
lookup_key.icon_size = icon_size;
pixbuf = g_hash_table_lookup (cache, &lookup_key);
pixbuf = file_icon_cache_lookup (cache, &lookup_key);
if (pixbuf)
return g_object_ref (pixbuf);
}
@ -1721,7 +1823,7 @@ get_pixbuf_from_gicon (GIcon *icon,
if (cache)
{
cache_key = file_icon_cache_key_new (screen, icon, icon_size);
g_hash_table_insert (cache, cache_key, g_object_ref (pixbuf));
file_icon_cache_insert (cache, cache_key, pixbuf);
}
return pixbuf;

View file

@ -130,6 +130,11 @@ void _gtk_file_system_set_bookmark_label (GtkFileSystem *file_system,
GFile *file,
const gchar *label);
/* Turns the result of g_file_find_enclosing_mount{,_async}() for @file into
* the volume _gtk_file_system_get_volume_for_file() would return. Takes
* ownership of @mount. */
GtkFileSystemVolume * _gtk_file_system_volume_for_mount (GFile *file,
GMount *mount);
GtkFileSystemVolume * _gtk_file_system_get_volume_for_file (GtkFileSystem *file_system,
GFile *file);

File diff suppressed because it is too large Load diff

View file

@ -53,6 +53,8 @@ GtkFileSystemModel *_gtk_file_system_model_new_for_directory(GFile *
guint n_columns,
...);
GCancellable * _gtk_file_system_model_get_cancellable (GtkFileSystemModel *model);
void _gtk_file_system_model_set_incremental (GtkFileSystemModel *model,
gboolean incremental);
gboolean _gtk_file_system_model_iter_is_visible (GtkFileSystemModel *model,
GtkTreeIter *iter);
gboolean _gtk_file_system_model_iter_is_filtered_out (GtkFileSystemModel *model,

View file

@ -74,6 +74,16 @@ struct _GtkIconViewItem
guint selected : 1;
guint selected_before_rubberbanding : 1;
/* Cached result of gtk_icon_view_calculate_item_size2(), only used when
* the view caches cell layouts (see _gtk_icon_view_set_cache_cell_layout).
* The inputs are the item geometry before the call and the row's
* per-cell maximum heights; the outputs are box/before/after plus the
* final width and height. */
guint layout_valid : 1;
guint layout_rtl : 1;
gint layout_x, layout_y, layout_width;
gint layout_out_width, layout_out_height;
gint *layout_max_height;
};
typedef struct _GtkIconViewCellInfo GtkIconViewCellInfo;
@ -106,6 +116,15 @@ struct _GtkIconViewPrivate
{
gint width, height;
/* Reuse per-item cell layouts across relayouts (internal, opt-in). */
guint cache_cell_layout : 1;
/* Last item looked up by index; makes sequential row-changed
* notifications O(1) instead of O(n) each. Reset whenever the item
* list changes. */
GList *nth_cache_link;
gint nth_cache_index;
GtkSelectionMode selection_mode;
GdkWindow *bin_window;
@ -305,6 +324,7 @@ static void gtk_icon_view_queue_draw_path (GtkIco
static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
GtkIconViewItem *item);
static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
static void gtk_icon_view_invalidate_cell_layouts (GtkIconView *icon_view);
static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
GtkIconViewItem *item,
gint cursor_cell);
@ -1425,6 +1445,9 @@ gtk_icon_view_style_set (GtkWidget *widget,
gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
}
/* Cell sizes depend on the style; never reuse layouts measured before. */
gtk_icon_view_invalidate_cell_layouts (icon_view);
gtk_widget_queue_resize (widget);
}
@ -1590,6 +1613,10 @@ gtk_icon_view_expose (GtkWidget *widget,
GtkIconViewItem *item = icons->data;
GdkRectangle area;
/* Rows are laid out top to bottom; nothing after this can be exposed. */
if (item->y > expose->area.y + expose->area.height)
break;
area.x = item->x;
area.y = item->y;
area.width = item->width;
@ -2687,6 +2714,115 @@ gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
}
}
/* Same result as gtk_icon_view_calculate_item_size2(), but when cell
* layout caching is enabled and nothing that the calculation depends on
* has changed except the item position, the cached cell boxes are moved
* instead of measuring all cell renderers again. Measuring text cells is
* by far the most expensive part of a relayout, and relayouts happen for
* every model change, so this keeps large views responsive. */
static void
gtk_icon_view_calculate_item_size2_cached (GtkIconView *icon_view,
GtkIconViewItem *item,
gint *max_height,
gboolean rtl)
{
gint n_cells = icon_view->priv->n_cells;
gint i;
if (!icon_view->priv->cache_cell_layout)
{
gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
return;
}
if (item->layout_valid &&
item->n_cells == n_cells &&
item->layout_max_height != NULL &&
item->layout_rtl == (rtl != FALSE) &&
item->layout_width == item->width &&
memcmp (item->layout_max_height, max_height, n_cells * sizeof (gint)) == 0)
{
gint dx = item->x - item->layout_x;
gint dy = item->y - item->layout_y;
if (dx != 0 || dy != 0)
{
for (i = 0; i < n_cells; i++)
{
item->box[i].x += dx;
item->box[i].y += dy;
}
}
item->layout_x = item->x;
item->layout_y = item->y;
item->width = item->layout_out_width;
item->height = item->layout_out_height;
return;
}
item->layout_x = item->x;
item->layout_y = item->y;
item->layout_width = item->width;
item->layout_rtl = rtl != FALSE;
gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
if (item->layout_max_height == NULL)
item->layout_max_height = g_new (gint, n_cells);
memcpy (item->layout_max_height, max_height, n_cells * sizeof (gint));
item->layout_out_width = item->width;
item->layout_out_height = item->height;
item->layout_valid = item->n_cells == n_cells;
}
static void
gtk_icon_view_invalidate_cell_layouts (GtkIconView *icon_view)
{
GList *l;
for (l = icon_view->priv->items; l; l = l->next)
((GtkIconViewItem *) l->data)->layout_valid = FALSE;
}
/*
* _gtk_icon_view_set_cache_cell_layout:
*
* Internal. Lets an icon view reuse measured cell layouts across
* relayouts. Only for views whose owner invalidates the layout itself
* (with _gtk_icon_view_invalidate_cell_layout() or by changing the model
* row) whenever cell renderer sizes change outside the icon view's
* knowledge. Off by default, so applications see no behaviour change.
*/
void
_gtk_icon_view_set_cache_cell_layout (GtkWidget *widget,
gboolean cache)
{
GtkIconView *icon_view;
g_return_if_fail (GTK_IS_ICON_VIEW (widget));
icon_view = GTK_ICON_VIEW (widget);
cache = cache != FALSE;
if (icon_view->priv->cache_cell_layout == cache)
return;
icon_view->priv->cache_cell_layout = cache;
gtk_icon_view_invalidate_cell_layouts (icon_view);
}
void
_gtk_icon_view_invalidate_cell_layout (GtkWidget *widget)
{
GtkIconView *icon_view;
g_return_if_fail (GTK_IS_ICON_VIEW (widget));
icon_view = GTK_ICON_VIEW (widget);
gtk_icon_view_invalidate_cell_layouts (icon_view);
gtk_icon_view_queue_layout (icon_view);
}
static GList *
gtk_icon_view_layout_single_row (GtkIconView *icon_view,
GList *first_item,
@ -2771,7 +2907,7 @@ gtk_icon_view_layout_single_row (GtkIconView *icon_view,
item->col = col - 1 - item->col;
}
gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
gtk_icon_view_calculate_item_size2_cached (icon_view, item, max_height, rtl);
/* We may want to readjust the new y coordinate. */
if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
@ -3011,6 +3147,10 @@ gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
item->after = g_new0 (gint, icon_view->priv->n_cells);
item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
g_free (item->layout_max_height);
item->layout_max_height = NULL;
item->layout_valid = FALSE;
item->n_cells = icon_view->priv->n_cells;
}
@ -3157,6 +3297,7 @@ gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
{
item->width = -1;
item->height = -1;
item->layout_valid = FALSE;
}
static void
@ -3480,6 +3621,7 @@ gtk_icon_view_item_free (GtkIconViewItem *item)
g_free (item->before);
g_free (item->after);
g_free (item->box);
g_free (item->layout_max_height);
g_free (item);
}
@ -3588,6 +3730,7 @@ gtk_icon_view_unselect_item (GtkIconView *icon_view,
static void
verify_items (GtkIconView *icon_view)
{
#ifdef G_ENABLE_DEBUG
GList *items;
int i = 0;
@ -3601,6 +3744,38 @@ verify_items (GtkIconView *icon_view)
i++;
}
#endif
}
static void
gtk_icon_view_reset_nth_cache (GtkIconView *icon_view)
{
icon_view->priv->nth_cache_link = NULL;
icon_view->priv->nth_cache_index = -1;
}
static GtkIconViewItem *
gtk_icon_view_nth_item (GtkIconView *icon_view,
gint index)
{
GtkIconViewPrivate *priv = icon_view->priv;
GList *link = NULL;
if (priv->nth_cache_link != NULL)
{
if (index == priv->nth_cache_index)
link = priv->nth_cache_link;
else if (index == priv->nth_cache_index + 1)
link = priv->nth_cache_link->next;
}
if (link == NULL)
link = g_list_nth (priv->items, index);
priv->nth_cache_link = link;
priv->nth_cache_index = link ? index : -1;
return link ? link->data : NULL;
}
static void
@ -3618,7 +3793,7 @@ gtk_icon_view_row_changed (GtkTreeModel *model,
gtk_icon_view_stop_editing (icon_view, TRUE);
index = gtk_tree_path_get_indices(path)[0];
item = g_list_nth_data (icon_view->priv->items, index);
item = gtk_icon_view_nth_item (icon_view, index);
gtk_icon_view_item_invalidate_size (item);
gtk_icon_view_queue_layout (icon_view);
@ -3640,6 +3815,8 @@ gtk_icon_view_row_inserted (GtkTreeModel *model,
icon_view = GTK_ICON_VIEW (data);
gtk_icon_view_reset_nth_cache (icon_view);
iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
index = gtk_tree_path_get_indices(path)[0];
@ -3684,6 +3861,8 @@ gtk_icon_view_row_deleted (GtkTreeModel *model,
icon_view = GTK_ICON_VIEW (data);
gtk_icon_view_reset_nth_cache (icon_view);
index = gtk_tree_path_get_indices(path)[0];
list = g_list_nth (icon_view->priv->items, index);
@ -3735,6 +3914,8 @@ gtk_icon_view_rows_reordered (GtkTreeModel *model,
icon_view = GTK_ICON_VIEW (data);
gtk_icon_view_reset_nth_cache (icon_view);
gtk_icon_view_stop_editing (icon_view, TRUE);
length = gtk_tree_model_iter_n_children (model, NULL);
@ -3771,6 +3952,8 @@ gtk_icon_view_build_items (GtkIconView *icon_view)
gboolean iters_persist;
GList *items = NULL;
gtk_icon_view_reset_nth_cache (icon_view);
iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
@ -5209,6 +5392,13 @@ gtk_icon_view_get_visible_range (GtkIconView *icon_view,
{
GtkIconViewItem *item = icons->data;
/* Items are laid out row by row, so once an item starts below the
* visible area, all following items do too. Stop here instead of
* walking the rest of a possibly huge list. */
if (start_index != -1 &&
item->y > (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size))
break;
if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
(item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
(item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
@ -5322,6 +5512,8 @@ gtk_icon_view_set_model (GtkIconView *icon_view,
g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
gtk_icon_view_reset_nth_cache (icon_view);
if (icon_view->priv->model == model)
return;

View file

@ -141,6 +141,13 @@ const gchar *_gtk_font_style_name_translate (const gchar *name);
#define _gtk_font_style_name_translate(name) (name)
#endif
/* GtkIconView internals used by the file chooser */
G_GNUC_INTERNAL
void _gtk_icon_view_set_cache_cell_layout (GtkWidget *icon_view,
gboolean cache);
G_GNUC_INTERNAL
void _gtk_icon_view_invalidate_cell_layout (GtkWidget *icon_view);
gboolean _gtk_fnmatch (const char *pattern,
const char *string,
gboolean no_leading_period);