コード例 #1
0
ファイル: SDL_touch.c プロジェクト: wanliLiu/BarSwipe
SDL_Touch *
SDL_GetTouch(SDL_TouchID id)
{
    int index = SDL_GetTouchIndex(id);
    if (index < 0 || index >= SDL_num_touch) {
        SDL_SetError("Unknown touch device");
        return NULL;
    }
    return SDL_touchDevices[index];
}
コード例 #2
0
ファイル: SDL_touch.c プロジェクト: wanliLiu/BarSwipe
void
SDL_DelTouch(SDL_TouchID id)
{
    int i;
    int index = SDL_GetTouchIndex(id);
    SDL_Touch *touch = SDL_GetTouch(id);

    if (!touch) {
        return;
    }

    for (i = 0; i < touch->max_fingers; ++i) {
        SDL_free(touch->fingers[i]);
    }
    SDL_free(touch->fingers);
    SDL_free(touch);

    SDL_num_touch--;
    SDL_touchDevices[index] = SDL_touchDevices[SDL_num_touch];
}
コード例 #3
0
ファイル: SDL_touch.c プロジェクト: wanliLiu/BarSwipe
int
SDL_AddTouch(SDL_TouchID touchID, const char *name)
{
    SDL_Touch **touchDevices;
    int index;

    index = SDL_GetTouchIndex(touchID);
    if (index >= 0) {
        return index;
    }

    /* Add the touch to the list of touch */
    touchDevices = (SDL_Touch **) SDL_realloc(SDL_touchDevices,
                                      (SDL_num_touch + 1) * sizeof(*touchDevices));
    if (!touchDevices) {
        return SDL_OutOfMemory();
    }

    SDL_touchDevices = touchDevices;
    index = SDL_num_touch;

    SDL_touchDevices[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchDevices[index]));
    if (!SDL_touchDevices[index]) {
        return SDL_OutOfMemory();
    }

    /* Added touch to list */
    ++SDL_num_touch;

    /* we're setting the touch properties */
    SDL_touchDevices[index]->id = touchID;
    SDL_touchDevices[index]->num_fingers = 0;
    SDL_touchDevices[index]->max_fingers = 0;
    SDL_touchDevices[index]->fingers = NULL;

    /* Record this touch device for gestures */
    /* We could do this on the fly in the gesture code if we wanted */
    SDL_GestureAddTouch(touchID);

    return index;
}
コード例 #4
0
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
}
コード例 #5
0
ファイル: SDL_x11events.c プロジェクト: new299/wflow
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
}