Krolyxon
Commit 12efa0e

Branches

Refs →

nsxivnsxiv.h

451 lines · 7.6 KB · Objective-C

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