gui: simplify blanktimer
- get rid of separate thread, check timer in rendering thread instead
- use an enum for the blanking state instead of magic integers
- move #ifdefs for TW_NO_SCREEN_TIMEOUT inside blanktimer class
- move some #includes and enum TOUCH_STATE to pages.hpp
Change-Id: Id4b104e3680dc5db41d8ba85e32d722cf4086299
diff --git a/gui/gui.cpp b/gui/gui.cpp
index db6e23f..edf2d76 100644
--- a/gui/gui.cpp
+++ b/gui/gui.cpp
@@ -50,9 +50,7 @@
#include "../twrp-functions.hpp"
#include "../openrecoveryscript.hpp"
#include "../orscmd/orscmd.h"
-#ifndef TW_NO_SCREEN_TIMEOUT
#include "blanktimer.hpp"
-#endif
// Enable to print render time of each frame to the log file
//#define PRINT_RENDER_TIME 1
@@ -71,9 +69,7 @@
static int gNoAnimation = 1;
static int gGuiInputRunning = 0;
static int gCmdLineRunning = 0;
-#ifndef TW_NO_SCREEN_TIMEOUT
blanktimer blankTimer;
-#endif
// Needed by pages.cpp too
int gGuiRunning = 0;
@@ -178,24 +174,23 @@
static void * input_thread(void *cookie)
{
-
int drag = 0;
static int touch_and_hold = 0, dontwait = 0;
static int touch_repeat = 0, key_repeat = 0;
static int x = 0, y = 0;
- static int lshift = 0, rshift = 0;
static struct timeval touchStart;
- string seconds;
HardwareKeyboard *kb = PageManager::GetHardwareKeyboard();
MouseCursor *cursor = PageManager::GetMouseCursor();
#ifndef TW_NO_SCREEN_TIMEOUT
- //start screen timeout threads
- blankTimer.setTimerThread();
- DataManager::GetValue("tw_screen_timeout_secs", seconds);
- blankTimer.setTime(atoi(seconds.c_str()));
+ {
+ string seconds;
+ DataManager::GetValue("tw_screen_timeout_secs", seconds);
+ blankTimer.setTime(atoi(seconds.c_str()));
+ blankTimer.resetTimerAndUnblank();
+ }
#else
- LOGINFO("Skipping screen timeout threads: TW_NO_SCREEN_TIMEOUT is set\n");
+ LOGINFO("Skipping screen timeout: TW_NO_SCREEN_TIMEOUT is set\n");
#endif
for (;;)
@@ -225,9 +220,7 @@
LOGERR("TOUCH_HOLD: %d,%d\n", x, y);
#endif
PageManager::NotifyTouch(TOUCH_HOLD, x, y);
-#ifndef TW_NO_SCREEN_TIMEOUT
blankTimer.resetTimerAndUnblank();
-#endif
}
else if (touch_repeat && mtime > 100)
{
@@ -236,9 +229,7 @@
#endif
gettimeofday(&touchStart, NULL);
PageManager::NotifyTouch(TOUCH_REPEAT, x, y);
-#ifndef TW_NO_SCREEN_TIMEOUT
blankTimer.resetTimerAndUnblank();
-#endif
}
else if (key_repeat == 1 && mtime > 500)
{
@@ -248,9 +239,7 @@
gettimeofday(&touchStart, NULL);
key_repeat = 2;
kb->KeyRepeat();
-#ifndef TW_NO_SCREEN_TIMEOUT
blankTimer.resetTimerAndUnblank();
-#endif
}
else if (key_repeat == 2 && mtime > 100)
@@ -260,9 +249,7 @@
#endif
gettimeofday(&touchStart, NULL);
kb->KeyRepeat();
-#ifndef TW_NO_SCREEN_TIMEOUT
blankTimer.resetTimerAndUnblank();
-#endif
}
}
else if (ev.type == EV_ABS)
@@ -279,9 +266,7 @@
LOGERR("TOUCH_RELEASE: %d,%d\n", x, y);
#endif
PageManager::NotifyTouch(TOUCH_RELEASE, x, y);
-#ifndef TW_NO_SCREEN_TIMEOUT
blankTimer.resetTimerAndUnblank();
-#endif
touch_and_hold = 0;
touch_repeat = 0;
if (!key_repeat)
@@ -306,9 +291,7 @@
key_repeat = 0;
gettimeofday(&touchStart, NULL);
}
-#ifndef TW_NO_SCREEN_TIMEOUT
blankTimer.resetTimerAndUnblank();
-#endif
}
else
{
@@ -320,9 +303,7 @@
if (PageManager::NotifyTouch(TOUCH_DRAG, x, y) > 0)
state = 1;
key_repeat = 0;
-#ifndef TW_NO_SCREEN_TIMEOUT
blankTimer.resetTimerAndUnblank();
-#endif
}
}
}
@@ -384,17 +365,13 @@
touch_repeat = 0;
dontwait = 1;
gettimeofday(&touchStart, NULL);
-#ifndef TW_NO_SCREEN_TIMEOUT
blankTimer.resetTimerAndUnblank();
-#endif
} else {
key_repeat = 0;
touch_and_hold = 0;
touch_repeat = 0;
dontwait = 0;
-#ifndef TW_NO_SCREEN_TIMEOUT
blankTimer.resetTimerAndUnblank();
-#endif
}
} else {
// This is a key release
@@ -403,9 +380,7 @@
touch_and_hold = 0;
touch_repeat = 0;
dontwait = 0;
-#ifndef TW_NO_SCREEN_TIMEOUT
blankTimer.resetTimerAndUnblank();
-#endif
}
}
else if(ev.type == EV_REL)
@@ -615,6 +590,7 @@
flip();
}
+ blankTimer.checkForTimeout();
if (DataManager::GetIntValue("tw_gui_done") != 0)
break;
}
@@ -665,6 +641,7 @@
PageManager::Render();
flip();
}
+ blankTimer.checkForTimeout();
if (DataManager::GetIntValue("tw_page_done") != 0)
{
gui_changePage("main");
@@ -750,8 +727,6 @@
extern "C" int gui_init(void)
{
- int fd;
-
gr_init();
if (res_create_surface("/res/images/curtain.jpg", &gCurtain))