Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

touch gesture support #138

Open
yannick opened this issue Dec 15, 2018 · 10 comments
Open

touch gesture support #138

yannick opened this issue Dec 15, 2018 · 10 comments
Labels
Feature New feature request Help Wanted issues contributors are welcome to volunteer to address

Comments

@yannick
Copy link

yannick commented Dec 15, 2018

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

@ghost
Copy link

ghost commented Jan 4, 2019

Oh yes, this would be awesome.

@eXeC64
Copy link
Owner

eXeC64 commented Jan 14, 2019

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 eXeC64 added Feature New feature request Help Wanted issues contributors are welcome to volunteer to address labels Jan 14, 2019
@eXeC64
Copy link
Owner

eXeC64 commented Feb 16, 2019

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.

@FunctionalHacker
Copy link

FunctionalHacker commented May 9, 2019

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.

@eXeC64
Copy link
Owner

eXeC64 commented Jun 22, 2019

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
Copy link
Owner

eXeC64 commented Aug 18, 2019

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.

@FunctionalHacker
Copy link

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

@WhyNotHugo
Copy link
Contributor

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.

@gg-rewrite
Copy link

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
Copy link

And done.

Can you review #245 please?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Feature New feature request Help Wanted issues contributors are welcome to volunteer to address
Projects
None yet
Development

No branches or pull requests

5 participants