imv icon indicating copy to clipboard operation
imv copied to clipboard

touch gesture support

Open yannick opened this issue 6 years ago • 10 comments

would be awesome to have touch gesture support such as pinch zoom and swipe for switching to the next image in the same folder

yannick avatar Dec 15 '18 13:12 yannick

Oh yes, this would be awesome.

ghost avatar Jan 04 '19 12:01 ghost

It's certainly doable, as SDL supports touch events, but it'd require some additional logic for interpreting gestures, and I have no touch screen devices that run a desktop environment.

If someone wants to work on this, they're welcome to.

eXeC64 avatar Jan 14 '19 19:01 eXeC64

Here's a completely untested patch that might work. The constants will need tuning:

diff --git a/src/imv.c b/src/imv.c
index 2af5878..570ebdd 100644
--- a/src/imv.c
+++ b/src/imv.c
@@ -1114,10 +1114,30 @@ static void handle_event(struct imv *imv, SDL_Event *event)
       if (event->motion.state & SDL_BUTTON_LMASK) {
         imv_viewport_move(imv->view, event->motion.xrel, event->motion.yrel, imv->image);
       }
       SDL_ShowCursor(SDL_ENABLE);
       break;
+    case SDL_MULTIGESTURE: {
+        const int num_fingers = event->mgesture.numFingers;
+        const int swipe_threshold = 100;
+        const float gesture_scale = 10.0;
+        const int x = gesture_scale * event->mgesture.x;
+        const int y = gesture_scale * event->mgesture.y;
+
+        if (num_fingers > 1 && x > swipe_threshold) {
+          imv_navigator_select_rel(imv->navigator, 1);
+          imv->slideshow_time_elapsed = 0;
+        } else if (num_fingers > 1 x < -swipe_threshold) {
+          imv_navigator_select_rel(imv->navigator, -1);
+          imv->slideshow_time_elapsed = 0;
+        } else {
+          const int zoom = gesture_scale * event->mgesture.dDist;
+          imv_viewport_move(imv->view, x, y, imv->image);
+          imv_viewport_zoom(imv->view, imv->image, IMV_ZOOM_KEYBOARD, zoom);
+        }
+      }
+      break;
     case SDL_WINDOWEVENT:
       /* For some reason SDL passes events to us that occurred before we
        * gained focus, and passes them *after* the focus gained event.
        * Due to behavioural quirks from such events, whenever we gain focus
        * we have to ignore all window events already in the queue.

If you're able to test this, please let me know how you get on.

eXeC64 avatar Feb 16 '19 15:02 eXeC64

Okay I tested this patch. By the way there is a typo in the patch, I think it should be else if (num_fingers > 1 && x < -swipe_threshold), instead of else if (num_fingers > 1 x < -swipe_threshold). I don't know how to code C though, so I might be wrong.

Trying to move the image using a touch screen doesn't do anything. Trying to pinch zoom makes the image move and disappear to the lower right corner.

EDIT: I'm on Sway, if that makes a difference.

FunctionalHacker avatar May 09 '19 07:05 FunctionalHacker

For various reasons, in the next major release imv is switching to glfw. Unfortunately, glfw doesn't seem to contain touch screen / gesture support as of yet, so this feature is going to be in the long grass for a while.

eXeC64 avatar Jun 22 '19 01:06 eXeC64

I ended up moving to native X11/Wayland for v4, not glfw. Touch gesture support could be an optional feature using an external library, but I'm likely to only put any effort into maintaining it on Wayland. Since I don't have any touchscreen devices running linux, I can't really develop or test this anyway.

eXeC64 avatar Aug 18 '19 00:08 eXeC64

I can test with a touch screen laptop if you want to start a branch

FunctionalHacker avatar Oct 31 '19 09:10 FunctionalHacker

I have no touch screen devices that run a desktop environment

Can't you use a laptop touchpad to try this out? Or an external one?

I'm currently not on a touchscreen display, but would still appreciate the gesture support.

WhyNotHugo avatar Mar 17 '20 01:03 WhyNotHugo

Can't you use a laptop touchpad to try this out? Or an external one?

Unfortunately not, at least in wayland touchpad and touchscreen events are separate.

Right now I'm working on at least initial support tap scrolling/zoom for wayland. No promises but hopefully soon I'll roll out a PR for this one.

gg-rewrite avatar May 03 '20 09:05 gg-rewrite

And done.

Can you review #245 please?

gg-rewrite avatar May 05 '20 15:05 gg-rewrite