From db3c03943fc5d65d844efdd58e23c369c7b4fd68 Mon Sep 17 00:00:00 2001 From: xianjimli Date: Thu, 5 Jul 2018 16:15:58 +0800 Subject: [PATCH] fix event dispatch --- src/base/widget.c | 6 ++++-- src/base/window_manager.c | 16 +++++++++++++--- src/base/window_manager.h | 1 + 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/base/widget.c b/src/base/widget.c index e6a8f02ac..35c9251cf 100644 --- a/src/base/widget.c +++ b/src/base/widget.c @@ -943,6 +943,7 @@ ret_t widget_on_pointer_move(widget_t* widget, pointer_event_t* e) { ret_t widget_on_pointer_up(widget_t* widget, pointer_event_t* e) { ret_t ret = RET_OK; + widget_t* target = NULL; return_value_if_fail(widget != NULL && e != NULL, RET_BAD_PARAMS); return_value_if_fail(widget->vt != NULL, RET_BAD_PARAMS); @@ -951,8 +952,9 @@ ret_t widget_on_pointer_up(widget_t* widget, pointer_event_t* e) { ret = widget->vt->on_pointer_up(widget, e); } - if (widget->target != NULL) { - widget_on_pointer_up(widget->target, e); + target = widget_find_target(widget, e->x, e->y); + if (target != NULL) { + widget_on_pointer_up(target, e); } return ret; diff --git a/src/base/window_manager.c b/src/base/window_manager.c index 0cde6ae51..ef92e1155 100644 --- a/src/base/window_manager.c +++ b/src/base/window_manager.c @@ -199,7 +199,9 @@ widget_t* window_manager_find_target(widget_t* widget, xy_t x, xy_t y) { return_value_if_fail(widget != NULL, NULL); if (wm->grab_widgets.size > 0) { - return WIDGET(wm->grab_widgets.elms[wm->grab_widgets.size - 1]); + widget_t* target = WIDGET(wm->grab_widgets.elms[wm->grab_widgets.size - 1]); + /*log_debug("target=%s\n", target->vt->type_name);*/ + return target; } widget_to_local(widget, &p); @@ -361,6 +363,7 @@ static ret_t window_manager_grab(widget_t* widget, widget_t* child) { window_manager_t* wm = WINDOW_MANAGER(widget); return_value_if_fail(widget != NULL && child != NULL, RET_BAD_PARAMS); + log_debug("grab: %s\n", child->vt->type_name); return array_push(&(wm->grab_widgets), child); } @@ -368,6 +371,7 @@ static ret_t window_manager_ungrab(widget_t* widget, widget_t* child) { window_manager_t* wm = WINDOW_MANAGER(widget); return_value_if_fail(widget != NULL && child != NULL, RET_BAD_PARAMS); + log_debug("ungrab: %s\n", child->vt->type_name); return array_remove(&(wm->grab_widgets), NULL, child, NULL); } @@ -584,8 +588,12 @@ ret_t window_manager_dispatch_input_event(widget_t* widget, event_t* e) { return_value_if_fail(wm != NULL && e != NULL, RET_BAD_PARAMS); if (wm->ignore_user_input) { - log_debug("animating ignore input\n"); - return RET_OK; + if (wm->pressed && e->type == EVT_POINTER_UP) { + log_debug("animating ignore input, but it is last pointer_up\n"); + } else { + log_debug("animating ignore input\n"); + return RET_OK; + } } switch (e->type) { @@ -596,6 +604,7 @@ ret_t window_manager_dispatch_input_event(widget_t* widget, event_t* e) { evt->alt = wm->alt; evt->ctrl = wm->ctrl; evt->shift = wm->shift; + wm->pressed = TRUE; widget_on_pointer_down(widget, evt); break; } @@ -617,6 +626,7 @@ ret_t window_manager_dispatch_input_event(widget_t* widget, event_t* e) { evt->ctrl = wm->ctrl; evt->shift = wm->shift; widget_on_pointer_up(widget, evt); + wm->pressed = FALSE; break; } case EVT_KEY_DOWN: { diff --git a/src/base/window_manager.h b/src/base/window_manager.h index 1de5e5d8a..f0a0355ee 100644 --- a/src/base/window_manager.h +++ b/src/base/window_manager.h @@ -56,6 +56,7 @@ typedef struct _window_manager_t { uint32_t fps_time; uint32_t fps_count; bool_t show_fps; + bool_t pressed; } window_manager_t; widget_t* window_manager(void);