comma: fix touch rotate (#6)
This commit is contained in:
parent
fb06da3384
commit
3cf4f3abdd
|
|
@ -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 = (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…
Reference in New Issue
Block a user