void X11_PumpEvents(_THIS) { SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; /* Update activity every 30 seconds to prevent screensaver */ if (_this->suspend_screensaver) { Uint32 now = SDL_GetTicks(); if (!data->screensaver_activity || (int) (now - data->screensaver_activity) >= 30000) { XResetScreenSaver(data->display); data->screensaver_activity = now; } } /* Keep processing pending events */ while (X11_Pending(data->display)) { X11_DispatchEvent(_this); } #ifdef SDL_INPUT_LINUXEV /* Process Touch events - TODO When X gets touch support, use that instead*/ int i = 0,rd; char name[256]; struct input_event ev[64]; int size = sizeof (struct input_event); for(i = 0;i < SDL_GetNumTouch();++i) { SDL_Touch* touch = SDL_GetTouchIndex(i); if(!touch) printf("Touch %i/%i DNE\n",i,SDL_GetNumTouch()); EventTouchData* data; data = (EventTouchData*)(touch->driverdata); if(data == NULL) { printf("No driver data\n"); continue; } if(data->eventStream <= 0) printf("Error: Couldn't open stream\n"); rd = read(data->eventStream, ev, size * 64); //printf("Got %i/%i bytes\n",rd,size); if(rd >= size) { for (i = 0; i < rd / sizeof(struct input_event); i++) { switch (ev[i].type) { case EV_ABS: //printf("Got position x: %i!\n",data->x); switch (ev[i].code) { case ABS_X: data->x = ev[i].value; break; case ABS_Y: data->y = ev[i].value; break; case ABS_PRESSURE: data->pressure = ev[i].value; if(data->pressure < 0) data->pressure = 0; break; case ABS_MISC: if(ev[i].value == 0) data->up = SDL_TRUE; break; } break; case EV_MSC: if(ev[i].code == MSC_SERIAL) data->finger = ev[i].value; break; case EV_SYN: //printf("Id: %i\n",touch->id); if(data->up) { SDL_SendFingerDown(touch->id,data->finger, SDL_FALSE,data->x,data->y, data->pressure); } else if(data->x >= 0 || data->y >= 0) SDL_SendTouchMotion(touch->id,data->finger, SDL_FALSE,data->x,data->y, data->pressure); //printf("Synched: %i tx: %i, ty: %i\n", // data->finger,data->x,data->y); data->x = -1; data->y = -1; data->pressure = -1; data->finger = 0; data->up = SDL_FALSE; break; } } } } #endif }
void X11_PumpEvents(_THIS) { SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; /* Update activity every 30 seconds to prevent screensaver */ if (_this->suspend_screensaver) { Uint32 now = SDL_GetTicks(); if (!data->screensaver_activity || (int) (now - data->screensaver_activity) >= 30000) { XResetScreenSaver(data->display); #if SDL_USE_LIBDBUS SDL_dbus_screensaver_tickle(_this); #endif data->screensaver_activity = now; } } /* Keep processing pending events */ while (X11_Pending(data->display)) { X11_DispatchEvent(_this); } /* FIXME: Only need to do this when there are pending focus changes */ X11_HandleFocusChanges(_this); /*Dont process evtouch events if XInput2 multitouch is supported*/ if(X11_Xinput2IsMultitouchSupported()) { return; } #ifdef SDL_INPUT_LINUXEV /* Process Touch events*/ int i = 0,rd; struct input_event ev[64]; int size = sizeof (struct input_event); /* !!! FIXME: clean the tabstops out of here. */ for(i = 0;i < SDL_GetNumTouch();++i) { SDL_Touch* touch = SDL_GetTouchIndex(i); if(!touch) printf("Touch %i/%i DNE\n",i,SDL_GetNumTouch()); EventTouchData* data; data = (EventTouchData*)(touch->driverdata); if(data == NULL) { printf("No driver data\n"); continue; } if(data->eventStream <= 0) printf("Error: Couldn't open stream\n"); rd = read(data->eventStream, ev, size * 64); if(rd >= size) { for (i = 0; i < rd / sizeof(struct input_event); i++) { switch (ev[i].type) { case EV_ABS: switch (ev[i].code) { case ABS_X: data->x = ev[i].value; break; case ABS_Y: data->y = ev[i].value; break; case ABS_PRESSURE: data->pressure = ev[i].value; if(data->pressure < 0) data->pressure = 0; break; case ABS_MISC: if(ev[i].value == 0) data->up = SDL_TRUE; break; } break; case EV_MSC: if(ev[i].code == MSC_SERIAL) data->finger = ev[i].value; break; case EV_KEY: if(ev[i].code == BTN_TOUCH) if(ev[i].value == 0) data->up = SDL_TRUE; break; case EV_SYN: if(!data->down) { data->down = SDL_TRUE; SDL_SendFingerDown(touch->id,data->finger, data->down, data->x, data->y, data->pressure); } else if(!data->up) SDL_SendTouchMotion(touch->id,data->finger, SDL_FALSE, data->x,data->y, data->pressure); else { data->down = SDL_FALSE; SDL_SendFingerDown(touch->id,data->finger, data->down, data->x,data->y, data->pressure); data->x = -1; data->y = -1; data->pressure = -1; data->finger = 0; data->up = SDL_FALSE; } break; } } } } #endif }