Krolyxon
Commit 1480260

Branches

Refs →

nsxiv1480260

One header file for type definitions and function declarations

Author
Bert Münnich
Date
2017-10-16 21:10 +0200
Parent
4af189e
Commit
148026007cae3b97d39d2cfee7562c139eb486b2

+483 −687

18 files changed

  1. D autoreload.h +0 −36
  2. M autoreload_inotify.c +2 −3
  3. M autoreload_nop.c +1 −1
  4. M commands.c +4 −9
  5. D commands.h +0 −59
  6. M image.c +4 −7
  7. D image.h +0 −98
  8. M main.c +4 −15
  9. M options.c +6 −9
  10. D options.h +0 −63
  11. A sxiv.h +451 −0
  12. M thumbs.c +4 −8
  13. D thumbs.h +0 −77
  14. D types.h +0 −100
  15. M util.c +2 −3
  16. D util.h +0 −80
  17. M window.c +5 −8
  18. D window.h +0 −111
D autoreload.h View
@@ -1,36 +0,0 @@
1−/* Copyright 2017 Max Voit
2− *
3− * This file is part of sxiv.
4− *
5− * sxiv is free software; you can redistribute it and/or modify
6− * it under the terms of the GNU General Public License as published
7− * by the Free Software Foundation; either version 2 of the License,
8− * or (at your option) any later version.
9− *
10− * sxiv is distributed in the hope that it will be useful,
11− * but WITHOUT ANY WARRANTY; without even the implied warranty of
12− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13− * GNU General Public License for more details.
14− *
15− * You should have received a copy of the GNU General Public License
16− * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
17− */
18−
19−#ifndef AUTORELOAD_H
20−#define AUTORELOAD_H
21−
22−#include "types.h"
23−
24−typedef struct {
25− int fd;
26− int wd_dir;
27− int wd_file;
28− char *filename;
29−} arl_t;
30−
31−void arl_init(arl_t*);
32−void arl_cleanup(arl_t*);
33−void arl_setup(arl_t*, const char* /* result of realpath(3) */);
34−bool arl_handle(arl_t*);
35−
36−#endif /* AUTORELOAD_H */
M autoreload_inotify.c View
@@ -16,15 +16,14 @@
1616 * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
1717 */
1818
19+#include "sxiv.h"
20+
1921 #include <errno.h>
2022 #include <stdlib.h>
2123 #include <string.h>
2224 #include <unistd.h>
2325 #include <sys/inotify.h>
2426
25−#include "util.h"
26−#include "autoreload.h"
27−
2827 void arl_init(arl_t *arl)
2928 {
3029 arl->fd = inotify_init1(IN_CLOEXEC | IN_NONBLOCK);
M autoreload_nop.c View
@@ -16,7 +16,7 @@
1616 * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
1717 */
1818
19−#include "autoreload.h"
19+#include "sxiv.h"
2020
2121 void arl_init(arl_t *arl)
2222 {
M commands.c View
@@ -16,20 +16,15 @@
1616 * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
1717 */
1818
19+#include "sxiv.h"
20+#define _IMAGE_CONFIG
21+#include "config.h"
22+
1923 #include <stdlib.h>
2024 #include <string.h>
2125 #include <unistd.h>
2226 #include <sys/wait.h>
2327
24−#include "commands.h"
25−#include "image.h"
26−#include "options.h"
27−#include "thumbs.h"
28−#include "util.h"
29−
30−#define _IMAGE_CONFIG
31−#include "config.h"
32−
3328 void remove_file(int, bool);
3429 void load_image(int);
3530 void open_info(void);
D commands.h View
@@ -1,59 +0,0 @@
1−/* Copyright 2011, 2014 Bert Muennich
2− *
3− * This file is part of sxiv.
4− *
5− * sxiv is free software; you can redistribute it and/or modify
6− * it under the terms of the GNU General Public License as published
7− * by the Free Software Foundation; either version 2 of the License,
8− * or (at your option) any later version.
9− *
10− * sxiv is distributed in the hope that it will be useful,
11− * but WITHOUT ANY WARRANTY; without even the implied warranty of
12− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13− * GNU General Public License for more details.
14− *
15− * You should have received a copy of the GNU General Public License
16− * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
17− */
18−
19−#ifndef COMMANDS_H
20−#define COMMANDS_H
21−
22−#include <X11/Xlib.h>
23−
24−#include "types.h"
25−
26−typedef int arg_t;
27−typedef bool (*cmd_f)(arg_t);
28−
29−#define G_CMD(c) g_##c,
30−#define I_CMD(c) i_##c,
31−#define T_CMD(c) t_##c,
32−
33−typedef enum {
34−#include "commands.lst"
35− CMD_COUNT
36−} cmd_id_t;
37−
38−typedef struct {
39− int mode;
40− cmd_f func;
41−} cmd_t;
42−
43−typedef struct {
44− unsigned int mask;
45− KeySym ksym;
46− cmd_id_t cmd;
47− arg_t arg;
48−} keymap_t;
49−
50−typedef struct {
51− unsigned int mask;
52− unsigned int button;
53− cmd_id_t cmd;
54− arg_t arg;
55−} button_t;
56−
57−const extern cmd_t cmds[CMD_COUNT];
58−
59−#endif /* COMMANDS_H */
M image.c View
@@ -16,6 +16,10 @@
1616 * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
1717 */
1818
19+#include "sxiv.h"
20+#define _IMAGE_CONFIG
21+#include "config.h"
22+
1923 #include <errno.h>
2024 #include <stdlib.h>
2125 #include <string.h>
@@ -23,13 +27,6 @@
2327 #include <sys/types.h>
2428 #include <unistd.h>
2529
26−#include "image.h"
27−#include "options.h"
28−#include "util.h"
29−
30−#define _IMAGE_CONFIG
31−#include "config.h"
32−
3330 #if HAVE_LIBEXIF
3431 #include <libexif/exif-data.h>
3532 #endif
D image.h View
@@ -1,98 +0,0 @@
1−/* Copyright 2011 Bert Muennich
2− *
3− * This file is part of sxiv.
4− *
5− * sxiv is free software; you can redistribute it and/or modify
6− * it under the terms of the GNU General Public License as published
7− * by the Free Software Foundation; either version 2 of the License,
8− * or (at your option) any later version.
9− *
10− * sxiv is distributed in the hope that it will be useful,
11− * but WITHOUT ANY WARRANTY; without even the implied warranty of
12− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13− * GNU General Public License for more details.
14− *
15− * You should have received a copy of the GNU General Public License
16− * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
17− */
18−
19−#ifndef IMAGE_H
20−#define IMAGE_H
21−
22−#include <Imlib2.h>
23−
24−#include "types.h"
25−#include "window.h"
26−
27−typedef struct {
28− Imlib_Image im;
29− unsigned int delay;
30−} img_frame_t;
31−
32−typedef struct {
33− img_frame_t *frames;
34− int cap;
35− int cnt;
36− int sel;
37− bool animate;
38− int framedelay;
39− int length;
40−} multi_img_t;
41−
42−typedef struct {
43− Imlib_Image im;
44− int w;
45− int h;
46−
47− win_t *win;
48− float x;
49− float y;
50−
51− scalemode_t scalemode;
52− float zoom;
53−
54− bool checkpan;
55− bool dirty;
56− bool aa;
57− bool alpha;
58−
59− Imlib_Color_Modifier cmod;
60− int gamma;
61−
62− struct {
63− bool on;
64− int delay;
65− } ss;
66−
67− multi_img_t multi;
68−} img_t;
69−
70−void img_init(img_t*, win_t*);
71−
72−bool img_load(img_t*, const fileinfo_t*);
73−CLEANUP void img_close(img_t*, bool);
74−
75−void img_render(img_t*);
76−
77−bool img_fit_win(img_t*, scalemode_t);
78−
79−bool img_zoom(img_t*, float);
80−bool img_zoom_in(img_t*);
81−bool img_zoom_out(img_t*);
82−
83−bool img_pos(img_t*, float, float);
84−bool img_move(img_t*, float, float);
85−bool img_pan(img_t*, direction_t, int);
86−bool img_pan_edge(img_t*, direction_t);
87−
88−void img_rotate(img_t*, degree_t);
89−void img_flip(img_t*, flipdir_t);
90−
91−void img_toggle_antialias(img_t*);
92−
93−bool img_change_gamma(img_t*, int);
94−
95−bool img_frame_navigate(img_t*, int);
96−bool img_frame_animate(img_t*);
97−
98−#endif /* IMAGE_H */
M main.c View
@@ -16,9 +16,11 @@
1616 * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
1717 */
1818
19+#include "sxiv.h"
20+#define _MAPPINGS_CONFIG
21+#include "config.h"
22+
1923 #include <stdlib.h>
20−#include <stdio.h>
21−#include <stdarg.h>
2224 #include <string.h>
2325 #include <fcntl.h>
2426 #include <unistd.h>
@@ -26,24 +28,11 @@
2628 #include <signal.h>
2729 #include <sys/select.h>
2830 #include <sys/stat.h>
29−#include <sys/time.h>
3031 #include <sys/wait.h>
3132 #include <time.h>
3233 #include <X11/keysym.h>
3334 #include <X11/XF86keysym.h>
3435
35−#include "types.h"
36−#include "commands.h"
37−#include "image.h"
38−#include "options.h"
39−#include "thumbs.h"
40−#include "util.h"
41−#include "window.h"
42−#include "autoreload.h"
43−
44−#define _MAPPINGS_CONFIG
45−#include "config.h"
46−
4736 typedef struct {
4837 struct timeval when;
4938 bool active;
M options.c View
@@ -16,19 +16,16 @@
1616 * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
1717 */
1818
19+#include "sxiv.h"
20+#define _IMAGE_CONFIG
21+#include "config.h"
22+
1923 #include <stdlib.h>
2024 #include <string.h>
21−#include <stdio.h>
2225 #include <unistd.h>
2326
24−#include "options.h"
25−#include "util.h"
26−
27−#define _IMAGE_CONFIG
28−#include "config.h"
29−
30−options_t _options;
31−const options_t *options = (const options_t*) &_options;
27+opt_t _options;
28+const opt_t *options = (const opt_t*) &_options;
3229
3330 void print_usage(void)
3431 {
D options.h View
@@ -1,63 +0,0 @@
1−/* Copyright 2011 Bert Muennich
2− *
3− * This file is part of sxiv.
4− *
5− * sxiv is free software; you can redistribute it and/or modify
6− * it under the terms of the GNU General Public License as published
7− * by the Free Software Foundation; either version 2 of the License,
8− * or (at your option) any later version.
9− *
10− * sxiv is distributed in the hope that it will be useful,
11− * but WITHOUT ANY WARRANTY; without even the implied warranty of
12− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13− * GNU General Public License for more details.
14− *
15− * You should have received a copy of the GNU General Public License
16− * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
17− */
18−
19−#ifndef OPTIONS_H
20−#define OPTIONS_H
21−
22−#include "types.h"
23−#include "image.h"
24−
25−typedef struct {
26− /* file list: */
27− char **filenames;
28− bool from_stdin;
29− bool to_stdout;
30− bool recursive;
31− int filecnt;
32− int startnum;
33−
34− /* image: */
35− scalemode_t scalemode;
36− float zoom;
37− bool animate;
38− int gamma;
39− int slideshow;
40− int framerate;
41−
42− /* window: */
43− bool fullscreen;
44− bool hide_bar;
45− long embed;
46− char *geometry;
47− char *res_name;
48−
49− /* misc flags: */
50− bool quiet;
51− bool thumb_mode;
52− bool clean_cache;
53− bool private_mode;
54−} options_t;
55−
56−extern const options_t *options;
57−
58−void print_usage(void);
59−void print_version(void);
60−
61−void parse_options(int, char**);
62−
63−#endif /* OPTIONS_H */
A sxiv.h View
@@ -0,0 +1,451 @@
1+/* Copyright 2011 Bert Muennich
2+ *
3+ * This file is part of sxiv.
4+ *
5+ * sxiv is free software; you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published
7+ * by the Free Software Foundation; either version 2 of the License,
8+ * or (at your option) any later version.
9+ *
10+ * sxiv is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU General Public License
16+ * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
17+ */
18+
19+#ifndef SXIV_H
20+#define SXIV_H
21+
22+#include <stdarg.h>
23+#include <stdbool.h>
24+#include <stdio.h>
25+#include <sys/time.h>
26+#include <sys/types.h>
27+#include <Imlib2.h>
28+#include <X11/Xlib.h>
29+
30+/*
31+ * Annotation for functions called in cleanup().
32+ * These functions are not allowed to call error(!0, ...) or exit().
33+ */
34+#define CLEANUP
35+
36+#ifndef MIN
37+#define MIN(a,b) ((a) < (b) ? (a) : (b))
38+#endif
39+#ifndef MAX
40+#define MAX(a,b) ((a) > (b) ? (a) : (b))
41+#endif
42+
43+#define ARRLEN(a) (sizeof(a) / sizeof((a)[0]))
44+
45+#define STREQ(s1,s2) (strcmp((s1), (s2)) == 0)
46+
47+#define TV_DIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec ) * 1000 + \
48+ ((t1)->tv_usec - (t2)->tv_usec) / 1000)
49+
50+#define TV_SET_MSEC(tv,t) { \
51+ (tv)->tv_sec = (t) / 1000; \
52+ (tv)->tv_usec = (t) % 1000 * 1000; \
53+}
54+
55+#define TV_ADD_MSEC(tv,t) { \
56+ (tv)->tv_sec += (t) / 1000; \
57+ (tv)->tv_usec += (t) % 1000 * 1000; \
58+}
59+
60+typedef enum {
61+ BO_BIG_ENDIAN,
62+ BO_LITTLE_ENDIAN
63+} byteorder_t;
64+
65+typedef enum {
66+ MODE_IMAGE,
67+ MODE_THUMB
68+} appmode_t;
69+
70+typedef enum {
71+ DIR_LEFT = 1,
72+ DIR_RIGHT = 2,
73+ DIR_UP = 4,
74+ DIR_DOWN = 8
75+} direction_t;
76+
77+typedef enum {
78+ DEGREE_90 = 1,
79+ DEGREE_180 = 2,
80+ DEGREE_270 = 3
81+} degree_t;
82+
83+typedef enum {
84+ FLIP_HORIZONTAL = 1,
85+ FLIP_VERTICAL = 2
86+} flipdir_t;
87+
88+typedef enum {
89+ SCALE_DOWN,
90+ SCALE_FIT,
91+ SCALE_WIDTH,
92+ SCALE_HEIGHT,
93+ SCALE_ZOOM
94+} scalemode_t;
95+
96+typedef enum {
97+ CURSOR_ARROW,
98+ CURSOR_DRAG,
99+ CURSOR_WATCH,
100+ CURSOR_LEFT,
101+ CURSOR_RIGHT,
102+ CURSOR_NONE,
103+
104+ CURSOR_COUNT
105+} cursor_t;
106+
107+typedef enum {
108+ FF_WARN = 1,
109+ FF_MARK = 2,
110+ FF_TN_INIT = 4
111+} fileflags_t;
112+
113+typedef struct {
114+ const char *name; /* as given by user */
115+ const char *path; /* always absolute */
116+ const char *base;
117+ fileflags_t flags;
118+} fileinfo_t;
119+
120+/* timeouts in milliseconds: */
121+enum {
122+ TO_REDRAW_RESIZE = 75,
123+ TO_REDRAW_THUMBS = 200,
124+ TO_CURSOR_HIDE = 1200,
125+ TO_DOUBLE_CLICK = 300
126+};
127+
128+typedef void (*timeout_f)(void);
129+
130+typedef struct arl arl_t;
131+typedef struct img img_t;
132+typedef struct opt opt_t;
133+typedef struct tns tns_t;
134+typedef struct win win_t;
135+
136+
137+/* autoreload.c */
138+
139+struct arl {
140+ int fd;
141+ int wd_dir;
142+ int wd_file;
143+ char *filename;
144+};
145+
146+void arl_init(arl_t*);
147+void arl_cleanup(arl_t*);
148+void arl_setup(arl_t*, const char* /* result of realpath(3) */);
149+bool arl_handle(arl_t*);
150+
151+
152+/* commands.c */
153+
154+typedef int arg_t;
155+typedef bool (*cmd_f)(arg_t);
156+
157+#define G_CMD(c) g_##c,
158+#define I_CMD(c) i_##c,
159+#define T_CMD(c) t_##c,
160+
161+typedef enum {
162+#include "commands.lst"
163+ CMD_COUNT
164+} cmd_id_t;
165+
166+typedef struct {
167+ int mode;
168+ cmd_f func;
169+} cmd_t;
170+
171+typedef struct {
172+ unsigned int mask;
173+ KeySym ksym;
174+ cmd_id_t cmd;
175+ arg_t arg;
176+} keymap_t;
177+
178+typedef struct {
179+ unsigned int mask;
180+ unsigned int button;
181+ cmd_id_t cmd;
182+ arg_t arg;
183+} button_t;
184+
185+extern const cmd_t cmds[CMD_COUNT];
186+
187+
188+/* image.c */
189+
190+typedef struct {
191+ Imlib_Image im;
192+ unsigned int delay;
193+} img_frame_t;
194+
195+typedef struct {
196+ img_frame_t *frames;
197+ int cap;
198+ int cnt;
199+ int sel;
200+ bool animate;
201+ int framedelay;
202+ int length;
203+} multi_img_t;
204+
205+struct img {
206+ Imlib_Image im;
207+ int w;
208+ int h;
209+
210+ win_t *win;
211+ float x;
212+ float y;
213+
214+ scalemode_t scalemode;
215+ float zoom;
216+
217+ bool checkpan;
218+ bool dirty;
219+ bool aa;
220+ bool alpha;
221+
222+ Imlib_Color_Modifier cmod;
223+ int gamma;
224+
225+ struct {
226+ bool on;
227+ int delay;
228+ } ss;
229+
230+ multi_img_t multi;
231+};
232+
233+void img_init(img_t*, win_t*);
234+bool img_load(img_t*, const fileinfo_t*);
235+CLEANUP void img_close(img_t*, bool);
236+void img_render(img_t*);
237+bool img_fit_win(img_t*, scalemode_t);
238+bool img_zoom(img_t*, float);
239+bool img_zoom_in(img_t*);
240+bool img_zoom_out(img_t*);
241+bool img_pos(img_t*, float, float);
242+bool img_move(img_t*, float, float);
243+bool img_pan(img_t*, direction_t, int);
244+bool img_pan_edge(img_t*, direction_t);
245+void img_rotate(img_t*, degree_t);
246+void img_flip(img_t*, flipdir_t);
247+void img_toggle_antialias(img_t*);
248+bool img_change_gamma(img_t*, int);
249+bool img_frame_navigate(img_t*, int);
250+bool img_frame_animate(img_t*);
251+
252+
253+/* options.c */
254+
255+struct opt {
256+ /* file list: */
257+ char **filenames;
258+ bool from_stdin;
259+ bool to_stdout;
260+ bool recursive;
261+ int filecnt;
262+ int startnum;
263+
264+ /* image: */
265+ scalemode_t scalemode;
266+ float zoom;
267+ bool animate;
268+ int gamma;
269+ int slideshow;
270+ int framerate;
271+
272+ /* window: */
273+ bool fullscreen;
274+ bool hide_bar;
275+ long embed;
276+ char *geometry;
277+ char *res_name;
278+
279+ /* misc flags: */
280+ bool quiet;
281+ bool thumb_mode;
282+ bool clean_cache;
283+ bool private_mode;
284+};
285+
286+extern const opt_t *options;
287+
288+void print_usage(void);
289+void print_version(void);
290+void parse_options(int, char**);
291+
292+
293+/* thumbs.c */
294+
295+typedef struct {
296+ Imlib_Image im;
297+ int w;
298+ int h;
299+ int x;
300+ int y;
301+} thumb_t;
302+
303+struct tns {
304+ fileinfo_t *files;
305+ thumb_t *thumbs;
306+ const int *cnt;
307+ int *sel;
308+ int initnext;
309+ int loadnext;
310+ int first, end;
311+ int r_first, r_end;
312+
313+ win_t *win;
314+ int x;
315+ int y;
316+ int cols;
317+ int rows;
318+ int zl;
319+ int bw;
320+ int dim;
321+
322+ bool dirty;
323+};
324+
325+void tns_clean_cache(tns_t*);
326+void tns_init(tns_t*, fileinfo_t*, const int*, int*, win_t*);
327+CLEANUP void tns_free(tns_t*);
328+bool tns_load(tns_t*, int, bool, bool);
329+void tns_unload(tns_t*, int);
330+void tns_render(tns_t*);
331+void tns_mark(tns_t*, int, bool);
332+void tns_highlight(tns_t*, int, bool);
333+bool tns_move_selection(tns_t*, direction_t, int);
334+bool tns_scroll(tns_t*, direction_t, bool);
335+bool tns_zoom(tns_t*, int);
336+int tns_translate(tns_t*, int, int);
337+
338+
339+/* util.c */
340+
341+#include <dirent.h>
342+
343+typedef struct {
344+ DIR *dir;
345+ char *name;
346+ int d;
347+ bool recursive;
348+
349+ char **stack;
350+ int stcap;
351+ int stlen;
352+} r_dir_t;
353+
354+extern const char *progname;
355+
356+void* emalloc(size_t);
357+void* erealloc(void*, size_t);
358+char* estrdup(const char*);
359+void error(int, int, const char*, ...);
360+void size_readable(float*, const char**);
361+int r_opendir(r_dir_t*, const char*, bool);
362+int r_closedir(r_dir_t*);
363+char* r_readdir(r_dir_t*);
364+int r_mkdir(char*);
365+
366+
367+/* window.c */
368+
369+#include <X11/Xutil.h>
370+#include <X11/Xft/Xft.h>
371+
372+enum {
373+ BAR_L_LEN = 512,
374+ BAR_R_LEN = 64
375+};
376+
377+enum {
378+ ATOM_WM_DELETE_WINDOW,
379+ ATOM__NET_WM_NAME,
380+ ATOM__NET_WM_ICON_NAME,
381+ ATOM__NET_WM_ICON,
382+ ATOM__NET_WM_STATE,
383+ ATOM__NET_WM_STATE_FULLSCREEN,
384+ ATOM__NET_SUPPORTED,
385+ ATOM_COUNT
386+};
387+
388+typedef struct {
389+ Display *dpy;
390+ int scr;
391+ int scrw, scrh;
392+ Visual *vis;
393+ Colormap cmap;
394+ int depth;
395+} win_env_t;
396+
397+typedef struct {
398+ size_t size;
399+ char *p;
400+ char *buf;
401+} win_bar_t;
402+
403+struct win {
404+ Window xwin;
405+ win_env_t env;
406+
407+ XftColor bgcol;
408+ XftColor fscol;
409+ XftColor selcol;
410+
411+ int x;
412+ int y;
413+ unsigned int w;
414+ unsigned int h; /* = win height - bar height */
415+ unsigned int bw;
416+
417+ bool fullscreen;
418+
419+ struct {
420+ int w;
421+ int h;
422+ Pixmap pm;
423+ } buf;
424+
425+ struct {
426+ unsigned int h;
427+ win_bar_t l;
428+ win_bar_t r;
429+ XftColor bgcol;
430+ XftColor fgcol;
431+ } bar;
432+};
433+
434+extern Atom atoms[ATOM_COUNT];
435+
436+void win_init(win_t*);
437+void win_open(win_t*);
438+CLEANUP void win_close(win_t*);
439+bool win_configure(win_t*, XConfigureEvent*);
440+void win_toggle_fullscreen(win_t*);
441+void win_toggle_bar(win_t*);
442+void win_clear(win_t*);
443+void win_draw(win_t*);
444+void win_draw_rect(win_t*, int, int, int, int, bool, int, unsigned long);
445+int win_textwidth(const win_env_t*, const char*, unsigned int, bool);
446+void win_set_title(win_t*, const char*);
447+void win_set_cursor(win_t*, cursor_t);
448+void win_cursor_pos(win_t*, int*, int*);
449+
450+#endif /* SXIV_H */
451+
M thumbs.c View
@@ -16,8 +16,11 @@
1616 * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
1717 */
1818
19+#include "sxiv.h"
20+#define _THUMBS_CONFIG
21+#include "config.h"
22+
1923 #include <errno.h>
20−#include <stdio.h>
2124 #include <stdlib.h>
2225 #include <string.h>
2326 #include <sys/types.h>
@@ -25,13 +28,6 @@
2528 #include <unistd.h>
2629 #include <utime.h>
2730
28−#include "options.h"
29−#include "thumbs.h"
30−#include "util.h"
31−
32−#define _THUMBS_CONFIG
33−#include "config.h"
34−
3531 #if HAVE_LIBEXIF
3632 #include <libexif/exif-data.h>
3733 void exif_auto_orientate(const fileinfo_t*);
D thumbs.h View
@@ -1,77 +0,0 @@
1−/* Copyright 2011 Bert Muennich
2− *
3− * This file is part of sxiv.
4− *
5− * sxiv is free software; you can redistribute it and/or modify
6− * it under the terms of the GNU General Public License as published
7− * by the Free Software Foundation; either version 2 of the License,
8− * or (at your option) any later version.
9− *
10− * sxiv is distributed in the hope that it will be useful,
11− * but WITHOUT ANY WARRANTY; without even the implied warranty of
12− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13− * GNU General Public License for more details.
14− *
15− * You should have received a copy of the GNU General Public License
16− * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
17− */
18−
19−#ifndef THUMBS_H
20−#define THUMBS_H
21−
22−#include <X11/Xlib.h>
23−#include <Imlib2.h>
24−
25−#include "types.h"
26−#include "window.h"
27−
28−typedef struct {
29− Imlib_Image im;
30− int w;
31− int h;
32− int x;
33− int y;
34−} thumb_t;
35−
36−typedef struct {
37− fileinfo_t *files;
38− thumb_t *thumbs;
39− const int *cnt;
40− int *sel;
41− int initnext;
42− int loadnext;
43− int first, end;
44− int r_first, r_end;
45−
46− win_t *win;
47− int x;
48− int y;
49− int cols;
50− int rows;
51− int zl;
52− int bw;
53− int dim;
54−
55− bool dirty;
56−} tns_t;
57−
58−void tns_clean_cache(tns_t*);
59−
60−void tns_init(tns_t*, fileinfo_t*, const int*, int*, win_t*);
61−CLEANUP void tns_free(tns_t*);
62−
63−bool tns_load(tns_t*, int, bool, bool);
64−void tns_unload(tns_t*, int);
65−
66−void tns_render(tns_t*);
67−void tns_mark(tns_t*, int, bool);
68−void tns_highlight(tns_t*, int, bool);
69−
70−bool tns_move_selection(tns_t*, direction_t, int);
71−bool tns_scroll(tns_t*, direction_t, bool);
72−
73−bool tns_zoom(tns_t*, int);
74−
75−int tns_translate(tns_t*, int, int);
76−
77−#endif /* THUMBS_H */
D types.h View
@@ -1,100 +0,0 @@
1−/* Copyright 2011 Bert Muennich
2− *
3− * This file is part of sxiv.
4− *
5− * sxiv is free software; you can redistribute it and/or modify
6− * it under the terms of the GNU General Public License as published
7− * by the Free Software Foundation; either version 2 of the License,
8− * or (at your option) any later version.
9− *
10− * sxiv is distributed in the hope that it will be useful,
11− * but WITHOUT ANY WARRANTY; without even the implied warranty of
12− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13− * GNU General Public License for more details.
14− *
15− * You should have received a copy of the GNU General Public License
16− * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
17− */
18−
19−#ifndef TYPES_H
20−#define TYPES_H
21−
22−#include <stdbool.h>
23−
24−/*
25− * Annotation for functions called in cleanup().
26− * These functions are not allowed to call error(!0, ...) or exit().
27− */
28−#define CLEANUP
29−
30−typedef enum {
31− BO_BIG_ENDIAN,
32− BO_LITTLE_ENDIAN
33−} byteorder_t;
34−
35−typedef enum {
36− MODE_IMAGE,
37− MODE_THUMB
38−} appmode_t;
39−
40−typedef enum {
41− DIR_LEFT = 1,
42− DIR_RIGHT = 2,
43− DIR_UP = 4,
44− DIR_DOWN = 8
45−} direction_t;
46−
47−typedef enum {
48− DEGREE_90 = 1,
49− DEGREE_180 = 2,
50− DEGREE_270 = 3
51−} degree_t;
52−
53−typedef enum {
54− FLIP_HORIZONTAL = 1,
55− FLIP_VERTICAL = 2
56−} flipdir_t;
57−
58−typedef enum {
59− SCALE_DOWN,
60− SCALE_FIT,
61− SCALE_WIDTH,
62− SCALE_HEIGHT,
63− SCALE_ZOOM
64−} scalemode_t;
65−
66−typedef enum {
67− CURSOR_ARROW,
68− CURSOR_DRAG,
69− CURSOR_WATCH,
70− CURSOR_LEFT,
71− CURSOR_RIGHT,
72− CURSOR_NONE,
73−
74− CURSOR_COUNT
75−} cursor_t;
76−
77−typedef enum {
78− FF_WARN = 1,
79− FF_MARK = 2,
80− FF_TN_INIT = 4
81−} fileflags_t;
82−
83−typedef struct {
84− const char *name; /* as given by user */
85− const char *path; /* always absolute */
86− const char *base;
87− fileflags_t flags;
88−} fileinfo_t;
89−
90−/* timeouts in milliseconds: */
91−enum {
92− TO_REDRAW_RESIZE = 75,
93− TO_REDRAW_THUMBS = 200,
94− TO_CURSOR_HIDE = 1200,
95− TO_DOUBLE_CLICK = 300
96−};
97−
98−typedef void (*timeout_f)(void);
99−
100−#endif /* TYPES_H */
M util.c View
@@ -16,6 +16,8 @@
1616 * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
1717 */
1818
19+#include "sxiv.h"
20+
1921 #include <stdlib.h>
2022 #include <string.h>
2123 #include <sys/types.h>
@@ -23,9 +25,6 @@
2325 #include <unistd.h>
2426 #include <errno.h>
2527
26−#include "options.h"
27−#include "util.h"
28−
2928 const char *progname;
3029
3130 void* emalloc(size_t size)
D util.h View
@@ -1,80 +0,0 @@
1−/* Copyright 2011 Bert Muennich
2− *
3− * This file is part of sxiv.
4− *
5− * sxiv is free software; you can redistribute it and/or modify
6− * it under the terms of the GNU General Public License as published
7− * by the Free Software Foundation; either version 2 of the License,
8− * or (at your option) any later version.
9− *
10− * sxiv is distributed in the hope that it will be useful,
11− * but WITHOUT ANY WARRANTY; without even the implied warranty of
12− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13− * GNU General Public License for more details.
14− *
15− * You should have received a copy of the GNU General Public License
16− * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
17− */
18−
19−#ifndef UTIL_H
20−#define UTIL_H
21−
22−#include <stdio.h>
23−#include <stdarg.h>
24−#include <dirent.h>
25−#include <sys/time.h>
26−#include <sys/types.h>
27−
28−#include "types.h"
29−
30−#ifndef MIN
31−#define MIN(a,b) ((a) < (b) ? (a) : (b))
32−#endif
33−#ifndef MAX
34−#define MAX(a,b) ((a) > (b) ? (a) : (b))
35−#endif
36−
37−#define ARRLEN(a) (sizeof(a) / sizeof((a)[0]))
38−
39−#define STREQ(s1,s2) (strcmp((s1), (s2)) == 0)
40−
41−#define TV_DIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec ) * 1000 + \
42− ((t1)->tv_usec - (t2)->tv_usec) / 1000)
43−
44−#define TV_SET_MSEC(tv,t) { \
45− (tv)->tv_sec = (t) / 1000; \
46− (tv)->tv_usec = (t) % 1000 * 1000; \
47−}
48−
49−#define TV_ADD_MSEC(tv,t) { \
50− (tv)->tv_sec += (t) / 1000; \
51− (tv)->tv_usec += (t) % 1000 * 1000; \
52−}
53−
54−typedef struct {
55− DIR *dir;
56− char *name;
57− int d;
58− bool recursive;
59−
60− char **stack;
61− int stcap;
62− int stlen;
63−} r_dir_t;
64−
65−extern const char *progname;
66−
67−void* emalloc(size_t);
68−void* erealloc(void*, size_t);
69−char* estrdup(const char*);
70−
71−void error(int, int, const char*, ...);
72−
73−void size_readable(float*, const char**);
74−
75−int r_opendir(r_dir_t*, const char*, bool);
76−int r_closedir(r_dir_t*);
77−char* r_readdir(r_dir_t*);
78−int r_mkdir(char*);
79−
80−#endif /* UTIL_H */
M window.c View
@@ -16,20 +16,17 @@
1616 * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
1717 */
1818
19+#include "sxiv.h"
20+#define _WINDOW_CONFIG
21+#include "config.h"
22+#include "icon/data.h"
23+
1924 #include <stdlib.h>
2025 #include <string.h>
2126 #include <locale.h>
2227 #include <X11/cursorfont.h>
2328 #include <X11/Xatom.h>
2429
25−#include "options.h"
26−#include "util.h"
27−#include "window.h"
28−#include "icon/data.h"
29−
30−#define _WINDOW_CONFIG
31−#include "config.h"
32−
3330 enum {
3431 H_TEXT_PAD = 5,
3532 V_TEXT_PAD = 1
D window.h View
@@ -1,111 +0,0 @@
1−/* Copyright 2011 Bert Muennich
2− *
3− * This file is part of sxiv.
4− *
5− * sxiv is free software; you can redistribute it and/or modify
6− * it under the terms of the GNU General Public License as published
7− * by the Free Software Foundation; either version 2 of the License,
8− * or (at your option) any later version.
9− *
10− * sxiv is distributed in the hope that it will be useful,
11− * but WITHOUT ANY WARRANTY; without even the implied warranty of
12− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13− * GNU General Public License for more details.
14− *
15− * You should have received a copy of the GNU General Public License
16− * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
17− */
18−
19−#ifndef WINDOW_H
20−#define WINDOW_H
21−
22−#include <X11/Xlib.h>
23−#include <X11/Xutil.h>
24−#include <X11/Xft/Xft.h>
25−
26−#include "types.h"
27−
28−enum {
29− BAR_L_LEN = 512,
30− BAR_R_LEN = 64
31−};
32−
33−enum {
34− ATOM_WM_DELETE_WINDOW,
35− ATOM__NET_WM_NAME,
36− ATOM__NET_WM_ICON_NAME,
37− ATOM__NET_WM_ICON,
38− ATOM__NET_WM_STATE,
39− ATOM__NET_WM_STATE_FULLSCREEN,
40− ATOM__NET_SUPPORTED,
41− ATOM_COUNT
42−};
43−
44−typedef struct {
45− Display *dpy;
46− int scr;
47− int scrw, scrh;
48− Visual *vis;
49− Colormap cmap;
50− int depth;
51−} win_env_t;
52−
53−typedef struct {
54− size_t size;
55− char *p;
56− char *buf;
57−} win_bar_t;
58−
59−typedef struct {
60− Window xwin;
61− win_env_t env;
62−
63− XftColor bgcol;
64− XftColor fscol;
65− XftColor selcol;
66−
67− int x;
68− int y;
69− unsigned int w;
70− unsigned int h; /* = win height - bar height */
71− unsigned int bw;
72−
73− bool fullscreen;
74−
75− struct {
76− int w;
77− int h;
78− Pixmap pm;
79− } buf;
80−
81− struct {
82− unsigned int h;
83− win_bar_t l;
84− win_bar_t r;
85− XftColor bgcol;
86− XftColor fgcol;
87− } bar;
88−} win_t;
89−
90−extern Atom atoms[ATOM_COUNT];
91−
92−void win_init(win_t*);
93−void win_open(win_t*);
94−CLEANUP void win_close(win_t*);
95−
96−bool win_configure(win_t*, XConfigureEvent*);
97−
98−void win_toggle_fullscreen(win_t*);
99−void win_toggle_bar(win_t*);
100−
101−void win_clear(win_t*);
102−void win_draw(win_t*);
103−void win_draw_rect(win_t*, int, int, int, int, bool, int, unsigned long);
104−
105−int win_textwidth(const win_env_t*, const char*, unsigned int, bool);
106−
107−void win_set_title(win_t*, const char*);
108−void win_set_cursor(win_t*, cursor_t);
109−void win_cursor_pos(win_t*, int*, int*);
110−
111−#endif /* WINDOW_H */