-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsquare-thumbs-v31.diff
More file actions
160 lines (146 loc) · 4.66 KB
/
Copy pathsquare-thumbs-v31.diff
File metadata and controls
160 lines (146 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
From 84e5a62298a0228f5b082482a015c436a0e32aa9 Mon Sep 17 00:00:00 2001
From: explosion-mental <explosion0mental@gmail.com>
Date: Sat, 28 Jan 2023 17:03:08 -0500
Subject: [PATCH] [PATCH] square_thumbs
Only in **thumbnail mode**; displays the images in squares of the same
size, in a more consitent and uniform way. It will scale into ('zoom')
the image if it happens to be too small (horizontally or vertically)
in a case that will leave a spaces around, which is the normal
behaviour.
Additionally adds a keybinding to change this at runtime and a
configuration option in config.def.h to change this at compile time.
---
commands.c | 8 ++++++++
commands.h | 2 ++
config.def.h | 5 +++++
nsxiv.h | 1 +
thumbs.c | 46 +++++++++++++++++++++++++++++++++-------------
5 files changed, 49 insertions(+), 13 deletions(-)
diff --git a/commands.c b/commands.c
index a4ae38d..2e29c87 100644
--- a/commands.c
+++ b/commands.c
@@ -476,3 +476,11 @@ bool ct_select(arg_t _)
return dirty;
}
+
+bool ct_toggle_squared(arg_t _)
+{
+ tns_toggle_squared();
+ ct_reload_all(0);
+
+ return true;
+}
diff --git a/commands.h b/commands.h
index 76b1330..5460121 100644
--- a/commands.h
+++ b/commands.h
@@ -45,6 +45,7 @@ bool ct_reload_all(arg_t);
bool ct_scroll(arg_t);
bool ct_drag_mark_image(arg_t);
bool ct_select(arg_t);
+bool ct_toggle_squared(arg_t);
#ifdef INCLUDE_MAPPINGS_CONFIG
/* global */
@@ -92,6 +93,7 @@ bool ct_select(arg_t);
#define t_scroll { ct_scroll, MODE_THUMB }
#define t_drag_mark_image { ct_drag_mark_image, MODE_THUMB }
#define t_select { ct_select, MODE_THUMB }
+#define t_toggle_squared { ct_toggle_squared, MODE_THUMB }
#endif /* _MAPPINGS_CONFIG */
#endif /* COMMANDS_H */
diff --git a/config.def.h b/config.def.h
index a0935f6..93724bc 100644
--- a/config.def.h
+++ b/config.def.h
@@ -79,6 +79,10 @@ static const int thumb_sizes[] = { 32, 64, 96, 128, 160 };
/* thumbnail size at startup, index into thumb_sizes[]: */
static const int THUMB_SIZE = 3;
+/* whether to show thumbnails in squares or respect their aspect ratio,
+ * toggleable with t_toggle_squared 's' keybinding in thumbnail mode */
+static bool SQUARE_THUMBS = false;
+
#endif
#ifdef INCLUDE_MAPPINGS_CONFIG
@@ -135,6 +139,7 @@ static const keymap_t keys[] = {
{ 0, XK_l, t_move_sel, DIR_RIGHT },
{ 0, XK_Right, t_move_sel, DIR_RIGHT },
{ 0, XK_R, t_reload_all, None },
+ { 0, XK_s, t_toggle_squared, None },
{ 0, XK_n, i_navigate, +1 },
{ 0, XK_n, i_scroll_to_edge, DIR_LEFT | DIR_UP },
diff --git a/nsxiv.h b/nsxiv.h
index 8011f9e..f1e6981 100644
--- a/nsxiv.h
+++ b/nsxiv.h
@@ -310,6 +310,7 @@ bool tns_move_selection(tns_t*, direction_t, int);
bool tns_scroll(tns_t*, direction_t, bool);
bool tns_zoom(tns_t*, int);
int tns_translate(tns_t*, int, int);
+bool tns_toggle_squared(void);
/* util.c */
diff --git a/thumbs.c b/thumbs.c
index b5da098..0cbd815 100644
--- a/thumbs.c
+++ b/thumbs.c
@@ -196,23 +196,37 @@ CLEANUP void tns_free(tns_t *tns)
static Imlib_Image tns_scale_down(Imlib_Image im, int dim)
{
int w, h;
- float z, zw, zh;
imlib_context_set_image(im);
w = imlib_image_get_width();
h = imlib_image_get_height();
- zw = (float) dim / (float) w;
- zh = (float) dim / (float) h;
- z = MIN(zw, zh);
- z = MIN(z, 1.0);
-
- if (z < 1.0) {
- imlib_context_set_anti_alias(1);
- im = imlib_create_cropped_scaled_image(0, 0, w, h,
- MAX(z * w, 1), MAX(z * h, 1));
- if (im == NULL)
- error(EXIT_FAILURE, ENOMEM, NULL);
- imlib_free_image_and_decache();
+
+ if (SQUARE_THUMBS == false) { /* normal thumbs */
+ float z, zw, zh;
+ zw = (float) dim / (float) w;
+ zh = (float) dim / (float) h;
+ z = MIN(zw, zh);
+ z = MIN(z, 1.0);
+
+ if (z < 1.0) {
+ imlib_context_set_anti_alias(1);
+ im = imlib_create_cropped_scaled_image(0, 0, w, h,
+ MAX(z * w, 1), MAX(z * h, 1));
+ if (im == NULL)
+ error(EXIT_FAILURE, ENOMEM, NULL);
+ imlib_free_image_and_decache();
+ }
+ } else { /* generate square thumbs */
+ int x = (w < h) ? 0 : (w - h) / 2;
+ int y = (w > h) ? 0 : (h - w) / 2;
+ int s = (w < h) ? w : h;
+ if (dim < w || dim < h) {
+ imlib_context_set_anti_alias(1);
+ im = imlib_create_cropped_scaled_image(x, y, s, s, dim, dim);
+ if (im == NULL)
+ error(EXIT_FAILURE, ENOMEM, NULL);
+ imlib_free_image_and_decache();
+ }
}
return im;
}
@@ -585,3 +599,9 @@ int tns_translate(tns_t *tns, int x, int y)
return n;
}
+
+bool tns_toggle_squared(void)
+{
+ SQUARE_THUMBS = !SQUARE_THUMBS;
+ return true;
+}
--
2.39.1