Skip to content

Commit 0914848

Browse files
authored
EDG-3585 Small fixup for refresh & cleanup in buildDrawLists (#916)
* EGD-3585 Minor refresh fixup& Normalised buildDrawList everywhere
1 parent a424fbe commit 0914848

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+242
-473
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* `[desktop][messages]` Fixed notifications display and navigation
2222
* `[cellular]` Fixed 32 bit UCS2 codes handling.
2323
* `[call]` Fixed incorrect start of call duration timer
24+
* `[GUI]` minor refresh race fixed
2425

2526
### Other
2627

module-apps/Application.cpp

Lines changed: 38 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ namespace app
7474

7575
longPressTimer = std::make_unique<sys::Timer>("LongPress", this, key_timer_ms);
7676
longPressTimer->connect([&](sys::Timer &) { longPressTimerCallback(); });
77+
78+
connect(typeid(AppRefreshMessage), [this](sys::DataMessage *msg, sys::ResponseMessage *) -> sys::Message_t {
79+
return handleAppRefresh(msg);
80+
});
7781
}
7882

7983
Application::~Application() = default;
@@ -108,43 +112,32 @@ namespace app
108112

109113
void Application::render(gui::RefreshModes mode)
110114
{
111-
if (getCurrentWindow() == nullptr) {
115+
if (windowsStack.isEmpty()) {
112116
LOG_ERROR("Current window is not defined");
113117
return;
114118
}
115119

116-
LOG_DEBUG("Rendering %s", getCurrentWindow()->getName().c_str());
117-
118120
// send drawing commands only when if application is in active and visible.
119121
if (state == State::ACTIVE_FORGROUND) {
120-
auto currwin = getCurrentWindow();
122+
auto window = getCurrentWindow();
121123
if (Store::Battery::get().state == Store::Battery::State::Charging) {
122-
currwin->batteryCharging(true);
124+
window->batteryCharging(true);
123125
}
124126
else {
125-
currwin->updateBatteryLevel(Store::Battery::get().level);
127+
window->updateBatteryLevel(Store::Battery::get().level);
126128
}
127-
currwin->setSIM();
128-
currwin->updateSignalStrength();
129-
currwin->updateNetworkAccessTechnology();
130-
131-
std::list<gui::DrawCommand *> commandsList = currwin->buildDrawList();
129+
window->setSIM();
130+
window->updateSignalStrength();
131+
window->updateNetworkAccessTechnology();
132132

133+
auto message = std::make_shared<sgui::DrawMessage>(window->buildDrawList(), mode);
133134
if (shutdownInProgress) {
134-
auto msg =
135-
std::make_shared<sgui::DrawMessage>(commandsList, mode, sgui::DrawMessage::DrawCommand::SHUTDOWN);
136-
sys::Bus::SendUnicast(msg, "ServiceGUI", this);
135+
message->setCommandType(sgui::DrawMessage::Type::SHUTDOWN);
137136
}
138137
else if (suspendInProgress) {
139-
auto msg =
140-
std::make_shared<sgui::DrawMessage>(commandsList, mode, sgui::DrawMessage::DrawCommand::SUSPEND);
141-
sys::Bus::SendUnicast(msg, "ServiceGUI", this);
142-
}
143-
else {
144-
auto msg =
145-
std::make_shared<sgui::DrawMessage>(commandsList, mode, sgui::DrawMessage::DrawCommand::NORMAL);
146-
sys::Bus::SendUnicast(msg, "ServiceGUI", this);
138+
message->setCommandType(sgui::DrawMessage::Type::SUSPEND);
147139
}
140+
sys::Bus::SendUnicast(message, "ServiceGUI", this);
148141
}
149142

150143
if (suspendInProgress)
@@ -197,8 +190,10 @@ namespace app
197190

198191
void Application::refreshWindow(gui::RefreshModes mode)
199192
{
200-
auto msg = std::make_shared<AppRefreshMessage>(mode);
201-
sys::Bus::SendUnicast(msg, this->GetName(), this);
193+
if (not windowsStack.isEmpty()) {
194+
auto msg = std::make_shared<AppRefreshMessage>(mode, getCurrentWindow()->getName());
195+
sys::Bus::SendUnicast(msg, this->GetName(), this);
196+
}
202197
}
203198

204199
sys::Message_t Application::DataReceivedHandler(sys::DataMessage *msgl)
@@ -239,9 +234,6 @@ namespace app
239234
else if (msgl->messageType == MessageType::AppRebuild) {
240235
return handleAppRebuild(msg);
241236
}
242-
else if (msgl->messageType == MessageType::AppRefresh) {
243-
return handleAppRefresh(msgl);
244-
}
245237
else if (msgl->messageType == MessageType::AppFocusLost) {
246238
return handleAppFocusLost(msgl);
247239
}
@@ -282,7 +274,7 @@ namespace app
282274
else if (msg->getEvent().state == gui::InputEvent::State::keyReleasedShort) {
283275
longPressTimer->stop();
284276
}
285-
if (getCurrentWindow() != nullptr && getCurrentWindow()->onInput(msg->getEvent())) {
277+
if (not windowsStack.isEmpty() && getCurrentWindow()->onInput(msg->getEvent())) {
286278
refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST);
287279
}
288280
return msgHandled();
@@ -397,25 +389,23 @@ namespace app
397389
if (switchData && switchData->ignoreCurrentWindowOnStack) {
398390
popToWindow(getPrevWindow());
399391
}
400-
getCurrentWindow()->onClose();
392+
if (not windowsStack.isEmpty()) {
393+
getCurrentWindow()->onClose();
394+
}
401395
setActiveWindow(msg->getWindowName());
402396
LOG_DEBUG("Current window: %s vs %s", getCurrentWindow()->getName().c_str(), msg->getWindowName().c_str());
403397
getCurrentWindow()->handleSwitchData(switchData.get());
404398

405-
// check if this is case where application is returning to the last visible window.
406-
if ((switchData != nullptr) && (msg->LastSeenWindow)) {}
407-
else {
408-
auto ret = dynamic_cast<gui::SwitchSpecialChar *>(switchData.get());
409-
if (ret != nullptr && switchData != nullptr) {
410-
auto text = dynamic_cast<gui::Text *>(getCurrentWindow()->getFocusItem());
411-
if (text != nullptr) {
412-
text->addText(ret->getDescription());
413-
refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST);
414-
return msgHandled();
415-
}
399+
auto ret = dynamic_cast<gui::SwitchSpecialChar *>(switchData.get());
400+
if (ret != nullptr && switchData != nullptr) {
401+
auto text = dynamic_cast<gui::Text *>(getCurrentWindow()->getFocusItem());
402+
if (text != nullptr) {
403+
text->addText(ret->getDescription());
404+
refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST);
405+
return msgHandled();
416406
}
417-
getCurrentWindow()->onBeforeShow(msg->getCommand(), switchData.get());
418407
}
408+
getCurrentWindow()->onBeforeShow(msg->getCommand(), switchData.get());
419409
refreshWindow(gui::RefreshModes::GUI_REFRESH_DEEP);
420410
}
421411
else {
@@ -449,6 +439,13 @@ namespace app
449439
sys::Message_t Application::handleAppRefresh(sys::DataMessage *msgl)
450440
{
451441
auto *msg = static_cast<AppRefreshMessage *>(msgl);
442+
assert(msg);
443+
if (windowsStack.isEmpty() || (getCurrentWindow()->getName() != msg->getWindowName())) {
444+
LOG_DEBUG("Ignore request for window %s we are on window %s",
445+
msg->getWindowName().c_str(),
446+
windowsStack.isEmpty() ? "none" : getCurrentWindow()->getName().c_str());
447+
return msgNotHandled();
448+
}
452449
render(msg->getMode());
453450
return msgHandled();
454451
}
@@ -518,15 +515,6 @@ namespace app
518515
sys::Bus::SendUnicast(msg, application, sender);
519516
}
520517

521-
void Application::messageRefreshApplication(sys::Service *sender,
522-
std::string application,
523-
std::string window,
524-
gui::SwitchData *data)
525-
{
526-
auto msg = std::make_shared<AppMessage>(MessageType::AppRefresh);
527-
sys::Bus::SendUnicast(msg, application, sender);
528-
}
529-
530518
void Application::messageCloseApplication(sys::Service *sender, std::string application)
531519
{
532520

module-apps/Application.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,6 @@ namespace app
291291
std::string application,
292292
std::string window,
293293
std::unique_ptr<gui::SwitchData> data);
294-
static void messageRefreshApplication(sys::Service *sender,
295-
std::string application,
296-
std::string window,
297-
gui::SwitchData *data = nullptr);
298294
static void messageCloseApplication(sys::Service *sender, std::string application);
299295
static void messageRebuildApplication(sys::Service *sender, std::string application);
300296
static void messageApplicationLostFocus(sys::Service *sender, std::string application);
@@ -328,6 +324,7 @@ namespace app
328324
/// @ingrup AppWindowStack
329325
void cleanPrevWindw();
330326
/// getter for current wisible window in application
327+
/// if there is none - returns default window
331328
/// @ingrup AppWindowStack
332329
gui::AppWindow *getCurrentWindow();
333330

module-apps/WindowsStack.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,10 @@ namespace app
5151
auto ret = windows.find(name);
5252
return ret == std::end(windows) ? nullptr : ret->second.get();
5353
}
54+
55+
[[nodiscard]] auto isEmpty() const noexcept
56+
{
57+
return stack.size() == 0;
58+
}
5459
};
5560
} // namespace app

