CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
cdc::ui::ViewStack Class Reference

#include <ViewStack.h>

Public Types

using InactivityCallback = void(*)()

Public Member Functions

void push (IView *view, void *context=nullptr)
void pop ()
void replace (IView *view, void *context=nullptr)
void popToRoot ()
void popToAnchor (IView *anchor)
 Pops views until the specified anchor view is the current view.
void popToDepth (uint8_t targetDepth)
 Pops views until the stack depth is at most targetDepth.
IViewcurrent () const
IViewat (uint8_t depth) const
uint8_t depth () const
bool isEmpty () const
void dispatchKey (char key)
void dispatchLongPress (char key)
void dispatchTick (uint32_t nowMs)
void render (bool synchronous=false)
 Render current view (and modal if present) and flush to display.
bool needsRender () const
void showModal (IView *modal)
void hideModal ()
void removeModal (IView *modal)
 Remove a specific modal from any position in the modal stack.
bool hasModal () const
IViewgetModal () const
void forceFullRefresh ()
bool acquireExclusive (const void *owner)
 Acquires exclusive ownership of the view stack.
bool releaseExclusive (const void *owner)
 Releases exclusive ownership.
const void * exclusiveOwner () const
 Returns current exclusive owner, or nullptr if none.
void setInactivityTimeout (InactivityCallback callback, uint32_t timeoutMs)
void resetInactivityTimer ()
void checkInactivity (uint32_t nowMs)

Static Public Member Functions

static ViewStack & instance ()
 Returns singleton view-stack instance.

Static Public Attributes

static constexpr uint8_t MAX_DEPTH = 20

Detailed Description

ViewStack - Navigation stack for views

Manages a stack of views for hierarchical navigation. Supports push/pop/replace operations and modal overlays.

Reference: ~/GIT/cdc-badge-os-legacy/main/app_input.cpp (state machine)

Definition at line 18 of file ViewStack.h.

Member Typedef Documentation

◆ InactivityCallback

Callback type for inactivity timeout

Definition at line 196 of file ViewStack.h.

Member Function Documentation

◆ acquireExclusive()

bool cdc::ui::ViewStack::acquireExclusive ( const void * owner)

Acquires exclusive ownership of the view stack.

Parameters
ownerCaller-supplied identity token (use the view pointer or a static address).
Returns
true if lock acquired, false if already held by someone else.

While exclusive ownership is held, push/pop/replace/showModal from anyone other than the owner are rejected with a warning log.

Definition at line 480 of file ViewStack.cpp.

References LOG_D, LOG_W, and cdc::ui::TAG.

Referenced by cdc::plugin_manager::PluginUiState::acquireExclusive().

◆ at()

IView * cdc::ui::ViewStack::at ( uint8_t depth) const

Get view at specific depth (0 = root)

Definition at line 246 of file ViewStack.cpp.

◆ checkInactivity()

void cdc::ui::ViewStack::checkInactivity ( uint32_t nowMs)

Check and handle inactivity (call in tick/loop)

Parameters
nowMsCurrent time in milliseconds

Definition at line 451 of file ViewStack.cpp.

References LOG_I, and cdc::ui::TAG.

Referenced by cdc::ui::ui_process().

◆ current()

IView * cdc::ui::ViewStack::current ( ) const

◆ depth()

uint8_t cdc::ui::ViewStack::depth ( ) const
inline

Get current stack depth

Definition at line 83 of file ViewStack.h.

Referenced by cdc::ui::isBadgeLocked(), and cdc::plugin_manager::PluginManager::startPlugin().

◆ dispatchKey()

void cdc::ui::ViewStack::dispatchKey ( char key)

Dispatch key press to current view

Parameters
keyKey character

Definition at line 252 of file ViewStack.cpp.

References cdc::core::EventBus::instance(), cdc::core::KEY_PRESSED, cdc::ui::IView::onKey(), cdc::core::EventBus::publish(), cdc::ui::REQUEST_POP, and resetInactivityTimer().

Referenced by cdc::ui::ui_process().

◆ dispatchLongPress()

void cdc::ui::ViewStack::dispatchLongPress ( char key)

Dispatch long press to current view

Parameters
keyKey character

Definition at line 277 of file ViewStack.cpp.

