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