Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <fcntl.h> |
| 20 | #include <dirent.h> |
| 21 | #include <sys/poll.h> |
| 22 | #include <limits.h> |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 23 | #include <linux/input.h> |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 24 | #include <sys/types.h> |
| 25 | #include <sys/stat.h> |
| 26 | #include <unistd.h> |
| 27 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 28 | |
| 29 | #include "../common.h" |
| 30 | |
| 31 | #include "minui.h" |
| 32 | |
| 33 | //#define _EVENT_LOGGING |
| 34 | |
Dees_Troy | 3f23d9e | 2013-05-03 21:04:05 +0000 | [diff] [blame] | 35 | #define MAX_DEVICES 32 |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 36 | |
| 37 | #define VIBRATOR_TIMEOUT_FILE "/sys/class/timed_output/vibrator/enable" |
| 38 | #define VIBRATOR_TIME_MS 50 |
| 39 | |
Dees_Troy | f759675 | 2012-09-28 13:21:36 -0400 | [diff] [blame] | 40 | #ifndef SYN_REPORT |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 41 | #define SYN_REPORT 0x00 |
Dees_Troy | f759675 | 2012-09-28 13:21:36 -0400 | [diff] [blame] | 42 | #endif |
| 43 | #ifndef SYN_CONFIG |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 44 | #define SYN_CONFIG 0x01 |
Dees_Troy | f759675 | 2012-09-28 13:21:36 -0400 | [diff] [blame] | 45 | #endif |
| 46 | #ifndef SYN_MT_REPORT |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 47 | #define SYN_MT_REPORT 0x02 |
Dees_Troy | f759675 | 2012-09-28 13:21:36 -0400 | [diff] [blame] | 48 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 49 | |
| 50 | #define ABS_MT_POSITION 0x2a /* Group a set of X and Y */ |
| 51 | #define ABS_MT_AMPLITUDE 0x2b /* Group a set of Z and W */ |
| 52 | #define ABS_MT_SLOT 0x2f |
| 53 | #define ABS_MT_TOUCH_MAJOR 0x30 |
| 54 | #define ABS_MT_TOUCH_MINOR 0x31 |
| 55 | #define ABS_MT_WIDTH_MAJOR 0x32 |
| 56 | #define ABS_MT_WIDTH_MINOR 0x33 |
| 57 | #define ABS_MT_ORIENTATION 0x34 |
| 58 | #define ABS_MT_POSITION_X 0x35 |
| 59 | #define ABS_MT_POSITION_Y 0x36 |
| 60 | #define ABS_MT_TOOL_TYPE 0x37 |
| 61 | #define ABS_MT_BLOB_ID 0x38 |
| 62 | #define ABS_MT_TRACKING_ID 0x39 |
| 63 | #define ABS_MT_PRESSURE 0x3a |
| 64 | #define ABS_MT_DISTANCE 0x3b |
| 65 | |
| 66 | enum { |
| 67 | DOWN_NOT, |
| 68 | DOWN_SENT, |
| 69 | DOWN_RELEASED, |
| 70 | }; |
| 71 | |
| 72 | struct virtualkey { |
| 73 | int scancode; |
| 74 | int centerx, centery; |
| 75 | int width, height; |
| 76 | }; |
| 77 | |
| 78 | struct position { |
| 79 | int x, y; |
| 80 | int synced; |
| 81 | struct input_absinfo xi, yi; |
| 82 | }; |
| 83 | |
| 84 | struct ev { |
| 85 | struct pollfd *fd; |
| 86 | |
| 87 | struct virtualkey *vks; |
| 88 | int vk_count; |
| 89 | |
| 90 | char deviceName[64]; |
| 91 | |
| 92 | int ignored; |
| 93 | |
| 94 | struct position p, mt_p; |
| 95 | int down; |
| 96 | }; |
| 97 | |
| 98 | static struct pollfd ev_fds[MAX_DEVICES]; |
| 99 | static struct ev evs[MAX_DEVICES]; |
| 100 | static unsigned ev_count = 0; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 101 | static struct timeval lastInputStat; |
| 102 | static unsigned long lastInputMTime; |
| 103 | static int has_mouse = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 104 | |
| 105 | static inline int ABS(int x) { |
| 106 | return x<0?-x:x; |
| 107 | } |
| 108 | |
| 109 | int vibrate(int timeout_ms) |
| 110 | { |
| 111 | char str[20]; |
| 112 | int fd; |
| 113 | int ret; |
| 114 | |
Samer Diab (S.a.M.e.R_d) | 71e9b04 | 2014-01-07 20:18:47 +0000 | [diff] [blame] | 115 | if (timeout_ms > 10000) timeout_ms = 1000; |
| 116 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 117 | fd = open(VIBRATOR_TIMEOUT_FILE, O_WRONLY); |
| 118 | if (fd < 0) |
| 119 | return -1; |
| 120 | |
| 121 | ret = snprintf(str, sizeof(str), "%d", timeout_ms); |
| 122 | ret = write(fd, str, ret); |
| 123 | close(fd); |
| 124 | |
| 125 | if (ret < 0) |
| 126 | return -1; |
| 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | /* Returns empty tokens */ |
| 132 | static char *vk_strtok_r(char *str, const char *delim, char **save_str) |
| 133 | { |
| 134 | if(!str) |
| 135 | { |
| 136 | if(!*save_str) |
| 137 | return NULL; |
| 138 | |
| 139 | str = (*save_str) + 1; |
| 140 | } |
| 141 | *save_str = strpbrk(str, delim); |
| 142 | |
| 143 | if (*save_str) |
| 144 | **save_str = '\0'; |
| 145 | |
| 146 | return str; |
| 147 | } |
| 148 | |
| 149 | static int vk_init(struct ev *e) |
| 150 | { |
| 151 | char vk_path[PATH_MAX] = "/sys/board_properties/virtualkeys."; |
| 152 | char vks[2048], *ts = NULL; |
| 153 | ssize_t len; |
| 154 | int vk_fd; |
| 155 | int i; |
| 156 | |
| 157 | e->vk_count = 0; |
| 158 | |
| 159 | len = strlen(vk_path); |
| 160 | len = ioctl(e->fd->fd, EVIOCGNAME(sizeof(e->deviceName)), e->deviceName); |
| 161 | if (len <= 0) |
| 162 | { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 163 | printf("Unable to query event object.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 164 | return -1; |
| 165 | } |
| 166 | #ifdef _EVENT_LOGGING |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 167 | printf("Event object: %s\n", e->deviceName); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 168 | #endif |
| 169 | |
Flemmard | f467461 | 2014-01-10 09:14:44 +0100 | [diff] [blame] | 170 | #ifdef WHITELIST_INPUT |
| 171 | if (strcmp(e->deviceName, EXPAND(WHITELIST_INPUT)) != 0) |
| 172 | { |
| 173 | e->ignored = 1; |
| 174 | } |
| 175 | #else |
Ethan Yonker | 5742a40 | 2014-08-12 14:52:49 -0500 | [diff] [blame] | 176 | #ifndef TW_INPUT_BLACKLIST |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 177 | // Blacklist these "input" devices |
Ethan Yonker | 3c4ac3b | 2014-08-14 11:15:32 -0500 | [diff] [blame] | 178 | if (strcmp(e->deviceName, "bma250") == 0 || strcmp(e->deviceName, "bma150") == 0) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 179 | { |
Ethan Yonker | 5742a40 | 2014-08-12 14:52:49 -0500 | [diff] [blame] | 180 | printf("blacklisting %s input device\n", e->deviceName); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 181 | e->ignored = 1; |
| 182 | } |
Ethan Yonker | 5742a40 | 2014-08-12 14:52:49 -0500 | [diff] [blame] | 183 | #else |
| 184 | char* bl = strdup(EXPAND(TW_INPUT_BLACKLIST)); |
| 185 | char* blacklist = strtok(bl, "\n"); |
| 186 | |
| 187 | while (blacklist != NULL) { |
| 188 | if (strcmp(e->deviceName, blacklist) == 0) { |
| 189 | printf("blacklisting %s input device\n", blacklist); |
| 190 | e->ignored = 1; |
| 191 | } |
| 192 | blacklist = strtok(NULL, "\n"); |
| 193 | } |
| 194 | free(bl); |
| 195 | #endif |
Flemmard | f467461 | 2014-01-10 09:14:44 +0100 | [diff] [blame] | 196 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 197 | |
| 198 | strcat(vk_path, e->deviceName); |
| 199 | |
| 200 | // Some devices split the keys from the touchscreen |
| 201 | e->vk_count = 0; |
| 202 | vk_fd = open(vk_path, O_RDONLY); |
| 203 | if (vk_fd >= 0) |
| 204 | { |
| 205 | len = read(vk_fd, vks, sizeof(vks)-1); |
| 206 | close(vk_fd); |
| 207 | if (len <= 0) |
| 208 | return -1; |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 209 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 210 | vks[len] = '\0'; |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 211 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 212 | /* Parse a line like: |
| 213 | keytype:keycode:centerx:centery:width:height:keytype2:keycode2:centerx2:... |
| 214 | */ |
| 215 | for (ts = vks, e->vk_count = 1; *ts; ++ts) { |
| 216 | if (*ts == ':') |
| 217 | ++e->vk_count; |
| 218 | } |
| 219 | |
| 220 | if (e->vk_count % 6) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 221 | printf("minui: %s is %d %% 6\n", vk_path, e->vk_count % 6); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 222 | } |
| 223 | e->vk_count /= 6; |
| 224 | if (e->vk_count <= 0) |
| 225 | return -1; |
| 226 | |
| 227 | e->down = DOWN_NOT; |
| 228 | } |
| 229 | |
| 230 | ioctl(e->fd->fd, EVIOCGABS(ABS_X), &e->p.xi); |
| 231 | ioctl(e->fd->fd, EVIOCGABS(ABS_Y), &e->p.yi); |
| 232 | e->p.synced = 0; |
| 233 | #ifdef _EVENT_LOGGING |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 234 | printf("EV: ST minX: %d maxX: %d minY: %d maxY: %d\n", e->p.xi.minimum, e->p.xi.maximum, e->p.yi.minimum, e->p.yi.maximum); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 235 | #endif |
| 236 | |
| 237 | ioctl(e->fd->fd, EVIOCGABS(ABS_MT_POSITION_X), &e->mt_p.xi); |
| 238 | ioctl(e->fd->fd, EVIOCGABS(ABS_MT_POSITION_Y), &e->mt_p.yi); |
| 239 | e->mt_p.synced = 0; |
| 240 | #ifdef _EVENT_LOGGING |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 241 | printf("EV: MT minX: %d maxX: %d minY: %d maxY: %d\n", e->mt_p.xi.minimum, e->mt_p.xi.maximum, e->mt_p.yi.minimum, e->mt_p.yi.maximum); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 242 | #endif |
| 243 | |
| 244 | e->vks = malloc(sizeof(*e->vks) * e->vk_count); |
| 245 | |
| 246 | for (i = 0; i < e->vk_count; ++i) { |
| 247 | char *token[6]; |
| 248 | int j; |
| 249 | |
| 250 | for (j = 0; j < 6; ++j) { |
| 251 | token[j] = vk_strtok_r((i||j)?NULL:vks, ":", &ts); |
| 252 | } |
| 253 | |
| 254 | if (strcmp(token[0], "0x01") != 0) { |
| 255 | /* Java does string compare, so we do too. */ |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 256 | printf("minui: %s: ignoring unknown virtual key type %s\n", vk_path, token[0]); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 257 | continue; |
| 258 | } |
| 259 | |
| 260 | e->vks[i].scancode = strtol(token[1], NULL, 0); |
| 261 | e->vks[i].centerx = strtol(token[2], NULL, 0); |
| 262 | e->vks[i].centery = strtol(token[3], NULL, 0); |
| 263 | e->vks[i].width = strtol(token[4], NULL, 0); |
| 264 | e->vks[i].height = strtol(token[5], NULL, 0); |
| 265 | } |
| 266 | |
| 267 | return 0; |
| 268 | } |
| 269 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 270 | #define BITS_PER_LONG (sizeof(long) * 8) |
| 271 | #define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1) |
| 272 | #define OFF(x) ((x)%BITS_PER_LONG) |
| 273 | #define LONG(x) ((x)/BITS_PER_LONG) |
| 274 | #define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1) |
Vojtech Bocek | 971d318 | 2014-02-20 21:43:28 +0100 | [diff] [blame] | 275 | |
| 276 | // Check for EV_REL (REL_X and REL_Y) and, because touchscreens can have those too, |
| 277 | // check also for EV_KEY (BTN_LEFT and BTN_RIGHT) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 278 | static void check_mouse(int fd) |
| 279 | { |
| 280 | if(has_mouse) |
| 281 | return; |
| 282 | |
| 283 | unsigned long bit[EV_MAX][NBITS(KEY_MAX)]; |
| 284 | memset(bit, 0, sizeof(bit)); |
| 285 | ioctl(fd, EVIOCGBIT(0, EV_MAX), bit[0]); |
| 286 | |
Vojtech Bocek | 971d318 | 2014-02-20 21:43:28 +0100 | [diff] [blame] | 287 | if(!test_bit(EV_REL, bit[0]) || !test_bit(EV_KEY, bit[0])) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 288 | return; |
| 289 | |
| 290 | ioctl(fd, EVIOCGBIT(EV_REL, KEY_MAX), bit[EV_REL]); |
Vojtech Bocek | 971d318 | 2014-02-20 21:43:28 +0100 | [diff] [blame] | 291 | if(!test_bit(REL_X, bit[EV_REL]) || !test_bit(REL_Y, bit[EV_REL])) |
| 292 | return; |
| 293 | |
| 294 | ioctl(fd, EVIOCGBIT(EV_KEY, KEY_MAX), bit[EV_KEY]); |
| 295 | if(!test_bit(BTN_LEFT, bit[EV_KEY]) || !test_bit(BTN_RIGHT, bit[EV_KEY])) |
| 296 | return; |
| 297 | |
| 298 | has_mouse = 1; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | int ev_has_mouse(void) |
| 302 | { |
| 303 | return has_mouse; |
| 304 | } |
| 305 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 306 | int ev_init(void) |
| 307 | { |
| 308 | DIR *dir; |
| 309 | struct dirent *de; |
| 310 | int fd; |
| 311 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 312 | has_mouse = 0; |
| 313 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 314 | dir = opendir("/dev/input"); |
| 315 | if(dir != 0) { |
| 316 | while((de = readdir(dir))) { |
| 317 | // fprintf(stderr,"/dev/input/%s\n", de->d_name); |
| 318 | if(strncmp(de->d_name,"event",5)) continue; |
| 319 | fd = openat(dirfd(dir), de->d_name, O_RDONLY); |
| 320 | if(fd < 0) continue; |
| 321 | |
| 322 | ev_fds[ev_count].fd = fd; |
| 323 | ev_fds[ev_count].events = POLLIN; |
| 324 | evs[ev_count].fd = &ev_fds[ev_count]; |
| 325 | |
| 326 | /* Load virtualkeys if there are any */ |
| 327 | vk_init(&evs[ev_count]); |
| 328 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 329 | check_mouse(fd); |
| 330 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 331 | ev_count++; |
| 332 | if(ev_count == MAX_DEVICES) break; |
| 333 | } |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 334 | closedir(dir); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 335 | } |
| 336 | |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 337 | struct stat st; |
| 338 | if(stat("/dev/input", &st) >= 0) |
| 339 | lastInputMTime = st.st_mtime; |
| 340 | gettimeofday(&lastInputStat, NULL); |
| 341 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | void ev_exit(void) |
| 346 | { |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 347 | while (ev_count-- > 0) { |
| 348 | if (evs[ev_count].vk_count) { |
| 349 | free(evs[ev_count].vks); |
| 350 | evs[ev_count].vk_count = 0; |
| 351 | } |
| 352 | close(ev_fds[ev_count].fd); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 353 | } |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 354 | ev_count = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | static int vk_inside_display(__s32 value, struct input_absinfo *info, int screen_size) |
| 358 | { |
| 359 | int screen_pos; |
| 360 | |
| 361 | if (info->minimum == info->maximum) |
| 362 | return 0; |
| 363 | |
| 364 | screen_pos = (value - info->minimum) * (screen_size - 1) / (info->maximum - info->minimum); |
| 365 | return (screen_pos >= 0 && screen_pos < screen_size); |
| 366 | } |
| 367 | |
Dees_Troy | b7ecc09 | 2013-08-24 12:15:41 +0000 | [diff] [blame] | 368 | static int vk_tp_to_screen(struct position *p, int *x, int *y) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 369 | { |
| 370 | if (p->xi.minimum == p->xi.maximum || p->yi.minimum == p->yi.maximum) |
| 371 | { |
| 372 | // In this case, we assume the screen dimensions are the same. |
| 373 | *x = p->x; |
| 374 | *y = p->y; |
| 375 | return 0; |
| 376 | } |
| 377 | |
Dees_Troy | b7ecc09 | 2013-08-24 12:15:41 +0000 | [diff] [blame] | 378 | #ifdef _EVENT_LOGGING |
| 379 | printf("EV: p->x=%d x-range=%d,%d fb-width=%d\n", p->x, p->xi.minimum, p->xi.maximum, gr_fb_width()); |
| 380 | #endif |
| 381 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 382 | #ifndef RECOVERY_TOUCHSCREEN_SWAP_XY |
Dees_Troy | b7ecc09 | 2013-08-24 12:15:41 +0000 | [diff] [blame] | 383 | int fb_width = gr_fb_width(); |
| 384 | int fb_height = gr_fb_height(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 385 | #else |
| 386 | // We need to swap the scaling sizes, too |
Dees_Troy | b7ecc09 | 2013-08-24 12:15:41 +0000 | [diff] [blame] | 387 | int fb_width = gr_fb_height(); |
| 388 | int fb_height = gr_fb_width(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 389 | #endif |
| 390 | |
| 391 | *x = (p->x - p->xi.minimum) * (fb_width - 1) / (p->xi.maximum - p->xi.minimum); |
| 392 | *y = (p->y - p->yi.minimum) * (fb_height - 1) / (p->yi.maximum - p->yi.minimum); |
| 393 | |
| 394 | if (*x >= 0 && *x < fb_width && |
| 395 | *y >= 0 && *y < fb_height) |
| 396 | { |
| 397 | return 0; |
| 398 | } |
| 399 | |
| 400 | return 1; |
| 401 | } |
| 402 | |
| 403 | /* Translate a virtual key in to a real key event, if needed */ |
| 404 | /* Returns non-zero when the event should be consumed */ |
Dees_Troy | b7ecc09 | 2013-08-24 12:15:41 +0000 | [diff] [blame] | 405 | static int vk_modify(struct ev *e, struct input_event *ev) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 406 | { |
| 407 | static int downX = -1, downY = -1; |
| 408 | static int discard = 0; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 409 | static int last_virt_key = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 410 | static int lastWasSynReport = 0; |
| 411 | static int touchReleaseOnNextSynReport = 0; |
Dees_Troy | d86400b | 2013-05-13 19:04:35 +0000 | [diff] [blame] | 412 | static int use_tracking_id_negative_as_touch_release = 0; // On some devices, type: 3 code: 39 value: -1, aka EV_ABS ABS_MT_TRACKING_ID -1 indicates a true touch release |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 413 | int i; |
| 414 | int x, y; |
| 415 | |
| 416 | // This is used to ditch useless event handlers, like an accelerometer |
| 417 | if (e->ignored) return 1; |
| 418 | |
| 419 | if (ev->type == EV_REL && ev->code == REL_Z) |
| 420 | { |
| 421 | // This appears to be an accelerometer or another strange input device. It's not the touchscreen. |
| 422 | #ifdef _EVENT_LOGGING |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 423 | printf("EV: Device disabled due to non-touchscreen messages.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 424 | #endif |
| 425 | e->ignored = 1; |
| 426 | return 1; |
| 427 | } |
| 428 | |
| 429 | #ifdef _EVENT_LOGGING |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 430 | printf("EV: %s => type: %x code: %x value: %d\n", e->deviceName, ev->type, ev->code, ev->value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 431 | #endif |
| 432 | |
| 433 | // Handle keyboard events, value of 1 indicates key down, 0 indicates key up |
| 434 | if (ev->type == EV_KEY) { |
| 435 | return 0; |
| 436 | } |
| 437 | |
| 438 | if (ev->type == EV_ABS) { |
| 439 | switch (ev->code) { |
| 440 | |
| 441 | case ABS_X: //00 |
| 442 | e->p.synced |= 0x01; |
| 443 | e->p.x = ev->value; |
| 444 | #ifdef _EVENT_LOGGING |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 445 | printf("EV: %s => EV_ABS ABS_X %d\n", e->deviceName, ev->value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 446 | #endif |
| 447 | break; |
| 448 | |
| 449 | case ABS_Y: //01 |
| 450 | e->p.synced |= 0x02; |
| 451 | e->p.y = ev->value; |
| 452 | #ifdef _EVENT_LOGGING |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 453 | printf("EV: %s => EV_ABS ABS_Y %d\n", e->deviceName, ev->value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 454 | #endif |
| 455 | break; |
| 456 | |
| 457 | case ABS_MT_POSITION: //2a |
| 458 | e->mt_p.synced = 0x03; |
| 459 | if (ev->value == (1 << 31)) |
| 460 | { |
Ethan Yonker | 32f68a3 | 2014-12-29 08:13:23 -0600 | [diff] [blame] | 461 | #ifndef TW_IGNORE_MT_POSITION_0 |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 462 | e->mt_p.x = 0; |
| 463 | e->mt_p.y = 0; |
| 464 | lastWasSynReport = 1; |
Ethan Yonker | 32f68a3 | 2014-12-29 08:13:23 -0600 | [diff] [blame] | 465 | #endif |
| 466 | #ifdef _EVENT_LOGGING |
| 467 | #ifndef TW_IGNORE_MT_POSITION_0 |
| 468 | printf("EV: %s => EV_ABS ABS_MT_POSITION %d, set x and y to 0 and lastWasSynReport to 1\n", e->deviceName, ev->value); |
| 469 | #else |
| 470 | printf("Ignoring ABS_MT_POSITION 0\n", e->deviceName, ev->value); |
| 471 | #endif |
| 472 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 473 | } |
| 474 | else |
| 475 | { |
| 476 | lastWasSynReport = 0; |
| 477 | e->mt_p.x = (ev->value & 0x7FFF0000) >> 16; |
| 478 | e->mt_p.y = (ev->value & 0xFFFF); |
Ethan Yonker | 32f68a3 | 2014-12-29 08:13:23 -0600 | [diff] [blame] | 479 | #ifdef _EVENT_LOGGING |
| 480 | printf("EV: %s => EV_ABS ABS_MT_POSITION %d, set x: %d and y: %d and lastWasSynReport to 0\n", e->deviceName, ev->value, (ev->value & 0x7FFF0000) >> 16, (ev->value & 0xFFFF)); |
| 481 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 482 | } |
| 483 | break; |
| 484 | |
| 485 | case ABS_MT_TOUCH_MAJOR: //30 |
| 486 | if (ev->value == 0) |
| 487 | { |
Ibrahim Awwal | 2e9cb01 | 2014-01-04 12:38:26 -0800 | [diff] [blame] | 488 | #ifndef TW_IGNORE_MAJOR_AXIS_0 |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 489 | // We're in a touch release, although some devices will still send positions as well |
| 490 | e->mt_p.x = 0; |
| 491 | e->mt_p.y = 0; |
| 492 | touchReleaseOnNextSynReport = 1; |
Ibrahim Awwal | 2e9cb01 | 2014-01-04 12:38:26 -0800 | [diff] [blame] | 493 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 494 | } |
| 495 | #ifdef _EVENT_LOGGING |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 496 | printf("EV: %s => EV_ABS ABS_MT_TOUCH_MAJOR %d\n", e->deviceName, ev->value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 497 | #endif |
| 498 | break; |
| 499 | |
| 500 | case ABS_MT_PRESSURE: //3a |
| 501 | if (ev->value == 0) |
| 502 | { |
| 503 | // We're in a touch release, although some devices will still send positions as well |
| 504 | e->mt_p.x = 0; |
| 505 | e->mt_p.y = 0; |
| 506 | touchReleaseOnNextSynReport = 1; |
| 507 | } |
| 508 | #ifdef _EVENT_LOGGING |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 509 | printf("EV: %s => EV_ABS ABS_MT_PRESSURE %d\n", e->deviceName, ev->value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 510 | #endif |
| 511 | break; |
| 512 | |
| 513 | case ABS_MT_POSITION_X: //35 |
| 514 | e->mt_p.synced |= 0x01; |
| 515 | e->mt_p.x = ev->value; |
| 516 | #ifdef _EVENT_LOGGING |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 517 | printf("EV: %s => EV_ABS ABS_MT_POSITION_X %d\n", e->deviceName, ev->value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 518 | #endif |
| 519 | break; |
| 520 | |
| 521 | case ABS_MT_POSITION_Y: //36 |
| 522 | e->mt_p.synced |= 0x02; |
| 523 | e->mt_p.y = ev->value; |
| 524 | #ifdef _EVENT_LOGGING |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 525 | printf("EV: %s => EV_ABS ABS_MT_POSITION_Y %d\n", e->deviceName, ev->value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 526 | #endif |
| 527 | break; |
| 528 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 529 | case ABS_MT_TOUCH_MINOR: //31 |
Dees_Troy | d86400b | 2013-05-13 19:04:35 +0000 | [diff] [blame] | 530 | #ifdef _EVENT_LOGGING |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 531 | printf("EV: %s => EV_ABS ABS_MT_TOUCH_MINOR %d\n", e->deviceName, ev->value); |
Dees_Troy | d86400b | 2013-05-13 19:04:35 +0000 | [diff] [blame] | 532 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 533 | break; |
| 534 | |
| 535 | case ABS_MT_WIDTH_MAJOR: //32 |
Dees_Troy | d86400b | 2013-05-13 19:04:35 +0000 | [diff] [blame] | 536 | #ifdef _EVENT_LOGGING |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 537 | printf("EV: %s => EV_ABS ABS_MT_WIDTH_MAJOR %d\n", e->deviceName, ev->value); |
Dees_Troy | d86400b | 2013-05-13 19:04:35 +0000 | [diff] [blame] | 538 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 539 | break; |
| 540 | |
| 541 | case ABS_MT_WIDTH_MINOR: //33 |
Dees_Troy | d86400b | 2013-05-13 19:04:35 +0000 | [diff] [blame] | 542 | #ifdef _EVENT_LOGGING |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 543 | printf("EV: %s => EV_ABS ABS_MT_WIDTH_MINOR %d\n", e->deviceName, ev->value); |
Dees_Troy | d86400b | 2013-05-13 19:04:35 +0000 | [diff] [blame] | 544 | #endif |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 545 | break; |
| 546 | |
Dees_Troy | d86400b | 2013-05-13 19:04:35 +0000 | [diff] [blame] | 547 | case ABS_MT_TRACKING_ID: //39 |
| 548 | if (ev->value < 0) { |
| 549 | e->mt_p.x = 0; |
| 550 | e->mt_p.y = 0; |
| 551 | touchReleaseOnNextSynReport = 2; |
| 552 | use_tracking_id_negative_as_touch_release = 1; |
| 553 | #ifdef _EVENT_LOGGING |
| 554 | if (use_tracking_id_negative_as_touch_release) |
| 555 | printf("using ABS_MT_TRACKING_ID value -1 to indicate touch releases\n"); |
| 556 | #endif |
| 557 | } |
| 558 | #ifdef _EVENT_LOGGING |
| 559 | printf("EV: %s => EV_ABS ABS_MT_TRACKING_ID %d\n", e->deviceName, ev->value); |
| 560 | #endif |
| 561 | break; |
| 562 | |
| 563 | #ifdef _EVENT_LOGGING |
| 564 | // These are for touch logging purposes only |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 565 | case ABS_MT_ORIENTATION: //34 |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 566 | printf("EV: %s => EV_ABS ABS_MT_ORIENTATION %d\n", e->deviceName, ev->value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 567 | return 1; |
| 568 | break; |
| 569 | |
| 570 | case ABS_MT_TOOL_TYPE: //37 |
| 571 | LOGI("EV: %s => EV_ABS ABS_MT_TOOL_TYPE %d\n", e->deviceName, ev->value); |
| 572 | return 1; |
| 573 | break; |
| 574 | |
| 575 | case ABS_MT_BLOB_ID: //38 |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 576 | printf("EV: %s => EV_ABS ABS_MT_BLOB_ID %d\n", e->deviceName, ev->value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 577 | return 1; |
| 578 | break; |
| 579 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 580 | case ABS_MT_DISTANCE: //3b |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 581 | printf("EV: %s => EV_ABS ABS_MT_DISTANCE %d\n", e->deviceName, ev->value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 582 | return 1; |
| 583 | break; |
| 584 | #endif |
| 585 | |
| 586 | default: |
| 587 | // This is an unhandled message, just skip it |
| 588 | return 1; |
| 589 | } |
| 590 | |
| 591 | if (ev->code != ABS_MT_POSITION) |
| 592 | { |
| 593 | lastWasSynReport = 0; |
| 594 | return 1; |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | // Check if we should ignore the message |
| 599 | if (ev->code != ABS_MT_POSITION && (ev->type != EV_SYN || (ev->code != SYN_REPORT && ev->code != SYN_MT_REPORT))) |
| 600 | { |
| 601 | lastWasSynReport = 0; |
| 602 | return 0; |
| 603 | } |
| 604 | |
| 605 | #ifdef _EVENT_LOGGING |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 606 | if (ev->type == EV_SYN && ev->code == SYN_REPORT) printf("EV: %s => EV_SYN SYN_REPORT\n", e->deviceName); |
| 607 | if (ev->type == EV_SYN && ev->code == SYN_MT_REPORT) printf("EV: %s => EV_SYN SYN_MT_REPORT\n", e->deviceName); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 608 | #endif |
| 609 | |
| 610 | // Discard the MT versions |
| 611 | if (ev->code == SYN_MT_REPORT) return 0; |
| 612 | |
Dees_Troy | d86400b | 2013-05-13 19:04:35 +0000 | [diff] [blame] | 613 | if (((lastWasSynReport == 1 || touchReleaseOnNextSynReport == 1) && !use_tracking_id_negative_as_touch_release) || (use_tracking_id_negative_as_touch_release && touchReleaseOnNextSynReport == 2)) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 614 | { |
| 615 | // Reset the value |
| 616 | touchReleaseOnNextSynReport = 0; |
| 617 | |
| 618 | // We are a finger-up state |
| 619 | if (!discard) |
| 620 | { |
| 621 | // Report the key up |
| 622 | ev->type = EV_ABS; |
| 623 | ev->code = 0; |
| 624 | ev->value = (downX << 16) | downY; |
| 625 | } |
| 626 | downX = -1; |
| 627 | downY = -1; |
| 628 | if (discard) |
| 629 | { |
| 630 | discard = 0; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 631 | |
| 632 | // Send the keyUp event |
| 633 | ev->type = EV_KEY; |
| 634 | ev->code = last_virt_key; |
| 635 | ev->value = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 636 | } |
| 637 | return 0; |
| 638 | } |
| 639 | lastWasSynReport = 1; |
| 640 | |
| 641 | // Retrieve where the x,y position is |
| 642 | if (e->p.synced & 0x03) |
| 643 | { |
Dees_Troy | b7ecc09 | 2013-08-24 12:15:41 +0000 | [diff] [blame] | 644 | vk_tp_to_screen(&e->p, &x, &y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 645 | } |
| 646 | else if (e->mt_p.synced & 0x03) |
| 647 | { |
Dees_Troy | b7ecc09 | 2013-08-24 12:15:41 +0000 | [diff] [blame] | 648 | vk_tp_to_screen(&e->mt_p, &x, &y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 649 | } |
| 650 | else |
| 651 | { |
| 652 | // We don't have useful information to convey |
| 653 | return 1; |
| 654 | } |
| 655 | |
| 656 | #ifdef RECOVERY_TOUCHSCREEN_SWAP_XY |
| 657 | x ^= y; |
| 658 | y ^= x; |
| 659 | x ^= y; |
| 660 | #endif |
| 661 | #ifdef RECOVERY_TOUCHSCREEN_FLIP_X |
Dees_Troy | b7ecc09 | 2013-08-24 12:15:41 +0000 | [diff] [blame] | 662 | x = gr_fb_width() - x; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 663 | #endif |
| 664 | #ifdef RECOVERY_TOUCHSCREEN_FLIP_Y |
Dees_Troy | b7ecc09 | 2013-08-24 12:15:41 +0000 | [diff] [blame] | 665 | y = gr_fb_height() - y; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 666 | #endif |
| 667 | |
| 668 | #ifdef _EVENT_LOGGING |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 669 | printf("EV: x: %d y: %d\n", x, y); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 670 | #endif |
| 671 | |
| 672 | // Clear the current sync states |
| 673 | e->p.synced = e->mt_p.synced = 0; |
| 674 | |
| 675 | // If we have nothing useful to report, skip it |
| 676 | if (x == -1 || y == -1) return 1; |
| 677 | |
| 678 | // On first touch, see if we're at a virtual key |
| 679 | if (downX == -1) |
| 680 | { |
| 681 | // Attempt mapping to virtual key |
| 682 | for (i = 0; i < e->vk_count; ++i) |
| 683 | { |
| 684 | int xd = ABS(e->vks[i].centerx - x); |
| 685 | int yd = ABS(e->vks[i].centery - y); |
| 686 | |
| 687 | if (xd < e->vks[i].width/2 && yd < e->vks[i].height/2) |
| 688 | { |
| 689 | ev->type = EV_KEY; |
| 690 | ev->code = e->vks[i].scancode; |
| 691 | ev->value = 1; |
| 692 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 693 | last_virt_key = e->vks[i].scancode; |
| 694 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 695 | vibrate(VIBRATOR_TIME_MS); |
| 696 | |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 697 | // Mark that all further movement until lift is discard, |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 698 | // and make sure we don't come back into this area |
| 699 | discard = 1; |
| 700 | downX = 0; |
| 701 | return 0; |
| 702 | } |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | // If we were originally a button press, discard this event |
| 707 | if (discard) |
| 708 | { |
| 709 | return 1; |
| 710 | } |
| 711 | |
| 712 | // Record where we started the touch for deciding if this is a key or a scroll |
| 713 | downX = x; |
| 714 | downY = y; |
| 715 | |
| 716 | ev->type = EV_ABS; |
| 717 | ev->code = 1; |
| 718 | ev->value = (x << 16) | y; |
| 719 | return 0; |
| 720 | } |
| 721 | |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 722 | int ev_get(struct input_event *ev, int timeout_ms) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 723 | { |
| 724 | int r; |
| 725 | unsigned n; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 726 | struct timeval curr; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 727 | |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 728 | gettimeofday(&curr, NULL); |
| 729 | if(curr.tv_sec - lastInputStat.tv_sec >= 2) |
| 730 | { |
| 731 | struct stat st; |
| 732 | stat("/dev/input", &st); |
| 733 | if (st.st_mtime > lastInputMTime) |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 734 | { |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 735 | printf("Reloading input devices\n"); |
| 736 | ev_exit(); |
| 737 | ev_init(); |
| 738 | lastInputMTime = st.st_mtime; |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 739 | } |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 740 | lastInputStat = curr; |
| 741 | } |
Vojtech Bocek | 1fc30fc | 2014-01-29 18:37:19 +0100 | [diff] [blame] | 742 | |
that | de72b6d | 2015-02-08 08:55:00 +0100 | [diff] [blame] | 743 | r = poll(ev_fds, ev_count, timeout_ms); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 744 | |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 745 | if(r > 0) { |
| 746 | for(n = 0; n < ev_count; n++) { |
| 747 | if(ev_fds[n].revents & POLLIN) { |
| 748 | r = read(ev_fds[n].fd, ev, sizeof(*ev)); |
| 749 | if(r == sizeof(*ev)) { |
| 750 | if (!vk_modify(&evs[n], ev)) |
| 751 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 752 | } |
| 753 | } |
| 754 | } |
that | c5837f3 | 2015-02-01 01:59:43 +0100 | [diff] [blame] | 755 | return -1; |
Ethan Yonker | e13fa63 | 2015-01-27 11:30:03 -0600 | [diff] [blame] | 756 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 757 | |
that | c5837f3 | 2015-02-01 01:59:43 +0100 | [diff] [blame] | 758 | return -2; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | int ev_wait(int timeout) |
| 762 | { |
| 763 | return -1; |
| 764 | } |
| 765 | |
| 766 | void ev_dispatch(void) |
| 767 | { |
| 768 | return; |
| 769 | } |
| 770 | |
| 771 | int ev_get_input(int fd, short revents, struct input_event *ev) |
| 772 | { |
| 773 | return -1; |
| 774 | } |