2013-02-08 20:52:41 +00:00
|
|
|
/* Copyright 2011, 2012 Bert Muennich
|
2011-07-26 16:01:29 +00:00
|
|
|
*
|
2013-02-08 20:52:41 +00:00
|
|
|
* This file is part of sxiv.
|
2011-08-17 23:18:26 +00:00
|
|
|
*
|
2013-02-08 20:52:41 +00: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-17 23:18:26 +00:00
|
|
|
*
|
2013-02-08 20:52:41 +00: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 16:01:29 +00:00
|
|
|
*/
|
|
|
|
|
2011-09-08 18:54:24 +00:00
|
|
|
#define _POSIX_C_SOURCE 200112L
|
2011-10-16 16:58:32 +00:00
|
|
|
#define _IMAGE_CONFIG
|
2011-09-03 13:58:58 +00:00
|
|
|
|
2011-09-08 18:54:24 +00:00
|
|
|
#include <stdlib.h>
|
2011-07-26 16:01:29 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
2011-08-19 13:02:10 +00:00
|
|
|
#include "commands.h"
|
2011-07-26 16:01:29 +00:00
|
|
|
#include "image.h"
|
2013-03-19 20:11:29 +00:00
|
|
|
#include "options.h"
|
2011-07-26 16:01:29 +00:00
|
|
|
#include "thumbs.h"
|
|
|
|
#include "util.h"
|
2011-10-16 16:58:32 +00:00
|
|
|
#include "config.h"
|
2011-07-26 16:01:29 +00:00
|
|
|
|
2011-10-12 16:38:29 +00:00
|
|
|
void cleanup(void);
|
2011-09-11 19:01:24 +00:00
|
|
|
void remove_file(int, bool);
|
2011-07-26 16:01:29 +00:00
|
|
|
void load_image(int);
|
2013-02-12 16:55:47 +00:00
|
|
|
void open_info(void);
|
2011-10-12 16:38:29 +00:00
|
|
|
void redraw(void);
|
|
|
|
void reset_cursor(void);
|
|
|
|
void animate(void);
|
2014-01-04 17:38:40 +00:00
|
|
|
void slideshow(void);
|
2011-09-11 19:01:24 +00:00
|
|
|
void set_timeout(timeout_f, int, bool);
|
2011-09-02 02:33:44 +00:00
|
|
|
void reset_timeout(timeout_f);
|
2011-07-26 16:01:29 +00:00
|
|
|
|
|
|
|
extern appmode_t mode;
|
|
|
|
extern img_t img;
|
|
|
|
extern tns_t tns;
|
|
|
|
extern win_t win;
|
|
|
|
|
2011-08-17 22:38:55 +00:00
|
|
|
extern fileinfo_t *files;
|
2011-07-26 16:01:29 +00:00
|
|
|
extern int filecnt, fileidx;
|
2012-08-16 11:40:04 +00:00
|
|
|
extern int alternate;
|
2011-07-26 16:01:29 +00:00
|
|
|
|
2011-10-16 14:08:55 +00:00
|
|
|
extern int prefix;
|
|
|
|
|
2011-10-16 16:58:32 +00:00
|
|
|
const int ss_delays[] = {
|
|
|
|
1, 2, 3, 5, 10, 15, 20, 30, 60, 120, 180, 300, 600
|
|
|
|
};
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool it_quit(arg_t a)
|
|
|
|
{
|
2013-03-19 20:11:29 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
2013-11-14 13:37:08 +00:00
|
|
|
if (options->to_stdout) {
|
2013-08-10 19:18:53 +00:00
|
|
|
for (i = 0; i < filecnt; i++) {
|
2013-08-22 07:44:14 +00:00
|
|
|
if (files[i].marked)
|
2013-08-10 19:18:53 +00:00
|
|
|
printf("%s\n", files[i].name);
|
|
|
|
}
|
2013-03-19 20:11:29 +00:00
|
|
|
}
|
2011-07-26 16:01:29 +00:00
|
|
|
cleanup();
|
2011-09-26 13:40:07 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool it_switch_mode(arg_t a)
|
|
|
|
{
|
2011-08-19 11:09:22 +00:00
|
|
|
if (mode == MODE_IMAGE) {
|
2013-08-22 10:59:05 +00:00
|
|
|
if (tns.thumbs == NULL) {
|
2011-09-17 15:23:51 +00:00
|
|
|
tns_init(&tns, filecnt, &win);
|
2013-08-22 10:59:05 +00:00
|
|
|
tns.alpha = img.alpha;
|
|
|
|
}
|
2011-09-11 19:01:24 +00:00
|
|
|
img_close(&img, false);
|
2011-09-03 15:01:39 +00:00
|
|
|
reset_timeout(reset_cursor);
|
2014-01-04 17:38:40 +00:00
|
|
|
if (img.ss.on) {
|
|
|
|
img.ss.on = false;
|
|
|
|
reset_timeout(slideshow);
|
|
|
|
}
|
2011-11-01 07:36:20 +00:00
|
|
|
tns.sel = fileidx;
|
2011-09-11 19:01:24 +00:00
|
|
|
tns.dirty = true;
|
2011-08-19 11:09:22 +00:00
|
|
|
mode = MODE_THUMB;
|
2011-07-26 16:01:29 +00:00
|
|
|
} else {
|
2011-08-19 11:06:19 +00:00
|
|
|
load_image(tns.sel);
|
2011-08-19 11:09:22 +00:00
|
|
|
mode = MODE_IMAGE;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
2011-09-11 19:01:24 +00:00
|
|
|
return true;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool it_toggle_fullscreen(arg_t a)
|
|
|
|
{
|
2011-07-26 16:01:29 +00:00
|
|
|
win_toggle_fullscreen(&win);
|
2012-02-15 21:33:39 +00:00
|
|
|
/* redraw after next ConfigureNotify event */
|
2011-09-11 19:01:24 +00:00
|
|
|
set_timeout(redraw, TO_REDRAW_RESIZE, false);
|
2011-08-19 11:09:22 +00:00
|
|
|
if (mode == MODE_IMAGE)
|
2012-05-14 19:45:24 +00:00
|
|
|
img.checkpan = img.dirty = true;
|
2011-07-26 16:01:29 +00:00
|
|
|
else
|
2011-09-11 19:01:24 +00:00
|
|
|
tns.dirty = true;
|
|
|
|
return false;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool it_toggle_bar(arg_t a)
|
|
|
|
{
|
2012-02-15 21:33:39 +00:00
|
|
|
win_toggle_bar(&win);
|
2013-02-12 16:55:47 +00:00
|
|
|
if (mode == MODE_IMAGE) {
|
2012-02-15 21:33:39 +00:00
|
|
|
img.checkpan = img.dirty = true;
|
2013-02-12 16:55:47 +00:00
|
|
|
if (win.bar.h > 0)
|
|
|
|
open_info();
|
|
|
|
} else {
|
2012-02-15 21:33:39 +00:00
|
|
|
tns.dirty = true;
|
2013-02-12 16:55:47 +00:00
|
|
|
}
|
2012-02-15 21:33:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool t_reload_all(arg_t a)
|
|
|
|
{
|
2012-05-13 19:52:53 +00:00
|
|
|
if (mode == MODE_THUMB) {
|
|
|
|
tns_free(&tns);
|
|
|
|
tns_init(&tns, filecnt, &win);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-08 14:30:56 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool it_reload_image(arg_t a)
|
|
|
|
{
|
2011-08-19 11:09:22 +00:00
|
|
|
if (mode == MODE_IMAGE) {
|
2011-08-19 11:06:19 +00:00
|
|
|
load_image(fileidx);
|
2011-09-03 15:01:39 +00:00
|
|
|
} else {
|
|
|
|
win_set_cursor(&win, CURSOR_WATCH);
|
2011-09-11 19:01:24 +00:00
|
|
|
if (!tns_load(&tns, tns.sel, &files[tns.sel], true, false)) {
|
|
|
|
remove_file(tns.sel, false);
|
|
|
|
tns.dirty = true;
|
2011-09-03 15:01:39 +00:00
|
|
|
if (tns.sel >= tns.cnt)
|
|
|
|
tns.sel = tns.cnt - 1;
|
|
|
|
}
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
2011-09-11 19:01:24 +00:00
|
|
|
return true;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool it_remove_image(arg_t a)
|
|
|
|
{
|
2011-08-19 11:09:22 +00:00
|
|
|
if (mode == MODE_IMAGE) {
|
2011-09-11 19:01:24 +00:00
|
|
|
remove_file(fileidx, true);
|
2011-08-19 11:06:19 +00:00
|
|
|
load_image(fileidx >= filecnt ? filecnt - 1 : fileidx);
|
2011-09-11 19:01:24 +00:00
|
|
|
return true;
|
2011-08-19 11:06:19 +00:00
|
|
|
} else if (tns.sel < tns.cnt) {
|
2011-09-11 19:01:24 +00:00
|
|
|
remove_file(tns.sel, true);
|
|
|
|
tns.dirty = true;
|
2011-08-19 11:06:19 +00:00
|
|
|
if (tns.sel >= tns.cnt)
|
|
|
|
tns.sel = tns.cnt - 1;
|
2011-09-11 19:01:24 +00:00
|
|
|
return true;
|
2011-07-26 16:01:29 +00:00
|
|
|
} else {
|
2011-09-11 19:01:24 +00:00
|
|
|
return false;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool i_navigate(arg_t a)
|
|
|
|
{
|
2011-09-03 21:07:14 +00:00
|
|
|
long n = (long) a;
|
2011-08-12 15:14:14 +00:00
|
|
|
|
2011-08-19 11:09:22 +00:00
|
|
|
if (mode == MODE_IMAGE) {
|
2011-10-16 16:58:32 +00:00
|
|
|
if (prefix > 0)
|
2011-10-16 16:36:25 +00:00
|
|
|
n *= prefix;
|
2011-07-26 16:01:29 +00:00
|
|
|
n += fileidx;
|
|
|
|
if (n < 0)
|
|
|
|
n = 0;
|
|
|
|
if (n >= filecnt)
|
|
|
|
n = filecnt - 1;
|
|
|
|
|
|
|
|
if (n != fileidx) {
|
|
|
|
load_image(n);
|
2011-09-11 19:01:24 +00:00
|
|
|
return true;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-11 19:01:24 +00:00
|
|
|
return false;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool i_alternate(arg_t a)
|
|
|
|
{
|
2012-08-16 11:40:04 +00:00
|
|
|
if (mode == MODE_IMAGE) {
|
|
|
|
load_image(alternate);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool it_first(arg_t a)
|
|
|
|
{
|
2011-08-19 11:09:22 +00:00
|
|
|
if (mode == MODE_IMAGE && fileidx != 0) {
|
2011-07-26 16:01:29 +00:00
|
|
|
load_image(0);
|
2011-09-11 19:01:24 +00:00
|
|
|
return true;
|
2011-08-19 11:09:22 +00:00
|
|
|
} else if (mode == MODE_THUMB && tns.sel != 0) {
|
2011-07-26 16:01:29 +00:00
|
|
|
tns.sel = 0;
|
2011-09-11 19:01:24 +00:00
|
|
|
tns.dirty = true;
|
|
|
|
return true;
|
2011-07-26 16:01:29 +00:00
|
|
|
} else {
|
2011-09-11 19:01:24 +00:00
|
|
|
return false;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool it_n_or_last(arg_t a)
|
|
|
|
{
|
2011-10-16 14:08:55 +00:00
|
|
|
int n = prefix != 0 && prefix - 1 < filecnt ? prefix - 1 : filecnt - 1;
|
|
|
|
|
|
|
|
if (mode == MODE_IMAGE && fileidx != n) {
|
|
|
|
load_image(n);
|
2011-09-11 19:01:24 +00:00
|
|
|
return true;
|
2011-10-16 14:08:55 +00:00
|
|
|
} else if (mode == MODE_THUMB && tns.sel != n) {
|
|
|
|
tns.sel = n;
|
2011-09-11 19:01:24 +00:00
|
|
|
tns.dirty = true;
|
|
|
|
return true;
|
2011-07-26 16:01:29 +00:00
|
|
|
} else {
|
2011-09-11 19:01:24 +00:00
|
|
|
return false;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool i_navigate_frame(arg_t a)
|
|
|
|
{
|
2011-08-19 16:46:17 +00:00
|
|
|
if (mode == MODE_IMAGE && !img.multi.animate)
|
2011-09-03 21:07:14 +00:00
|
|
|
return img_frame_navigate(&img, (long) a);
|
2011-08-19 16:46:17 +00:00
|
|
|
else
|
2011-09-11 19:01:24 +00:00
|
|
|
return false;
|
2011-08-19 16:46:17 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool i_toggle_animation(arg_t a)
|
|
|
|
{
|
2011-08-19 16:46:17 +00:00
|
|
|
if (mode != MODE_IMAGE)
|
2011-09-11 19:01:24 +00:00
|
|
|
return false;
|
2011-08-19 16:46:17 +00:00
|
|
|
|
|
|
|
if (img.multi.animate) {
|
2011-09-02 02:33:44 +00:00
|
|
|
reset_timeout(animate);
|
2011-09-11 19:01:24 +00: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 16:46:17 +00:00
|
|
|
}
|
2011-09-11 19:01:24 +00:00
|
|
|
return true;
|
2011-08-16 22:56:18 +00:00
|
|
|
}
|
|
|
|
|
2013-08-10 19:18:53 +00:00
|
|
|
bool it_toggle_image_mark(arg_t a)
|
|
|
|
{
|
|
|
|
int sel = mode == MODE_IMAGE ? fileidx : tns.sel;
|
|
|
|
|
|
|
|
files[sel].marked = !files[sel].marked;
|
2013-11-14 13:37:08 +00:00
|
|
|
if (mode == MODE_THUMB)
|
|
|
|
tns_mark(&tns, sel, files[sel].marked);
|
2013-08-10 19:18:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-14 13:45:27 +00:00
|
|
|
bool it_reverse_marks(arg_t a)
|
|
|
|
{
|
|
|
|
int i, cnt = mode == MODE_IMAGE ? filecnt : tns.cnt;
|
|
|
|
|
2013-11-14 16:16:09 +00:00
|
|
|
for (i = 0; i < cnt; i++)
|
2013-11-14 13:45:27 +00:00
|
|
|
files[i].marked = !files[i].marked;
|
2013-11-14 16:16:09 +00:00
|
|
|
if (mode == MODE_THUMB)
|
|
|
|
tns.dirty = true;
|
2013-11-14 13:45:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-10 19:18:53 +00:00
|
|
|
bool it_navigate_marked(arg_t a)
|
|
|
|
{
|
|
|
|
long n = (long) a;
|
|
|
|
int d, i, cnt, sel, new;
|
|
|
|
|
|
|
|
if (mode == MODE_IMAGE)
|
|
|
|
cnt = filecnt, sel = new = fileidx;
|
|
|
|
else
|
|
|
|
cnt = tns.cnt, sel = new = tns.sel;
|
|
|
|
if (prefix > 0)
|
|
|
|
n *= prefix;
|
|
|
|
d = n > 0 ? 1 : -1;
|
|
|
|
for (i = sel + d; n != 0 && i >= 0 && i < cnt; i += d) {
|
|
|
|
if (files[i].marked) {
|
|
|
|
n -= d;
|
|
|
|
new = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (new != sel) {
|
|
|
|
if (mode == MODE_IMAGE) {
|
|
|
|
load_image(new);
|
|
|
|
} else {
|
|
|
|
tns.sel = new;
|
|
|
|
tns.dirty = true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool it_scroll_move(arg_t a)
|
|
|
|
{
|
2011-08-12 15:14:14 +00:00
|
|
|
direction_t dir = (direction_t) a;
|
|
|
|
|
2011-08-19 11:09:22 +00:00
|
|
|
if (mode == MODE_IMAGE)
|
2011-10-16 15:39:22 +00:00
|
|
|
return img_pan(&img, dir, prefix);
|
2011-07-26 16:01:29 +00:00
|
|
|
else
|
2012-07-15 08:30:58 +00:00
|
|
|
return tns_move_selection(&tns, dir, prefix);
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool it_scroll_screen(arg_t a)
|
|
|
|
{
|
2011-08-12 15:14:14 +00:00
|
|
|
direction_t dir = (direction_t) a;
|
|
|
|
|
2011-08-19 11:09:22 +00:00
|
|
|
if (mode == MODE_IMAGE)
|
2011-10-16 15:39:22 +00:00
|
|
|
return img_pan(&img, dir, -1);
|
2011-07-26 16:01:29 +00:00
|
|
|
else
|
2011-10-27 14:21:01 +00:00
|
|
|
return tns_scroll(&tns, dir, true);
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool i_scroll_to_edge(arg_t a)
|
|
|
|
{
|
2011-08-12 15:14:14 +00:00
|
|
|
direction_t dir = (direction_t) a;
|
|
|
|
|
2011-08-19 11:09:22 +00:00
|
|
|
if (mode == MODE_IMAGE)
|
2011-09-17 15:23:51 +00:00
|
|
|
return img_pan_edge(&img, dir);
|
2011-07-26 16:01:29 +00:00
|
|
|
else
|
2011-09-11 19:01:24 +00:00
|
|
|
return false;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2011-08-19 11:06:19 +00:00
|
|
|
/* Xlib helper function for i_drag() */
|
2013-02-08 21:05:31 +00:00
|
|
|
Bool is_motionnotify(Display *d, XEvent *e, XPointer a)
|
|
|
|
{
|
2011-08-12 10:27:07 +00:00
|
|
|
return e != NULL && e->type == MotionNotify;
|
|
|
|
}
|
|
|
|
|
2013-03-04 18:23:07 +00:00
|
|
|
#define WARP(x,y) \
|
|
|
|
XWarpPointer(win.env.dpy, None, win.xwin, 0, 0, 0, 0, x, y); \
|
|
|
|
ox = x, oy = y; \
|
|
|
|
break
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool i_drag(arg_t a)
|
|
|
|
{
|
2011-08-12 10:27:07 +00:00
|
|
|
int dx = 0, dy = 0, i, ox, oy, x, y;
|
|
|
|
unsigned int ui;
|
2011-09-11 19:01:24 +00:00
|
|
|
bool dragging = true, next = false;
|
2011-08-12 10:27:07 +00:00
|
|
|
XEvent e;
|
|
|
|
Window w;
|
|
|
|
|
2011-08-19 11:09:22 +00:00
|
|
|
if (mode != MODE_IMAGE)
|
2011-09-11 19:01:24 +00:00
|
|
|
return false;
|
2011-08-12 10:27:07 +00:00
|
|
|
if (!XQueryPointer(win.env.dpy, win.xwin, &w, &w, &i, &i, &ox, &oy, &ui))
|
2011-09-11 19:01:24 +00:00
|
|
|
return false;
|
2011-08-12 10:27:07 +00: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 19:01:24 +00:00
|
|
|
dragging = false;
|
2011-08-12 10:27:07 +00:00
|
|
|
break;
|
|
|
|
case MotionNotify:
|
|
|
|
x = e.xmotion.x;
|
|
|
|
y = e.xmotion.y;
|
2013-03-03 18:16:32 +00:00
|
|
|
|
|
|
|
/* wrap the mouse around */
|
2013-09-07 15:06:47 +00: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 10:27:07 +00:00
|
|
|
}
|
2013-03-03 18:16:32 +00:00
|
|
|
dx += x - ox;
|
|
|
|
dy += y - oy;
|
2011-08-12 10:27:07 +00:00
|
|
|
ox = x;
|
|
|
|
oy = y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (dragging)
|
2011-08-12 15:14:14 +00:00
|
|
|
next = XCheckIfEvent(win.env.dpy, &e, is_motionnotify, None);
|
2011-08-12 10:27:07 +00:00
|
|
|
if ((!dragging || !next) && (dx != 0 || dy != 0)) {
|
2012-03-02 18:19:27 +00:00
|
|
|
if (img_move(&img, dx, dy)) {
|
2011-09-17 15:23:51 +00:00
|
|
|
img_render(&img);
|
2012-03-02 18:19:27 +00:00
|
|
|
win_draw(&win);
|
|
|
|
}
|
2011-08-12 10:27:07 +00:00
|
|
|
dx = dy = 0;
|
|
|
|
}
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
2011-08-12 10:27:07 +00:00
|
|
|
|
|
|
|
win_set_cursor(&win, CURSOR_ARROW);
|
2011-09-11 19:01:24 +00:00
|
|
|
set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
|
2011-09-02 02:33:44 +00:00
|
|
|
reset_timeout(redraw);
|
2011-08-12 10:27:07 +00:00
|
|
|
|
2011-09-11 19:01:24 +00:00
|
|
|
return false;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool i_zoom(arg_t a)
|
|
|
|
{
|
2011-09-03 21:07:14 +00:00
|
|
|
long scale = (long) a;
|
2011-08-12 15:14:14 +00:00
|
|
|
|
2011-08-19 11:09:22 +00:00
|
|
|
if (mode != MODE_IMAGE)
|
2011-09-11 19:01:24 +00:00
|
|
|
return false;
|
2011-08-19 16:46:17 +00:00
|
|
|
|
2011-07-26 16:01:29 +00:00
|
|
|
if (scale > 0)
|
2011-09-17 15:23:51 +00:00
|
|
|
return img_zoom_in(&img);
|
2011-07-26 16:01:29 +00:00
|
|
|
else if (scale < 0)
|
2011-09-17 15:23:51 +00:00
|
|
|
return img_zoom_out(&img);
|
2011-07-26 16:01:29 +00:00
|
|
|
else
|
2011-10-16 15:58:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool i_set_zoom(arg_t a)
|
|
|
|
{
|
2011-10-16 15:58:53 +00:00
|
|
|
if (mode == MODE_IMAGE)
|
|
|
|
return img_zoom(&img, (prefix ? prefix : (long) a) / 100.0);
|
|
|
|
else
|
|
|
|
return false;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool i_fit_to_win(arg_t a)
|
|
|
|
{
|
2011-09-29 10:43:36 +00:00
|
|
|
bool ret = false;
|
2012-07-19 10:28:44 +00:00
|
|
|
scalemode_t sm = (scalemode_t) a;
|
2011-08-12 15:14:14 +00:00
|
|
|
|
2011-08-19 11:09:22 +00:00
|
|
|
if (mode == MODE_IMAGE) {
|
2012-07-19 10:28:44 +00:00
|
|
|
if ((ret = img_fit_win(&img, sm)))
|
2011-09-17 15:23:51 +00:00
|
|
|
img_center(&img);
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
2011-09-29 10:43:36 +00:00
|
|
|
return ret;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool i_fit_to_img(arg_t a)
|
|
|
|
{
|
2011-09-11 19:01:24 +00:00
|
|
|
int x, y;
|
2011-07-26 16:01:29 +00:00
|
|
|
unsigned int w, h;
|
2011-09-29 10:43:36 +00:00
|
|
|
bool ret = false;
|
2011-07-26 16:01:29 +00:00
|
|
|
|
2011-08-19 11:09:22 +00:00
|
|
|
if (mode == MODE_IMAGE) {
|
2011-07-26 16:01:29 +00: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-11-11 22:57:36 +00:00
|
|
|
img.dirty = true;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-29 10:43:36 +00:00
|
|
|
return ret;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
2011-08-12 15:14:14 +00:00
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool i_rotate(arg_t a)
|
|
|
|
{
|
2013-08-10 13:55:18 +00:00
|
|
|
degree_t degree = (degree_t) a;
|
2011-08-19 11:06:19 +00:00
|
|
|
|
2011-08-19 11:09:22 +00:00
|
|
|
if (mode == MODE_IMAGE) {
|
2013-08-10 13:55:18 +00:00
|
|
|
img_rotate(&img, degree);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
2011-08-19 11:06:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool i_flip(arg_t a)
|
|
|
|
{
|
2012-05-06 11:02:34 +00:00
|
|
|
flipdir_t dir = (flipdir_t) a;
|
2012-05-06 07:39:45 +00:00
|
|
|
|
|
|
|
if (mode == MODE_IMAGE) {
|
2012-05-06 11:02:34 +00:00
|
|
|
img_flip(&img, dir);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
2012-05-06 07:39:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-04 17:38:40 +00:00
|
|
|
bool i_slideshow(arg_t a)
|
2013-02-08 21:05:31 +00:00
|
|
|
{
|
2011-08-19 11:09:22 +00:00
|
|
|
if (mode == MODE_IMAGE) {
|
2014-01-04 17:38:40 +00: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);
|
|
|
|
} else {
|
|
|
|
img.ss.on = true;
|
|
|
|
}
|
2011-09-11 19:01:24 +00:00
|
|
|
return true;
|
2011-08-19 11:06:19 +00:00
|
|
|
} else {
|
2011-09-11 19:01:24 +00:00
|
|
|
return false;
|
2011-08-19 11:06:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-04 17:38:40 +00:00
|
|
|
bool i_toggle_antialias(arg_t a)
|
2013-11-13 19:54:09 +00:00
|
|
|
{
|
|
|
|
if (mode == MODE_IMAGE) {
|
2014-01-04 17:38:40 +00:00
|
|
|
img_toggle_antialias(&img);
|
|
|
|
return true;
|
2013-11-13 19:54:09 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 21:05:31 +00:00
|
|
|
bool it_toggle_alpha(arg_t a)
|
|
|
|
{
|
2011-09-11 19:01:24 +00:00
|
|
|
img.alpha = tns.alpha = !img.alpha;
|
|
|
|
if (mode == MODE_IMAGE)
|
|
|
|
img.dirty = true;
|
|
|
|
else
|
|
|
|
tns.dirty = true;
|
|
|
|
return true;
|
2011-08-19 11:06:19 +00:00
|
|
|
}
|
|
|
|
|
2014-01-04 17:38:40 +00:00
|
|
|
bool i_change_gamma(arg_t a)
|
|
|
|
{
|
|
|
|
if (mode == MODE_IMAGE) {
|
|
|
|
return img_change_gamma(&img, (long) a);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|