Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11mouse.c @ 2940:b93965a16fe0
Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Fixed building SDL without XInput support
Simplified the process of registering a mouse device
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 01 Jan 2009 07:59:08 +0000 |
parents | 99210400e8b9 |
children | 1e431c2631ee |
comparison
equal
deleted
inserted
replaced
2939:084e5b4fc5be | 2940:b93965a16fe0 |
---|---|
19 Sam Lantinga | 19 Sam Lantinga |
20 slouken@libsdl.org | 20 slouken@libsdl.org |
21 */ | 21 */ |
22 #include "SDL_config.h" | 22 #include "SDL_config.h" |
23 #include "SDL_x11video.h" | 23 #include "SDL_x11video.h" |
24 #include "SDL_x11mouse.h" | |
24 #include "../../events/SDL_mouse_c.h" | 25 #include "../../events/SDL_mouse_c.h" |
26 | |
27 #if SDL_VIDEO_DRIVER_X11_XINPUT | |
28 static void | |
29 X11_FreeMouse(SDL_Mouse *mouse) | |
30 { | |
31 X11_MouseData *data = (X11_MouseData *)mouse->driverdata; | |
32 | |
33 if (data) { | |
34 XCloseDevice(data->display, mouse->id); | |
35 SDL_free(data); | |
36 } | |
37 } | |
38 #endif | |
25 | 39 |
26 void | 40 void |
27 X11_InitMouse(_THIS) | 41 X11_InitMouse(_THIS) |
28 { | 42 { |
43 SDL_Mouse mouse; | |
29 #if SDL_VIDEO_DRIVER_X11_XINPUT | 44 #if SDL_VIDEO_DRIVER_X11_XINPUT |
30 XDevice **newDevices; | 45 Display *display = ((SDL_VideoData *) _this->driverdata)->display; |
31 int i, j, index = 0, numOfDevices; | 46 X11_MouseData *data; |
47 int i, j, n; | |
32 XDeviceInfo *DevList; | 48 XDeviceInfo *DevList; |
33 XAnyClassPtr deviceClass; | 49 XAnyClassPtr deviceClass; |
34 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | 50 int event_code; |
51 XEventClass xEvent; | |
52 #endif | |
35 | 53 |
36 SDL_XDevices = NULL; | 54 SDL_zero(mouse); |
37 SDL_NumOfXDevices = 0; | 55 SDL_AddMouse(&mouse, "CorePointer", 0, 0, 1); |
38 | 56 |
57 #if SDL_VIDEO_DRIVER_X11_XINPUT | |
39 if (!SDL_X11_HAVE_XINPUT) { | 58 if (!SDL_X11_HAVE_XINPUT) { |
40 /* should have dynamically loaded, but wasn't available. */ | 59 /* should have dynamically loaded, but wasn't available. */ |
41 return; | 60 return; |
42 } | 61 } |
43 | 62 |
44 /* we're getting the list of input devices */ | 63 /* we're getting the list of input devices */ |
45 DevList = XListInputDevices(data->display, &numOfDevices); | 64 DevList = XListInputDevices(display, &n); |
46 SDL_XDevices = (XDevice **) SDL_malloc(sizeof(XDevice)); | |
47 | 65 |
48 /* we're aquiring valuators:mices, tablets, etc. */ | 66 /* we're aquiring valuators: mice, tablets, etc. */ |
49 for (i = 0; i < numOfDevices; ++i) { | 67 for (i = 0; i < n; ++i) { |
50 /* if it's the core pointer or core keyborard we don't want it */ | 68 /* if it's the core pointer or core keyborard we don't want it */ |
51 if ((DevList[i].use != IsXPointer && DevList[i].use != IsXKeyboard)) { | 69 if ((DevList[i].use != IsXPointer && DevList[i].use != IsXKeyboard)) { |
52 /* we have to check all of the device classes */ | 70 /* we have to check all of the device classes */ |
53 deviceClass = DevList[i].inputclassinfo; | 71 deviceClass = DevList[i].inputclassinfo; |
54 for (j = 0; j < DevList[i].num_classes; ++j) { | 72 for (j = 0; j < DevList[i].num_classes; ++j) { |
55 if (deviceClass->class == ValuatorClass) { /* bingo ;) */ | 73 if (deviceClass->class == ValuatorClass) { /* bingo ;) */ |
56 XValuatorInfo *valInfo; | 74 XValuatorInfo *valInfo; |
57 SDL_Mouse mouse; | |
58 | 75 |
59 newDevices = | 76 data = (X11_MouseData *)SDL_calloc(1, sizeof(*data)); |
60 (XDevice **) SDL_realloc(SDL_XDevices, | 77 if (!data) { |
61 (index + | 78 continue; |
62 1) * sizeof(*newDevices)); | |
63 if (!newDevices) { | |
64 SDL_OutOfMemory(); | |
65 return; | |
66 } | 79 } |
67 SDL_XDevices = newDevices; | 80 data->display = display; |
68 SDL_XDevices[index] = | 81 data->device = XOpenDevice(display, DevList[i].id); |
69 XOpenDevice(data->display, DevList[i].id); | 82 |
83 /* motion events */ | |
84 DeviceMotionNotify(data->device, event_code, xEvent); | |
85 if (xEvent) { | |
86 data->xevents[data->num_xevents++] = xEvent; | |
87 data->motion = event_code; | |
88 } | |
89 | |
90 /* button events */ | |
91 DeviceButtonPress(data->device, event_code, xEvent); | |
92 if (xEvent) { | |
93 data->xevents[data->num_xevents++] = xEvent; | |
94 data->button_pressed = event_code; | |
95 } | |
96 DeviceButtonRelease(data->device, event_code, xEvent); | |
97 if (xEvent) { | |
98 data->xevents[data->num_xevents++] = xEvent; | |
99 data->button_released = event_code; | |
100 } | |
101 | |
102 /* proximity events */ | |
103 ProximityIn(data->device, event_code, xEvent); | |
104 if (xEvent) { | |
105 data->xevents[data->num_xevents++] = xEvent; | |
106 data->proximity_in = event_code; | |
107 } | |
108 ProximityOut(data->device, event_code, xEvent); | |
109 if (xEvent) { | |
110 data->xevents[data->num_xevents++] = xEvent; | |
111 data->proximity_out = event_code; | |
112 } | |
113 | |
70 SDL_zero(mouse); | 114 SDL_zero(mouse); |
115 mouse.id = DevList[i].id; | |
116 mouse.FreeMouse = X11_FreeMouse; | |
117 mouse.driverdata = data; | |
71 | 118 |
72 /* the id of the device differs from its index | |
73 * so we're assigning the index of a device to it's id */ | |
74 SDL_SetMouseIndexId(DevList[i].id, index); | |
75 /* lets get the device parameters */ | 119 /* lets get the device parameters */ |
76 valInfo = (XValuatorInfo *) deviceClass; | 120 valInfo = (XValuatorInfo *) deviceClass; |
77 /* if the device reports pressure, lets check it parameteres */ | 121 /* if the device reports pressure, lets check it parameteres */ |
78 if (valInfo->num_axes > 2) { | 122 if (valInfo->num_axes > 2) { |
79 data->mouse = | 123 SDL_AddMouse(&mouse, DevList[i].name, |
80 SDL_AddMouse(&mouse, index++, DevList[i].name, | |
81 valInfo->axes[2].max_value, | 124 valInfo->axes[2].max_value, |
82 valInfo->axes[2].min_value, 1); | 125 valInfo->axes[2].min_value, 1); |
83 } else { | 126 } else { |
84 data->mouse = | 127 SDL_AddMouse(&mouse, DevList[i].name, 0, 0, 1); |
85 SDL_AddMouse(&mouse, index++, DevList[i].name, 0, | |
86 0, 1); | |
87 } | 128 } |
88 break; | 129 break; |
89 } | 130 } |
90 /* if it's not class we're interested in, lets go further */ | 131 /* if it's not class we're interested in, lets go further */ |
91 deviceClass = | 132 deviceClass = |
93 deviceClass->length); | 134 deviceClass->length); |
94 } | 135 } |
95 } | 136 } |
96 } | 137 } |
97 XFreeDeviceList(DevList); | 138 XFreeDeviceList(DevList); |
98 | |
99 SDL_NumOfXDevices = index; | |
100 #endif | 139 #endif |
101 } | 140 } |
102 | 141 |
103 void | 142 void |
104 X11_QuitMouse(_THIS) | 143 X11_QuitMouse(_THIS) |