~exec64/imv-devel

Make mouse wheel action configurable v2 PROPOSED

Hugo Osvaldo Barrera: 1
 Make mouse wheel action configurable

 2 files changed, 55 insertions(+), 6 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~exec64/imv-devel/patches/53102/mbox | git am -3
Learn more about email & git

[PATCH v2] Make mouse wheel action configurable Export this patch

The default remains the same behaviour: zoom in/out. The new option
allows navigating to the next or previous image in the sequence.

Fixes: https://todo.sr.ht/~exec64/imv/33
---
v2: rebased to 4.5.0, tidied up parse_mouse_wheel
 doc/imv.5.txt |  4 ++++
 src/imv.c     | 57 +++++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/doc/imv.5.txt b/doc/imv.5.txt
index 3f009fa..4575c2f 100644
--- a/doc/imv.5.txt
+++ b/doc/imv.5.txt
@@ -49,6 +49,10 @@ The *[options]* section accepts the following settings:
*loop_input* = <true|false>::
	Return to first image after viewing the last one. Defaults to 'true'.

*mouse_wheel* = <zoom|navigate>::
	Action to perform on mouse wheel events. 'navigate' will switch to the next
	and previous image. Defaults to 'zoom'.

*overlay* = <true|false>::
	Start with the overlay visible. Defaults to 'false'.

diff --git a/src/imv.c b/src/imv.c
index ce0c43a..1fa0c6c 100644
--- a/src/imv.c
+++ b/src/imv.c
@@ -75,6 +75,12 @@ struct internal_event {
  } data;
};


enum wheel_action {
  ZOOM,
  NAVIGATE,
};

struct imv {
  /* set to true to trigger clean exit */
  bool quit;
@@ -177,6 +183,9 @@ struct imv {
  /* the user-specified format strings for the overlay and window title */
  char *title_text;

  /* action to perform on mouse wheel */
  enum wheel_action wheel_action;

  /* imv subsystems */
  struct imv_binds *binds;
  struct imv_navigator *navigator;
@@ -434,6 +443,30 @@ static void key_handler(struct imv *imv, const struct imv_event *event)
  imv->need_redraw = true;
}

static void mouse_wheel_handler(struct imv *imv, const struct imv_event *event) {
  switch (imv-> wheel_action) {
    case ZOOM:
      {
        double x, y;
        imv_window_get_mouse_position(imv->window, &x, &y);
        imv_viewport_zoom(imv->view, imv->current_image, IMV_ZOOM_MOUSE,
            x, y, -event->data.mouse_scroll.dy);
      }
      break;
    case NAVIGATE:
      {
        int index;
        if (event->data.mouse_scroll.dy > 0) {
          index = 1;
        } else {
          index = -1;
        }
        imv_navigator_select_rel(imv->navigator, index);
        imv_viewport_reset_transform(imv->view);
      }
      break;
  }
}

static void event_handler(void *data, const struct imv_event *e)
{
@@ -463,12 +496,7 @@ static void event_handler(void *data, const struct imv_event *e)
      }
      break;
    case IMV_EVENT_MOUSE_SCROLL:
      {
        double x, y;
        imv_window_get_mouse_position(imv->window, &x, &y);
        imv_viewport_zoom(imv->view, imv->current_image, IMV_ZOOM_MOUSE,
            x, y, -e->data.mouse_scroll.dy);
      }
        mouse_wheel_handler(imv, e);
      break;
    case IMV_EVENT_CUSTOM:
      consume_internal_event(imv, e->data.custom);
@@ -784,6 +812,19 @@ static bool parse_initial_height(struct imv *imv, const char *height_value)
  return true;
}

static bool parse_mouse_wheel(struct imv *imv, const char *value)
{
  if (!strcmp("navigate", value)) {
    imv->wheel_action = NAVIGATE;
    return true;
  } else if (!strcmp("zoom", value)) {
    imv->wheel_action = ZOOM;
    return true;
  }

  return false;
}

static void *pipe_stdin(void *data)
{
  int *fd = data;
@@ -1659,6 +1700,10 @@ static int handle_ini_value(void *user, const char *section, const char *name,
      return 1;
    }

    if (!strcmp(name, "mouse_wheel")) {
      return parse_mouse_wheel(imv, value);
    }

    /* No matches so far */
    imv_log(IMV_WARNING, "Ignoring unknown option: %s\n", name);
    return 1;
-- 
2.45.1