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 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 60 | const static int CURTAIN_FADE = 32; |
| 61 | |
| 62 | using namespace rapidxml; |
| 63 | |
| 64 | // Global values |
| 65 | static gr_surface gCurtain = NULL; |
| 66 | static int gGuiInitialized = 0; |
| 67 | static int gGuiConsoleRunning = 0; |
| 68 | static int gGuiConsoleTerminate = 0; |
| 69 | static int gForceRender = 0; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 70 | pthread_mutex_t gForceRendermutex; |
Dees_Troy | c8b199c | 2012-09-24 11:55:07 -0400 | [diff] [blame] | 71 | static int gNoAnimation = 1; |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 72 | static int gGuiInputRunning = 0; |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 73 | #ifndef TW_NO_SCREEN_TIMEOUT |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 74 | blanktimer blankTimer; |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 75 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 76 | |
| 77 | // Needed by pages.cpp too |
| 78 | int gGuiRunning = 0; |
| 79 | |
| 80 | static int gRecorder = -1; |
| 81 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 82 | extern "C" void gr_write_frame_to_file(int fd); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 83 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 84 | void flip(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 85 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 86 | if (gRecorder != -1) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 87 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 88 | timespec time; |
| 89 | clock_gettime(CLOCK_MONOTONIC, &time); |
| 90 | write(gRecorder, &time, sizeof(timespec)); |
| 91 | gr_write_frame_to_file(gRecorder); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 92 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 93 | gr_flip(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 94 | } |
| 95 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 96 | void rapidxml::parse_error_handler(const char *what, void *where) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 97 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 98 | fprintf(stderr, "Parser error: %s\n", what); |
| 99 | fprintf(stderr, " Start of string: %s\n",(char *) where); |
| 100 | LOGERR("Error parsing XML file.\n"); |
| 101 | //abort(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 102 | } |
| 103 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 104 | static void curtainSet() |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 105 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 106 | gr_color(0, 0, 0, 255); |
| 107 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
| 108 | gr_blit(gCurtain, 0, 0, gr_get_width(gCurtain), gr_get_height(gCurtain), 0, 0); |
| 109 | gr_flip(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 110 | } |
| 111 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 112 | static void curtainRaise(gr_surface surface) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 113 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 114 | int sy = 0; |
| 115 | int h = gr_get_height(gCurtain) - 1; |
| 116 | int w = gr_get_width(gCurtain); |
| 117 | int fy = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 118 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 119 | int msw = gr_get_width(surface); |
| 120 | int msh = gr_get_height(surface); |
| 121 | int CURTAIN_RATE = msh / 30; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 122 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 123 | if (gNoAnimation == 0) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 124 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 125 | for (; h > 0; h -= CURTAIN_RATE, sy += CURTAIN_RATE, fy += CURTAIN_RATE) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 126 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 127 | gr_blit(surface, 0, 0, msw, msh, 0, 0); |
| 128 | gr_blit(gCurtain, 0, sy, w, h, 0, 0); |
| 129 | gr_flip(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 130 | } |
| 131 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 132 | gr_blit(surface, 0, 0, msw, msh, 0, 0); |
| 133 | flip(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 134 | } |
| 135 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 136 | void curtainClose() |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 137 | { |
| 138 | #if 0 |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 139 | int w = gr_get_width(gCurtain); |
| 140 | int h = 1; |
| 141 | int sy = gr_get_height(gCurtain) - 1; |
| 142 | int fbh = gr_fb_height(); |
| 143 | int CURTAIN_RATE = fbh / 30; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 144 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 145 | if (gNoAnimation == 0) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 146 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 147 | for (; h < fbh; h += CURTAIN_RATE, sy -= CURTAIN_RATE) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 148 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 149 | gr_blit(gCurtain, 0, sy, w, h, 0, 0); |
| 150 | gr_flip(); |
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, 0, gr_get_width(gCurtain), |
| 153 | gr_get_height(gCurtain), 0, 0); |
| 154 | gr_flip(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 155 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 156 | if (gRecorder != -1) |
| 157 | close(gRecorder); |
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 | int fade; |
| 160 | for (fade = 16; fade < 255; fade += CURTAIN_FADE) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 161 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 162 | gr_blit(gCurtain, 0, 0, gr_get_width(gCurtain), |
| 163 | gr_get_height(gCurtain), 0, 0); |
| 164 | gr_color(0, 0, 0, fade); |
| 165 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
| 166 | gr_flip(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 167 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 168 | gr_color(0, 0, 0, 255); |
| 169 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
| 170 | gr_flip(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 171 | } |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 172 | #else |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 173 | gr_blit(gCurtain, 0, 0, gr_get_width(gCurtain), gr_get_height(gCurtain), 0, 0); |
| 174 | gr_flip(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 175 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 176 | } |
| 177 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 178 | static void * input_thread(void *cookie) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 179 | { |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 180 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 181 | int drag = 0; |
| 182 | static int touch_and_hold = 0, dontwait = 0; |
| 183 | static int touch_repeat = 0, key_repeat = 0; |
| 184 | static int x = 0, y = 0; |
| 185 | static int lshift = 0, rshift = 0; |
| 186 | static struct timeval touchStart; |
| 187 | HardwareKeyboard kb; |
| 188 | string seconds; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 189 | |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 190 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 191 | //start screen timeout threads |
| 192 | blankTimer.setTimerThread(); |
| 193 | DataManager::GetValue("tw_screen_timeout_secs", seconds); |
| 194 | blankTimer.setTime(atoi(seconds.c_str())); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 195 | #else |
| 196 | LOGINFO("Skipping screen timeout threads: TW_NO_SCREEN_TIMEOUT is set\n"); |
| 197 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 198 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 199 | for (;;) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 200 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 201 | // wait for the next event |
| 202 | struct input_event ev; |
| 203 | int state = 0, ret = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 204 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 205 | ret = ev_get(&ev, dontwait); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 206 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 207 | if (ret < 0) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 208 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 209 | struct timeval curTime; |
| 210 | gettimeofday(&curTime, NULL); |
| 211 | long mtime, seconds, useconds; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 212 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 213 | seconds = curTime.tv_sec - touchStart.tv_sec; |
| 214 | useconds = curTime.tv_usec - touchStart.tv_usec; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 215 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 216 | mtime = ((seconds) * 1000 + useconds / 1000.0) + 0.5; |
| 217 | if (touch_and_hold && mtime > 500) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 218 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 219 | touch_and_hold = 0; |
| 220 | touch_repeat = 1; |
| 221 | gettimeofday(&touchStart, NULL); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 222 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 223 | LOGERR("TOUCH_HOLD: %d,%d\n", x, y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 224 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 225 | PageManager::NotifyTouch(TOUCH_HOLD, x, y); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 226 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 227 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 228 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 229 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 230 | else if (touch_repeat && mtime > 100) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 231 | { |
| 232 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 233 | LOGERR("TOUCH_REPEAT: %d,%d\n", x, y); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 234 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 235 | gettimeofday(&touchStart, NULL); |
| 236 | PageManager::NotifyTouch(TOUCH_REPEAT, x, y); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 237 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 238 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 239 | #endif |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 240 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 241 | else if (key_repeat == 1 && mtime > 500) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 242 | { |
| 243 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 244 | LOGERR("KEY_HOLD: %d,%d\n", x, y); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 245 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 246 | gettimeofday(&touchStart, NULL); |
| 247 | key_repeat = 2; |
| 248 | kb.KeyRepeat(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 249 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 250 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 251 | #endif |
| 252 | |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 253 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 254 | else if (key_repeat == 2 && mtime > 100) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 255 | { |
| 256 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 257 | LOGERR("KEY_REPEAT: %d,%d\n", x, y); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 258 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 259 | gettimeofday(&touchStart, NULL); |
| 260 | kb.KeyRepeat(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 261 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 262 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 263 | #endif |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 264 | } |
| 265 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 266 | else if (ev.type == EV_ABS) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 267 | { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 268 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 269 | x = ev.value >> 16; |
| 270 | y = ev.value & 0xFFFF; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 271 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 272 | if (ev.code == 0) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 273 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 274 | if (state == 0) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 275 | { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 276 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 277 | LOGERR("TOUCH_RELEASE: %d,%d\n", x, y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 278 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 279 | PageManager::NotifyTouch(TOUCH_RELEASE, x, y); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 280 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 281 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 282 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 283 | touch_and_hold = 0; |
| 284 | touch_repeat = 0; |
| 285 | if (!key_repeat) |
| 286 | dontwait = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 287 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 288 | state = 0; |
| 289 | drag = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 290 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 291 | else |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 292 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 293 | if (!drag) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 294 | { |
| 295 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 296 | LOGERR("TOUCH_START: %d,%d\n", x, y); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 297 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 298 | if (PageManager::NotifyTouch(TOUCH_START, x, y) > 0) |
| 299 | state = 1; |
| 300 | drag = 1; |
| 301 | touch_and_hold = 1; |
| 302 | dontwait = 1; |
| 303 | key_repeat = 0; |
| 304 | gettimeofday(&touchStart, NULL); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 305 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 306 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 307 | #endif |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 308 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 309 | else |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 310 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 311 | if (state == 0) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 312 | { |
| 313 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 314 | LOGERR("TOUCH_DRAG: %d,%d\n", x, y); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 315 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 316 | if (PageManager::NotifyTouch(TOUCH_DRAG, x, y) > 0) |
| 317 | state = 1; |
| 318 | key_repeat = 0; |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 319 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 320 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 321 | #endif |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | } |
| 325 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 326 | else if (ev.type == EV_KEY) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 327 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 328 | // Handle key-press here |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 329 | #ifdef _EVENT_LOGGING |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 330 | LOGERR("TOUCH_KEY: %d\n", ev.code); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 331 | #endif |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 332 | if (ev.value != 0) |
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 | // This is a key press |
| 335 | if (kb.KeyDown(ev.code)) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 336 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 337 | key_repeat = 1; |
| 338 | touch_and_hold = 0; |
| 339 | touch_repeat = 0; |
| 340 | dontwait = 1; |
| 341 | gettimeofday(&touchStart, NULL); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 342 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 343 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 344 | #endif |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 345 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 346 | else |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 347 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 348 | key_repeat = 0; |
| 349 | touch_and_hold = 0; |
| 350 | touch_repeat = 0; |
| 351 | dontwait = 0; |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 352 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 353 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 354 | #endif |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 355 | } |
| 356 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 357 | else |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 358 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 359 | // This is a key release |
| 360 | kb.KeyUp(ev.code); |
| 361 | key_repeat = 0; |
| 362 | touch_and_hold = 0; |
| 363 | touch_repeat = 0; |
| 364 | dontwait = 0; |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 365 | #ifndef TW_NO_SCREEN_TIMEOUT |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 366 | blankTimer.resetTimerAndUnblank(); |
Ricardo Gomez | c9ecd44 | 2013-07-05 16:13:52 -0700 | [diff] [blame] | 367 | #endif |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 368 | } |
| 369 | } |
| 370 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 371 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | // This special function will return immediately the first time, but then |
| 375 | // always returns 1/30th of a second (or immediately if called later) from |
| 376 | // the last time it was called |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 377 | static void loopTimer(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 378 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 379 | static timespec lastCall; |
| 380 | static int initialized = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 381 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 382 | if (!initialized) |
Dees_Troy | c8b199c | 2012-09-24 11:55:07 -0400 | [diff] [blame] | 383 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 384 | clock_gettime(CLOCK_MONOTONIC, &lastCall); |
| 385 | initialized = 1; |
| 386 | return; |
Dees_Troy | c8b199c | 2012-09-24 11:55:07 -0400 | [diff] [blame] | 387 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 388 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 389 | do |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 390 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 391 | timespec curTime; |
| 392 | clock_gettime(CLOCK_MONOTONIC, &curTime); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 393 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 394 | timespec diff = TWFunc::timespec_diff(lastCall, curTime); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 395 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 396 | // This is really 30 times per second |
| 397 | if (diff.tv_sec || diff.tv_nsec > 33333333) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 398 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 399 | lastCall = curTime; |
| 400 | return; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 401 | } |
| 402 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 403 | // We need to sleep some period time microseconds |
| 404 | unsigned int sleepTime = 33333 -(diff.tv_nsec / 1000); |
| 405 | usleep(sleepTime); |
| 406 | } while (1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 407 | } |
| 408 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 409 | static int runPages(void) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 410 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 411 | // Raise the curtain |
| 412 | if (gCurtain != NULL) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 413 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 414 | gr_surface surface; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 415 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 416 | PageManager::Render(); |
| 417 | gr_get_surface(&surface); |
| 418 | curtainRaise(surface); |
| 419 | gr_free_surface(surface); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 420 | } |
| 421 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 422 | gGuiRunning = 1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 423 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 424 | DataManager::SetValue("tw_loaded", 1); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 425 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 426 | for (;;) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 427 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 428 | loopTimer(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 429 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 430 | if (!gForceRender) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 431 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 432 | int ret; |
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 | ret = PageManager::Update(); |
| 435 | if (ret > 1) |
| 436 | PageManager::Render(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 437 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 438 | if (ret > 0) |
| 439 | flip(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 440 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 441 | else |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 442 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 443 | pthread_mutex_lock(&gForceRendermutex); |
| 444 | gForceRender = 0; |
| 445 | pthread_mutex_unlock(&gForceRendermutex); |
| 446 | PageManager::Render(); |
| 447 | flip(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 448 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 449 | |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 450 | if (DataManager::GetIntValue("tw_gui_done") != 0) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 451 | break; |
| 452 | } |
| 453 | |
| 454 | gGuiRunning = 0; |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | static int runPage(const char *page_name) |
| 459 | { |
| 460 | gui_changePage(page_name); |
| 461 | |
| 462 | // Raise the curtain |
| 463 | if (gCurtain != NULL) |
| 464 | { |
| 465 | gr_surface surface; |
| 466 | |
| 467 | PageManager::Render(); |
| 468 | gr_get_surface(&surface); |
| 469 | curtainRaise(surface); |
| 470 | gr_free_surface(surface); |
| 471 | } |
| 472 | |
| 473 | gGuiRunning = 1; |
| 474 | |
| 475 | DataManager::SetValue("tw_loaded", 1); |
| 476 | |
| 477 | for (;;) |
| 478 | { |
| 479 | loopTimer(); |
| 480 | |
| 481 | if (!gForceRender) |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 482 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 483 | int ret; |
| 484 | |
| 485 | ret = PageManager::Update(); |
| 486 | if (ret > 1) |
| 487 | PageManager::Render(); |
| 488 | |
| 489 | if (ret > 0) |
| 490 | flip(); |
| 491 | } |
| 492 | else |
| 493 | { |
| 494 | pthread_mutex_lock(&gForceRendermutex); |
| 495 | gForceRender = 0; |
| 496 | pthread_mutex_unlock(&gForceRendermutex); |
| 497 | PageManager::Render(); |
| 498 | flip(); |
| 499 | } |
| 500 | if (DataManager::GetIntValue("tw_page_done") != 0) |
| 501 | { |
| 502 | gui_changePage("main"); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 503 | break; |
| 504 | } |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 505 | } |
| 506 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 507 | gGuiRunning = 0; |
| 508 | return 0; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 509 | } |
| 510 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 511 | int gui_forceRender(void) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 512 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 513 | pthread_mutex_lock(&gForceRendermutex); |
| 514 | gForceRender = 1; |
| 515 | pthread_mutex_unlock(&gForceRendermutex); |
| 516 | return 0; |
| 517 | } |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 518 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 519 | int gui_changePage(std::string newPage) |
| 520 | { |
| 521 | LOGINFO("Set page: '%s'\n", newPage.c_str()); |
| 522 | PageManager::ChangePage(newPage); |
| 523 | pthread_mutex_lock(&gForceRendermutex); |
| 524 | gForceRender = 1; |
| 525 | pthread_mutex_unlock(&gForceRendermutex); |
| 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | int gui_changeOverlay(std::string overlay) |
| 530 | { |
| 531 | PageManager::ChangeOverlay(overlay); |
| 532 | pthread_mutex_lock(&gForceRendermutex); |
| 533 | gForceRender = 1; |
| 534 | pthread_mutex_unlock(&gForceRendermutex); |
| 535 | return 0; |
| 536 | } |
| 537 | |
| 538 | int gui_changePackage(std::string newPackage) |
| 539 | { |
| 540 | PageManager::SelectPackage(newPackage); |
| 541 | pthread_mutex_lock(&gForceRendermutex); |
| 542 | gForceRender = 1; |
| 543 | pthread_mutex_unlock(&gForceRendermutex); |
| 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | std::string gui_parse_text(string inText) |
| 548 | { |
| 549 | // Copied from std::string GUIText::parseText(void) |
| 550 | // This function parses text for DataManager values encompassed by %value% in the XML |
| 551 | static int counter = 0; |
| 552 | std::string str = inText; |
| 553 | size_t pos = 0; |
| 554 | size_t next = 0, end = 0; |
| 555 | |
| 556 | while (1) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 557 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 558 | next = str.find('%', pos); |
| 559 | if (next == std::string::npos) |
| 560 | return str; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 561 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 562 | end = str.find('%', next + 1); |
| 563 | if (end == std::string::npos) |
| 564 | return str; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 565 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 566 | // We have a block of data |
| 567 | std::string var = str.substr(next + 1,(end - next) - 1); |
| 568 | str.erase(next,(end - next) + 1); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 569 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 570 | if (next + 1 == end) |
| 571 | str.insert(next, 1, '%'); |
| 572 | else |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 573 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 574 | std::string value; |
| 575 | if (DataManager::GetValue(var, value) == 0) |
| 576 | str.insert(next, value); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 577 | } |
| 578 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 579 | pos = next + 1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 583 | extern "C" int gui_init(void) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 584 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 585 | int fd; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 586 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 587 | gr_init(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 588 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 589 | if (res_create_surface("/res/images/curtain.jpg", &gCurtain)) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 590 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 591 | printf |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 592 | ("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] | 593 | return -1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 594 | } |
| 595 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 596 | curtainSet(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 597 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 598 | ev_init(); |
| 599 | return 0; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 600 | } |
| 601 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 602 | extern "C" int gui_loadResources(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 603 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 604 | // unlink("/sdcard/video.last"); |
| 605 | // rename("/sdcard/video.bin", "/sdcard/video.last"); |
| 606 | // gRecorder = open("/sdcard/video.bin", O_CREAT | O_WRONLY); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 607 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 608 | int check = 0; |
| 609 | DataManager::GetValue(TW_IS_ENCRYPTED, check); |
| 610 | if (check) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 611 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 612 | if (PageManager::LoadPackage("TWRP", "/res/ui.xml", "decrypt")) |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 613 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 614 | LOGERR("Failed to load base packages.\n"); |
| 615 | goto error; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 616 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 617 | else |
| 618 | check = 1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 619 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 620 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 621 | if (check == 0 && PageManager::LoadPackage("TWRP", "/script/ui.xml", "main")) |
| 622 | { |
| 623 | std::string theme_path; |
| 624 | |
| 625 | theme_path = DataManager::GetSettingsStoragePath(); |
| 626 | if (!PartitionManager.Mount_Settings_Storage(false)) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 627 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 628 | int retry_count = 5; |
| 629 | while (retry_count > 0 && !PartitionManager.Mount_Settings_Storage(false)) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 630 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 631 | usleep(500000); |
| 632 | retry_count--; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 633 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 634 | |
| 635 | if (!PartitionManager.Mount_Settings_Storage(false)) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 636 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 637 | LOGERR("Unable to mount %s during GUI startup.\n", |
| 638 | theme_path.c_str()); |
| 639 | check = 1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 640 | } |
| 641 | } |
| 642 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 643 | theme_path += "/TWRP/theme/ui.zip"; |
| 644 | if (check || PageManager::LoadPackage("TWRP", theme_path, "main")) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 645 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 646 | if (PageManager::LoadPackage("TWRP", "/res/ui.xml", "main")) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 647 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 648 | LOGERR("Failed to load base packages.\n"); |
| 649 | goto error; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 650 | } |
| 651 | } |
| 652 | } |
| 653 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 654 | // Set the default package |
| 655 | PageManager::SelectPackage("TWRP"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 656 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 657 | gGuiInitialized = 1; |
| 658 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 659 | |
| 660 | error: |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 661 | LOGERR("An internal error has occurred.\n"); |
| 662 | gGuiInitialized = 0; |
| 663 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 664 | } |
| 665 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 666 | extern "C" int gui_start(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 667 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 668 | if (!gGuiInitialized) |
| 669 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 670 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 671 | gGuiConsoleTerminate = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 672 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 673 | while (gGuiConsoleRunning) |
| 674 | loopTimer(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 675 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 676 | // Set the default package |
| 677 | PageManager::SelectPackage("TWRP"); |
| 678 | |
| 679 | if (!gGuiInputRunning) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 680 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 681 | // Start by spinning off an input handler. |
| 682 | pthread_t t; |
| 683 | pthread_create(&t, NULL, input_thread, NULL); |
| 684 | gGuiInputRunning = 1; |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 685 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 686 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 687 | return runPages(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 688 | } |
| 689 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 690 | extern "C" int gui_startPage(const char *page_name) |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 691 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 692 | if (!gGuiInitialized) |
| 693 | return -1; |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 694 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 695 | gGuiConsoleTerminate = 1; |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 696 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 697 | while (gGuiConsoleRunning) |
| 698 | loopTimer(); |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 699 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 700 | // Set the default package |
| 701 | PageManager::SelectPackage("TWRP"); |
| 702 | |
| 703 | if (!gGuiInputRunning) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 704 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 705 | // Start by spinning off an input handler. |
| 706 | pthread_t t; |
| 707 | pthread_create(&t, NULL, input_thread, NULL); |
| 708 | gGuiInputRunning = 1; |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 709 | } |
| 710 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 711 | DataManager::SetValue("tw_page_done", 0); |
| 712 | return runPage(page_name); |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 713 | } |
| 714 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 715 | static void * console_thread(void *cookie) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 716 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 717 | PageManager::SwitchToConsole(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 718 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 719 | while (!gGuiConsoleTerminate) |
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 | loopTimer(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 722 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 723 | if (!gForceRender) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 724 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 725 | int ret; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 726 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 727 | ret = PageManager::Update(); |
| 728 | if (ret > 1) |
| 729 | PageManager::Render(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 730 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 731 | if (ret > 0) |
| 732 | flip(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 733 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 734 | if (ret < 0) |
| 735 | LOGERR("An update request has failed.\n"); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 736 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 737 | else |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 738 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 739 | pthread_mutex_lock(&gForceRendermutex); |
| 740 | gForceRender = 0; |
| 741 | pthread_mutex_unlock(&gForceRendermutex); |
| 742 | PageManager::Render(); |
| 743 | flip(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 744 | } |
| 745 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 746 | gGuiConsoleRunning = 0; |
| 747 | return NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 748 | } |
| 749 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 750 | extern "C" int gui_console_only(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 751 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 752 | if (!gGuiInitialized) |
| 753 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 754 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 755 | gGuiConsoleTerminate = 0; |
| 756 | gGuiConsoleRunning = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 757 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 758 | // Start by spinning off an input handler. |
| 759 | pthread_t t; |
| 760 | pthread_create(&t, NULL, console_thread, NULL); |
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 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 763 | } |