src/video/x11/SDL_x11mouse.c
author Szymon Wilczek
Sun, 06 Jul 2008 09:24:56 +0000
branchgsoc2008_manymouse
changeset 3766 24db5d326f57
parent 3761 e0c95ad1ba87
child 3772 9087a84cba51
permissions -rw-r--r--
Pressure levels. Documentation http://wilku.ravenlord.ws/doku.php?id=documentation
     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     DevList=XListInputDevices(data->display, &numOfDevices);
    40     SDL_XDevices=(XDevice**) SDL_malloc(sizeof(XDevice));
    41     for(i=0;i<numOfDevices;++i)
    42     {
    43         if((DevList[i].use!=IsXPointer && DevList[i].use!=IsXKeyboard))
    44         {
    45             deviceClass=DevList[i].inputclassinfo;
    46             for(j=0;j<DevList[i].num_classes;++j)
    47             {
    48                 if(deviceClass->class==ValuatorClass)
    49                 {
    50                     XValuatorInfo* valInfo;
    51                     newDevices= (XDevice**) SDL_realloc(SDL_XDevices, (index+1)*sizeof(*newDevices));
    52                     if(!newDevices)
    53                     {
    54                         SDL_OutOfMemory();
    55                         return -1;
    56                     }
    57                     SDL_XDevices=newDevices;
    58                     SDL_XDevices[index]=XOpenDevice(data->display,DevList[i].id);
    59                     SDL_Mouse mouse;
    60                     SDL_zero(mouse);
    61                     SDL_SetIndexId(DevList[i].id,index);
    62                     valInfo=(XValuatorInfo*)deviceClass;
    63                     if(valInfo->num_axes>2)
    64                     {
    65                         data->mouse = SDL_AddMouse(&mouse, index++,DevList[i].name,valInfo->axes[2].max_value,valInfo->axes[2].min_value);
    66                     }
    67                     else
    68                     {
    69                          data->mouse = SDL_AddMouse(&mouse, index++,DevList[i].name,0,0);
    70                     }
    71                     break;
    72                 }
    73                 deviceClass=(XAnyClassPtr)((char*)deviceClass + deviceClass->length);
    74             }
    75         }
    76     }
    77     XFreeDeviceList(DevList);
    78     SDL_NumOfXDevices=index;
    79 }
    80 
    81 void
    82 X11_QuitMouse(_THIS)
    83 {
    84     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    85 
    86     SDL_MouseQuit();
    87 }
    88 
    89 /* vi: set ts=4 sw=4 expandtab: */