aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert <ber.t@gmx.com>2011-09-11 21:01:24 +0200
committerBert <ber.t@gmx.com>2011-09-11 21:01:24 +0200
commitb2a2a62b7b8a066467d7e8ef520fef7c17e3c5ca (patch)
treec13904baa041941854a7550f883ba38e14205f1e
parente2d4b9c7915a2a356cae04d33f1713ae224fbe7e (diff)
Added own bool type
-rw-r--r--commands.c216
-rw-r--r--commands.h58
-rw-r--r--config.def.h154
-rw-r--r--image.c169
-rw-r--r--image.h38
-rw-r--r--main.c85
-rw-r--r--options.c33
-rw-r--r--options.h16
-rw-r--r--thumbs.c79
-rw-r--r--thumbs.h12
-rw-r--r--types.h7
-rw-r--r--window.c29
-rw-r--r--window.h10
13 files changed, 454 insertions, 452 deletions
diff --git a/commands.c b/commands.c
index 4c9553e..18080cd 100644
--- a/commands.c
+++ b/commands.c
@@ -26,17 +26,16 @@
#include "commands.h"
#include "image.h"
#include "thumbs.h"
-#include "types.h"
#include "util.h"
void cleanup();
-void remove_file(int, unsigned char);
+void remove_file(int, bool);
void load_image(int);
void redraw();
void reset_cursor();
void animate();
void slideshow();
-void set_timeout(timeout_f, int, int);
+void set_timeout(timeout_f, int, bool);
void reset_timeout(timeout_f);
extern appmode_t mode;
@@ -47,73 +46,73 @@ extern win_t win;
extern fileinfo_t *files;
extern int filecnt, fileidx;
-int it_quit(arg_t a) {
+bool it_quit(arg_t a) {
cleanup();
exit(0);
}
-int it_switch_mode(arg_t a) {
+bool it_switch_mode(arg_t a) {
if (mode == MODE_IMAGE) {
if (!tns.thumbs)
tns_init(&tns, filecnt);
- img_close(&img, 0);
+ img_close(&img, false);
reset_timeout(reset_cursor);
if (img.slideshow) {
- img.slideshow = 0;
+ img.slideshow = false;
reset_timeout(slideshow);
}
tns.sel = fileidx;
- tns.dirty = 1;
+ tns.dirty = true;
mode = MODE_THUMB;
} else {
load_image(tns.sel);
mode = MODE_IMAGE;
}
- return 1;
+ return true;
}
-int it_toggle_fullscreen(arg_t a) {
+bool it_toggle_fullscreen(arg_t a) {
win_toggle_fullscreen(&win);
- set_timeout(redraw, TO_REDRAW_RESIZE, 0);
+ set_timeout(redraw, TO_REDRAW_RESIZE, false);
if (mode == MODE_IMAGE)
- img.checkpan = 1;
+ img.checkpan = true;
else
- tns.dirty = 1;
- return 0;
+ tns.dirty = true;
+ return false;
}
-int it_reload_image(arg_t a) {
+bool it_reload_image(arg_t a) {
if (mode == MODE_IMAGE) {
load_image(fileidx);
} else {
win_set_cursor(&win, CURSOR_WATCH);
- if (!tns_load(&tns, tns.sel, &files[tns.sel], True, False)) {
- remove_file(tns.sel, 0);
- tns.dirty = 1;
+ if (!tns_load(&tns, tns.sel, &files[tns.sel], true, false)) {
+ remove_file(tns.sel, false);
+ tns.dirty = true;
if (tns.sel >= tns.cnt)
tns.sel = tns.cnt - 1;
}
}
- return 1;
+ return true;
}
-int it_remove_image(arg_t a) {
+bool it_remove_image(arg_t a) {
if (mode == MODE_IMAGE) {
- remove_file(fileidx, 1);
+ remove_file(fileidx, true);
load_image(fileidx >= filecnt ? filecnt - 1 : fileidx);
- return 1;
+ return true;
} else if (tns.sel < tns.cnt) {
- remove_file(tns.sel, 1);
- tns.dirty = 1;
+ remove_file(tns.sel, true);
+ tns.dirty = true;
if (tns.sel >= tns.cnt)
tns.sel = tns.cnt - 1;
- return 1;
+ return true;
} else {
- return 0;
+ return false;
}
}
-int i_navigate(arg_t a) {
+bool i_navigate(arg_t a) {
long n = (long) a;
if (mode == MODE_IMAGE) {
@@ -125,86 +124,83 @@ int i_navigate(arg_t a) {
if (n != fileidx) {
load_image(n);
- return 1;
+ return true;
}
}
- return 0;
+ return false;
}
-int it_first(arg_t a) {
+bool it_first(arg_t a) {
if (mode == MODE_IMAGE && fileidx != 0) {
load_image(0);
- return 1;
+ return true;
} else if (mode == MODE_THUMB && tns.sel != 0) {
tns.sel = 0;
- tns.dirty = 1;
- return 1;
+ tns.dirty = true;
+ return true;
} else {
- return 0;
+ return false;
}
}
-int it_last(arg_t a) {
+bool it_last(arg_t a) {
if (mode == MODE_IMAGE && fileidx != filecnt - 1) {
load_image(filecnt - 1);
- return 1;
+ return true;
} else if (mode == MODE_THUMB && tns.sel != tns.cnt - 1) {
tns.sel = tns.cnt - 1;
- tns.dirty = 1;
- return 1;
+ tns.dirty = true;
+ return true;
} else {
- return 0;
+ return false;
}
}
-int i_navigate_frame(arg_t a) {
+bool i_navigate_frame(arg_t a) {
if (mode == MODE_IMAGE && !img.multi.animate)
return img_frame_navigate(&img, (long) a);
else
- return 0;
+ return false;
}
-int i_toggle_animation(arg_t a) {
- int delay;
-
+bool i_toggle_animation(arg_t a) {
if (mode != MODE_IMAGE)
- return 0;
+ return false;
if (img.multi.animate) {
reset_timeout(animate);
- img.multi.animate = 0;
- } else {
- delay = img_frame_animate(&img, 1);
- set_timeout(animate, delay, 1);
+ img.multi.animate = false;
+ } else if (img_frame_animate(&img, true)) {
+ set_timeout(animate, img.multi.frames[img.multi.sel].delay, true);
}
- return 1;
+ return true;
}
-int it_move(arg_t a) {
+bool it_move(arg_t a) {
direction_t dir = (direction_t) a;
if (mode == MODE_IMAGE)
- return img_pan(&img, &win, dir, 0);
+ return img_pan(&img, &win, dir, false);
else
return tns_move_selection(&tns, &win, dir);
}
-int i_pan_screen(arg_t a) {
+bool i_pan_screen(arg_t a) {
direction_t dir = (direction_t) a;
if (mode == MODE_IMAGE)
- return img_pan(&img, &win, dir, 1);
+ return img_pan(&img, &win, dir, true);
else
- return 0;
+ return false;
}
-int i_pan_edge(arg_t a) {
+bool i_pan_edge(arg_t a) {
direction_t dir = (direction_t) a;
if (mode == MODE_IMAGE)
return img_pan_edge(&img, &win, dir);
else
- return 0;
+ return false;
}
/* Xlib helper function for i_drag() */
@@ -212,17 +208,17 @@ Bool is_motionnotify(Display *d, XEvent *e, XPointer a) {
return e != NULL && e->type == MotionNotify;
}
-int i_drag(arg_t a) {
+bool i_drag(arg_t a) {
int dx = 0, dy = 0, i, ox, oy, x, y;
unsigned int ui;
- Bool dragging = True, next = False;
+ bool dragging = true, next = false;
XEvent e;
Window w;
if (mode != MODE_IMAGE)
- return 0;
+ return false;
if (!XQueryPointer(win.env.dpy, win.xwin, &w, &w, &i, &i, &ox, &oy, &ui))
- return 0;
+ return false;
win_set_cursor(&win, CURSOR_HAND);
@@ -233,7 +229,7 @@ int i_drag(arg_t a) {
switch (e.type) {
case ButtonPress:
case ButtonRelease:
- dragging = False;
+ dragging = false;
break;
case MotionNotify:
x = e.xmotion.x;
@@ -256,17 +252,17 @@ int i_drag(arg_t a) {
}
win_set_cursor(&win, CURSOR_ARROW);
- set_timeout(reset_cursor, TO_CURSOR_HIDE, 1);
+ set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
reset_timeout(redraw);
- return 0;
+ return false;
}
-int i_zoom(arg_t a) {
+bool i_zoom(arg_t a) {
long scale = (long) a;
if (mode != MODE_IMAGE)
- return 0;
+ return false;
if (scale > 0)
return img_zoom_in(&img, &win);
@@ -276,21 +272,22 @@ int i_zoom(arg_t a) {
return img_zoom(&img, &win, 1.0);
}
-int i_fit_to_win(arg_t a) {
- int ret;
+bool i_fit_to_win(arg_t a) {
+ bool ret;
if (mode == MODE_IMAGE) {
if ((ret = img_fit_win(&img, &win)))
img_center(&img, &win);
return ret;
} else {
- return 0;
+ return false;
}
}
-int i_fit_to_img(arg_t a) {
- int ret, x, y;
+bool i_fit_to_img(arg_t a) {
+ int x, y;
unsigned int w, h;
+ bool ret;
if (mode == MODE_IMAGE) {
x = MAX(0, win.x + img.x);
@@ -303,90 +300,91 @@ int i_fit_to_img(arg_t a) {
}
return ret;
} else {
- return 0;
+ return false;
}
}
-int i_rotate(arg_t a) {
+bool i_rotate(arg_t a) {
direction_t dir = (direction_t) a;
if (mode == MODE_IMAGE) {
if (dir == DIR_LEFT) {
img_rotate_left(&img, &win);
- return 1;
+ return true;
} else if (dir == DIR_RIGHT) {
img_rotate_right(&img, &win);
- return 1;
+ return true;
}
}
- return 0;
+ return false;
}
-int i_toggle_slideshow(arg_t a) {
+bool i_toggle_slideshow(arg_t a) {
if (mode == MODE_IMAGE) {
if (img.slideshow) {
- img.slideshow = 0;
+ img.slideshow = false;
reset_timeout(slideshow);
- return 1;
+ return true;
} else if (fileidx + 1 < filecnt) {
- img.slideshow = 1;
- set_timeout(slideshow, img.ss_delay, 1);
- return 1;
+ img.slideshow = true;
+ set_timeout(slideshow, img.ss_delay, true);
+ return true;
}
}
- return 0;
+ return false;
}
-int i_adjust_slideshow(arg_t a) {
+bool i_adjust_slideshow(arg_t a) {
long d = (long) a;
int i, delays[] = { 1, 2, 3, 5, 10, 15, 20, 30, 60, 120, 180, 300, 600 };
if (mode != MODE_IMAGE || !img.slideshow)
- return 0;
+ return false;
if (d < 0) {
for (i = ARRLEN(delays) - 2; i >= 0; i--) {
if (img.ss_delay > delays[i] * 1000) {
img.ss_delay = delays[i] * 1000;
- return 1;
+ return true;
}
}
} else {
for (i = 1; i < ARRLEN(delays); i++) {
if (img.ss_delay < delays[i] * 1000) {
img.ss_delay = delays[i] * 1000;
- return 1;
+ return true;
}
}
}
- return 0;
+ return false;
}
-int i_toggle_antialias(arg_t a) {
+bool i_toggle_antialias(arg_t a) {
if (mode == MODE_IMAGE) {
img_toggle_antialias(&img);
- return 1;
+ return true;
} else {
- return 0;
+ return false;
}
}
-int it_toggle_alpha(arg_t a) {
- img.alpha ^= 1;
- tns.alpha = img.alpha;
- if (mode == MODE_THUMB)
- tns.dirty = 1;
- return 1;
+bool it_toggle_alpha(arg_t a) {
+ img.alpha = tns.alpha = !img.alpha;
+ if (mode == MODE_IMAGE)
+ img.dirty = true;
+ else
+ tns.dirty = true;
+ return true;
}
-int it_open_with(arg_t a) {
+bool it_open_with(arg_t a) {
const char *prog = (const char*) a;
pid_t pid;
if (!prog || !*prog)
- return 0;
+ return false;
- if((pid = fork()) == 0) {
+ if ((pid = fork()) == 0) {
execlp(prog, prog,
files[mode == MODE_IMAGE ? fileidx : tns.sel].path, NULL);
warn("could not exec: %s", prog);
@@ -395,10 +393,10 @@ int it_open_with(arg_t a) {
warn("could not fork. program was: %s", prog);
}
- return 0;
+ return false;
}
-int it_shell_cmd(arg_t a) {
+bool it_shell_cmd(arg_t a) {
int n, status;
const char *cmdline = (const char*) a;
pid_t pid;
@@ -411,7 +409,7 @@ int it_shell_cmd(arg_t a) {
if (setenv("SXIV_IMG", files[n].path, 1) < 0) {
warn("could not set env.-variable: SXIV_IMG. command line was: %s",
cmdline);
- return 0;
+ return false;
}
if ((pid = fork()) == 0) {
@@ -420,7 +418,7 @@ int it_shell_cmd(arg_t a) {
exit(1);
} else if (pid < 0) {
warn("could not fork. command line was: %s", cmdline);
- return 0;
+ return false;
}
win_set_cursor(&win, CURSOR_WATCH);
@@ -431,17 +429,17 @@ int it_shell_cmd(arg_t a) {
WEXITSTATUS(status), cmdline);
if (mode == MODE_IMAGE) {
- img_close(&img, 1);
+ img_close(&img, true);
load_image(fileidx);
}
- if (!tns_load(&tns, n, &files[n], True, mode == MODE_IMAGE) &&
+ if (!tns_load(&tns, n, &files[n], true, mode == MODE_IMAGE) &&
mode == MODE_THUMB)
{
- remove_file(tns.sel, 0);
- tns.dirty = 1;
+ remove_file(tns.sel, false);
+ tns.dirty = true;
if (tns.sel >= tns.cnt)
tns.sel = tns.cnt - 1;
}
- return 1;
+ return true;
}
diff --git a/commands.h b/commands.h
index e038246..2609754 100644
--- a/commands.h
+++ b/commands.h
@@ -21,47 +21,49 @@
#include <X11/Xlib.h>
+#include "types.h"
+
typedef void* arg_t;
-typedef int (*command_f)(arg_t);
+typedef bool (*command_f)(arg_t);
typedef struct {
- Bool ctrl;
+ bool ctrl;
KeySym ksym;
command_f cmd;
arg_t arg;
} keymap_t;
typedef struct {
- Bool ctrl;
- Bool shift;
+ bool ctrl;
+ bool shift;
unsigned int button;
command_f cmd;
arg_t arg;
} button_t;
-int it_quit(arg_t);
-int it_switch_mode(arg_t);
-int it_toggle_fullscreen(arg_t);
-int it_reload_image(arg_t);
-int it_remove_image(arg_t);
-int i_navigate(arg_t);
-int it_first(arg_t);
-int it_last(arg_t);
-int i_navigate_frame(arg_t);
-int i_toggle_animation(arg_t);
-int it_move(arg_t);
-int i_pan_screen(arg_t);
-int i_pan_edge(arg_t);
-int i_drag(arg_t);
-int i_zoom(arg_t);
-int i_fit_to_win(arg_t);
-int i_fit_to_img(arg_t);
-int i_rotate(arg_t);
-int i_toggle_slideshow(arg_t);
-int i_adjust_slideshow(arg_t);
-int i_toggle_antialias(arg_t);
-int it_toggle_alpha(arg_t);
-int it_open_with(arg_t);
-int it_shell_cmd(arg_t);
+bool it_quit(arg_t);
+bool it_switch_mode(arg_t);
+bool it_toggle_fullscreen(arg_t);
+bool it_reload_image(arg_t);
+bool it_remove_image(arg_t);
+bool i_navigate(arg_t);
+bool it_first(arg_t);
+bool it_last(arg_t);
+bool i_navigate_frame(arg_t);
+bool i_toggle_animation(arg_t);
+bool it_move(arg_t);
+bool i_pan_screen(arg_t);
+bool i_pan_edge(arg_t);
+bool i_drag(arg_t);
+bool i_zoom(arg_t);
+bool i_fit_to_win(arg_t);
+bool i_fit_to_img(arg_t);
+bool i_rotate(arg_t);
+bool i_toggle_slideshow(arg_t);
+bool i_adjust_slideshow(arg_t);
+bool i_toggle_antialias(arg_t);
+bool it_toggle_alpha(arg_t);
+bool it_open_with(arg_t);
+bool it_shell_cmd(arg_t);
#endif /* COMMANDS_H */
diff --git a/config.def.h b/config.def.h
index 50cecb8..022bf9a 100644
--- a/config.def.h
+++ b/config.def.h
@@ -51,96 +51,96 @@ enum { THUMB_SIZE = 60 };
/* keyboard mappings for image and thumbnail mode: */
static const keymap_t keys[] = {
/* ctrl key function argument */
- { False, XK_q, it_quit, (arg_t) None },
- { False, XK_Return, it_switch_mode, (arg_t) None },
- { False, XK_f, it_toggle_fullscreen, (arg_t) None },
-
- { False, XK_r, it_reload_image, (arg_t) None },
- { False, XK_D, it_remove_image, (arg_t) None },
-
- { False, XK_n, i_navigate, (arg_t) +1 },
- { False, XK_space, i_navigate, (arg_t) +1 },
- { False, XK_p, i_navigate, (arg_t) -1 },
- { False, XK_BackSpace, i_navigate, (arg_t) -1 },
- { False, XK_bracketright, i_navigate, (arg_t) +10 },
- { False, XK_bracketleft, i_navigate, (arg_t) -10 },
- { False, XK_g, it_first, (arg_t) None },
- { False, XK_G, it_last, (arg_t) None },
-
- { True, XK_n, i_navigate_frame, (arg_t) +1 },
- { True, XK_p, i_navigate_frame, (arg_t) -1 },
- { True, XK_space, i_toggle_animation, (arg_t) None },
-
- { False, XK_h, it_move, (arg_t) DIR_LEFT },
- { False, XK_Left, it_move, (arg_t) DIR_LEFT },
- { False, XK_j, it_move, (arg_t) DIR_DOWN },
- { False, XK_Down, it_move, (arg_t) DIR_DOWN },
- { False, XK_k, it_move, (arg_t) DIR_UP },
- { False, XK_Up, it_move, (arg_t) DIR_UP },
- { False, XK_l, it_move, (arg_t) DIR_RIGHT },
- { False, XK_Right, it_move, (arg_t) DIR_RIGHT },
-
- { True, XK_h, i_pan_screen, (arg_t) DIR_LEFT },
- { True, XK_Left, i_pan_screen, (arg_t) DIR_LEFT },
- { True, XK_j, i_pan_screen, (arg_t) DIR_DOWN },
- { True, XK_Down, i_pan_screen, (arg_t) DIR_DOWN },
- { True, XK_k, i_pan_screen, (arg_t) DIR_UP },
- { True, XK_Up, i_pan_screen, (arg_t) DIR_UP },
- { True, XK_l, i_pan_screen, (arg_t) DIR_RIGHT },
- { True, XK_Right, i_pan_screen, (arg_t) DIR_RIGHT },
-
- { False, XK_H, i_pan_edge, (arg_t) DIR_LEFT },
- { False, XK_J, i_pan_edge, (arg_t) DIR_DOWN },
- { False, XK_K, i_pan_edge, (arg_t) DIR_UP },
- { False, XK_L, i_pan_edge, (arg_t) DIR_RIGHT },
-
- { False, XK_plus, i_zoom, (arg_t) +1 },
- { False, XK_equal, i_zoom, (arg_t) +1 },
- { False, XK_KP_Add, i_zoom, (arg_t) +1 },
- { False, XK_minus, i_zoom, (arg_t) -1 },
- { False, XK_KP_Subtract, i_zoom, (arg_t) -1 },
- { False, XK_0, i_zoom, (arg_t) None },
- { False, XK_KP_0, i_zoom, (arg_t) None },
- { False, XK_w, i_fit_to_win, (arg_t) None },
- { False, XK_W, i_fit_to_img, (arg_t) None },
-
- { False, XK_less, i_rotate, (arg_t) DIR_LEFT },
- { False, XK_greater, i_rotate, (arg_t) DIR_RIGHT },
-
- { False, XK_s, i_toggle_slideshow, (arg_t) None },
- { True, XK_plus, i_adjust_slideshow, (arg_t) +1 },
- { True, XK_equal, i_adjust_slideshow, (arg_t) +1 },
- { True, XK_minus, i_adjust_slideshow, (arg_t) -1 },
-
- { False, XK_a, i_toggle_antialias, (arg_t) None },
- { False, XK_A, it_toggle_alpha, (arg_t) None },
+ { false, XK_q, it_quit, (arg_t) None },
+ { false, XK_Return, it_switch_mode, (arg_t) None },
+ { false, XK_f, it_toggle_fullscreen, (arg_t) None },
+
+ { false, XK_r, it_reload_image, (arg_t) None },
+ { false, XK_D, it_remove_image, (arg_t) None },
+
+ { false, XK_n, i_navigate, (arg_t) +1 },
+ { false, XK_space, i_navigate, (arg_t) +1 },
+ { false, XK_p, i_navigate, (arg_t) -1 },
+ { false, XK_BackSpace, i_navigate, (arg_t) -1 },
+ { false, XK_bracketright, i_navigate, (arg_t) +10 },
+ { false, XK_bracketleft, i_navigate, (arg_t) -10 },
+ { false, XK_g, it_first, (arg_t) None },
+ { false, XK_G, it_last, (arg_t) None },
+
+ { true, XK_n, i_navigate_frame, (arg_t) +1 },
+ { true, XK_p, i_navigate_frame, (arg_t) -1 },
+ { true, XK_space, i_toggle_animation, (arg_t) None },
+
+ { false, XK_h, it_move, (arg_t) DIR_LEFT },
+ { false, XK_Left, it_move, (arg_t) DIR_LEFT },
+ { false, XK_j, it_move, (arg_t) DIR_DOWN },
+ { false, XK_Down, it_move, (arg_t) DIR_DOWN },
+ { false, XK_k, it_move, (arg_t) DIR_UP },
+ { false, XK_Up, it_move, (arg_t) DIR_UP },
+ { false, XK_l, it_move, (arg_t) DIR_RIGHT },
+ { false, XK_Right, it_move, (arg_t) DIR_RIGHT },
+
+ { true, XK_h, i_pan_screen, (arg_t) DIR_LEFT },
+ { true, XK_Left, i_pan_screen, (arg_t) DIR_LEFT },
+ { true, XK_j, i_pan_screen, (arg_t) DIR_DOWN },
+ { true, XK_Down, i_pan_screen, (arg_t) DIR_DOWN },
+ { true, XK_k, i_pan_screen, (arg_t) DIR_UP },
+ { true, XK_Up, i_pan_screen, (arg_t) DIR_UP },
+ { true, XK_l, i_pan_screen, (arg_t) DIR_RIGHT },
+ { true, XK_Right, i_pan_screen, (arg_t) DIR_RIGHT },
+
+ { false, XK_H, i_pan_edge, (arg_t) DIR_LEFT },
+ { false, XK_J, i_pan_edge, (arg_t) DIR_DOWN },
+ { false, XK_K, i_pan_edge, (arg_t) DIR_UP },
+ { false, XK_L, i_pan_edge, (arg_t) DIR_RIGHT },
+
+ { false, XK_plus, i_zoom, (arg_t) +1 },
+ { false, XK_equal, i_zoom, (arg_t) +1 },
+ { false, XK_KP_Add, i_zoom, (arg_t) +1 },
+ { false, XK_minus, i_zoom, (arg_t) -1 },
+ { false, XK_KP_Subtract, i_zoom, (arg_t) -1 },
+ { false, XK_0, i_zoom, (arg_t) None },
+ { false, XK_KP_0, i_zoom, (arg_t) None },
+ { false, XK_w, i_fit_to_win, (arg_t) None },
+ { false, XK_W, i_fit_to_img, (arg_t) None },
+
+ { false, XK_less, i_rotate, (arg_t) DIR_LEFT },
+ { false, XK_greater, i_rotate, (arg_t) DIR_RIGHT },
+
+ { false, XK_s, i_toggle_slideshow, (arg_t) None },
+ { true, XK_plus, i_adjust_slideshow, (arg_t) +1 },
+ { true, XK_equal, i_adjust_slideshow, (arg_t) +1 },
+ { true, XK_minus, i_adjust_slideshow, (arg_t) -1 },
+
+ { false, XK_a, i_toggle_antialias, (arg_t) None },
+ { false, XK_A, it_toggle_alpha, (arg_t) None },
/* open current image with given program: */
- { True, XK_g, it_open_with, (arg_t) "gimp" },
+ { true, XK_g, it_open_with, (arg_t) "gimp" },
/* run shell command line on current file ("$SXIV_IMG"): */
- { True, XK_less, it_shell_cmd, (arg_t) \
+ { true, XK_less, it_shell_cmd, (arg_t) \
"mogrify -rotate -90 \"$SXIV_IMG\"" },
- { True, XK_greater, it_shell_cmd, (arg_t) \
+ { true, XK_greater, it_shell_cmd, (arg_t) \
"mogrify -rotate +90 \"$SXIV_IMG\"" },
- { True, XK_comma, it_shell_cmd, (arg_t) \
+ { true, XK_comma, it_shell_cmd, (arg_t) \
"jpegtran -rotate 270 -copy all -outfile \"$SXIV_IMG\" \"$SXIV_IMG\"" },
- { True, XK_period, it_shell_cmd, (arg_t) \
+ { true, XK_period, it_shell_cmd, (arg_t) \
"jpegtran -rotate 90 -copy all -outfile \"$SXIV_IMG\" \"$SXIV_IMG\"" },
};
/* mouse button mappings for image mode: */
static const button_t buttons[] = {
/* ctrl shift button function argument */
- { False, False, Button1, i_navigate, (arg_t) +1 },
- { False, False, Button3, i_navigate, (arg_t) -1 },
- { False, False, Button2, i_drag, (arg_t) None },
- { False, False, Button4, it_move, (arg_t) DIR_UP },
- { False, False, Button5, it_move, (arg_t) DIR_DOWN },
- { False, True, Button4, it_move, (arg_t) DIR_LEFT },
- { False, True, Button5, it_move, (arg_t) DIR_RIGHT },
- { True, False, Button4, i_zoom, (arg_t) +1 },
- { True, False, Button5, i_zoom, (arg_t) -1 },
+ { false, false, Button1, i_navigate, (arg_t) +1 },
+ { false, false, Button3, i_navigate, (arg_t) -1 },
+ { false, false, Button2, i_drag, (arg_t) None },
+ { false, false, Button4, it_move, (arg_t) DIR_UP },
+ { false, false, Button5, it_move, (arg_t) DIR_DOWN },
+ { false, true, Button4, it_move, (arg_t) DIR_LEFT },
+ { false, true, Button5, it_move, (arg_t) DIR_RIGHT },
+ { true, false, Button4, i_zoom, (arg_t) +1 },
+ { true, false, Button5, i_zoom, (arg_t) -1 },
};
#endif
diff --git a/image.c b/image.c
index fd6585b..8b4ff49 100644
--- a/image.c
+++ b/image.c
@@ -51,15 +51,15 @@ void img_init(img_t *img, win_t *win) {
if (img) {
img->im = NULL;
img->multi.cap = img->multi.cnt = 0;
- img->multi.animate = 0;
+ img->multi.animate = false;
img->zoom = options->zoom;
img->zoom = MAX(img->zoom, zoom_min);
img->zoom = MIN(img->zoom, zoom_max);
- img->checkpan = 0;
- img->dirty = 0;
+ img->checkpan = false;
+ img->dirty = false;
img->aa = options->aa;
- img->alpha = 1;
- img->slideshow = 0;
+ img->alpha = true;
+ img->slideshow = false;
img->ss_delay = SLIDESHOW_DELAY * 1000;
}
@@ -119,7 +119,7 @@ void exif_auto_orientate(const fileinfo_t *file) {
/* Originally based on, but in its current form merely inspired by Imlib2's
* src/modules/loaders/loader_gif.c:load(), written by Carsten Haitzler.
*/
-int img_load_gif(img_t *img, const fileinfo_t *file) {
+bool img_load_gif(img_t *img, const fileinfo_t *file) {
GifFileType *gif;
GifRowType *rows = NULL;
GifRecordType rec;
@@ -131,8 +131,9 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
int x, y, w, h, sw, sh;
int intoffset[] = { 0, 4, 2, 1 };
int intjump[] = { 8, 8, 4, 2 };
- int err = 0, transp = -1;
+ int transp = -1;
unsigned int delay = 0;
+ bool err = false;
if (img->multi.cap == 0) {
img->multi.cap = 8;
@@ -145,7 +146,7 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
gif = DGifOpenFileName(file->path);
if (!gif) {
warn("could not open gif file: %s", file->name);
- return 0;
+ return false;
}
bg = gif->SBackGroundColor;
sw = gif->SWidth;
@@ -153,7 +154,7 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
do {
if (DGifGetRecordType(gif, &rec) == GIF_ERROR) {
- err = 1;
+ err = true;
break;
}
if (rec == EXTENSION_RECORD_TYPE) {
@@ -177,7 +178,7 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
}
} else if (rec == IMAGE_DESC_RECORD_TYPE) {
if (DGifGetImageDesc(gif) == GIF_ERROR) {
- err = 1;
+ err = true;
break;
}
x = gif->Image.Left;
@@ -235,7 +236,7 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
free(data);
if (!im) {
- err = 1;
+ err = true;
break;
}
@@ -272,7 +273,7 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
imlib_context_set_image(img->multi.frames[0].im);
imlib_free_image();
img->multi.cnt = 0;
- img->multi.animate = 0;
+ img->multi.animate = false;
}
imlib_context_set_image(img->im);
@@ -281,15 +282,15 @@ int img_load_gif(img_t *img, const fileinfo_t *file) {
}
#endif /* GIF_SUPPORT */
-int img_load(img_t *img, const fileinfo_t *file) {
+bool img_load(img_t *img, const fileinfo_t *file) {
const char *fmt;
if (!img || !file || !file->name || !file->path)
- return 0;
+ return false;
if (access(file->path, R_OK) || !(img->im = imlib_load_image(file->path))) {
warn("could not open image: %s", file->name);
- return 0;
+ return false;
}
imlib_context_set_image(img->im);
@@ -310,17 +311,17 @@ int img_load(img_t *img, const fileinfo_t *file) {
#endif
img->scalemode = options->scalemode;
- img->re = 0;
- img->checkpan = 0;
+ img->re = false;
+ img->checkpan = false;
+ img->dirty = true;
img->w = imlib_image_get_width();
img->h = imlib_image_get_height();
- img->dirty = 1;
- return 1;
+ return true;
}
-void img_close(img_t *img, int decache) {
+void img_close(img_t *img, bool decache) {
int i;
if (!img)
@@ -343,7 +344,7 @@ void img_close(img_t *img, int decache) {
}
}
-void img_check_pan(img_t *img, win_t *win, int moved) {
+void img_check_pan(img_t *img, win_t *win, bool moved) {
int ox, oy;
if (!img || !win)
@@ -370,14 +371,14 @@ void img_check_pan(img_t *img, win_t *win, int moved) {
}
if (!moved && (ox != img->x || oy != img->y))
- img->dirty = 1;
+ img->dirty = true;
}
-int img_fit(img_t *img, win_t *win) {
+bool img_fit(img_t *img, win_t *win) {
float z, zmax, zw, zh;
if (!img || !win || img->scalemode == SCALE_ZOOM)
- return 0;
+ return false;
zmax = img->scalemode == SCALE_DOWN ? 1.0 : zoom_max;
zw = (float) win->w / (float) img->w;
@@ -389,10 +390,10 @@ int img_fit(img_t *img, win_t *win) {
if (ZOOMDIFF(z, img->zoom)) {
img->zoom = z;
- img->dirty = 1;
- return 1;
+ img->dirty = true;
+ return true;
} else {
- return 0;
+ return false;
}
}
@@ -407,7 +408,7 @@ void img_render(img_t *img, win_t *win) {
if (!img->re) {
/* rendered for the first time */
- img->re = 1;
+ img->re = true;
if (img->zoom * img->w <= win->w)
img->x = (win->w - img->w * img->zoom) / 2;
else
@@ -419,8 +420,8 @@ void img_render(img_t *img, win_t *win) {
}
if (img->checkpan) {
- img_check_pan(img, win, 0);
- img->checkpan = 0;
+ img_check_pan(img, win, false);
+ img->checkpan = false;
}
if (!img->dirty)
@@ -462,22 +463,22 @@ void img_render(img_t *img, win_t *win) {
win_draw(win);
- img->dirty = 0;
+ img->dirty = false;
}
-int img_fit_win(img_t *img, win_t *win) {
+bool img_fit_win(img_t *img, win_t *win) {
if (!img || !img->im || !win)
- return 0;
+ return false;
img->scalemode = SCALE_FIT;
return img_fit(img, win);
}
-int img_center(img_t *img, win_t *win) {
+bool img_center(img_t *img, win_t *win) {
int ox, oy;
if (!img || !win)
- return 0;
+ return false;
ox = img->x;
oy = img->y;
@@ -486,16 +487,16 @@ int img_center(img_t *img, win_t *win) {
img->y = (win->h - img->h * img->zoom) / 2;
if (ox != img->x || oy != img->y) {
- img->dirty = 1;
- return 1;
+ img->dirty = true;
+ return true;
} else {
- return 0;
+ return false;
}
}
-int img_zoom(img_t *img, win_t *win, float z) {
+bool img_zoom(img_t *img, win_t *win, float z) {
if (!img || !img->im || !win)
- return 0;
+ return false;
z = MAX(z, zoom_min);
z = MIN(z, zoom_max);
@@ -506,45 +507,45 @@ int img_zoom(img_t *img, win_t *win, float z) {
img->x = win->w / 2 - (win->w / 2 - img->x) * z / img->zoom;
img->y = win->h / 2 - (win->h / 2 - img->y) * z / img->zoom;
img->zoom = z;
- img->checkpan = 1;
- img->dirty = 1;
- return 1;
+ img->checkpan = true;
+ img->dirty = true;
+ return true;
} else {
- return 0;
+ return false;
}
}
-int img_zoom_in(img_t *img, win_t *win) {
+bool img_zoom_in(img_t *img, win_t *win) {
int i;
if (!img || !img->im || !win)
- return 0;
+ return false;
for (i = 1; i < ARRLEN(zoom_levels); i++) {
if (zoom_levels[i] > img->zoom * 100.0)
return img_zoom(img, win, zoom_levels[i] / 100.0);
}
- return 0;
+ return false;
}
-int img_zoom_out(img_t *img, win_t *win) {
+bool img_zoom_out(img_t *img, win_t *win) {
int i;
if (!img || !img->im || !win)
- return 0;
+ return false;
for (i = ARRLEN(zoom_levels) - 2; i >= 0; i--) {
if (zoom_levels[i] < img->zoom * 100.0)
return img_zoom(img, win, zoom_levels[i] / 100.0);
}
- return 0;
+ return false;
}
-int img_move(img_t *img, win_t *win, int dx, int dy) {
+bool img_move(img_t *img, win_t *win, int dx, int dy) {
int ox, oy;
if (!img || !img->im || !win)
- return 0;
+ return false;
ox = img->x;
oy = img->y;
@@ -552,19 +553,19 @@ int img_move(img_t *img, win_t *win, int dx, int dy) {
img->x += dx;
img->y += dy;
- img_check_pan(img, win, 1);
+ img_check_pan(img, win, true);
if (ox != img->x || oy != img->y) {
- img->dirty = 1;
- return 1;
+ img->dirty = true;
+ return true;
} else {
- return 0;
+ return false;
}
}
-int img_pan(img_t *img, win_t *win, direction_t dir, int screen) {
+bool img_pan(img_t *img, win_t *win, direction_t dir, bool screen) {
if (!img || !img->im || !win)
- return 0;
+ return false;
switch (dir) {
case DIR_LEFT:
@@ -576,14 +577,14 @@ int img_pan(img_t *img, win_t *win, direction_t dir, int screen) {
case DIR_DOWN:
return img_move(img, win, 0, win->h / (screen ? 1 : 5) * -1);
}
- return 0;
+ return false;
}
-int img_pan_edge(img_t *img, win_t *win, direction_t dir) {
+bool img_pan_edge(img_t *img, win_t *win, direction_t dir) {
int ox, oy;
if (!img || !img->im || !win)
- return 0;
+ return false;
ox = img->x;
oy = img->y;
@@ -603,13 +604,13 @@ int img_pan_edge(img_t *img, win_t *win, direction_t dir) {
break;
}
- img_check_pan(img, win, 1);
+ img_check_pan(img, win, true);
if (ox != img->x || oy != img->y) {
- img->dirty = 1;
- return 1;
+ img->dirty = true;
+ return true;
} else {
- return 0;
+ return false;
}
}
@@ -632,8 +633,8 @@ void img_rotate(img_t *img, win_t *win, int d) {
img->w = img->h;
img->h = tmp;
- img->checkpan = 1;
- img->dirty = 1;
+ img->checkpan = true;
+ img->dirty = true;
}
void img_rotate_left(img_t *img, win_t *win) {
@@ -648,18 +649,18 @@ void img_toggle_antialias(img_t *img) {
if (!img || !img->im)
return;
- img->aa ^= 1;
+ img->aa = !img->aa;
imlib_context_set_image(img->im);
imlib_context_set_anti_alias(img->aa);
- img->dirty = 1;
+ img->dirty = true;
}
-int img_frame_goto(img_t *img, int n) {
+bool img_frame_goto(img_t *img, int n) {
if (!img || n < 0 || n >= img->multi.cnt)
- return 0;
+ return false;
if (n == img->multi.sel)
- return 0;
+ return false;
img->multi.sel = n;
img->im = img->multi.frames[n].im;
@@ -667,15 +668,15 @@ int img_frame_goto(img_t *img, int n) {
imlib_context_set_image(img->im);
img->w = imlib_image_get_width();
img->h = imlib_image_get_height();
- img->checkpan = 1;
- img->dirty = 1;
+ img->checkpan = true;
+ img->dirty = true;
- return 1;
+ return true;
}
-int img_frame_navigate(img_t *img, int d) {
+bool img_frame_navigate(img_t *img, int d) {
if (!img || !img->multi.cnt || !d)
- return 0;
+ return false;
d += img->multi.sel;
if (d < 0)
@@ -686,22 +687,22 @@ int img_frame_navigate(img_t *img, int d) {
return img_frame_goto(img, d);
}
-int img_frame_animate(img_t *img, int restart) {
+bool img_frame_animate(img_t *img, bool restart) {
if (!img || !img->multi.cnt)
- return 0;
+ return false;
if (img->multi.sel + 1 >= img->multi.cnt) {
if (restart || (GIF_LOOP && !img->slideshow)) {
img_frame_goto(img, 0);
} else {
- img->multi.animate = 0;
- return 0;
+ img->multi.animate = false;
+ return false;
}
} else if (!restart) {
img_frame_goto(img, img->multi.sel + 1);
}
- img->multi.animate = 1;
+ img->multi.animate = true;
+ img->dirty = true;
- img->dirty = 1;
- return img->multi.frames[img->multi.sel].delay;
+ return true;
}
diff --git a/image.h b/image.h
index ca699c8..316729a 100644
--- a/image.h
+++ b/image.h
@@ -34,7 +34,7 @@ typedef struct {
int cap;
int cnt;
int sel;
- unsigned char animate;
+ bool animate;
} multi_img_t;
typedef struct {
@@ -44,13 +44,13 @@ typedef struct {
float zoom;
scalemode_t scalemode;
- unsigned char re;
- unsigned char checkpan;
- unsigned char dirty;
- unsigned char aa;
- unsigned char alpha;
+ bool re;
+ bool checkpan;
+ bool dirty;
+ bool aa;
+ bool alpha;
- unsigned char slideshow;
+ bool slideshow;
int ss_delay; /* in ms */
int x;
@@ -61,28 +61,28 @@ typedef struct {
void img_init(img_t*, win_t*);
-int img_load(img_t*, const fileinfo_t*);
-void img_close(img_t*, int);
+bool img_load(img_t*, const fileinfo_t*);
+void img_close(img_t*, bool);
void img_render(img_t*, win_t*);
-int img_fit_win(img_t*, win_t*);
-int img_center(img_t*, win_t*);
+bool img_fit_win(img_t*, win_t*);
+bool img_center(img_t*, win_t*);
-int img_zoom(img_t*, win_t*, float);
-int img_zoom_in(img_t*, win_t*);
-int img_zoom_out(img_t*, win_t*);
+bool img_zoom(img_t*, win_t*, float);
+bool img_zoom_in(img_t*, win_t*);
+bool img_zoom_out(img_t*, win_t*);
-int img_move(img_t*, win_t*, int, int);
-int img_pan(img_t*, win_t*, direction_t, int);
-int img_pan_edge(img_t*, win_t*, direction_t);
+bool img_move(img_t*, win_t*, int, int);
+bool img_pan(img_t*, win_t*, direction_t, bool);
+bool img_pan_edge(img_t*, win_t*, direction_t);
void img_rotate_left(img_t*, win_t*);
void img_rotate_right(img_t*, win_t*);
void img_toggle_antialias(img_t*);
-int img_frame_navigate(img_t*, int);
-int img_frame_animate(img_t*, int);
+bool img_frame_navigate(img_t*, int);
+bool img_frame_animate(img_t*, bool);
#endif /* IMAGE_H */
diff --git a/main.c b/main.c
index c96a030..36bbb6d 100644
--- a/main.c
+++ b/main.c
@@ -17,6 +17,7 @@
*/
#define _POSIX_C_SOURCE 200112L
+#define _MAPPINGS_CONFIG
#include <stdlib.h>
#include <stdio.h>
@@ -34,8 +35,6 @@
#include "types.h"
#include "util.h"
#include "window.h"
-
-#define _MAPPINGS_CONFIG
#include "config.h"
enum {
@@ -45,7 +44,7 @@ enum {
typedef struct {
struct timeval when;
- Bool active;
+ bool active;
timeout_f handler;
} timeout_t;
@@ -67,17 +66,17 @@ size_t filesize;
char win_title[TITLE_LEN];
timeout_t timeouts[] = {
- { { 0, 0 }, False, redraw },
- { { 0, 0 }, False, reset_cursor },
- { { 0, 0 }, False, animate },
- { { 0, 0 }, False, slideshow },
+ { { 0, 0 }, false, redraw },
+ { { 0, 0 }, false, reset_cursor },
+ { { 0, 0 }, false, animate },
+ { { 0, 0 }, false, slideshow },
};
void cleanup() {
static int in = 0;
if (!in++) {
- img_close(&img, 0);
+ img_close(&img, false);
tns_free(&tns);
win_close(&win);
}
@@ -103,14 +102,14 @@ void check_add_file(char *filename) {
return;
}
}
- files[fileidx].loaded = 0;
+ files[fileidx].loaded = false;
files[fileidx].name = s_strdup(filename);
if (*filename == '/')
files[fileidx].path = files[fileidx].name;
fileidx++;
}
-void remove_file(int n, unsigned char silent) {
+void remove_file(int n, bool silent) {
if (n < 0 || n >= filecnt)
return;
@@ -138,7 +137,7 @@ void remove_file(int n, unsigned char silent) {
tns.cnt--;
}
-void set_timeout(timeout_f handler, int time, int overwrite) {
+void set_timeout(timeout_f handler, int time, bool overwrite) {
int i;
for (i = 0; i < ARRLEN(timeouts); i++) {
@@ -146,7 +145,7 @@ void set_timeout(timeout_f handler, int time, int overwrite) {
if (!timeouts[i].active || overwrite) {
gettimeofday(&timeouts[i].when, 0);
MSEC_ADD_TO_TIMEVAL(time, &timeouts[i].when);
- timeouts[i].active = True;
+ timeouts[i].active = true;
}
return;
}
@@ -158,13 +157,13 @@ void reset_timeout(timeout_f handler) {
for (i = 0; i < ARRLEN(timeouts); i++) {
if (timeouts[i].handler == handler) {
- timeouts[i].active = False;
+ timeouts[i].active = false;
return;
}
}
}
-int check_timeouts(struct timeval *t) {
+bool check_timeouts(struct timeval *t) {
int i = 0, tdiff, tmin = -1;
struct timeval now;
@@ -173,7 +172,7 @@ int check_timeouts(struct timeval *t) {
if (timeouts[i].active) {
tdiff = TIMEDIFF(&timeouts[i].when, &now);
if (tdiff <= 0) {
- timeouts[i].active = False;
+ timeouts[i].active = false;
if (timeouts[i].handler)
timeouts[i].handler();
i = tmin = -1;
@@ -196,14 +195,14 @@ void load_image(int new) {
win_set_cursor(&win, CURSOR_WATCH);
- img_close(&img, 0);
+ img_close(&img, false);
while (!img_load(&img, &files[new])) {
- remove_file(new, 0);
+ remove_file(new, false);
if (new >= filecnt)
new = filecnt - 1;
}
- files[new].loaded = 1;
+ files[new].loaded = true;
fileidx = new;
if (!stat(files[new].path, &fstats))
filesize = fstats.st_size;
@@ -211,7 +210,7 @@ void load_image(int new) {
filesize = 0;
if (img.multi.cnt && img.multi.animate)
- set_timeout(animate, img.multi.frames[img.multi.sel].delay, 1);
+ set_timeout(animate, img.multi.frames[img.multi.sel].delay, true);
else
reset_timeout(animate);
}
@@ -265,9 +264,9 @@ void redraw() {
img_render(&img, &win);
if (img.slideshow && !img.multi.animate) {
if (fileidx + 1 < filecnt)
- set_timeout(slideshow, img.ss_delay, 1);
+ set_timeout(slideshow, img.ss_delay, true);
else
- img.slideshow = 0;
+ img.slideshow = false;
}
} else {
tns_render(&tns, &win);
@@ -299,12 +298,10 @@ void reset_cursor() {
}
void animate() {
- int delay;
-
- delay = img_frame_animate(&img, 0);
- redraw();
- if (delay)
- set_timeout(animate, delay, 1);
+ if (img_frame_animate(&img, false)) {
+ redraw();
+ set_timeout(animate, img.multi.frames[img.multi.sel].delay, true);
+ }
}
void slideshow() {
@@ -313,16 +310,16 @@ void slideshow() {
load_image(fileidx + 1);
redraw();
} else {
- img.slideshow = 0;
+ img.slideshow = false;
}
}
}
-Bool keymask(const keymap_t *k, unsigned int state) {
+bool keymask(const keymap_t *k, unsigned int state) {
return (k->ctrl ? ControlMask : 0) == (state & ControlMask);
}
-Bool buttonmask(const button_t *b, unsigned int state) {
+bool buttonmask(const button_t *b, unsigned int state) {
return ((b->ctrl ? ControlMask : 0) | (b->shift ? ShiftMask : 0)) ==
(state & (ControlMask | ShiftMask));
}
@@ -354,7 +351,7 @@ void on_buttonpress(XButtonEvent *bev) {
if (mode == MODE_IMAGE) {
win_set_cursor(&win, CURSOR_ARROW);
- set_timeout(reset_cursor, TO_CURSOR_HIDE, 1);
+ set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
for (i = 0; i < ARRLEN(buttons); i++) {
if (buttons[i].button == bev->button &&
@@ -372,11 +369,11 @@ void on_buttonpress(XButtonEvent *bev) {
if ((sel = tns_translate(&tns, bev->x, bev->y)) >= 0) {
if (sel == tns.sel) {
mode = MODE_IMAGE;
- set_timeout(reset_cursor, TO_CURSOR_HIDE, 1);
+ set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
load_image(tns.sel);
} else {
- tns_highlight(&tns, &win, tns.sel, False);
- tns_highlight(&tns, &win, sel, True);
+ tns_highlight(&tns, &win, tns.sel, false);
+ tns_highlight(&tns, &win, sel, true);
tns.sel = sel;
}
redraw();
@@ -405,11 +402,11 @@ void run() {
!XPending(win.env.dpy))
{
/* load thumbnails */
- set_timeout(redraw, TO_REDRAW_THUMBS, 0);
- if (tns_load(&tns, tns.cnt, &files[tns.cnt], False, False))
+ set_timeout(redraw, TO_REDRAW_THUMBS, false);
+ if (tns_load(&tns, tns.cnt, &files[tns.cnt], false, false))
tns.cnt++;
else
- remove_file(tns.cnt, 0);
+ remove_file(tns.cnt, false);
if (tns.cnt == filecnt)
redraw();
else
@@ -436,11 +433,11 @@ void run() {
break;
case ConfigureNotify:
if (win_configure(&win, &ev.xconfigure)) {
- set_timeout(redraw, TO_REDRAW_RESIZE, 0);
+ set_timeout(redraw, TO_REDRAW_RESIZE, false);
if (mode == MODE_IMAGE)
- img.checkpan = 1;
+ img.checkpan = true;
else
- tns.dirty = 1;
+ tns.dirty = true;
}
break;
case KeyPress:
@@ -449,7 +446,7 @@ void run() {
case MotionNotify:
if (mode == MODE_IMAGE) {
win_set_cursor(&win, CURSOR_ARROW);
- set_timeout(reset_cursor, TO_CURSOR_HIDE, 1);
+ set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
}
break;
}
@@ -539,11 +536,11 @@ int main(int argc, char **argv) {
win_init(&win);
img_init(&img, &win);
- if (options->thumbnails) {
+ if (options->thumb_mode) {
mode = MODE_THUMB;
tns_init(&tns, filecnt);
- while (!tns_load(&tns, 0, &files[0], False, False))
- remove_file(0, 0);
+ while (!tns_load(&tns, 0, &files[0], false, false))
+ remove_file(0, false);
tns.cnt = 1;
} else {
mode = MODE_IMAGE;
diff --git a/options.c b/options.c
index 1e4a56c..13e1174 100644
--- a/options.c
+++ b/options.c
@@ -17,6 +17,7 @@
*/
#define _POSIX_C_SOURCE 200112L
+#define _IMAGE_CONFIG
#include <stdlib.h>
#include <string.h>
@@ -25,8 +26,6 @@
#include "options.h"
#include "util.h"
-
-#define _IMAGE_CONFIG
#include "config.h"
options_t _options;
@@ -56,20 +55,20 @@ void print_version() {
void parse_options(int argc, char **argv) {
int opt, t;
- _options.recursive = 0;
+ _options.recursive = false;
_options.startnum = 0;
_options.scalemode = SCALE_MODE;
_options.zoom = 1.0;
- _options.aa = 1;
+ _options.aa = true;
- _options.fixed = 0;
- _options.fullscreen = 0;
+ _options.fixed_win = false;
+ _options.fullscreen = false;
_options.geometry = NULL;
- _options.quiet = 0;
- _options.thumbnails = 0;
- _options.clean_cache = 0;
+ _options.quiet = false;
+ _options.thumb_mode = false;
+ _options.clean_cache = false;
while ((opt = getopt(argc, argv, "cdFfg:hn:pqrstvZz:")) != -1) {
switch (opt) {
@@ -77,16 +76,16 @@ void parse_options(int argc, char **argv) {
print_usage();
exit(1);
case 'c':
- _options.clean_cache = 1;
+ _options.clean_cache = true;
break;
case 'd':
_options.scalemode = SCALE_DOWN;
break;
case 'F':
- _options.fixed = 1;
+ _options.fixed_win = true;
break;
case 'f':
- _options.fullscreen = 1;
+ _options.fullscreen = true;
break;
case 'g':
_options.geometry = optarg;
@@ -104,19 +103,19 @@ void parse_options(int argc, char **argv) {
}
break;
case 'p':
- _options.aa = 0;
+ _options.aa = false;
break;
case 'q':
- _options.quiet = 1;
+ _options.quiet = true;
break;
case 'r':
- _options.recursive = 1;
+ _options.recursive = true;
break;
case 's':
_options.scalemode = SCALE_FIT;
break;
case 't':
- _options.thumbnails = 1;
+ _options.thumb_mode = true;
break;
case 'v':
print_version();
@@ -140,5 +139,5 @@ void parse_options(int argc, char **argv) {
_options.filenames = argv + optind;
_options.filecnt = argc - optind;
_options.from_stdin = _options.filecnt == 1 &&
- strcmp(_options.filenames[0], "-") == 0;
+ !strcmp(_options.filenames[0], "-");
}
diff --git a/options.h b/options.h
index 67ad926..3bf685a 100644
--- a/options.h
+++ b/options.h
@@ -25,25 +25,25 @@
typedef struct {
/* file list: */
char **filenames;
- unsigned char from_stdin;
- unsigned char recursive;
+ bool from_stdin;
+ bool recursive;
int filecnt;
int startnum;
/* image: */
scalemode_t scalemode;
float zoom;
- unsigned char aa;
+ bool aa;
/* window: */
- unsigned char fixed;
- unsigned char fullscreen;
+ bool fixed_win;
+ bool fullscreen;
char *geometry;
/* misc flags: */
- unsigned char quiet;
- unsigned char thumbnails;
- unsigned char clean_cache;
+ bool quiet;
+ bool thumb_mode;
+ bool clean_cache;
} options_t;
extern const options_t *options;
diff --git a/thumbs.c b/thumbs.c
index 52597dd..fa54576 100644
--- a/thumbs.c
+++ b/thumbs.c
@@ -17,6 +17,7 @@
*/
#define _POSIX_C_SOURCE 200112L
+#define _THUMBS_CONFIG
#include <stdlib.h>
#include <string.h>
@@ -27,8 +28,6 @@
#include "thumbs.h"
#include "util.h"
-
-#define _THUMBS_CONFIG
#include "config.h"
#ifdef EXIF_SUPPORT
@@ -38,7 +37,7 @@ void exif_auto_orientate(const fileinfo_t*);
const int thumb_dim = THUMB_SIZE + 10;
char *cache_dir = NULL;
-int tns_cache_enabled() {
+bool tns_cache_enabled() {
struct stat stats;
return cache_dir && !stat(cache_dir, &stats) && S_ISDIR(stats.st_mode) &&
@@ -81,7 +80,7 @@ Imlib_Image* tns_cache_load(const char *filepath) {
return im;
}
-void tns_cache_write(thumb_t *t, Bool force) {
+void tns_cache_write(thumb_t *t, bool force) {
char *cfile, *dirend;
struct stat cstats, fstats;
struct utimbuf times;
@@ -120,7 +119,8 @@ void tns_cache_write(thumb_t *t, Bool force) {
}
void tns_clean_cache(tns_t *tns) {
- int dirlen, delete;
+ int dirlen;
+ bool delete;
char *cfile, *filename, *tpos;
r_dir_t dir;
@@ -136,11 +136,12 @@ void tns_clean_cache(tns_t *tns) {
while ((cfile = r_readdir(&dir))) {
filename = cfile + dirlen;
- delete = 0;
+ delete = false;
if ((tpos = strrchr(filename, '.'))) {
*tpos = '\0';
- delete = access(filename, F_OK);
+ if (access(filename, F_OK))
+ delete = true;
*tpos = '.';
}
@@ -170,8 +171,8 @@ void tns_init(tns_t *tns, int cnt) {
tns->cnt = tns->first = tns->sel = 0;
tns->cap = cnt;
- tns->alpha = 1;
- tns->dirty = 0;
+ tns->alpha = true;
+ tns->dirty = false;
if ((homedir = getenv("HOME"))) {
if (cache_dir)
@@ -207,21 +208,21 @@ void tns_free(tns_t *tns) {
}
}
-int tns_load(tns_t *tns, int n, const fileinfo_t *file,
- Bool force, Bool silent)
+bool tns_load(tns_t *tns, int n, const fileinfo_t *file,
+ bool force, bool silent)
{
int w, h;
- int use_cache, cache_hit = 0;
+ bool use_cache, cache_hit = false;
float z, zw, zh;
thumb_t *t;
Imlib_Image *im;
const char *fmt;
if (!tns || !tns->thumbs || !file || !file->name || !file->path)
- return 0;
+ return false;
if (n < 0 || n >= tns->cap)
- return 0;
+ return false;
t = &tns->thumbs[n];
t->file = file;
@@ -233,7 +234,7 @@ int tns_load(tns_t *tns, int n, const fileinfo_t *file,
if ((use_cache = tns_cache_enabled())) {
if (!force && (im = tns_cache_load(file->path)))
- cache_hit = 1;
+ cache_hit = true;
}
if (!cache_hit &&
@@ -241,7 +242,7 @@ int tns_load(tns_t *tns, int n, const fileinfo_t *file,
{
if (!silent)
warn("could not open image: %s", file->name);
- return 0;
+ return false;
}
imlib_context_set_image(im);
@@ -270,13 +271,13 @@ int tns_load(tns_t *tns, int n, const fileinfo_t *file,
imlib_free_image_and_decache();
if (use_cache && !cache_hit)
- tns_cache_write(t, False);
+ tns_cache_write(t, false);
- tns->dirty = 1;
- return 1;
+ tns->dirty = true;
+ return true;
}
-void tns_check_view(tns_t *tns, Bool scrolled) {
+void tns_check_view(tns_t *tns, bool scrolled) {
int r;
if (!tns)
@@ -295,10 +296,10 @@ void tns_check_view(tns_t *tns, Bool scrolled) {
/* scroll to selection */
if (tns->first + tns->cols * tns->rows <= tns->sel) {
tns->first = tns->sel - r - tns->cols * (tns->rows - 1);
- tns->dirty = 1;
+ tns->dirty = true;
} else if (tns->first > tns->sel) {
tns->first = tns->sel - r;
- tns->dirty = 1;
+ tns->dirty = true;
}
}
}
@@ -323,7 +324,7 @@ void tns_render(tns_t *tns, win_t *win) {
tns->first = 0;
cnt = tns->cnt;
} else {
- tns_check_view(tns, False);
+ tns_check_view(tns, false);
cnt = tns->cols * tns->rows;
if ((r = tns->first + cnt - tns->cnt) >= tns->cols)
tns->first -= r - r % tns->cols;
@@ -342,7 +343,7 @@ void tns_render(tns_t *tns, win_t *win) {
imlib_context_set_image(t->im);
if (imlib_image_has_alpha() && !tns->alpha)
- win_draw_rect(win, win->pm, t->x, t->y, t->w, t->h, True, 0, win->white);
+ win_draw_rect(win, win->pm, t->x, t->y, t->w, t->h, true, 0, win->white);
imlib_render_image_part_on_drawable_at_size(0, 0, t->w, t->h,
t->x, t->y, t->w, t->h);
@@ -354,11 +355,11 @@ void tns_render(tns_t *tns, win_t *win) {
}
}
- tns->dirty = 0;
- tns_highlight(tns, win, tns->sel, True);
+ tns->dirty = false;
+ tns_highlight(tns, win, tns->sel, true);
}
-void tns_highlight(tns_t *tns, win_t *win, int n, Bool hl) {
+void tns_highlight(tns_t *tns, win_t *win, int n, bool hl) {
thumb_t *t;
int x, y;
unsigned long col;
@@ -379,17 +380,17 @@ void tns_highlight(tns_t *tns, win_t *win, int n, Bool hl) {
x = t->x - (THUMB_SIZE - t->w) / 2;
y = t->y - (THUMB_SIZE - t->h) / 2;
win_draw_rect(win, win->pm, x - 3, y - 3, THUMB_SIZE + 6, THUMB_SIZE + 6,
- False, 2, col);
+ false, 2, col);
}
win_draw(win);
}
-int tns_move_selection(tns_t *tns, win_t *win, direction_t dir) {
+bool tns_move_selection(tns_t *tns, win_t *win, direction_t dir) {
int old;
if (!tns || !tns->thumbs || !win)
- return 0;
+ return false;
old = tns->sel;
@@ -413,31 +414,31 @@ int tns_move_selection(tns_t *tns, win_t *win, direction_t dir) {
}
if (tns->sel != old) {
- tns_highlight(tns, win, old, False);
- tns_check_view(tns, False);
+ tns_highlight(tns, win, old, false);
+ tns_check_view(tns, false);
if (!tns->dirty)
- tns_highlight(tns, win, tns->sel, True);
+ tns_highlight(tns, win, tns->sel, true);
}
return tns->sel != old;
}
-int tns_scroll(tns_t *tns, direction_t dir) {
+bool tns_scroll(tns_t *tns, direction_t dir) {
int old;
if (!tns)
- return 0;
+ return false;
old = tns->first;
if (dir == DIR_DOWN && tns->first + tns->cols * tns->rows < tns->cnt) {
tns->first += tns->cols;
- tns_check_view(tns, True);
- tns->dirty = 1;
+ tns_check_view(tns, true);
+ tns->dirty = true;
} else if (dir == DIR_UP && tns->first >= tns->cols) {
tns->first -= tns->cols;
- tns_check_view(tns, True);
- tns->dirty = 1;
+ tns_check_view(tns, true);
+ tns->dirty = true;
}
return tns->first != old;
diff --git a/thumbs.h b/thumbs.h
index 47f7ba8..92f5726 100644
--- a/thumbs.h
+++ b/thumbs.h
@@ -44,8 +44,8 @@ typedef struct {
int rows;
int first;
int sel;
- unsigned char alpha;
- unsigned char dirty;
+ bool alpha;
+ bool dirty;
} tns_t;
void tns_clean_cache(tns_t*);
@@ -53,13 +53,13 @@ void tns_clean_cache(tns_t*);
void tns_init(tns_t*, int);
void tns_free(tns_t*);
-int tns_load(tns_t*, int, const fileinfo_t*, Bool, Bool);
+bool tns_load(tns_t*, int, const fileinfo_t*, bool, bool);
void tns_render(tns_t*, win_t*);
-void tns_highlight(tns_t*, win_t*, int, Bool);
+void tns_highlight(tns_t*, win_t*, int, bool);
-int tns_move_selection(tns_t*, win_t*, direction_t);
-int tns_scroll(tns_t*, direction_t);
+bool tns_move_selection(tns_t*, win_t*, direction_t);
+bool tns_scroll(tns_t*, direction_t);
int tns_translate(tns_t*, int, int);
diff --git a/types.h b/types.h
index dd85922..ddf6cf6 100644
--- a/types.h
+++ b/types.h
@@ -2,6 +2,11 @@
#define TYPES_H
typedef enum {
+ false,
+ true
+} bool;
+
+typedef enum {
MODE_IMAGE,
MODE_THUMB
} appmode_t;
@@ -29,7 +34,7 @@ typedef enum {
typedef struct {
const char *name; /* as given by user */
const char *path; /* always absolute */
- unsigned char loaded;
+ bool loaded;
} fileinfo_t;
/* timeouts in milliseconds: */
diff --git a/window.c b/window.c
index 4a90516..fd6229c 100644
--- a/window.c
+++ b/window.c
@@ -17,6 +17,7 @@
*/
#define _POSIX_C_SOURCE 200112L
+#define _WINDOW_CONFIG
#include <string.h>
#include <X11/Xutil.h>
@@ -25,8 +26,6 @@
#include "options.h"
#include "util.h"
#include "window.h"
-
-#define _WINDOW_CONFIG
#include "config.h"
static Cursor carrow;
@@ -76,7 +75,7 @@ void win_init(win_t *win) {
win->xwin = 0;
win->pm = 0;
- win->fullscreen = 0;
+ win->fullscreen = false;
}
void win_set_sizehints(win_t *win) {
@@ -97,7 +96,7 @@ void win_open(win_t *win) {
win_env_t *e;
XClassHint classhint;
XColor col;
- char none_data[] = {0, 0, 0, 0, 0, 0, 0, 0};
+ char none_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
Pixmap none;
int gmask;
@@ -158,7 +157,7 @@ void win_open(win_t *win) {
classhint.res_class = "sxiv";
XSetClassHint(e->dpy, win->xwin, &classhint);
- if (options->fixed)
+ if (options->fixed_win)
win_set_sizehints(win);
XMapWindow(e->dpy, win->xwin);
@@ -186,11 +185,11 @@ void win_close(win_t *win) {
XCloseDisplay(win->env.dpy);
}
-int win_configure(win_t *win, XConfigureEvent *c) {
- int changed;
+bool win_configure(win_t *win, XConfigureEvent *c) {
+ bool changed;
if (!win)
- return 0;
+ return false;
changed = win->w != c->width || win->h != c->height;
@@ -203,9 +202,9 @@ int win_configure(win_t *win, XConfigureEvent *c) {
return changed;
}
-int win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h) {
+bool win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h) {
if (!win || !win->xwin)
- return 0;
+ return false;
x = MAX(0, x);
y = MAX(0, y);
@@ -213,19 +212,19 @@ int win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h) {
h = MIN(h, win->env.scrh - 2 * win->bw);
if (win->x == x && win->y == y && win->w == w && win->h == h)
- return 0;
+ return false;
win->x = x;
win->y = y;
win->w = w;
win->h = h;
- if (options->fixed)
+ if (options->fixed_win)
win_set_sizehints(win);
XMoveResizeWindow(win->env.dpy, win->xwin, win->x, win->y, win->w, win->h);
- return 1;
+ return true;
}
void win_toggle_fullscreen(win_t *win) {
@@ -235,7 +234,7 @@ void win_toggle_fullscreen(win_t *win) {
if (!win || !win->xwin)
return;
- win->fullscreen ^= 1;
+ win->fullscreen = !win->fullscreen;
memset(&ev, 0, sizeof(ev));
ev.type = ClientMessage;
@@ -279,7 +278,7 @@ void win_draw(win_t *win) {
}
void win_draw_rect(win_t *win, Pixmap pm, int x, int y, int w, int h,
- Bool fill, int lw, unsigned long col) {
+ bool fill, int lw, unsigned long col) {
XGCValues gcval;
if (!win || !pm)
diff --git a/window.h b/window.h
index 1058919..ac60156 100644
--- a/window.h
+++ b/window.h
@@ -46,9 +46,9 @@ typedef struct {
int y;
unsigned int w;
unsigned int h;
-
unsigned int bw;
- unsigned char fullscreen;
+
+ bool fullscreen;
} win_t;
extern Atom wm_delete_win;
@@ -57,14 +57,14 @@ void win_init(win_t*);
void win_open(win_t*);
void win_close(win_t*);
-int win_configure(win_t*, XConfigureEvent*);
-int win_moveresize(win_t*, int, int, unsigned int, unsigned int);
+bool win_configure(win_t*, XConfigureEvent*);
+bool win_moveresize(win_t*, int, int, unsigned int, unsigned int);
void win_toggle_fullscreen(win_t*);
void win_clear(win_t*);
void win_draw(win_t*);
-void win_draw_rect(win_t*, Pixmap, int, int, int, int, Bool, int,
+void win_draw_rect(win_t*, Pixmap, int, int, int, int, bool, int,
unsigned long);
void win_set_title(win_t*, const char*);