imv
imv copied to clipboard
touch gesture support
would be awesome to have touch gesture support such as pinch zoom and swipe for switching to the next image in the same folder
Oh yes, this would be awesome.
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.
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.
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.
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.
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.
I can test with a touch screen laptop if you want to start a branch
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.
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.
And done.
Can you review #245 please?