diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index 336b9e989..7e63f7503 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -225,6 +225,7 @@ bool AppsContainer::dispatchEvent(Ion::Events::Event event) { return didProcessEvent || alphaLockWantsRedraw; } +// List of keys that are used to switch between apps, in order of app to go (eg. 0 : First App, 1 : Second App, 2 : Third App, ...) static constexpr Ion::Events::Event switch_events[] = { Ion::Events::ShiftSeven, Ion::Events::ShiftEight, Ion::Events::ShiftNine, Ion::Events::ShiftFour, Ion::Events::ShiftFive, Ion::Events::ShiftSix, @@ -236,14 +237,17 @@ bool AppsContainer::processEvent(Ion::Events::Event event) { // Warning: if the window is dirtied, you need to call window()->redraw() if (event == Ion::Events::USBPlug) { if (Ion::USB::isPlugged()) { + // If the exam mode is enabled, we ask to disable it, else, we enable USB if (GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) { displayExamModePopUp(GlobalPreferences::ExamMode::Off); window()->redraw(); } else { Ion::USB::enable(); } + // Update brightness when USB is plugged Ion::Backlight::setBrightness(GlobalPreferences::sharedGlobalPreferences()->brightnessLevel()); } else { + // If the USB isn't plugged in USBPlug event, we disable USB Ion::USB::disable(); } return true; @@ -274,20 +278,38 @@ bool AppsContainer::processEvent(Ion::Events::Event event) { return true; } + // Add Shift + Ans shortcut to go to the previous app + if (event == Ion::Events::ShiftAns) { + switchTo(appSnapshotAtIndex(m_lastAppIndex)); + return true; + } + + // If the event is the OnOff key, we suspend the calculator. if (event == Ion::Events::OnOff) { suspend(true); return true; } + // If the event is a brightness event, we update the brightness according to the event. if (event == Ion::Events::BrightnessPlus || event == Ion::Events::BrightnessMinus) { int delta = Ion::Backlight::MaxBrightness/GlobalPreferences::NumberOfBrightnessStates; int NumberOfStepsPerShortcut = GlobalPreferences::sharedGlobalPreferences()->brightnessShortcut(); int direction = (event == Ion::Events::BrightnessPlus) ? NumberOfStepsPerShortcut*delta : -delta*NumberOfStepsPerShortcut; GlobalPreferences::sharedGlobalPreferences()->setBrightnessLevel(GlobalPreferences::sharedGlobalPreferences()->brightnessLevel()+direction); } + // Else, the event was not processed. return false; } bool AppsContainer::switchTo(App::Snapshot * snapshot) { + // Get app index of the snapshot + int m_appIndexToSwitch = appIndexFromSnapshot(snapshot); + // If the app is home, skip app index saving + if (m_appIndexToSwitch != 0) { + // Save last app index + m_lastAppIndex = m_currentAppIndex; + // Save current app index + m_currentAppIndex = m_appIndexToSwitch; + } if (s_activeApp && snapshot != s_activeApp->snapshot()) { resetShiftAlphaStatus(); } diff --git a/apps/apps_container.h b/apps/apps_container.h index a8fca78dd..c6c53b0fe 100644 --- a/apps/apps_container.h +++ b/apps/apps_container.h @@ -28,6 +28,7 @@ public: static bool poincareCircuitBreaker(); virtual int numberOfApps() = 0; virtual App::Snapshot * appSnapshotAtIndex(int index) = 0; + virtual int appIndexFromSnapshot(App::Snapshot * snapshot) = 0; App::Snapshot * initialAppSnapshot(); App::Snapshot * hardwareTestAppSnapshot(); App::Snapshot * onBoardingAppSnapshot(); @@ -67,6 +68,8 @@ private: static KDColor k_promptFGColors[]; static KDColor k_promptBGColors[]; static int k_promptNumberOfMessages; + int m_currentAppIndex; // Home isn't included after the second app switching + int m_lastAppIndex; AppsWindow m_window; EmptyBatteryWindow m_emptyBatteryWindow; Shared::GlobalContext m_globalContext; diff --git a/apps/apps_container_storage.cpp b/apps/apps_container_storage.cpp index 2ef60aafa..ad2dec619 100644 --- a/apps/apps_container_storage.cpp +++ b/apps/apps_container_storage.cpp @@ -36,3 +36,20 @@ App::Snapshot * AppsContainerStorage::appSnapshotAtIndex(int index) { assert(index >= 0 && index < k_numberOfCommonApps); return snapshots[index]; } + +// Get the index of the app from its snapshot +int AppsContainerStorage::appIndexFromSnapshot(App::Snapshot * snapshot) { + App::Snapshot * snapshots[] = { + homeAppSnapshot() + APPS_CONTAINER_SNAPSHOT_LIST + }; + assert(sizeof(snapshots)/sizeof(snapshots[0]) == k_numberOfCommonApps); + for (int i = 0; i < k_numberOfCommonApps; i++) { + if (snapshots[i] == snapshot) { + return i; + } + } + // Achievement unlock : how did you get here ? + assert(false); + return NULL; +} diff --git a/apps/apps_container_storage.h b/apps/apps_container_storage.h index 9abd3c27a..c3191a751 100644 --- a/apps/apps_container_storage.h +++ b/apps/apps_container_storage.h @@ -12,6 +12,7 @@ public: AppsContainerStorage(); int numberOfApps() override; App::Snapshot * appSnapshotAtIndex(int index) override; + int appIndexFromSnapshot(App::Snapshot * snapshot) override; void * currentAppBuffer() override { return &m_apps; }; private: union Apps { diff --git a/ion/include/ion/events.h b/ion/include/ion/events.h index 51c8da397..e7ae2feb2 100644 --- a/ion/include/ion/events.h +++ b/ion/include/ion/events.h @@ -185,6 +185,7 @@ constexpr Event ShiftSeven = Event::ShiftKey(Keyboard::Key::Seven); constexpr Event ShiftEight = Event::ShiftKey(Keyboard::Key::Eight); constexpr Event ShiftNine = Event::ShiftKey(Keyboard::Key::Nine); +constexpr Event ShiftAns = Event::ShiftKey(Keyboard::Key::Ans); constexpr Event ShiftEXE = Event::ShiftKey(Keyboard::Key::EXE); // Alpha