From 438e841226e0b365eb40b1293798f4543a446931 Mon Sep 17 00:00:00 2001 From: Mooffie Date: Wed, 23 Mar 2016 18:17:05 +0200 Subject: [PATCH] Rename mouse.was_drag to mouse.last_msg. Get rid of the 'click' variable. Signed-off-by: Andrew Borodin --- lib/widget/dialog.c | 5 ++--- lib/widget/mouse.c | 30 +++++++++++++++--------------- lib/widget/mouse.h | 4 ++-- lib/widget/widget-common.c | 4 ++-- lib/widget/widget-common.h | 7 +++++-- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index 8fa00fc10..216edf284 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -365,12 +365,11 @@ dlg_handle_key (WDialog * h, int d_key) static int dlg_mouse_translator (Gpm_Event * event, Widget * w) { - gboolean run_click; mouse_event_t me; - me = mouse_translate_event (w, event, &run_click); + me = mouse_translate_event (w, event); - return mouse_process_event (w, &me, run_click); + return mouse_process_event (w, &me); } /* --------------------------------------------------------------------------------------------- */ diff --git a/lib/widget/mouse.c b/lib/widget/mouse.c index 6e63a8767..38347692c 100644 --- a/lib/widget/mouse.c +++ b/lib/widget/mouse.c @@ -78,12 +78,11 @@ init_mouse_event (mouse_event_t * event, mouse_msg_t msg, const Gpm_Event * glob * * @param w Widget object * @param event GPM event - * @param click whether mouse click was raised or not * * @return high level mouse event */ mouse_event_t -mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click) +mouse_translate_event (Widget * w, Gpm_Event * event) { gboolean in_widget; mouse_msg_t msg = MSG_MOUSE_NONE; @@ -97,8 +96,6 @@ mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click) */ in_widget = w->mouse.forced_capture || mouse_global_in_widget (event, w); - *click = FALSE; - if ((event->type & GPM_DOWN) != 0) { if (in_widget) @@ -132,9 +129,6 @@ mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click) w->mouse.capture = FALSE; msg = MSG_MOUSE_UP; - if (in_widget) - *click = !w->mouse.was_drag; - /* * When using xterm, event->buttons reports the buttons' state * after the event occurred (meaning that event->buttons is zero, @@ -158,10 +152,6 @@ mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click) msg = MSG_MOUSE_MOVE; } - if (msg != MSG_MOUSE_NONE) - /* Remember the current state for next event. */ - w->mouse.was_drag = ((event->type & GPM_DRAG) != 0); - init_mouse_event (&local, msg, event, w); return local; @@ -172,23 +162,33 @@ mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click) /** * Call widget mouse handler to process high-level mouse event. * + * Besides sending to the widget the event itself, this function may also + * send one or more pseudo events. Currently, MSG_MOUSE_CLICK is the only + * pseudo event in existence but in the future (e.g., with the introduction + * of a drag-drop API) there may be more. + * * @param w Widget object - * @param high level mouse event - * @param click whether mouse click was raised or not + * @param event high level mouse event * * @return result of mouse event handling */ int -mouse_process_event (Widget * w, mouse_event_t * event, gboolean click) +mouse_process_event (Widget * w, mouse_event_t * event) { int ret = MOU_UNHANDLED; if (event->msg != MSG_MOUSE_NONE) { w->mouse_callback (w, event->msg, event); - if (click) + + /* Upon releasing the mouse button: if the mouse hasn't been dragged + * since the MSG_MOUSE_DOWN, we also trigger a click. */ + if (event->msg == MSG_MOUSE_UP && w->mouse.last_msg == MSG_MOUSE_DOWN) w->mouse_callback (w, MSG_MOUSE_CLICK, event); + /* Record the current event type for the benefit of the next event. */ + w->mouse.last_msg = event->msg; + if (!event->result.abort) ret = event->result.repeat ? MOU_REPEAT : MOU_NORMAL; } diff --git a/lib/widget/mouse.h b/lib/widget/mouse.h index 8cdd0e9fd..b0c8c1f7b 100644 --- a/lib/widget/mouse.h +++ b/lib/widget/mouse.h @@ -58,9 +58,9 @@ typedef struct /*** declarations of public functions ************************************************************/ /* Translate GPM event to high-level event */ -mouse_event_t mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click); +mouse_event_t mouse_translate_event (Widget * w, Gpm_Event * event); /* Process high-level mouse event */ -int mouse_process_event (Widget * w, mouse_event_t * event, gboolean click); +int mouse_process_event (Widget * w, mouse_event_t * event); /*** inline functions ****************************************************************************/ diff --git a/lib/widget/widget-common.c b/lib/widget/widget-common.c index a29181aa5..4bd9af294 100644 --- a/lib/widget/widget-common.c +++ b/lib/widget/widget-common.c @@ -149,10 +149,10 @@ widget_init (Widget * w, int y, int x, int lines, int cols, w->mouse_callback = mouse_callback; w->set_options = widget_default_set_options_callback; w->owner = NULL; - w->mouse.capture = FALSE; w->mouse.forced_capture = FALSE; + w->mouse.capture = FALSE; + w->mouse.last_msg = MSG_MOUSE_NONE; w->mouse.last_buttons_down = 0; - w->mouse.was_drag = FALSE; /* Almost all widgets want to put the cursor in a suitable place */ w->options = W_WANT_CURSOR; diff --git a/lib/widget/widget-common.h b/lib/widget/widget-common.h index be524d1ff..be5f41f01 100644 --- a/lib/widget/widget-common.h +++ b/lib/widget/widget-common.h @@ -112,10 +112,13 @@ struct Widget /* Mouse-related fields. */ struct { + /* Public members: */ + gboolean forced_capture; /* Overrides the 'capture' member. Set explicitly by the programmer. */ + + /* Implementation details: */ gboolean capture; /* Whether the widget "owns" the mouse. */ - gboolean forced_capture; /* Overrides the above. Set explicitly by the programmer. */ + mouse_msg_t last_msg; /* The previous event type processed. */ int last_buttons_down; - gboolean was_drag; } mouse; };