References cdc::ui::CONSUMED, cdc::core::EventBus::instance(), cdc::core::KEY_LONG_PRESS, cdc::ui::IView::onLongPress(), cdc::core::EventBus::publish(), and cdc::ui::REQUEST_POP.

Referenced by cdc::ui::ui_init().

◆ dispatchTick()

void cdc::ui::ViewStack::dispatchTick ( uint32_t nowMs)

Dispatch tick to current view and modal

Parameters
nowMsCurrent time

Definition at line 307 of file ViewStack.cpp.

References cdc::ui::IView::onTick().

Referenced by cdc::ui::ui_process().

◆ exclusiveOwner()

const void * cdc::ui::ViewStack::exclusiveOwner ( ) const
inline

Returns current exclusive owner, or nullptr if none.

Definition at line 189 of file ViewStack.h.

◆ forceFullRefresh()

void cdc::ui::ViewStack::forceFullRefresh ( )
inline

Force next render to use FULL refresh (called automatically after view changes)

Definition at line 165 of file ViewStack.h.

◆ getModal()

IView * cdc::ui::ViewStack::getModal ( ) const
inline

Get the top (input-receiving) modal view, or nullptr if none.

Definition at line 159 of file ViewStack.h.

◆ hasModal()

bool cdc::ui::ViewStack::hasModal ( ) const
inline

Check if any modal is active

Definition at line 154 of file ViewStack.h.

◆ hideModal()

◆ instance()

ViewStack & cdc::ui::ViewStack::instance ( )
static

Returns singleton view-stack instance.

Get singleton instance

Definition at line 34 of file ViewStack.cpp.

References instance().

