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