Ticket #3571: 3571-fixup-WInput-use-the-new-mouse-API.patch

File 3571-fixup-WInput-use-the-new-mouse-API.patch, 2.4 KB (added by mooffie, 8 years ago)
  • lib/widget/input.c

    From 28edd8ddaed980cf5a592fe78a83fcfd83c6baca Mon Sep 17 00:00:00 2001
    From: Mooffie <mooffie@gmail.com>
    Date: Fri, 19 Feb 2016 12:28:42 +0200
    Subject: [PATCH] fixup! WInput: use the new mouse API.
    
    ---
     lib/widget/input.c | 27 +++++++++++++++------------
     1 file changed, 15 insertions(+), 12 deletions(-)
    
    diff --git a/lib/widget/input.c b/lib/widget/input.c
    index 3c07537..c4f0384 100644
    a b input_destroy (WInput * in) 
    908908 
    909909/* --------------------------------------------------------------------------------------------- */ 
    910910 
    911 static void 
    912 input_update_point (WInput * in, int pos) 
     911/** 
     912 * Calculates the buffer index (aka "point") corresponding to some screen coordinate. 
     913 */ 
     914static int 
     915input_screen_to_point (WInput * in, int x) 
    913916{ 
    914     pos += in->term_first_shown; 
     917    x += in->term_first_shown; 
    915918 
    916     if (pos < str_term_width1 (in->buffer)) 
    917         in->point = str_column_to_pos (in->buffer, pos); 
     919    if (x < 0) 
     920        return 0; 
     921    else if (x < str_term_width1 (in->buffer)) 
     922        return str_column_to_pos (in->buffer, x); 
    918923    else 
    919         in->point = str_length (in->buffer); 
     924        return str_length (in->buffer); 
    920925} 
    921926 
    922927/* --------------------------------------------------------------------------------------------- */ 
    input_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) 
    933938    case MSG_MOUSE_DOWN: 
    934939        dlg_select_widget (w); 
    935940        in->first = FALSE; 
    936         input_mark_cmd (in, FALSE); 
    937941 
    938942        if (event->x >= w->cols - HISTORY_BUTTON_WIDTH && should_show_history_button (in)) 
    939943            do_show_hist (in); 
    940944        else 
    941945        { 
    942             input_update_point (in, event->x); 
     946            input_mark_cmd (in, FALSE); 
     947            input_set_point (in, input_screen_to_point (in, event->x)); 
    943948            /* save point for the possible following MSG_MOUSE_DRAG action */ 
    944949            prev_point = in->point; 
    945950        } 
    946         input_update (in, TRUE); 
    947951        break; 
    948952 
    949953    case MSG_MOUSE_DRAG: 
    950         /* start point: set marker using point before first GPM_DRAG action */ 
     954        /* start point: set marker using point before first MSG_MOUSE_DRAG action */ 
    951955        if (in->mark < 0) 
    952956            in->mark = prev_point; 
    953957 
    954         input_update_point (in, event->x); 
    955         input_update (in, TRUE); 
     958        input_set_point (in, input_screen_to_point (in, event->x)); 
    956959        break; 
    957960 
    958961    default: