static void touch_handle_touch(void *data, struct qt_touch_extension *qt_touch_extension, uint32_t time, uint32_t id, uint32_t state, int32_t x, int32_t y, int32_t normalized_x, int32_t normalized_y, int32_t width, int32_t height, uint32_t pressure, int32_t velocity_x, int32_t velocity_y, uint32_t flags, struct wl_array *rawdata) { /** * Event is assembled in QtWayland in TouchExtensionGlobal::postTouchEvent * (src/compositor/wayland_wrapper/qwltouch.cpp) **/ float FIXED_TO_FLOAT = 1. / 10000.; float xf = FIXED_TO_FLOAT * x; float yf = FIXED_TO_FLOAT * y; float PRESSURE_TO_FLOAT = 1. / 255.; float pressuref = PRESSURE_TO_FLOAT * pressure; uint32_t touchState = state & 0xFFFF; /* Other fields that are sent by the server (qwltouch.cpp), but not used at the moment can be decoded in this way: uint32_t sentPointCount = state >> 16; uint32_t touchFlags = flags & 0xFFFF; uint32_t capabilities = flags >> 16; */ SDL_TouchID deviceId = 1; if (SDL_AddTouch(deviceId, "qt_touch_extension") < 0) { SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__); } switch (touchState) { case QtWaylandTouchPointPressed: case QtWaylandTouchPointReleased: SDL_SendTouch(deviceId, (SDL_FingerID)id, (touchState == QtWaylandTouchPointPressed) ? SDL_TRUE : SDL_FALSE, xf, yf, pressuref); break; case QtWaylandTouchPointMoved: SDL_SendTouchMotion(deviceId, (SDL_FingerID)id, xf, yf, pressuref); break; default: /* Should not happen */ break; } }
void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p) { SDL_TouchID touchDeviceId = 0; SDL_FingerID fingerId = 0; int window_x, window_y; static SDL_FingerID pointerFingerID = 0; if (!Android_Window) { return; } touchDeviceId = (SDL_TouchID)touch_device_id_in; if (SDL_AddTouch(touchDeviceId, "") < 0) { SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__); } fingerId = (SDL_FingerID)pointer_finger_id_in; switch (action) { case ACTION_DOWN: /* Primary pointer down */ if (!separate_mouse_and_touch) { Android_GetWindowCoordinates(x, y, &window_x, &window_y); /* send moved event */ SDL_SendMouseMotion(Android_Window, SDL_TOUCH_MOUSEID, 0, window_x, window_y); /* send mouse down event */ SDL_SendMouseButton(Android_Window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT); } pointerFingerID = fingerId; case ACTION_POINTER_DOWN: /* Non primary pointer down */ SDL_SendTouch(touchDeviceId, fingerId, SDL_TRUE, x, y, p); break; case ACTION_MOVE: if (!pointerFingerID) { if (!separate_mouse_and_touch) { Android_GetWindowCoordinates(x, y, &window_x, &window_y); /* send moved event */ SDL_SendMouseMotion(Android_Window, SDL_TOUCH_MOUSEID, 0, window_x, window_y); } } SDL_SendTouchMotion(touchDeviceId, fingerId, x, y, p); break; case ACTION_UP: /* Primary pointer up */ if (!separate_mouse_and_touch) { /* send mouse up */ SDL_SendMouseButton(Android_Window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT); } pointerFingerID = (SDL_FingerID) 0; case ACTION_POINTER_UP: /* Non primary pointer up */ SDL_SendTouch(touchDeviceId, fingerId, SDL_FALSE, x, y, p); break; default: break; } }
void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p) { SDL_TouchID touchDeviceId = 0; SDL_FingerID fingerId = 0; int window_x, window_y; if (!Android_Window) { return; } touchDeviceId = (SDL_TouchID)touch_device_id_in; if (!SDL_GetTouch(touchDeviceId)) { if (SDL_AddTouch(touchDeviceId, "") < 0) { SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__); } } fingerId = (SDL_FingerID)pointer_finger_id_in; switch (action) { case ACTION_DOWN: case ACTION_POINTER_1_DOWN: if (!leftFingerDown) { Android_GetWindowCoordinates(x, y, &window_x, &window_y); /* send moved event */ SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y); /* send mouse down event */ SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT); leftFingerDown = fingerId; } SDL_SendTouch(touchDeviceId, fingerId, SDL_TRUE, x, y, p); break; case ACTION_MOVE: if (!leftFingerDown) { Android_GetWindowCoordinates(x, y, &window_x, &window_y); /* send moved event */ SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y); } SDL_SendTouchMotion(touchDeviceId, fingerId, x, y, p); break; case ACTION_UP: case ACTION_POINTER_1_UP: if (fingerId == leftFingerDown) { /* send mouse up */ SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT); leftFingerDown = 0; } SDL_SendTouch(touchDeviceId, fingerId, SDL_FALSE, x, y, p); break; default: break; } }
void Android_InitTouch(void) { int i; int* ids; int number = Android_JNI_GetTouchDeviceIds(&ids); if (0 < number) { for (i = 0; i < number; ++i) { SDL_AddTouch((SDL_TouchID) ids[i], ""); /* no error handling */ } SDL_free(ids); } }
void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p) { SDL_TouchID touchDeviceId = 0; SDL_FingerID fingerId = 0; if (!Android_Window) { return; } touchDeviceId = (SDL_TouchID)touch_device_id_in; if (!SDL_GetTouch(touchDeviceId)) { SDL_Touch touch; memset( &touch, 0, sizeof(touch) ); touch.id = touchDeviceId; touch.x_min = 0.0f; touch.x_max = (float)Android_ScreenWidth; touch.native_xres = touch.x_max - touch.x_min; touch.y_min = 0.0f; touch.y_max = (float)Android_ScreenHeight; touch.native_yres = touch.y_max - touch.y_min; touch.pressure_min = 0.0f; touch.pressure_max = 1.0f; touch.native_pressureres = touch.pressure_max - touch.pressure_min; if (SDL_AddTouch(&touch, "") < 0) { SDL_Log("error: can't add touch %s, %d", __FILE__, __LINE__); } } fingerId = (SDL_FingerID)pointer_finger_id_in; switch (action) { case ACTION_DOWN: case ACTION_POINTER_1_DOWN: SDL_SendMouseMotion(Android_Window, 0, x, y); SDL_SendMouseButton(Android_Window, SDL_PRESSED, SDL_BUTTON_LEFT); SDL_SendFingerDown(touchDeviceId, fingerId, SDL_TRUE, x, y, p); break; case ACTION_MOVE: SDL_SendMouseMotion(Android_Window, 0, x, y); SDL_SendTouchMotion(touchDeviceId, fingerId, SDL_FALSE, x, y, p); break; case ACTION_UP: case ACTION_POINTER_1_UP: SDL_SendMouseButton(Android_Window, SDL_RELEASED, SDL_BUTTON_LEFT); SDL_SendFingerDown(touchDeviceId, fingerId, SDL_FALSE, x, y, p); break; default: break; } }
void Android_InitTouch(void) { int i; int* ids; const int number = Android_JNI_GetTouchDeviceIds(&ids); SDL_AddHintCallback(SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH, SeparateEventsHintWatcher, NULL); if (0 < number) { for (i = 0; i < number; ++i) { SDL_AddTouch((SDL_TouchID) ids[i], ""); /* no error handling */ } SDL_free(ids); } }
static void SDLCALL SDL_MouseTouchEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint) { SDL_Mouse *mouse = (SDL_Mouse *)userdata; if (hint == NULL || *hint == '\0') { /* Default */ #if defined(__ANDROID__) || (defined(__IPHONEOS__) && !defined(__TVOS__)) mouse->mouse_touch_events = SDL_TRUE; #else mouse->mouse_touch_events = SDL_FALSE; #endif } else if (*hint == '1' || SDL_strcasecmp(hint, "true") == 0) { mouse->mouse_touch_events = SDL_TRUE; } else { mouse->mouse_touch_events = SDL_FALSE; } if (mouse->mouse_touch_events) { SDL_AddTouch(SDL_MOUSE_TOUCHID, SDL_TOUCH_DEVICE_DIRECT, "mouse_input"); } }
void X11_InitTouch(_THIS) { #ifdef SDL_INPUT_LINUXEV FILE *fd; fd = fopen("/proc/bus/input/devices","r"); char c; int i = 0; char line[256]; char tstr[256]; int vendor = -1,product = -1,event = -1; while(!feof(fd)) { if(fgets(line,256,fd) <=0) continue; if(line[0] == '\n') { if(vendor == 1386) { /*printf("Wacom... Assuming it is a touch device\n");*/ /*sprintf(tstr,"/dev/input/event%i",event);*/ /*printf("At location: %s\n",tstr);*/ SDL_Touch touch; touch.pressure_max = 0; touch.pressure_min = 0; touch.id = event; touch.driverdata = SDL_malloc(sizeof(EventTouchData)); EventTouchData* data = (EventTouchData*)(touch.driverdata); data->x = -1; data->y = -1; data->pressure = -1; data->finger = 0; data->up = SDL_FALSE; data->eventStream = open(tstr, O_RDONLY | O_NONBLOCK); ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr); int abs[5]; ioctl(data->eventStream,EVIOCGABS(0),abs); touch.x_min = abs[1]; touch.x_max = abs[2]; touch.native_xres = touch.x_max - touch.x_min; ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs); touch.y_min = abs[1]; touch.y_max = abs[2]; touch.native_yres = touch.y_max - touch.y_min; ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs); touch.pressure_min = abs[1]; touch.pressure_max = abs[2]; touch.native_pressureres = touch.pressure_max - touch.pressure_min; SDL_AddTouch(&touch, tstr); } vendor = -1; product = -1; event = -1; } else if(line[0] == 'I') { i = 1; while(line[i]) { sscanf(&line[i],"Vendor=%x",&vendor); sscanf(&line[i],"Product=%x",&product); i++; } } else if(line[0] == 'H') { i = 1; while(line[i]) { sscanf(&line[i],"event%d",&event); i++; } } } close(fd); #endif }
static void AddTouchDevice(int device_id) { if (SDL_AddTouch(device_id, "") < 0) SDL_SetError("Error: can't add touch %s, %d", __FILE__, __LINE__); }
static int SDL_EVDEV_init_touchscreen(SDL_evdevlist_item* item) { int ret, i; char name[64]; struct input_absinfo abs_info; if (!item->is_touchscreen) return 0; item->touchscreen_data = SDL_calloc(1, sizeof(*item->touchscreen_data)); if (item->touchscreen_data == NULL) return SDL_OutOfMemory(); ret = ioctl(item->fd, EVIOCGNAME(sizeof(name)), name); if (ret < 0) { SDL_free(item->touchscreen_data); return SDL_SetError("Failed to get evdev touchscreen name"); } item->touchscreen_data->name = SDL_strdup(name); if (item->touchscreen_data->name == NULL) { SDL_free(item->touchscreen_data); return SDL_OutOfMemory(); } ret = ioctl(item->fd, EVIOCGABS(ABS_MT_POSITION_X), &abs_info); if (ret < 0) { SDL_free(item->touchscreen_data->name); SDL_free(item->touchscreen_data); return SDL_SetError("Failed to get evdev touchscreen limits"); } item->touchscreen_data->min_x = abs_info.minimum; item->touchscreen_data->max_x = abs_info.maximum; item->touchscreen_data->range_x = abs_info.maximum - abs_info.minimum; ret = ioctl(item->fd, EVIOCGABS(ABS_MT_POSITION_Y), &abs_info); if (ret < 0) { SDL_free(item->touchscreen_data->name); SDL_free(item->touchscreen_data); return SDL_SetError("Failed to get evdev touchscreen limits"); } item->touchscreen_data->min_y = abs_info.minimum; item->touchscreen_data->max_y = abs_info.maximum; item->touchscreen_data->range_y = abs_info.maximum - abs_info.minimum; ret = ioctl(item->fd, EVIOCGABS(ABS_MT_SLOT), &abs_info); if (ret < 0) { SDL_free(item->touchscreen_data->name); SDL_free(item->touchscreen_data); return SDL_SetError("Failed to get evdev touchscreen limits"); } item->touchscreen_data->max_slots = abs_info.maximum + 1; item->touchscreen_data->slots = SDL_calloc( item->touchscreen_data->max_slots, sizeof(*item->touchscreen_data->slots)); if (item->touchscreen_data->slots == NULL) { SDL_free(item->touchscreen_data->name); SDL_free(item->touchscreen_data); return SDL_OutOfMemory(); } for(i = 0; i < item->touchscreen_data->max_slots; i++) { item->touchscreen_data->slots[i].tracking_id = -1; } ret = SDL_AddTouch(item->fd, /* I guess our fd is unique enough */ item->touchscreen_data->name); if (ret < 0) { SDL_free(item->touchscreen_data->slots); SDL_free(item->touchscreen_data->name); SDL_free(item->touchscreen_data); return ret; } return 0; }