mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps] Add Shift + Ans shortcut to go to the last application (#196)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user