module-apps/application-desktop/windows/DesktopMainWindow.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ namespace gui
7878
DesktopMainWindow::DesktopMainWindow(app::Application *app) : AppWindow(app, app::window::name::desktop_main_window)
7979
{
8080
buildInterface();
81+
82+
preBuildDrawListHook = [this](std::list<Command> &cmd) {
83+
if (time != nullptr) {
84+
time->setText(topBar->getTimeString());
85+
}
86+
};
8187
}
8288

8389
void DesktopMainWindow::setVisibleState()
@@ -146,7 +152,6 @@ namespace gui
146152
if (inputEvent.is(KeyCode::KEY_PND) && (!app->lockHandler.lock.isLocked())) {
147153
app->lockHandler.lock.lock();
148154
setVisibleState();
149-
application->refreshWindow(RefreshModes::GUI_REFRESH_FAST);
150155
application->setSuspendFlag(true);
151156
return true;
152157
}
@@ -249,12 +254,6 @@ namespace gui
249254
return ret;
250255
}
251256

252-
std::list<DrawCommand *> DesktopMainWindow::buildDrawList()
253-
{
254-
time->setText(topBar->getTimeString());
255-
return gui::AppWindow::buildDrawList();
256-
}
257-
258257
auto DesktopMainWindow::buildNotifications(app::ApplicationDesktop *app) -> bool
259258
{
260259
erase(notifications);

module-apps/application-desktop/windows/DesktopMainWindow.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ namespace gui
8383
void destroyInterface() override;
8484
bool updateTime(const UTF8 &timeStr) override;
8585
bool updateTime(const uint32_t &timestamp, bool mode24H) override;
86-
std::list<DrawCommand *> buildDrawList() override;
8786

8887
private:
8988
void invalidate() noexcept;

module-apps/messages/AppMessage.hpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

4-
#ifndef MODULE_APPS_MESSAGES_APPMESSAGE_HPP_
5-
#define MODULE_APPS_MESSAGES_APPMESSAGE_HPP_
4+
#pragma once
65

6+
#include "Common.hpp"
77
#include "MessageType.hpp"
88
#include "Service/Message.hpp"
99
#include "SwitchData.hpp"
@@ -21,7 +21,7 @@ namespace app
2121
{
2222
public:
2323
AppMessage(MessageType messageType) : sys::DataMessage(messageType){};
24-
virtual ~AppMessage(){};
24+
AppMessage() : sys::DataMessage(MessageType::AppMessage){};
2525
};
2626

2727
// this message is used to notify application about switching event. Application will gain or lose focus upon
@@ -80,16 +80,21 @@ namespace app
8080
{
8181
protected:
8282
gui::RefreshModes mode;
83+
std::string window_name;
8384

8485
public:
85-
// AppRefreshMessage( const std::string& application, gui::RefreshModes mode ) :
86-
AppRefreshMessage(gui::RefreshModes mode) : AppMessage(MessageType::AppRefresh), mode{mode} {};
87-
virtual ~AppRefreshMessage(){};
86+
AppRefreshMessage(gui::RefreshModes mode, std::string window_name)
87+
: mode{mode}, window_name(std::move(window_name)){};
8888

89-
const gui::RefreshModes &getMode()
89+
[[nodiscard]] const gui::RefreshModes &getMode() const
9090
{
9191
return mode;
92-
};
92+
}
93+
94+
[[nodiscard]] const std::string &getWindowName() const
95+
{
96+
return window_name;
97+
}
9398
};
9499

