@@ -1,6 +1,6 @@ | |||||
all: sxiv | all: sxiv | ||||
VERSION=git-20110227 | |||||
VERSION=0.7 | |||||
CC?=gcc | CC?=gcc | ||||
PREFIX?=/usr/local | PREFIX?=/usr/local | ||||
@@ -16,7 +16,6 @@ | |||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||||
*/ | */ | ||||
#include <string.h> | |||||
#include <unistd.h> | #include <unistd.h> | ||||
#include "config.h" | #include "config.h" | ||||
@@ -29,9 +28,6 @@ int zl_cnt; | |||||
float zoom_min; | float zoom_min; | ||||
float zoom_max; | float zoom_max; | ||||
const short ori_left[8] = { 8, 7, 6, 5, 2, 1, 4, 3 }; | |||||
const short ori_right[8] = { 6, 5, 8, 7, 4, 3, 2, 1 }; | |||||
Imlib_Image *im_broken; | Imlib_Image *im_broken; | ||||
void img_init(img_t *img, win_t *win) { | void img_init(img_t *img, win_t *win) { | ||||
@@ -94,8 +90,8 @@ int img_load(img_t *img, const char *filename) { | |||||
img->scalemode = SCALE_DOWN; | img->scalemode = SCALE_DOWN; | ||||
} | } | ||||
img->ori = img->o_ori = 1; | |||||
img->re = img->checkpan = 0; | |||||
img->re = 0; | |||||
img->checkpan = 0; | |||||
img->w = imlib_image_get_width(); | img->w = imlib_image_get_width(); | ||||
img->h = imlib_image_get_height(); | img->h = imlib_image_get_height(); | ||||
@@ -103,25 +99,6 @@ int img_load(img_t *img, const char *filename) { | |||||
return 1; | return 1; | ||||
} | } | ||||
int img_save(img_t *img) { | |||||
const char *fmt; | |||||
if (!img || !img->im) | |||||
return 0; | |||||
imlib_context_set_image(img->im); | |||||
if (img->ori != img->o_ori) { | |||||
fmt = imlib_image_format(); | |||||
if (strcmp(fmt, "png") == 0) { | |||||
imlib_save_image(imlib_image_get_filename()); | |||||
return 1; | |||||
} | |||||
} | |||||
return 0; | |||||
} | |||||
void img_close(img_t *img) { | void img_close(img_t *img) { | ||||
if (img && img->im) { | if (img && img->im) { | ||||
imlib_context_set_image(img->im); | imlib_context_set_image(img->im); | ||||
@@ -364,17 +341,11 @@ void img_rotate(img_t *img, win_t *win, int d) { | |||||
} | } | ||||
void img_rotate_left(img_t *img, win_t *win) { | void img_rotate_left(img_t *img, win_t *win) { | ||||
if (img) { | |||||
img_rotate(img, win, 3); | |||||
img->ori = ori_left[img->ori]; | |||||
} | |||||
img_rotate(img, win, 3); | |||||
} | } | ||||
void img_rotate_right(img_t *img, win_t *win) { | void img_rotate_right(img_t *img, win_t *win) { | ||||
if (img) { | |||||
img_rotate(img, win, 1); | |||||
img->ori = ori_right[img->ori]; | |||||
} | |||||
img_rotate(img, win, 1); | |||||
} | } | ||||
void img_toggle_antialias(img_t *img) { | void img_toggle_antialias(img_t *img) { | ||||
@@ -41,8 +41,6 @@ typedef struct img_s { | |||||
float zoom; | float zoom; | ||||
scalemode_t scalemode; | scalemode_t scalemode; | ||||
short ori; | |||||
short o_ori; | |||||
unsigned char re; | unsigned char re; | ||||
unsigned char checkpan; | unsigned char checkpan; | ||||
@@ -59,7 +57,6 @@ void img_free(img_t*); | |||||
int img_check(const char*); | int img_check(const char*); | ||||
int img_load(img_t*, const char*); | int img_load(img_t*, const char*); | ||||
int img_save(img_t*); | |||||
void img_close(img_t*); | void img_close(img_t*); | ||||
void img_render(img_t*, win_t*); | void img_render(img_t*, win_t*); | ||||
@@ -69,11 +69,10 @@ void cleanup() { | |||||
} | } | ||||
} | } | ||||
int load_image(int new) { | |||||
int load_image() { | |||||
struct stat fstats; | struct stat fstats; | ||||
img_close(&img); | img_close(&img); | ||||
fileidx = new; | |||||
if (!stat(filenames[fileidx], &fstats)) | if (!stat(filenames[fileidx], &fstats)) | ||||
filesize = fstats.st_size; | filesize = fstats.st_size; | ||||
@@ -141,7 +140,7 @@ int main(int argc, char **argv) { | |||||
} else { | } else { | ||||
mode = MODE_NORMAL; | mode = MODE_NORMAL; | ||||
tns.thumbs = NULL; | tns.thumbs = NULL; | ||||
load_image(fileidx); | |||||
load_image(); | |||||
img_render(&img, &win); | img_render(&img, &win); | ||||
} | } | ||||
@@ -308,29 +307,41 @@ void on_keypress(XKeyEvent *kev) { | |||||
/* navigate image list */ | /* navigate image list */ | ||||
case XK_n: | case XK_n: | ||||
case XK_space: | case XK_space: | ||||
if (fileidx + 1 < filecnt) | |||||
changed = load_image(fileidx + 1); | |||||
if (fileidx + 1 < filecnt) { | |||||
++fileidx; | |||||
changed = load_image(); | |||||
} | |||||
break; | break; | ||||
case XK_p: | case XK_p: | ||||
case XK_BackSpace: | case XK_BackSpace: | ||||
if (fileidx > 0) | |||||
changed = load_image(fileidx - 1); | |||||
if (fileidx > 0) { | |||||
--fileidx; | |||||
changed = load_image(); | |||||
} | |||||
break; | break; | ||||
case XK_bracketleft: | case XK_bracketleft: | ||||
if (fileidx != 0) | |||||
changed = load_image(MAX(0, fileidx - 10)); | |||||
if (fileidx != 0) { | |||||
fileidx = MAX(0, fileidx - 10); | |||||
changed = load_image(); | |||||
} | |||||
break; | break; | ||||
case XK_bracketright: | case XK_bracketright: | ||||
if (fileidx != filecnt - 1) | |||||
changed = load_image(MIN(fileidx + 10, filecnt - 1)); | |||||
if (fileidx != filecnt - 1) { | |||||
fileidx = MIN(fileidx + 10, filecnt - 1); | |||||
changed = load_image(); | |||||
} | |||||
break; | break; | ||||
case XK_g: | case XK_g: | ||||
if (fileidx != 0) | |||||
changed = load_image(0); | |||||
if (fileidx != 0) { | |||||
fileidx = 0; | |||||
changed = load_image(); | |||||
} | |||||
break; | break; | ||||
case XK_G: | case XK_G: | ||||
if (fileidx != filecnt - 1) | |||||
changed = load_image(filecnt - 1); | |||||
if (fileidx != filecnt - 1) { | |||||
fileidx = filecnt - 1; | |||||
changed = load_image(); | |||||
} | |||||
break; | break; | ||||
/* zooming */ | /* zooming */ | ||||
@@ -407,11 +418,7 @@ void on_keypress(XKeyEvent *kev) { | |||||
changed = 1; | changed = 1; | ||||
break; | break; | ||||
case XK_r: | case XK_r: | ||||
changed = load_image(fileidx); | |||||
break; | |||||
case XK_S: | |||||
if (img_save(&img)) | |||||
tns_load(&tns, &win, fileidx, filenames[fileidx]); | |||||
changed = load_image(); | |||||
break; | break; | ||||
} | } | ||||
} else { | } else { | ||||
@@ -419,7 +426,8 @@ void on_keypress(XKeyEvent *kev) { | |||||
switch (ksym) { | switch (ksym) { | ||||
/* open selected image */ | /* open selected image */ | ||||
case XK_Return: | case XK_Return: | ||||
load_image(tns.sel); | |||||
fileidx = tns.sel; | |||||
load_image(); | |||||
mode = MODE_NORMAL; | mode = MODE_NORMAL; | ||||
win_set_cursor(&win, CURSOR_NONE); | win_set_cursor(&win, CURSOR_NONE); | ||||
changed = 1; | changed = 1; | ||||
@@ -488,8 +496,10 @@ void on_buttonpress(XButtonEvent *bev) { | |||||
if (mode == MODE_NORMAL) { | if (mode == MODE_NORMAL) { | ||||
switch (bev->button) { | switch (bev->button) { | ||||
case Button1: | case Button1: | ||||
if (fileidx + 1 < filecnt) | |||||
changed = load_image(fileidx + 1); | |||||
if (fileidx + 1 < filecnt) { | |||||
++fileidx; | |||||
changed = load_image(); | |||||
} | |||||
break; | break; | ||||
case Button2: | case Button2: | ||||
mox = bev->x; | mox = bev->x; | ||||
@@ -499,8 +509,10 @@ void on_buttonpress(XButtonEvent *bev) { | |||||
drag = 1; | drag = 1; | ||||
break; | break; | ||||
case Button3: | case Button3: | ||||
if (fileidx > 0) | |||||
changed = load_image(fileidx - 1); | |||||
if (fileidx > 0) { | |||||
--fileidx; | |||||
changed = load_image(); | |||||
} | |||||
break; | break; | ||||
case Button4: | case Button4: | ||||
if (mask == ControlMask) | if (mask == ControlMask) | ||||
@@ -531,7 +543,8 @@ void on_buttonpress(XButtonEvent *bev) { | |||||
case Button1: | case Button1: | ||||
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) { | ||||
load_image(tns.sel); | |||||
fileidx = tns.sel; | |||||
load_image(); | |||||
mode = MODE_NORMAL; | mode = MODE_NORMAL; | ||||
timo_cursor = TO_CURSOR_HIDE; | timo_cursor = TO_CURSOR_HIDE; | ||||
} else { | } else { | ||||
@@ -587,8 +600,7 @@ void run() { | |||||
gettimeofday(&t0, 0); | gettimeofday(&t0, 0); | ||||
while (!XPending(win.env.dpy) && tns.cnt < filecnt) { | while (!XPending(win.env.dpy) && tns.cnt < filecnt) { | ||||
/* tns.cnt is increased inside tns_load */ | |||||
tns_load(&tns, &win, tns.cnt, filenames[tns.cnt]); | |||||
tns_load(&tns, &win, filenames[tns.cnt]); | |||||
gettimeofday(&t1, 0); | gettimeofday(&t1, 0); | ||||
if (TV_TO_DOUBLE(t1) - TV_TO_DOUBLE(t0) >= 0.25) | if (TV_TO_DOUBLE(t1) - TV_TO_DOUBLE(t0) >= 0.25) | ||||
break; | break; | ||||
@@ -35,7 +35,6 @@ void tns_init(tns_t *tns, int cnt) { | |||||
tns->cnt = tns->first = tns->sel = 0; | tns->cnt = tns->first = tns->sel = 0; | ||||
tns->thumbs = (thumb_t*) s_malloc(cnt * sizeof(thumb_t)); | tns->thumbs = (thumb_t*) s_malloc(cnt * sizeof(thumb_t)); | ||||
memset(tns->thumbs, 0, cnt * sizeof(thumb_t)); | memset(tns->thumbs, 0, cnt * sizeof(thumb_t)); | ||||
tns->cap = cnt; | |||||
tns->dirty = 0; | tns->dirty = 0; | ||||
} | } | ||||
@@ -52,7 +51,7 @@ void tns_free(tns_t *tns, win_t *win) { | |||||
tns->thumbs = NULL; | tns->thumbs = NULL; | ||||
} | } | ||||
void tns_load(tns_t *tns, win_t *win, int n, const char *filename) { | |||||
void tns_load(tns_t *tns, win_t *win, const char *filename) { | |||||
int w, h; | int w, h; | ||||
float z, zw, zh; | float z, zw, zh; | ||||
thumb_t *t; | thumb_t *t; | ||||
@@ -61,17 +60,10 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) { | |||||
if (!tns || !win || !filename) | if (!tns || !win || !filename) | ||||
return; | return; | ||||
if (n >= tns->cap) | |||||
return; | |||||
else if (n >= tns->cnt) | |||||
tns->cnt = n + 1; | |||||
if ((im = imlib_load_image(filename))) { | |||||
if ((im = imlib_load_image(filename))) | |||||
imlib_context_set_image(im); | imlib_context_set_image(im); | ||||
imlib_image_set_changes_on_disk(); | |||||
} else { | |||||
else | |||||
imlib_context_set_image(im_broken); | imlib_context_set_image(im_broken); | ||||
} | |||||
w = imlib_image_get_width(); | w = imlib_image_get_width(); | ||||
h = imlib_image_get_height(); | h = imlib_image_get_height(); | ||||
@@ -81,12 +73,10 @@ void tns_load(tns_t *tns, win_t *win, int n, const char *filename) { | |||||
if (!im && z > 1.0) | if (!im && z > 1.0) | ||||
z = 1.0; | z = 1.0; | ||||
t = &tns->thumbs[n]; | |||||
t = &tns->thumbs[tns->cnt++]; | |||||
t->w = z * w; | t->w = z * w; | ||||
t->h = z * h; | t->h = z * h; | ||||
if (t->pm) | |||||
win_free_pixmap(win, t->pm); | |||||
t->pm = win_create_pixmap(win, t->w, t->h); | t->pm = win_create_pixmap(win, t->w, t->h); | ||||
imlib_context_set_drawable(t->pm); | imlib_context_set_drawable(t->pm); | ||||
imlib_context_set_anti_alias(1); | imlib_context_set_anti_alias(1); | ||||
@@ -38,7 +38,6 @@ typedef struct thumb_s { | |||||
typedef struct tns_s { | typedef struct tns_s { | ||||
thumb_t *thumbs; | thumb_t *thumbs; | ||||
int cap; | |||||
int cnt; | int cnt; | ||||
int x; | int x; | ||||
int y; | int y; | ||||
@@ -52,7 +51,7 @@ typedef struct tns_s { | |||||
void tns_init(tns_t*, int); | void tns_init(tns_t*, int); | ||||
void tns_free(tns_t*, win_t*); | void tns_free(tns_t*, win_t*); | ||||
void tns_load(tns_t*, win_t*, int, const char*); | |||||
void tns_load(tns_t*, win_t*, const char*); | |||||
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); | ||||