Referenced by cdc::plugin_manager::PluginUiState::acquireExclusive(), cdc::ui::SleepManager::checkLockScreenSleep(), cdc::serial::cmdPaste(), cdc::ui::WifiHandlers::connect(), cdc::mod_fido2::fido2_ui_user_presence_callback(), cdc::ui::hideContextMenu(), cdc::ui::hideMessage(), host_lockscreen_alert(), host_ui_pop(), host_ui_pop_to_plugin(), host_ui_push_info(), host_ui_push_toast(), cdc::plugin_manager::PluginUiState::insertListItem(), instance(), cdc::ui::isBadgeLocked(), cdc::ui::msgTransferUiProcess(), cdc::ui::onBlePairingRequestEvent(), cdc::ui::onBluetoothMenuSelect(), cdc::mod_nvsedit::onDeleteKey(), cdc::ui::onExpertMenuSelect(), cdc::mod_gpg::onGpgPinComplete(), cdc::ui::onInactivityTimeout(), cdc::ui::ColorPickerView::onKey(), cdc::ui::ConfirmView::onKey(), cdc::ui::DateInputView::onKey(), cdc::ui::SliderView::onKey(), cdc::ui::T9InputView::onKey(), cdc::ui::TimeInputView::onKey(), cdc::ui::ToastView::onKey(), cdc::ui::onLanguageSelect(), cdc::mod_2fa::onListSelect(), cdc::ui::T9InputView::onLongPress(), cdc::ui::onMainMenuSelect(), cdc::mod_password::onMenuDeleteConfirm(), cdc::mod_fido2::onPinCancel(), cdc::ui::settings::onPinChangeComplete(), cdc::mod_fido2::onPinFailure(), cdc::mod_fido2::onPinSuccess(), cdc::ui::onPinSuccess(), cdc::mod_fido2::onPromptApprove(), cdc::mod_gpg::onReceivedActionSelect(), cdc::mod_gpg::onReceivedDeleteConfirm(), cdc::mod_vcard::onReceivedDeleteConfirm(), cdc::mod_gpg::onSettingsSelect(), cdc::ui::onSettingsSelect(), cdc::ui::BlePairingView::onTick(), cdc::ui::ToastView::onTick(), cdc::ui::onToolsSelect(), cdc::ui::onUnlockRequested(), cdc::ui::onWifiMainSelect(), cdc::mod_2fa::onWizardAlgo(), cdc::mod_gpg::onWizardCurve(), cdc::mod_gpg::onWizardEmail(), cdc::mod_2fa::onWizardIssuer(), cdc::mod_gpg::onWizardName(), cdc::mod_password::onWizardUsername(), cdc::mod_vcard::openReceivedList(), cdc::ui::performAntiBlockLock(), cdc::ui::prepareForBootloaderReset(), cdc::mod_fido2::promptComplete(), cdc::mod_2fa::pushAlgoStep(), cdc::plugin_manager::PluginUiState::pushCanvas(), cdc::plugin_manager::PluginUiState::pushColorPicker(), cdc::plugin_manager::PluginUiState::pushConfirm(), cdc::plugin_manager::PluginUiState::pushContextMenu(), cdc::mod_vcard::pushCurrentStep(), cdc::plugin_manager::PluginUiState::pushDate(), cdc::plugin_manager::PluginUiState::pushList(), cdc::plugin_manager::PluginUiState::pushPin(), cdc::plugin_manager::PluginUiState::pushSlider(), cdc::plugin_manager::PluginUiState::pushT9(), cdc::mod_2fa::pushT9WizardStep(), cdc::mod_password::pushT9WizardStep(), cdc::plugin_manager::PluginUiState::pushTime(), cdc::mod_2fa::pushTouchStep(), cdc::mod_2fa::pushUsbCrStep(), cdc::plugin_manager::PluginUiState::releaseExclusive(), cdc::plugin_manager::PluginUiState::removeListItem(), cdc::plugin_manager::PluginUiState::resetForPluginStop(), cdc::mod_fido2::restoreView(), cdc::ui::runTropicCacheCleanup(), cdc::ui::runTropicCacheRebuild(), cdc::plugin_manager::PluginUiState::setInactivity(), cdc::plugin_manager::PluginUiState::setViewFooter(), cdc::plugin_manager::PluginUiState::setViewLifecycle(), cdc::ui::showBackupMenu(), cdc::ui::showBeaconMenu(), cdc::ui::showBluetoothMenu(), cdc::ui::showConfirm(), cdc::ui::showContextMenu(), cdc::mod_fido2::showDetail(), cdc::mod_password::showDetails(), cdc::ui::showDuressPinSetup(), cdc::ui::showExpertMenu(), cdc::mod_gpg::showExport(), cdc::ui::showInfo(), cdc::mod_nvsedit::showKeyListView(), cdc::ui::showListView(), cdc::ui::showMessage(), cdc::ui::showModulesView(), cdc::mod_nvsedit::showNamespaceListView(), cdc::ui::showPairedDevices(), cdc::ui::showPinEntry(), cdc::ui::showQRCode(), cdc::mod_gpg::showReceivedDetail(), cdc::mod_gpg::showReceivedKeys(), cdc::mod_gpg::showSettings(), cdc::ui::showSlider(), cdc::mod_gpg::showStatus(), cdc::ui::showT9Input(), cdc::ui::showToastInternal(), cdc::mod_nvsedit::showValueView(), cdc::mod_vcard::showVcardDetails(), cdc::ui::showWifiMainMenu(), cdc::ui::startBluetoothScan(), cdc::plugin_manager::PluginManager::startPlugin(), cdc::plugin_manager::PluginManager::stopActivePlugin(), cdc::ui::ui_init(), cdc::ui::ui_process(), cdc::plugin_manager::PluginManager::unloadAllFromRam(), cdc::plugin_manager::PluginManager::unloadFromRam(), cdc::plugin_manager::PluginUiState::updateListItem(), cdc::ui::updateLockScreenClock(), cdc::ui::wifiConnect(), cdc::ui::wifiFinishSetup(), cdc::ui::wifiNtpSync(), cdc::ui::wifiShowAuthMenu(), cdc::ui::wifiShowIpModeMenu(), cdc::ui::wifiStartScan(), cdc::mod_2fa::wizardFinish(), cdc::mod_password::wizardFinish(), cdc::mod_vcard::wizardFinish(), cdc::mod_2fa::wizardStart(), and cdc::mod_gpg::wizardStart().

◆ isEmpty()

bool cdc::ui::ViewStack::isEmpty ( ) const
inline

Check if stack is empty

Definition at line 88 of file ViewStack.h.

◆ needsRender()

bool cdc::ui::ViewStack::needsRender ( ) const

Check if any view needs rendering

Definition at line 377 of file ViewStack.cpp.

References cdc::ui::IView::needsRender(), and needsRender().

Referenced by needsRender(), and render().

◆ pop()

◆ popToAnchor()

void cdc::ui::ViewStack::popToAnchor ( IView * anchor)

Pops views until the specified anchor view is the current view.

