Krolyxon
Commit 43fcd2e

Branches

Refs →

nsxivnsxiv.h

448 lines · 7.7 KB · Objective-C

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