Krolyxon
Commit e63843d

Branches

Refs →

nsxivsxiv.h

449 lines · 7.5 KB · Objective-C

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
60typedef enum {
61 BO_BIG_ENDIAN,
62 BO_LITTLE_ENDIAN
63} byteorder_t;
64
65typedef enum {
66 MODE_IMAGE,
67 MODE_THUMB
68} appmode_t;
69
70typedef enum {
71 DIR_LEFT = 1,
72 DIR_RIGHT = 2,
73 DIR_UP = 4,
74 DIR_DOWN = 8
75} direction_t;
76
77typedef enum {
78 DEGREE_90 = 1,
79 DEGREE_180 = 2,
80 DEGREE_270 = 3
81} degree_t;
82
83typedef enum {
84 FLIP_HORIZONTAL = 1,
85 FLIP_VERTICAL = 2
86} flipdir_t;
87
88typedef enum {
89 SCALE_DOWN,
90 SCALE_FIT,
91 SCALE_WIDTH,
92 SCALE_HEIGHT,
93 SCALE_ZOOM
94} scalemode_t;
95
96typedef 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
107typedef enum {
108 FF_WARN = 1,
109 FF_MARK = 2,
110 FF_TN_INIT = 4
111} fileflags_t;
112
113typedef struct {
114 const char *name; /* as given by user */
115 const char *path; /* always absolute */
116 fileflags_t flags;
117} fileinfo_t;
118
119/* timeouts in milliseconds: */
120enum {
121 TO_REDRAW_RESIZE = 75,
122 TO_REDRAW_THUMBS = 200,
123 TO_CURSOR_HIDE = 1200,
124 TO_DOUBLE_CLICK = 300
125};
126
127typedef void (*timeout_f)(void);
128
129typedef struct arl arl_t;
130typedef struct img img_t;
131typedef struct opt opt_t;
132typedef struct tns tns_t;
133typedef struct win win_t;
134
135
136/* autoreload.c */
137
138struct arl {
139 int fd;
140 int wd_dir;
141 int wd_file;
142 char *filename;
143};
144
145void arl_init(arl_t*);
146void arl_cleanup(arl_t*);
147void arl_setup(arl_t*, const char* /* result of realpath(3) */);
148bool arl_handle(arl_t*);
149
150
151/* commands.c */
152
153typedef int arg_t;
154typedef bool (*cmd_f)(arg_t);
155
156#define G_CMD(c) g_##c,
157#define I_CMD(c) i_##c,
158#define T_CMD(c) t_##c,
159
160typedef enum {
161#include "commands.lst"
162 CMD_COUNT
163} cmd_id_t;
164
165typedef struct {
166 int mode;
167 cmd_f func;
168} cmd_t;
169
170typedef struct {
171 unsigned int mask;
172 KeySym ksym;
173 cmd_id_t cmd;
174 arg_t arg;
175} keymap_t;
176
177typedef struct {
178 unsigned int mask;
179 unsigned int button;
180 cmd_id_t cmd;
181 arg_t arg;
182} button_t;
183
184extern const cmd_t cmds[CMD_COUNT];
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*, float);
238bool img_zoom_in(img_t*);
239bool img_zoom_out(img_t*);
240bool img_pos(img_t*, float, float);
241bool img_move(img_t*, float, float);
242bool img_pan(img_t*, direction_t, int);
243bool img_pan_edge(img_t*, direction_t);
244void img_rotate(img_t*, degree_t);
245void img_flip(img_t*, flipdir_t);
246void img_toggle_antialias(img_t*);
247bool img_change_gamma(img_t*, int);
248bool img_frame_navigate(img_t*, int);
249bool img_frame_animate(img_t*);
250
251
252/* options.c */
253
254struct opt {
255 /* file list: */
256 char **filenames;
257 bool from_stdin;
258 bool to_stdout;
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
278 /* misc flags: */
279 bool quiet;
280 bool thumb_mode;
281 bool clean_cache;
282 bool private_mode;
283};
284
285extern const opt_t *options;
286
287void print_usage(void);
288void print_version(void);
289void parse_options(int, char**);
290
291
292/* thumbs.c */
293
294typedef struct {
295 Imlib_Image im;
296 int w;
297 int h;
298 int x;
299 int y;
300} thumb_t;
301
302struct tns {
303 fileinfo_t *files;
304 thumb_t *thumbs;
305 const int *cnt;
306 int *sel;
307 int initnext;
308 int loadnext;
309 int first, end;
310 int r_first, r_end;
311
312 win_t *win;
313 int x;
314 int y;
315 int cols;
316 int rows;
317 int zl;
318 int bw;
319 int dim;
320
321 bool dirty;
322};
323
324void tns_clean_cache(tns_t*);
325void tns_init(tns_t*, fileinfo_t*, const int*, int*, win_t*);
326CLEANUP void tns_free(tns_t*);
327bool tns_load(tns_t*, int, bool, bool);
328void tns_unload(tns_t*, int);
329void tns_render(tns_t*);
330void tns_mark(tns_t*, int, bool);
331void tns_highlight(tns_t*, int, bool);
332bool tns_move_selection(tns_t*, direction_t, int);
333bool tns_scroll(tns_t*, direction_t, bool);
334bool tns_zoom(tns_t*, int);
335int tns_translate(tns_t*, int, int);
336
337
338/* util.c */
339
340#include <dirent.h>
341
342typedef struct {
343 DIR *dir;
344 char *name;
345 int d;
346 bool recursive;
347
348 char **stack;
349 int stcap;
350 int stlen;
351} r_dir_t;
352
353extern const char *progname;
354
355void* emalloc(size_t);
356void* erealloc(void*, size_t);
357char* estrdup(const char*);
358void error(int, int, const char*, ...);
359void size_readable(float*, const char**);
360int r_opendir(r_dir_t*, const char*, bool);
361int r_closedir(r_dir_t*);
362char* r_readdir(r_dir_t*);
363int r_mkdir(char*);
364
365
366/* window.c */
367
368#include <X11/Xutil.h>
369#include <X11/Xft/Xft.h>
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_STATE_FULLSCREEN,
383 ATOM__NET_SUPPORTED,
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 XftColor bgcol;
407 XftColor fscol;
408 XftColor selcol;
409
410 int x;
411 int y;
412 unsigned int w;
413 unsigned int h; /* = win height - bar height */
414 unsigned int bw;
415
416 bool fullscreen;
417
418 struct {
419 int w;
420 int h;
421 Pixmap pm;
422 } buf;
423
424 struct {
425 unsigned int h;
426 win_bar_t l;
427 win_bar_t r;
428 XftColor bgcol;
429 XftColor fgcol;
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 /* SXIV_H */
449