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
slouken@1950
     1
/*
slouken@1950
     2
    SDL - Simple DirectMedia Layer
slouken@1950
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@1950
     4
slouken@1950
     5
    This library is free software; you can redistribute it and/or
slouken@1950
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1950
     7
    License as published by the Free Software Foundation; either
slouken@1950
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1950
     9
slouken@1950
    10
    This library is distributed in the hope that it will be useful,
slouken@1950
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1950
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1950
    13
    Lesser General Public License for more details.
slouken@1950
    14
slouken@1950
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1950
    16
    License along with this library; if not, write to the Free Software
slouken@1950
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1950
    18
slouken@1950
    19
    Sam Lantinga
slouken@1950
    20
    slouken@libsdl.org
slouken@1950
    21
*/
slouken@1950
    22
#include "SDL_config.h"
slouken@1950
    23
slouken@1950
    24
#include "SDL_x11video.h"
slouken@1950
    25
slouken@1950
    26
#include "../../events/SDL_mouse_c.h"
slouken@1950
    27
slouken@1950
    28
void
slouken@1950
    29
X11_InitMouse(_THIS)
slouken@1950
    30
{
kazeuser@3760
    31
    extern XDevice **SDL_XDevices;
kazeuser@3760
    32
    XDevice **newDevices;
kazeuser@3760
    33
    int i,j,index=0, numOfDevices;
kazeuser@3760
    34
    extern int SDL_NumOfXDevices;
kazeuser@3760
    35
    XDeviceInfo *DevList;
kazeuser@3760
    36
    XAnyClassPtr deviceClass;
slouken@1950
    37
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
kazeuser@3760
    38
   
kazeuser@3760
    39
    DevList=XListInputDevices(data->display, &numOfDevices);
kazeuser@3761
    40
    SDL_XDevices=(XDevice**) SDL_malloc(sizeof(XDevice));
kazeuser@3760
    41
    for(i=0;i<numOfDevices;++i)
kazeuser@3760
    42
    {
kazeuser@3760
    43
        if((DevList[i].use!=IsXPointer && DevList[i].use!=IsXKeyboard))
kazeuser@3760
    44
        {
kazeuser@3760
    45
            deviceClass=DevList[i].inputclassinfo;
kazeuser@3760
    46
            for(j=0;j<DevList[i].num_classes;++j)
kazeuser@3760
    47
            {
kazeuser@3760
    48
                if(deviceClass->class==ValuatorClass)
kazeuser@3760
    49
                {
kazeuser@3766
    50
                    XValuatorInfo* valInfo;
kazeuser@3760
    51
                    newDevices= (XDevice**) SDL_realloc(SDL_XDevices, (index+1)*sizeof(*newDevices));
kazeuser@3760
    52
                    if(!newDevices)
kazeuser@3760
    53
                    {
kazeuser@3760
    54
                        SDL_OutOfMemory();
kazeuser@3760
    55
                        return -1;
kazeuser@3760
    56
                    }
kazeuser@3760
    57
                    SDL_XDevices=newDevices;
kazeuser@3760
    58
                    SDL_XDevices[index]=XOpenDevice(data->display,DevList[i].id);
kazeuser@3760
    59
                    SDL_Mouse mouse;
kazeuser@3760
    60
                    SDL_zero(mouse);
kazeuser@3760
    61
                    SDL_SetIndexId(DevList[i].id,index);
kazeuser@3766
    62
                    valInfo=(XValuatorInfo*)deviceClass;
kazeuser@3766
    63
                    if(valInfo->num_axes>2)
kazeuser@3766
    64
                    {
kazeuser@3766
    65
                        data->mouse = SDL_AddMouse(&mouse, index++,DevList[i].name,valInfo->axes[2].max_value,valInfo->axes[2].min_value);
kazeuser@3766
    66
                    }
kazeuser@3766
    67
                    else
kazeuser@3766
    68
                    {
kazeuser@3766
    69
                         data->mouse = SDL_AddMouse(&mouse, index++,DevList[i].name,0,0);
kazeuser@3766
    70
                    }
kazeuser@3760
    71
                    break;
kazeuser@3760
    72
                }
kazeuser@3760
    73
                deviceClass=(XAnyClassPtr)((char*)deviceClass + deviceClass->length);
kazeuser@3760
    74
            }
kazeuser@3760
    75
        }
kazeuser@3760
    76
    }
kazeuser@3760
    77
    XFreeDeviceList(DevList);
kazeuser@3760
    78
    SDL_NumOfXDevices=index;
slouken@1950
    79
}
slouken@1950
    80
slouken@1950
    81
void
slouken@1950
    82
X11_QuitMouse(_THIS)
slouken@1950
    83
{
slouken@1950
    84
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@1950
    85
kazeuser@3760
    86
    SDL_MouseQuit();
slouken@1950
    87
}
slouken@1950
    88
slouken@1950
    89
/* vi: set ts=4 sw=4 expandtab: */