Krolyxon
Commit d5c5708

Branches

Refs →

nsxivd5c5708

Use argument to select between two drag methods

Author
phi
Date
2018-01-12 20:39 +0800
Committer
Bert Münnich · 2018-01-22 09:46 +0100
Parent
8017b75
Commit
d5c5708110bcaa60815d7648260f9688bbd12824

+22 −8

4 files changed

  1. M Makefile +1 −1
  2. M commands.c +15 −6
  3. M config.def.h +1 −1
  4. M sxiv.h +5 −0
M Makefile View
@@ -1,4 +1,4 @@
1−VERSION = git-20180109
1+VERSION = git-20180122
22
33 srcdir = .
44 VPATH = $(srcdir)
M commands.c View
@@ -321,9 +321,9 @@ bool ci_scroll_to_edge(arg_t dir)
321321 return img_pan_edge(&img, dir);
322322 }
323323
324−bool ci_drag(arg_t _)
324+bool ci_drag(arg_t mode)
325325 {
326− int x, y;
326+ int x, y, ox, oy;
327327 float px, py;
328328 XEvent e;
329329
@@ -333,12 +333,19 @@ bool ci_drag(arg_t _)
333333 win_set_cursor(&win, CURSOR_DRAG);
334334
335335 win_cursor_pos(&win, &x, &y);
336+ ox = x;
337+ oy = y;
336338
337339 for (;;) {
338− px = MIN(MAX(0.0, x - win.w*0.1), win.w*0.8) / (win.w*0.8)
339− * (win.w - img.w * img.zoom);
340− py = MIN(MAX(0.0, y - win.h*0.1), win.h*0.8) / (win.h*0.8)
341− * (win.h - img.h * img.zoom);
340+ if (mode == DRAG_ABSOLUTE) {
341+ px = MIN(MAX(0.0, x - win.w*0.1), win.w*0.8) / (win.w*0.8)
342+ * (win.w - img.w * img.zoom);
343+ py = MIN(MAX(0.0, y - win.h*0.1), win.h*0.8) / (win.h*0.8)
344+ * (win.h - img.h * img.zoom);
345+ } else {
346+ px = img.x + x - ox;
347+ py = img.y + y - oy;
348+ }
342349
343350 if (img_pos(&img, px, py)) {
344351 img_render(&img);
@@ -349,6 +356,8 @@ bool ci_drag(arg_t _)
349356 if (e.type == ButtonPress || e.type == ButtonRelease)
350357 break;
351358 while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e));
359+ ox = x;
360+ oy = y;
352361 x = e.xmotion.x;
353362 y = e.xmotion.y;
354363 }
M config.def.h View
@@ -151,7 +151,7 @@ static const keymap_t keys[] = {
151151 static const button_t buttons[] = {
152152 /* modifiers button function argument */
153153 { 0, 1, i_cursor_navigate, None },
154− { 0, 2, i_drag, None },
154+ { 0, 2, i_drag, DRAG_ABSOLUTE },
155155 { 0, 3, g_switch_mode, None },
156156 { 0, 4, g_zoom, +1 },
157157 { 0, 5, g_zoom, -1 },
M sxiv.h View
@@ -93,6 +93,11 @@ typedef enum {
9393 SCALE_ZOOM
9494 } scalemode_t;
9595
96+typedef enum {
97+ DRAG_RELATIVE,
98+ DRAG_ABSOLUTE
99+} dragmode_t;
100+
96101 typedef enum {
97102 CURSOR_ARROW,
98103 CURSOR_DRAG,