Added SDL_touch.c/SDL_touch_c.h as slightly modifeind SDL_mouse*. Made reads in touchSimp non-blocking.
authorJim Grandpre <jim.tla@gmail.com>
Tue, 25 May 2010 23:23:23 -0400
changeset 4640f068a6dfc858
parent 4639 f5cd4b6231ba
child 4641 49a97daea6ec
Added SDL_touch.c/SDL_touch_c.h as slightly modifeind SDL_mouse*. Made reads in touchSimp non-blocking.
src/events/SDL_events_c.h
src/events/SDL_touch.c
src/events/SDL_touch_c.h
src/video/x11/SDL_x11events.c
touchTest/touchSimp
touchTest/touchSimp.c
     1.1 --- a/src/events/SDL_events_c.h	Mon May 24 23:44:24 2010 -0400
     1.2 +++ b/src/events/SDL_events_c.h	Tue May 25 23:23:23 2010 -0400
     1.3 @@ -26,6 +26,7 @@
     1.4  #include "SDL_thread.h"
     1.5  #include "SDL_mouse_c.h"
     1.6  #include "SDL_keyboard_c.h"
     1.7 +#include "SDL_touch_c.h"
     1.8  #include "SDL_windowevents_c.h"
     1.9  
    1.10  /* Start and stop the event processing loop */
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/events/SDL_touch.c	Tue May 25 23:23:23 2010 -0400
     2.3 @@ -0,0 +1,575 @@
     2.4 +/*
     2.5 +    SDL - Simple DirectMedia Layer
     2.6 +    Copyright (C) 1997-2010 Sam Lantinga
     2.7 +
     2.8 +    This library is free software; you can redistribute it and/or
     2.9 +    modify it under the terms of the GNU Lesser General Public
    2.10 +    License as published by the Free Software Foundation; either
    2.11 +    version 2.1 of the License, or (at your option) any later version.
    2.12 +
    2.13 +    This library is distributed in the hope that it will be useful,
    2.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    2.16 +    Lesser General Public License for more details.
    2.17 +
    2.18 +    You should have received a copy of the GNU Lesser General Public
    2.19 +    License along with this library; if not, write to the Free Software
    2.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2.21 +
    2.22 +    Sam Lantinga
    2.23 +    slouken@libsdl.org
    2.24 +*/
    2.25 +#include "SDL_config.h"
    2.26 +
    2.27 +/* General touch handling code for SDL */
    2.28 +
    2.29 +#include "SDL_events.h"
    2.30 +#include "SDL_events_c.h"
    2.31 +#include "../video/SDL_sysvideo.h"
    2.32 +
    2.33 +
    2.34 +static int SDL_num_touch = 0;
    2.35 +static int SDL_current_touch = -1;
    2.36 +static SDL_Touch **SDL_touch = NULL;
    2.37 +
    2.38 +
    2.39 +/* Public functions */
    2.40 +int
    2.41 +SDL_TouchInit(void)
    2.42 +{
    2.43 +    return (0);
    2.44 +}
    2.45 +
    2.46 +SDL_Touch *
    2.47 +SDL_GetTouch(int index)
    2.48 +{
    2.49 +    if (index < 0 || index >= SDL_num_touch) {
    2.50 +        return NULL;
    2.51 +    }
    2.52 +    return SDL_touch[index];
    2.53 +}
    2.54 +
    2.55 +static int
    2.56 +SDL_GetTouchIndexId(int id)
    2.57 +{
    2.58 +    int index;
    2.59 +    SDL_Touch *touch;
    2.60 +
    2.61 +    for (index = 0; index < SDL_num_touch; ++index) {
    2.62 +        touch = SDL_GetTouch(index);
    2.63 +        if (touch->id == id) {
    2.64 +            return index;
    2.65 +        }
    2.66 +    }
    2.67 +    return -1;
    2.68 +}
    2.69 +
    2.70 +int
    2.71 +SDL_AddTouch(const SDL_Touch * touch, char *name, int pressure_max,
    2.72 +             int pressure_min, int ends)
    2.73 +{
    2.74 +    SDL_Touch **touch;
    2.75 +    int selected_touch;
    2.76 +    int index;
    2.77 +    size_t length;
    2.78 +
    2.79 +    if (SDL_GetTouchIndexId(touch->id) != -1) {
    2.80 +        SDL_SetError("Touch ID already in use");
    2.81 +    }
    2.82 +
    2.83 +    /* Add the touch to the list of touch */
    2.84 +    touch = (SDL_Touch **) SDL_realloc(SDL_touch,
    2.85 +                                      (SDL_num_touch + 1) * sizeof(*touch));
    2.86 +    if (!touch) {
    2.87 +        SDL_OutOfMemory();
    2.88 +        return -1;
    2.89 +    }
    2.90 +
    2.91 +    SDL_touch = touch;
    2.92 +    index = SDL_num_touch++;
    2.93 +
    2.94 +    SDL_touch[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touch[index]));
    2.95 +    if (!SDL_touch[index]) {
    2.96 +        SDL_OutOfMemory();
    2.97 +        return -1;
    2.98 +    }
    2.99 +    *SDL_touch[index] = *touch;
   2.100 +
   2.101 +    /* we're setting the touch properties */
   2.102 +    length = 0;
   2.103 +    length = SDL_strlen(name);
   2.104 +    SDL_touch[index]->focus = 0;
   2.105 +    SDL_touch[index]->name = SDL_malloc((length + 2) * sizeof(char));
   2.106 +    SDL_strlcpy(SDL_touch[index]->name, name, length + 1);
   2.107 +    SDL_touch[index]->pressure_max = pressure_max;
   2.108 +    SDL_touch[index]->pressure_min = pressure_min;
   2.109 +    SDL_touch[index]->cursor_shown = SDL_TRUE;
   2.110 +    selected_touch = SDL_SelectTouch(index);
   2.111 +    SDL_touch[index]->cur_cursor = NULL;
   2.112 +    SDL_touch[index]->def_cursor =
   2.113 +    /* we're assuming that all touch are in the computer sensing zone */
   2.114 +    SDL_touch[index]->proximity = SDL_TRUE;
   2.115 +    /* we're assuming that all touch are working in the absolute position mode
   2.116 +       thanx to that, the users that don't want to use many touch don't have to
   2.117 +       worry about anything */
   2.118 +    SDL_touch[index]->relative_mode = SDL_FALSE;
   2.119 +    SDL_touch[index]->current_end = 0;
   2.120 +    SDL_touch[index]->total_ends = ends;
   2.121 +    SDL_SelectTouch(selected_touch);
   2.122 +
   2.123 +    return index;
   2.124 +}
   2.125 +
   2.126 +void
   2.127 +SDL_DelTouch(int index)
   2.128 +{
   2.129 +    SDL_Touch *touch = SDL_GetTouch(index);
   2.130 +
   2.131 +    if (!touch) {
   2.132 +        return;
   2.133 +    }
   2.134 +
   2.135 +    touch->def_cursor = NULL;
   2.136 +    SDL_free(touch->name);
   2.137 + 
   2.138 +    if (touch->FreeTouch) {
   2.139 +        touch->FreeTouch(touch);
   2.140 +    }
   2.141 +    SDL_free(touch);
   2.142 +
   2.143 +    SDL_touch[index] = NULL;
   2.144 +}
   2.145 +
   2.146 +void
   2.147 +SDL_ResetTouch(int index)
   2.148 +{
   2.149 +    SDL_Touch *touch = SDL_GetTouch(index);
   2.150 +
   2.151 +    if (!touch) {
   2.152 +        return;
   2.153 +    }
   2.154 +
   2.155 +    /* FIXME */
   2.156 +}
   2.157 +
   2.158 +void
   2.159 +SDL_TouchQuit(void)
   2.160 +{
   2.161 +    int i;
   2.162 +
   2.163 +    for (i = 0; i < SDL_num_touch; ++i) {
   2.164 +        SDL_DelTouch(i);
   2.165 +    }
   2.166 +    SDL_num_touch = 0;
   2.167 +    SDL_current_touch = -1;
   2.168 +
   2.169 +    if (SDL_touch) {
   2.170 +        SDL_free(SDL_touch);
   2.171 +        SDL_touch = NULL;
   2.172 +    }
   2.173 +}
   2.174 +
   2.175 +int
   2.176 +SDL_GetNumTouch(void)
   2.177 +{
   2.178 +    return SDL_num_touch;
   2.179 +}
   2.180 +
   2.181 +int
   2.182 +SDL_SelectTouch(int index)
   2.183 +{
   2.184 +    if (index >= 0 && index < SDL_num_touch) {
   2.185 +        SDL_current_touch = index;
   2.186 +    }
   2.187 +    return SDL_current_touch;
   2.188 +}
   2.189 +
   2.190 +SDL_Window *
   2.191 +SDL_GetTouchFocusWindow(int index)
   2.192 +{
   2.193 +    SDL_Touch *touch = SDL_GetTouch(index);
   2.194 +
   2.195 +    if (!touch) {
   2.196 +        return 0;
   2.197 +    }
   2.198 +    return touch->focus;
   2.199 +}
   2.200 +
   2.201 +static int SDLCALL
   2.202 +FlushTouchMotion(void *param, SDL_Event * event)
   2.203 +{
   2.204 +    if (event->type == SDL_TOUCHMOTION
   2.205 +        && event->motion.which == (Uint8) SDL_current_touch) {
   2.206 +        return 0;
   2.207 +    } else {
   2.208 +        return 1;
   2.209 +    }
   2.210 +}
   2.211 +
   2.212 +int
   2.213 +SDL_SetRelativeTouchMode(int index, SDL_bool enabled)
   2.214 +{
   2.215 +    SDL_Touch *touch = SDL_GetTouch(index);
   2.216 +
   2.217 +    if (!touch) {
   2.218 +        return -1;
   2.219 +    }
   2.220 +
   2.221 +    /* Flush pending touch motion */
   2.222 +    touch->flush_motion = SDL_TRUE;
   2.223 +    SDL_PumpEvents();
   2.224 +    touch->flush_motion = SDL_FALSE;
   2.225 +    SDL_FilterEvents(FlushTouchMotion, touch);
   2.226 +
   2.227 +    /* Set the relative mode */
   2.228 +    touch->relative_mode = enabled;
   2.229 +
   2.230 +
   2.231 +
   2.232 +    if (!enabled) {
   2.233 +        /* Restore the expected touch position */
   2.234 +        SDL_WarpTouchInWindow(touch->focus, touch->x, touch->y);
   2.235 +    }
   2.236 +    return 0;
   2.237 +}
   2.238 +
   2.239 +SDL_bool
   2.240 +SDL_GetRelativeTouchMode(int index)
   2.241 +{
   2.242 +    SDL_Touch *touch = SDL_GetTouch(index);
   2.243 +
   2.244 +    if (!touch) {
   2.245 +        return SDL_FALSE;
   2.246 +    }
   2.247 +    return touch->relative_mode;
   2.248 +}
   2.249 +
   2.250 +Uint8
   2.251 +SDL_GetTouchState(int *x, int *y)
   2.252 +{
   2.253 +    SDL_Touch *touch = SDL_GetTouch(SDL_current_touch);
   2.254 +
   2.255 +    if (!touch) {
   2.256 +        if (x) {
   2.257 +            *x = 0;
   2.258 +        }
   2.259 +        if (y) {
   2.260 +            *y = 0;
   2.261 +        }
   2.262 +        return 0;
   2.263 +    }
   2.264 +
   2.265 +    if (x) {
   2.266 +        *x = touch->x;
   2.267 +    }
   2.268 +    if (y) {
   2.269 +        *y = touch->y;
   2.270 +    }
   2.271 +    return touch->buttonstate;
   2.272 +}
   2.273 +
   2.274 +Uint8
   2.275 +SDL_GetRelativeTouchState(int index, int *x, int *y)
   2.276 +{
   2.277 +    SDL_Touch *touch = SDL_GetTouch(index);
   2.278 +
   2.279 +    if (!touch) {
   2.280 +        if (x) {
   2.281 +            *x = 0;
   2.282 +        }
   2.283 +        if (y) {
   2.284 +            *y = 0;
   2.285 +        }
   2.286 +        return 0;
   2.287 +    }
   2.288 +
   2.289 +    if (x) {
   2.290 +        *x = touch->xdelta;
   2.291 +    }
   2.292 +    if (y) {
   2.293 +        *y = touch->ydelta;
   2.294 +    }
   2.295 +    touch->xdelta = 0;
   2.296 +    touch->ydelta = 0;
   2.297 +    return touch->buttonstate;
   2.298 +}
   2.299 +
   2.300 +void
   2.301 +SDL_SetTouchFocus(int id, SDL_Window * window)
   2.302 +{
   2.303 +    int index = SDL_GetTouchIndexId(id);
   2.304 +    SDL_Touch *touch = SDL_GetTouch(index);
   2.305 +    int i;
   2.306 +    SDL_bool focus;
   2.307 +
   2.308 +    if (!touch || (touch->focus == window)) {
   2.309 +        return;
   2.310 +    }
   2.311 +
   2.312 +    /* See if the current window has lost focus */
   2.313 +    if (touch->focus) {
   2.314 +        focus = SDL_FALSE;
   2.315 +        for (i = 0; i < SDL_num_touch; ++i) {
   2.316 +            SDL_Touch *check;
   2.317 +            if (i != index) {
   2.318 +                check = SDL_GetTouch(i);
   2.319 +                if (check && check->focus == touch->focus) {
   2.320 +                    focus = SDL_TRUE;
   2.321 +                    break;
   2.322 +                }
   2.323 +            }
   2.324 +        }
   2.325 +        if (!focus) {
   2.326 +            SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
   2.327 +        }
   2.328 +    }
   2.329 +
   2.330 +    touch->focus = window;
   2.331 +
   2.332 +    if (touch->focus) {
   2.333 +        focus = SDL_FALSE;
   2.334 +        for (i = 0; i < SDL_num_touch; ++i) {
   2.335 +            SDL_Touch *check;
   2.336 +            if (i != index) {
   2.337 +                check = SDL_GetTouch(i);
   2.338 +                if (check && check->focus == touch->focus) {
   2.339 +                    focus = SDL_TRUE;
   2.340 +                    break;
   2.341 +                }
   2.342 +            }
   2.343 +        }
   2.344 +        if (!focus) {
   2.345 +            SDL_SendWindowEvent(touch->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
   2.346 +        }
   2.347 +    }
   2.348 +}
   2.349 +
   2.350 +int
   2.351 +SDL_SendProximity(int id, int x, int y, int type)
   2.352 +{
   2.353 +    int index = SDL_GetTouchIndexId(id);
   2.354 +    SDL_Touch *touch = SDL_GetTouch(index);
   2.355 +    int posted = 0;
   2.356 +
   2.357 +    if (!touch) {
   2.358 +        return 0;
   2.359 +    }
   2.360 +
   2.361 +    touch->last_x = x;
   2.362 +    touch->last_y = y;
   2.363 +    if (SDL_GetEventState(type) == SDL_ENABLE) {
   2.364 +        SDL_Event event;
   2.365 +        event.proximity.which = (Uint8) index;
   2.366 +        event.proximity.x = x;
   2.367 +        event.proximity.y = y;
   2.368 +        event.proximity.cursor = touch->current_end;
   2.369 +        event.proximity.type = type;
   2.370 +        /* FIXME: is this right? */
   2.371 +        event.proximity.windowID = touch->focus ? touch->focus->id : 0;
   2.372 +        posted = (SDL_PushEvent(&event) > 0);
   2.373 +        if (type == SDL_PROXIMITYIN) {
   2.374 +            touch->proximity = SDL_TRUE;
   2.375 +        } else {
   2.376 +            touch->proximity = SDL_FALSE;
   2.377 +        }
   2.378 +    }
   2.379 +    return posted;
   2.380 +}
   2.381 +
   2.382 +int
   2.383 +SDL_SendTouchMotion(int id, int relative, int x, int y, int pressure)
   2.384 +{
   2.385 +    int index = SDL_GetTouchIndexId(id);
   2.386 +    SDL_Touch *touch = SDL_GetTouch(index);
   2.387 +    int posted;
   2.388 +    int xrel;
   2.389 +    int yrel;
   2.390 +    int x_max = 0, y_max = 0;
   2.391 +
   2.392 +    if (!touch || touch->flush_motion) {
   2.393 +        return 0;
   2.394 +    }
   2.395 +
   2.396 +    /* if the touch is out of proximity we don't to want to have any motion from it */
   2.397 +    if (touch->proximity == SDL_FALSE) {
   2.398 +        touch->last_x = x;
   2.399 +        touch->last_y = y;
   2.400 +        return 0;
   2.401 +    }
   2.402 +
   2.403 +    /* the relative motion is calculated regarding the system cursor last position */
   2.404 +    if (relative) {
   2.405 +        xrel = x;
   2.406 +        yrel = y;
   2.407 +        x = (touch->last_x + x);
   2.408 +        y = (touch->last_y + y);
   2.409 +    } else {
   2.410 +        xrel = x - touch->last_x;
   2.411 +        yrel = y - touch->last_y;
   2.412 +    }
   2.413 +
   2.414 +    /* Drop events that don't change state */
   2.415 +    if (!xrel && !yrel) {
   2.416 +#if 0
   2.417 +        printf("Touch event didn't change state - dropped!\n");
   2.418 +#endif
   2.419 +        return 0;
   2.420 +    }
   2.421 +
   2.422 +    /* Update internal touch coordinates */
   2.423 +    if (touch->relative_mode == SDL_FALSE) {
   2.424 +        touch->x = x;
   2.425 +        touch->y = y;
   2.426 +    } else {
   2.427 +        touch->x += xrel;
   2.428 +        touch->y += yrel;
   2.429 +    }
   2.430 +
   2.431 +    SDL_GetWindowSize(touch->focus, &x_max, &y_max);
   2.432 +
   2.433 +    /* make sure that the pointers find themselves inside the windows */
   2.434 +    /* only check if touch->xmax is set ! */
   2.435 +    if (x_max && touch->x > x_max) {
   2.436 +        touch->x = x_max;
   2.437 +    } else if (touch->x < 0) {
   2.438 +        touch->x = 0;
   2.439 +    }
   2.440 +
   2.441 +    if (y_max && touch->y > y_max) {
   2.442 +        touch->y = y_max;
   2.443 +    } else if (touch->y < 0) {
   2.444 +        touch->y = 0;
   2.445 +    }
   2.446 +
   2.447 +    touch->xdelta += xrel;
   2.448 +    touch->ydelta += yrel;
   2.449 +    touch->pressure = pressure;
   2.450 +
   2.451 +
   2.452 +
   2.453 +    /* Post the event, if desired */
   2.454 +    posted = 0;
   2.455 +    if (SDL_GetEventState(SDL_TOUCHMOTION) == SDL_ENABLE &&
   2.456 +        touch->proximity == SDL_TRUE) {
   2.457 +        SDL_Event event;
   2.458 +        event.motion.type = SDL_TOUCHMOTION;
   2.459 +        event.motion.which = (Uint8) index;
   2.460 +        event.motion.state = touch->buttonstate;
   2.461 +        event.motion.x = touch->x;
   2.462 +        event.motion.y = touch->y;
   2.463 +        event.motion.z = touch->z;
   2.464 +        event.motion.pressure = touch->pressure;
   2.465 +        event.motion.pressure_max = touch->pressure_max;
   2.466 +        event.motion.pressure_min = touch->pressure_min;
   2.467 +        event.motion.rotation = 0;
   2.468 +        event.motion.tilt_x = 0;
   2.469 +        event.motion.tilt_y = 0;
   2.470 +        event.motion.cursor = touch->current_end;
   2.471 +        event.motion.xrel = xrel;
   2.472 +        event.motion.yrel = yrel;
   2.473 +        event.motion.windowID = touch->focus ? touch->focus->id : 0;
   2.474 +        posted = (SDL_PushEvent(&event) > 0);
   2.475 +    }
   2.476 +    touch->last_x = touch->x;
   2.477 +    touch->last_y = touch->y;
   2.478 +    return posted;
   2.479 +}
   2.480 +
   2.481 +int
   2.482 +SDL_SendTouchButton(int id, Uint8 state, Uint8 button)
   2.483 +{
   2.484 +    int index = SDL_GetTouchIndexId(id);
   2.485 +    SDL_Touch *touch = SDL_GetTouch(index);
   2.486 +    int posted;
   2.487 +    Uint32 type;
   2.488 +
   2.489 +    if (!touch) {
   2.490 +        return 0;
   2.491 +    }
   2.492 +
   2.493 +    /* Figure out which event to perform */
   2.494 +    switch (state) {
   2.495 +    case SDL_PRESSED:
   2.496 +        if (touch->buttonstate & SDL_BUTTON(button)) {
   2.497 +            /* Ignore this event, no state change */
   2.498 +            return 0;
   2.499 +        }
   2.500 +        type = SDL_TOUCHBUTTONDOWN;
   2.501 +        touch->buttonstate |= SDL_BUTTON(button);
   2.502 +        break;
   2.503 +    case SDL_RELEASED:
   2.504 +        if (!(touch->buttonstate & SDL_BUTTON(button))) {
   2.505 +            /* Ignore this event, no state change */
   2.506 +            return 0;
   2.507 +        }
   2.508 +        type = SDL_TOUCHBUTTONUP;
   2.509 +        touch->buttonstate &= ~SDL_BUTTON(button);
   2.510 +        break;
   2.511 +    default:
   2.512 +        /* Invalid state -- bail */
   2.513 +        return 0;
   2.514 +    }
   2.515 +
   2.516 +    /* Post the event, if desired */
   2.517 +    posted = 0;
   2.518 +    if (SDL_GetEventState(type) == SDL_ENABLE) {
   2.519 +        SDL_Event event;
   2.520 +        event.type = type;
   2.521 +        event.button.which = (Uint8) index;
   2.522 +        event.button.state = state;
   2.523 +        event.button.button = button;
   2.524 +        event.button.x = touch->x;
   2.525 +        event.button.y = touch->y;
   2.526 +        event.button.windowID = touch->focus ? touch->focus->id : 0;
   2.527 +        posted = (SDL_PushEvent(&event) > 0);
   2.528 +    }
   2.529 +    return posted;
   2.530 +}
   2.531 +
   2.532 +int
   2.533 +SDL_SendTouchWheel(int index, int x, int y)
   2.534 +{
   2.535 +    SDL_Touch *touch = SDL_GetTouch(index);
   2.536 +    int posted;
   2.537 +
   2.538 +    if (!touch || (!x && !y)) {
   2.539 +        return 0;
   2.540 +    }
   2.541 +
   2.542 +    /* Post the event, if desired */
   2.543 +    posted = 0;
   2.544 +    if (SDL_GetEventState(SDL_TOUCHWHEEL) == SDL_ENABLE) {
   2.545 +        SDL_Event event;
   2.546 +        event.type = SDL_TOUCHWHEEL;
   2.547 +        event.wheel.which = (Uint8) index;
   2.548 +        event.wheel.x = x;
   2.549 +        event.wheel.y = y;
   2.550 +        event.wheel.windowID = touch->focus ? touch->focus->id : 0;
   2.551 +        posted = (SDL_PushEvent(&event) > 0);
   2.552 +    }
   2.553 +    return posted;
   2.554 +}
   2.555 +
   2.556 +
   2.557 +char *
   2.558 +SDL_GetTouchName(int index)
   2.559 +{
   2.560 +    SDL_Touch *touch = SDL_GetTouch(index);
   2.561 +    if (!touch) {
   2.562 +        return NULL;
   2.563 +    }
   2.564 +    return touch->name;
   2.565 +}
   2.566 +
   2.567 +void
   2.568 +SDL_ChangeEnd(int id, int end)
   2.569 +{
   2.570 +    int index = SDL_GetTouchIndexId(id);
   2.571 +    SDL_Touch *touch = SDL_GetTouch(index);
   2.572 +
   2.573 +    if (touch) {
   2.574 +        touch->current_end = end;
   2.575 +    }
   2.576 +}
   2.577 +
   2.578 +/* vi: set ts=4 sw=4 expandtab: */
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/events/SDL_touch_c.h	Tue May 25 23:23:23 2010 -0400
     3.3 @@ -0,0 +1,113 @@
     3.4 +/*
     3.5 +    SDL - Simple DirectMedia Layer
     3.6 +    Copyright (C) 1997-2010 Sam Lantinga
     3.7 +
     3.8 +    This library is free software; you can redistribute it and/or
     3.9 +    modify it under the terms of the GNU Lesser General Public
    3.10 +    License as published by the Free Software Foundation; either
    3.11 +    version 2.1 of the License, or (at your option) any later version.
    3.12 +
    3.13 +    This library is distributed in the hope that it will be useful,
    3.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.16 +    Lesser General Public License for more details.
    3.17 +
    3.18 +    You should have received a copy of the GNU Lesser General Public
    3.19 +    License along with this library; if not, write to the Free Software
    3.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    3.21 +
    3.22 +    Sam Lantinga
    3.23 +    slouken@libsdl.org
    3.24 +*/
    3.25 +#include "SDL_config.h"
    3.26 +
    3.27 +#ifndef _SDL_touch_c_h
    3.28 +#define _SDL_touch_c_h
    3.29 +
    3.30 +typedef struct SDL_Touch SDL_Touch;
    3.31 +
    3.32 +
    3.33 +struct SDL_Touch
    3.34 +{
    3.35 +    /* Warp the touch to (x,y) */
    3.36 +    void (*WarpTouch) (SDL_Touch * touch, SDL_Window * window, int x,
    3.37 +                       int y);
    3.38 +
    3.39 +    /* Free the touch when it's time */
    3.40 +    void (*FreeTouch) (SDL_Touch * touch);
    3.41 +
    3.42 +    /* data common for tablets */
    3.43 +    int pressure;
    3.44 +    int pressure_max;
    3.45 +    int pressure_min;
    3.46 +    int tilt;                   /* for future use */
    3.47 +    int rotation;               /* for future use */
    3.48 +    int total_ends;
    3.49 +    int current_end;
    3.50 +
    3.51 +    /* Data common to all touch */
    3.52 +    int id;
    3.53 +    SDL_Window *focus;
    3.54 +    int which;
    3.55 +    int x;
    3.56 +    int y;
    3.57 +    int z;                      /* for future use */
    3.58 +    int xdelta;
    3.59 +    int ydelta;
    3.60 +    int last_x, last_y;         /* the last reported x and y coordinates */
    3.61 +    char *name;
    3.62 +    Uint8 buttonstate;
    3.63 +    SDL_bool relative_mode;
    3.64 +    SDL_bool proximity;
    3.65 +    SDL_bool flush_motion;
    3.66 +
    3.67 +    SDL_Cursor *cursors;
    3.68 +    SDL_Cursor *def_cursor;
    3.69 +    SDL_Cursor *cur_cursor;
    3.70 +    SDL_bool cursor_shown;
    3.71 +
    3.72 +    void *driverdata;
    3.73 +};
    3.74 +
    3.75 +/* Initialize the touch subsystem */
    3.76 +extern int SDL_TouchInit(void);
    3.77 +
    3.78 +/* Get the touch at an index */
    3.79 +extern SDL_Touch *SDL_GetTouch(int index);
    3.80 +
    3.81 +/* Add a touch, possibly reattaching at a particular index (or -1),
    3.82 +   returning the index of the touch, or -1 if there was an error.
    3.83 + */
    3.84 +extern int SDL_AddTouch(const SDL_Touch * touch, char *name,
    3.85 +                        int pressure_max, int pressure_min, int ends);
    3.86 +
    3.87 +/* Remove a touch at an index, clearing the slot for later */
    3.88 +extern void SDL_DelTouch(int index);
    3.89 +
    3.90 +/* Clear the button state of a touch at an index */
    3.91 +extern void SDL_ResetTouch(int index);
    3.92 +
    3.93 +/* Set the touch focus window */
    3.94 +extern void SDL_SetTouchFocus(int id, SDL_Window * window);
    3.95 +
    3.96 +/* Send a touch motion event for a touch */
    3.97 +extern int SDL_SendTouchMotion(int id, int relative, int x, int y, int z);
    3.98 +
    3.99 +/* Send a touch button event for a touch */
   3.100 +extern int SDL_SendTouchButton(int id, Uint8 state, Uint8 button);
   3.101 +
   3.102 +/* Send a touch wheel event for a touch */
   3.103 +extern int SDL_SendTouchWheel(int id, int x, int y);
   3.104 +
   3.105 +/* Send a proximity event for a touch */
   3.106 +extern int SDL_SendProximity(int id, int x, int y, int type);
   3.107 +
   3.108 +/* Shutdown the touch subsystem */
   3.109 +extern void SDL_TouchQuit(void);
   3.110 +
   3.111 +/* FIXME: Where do these functions go in this header? */
   3.112 +extern void SDL_ChangeEnd(int id, int end);
   3.113 +
   3.114 +#endif /* _SDL_touch_c_h */
   3.115 +
   3.116 +/* vi: set ts=4 sw=4 expandtab: */
     4.1 --- a/src/video/x11/SDL_x11events.c	Mon May 24 23:44:24 2010 -0400
     4.2 +++ b/src/video/x11/SDL_x11events.c	Tue May 25 23:23:23 2010 -0400
     4.3 @@ -408,6 +408,10 @@
     4.4      while (X11_Pending(data->display)) {
     4.5          X11_DispatchEvent(_this);
     4.6      }
     4.7 +
     4.8 +
     4.9 +    /* Process Touch events - TODO When X gets touch support, REMOVE THIS*/
    4.10 +    
    4.11  }
    4.12  
    4.13  /* This is so wrong it hurts */
     5.1 Binary file touchTest/touchSimp has changed
     6.1 --- a/touchTest/touchSimp.c	Mon May 24 23:44:24 2010 -0400
     6.2 +++ b/touchTest/touchSimp.c	Tue May 25 23:23:23 2010 -0400
     6.3 @@ -20,6 +20,7 @@
     6.4  
     6.5  
     6.6  
     6.7 +
     6.8  typedef struct {
     6.9    int x,y;
    6.10  } Point;
    6.11 @@ -120,7 +121,7 @@
    6.12      device = argv[1];
    6.13    
    6.14    //Open Device
    6.15 -  if ((fd = open (device, O_RDONLY)) == -1)
    6.16 +  if ((fd = open (device, O_RDONLY | O_NONBLOCK)) == -1)
    6.17      printf ("%s is not a vaild device.\n", device);
    6.18    
    6.19    //Print Device Name
    6.20 @@ -189,50 +190,53 @@
    6.21  	}
    6.22  
    6.23        //poll for Touch <- Goal: make this a case:      
    6.24 -      if ((rd = read (fd, ev, size * 64)) < size)
    6.25 -	perror_exit ("read()");          
    6.26 +      
    6.27 +
    6.28 +      /*if ((rd = read (fd, ev, size * 64)) < size)
    6.29 +	perror_exit ("read()");          */
    6.30        //printf("time: %i\n type: %X\n code: %X\n value: %i\n ",
    6.31        //     ev->time,ev->type,ev->code,ev->value);
    6.32 -      for (i = 0; i < rd / sizeof(struct input_event); i++)
    6.33 -	switch (ev[i].type)	
    6.34 -	  {
    6.35 -	  case EV_ABS:
    6.36 -	    if(ev[i].code == ABS_X)
    6.37 -	      tx = ev[i].value;
    6.38 -	    else if (ev[i].code == ABS_Y)
    6.39 -	      ty = ev[i].value;
    6.40 -	    else if (ev[i].code == ABS_MISC)
    6.41 -	      {	     
    6.42 -		//printf("Misc:type: %X\n     code: %X\n     value: %i\n ",
    6.43 -		//      ev[i].type,ev[i].code,ev[i].value);
    6.44 -	      }
    6.45 -	    break;
    6.46 -	  case EV_MSC:
    6.47 -	    if(ev[i].code == MSC_SERIAL)
    6.48 -	      curf = ev[i].value;
    6.49 -	    break;
    6.50 -	  case EV_SYN:
    6.51 -	    curf -= 1;
    6.52 -	    if(tx >= 0)
    6.53 -	      finger[curf].x = tx;
    6.54 -	    if(ty >= 0)
    6.55 -	      finger[curf].y = ty;
    6.56 -
    6.57 -	    //printf("Synched: %i tx: %i, ty: %i\n",curf,finger[curf].x,finger[curf].y);
    6.58 -	    tx = -1;
    6.59 -	    ty = -1;
    6.60 -	    break;    
    6.61 -
    6.62 -	}
    6.63 -      //And draw
    6.64 -      DrawScreen(screen,h);
    6.65 -      /*
    6.66 -      for(i=0;i<512;i++) 
    6.67 -	if(keystat[i]) printf("%i\n",i);
    6.68 -      printf("Buttons:%i\n",bstatus);
    6.69 -      */
    6.70 -    }  
    6.71 -  SDL_Quit();
    6.72 -  
    6.73 +      if((rd = read (fd, ev, size * 64)) >= size)
    6.74 +	 for (i = 0; i < rd / sizeof(struct input_event); i++)
    6.75 +	   switch (ev[i].type)	
    6.76 +	     {
    6.77 +	     case EV_ABS:
    6.78 +	       if(ev[i].code == ABS_X)
    6.79 +		 tx = ev[i].value;
    6.80 +	       else if (ev[i].code == ABS_Y)
    6.81 +		 ty = ev[i].value;
    6.82 +	       else if (ev[i].code == ABS_MISC)
    6.83 +		 {	     
    6.84 +		   //printf("Misc:type: %X\n     code: %X\n     value: %i\n ",
    6.85 +		   //      ev[i].type,ev[i].code,ev[i].value);
    6.86 +		 }
    6.87 +	       break;
    6.88 +	     case EV_MSC:
    6.89 +	       if(ev[i].code == MSC_SERIAL)
    6.90 +		 curf = ev[i].value;
    6.91 +	       break;
    6.92 +	     case EV_SYN:
    6.93 +	       curf -= 1;
    6.94 +	       if(tx >= 0)
    6.95 +		 finger[curf].x = tx;
    6.96 +	       if(ty >= 0)
    6.97 +		 finger[curf].y = ty;
    6.98 +	       
    6.99 +	       //printf("Synched: %i tx: %i, ty: %i\n",curf,finger[curf].x,finger[curf].y);
   6.100 +	       tx = -1;
   6.101 +	       ty = -1;
   6.102 +	       break;    
   6.103 +	       
   6.104 +	     }
   6.105 +	 //And draw
   6.106 +     DrawScreen(screen,h);
   6.107 +	 /*
   6.108 +	   for(i=0;i<512;i++) 
   6.109 +	   if(keystat[i]) printf("%i\n",i);
   6.110 +	   printf("Buttons:%i\n",bstatus);
   6.111 +	 */
   6.112 +     }  
   6.113 +     SDL_Quit();
   6.114 +      
   6.115    return 0;
   6.116  }