First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xgl / xglinput.c
blobcda21ad49b1d3868e9b24ffccf4cc343ce98e051
1 /*
2 * Copyright © 2004 David Reveman
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * David Reveman not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior permission.
11 * David Reveman makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without express or
13 * implied warranty.
15 * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: David Reveman <davidr@novell.com>
26 #include "xgl.h"
27 #include "inputstr.h"
28 #include "mipointer.h"
30 #define XK_PUBLISHING
31 #include <X11/keysym.h>
32 #if HAVE_X11_XF86KEYSYM_H
33 #include <X11/XF86keysym.h>
34 #endif
36 #define NUM_BUTTONS 7
38 int
39 xglMouseProc (DeviceIntPtr pDevice,
40 int onoff)
42 BYTE map[NUM_BUTTONS + 1];
43 DevicePtr pDev = (DevicePtr) pDevice;
44 int i;
46 switch (onoff) {
47 case DEVICE_INIT:
48 for (i = 1; i <= NUM_BUTTONS; i++)
49 map[i] = i;
51 InitPointerDeviceStruct (pDev,
52 map,
53 NUM_BUTTONS,
54 miPointerGetMotionEvents,
55 (PtrCtrlProcPtr) NoopDDA,
56 miPointerGetMotionBufferSize ());
57 break;
58 case DEVICE_ON:
59 pDev->on = TRUE;
60 break;
61 case DEVICE_OFF:
62 case DEVICE_CLOSE:
63 pDev->on = FALSE;
64 break;
67 return Success;
70 void
71 xglBell (int volume,
72 DeviceIntPtr pDev,
73 pointer ctrl,
74 int something)
78 void
79 xglKbdCtrl (DeviceIntPtr pDevice,
80 KeybdCtrl *ctrl)
84 #define XGL_KEYMAP_WIDTH 2
86 KeySym xglKeymap[] = {
87 /* 1 8 */ XK_Escape, NoSymbol,
88 /* 2 9 */ XK_1, XK_exclam,
89 /* 3 10 */ XK_2, XK_at,
90 /* 4 11 */ XK_3, XK_numbersign,
91 /* 5 12 */ XK_4, XK_dollar,
92 /* 6 13 */ XK_5, XK_percent,
93 /* 7 14 */ XK_6, XK_asciicircum,
94 /* 8 15 */ XK_7, XK_ampersand,
95 /* 9 16 */ XK_8, XK_asterisk,
96 /* 10 17 */ XK_9, XK_parenleft,
97 /* 11 18 */ XK_0, XK_parenright,
98 /* 12 19 */ XK_minus, XK_underscore,
99 /* 13 20 */ XK_equal, XK_plus,
100 /* 14 21 */ XK_BackSpace, NoSymbol,
101 /* 15 22 */ XK_Tab, NoSymbol,
102 /* 16 23 */ XK_Q, NoSymbol,
103 /* 17 24 */ XK_W, NoSymbol,
104 /* 18 25 */ XK_E, NoSymbol,
105 /* 19 26 */ XK_R, NoSymbol,
106 /* 20 27 */ XK_T, NoSymbol,
107 /* 21 28 */ XK_Y, NoSymbol,
108 /* 22 29 */ XK_U, NoSymbol,
109 /* 23 30 */ XK_I, NoSymbol,
110 /* 24 31 */ XK_O, NoSymbol,
111 /* 25 32 */ XK_P, NoSymbol,
112 /* 26 33 */ XK_bracketleft, XK_braceleft,
113 /* 27 34 */ XK_bracketright, XK_braceright,
114 /* 28 35 */ XK_Return, NoSymbol,
115 /* 29 36 */ XK_Control_L, NoSymbol,
116 /* 30 37 */ XK_A, NoSymbol,
117 /* 31 38 */ XK_S, NoSymbol,
118 /* 32 39 */ XK_D, NoSymbol,
119 /* 33 40 */ XK_F, NoSymbol,
120 /* 34 41 */ XK_G, NoSymbol,
121 /* 35 42 */ XK_H, NoSymbol,
122 /* 36 43 */ XK_J, NoSymbol,
123 /* 37 44 */ XK_K, NoSymbol,
124 /* 38 45 */ XK_L, NoSymbol,
125 /* 39 46 */ XK_semicolon, XK_colon,
126 /* 40 47 */ XK_apostrophe, XK_quotedbl,
127 /* 41 48 */ XK_grave, XK_asciitilde,
128 /* 42 49 */ XK_Shift_L, NoSymbol,
129 /* 43 50 */ XK_backslash, XK_bar,
130 /* 44 51 */ XK_Z, NoSymbol,
131 /* 45 52 */ XK_X, NoSymbol,
132 /* 46 53 */ XK_C, NoSymbol,
133 /* 47 54 */ XK_V, NoSymbol,
134 /* 48 55 */ XK_B, NoSymbol,
135 /* 49 56 */ XK_N, NoSymbol,
136 /* 50 57 */ XK_M, NoSymbol,
137 /* 51 58 */ XK_comma, XK_less,
138 /* 52 59 */ XK_period, XK_greater,
139 /* 53 60 */ XK_slash, XK_question,
140 /* 54 61 */ XK_Shift_R, NoSymbol,
141 /* 55 62 */ XK_KP_Multiply, NoSymbol,
142 /* 56 63 */ XK_Alt_L, XK_Meta_L,
143 /* 57 64 */ XK_space, NoSymbol,
144 /* 58 65 */ XK_Caps_Lock, NoSymbol,
145 /* 59 66 */ XK_F1, NoSymbol,
146 /* 60 67 */ XK_F2, NoSymbol,
147 /* 61 68 */ XK_F3, NoSymbol,
148 /* 62 69 */ XK_F4, NoSymbol,
149 /* 63 70 */ XK_F5, NoSymbol,
150 /* 64 71 */ XK_F6, NoSymbol,
151 /* 65 72 */ XK_F7, NoSymbol,
152 /* 66 73 */ XK_F8, NoSymbol,
153 /* 67 74 */ XK_F9, NoSymbol,
154 /* 68 75 */ XK_F10, NoSymbol,
155 /* 69 76 */ XK_Break, XK_Pause,
156 /* 70 77 */ XK_Scroll_Lock, NoSymbol,
157 /* 71 78 */ XK_KP_Home, XK_KP_7,
158 /* 72 79 */ XK_KP_Up, XK_KP_8,
159 /* 73 80 */ XK_KP_Page_Up, XK_KP_9,
160 /* 74 81 */ XK_KP_Subtract, NoSymbol,
161 /* 75 82 */ XK_KP_Left, XK_KP_4,
162 /* 76 83 */ XK_KP_5, NoSymbol,
163 /* 77 84 */ XK_KP_Right, XK_KP_6,
164 /* 78 85 */ XK_KP_Add, NoSymbol,
165 /* 79 86 */ XK_KP_End, XK_KP_1,
166 /* 80 87 */ XK_KP_Down, XK_KP_2,
167 /* 81 88 */ XK_KP_Page_Down, XK_KP_3,
168 /* 82 89 */ XK_KP_Insert, XK_KP_0,
169 /* 83 90 */ XK_KP_Delete, XK_KP_Decimal,
170 /* 84 91 */ NoSymbol, NoSymbol,
171 /* 85 92 */ NoSymbol, NoSymbol,
172 /* 86 93 */ NoSymbol, NoSymbol,
173 /* 87 94 */ XK_F11, NoSymbol,
174 /* 88 95 */ XK_F12, NoSymbol,
175 /* 89 96 */ XK_Control_R, NoSymbol,
176 /* 90 97 */ XK_KP_Enter, NoSymbol,
177 /* 91 98 */ XK_KP_Divide, NoSymbol,
178 /* 92 99 */ XK_Sys_Req, XK_Print,
179 /* 93 100 */ XK_Alt_R, XK_Meta_R,
180 /* 94 101 */ XK_Num_Lock, NoSymbol,
181 /* 95 102 */ XK_Home, NoSymbol,
182 /* 96 103 */ XK_Up, NoSymbol,
183 /* 97 104 */ XK_Page_Up, NoSymbol,
184 /* 98 105 */ XK_Left, NoSymbol,
185 /* 99 106 */ XK_Right, NoSymbol,
186 /* 100 107 */ XK_End, NoSymbol,
187 /* 101 108 */ XK_Down, NoSymbol,
188 /* 102 109 */ XK_Page_Down, NoSymbol,
189 /* 103 110 */ XK_Insert, NoSymbol,
190 /* 104 111 */ XK_Delete, NoSymbol,
191 /* 105 112 */ XK_Super_L, NoSymbol,
192 /* 106 113 */ XK_Super_R, NoSymbol,
193 /* 107 114 */ XK_Menu, NoSymbol,
195 /* 108 115 */ XK_Next, NoSymbol, /* right button on side */
196 /* 109 116 */ XK_Prior, NoSymbol, /* left button on side */
197 /* 110 117 */ XK_Up, NoSymbol, /* joypad */
198 /* 111 118 */ XK_Down, NoSymbol,
199 /* 112 119 */ XK_Left, NoSymbol,
200 /* 113 120 */ XK_Right, NoSymbol,
201 /* 114 121 */ NoSymbol, NoSymbol, /* left near speaker */
202 /* 115 122 */ NoSymbol, NoSymbol, /* right near speaker */
203 /* 116 123 */ NoSymbol, NoSymbol, /* tiny button */
206 CARD8 xglModMap[MAP_LENGTH];
208 KeySymsRec xglKeySyms = {
209 xglKeymap,
211 8 + (sizeof (xglKeymap) / sizeof (xglKeymap[0]) / XGL_KEYMAP_WIDTH) - 1,
212 XGL_KEYMAP_WIDTH
216 xglKeybdProc (DeviceIntPtr pDevice,
217 int onoff)
219 Bool ret;
220 DevicePtr pDev = (DevicePtr) pDevice;
222 if (!pDev)
223 return BadImplementation;
225 switch (onoff) {
226 case DEVICE_INIT:
227 if (pDev != LookupKeyboardDevice ())
228 return !Success;
230 ret = InitKeyboardDeviceStruct (pDev,
231 &xglKeySyms,
232 xglModMap,
233 xglBell,
234 xglKbdCtrl);
235 if (!ret)
236 return BadImplementation;
237 break;
238 case DEVICE_ON:
239 pDev->on = TRUE;
240 break;
241 case DEVICE_OFF:
242 case DEVICE_CLOSE:
243 pDev->on = FALSE;
244 break;
247 return Success;
250 void
251 xglInitInput (int argc, char **argv)
253 DeviceIntPtr pKeyboard, pPointer;
255 pPointer = AddInputDevice (xglMouseProc, TRUE);
256 pKeyboard = AddInputDevice (xglKeybdProc, TRUE);
258 RegisterPointerDevice (pPointer);
259 RegisterKeyboardDevice (pKeyboard);
261 miRegisterPointerDevice (screenInfo.screens[0], pPointer);
262 mieqInit (&pKeyboard->public, &pPointer->public);