src/video/x11/SDL_x11mouse.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 01 Sep 2008 16:04:20 +0000
changeset 2738 79c1bd651f04
parent 2710 44e49d3fa6cf
child 2763 6fc50bdd88c0
permissions -rw-r--r--
Fixed a bunch of compile warnings on Mac OS X
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 #include "SDL_x11video.h"
    25 
    26 #include "../../events/SDL_mouse_c.h"
    27 
    28 void
    29 X11_InitMouse(_THIS)
    30 {
    31     extern XDevice **SDL_XDevices;
    32     XDevice **newDevices;
    33     int i, j, index = 0, numOfDevices;
    34     extern int SDL_NumOfXDevices;
    35     XDeviceInfo *DevList;
    36     XAnyClassPtr deviceClass;
    37     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    38 
    39     /* we're getting the list of input devices */
    40     DevList = XListInputDevices(data->display, &numOfDevices);
    41     SDL_XDevices = (XDevice **) SDL_malloc(sizeof(XDevice));
    42 
    43     /* we're aquiring valuators:mices, tablets, etc. */
    44     for (i = 0; i < numOfDevices; ++i) {
    45         /* if it's the core pointer or core keyborard we don't want it */
    46         if ((DevList[i].use != IsXPointer && DevList[i].use != IsXKeyboard)) {
    47             /* we have to check all of the device classes */
    48             deviceClass = DevList[i].inputclassinfo;
    49             for (j = 0; j < DevList[i].num_classes; ++j) {
    50                 if (deviceClass->class == ValuatorClass) {      /* bingo ;) */
    51                     XValuatorInfo *valInfo;
    52                     SDL_Mouse mouse;
    53 
    54                     newDevices =
    55                         (XDevice **) SDL_realloc(SDL_XDevices,
    56                                                  (index +
    57                                                   1) * sizeof(*newDevices));
    58                     if (!newDevices) {
    59                         SDL_OutOfMemory();
    60                         return;
    61                     }
    62                     SDL_XDevices = newDevices;
    63                     SDL_XDevices[index] =
    64                         XOpenDevice(data->display, DevList[i].id);
    65                     SDL_zero(mouse);
    66 
    67                     /* the id of the device differs from its index
    68                      * so we're assigning the index of a device to it's id */
    69                     SDL_SetMouseIndexId(DevList[i].id, index);
    70                     /* lets get the device parameters */
    71                     valInfo = (XValuatorInfo *) deviceClass;
    72                     /* if the device reports pressure, lets check it parameteres */
    73                     if (valInfo->num_axes > 2) {
    74                         data->mouse =
    75                             SDL_AddMouse(&mouse, index++, DevList[i].name,
    76                                          valInfo->axes[2].max_value,
    77                                          valInfo->axes[2].min_value, 1);
    78                     } else {
    79                         data->mouse =
    80                             SDL_AddMouse(&mouse, index++, DevList[i].name, 0,
    81                                          0, 1);
    82                     }
    83                     break;
    84                 }
    85                 /* if it's not class we're interested in, lets go further */
    86                 deviceClass =
    87                     (XAnyClassPtr) ((char *) deviceClass +
    88                                     deviceClass->length);
    89             }
    90         }
    91     }
    92     XFreeDeviceList(DevList);
    93 
    94     SDL_NumOfXDevices = index;
    95 }
    96 
    97 void
    98 X11_QuitMouse(_THIS)
    99 {
   100     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
   101 
   102     /* let's delete all of the mice */
   103     SDL_MouseQuit();
   104 }
   105 
   106 /* vi: set ts=4 sw=4 expandtab: */