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 --- main.c | 61 +++++++++---------------------------------------------------- 1 file changed, 9 insertions(+), 52 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index f8c727f..efedfc6 100644 --- a/main.c +++ b/main.c @@ -57,6 +57,7 @@ arl_t arl; img_t img; tns_t tns; win_t win; +const XButtonEvent *xbutton_ev; fileinfo_t *files; int filecnt, fileidx; @@ -661,64 +662,19 @@ static void on_keypress(XKeyEvent *kev) prefix = 0; } -static void on_buttonpress(XButtonEvent *bev) +static void on_buttonpress(const XButtonEvent *bev) { - int sel; bool dirty = false; - static Time firstclick; if (mode == MODE_IMAGE) { set_timeout(reset_cursor, TO_CURSOR_HIDE, true); reset_cursor(); - dirty = process_bindings(buttons, ARRLEN(buttons), bev->button, bev->state, 0); - if (dirty) - redraw(); - } else { - /* thumbnail mode (hard-coded) */ - switch (bev->button) { - case Button1: - if ((sel = tns_translate(&tns, bev->x, bev->y)) >= 0) { - if (sel != fileidx) { - tns_highlight(&tns, fileidx, false); - tns_highlight(&tns, sel, true); - fileidx = sel; - firstclick = bev->time; - redraw(); - } else if (bev->time - firstclick <= TO_DOUBLE_CLICK) { - mode = MODE_IMAGE; - set_timeout(reset_cursor, TO_CURSOR_HIDE, true); - load_image(fileidx); - redraw(); - } else { - firstclick = bev->time; - } - } - break; - case Button3: - if ((sel = tns_translate(&tns, bev->x, bev->y)) >= 0) { - bool on = !(files[sel].flags & FF_MARK); - XEvent e; - - 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); - } - } - break; - case Button4: - case Button5: - if (tns_scroll(&tns, bev->button == Button4 ? DIR_UP : DIR_DOWN, - (bev->state & ControlMask) != 0)) - redraw(); - break; - } + dirty = process_bindings(buttons_img, ARRLEN(buttons_img), bev->button, bev->state, 0); + } else { /* thumbnail mode */ + dirty = process_bindings(buttons_tns, ARRLEN(buttons_tns), bev->button, bev->state, 0); } + if (dirty) + redraw(); prefix = 0; } @@ -731,13 +687,14 @@ static void run(void) bool discard, init_thumb, load_thumb, to_set; XEvent ev, nextev; + xbutton_ev = &ev.xbutton; while (true) { to_set = check_timeouts(&timeout); init_thumb = mode == MODE_THUMB && tns.initnext < filecnt; load_thumb = mode == MODE_THUMB && tns.loadnext < tns.end; if ((init_thumb || load_thumb || to_set || info.fd != -1 || - arl.fd != -1) && XPending(win.env.dpy) == 0) + arl.fd != -1) && XPending(win.env.dpy) == 0) { if (load_thumb) { set_timeout(redraw, TO_REDRAW_THUMBS, false); -- cgit v1.2.3