Parameters
anchorAnchor view to return to.

Stops popping if the anchor is reached or only the root view remains. Useful for returning to a list view after wizard completion.

Definition at line 224 of file ViewStack.cpp.

Referenced by cdc::mod_password::onMenuDeleteConfirm(), cdc::mod_vcard::onReceivedDeleteConfirm(), cdc::mod_2fa::wizardFinish(), cdc::mod_password::wizardFinish(), and cdc::mod_vcard::wizardFinish().

◆ popToDepth()

void cdc::ui::ViewStack::popToDepth ( uint8_t targetDepth)

Pops views until the stack depth is at most targetDepth.

Parameters
targetDepthDepth to collapse down to; never pops below the root.

Used by host_ui_pop_to_plugin to return to a plugin's first view in one step, since plugin root views have no stable pointer for popToAnchor.

Definition at line 233 of file ViewStack.cpp.

Referenced by host_ui_pop_to_plugin().

◆ popToRoot()

void cdc::ui::ViewStack::popToRoot ( )

Pop all views except root

Definition at line 217 of file ViewStack.cpp.

◆ push()

void cdc::ui::ViewStack::push ( IView * view,
void * context = nullptr )

Push a view onto the stack

Parameters
viewView to push
contextOptional context to pass to onEnter

Definition at line 177 of file ViewStack.cpp.

Referenced by host_ui_push_info(), cdc::ui::onBluetoothMenuSelect(), cdc::ui::onExpertMenuSelect(), cdc::mod_2fa::onListSelect(), cdc::ui::onMainMenuSelect(), cdc::mod_gpg::onReceivedActionSelect(), cdc::mod_gpg::onSettingsSelect(), cdc::ui::onSettingsSelect(), cdc::ui::onToolsSelect(), cdc::ui::onUnlockRequested(), cdc::ui::onWifiMainSelect(), cdc::mod_2fa::onWizardAlgo(), cdc::mod_gpg::onWizardEmail(), cdc::mod_2fa::onWizardIssuer(), cdc::mod_gpg::onWizardName(), cdc::mod_password::onWizardUsername(), cdc::mod_vcard::openReceivedList(), cdc::mod_2fa::pushAlgoStep(), cdc::plugin_manager::PluginUiState::pushCanvas(), cdc::plugin_manager::PluginUiState::pushColorPicker(), cdc::mod_vcard::pushCurrentStep(), cdc::plugin_manager::PluginUiState::pushDate(), cdc::plugin_manager::PluginUiState::pushPin(), cdc::plugin_manager::PluginUiState::pushSlider(), cdc::plugin_manager::PluginUiState::pushT9(), cdc::mod_2fa::pushT9WizardStep(), cdc::mod_password::pushT9WizardStep(), cdc::plugin_manager::PluginUiState::pushTime(), cdc::mod_2fa::pushTouchStep(), cdc::mod_2fa::pushUsbCrStep(), cdc::ui::showBackupMenu(), cdc::ui::showBeaconMenu(), cdc::ui::showBluetoothMenu(), cdc::mod_fido2::showDetail(), cdc::mod_password::showDetails(), cdc::ui::showDuressPinSetup(), cdc::ui::showExpertMenu(), cdc::mod_gpg::showExport(), cdc::ui::showInfo(), cdc::mod_nvsedit::showKeyListView(), cdc::ui::showListView(), cdc::ui::showModulesView(), cdc::mod_nvsedit::showNamespaceListView(), cdc::ui::showPairedDevices(), cdc::ui::showPinEntry(), cdc::ui::showQRCode(), cdc::mod_gpg::showReceivedDetail(), cdc::mod_gpg::showReceivedKeys(), cdc::mod_gpg::showSettings(), cdc::ui::showSlider(), cdc::mod_gpg::showStatus(), cdc::ui::showT9Input(), cdc::mod_nvsedit::showValueView(), cdc::mod_vcard::showVcardDetails(), cdc::ui::showWifiMainMenu(), cdc::ui::startBluetoothScan(), cdc::ui::ui_init(), cdc::ui::wifiShowAuthMenu(), cdc::ui::wifiShowIpModeMenu(), cdc::ui::wifiStartScan(), cdc::mod_2fa::wizardStart(), and cdc::mod_gpg::wizardStart().

◆ releaseExclusive()

bool cdc::ui::ViewStack::releaseExclusive ( const void * owner)

