summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorphi <crispyfrog@163.com>2018-01-12 13:39:46 +0100
committerBert Münnich <ber.t@posteo.de>2018-01-22 09:46:38 +0100
commitd5c5708110bcaa60815d7648260f9688bbd12824 (patch)
tree0560ffe8af3561cea3111120e07e0dc11119dd84
parent8017b75de4c2a77245f5ae9d635cc026c00783a7 (diff)
downloadnsxiv-d5c5708110bcaa60815d7648260f9688bbd12824.tar.zst
Use argument to select between two drag methods
-rw-r--r--Makefile2
-rw-r--r--commands.c21
-rw-r--r--config.def.h2
-rw-r--r--sxiv.h5
4 files changed, 22 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index 3df162f..8ce289d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-VERSION = git-20180109
+VERSION = git-20180122
srcdir = .
VPATH = $(srcdir)
diff --git a/commands.c b/commands.c
index 966ee4c..4ad4e04 100644
--- a/commands.c
+++ b/commands.c
@@ -321,9 +321,9 @@ bool ci_scroll_to_edge(arg_t dir)
return img_pan_edge(&img, dir);
}
-bool ci_drag(arg_t _)
+bool ci_drag(arg_t mode)
{
- int x, y;
+ int x, y, ox, oy;
float px, py;
XEvent e;
@@ -333,12 +333,19 @@ bool ci_drag(arg_t _)
win_set_cursor(&win, CURSOR_DRAG);
win_cursor_pos(&win, &x, &y);
+ ox = x;
+ oy = y;
for (;;) {
- 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);
+ if (mode == DRAG_ABSOLUTE) {
+ 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;
+ }
if (img_pos(&img, px, py)) {
img_render(&img);
@@ -349,6 +356,8 @@ bool ci_drag(arg_t _)
if (e.type == ButtonPress || e.type == ButtonRelease)
break;
while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e));
+ ox = x;
+ oy = y;
x = e.xmotion.x;
y = e.xmotion.y;
}
diff --git a/config.def.h b/config.def.h
index 5af745d..de9ca51 100644
--- a/config.def.h
+++ b/config.def.h
@@ -151,7 +151,7 @@ static const keymap_t keys[] = {
static const button_t buttons[] = {
/* modifiers button function argument */
{ 0, 1, i_cursor_navigate, None },
- { 0, 2, i_drag, None },
+ { 0, 2, i_drag, DRAG_ABSOLUTE },
{ 0, 3, g_switch_mode, None },
{ 0, 4, g_zoom, +1 },
{ 0, 5, g_zoom, -1 },
diff --git a/sxiv.h b/sxiv.h
index 4e384c8..d1acb4c 100644
--- a/sxiv.h
+++ b/sxiv.h
@@ -94,6 +94,11 @@ typedef enum {
} scalemode_t;
typedef enum {
+ DRAG_RELATIVE,
+ DRAG_ABSOLUTE
+} dragmode_t;
+
+typedef enum {
CURSOR_ARROW,
CURSOR_DRAG,
CURSOR_WATCH,