Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1 | /* |
Dees Troy | 3be70a8 | 2013-10-22 14:25:12 +0000 | [diff] [blame] | 2 | Copyright 2012 bigbiff/Dees_Troy TeamWin |
| 3 | This file is part of TWRP/TeamWin Recovery Project. |
| 4 | |
| 5 | TWRP is free software: you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation, either version 3 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | TWRP is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with TWRP. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 18 | |
| 19 | #include <linux/input.h> |
| 20 | #include <pthread.h> |
| 21 | #include <stdarg.h> |
| 22 | #include <stdio.h> |
| 23 | #include <errno.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <fcntl.h> |
| 27 | #include <sys/reboot.h> |
| 28 | #include <sys/stat.h> |
| 29 | #include <sys/time.h> |
| 30 | #include <sys/mman.h> |
| 31 | #include <sys/types.h> |
| 32 | #include <sys/ioctl.h> |
| 33 | #include <sys/mount.h> |
| 34 | #include <time.h> |
| 35 | #include <unistd.h> |
| 36 | #include <stdlib.h> |
| 37 | |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 38 | extern "C" |
| 39 | { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 40 | #include "../twcommon.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 41 | #include "../minuitwrp/minui.h" |
Dees Troy | b7ae098 | 2013-09-10 20:47:35 +0000 | [diff] [blame] | 42 | #ifdef HAVE_SELINUX |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 43 | #include "../minzip/Zip.h" |
Dees Troy | b7ae098 | 2013-09-10 20:47:35 +0000 | [diff] [blame] | 44 | #else |
| 45 | #include "../minzipold/Zip.h" |
| 46 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 47 | #include <pixelflinger/pixelflinger.h> |
| 48 | } |
| 49 | |
| 50 | #include "rapidxml.hpp" |
| 51 | #include "objects.hpp" |
| 52 | #include "../data.hpp" |
| 53 | #include "../variables.h" |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 54 | #include "../partitions.hpp" |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 55 | #include "../twrp-functions.hpp" |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 56 | #ifndef TW_NO_SCREEN_TIMEOUT |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 57 | #include "blanktimer.hpp" |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 58 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 59 | |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 60 | // Enable to print render time of each frame to the log file |
| 61 | //#define PRINT_RENDER_TIME 1 |
| 62 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 63 | const static int CURTAIN_FADE = 32; |
| 64 | |
| 65 | using namespace rapidxml; |
| 66 | |
| 67 | // Global values |
| 68 | static gr_surface gCurtain = NULL; |
| 69 | static int gGuiInitialized = 0; |
| 70 | static int gGuiConsoleRunning = 0; |
| 71 | static int gGuiConsoleTerminate = 0; |
| 72 | static int gForceRender = 0; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 73 | pthread_mutex_t gForceRendermutex; |
Dees_Troy | c8b199c | 2012-09-24 11:55:07 -0400 | [diff] [blame] | 74 | static int gNoAnimation = 1; |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 75 | static int gGuiInputRunning = 0; |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 76 | #ifndef TW_NO_SCREEN_TIMEOUT |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 77 | blanktimer blankTimer; |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 78 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 79 | |
| 80 | // Needed by pages.cpp too |
| 81 | int gGuiRunning = 0; |
| 82 | |
| 83 | static int gRecorder = -1; |
| 84 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 85 | extern "C" void gr_write_frame_to_file(int fd); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 86 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 87 | void flip(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 88 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 89 | if (gRecorder != -1) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 90 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 91 | timespec time; |
| 92 | clock_gettime(CLOCK_MONOTONIC, &time); |
| 93 | write(gRecorder, &time, sizeof(timespec)); |
| 94 | gr_write_frame_to_file(gRecorder); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 95 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 96 | gr_flip(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 97 | } |
| 98 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 99 | void rapidxml::parse_error_handler(const char *what, void *where) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 100 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 101 | fprintf(stderr, "Parser error: %s\n", what); |
| 102 | fprintf(stderr, " Start of string: %s\n",(char *) where); |
| 103 | LOGERR("Error parsing XML file.\n"); |
| 104 | //abort(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 105 | } |
| 106 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 107 | static void curtainSet() |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 108 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 109 | gr_color(0, 0, 0, 255); |
| 110 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
| 111 | gr_blit(gCurtain, 0, 0, gr_get_width(gCurtain), gr_get_height(gCurtain), 0, 0); |
| 112 | gr_flip(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 113 | } |
| 114 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 115 | static void curtainRaise(gr_surface surface) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 116 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 117 | int sy = 0; |
| 118 | int h = gr_get_height(gCurtain) - 1; |
| 119 | int w = gr_get_width(gCurtain); |
| 120 | int fy = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 121 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 122 | int msw = gr_get_width(surface); |
| 123 | int msh = gr_get_height(surface); |
| 124 | int CURTAIN_RATE = msh / 30; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 125 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 126 | if (gNoAnimation == 0) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 127 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 128 | for (; h > 0; h -= CURTAIN_RATE, sy += CURTAIN_RATE, fy += CURTAIN_RATE) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 129 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 130 | gr_blit(surface, 0, 0, msw, msh, 0, 0); |
| 131 | gr_blit(gCurtain, 0, sy, w, h, 0, 0); |
| 132 | gr_flip(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 133 | } |
| 134 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 135 | gr_blit(surface, 0, 0, msw, msh, 0, 0); |
| 136 | flip(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 137 | } |
| 138 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 139 | void curtainClose() |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 140 | { |
| 141 | #if 0 |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 142 | int w = gr_get_width(gCurtain); |
| 143 | int h = 1; |
| 144 | int sy = gr_get_height(gCurtain) - 1; |
| 145 | int fbh = gr_fb_height(); |
| 146 | int CURTAIN_RATE = fbh / 30; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 147 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 148 | if (gNoAnimation == 0) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 149 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 150 | for (; h < fbh; h += CURTAIN_RATE, sy -= CURTAIN_RATE) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 151 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 152 | gr_blit(gCurtain, 0, sy, w, h, 0, 0); |
| 153 | gr_flip(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 154 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 155 | gr_blit(gCurtain, 0, 0, gr_get_width(gCurtain), |
| 156 | gr_get_height(gCurtain), 0, 0); |
| 157 | gr_flip(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 158 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 159 | if (gRecorder != -1) |
| 160 | close(gRecorder); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 161 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 162 | int fade; |
| 163 | for (fade = 16; fade < 255; fade += CURTAIN_FADE) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 164 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 165 | gr_blit(gCurtain, 0, 0, gr_get_width(gCurtain), |
| 166 | gr_get_height(gCurtain), 0, 0); |
| 167 | gr_color(0, 0, 0, fade); |
| 168 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
| 169 | gr_flip(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 170 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 171 | gr_color(0, 0, 0, 255); |
| 172 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
| 173 | gr_flip(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 174 | } |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 175 | #else |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 176 | gr_blit(gCurtain, 0, 0, gr_get_width(gCurtain), gr_get_height(gCurtain), 0, 0); |
| 177 | gr_flip(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 178 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 179 | } |
| 180 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 181 | static void * input_thread(void *cookie) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 182 | { |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 183 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 184 | int drag = 0; |
| 185 | static int touch_and_hold = 0, dontwait = 0; |
| 186 | static int touch_repeat = 0, key_repeat = 0; |
| 187 | static int x = 0, y = 0; |
| 188 | static int lshift = 0, rshift = 0; |
| 189 | static struct timeval touchStart; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 190 | string seconds; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 191 | HardwareKeyboard *kb = PageManager::GetHardwareKeyboard(); |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 192 | MouseCursor *cursor = PageManager::GetMouseCursor(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 193 | |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 194 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 195 | //start screen timeout threads |
| 196 | blankTimer.setTimerThread(); |
| 197 | DataManager::GetValue("tw_screen_timeout_secs", seconds); |
| 198 | blankTimer.setTime(atoi(seconds.c_str())); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 199 | #else |
| 200 | LOGINFO("Skipping screen timeout threads: TW_NO_SCREEN_TIMEOUT is set\n"); |
| 201 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 202 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 203 | for (;;) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 204 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 205 | // wait for the next event |
| 206 | struct input_event ev; |
| 207 | int state = 0, ret = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 208 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 209 | ret = ev_get(&ev, dontwait); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 210 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 211 | if (ret < 0) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 212 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 213 | struct timeval curTime; |
| 214 | gettimeofday(&curTime, NULL); |
| 215 | long mtime, seconds, useconds; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 216 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 217 | seconds = curTime.tv_sec - touchStart.tv_sec; |
| 218 | useconds = curTime.tv_usec - touchStart.tv_usec; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 219 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 220 | mtime = ((seconds) * 1000 + useconds / 1000.0) + 0.5; |
| 221 | if (touch_and_hold && mtime > 500) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 222 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 223 | touch_and_hold = 0; |
| 224 | touch_repeat = 1; |
| 225 | gettimeofday(&touchStart, NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 226 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 227 | LOGERR("TOUCH_HOLD: %d,%d\n", x, y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 228 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 229 | PageManager::NotifyTouch(TOUCH_HOLD, x, y); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 230 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 231 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 232 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 233 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 234 | else if (touch_repeat && mtime > 100) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 235 | { |
| 236 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 237 | LOGERR("TOUCH_REPEAT: %d,%d\n", x, y); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 238 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 239 | gettimeofday(&touchStart, NULL); |
| 240 | PageManager::NotifyTouch(TOUCH_REPEAT, x, y); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 241 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 242 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 243 | #endif |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 244 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 245 | else if (key_repeat == 1 && mtime > 500) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 246 | { |
| 247 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 248 | LOGERR("KEY_HOLD: %d,%d\n", x, y); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 249 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 250 | gettimeofday(&touchStart, NULL); |
| 251 | key_repeat = 2; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 252 | kb->KeyRepeat(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 253 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 254 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 255 | #endif |
| 256 | |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 257 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 258 | else if (key_repeat == 2 && mtime > 100) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 259 | { |
| 260 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 261 | LOGERR("KEY_REPEAT: %d,%d\n", x, y); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 262 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 263 | gettimeofday(&touchStart, NULL); |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 264 | kb->KeyRepeat(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 265 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 266 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 267 | #endif |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 268 | } |
| 269 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 270 | else if (ev.type == EV_ABS) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 271 | { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 272 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 273 | x = ev.value >> 16; |
| 274 | y = ev.value & 0xFFFF; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 275 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 276 | if (ev.code == 0) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 277 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 278 | if (state == 0) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 279 | { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 280 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 281 | LOGERR("TOUCH_RELEASE: %d,%d\n", x, y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 282 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 283 | PageManager::NotifyTouch(TOUCH_RELEASE, x, y); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 284 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 285 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 286 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 287 | touch_and_hold = 0; |
| 288 | touch_repeat = 0; |
| 289 | if (!key_repeat) |
| 290 | dontwait = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 291 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 292 | state = 0; |
| 293 | drag = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 294 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 295 | else |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 296 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 297 | if (!drag) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 298 | { |
Dees Troy | 1eba56f | 2014-04-12 13:09:00 +0000 | [diff] [blame] | 299 | if (x != 0 && y != 0) { |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 300 | #ifdef _EVENT_LOGGING |
Dees Troy | 1eba56f | 2014-04-12 13:09:00 +0000 | [diff] [blame] | 301 | LOGERR("TOUCH_START: %d,%d\n", x, y); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 302 | #endif |
Dees Troy | 1eba56f | 2014-04-12 13:09:00 +0000 | [diff] [blame] | 303 | if (PageManager::NotifyTouch(TOUCH_START, x, y) > 0) |
| 304 | state = 1; |
| 305 | drag = 1; |
| 306 | touch_and_hold = 1; |
| 307 | dontwait = 1; |
| 308 | key_repeat = 0; |
| 309 | gettimeofday(&touchStart, NULL); |
| 310 | } |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 311 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 312 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 313 | #endif |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 314 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 315 | else |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 316 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 317 | if (state == 0) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 318 | { |
| 319 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 320 | LOGERR("TOUCH_DRAG: %d,%d\n", x, y); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 321 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 322 | if (PageManager::NotifyTouch(TOUCH_DRAG, x, y) > 0) |
| 323 | state = 1; |
| 324 | key_repeat = 0; |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 325 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 326 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 327 | #endif |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | } |
| 331 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 332 | else if (ev.type == EV_KEY) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 333 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 334 | // Handle key-press here |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 335 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 336 | LOGERR("TOUCH_KEY: %d\n", ev.code); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 337 | #endif |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 338 | // Left mouse button |
| 339 | if(ev.code == BTN_LEFT) |
| 340 | { |
| 341 | if(ev.value == 1) |
| 342 | { |
| 343 | cursor->GetPos(x, y); |
| 344 | |
| 345 | if (PageManager::NotifyTouch(TOUCH_START, x, y) > 0) |
| 346 | state = 1; |
| 347 | drag = 1; |
| 348 | touch_and_hold = 1; |
| 349 | dontwait = 1; |
| 350 | key_repeat = 0; |
| 351 | gettimeofday(&touchStart, NULL); |
| 352 | } |
| 353 | else if(drag == 1) |
| 354 | { |
| 355 | if (state == 0) |
| 356 | { |
| 357 | cursor->GetPos(x, y); |
| 358 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 359 | #ifdef _EVENT_LOGGING |
| 360 | LOGERR("TOUCH_RELEASE: %d,%d\n", x, y); |
| 361 | #endif |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 362 | PageManager::NotifyTouch(TOUCH_RELEASE, x, y); |
| 363 | |
| 364 | touch_and_hold = 0; |
| 365 | touch_repeat = 0; |
| 366 | if (!key_repeat) |
| 367 | dontwait = 0; |
| 368 | } |
| 369 | state = 0; |
| 370 | drag = 0; |
| 371 | } |
| 372 | } |
| 373 | // side mouse button, often used for "back" function |
| 374 | else if(ev.code == BTN_SIDE) |
| 375 | { |
| 376 | if(ev.value == 1) |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 377 | kb->KeyDown(KEY_BACK); |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 378 | else |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 379 | kb->KeyUp(KEY_BACK); |
| 380 | } else if (ev.value != 0) { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 381 | // This is a key press |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 382 | if (kb->KeyDown(ev.code)) { |
| 383 | // Key repeat is enabled for this key |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 384 | key_repeat = 1; |
| 385 | touch_and_hold = 0; |
| 386 | touch_repeat = 0; |
| 387 | dontwait = 1; |
| 388 | gettimeofday(&touchStart, NULL); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 389 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 390 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 391 | #endif |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 392 | } else { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 393 | key_repeat = 0; |
| 394 | touch_and_hold = 0; |
| 395 | touch_repeat = 0; |
| 396 | dontwait = 0; |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 397 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 398 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 399 | #endif |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 400 | } |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 401 | } else { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 402 | // This is a key release |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 403 | kb->KeyUp(ev.code); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 404 | key_repeat = 0; |
| 405 | touch_and_hold = 0; |
| 406 | touch_repeat = 0; |
| 407 | dontwait = 0; |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 408 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 409 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 410 | #endif |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 411 | } |
| 412 | } |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 413 | else if(ev.type == EV_REL) |
| 414 | { |
| 415 | #ifdef _EVENT_LOGGING |
| 416 | LOGERR("EV_REL %d %d\n", ev.code, ev.value); |
| 417 | #endif |
| 418 | if(ev.code == REL_X) |
| 419 | cursor->Move(ev.value, 0); |
| 420 | else if(ev.code == REL_Y) |
| 421 | cursor->Move(0, ev.value); |
| 422 | |
| 423 | if(drag == 1) { |
| 424 | cursor->GetPos(x, y); |
| 425 | #ifdef _EVENT_LOGGING |
| 426 | LOGERR("TOUCH_DRAG: %d, %d\n", x, y); |
| 427 | #endif |
| 428 | if (PageManager::NotifyTouch(TOUCH_DRAG, x, y) > 0) |
| 429 | state = 1; |
| 430 | key_repeat = 0; |
| 431 | } |
| 432 | } |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 433 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 434 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | // This special function will return immediately the first time, but then |
| 438 | // always returns 1/30th of a second (or immediately if called later) from |
| 439 | // the last time it was called |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 440 | static void loopTimer(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 441 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 442 | static timespec lastCall; |
| 443 | static int initialized = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 444 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 445 | if (!initialized) |
Dees_Troy | c8b199c | 2012-09-24 11:55:07 -0400 | [diff] [blame] | 446 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 447 | clock_gettime(CLOCK_MONOTONIC, &lastCall); |
| 448 | initialized = 1; |
| 449 | return; |
Dees_Troy | c8b199c | 2012-09-24 11:55:07 -0400 | [diff] [blame] | 450 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 451 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 452 | do |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 453 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 454 | timespec curTime; |
| 455 | clock_gettime(CLOCK_MONOTONIC, &curTime); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 456 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 457 | timespec diff = TWFunc::timespec_diff(lastCall, curTime); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 458 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 459 | // This is really 30 times per second |
| 460 | if (diff.tv_sec || diff.tv_nsec > 33333333) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 461 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 462 | lastCall = curTime; |
| 463 | return; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 464 | } |
| 465 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 466 | // We need to sleep some period time microseconds |
| 467 | unsigned int sleepTime = 33333 -(diff.tv_nsec / 1000); |
| 468 | usleep(sleepTime); |
| 469 | } while (1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 470 | } |
| 471 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 472 | static int runPages(void) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 473 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 474 | // Raise the curtain |
| 475 | if (gCurtain != NULL) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 476 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 477 | gr_surface surface; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 478 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 479 | PageManager::Render(); |
| 480 | gr_get_surface(&surface); |
| 481 | curtainRaise(surface); |
| 482 | gr_free_surface(surface); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 483 | } |
| 484 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 485 | gGuiRunning = 1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 486 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 487 | DataManager::SetValue("tw_loaded", 1); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 488 | |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 489 | #ifdef PRINT_RENDER_TIME |
| 490 | timespec start, end; |
| 491 | int32_t render_t, flip_t; |
| 492 | #endif |
| 493 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 494 | for (;;) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 495 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 496 | loopTimer(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 497 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 498 | if (!gForceRender) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 499 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 500 | int ret; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 501 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 502 | ret = PageManager::Update(); |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 503 | |
| 504 | #ifndef PRINT_RENDER_TIME |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 505 | if (ret > 1) |
| 506 | PageManager::Render(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 507 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 508 | if (ret > 0) |
| 509 | flip(); |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 510 | #else |
| 511 | if (ret > 1) |
| 512 | { |
| 513 | clock_gettime(CLOCK_MONOTONIC, &start); |
| 514 | PageManager::Render(); |
| 515 | clock_gettime(CLOCK_MONOTONIC, &end); |
| 516 | render_t = TWFunc::timespec_diff_ms(start, end); |
| 517 | |
| 518 | flip(); |
| 519 | clock_gettime(CLOCK_MONOTONIC, &start); |
| 520 | flip_t = TWFunc::timespec_diff_ms(end, start); |
| 521 | |
| 522 | LOGINFO("Render(): %u ms, flip(): %u ms, total: %u ms\n", render_t, flip_t, render_t+flip_t); |
| 523 | } |
| 524 | else if(ret == 1) |
| 525 | flip(); |
| 526 | #endif |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 527 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 528 | else |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 529 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 530 | pthread_mutex_lock(&gForceRendermutex); |
| 531 | gForceRender = 0; |
| 532 | pthread_mutex_unlock(&gForceRendermutex); |
| 533 | PageManager::Render(); |
| 534 | flip(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 535 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 536 | |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 537 | if (DataManager::GetIntValue("tw_gui_done") != 0) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 538 | break; |
| 539 | } |
| 540 | |
| 541 | gGuiRunning = 0; |
| 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | static int runPage(const char *page_name) |
| 546 | { |
| 547 | gui_changePage(page_name); |
| 548 | |
| 549 | // Raise the curtain |
| 550 | if (gCurtain != NULL) |
| 551 | { |
| 552 | gr_surface surface; |
| 553 | |
| 554 | PageManager::Render(); |
| 555 | gr_get_surface(&surface); |
| 556 | curtainRaise(surface); |
| 557 | gr_free_surface(surface); |
| 558 | } |
| 559 | |
| 560 | gGuiRunning = 1; |
| 561 | |
| 562 | DataManager::SetValue("tw_loaded", 1); |
| 563 | |
| 564 | for (;;) |
| 565 | { |
| 566 | loopTimer(); |
| 567 | |
| 568 | if (!gForceRender) |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 569 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 570 | int ret; |
| 571 | |
| 572 | ret = PageManager::Update(); |
| 573 | if (ret > 1) |
| 574 | PageManager::Render(); |
| 575 | |
| 576 | if (ret > 0) |
| 577 | flip(); |
| 578 | } |
| 579 | else |
| 580 | { |
| 581 | pthread_mutex_lock(&gForceRendermutex); |
| 582 | gForceRender = 0; |
| 583 | pthread_mutex_unlock(&gForceRendermutex); |
| 584 | PageManager::Render(); |
| 585 | flip(); |
| 586 | } |
| 587 | if (DataManager::GetIntValue("tw_page_done") != 0) |
| 588 | { |
| 589 | gui_changePage("main"); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 590 | break; |
| 591 | } |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 592 | } |
| 593 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 594 | gGuiRunning = 0; |
| 595 | return 0; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 596 | } |
| 597 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 598 | int gui_forceRender(void) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 599 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 600 | pthread_mutex_lock(&gForceRendermutex); |
| 601 | gForceRender = 1; |
| 602 | pthread_mutex_unlock(&gForceRendermutex); |
| 603 | return 0; |
| 604 | } |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 605 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 606 | int gui_changePage(std::string newPage) |
| 607 | { |
| 608 | LOGINFO("Set page: '%s'\n", newPage.c_str()); |
| 609 | PageManager::ChangePage(newPage); |
| 610 | pthread_mutex_lock(&gForceRendermutex); |
| 611 | gForceRender = 1; |
| 612 | pthread_mutex_unlock(&gForceRendermutex); |
| 613 | return 0; |
| 614 | } |
| 615 | |
| 616 | int gui_changeOverlay(std::string overlay) |
| 617 | { |
| 618 | PageManager::ChangeOverlay(overlay); |
| 619 | pthread_mutex_lock(&gForceRendermutex); |
| 620 | gForceRender = 1; |
| 621 | pthread_mutex_unlock(&gForceRendermutex); |
| 622 | return 0; |
| 623 | } |
| 624 | |
| 625 | int gui_changePackage(std::string newPackage) |
| 626 | { |
| 627 | PageManager::SelectPackage(newPackage); |
| 628 | pthread_mutex_lock(&gForceRendermutex); |
| 629 | gForceRender = 1; |
| 630 | pthread_mutex_unlock(&gForceRendermutex); |
| 631 | return 0; |
| 632 | } |
| 633 | |
| 634 | std::string gui_parse_text(string inText) |
| 635 | { |
| 636 | // Copied from std::string GUIText::parseText(void) |
| 637 | // This function parses text for DataManager values encompassed by %value% in the XML |
| 638 | static int counter = 0; |
| 639 | std::string str = inText; |
| 640 | size_t pos = 0; |
| 641 | size_t next = 0, end = 0; |
| 642 | |
| 643 | while (1) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 644 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 645 | next = str.find('%', pos); |
| 646 | if (next == std::string::npos) |
| 647 | return str; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 648 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 649 | end = str.find('%', next + 1); |
| 650 | if (end == std::string::npos) |
| 651 | return str; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 652 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 653 | // We have a block of data |
| 654 | std::string var = str.substr(next + 1,(end - next) - 1); |
| 655 | str.erase(next,(end - next) + 1); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 656 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 657 | if (next + 1 == end) |
| 658 | str.insert(next, 1, '%'); |
| 659 | else |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 660 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 661 | std::string value; |
| 662 | if (DataManager::GetValue(var, value) == 0) |
| 663 | str.insert(next, value); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 664 | } |
| 665 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 666 | pos = next + 1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 667 | } |
| 668 | } |
| 669 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 670 | extern "C" int gui_init(void) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 671 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 672 | int fd; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 673 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 674 | gr_init(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 675 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 676 | if (res_create_surface("/res/images/curtain.jpg", &gCurtain)) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 677 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 678 | printf |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 679 | ("Unable to locate '/res/images/curtain.jpg'\nDid you set a DEVICE_RESOLUTION in your config files?\n"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 680 | return -1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 681 | } |
| 682 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 683 | curtainSet(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 684 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 685 | ev_init(); |
| 686 | return 0; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 687 | } |
| 688 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 689 | extern "C" int gui_loadResources(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 690 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 691 | // unlink("/sdcard/video.last"); |
| 692 | // rename("/sdcard/video.bin", "/sdcard/video.last"); |
| 693 | // gRecorder = open("/sdcard/video.bin", O_CREAT | O_WRONLY); |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 694 | #ifndef TW_OEM_BUILD |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 695 | int check = 0; |
| 696 | DataManager::GetValue(TW_IS_ENCRYPTED, check); |
| 697 | if (check) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 698 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 699 | if (PageManager::LoadPackage("TWRP", "/res/ui.xml", "decrypt")) |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 700 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 701 | LOGERR("Failed to load base packages.\n"); |
| 702 | goto error; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 703 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 704 | else |
| 705 | check = 1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 706 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 707 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 708 | if (check == 0 && PageManager::LoadPackage("TWRP", "/script/ui.xml", "main")) |
| 709 | { |
| 710 | std::string theme_path; |
| 711 | |
| 712 | theme_path = DataManager::GetSettingsStoragePath(); |
| 713 | if (!PartitionManager.Mount_Settings_Storage(false)) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 714 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 715 | int retry_count = 5; |
| 716 | while (retry_count > 0 && !PartitionManager.Mount_Settings_Storage(false)) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 717 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 718 | usleep(500000); |
| 719 | retry_count--; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 720 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 721 | |
| 722 | if (!PartitionManager.Mount_Settings_Storage(false)) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 723 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 724 | LOGERR("Unable to mount %s during GUI startup.\n", |
| 725 | theme_path.c_str()); |
| 726 | check = 1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 727 | } |
| 728 | } |
| 729 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 730 | theme_path += "/TWRP/theme/ui.zip"; |
| 731 | if (check || PageManager::LoadPackage("TWRP", theme_path, "main")) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 732 | { |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 733 | #endif // ifndef TW_OEM_BUILD |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 734 | if (PageManager::LoadPackage("TWRP", "/res/ui.xml", "main")) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 735 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 736 | LOGERR("Failed to load base packages.\n"); |
| 737 | goto error; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 738 | } |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 739 | #ifndef TW_OEM_BUILD |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 740 | } |
| 741 | } |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 742 | #endif // ifndef TW_OEM_BUILD |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 743 | // Set the default package |
| 744 | PageManager::SelectPackage("TWRP"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 745 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 746 | gGuiInitialized = 1; |
| 747 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 748 | |
| 749 | error: |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 750 | LOGERR("An internal error has occurred: unable to load theme.\n"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 751 | gGuiInitialized = 0; |
| 752 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 753 | } |
| 754 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 755 | extern "C" int gui_start(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 756 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 757 | if (!gGuiInitialized) |
| 758 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 759 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 760 | gGuiConsoleTerminate = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 761 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 762 | while (gGuiConsoleRunning) |
| 763 | loopTimer(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 764 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 765 | // Set the default package |
| 766 | PageManager::SelectPackage("TWRP"); |
| 767 | |
| 768 | if (!gGuiInputRunning) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 769 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 770 | // Start by spinning off an input handler. |
| 771 | pthread_t t; |
| 772 | pthread_create(&t, NULL, input_thread, NULL); |
| 773 | gGuiInputRunning = 1; |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 774 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 775 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 776 | return runPages(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 777 | } |
| 778 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 779 | extern "C" int gui_startPage(const char *page_name) |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 780 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 781 | if (!gGuiInitialized) |
| 782 | return -1; |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 783 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 784 | gGuiConsoleTerminate = 1; |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 785 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 786 | while (gGuiConsoleRunning) |
| 787 | loopTimer(); |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 788 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 789 | // Set the default package |
| 790 | PageManager::SelectPackage("TWRP"); |
| 791 | |
| 792 | if (!gGuiInputRunning) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 793 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 794 | // Start by spinning off an input handler. |
| 795 | pthread_t t; |
| 796 | pthread_create(&t, NULL, input_thread, NULL); |
| 797 | gGuiInputRunning = 1; |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 798 | } |
| 799 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 800 | DataManager::SetValue("tw_page_done", 0); |
| 801 | return runPage(page_name); |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 802 | } |
| 803 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 804 | static void * console_thread(void *cookie) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 805 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 806 | PageManager::SwitchToConsole(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 807 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 808 | while (!gGuiConsoleTerminate) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 809 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 810 | loopTimer(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 811 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 812 | if (!gForceRender) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 813 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 814 | int ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 815 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 816 | ret = PageManager::Update(); |
| 817 | if (ret > 1) |
| 818 | PageManager::Render(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 819 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 820 | if (ret > 0) |
| 821 | flip(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 822 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 823 | if (ret < 0) |
| 824 | LOGERR("An update request has failed.\n"); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 825 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 826 | else |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 827 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 828 | pthread_mutex_lock(&gForceRendermutex); |
| 829 | gForceRender = 0; |
| 830 | pthread_mutex_unlock(&gForceRendermutex); |
| 831 | PageManager::Render(); |
| 832 | flip(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 833 | } |
| 834 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 835 | gGuiConsoleRunning = 0; |
| 836 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 837 | } |
| 838 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 839 | extern "C" int gui_console_only(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 840 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 841 | if (!gGuiInitialized) |
| 842 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 843 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 844 | gGuiConsoleTerminate = 0; |
| 845 | gGuiConsoleRunning = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 846 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 847 | // Start by spinning off an input handler. |
| 848 | pthread_t t; |
| 849 | pthread_create(&t, NULL, console_thread, NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 850 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 851 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 852 | } |