Use argument to select between two drag methods

This commit is contained in:
phi 2018-01-12 20:39:46 +08:00 committed by Bert Münnich
parent 8017b75de4
commit d5c5708110
4 changed files with 22 additions and 8 deletions

View file

@ -1,4 +1,4 @@
VERSION = git-20180109 VERSION = git-20180122
srcdir = . srcdir = .
VPATH = $(srcdir) VPATH = $(srcdir)

View file

@ -321,9 +321,9 @@ bool ci_scroll_to_edge(arg_t dir)
return img_pan_edge(&img, 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; float px, py;
XEvent e; XEvent e;
@ -333,12 +333,19 @@ bool ci_drag(arg_t _)
win_set_cursor(&win, CURSOR_DRAG); win_set_cursor(&win, CURSOR_DRAG);
win_cursor_pos(&win, &x, &y); win_cursor_pos(&win, &x, &y);
ox = x;
oy = y;
for (;;) { for (;;) {
px = MIN(MAX(0.0, x - win.w*0.1), win.w*0.8) / (win.w*0.8) if (mode == DRAG_ABSOLUTE) {
* (win.w - img.w * img.zoom); px = MIN(MAX(0.0, x - win.w*0.1), win.w*0.8) / (win.w*0.8)
py = MIN(MAX(0.0, y - win.h*0.1), win.h*0.8) / (win.h*0.8) * (win.w - img.w * img.zoom);
* (win.h - img.h * 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)) { if (img_pos(&img, px, py)) {
img_render(&img); img_render(&img);
@ -349,6 +356,8 @@ bool ci_drag(arg_t _)
if (e.type == ButtonPress || e.type == ButtonRelease) if (e.type == ButtonPress || e.type == ButtonRelease)
break; break;
while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e)); while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e));
ox = x;
oy = y;
x = e.xmotion.x; x = e.xmotion.x;
y = e.xmotion.y; y = e.xmotion.y;
} }

View file

@ -151,7 +151,7 @@ static const keymap_t keys[] = {
static const button_t buttons[] = { static const button_t buttons[] = {
/* modifiers button function argument */ /* modifiers button function argument */
{ 0, 1, i_cursor_navigate, None }, { 0, 1, i_cursor_navigate, None },
{ 0, 2, i_drag, None }, { 0, 2, i_drag, DRAG_ABSOLUTE },
{ 0, 3, g_switch_mode, None }, { 0, 3, g_switch_mode, None },
{ 0, 4, g_zoom, +1 }, { 0, 4, g_zoom, +1 },
{ 0, 5, g_zoom, -1 }, { 0, 5, g_zoom, -1 },

5
sxiv.h
View file

@ -93,6 +93,11 @@ typedef enum {
SCALE_ZOOM SCALE_ZOOM
} scalemode_t; } scalemode_t;
typedef enum {
DRAG_RELATIVE,
DRAG_ABSOLUTE
} dragmode_t;
typedef enum { typedef enum {
CURSOR_ARROW, CURSOR_ARROW,
CURSOR_DRAG, CURSOR_DRAG,