Krolyxon
Commit 88f77bc

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_FILL,
92 SCALE_WIDTH,
93 SCALE_HEIGHT,
94 SCALE_ZOOM
95} scalemode_t;
96
97typedef enum {
98 DRAG_RELATIVE,
99 DRAG_ABSOLUTE
100} dragmode_t;
101
102typedef enum {
103 CURSOR_ARROW,
104 CURSOR_DRAG,
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 struct {
120 const char *name; /* as given by user */
121 const char *path; /* always absolute */
122 fileflags_t flags;
123} fileinfo_t;
124
125/* timeouts in milliseconds: */
126enum {
127 TO_REDRAW_RESIZE = 75,
128 TO_REDRAW_THUMBS = 200,
129 TO_CURSOR_HIDE = 1200,
130 TO_DOUBLE_CLICK = 300
131};
132
133typedef void (*timeout_f)(void);
134
135typedef struct arl arl_t;
136typedef struct img img_t;
137typedef struct opt opt_t;
138typedef struct tns tns_t;
139typedef struct win win_t;
140
141
142/* autoreload.c */
143
144struct arl {
145 int fd;
146 int wd_dir;
147 int wd_file;
148 char *filename;
149};
150
151void arl_init(arl_t*);
152void arl_cleanup(arl_t*);
153void arl_setup(arl_t*, const char* /* result of realpath(3) */);
154bool arl_handle(arl_t*);
155
156
157/* commands.c */
158
159typedef int arg_t;
160typedef bool (*cmd_f)(arg_t);
161
162#define G_CMD(c) g_##c,
163#define I_CMD(c) i_##c,
164#define T_CMD(c) t_##c,
165
166typedef enum {
167#include "commands.lst"
168 CMD_COUNT
169} cmd_id_t;
170
171typedef struct {
172 int mode;
173 cmd_f func;
174} cmd_t;
175
176typedef struct {
177 unsigned int mask;
178 KeySym ksym;
179 cmd_id_t cmd;
180 arg_t arg;
181} keymap_t;
182
183typedef struct {
184 unsigned int mask;
185 unsigned int button;
186 cmd_id_t cmd;
187 arg_t arg;
188} button_t;
189
190extern const cmd_t cmds[CMD_COUNT];
191
192
193/* image.c */
194
195typedef struct {
196 Imlib_Image im;
197 unsigned int delay;
198} img_frame_t;
199
200typedef struct {
201 img_frame_t *frames;
202 int cap;
203 int cnt;
204 int sel;
205 bool animate;
206 int framedelay;
207 int length;
208} multi_img_t;
209
210struct img {
211 Imlib_Image im;
212 int w;
213 int h;
214
215 win_t *win;
216 float x;
217 float y;
218
219 scalemode_t scalemode;
220 float zoom;
221
222 bool checkpan;
223 bool dirty;
224 bool aa;
225 bool alpha;
226
227 Imlib_Color_Modifier cmod;
228 int gamma;
229
230 struct {
231 bool on;
232 int delay;
233 } ss;
234
235 multi_img_t multi;
236};
237
238void img_init(img_t*, win_t*);
239bool img_load(img_t*, const fileinfo_t*);
240CLEANUP void img_close(img_t*, bool);
241void img_render(img_t*);
242bool img_fit_win(img_t*, scalemode_t);
243bool img_zoom(img_t*, float);
244bool img_zoom_in(img_t*);
245bool img_zoom_out(img_t*);
246bool img_pos(img_t*, float, float);
247bool img_move(img_t*, float, float);
248bool img_pan(img_t*, direction_t, int);
249bool img_pan_edge(img_t*, direction_t);
250void img_rotate(img_t*, degree_t);
251void img_flip(img_t*, flipdir_t);
252void img_toggle_antialias(img_t*);
253bool img_change_gamma(img_t*, int);
254bool img_frame_navigate(img_t*, int);
255bool img_frame_animate(img_t*);
256
257
258/* options.c */
259
260struct opt {
261 /* file list: */
262 char **filenames;
263 bool from_stdin;
264 bool to_stdout;
265 bool recursive;
266 int filecnt;
267 int startnum;
268
269 /* image: */
270 scalemode_t scalemode;
271 float zoom;
272 bool animate;
273 int gamma;
274 int slideshow;
275 int framerate;
276
277 /* window: */
278 bool fullscreen;
279 bool hide_bar;
280 long embed;
281 char *geometry;
282 char *res_name;
283
284 /* misc flags: */
285 bool quiet;
286 bool thumb_mode;
287 bool clean_cache;
288 bool private_mode;
289};
290
291extern const opt_t *options;
292
293void print_usage(void);
294void print_version(void);
295void parse_options(int, char**);
296
297
298/* thumbs.c */
299
300typedef struct {
301 Imlib_Image im;
302 int w;
303 int h;
304 int x;
305 int y;
306} thumb_t;
307
308struct tns {
309 fileinfo_t *files;
310 thumb_t *thumbs;
311 const int *cnt;
312 int *sel;
313 int initnext;
314 int loadnext;
315 int first, end;
316 int r_first, r_end;
317
318 win_t *win;
319 int x;
320 int y;
321 int cols;
322 int rows;
323 int zl;
324 int bw;
325 int dim;
326
327 bool dirty;
328};
329
330void tns_clean_cache(tns_t*);
331void tns_init(tns_t*, fileinfo_t*, const int*, int*, win_t*);
332CLEANUP void tns_free(tns_t*);
333bool tns_load(tns_t*, int, bool, bool);
334void tns_unload(tns_t*, int);
335void tns_render(tns_t*);
336void tns_mark(tns_t*, int, bool);
337void tns_highlight(tns_t*, int, bool);
338bool tns_move_selection(tns_t*, direction_t, int);
339bool tns_scroll(tns_t*, direction_t, bool);
340bool tns_zoom(tns_t*, int);
341int tns_translate(tns_t*, int, int);
342
343
344/* util.c */
345
346#include <dirent.h>
347
348typedef struct {
349 DIR *dir;
350 char *name;
351 int d;
352 bool recursive;
353
354 char **stack;
355 int stcap;
356 int stlen;
357} r_dir_t;
358
359extern const char *progname;
360
361void* emalloc(size_t);
362void* erealloc(void*, size_t);
363char* estrdup(const char*);
364void error(int, int, const char*, ...);
365void size_readable(float*, const char**);
366int r_opendir(r_dir_t*, const char*, bool);
367int r_closedir(r_dir_t*);
368char* r_readdir(r_dir_t*, bool);
369int r_mkdir(char*);
370
371
372/* window.c */
373
374#include <X11/Xutil.h>
375#include <X11/Xft/Xft.h>
376
377enum {
378 BAR_L_LEN = 512,
379 BAR_R_LEN = 64
380};
381
382enum {
383 ATOM_WM_DELETE_WINDOW,
384 ATOM__NET_WM_NAME,
385 ATOM__NET_WM_ICON_NAME,
386 ATOM__NET_WM_ICON,
387 ATOM__NET_WM_STATE,
388 ATOM__NET_WM_STATE_FULLSCREEN,
389 ATOM_COUNT
390};
391
392typedef struct {
393 Display *dpy;
394 int scr;
395 int scrw, scrh;
396 Visual *vis;
397 Colormap cmap;
398 int depth;
399} win_env_t;
400
401typedef struct {
402 size_t size;
403 char *p;
404 char *buf;
405} win_bar_t;
406
407struct win {
408 Window xwin;
409 win_env_t env;
410
411 XftColor bg;
412 XftColor fg;
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 /* SXIV_H */
449