Krolyxon
Commit 6d5a040

Branches

Refs →

nsxivnsxiv.h

462 lines · 8.0 KB · Objective-C

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