Remove insanity
This commit is contained in:
parent
2b17ed838a
commit
5fea2245f1
@ -41,7 +41,8 @@
|
|||||||
struct _FastivBrowser {
|
struct _FastivBrowser {
|
||||||
GtkWidget parent_instance;
|
GtkWidget parent_instance;
|
||||||
|
|
||||||
FastivIoThumbnailSize item_size; ///< Thumbnail height in pixels
|
FastivIoThumbnailSize item_size; ///< Thumbnail size
|
||||||
|
int item_height; ///< Thumbnail height in pixels
|
||||||
|
|
||||||
GArray *entries; ///< [Entry]
|
GArray *entries; ///< [Entry]
|
||||||
GArray *layouted_rows; ///< [Row]
|
GArray *layouted_rows; ///< [Row]
|
||||||
@ -115,7 +116,7 @@ append_row(FastivBrowser *self, int *y, int x, GArray *items_array)
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
// Not trying to pack them vertically, but this would be the place to do it.
|
// Not trying to pack them vertically, but this would be the place to do it.
|
||||||
*y += (int) self->item_size;
|
*y += self->item_height;
|
||||||
*y += self->item_border_y;
|
*y += self->item_border_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +207,7 @@ item_extents(FastivBrowser *self, const Item *item, const Row *row)
|
|||||||
int height = cairo_image_surface_get_height(item->entry->thumbnail);
|
int height = cairo_image_surface_get_height(item->entry->thumbnail);
|
||||||
return (GdkRectangle) {
|
return (GdkRectangle) {
|
||||||
.x = row->x_offset + item->x_offset,
|
.x = row->x_offset + item->x_offset,
|
||||||
.y = row->y_offset + (int) self->item_size - height,
|
.y = row->y_offset + self->item_height - height,
|
||||||
.width = width,
|
.width = width,
|
||||||
.height = height,
|
.height = height,
|
||||||
};
|
};
|
||||||
@ -354,9 +355,10 @@ entry_add_thumbnail(gpointer data, gpointer user_data)
|
|||||||
if (self->thumbnail)
|
if (self->thumbnail)
|
||||||
cairo_surface_destroy(self->thumbnail);
|
cairo_surface_destroy(self->thumbnail);
|
||||||
|
|
||||||
FastivIoThumbnailSize size = FASTIV_BROWSER(user_data)->item_size;
|
FastivBrowser *browser = FASTIV_BROWSER(user_data);
|
||||||
self->thumbnail = rescale_thumbnail(
|
self->thumbnail = rescale_thumbnail(
|
||||||
fastiv_io_lookup_thumbnail(self->filename, size), (int) size);
|
fastiv_io_lookup_thumbnail(self->filename, browser->item_size),
|
||||||
|
browser->item_height);
|
||||||
if (self->thumbnail)
|
if (self->thumbnail)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -390,7 +392,7 @@ materialize_icon(FastivBrowser *self, Entry *entry)
|
|||||||
// TODO(p): Make sure we have /some/ icon for every entry.
|
// TODO(p): Make sure we have /some/ icon for every entry.
|
||||||
// TODO(p): We might want to populate these on an as-needed basis.
|
// TODO(p): We might want to populate these on an as-needed basis.
|
||||||
GtkIconInfo *icon_info = gtk_icon_theme_lookup_by_gicon(
|
GtkIconInfo *icon_info = gtk_icon_theme_lookup_by_gicon(
|
||||||
gtk_icon_theme_get_default(), entry->icon, (int) self->item_size / 2,
|
gtk_icon_theme_get_default(), entry->icon, self->item_height / 2,
|
||||||
GTK_ICON_LOOKUP_FORCE_SYMBOLIC);
|
GTK_ICON_LOOKUP_FORCE_SYMBOLIC);
|
||||||
if (!icon_info)
|
if (!icon_info)
|
||||||
return;
|
return;
|
||||||
@ -401,7 +403,7 @@ materialize_icon(FastivBrowser *self, Entry *entry)
|
|||||||
GdkPixbuf *pixbuf = gtk_icon_info_load_symbolic(
|
GdkPixbuf *pixbuf = gtk_icon_info_load_symbolic(
|
||||||
icon_info, &white, &white, &white, &white, NULL, NULL);
|
icon_info, &white, &white, &white, &white, NULL, NULL);
|
||||||
if (pixbuf) {
|
if (pixbuf) {
|
||||||
int outer_size = (int) self->item_size;
|
int outer_size = self->item_height;
|
||||||
entry->thumbnail =
|
entry->thumbnail =
|
||||||
cairo_image_surface_create(CAIRO_FORMAT_A8, outer_size, outer_size);
|
cairo_image_surface_create(CAIRO_FORMAT_A8, outer_size, outer_size);
|
||||||
|
|
||||||
@ -492,6 +494,7 @@ fastiv_browser_set_property(
|
|||||||
case PROP_THUMBNAIL_SIZE:
|
case PROP_THUMBNAIL_SIZE:
|
||||||
if (g_value_get_enum(value) != (int) self->item_size) {
|
if (g_value_get_enum(value) != (int) self->item_size) {
|
||||||
self->item_size = g_value_get_enum(value);
|
self->item_size = g_value_get_enum(value);
|
||||||
|
self->item_height = fastiv_io_thumbnail_sizes[self->item_size].size;
|
||||||
reload_thumbnails(self);
|
reload_thumbnails(self);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -516,7 +519,7 @@ fastiv_browser_get_preferred_width(
|
|||||||
GtkBorder padding = {};
|
GtkBorder padding = {};
|
||||||
gtk_style_context_get_padding(style, GTK_STATE_FLAG_NORMAL, &padding);
|
gtk_style_context_get_padding(style, GTK_STATE_FLAG_NORMAL, &padding);
|
||||||
*minimum = *natural =
|
*minimum = *natural =
|
||||||
g_permitted_width_multiplier * (int) self->item_size +
|
g_permitted_width_multiplier * self->item_height +
|
||||||
padding.left + 2 * self->item_border_x + padding.right;
|
padding.left + 2 * self->item_border_x + padding.right;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -594,7 +597,7 @@ fastiv_browser_draw(GtkWidget *widget, cairo_t *cr)
|
|||||||
.x = 0,
|
.x = 0,
|
||||||
.y = row->y_offset - self->item_border_y,
|
.y = row->y_offset - self->item_border_y,
|
||||||
.width = allocation.width,
|
.width = allocation.width,
|
||||||
.height = (int) self->item_size + 2 * self->item_border_y,
|
.height = self->item_height + 2 * self->item_border_y,
|
||||||
};
|
};
|
||||||
if (!have_clip || gdk_rectangle_intersect(&clip, &extents, NULL))
|
if (!have_clip || gdk_rectangle_intersect(&clip, &extents, NULL))
|
||||||
draw_row(self, cr, row);
|
draw_row(self, cr, row);
|
||||||
@ -755,6 +758,7 @@ fastiv_browser_init(FastivBrowser *self)
|
|||||||
g_array_set_clear_func(self->layouted_rows, (GDestroyNotify) row_free);
|
g_array_set_clear_func(self->layouted_rows, (GDestroyNotify) row_free);
|
||||||
|
|
||||||
self->item_size = FASTIV_IO_THUMBNAIL_SIZE_NORMAL;
|
self->item_size = FASTIV_IO_THUMBNAIL_SIZE_NORMAL;
|
||||||
|
self->item_height = fastiv_io_thumbnail_sizes[self->item_size].size;
|
||||||
self->selected = -1;
|
self->selected = -1;
|
||||||
self->glow = cairo_image_surface_create(CAIRO_FORMAT_A1, 0, 0);
|
self->glow = cairo_image_surface_create(CAIRO_FORMAT_A1, 0, 0);
|
||||||
|
|
||||||
|
31
fastiv-io.c
31
fastiv-io.c
@ -118,9 +118,10 @@ fastiv_io_thumbnail_size_get_type(void)
|
|||||||
return guard;
|
return guard;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define XX(name, value, dir) {FASTIV_IO_THUMBNAIL_SIZE_ ## name, dir},
|
#define XX(name, value, dir) {value, dir},
|
||||||
FastivIoThumbnailSizeInfo fastiv_io_thumbnail_sizes[] = {
|
FastivIoThumbnailSizeInfo
|
||||||
FASTIV_IO_THUMBNAIL_SIZES(XX) {}};
|
fastiv_io_thumbnail_sizes[FASTIV_IO_THUMBNAIL_SIZE_COUNT] = {
|
||||||
|
FASTIV_IO_THUMBNAIL_SIZES(XX)};
|
||||||
#undef XX
|
#undef XX
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
@ -1006,17 +1007,8 @@ fail_init:
|
|||||||
cairo_surface_t *
|
cairo_surface_t *
|
||||||
fastiv_io_lookup_thumbnail(const gchar *target, FastivIoThumbnailSize size)
|
fastiv_io_lookup_thumbnail(const gchar *target, FastivIoThumbnailSize size)
|
||||||
{
|
{
|
||||||
// TODO(p): Consider having linear enum constants,
|
g_return_val_if_fail(size >= FASTIV_IO_THUMBNAIL_SIZE_MIN &&
|
||||||
// and using a trivial lookup table. This is ridiculous.
|
size <= FASTIV_IO_THUMBNAIL_SIZE_MAX, NULL);
|
||||||
int size_index = 0;
|
|
||||||
while (fastiv_io_thumbnail_sizes[size_index].size &&
|
|
||||||
fastiv_io_thumbnail_sizes[size_index].size < size)
|
|
||||||
size_index++;
|
|
||||||
int size_count = size_index;
|
|
||||||
while (fastiv_io_thumbnail_sizes[size_count].size)
|
|
||||||
size_count++;
|
|
||||||
|
|
||||||
g_return_val_if_fail(fastiv_io_thumbnail_sizes[size_index].size, NULL);
|
|
||||||
|
|
||||||
GStatBuf st;
|
GStatBuf st;
|
||||||
if (g_stat(target, &st))
|
if (g_stat(target, &st))
|
||||||
@ -1031,15 +1023,16 @@ fastiv_io_lookup_thumbnail(const gchar *target, FastivIoThumbnailSize size)
|
|||||||
gchar *sum = g_compute_checksum_for_string(G_CHECKSUM_MD5, uri, -1);
|
gchar *sum = g_compute_checksum_for_string(G_CHECKSUM_MD5, uri, -1);
|
||||||
gchar *cache_dir = get_xdg_home_dir("XDG_CACHE_HOME", ".cache");
|
gchar *cache_dir = get_xdg_home_dir("XDG_CACHE_HOME", ".cache");
|
||||||
|
|
||||||
|
// The lookup sequence is: nominal..max, then mirroring back to ..min.
|
||||||
cairo_surface_t *result = NULL;
|
cairo_surface_t *result = NULL;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
for (int i = 0; i < size_count; i++) {
|
for (int i = 0; i < FASTIV_IO_THUMBNAIL_SIZE_COUNT; i++) {
|
||||||
int size_use = size_index + i;
|
int use = size + i;
|
||||||
if (size_use >= size_count)
|
if (use > FASTIV_IO_THUMBNAIL_SIZE_MAX)
|
||||||
size_use = size_count - i - 1;
|
use = FASTIV_IO_THUMBNAIL_SIZE_MAX - i;
|
||||||
|
|
||||||
gchar *path = g_strdup_printf("%s/thumbnails/%s/%s.png", cache_dir,
|
gchar *path = g_strdup_printf("%s/thumbnails/%s/%s.png", cache_dir,
|
||||||
fastiv_io_thumbnail_sizes[size_use].directory_name, sum);
|
fastiv_io_thumbnail_sizes[use].thumbnail_spec_name, sum);
|
||||||
result = read_spng_thumbnail(path, uri, st.st_mtim.tv_sec, &error);
|
result = read_spng_thumbnail(path, uri, st.st_mtim.tv_sec, &error);
|
||||||
if (error) {
|
if (error) {
|
||||||
g_debug("%s: %s", path, error->message);
|
g_debug("%s: %s", path, error->message);
|
||||||
|
16
fastiv-io.h
16
fastiv-io.h
@ -32,23 +32,25 @@ typedef enum _FastivIoThumbnailSize {
|
|||||||
XX(NORMAL, 256, "large") \
|
XX(NORMAL, 256, "large") \
|
||||||
XX(LARGE, 512, "x-large") \
|
XX(LARGE, 512, "x-large") \
|
||||||
XX(HUGE, 1024, "xx-large")
|
XX(HUGE, 1024, "xx-large")
|
||||||
#define XX(name, value, dir) FASTIV_IO_THUMBNAIL_SIZE_ ## name = value,
|
#define XX(name, value, dir) FASTIV_IO_THUMBNAIL_SIZE_ ## name,
|
||||||
FASTIV_IO_THUMBNAIL_SIZES(XX)
|
FASTIV_IO_THUMBNAIL_SIZES(XX)
|
||||||
#undef XX
|
#undef XX
|
||||||
FASTIV_IO_THUMBNAIL_SIZE_MIN = FASTIV_IO_THUMBNAIL_SIZE_SMALL,
|
FASTIV_IO_THUMBNAIL_SIZE_COUNT,
|
||||||
FASTIV_IO_THUMBNAIL_SIZE_MAX = FASTIV_IO_THUMBNAIL_SIZE_HUGE
|
|
||||||
|
FASTIV_IO_THUMBNAIL_SIZE_MIN = 0,
|
||||||
|
FASTIV_IO_THUMBNAIL_SIZE_MAX = FASTIV_IO_THUMBNAIL_SIZE_COUNT - 1
|
||||||
} FastivIoThumbnailSize;
|
} FastivIoThumbnailSize;
|
||||||
|
|
||||||
GType fastiv_io_thumbnail_size_get_type(void) G_GNUC_CONST;
|
GType fastiv_io_thumbnail_size_get_type(void) G_GNUC_CONST;
|
||||||
#define FASTIV_TYPE_IO_THUMBNAIL_SIZE (fastiv_io_thumbnail_size_get_type())
|
#define FASTIV_TYPE_IO_THUMBNAIL_SIZE (fastiv_io_thumbnail_size_get_type())
|
||||||
|
|
||||||
typedef struct _FastivIoThumbnailSizeInfo {
|
typedef struct _FastivIoThumbnailSizeInfo {
|
||||||
FastivIoThumbnailSize size; ///< Nominal size in pixels
|
int size; ///< Nominal size in pixels
|
||||||
const char *directory_name; ///< thumbnail-spec directory name
|
const char *thumbnail_spec_name; ///< thumbnail-spec directory name
|
||||||
} FastivIoThumbnailSizeInfo;
|
} FastivIoThumbnailSizeInfo;
|
||||||
|
|
||||||
// The array is null-terminated.
|
extern FastivIoThumbnailSizeInfo
|
||||||
extern FastivIoThumbnailSizeInfo fastiv_io_thumbnail_sizes[];
|
fastiv_io_thumbnail_sizes[FASTIV_IO_THUMBNAIL_SIZE_COUNT];
|
||||||
|
|
||||||
cairo_surface_t *fastiv_io_open(const gchar *path, GError **error);
|
cairo_surface_t *fastiv_io_open(const gchar *path, GError **error);
|
||||||
cairo_surface_t *fastiv_io_open_from_data(
|
cairo_surface_t *fastiv_io_open_from_data(
|
||||||
|
16
fastiv.c
16
fastiv.c
@ -335,20 +335,14 @@ on_open_location(G_GNUC_UNUSED GtkPlacesSidebar *sidebar, GFile *location,
|
|||||||
static void
|
static void
|
||||||
on_toolbar_zoom(G_GNUC_UNUSED GtkButton *button, gpointer user_data)
|
on_toolbar_zoom(G_GNUC_UNUSED GtkButton *button, gpointer user_data)
|
||||||
{
|
{
|
||||||
FastivIoThumbnailSize size = FASTIV_IO_THUMBNAIL_SIZE_MIN;
|
FastivIoThumbnailSize size = FASTIV_IO_THUMBNAIL_SIZE_COUNT;
|
||||||
g_object_get(g.browser, "thumbnail-size", &size, NULL);
|
g_object_get(g.browser, "thumbnail-size", &size, NULL);
|
||||||
|
|
||||||
gintptr position = -1, count = 0, adjustment = (gintptr) user_data;
|
size += (gintptr) user_data;
|
||||||
while (fastiv_io_thumbnail_sizes[count].size) {
|
g_return_if_fail(size >= FASTIV_IO_THUMBNAIL_SIZE_MIN &&
|
||||||
if (fastiv_io_thumbnail_sizes[count].size == size)
|
size <= FASTIV_IO_THUMBNAIL_SIZE_MAX);
|
||||||
position = count;
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
position += adjustment;
|
g_object_set(g.browser, "thumbnail-size", size, NULL);
|
||||||
g_return_if_fail(position >= 0 && position < count);
|
|
||||||
g_object_set(g.browser, "thumbnail-size",
|
|
||||||
fastiv_io_thumbnail_sizes[position].size, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user