I like copy-on-release and it is how xterm works (it preserves the
selection too, but we don't really have an option of doing that).

Maybe instead you could make a right- or middle-button drag select but
not exit copy mode?


On Sat, Jun 21, 2014 at 04:30:18PM +0100, Balazs Kezes wrote:
> From 18ca63c60b9e0ab404f93a63fd6d1252364ab7e6 Mon Sep 17 00:00:00 2001
> From: Balazs Kezes <rlblas...@gmail.com>
> Date: Sat, 21 Jun 2014 15:41:42 +0100
> Subject: [PATCH 3/5] Extend selection with right click in copy mode
> 
> This changes the behavior of the mouse in the copy mode. Previously when you
> released the left button you automatically left the copy mode. Not anymore. To
> leave the copy mode you need to press the middle mouse button. Right click 
> will
> extend the current selection.
> 
> But also make sure that when you left click once that won't enter the copy 
> mode
> unless you start dragging. A common usecase is to use the left button to 
> select
> a pane - we don't want to break this case. Look at the logic around
> quit_on_mouse_release for how is this behavior preserved.
> ---
>  cmd-copy-mode.c |  2 +-
>  input-keys.c    |  2 +-
>  tmux.h          |  2 +-
>  window-copy.c   | 66 
> +++++++++++++++++++++++++++++++++++++++++----------------
>  4 files changed, 51 insertions(+), 21 deletions(-)
> 
> diff --git a/cmd-copy-mode.c b/cmd-copy-mode.c
> index f11c7af..7e1a995 100644
> --- a/cmd-copy-mode.c
> +++ b/cmd-copy-mode.c
> @@ -56,7 +56,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmd_q *cmdq)
>       if (wp->mode != &window_copy_mode) {
>               if (window_pane_set_mode(wp, &window_copy_mode) != 0)
>                       return (CMD_RETURN_NORMAL);
> -             window_copy_init_from_pane(wp);
> +             window_copy_init_from_pane(wp, 0);
>       }
>       if (wp->mode == &window_copy_mode && args_has(self->args, 'u'))
>               window_copy_pageup(wp);
> diff --git a/input-keys.c b/input-keys.c
> index 840104f..767bbdd 100644
> --- a/input-keys.c
> +++ b/input-keys.c
> @@ -268,7 +268,7 @@ input_mouse(struct window_pane *wp, struct session *s, 
> struct mouse_event *m)
>               }
>       } else {
>               if (window_pane_set_mode(wp, &window_copy_mode) == 0) {
> -                     window_copy_init_from_pane(wp);
> +                     window_copy_init_from_pane(wp, !wheel);
>                       if (wp->mode->mouse != NULL)
>                               wp->mode->mouse(wp, s, m);
>               }
> diff --git a/tmux.h b/tmux.h
> index c4c5236..2c178ad 100644
> --- a/tmux.h
> +++ b/tmux.h
> @@ -2245,7 +2245,7 @@ extern const char window_clock_table[14][5][5];
>  
>  /* window-copy.c */
>  extern const struct window_mode window_copy_mode;
> -void          window_copy_init_from_pane(struct window_pane *);
> +void          window_copy_init_from_pane(struct window_pane *, int);
>  void          window_copy_init_for_output(struct window_pane *);
>  void printflike2 window_copy_add(struct window_pane *, const char *, ...);
>  void          window_copy_vadd(struct window_pane *, const char *, va_list);
> diff --git a/window-copy.c b/window-copy.c
> index 0775bcb..f398771 100644
> --- a/window-copy.c
> +++ b/window-copy.c
> @@ -154,6 +154,8 @@ struct window_copy_mode_data {
>  
>       enum window_copy_input_type jumptype;
>       char            jumpchar;
> +
> +     int             quit_on_mouse_release;
>  };
>  
>  struct screen *
> @@ -189,6 +191,8 @@ window_copy_init(struct window_pane *wp)
>       data->jumptype = WINDOW_COPY_OFF;
>       data->jumpchar = '\0';
>  
> +     data->quit_on_mouse_release = 0;
> +
>       s = &data->screen;
>       screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0);
>       if (options_get_number(&wp->window->options, "mode-mouse"))
> @@ -206,7 +210,7 @@ window_copy_init(struct window_pane *wp)
>  }
>  
>  void
> -window_copy_init_from_pane(struct window_pane *wp)
> +window_copy_init_from_pane(struct window_pane *wp, int quit_on_mouse_release)
>  {
>       struct window_copy_mode_data    *data = wp->modedata;
>       struct screen                   *s = &data->screen;
> @@ -219,6 +223,7 @@ window_copy_init_from_pane(struct window_pane *wp)
>       data->backing = &wp->base;
>       data->cx = data->backing->cx;
>       data->cy = data->backing->cy;
> +     data->quit_on_mouse_release = quit_on_mouse_release;
>  
>       s->cx = data->cx;
>       s->cy = data->cy;
> @@ -869,6 +874,14 @@ window_copy_key_numeric_prefix(struct window_pane *wp, 
> int key)
>       return (0);
>  }
>  
> +static void
> +window_copy_select_via_mouse(struct window_pane *wp, struct mouse_event *m)
> +{
> +     window_copy_update_cursor(wp, m->x, m->y);
> +     if (window_copy_update_selection(wp, 1))
> +             window_copy_redraw_screen(wp);
> +}
> +
>  void
>  window_copy_mouse(
>      struct window_pane *wp, struct session *sess, struct mouse_event *m)
> @@ -876,6 +889,7 @@ window_copy_mouse(
>       struct window_copy_mode_data    *data = wp->modedata;
>       struct screen                   *s = &data->screen;
>       u_int                            i;
> +     int                              pressed, released, dragged;
>  
>       if (m->x >= screen_size_x(s))
>               return;
> @@ -901,35 +915,51 @@ window_copy_mouse(
>               return;
>       }
>  
> -     /*
> -      * If already reading motion, move the cursor while buttons are still
> -      * pressed, or stop the selection on their release.
> -      */
> -     if (s->mode & MODE_MOUSE_BUTTON) {
> -             if (~m->event & MOUSE_EVENT_UP) {
> -                     window_copy_update_cursor(wp, m->x, m->y);
> -                     if (window_copy_update_selection(wp, 1))
> -                             window_copy_redraw_screen(wp);
> -                     return;
> -             }
> -             goto reset_mode;
> -     }
> +     pressed = (m->event & MOUSE_EVENT_DOWN);
> +     released = (m->event & MOUSE_EVENT_UP);
> +     dragged = (m->event & MOUSE_EVENT_DRAG);
>  
> -     /* Otherwise if other buttons pressed, start selection and motion. */
> -     if (~m->event & MOUSE_EVENT_UP) {
> +     if (!(s->mode & MODE_MOUSE_BUTTON) && pressed) {
>               s->mode &= ~MODE_MOUSE_STANDARD;
>               s->mode |= MODE_MOUSE_BUTTON;
> +     } else if ((s->mode & MODE_MOUSE_BUTTON) && released) {
> +             s->mode &= ~MODE_MOUSE_BUTTON;
> +             s->mode |= MODE_MOUSE_STANDARD;
> +     }
>  
> +     if (data->quit_on_mouse_release && m->clicks == 1 && released) {
> +             if (sess != NULL)
> +                     window_pane_reset_mode(wp);
> +             return;
> +     } else if (!pressed) {
> +             /* Let's reset this on release, dragged or wheel events. */
> +             data->quit_on_mouse_release = 0;
> +     }
> +
> +     if (m->button == 1) {
> +             if (released)
> +                     goto reset_mode;
> +             else
> +                     return;
> +     }
> +
> +     if (pressed && m->button == 0 && !s->sel.flag) {
>               window_copy_update_cursor(wp, m->x, m->y);
>               window_copy_start_selection(wp);
>               window_copy_redraw_screen(wp);
>       }
>  
> +     if (dragged || (pressed && m->button == 2)) {
> +             window_copy_select_via_mouse(wp, m);
> +     } else if (pressed && m->button == 0) {
> +             window_copy_update_cursor(wp, m->x, m->y);
> +             window_copy_start_selection(wp);
> +             window_copy_select_via_mouse(wp, m);
> +     }
> +
>       return;
>  
>  reset_mode:
> -     s->mode &= ~MODE_MOUSE_BUTTON;
> -     s->mode |= MODE_MOUSE_STANDARD;
>       if (sess != NULL) {
>               window_copy_copy_selection(wp, NULL);
>               window_pane_reset_mode(wp);
> -- 
> 2.0.0.526.g5318336
> 


------------------------------------------------------------------------------
HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
Find What Matters Most in Your Big Data with HPCC Systems
Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
Leverages Graph Analysis for Fast Processing & Easy Data Exploration
http://p.sf.net/sfu/hpccsystems
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to