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) |
365 | 365 | static int |
366 | 366 | dlg_mouse_translator (Gpm_Event * event, Widget * w) |
367 | 367 | { |
368 | | gboolean run_click; |
369 | 368 | mouse_event_t me; |
370 | 369 | |
371 | | me = mouse_translate_event (w, event, &run_click); |
| 370 | me = mouse_translate_event (w, event); |
372 | 371 | |
373 | | return mouse_process_event (w, &me, run_click); |
| 372 | return mouse_process_event (w, &me); |
374 | 373 | } |
375 | 374 | |
376 | 375 | /* --------------------------------------------------------------------------------------------- */ |
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 |
78 | 78 | * |
79 | 79 | * @param w Widget object |
80 | 80 | * @param event GPM event |
81 | | * @param click whether mouse click was raised or not |
82 | 81 | * |
83 | 82 | * @return high level mouse event |
84 | 83 | */ |
85 | 84 | mouse_event_t |
86 | | mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click) |
| 85 | mouse_translate_event (Widget * w, Gpm_Event * event) |
87 | 86 | { |
88 | 87 | gboolean in_widget; |
89 | 88 | mouse_msg_t msg = MSG_MOUSE_NONE; |
… |
… |
mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click) |
97 | 96 | */ |
98 | 97 | in_widget = w->mouse.forced_capture || mouse_global_in_widget (event, w); |
99 | 98 | |
100 | | *click = FALSE; |
101 | | |
102 | 99 | if ((event->type & GPM_DOWN) != 0) |
103 | 100 | { |
104 | 101 | if (in_widget) |
… |
… |
mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click) |
132 | 129 | w->mouse.capture = FALSE; |
133 | 130 | msg = MSG_MOUSE_UP; |
134 | 131 | |
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 | | |
139 | 132 | /* |
140 | 133 | * When using xterm, event->buttons reports the buttons' state |
141 | 134 | * after the event occurred (meaning that event->buttons is zero, |
… |
… |
mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click) |
159 | 152 | msg = MSG_MOUSE_MOVE; |
160 | 153 | } |
161 | 154 | |
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 | | |
166 | 155 | init_mouse_event (&local, msg, event, w); |
167 | 156 | |
168 | 157 | return local; |
… |
… |
mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click) |
173 | 162 | /** |
174 | 163 | * Call widget mouse handler to process high-level mouse event. |
175 | 164 | * |
| 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 | * |
176 | 170 | * @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 |
179 | 172 | * |
180 | 173 | * @return result of mouse event handling |
181 | 174 | */ |
182 | 175 | int |
183 | | mouse_process_event (Widget * w, mouse_event_t * event, gboolean click) |
| 176 | mouse_process_event (Widget * w, mouse_event_t * event) |
184 | 177 | { |
185 | 178 | int ret = MOU_UNHANDLED; |
186 | 179 | |
187 | 180 | if (event->msg != MSG_MOUSE_NONE) |
188 | 181 | { |
189 | 182 | 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) |
191 | 187 | w->mouse_callback (w, MSG_MOUSE_CLICK, event); |
192 | 188 | |
| 189 | /* Record the current event type for the benefit of the next event. */ |
| 190 | w->mouse.last_msg = event->msg; |
| 191 | |
193 | 192 | if (!event->result.abort) |
194 | 193 | ret = event->result.repeat ? MOU_REPEAT : MOU_NORMAL; |
195 | 194 | } |
diff --git a/lib/widget/mouse.h b/lib/widget/mouse.h
index 8cdd0e9..b0c8c1f 100644
a
|
b
|
typedef struct |
58 | 58 | /*** declarations of public functions ************************************************************/ |
59 | 59 | |
60 | 60 | /* Translate GPM event to high-level event */ |
61 | | mouse_event_t mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click); |
| 61 | mouse_event_t mouse_translate_event (Widget * w, Gpm_Event * event); |
62 | 62 | /* Process high-level mouse event */ |
63 | | int mouse_process_event (Widget * w, mouse_event_t * event, gboolean click); |
| 63 | int mouse_process_event (Widget * w, mouse_event_t * event); |
64 | 64 | |
65 | 65 | /*** inline functions ****************************************************************************/ |
66 | 66 | |
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) |
766 | 766 | while (edit->drag_state != MCEDIT_DRAG_NORMAL) |
767 | 767 | { |
768 | 768 | int c; |
769 | | gboolean click = FALSE; /* unused */ |
770 | 769 | |
771 | 770 | if (event.msg == MSG_MOUSE_UP) |
772 | 771 | goto finish; |
… |
… |
edit_mouse_move_resize (WEdit * edit, mouse_event_t event) |
812 | 811 | * outside of widget */ |
813 | 812 | c = tty_get_event (&gevent, FALSE, TRUE); |
814 | 813 | if (c == EV_MOUSE) |
815 | | event = mouse_translate_event (w, &gevent, &click); |
| 814 | event = mouse_translate_event (w, &gevent); |
816 | 815 | else |
817 | 816 | { |
818 | 817 | finish: |