[escher] Fix bug: do not redraw window at each timer fire but only for

timer requiring redraw

Change-Id: Ia39a35185a4836809970f5ba77cc76a8b2e6ee26
This commit is contained in:
Émilie Feral
2017-05-23 11:09:12 +02:00
parent f9a1caa8eb
commit c644a8d4f7
23 changed files with 35 additions and 52 deletions

View File

@@ -151,10 +151,13 @@ void AppsContainer::switchTo(App::Snapshot * snapshot) {
}
}
void AppsContainer::updateBatteryState() {
m_window.updateBatteryLevel();
m_window.updateIsChargingState();
m_window.updatePluggedState();
bool AppsContainer::updateBatteryState() {
if (m_window.updateBatteryLevel() ||
m_window.updateIsChargingState() ||
m_window.updatePluggedState()) {
return true;
}
return false;
}
void AppsContainer::refreshPreferences() {

View File

@@ -43,7 +43,7 @@ public:
void suspend(bool checkIfPowerKeyReleased = false);
virtual bool dispatchEvent(Ion::Events::Event event) override;
void switchTo(App::Snapshot * snapshot) override;
void updateBatteryState();
bool updateBatteryState();
void refreshPreferences();
void displayExamModePopUp(bool activate);
void shutdownDueToLowBattery();

View File

@@ -5,6 +5,7 @@ BacklightDimmingTimer::BacklightDimmingTimer() :
{
}
void BacklightDimmingTimer::fire() {
bool BacklightDimmingTimer::fire() {
Ion::Backlight::setBrightness(k_dimBacklightBrightness);
return false;
}

View File

@@ -9,7 +9,7 @@ public:
private:
constexpr static int k_idleBeforeDimmingDuration = 30*1000; // In miliseconds
constexpr static int k_dimBacklightBrightness = 0;
void fire() override;
bool fire() override;
};
#endif

View File

@@ -7,9 +7,10 @@ BatteryTimer::BatteryTimer(AppsContainer * container) :
{
}
void BatteryTimer::fire() {
m_container->updateBatteryState();
bool BatteryTimer::fire() {
bool needRedrawing = m_container->updateBatteryState();
if (Ion::Battery::level() == Ion::Battery::Charge::EMPTY) {
m_container->shutdownDueToLowBattery();
}
return needRedrawing;
}

View File

@@ -9,7 +9,7 @@ class BatteryTimer : public Timer {
public:
BatteryTimer(AppsContainer * container);
private:
void fire() override;
bool fire() override;
AppsContainer * m_container;
};

View File

@@ -6,8 +6,9 @@ LedTimer::LedTimer() :
{
}
void LedTimer::fire() {
bool LedTimer::fire() {
m_on = !m_on;
KDColor ledColor = m_on ? KDColorRed : KDColorBlack;
Ion::LED::setColor(ledColor);
return false;
}

View File

@@ -7,7 +7,7 @@ class LedTimer : public Timer {
public:
LedTimer();
private:
void fire() override;
bool fire() override;
bool m_on;
};

View File

@@ -14,8 +14,9 @@ View * LogoController::view() {
return &m_logoView;
}
void LogoController::fire() {
bool LogoController::fire() {
app()->dismissModalViewController();
return true;
}
}

View File

@@ -11,7 +11,7 @@ public:
LogoController();
View * view() override;
private:
void fire() override;
bool fire() override;
LogoView m_logoView;
};

View File

@@ -7,6 +7,7 @@ SuspendTimer::SuspendTimer(AppsContainer * container) :
{
}
void SuspendTimer::fire() {
bool SuspendTimer::fire() {
m_container->suspend();
return false;
}

View File

@@ -10,7 +10,7 @@ public:
SuspendTimer(AppsContainer * container);
private:
constexpr static int k_idleBeforeSuspendDuration = 5*60*1000; // In miliseconds
void fire() override;
bool fire() override;
AppsContainer * m_container;
};

View File

@@ -9,10 +9,12 @@ USBTimer::USBTimer(AppsContainer * container) :
{
}
void USBTimer::fire() {
bool USBTimer::fire() {
bool needRedrawing = false;
if (Ion::USB::isPlugged()) {
if (!m_previousPluggedState && GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::Activate) {
m_container->displayExamModePopUp(false);
needRedrawing = true;
}
#if LED_WHILE_CHARGING
KDColor LEDColor = Ion::Battery::isCharging() ? KDColorYellow : KDColorGreen;
@@ -27,4 +29,5 @@ void USBTimer::fire() {
m_previousPluggedState = false;
}
}
return needRedrawing;
}

View File

@@ -9,7 +9,7 @@ class USBTimer : public Timer {
public:
USBTimer(AppsContainer * container);
private:
void fire() override;
bool fire() override;
AppsContainer * m_container;
bool m_previousPluggedState;
};

View File

@@ -22,7 +22,6 @@ objs += $(addprefix escher/src/,\
highlight_cell.o\
image_view.o\
invocation.o\
invocation_timer.o\
input_view_controller.o\
key_view.o\
list_view_data_source.o\

View File

@@ -25,7 +25,6 @@
#include <escher/image_view.h>
#include <escher/input_view_controller.h>
#include <escher/invocation.h>
#include <escher/invocation_timer.h>
#include <escher/i18n.h>
#include <escher/key_view.h>
#include <escher/list_view_data_source.h>

View File

@@ -1,15 +0,0 @@
#ifndef ESCHER_INVOCATION_TIMER_H
#define ESCHER_INVOCATION_TIMER_H
#include <escher/timer.h>
#include <escher/invocation.h>
class InvocationTimer : public Timer {
public:
InvocationTimer(Invocation invocation, uint32_t period);
private:
void fire() override;
Invocation m_invocation;
};
#endif

View File

@@ -19,7 +19,7 @@ public:
bool tick();
void reset();
protected:
virtual void fire() = 0;
virtual bool fire() = 0;
private:
uint32_t m_period;
uint32_t m_numberOfTicksBeforeFire;

View File

@@ -35,7 +35,7 @@ App * Container::activeApp() {
}
bool Container::dispatchEvent(Ion::Events::Event event) {
if (event == Ion::Events::TimerTick || m_activeApp->processEvent(event)) {
if (event == Ion::Events::TimerFire || m_activeApp->processEvent(event)) {
window()->redraw();
return true;
}

View File

@@ -1,11 +0,0 @@
#include <escher/invocation_timer.h>
InvocationTimer::InvocationTimer(Invocation invocation, uint32_t period) :
Timer(period),
m_invocation(invocation)
{
}
void InvocationTimer::fire() {
m_invocation.perform(this);
}

View File

@@ -49,7 +49,7 @@ bool RunLoop::step() {
for (int i=0; i<numberOfTimers(); i++) {
Timer * timer = timerAtIndex(i);
if (timer->tick()) {
dispatchEvent(Ion::Events::TimerTick);
dispatchEvent(Ion::Events::TimerFire);
}
}
}

View File

@@ -9,9 +9,9 @@ Timer::Timer(uint32_t period) :
bool Timer::tick() {
m_numberOfTicksBeforeFire--;
if (m_numberOfTicksBeforeFire == 0) {
fire();
bool needRedraw = fire();
reset();
return true;
return needRedraw;
}
return false;
}

View File

@@ -200,7 +200,7 @@ constexpr Event UpperZ = Event::ShiftAlphaKey(Keyboard::Key::H4);
constexpr Event None = Event::Special(0);
constexpr Event Termination = Event::Special(1);
constexpr Event TimerTick = Event::Special(2);
constexpr Event TimerFire = Event::Special(2);
}
}