New option: -a, do not filter out unsupported files

This commit is contained in:
Bert 2011-04-06 19:30:06 +02:00
parent 426edfb349
commit facd7e3b42
7 changed files with 35 additions and 15 deletions

View file

@ -1,6 +1,6 @@
all: sxiv all: sxiv
VERSION=git-20110405 VERSION=git-20110406
CC?=gcc CC?=gcc
PREFIX?=/usr/local PREFIX?=/usr/local

View file

@ -34,6 +34,8 @@ small previews is displayed, making it easy to choose an image to open.
sxiv supports the following command-line options: sxiv supports the following command-line options:
-a Display all given files, do not filter out unsupported files
(shorter startup time for long file list or slow file types)
-d Scale all images to 100%, but fit large images into window -d Scale all images to 100%, but fit large images into window
-F Use size-hints to make the window fixed/floating -F Use size-hints to make the window fixed/floating
-f Start in fullscreen mode -f Start in fullscreen mode

BIN
invalid.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

30
main.c
View file

@ -77,19 +77,22 @@ void cleanup() {
} }
int load_image(int new) { int load_image(int new) {
int ret = 0;
struct stat fstats; struct stat fstats;
if (new >= 0 && new < filecnt) { if (new >= 0 && new < filecnt) {
win_set_cursor(&win, CURSOR_WATCH);
img_close(&img, 0); img_close(&img, 0);
fileidx = new; fileidx = new;
if (!stat(filenames[fileidx], &fstats)) if (!stat(filenames[fileidx], &fstats))
filesize = fstats.st_size; filesize = fstats.st_size;
else else
filesize = 0; filesize = 0;
return img_load(&img, filenames[fileidx]); if (!(ret = img_load(&img, filenames[fileidx])))
} else { win_set_cursor(&win, CURSOR_NONE);
return 0;
} }
return ret;
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
@ -199,7 +202,7 @@ int check_append(const char *filename) {
if (access(filename, R_OK)) { if (access(filename, R_OK)) {
warn("could not open file: %s", filename); warn("could not open file: %s", filename);
return 0; return 0;
} else if (img_check(filename)) { } else if (options->all || img_check(filename)) {
if (fileidx == filecnt) { if (fileidx == filecnt) {
filecnt *= 2; filecnt *= 2;
filenames = (const char**) s_realloc(filenames, filenames = (const char**) s_realloc(filenames,
@ -353,10 +356,15 @@ unsigned char drag;
int mox, moy; int mox, moy;
void redraw() { void redraw() {
if (mode == MODE_NORMAL) if (mode == MODE_NORMAL) {
img_render(&img, &win); img_render(&img, &win);
else if (timo_cursor)
win_set_cursor(&win, CURSOR_ARROW);
else if (!drag)
win_set_cursor(&win, CURSOR_NONE);
} else {
tns_render(&tns, &win); tns_render(&tns, &win);
}
update_title(); update_title();
timo_redraw = 0; timo_redraw = 0;
} }
@ -390,7 +398,8 @@ void on_keypress(XKeyEvent *kev) {
} }
redraw(); redraw();
} }
win_set_cursor(&win, mode == MODE_NORMAL ? CURSOR_NONE : CURSOR_ARROW); if (mode == MODE_THUMBS)
win_set_cursor(&win, CURSOR_ARROW);
return; return;
} }
} }
@ -515,7 +524,6 @@ void on_keypress(XKeyEvent *kev) {
case XK_Return: case XK_Return:
load_image(tns.sel); load_image(tns.sel);
mode = MODE_NORMAL; mode = MODE_NORMAL;
win_set_cursor(&win, CURSOR_NONE);
changed = 1; changed = 1;
break; break;
@ -580,6 +588,9 @@ void on_buttonpress(XButtonEvent *bev) {
changed = 0; changed = 0;
if (mode == MODE_NORMAL) { if (mode == MODE_NORMAL) {
win_set_cursor(&win, CURSOR_ARROW);
timo_cursor = TO_CURSOR_HIDE;
switch (bev->button) { switch (bev->button) {
case Button1: case Button1:
if (fileidx + 1 < filecnt) if (fileidx + 1 < filecnt)
@ -672,9 +683,6 @@ void run() {
timo_cursor = timo_redraw = 0; timo_cursor = timo_redraw = 0;
drag = 0; drag = 0;
if (mode == MODE_NORMAL)
timo_cursor = TO_CURSOR_HIDE;
while (1) { while (1) {
if (mode == MODE_THUMBS && tns.cnt < filecnt) { if (mode == MODE_THUMBS && tns.cnt < filecnt) {
win_set_cursor(&win, CURSOR_WATCH); win_set_cursor(&win, CURSOR_WATCH);

View file

@ -31,7 +31,7 @@ options_t _options;
const options_t *options = (const options_t*) &_options; const options_t *options = (const options_t*) &_options;
void print_usage() { void print_usage() {
printf("usage: sxiv [-dFfhpqrstvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n"); printf("usage: sxiv [-adFfhpqrstvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n");
} }
void print_version() { void print_version() {
@ -51,14 +51,18 @@ void parse_options(int argc, char **argv) {
_options.fullscreen = 0; _options.fullscreen = 0;
_options.geometry = NULL; _options.geometry = NULL;
_options.all = 0;
_options.quiet = 0; _options.quiet = 0;
_options.recursive = 0; _options.recursive = 0;
while ((opt = getopt(argc, argv, "dFfg:hpqrstvZz:")) != -1) { while ((opt = getopt(argc, argv, "adFfg:hpqrstvZz:")) != -1) {
switch (opt) { switch (opt) {
case '?': case '?':
print_usage(); print_usage();
exit(1); exit(1);
case 'a':
_options.all = 1;
break;
case 'd': case 'd':
_options.scalemode = SCALE_DOWN; _options.scalemode = SCALE_DOWN;
break; break;

View file

@ -35,6 +35,7 @@ typedef struct {
unsigned char fullscreen; unsigned char fullscreen;
char *geometry; char *geometry;
unsigned char all;
unsigned char quiet; unsigned char quiet;
unsigned char recursive; unsigned char recursive;
} options_t; } options_t;

7
sxiv.1
View file

@ -3,7 +3,7 @@
sxiv \- Simple (or small or suckless) X Image Viewer sxiv \- Simple (or small or suckless) X Image Viewer
.SH SYNOPSIS .SH SYNOPSIS
.B sxiv .B sxiv
.RB [ \-dFfhpqrstvZ ] .RB [ \-adFfhpqrstvZ ]
.RB [ \-g .RB [ \-g
.IR GEOMETRY ] .IR GEOMETRY ]
.RB [ \-z .RB [ \-z
@ -28,6 +28,11 @@ Please note, that the fullscreen mode requires an EWMH/NetWM compliant window
manager. manager.
.SH OPTIONS .SH OPTIONS
.TP .TP
.B \-a
Display all given files, do not filter out unsupported files. This might result
in a much shorter startup time, when the file list is very long or contains
large files of slow loadable types, e.g. gif and progressive jpg.
.TP
.B \-d .B \-d
Scale all images to 100%, but fit large images into window. Scale all images to 100%, but fit large images into window.
.TP .TP