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 <pixelflinger/pixelflinger.h> |
| 42 | } |
Ethan Yonker | fbb4353 | 2015-12-28 21:54:50 +0100 | [diff] [blame] | 43 | #include "../minuitwrp/minui.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 44 | |
| 45 | #include "rapidxml.hpp" |
| 46 | #include "objects.hpp" |
| 47 | #include "../data.hpp" |
| 48 | #include "../variables.h" |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 49 | #include "../partitions.hpp" |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 50 | #include "../twrp-functions.hpp" |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 51 | #include "../openrecoveryscript.hpp" |
| 52 | #include "../orscmd/orscmd.h" |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 53 | #include "blanktimer.hpp" |
Ethan Yonker | 0453695 | 2015-01-27 08:41:28 -0600 | [diff] [blame] | 54 | #include "../tw_atomic.hpp" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 55 | |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 56 | // Enable to print render time of each frame to the log file |
| 57 | //#define PRINT_RENDER_TIME 1 |
| 58 | |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 59 | #ifdef _EVENT_LOGGING |
that | c5837f3 | 2015-02-01 01:59:43 +0100 | [diff] [blame] | 60 | #define LOGEVENT(...) LOGERR(__VA_ARGS__) |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 61 | #else |
| 62 | #define LOGEVENT(...) do {} while (0) |
| 63 | #endif |
| 64 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 65 | using namespace rapidxml; |
| 66 | |
| 67 | // Global values |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 68 | static int gGuiInitialized = 0; |
Ethan Yonker | 0453695 | 2015-01-27 08:41:28 -0600 | [diff] [blame] | 69 | static TWAtomicInt gForceRender; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 70 | blanktimer blankTimer; |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 71 | int ors_read_fd = -1; |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 72 | static FILE* orsout = NULL; |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 73 | static float scale_theme_w = 1; |
| 74 | static float scale_theme_h = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 75 | |
| 76 | // Needed by pages.cpp too |
| 77 | int gGuiRunning = 0; |
| 78 | |
that | 1964d19 | 2016-01-07 00:41:03 +0100 | [diff] [blame] | 79 | int g_pty_fd = -1; // set by terminal on init |
| 80 | void terminal_pty_read(); |
| 81 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 82 | static int gRecorder = -1; |
| 83 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 84 | extern "C" void gr_write_frame_to_file(int fd); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 85 | |
Matt Mower | b68bff0 | 2017-01-11 15:46:26 -0600 | [diff] [blame] | 86 | static void flip(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 87 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 88 | if (gRecorder != -1) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 89 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 90 | timespec time; |
| 91 | clock_gettime(CLOCK_MONOTONIC, &time); |
| 92 | write(gRecorder, &time, sizeof(timespec)); |
| 93 | gr_write_frame_to_file(gRecorder); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 94 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 95 | gr_flip(); |
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 | void rapidxml::parse_error_handler(const char *what, void *where) |
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 | fprintf(stderr, "Parser error: %s\n", what); |
| 101 | fprintf(stderr, " Start of string: %s\n",(char *) where); |
| 102 | LOGERR("Error parsing XML file.\n"); |
| 103 | //abort(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 104 | } |
| 105 | |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 106 | class InputHandler |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 107 | { |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 108 | public: |
| 109 | void init() |
that | fb759d4 | 2015-01-11 12:16:53 +0100 | [diff] [blame] | 110 | { |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 111 | // these might be read from DataManager in the future |
| 112 | touch_hold_ms = 500; |
| 113 | touch_repeat_ms = 100; |
| 114 | key_hold_ms = 500; |
| 115 | key_repeat_ms = 100; |
| 116 | touch_status = TS_NONE; |
| 117 | key_status = KS_NONE; |
| 118 | state = AS_NO_ACTION; |
| 119 | x = y = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 120 | |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 121 | #ifndef TW_NO_SCREEN_TIMEOUT |
| 122 | { |
| 123 | string seconds; |
| 124 | DataManager::GetValue("tw_screen_timeout_secs", seconds); |
| 125 | blankTimer.setTime(atoi(seconds.c_str())); |
| 126 | blankTimer.resetTimerAndUnblank(); |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 127 | } |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 128 | #else |
| 129 | LOGINFO("Skipping screen timeout: TW_NO_SCREEN_TIMEOUT is set\n"); |
| 130 | #endif |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 131 | } |
| 132 | |
that | c5837f3 | 2015-02-01 01:59:43 +0100 | [diff] [blame] | 133 | // process input events. returns true if any event was received. |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 134 | bool processInput(int timeout_ms); |
that | c5837f3 | 2015-02-01 01:59:43 +0100 | [diff] [blame] | 135 | |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 136 | void handleDrag(); |
| 137 | |
| 138 | private: |
| 139 | // timeouts for touch/key hold and repeat |
| 140 | int touch_hold_ms; |
| 141 | int touch_repeat_ms; |
| 142 | int key_hold_ms; |
| 143 | int key_repeat_ms; |
| 144 | |
| 145 | enum touch_status_enum { |
| 146 | TS_NONE = 0, |
| 147 | TS_TOUCH_AND_HOLD = 1, |
| 148 | TS_TOUCH_REPEAT = 2, |
| 149 | }; |
| 150 | |
| 151 | enum key_status_enum { |
| 152 | KS_NONE = 0, |
| 153 | KS_KEY_PRESSED = 1, |
| 154 | KS_KEY_REPEAT = 2, |
| 155 | }; |
| 156 | |
| 157 | enum action_state_enum { |
| 158 | AS_IN_ACTION_AREA = 0, // we've touched a spot with an action |
| 159 | AS_NO_ACTION = 1, // we've touched in an empty area (no action) and ignore remaining events until touch release |
| 160 | }; |
| 161 | touch_status_enum touch_status; |
| 162 | key_status_enum key_status; |
| 163 | action_state_enum state; |
| 164 | int x, y; // x and y coordinates of last touch |
| 165 | struct timeval touchStart; // used to track time for long press / key repeat |
| 166 | |
| 167 | void processHoldAndRepeat(); |
| 168 | void process_EV_REL(input_event& ev); |
| 169 | void process_EV_ABS(input_event& ev); |
| 170 | void process_EV_KEY(input_event& ev); |
| 171 | |
| 172 | void doTouchStart(); |
| 173 | }; |
| 174 | |
| 175 | InputHandler input_handler; |
| 176 | |
| 177 | |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 178 | bool InputHandler::processInput(int timeout_ms) |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 179 | { |
| 180 | input_event ev; |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 181 | int ret = ev_get(&ev, timeout_ms); |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 182 | |
| 183 | if (ret < 0) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 184 | { |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 185 | // This path means that we did not get any new touch data, but |
| 186 | // we do not get new touch data if you press and hold on either |
| 187 | // the screen or on a keyboard key or mouse button |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 188 | if (touch_status || key_status) |
| 189 | processHoldAndRepeat(); |
that | c5837f3 | 2015-02-01 01:59:43 +0100 | [diff] [blame] | 190 | return (ret != -2); // -2 means no more events in the queue |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 191 | } |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 192 | |
| 193 | switch (ev.type) |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 194 | { |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 195 | case EV_ABS: |
| 196 | process_EV_ABS(ev); |
| 197 | break; |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 198 | |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 199 | case EV_REL: |
| 200 | process_EV_REL(ev); |
| 201 | break; |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 202 | |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 203 | case EV_KEY: |
| 204 | process_EV_KEY(ev); |
| 205 | break; |
| 206 | } |
that | c5837f3 | 2015-02-01 01:59:43 +0100 | [diff] [blame] | 207 | |
Matt Mower | 9472ba1 | 2016-01-20 18:12:47 -0600 | [diff] [blame] | 208 | if (ev.code != KEY_POWER && ev.code > KEY_RESERVED) |
| 209 | blankTimer.resetTimerAndUnblank(); |
| 210 | |
that | c5837f3 | 2015-02-01 01:59:43 +0100 | [diff] [blame] | 211 | return true; // we got an event, so there might be more in the queue |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | void InputHandler::processHoldAndRepeat() |
| 215 | { |
| 216 | HardwareKeyboard *kb = PageManager::GetHardwareKeyboard(); |
| 217 | |
| 218 | // touch and key repeat section |
| 219 | struct timeval curTime; |
| 220 | gettimeofday(&curTime, NULL); |
| 221 | long seconds = curTime.tv_sec - touchStart.tv_sec; |
| 222 | long useconds = curTime.tv_usec - touchStart.tv_usec; |
| 223 | long mtime = ((seconds) * 1000 + useconds / 1000.0) + 0.5; |
| 224 | |
| 225 | if (touch_status == TS_TOUCH_AND_HOLD && mtime > touch_hold_ms) |
| 226 | { |
| 227 | touch_status = TS_TOUCH_REPEAT; |
| 228 | gettimeofday(&touchStart, NULL); |
| 229 | LOGEVENT("TOUCH_HOLD: %d,%d\n", x, y); |
| 230 | PageManager::NotifyTouch(TOUCH_HOLD, x, y); |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 231 | } |
| 232 | else if (touch_status == TS_TOUCH_REPEAT && mtime > touch_repeat_ms) |
| 233 | { |
| 234 | LOGEVENT("TOUCH_REPEAT: %d,%d\n", x, y); |
| 235 | gettimeofday(&touchStart, NULL); |
| 236 | PageManager::NotifyTouch(TOUCH_REPEAT, x, y); |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 237 | } |
| 238 | else if (key_status == KS_KEY_PRESSED && mtime > key_hold_ms) |
| 239 | { |
| 240 | LOGEVENT("KEY_HOLD: %d,%d\n", x, y); |
| 241 | gettimeofday(&touchStart, NULL); |
| 242 | key_status = KS_KEY_REPEAT; |
| 243 | kb->KeyRepeat(); |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 244 | } |
| 245 | else if (key_status == KS_KEY_REPEAT && mtime > key_repeat_ms) |
| 246 | { |
| 247 | LOGEVENT("KEY_REPEAT: %d,%d\n", x, y); |
| 248 | gettimeofday(&touchStart, NULL); |
| 249 | kb->KeyRepeat(); |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | |
| 253 | void InputHandler::doTouchStart() |
| 254 | { |
| 255 | LOGEVENT("TOUCH_START: %d,%d\n", x, y); |
| 256 | if (PageManager::NotifyTouch(TOUCH_START, x, y) > 0) |
| 257 | state = AS_NO_ACTION; |
| 258 | else |
| 259 | state = AS_IN_ACTION_AREA; |
| 260 | touch_status = TS_TOUCH_AND_HOLD; |
| 261 | gettimeofday(&touchStart, NULL); |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | void InputHandler::process_EV_ABS(input_event& ev) |
| 265 | { |
| 266 | x = ev.value >> 16; |
| 267 | y = ev.value & 0xFFFF; |
| 268 | |
| 269 | if (ev.code == 0) |
| 270 | { |
Ethan Yonker | 30fa335 | 2015-03-09 13:57:21 -0500 | [diff] [blame] | 271 | #ifndef TW_USE_KEY_CODE_TOUCH_SYNC |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 272 | if (state == AS_IN_ACTION_AREA) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 273 | { |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 274 | LOGEVENT("TOUCH_RELEASE: %d,%d\n", x, y); |
| 275 | PageManager::NotifyTouch(TOUCH_RELEASE, x, y); |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 276 | } |
| 277 | touch_status = TS_NONE; |
Ethan Yonker | 30fa335 | 2015-03-09 13:57:21 -0500 | [diff] [blame] | 278 | #endif |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 279 | } |
| 280 | else |
| 281 | { |
| 282 | if (!touch_status) |
| 283 | { |
Ethan Yonker | 30fa335 | 2015-03-09 13:57:21 -0500 | [diff] [blame] | 284 | #ifndef TW_USE_KEY_CODE_TOUCH_SYNC |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 285 | doTouchStart(); |
Ethan Yonker | 30fa335 | 2015-03-09 13:57:21 -0500 | [diff] [blame] | 286 | #endif |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 287 | } |
| 288 | else |
| 289 | { |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 290 | if (state == AS_IN_ACTION_AREA) |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 291 | { |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 292 | LOGEVENT("TOUCH_DRAG: %d,%d\n", x, y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 293 | } |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 294 | } |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 295 | } |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | void InputHandler::process_EV_KEY(input_event& ev) |
| 299 | { |
| 300 | HardwareKeyboard *kb = PageManager::GetHardwareKeyboard(); |
| 301 | |
| 302 | // Handle key-press here |
| 303 | LOGEVENT("TOUCH_KEY: %d\n", ev.code); |
| 304 | // Left mouse button is treated as a touch |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 305 | if (ev.code == BTN_LEFT) |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 306 | { |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 307 | MouseCursor *cursor = PageManager::GetMouseCursor(); |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 308 | if (ev.value == 1) |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 309 | { |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 310 | cursor->GetPos(x, y); |
| 311 | doTouchStart(); |
| 312 | } |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 313 | else if (touch_status) |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 314 | { |
| 315 | // Left mouse button was previously pressed and now is |
| 316 | // being released so send a TOUCH_RELEASE |
| 317 | if (state == AS_IN_ACTION_AREA) |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 318 | { |
| 319 | cursor->GetPos(x, y); |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 320 | |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 321 | LOGEVENT("Mouse TOUCH_RELEASE: %d,%d\n", x, y); |
| 322 | PageManager::NotifyTouch(TOUCH_RELEASE, x, y); |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 323 | } |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 324 | touch_status = TS_NONE; |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 325 | } |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 326 | } |
| 327 | // side mouse button, often used for "back" function |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 328 | else if (ev.code == BTN_SIDE) |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 329 | { |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 330 | if (ev.value == 1) |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 331 | kb->KeyDown(KEY_BACK); |
| 332 | else |
| 333 | kb->KeyUp(KEY_BACK); |
| 334 | } else if (ev.value != 0) { |
| 335 | // This is a key press |
Ethan Yonker | 30fa335 | 2015-03-09 13:57:21 -0500 | [diff] [blame] | 336 | #ifdef TW_USE_KEY_CODE_TOUCH_SYNC |
| 337 | if (ev.code == TW_USE_KEY_CODE_TOUCH_SYNC) { |
| 338 | LOGEVENT("key code %i key press == touch start %i %i\n", TW_USE_KEY_CODE_TOUCH_SYNC, x, y); |
| 339 | doTouchStart(); |
| 340 | return; |
| 341 | } |
| 342 | #endif |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 343 | if (kb->KeyDown(ev.code)) { |
| 344 | // Key repeat is enabled for this key |
| 345 | key_status = KS_KEY_PRESSED; |
| 346 | touch_status = TS_NONE; |
| 347 | gettimeofday(&touchStart, NULL); |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 348 | } else { |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 349 | key_status = KS_NONE; |
| 350 | touch_status = TS_NONE; |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 351 | } |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 352 | } else { |
| 353 | // This is a key release |
| 354 | kb->KeyUp(ev.code); |
| 355 | key_status = KS_NONE; |
| 356 | touch_status = TS_NONE; |
Ethan Yonker | 30fa335 | 2015-03-09 13:57:21 -0500 | [diff] [blame] | 357 | #ifdef TW_USE_KEY_CODE_TOUCH_SYNC |
| 358 | if (ev.code == TW_USE_KEY_CODE_TOUCH_SYNC) { |
| 359 | LOGEVENT("key code %i key release == touch release %i %i\n", TW_USE_KEY_CODE_TOUCH_SYNC, x, y); |
| 360 | PageManager::NotifyTouch(TOUCH_RELEASE, x, y); |
| 361 | } |
| 362 | #endif |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 363 | } |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 364 | } |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 365 | |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 366 | void InputHandler::process_EV_REL(input_event& ev) |
| 367 | { |
| 368 | // Mouse movement |
| 369 | MouseCursor *cursor = PageManager::GetMouseCursor(); |
| 370 | LOGEVENT("EV_REL %d %d\n", ev.code, ev.value); |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 371 | if (ev.code == REL_X) |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 372 | cursor->Move(ev.value, 0); |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 373 | else if (ev.code == REL_Y) |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 374 | cursor->Move(0, ev.value); |
| 375 | |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 376 | if (touch_status) { |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 377 | cursor->GetPos(x, y); |
| 378 | LOGEVENT("Mouse TOUCH_DRAG: %d, %d\n", x, y); |
| 379 | key_status = KS_NONE; |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 380 | } |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | void InputHandler::handleDrag() |
| 384 | { |
| 385 | // This allows us to only send one NotifyTouch event per render |
| 386 | // cycle to reduce overhead and perceived input latency. |
| 387 | static int prevx = 0, prevy = 0; // these track where the last drag notice was so that we don't send duplicate drag notices |
| 388 | if (touch_status && (x != prevx || y != prevy)) { |
| 389 | prevx = x; |
| 390 | prevy = y; |
| 391 | if (PageManager::NotifyTouch(TOUCH_DRAG, x, y) > 0) |
| 392 | state = AS_NO_ACTION; |
| 393 | else |
| 394 | state = AS_IN_ACTION_AREA; |
| 395 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 396 | } |
| 397 | |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 398 | static void setup_ors_command() |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 399 | { |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 400 | ors_read_fd = -1; |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 401 | |
| 402 | unlink(ORS_INPUT_FILE); |
| 403 | if (mkfifo(ORS_INPUT_FILE, 06660) != 0) { |
| 404 | LOGINFO("Unable to mkfifo %s\n", ORS_INPUT_FILE); |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 405 | return; |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 406 | } |
| 407 | unlink(ORS_OUTPUT_FILE); |
| 408 | if (mkfifo(ORS_OUTPUT_FILE, 06666) != 0) { |
| 409 | LOGINFO("Unable to mkfifo %s\n", ORS_OUTPUT_FILE); |
| 410 | unlink(ORS_INPUT_FILE); |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 411 | return; |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 412 | } |
| 413 | |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 414 | ors_read_fd = open(ORS_INPUT_FILE, O_RDONLY | O_NONBLOCK); |
| 415 | if (ors_read_fd < 0) { |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 416 | LOGINFO("Unable to open %s\n", ORS_INPUT_FILE); |
| 417 | unlink(ORS_INPUT_FILE); |
| 418 | unlink(ORS_OUTPUT_FILE); |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 419 | } |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 420 | } |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 421 | |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 422 | // callback called after a CLI command was executed |
| 423 | static void ors_command_done() |
| 424 | { |
| 425 | gui_set_FILE(NULL); |
| 426 | fclose(orsout); |
| 427 | orsout = NULL; |
| 428 | |
| 429 | if (DataManager::GetIntValue("tw_page_done") == 0) { |
| 430 | // The select function will return ready to read and the |
| 431 | // read function will return errno 19 no such device unless |
| 432 | // we set everything up all over again. |
| 433 | close(ors_read_fd); |
| 434 | setup_ors_command(); |
| 435 | } |
| 436 | } |
| 437 | |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 438 | static void ors_command_read() |
| 439 | { |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 440 | char command[1024]; |
| 441 | int read_ret = read(ors_read_fd, &command, sizeof(command)); |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 442 | |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 443 | if (read_ret > 0) { |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 444 | command[1022] = '\n'; |
| 445 | command[1023] = '\0'; |
| 446 | LOGINFO("Command '%s' received\n", command); |
| 447 | orsout = fopen(ORS_OUTPUT_FILE, "w"); |
| 448 | if (!orsout) { |
| 449 | close(ors_read_fd); |
| 450 | ors_read_fd = -1; |
| 451 | LOGINFO("Unable to fopen %s\n", ORS_OUTPUT_FILE); |
| 452 | unlink(ORS_INPUT_FILE); |
| 453 | unlink(ORS_OUTPUT_FILE); |
| 454 | return; |
| 455 | } |
| 456 | if (DataManager::GetIntValue("tw_busy") != 0) { |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 457 | fputs("Failed, operation in progress\n", orsout); |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 458 | LOGINFO("Command cannot be performed, operation in progress.\n"); |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 459 | fclose(orsout); |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 460 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 461 | if (strlen(command) == 11 && strncmp(command, "dumpstrings", 11) == 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 462 | gui_set_FILE(orsout); |
| 463 | PageManager::GetResources()->DumpStrings(); |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 464 | ors_command_done(); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 465 | //check to see if we should show backup page for parsing adbbackup partitions |
| 466 | } else if (strlen(command) == 23 && strncmp(command, "adbbackup", 9) == 0) { |
| 467 | gui_set_FILE(orsout); |
| 468 | DataManager::SetValue("tw_action", "twcmd"); |
| 469 | DataManager::SetValue("tw_action_param", command); |
| 470 | DataManager::SetValue("tw_enable_adb_backup", 1); |
| 471 | gui_changePage("backup"); |
| 472 | ors_command_done(); |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 473 | } else { |
| 474 | // mirror output messages |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 475 | gui_set_FILE(orsout); |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 476 | // close orsout and restart listener after command is done |
| 477 | OpenRecoveryScript::Call_After_CLI_Command(ors_command_done); |
| 478 | // run the command in a threaded action... |
| 479 | DataManager::SetValue("tw_action", "twcmd"); |
| 480 | DataManager::SetValue("tw_action_param", command); |
| 481 | // ...and switch back to the current page when finished |
| 482 | std::string currentPage = PageManager::GetCurrentPage(); |
| 483 | DataManager::SetValue("tw_has_action2", "1"); |
| 484 | DataManager::SetValue("tw_action2", "page"); |
| 485 | DataManager::SetValue("tw_action2_param", currentPage); |
| 486 | DataManager::SetValue("tw_action_text1", gui_lookup("running_recovery_commands", "Running Recovery Commands")); |
| 487 | DataManager::SetValue("tw_action_text2", ""); |
| 488 | gui_changePage("singleaction_page"); |
| 489 | // now immediately return to the GUI main loop (the action runs in the background thread) |
| 490 | // put all things that need to be done after the command is finished into ors_command_done, not here |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 491 | } |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 492 | } |
| 493 | } |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 494 | } |
| 495 | |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 496 | // Get and dispatch input events until it's time to draw the next frame |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 497 | // This special function will return immediately the first time, but then |
| 498 | // always returns 1/30th of a second (or immediately if called later) from |
| 499 | // the last time it was called |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 500 | static void loopTimer(int input_timeout_ms) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 501 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 502 | static timespec lastCall; |
| 503 | static int initialized = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 504 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 505 | if (!initialized) |
Dees_Troy | c8b199c | 2012-09-24 11:55:07 -0400 | [diff] [blame] | 506 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 507 | clock_gettime(CLOCK_MONOTONIC, &lastCall); |
| 508 | initialized = 1; |
| 509 | return; |
Dees_Troy | c8b199c | 2012-09-24 11:55:07 -0400 | [diff] [blame] | 510 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 511 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 512 | do |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 513 | { |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 514 | bool got_event = input_handler.processInput(input_timeout_ms); // get inputs but don't send drag notices |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 515 | timespec curTime; |
| 516 | clock_gettime(CLOCK_MONOTONIC, &curTime); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 517 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 518 | timespec diff = TWFunc::timespec_diff(lastCall, curTime); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 519 | |
that | c5837f3 | 2015-02-01 01:59:43 +0100 | [diff] [blame] | 520 | // This is really 2 or 30 times per second |
| 521 | // As long as we get events, increase the timeout so we can catch up with input |
| 522 | long timeout = got_event ? 500000000 : 33333333; |
| 523 | |
| 524 | if (diff.tv_sec || diff.tv_nsec > timeout) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 525 | { |
that | c5837f3 | 2015-02-01 01:59:43 +0100 | [diff] [blame] | 526 | // int32_t input_time = TWFunc::timespec_diff_ms(lastCall, curTime); |
| 527 | // LOGINFO("loopTimer(): %u ms, count: %u\n", input_time, count); |
| 528 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 529 | lastCall = curTime; |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 530 | input_handler.handleDrag(); // send only drag notices if needed |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 531 | return; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 532 | } |
| 533 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 534 | // We need to sleep some period time microseconds |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 535 | //unsigned int sleepTime = 33333 -(diff.tv_nsec / 1000); |
| 536 | //usleep(sleepTime); // removed so we can scan for input |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 537 | input_timeout_ms = 0; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 538 | } while (1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 539 | } |
| 540 | |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 541 | static int runPages(const char *page_name, const int stop_on_page_done) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 542 | { |
Ethan Yonker | 3f15be4 | 2015-02-09 09:39:47 -0600 | [diff] [blame] | 543 | DataManager::SetValue("tw_page_done", 0); |
| 544 | DataManager::SetValue("tw_gui_done", 0); |
| 545 | |
Ethan Yonker | afde098 | 2016-01-23 08:55:35 -0600 | [diff] [blame] | 546 | if (page_name) { |
| 547 | PageManager::SetStartPage(page_name); |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 548 | gui_changePage(page_name); |
Ethan Yonker | afde098 | 2016-01-23 08:55:35 -0600 | [diff] [blame] | 549 | } |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 550 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 551 | gGuiRunning = 1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 552 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 553 | DataManager::SetValue("tw_loaded", 1); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 554 | |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 555 | struct timeval timeout; |
| 556 | fd_set fdset; |
| 557 | int has_data = 0; |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 558 | |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 559 | int input_timeout_ms = 0; |
| 560 | int idle_frames = 0; |
| 561 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 562 | for (;;) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 563 | { |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 564 | loopTimer(input_timeout_ms); |
that | 1964d19 | 2016-01-07 00:41:03 +0100 | [diff] [blame] | 565 | if (g_pty_fd > 0) { |
| 566 | // TODO: this is not nice, we should have one central select for input, pty, and ors |
| 567 | FD_ZERO(&fdset); |
| 568 | FD_SET(g_pty_fd, &fdset); |
| 569 | timeout.tv_sec = 0; |
| 570 | timeout.tv_usec = 1; |
| 571 | has_data = select(g_pty_fd+1, &fdset, NULL, NULL, &timeout); |
| 572 | if (has_data > 0) { |
| 573 | terminal_pty_read(); |
| 574 | } |
| 575 | } |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 576 | #ifndef TW_OEM_BUILD |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 577 | if (ors_read_fd > 0 && !orsout) { // orsout is non-NULL if a command is still running |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 578 | FD_ZERO(&fdset); |
| 579 | FD_SET(ors_read_fd, &fdset); |
| 580 | timeout.tv_sec = 0; |
| 581 | timeout.tv_usec = 1; |
| 582 | has_data = select(ors_read_fd+1, &fdset, NULL, NULL, &timeout); |
| 583 | if (has_data > 0) { |
| 584 | ors_command_read(); |
| 585 | } |
| 586 | } |
| 587 | #endif |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 588 | |
Ethan Yonker | 0453695 | 2015-01-27 08:41:28 -0600 | [diff] [blame] | 589 | if (!gForceRender.get_value()) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 590 | { |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 591 | int ret = PageManager::Update(); |
| 592 | if (ret == 0) |
| 593 | ++idle_frames; |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 594 | else if (ret == -2) |
| 595 | break; // Theme reload failure |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 596 | else |
| 597 | idle_frames = 0; |
| 598 | // due to possible animation objects, we need to delay activating the input timeout |
| 599 | input_timeout_ms = idle_frames > 15 ? 1000 : 0; |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 600 | |
| 601 | #ifndef PRINT_RENDER_TIME |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 602 | if (ret > 1) |
| 603 | PageManager::Render(); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 604 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 605 | if (ret > 0) |
| 606 | flip(); |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 607 | #else |
| 608 | if (ret > 1) |
| 609 | { |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 610 | timespec start, end; |
| 611 | int32_t render_t, flip_t; |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 612 | clock_gettime(CLOCK_MONOTONIC, &start); |
| 613 | PageManager::Render(); |
| 614 | clock_gettime(CLOCK_MONOTONIC, &end); |
| 615 | render_t = TWFunc::timespec_diff_ms(start, end); |
| 616 | |
| 617 | flip(); |
| 618 | clock_gettime(CLOCK_MONOTONIC, &start); |
| 619 | flip_t = TWFunc::timespec_diff_ms(end, start); |
| 620 | |
| 621 | LOGINFO("Render(): %u ms, flip(): %u ms, total: %u ms\n", render_t, flip_t, render_t+flip_t); |
| 622 | } |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 623 | else if (ret > 0) |
Vojtech Bocek | e5ffcd1 | 2014-02-06 21:17:32 +0100 | [diff] [blame] | 624 | flip(); |
| 625 | #endif |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 626 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 627 | else |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 628 | { |
Ethan Yonker | 0453695 | 2015-01-27 08:41:28 -0600 | [diff] [blame] | 629 | gForceRender.set_value(0); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 630 | PageManager::Render(); |
| 631 | flip(); |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 632 | input_timeout_ms = 0; |
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 | |
that | fb759d4 | 2015-01-11 12:16:53 +0100 | [diff] [blame] | 635 | blankTimer.checkForTimeout(); |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 636 | if (stop_on_page_done && DataManager::GetIntValue("tw_page_done") != 0) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 637 | { |
| 638 | gui_changePage("main"); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 639 | break; |
| 640 | } |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 641 | if (DataManager::GetIntValue("tw_gui_done") != 0) |
| 642 | break; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 643 | } |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 644 | if (ors_read_fd > 0) |
| 645 | close(ors_read_fd); |
| 646 | ors_read_fd = -1; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 647 | gGuiRunning = 0; |
| 648 | return 0; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 649 | } |
| 650 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 651 | int gui_forceRender(void) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 652 | { |
Ethan Yonker | 0453695 | 2015-01-27 08:41:28 -0600 | [diff] [blame] | 653 | gForceRender.set_value(1); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 654 | return 0; |
| 655 | } |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 656 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 657 | int gui_changePage(std::string newPage) |
| 658 | { |
| 659 | LOGINFO("Set page: '%s'\n", newPage.c_str()); |
| 660 | PageManager::ChangePage(newPage); |
Ethan Yonker | 0453695 | 2015-01-27 08:41:28 -0600 | [diff] [blame] | 661 | gForceRender.set_value(1); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 662 | return 0; |
| 663 | } |
| 664 | |
| 665 | int gui_changeOverlay(std::string overlay) |
| 666 | { |
Ethan Yonker | 1c27331 | 2015-03-16 12:18:56 -0500 | [diff] [blame] | 667 | LOGINFO("Set overlay: '%s'\n", overlay.c_str()); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 668 | PageManager::ChangeOverlay(overlay); |
Ethan Yonker | 0453695 | 2015-01-27 08:41:28 -0600 | [diff] [blame] | 669 | gForceRender.set_value(1); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 670 | return 0; |
| 671 | } |
| 672 | |
that | b2e8f67 | 2015-03-05 20:25:39 +0100 | [diff] [blame] | 673 | std::string gui_parse_text(std::string str) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 674 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 675 | // This function parses text for DataManager values encompassed by %value% in the XML |
that | b2e8f67 | 2015-03-05 20:25:39 +0100 | [diff] [blame] | 676 | // and string resources (%@resource_name%) |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 677 | size_t pos = 0, next, end; |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 678 | |
| 679 | while (1) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 680 | { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 681 | next = str.find("{@", pos); |
| 682 | if (next == std::string::npos) |
| 683 | break; |
| 684 | |
| 685 | end = str.find('}', next + 1); |
| 686 | if (end == std::string::npos) |
| 687 | break; |
| 688 | |
| 689 | std::string var = str.substr(next + 2, (end - next) - 2); |
| 690 | str.erase(next, (end - next) + 1); |
| 691 | |
| 692 | size_t default_loc = var.find('=', 0); |
| 693 | std::string lookup; |
| 694 | if (default_loc == std::string::npos) { |
| 695 | str.insert(next, PageManager::GetResources()->FindString(var)); |
| 696 | } else { |
| 697 | lookup = var.substr(0, default_loc); |
| 698 | std::string default_string = var.substr(default_loc + 1, var.size() - default_loc - 1); |
| 699 | str.insert(next, PageManager::GetResources()->FindString(lookup, default_string)); |
| 700 | } |
| 701 | } |
| 702 | pos = 0; |
| 703 | while (1) |
| 704 | { |
| 705 | next = str.find('%', pos); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 706 | if (next == std::string::npos) |
| 707 | return str; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 708 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 709 | end = str.find('%', next + 1); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 710 | if (end == std::string::npos) |
| 711 | return str; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 712 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 713 | // We have a block of data |
that | b2e8f67 | 2015-03-05 20:25:39 +0100 | [diff] [blame] | 714 | std::string var = str.substr(next + 1, (end - next) - 1); |
| 715 | str.erase(next, (end - next) + 1); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 716 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 717 | if (next + 1 == end) |
| 718 | str.insert(next, 1, '%'); |
| 719 | else |
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 | std::string value; |
that | b2e8f67 | 2015-03-05 20:25:39 +0100 | [diff] [blame] | 722 | if (var.size() > 0 && var[0] == '@') { |
| 723 | // this is a string resource ("%@string_name%") |
| 724 | value = PageManager::GetResources()->FindString(var.substr(1)); |
| 725 | str.insert(next, value); |
| 726 | } |
| 727 | else if (DataManager::GetValue(var, value) == 0) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 728 | str.insert(next, value); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 729 | } |
| 730 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 731 | pos = next + 1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 732 | } |
| 733 | } |
| 734 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 735 | std::string gui_lookup(const std::string& resource_name, const std::string& default_value) { |
| 736 | return PageManager::GetResources()->FindString(resource_name, default_value); |
| 737 | } |
| 738 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 739 | extern "C" int gui_init(void) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 740 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 741 | gr_init(); |
Matt Mower | b26c116 | 2016-02-03 21:05:57 -0600 | [diff] [blame] | 742 | TWFunc::Set_Brightness(DataManager::GetStrValue("tw_brightness")); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 743 | |
that | 235c648 | 2016-01-24 21:59:00 +0100 | [diff] [blame] | 744 | // load and show splash screen |
| 745 | if (PageManager::LoadPackage("splash", TWRES "splash.xml", "splash")) { |
| 746 | LOGERR("Failed to load splash screen XML.\n"); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 747 | } |
that | 235c648 | 2016-01-24 21:59:00 +0100 | [diff] [blame] | 748 | else { |
| 749 | PageManager::SelectPackage("splash"); |
| 750 | PageManager::Render(); |
| 751 | flip(); |
| 752 | PageManager::ReleasePackage("splash"); |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 753 | } |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 754 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 755 | ev_init(); |
| 756 | return 0; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 757 | } |
| 758 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 759 | extern "C" int gui_loadResources(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 760 | { |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 761 | #ifndef TW_OEM_BUILD |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 762 | int check = 0; |
| 763 | DataManager::GetValue(TW_IS_ENCRYPTED, check); |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 764 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 765 | if (check) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 766 | { |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 767 | if (PageManager::LoadPackage("TWRP", TWRES "ui.xml", "decrypt")) |
Dees_Troy | 5bf4392 | 2012-09-07 16:07:55 -0400 | [diff] [blame] | 768 | { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 769 | gui_err("base_pkg_err=Failed to load base packages."); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 770 | goto error; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 771 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 772 | else |
| 773 | check = 1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 774 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 775 | |
Ethan Yonker | 86404bd | 2016-03-31 08:01:05 -0500 | [diff] [blame] | 776 | if (check == 0) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 777 | { |
| 778 | std::string theme_path; |
| 779 | |
| 780 | theme_path = DataManager::GetSettingsStoragePath(); |
| 781 | if (!PartitionManager.Mount_Settings_Storage(false)) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 782 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 783 | int retry_count = 5; |
| 784 | while (retry_count > 0 && !PartitionManager.Mount_Settings_Storage(false)) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 785 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 786 | usleep(500000); |
| 787 | retry_count--; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 788 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 789 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 790 | if (!PartitionManager.Mount_Settings_Storage(true)) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 791 | { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 792 | LOGINFO("Unable to mount %s during GUI startup.\n", theme_path.c_str()); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 793 | check = 1; |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 794 | } |
| 795 | } |
| 796 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 797 | theme_path += "/TWRP/theme/ui.zip"; |
| 798 | if (check || PageManager::LoadPackage("TWRP", theme_path, "main")) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 799 | { |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 800 | #endif // ifndef TW_OEM_BUILD |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 801 | if (PageManager::LoadPackage("TWRP", TWRES "ui.xml", "main")) |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 802 | { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 803 | gui_err("base_pkg_err=Failed to load base packages."); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 804 | goto error; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 805 | } |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 806 | #ifndef TW_OEM_BUILD |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 807 | } |
| 808 | } |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 809 | #endif // ifndef TW_OEM_BUILD |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 810 | // Set the default package |
| 811 | PageManager::SelectPackage("TWRP"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 812 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 813 | gGuiInitialized = 1; |
| 814 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 815 | |
| 816 | error: |
Ethan Yonker | 83e8257 | 2014-04-04 10:59:28 -0500 | [diff] [blame] | 817 | LOGERR("An internal error has occurred: unable to load theme.\n"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 818 | gGuiInitialized = 0; |
| 819 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 820 | } |
| 821 | |
Ethan Yonker | cf50da5 | 2015-01-12 21:59:07 -0600 | [diff] [blame] | 822 | extern "C" int gui_loadCustomResources(void) |
| 823 | { |
| 824 | #ifndef TW_OEM_BUILD |
| 825 | if (!PartitionManager.Mount_Settings_Storage(false)) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 826 | LOGINFO("Unable to mount settings storage during GUI startup.\n"); |
Ethan Yonker | cf50da5 | 2015-01-12 21:59:07 -0600 | [diff] [blame] | 827 | return -1; |
| 828 | } |
| 829 | |
| 830 | std::string theme_path = DataManager::GetSettingsStoragePath(); |
| 831 | theme_path += "/TWRP/theme/ui.zip"; |
| 832 | // Check for a custom theme |
| 833 | if (TWFunc::Path_Exists(theme_path)) { |
| 834 | // There is a custom theme, try to load it |
| 835 | if (PageManager::ReloadPackage("TWRP", theme_path)) { |
| 836 | // Custom theme failed to load, try to load stock theme |
Dees Troy | 3454ade | 2015-01-20 19:21:04 +0000 | [diff] [blame] | 837 | if (PageManager::ReloadPackage("TWRP", TWRES "ui.xml")) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 838 | gui_err("base_pkg_err=Failed to load base packages."); |
Ethan Yonker | cf50da5 | 2015-01-12 21:59:07 -0600 | [diff] [blame] | 839 | goto error; |
| 840 | } |
| 841 | } |
| 842 | } |
| 843 | // Set the default package |
| 844 | PageManager::SelectPackage("TWRP"); |
| 845 | #endif |
| 846 | return 0; |
| 847 | |
| 848 | error: |
| 849 | LOGERR("An internal error has occurred: unable to load theme.\n"); |
| 850 | gGuiInitialized = 0; |
| 851 | return -1; |
| 852 | } |
| 853 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 854 | extern "C" int gui_start(void) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 855 | { |
Ethan Yonker | afde098 | 2016-01-23 08:55:35 -0600 | [diff] [blame] | 856 | return gui_startPage("main", 1, 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 857 | } |
| 858 | |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 859 | extern "C" int gui_startPage(const char *page_name, const int allow_commands, int stop_on_page_done) |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 860 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 861 | if (!gGuiInitialized) |
| 862 | return -1; |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 863 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 864 | // Set the default package |
| 865 | PageManager::SelectPackage("TWRP"); |
| 866 | |
that | 9fa5153 | 2015-01-29 02:04:47 +0100 | [diff] [blame] | 867 | input_handler.init(); |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 868 | #ifndef TW_OEM_BUILD |
| 869 | if (allow_commands) |
| 870 | { |
| 871 | if (ors_read_fd < 0) |
| 872 | setup_ors_command(); |
| 873 | } else { |
| 874 | if (ors_read_fd >= 0) { |
| 875 | close(ors_read_fd); |
| 876 | ors_read_fd = -1; |
| 877 | } |
| 878 | } |
| 879 | #endif |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 880 | return runPages(page_name, stop_on_page_done); |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 881 | } |
| 882 | |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 883 | |
| 884 | extern "C" void set_scale_values(float w, float h) |
| 885 | { |
| 886 | scale_theme_w = w; |
| 887 | scale_theme_h = h; |
| 888 | } |
| 889 | |
| 890 | extern "C" int scale_theme_x(int initial_x) |
| 891 | { |
| 892 | if (scale_theme_w != 1) { |
that | ba75a0e | 2015-02-14 21:20:10 +0100 | [diff] [blame] | 893 | int scaled = (float)initial_x * scale_theme_w; |
| 894 | if (scaled == 0 && initial_x > 0) |
| 895 | return 1; |
| 896 | return scaled; |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 897 | } |
| 898 | return initial_x; |
| 899 | } |
| 900 | |
| 901 | extern "C" int scale_theme_y(int initial_y) |
| 902 | { |
| 903 | if (scale_theme_h != 1) { |
that | ba75a0e | 2015-02-14 21:20:10 +0100 | [diff] [blame] | 904 | int scaled = (float)initial_y * scale_theme_h; |
| 905 | if (scaled == 0 && initial_y > 0) |
| 906 | return 1; |
| 907 | return scaled; |
Ethan Yonker | 63e414f | 2015-02-06 15:44:39 -0600 | [diff] [blame] | 908 | } |
| 909 | return initial_y; |
| 910 | } |
| 911 | |
| 912 | extern "C" int scale_theme_min(int initial_value) |
| 913 | { |
| 914 | if (scale_theme_w != 1 || scale_theme_h != 1) { |
| 915 | if (scale_theme_w < scale_theme_h) |
| 916 | return scale_theme_x(initial_value); |
| 917 | else |
| 918 | return scale_theme_y(initial_value); |
| 919 | } |
| 920 | return initial_value; |
| 921 | } |
| 922 | |
| 923 | extern "C" float get_scale_w() |
| 924 | { |
| 925 | return scale_theme_w; |
| 926 | } |
| 927 | |
| 928 | extern "C" float get_scale_h() |
| 929 | { |
| 930 | return scale_theme_h; |
| 931 | } |