Mercurial > sdl-ios-xcode
annotate src/video/x11/SDL_x11mouse.c @ 2840:53ca0d758b0a
The previous checkin fixes the crash, so at least we're not overrunning
the texture pixel data anymore...
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 06 Dec 2008 17:43:10 +0000 |
parents | f55c87ae336b |
children | 99210400e8b9 |
rev | line source |
---|---|
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 Sam Lantinga |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 */ |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 #include "SDL_config.h" |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 #include "SDL_x11video.h" |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 #include "../../events/SDL_mouse_c.h" |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 void |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 X11_InitMouse(_THIS) |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 { |
2763
6fc50bdd88c0
Some cleanups on the new XInput code.
Ryan C. Gordon <icculus@icculus.org>
parents:
2710
diff
changeset
|
29 #if SDL_VIDEO_DRIVER_X11_XINPUT |
2710
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
30 XDevice **newDevices; |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
31 int i, j, index = 0, numOfDevices; |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
32 XDeviceInfo *DevList; |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
33 XAnyClassPtr deviceClass; |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
2710
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
35 |
2763
6fc50bdd88c0
Some cleanups on the new XInput code.
Ryan C. Gordon <icculus@icculus.org>
parents:
2710
diff
changeset
|
36 SDL_XDevices = NULL; |
6fc50bdd88c0
Some cleanups on the new XInput code.
Ryan C. Gordon <icculus@icculus.org>
parents:
2710
diff
changeset
|
37 SDL_NumOfXDevices = 0; |
6fc50bdd88c0
Some cleanups on the new XInput code.
Ryan C. Gordon <icculus@icculus.org>
parents:
2710
diff
changeset
|
38 |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2763
diff
changeset
|
39 if (!SDL_X11_HAVE_XINPUT) { |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2763
diff
changeset
|
40 /* should have dynamically loaded, but wasn't available. */ |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2763
diff
changeset
|
41 return; |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2763
diff
changeset
|
42 } |
2763
6fc50bdd88c0
Some cleanups on the new XInput code.
Ryan C. Gordon <icculus@icculus.org>
parents:
2710
diff
changeset
|
43 |
2710
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
44 /* we're getting the list of input devices */ |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
45 DevList = XListInputDevices(data->display, &numOfDevices); |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
46 SDL_XDevices = (XDevice **) SDL_malloc(sizeof(XDevice)); |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
47 |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
48 /* we're aquiring valuators:mices, tablets, etc. */ |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
49 for (i = 0; i < numOfDevices; ++i) { |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
50 /* if it's the core pointer or core keyborard we don't want it */ |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
51 if ((DevList[i].use != IsXPointer && DevList[i].use != IsXKeyboard)) { |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
52 /* we have to check all of the device classes */ |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
53 deviceClass = DevList[i].inputclassinfo; |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
54 for (j = 0; j < DevList[i].num_classes; ++j) { |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
55 if (deviceClass->class == ValuatorClass) { /* bingo ;) */ |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
56 XValuatorInfo *valInfo; |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
57 SDL_Mouse mouse; |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 |
2710
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
59 newDevices = |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
60 (XDevice **) SDL_realloc(SDL_XDevices, |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
61 (index + |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
62 1) * sizeof(*newDevices)); |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
63 if (!newDevices) { |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
64 SDL_OutOfMemory(); |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
65 return; |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
66 } |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
67 SDL_XDevices = newDevices; |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
68 SDL_XDevices[index] = |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
69 XOpenDevice(data->display, DevList[i].id); |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
70 SDL_zero(mouse); |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
71 |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
72 /* the id of the device differs from its index |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
73 * so we're assigning the index of a device to it's id */ |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
74 SDL_SetMouseIndexId(DevList[i].id, index); |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
75 /* lets get the device parameters */ |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
76 valInfo = (XValuatorInfo *) deviceClass; |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
77 /* if the device reports pressure, lets check it parameteres */ |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
78 if (valInfo->num_axes > 2) { |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
79 data->mouse = |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
80 SDL_AddMouse(&mouse, index++, DevList[i].name, |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
81 valInfo->axes[2].max_value, |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
82 valInfo->axes[2].min_value, 1); |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
83 } else { |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
84 data->mouse = |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
85 SDL_AddMouse(&mouse, index++, DevList[i].name, 0, |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
86 0, 1); |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
87 } |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
88 break; |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
89 } |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
90 /* if it's not class we're interested in, lets go further */ |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
91 deviceClass = |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
92 (XAnyClassPtr) ((char *) deviceClass + |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
93 deviceClass->length); |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
94 } |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
95 } |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
96 } |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
97 XFreeDeviceList(DevList); |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
98 |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
99 SDL_NumOfXDevices = index; |
2763
6fc50bdd88c0
Some cleanups on the new XInput code.
Ryan C. Gordon <icculus@icculus.org>
parents:
2710
diff
changeset
|
100 #endif |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 void |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 X11_QuitMouse(_THIS) |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 { |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 |
2763
6fc50bdd88c0
Some cleanups on the new XInput code.
Ryan C. Gordon <icculus@icculus.org>
parents:
2710
diff
changeset
|
108 /* !!! FIXME: use XCloseDevice()? Or maybe handle under SDL_MouseQuit()? */ |
6fc50bdd88c0
Some cleanups on the new XInput code.
Ryan C. Gordon <icculus@icculus.org>
parents:
2710
diff
changeset
|
109 |
2710
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
110 /* let's delete all of the mice */ |
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1950
diff
changeset
|
111 SDL_MouseQuit(); |
1950
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 } |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 |
a344e42bce3b
Started work on the new X11 driver.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 /* vi: set ts=4 sw=4 expandtab: */ |