Ticket #3571: 3571-Get-rid-of-the-click-variable.patch

File 3571-Get-rid-of-the-click-variable.patch, 5.7 KB (added by mooffie, 8 years ago)
  • lib/widget/dialog.c

    From ede8abc8a991051c58f96a522ca4b8b5f3f6297d Mon Sep 17 00:00:00 2001
    From: Mooffie <mooffie@gmail.com>
    Date: Thu, 24 Mar 2016 00:20:06 +0200
    Subject: [PATCH] Get rid of the 'click' variable.
    
    ---
     lib/widget/dialog.c     |  5 ++---
     lib/widget/mouse.c      | 31 +++++++++++++++----------------
     lib/widget/mouse.h      |  4 ++--
     src/editor/editwidget.c |  3 +--
     4 files changed, 20 insertions(+), 23 deletions(-)
    
    diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c
    index 8fa00fc..216edf2 100644
    a b dlg_handle_key (WDialog * h, int d_key) 
    365365static int 
    366366dlg_mouse_translator (Gpm_Event * event, Widget * w) 
    367367{ 
    368     gboolean run_click; 
    369368    mouse_event_t me; 
    370369 
    371     me = mouse_translate_event (w, event, &run_click); 
     370    me = mouse_translate_event (w, event); 
    372371 
    373     return mouse_process_event (w, &me, run_click); 
     372    return mouse_process_event (w, &me); 
    374373} 
    375374 
    376375/* --------------------------------------------------------------------------------------------- */ 
  • lib/widget/mouse.c

    diff --git a/lib/widget/mouse.c b/lib/widget/mouse.c
    index 1c83049..3834769 100644
    a b init_mouse_event (mouse_event_t * event, mouse_msg_t msg, const Gpm_Event * glob 
    7878 * 
    7979 * @param w Widget object 
    8080 * @param event GPM event 
    81  * @param click whether mouse click was raised or not 
    8281 * 
    8382 * @return high level mouse event 
    8483 */ 
    8584mouse_event_t 
    86 mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click) 
     85mouse_translate_event (Widget * w, Gpm_Event * event) 
    8786{ 
    8887    gboolean in_widget; 
    8988    mouse_msg_t msg = MSG_MOUSE_NONE; 
    mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click) 
    9796     */ 
    9897    in_widget = w->mouse.forced_capture || mouse_global_in_widget (event, w); 
    9998 
    100     *click = FALSE; 
    101  
    10299    if ((event->type & GPM_DOWN) != 0) 
    103100    { 
    104101        if (in_widget) 
    mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click) 
    132129            w->mouse.capture = FALSE; 
    133130            msg = MSG_MOUSE_UP; 
    134131 
    135             if (in_widget) 
    136                 /* If the mouse hasn't been dragged since the MSG_MOUSE_DOWN, we trigger a click. */ 
    137                 *click = (w->mouse.last_msg == MSG_MOUSE_DOWN); 
    138  
    139132            /* 
    140133             * When using xterm, event->buttons reports the buttons' state 
    141134             * after the event occurred (meaning that event->buttons is zero, 
    mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click) 
    159152            msg = MSG_MOUSE_MOVE; 
    160153    } 
    161154 
    162     if (msg != MSG_MOUSE_NONE) 
    163         /* Record the current event type for the benefit of the next event. */ 
    164         w->mouse.last_msg = msg; 
    165  
    166155    init_mouse_event (&local, msg, event, w); 
    167156 
    168157    return local; 
    mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click) 
    173162/** 
    174163 * Call widget mouse handler to process high-level mouse event. 
    175164 * 
     165 * Besides sending to the widget the event itself, this function may also 
     166 * send one or more pseudo events. Currently, MSG_MOUSE_CLICK is the only 
     167 * pseudo event in existence but in the future (e.g., with the introduction 
     168 * of a drag-drop API) there may be more. 
     169 * 
    176170 * @param w Widget object 
    177  * @param high level mouse event 
    178  * @param click whether mouse click was raised or not 
     171 * @param event high level mouse event 
    179172 * 
    180173 * @return result of mouse event handling 
    181174 */ 
    182175int 
    183 mouse_process_event (Widget * w, mouse_event_t * event, gboolean click) 
     176mouse_process_event (Widget * w, mouse_event_t * event) 
    184177{ 
    185178    int ret = MOU_UNHANDLED; 
    186179 
    187180    if (event->msg != MSG_MOUSE_NONE) 
    188181    { 
    189182        w->mouse_callback (w, event->msg, event); 
    190         if (click) 
     183 
     184        /* Upon releasing the mouse button: if the mouse hasn't been dragged 
     185         * since the MSG_MOUSE_DOWN, we also trigger a click. */ 
     186        if (event->msg == MSG_MOUSE_UP && w->mouse.last_msg == MSG_MOUSE_DOWN) 
    191187            w->mouse_callback (w, MSG_MOUSE_CLICK, event); 
    192188 
     189        /* Record the current event type for the benefit of the next event. */ 
     190        w->mouse.last_msg = event->msg; 
     191 
    193192        if (!event->result.abort) 
    194193            ret = event->result.repeat ? MOU_REPEAT : MOU_NORMAL; 
    195194    } 
  • lib/widget/mouse.h

    diff --git a/lib/widget/mouse.h b/lib/widget/mouse.h
    index 8cdd0e9..b0c8c1f 100644
    a b typedef struct 
    5858/*** declarations of public functions ************************************************************/ 
    5959 
    6060/* Translate GPM event to high-level event */ 
    61 mouse_event_t mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click); 
     61mouse_event_t mouse_translate_event (Widget * w, Gpm_Event * event); 
    6262/* Process high-level mouse event */ 
    63 int mouse_process_event (Widget * w, mouse_event_t * event, gboolean click); 
     63int mouse_process_event (Widget * w, mouse_event_t * event); 
    6464 
    6565/*** inline functions ****************************************************************************/ 
    6666 
  • src/editor/editwidget.c

    diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c
    index 21d209e..277af8e 100644
    a b edit_mouse_move_resize (WEdit * edit, mouse_event_t event) 
    766766    while (edit->drag_state != MCEDIT_DRAG_NORMAL) 
    767767    { 
    768768        int c; 
    769         gboolean click = FALSE; /* unused */ 
    770769 
    771770        if (event.msg == MSG_MOUSE_UP) 
    772771            goto finish; 
    edit_mouse_move_resize (WEdit * edit, mouse_event_t event) 
    812811         * outside of widget */ 
    813812        c = tty_get_event (&gevent, FALSE, TRUE); 
    814813        if (c == EV_MOUSE) 
    815             event = mouse_translate_event (w, &gevent, &click); 
     814            event = mouse_translate_event (w, &gevent); 
    816815        else 
    817816        { 
    818817          finish: