From 3cdb59805ec68ac62176660e2d43622d1364a6d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=82=E3=81=8F?= Date: Sun, 30 Jan 2022 19:45:08 +0300 Subject: [PATCH] Desktop: fix crash caused by unconsumed back button short press (#974) --- applications/desktop/views/desktop_main.c | 33 ++++++++++++----------- applications/gui/view_stack.c | 9 ++++--- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/applications/desktop/views/desktop_main.c b/applications/desktop/views/desktop_main.c index b03381b9..83d561df 100644 --- a/applications/desktop/views/desktop_main.c +++ b/applications/desktop/views/desktop_main.c @@ -35,25 +35,26 @@ bool desktop_main_input(InputEvent* event, void* context) { furi_assert(context); DesktopMainView* main_view = context; - bool consumed = false; - if(event->key == InputKeyOk && event->type == InputTypeShort) { - main_view->callback(DesktopMainEventOpenMenu, main_view->context); - } else if(event->key == InputKeyDown && event->type == InputTypeLong) { - main_view->callback(DesktopMainEventOpenDebug, main_view->context); - } else if(event->key == InputKeyUp && event->type == InputTypeShort) { - main_view->callback(DesktopMainEventOpenLockMenu, main_view->context); - } else if(event->key == InputKeyDown && event->type == InputTypeShort) { - main_view->callback(DesktopMainEventOpenArchive, main_view->context); - } else if(event->key == InputKeyLeft && event->type == InputTypeShort) { - main_view->callback(DesktopMainEventOpenFavorite, main_view->context); - } else if(event->key == InputKeyRight && event->type == InputTypeShort) { - main_view->callback(DesktopMainEventRightShort, main_view->context); - } else if(event->key == InputKeyBack && event->type == InputTypeShort) { - consumed = true; + if(event->type == InputTypeShort) { + if(event->key == InputKeyOk) { + main_view->callback(DesktopMainEventOpenMenu, main_view->context); + } else if(event->key == InputKeyUp) { + main_view->callback(DesktopMainEventOpenLockMenu, main_view->context); + } else if(event->key == InputKeyDown) { + main_view->callback(DesktopMainEventOpenArchive, main_view->context); + } else if(event->key == InputKeyLeft) { + main_view->callback(DesktopMainEventOpenFavorite, main_view->context); + } else if(event->key == InputKeyRight) { + main_view->callback(DesktopMainEventRightShort, main_view->context); + } + } else if(event->type == InputTypeLong) { + if(event->key == InputKeyDown) { + main_view->callback(DesktopMainEventOpenDebug, main_view->context); + } } - return consumed; + return true; } DesktopMainView* desktop_main_alloc() { diff --git a/applications/gui/view_stack.c b/applications/gui/view_stack.c index 39ffc8c7..d790b801 100644 --- a/applications/gui/view_stack.c +++ b/applications/gui/view_stack.c @@ -105,13 +105,14 @@ static bool view_stack_input(InputEvent* event, void* context) { furi_assert(event); furi_assert(context); - bool consumed = false; ViewStack* view_stack = context; + bool consumed = false; ViewStackModel* model = view_get_model(view_stack->view); - for(int i = MAX_VIEWS - 1; !consumed && (i >= 0); --i) { - if(model->views[i]) { - consumed = view_input(model->views[i], event); + for(int i = MAX_VIEWS - 1; i >= 0; i--) { + if(model->views[i] && view_input(model->views[i], event)) { + consumed = true; + break; } } view_commit_model(view_stack->view, false);