2011-08-19 14:02:10 +01:00
|
|
|
/* sxiv: commands.c
|
2011-10-14 09:40:49 +01:00
|
|
|
* Copyright (c) 2011 Bert Muennich <be.muennich at googlemail.com>
|
2011-07-26 17:01:29 +01:00
|
|
|
*
|
2011-09-03 22:11:45 +01:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
2011-08-18 00:18:26 +01:00
|
|
|
*
|
2011-09-03 22:11:45 +01:00
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
2011-08-18 00:18:26 +01:00
|
|
|
*
|
2011-09-03 22:11:45 +01:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2011-07-26 17:01:29 +01:00
|
|
|
*/
|
|
|
|
|
2011-09-08 19:54:24 +01:00
|
|
|
#define _POSIX_C_SOURCE 200112L
|
2011-10-16 17:58:32 +01:00
|
|
|
#define _IMAGE_CONFIG
|
2011-09-03 14:58:58 +01:00
|
|
|
|
2011-09-08 19:54:24 +01:00
|
|
|
#include <stdlib.h>
|
2011-07-26 17:01:29 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
2011-08-19 14:02:10 +01:00
|
|
|
#include "commands.h"
|
2011-07-26 17:01:29 +01:00
|
|
|
#include "image.h"
|
|
|
|
#include "thumbs.h"
|
|
|
|
#include "util.h"
|
2011-10-16 17:58:32 +01:00
|
|
|
#include "config.h"
|
2011-07-26 17:01:29 +01:00
|
|
|
|
2011-10-12 17:38:29 +01:00
|
|
|
void cleanup(void);
|
2011-09-11 20:01:24 +01:00
|
|
|
void remove_file(int, bool);
|
2011-07-26 17:01:29 +01:00
|
|
|
void load_image(int);
|
2011-10-12 17:38:29 +01:00
|
|
|
void redraw(void);
|
|
|
|
void reset_cursor(void);
|
|
|
|
void animate(void);
|
|
|
|
void slideshow(void);
|
2011-09-11 20:01:24 +01:00
|
|
|
void set_timeout(timeout_f, int, bool);
|
2011-09-02 03:33:44 +01:00
|
|
|
void reset_timeout(timeout_f);
|
2011-07-26 17:01:29 +01:00
|
|
|
|
|
|
|
extern appmode_t mode;
|
|
|
|
extern img_t img;
|
|
|
|
extern tns_t tns;
|
|
|
|
extern win_t win;
|
|
|
|
|
2011-08-17 23:38:55 +01:00
|
|
|
extern fileinfo_t *files;
|
2011-07-26 17:01:29 +01:00
|
|
|
extern int filecnt, fileidx;
|
|
|
|
|
2011-10-16 15:08:55 +01:00
|
|
|
extern int prefix;
|
|
|
|
|
2011-10-16 17:58:32 +01:00
|
|
|
const int ss_delays[] = {
|
|
|
|
1, 2, 3, 5, 10, 15, 20, 30, 60, 120, 180, 300, 600
|
|
|
|
};
|
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
bool it_quit(arg_t a) {
|
2011-07-26 17:01:29 +01:00
|
|
|
cleanup();
|
2011-09-26 14:40:07 +01:00
|
|
|
exit(EXIT_SUCCESS);
|
2011-07-26 17:01:29 +01:00
|
|
|
}
|
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
bool it_switch_mode(arg_t a) {
|
2011-08-19 12:09:22 +01:00
|
|
|
if (mode == MODE_IMAGE) {
|
2011-09-29 11:43:36 +01:00
|
|
|
if (tns.thumbs == NULL)
|
2011-09-17 16:23:51 +01:00
|
|
|
tns_init(&tns, filecnt, &win);
|
2011-09-11 20:01:24 +01:00
|
|
|
img_close(&img, false);
|
2011-09-03 16:01:39 +01:00
|
|
|
reset_timeout(reset_cursor);
|
2011-09-10 17:41:20 +01:00
|
|
|
if (img.slideshow) {
|
2011-09-11 20:01:24 +01:00
|
|
|
img.slideshow = false;
|
2011-09-10 17:41:20 +01:00
|
|
|
reset_timeout(slideshow);
|
|
|
|
}
|
2011-11-01 07:36:20 +00:00
|
|
|
tns.sel = fileidx;
|
2011-09-11 20:01:24 +01:00
|
|
|
tns.dirty = true;
|
2011-08-19 12:09:22 +01:00
|
|
|
mode = MODE_THUMB;
|
2011-07-26 17:01:29 +01:00
|
|
|
} else {
|
2011-08-19 12:06:19 +01:00
|
|
|
load_image(tns.sel);
|
2011-08-19 12:09:22 +01:00
|
|
|
mode = MODE_IMAGE;
|
2011-07-26 17:01:29 +01:00
|
|
|
}
|
2011-09-11 20:01:24 +01:00
|
|
|
return true;
|
2011-07-26 17:01:29 +01:00
|
|
|
}
|
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
bool it_toggle_fullscreen(arg_t a) {
|
2011-07-26 17:01:29 +01:00
|
|
|
win_toggle_fullscreen(&win);
|
2011-09-11 20:01:24 +01:00
|
|
|
set_timeout(redraw, TO_REDRAW_RESIZE, false);
|
2011-08-19 12:09:22 +01:00
|
|
|
if (mode == MODE_IMAGE)
|
2011-09-11 20:01:24 +01:00
|
|
|
img.checkpan = true;
|
2011-07-26 17:01:29 +01:00
|
|
|
else
|
2011-09-11 20:01:24 +01:00
|
|
|
tns.dirty = true;
|
|
|
|
return false;
|
2011-07-26 17:01:29 +01:00
|
|
|
}
|
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
bool it_reload_image(arg_t a) {
|
2011-08-19 12:09:22 +01:00
|
|
|
if (mode == MODE_IMAGE) {
|
2011-08-19 12:06:19 +01:00
|
|
|
load_image(fileidx);
|
2011-09-03 16:01:39 +01:00
|
|
|
} else {
|
|
|
|
win_set_cursor(&win, CURSOR_WATCH);
|
2011-09-11 20:01:24 +01:00
|
|
|
if (!tns_load(&tns, tns.sel, &files[tns.sel], true, false)) {
|
|
|
|
remove_file(tns.sel, false);
|
|
|
|
tns.dirty = true;
|
2011-09-03 16:01:39 +01:00
|
|
|
if (tns.sel >= tns.cnt)
|
|
|
|
tns.sel = tns.cnt - 1;
|
|
|
|
}
|
2011-07-26 17:01:29 +01:00
|
|
|
}
|
2011-09-11 20:01:24 +01:00
|
|
|
return true;
|
2011-07-26 17:01:29 +01:00
|
|
|
}
|
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
bool it_remove_image(arg_t a) {
|
2011-08-19 12:09:22 +01:00
|
|
|
if (mode == MODE_IMAGE) {
|
2011-09-11 20:01:24 +01:00
|
|
|
remove_file(fileidx, true);
|
2011-08-19 12:06:19 +01:00
|
|
|
load_image(fileidx >= filecnt ? filecnt - 1 : fileidx);
|
2011-09-11 20:01:24 +01:00
|
|
|
return true;
|
2011-08-19 12:06:19 +01:00
|
|
|
} else if (tns.sel < tns.cnt) {
|
2011-09-11 20:01:24 +01:00
|
|
|
remove_file(tns.sel, true);
|
|
|
|
tns.dirty = true;
|
2011-08-19 12:06:19 +01:00
|
|
|
if (tns.sel >= tns.cnt)
|
|
|
|
tns.sel = tns.cnt - 1;
|
2011-09-11 20:01:24 +01:00
|
|
|
return true;
|
2011-07-26 17:01:29 +01:00
|
|
|
} else {
|
2011-09-11 20:01:24 +01:00
|
|
|
return false;
|
2011-07-26 17:01:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
bool i_navigate(arg_t a) {
|
2011-09-03 22:07:14 +01:00
|
|
|
long n = (long) a;
|
2011-08-12 16:14:14 +01:00
|
|
|
|
2011-08-19 12:09:22 +01:00
|
|
|
if (mode == MODE_IMAGE) {
|
2011-10-16 17:58:32 +01:00
|
|
|
if (prefix > 0)
|
2011-10-16 17:36:25 +01:00
|
|
|
n *= prefix;
|
2011-07-26 17:01:29 +01:00
|
|
|
n += fileidx;
|
|
|
|
if (n < 0)
|
|
|
|
n = 0;
|
|
|
|
if (n >= filecnt)
|
|
|
|
n = filecnt - 1;
|
|
|
|
|
|
|
|
if (n != fileidx) {
|
|
|
|
load_image(n);
|
2011-09-11 20:01:24 +01:00
|
|
|
return true;
|
2011-07-26 17:01:29 +01:00
|
|
|
}
|
|
|
|
}
|
2011-09-11 20:01:24 +01:00
|
|
|
return false;
|
2011-07-26 17:01:29 +01:00
|
|
|
}
|
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
bool it_first(arg_t a) {
|
2011-08-19 12:09:22 +01:00
|
|
|
if (mode == MODE_IMAGE && fileidx != 0) {
|
2011-07-26 17:01:29 +01:00
|
|
|
load_image(0);
|
2011-09-11 20:01:24 +01:00
|
|
|
return true;
|
2011-08-19 12:09:22 +01:00
|
|
|
} else if (mode == MODE_THUMB && tns.sel != 0) {
|
2011-07-26 17:01:29 +01:00
|
|
|
tns.sel = 0;
|
2011-09-11 20:01:24 +01:00
|
|
|
tns.dirty = true;
|
|
|
|
return true;
|
2011-07-26 17:01:29 +01:00
|
|
|
} else {
|
2011-09-11 20:01:24 +01:00
|
|
|
return false;
|
2011-07-26 17:01:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-16 15:08:55 +01:00
|
|
|
bool it_n_or_last(arg_t a) {
|
|
|
|
int n = prefix != 0 && prefix - 1 < filecnt ? prefix - 1 : filecnt - 1;
|
|
|
|
|
|
|
|
if (mode == MODE_IMAGE && fileidx != n) {
|
|
|
|
load_image(n);
|
2011-09-11 20:01:24 +01:00
|
|
|
return true;
|
2011-10-16 15:08:55 +01:00
|
|
|
} else if (mode == MODE_THUMB && tns.sel != n) {
|
|
|
|
tns.sel = n;
|
2011-09-11 20:01:24 +01:00
|
|
|
tns.dirty = true;
|
|
|
|
return true;
|
2011-07-26 17:01:29 +01:00
|
|
|
} else {
|
2011-09-11 20:01:24 +01:00
|
|
|
return false;
|
2011-07-26 17:01:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
bool i_navigate_frame(arg_t a) {
|
2011-08-19 17:46:17 +01:00
|
|
|
if (mode == MODE_IMAGE && !img.multi.animate)
|
2011-09-03 22:07:14 +01:00
|
|
|
return img_frame_navigate(&img, (long) a);
|
2011-08-19 17:46:17 +01:00
|
|
|
else
|
2011-09-11 20:01:24 +01:00
|
|
|
return false;
|
2011-08-19 17:46:17 +01:00
|
|
|
}
|
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
bool i_toggle_animation(arg_t a) {
|
2011-08-19 17:46:17 +01:00
|
|
|
if (mode != MODE_IMAGE)
|
2011-09-11 20:01:24 +01:00
|
|
|
return false;
|
2011-08-19 17:46:17 +01:00
|
|
|
|
|
|
|
if (img.multi.animate) {
|
2011-09-02 03:33:44 +01:00
|
|
|
reset_timeout(animate);
|
2011-09-11 20:01:24 +01:00
|
|
|
img.multi.animate = false;
|
|
|
|
} else if (img_frame_animate(&img, true)) {
|
|
|
|
set_timeout(animate, img.multi.frames[img.multi.sel].delay, true);
|
2011-08-19 17:46:17 +01:00
|
|
|
}
|
2011-09-11 20:01:24 +01:00
|
|
|
return true;
|
2011-08-16 23:56:18 +01:00
|
|
|
}
|
|
|
|
|
2011-10-27 15:21:01 +01:00
|
|
|
bool it_scroll_move(arg_t a) {
|
2011-08-12 16:14:14 +01:00
|
|
|
direction_t dir = (direction_t) a;
|
|
|
|
|
2011-08-19 12:09:22 +01:00
|
|
|
if (mode == MODE_IMAGE)
|
2011-10-16 16:39:22 +01:00
|
|
|
return img_pan(&img, dir, prefix);
|
2011-07-26 17:01:29 +01:00
|
|
|
else
|
2011-09-17 16:23:51 +01:00
|
|
|
return tns_move_selection(&tns, dir);
|
2011-07-26 17:01:29 +01:00
|
|
|
}
|
|
|
|
|
2011-10-27 15:21:01 +01:00
|
|
|
bool it_scroll_screen(arg_t a) {
|
2011-08-12 16:14:14 +01:00
|
|
|
direction_t dir = (direction_t) a;
|
|
|
|
|
2011-08-19 12:09:22 +01:00
|
|
|
if (mode == MODE_IMAGE)
|
2011-10-16 16:39:22 +01:00
|
|
|
return img_pan(&img, dir, -1);
|
2011-07-26 17:01:29 +01:00
|
|
|
else
|
2011-10-27 15:21:01 +01:00
|
|
|
return tns_scroll(&tns, dir, true);
|
2011-07-26 17:01:29 +01:00
|
|
|
}
|
|
|
|
|
2011-10-27 15:21:01 +01:00
|
|
|
bool i_scroll_to_edge(arg_t a) {
|
2011-08-12 16:14:14 +01:00
|
|
|
direction_t dir = (direction_t) a;
|
|
|
|
|
2011-08-19 12:09:22 +01:00
|
|
|
if (mode == MODE_IMAGE)
|
2011-09-17 16:23:51 +01:00
|
|
|
return img_pan_edge(&img, dir);
|
2011-07-26 17:01:29 +01:00
|
|
|
else
|
2011-09-11 20:01:24 +01:00
|
|
|
return false;
|
2011-07-26 17:01:29 +01:00
|
|
|
}
|
|
|
|
|
2011-08-19 12:06:19 +01:00
|
|
|
/* Xlib helper function for i_drag() */
|
2011-08-12 16:14:14 +01:00
|
|
|
Bool is_motionnotify(Display *d, XEvent *e, XPointer a) {
|
2011-08-12 11:27:07 +01:00
|
|
|
return e != NULL && e->type == MotionNotify;
|
|
|
|
}
|
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
bool i_drag(arg_t a) {
|
2011-08-12 11:27:07 +01:00
|
|
|
int dx = 0, dy = 0, i, ox, oy, x, y;
|
|
|
|
unsigned int ui;
|
2011-09-11 20:01:24 +01:00
|
|
|
bool dragging = true, next = false;
|
2011-08-12 11:27:07 +01:00
|
|
|
XEvent e;
|
|
|
|
Window w;
|
|
|
|
|
2011-08-19 12:09:22 +01:00
|
|
|
if (mode != MODE_IMAGE)
|
2011-09-11 20:01:24 +01:00
|
|
|
return false;
|
2011-08-12 11:27:07 +01:00
|
|
|
if (!XQueryPointer(win.env.dpy, win.xwin, &w, &w, &i, &i, &ox, &oy, &ui))
|
2011-09-11 20:01:24 +01:00
|
|
|
return false;
|
2011-08-12 11:27:07 +01:00
|
|
|
|
|
|
|
win_set_cursor(&win, CURSOR_HAND);
|
|
|
|
|
|
|
|
while (dragging) {
|
|
|
|
if (!next)
|
|
|
|
XMaskEvent(win.env.dpy,
|
|
|
|
ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &e);
|
|
|
|
switch (e.type) {
|
|
|
|
case ButtonPress:
|
|
|
|
case ButtonRelease:
|
2011-09-11 20:01:24 +01:00
|
|
|
dragging = false;
|
2011-08-12 11:27:07 +01:00
|
|
|
break;
|
|
|
|
case MotionNotify:
|
|
|
|
x = e.xmotion.x;
|
|
|
|
y = e.xmotion.y;
|
|
|
|
if (x >= 0 && x <= win.w && y >= 0 && y <= win.h) {
|
|
|
|
dx += x - ox;
|
|
|
|
dy += y - oy;
|
|
|
|
}
|
|
|
|
ox = x;
|
|
|
|
oy = y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (dragging)
|
2011-08-12 16:14:14 +01:00
|
|
|
next = XCheckIfEvent(win.env.dpy, &e, is_motionnotify, None);
|
2011-08-12 11:27:07 +01:00
|
|
|
if ((!dragging || !next) && (dx != 0 || dy != 0)) {
|
2011-09-17 16:23:51 +01:00
|
|
|
if (img_move(&img, dx, dy))
|
|
|
|
img_render(&img);
|
2011-08-12 11:27:07 +01:00
|
|
|
dx = dy = 0;
|
|
|
|
}
|
2011-07-26 17:01:29 +01:00
|
|
|
}
|
2011-08-12 11:27:07 +01:00
|
|
|
|
|
|
|
win_set_cursor(&win, CURSOR_ARROW);
|
2011-09-11 20:01:24 +01:00
|
|
|
set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
|
2011-09-02 03:33:44 +01:00
|
|
|
reset_timeout(redraw);
|
2011-08-12 11:27:07 +01:00
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
return false;
|
2011-07-26 17:01:29 +01:00
|
|
|
}
|
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
bool i_zoom(arg_t a) {
|
2011-09-03 22:07:14 +01:00
|
|
|
long scale = (long) a;
|
2011-08-12 16:14:14 +01:00
|
|
|
|
2011-08-19 12:09:22 +01:00
|
|
|
if (mode != MODE_IMAGE)
|
2011-09-11 20:01:24 +01:00
|
|
|
return false;
|
2011-08-19 17:46:17 +01:00
|
|
|
|
2011-07-26 17:01:29 +01:00
|
|
|
if (scale > 0)
|
2011-09-17 16:23:51 +01:00
|
|
|
return img_zoom_in(&img);
|
2011-07-26 17:01:29 +01:00
|
|
|
else if (scale < 0)
|
2011-09-17 16:23:51 +01:00
|
|
|
return img_zoom_out(&img);
|
2011-07-26 17:01:29 +01:00
|
|
|
else
|
2011-10-16 16:58:53 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool i_set_zoom(arg_t a) {
|
|
|
|
if (mode == MODE_IMAGE)
|
|
|
|
return img_zoom(&img, (prefix ? prefix : (long) a) / 100.0);
|
|
|
|
else
|
|
|
|
return false;
|
2011-07-26 17:01:29 +01:00
|
|
|
}
|
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
bool i_fit_to_win(arg_t a) {
|
2011-09-29 11:43:36 +01:00
|
|
|
bool ret = false;
|
2011-08-12 16:14:14 +01:00
|
|
|
|
2011-08-19 12:09:22 +01:00
|
|
|
if (mode == MODE_IMAGE) {
|
2011-09-17 16:23:51 +01:00
|
|
|
if ((ret = img_fit_win(&img)))
|
|
|
|
img_center(&img);
|
2011-07-26 17:01:29 +01:00
|
|
|
}
|
2011-09-29 11:43:36 +01:00
|
|
|
return ret;
|
2011-07-26 17:01:29 +01:00
|
|
|
}
|
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
bool i_fit_to_img(arg_t a) {
|
|
|
|
int x, y;
|
2011-07-26 17:01:29 +01:00
|
|
|
unsigned int w, h;
|
2011-09-29 11:43:36 +01:00
|
|
|
bool ret = false;
|
2011-07-26 17:01:29 +01:00
|
|
|
|
2011-08-19 12:09:22 +01:00
|
|
|
if (mode == MODE_IMAGE) {
|
2011-07-26 17:01:29 +01:00
|
|
|
x = MAX(0, win.x + img.x);
|
|
|
|
y = MAX(0, win.y + img.y);
|
|
|
|
w = img.w * img.zoom;
|
|
|
|
h = img.h * img.zoom;
|
|
|
|
if ((ret = win_moveresize(&win, x, y, w, h))) {
|
|
|
|
img.x = x - win.x;
|
|
|
|
img.y = y - win.y;
|
|
|
|
}
|
|
|
|
}
|
2011-09-29 11:43:36 +01:00
|
|
|
return ret;
|
2011-07-26 17:01:29 +01:00
|
|
|
}
|
2011-08-12 16:14:14 +01:00
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
bool i_rotate(arg_t a) {
|
2011-08-19 12:06:19 +01:00
|
|
|
direction_t dir = (direction_t) a;
|
|
|
|
|
2011-08-19 12:09:22 +01:00
|
|
|
if (mode == MODE_IMAGE) {
|
2011-08-19 12:06:19 +01:00
|
|
|
if (dir == DIR_LEFT) {
|
2011-09-17 16:23:51 +01:00
|
|
|
img_rotate_left(&img);
|
2011-09-11 20:01:24 +01:00
|
|
|
return true;
|
2011-08-19 12:06:19 +01:00
|
|
|
} else if (dir == DIR_RIGHT) {
|
2011-09-17 16:23:51 +01:00
|
|
|
img_rotate_right(&img);
|
2011-09-11 20:01:24 +01:00
|
|
|
return true;
|
2011-08-19 12:06:19 +01:00
|
|
|
}
|
|
|
|
}
|
2011-09-11 20:01:24 +01:00
|
|
|
return false;
|
2011-08-19 12:06:19 +01:00
|
|
|
}
|
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
bool i_toggle_slideshow(arg_t a) {
|
2011-09-10 17:41:20 +01:00
|
|
|
if (mode == MODE_IMAGE) {
|
|
|
|
if (img.slideshow) {
|
2011-09-11 20:01:24 +01:00
|
|
|
img.slideshow = false;
|
2011-09-10 17:41:20 +01:00
|
|
|
reset_timeout(slideshow);
|
2011-09-11 20:01:24 +01:00
|
|
|
return true;
|
2011-09-10 17:41:20 +01:00
|
|
|
} else if (fileidx + 1 < filecnt) {
|
2011-09-11 20:01:24 +01:00
|
|
|
img.slideshow = true;
|
|
|
|
set_timeout(slideshow, img.ss_delay, true);
|
|
|
|
return true;
|
2011-09-10 17:41:20 +01:00
|
|
|
}
|
|
|
|
}
|
2011-09-11 20:01:24 +01:00
|
|
|
return false;
|
2011-09-10 17:41:20 +01:00
|
|
|
}
|
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
bool i_adjust_slideshow(arg_t a) {
|
2011-09-10 17:41:20 +01:00
|
|
|
long d = (long) a;
|
2011-10-16 17:58:32 +01:00
|
|
|
int i;
|
2011-09-10 17:41:20 +01:00
|
|
|
|
|
|
|
if (mode != MODE_IMAGE || !img.slideshow)
|
2011-09-11 20:01:24 +01:00
|
|
|
return false;
|
2011-09-10 17:41:20 +01:00
|
|
|
|
|
|
|
if (d < 0) {
|
2011-10-16 17:58:32 +01:00
|
|
|
for (i = ARRLEN(ss_delays) - 2; i >= 0; i--) {
|
|
|
|
if (img.ss_delay > ss_delays[i] * 1000) {
|
|
|
|
img.ss_delay = ss_delays[i] * 1000;
|
2011-09-11 20:01:24 +01:00
|
|
|
return true;
|
2011-09-10 17:41:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2011-10-16 17:58:32 +01:00
|
|
|
for (i = 1; i < ARRLEN(ss_delays); i++) {
|
|
|
|
if (img.ss_delay < ss_delays[i] * 1000) {
|
|
|
|
img.ss_delay = ss_delays[i] * 1000;
|
2011-09-11 20:01:24 +01:00
|
|
|
return true;
|
2011-09-10 17:41:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-09-11 20:01:24 +01:00
|
|
|
return false;
|
2011-09-10 17:41:20 +01:00
|
|
|
}
|
|
|
|
|
2011-10-16 17:58:32 +01:00
|
|
|
bool i_reset_slideshow(arg_t a) {
|
|
|
|
if (mode != MODE_IMAGE || !img.slideshow)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (prefix > 0) {
|
|
|
|
img.ss_delay = MIN(prefix, ss_delays[ARRLEN(ss_delays) - 1]);
|
|
|
|
img.ss_delay = MAX(img.ss_delay, ss_delays[0]) * 1000;
|
|
|
|
} else {
|
|
|
|
img.ss_delay = SLIDESHOW_DELAY * 1000;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
bool i_toggle_antialias(arg_t a) {
|
2011-08-19 12:09:22 +01:00
|
|
|
if (mode == MODE_IMAGE) {
|
2011-08-19 12:06:19 +01:00
|
|
|
img_toggle_antialias(&img);
|
2011-09-11 20:01:24 +01:00
|
|
|
return true;
|
2011-08-19 12:06:19 +01:00
|
|
|
} else {
|
2011-09-11 20:01:24 +01:00
|
|
|
return false;
|
2011-08-19 12:06:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
bool it_toggle_alpha(arg_t a) {
|
|
|
|
img.alpha = tns.alpha = !img.alpha;
|
|
|
|
if (mode == MODE_IMAGE)
|
|
|
|
img.dirty = true;
|
|
|
|
else
|
|
|
|
tns.dirty = true;
|
|
|
|
return true;
|
2011-08-19 12:06:19 +01:00
|
|
|
}
|
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
bool it_open_with(arg_t a) {
|
2011-08-12 16:14:14 +01:00
|
|
|
const char *prog = (const char*) a;
|
|
|
|
pid_t pid;
|
|
|
|
|
2011-09-29 11:43:36 +01:00
|
|
|
if (prog == NULL || *prog == '\0')
|
2011-09-11 20:01:24 +01:00
|
|
|
return false;
|
2011-08-12 16:14:14 +01:00
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
if ((pid = fork()) == 0) {
|
2011-08-12 16:14:14 +01:00
|
|
|
execlp(prog, prog,
|
2011-08-19 12:09:22 +01:00
|
|
|
files[mode == MODE_IMAGE ? fileidx : tns.sel].path, NULL);
|
2011-08-12 16:14:14 +01:00
|
|
|
warn("could not exec: %s", prog);
|
2011-09-26 14:40:07 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2011-08-12 16:14:14 +01:00
|
|
|
} else if (pid < 0) {
|
2011-09-03 14:58:58 +01:00
|
|
|
warn("could not fork. program was: %s", prog);
|
2011-08-12 16:14:14 +01:00
|
|
|
}
|
2011-09-11 20:01:24 +01:00
|
|
|
return false;
|
2011-08-12 16:14:14 +01:00
|
|
|
}
|
|
|
|
|
2011-09-11 20:01:24 +01:00
|
|
|
bool it_shell_cmd(arg_t a) {
|
2011-09-03 14:58:58 +01:00
|
|
|
int n, status;
|
|
|
|
const char *cmdline = (const char*) a;
|
2011-08-12 16:14:14 +01:00
|
|
|
pid_t pid;
|
|
|
|
|
2011-09-29 11:43:36 +01:00
|
|
|
if (cmdline == NULL || *cmdline == '\0')
|
|
|
|
return false;
|
2011-08-12 16:14:14 +01:00
|
|
|
|
2011-09-03 14:58:58 +01:00
|
|
|
n = mode == MODE_IMAGE ? fileidx : tns.sel;
|
|
|
|
|
|
|
|
if (setenv("SXIV_IMG", files[n].path, 1) < 0) {
|
2011-09-10 17:41:20 +01:00
|
|
|
warn("could not set env.-variable: SXIV_IMG. command line was: %s",
|
2011-09-03 14:58:58 +01:00
|
|
|
cmdline);
|
2011-09-11 20:01:24 +01:00
|
|
|
return false;
|
2011-08-12 16:14:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((pid = fork()) == 0) {
|
|
|
|
execl("/bin/sh", "/bin/sh", "-c", cmdline, NULL);
|
2011-09-10 17:41:20 +01:00
|
|
|
warn("could not exec: /bin/sh. command line was: %s", cmdline);
|
2011-09-26 14:40:07 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2011-08-12 16:14:14 +01:00
|
|
|
} else if (pid < 0) {
|
|
|
|
warn("could not fork. command line was: %s", cmdline);
|
2011-09-11 20:01:24 +01:00
|
|
|
return false;
|
2011-08-12 16:14:14 +01:00
|
|
|
}
|
|
|
|
|
2011-09-03 16:01:39 +01:00
|
|
|
win_set_cursor(&win, CURSOR_WATCH);
|
|
|
|
|
2011-08-12 16:14:14 +01:00
|
|
|
waitpid(pid, &status, 0);
|
2011-09-29 11:43:36 +01:00
|
|
|
if (WIFEXITED(status) == 0 || WEXITSTATUS(status) != 0)
|
2011-08-12 16:14:14 +01:00
|
|
|
warn("child exited with non-zero return value: %d. command line was: %s",
|
|
|
|
WEXITSTATUS(status), cmdline);
|
|
|
|
|
2011-08-19 12:09:22 +01:00
|
|
|
if (mode == MODE_IMAGE) {
|
2011-09-11 20:01:24 +01:00
|
|
|
img_close(&img, true);
|
2011-08-12 16:14:14 +01:00
|
|
|
load_image(fileidx);
|
2011-09-03 14:58:58 +01:00
|
|
|
}
|
2011-09-11 20:01:24 +01:00
|
|
|
if (!tns_load(&tns, n, &files[n], true, mode == MODE_IMAGE) &&
|
2011-09-03 14:58:58 +01:00
|
|
|
mode == MODE_THUMB)
|
|
|
|
{
|
2011-09-11 20:01:24 +01:00
|
|
|
remove_file(tns.sel, false);
|
|
|
|
tns.dirty = true;
|
2011-09-03 14:58:58 +01:00
|
|
|
if (tns.sel >= tns.cnt)
|
|
|
|
tns.sel = tns.cnt - 1;
|
2011-08-12 16:14:14 +01:00
|
|
|
}
|
2011-09-11 20:01:24 +01:00
|
|
|
return true;
|
2011-08-12 16:14:14 +01:00
|
|
|
}
|