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