src/video/x11/SDL_x11touch.c
author Ryan C. Gordon <icculus@icculus.org>
Thu, 13 Oct 2011 01:08:30 -0400
changeset 5981 75caa8a7d559
parent 5968 b229328c7ad4
child 6138 4c64952a58fb
permissions -rw-r--r--
Fixed a whole slew of compiler warnings that -Wall exposed.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
     2
  Simple DirectMedia Layer
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
     3
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
     7
  arising from the use of this software.
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    11
  freely, subject to the following restrictions:
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5481
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    20
*/
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    21
#include "SDL_config.h"
5481
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    22
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    23
#if SDL_VIDEO_DRIVER_X11
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    24
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    25
#include "SDL_x11video.h"
4923
1002d074d459 Renamed X11 touch files for consistency
Sam Lantinga <slouken@libsdl.org>
parents: 4683
diff changeset
    26
#include "SDL_x11touch.h"
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    27
#include "../../events/SDL_touch_c.h"
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    28
4681
5378f2d0754f Fixed some Gesture bugs
Jim Grandpre <jim.tla@gmail.com>
parents: 4678
diff changeset
    29
5378f2d0754f Fixed some Gesture bugs
Jim Grandpre <jim.tla@gmail.com>
parents: 4678
diff changeset
    30
#ifdef SDL_INPUT_LINUXEV
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    31
#include <linux/input.h>
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    32
#include <fcntl.h>
4669
62e6a6e9720b Fixed x11 compile bugs.
jimtla
parents: 4646
diff changeset
    33
#endif
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    34
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    35
void
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    36
X11_InitTouch(_THIS)
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    37
{
4681
5378f2d0754f Fixed some Gesture bugs
Jim Grandpre <jim.tla@gmail.com>
parents: 4678
diff changeset
    38
#ifdef SDL_INPUT_LINUXEV
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    39
  FILE *fd;
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    40
  fd = fopen("/proc/bus/input/devices","r");
5966
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    41
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    42
  int i = 0;
5968
b229328c7ad4 Fixed to compile with pedantic C
Sam Lantinga <slouken@libsdl.org>
parents: 5967
diff changeset
    43
  int tsfd;
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    44
  char line[256];
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    45
  char tstr[256];
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    46
  int vendor = -1,product = -1,event = -1;
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    47
  while(!feof(fd)) {
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    48
    if(fgets(line,256,fd) <=0) continue;
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    49
    if(line[0] == '\n') {
5966
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    50
      if(vendor == 1386 || vendor==1) {
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    51
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    52
        sprintf(tstr,"/dev/input/event%i",event);
5603
e1ca92e7f2ff X11 touch handling fixed for one device (LPC32xx Touchscreen).
Ryan C. Gordon <icculus@icculus.org>
parents: 5535
diff changeset
    53
5968
b229328c7ad4 Fixed to compile with pedantic C
Sam Lantinga <slouken@libsdl.org>
parents: 5967
diff changeset
    54
        tsfd = open( tstr, O_RDONLY | O_NONBLOCK );
5967
ae97a61f002f ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5966
diff changeset
    55
        if ( tsfd == -1 )
ae97a61f002f ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5966
diff changeset
    56
            continue;   /* Maybe not enough permissions ? */
ae97a61f002f ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5966
diff changeset
    57
5966
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    58
        SDL_Touch touch;
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    59
        touch.pressure_max = 0;
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    60
        touch.pressure_min = 0;
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    61
        touch.id = event; 
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    62
5966
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    63
        touch.driverdata = SDL_malloc(sizeof(EventTouchData));
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    64
        EventTouchData* data = (EventTouchData*)(touch.driverdata);
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    65
5966
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    66
        data->x = -1;
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    67
        data->y = -1;
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    68
        data->pressure = -1;
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    69
        data->finger = 0;
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    70
        data->up = SDL_FALSE;
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    71
        data->down = SDL_FALSE;
4683
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4681
diff changeset
    72
5967
ae97a61f002f ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5966
diff changeset
    73
        data->eventStream = tsfd;
5966
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    74
        ioctl (data->eventStream, EVIOCGNAME (sizeof (tstr)), tstr);
4646
eea1bf53effa Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents: 4645
diff changeset
    75
5966
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    76
        int abs[5];
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    77
        ioctl(data->eventStream,EVIOCGABS(0),abs);	
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    78
        touch.x_min = abs[1];
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    79
        touch.x_max = abs[2];
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    80
        touch.native_xres = touch.x_max - touch.x_min;
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    81
        ioctl(data->eventStream,EVIOCGABS(ABS_Y),abs);	
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    82
        touch.y_min = abs[1];
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    83
        touch.y_max = abs[2];
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    84
        touch.native_yres = touch.y_max - touch.y_min;
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    85
        ioctl(data->eventStream,EVIOCGABS(ABS_PRESSURE),abs);	
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    86
        touch.pressure_min = abs[1];
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    87
        touch.pressure_max = abs[2];
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    88
        touch.native_pressureres = touch.pressure_max - touch.pressure_min;
4646
eea1bf53effa Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents: 4645
diff changeset
    89
5966
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    90
        SDL_AddTouch(&touch, tstr);
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    91
      }
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    92
      vendor = -1;
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    93
      product = -1;
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    94
      event = -1;      
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    95
    }
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    96
    else if(line[0] == 'I') {
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    97
      i = 1;
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    98
      while(line[i]) {
5966
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
    99
        sscanf(&line[i],"Vendor=%x",&vendor);
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
   100
        sscanf(&line[i],"Product=%x",&product);
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
   101
        i++;
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   102
      }
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   103
    }
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   104
    else if(line[0] == 'H') {
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   105
      i = 1;
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   106
      while(line[i]) {
5966
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
   107
        sscanf(&line[i],"event%d",&event);
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
   108
        i++;
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   109
      }
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   110
    }
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   111
  }
5966
2edecf22a2e7 ============================================================
Sam Lantinga <slouken@libsdl.org>
parents: 5603
diff changeset
   112
5981
75caa8a7d559 Fixed a whole slew of compiler warnings that -Wall exposed.
Ryan C. Gordon <icculus@icculus.org>
parents: 5968
diff changeset
   113
  fclose(fd);
4669
62e6a6e9720b Fixed x11 compile bugs.
jimtla
parents: 4646
diff changeset
   114
#endif
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   115
}
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   116
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   117
void
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   118
X11_QuitTouch(_THIS)
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   119
{
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   120
    SDL_TouchQuit();
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   121
}
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   122
5481
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   123
#endif /* SDL_VIDEO_DRIVER_X11 */
22dfc3958dc3 Fixed so code will compile with SDL_config_minimal.h
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
   124
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   125
/* vi: set ts=4 sw=4 expandtab: */