Browse Source

comma: fix touch rotate (#6)

pull/5008/head
Maxime Desroches 1 month ago
committed by GitHub
parent
commit
3cf4f3abdd
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
1 changed files with 21 additions and 4 deletions
  1. +21
    -4
      src/platforms/rcore_comma.c

+ 21
- 4
src/platforms/rcore_comma.c View File

@ -78,6 +78,7 @@ struct finger {
struct touch { struct touch {
struct finger fingers[1]; struct finger fingers[1];
int fd; int fd;
int canonical;
}; };
// hold all the low level wayland stuff // hold all the low level wayland stuff
@ -288,13 +289,29 @@ static int init_egl () {
return 0; return 0;
} }
static int init_touch(const char *dev_path) {
static int init_touch(const char *dev_path, const char *origin_path) {
platform.touch.fd = open(dev_path, O_RDONLY|O_NONBLOCK); platform.touch.fd = open(dev_path, O_RDONLY|O_NONBLOCK);
if (platform.touch.fd < 0) { if (platform.touch.fd < 0) {
TRACELOG(LOG_WARNING, "COMMA: Failed to open touch device at %s", dev_path); TRACELOG(LOG_WARNING, "COMMA: Failed to open touch device at %s", dev_path);
return -1; return -1;
} }
FILE *fp = fopen(origin_path, "r");
if (fp != NULL) {
int origin;
int ret = fscanf(fp, "%d", &origin);
fclose(fp);
if (ret != 1) {
TRACELOG(LOG_WARNING, "COMMA: Failed to test for screen origin");
return -1;
} else {
platform.touch.canonical = origin == 1;
}
} else {
TRACELOG(LOG_WARNING, "COMMA: Failed to open screen origin");
return -1;
}
platform.touch.fingers[0].x = -1; platform.touch.fingers[0].x = -1;
platform.touch.fingers[0].y = -1; platform.touch.fingers[0].y = -1;
platform.touch.fingers[0].action = TOUCH_ACTION_UP; platform.touch.fingers[0].action = TOUCH_ACTION_UP;
@ -653,9 +670,9 @@ void PollInputEvents(void) {
if (event.code == ABS_MT_TRACKING_ID) { if (event.code == ABS_MT_TRACKING_ID) {
platform.touch.fingers[slot].action = event.value == -1 ? TOUCH_ACTION_UP : TOUCH_ACTION_DOWN; platform.touch.fingers[slot].action = event.value == -1 ? TOUCH_ACTION_UP : TOUCH_ACTION_DOWN;
} else if (event.code == ABS_MT_POSITION_X) { } else if (event.code == ABS_MT_POSITION_X) {
platform.touch.fingers[slot].y = event.value;
platform.touch.fingers[slot].y = p">(1 - platform.touch.canonical) * (CORE.Window.screen.height - event.value) + (platform.touch.canonical * event.value);
} else if (event.code == ABS_MT_POSITION_Y) { } else if (event.code == ABS_MT_POSITION_Y) {
platform.touch.fingers[slot].x = CORE.Window.screen.width - event.value;
platform.touch.fingers[slot].x = platform.touch.canonical * (CORE.Window.screen.width - event.value) + ((1 - platform.touch.canonical) * event.value);
} }
} }
} }
@ -690,7 +707,7 @@ int InitPlatform(void) {
return -1; return -1;
} }
if (init_touch("/dev/input/event2")) {
if (init_touch("/dev/input/event2", "/sys/devices/platform/vendor/vendor:gpio-som-id/som_id")) {
TRACELOG(LOG_FATAL, "COMMA: Failed to initialize touch device"); TRACELOG(LOG_FATAL, "COMMA: Failed to initialize touch device");
return -1; return -1;
} }

Loading…
Cancel
Save