Try to fix mouse input

This commit is contained in:
UnknownShadow200 2024-05-21 23:29:37 +10:00
parent ec2a492687
commit 6b25058f68

View File

@ -153,23 +153,26 @@ static int stdin_available(void) {
tok = strtok(NULL, ";"); \ tok = strtok(NULL, ";"); \
x = atoi(tok); \ x = atoi(tok); \
tok = strtok(NULL, ";"); \ tok = strtok(NULL, ";"); \
y = atoi(tok); y = atoi(tok) * 2;
static void ProcessMouse(char* buf, int n) { static void ProcessMouse(char* buf, int n) {
char cpy[128]; char cpy[256+2];
char* tok = strtok(cpy+3, ";"); strncpy(cpy, buf, n);
int x, y, mouse; char* tok = strtok(cpy + 3, ";");
int x, y, mouse;
if (!tok) return;
switch(tok[0]){ switch (tok[0]){
case '0': case '0':
mouse = (strchr(buf, 'm') == NULL); mouse = strchr(buf, 'm') == NULL;
ExtractXY(); ExtractXY();
Platform_Log2("CLICK: %i, %i", &x, &y); Pointer_SetPosition(0, x, y);
break; Input_SetNonRepeatable(CCMOUSE_L, mouse);
case '3': break;
mouse = (strcmp(tok, "32") == 0); case '3':
ExtractXY(); mouse = (strcmp(tok, "32") == 0);
Platform_Log2("HOVER: %i, %i", &x, &y); ExtractXY();
Pointer_SetPosition(0, x, y);
break; break;
} }
} }
@ -187,13 +190,13 @@ static void ProcessKey(int key) {
} }
void Window_ProcessEvents(float delta) { void Window_ProcessEvents(float delta) {
char buf[128]; char buf[256];
int n; int n;
if (!stdin_available()) return; if (!stdin_available()) return;
n = read(STDIN_FILENO, buf, sizeof(buf)); n = read(STDIN_FILENO, buf, sizeof(buf));
int A = buf[0]; int A = buf[0];
Platform_Log2("IN: %i, %i", &n, &A); //Platform_Log2("IN: %i, %i", &n, &A);
if (n >= 4 && buf[0] == '\x1b' && buf[1] == '[' && buf[2] == '<') { if (n >= 4 && buf[0] == '\x1b' && buf[1] == '[' && buf[2] == '<') {
ProcessMouse(buf, n); ProcessMouse(buf, n);