95100
class AppSwitchWindowMessage : public AppMessage
@@ -101,7 +106,6 @@ namespace app
101106
std::unique_ptr<gui::SwitchData> data;
102107

103108
public:
104-
bool LastSeenWindow = false;
105109
AppSwitchWindowMessage() = delete;
106110

107111
AppSwitchWindowMessage(const std::string &window,
@@ -170,4 +174,3 @@ namespace app
170174
{}
171175
};
172176
}; // namespace app
173-
#endif /* MODULE_APPS_MESSAGES_APPMESSAGE_HPP_ */

module-apps/windows/AppWindow.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,6 @@ namespace gui
118118
}
119119
}
120120

121-
std::list<DrawCommand *> AppWindow::buildDrawList()
122-
{
123-
return Window::buildDrawList();
124-
}
125-
126121
bool AppWindow::onDatabaseMessage(sys::Message *msg)
127122
{
128123
return false;

module-apps/windows/AppWindow.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ namespace gui
7777
void buildInterface() override;
7878
void destroyInterface() override;
7979
bool onInput(const InputEvent &inputEvent) override;
80-
std::list<DrawCommand *> buildDrawList() override;
8180
/// Setting bottom bar temporary text
8281
/// @param text - bottomBar text
8382
/// @param overwriteOthers - set or not other bottomBar texts to "" (default true)

module-gui/gui/Common.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,14 @@ namespace gui
143143
void setTimeFunction(timeSecondsFunctionPtr fptr);
144144

145145
} // namespace gui
146+
147+
inline const char *c_str(gui::RefreshModes refresh)
148+
{
149+
switch (refresh) {
150+
case gui::RefreshModes::GUI_REFRESH_FAST:
151+
return "GUI_REFRESH_FAST";
152+
case gui::RefreshModes::GUI_REFRESH_DEEP:
153+
return "GUI_REFRESH_DEEP";
154+
}
155+
return "";
156+
}

0 commit comments

Comments
 (0)