diff --git a/escher/include/escher/container.h b/escher/include/escher/container.h index 9d70aa331..93bb3eafa 100644 --- a/escher/include/escher/container.h +++ b/escher/include/escher/container.h @@ -17,6 +17,7 @@ class Container : public RunLoop { public: + static App * activeApp() { return s_activeApp; } static Container * sharedContainer() { assert(s_sharedContainer); return s_sharedContainer; @@ -29,7 +30,6 @@ public: Container& operator=(Container&& other) = delete; virtual void * currentAppBuffer() = 0; virtual void run(); - App * activeApp() { return m_activeApp; } virtual bool dispatchEvent(Ion::Events::Event event) override; virtual bool switchTo(App::Snapshot * snapshot); protected: @@ -43,7 +43,7 @@ private: Timer * timerAtIndex(int i) override; virtual int numberOfContainerTimers(); virtual Timer * containerTimerAtIndex(int i); - App * m_activeApp; + static App * s_activeApp; static Container * s_sharedContainer; }; diff --git a/escher/src/container.cpp b/escher/src/container.cpp index 5bed9f494..45791bfc6 100644 --- a/escher/src/container.cpp +++ b/escher/src/container.cpp @@ -2,39 +2,39 @@ #include Container::Container() : - RunLoop(), - m_activeApp(nullptr) + RunLoop() { } // Initialize private static member +App * Container::s_activeApp = nullptr; Container * Container::s_sharedContainer = nullptr; Container::~Container() { - if (m_activeApp) { - m_activeApp->~App(); + if (s_activeApp) { + s_activeApp->~App(); } } bool Container::switchTo(App::Snapshot * snapshot) { - if (m_activeApp && snapshot == m_activeApp->snapshot()) { + if (s_activeApp && snapshot == s_activeApp->snapshot()) { return true; } - if (m_activeApp && !m_activeApp->prepareForExit()) { + if (s_activeApp && !s_activeApp->prepareForExit()) { /* activeApp()->prepareForExit() returned false, which means that the app * needs another event loop to prepare for being switched off. */ return false; } - if (m_activeApp) { - m_activeApp->willBecomeInactive(); - m_activeApp->snapshot()->pack(m_activeApp); - m_activeApp = nullptr; + if (s_activeApp) { + s_activeApp->willBecomeInactive(); + s_activeApp->snapshot()->pack(s_activeApp); + s_activeApp = nullptr; } if (snapshot) { - m_activeApp = snapshot->unpack(this); + s_activeApp = snapshot->unpack(this); } - if (m_activeApp) { - m_activeApp->didBecomeActive(window()); + if (s_activeApp) { + s_activeApp->didBecomeActive(window()); window()->redraw(); } return true; @@ -45,7 +45,7 @@ bool Container::dispatchEvent(Ion::Events::Event event) { window()->redraw(); return true; } - if (m_activeApp->processEvent(event)) { + if (s_activeApp->processEvent(event)) { window()->redraw(); return true; } @@ -58,14 +58,14 @@ void Container::run() { } int Container::numberOfTimers() { - return m_activeApp->numberOfTimers() + numberOfContainerTimers(); + return s_activeApp->numberOfTimers() + numberOfContainerTimers(); } Timer * Container::timerAtIndex(int i) { - if (i < m_activeApp->numberOfTimers()) { - return m_activeApp->timerAtIndex(i); + if (i < s_activeApp->numberOfTimers()) { + return s_activeApp->timerAtIndex(i); } - return containerTimerAtIndex(i-m_activeApp->numberOfTimers()); + return containerTimerAtIndex(i-s_activeApp->numberOfTimers()); } int Container::numberOfContainerTimers() {