Releases exclusive ownership.

Parameters
ownerMust match the token used in acquireExclusive.
Returns
true if released, false if owner mismatch or not held.

Definition at line 495 of file ViewStack.cpp.

References LOG_D, LOG_W, and cdc::ui::TAG.

Referenced by cdc::plugin_manager::PluginUiState::releaseExclusive().

◆ removeModal()

void cdc::ui::ViewStack::removeModal ( IView * modal)

Remove a specific modal from any position in the modal stack.

Unlike hideModal() this does not require the modal to be on top; modals stacked above it stay in place. Used to retract an overlay whose backing view object is about to be destroyed (e.g. plugin teardown), so the stack keeps no dangling pointer. No-op if the modal is not currently shown.

Parameters
modalThe modal view to remove.

Definition at line 433 of file ViewStack.cpp.

◆ render()

void cdc::ui::ViewStack::render ( bool synchronous = false)

Render current view (and modal if present) and flush to display.

Parameters
synchronousWhen true, flush via the blocking display path (flushSync) so the panel update has fully completed on return. When false (default), flush asynchronously via the render task.

Definition at line 318 of file ViewStack.cpp.

References cdc::ui::IView::clearDirty(), cdc::ui::display, cdc::hal::FULL, cdc::hal::getDisplayInstance(), cdc::ui::IView::needsRender(), needsRender(), cdc::hal::PARTIAL, cdc::hal::PARTIAL_LIGHT, cdc::ui::IView::prefersLightRefresh(), and cdc::ui::IView::render().

Referenced by cdc::ui::WifiHandlers::connect(), host_ui_push_toast(), cdc::ui::showConfirm(), cdc::ui::showToastInternal(), cdc::plugin_manager::PluginManager::startPlugin(), and cdc::ui::ui_process().

◆ replace()

void cdc::ui::ViewStack::replace ( IView * view,
void * context = nullptr )

Replace top view with another

Parameters
viewNew view
contextOptional context

Definition at line 187 of file ViewStack.cpp.

References cdc::ui::IView::getName(), cdc::ui::isListView(), LOG_D, LOG_W, cdc::ui::IView::onEnter(), cdc::ui::IView::onExit(), and cdc::ui::TAG.

Referenced by cdc::ui::onPinSuccess().

◆ resetInactivityTimer()

void cdc::ui::ViewStack::resetInactivityTimer ( )

Reset inactivity timer (called automatically on key press)

Definition at line 446 of file ViewStack.cpp.

Referenced by dispatchKey(), cdc::ui::onInactivityTimeout(), and cdc::ui::BlePairingView::onTick().

◆ setInactivityTimeout()

void cdc::ui::ViewStack::setInactivityTimeout ( InactivityCallback callback,
uint32_t timeoutMs )

Set inactivity timeout callback

Parameters
callbackFunction to call when timeout expires
timeoutMsTimeout in milliseconds (0 to disable)

Definition at line 438 of file ViewStack.cpp.

References LOG_D, and cdc::ui::TAG.

Referenced by cdc::plugin_manager::PluginUiState::setInactivity(), and cdc::ui::ui_init().

◆ showModal()

void cdc::ui::ViewStack::showModal ( IView * modal)

Show a modal overlay (e.g., toast, context menu). Modals stack: the new one is pushed on top of any already-shown modal and receives input exclusively. If the same modal is already stacked it is lifted to the top.

Parameters
modalModal view

Definition at line 386 of file ViewStack.cpp.

References cdc::ui::IView::getName(), LOG_D, LOG_W, cdc::ui::IView::onEnter(), cdc::ui::IView::onPause(), and cdc::ui::TAG.

Referenced by host_ui_push_toast(), cdc::ui::onBlePairingRequestEvent(), cdc::plugin_manager::PluginUiState::pushConfirm(), cdc::plugin_manager::PluginUiState::pushContextMenu(), cdc::ui::showConfirm(), cdc::ui::showContextMenu(), cdc::ui::showMessage(), cdc::ui::showToastInternal(), and cdc::plugin_manager::PluginManager::startPlugin().

Member Data Documentation

◆ MAX_DEPTH

uint8_t cdc::ui::ViewStack::MAX_DEPTH = 20
staticconstexpr

Definition at line 20 of file ViewStack.h.


The documentation for this class was generated from the following files: