summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDennis Real <github@tildepipe.org>2012-03-16 19:13:47 +0100
committerDennis Real <github@tildepipe.org>2012-03-16 19:13:47 +0100
commit8e96382805eb77a82209df9d71dbf9c0dd1c4cdb (patch)
tree48c54b9715d88cb6e9f8455d689364b73b842f8f /src
parent77fa5aca182435f2771511832ea198d027393ceb (diff)
parent29cd868898660c58b1925bf3647c4c63b7bd3151 (diff)
Merge branch 'master' of git://github.com/derf/feh
Diffstat (limited to 'src')
-rw-r--r--src/feh.h3
-rw-r--r--src/imlib.c42
-rw-r--r--src/keyevents.c14
-rw-r--r--src/list.c7
-rw-r--r--src/main.c2
-rw-r--r--src/multiwindow.c2
-rw-r--r--src/options.c5
-rw-r--r--src/options.h2
-rw-r--r--src/signals.c34
-rw-r--r--src/slideshow.c9
-rw-r--r--src/thumbnail.c1
11 files changed, 99 insertions, 22 deletions
diff --git a/src/feh.h b/src/feh.h
index 7088dea..1d48e53 100644
--- a/src/feh.h
+++ b/src/feh.h
@@ -188,4 +188,7 @@ extern feh_menu *menu_main;
extern feh_menu *menu_close;
extern char *mode; /* label for the current mode */
+/* to terminate long-running children with SIGALRM */
+extern int childpid;
+
#endif
diff --git a/src/imlib.c b/src/imlib.c
index c0252c3..eda3e2a 100644
--- a/src/imlib.c
+++ b/src/imlib.c
@@ -59,6 +59,8 @@ int xinerama_screen;
int num_xinerama_screens;
#endif /* HAVE_LIBXINERAMA */
+int childpid = 0;
+
static char *feh_http_load_image(char *url);
static char *feh_magick_load_image(char *filename);
@@ -253,7 +255,10 @@ static char *feh_magick_load_image(char *filename)
char *tmpname;
char *sfn;
int fd = -1, devnull = -1;
- int pid, status;
+ int status;
+
+ if (opt.magick_timeout < 0)
+ return NULL;
basename = strrchr(filename, '/');
@@ -277,27 +282,52 @@ static char *feh_magick_load_image(char *filename)
snprintf(argv_fd, sizeof(argv_fd), "png:fd:%d", fd);
-
- if ((pid = fork()) == 0) {
+ if ((childpid = fork()) == 0) {
/* discard convert output */
devnull = open("/dev/null", O_WRONLY);
+ dup2(devnull, 0);
dup2(devnull, 1);
dup2(devnull, 2);
+ /*
+ * convert only accepts SIGINT via killpg, a normal kill doesn't work
+ */
+ setpgid(0, 0);
+
execlp("convert", "convert", filename, argv_fd, NULL);
exit(1);
}
else {
- waitpid(pid, &status, 0);
+ alarm(opt.magick_timeout);
+ waitpid(childpid, &status, 0);
+ alarm(0);
if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) {
close(fd);
unlink(sfn);
sfn = NULL;
- if (!opt.quiet)
- weprintf("%s - No loader for that file format", filename);
+ if (!opt.quiet) {
+ if (WIFSIGNALED(status))
+ weprintf("%s - Conversion took too long, skipping",
+ filename);
+ else
+ weprintf("%s - No loader for that file format",
+ filename);
+ }
+
+ /*
+ * Reap child. The previous waitpid call was interrupted by
+ * alarm, but convert doesn't terminate immediately.
+ * XXX
+ * normally, if (WIFSIGNALED(status)) waitpid(childpid, &status, 0);
+ * would suffice. However, as soon as feh has its own window,
+ * this doesn't work anymore and the following workaround is
+ * required. Hm.
+ */
+ waitpid(-1, &status, 0);
}
+ childpid = 0;
}
return sfn;
diff --git a/src/keyevents.c b/src/keyevents.c
index 0ada751..343b5d1 100644
--- a/src/keyevents.c
+++ b/src/keyevents.c
@@ -129,10 +129,10 @@ void init_keyevents(void) {
feh_set_kb(&keys.action_9 , 0, XK_9 , 0, XK_KP_9 , 0, 0);
feh_set_kb(&keys.zoom_in , 0, XK_Up , 0, XK_KP_Add , 0, 0);
feh_set_kb(&keys.zoom_out , 0, XK_Down , 0, XK_KP_Subtract,0, 0);
- feh_set_kb(&keys.zoom_default, 0, XK_KP_Multiply, 0, 0 , 0, 0);
- feh_set_kb(&keys.zoom_fit , 0, XK_KP_Divide , 0, 0 , 0, 0);
+ feh_set_kb(&keys.zoom_default, 0, XK_KP_Multiply, 0, XK_asterisk, 0, 0);
+ feh_set_kb(&keys.zoom_fit , 0, XK_KP_Divide , 0, XK_slash , 0, 0);
feh_set_kb(&keys.size_to_image, 0, XK_w , 0, 0 , 0, 0);
- feh_set_kb(&keys.render , 0, XK_KP_Begin , 0, 0 , 0, 0);
+ feh_set_kb(&keys.render , 0, XK_KP_Begin , 0, XK_R , 0, 0);
feh_set_kb(&keys.toggle_actions, 0, XK_a, 0, 0, 0, 0);
feh_set_kb(&keys.toggle_aliasing, 0, XK_A, 0, 0, 0, 0);
feh_set_kb(&keys.toggle_filenames, 0, XK_d, 0, 0, 0, 0);
@@ -479,34 +479,42 @@ void feh_event_handle_keypress(XEvent * ev)
}
else if (feh_is_kp(&keys.scroll_right, keysym, state)) {
winwid->im_x -= 20;
+ winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 1);
}
else if (feh_is_kp(&keys.scroll_left, keysym, state)) {
winwid->im_x += 20;
+ winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 1);
}
else if (feh_is_kp(&keys.scroll_down, keysym, state)) {
winwid->im_y -= 20;
+ winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 1);
}
else if (feh_is_kp(&keys.scroll_up, keysym, state)) {
winwid->im_y += 20;
+ winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 1);
}
else if (feh_is_kp(&keys.scroll_right_page, keysym, state)) {
winwid->im_x -= winwid->w;
+ winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 0);
}
else if (feh_is_kp(&keys.scroll_left_page, keysym, state)) {
winwid->im_x += winwid->w;
+ winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 0);
}
else if (feh_is_kp(&keys.scroll_down_page, keysym, state)) {
winwid->im_y -= winwid->h;
+ winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 0);
}
else if (feh_is_kp(&keys.scroll_up_page, keysym, state)) {
winwid->im_y += winwid->h;
+ winwidget_sanitise_offsets(winwid);
winwidget_render_image(winwid, 0, 0);
}
else if (feh_is_kp(&keys.jump_back, keysym, state)) {
diff --git a/src/list.c b/src/list.c
index 17fcbcc..2affe85 100644
--- a/src/list.c
+++ b/src/list.c
@@ -77,6 +77,7 @@ void real_loadables_mode(int loadable)
{
feh_file *file;
gib_list *l;
+ char ret = 0;
opt.quiet = 1;
@@ -91,6 +92,8 @@ void real_loadables_mode(int loadable)
puts(file->filename);
feh_action_run(file, opt.actions[0]);
}
+ else
+ ret = 1;
gib_imlib_free_image_and_decache(im);
} else {
/* Oh dear. */
@@ -98,7 +101,9 @@ void real_loadables_mode(int loadable)
puts(file->filename);
feh_action_run(file, opt.actions[0]);
}
+ else
+ ret = 1;
}
}
- exit(0);
+ exit(ret);
}
diff --git a/src/main.c b/src/main.c
index 5891056..e6239e1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -30,6 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "timers.h"
#include "options.h"
#include "events.h"
+#include "signals.h"
#include "wallpaper.h"
char **cmdargv = NULL;
@@ -43,6 +44,7 @@ int main(int argc, char **argv)
init_parse_options(argc, argv);
init_imlib_fonts();
+ setup_signal_handlers();
if (opt.display) {
init_x_and_imlib();
diff --git a/src/multiwindow.c b/src/multiwindow.c
index 1bd8a8a..9797fb0 100644
--- a/src/multiwindow.c
+++ b/src/multiwindow.c
@@ -65,7 +65,5 @@ void init_multiwindow_mode(void)
free(s);
}
- setup_signal_handlers();
-
return;
}
diff --git a/src/options.c b/src/options.c
index f389e0e..a277003 100644
--- a/src/options.c
+++ b/src/options.c
@@ -53,6 +53,7 @@ void init_parse_options(int argc, char **argv)
opt.display = 1;
opt.aspect = 1;
opt.slideshow_delay = 0.0;
+ opt.magick_timeout = 10;
opt.thumb_w = 60;
opt.thumb_h = 60;
opt.thumb_redraw = 10;
@@ -378,6 +379,7 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
{"zoom" , 1, 0, 205},
{"no-screen-clip", 0, 0, 206},
{"index-info" , 1, 0, 207},
+ {"magick-timeout", 1, 0, 208},
{"caption-path" , 1, 0, 'K'},
{"action1" , 1, 0, 209},
{"action2" , 1, 0, 210},
@@ -646,6 +648,9 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
case 207:
opt.index_info = estrdup(optarg);
break;
+ case 208:
+ opt.magick_timeout = atoi(optarg);
+ break;
case 'K':
opt.caption_path = estrdup(optarg);
break;
diff --git a/src/options.h b/src/options.h
index bee7c73..898e9ff 100644
--- a/src/options.h
+++ b/src/options.h
@@ -117,6 +117,8 @@ struct __fehoptions {
double slideshow_delay;
+ signed short magick_timeout;
+
Imlib_Font menu_fn;
};
diff --git a/src/signals.c b/src/signals.c
index d5a6899..0b18aac 100644
--- a/src/signals.c
+++ b/src/signals.c
@@ -36,9 +36,13 @@ void setup_signal_handlers()
if (
(sigemptyset(&feh_ss) == -1) ||
(sigaddset(&feh_ss, SIGUSR1) == -1) ||
- (sigaddset(&feh_ss, SIGUSR2) == -1))
+ (sigaddset(&feh_ss, SIGUSR2) == -1) ||
+ (sigaddset(&feh_ss, SIGALRM) == -1) ||
+ (sigaddset(&feh_ss, SIGTERM) == -1) ||
+ (sigaddset(&feh_ss, SIGQUIT) == -1) ||
+ (sigaddset(&feh_ss, SIGINT) == -1))
{
- weprintf("Failed to set up signal mask, SIGUSR1/2 won't work");
+ weprintf("Failed to set up signal masks");
return;
}
@@ -48,9 +52,13 @@ void setup_signal_handlers()
if (
(sigaction(SIGUSR1, &feh_sh, NULL) == -1) ||
- (sigaction(SIGUSR2, &feh_sh, NULL) == -1))
+ (sigaction(SIGUSR2, &feh_sh, NULL) == -1) ||
+ (sigaction(SIGALRM, &feh_sh, NULL) == -1) ||
+ (sigaction(SIGTERM, &feh_sh, NULL) == -1) ||
+ (sigaction(SIGQUIT, &feh_sh, NULL) == -1) ||
+ (sigaction(SIGINT, &feh_sh, NULL) == -1))
{
- weprintf("Failed to set up signal handler, SIGUSR1/2 won't work");
+ weprintf("Failed to set up signal handler");
return;
}
@@ -59,10 +67,24 @@ void setup_signal_handlers()
void feh_handle_signal(int signo)
{
- winwidget winwid
- = winwidget_get_first_window_of_type(WIN_TYPE_SLIDESHOW);
+ winwidget winwid;
int i;
+ switch (signo) {
+ case SIGALRM:
+ if (childpid)
+ killpg(childpid, SIGINT);
+ return;
+ case SIGINT:
+ case SIGTERM:
+ case SIGQUIT:
+ if (childpid)
+ killpg(childpid, SIGINT);
+ exit(128 + signo);
+ }
+
+ winwid = winwidget_get_first_window_of_type(WIN_TYPE_SLIDESHOW);
+
if (winwid) {
if (signo == SIGUSR1)
slideshow_change_image(winwid, SLIDE_NEXT, 1);
diff --git a/src/slideshow.c b/src/slideshow.c
index a868a44..337e202 100644
--- a/src/slideshow.c
+++ b/src/slideshow.c
@@ -76,8 +76,6 @@ void init_slideshow_mode(void)
if (!success)
show_mini_usage();
- setup_signal_handlers();
-
return;
}
@@ -266,8 +264,11 @@ void slideshow_change_image(winwidget winwid, int change, int render)
current_file = feh_list_jump(filelist, current_file, BACK, 1);
break;
case SLIDE_RAND:
- current_file = feh_list_jump(filelist, current_file, FORWARD, rand() % filelist_len);
- change = SLIDE_NEXT;
+ if (filelist_len > 1) {
+ current_file = feh_list_jump(filelist, current_file, FORWARD,
+ (rand() % (filelist_len - 1)) + 1);
+ change = SLIDE_NEXT;
+ }
break;
case SLIDE_JUMP_FWD:
if (filelist_len < 5)
diff --git a/src/thumbnail.c b/src/thumbnail.c
index b13b3d8..f276592 100644
--- a/src/thumbnail.c
+++ b/src/thumbnail.c
@@ -32,6 +32,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "md5.h"
#include "feh_png.h"
#include "index.h"
+#include "signals.h"
static gib_list *thumbnails = NULL;