Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added own bool type

  • Loading branch information...
commit b2a2a62b7b8a066467d7e8ef520fef7c17e3c5ca 1 parent e2d4b9c
Bert Münnich authored
216 commands.c
@@ -26,17 +26,16 @@
26 26 #include "commands.h"
27 27 #include "image.h"
28 28 #include "thumbs.h"
29   -#include "types.h"
30 29 #include "util.h"
31 30
32 31 void cleanup();
33   -void remove_file(int, unsigned char);
  32 +void remove_file(int, bool);
34 33 void load_image(int);
35 34 void redraw();
36 35 void reset_cursor();
37 36 void animate();
38 37 void slideshow();
39   -void set_timeout(timeout_f, int, int);
  38 +void set_timeout(timeout_f, int, bool);
40 39 void reset_timeout(timeout_f);
41 40
42 41 extern appmode_t mode;
@@ -47,73 +46,73 @@ extern win_t win;
47 46 extern fileinfo_t *files;
48 47 extern int filecnt, fileidx;
49 48
50   -int it_quit(arg_t a) {
  49 +bool it_quit(arg_t a) {
51 50 cleanup();
52 51 exit(0);
53 52 }
54 53
55   -int it_switch_mode(arg_t a) {
  54 +bool it_switch_mode(arg_t a) {
56 55 if (mode == MODE_IMAGE) {
57 56 if (!tns.thumbs)
58 57 tns_init(&tns, filecnt);
59   - img_close(&img, 0);
  58 + img_close(&img, false);
60 59 reset_timeout(reset_cursor);
61 60 if (img.slideshow) {
62   - img.slideshow = 0;
  61 + img.slideshow = false;
63 62 reset_timeout(slideshow);
64 63 }
65 64 tns.sel = fileidx;
66   - tns.dirty = 1;
  65 + tns.dirty = true;
67 66 mode = MODE_THUMB;
68 67 } else {
69 68 load_image(tns.sel);
70 69 mode = MODE_IMAGE;
71 70 }
72   - return 1;
  71 + return true;
73 72 }
74 73
75   -int it_toggle_fullscreen(arg_t a) {
  74 +bool it_toggle_fullscreen(arg_t a) {
76 75 win_toggle_fullscreen(&win);
77   - set_timeout(redraw, TO_REDRAW_RESIZE, 0);
  76 + set_timeout(redraw, TO_REDRAW_RESIZE, false);
78 77 if (mode == MODE_IMAGE)
79   - img.checkpan = 1;
  78 + img.checkpan = true;
80 79 else
81   - tns.dirty = 1;
82   - return 0;
  80 + tns.dirty = true;
  81 + return false;
83 82 }
84 83
85   -int it_reload_image(arg_t a) {
  84 +bool it_reload_image(arg_t a) {
86 85 if (mode == MODE_IMAGE) {
87 86 load_image(fileidx);
88 87 } else {
89 88 win_set_cursor(&win, CURSOR_WATCH);
90   - if (!tns_load(&tns, tns.sel, &files[tns.sel], True, False)) {
91   - remove_file(tns.sel, 0);
92   - tns.dirty = 1;
  89 + if (!tns_load(&tns, tns.sel, &files[tns.sel], true, false)) {
  90 + remove_file(tns.sel, false);
  91 + tns.dirty = true;
93 92 if (tns.sel >= tns.cnt)
94 93 tns.sel = tns.cnt - 1;
95 94 }
96 95 }
97   - return 1;
  96 + return true;
98 97 }
99 98
100   -int it_remove_image(arg_t a) {
  99 +bool it_remove_image(arg_t a) {
101 100 if (mode == MODE_IMAGE) {
102   - remove_file(fileidx, 1);
  101 + remove_file(fileidx, true);
103 102 load_image(fileidx >= filecnt ? filecnt - 1 : fileidx);
104   - return 1;
  103 + return true;
105 104 } else if (tns.sel < tns.cnt) {
106   - remove_file(tns.sel, 1);
107   - tns.dirty = 1;
  105 + remove_file(tns.sel, true);
  106 + tns.dirty = true;
108 107 if (tns.sel >= tns.cnt)
109 108 tns.sel = tns.cnt - 1;
110   - return 1;
  109 + return true;
111 110 } else {
112   - return 0;
  111 + return false;
113 112 }
114 113 }
115 114
116   -int i_navigate(arg_t a) {
  115 +bool i_navigate(arg_t a) {
117 116 long n = (long) a;
118 117
119 118 if (mode == MODE_IMAGE) {
@@ -125,86 +124,83 @@ int i_navigate(arg_t a) {
125 124
126 125 if (n != fileidx) {
127 126 load_image(n);
128   - return 1;
  127 + return true;
129 128 }
130 129 }
131   - return 0;
  130 + return false;
132 131 }
133 132
134   -int it_first(arg_t a) {
  133 +bool it_first(arg_t a) {
135 134 if (mode == MODE_IMAGE && fileidx != 0) {
136 135 load_image(0);
137   - return 1;
  136 + return true;
138 137 } else if (mode == MODE_THUMB && tns.sel != 0) {
139 138 tns.sel = 0;
140   - tns.dirty = 1;
141   - return 1;
  139 + tns.dirty = true;
  140 + return true;
142 141 } else {
143   - return 0;
  142 + return false;
144 143 }
145 144 }
146 145
147   -int it_last(arg_t a) {
  146 +bool it_last(arg_t a) {
148 147 if (mode == MODE_IMAGE && fileidx != filecnt - 1) {
149 148 load_image(filecnt - 1);
150   - return 1;
  149 + return true;
151 150 } else if (mode == MODE_THUMB && tns.sel != tns.cnt - 1) {
152 151 tns.sel = tns.cnt - 1;
153   - tns.dirty = 1;
154   - return 1;
  152 + tns.dirty = true;
  153 + return true;
155 154 } else {
156   - return 0;
  155 + return false;
157 156 }
158 157 }
159 158
160   -int i_navigate_frame(arg_t a) {
  159 +bool i_navigate_frame(arg_t a) {
161 160 if (mode == MODE_IMAGE && !img.multi.animate)
162 161 return img_frame_navigate(&img, (long) a);
163 162 else
164   - return 0;
  163 + return false;
165 164 }
166 165
167   -int i_toggle_animation(arg_t a) {
168   - int delay;
169   -
  166 +bool i_toggle_animation(arg_t a) {
170 167 if (mode != MODE_IMAGE)
171   - return 0;
  168 + return false;
172 169
173 170 if (img.multi.animate) {
174 171 reset_timeout(animate);
175   - img.multi.animate = 0;
176   - } else {
177   - delay = img_frame_animate(&img, 1);
178   - set_timeout(animate, delay, 1);
  172 + img.multi.animate = false;
  173 + } else if (img_frame_animate(&img, true)) {
  174 + set_timeout(animate, img.multi.frames[img.multi.sel].delay, true);
179 175 }
180   - return 1;
  176 + return true;
181 177 }
182 178
183   -int it_move(arg_t a) {
  179 +bool it_move(arg_t a) {
184 180 direction_t dir = (direction_t) a;
185 181
186 182 if (mode == MODE_IMAGE)
187   - return img_pan(&img, &win, dir, 0);
  183 + return img_pan(&img, &win, dir, false);
188 184 else
189 185 return tns_move_selection(&tns, &win, dir);
190 186 }
191 187
192   -int i_pan_screen(arg_t a) {
  188 +bool i_pan_screen(arg_t a) {
193 189 direction_t dir = (direction_t) a;
194 190
195 191 if (mode == MODE_IMAGE)
196   - return img_pan(&img, &win, dir, 1);
  192 + return img_pan(&img, &win, dir, true);
197 193 else
198   - return 0;
  194 + return false;
199 195 }
200 196
201   -int i_pan_edge(arg_t a) {
  197 +bool i_pan_edge(arg_t a) {
202 198 direction_t dir = (direction_t) a;
203 199
204 200 if (mode == MODE_IMAGE)
205 201 return img_pan_edge(&img, &win, dir);
206 202 else
207   - return 0;
  203 + return false;
208 204 }
209 205
210 206 /* Xlib helper function for i_drag() */
@@ -212,17 +208,17 @@ Bool is_motionnotify(Display *d, XEvent *e, XPointer a) {
212 208 return e != NULL && e->type == MotionNotify;
213 209 }
214 210
215   -int i_drag(arg_t a) {
  211 +bool i_drag(arg_t a) {
216 212 int dx = 0, dy = 0, i, ox, oy, x, y;
217 213 unsigned int ui;
218   - Bool dragging = True, next = False;
  214 + bool dragging = true, next = false;
219 215 XEvent e;
220 216 Window w;
221 217
222 218 if (mode != MODE_IMAGE)
223   - return 0;
  219 + return false;
224 220 if (!XQueryPointer(win.env.dpy, win.xwin, &w, &w, &i, &i, &ox, &oy, &ui))
225   - return 0;
  221 + return false;
226 222
227 223 win_set_cursor(&win, CURSOR_HAND);
228 224
@@ -233,7 +229,7 @@ int i_drag(arg_t a) {
233 229 switch (e.type) {
234 230 case ButtonPress:
235 231 case ButtonRelease:
236   - dragging = False;
  232 + dragging = false;
237 233 break;
238 234 case MotionNotify:
239 235 x = e.xmotion.x;
@@ -256,17 +252,17 @@ int i_drag(arg_t a) {
256 252 }
257 253
258 254 win_set_cursor(&win, CURSOR_ARROW);
259   - set_timeout(reset_cursor, TO_CURSOR_HIDE, 1);
  255 + set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
260 256 reset_timeout(redraw);
261 257
262   - return 0;
  258 + return false;
263 259 }
264 260
265   -int i_zoom(arg_t a) {
  261 +bool i_zoom(arg_t a) {
266 262 long scale = (long) a;
267 263
268 264 if (mode != MODE_IMAGE)
269   - return 0;
  265 + return false;
270 266
271 267 if (scale > 0)
272 268 return img_zoom_in(&img, &win);
@@ -276,21 +272,22 @@ int i_zoom(arg_t a) {
276 272 return img_zoom(&img, &win, 1.0);
277 273 }
278 274
279   -int i_fit_to_win(arg_t a) {
280   - int ret;
  275 +bool i_fit_to_win(arg_t a) {
  276 + bool ret;
281 277
282 278 if (mode == MODE_IMAGE) {
283 279 if ((ret = img_fit_win(&img, &win)))
284 280 img_center(&img, &win);
285 281 return ret;
286 282 } else {
287   - return 0;
  283 + return false;
288 284 }
289 285 }
290 286
291   -int i_fit_to_img(arg_t a) {
292   - int ret, x, y;
  287 +bool i_fit_to_img(arg_t a) {
  288 + int x, y;
293 289 unsigned int w, h;
  290 + bool ret;
294 291
295 292 if (mode == MODE_IMAGE) {
296 293 x = MAX(0, win.x + img.x);
@@ -303,90 +300,91 @@ int i_fit_to_img(arg_t a) {
303 300 }
304 301 return ret;
305 302 } else {
306   - return 0;
  303 + return false;
307 304 }
308 305 }
309 306
310   -int i_rotate(arg_t a) {
  307 +bool i_rotate(arg_t a) {
311 308 direction_t dir = (direction_t) a;
312 309
313 310 if (mode == MODE_IMAGE) {
314 311 if (dir == DIR_LEFT) {
315 312 img_rotate_left(&img, &win);
316   - return 1;
  313 + return true;
317 314 } else if (dir == DIR_RIGHT) {
318 315 img_rotate_right(&img, &win);
319   - return 1;
  316 + return true;
320 317 }
321 318 }
322   - return 0;
  319 + return false;
323 320 }
324 321
325   -int i_toggle_slideshow(arg_t a) {
  322 +bool i_toggle_slideshow(arg_t a) {
326 323 if (mode == MODE_IMAGE) {
327 324 if (img.slideshow) {
328   - img.slideshow = 0;
  325 + img.slideshow = false;
329 326 reset_timeout(slideshow);
330   - return 1;
  327 + return true;
331 328 } else if (fileidx + 1 < filecnt) {
332   - img.slideshow = 1;
333   - set_timeout(slideshow, img.ss_delay, 1);
334   - return 1;
  329 + img.slideshow = true;
  330 + set_timeout(slideshow, img.ss_delay, true);
  331 + return true;
335 332 }
336 333 }
337   - return 0;
  334 + return false;
338 335 }
339 336
340   -int i_adjust_slideshow(arg_t a) {
  337 +bool i_adjust_slideshow(arg_t a) {
341 338 long d = (long) a;
342 339 int i, delays[] = { 1, 2, 3, 5, 10, 15, 20, 30, 60, 120, 180, 300, 600 };
343 340
344 341 if (mode != MODE_IMAGE || !img.slideshow)
345   - return 0;
  342 + return false;
346 343
347 344 if (d < 0) {
348 345 for (i = ARRLEN(delays) - 2; i >= 0; i--) {
349 346 if (img.ss_delay > delays[i] * 1000) {
350 347 img.ss_delay = delays[i] * 1000;
351   - return 1;
  348 + return true;
352 349 }
353 350 }
354 351 } else {
355 352 for (i = 1; i < ARRLEN(delays); i++) {
356 353 if (img.ss_delay < delays[i] * 1000) {
357 354 img.ss_delay = delays[i] * 1000;
358   - return 1;
  355 + return true;
359 356 }
360 357 }
361 358 }
362   - return 0;
  359 + return false;
363 360 }
364 361
365   -int i_toggle_antialias(arg_t a) {
  362 +bool i_toggle_antialias(arg_t a) {
366 363 if (mode == MODE_IMAGE) {
367 364 img_toggle_antialias(&img);
368   - return 1;
  365 + return true;
369 366 } else {
370   - return 0;
  367 + return false;
371 368 }
372 369 }
373 370
374   -int it_toggle_alpha(arg_t a) {
375   - img.alpha ^= 1;
376   - tns.alpha = img.alpha;
377   - if (mode == MODE_THUMB)
378   - tns.dirty = 1;
379   - return 1;
  371 +bool it_toggle_alpha(arg_t a) {
  372 + img.alpha = tns.alpha = !img.alpha;
  373 + if (mode == MODE_IMAGE)
  374 + img.dirty = true;
  375 + else
  376 + tns.dirty = true;
  377 + return true;
380 378 }
381 379
382   -int it_open_with(arg_t a) {
  380 +bool it_open_with(arg_t a) {
383 381 const char *prog = (const char*) a;
384 382 pid_t pid;
385 383
386 384 if (!prog || !*prog)
387   - return 0;
  385 + return false;
388 386
389   - if((pid = fork()) == 0) {
  387 + if ((pid = fork()) == 0) {
390 388 execlp(prog, prog,
391 389 files[mode == MODE_IMAGE ? fileidx : tns.sel].path, NULL);
392 390 warn("could not exec: %s", prog);
@@ -395,10 +393,10 @@ int it_open_with(arg_t a) {
395 393 warn("could not fork. program was: %s", prog);
396 394 }
397 395
398   - return 0;
  396 + return false;
399 397 }
400 398
401   -int it_shell_cmd(arg_t a) {
  399 +bool it_shell_cmd(arg_t a) {
402 400 int n, status;
403 401 const char *cmdline = (const char*) a;
404 402 pid_t pid;
@@ -411,7 +409,7 @@ int it_shell_cmd(arg_t a) {
411 409 if (setenv("SXIV_IMG", files[n].path, 1) < 0) {
412 410 warn("could not set env.-variable: SXIV_IMG. command line was: %s",
413 411 cmdline);
414   - return 0;
  412 + return false;
415 413 }
416 414
417 415 if ((pid = fork()) == 0) {
@@ -420,7 +418,7 @@ int it_shell_cmd(arg_t a) {
420 418 exit(1);
421 419 } else if (pid < 0) {
422 420 warn("could not fork. command line was: %s", cmdline);
423   - return 0;
  421 + return false;
424 422 }
425 423
426 424 win_set_cursor(&win, CURSOR_WATCH);
@@ -431,17 +429,17 @@ int it_shell_cmd(arg_t a) {
431 429 WEXITSTATUS(status), cmdline);
432 430
433 431 if (mode == MODE_IMAGE) {
434   - img_close(&img, 1);
  432 + img_close(&img, true);
435 433 load_image(fileidx);
436 434 }
437   - if (!tns_load(&tns, n, &files[n], True, mode == MODE_IMAGE) &&
  435 + if (!tns_load(&tns, n, &files[n], true, mode == MODE_IMAGE) &&
438 436 mode == MODE_THUMB)
439 437 {
440   - remove_file(tns.sel, 0);
441   - tns.dirty = 1;
  438 + remove_file(tns.sel, false);
  439 + tns.dirty = true;
442 440 if (tns.sel >= tns.cnt)
443 441 tns.sel = tns.cnt - 1;
444 442 }
445 443
446   - return 1;
  444 + return true;
447 445 }
58 commands.h
@@ -21,47 +21,49 @@
21 21
22 22 #include <X11/Xlib.h>
23 23
  24 +#include "types.h"
  25 +
24 26 typedef void* arg_t;
25   -typedef int (*command_f)(arg_t);
  27 +typedef bool (*command_f)(arg_t);
26 28
27 29 typedef struct {
28   - Bool ctrl;
  30 + bool ctrl;
29 31 KeySym ksym;
30 32 command_f cmd;
31 33 arg_t arg;
32 34 } keymap_t;
33 35
34 36 typedef struct {
35   - Bool ctrl;
36   - Bool shift;
  37 + bool ctrl;
  38 + bool shift;
37 39 unsigned int button;
38 40 command_f cmd;
39 41 arg_t arg;
40 42 } button_t;
41 43
42   -int it_quit(arg_t);
43   -int it_switch_mode(arg_t);
44   -int it_toggle_fullscreen(arg_t);
45   -int it_reload_image(arg_t);
46   -int it_remove_image(arg_t);
47   -int i_navigate(arg_t);
48   -int it_first(arg_t);
49   -int it_last(arg_t);
50   -int i_navigate_frame(arg_t);
51   -int i_toggle_animation(arg_t);
52   -int it_move(arg_t);
53   -int i_pan_screen(arg_t);
54   -int i_pan_edge(arg_t);
55   -int i_drag(arg_t);
56   -int i_zoom(arg_t);
57   -int i_fit_to_win(arg_t);
58   -int i_fit_to_img(arg_t);
59   -int i_rotate(arg_t);
60   -int i_toggle_slideshow(arg_t);
61   -int i_adjust_slideshow(arg_t);
62   -int i_toggle_antialias(arg_t);
63   -int it_toggle_alpha(arg_t);
64   -int it_open_with(arg_t);
65   -int it_shell_cmd(arg_t);
  44 +bool it_quit(arg_t);
  45 +bool it_switch_mode(arg_t);
  46 +bool it_toggle_fullscreen(arg_t);
  47 +bool it_reload_image(arg_t);
  48 +bool it_remove_image(arg_t);
  49 +bool i_navigate(arg_t);
  50 +bool it_first(arg_t);
  51 +bool it_last(arg_t);
  52 +bool i_navigate_frame(arg_t);
  53 +bool i_toggle_animation(arg_t);
  54 +bool it_move(arg_t);
  55 +bool i_pan_screen(arg_t);
  56 +bool i_pan_edge(arg_t);
  57 +bool i_drag(arg_t);
  58 +bool i_zoom(arg_t);
  59 +bool i_fit_to_win(arg_t);
  60 +bool i_fit_to_img(arg_t);
  61 +bool i_rotate(arg_t);
  62 +bool i_toggle_slideshow(arg_t);
  63 +bool i_adjust_slideshow(arg_t);
  64 +bool i_toggle_antialias(arg_t);
  65 +bool it_toggle_alpha(arg_t);
  66 +bool it_open_with(arg_t);
  67 +bool it_shell_cmd(arg_t);
66 68
67 69 #endif /* COMMANDS_H */
154 config.def.h
@@ -51,96 +51,96 @@ enum { THUMB_SIZE = 60 };
51 51 /* keyboard mappings for image and thumbnail mode: */
52 52 static const keymap_t keys[] = {
53 53 /* ctrl key function argument */
54   - { False, XK_q, it_quit, (arg_t) None },
55   - { False, XK_Return, it_switch_mode, (arg_t) None },
56   - { False, XK_f, it_toggle_fullscreen, (arg_t) None },
57   -
58   - { False, XK_r, it_reload_image, (arg_t) None },
59   - { False, XK_D, it_remove_image, (arg_t) None },
60   -
61   - { False, XK_n, i_navigate, (arg_t) +1 },
62   - { False, XK_space, i_navigate, (arg_t) +1 },
63   - { False, XK_p, i_navigate, (arg_t) -1 },
64   - { False, XK_BackSpace, i_navigate, (arg_t) -1 },
65   - { False, XK_bracketright, i_navigate, (arg_t) +10 },
66   - { False, XK_bracketleft, i_navigate, (arg_t) -10 },
67   - { False, XK_g, it_first, (arg_t) None },
68   - { False, XK_G, it_last, (arg_t) None },
69   -
70   - { True, XK_n, i_navigate_frame, (arg_t) +1 },
71   - { True, XK_p, i_navigate_frame, (arg_t) -1 },
72   - { True, XK_space, i_toggle_animation, (arg_t) None },
73   -
74   - { False, XK_h, it_move, (arg_t) DIR_LEFT },
75   - { False, XK_Left, it_move, (arg_t) DIR_LEFT },
76   - { False, XK_j, it_move, (arg_t) DIR_DOWN },
77   - { False, XK_Down, it_move, (arg_t) DIR_DOWN },
78   - { False, XK_k, it_move, (arg_t) DIR_UP },
79   - { False, XK_Up, it_move, (arg_t) DIR_UP },
80   - { False, XK_l, it_move, (arg_t) DIR_RIGHT },
81   - { False, XK_Right, it_move, (arg_t) DIR_RIGHT },
82   -
83   - { True, XK_h, i_pan_screen, (arg_t) DIR_LEFT },
84   - { True, XK_Left, i_pan_screen, (arg_t) DIR_LEFT },
85   - { True, XK_j, i_pan_screen, (arg_t) DIR_DOWN },
86   - { True, XK_Down, i_pan_screen, (arg_t) DIR_DOWN },
87   - { True, XK_k, i_pan_screen, (arg_t) DIR_UP },
88   - { True, XK_Up, i_pan_screen, (arg_t) DIR_UP },
89   - { True, XK_l, i_pan_screen, (arg_t) DIR_RIGHT },
90   - { True, XK_Right, i_pan_screen, (arg_t) DIR_RIGHT },
91   -
92   - { False, XK_H, i_pan_edge, (arg_t) DIR_LEFT },
93   - { False, XK_J, i_pan_edge, (arg_t) DIR_DOWN },
94   - { False, XK_K, i_pan_edge, (arg_t) DIR_UP },
95   - { False, XK_L, i_pan_edge, (arg_t) DIR_RIGHT },
96   -
97   - { False, XK_plus, i_zoom, (arg_t) +1 },
98   - { False, XK_equal, i_zoom, (arg_t) +1 },
99   - { False, XK_KP_Add, i_zoom, (arg_t) +1 },
100   - { False, XK_minus, i_zoom, (arg_t) -1 },
101   - { False, XK_KP_Subtract, i_zoom, (arg_t) -1 },
102   - { False, XK_0, i_zoom, (arg_t) None },
103   - { False, XK_KP_0, i_zoom, (arg_t) None },
104   - { False, XK_w, i_fit_to_win, (arg_t) None },
105   - { False, XK_W, i_fit_to_img, (arg_t) None },
106   -
107   - { False, XK_less, i_rotate, (arg_t) DIR_LEFT },
108   - { False, XK_greater, i_rotate, (arg_t) DIR_RIGHT },
109   -
110   - { False, XK_s, i_toggle_slideshow, (arg_t) None },
111   - { True, XK_plus, i_adjust_slideshow, (arg_t) +1 },
112   - { True, XK_equal, i_adjust_slideshow, (arg_t) +1 },
113   - { True, XK_minus, i_adjust_slideshow, (arg_t) -1 },
114   -
115   - { False, XK_a, i_toggle_antialias, (arg_t) None },
116   - { False, XK_A, it_toggle_alpha, (arg_t) None },
  54 + { false, XK_q, it_quit, (arg_t) None },
  55 + { false, XK_Return, it_switch_mode, (arg_t) None },
  56 + { false, XK_f, it_toggle_fullscreen, (arg_t) None },
  57 +
  58 + { false, XK_r, it_reload_image, (arg_t) None },
  59 + { false, XK_D, it_remove_image, (arg_t) None },
  60 +
  61 + { false, XK_n, i_navigate, (arg_t) +1 },
  62 + { false, XK_space, i_navigate, (arg_t) +1 },
  63 + { false, XK_p, i_navigate, (arg_t) -1 },
  64 + { false, XK_BackSpace, i_navigate, (arg_t) -1 },
  65 + { false, XK_bracketright, i_navigate, (arg_t) +10 },
  66 + { false, XK_bracketleft, i_navigate, (arg_t) -10 },
  67 + { false, XK_g, it_first, (arg_t) None },
  68 + { false, XK_G, it_last, (arg_t) None },
  69 +
  70 + { true, XK_n, i_navigate_frame, (arg_t) +1 },
  71 + { true, XK_p, i_navigate_frame, (arg_t) -1 },
  72 + { true, XK_space, i_toggle_animation, (arg_t) None },
  73 +
  74 + { false, XK_h, it_move, (arg_t) DIR_LEFT },
  75 + { false, XK_Left, it_move, (arg_t) DIR_LEFT },
  76 + { false, XK_j, it_move, (arg_t) DIR_DOWN },
  77 + { false, XK_Down, it_move, (arg_t) DIR_DOWN },
  78 + { false, XK_k, it_move, (arg_t) DIR_UP },
  79 + { false, XK_Up, it_move, (arg_t) DIR_UP },
  80 + { false, XK_l, it_move, (arg_t) DIR_RIGHT },
  81 + { false, XK_Right, it_move, (arg_t) DIR_RIGHT },
  82 +
  83 + { true, XK_h, i_pan_screen, (arg_t) DIR_LEFT },
  84 + { true, XK_Left, i_pan_screen, (arg_t) DIR_LEFT },
  85 + { true, XK_j, i_pan_screen, (arg_t) DIR_DOWN },
  86 + { true, XK_Down, i_pan_screen, (arg_t) DIR_DOWN },
  87 + { true, XK_k, i_pan_screen, (arg_t) DIR_UP },
  88 + { true, XK_Up, i_pan_screen, (arg_t) DIR_UP },
  89 + { true, XK_l, i_pan_screen, (arg_t) DIR_RIGHT },
  90 + { true, XK_Right, i_pan_screen, (arg_t) DIR_RIGHT },
  91 +
  92 + { false, XK_H, i_pan_edge, (arg_t) DIR_LEFT },
  93 + { false, XK_J, i_pan_edge, (arg_t) DIR_DOWN },
  94 + { false, XK_K, i_pan_edge, (arg_t) DIR_UP },
  95 + { false, XK_L, i_pan_edge, (arg_t) DIR_RIGHT },
  96 +
  97 + { false, XK_plus, i_zoom, (arg_t) +1 },
  98 + { false, XK_equal, i_zoom, (arg_t) +1 },
  99 + { false, XK_KP_Add, i_zoom, (arg_t) +1 },
  100 + { false, XK_minus, i_zoom, (arg_t) -1 },
  101 + { false, XK_KP_Subtract, i_zoom, (arg_t) -1 },
  102 + { false, XK_0, i_zoom, (arg_t) None },
  103 + { false, XK_KP_0, i_zoom, (arg_t) None },
  104 + { false, XK_w, i_fit_to_win, (arg_t) None },
  105 + { false, XK_W, i_fit_to_img, (arg_t) None },
  106 +
  107 + { false, XK_less, i_rotate, (arg_t) DIR_LEFT },
  108 + { false, XK_greater, i_rotate, (arg_t) DIR_RIGHT },
  109 +
  110 + { false, XK_s, i_toggle_slideshow, (arg_t) None },
  111 + { true, XK_plus, i_adjust_slideshow, (arg_t) +1 },
  112 + { true, XK_equal, i_adjust_slideshow, (arg_t) +1 },
  113 + { true, XK_minus, i_adjust_slideshow, (arg_t) -1 },
  114 +
  115 + { false, XK_a, i_toggle_antialias, (arg_t) None },
  116 + { false, XK_A, it_toggle_alpha, (arg_t) None },
117 117
118 118 /* open current image with given program: */
119   - { True, XK_g, it_open_with, (arg_t) "gimp" },
  119 + { true, XK_g, it_open_with, (arg_t) "gimp" },
120 120
121 121 /* run shell command line on current file ("$SXIV_IMG"): */
122   - { True, XK_less, it_shell_cmd, (arg_t) \
  122 + { true, XK_less, it_shell_cmd, (arg_t) \
123 123 "mogrify -rotate -90 \"$SXIV_IMG\"" },
124   - { True, XK_greater, it_shell_cmd, (arg_t) \
  124 + { true, XK_greater, it_shell_cmd, (arg_t) \
125 125 "mogrify -rotate +90 \"$SXIV_IMG\"" },
126   - { True, XK_comma, it_shell_cmd, (arg_t) \
  126 + { true, XK_comma, it_shell_cmd, (arg_t) \
127 127 "jpegtran -rotate 270 -copy all -outfile \"$SXIV_IMG\" \"$SXIV_IMG\"" },
128   - { True, XK_period, it_shell_cmd, (arg_t) \
  128 + { true, XK_period, it_shell_cmd, (arg_t) \
129 129 "jpegtran -rotate 90 -copy all -outfile \"$SXIV_IMG\" \"$SXIV_IMG\"" },
130 130 };
131 131
132 132 /* mouse button mappings for image mode: */
133 133 static const button_t buttons[] = {
134 134 /* ctrl shift button function argument */
135   - { False, False, Button1, i_navigate, (arg_t) +1 },
136   - { False, False, Button3, i_navigate, (arg_t) -1 },
137   - { False, False, Button2, i_drag, (arg_t) None },
138   - { False, False, Button4, it_move, (arg_t) DIR_UP },
139   - { False, False, Button5, it_move, (arg_t) DIR_DOWN },
140   - { False, True, Button4, it_move, (arg_t) DIR_LEFT },
141   - { False, True, Button5, it_move, (arg_t) DIR_RIGHT },
142   - { True, False, Button4, i_zoom, (arg_t) +1 },
143   - { True, False, Button5, i_zoom, (arg_t) -1 },
  135 + { false, false, Button1, i_navigate, (arg_t) +1 },
  136 + { false, false, Button3, i_navigate, (arg_t) -1 },
  137 + { false, false, Button2, i_drag, (arg_t) None },
  138 + { false, false, Button4, it_move, (arg_t) DIR_UP },
  139 + { false, false, Button5, it_move, (arg_t) DIR_DOWN },
  140 + { false, true, Button4, it_move, (arg_t) DIR_LEFT },
  141 + { false, true, Button5, it_move, (arg_t) DIR_RIGHT },
  142 + { true, false, Button4, i_zoom, (arg_t) +1 },
  143 + { true, false, Button5, i_zoom, (arg_t) -1 },
144 144 };
145 145
146 146 #endif
169 image.c
@@ -51,15 +51,15 @@ void img_init(img_t *img, win_t *win) {
51 51 if (img) {
52 52 img->im = NULL;
53 53 img->multi.cap = img->multi.cnt = 0;
54   - img->multi.animate = 0;
  54 + img->multi.animate = false;
55 55 img->zoom = options->zoom;
56 56 img->zoom = MAX(img->zoom, zoom_min);
57 57 img->zoom = MIN(img->zoom, zoom_max);
58   - img->checkpan = 0;
59   - img->dirty = 0;
  58 + img->checkpan = false;
  59 + img->dirty = false;
60 60 img->aa = options->aa;
61   - img->alpha = 1;
62   - img->slideshow = 0;
  61 + img->alpha = true;
  62 + img->slideshow = false;
63 63 img->ss_delay = SLIDESHOW_DELAY * 1000;
64 64 }
65 65
@@ -119,7 +119,7 @@ void exif_auto_orientate(const fileinfo_t *file) {
119 119 /* Originally based on, but in its current form merely inspired by Imlib2's
120 120 * src/modules/loaders/loader_gif.c:load(), written by Carsten Haitzler.
121 121 */
122   -int img_load_gif(img_t *img, const fileinfo_t *file) {
  122 +bool img_load_gif(img_t *img, const fileinfo_t *file) {
123 123 GifFileType *gif;
124 124 GifRowType *rows = NULL;
125 125 GifRecordType rec;
@@ -131,8 +131,9 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
131 131 int x, y, w, h, sw, sh;
132 132 int intoffset[] = { 0, 4, 2, 1 };
133 133 int intjump[] = { 8, 8, 4, 2 };
134   - int err = 0, transp = -1;
  134 + int transp = -1;
135 135 unsigned int delay = 0;
  136 + bool err = false;
136 137
137 138 if (img->multi.cap == 0) {
138 139 img->multi.cap = 8;
@@ -145,7 +146,7 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
145 146 gif = DGifOpenFileName(file->path);
146 147 if (!gif) {
147 148 warn("could not open gif file: %s", file->name);
148   - return 0;
  149 + return false;
149 150 }
150 151 bg = gif->SBackGroundColor;
151 152 sw = gif->SWidth;
@@ -153,7 +154,7 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
153 154
154 155 do {
155 156 if (DGifGetRecordType(gif, &rec) == GIF_ERROR) {
156   - err = 1;
  157 + err = true;
157 158 break;
158 159 }
159 160 if (rec == EXTENSION_RECORD_TYPE) {
@@ -177,7 +178,7 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
177 178 }
178 179 } else if (rec == IMAGE_DESC_RECORD_TYPE) {
179 180 if (DGifGetImageDesc(gif) == GIF_ERROR) {
180   - err = 1;
  181 + err = true;
181 182 break;
182 183 }
183 184 x = gif->Image.Left;
@@ -235,7 +236,7 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
235 236 free(data);
236 237
237 238 if (!im) {
238   - err = 1;
  239 + err = true;
239 240 break;
240 241 }
241 242
@@ -272,7 +273,7 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
272 273 imlib_context_set_image(img->multi.frames[0].im);
273 274 imlib_free_image();
274 275 img->multi.cnt = 0;
275   - img->multi.animate = 0;
  276 + img->multi.animate = false;
276 277 }
277 278
278 279 imlib_context_set_image(img->im);
@@ -281,15 +282,15 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
281 282 }
282 283 #endif /* GIF_SUPPORT */
283 284
284   -int img_load(img_t *img, const fileinfo_t *file) {
  285 +bool img_load(img_t *img, const fileinfo_t *file) {
285 286 const char *fmt;
286 287
287 288 if (!img || !file || !file->name || !file->path)
288   - return 0;
  289 + return false;
289 290
290 291 if (access(file->path, R_OK) || !(img->im = imlib_load_image(file->path))) {
291 292 warn("could not open image: %s", file->name);
292   - return 0;
  293 + return false;
293 294 }
294 295
295 296 imlib_context_set_image(img->im);
@@ -310,17 +311,17 @@ int img_load(img_t *img, const fileinfo_t *file) {
310 311 #endif
311 312
312 313 img->scalemode = options->scalemode;
313   - img->re = 0;
314   - img->checkpan = 0;
  314 + img->re = false;
  315 + img->checkpan = false;
  316 + img->dirty = true;
315 317
316 318 img->w = imlib_image_get_width();
317 319 img->h = imlib_image_get_height();
318 320
319   - img->dirty = 1;
320   - return 1;
  321 + return true;
321 322 }
322 323
323   -void img_close(img_t *img, int decache) {
  324 +void img_close(img_t *img, bool decache) {
324 325 int i;
325 326
326 327 if (!img)
@@ -343,7 +344,7 @@ void img_close(img_t *img, int decache) {
343 344 }
344 345 }
345 346
346   -void img_check_pan(img_t *img, win_t *win, int moved) {
  347 +void img_check_pan(img_t *img, win_t *win, bool moved) {
347 348 int ox, oy;
348 349
349 350 if (!img || !win)
@@ -370,14 +371,14 @@ void img_check_pan(img_t *img, win_t *win, int moved) {
370 371 }
371 372
372 373 if (!moved && (ox != img->x || oy != img->y))
373   - img->dirty = 1;
  374 + img->dirty = true;
374 375 }
375 376
376   -int img_fit(img_t *img, win_t *win) {
  377 +bool img_fit(img_t *img, win_t *win) {
377 378 float z, zmax, zw, zh;
378 379
379 380 if (!img || !win || img->scalemode == SCALE_ZOOM)
380   - return 0;
  381 + return false;
381 382
382 383 zmax = img->scalemode == SCALE_DOWN ? 1.0 : zoom_max;
383 384 zw = (float) win->w / (float) img->w;
@@ -389,10 +390,10 @@ int img_fit(img_t *img, win_t *win) {
389 390
390 391 if (ZOOMDIFF(z, img->zoom)) {
391 392 img->zoom = z;
392   - img->dirty = 1;
393   - return 1;
  393 + img->dirty = true;
  394 + return true;
394 395 } else {
395   - return 0;
  396 + return false;
396 397 }
397 398 }
398 399
@@ -407,7 +408,7 @@ void img_render(img_t *img, win_t *win) {
407 408
408 409 if (!img->re) {
409 410 /* rendered for the first time */
410   - img->re = 1;
  411 + img->re = true;
411 412 if (img->zoom * img->w <= win->w)
412 413 img->x = (win->w - img->w * img->zoom) / 2;
413 414 else
@@ -419,8 +420,8 @@ void img_render(img_t *img, win_t *win) {
419 420 }
420 421
421 422 if (img->checkpan) {
422   - img_check_pan(img, win, 0);
423   - img->checkpan = 0;
  423 + img_check_pan(img, win, false);
  424 + img->checkpan = false;
424 425 }
425 426
426 427 if (!img->dirty)
@@ -462,22 +463,22 @@ void img_render(img_t *img, win_t *win) {
462 463
463 464 win_draw(win);
464 465
465   - img->dirty = 0;
  466 + img->dirty = false;
466 467 }
467 468
468   -int img_fit_win(img_t *img, win_t *win) {
  469 +bool img_fit_win(img_t *img, win_t *win) {
469 470 if (!img || !img->im || !win)
470   - return 0;
  471 + return false;
471 472
472 473 img->scalemode = SCALE_FIT;
473 474 return img_fit(img, win);
474 475 }
475 476
476   -int img_center(img_t *img, win_t *win) {
  477 +bool img_center(img_t *img, win_t *win) {
477 478 int ox, oy;
478 479
479 480 if (!img || !win)
480   - return 0;
  481 + return false;
481 482
482 483 ox = img->x;
483 484 oy = img->y;
@@ -486,16 +487,16 @@ int img_center(img_t *img, win_t *win) {
486 487 img->y = (win->h - img->h * img->zoom) / 2;
487 488
488 489 if (ox != img->x || oy != img->y) {
489   - img->dirty = 1;
490   - return 1;
  490 + img->dirty = true;
  491 + return true;
491 492 } else {
492   - return 0;
  493 + return false;
493 494 }
494 495 }
495 496
496   -int img_zoom(img_t *img, win_t *win, float z) {
  497 +bool img_zoom(img_t *img, win_t *win, float z) {
497 498 if (!img || !img->im || !win)
498   - return 0;
  499 + return false;
499 500
500 501 z = MAX(z, zoom_min);
501 502 z = MIN(z, zoom_max);
@@ -506,45 +507,45 @@ int img_zoom(img_t *img, win_t *win, float z) {
506 507 img->x = win->w / 2 - (win->w / 2 - img->x) * z / img->zoom;
507 508 img->y = win->h / 2 - (win->h / 2 - img->y) * z / img->zoom;
508 509 img->zoom = z;
509   - img->checkpan = 1;
510   - img->dirty = 1;
511   - return 1;
  510 + img->checkpan = true;
  511 + img->dirty = true;
  512 + return true;
512 513 } else {
513   - return 0;
  514 + return false;
514 515 }
515 516 }
516 517
517   -int img_zoom_in(img_t *img, win_t *win) {
  518 +bool img_zoom_in(img_t *img, win_t *win) {
518 519 int i;
519 520
520 521 if (!img || !img->im || !win)
521   - return 0;
  522 + return false;
522 523
523 524 for (i = 1; i < ARRLEN(zoom_levels); i++) {
524 525 if (zoom_levels[i] > img->zoom * 100.0)
525 526 return img_zoom(img, win, zoom_levels[i] / 100.0);
526 527 }
527   - return 0;
  528 + return false;
528 529 }
529 530
530   -int img_zoom_out(img_t *img, win_t *win) {
  531 +bool img_zoom_out(img_t *img, win_t *win) {
531 532 int i;
532 533
533 534 if (!img || !img->im || !win)
534   - return 0;
  535 + return false;
535 536
536 537 for (i = ARRLEN(zoom_levels) - 2; i >= 0; i--) {
537 538 if (zoom_levels[i] < img->zoom * 100.0)
538 539 return img_zoom(img, win, zoom_levels[i] / 100.0);
539 540 }
540   - return 0;
  541 + return false;
541 542 }
542 543
543   -int img_move(img_t *img, win_t *win, int dx, int dy) {
  544 +bool img_move(img_t *img, win_t *win, int dx, int dy) {
544 545 int ox, oy;
545 546
546 547 if (!img || !img->im || !win)
547   - return 0;
  548 + return false;
548 549
549 550 ox = img->x;
550 551 oy = img->y;
@@ -552,19 +553,19 @@ int img_move(img_t *img, win_t *win, int dx, int dy) {
552 553 img->x += dx;
553 554 img->y += dy;
554 555
555   - img_check_pan(img, win, 1);
  556 + img_check_pan(img, win, true);
556 557
557 558 if (ox != img->x || oy != img->y) {
558   - img->dirty = 1;
559   - return 1;
  559 + img->dirty = true;
  560 + return true;
560 561 } else {
561   - return 0;
  562 + return false;
562 563 }
563 564 }
564 565
565   -int img_pan(img_t *img, win_t *win, direction_t dir, int screen) {
  566 +bool img_pan(img_t *img, win_t *win, direction_t dir, bool screen) {
566 567 if (!img || !img->im || !win)
567   - return 0;
  568 + return false;
568 569
569 570 switch (dir) {
570 571 case DIR_LEFT:
@@ -576,14 +577,14 @@ int img_pan(img_t *img, win_t *win, direction_t dir, int screen) {
576 577 case DIR_DOWN:
577 578 return img_move(img, win, 0, win->h / (screen ? 1 : 5) * -1);
578 579 }
579   - return 0;
  580 + return false;
580 581 }
581 582
582   -int img_pan_edge(img_t *img, win_t *win, direction_t dir) {
  583 +bool img_pan_edge(img_t *img, win_t *win, direction_t dir) {
583 584 int ox, oy;
584 585
585 586 if (!img || !img->im || !win)
586   - return 0;
  587 + return false;
587 588
588 589 ox = img->x;
589 590 oy = img->y;
@@ -603,13 +604,13 @@ int img_pan_edge(img_t *img, win_t *win, direction_t dir) {
603 604 break;
604 605 }
605 606
606   - img_check_pan(img, win, 1);
  607 + img_check_pan(img, win, true);
607 608
608 609 if (ox != img->x || oy != img->y) {
609   - img->dirty = 1;
610   - return 1;
  610 + img->dirty = true;
  611 + return true;
611 612 } else {
612   - return 0;
  613 + return false;
613 614 }
614 615 }
615 616
@@ -632,8 +633,8 @@ void img_rotate(img_t *img, win_t *win, int d) {
632 633 img->w = img->h;
633 634 img->h = tmp;
634 635
635   - img->checkpan = 1;
636   - img->dirty = 1;
  636 + img->checkpan = true;
  637 + img->dirty = true;
637 638 }
638 639
639 640 void img_rotate_left(img_t *img, win_t *win) {
@@ -648,18 +649,18 @@ void img_toggle_antialias(img_t *img) {
648 649 if (!img || !img->im)
649 650 return;
650 651
651   - img->aa ^= 1;
  652 + img->aa = !img->aa;
652 653 imlib_context_set_image(img->im);
653 654 imlib_context_set_anti_alias(img->aa);
654   - img->dirty = 1;
  655 + img->dirty = true;
655 656 }
656 657
657   -int img_frame_goto(img_t *img, int n) {
  658 +bool img_frame_goto(img_t *img, int n) {
658 659 if (!img || n < 0 || n >= img->multi.cnt)
659   - return 0;
  660 + return false;
660 661
661 662 if (n == img->multi.sel)
662   - return 0;
  663 + return false;
663 664
664 665 img->multi.sel = n;
665 666 img->im = img->multi.frames[n].im;
@@ -667,15 +668,15 @@ int img_frame_goto(img_t *img, int n) {
667 668 imlib_context_set_image(img->im);
668 669 img->w = imlib_image_get_width();
669 670 img->h = imlib_image_get_height();
670   - img->checkpan = 1;
671   - img->dirty = 1;
  671 + img->checkpan = true;
  672 + img->dirty = true;
672 673
673   - return 1;
  674 + return true;
674 675 }
675 676
676   -int img_frame_navigate(img_t *img, int d) {
  677 +bool img_frame_navigate(img_t *img, int d) {
677 678 if (!img || !img->multi.cnt || !d)
678   - return 0;
  679 + return false;
679 680
680 681 d += img->multi.sel;
681 682 if (d < 0)
@@ -686,22 +687,22 @@ int img_frame_navigate(img_t *img, int d) {
686 687 return img_frame_goto(img, d);
687 688 }
688 689
689   -int img_frame_animate(img_t *img, int restart) {
  690 +bool img_frame_animate(img_t *img, bool restart) {
690 691 if (!img || !img->multi.cnt)
691   - return 0;
  692 + return false;
692 693
693 694 if (img->multi.sel + 1 >= img->multi.cnt) {
694 695 if (restart || (GIF_LOOP && !img->slideshow)) {
695 696 img_frame_goto(img, 0);
696 697 } else {
697   - img->multi.animate = 0;
698   - return 0;
  698 + img->multi.animate = false;
  699 + return false;
699 700 }
700 701 } else if (!restart) {
701 702 img_frame_goto(img, img->multi.sel + 1);
702 703 }
703   - img->multi.animate = 1;
  704 + img->multi.animate = true;
  705 + img->dirty = true;
704 706
705   - img->dirty = 1;
706   - return img->multi.frames[img->multi.sel].delay;
  707 + return true;
707 708 }
38 image.h
@@ -34,7 +34,7 @@ typedef struct {
34 34 int cap;
35 35 int cnt;
36 36 int sel;
37   - unsigned char animate;
  37 + bool animate;
38 38 } multi_img_t;
39 39
40 40 typedef struct {
@@ -44,13 +44,13 @@ typedef struct {
44 44 float zoom;
45 45 scalemode_t scalemode;
46 46
47   - unsigned char re;
48   - unsigned char checkpan;
49   - unsigned char dirty;
50   - unsigned char aa;
51   - unsigned char alpha;
  47 + bool re;
  48 + bool checkpan;
  49 + bool dirty;
  50 + bool aa;
  51 + bool alpha;
52 52
53   - unsigned char slideshow;
  53 + bool slideshow;
54 54 int ss_delay; /* in ms */
55 55
56 56 int x;
@@ -61,28 +61,28 @@ typedef struct {
61 61
62 62 void img_init(img_t*, win_t*);
63 63
64   -int img_load(img_t*, const fileinfo_t*);
65   -void img_close(img_t*, int);
  64 +bool img_load(img_t*, const fileinfo_t*);
  65 +void img_close(img_t*, bool);
66 66
67 67 void img_render(img_t*, win_t*);
68 68
69   -int img_fit_win(img_t*, win_t*);
70   -int img_center(img_t*, win_t*);
  69 +bool img_fit_win(img_t*, win_t*);
  70 +bool img_center(img_t*, win_t*);
71 71
72   -int img_zoom(img_t*, win_t*, float);
73   -int img_zoom_in(img_t*, win_t*);
74   -int img_zoom_out(img_t*, win_t*);
  72 +bool img_zoom(img_t*, win_t*, float);
  73 +bool img_zoom_in(img_t*, win_t*);
  74 +bool img_zoom_out(img_t*, win_t*);
75 75