2021-10-28 10:41:16 +00:00
|
|
|
/* Copyright 2011-2020 Bert Muennich
|
2022-02-09 07:09:42 +00:00
|
|
|
* Copyright 2021-2022 nsxiv contributors
|
2011-07-26 16:01:29 +00:00
|
|
|
*
|
2021-09-16 09:32:59 +00:00
|
|
|
* This file is a part of nsxiv.
|
2011-08-17 23:18:26 +00:00
|
|
|
*
|
2021-09-16 09:32:59 +00:00
|
|
|
* nsxiv is free software; you can redistribute it and/or modify
|
2013-02-08 20:52:41 +00:00
|
|
|
* 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
|
|
|
*
|
2021-09-16 09:32:59 +00:00
|
|
|
* nsxiv is distributed in the hope that it will be useful,
|
2013-02-08 20:52:41 +00:00
|
|
|
* 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
|
2021-09-16 09:32:59 +00:00
|
|
|
* along with nsxiv. If not, see <http://www.gnu.org/licenses/>.
|
2011-07-26 16:01:29 +00:00
|
|
|
*/
|
|
|
|
|
2021-09-16 09:32:59 +00:00
|
|
|
#include "nsxiv.h"
|
2017-10-16 19:10:35 +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-09-11 19:01:24 +00:00
|
|
|
void remove_file(int, bool);
|
2011-07-26 16:01:29 +00:00
|
|
|
void load_image(int);
|
2018-06-09 11:12:46 +00:00
|
|
|
bool mark_image(int, bool);
|
2018-02-18 12:16:00 +00:00
|
|
|
void close_info(void);
|
2013-02-12 16:55:47 +00:00
|
|
|
void open_info(void);
|
2021-11-04 04:20:28 +00:00
|
|
|
int nav_button(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);
|
2021-10-07 00:37:34 +00:00
|
|
|
void handle_key_handler(bool);
|
2011-07-26 16:01:29 +00:00
|
|
|
|
|
|
|
extern appmode_t mode;
|
|
|
|
extern img_t img;
|
|
|
|
extern tns_t tns;
|
|
|
|
extern win_t win;
|
2022-01-10 16:52:06 +00:00
|
|
|
extern const XButtonEvent *xbutton_ev;
|
2011-07-26 16:01:29 +00:00
|
|
|
|
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;
|
2014-08-16 17:24:34 +00:00
|
|
|
extern int markcnt;
|
2018-06-09 09:57:42 +00:00
|
|
|
extern int markidx;
|
2011-07-26 16:01:29 +00:00
|
|
|
|
2011-10-16 14:08:55 +00:00
|
|
|
extern int prefix;
|
2014-01-31 12:21:23 +00:00
|
|
|
extern bool extprefix;
|
2011-10-16 14:08:55 +00:00
|
|
|
|
2021-12-19 17:05:35 +00:00
|
|
|
bool cg_quit(arg_t status)
|
2013-02-08 21:05:31 +00:00
|
|
|
{
|
2013-03-19 20:11:29 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
2014-08-16 17:24:34 +00:00
|
|
|
if (options->to_stdout && markcnt > 0) {
|
2013-08-10 19:18:53 +00:00
|
|
|
for (i = 0; i < filecnt; i++) {
|
2015-01-04 14:38:49 +00:00
|
|
|
if (files[i].flags & FF_MARK)
|
2021-10-28 05:43:36 +00:00
|
|
|
printf("%s%c", files[i].name, options->using_null ? '\0' : '\n');
|
2013-08-10 19:18:53 +00:00
|
|
|
}
|
2013-03-19 20:11:29 +00:00
|
|
|
}
|
2021-12-19 17:05:35 +00:00
|
|
|
exit(status);
|
2021-12-25 02:09:54 +00:00
|
|
|
return None; /* silence tcc warning */
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool cg_switch_mode(arg_t _)
|
2013-02-08 21:05:31 +00:00
|
|
|
{
|
2011-08-19 11:09:22 +00:00
|
|
|
if (mode == MODE_IMAGE) {
|
2014-04-06 20:47:42 +00:00
|
|
|
if (tns.thumbs == NULL)
|
2014-09-30 19:54:17 +00:00
|
|
|
tns_init(&tns, files, &filecnt, &fileidx, &win);
|
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-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 {
|
2014-08-16 16:36:17 +00:00
|
|
|
load_image(fileidx);
|
2011-08-19 11:09:22 +00:00
|
|
|
mode = MODE_IMAGE;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
2014-07-23 19:50:31 +00:00
|
|
|
return true;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool cg_toggle_fullscreen(arg_t _)
|
2013-02-08 21:05:31 +00:00
|
|
|
{
|
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;
|
2014-07-23 19:50:31 +00:00
|
|
|
return false;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool cg_toggle_bar(arg_t _)
|
2013-02-08 21:05:31 +00:00
|
|
|
{
|
2012-02-15 21:33:39 +00:00
|
|
|
win_toggle_bar(&win);
|
2013-02-12 16:55:47 +00:00
|
|
|
if (mode == MODE_IMAGE) {
|
|
|
|
if (win.bar.h > 0)
|
|
|
|
open_info();
|
2018-02-18 12:16:00 +00:00
|
|
|
else
|
|
|
|
close_info();
|
|
|
|
img.checkpan = img.dirty = true;
|
2013-02-12 16:55:47 +00:00
|
|
|
} else {
|
2012-02-15 21:33:39 +00:00
|
|
|
tns.dirty = true;
|
2013-02-12 16:55:47 +00:00
|
|
|
}
|
2014-07-23 19:50:31 +00:00
|
|
|
return true;
|
2012-02-15 21:33:39 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool cg_prefix_external(arg_t _)
|
2014-01-31 12:21:23 +00:00
|
|
|
{
|
2021-10-07 00:37:34 +00:00
|
|
|
handle_key_handler(true);
|
2014-07-23 19:50:31 +00:00
|
|
|
return false;
|
2014-01-31 12:21:23 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool cg_reload_image(arg_t _)
|
2013-02-08 21:05:31 +00:00
|
|
|
{
|
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);
|
2015-01-04 20:19:26 +00:00
|
|
|
if (!tns_load(&tns, fileidx, true, false)) {
|
2014-08-16 16:36:17 +00:00
|
|
|
remove_file(fileidx, false);
|
2011-09-11 19:01:24 +00:00
|
|
|
tns.dirty = true;
|
2011-09-03 15:01:39 +00:00
|
|
|
}
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
2014-07-23 19:50:31 +00:00
|
|
|
return true;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool cg_remove_image(arg_t _)
|
2013-02-08 21:05:31 +00:00
|
|
|
{
|
2014-09-30 19:54:17 +00:00
|
|
|
remove_file(fileidx, true);
|
|
|
|
if (mode == MODE_IMAGE)
|
|
|
|
load_image(fileidx);
|
|
|
|
else
|
2011-09-11 19:01:24 +00:00
|
|
|
tns.dirty = true;
|
2014-09-30 19:54:17 +00:00
|
|
|
return true;
|
2012-08-16 11:40:04 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool cg_first(arg_t _)
|
2013-02-08 21:05:31 +00:00
|
|
|
{
|
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);
|
2014-07-23 19:50:31 +00:00
|
|
|
return true;
|
2014-08-16 16:36:17 +00:00
|
|
|
} else if (mode == MODE_THUMB && fileidx != 0) {
|
|
|
|
fileidx = 0;
|
2011-09-11 19:01:24 +00:00
|
|
|
tns.dirty = true;
|
2014-07-23 19:50:31 +00:00
|
|
|
return true;
|
2011-07-26 16:01:29 +00:00
|
|
|
} else {
|
2014-07-23 19:50:31 +00:00
|
|
|
return false;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool cg_n_or_last(arg_t _)
|
2013-02-08 21:05:31 +00:00
|
|
|
{
|
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);
|
2014-07-23 19:50:31 +00:00
|
|
|
return true;
|
2014-08-16 16:36:17 +00:00
|
|
|
} else if (mode == MODE_THUMB && fileidx != n) {
|
|
|
|
fileidx = n;
|
2011-09-11 19:01:24 +00:00
|
|
|
tns.dirty = true;
|
2014-07-23 19:50:31 +00:00
|
|
|
return true;
|
2011-07-26 16:01:29 +00:00
|
|
|
} else {
|
2014-07-23 19:50:31 +00:00
|
|
|
return false;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool cg_scroll_screen(arg_t dir)
|
2013-02-08 21:05:31 +00:00
|
|
|
{
|
2014-07-23 19:50:31 +00:00
|
|
|
if (mode == MODE_IMAGE)
|
|
|
|
return img_pan(&img, dir, -1);
|
|
|
|
else
|
|
|
|
return tns_scroll(&tns, dir, true);
|
2011-08-16 22:56:18 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool cg_zoom(arg_t d)
|
2014-09-27 22:26:02 +00:00
|
|
|
{
|
|
|
|
if (mode == MODE_THUMB)
|
|
|
|
return tns_zoom(&tns, d);
|
|
|
|
else
|
2021-09-25 05:10:29 +00:00
|
|
|
return img_zoom(&img, d);
|
2014-09-27 22:26:02 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool cg_toggle_image_mark(arg_t _)
|
2013-08-10 19:18:53 +00:00
|
|
|
{
|
2018-06-09 11:12:46 +00:00
|
|
|
return mark_image(fileidx, !(files[fileidx].flags & FF_MARK));
|
2013-08-10 19:18:53 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool cg_reverse_marks(arg_t _)
|
2013-11-14 13:45:27 +00:00
|
|
|
{
|
2014-08-16 17:24:34 +00:00
|
|
|
int i;
|
2013-11-14 13:45:27 +00:00
|
|
|
|
2014-08-16 17:24:34 +00:00
|
|
|
for (i = 0; i < filecnt; i++) {
|
2015-01-04 14:38:49 +00:00
|
|
|
files[i].flags ^= FF_MARK;
|
|
|
|
markcnt += files[i].flags & FF_MARK ? 1 : -1;
|
2014-08-16 17:24:34 +00:00
|
|
|
}
|
2013-11-14 16:16:09 +00:00
|
|
|
if (mode == MODE_THUMB)
|
|
|
|
tns.dirty = true;
|
2014-07-23 19:50:31 +00:00
|
|
|
return true;
|
2013-11-14 13:45:27 +00:00
|
|
|
}
|
|
|
|
|
2018-06-04 20:18:57 +00:00
|
|
|
bool cg_mark_range(arg_t _)
|
|
|
|
{
|
2018-06-10 10:39:23 +00:00
|
|
|
int d = markidx < fileidx ? 1 : -1, end, i;
|
2018-06-09 11:12:46 +00:00
|
|
|
bool dirty = false, on = !!(files[markidx].flags & FF_MARK);
|
2018-06-04 20:18:57 +00:00
|
|
|
|
2018-06-10 10:39:23 +00:00
|
|
|
for (i = markidx + d, end = fileidx + d; i != end; i += d)
|
|
|
|
dirty |= mark_image(i, on);
|
2018-06-09 11:12:46 +00:00
|
|
|
return dirty;
|
2018-06-04 20:18:57 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool cg_unmark_all(arg_t _)
|
2014-08-17 18:27:01 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < filecnt; i++)
|
2015-01-04 14:38:49 +00:00
|
|
|
files[i].flags &= ~FF_MARK;
|
2014-08-17 18:27:01 +00:00
|
|
|
markcnt = 0;
|
|
|
|
if (mode == MODE_THUMB)
|
|
|
|
tns.dirty = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool cg_navigate_marked(arg_t n)
|
2013-08-10 19:18:53 +00:00
|
|
|
{
|
2014-08-16 16:36:17 +00:00
|
|
|
int d, i;
|
2014-09-30 19:54:17 +00:00
|
|
|
int new = fileidx;
|
2021-10-11 03:07:18 +00:00
|
|
|
|
2013-08-10 19:18:53 +00:00
|
|
|
if (prefix > 0)
|
|
|
|
n *= prefix;
|
|
|
|
d = n > 0 ? 1 : -1;
|
2014-09-30 19:54:17 +00:00
|
|
|
for (i = fileidx + d; n != 0 && i >= 0 && i < filecnt; i += d) {
|
2015-01-04 14:38:49 +00:00
|
|
|
if (files[i].flags & FF_MARK) {
|
2013-08-10 19:18:53 +00:00
|
|
|
n -= d;
|
|
|
|
new = i;
|
|
|
|
}
|
|
|
|
}
|
2014-08-16 16:36:17 +00:00
|
|
|
if (new != fileidx) {
|
2013-08-10 19:18:53 +00:00
|
|
|
if (mode == MODE_IMAGE) {
|
|
|
|
load_image(new);
|
|
|
|
} else {
|
2014-08-16 16:36:17 +00:00
|
|
|
fileidx = new;
|
2013-08-10 19:18:53 +00:00
|
|
|
tns.dirty = true;
|
|
|
|
}
|
2014-07-23 19:50:31 +00:00
|
|
|
return true;
|
2013-08-10 19:18:53 +00:00
|
|
|
} else {
|
2014-07-23 19:50:31 +00:00
|
|
|
return false;
|
2013-08-10 19:18:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool cg_change_gamma(arg_t d)
|
2015-01-05 19:53:04 +00:00
|
|
|
{
|
2015-01-11 10:38:28 +00:00
|
|
|
if (img_change_gamma(&img, d * (prefix > 0 ? prefix : 1))) {
|
2015-01-05 19:53:04 +00:00
|
|
|
if (mode == MODE_THUMB)
|
|
|
|
tns.dirty = true;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool ci_navigate(arg_t n)
|
2013-02-08 21:05:31 +00:00
|
|
|
{
|
2014-07-23 19:50:31 +00: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-05 11:53:29 +00:00
|
|
|
bool ci_cursor_navigate(arg_t _)
|
|
|
|
{
|
2021-11-04 04:20:28 +00:00
|
|
|
return ci_navigate(nav_button() - 1);
|
2017-10-05 11:53:29 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool ci_alternate(arg_t _)
|
2014-07-23 19:50:31 +00:00
|
|
|
{
|
|
|
|
load_image(alternate);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool ci_navigate_frame(arg_t d)
|
2014-07-23 19:50:31 +00:00
|
|
|
{
|
2015-12-26 14:24:08 +00:00
|
|
|
if (prefix > 0)
|
|
|
|
d *= prefix;
|
2015-01-11 10:38:28 +00:00
|
|
|
return !img.multi.animate && img_frame_navigate(&img, d);
|
2014-07-23 19:50:31 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool ci_toggle_animation(arg_t _)
|
2014-07-23 19:50:31 +00:00
|
|
|
{
|
2014-07-25 20:52:31 +00:00
|
|
|
bool dirty = false;
|
|
|
|
|
2014-09-01 18:40:17 +00:00
|
|
|
if (img.multi.cnt > 0) {
|
|
|
|
img.multi.animate = !img.multi.animate;
|
|
|
|
if (img.multi.animate) {
|
2014-09-01 18:41:27 +00:00
|
|
|
dirty = img_frame_animate(&img);
|
2014-09-01 18:40:17 +00:00
|
|
|
set_timeout(animate, img.multi.frames[img.multi.sel].delay, true);
|
|
|
|
} else {
|
|
|
|
reset_timeout(animate);
|
|
|
|
}
|
2014-07-23 19:50:31 +00:00
|
|
|
}
|
2014-07-25 20:52:31 +00:00
|
|
|
return dirty;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool ci_scroll(arg_t dir)
|
2013-02-08 21:05:31 +00:00
|
|
|
{
|
2014-07-23 19:50:31 +00:00
|
|
|
return img_pan(&img, dir, prefix);
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2022-01-15 22:51:31 +00:00
|
|
|
bool ci_scroll_to_center(arg_t _)
|
|
|
|
{
|
|
|
|
return img_pan_center(&img);
|
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool ci_scroll_to_edge(arg_t dir)
|
2013-02-08 21:05:31 +00:00
|
|
|
{
|
2014-07-23 19:50:31 +00:00
|
|
|
return img_pan_edge(&img, dir);
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2021-12-24 00:14:12 +00:00
|
|
|
bool ci_drag(arg_t drag_mode)
|
2013-02-08 21:05:31 +00:00
|
|
|
{
|
2018-01-12 12:39:46 +00:00
|
|
|
int x, y, ox, oy;
|
2017-10-04 16:12:27 +00:00
|
|
|
float px, py;
|
2011-08-12 10:27:07 +00:00
|
|
|
XEvent e;
|
|
|
|
|
2017-10-05 11:47:02 +00:00
|
|
|
if ((int)(img.w * img.zoom) <= win.w && (int)(img.h * img.zoom) <= win.h)
|
2014-07-23 19:50:31 +00:00
|
|
|
return false;
|
2017-10-04 16:12:27 +00:00
|
|
|
|
2021-12-24 00:14:12 +00:00
|
|
|
win_set_cursor(&win, drag_mode == DRAG_ABSOLUTE ? CURSOR_DRAG_ABSOLUTE : CURSOR_DRAG_RELATIVE);
|
2017-10-05 11:47:02 +00:00
|
|
|
win_cursor_pos(&win, &x, &y);
|
2018-01-12 12:39:46 +00:00
|
|
|
ox = x;
|
|
|
|
oy = y;
|
2017-10-05 11:47:02 +00:00
|
|
|
|
2021-10-11 03:07:18 +00:00
|
|
|
while (true) {
|
2021-12-24 00:14:12 +00:00
|
|
|
if (drag_mode == DRAG_ABSOLUTE) {
|
2018-01-12 12:39:46 +00:00
|
|
|
px = MIN(MAX(0.0, x - win.w*0.1), win.w*0.8) / (win.w*0.8)
|
|
|
|
* (win.w - img.w * img.zoom);
|
|
|
|
py = MIN(MAX(0.0, y - win.h*0.1), win.h*0.8) / (win.h*0.8)
|
|
|
|
* (win.h - img.h * img.zoom);
|
|
|
|
} else {
|
|
|
|
px = img.x + x - ox;
|
|
|
|
py = img.y + y - oy;
|
|
|
|
}
|
2017-10-04 16:12:27 +00:00
|
|
|
|
|
|
|
if (img_pos(&img, px, py)) {
|
|
|
|
img_render(&img);
|
|
|
|
win_draw(&win);
|
2011-08-12 10:27:07 +00:00
|
|
|
}
|
2017-10-04 16:12:27 +00:00
|
|
|
XMaskEvent(win.env.dpy,
|
|
|
|
ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &e);
|
|
|
|
if (e.type == ButtonPress || e.type == ButtonRelease)
|
|
|
|
break;
|
|
|
|
while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e));
|
2018-01-12 12:39:46 +00:00
|
|
|
ox = x;
|
|
|
|
oy = y;
|
2017-10-04 16:12:27 +00:00
|
|
|
x = e.xmotion.x;
|
|
|
|
y = e.xmotion.y;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
2011-09-11 19:01:24 +00:00
|
|
|
set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
|
2017-10-05 11:49:11 +00:00
|
|
|
reset_cursor();
|
2011-08-12 10:27:07 +00:00
|
|
|
|
2014-07-23 19:50:31 +00:00
|
|
|
return true;
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool ci_set_zoom(arg_t zl)
|
2013-02-08 21:05:31 +00:00
|
|
|
{
|
2021-09-25 05:10:29 +00:00
|
|
|
return img_zoom_to(&img, (prefix ? prefix : zl) / 100.0);
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool ci_fit_to_win(arg_t sm)
|
2013-02-08 21:05:31 +00:00
|
|
|
{
|
2014-07-23 19:50:31 +00:00
|
|
|
return img_fit_win(&img, sm);
|
2011-07-26 16:01:29 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool ci_rotate(arg_t degree)
|
2013-02-08 21:05:31 +00:00
|
|
|
{
|
2014-07-23 19:50:31 +00:00
|
|
|
img_rotate(&img, degree);
|
|
|
|
return true;
|
2011-08-19 11:06:19 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool ci_flip(arg_t dir)
|
2013-02-08 21:05:31 +00:00
|
|
|
{
|
2014-07-23 19:50:31 +00:00
|
|
|
img_flip(&img, dir);
|
|
|
|
return true;
|
2012-05-06 07:39:45 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool ci_toggle_antialias(arg_t _)
|
2013-11-13 19:54:09 +00:00
|
|
|
{
|
2014-07-23 19:50:31 +00:00
|
|
|
img_toggle_antialias(&img);
|
|
|
|
return true;
|
2013-11-13 19:54:09 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool ci_toggle_alpha(arg_t _)
|
2013-02-08 21:05:31 +00:00
|
|
|
{
|
2014-07-23 19:50:31 +00:00
|
|
|
img.alpha = !img.alpha;
|
|
|
|
img.dirty = true;
|
|
|
|
return true;
|
2011-08-19 11:06:19 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool ci_slideshow(arg_t _)
|
2014-01-04 17:38:40 +00:00
|
|
|
{
|
2014-07-23 19:50:31 +00:00
|
|
|
if (prefix > 0) {
|
|
|
|
img.ss.on = true;
|
2016-12-01 19:33:24 +00:00
|
|
|
img.ss.delay = prefix * 10;
|
|
|
|
set_timeout(slideshow, img.ss.delay * 100, true);
|
2014-07-23 19:50:31 +00:00
|
|
|
} else if (img.ss.on) {
|
|
|
|
img.ss.on = false;
|
|
|
|
reset_timeout(slideshow);
|
2014-01-04 17:38:40 +00:00
|
|
|
} else {
|
2014-07-23 19:50:31 +00:00
|
|
|
img.ss.on = true;
|
2014-01-04 17:38:40 +00:00
|
|
|
}
|
2014-07-23 19:50:31 +00:00
|
|
|
return true;
|
2014-01-04 17:38:40 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool ct_move_sel(arg_t dir)
|
2014-07-23 19:50:31 +00:00
|
|
|
{
|
|
|
|
return tns_move_selection(&tns, dir, prefix);
|
|
|
|
}
|
|
|
|
|
2015-01-11 10:38:28 +00:00
|
|
|
bool ct_reload_all(arg_t _)
|
2014-07-23 19:50:31 +00:00
|
|
|
{
|
|
|
|
tns_free(&tns);
|
2014-09-30 19:54:17 +00:00
|
|
|
tns_init(&tns, files, &filecnt, &fileidx, &win);
|
2014-09-25 18:57:24 +00:00
|
|
|
tns.dirty = true;
|
|
|
|
return true;
|
2014-07-23 19:50:31 +00:00
|
|
|
}
|
2022-01-10 16:52:06 +00:00
|
|
|
|
|
|
|
bool ct_scroll(arg_t dir)
|
|
|
|
{
|
|
|
|
return tns_scroll(&tns, dir, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ct_drag_mark_image(arg_t _)
|
|
|
|
{
|
|
|
|
int sel;
|
|
|
|
|
|
|
|
if ((sel = tns_translate(&tns, xbutton_ev->x, xbutton_ev->y)) >= 0) {
|
|
|
|
XEvent e;
|
|
|
|
bool on = !(files[sel].flags & FF_MARK);
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
if (sel >= 0 && mark_image(sel, on))
|
|
|
|
redraw();
|
|
|
|
XMaskEvent(win.env.dpy,
|
|
|
|
ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &e);
|
|
|
|
if (e.type == ButtonPress || e.type == ButtonRelease)
|
|
|
|
break;
|
|
|
|
while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e));
|
|
|
|
sel = tns_translate(&tns, e.xbutton.x, e.xbutton.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ct_select(arg_t _)
|
|
|
|
{
|
|
|
|
int sel;
|
|
|
|
bool dirty = false;
|
|
|
|
static Time firstclick;
|
|
|
|
|
|
|
|
if ((sel = tns_translate(&tns, xbutton_ev->x, xbutton_ev->y)) >= 0) {
|
|
|
|
if (sel != fileidx) {
|
|
|
|
tns_highlight(&tns, fileidx, false);
|
|
|
|
tns_highlight(&tns, sel, true);
|
|
|
|
fileidx = sel;
|
|
|
|
firstclick = xbutton_ev->time;
|
|
|
|
dirty = true;
|
|
|
|
} else if (xbutton_ev->time - firstclick <= TO_DOUBLE_CLICK) {
|
|
|
|
mode = MODE_IMAGE;
|
|
|
|
set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
|
|
|
|
load_image(fileidx);
|
|
|
|
dirty = true;
|
|
|
|
} else {
|
|
|
|
firstclick = xbutton_ev->time;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dirty;
|
|
|
|
}
|