2014-07-23 21:50:31 +02:00
|
|
|
/* Copyright 2011, 2012, 2014 Bert Muennich
|
2011-07-26 18:01:29 +02:00
|
|
|
*
|
2013-02-08 21:52:41 +01:00
|
|
|
* This file is part of sxiv.
|
2011-08-18 01:18:26 +02:00
|
|
|
*
|
2013-02-08 21:52:41 +01:00
|
|
|
* sxiv 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 01:18:26 +02:00
|
|
|
*
|
2013-02-08 21:52:41 +01:00
|
|
|
* sxiv 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with sxiv. If not, see <http://www.gnu.org/licenses/>.
|
2011-07-26 18:01:29 +02:00
|
|
|
*/
|
|
|
|
|
2011-09-08 20:54:24 +02:00
|
|
|
#define _POSIX_C_SOURCE 200112L
|
2011-10-16 18:58:32 +02:00
|
|
|
#define _IMAGE_CONFIG
|
2011-09-03 15:58:58 +02:00
|
|
|
|
2011-09-08 20:54:24 +02:00
|
|
|
#include <stdlib.h>
|
2011-07-26 18:01:29 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
2011-08-19 15:02:10 +02:00
|
|
|
#include "commands.h"
|
2011-07-26 18:01:29 +02:00
|
|
|
#include "image.h"
|
2013-03-19 21:11:29 +01:00
|
|
|
#include "options.h"
|
2011-07-26 18:01:29 +02:00
|
|
|
#include "thumbs.h"
|
|
|
|
#include "util.h"
|
2011-10-16 18:58:32 +02:00
|
|
|
#include "config.h"
|
2011-07-26 18:01:29 +02:00
|
|
|
|
2011-10-12 18:38:29 +02:00
|
|
|
void cleanup(void);
|
2011-09-11 21:01:24 +02:00
|
|
|
void remove_file(int, bool);
|
2011-07-26 18:01:29 +02:00
|
|
|
void load_image(int);
|
2013-02-12 17:55:47 +01:00
|
|
|
void open_info(void);
|
2011-10-12 18:38:29 +02:00
|
|
|
void redraw(void);
|
|
|
|
void reset_cursor(void);
|
|
|
|
void animate(void);
|
2014-01-04 18:38:40 +01:00
|
|
|
void slideshow(void);
|
2011-09-11 21:01:24 +02:00
|
|
|
void set_timeout(timeout_f, int, bool);
|
2011-09-02 04:33:44 +02:00
|
|
|
void reset_timeout(timeout_f);
|
2011-07-26 18:01:29 +02:00
|
|
|
|
|
|
|
extern appmode_t mode;
|
|
|
|
extern img_t img;
|
|
|
|
extern tns_t tns;
|
|
|
|
extern win_t win;
|
|
|
|
|
2011-08-18 00:38:55 +02:00
|
|
|
extern fileinfo_t *files;
|
2011-07-26 18:01:29 +02:00
|
|
|
extern int filecnt, fileidx;
|
2012-08-16 13:40:04 +02:00
|
|
|
extern int alternate;
|
2014-08-16 19:24:34 +02:00
|
|
|
extern int markcnt;
|
2011-07-26 18:01:29 +02:00
|
|
|
|
2011-10-16 16:08:55 +02:00
|
|
|
extern int prefix;
|
2014-01-31 13:21:23 +01:00
|
|
|
extern bool extprefix;
|
2011-10-16 16:08:55 +02:00
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool cg_quit(arg_t a)
|
2013-02-08 22:05:31 +01:00
|
|
|
{
|
2013-03-19 21:11:29 +01:00
|
|
|
unsigned int i;
|
|
|
|
|
2014-08-16 19:24:34 +02:00
|
|
|
if (options->to_stdout && markcnt > 0) {
|
2013-08-10 21:18:53 +02:00
|
|
|
for (i = 0; i < filecnt; i++) {
|
2013-08-22 09:44:14 +02:00
|
|
|
if (files[i].marked)
|
2013-08-10 21:18:53 +02:00
|
|
|
printf("%s\n", files[i].name);
|
|
|
|
}
|
2013-03-19 21:11:29 +01:00
|
|
|
}
|
2011-07-26 18:01:29 +02:00
|
|
|
cleanup();
|
2011-09-26 15:40:07 +02:00
|
|
|
exit(EXIT_SUCCESS);
|
2011-07-26 18:01:29 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool cg_switch_mode(arg_t a)
|
2013-02-08 22:05:31 +01:00
|
|
|
{
|
2011-08-19 13:09:22 +02:00
|
|
|
if (mode == MODE_IMAGE) {
|
2014-04-06 22:47:42 +02:00
|
|
|
if (tns.thumbs == NULL)
|
2014-09-30 21:54:17 +02:00
|
|
|
tns_init(&tns, files, &filecnt, &fileidx, &win);
|
2011-09-11 21:01:24 +02:00
|
|
|
img_close(&img, false);
|
2011-09-03 17:01:39 +02:00
|
|
|
reset_timeout(reset_cursor);
|
2014-01-04 18:38:40 +01:00
|
|
|
if (img.ss.on) {
|
|
|
|
img.ss.on = false;
|
|
|
|
reset_timeout(slideshow);
|
|
|
|
}
|
2011-09-11 21:01:24 +02:00
|
|
|
tns.dirty = true;
|
2011-08-19 13:09:22 +02:00
|
|
|
mode = MODE_THUMB;
|
2011-07-26 18:01:29 +02:00
|
|
|
} else {
|
2014-08-16 18:36:17 +02:00
|
|
|
load_image(fileidx);
|
2011-08-19 13:09:22 +02:00
|
|
|
mode = MODE_IMAGE;
|
2011-07-26 18:01:29 +02:00
|
|
|
}
|
2014-07-23 21:50:31 +02:00
|
|
|
return true;
|
2011-07-26 18:01:29 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool cg_toggle_fullscreen(arg_t a)
|
2013-02-08 22:05:31 +01:00
|
|
|
{
|
2011-07-26 18:01:29 +02:00
|
|
|
win_toggle_fullscreen(&win);
|
2012-02-15 22:33:39 +01:00
|
|
|
/* redraw after next ConfigureNotify event */
|
2011-09-11 21:01:24 +02:00
|
|
|
set_timeout(redraw, TO_REDRAW_RESIZE, false);
|
2011-08-19 13:09:22 +02:00
|
|
|
if (mode == MODE_IMAGE)
|
2012-05-14 21:45:24 +02:00
|
|
|
img.checkpan = img.dirty = true;
|
2011-07-26 18:01:29 +02:00
|
|
|
else
|
2011-09-11 21:01:24 +02:00
|
|
|
tns.dirty = true;
|
2014-07-23 21:50:31 +02:00
|
|
|
return false;
|
2011-07-26 18:01:29 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool cg_toggle_bar(arg_t a)
|
2013-02-08 22:05:31 +01:00
|
|
|
{
|
2012-02-15 22:33:39 +01:00
|
|
|
win_toggle_bar(&win);
|
2013-02-12 17:55:47 +01:00
|
|
|
if (mode == MODE_IMAGE) {
|
2012-02-15 22:33:39 +01:00
|
|
|
img.checkpan = img.dirty = true;
|
2013-02-12 17:55:47 +01:00
|
|
|
if (win.bar.h > 0)
|
|
|
|
open_info();
|
|
|
|
} else {
|
2012-02-15 22:33:39 +01:00
|
|
|
tns.dirty = true;
|
2013-02-12 17:55:47 +01:00
|
|
|
}
|
2014-07-23 21:50:31 +02:00
|
|
|
return true;
|
2012-02-15 22:33:39 +01:00
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool cg_prefix_external(arg_t a)
|
2014-01-31 13:21:23 +01:00
|
|
|
{
|
|
|
|
extprefix = true;
|
2014-07-23 21:50:31 +02:00
|
|
|
return false;
|
2014-01-31 13:21:23 +01:00
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool cg_reload_image(arg_t a)
|
2013-02-08 22:05:31 +01:00
|
|
|
{
|
2011-08-19 13:09:22 +02:00
|
|
|
if (mode == MODE_IMAGE) {
|
2011-08-19 13:06:19 +02:00
|
|
|
load_image(fileidx);
|
2011-09-03 17:01:39 +02:00
|
|
|
} else {
|
|
|
|
win_set_cursor(&win, CURSOR_WATCH);
|
2014-08-16 22:21:51 +02:00
|
|
|
if (!tns_load(&tns, fileidx, true)) {
|
2014-08-16 18:36:17 +02:00
|
|
|
remove_file(fileidx, false);
|
2011-09-11 21:01:24 +02:00
|
|
|
tns.dirty = true;
|
2011-09-03 17:01:39 +02:00
|
|
|
}
|
2011-07-26 18:01:29 +02:00
|
|
|
}
|
2014-07-23 21:50:31 +02:00
|
|
|
return true;
|
2011-07-26 18:01:29 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool cg_remove_image(arg_t a)
|
2013-02-08 22:05:31 +01:00
|
|
|
{
|
2014-09-30 21:54:17 +02:00
|
|
|
remove_file(fileidx, true);
|
|
|
|
if (mode == MODE_IMAGE)
|
|
|
|
load_image(fileidx);
|
|
|
|
else
|
2011-09-11 21:01:24 +02:00
|
|
|
tns.dirty = true;
|
2014-09-30 21:54:17 +02:00
|
|
|
return true;
|
2012-08-16 13:40:04 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool cg_first(arg_t a)
|
2013-02-08 22:05:31 +01:00
|
|
|
{
|
2011-08-19 13:09:22 +02:00
|
|
|
if (mode == MODE_IMAGE && fileidx != 0) {
|
2011-07-26 18:01:29 +02:00
|
|
|
load_image(0);
|
2014-07-23 21:50:31 +02:00
|
|
|
return true;
|
2014-08-16 18:36:17 +02:00
|
|
|
} else if (mode == MODE_THUMB && fileidx != 0) {
|
|
|
|
fileidx = 0;
|
2011-09-11 21:01:24 +02:00
|
|
|
tns.dirty = true;
|
2014-07-23 21:50:31 +02:00
|
|
|
return true;
|
2011-07-26 18:01:29 +02:00
|
|
|
} else {
|
2014-07-23 21:50:31 +02:00
|
|
|
return false;
|
2011-07-26 18:01:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool cg_n_or_last(arg_t a)
|
2013-02-08 22:05:31 +01:00
|
|
|
{
|
2011-10-16 16:08:55 +02:00
|
|
|
int n = prefix != 0 && prefix - 1 < filecnt ? prefix - 1 : filecnt - 1;
|
|
|
|
|
|
|
|
if (mode == MODE_IMAGE && fileidx != n) {
|
|
|
|
load_image(n);
|
2014-07-23 21:50:31 +02:00
|
|
|
return true;
|
2014-08-16 18:36:17 +02:00
|
|
|
} else if (mode == MODE_THUMB && fileidx != n) {
|
|
|
|
fileidx = n;
|
2011-09-11 21:01:24 +02:00
|
|
|
tns.dirty = true;
|
2014-07-23 21:50:31 +02:00
|
|
|
return true;
|
2011-07-26 18:01:29 +02:00
|
|
|
} else {
|
2014-07-23 21:50:31 +02:00
|
|
|
return false;
|
2011-07-26 18:01:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool cg_scroll_screen(arg_t a)
|
2013-02-08 22:05:31 +01:00
|
|
|
{
|
2014-07-23 21:50:31 +02:00
|
|
|
direction_t dir = (direction_t) a;
|
2011-08-19 18:46:17 +02:00
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
if (mode == MODE_IMAGE)
|
|
|
|
return img_pan(&img, dir, -1);
|
|
|
|
else
|
|
|
|
return tns_scroll(&tns, dir, true);
|
2011-08-17 00:56:18 +02:00
|
|
|
}
|
|
|
|
|
2014-09-28 00:26:02 +02:00
|
|
|
bool cg_zoom(arg_t a)
|
|
|
|
{
|
|
|
|
long d = (long) a;
|
|
|
|
|
|
|
|
if (mode == MODE_THUMB)
|
|
|
|
return tns_zoom(&tns, d);
|
|
|
|
else if (d > 0)
|
|
|
|
return img_zoom_in(&img);
|
|
|
|
else if (d < 0)
|
|
|
|
return img_zoom_out(&img);
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool cg_toggle_image_mark(arg_t a)
|
2013-08-10 21:18:53 +02:00
|
|
|
{
|
2014-08-16 18:36:17 +02:00
|
|
|
files[fileidx].marked = !files[fileidx].marked;
|
2014-08-16 19:24:34 +02:00
|
|
|
markcnt += files[fileidx].marked ? 1 : -1;
|
2013-11-14 14:37:08 +01:00
|
|
|
if (mode == MODE_THUMB)
|
2014-08-16 18:36:17 +02:00
|
|
|
tns_mark(&tns, fileidx, files[fileidx].marked);
|
2014-07-23 21:50:31 +02:00
|
|
|
return true;
|
2013-08-10 21:18:53 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool cg_reverse_marks(arg_t a)
|
2013-11-14 14:45:27 +01:00
|
|
|
{
|
2014-08-16 19:24:34 +02:00
|
|
|
int i;
|
2013-11-14 14:45:27 +01:00
|
|
|
|
2014-08-16 19:24:34 +02:00
|
|
|
for (i = 0; i < filecnt; i++) {
|
2013-11-14 14:45:27 +01:00
|
|
|
files[i].marked = !files[i].marked;
|
2014-08-16 19:24:34 +02:00
|
|
|
markcnt += files[i].marked ? 1 : -1;
|
|
|
|
}
|
2013-11-14 17:16:09 +01:00
|
|
|
if (mode == MODE_THUMB)
|
|
|
|
tns.dirty = true;
|
2014-07-23 21:50:31 +02:00
|
|
|
return true;
|
2013-11-14 14:45:27 +01:00
|
|
|
}
|
|
|
|
|
2014-08-17 20:27:01 +02:00
|
|
|
bool cg_unmark_all(arg_t a)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < filecnt; i++)
|
|
|
|
files[i].marked = false;
|
|
|
|
markcnt = 0;
|
|
|
|
if (mode == MODE_THUMB)
|
|
|
|
tns.dirty = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool cg_navigate_marked(arg_t a)
|
2013-08-10 21:18:53 +02:00
|
|
|
{
|
|
|
|
long n = (long) a;
|
2014-08-16 18:36:17 +02:00
|
|
|
int d, i;
|
2014-09-30 21:54:17 +02:00
|
|
|
int new = fileidx;
|
2013-08-10 21:18:53 +02:00
|
|
|
|
|
|
|
if (prefix > 0)
|
|
|
|
n *= prefix;
|
|
|
|
d = n > 0 ? 1 : -1;
|
2014-09-30 21:54:17 +02:00
|
|
|
for (i = fileidx + d; n != 0 && i >= 0 && i < filecnt; i += d) {
|
2013-08-10 21:18:53 +02:00
|
|
|
if (files[i].marked) {
|
|
|
|
n -= d;
|
|
|
|
new = i;
|
|
|
|
}
|
|
|
|
}
|
2014-08-16 18:36:17 +02:00
|
|
|
if (new != fileidx) {
|
2013-08-10 21:18:53 +02:00
|
|
|
if (mode == MODE_IMAGE) {
|
|
|
|
load_image(new);
|
|
|
|
} else {
|
2014-08-16 18:36:17 +02:00
|
|
|
fileidx = new;
|
2013-08-10 21:18:53 +02:00
|
|
|
tns.dirty = true;
|
|
|
|
}
|
2014-07-23 21:50:31 +02:00
|
|
|
return true;
|
2013-08-10 21:18:53 +02:00
|
|
|
} else {
|
2014-07-23 21:50:31 +02:00
|
|
|
return false;
|
2013-08-10 21:18:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool ci_navigate(arg_t a)
|
2013-02-08 22:05:31 +01:00
|
|
|
{
|
2014-07-23 21:50:31 +02:00
|
|
|
long n = (long) a;
|
2011-08-12 17:14:14 +02:00
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
if (prefix > 0)
|
|
|
|
n *= prefix;
|
|
|
|
n += fileidx;
|
|
|
|
if (n < 0)
|
|
|
|
n = 0;
|
|
|
|
if (n >= filecnt)
|
|
|
|
n = filecnt - 1;
|
|
|
|
|
|
|
|
if (n != fileidx) {
|
|
|
|
load_image(n);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ci_alternate(arg_t a)
|
|
|
|
{
|
|
|
|
load_image(alternate);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ci_navigate_frame(arg_t a)
|
|
|
|
{
|
|
|
|
return !img.multi.animate && img_frame_navigate(&img, (long) a);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ci_toggle_animation(arg_t a)
|
|
|
|
{
|
2014-07-25 22:52:31 +02:00
|
|
|
bool dirty = false;
|
|
|
|
|
2014-09-01 20:40:17 +02:00
|
|
|
if (img.multi.cnt > 0) {
|
|
|
|
img.multi.animate = !img.multi.animate;
|
|
|
|
if (img.multi.animate) {
|
2014-09-01 20:41:27 +02:00
|
|
|
dirty = img_frame_animate(&img);
|
2014-09-01 20:40:17 +02:00
|
|
|
set_timeout(animate, img.multi.frames[img.multi.sel].delay, true);
|
|
|
|
} else {
|
|
|
|
reset_timeout(animate);
|
|
|
|
}
|
2014-07-23 21:50:31 +02:00
|
|
|
}
|
2014-07-25 22:52:31 +02:00
|
|
|
return dirty;
|
2011-07-26 18:01:29 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool ci_scroll(arg_t a)
|
2013-02-08 22:05:31 +01:00
|
|
|
{
|
2011-08-12 17:14:14 +02:00
|
|
|
direction_t dir = (direction_t) a;
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
return img_pan(&img, dir, prefix);
|
2011-07-26 18:01:29 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool ci_scroll_to_edge(arg_t a)
|
2013-02-08 22:05:31 +01:00
|
|
|
{
|
2011-08-12 17:14:14 +02:00
|
|
|
direction_t dir = (direction_t) a;
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
return img_pan_edge(&img, dir);
|
2011-07-26 18:01:29 +02:00
|
|
|
}
|
|
|
|
|
2011-08-19 13:06:19 +02:00
|
|
|
/* Xlib helper function for i_drag() */
|
2013-02-08 22:05:31 +01:00
|
|
|
Bool is_motionnotify(Display *d, XEvent *e, XPointer a)
|
|
|
|
{
|
2011-08-12 12:27:07 +02:00
|
|
|
return e != NULL && e->type == MotionNotify;
|
|
|
|
}
|
|
|
|
|
2013-03-04 19:23:07 +01:00
|
|
|
#define WARP(x,y) \
|
|
|
|
XWarpPointer(win.env.dpy, None, win.xwin, 0, 0, 0, 0, x, y); \
|
|
|
|
ox = x, oy = y; \
|
|
|
|
break
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool ci_drag(arg_t a)
|
2013-02-08 22:05:31 +01:00
|
|
|
{
|
2011-08-12 12:27:07 +02:00
|
|
|
int dx = 0, dy = 0, i, ox, oy, x, y;
|
|
|
|
unsigned int ui;
|
2011-09-11 21:01:24 +02:00
|
|
|
bool dragging = true, next = false;
|
2011-08-12 12:27:07 +02:00
|
|
|
XEvent e;
|
|
|
|
Window w;
|
|
|
|
|
|
|
|
if (!XQueryPointer(win.env.dpy, win.xwin, &w, &w, &i, &i, &ox, &oy, &ui))
|
2014-07-23 21:50:31 +02:00
|
|
|
return false;
|
2011-08-12 12:27:07 +02: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 21:01:24 +02:00
|
|
|
dragging = false;
|
2011-08-12 12:27:07 +02:00
|
|
|
break;
|
|
|
|
case MotionNotify:
|
|
|
|
x = e.xmotion.x;
|
|
|
|
y = e.xmotion.y;
|
2013-03-03 19:16:32 +01:00
|
|
|
|
|
|
|
/* wrap the mouse around */
|
2013-09-07 17:06:47 +02:00
|
|
|
if (x <= 0) {
|
|
|
|
WARP(win.w - 2, y);
|
|
|
|
} else if (x >= win.w - 1) {
|
|
|
|
WARP(1, y);
|
|
|
|
} else if (y <= 0) {
|
|
|
|
WARP(x, win.h - 2);
|
|
|
|
} else if (y >= win.h - 1) {
|
|
|
|
WARP(x, 1);
|
2011-08-12 12:27:07 +02:00
|
|
|
}
|
2013-03-03 19:16:32 +01:00
|
|
|
dx += x - ox;
|
|
|
|
dy += y - oy;
|
2011-08-12 12:27:07 +02:00
|
|
|
ox = x;
|
|
|
|
oy = y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (dragging)
|
2011-08-12 17:14:14 +02:00
|
|
|
next = XCheckIfEvent(win.env.dpy, &e, is_motionnotify, None);
|
2011-08-12 12:27:07 +02:00
|
|
|
if ((!dragging || !next) && (dx != 0 || dy != 0)) {
|
2012-03-02 19:19:27 +01:00
|
|
|
if (img_move(&img, dx, dy)) {
|
2011-09-17 17:23:51 +02:00
|
|
|
img_render(&img);
|
2012-03-02 19:19:27 +01:00
|
|
|
win_draw(&win);
|
|
|
|
}
|
2011-08-12 12:27:07 +02:00
|
|
|
dx = dy = 0;
|
|
|
|
}
|
2011-07-26 18:01:29 +02:00
|
|
|
}
|
2011-08-12 12:27:07 +02:00
|
|
|
win_set_cursor(&win, CURSOR_ARROW);
|
2011-09-11 21:01:24 +02:00
|
|
|
set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
|
2011-09-02 04:33:44 +02:00
|
|
|
reset_timeout(redraw);
|
2011-08-12 12:27:07 +02:00
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
return true;
|
2011-07-26 18:01:29 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool ci_set_zoom(arg_t a)
|
2013-02-08 22:05:31 +01:00
|
|
|
{
|
2014-07-23 21:50:31 +02:00
|
|
|
return img_zoom(&img, (prefix ? prefix : (long) a) / 100.0);
|
2011-07-26 18:01:29 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool ci_fit_to_win(arg_t a)
|
2013-02-08 22:05:31 +01:00
|
|
|
{
|
2012-07-19 12:28:44 +02:00
|
|
|
scalemode_t sm = (scalemode_t) a;
|
2011-08-12 17:14:14 +02:00
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
return img_fit_win(&img, sm);
|
2011-07-26 18:01:29 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool ci_rotate(arg_t a)
|
2013-02-08 22:05:31 +01:00
|
|
|
{
|
2013-08-10 15:55:18 +02:00
|
|
|
degree_t degree = (degree_t) a;
|
2011-08-19 13:06:19 +02:00
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
img_rotate(&img, degree);
|
|
|
|
return true;
|
2011-08-19 13:06:19 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool ci_flip(arg_t a)
|
2013-02-08 22:05:31 +01:00
|
|
|
{
|
2012-05-06 13:02:34 +02:00
|
|
|
flipdir_t dir = (flipdir_t) a;
|
2012-05-06 09:39:45 +02:00
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
img_flip(&img, dir);
|
|
|
|
return true;
|
2012-05-06 09:39:45 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool ci_change_gamma(arg_t a)
|
2013-02-08 22:05:31 +01:00
|
|
|
{
|
2014-07-23 21:50:31 +02:00
|
|
|
return img_change_gamma(&img, (long) a);
|
2011-08-19 13:06:19 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool ci_toggle_antialias(arg_t a)
|
2013-11-13 20:54:09 +01:00
|
|
|
{
|
2014-07-23 21:50:31 +02:00
|
|
|
img_toggle_antialias(&img);
|
|
|
|
return true;
|
2013-11-13 20:54:09 +01:00
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool ci_toggle_alpha(arg_t a)
|
2013-02-08 22:05:31 +01:00
|
|
|
{
|
2014-07-23 21:50:31 +02:00
|
|
|
img.alpha = !img.alpha;
|
|
|
|
img.dirty = true;
|
|
|
|
return true;
|
2011-08-19 13:06:19 +02:00
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool ci_slideshow(arg_t a)
|
2014-01-04 18:38:40 +01:00
|
|
|
{
|
2014-07-23 21:50:31 +02:00
|
|
|
if (prefix > 0) {
|
|
|
|
img.ss.on = true;
|
|
|
|
img.ss.delay = prefix;
|
|
|
|
set_timeout(slideshow, img.ss.delay * 1000, true);
|
|
|
|
} else if (img.ss.on) {
|
|
|
|
img.ss.on = false;
|
|
|
|
reset_timeout(slideshow);
|
2014-01-04 18:38:40 +01:00
|
|
|
} else {
|
2014-07-23 21:50:31 +02:00
|
|
|
img.ss.on = true;
|
2014-01-04 18:38:40 +01:00
|
|
|
}
|
2014-07-23 21:50:31 +02:00
|
|
|
return true;
|
2014-01-04 18:38:40 +01:00
|
|
|
}
|
|
|
|
|
2014-07-23 21:50:31 +02:00
|
|
|
bool ct_move_sel(arg_t a)
|
|
|
|
{
|
|
|
|
direction_t dir = (direction_t) a;
|
|
|
|
|
|
|
|
return tns_move_selection(&tns, dir, prefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ct_reload_all(arg_t a)
|
|
|
|
{
|
|
|
|
tns_free(&tns);
|
2014-09-30 21:54:17 +02:00
|
|
|
tns_init(&tns, files, &filecnt, &fileidx, &win);
|
2014-09-25 20:57:24 +02:00
|
|
|
tns.dirty = true;
|
|
|
|
return true;
|
2014-07-23 21:50:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#undef G_CMD
|
|
|
|
#define G_CMD(c) { -1, cg_##c },
|
|
|
|
#undef I_CMD
|
|
|
|
#define I_CMD(c) { MODE_IMAGE, ci_##c },
|
|
|
|
#undef T_CMD
|
|
|
|
#define T_CMD(c) { MODE_THUMB, ct_##c },
|
|
|
|
|
|
|
|
const cmd_t cmds[CMD_COUNT] = {
|
|
|
|
#include "commands.lst"
|
|
|
|
};
|
|
|
|
|