src/video/x11/SDL_x11mouse.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 04 Oct 2008 06:46:59 +0000
changeset 2765 f55c87ae336b
parent 2763 6fc50bdd88c0
child 2859 99210400e8b9
permissions -rw-r--r--
Final merge of Google Summer of Code 2008 work...

Bring SDL to iPhone and iPod Touch
by Holmes Futrell, mentored by Sam Lantinga
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
#include "SDL_x11video.h"
slouken@1950
    24
#include "../../events/SDL_mouse_c.h"
slouken@1950
    25
slouken@1950
    26
void
slouken@1950
    27
X11_InitMouse(_THIS)
slouken@1950
    28
{
icculus@2763
    29
#if SDL_VIDEO_DRIVER_X11_XINPUT
slouken@2710
    30
    XDevice **newDevices;
slouken@2710
    31
    int i, j, index = 0, numOfDevices;
slouken@2710
    32
    XDeviceInfo *DevList;
slouken@2710
    33
    XAnyClassPtr deviceClass;
slouken@1950
    34
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@1950
    35
icculus@2763
    36
    SDL_XDevices = NULL;
icculus@2763
    37
    SDL_NumOfXDevices = 0;
icculus@2763
    38
slouken@2765
    39
    if (!SDL_X11_HAVE_XINPUT) {
slouken@2765
    40
        /* should have dynamically loaded, but wasn't available. */
slouken@2765
    41
        return;
slouken@2765
    42
    }
icculus@2763
    43
slouken@2710
    44
    /* we're getting the list of input devices */
slouken@2710
    45
    DevList = XListInputDevices(data->display, &numOfDevices);
slouken@2710
    46
    SDL_XDevices = (XDevice **) SDL_malloc(sizeof(XDevice));
slouken@2710
    47
slouken@2710
    48
    /* we're aquiring valuators:mices, tablets, etc. */
slouken@2710
    49
    for (i = 0; i < numOfDevices; ++i) {
slouken@2710
    50
        /* if it's the core pointer or core keyborard we don't want it */
slouken@2710
    51
        if ((DevList[i].use != IsXPointer && DevList[i].use != IsXKeyboard)) {
slouken@2710
    52
            /* we have to check all of the device classes */
slouken@2710
    53
            deviceClass = DevList[i].inputclassinfo;
slouken@2710
    54
            for (j = 0; j < DevList[i].num_classes; ++j) {
slouken@2710
    55
                if (deviceClass->class == ValuatorClass) {      /* bingo ;) */
slouken@2710
    56
                    XValuatorInfo *valInfo;
slouken@2710
    57
                    SDL_Mouse mouse;
slouken@2710
    58
slouken@2710
    59
                    newDevices =
slouken@2710
    60
                        (XDevice **) SDL_realloc(SDL_XDevices,
slouken@2710
    61
                                                 (index +
slouken@2710
    62
                                                  1) * sizeof(*newDevices));
slouken@2710
    63
                    if (!newDevices) {
slouken@2710
    64
                        SDL_OutOfMemory();
slouken@2710
    65
                        return;
slouken@2710
    66
                    }
slouken@2710
    67
                    SDL_XDevices = newDevices;
slouken@2710
    68
                    SDL_XDevices[index] =
slouken@2710
    69
                        XOpenDevice(data->display, DevList[i].id);
slouken@2710
    70
                    SDL_zero(mouse);
slouken@2710
    71
slouken@2710
    72
                    /* the id of the device differs from its index
slouken@2710
    73
                     * so we're assigning the index of a device to it's id */
slouken@2710
    74
                    SDL_SetMouseIndexId(DevList[i].id, index);
slouken@2710
    75
                    /* lets get the device parameters */
slouken@2710
    76
                    valInfo = (XValuatorInfo *) deviceClass;
slouken@2710
    77
                    /* if the device reports pressure, lets check it parameteres */
slouken@2710
    78
                    if (valInfo->num_axes > 2) {
slouken@2710
    79
                        data->mouse =
slouken@2710
    80
                            SDL_AddMouse(&mouse, index++, DevList[i].name,
slouken@2710
    81
                                         valInfo->axes[2].max_value,
slouken@2710
    82
                                         valInfo->axes[2].min_value, 1);
slouken@2710
    83
                    } else {
slouken@2710
    84
                        data->mouse =
slouken@2710
    85
                            SDL_AddMouse(&mouse, index++, DevList[i].name, 0,
slouken@2710
    86
                                         0, 1);
slouken@2710
    87
                    }
slouken@2710
    88
                    break;
slouken@2710
    89
                }
slouken@2710
    90
                /* if it's not class we're interested in, lets go further */
slouken@2710
    91
                deviceClass =
slouken@2710
    92
                    (XAnyClassPtr) ((char *) deviceClass +
slouken@2710
    93
                                    deviceClass->length);
slouken@2710
    94
            }
slouken@2710
    95
        }
slouken@2710
    96
    }
slouken@2710
    97
    XFreeDeviceList(DevList);
slouken@2710
    98
slouken@2710
    99
    SDL_NumOfXDevices = index;
icculus@2763
   100
#endif
slouken@1950
   101
}
slouken@1950
   102
slouken@1950
   103
void
slouken@1950
   104
X11_QuitMouse(_THIS)
slouken@1950
   105
{
slouken@1950
   106
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
slouken@1950
   107
icculus@2763
   108
    /* !!! FIXME: use XCloseDevice()? Or maybe handle under SDL_MouseQuit()? */
icculus@2763
   109
slouken@2710
   110
    /* let's delete all of the mice */
slouken@2710
   111
    SDL_MouseQuit();
slouken@1950
   112
}
slouken@1950
   113
slouken@1950
   114
/* vi: set ts=4 sw=4 expandtab: */