From 7a75c42b37b08f44c72f9a7c98eb6076967470fb Mon Sep 17 00:00:00 2001 From: N-R-K <79544946+N-R-K@users.noreply.github.com> Date: Mon, 10 Jan 2022 16:52:06 +0000 Subject: make thumbnail bindings configureable via config.h (#167) this allows for configuring thumbnail mode mouse bindings similar to image mode bindings. however we can't put the thumbnails bindings into the existing buttons[] array due to fallthrough. For example M3 would switch mode and then end up selecting an image. which is why thumbnail bindings have been put into it's own array `buttons_tns[]` and `buttons[]` has been renamed to `buttons_img[]` for consistency. Closes: https://github.com/nsxiv/nsxiv/issues/131 --- commands.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'commands.c') diff --git a/commands.c b/commands.c index a751c94..aafc510 100644 --- a/commands.c +++ b/commands.c @@ -42,6 +42,7 @@ extern appmode_t mode; extern img_t img; extern tns_t tns; extern win_t win; +extern const XButtonEvent *xbutton_ev; extern fileinfo_t *files; extern int filecnt, fileidx; @@ -436,3 +437,57 @@ bool ct_reload_all(arg_t _) tns.dirty = true; return true; } + +bool ct_scroll(arg_t dir) +{ + return tns_scroll(&tns, dir, false); +} + +bool ct_drag_mark_image(arg_t _) +{ + int sel; + + if ((sel = tns_translate(&tns, xbutton_ev->x, xbutton_ev->y)) >= 0) { + XEvent e; + bool on = !(files[sel].flags & FF_MARK); + + while (true) { + if (sel >= 0 && mark_image(sel, on)) + redraw(); + XMaskEvent(win.env.dpy, + ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &e); + if (e.type == ButtonPress || e.type == ButtonRelease) + break; + while (XCheckTypedEvent(win.env.dpy, MotionNotify, &e)); + sel = tns_translate(&tns, e.xbutton.x, e.xbutton.y); + } + } + + return false; +} + +bool ct_select(arg_t _) +{ + int sel; + bool dirty = false; + static Time firstclick; + + if ((sel = tns_translate(&tns, xbutton_ev->x, xbutton_ev->y)) >= 0) { + if (sel != fileidx) { + tns_highlight(&tns, fileidx, false); + tns_highlight(&tns, sel, true); + fileidx = sel; + firstclick = xbutton_ev->time; + dirty = true; + } else if (xbutton_ev->time - firstclick <= TO_DOUBLE_CLICK) { + mode = MODE_IMAGE; + set_timeout(reset_cursor, TO_CURSOR_HIDE, true); + load_image(fileidx); + dirty = true; + } else { + firstclick = xbutton_ev->time; + } + } + + return dirty; +} -- cgit v1.2.3