Krolyxon
Commit 5775457

Branches

Refs →

nsxivnsxiv.h

452 lines · 7.7 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_ABSOLUTE,
103 CURSOR_DRAG_RELATIVE,
104 CURSOR_WATCH,
105 CURSOR_LEFT,
106 CURSOR_RIGHT,
107 CURSOR_NONE,
108
109 CURSOR_COUNT
110} cursor_t;
111
112typedef enum {
113 FF_WARN = 1,
114 FF_MARK = 2,
115 FF_TN_INIT = 4
116} fileflags_t;
117
118typedef enum {
119 SUFFIX_EMPTY,
120 SUFFIX_BASENAME,
121 SUFFIX_FULLPATH,
122} suffixmode_t;
123
124typedef struct {
125 const char *name; /* as given by user */
126 const char *path; /* always absolute */
127 fileflags_t flags;
128} fileinfo_t;
129
130/* timeouts in milliseconds: */
131enum {
132 TO_REDRAW_RESIZE = 75,
133 TO_REDRAW_THUMBS = 200,
134 TO_CURSOR_HIDE = 1200,
135 TO_DOUBLE_CLICK = 300
136};
137
138typedef void (*timeout_f)(void);
139
140typedef struct arl arl_t;
141typedef struct img img_t;
142typedef struct opt opt_t;
143typedef struct tns tns_t;
144typedef struct win win_t;
145
146
147/* autoreload.c */
148
149struct arl {
150 int fd;
151 int wd_dir;
152 int wd_file;
153 char *filename;
154};
155
156void arl_init(arl_t*);
157void arl_cleanup(arl_t*);
158void arl_setup(arl_t*, const char* /* result of realpath(3) */);
159bool arl_handle(arl_t*);
160
161
162/* commands.c */
163
164typedef int arg_t;
165typedef bool (*cmd_f)(arg_t);
166
167typedef struct {
168 cmd_f func;
169 appmode_t mode;
170} cmd_t;
171
172typedef struct {
173 unsigned int mask;
174 KeySym ksym;
175 cmd_t cmd;
176 arg_t arg;
177} keymap_t;
178
179typedef struct {
180 unsigned int mask;
181 unsigned int button;
182 cmd_t cmd;
183 arg_t arg;
184} button_t;
185
186
187/* image.c */
188
189typedef struct {
190 Imlib_Image im;
191 unsigned int delay;
192} img_frame_t;
193
194typedef struct {
195 img_frame_t *frames;
196 int cap;
197 int cnt;
198 int sel;
199 bool animate;
200 int framedelay;
201 int length;
202} multi_img_t;
203
204struct img {
205 Imlib_Image im;
206 int w;
207 int h;
208
209 win_t *win;
210 float x;
211 float y;
212
213 scalemode_t scalemode;
214 float zoom;
215
216 bool checkpan;
217 bool dirty;
218 bool aa;
219 bool alpha;
220
221 Imlib_Color_Modifier cmod;
222 int gamma;
223
224 struct {
225 bool on;
226 int delay;
227 } ss;
228
229 multi_img_t multi;
230};
231
232void img_init(img_t*, win_t*);
233bool img_load(img_t*, const fileinfo_t*);
234CLEANUP void img_close(img_t*, bool);
235void img_render(img_t*);
236bool img_fit_win(img_t*, scalemode_t);
237bool img_zoom(img_t*, int);
238bool img_zoom_to(img_t*, float);
239bool img_pos(img_t*, float, float);
240bool img_move(img_t*, float, float);
241bool img_pan(img_t*, direction_t, int);
242bool img_pan_edge(img_t*, direction_t);
243void img_rotate(img_t*, degree_t);
244void img_flip(img_t*, flipdir_t);
245void img_toggle_antialias(img_t*);
246bool img_change_gamma(img_t*, int);
247bool img_frame_navigate(img_t*, int);
248bool img_frame_animate(img_t*);
249
250
251/* options.c */
252
253struct opt {
254 /* file list: */
255 char **filenames;
256 bool from_stdin;
257 bool to_stdout;
258 char stdout_separator;
259 bool recursive;
260 int filecnt;
261 int startnum;
262
263 /* image: */
264 scalemode_t scalemode;
265 float zoom;
266 bool animate;
267 int gamma;
268 int slideshow;
269 int framerate;
270
271 /* window: */
272 bool fullscreen;
273 bool hide_bar;
274 long embed;
275 char *geometry;
276 char *res_name;
277 const char *title_prefix;
278 suffixmode_t title_suffixmode;
279
280 /* misc flags: */
281 bool quiet;
282 bool thumb_mode;
283 bool clean_cache;
284 bool private_mode;
285};
286
287extern const opt_t *options;
288
289void print_usage(void);
290void print_version(void);
291void parse_options(int, char**);
292
293
294/* thumbs.c */
295
296typedef struct {
297 Imlib_Image im;
298 int w;
299 int h;
300 int x;
301 int y;
302} thumb_t;
303
304struct tns {
305 fileinfo_t *files;
306 thumb_t *thumbs;
307 const int *cnt;
308 int *sel;
309 int initnext;
310 int loadnext;
311 int first, end;
312 int r_first, r_end;
313
314 win_t *win;
315 int x;
316 int y;
317 int cols;
318 int rows;
319 int zl;
320 int bw;
321 int dim;
322
323 bool dirty;
324};
325
326void tns_clean_cache(tns_t*);
327void tns_init(tns_t*, fileinfo_t*, const int*, int*, win_t*);
328CLEANUP void tns_free(tns_t*);
329bool tns_load(tns_t*, int, bool, bool);
330void tns_unload(tns_t*, int);
331void tns_render(tns_t*);
332void tns_mark(tns_t*, int, bool);
333void tns_highlight(tns_t*, int, bool);
334bool tns_move_selection(tns_t*, direction_t, int);
335bool tns_scroll(tns_t*, direction_t, bool);
336bool tns_zoom(tns_t*, int);
337int tns_translate(tns_t*, int, int);
338
339
340/* util.c */
341
342#include <dirent.h>
343
344typedef struct {
345 DIR *dir;
346 char *name;
347 int d;
348 bool recursive;
349
350 char **stack;
351 int stcap;
352 int stlen;
353} r_dir_t;
354
355extern const char *progname;
356
357void* emalloc(size_t);
358void* erealloc(void*, size_t);
359char* estrdup(const char*);
360void error(int, int, const char*, ...);
361void size_readable(float*, const char**);
362int r_opendir(r_dir_t*, const char*, bool);
363int r_closedir(r_dir_t*);
364char* r_readdir(r_dir_t*, bool);
365int r_mkdir(char*);
366
367
368/* window.c */
369
370#include <X11/Xutil.h>
371#if HAVE_LIBFONTS
372#include <X11/Xft/Xft.h>
373#endif
374
375enum {
376 BAR_L_LEN = 512,
377 BAR_R_LEN = 64
378};
379
380enum {
381 ATOM_WM_DELETE_WINDOW,
382 ATOM__NET_WM_NAME,
383 ATOM__NET_WM_ICON_NAME,
384 ATOM__NET_WM_ICON,
385 ATOM__NET_WM_STATE,
386 ATOM__NET_WM_PID,
387 ATOM__NET_WM_STATE_FULLSCREEN,
388 ATOM_COUNT
389};
390
391typedef struct {
392 Display *dpy;
393 int scr;
394 int scrw, scrh;
395 Visual *vis;
396 Colormap cmap;
397 int depth;
398} win_env_t;
399
400typedef struct {
401 size_t size;
402 char *p;
403 char *buf;
404} win_bar_t;
405
406struct win {
407 Window xwin;
408 win_env_t env;
409
410 XColor win_bg;
411 XColor win_fg;
412 XColor mrk_fg;
413#if HAVE_LIBFONTS
414 XftColor bar_bg;
415 XftColor bar_fg;
416#endif
417
418 int x;
419 int y;
420 unsigned int w;
421 unsigned int h; /* = win height - bar height */
422 unsigned int bw;
423
424 struct {
425 int w;
426 int h;
427 Pixmap pm;
428 } buf;
429
430 struct {
431 unsigned int h;
432 win_bar_t l;
433 win_bar_t r;
434 } bar;
435};
436
437extern Atom atoms[ATOM_COUNT];
438
439void win_init(win_t*);
440void win_open(win_t*);
441CLEANUP void win_close(win_t*);
442bool win_configure(win_t*, XConfigureEvent*);
443void win_toggle_fullscreen(win_t*);
444void win_toggle_bar(win_t*);
445void win_clear(win_t*);
446void win_draw(win_t*);
447void win_draw_rect(win_t*, int, int, int, int, bool, int, unsigned long);
448void win_set_title(win_t*, const char*);
449void win_set_cursor(win_t*, cursor_t);
450void win_cursor_pos(win_t*, int*, int*);
451
452#endif /* NSXIV_H */