From ee26f1df29d47eb04680aef6ddd66747b2809673 Mon Sep 17 00:00:00 2001 From: VIFEXT Date: Wed, 20 Mar 2024 10:11:59 +0800 Subject: [PATCH] fix(obj_tree): fix unintended click triggers on object deletion (#5907) Signed-off-by: pengyiqiang Co-authored-by: pengyiqiang --- src/core/lv_obj_tree.c | 13 +++++++++++-- tests/src/test_cases/test_observer.c | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/core/lv_obj_tree.c b/src/core/lv_obj_tree.c index 13a765a24..5b8fd420b 100644 --- a/src/core/lv_obj_tree.c +++ b/src/core/lv_obj_tree.c @@ -484,6 +484,15 @@ static void lv_obj_delete_async_cb(void * obj) lv_obj_delete(obj); } +static void obj_indev_reset(lv_indev_t * indev, lv_obj_t * obj) +{ + /*Wait for release to avoid accidentally triggering other obj to be clicked*/ + lv_indev_wait_release(indev); + + /*Reset the input device*/ + lv_indev_reset(indev, obj); +} + static void obj_delete_core(lv_obj_t * obj) { if(obj->is_deleting) @@ -516,7 +525,7 @@ static void obj_delete_core(lv_obj_t * obj) lv_indev_type_t indev_type = lv_indev_get_type(indev); if(indev_type == LV_INDEV_TYPE_POINTER || indev_type == LV_INDEV_TYPE_BUTTON) { if(indev->pointer.act_obj == obj || indev->pointer.last_obj == obj || indev->pointer.scroll_obj == obj) { - lv_indev_reset(indev, obj); + obj_indev_reset(indev, obj); } if(indev->pointer.last_pressed == obj) { indev->pointer.last_pressed = NULL; @@ -524,7 +533,7 @@ static void obj_delete_core(lv_obj_t * obj) } if(indev->group == group && obj == lv_indev_get_active_obj()) { - lv_indev_reset(indev, obj); + obj_indev_reset(indev, obj); } indev = lv_indev_get_next(indev); } diff --git a/tests/src/test_cases/test_observer.c b/tests/src/test_cases/test_observer.c index 61e5e0ab5..25341ba0c 100644 --- a/tests/src/test_cases/test_observer.c +++ b/tests/src/test_cases/test_observer.c @@ -422,6 +422,8 @@ void test_observer_arc_value(void) lv_obj_update_layout(obj); lv_test_mouse_release(); + lv_test_indev_wait(100); + lv_test_mouse_move_to(65, 10); lv_test_mouse_press(); lv_test_indev_wait(100); @@ -446,9 +448,12 @@ void test_observer_slider_value(void) lv_obj_update_layout(obj); lv_test_mouse_release(); + lv_test_indev_wait(100); + lv_test_mouse_move_to(65, 10); lv_test_mouse_press(); lv_test_indev_wait(100); + lv_test_mouse_move_to(75, 10); lv_test_mouse_press(); lv_test_indev_wait(100);