xref: /OK3568_Linux_fs/external/xserver/hw/dmx/input/dmxcommon.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright 2001-2003 Red Hat Inc., Durham, North Carolina.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * All Rights Reserved.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining
7*4882a593Smuzhiyun  * a copy of this software and associated documentation files (the
8*4882a593Smuzhiyun  * "Software"), to deal in the Software without restriction, including
9*4882a593Smuzhiyun  * without limitation on the rights to use, copy, modify, merge,
10*4882a593Smuzhiyun  * publish, distribute, sublicense, and/or sell copies of the Software,
11*4882a593Smuzhiyun  * and to permit persons to whom the Software is furnished to do so,
12*4882a593Smuzhiyun  * subject to the following conditions:
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * The above copyright notice and this permission notice (including the
15*4882a593Smuzhiyun  * next paragraph) shall be included in all copies or substantial
16*4882a593Smuzhiyun  * portions of the Software.
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19*4882a593Smuzhiyun  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20*4882a593Smuzhiyun  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21*4882a593Smuzhiyun  * NON-INFRINGEMENT.  IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
22*4882a593Smuzhiyun  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23*4882a593Smuzhiyun  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24*4882a593Smuzhiyun  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25*4882a593Smuzhiyun  * SOFTWARE.
26*4882a593Smuzhiyun  */
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun /*
29*4882a593Smuzhiyun  * Authors:
30*4882a593Smuzhiyun  *   David H. Dawes <dawes@xfree86.org>
31*4882a593Smuzhiyun  *   Kevin E. Martin <kem@redhat.com>
32*4882a593Smuzhiyun  *   Rickard E. (Rik) Faith <faith@redhat.com>
33*4882a593Smuzhiyun  */
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun /** \file
36*4882a593Smuzhiyun  *
37*4882a593Smuzhiyun  * This file implements common routines used by the backend and console
38*4882a593Smuzhiyun  * input devices.
39*4882a593Smuzhiyun  */
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun #ifdef HAVE_DMX_CONFIG_H
42*4882a593Smuzhiyun #include <dmx-config.h>
43*4882a593Smuzhiyun #endif
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun #define DMX_STATE_DEBUG 0
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun #include "dmxinputinit.h"
48*4882a593Smuzhiyun #include "dmxcommon.h"
49*4882a593Smuzhiyun #include "dmxconsole.h"
50*4882a593Smuzhiyun #include "dmxprop.h"
51*4882a593Smuzhiyun #include "dmxsync.h"
52*4882a593Smuzhiyun #include "dmxmap.h"
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun #include "inputstr.h"
55*4882a593Smuzhiyun #include "input.h"
56*4882a593Smuzhiyun #include <X11/keysym.h>
57*4882a593Smuzhiyun #include "mipointer.h"
58*4882a593Smuzhiyun #include "scrnintstr.h"
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun #include <unistd.h>             /* For usleep() */
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun #if DMX_STATE_DEBUG
63*4882a593Smuzhiyun #define DMXDBG0(f)               dmxLog(dmxDebug,f)
64*4882a593Smuzhiyun #else
65*4882a593Smuzhiyun #define DMXDBG0(f)
66*4882a593Smuzhiyun #endif
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun /** Each device has a private area that is visible only from inside the
69*4882a593Smuzhiyun  * driver code. */
70*4882a593Smuzhiyun typedef struct _myPrivate {
71*4882a593Smuzhiyun     DMX_COMMON_PRIVATE;
72*4882a593Smuzhiyun } myPrivate;
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun static void
dmxCommonKbdSetAR(Display * display,unsigned char * old,unsigned char * new)75*4882a593Smuzhiyun dmxCommonKbdSetAR(Display * display, unsigned char *old, unsigned char *new)
76*4882a593Smuzhiyun {
77*4882a593Smuzhiyun     XKeyboardControl kc;
78*4882a593Smuzhiyun     XKeyboardState ks;
79*4882a593Smuzhiyun     unsigned long mask = KBKey | KBAutoRepeatMode;
80*4882a593Smuzhiyun     int i, j;
81*4882a593Smuzhiyun     int minKeycode, maxKeycode;
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun     if (!old) {
84*4882a593Smuzhiyun         XGetKeyboardControl(display, &ks);
85*4882a593Smuzhiyun         old = (unsigned char *) ks.auto_repeats;
86*4882a593Smuzhiyun     }
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun     XDisplayKeycodes(display, &minKeycode, &maxKeycode);
89*4882a593Smuzhiyun     for (i = 1; i < 32; i++) {
90*4882a593Smuzhiyun         if (!old || old[i] != new[i]) {
91*4882a593Smuzhiyun             for (j = 0; j < 8; j++) {
92*4882a593Smuzhiyun                 if ((new[i] & (1 << j)) != (old[i] & (1 << j))) {
93*4882a593Smuzhiyun                     kc.key = i * 8 + j;
94*4882a593Smuzhiyun                     kc.auto_repeat_mode = ((new[i] & (1 << j))
95*4882a593Smuzhiyun                                            ? AutoRepeatModeOn
96*4882a593Smuzhiyun                                            : AutoRepeatModeOff);
97*4882a593Smuzhiyun                     if (kc.key >= minKeycode && kc.key <= maxKeycode)
98*4882a593Smuzhiyun                         XChangeKeyboardControl(display, mask, &kc);
99*4882a593Smuzhiyun                 }
100*4882a593Smuzhiyun             }
101*4882a593Smuzhiyun         }
102*4882a593Smuzhiyun     }
103*4882a593Smuzhiyun }
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun static void
dmxCommonKbdSetLeds(Display * display,unsigned long new)106*4882a593Smuzhiyun dmxCommonKbdSetLeds(Display * display, unsigned long new)
107*4882a593Smuzhiyun {
108*4882a593Smuzhiyun     int i;
109*4882a593Smuzhiyun     XKeyboardControl kc;
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun     for (i = 0; i < 32; i++) {
112*4882a593Smuzhiyun         kc.led = i + 1;
113*4882a593Smuzhiyun         kc.led_mode = (new & (1 << i)) ? LedModeOn : LedModeOff;
114*4882a593Smuzhiyun         XChangeKeyboardControl(display, KBLed | KBLedMode, &kc);
115*4882a593Smuzhiyun     }
116*4882a593Smuzhiyun }
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun static void
dmxCommonKbdSetCtrl(Display * display,KeybdCtrl * old,KeybdCtrl * new)119*4882a593Smuzhiyun dmxCommonKbdSetCtrl(Display * display, KeybdCtrl * old, KeybdCtrl * new)
120*4882a593Smuzhiyun {
121*4882a593Smuzhiyun     XKeyboardControl kc;
122*4882a593Smuzhiyun     unsigned long mask = KBKeyClickPercent | KBAutoRepeatMode;
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun     if (!old || old->click != new->click || old->autoRepeat != new->autoRepeat) {
125*4882a593Smuzhiyun 
126*4882a593Smuzhiyun         kc.key_click_percent = new->click;
127*4882a593Smuzhiyun         kc.auto_repeat_mode = new->autoRepeat;
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun         XChangeKeyboardControl(display, mask, &kc);
130*4882a593Smuzhiyun     }
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun     dmxCommonKbdSetLeds(display, new->leds);
133*4882a593Smuzhiyun     dmxCommonKbdSetAR(display, old ? old->autoRepeats : NULL, new->autoRepeats);
134*4882a593Smuzhiyun }
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun static void
dmxCommonMouSetCtrl(Display * display,PtrCtrl * old,PtrCtrl * new)137*4882a593Smuzhiyun dmxCommonMouSetCtrl(Display * display, PtrCtrl * old, PtrCtrl * new)
138*4882a593Smuzhiyun {
139*4882a593Smuzhiyun     Bool do_accel, do_threshold;
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun     if (!old
142*4882a593Smuzhiyun         || old->num != new->num
143*4882a593Smuzhiyun         || old->den != new->den || old->threshold != new->threshold) {
144*4882a593Smuzhiyun         do_accel = (new->num > 0 && new->den > 0);
145*4882a593Smuzhiyun         do_threshold = (new->threshold > 0);
146*4882a593Smuzhiyun         if (do_accel || do_threshold) {
147*4882a593Smuzhiyun             XChangePointerControl(display, do_accel, do_threshold,
148*4882a593Smuzhiyun                                   new->num, new->den, new->threshold);
149*4882a593Smuzhiyun         }
150*4882a593Smuzhiyun     }
151*4882a593Smuzhiyun }
152*4882a593Smuzhiyun 
153*4882a593Smuzhiyun /** Update the keyboard control. */
154*4882a593Smuzhiyun void
dmxCommonKbdCtrl(DevicePtr pDev,KeybdCtrl * ctrl)155*4882a593Smuzhiyun dmxCommonKbdCtrl(DevicePtr pDev, KeybdCtrl * ctrl)
156*4882a593Smuzhiyun {
157*4882a593Smuzhiyun     GETPRIVFROMPDEV;
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun     if (!priv->stateSaved && priv->be)
160*4882a593Smuzhiyun         dmxCommonSaveState(priv);
161*4882a593Smuzhiyun     if (!priv->display || !priv->stateSaved)
162*4882a593Smuzhiyun         return;
163*4882a593Smuzhiyun     dmxCommonKbdSetCtrl(priv->display,
164*4882a593Smuzhiyun                         priv->kctrlset ? &priv->kctrl : NULL, ctrl);
165*4882a593Smuzhiyun     priv->kctrl = *ctrl;
166*4882a593Smuzhiyun     priv->kctrlset = 1;
167*4882a593Smuzhiyun }
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun /** Update the mouse control. */
170*4882a593Smuzhiyun void
dmxCommonMouCtrl(DevicePtr pDev,PtrCtrl * ctrl)171*4882a593Smuzhiyun dmxCommonMouCtrl(DevicePtr pDev, PtrCtrl * ctrl)
172*4882a593Smuzhiyun {
173*4882a593Smuzhiyun     GETPRIVFROMPDEV;
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun     /* Don't set the acceleration for the
176*4882a593Smuzhiyun      * console, because that should be
177*4882a593Smuzhiyun      * controlled by the X server that the
178*4882a593Smuzhiyun      * console is running on.  Otherwise,
179*4882a593Smuzhiyun      * the acceleration for the console
180*4882a593Smuzhiyun      * window would be unexpected for the
181*4882a593Smuzhiyun      * scale of the window. */
182*4882a593Smuzhiyun     if (priv->be) {
183*4882a593Smuzhiyun         dmxCommonMouSetCtrl(priv->display,
184*4882a593Smuzhiyun                             priv->mctrlset ? &priv->mctrl : NULL, ctrl);
185*4882a593Smuzhiyun         priv->mctrl = *ctrl;
186*4882a593Smuzhiyun         priv->mctrlset = 1;
187*4882a593Smuzhiyun     }
188*4882a593Smuzhiyun }
189*4882a593Smuzhiyun 
190*4882a593Smuzhiyun /** Sound they keyboard bell. */
191*4882a593Smuzhiyun void
dmxCommonKbdBell(DevicePtr pDev,int percent,int volume,int pitch,int duration)192*4882a593Smuzhiyun dmxCommonKbdBell(DevicePtr pDev, int percent,
193*4882a593Smuzhiyun                  int volume, int pitch, int duration)
194*4882a593Smuzhiyun {
195*4882a593Smuzhiyun     GETPRIVFROMPDEV;
196*4882a593Smuzhiyun     XKeyboardControl kc;
197*4882a593Smuzhiyun     XKeyboardState ks;
198*4882a593Smuzhiyun     unsigned long mask = KBBellPercent | KBBellPitch | KBBellDuration;
199*4882a593Smuzhiyun 
200*4882a593Smuzhiyun     if (!priv->be)
201*4882a593Smuzhiyun         XGetKeyboardControl(priv->display, &ks);
202*4882a593Smuzhiyun     kc.bell_percent = volume;
203*4882a593Smuzhiyun     kc.bell_pitch = pitch;
204*4882a593Smuzhiyun     kc.bell_duration = duration;
205*4882a593Smuzhiyun     XChangeKeyboardControl(priv->display, mask, &kc);
206*4882a593Smuzhiyun     XBell(priv->display, percent);
207*4882a593Smuzhiyun     if (!priv->be) {
208*4882a593Smuzhiyun         kc.bell_percent = ks.bell_percent;
209*4882a593Smuzhiyun         kc.bell_pitch = ks.bell_pitch;
210*4882a593Smuzhiyun         kc.bell_duration = ks.bell_duration;
211*4882a593Smuzhiyun         XChangeKeyboardControl(priv->display, mask, &kc);
212*4882a593Smuzhiyun     }
213*4882a593Smuzhiyun }
214*4882a593Smuzhiyun 
215*4882a593Smuzhiyun /** Get the keyboard mapping. */
216*4882a593Smuzhiyun void
dmxCommonKbdGetMap(DevicePtr pDev,KeySymsPtr pKeySyms,CARD8 * pModMap)217*4882a593Smuzhiyun dmxCommonKbdGetMap(DevicePtr pDev, KeySymsPtr pKeySyms, CARD8 *pModMap)
218*4882a593Smuzhiyun {
219*4882a593Smuzhiyun     GETPRIVFROMPDEV;
220*4882a593Smuzhiyun     int min_keycode;
221*4882a593Smuzhiyun     int max_keycode;
222*4882a593Smuzhiyun     int map_width;
223*4882a593Smuzhiyun     KeySym *keyboard_mapping;
224*4882a593Smuzhiyun     XModifierKeymap *modifier_mapping;
225*4882a593Smuzhiyun     int i, j;
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun     /* Compute pKeySyms.  Cast
228*4882a593Smuzhiyun      * XGetKeyboardMapping because of
229*4882a593Smuzhiyun      * compiler warning on 64-bit machines.
230*4882a593Smuzhiyun      * We assume pointers to 32-bit and
231*4882a593Smuzhiyun      * 64-bit ints are the same. */
232*4882a593Smuzhiyun     XDisplayKeycodes(priv->display, &min_keycode, &max_keycode);
233*4882a593Smuzhiyun     keyboard_mapping = (KeySym *) XGetKeyboardMapping(priv->display,
234*4882a593Smuzhiyun                                                       min_keycode,
235*4882a593Smuzhiyun                                                       max_keycode
236*4882a593Smuzhiyun                                                       - min_keycode + 1,
237*4882a593Smuzhiyun                                                       &map_width);
238*4882a593Smuzhiyun     pKeySyms->minKeyCode = min_keycode;
239*4882a593Smuzhiyun     pKeySyms->maxKeyCode = max_keycode;
240*4882a593Smuzhiyun     pKeySyms->mapWidth = map_width;
241*4882a593Smuzhiyun     pKeySyms->map = keyboard_mapping;
242*4882a593Smuzhiyun 
243*4882a593Smuzhiyun     /* Compute pModMap  */
244*4882a593Smuzhiyun     modifier_mapping = XGetModifierMapping(priv->display);
245*4882a593Smuzhiyun     for (i = 0; i < MAP_LENGTH; i++)
246*4882a593Smuzhiyun         pModMap[i] = 0;
247*4882a593Smuzhiyun     for (j = 0; j < 8; j++) {
248*4882a593Smuzhiyun         int max_keypermod = modifier_mapping->max_keypermod;
249*4882a593Smuzhiyun 
250*4882a593Smuzhiyun         for (i = 0; i < max_keypermod; i++) {
251*4882a593Smuzhiyun             CARD8 keycode =
252*4882a593Smuzhiyun                 modifier_mapping->modifiermap[j * max_keypermod + i];
253*4882a593Smuzhiyun             if (keycode)
254*4882a593Smuzhiyun                 pModMap[keycode] |= 1 << j;
255*4882a593Smuzhiyun         }
256*4882a593Smuzhiyun     }
257*4882a593Smuzhiyun     XFreeModifiermap(modifier_mapping);
258*4882a593Smuzhiyun }
259*4882a593Smuzhiyun 
260*4882a593Smuzhiyun /** Fill in the XKEYBOARD parts of the \a info structure for the
261*4882a593Smuzhiyun  * specified \a pDev. */
262*4882a593Smuzhiyun void
dmxCommonKbdGetInfo(DevicePtr pDev,DMXLocalInitInfoPtr info)263*4882a593Smuzhiyun dmxCommonKbdGetInfo(DevicePtr pDev, DMXLocalInitInfoPtr info)
264*4882a593Smuzhiyun {
265*4882a593Smuzhiyun     GETPRIVFROMPDEV;
266*4882a593Smuzhiyun     GETDMXINPUTFROMPRIV;
267*4882a593Smuzhiyun     char *pt;
268*4882a593Smuzhiyun 
269*4882a593Smuzhiyun     dmxCommonSaveState(priv);
270*4882a593Smuzhiyun     if (priv->xkb) {
271*4882a593Smuzhiyun #define NAME(x) \
272*4882a593Smuzhiyun  priv->xkb->names->x ? XGetAtomName(priv->display,priv->xkb->names->x) : NULL
273*4882a593Smuzhiyun         info->names.keycodes = NAME(keycodes);
274*4882a593Smuzhiyun         info->names.types = NAME(types);
275*4882a593Smuzhiyun         info->names.compat = NAME(compat);
276*4882a593Smuzhiyun         info->names.symbols = NAME(symbols);
277*4882a593Smuzhiyun         info->names.geometry = NAME(geometry);
278*4882a593Smuzhiyun         info->freenames = 1;
279*4882a593Smuzhiyun #undef NAME
280*4882a593Smuzhiyun         dmxLogInput(dmxInput,
281*4882a593Smuzhiyun                     "XKEYBOARD: keycodes = %s\n", info->names.keycodes);
282*4882a593Smuzhiyun         dmxLogInput(dmxInput,
283*4882a593Smuzhiyun                     "XKEYBOARD: symbols  = %s\n", info->names.symbols);
284*4882a593Smuzhiyun         dmxLogInput(dmxInput,
285*4882a593Smuzhiyun                     "XKEYBOARD: geometry = %s\n", info->names.geometry);
286*4882a593Smuzhiyun         if ((pt = strchr(info->names.keycodes, '+')))
287*4882a593Smuzhiyun             *pt = '\0';
288*4882a593Smuzhiyun     }
289*4882a593Smuzhiyun     dmxCommonRestoreState(priv);
290*4882a593Smuzhiyun }
291*4882a593Smuzhiyun 
292*4882a593Smuzhiyun /** Turn \a pDev on (i.e., take input from \a pDev). */
293*4882a593Smuzhiyun int
dmxCommonKbdOn(DevicePtr pDev)294*4882a593Smuzhiyun dmxCommonKbdOn(DevicePtr pDev)
295*4882a593Smuzhiyun {
296*4882a593Smuzhiyun     GETPRIVFROMPDEV;
297*4882a593Smuzhiyun     if (priv->be)
298*4882a593Smuzhiyun         dmxCommonSaveState(priv);
299*4882a593Smuzhiyun     priv->eventMask |= DMX_KEYBOARD_EVENT_MASK;
300*4882a593Smuzhiyun     XSelectInput(priv->display, priv->window, priv->eventMask);
301*4882a593Smuzhiyun     if (priv->be)
302*4882a593Smuzhiyun         XSetInputFocus(priv->display, priv->window, RevertToPointerRoot,
303*4882a593Smuzhiyun                        CurrentTime);
304*4882a593Smuzhiyun     return -1;
305*4882a593Smuzhiyun }
306*4882a593Smuzhiyun 
307*4882a593Smuzhiyun /** Turn \a pDev off. */
308*4882a593Smuzhiyun void
dmxCommonKbdOff(DevicePtr pDev)309*4882a593Smuzhiyun dmxCommonKbdOff(DevicePtr pDev)
310*4882a593Smuzhiyun {
311*4882a593Smuzhiyun     GETPRIVFROMPDEV;
312*4882a593Smuzhiyun     priv->eventMask &= ~DMX_KEYBOARD_EVENT_MASK;
313*4882a593Smuzhiyun     XSelectInput(priv->display, priv->window, priv->eventMask);
314*4882a593Smuzhiyun     dmxCommonRestoreState(priv);
315*4882a593Smuzhiyun }
316*4882a593Smuzhiyun 
317*4882a593Smuzhiyun /** Turn \a pDev on (i.e., take input from \a pDev). */
318*4882a593Smuzhiyun int
dmxCommonOthOn(DevicePtr pDev)319*4882a593Smuzhiyun dmxCommonOthOn(DevicePtr pDev)
320*4882a593Smuzhiyun {
321*4882a593Smuzhiyun     GETPRIVFROMPDEV;
322*4882a593Smuzhiyun     GETDMXINPUTFROMPRIV;
323*4882a593Smuzhiyun     XEventClass event_list[DMX_MAX_XINPUT_EVENT_TYPES];
324*4882a593Smuzhiyun     int event_type[DMX_MAX_XINPUT_EVENT_TYPES];
325*4882a593Smuzhiyun     int count = 0;
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun #define ADD(type)                                                            \
328*4882a593Smuzhiyun     if (count < DMX_MAX_XINPUT_EVENT_TYPES) {                                \
329*4882a593Smuzhiyun         type(priv->xi, event_type[count], event_list[count]);                \
330*4882a593Smuzhiyun         if (event_type[count]) {                                             \
331*4882a593Smuzhiyun             dmxMapInsert(dmxLocal, event_type[count], XI_##type);            \
332*4882a593Smuzhiyun             ++count;                                                         \
333*4882a593Smuzhiyun         }                                                                    \
334*4882a593Smuzhiyun     } else {                                                                 \
335*4882a593Smuzhiyun         dmxLog(dmxWarning, "More than %d event types for %s\n",              \
336*4882a593Smuzhiyun                DMX_MAX_XINPUT_EVENT_TYPES, dmxInput->name);                  \
337*4882a593Smuzhiyun     }
338*4882a593Smuzhiyun 
339*4882a593Smuzhiyun     if (!(priv->xi = XOpenDevice(priv->display, dmxLocal->deviceId))) {
340*4882a593Smuzhiyun         dmxLog(dmxWarning, "Cannot open %s device (id=%d) on %s\n",
341*4882a593Smuzhiyun                dmxLocal->deviceName ? dmxLocal->deviceName : "(unknown)",
342*4882a593Smuzhiyun                (int) dmxLocal->deviceId, dmxInput->name);
343*4882a593Smuzhiyun         return -1;
344*4882a593Smuzhiyun     }
345*4882a593Smuzhiyun     ADD(DeviceKeyPress);
346*4882a593Smuzhiyun     ADD(DeviceKeyRelease);
347*4882a593Smuzhiyun     ADD(DeviceButtonPress);
348*4882a593Smuzhiyun     ADD(DeviceButtonRelease);
349*4882a593Smuzhiyun     ADD(DeviceMotionNotify);
350*4882a593Smuzhiyun     ADD(DeviceFocusIn);
351*4882a593Smuzhiyun     ADD(DeviceFocusOut);
352*4882a593Smuzhiyun     ADD(ProximityIn);
353*4882a593Smuzhiyun     ADD(ProximityOut);
354*4882a593Smuzhiyun     ADD(DeviceStateNotify);
355*4882a593Smuzhiyun     ADD(DeviceMappingNotify);
356*4882a593Smuzhiyun     ADD(ChangeDeviceNotify);
357*4882a593Smuzhiyun     XSelectExtensionEvent(priv->display, priv->window, event_list, count);
358*4882a593Smuzhiyun 
359*4882a593Smuzhiyun     return -1;
360*4882a593Smuzhiyun }
361*4882a593Smuzhiyun 
362*4882a593Smuzhiyun /** Turn \a pDev off. */
363*4882a593Smuzhiyun void
dmxCommonOthOff(DevicePtr pDev)364*4882a593Smuzhiyun dmxCommonOthOff(DevicePtr pDev)
365*4882a593Smuzhiyun {
366*4882a593Smuzhiyun     GETPRIVFROMPDEV;
367*4882a593Smuzhiyun 
368*4882a593Smuzhiyun     if (priv->xi)
369*4882a593Smuzhiyun         XCloseDevice(priv->display, priv->xi);
370*4882a593Smuzhiyun     priv->xi = NULL;
371*4882a593Smuzhiyun }
372*4882a593Smuzhiyun 
373*4882a593Smuzhiyun /** Fill the \a info structure with information needed to initialize \a
374*4882a593Smuzhiyun  * pDev. */
375*4882a593Smuzhiyun void
dmxCommonOthGetInfo(DevicePtr pDev,DMXLocalInitInfoPtr info)376*4882a593Smuzhiyun dmxCommonOthGetInfo(DevicePtr pDev, DMXLocalInitInfoPtr info)
377*4882a593Smuzhiyun {
378*4882a593Smuzhiyun     GETPRIVFROMPDEV;
379*4882a593Smuzhiyun     GETDMXINPUTFROMPRIV;
380*4882a593Smuzhiyun     XExtensionVersion *ext;
381*4882a593Smuzhiyun     XDeviceInfo *devices;
382*4882a593Smuzhiyun     Display *display = priv->display;
383*4882a593Smuzhiyun     int num;
384*4882a593Smuzhiyun     int i, j, k;
385*4882a593Smuzhiyun     XextErrorHandler handler;
386*4882a593Smuzhiyun 
387*4882a593Smuzhiyun     if (!display && !(display = XOpenDisplay(dmxInput->name)))
388*4882a593Smuzhiyun         return;
389*4882a593Smuzhiyun 
390*4882a593Smuzhiyun     /* Print out information about the XInput Extension. */
391*4882a593Smuzhiyun     handler = XSetExtensionErrorHandler(dmxInputExtensionErrorHandler);
392*4882a593Smuzhiyun     ext = XGetExtensionVersion(display, INAME);
393*4882a593Smuzhiyun     XSetExtensionErrorHandler(handler);
394*4882a593Smuzhiyun 
395*4882a593Smuzhiyun     if (ext && ext != (XExtensionVersion *) NoSuchExtension) {
396*4882a593Smuzhiyun         XFree(ext);
397*4882a593Smuzhiyun         devices = XListInputDevices(display, &num);
398*4882a593Smuzhiyun         for (i = 0; i < num; i++) {
399*4882a593Smuzhiyun             if (devices[i].id == (XID) dmxLocal->deviceId) {
400*4882a593Smuzhiyun                 XAnyClassPtr any;
401*4882a593Smuzhiyun                 XKeyInfoPtr ki;
402*4882a593Smuzhiyun                 XButtonInfoPtr bi;
403*4882a593Smuzhiyun                 XValuatorInfoPtr vi;
404*4882a593Smuzhiyun 
405*4882a593Smuzhiyun                 for (j = 0, any = devices[i].inputclassinfo;
406*4882a593Smuzhiyun                      j < devices[i].num_classes;
407*4882a593Smuzhiyun                      any = (XAnyClassPtr) ((char *) any + any->length), j++) {
408*4882a593Smuzhiyun                     switch (any->class) {
409*4882a593Smuzhiyun                     case KeyClass:
410*4882a593Smuzhiyun                         ki = (XKeyInfoPtr) any;
411*4882a593Smuzhiyun                         info->keyboard = 1;
412*4882a593Smuzhiyun                         info->keyClass = 1;
413*4882a593Smuzhiyun                         info->keySyms.minKeyCode = ki->min_keycode;
414*4882a593Smuzhiyun                         info->keySyms.maxKeyCode = ki->max_keycode;
415*4882a593Smuzhiyun                         info->kbdFeedbackClass = 1;
416*4882a593Smuzhiyun                         break;
417*4882a593Smuzhiyun                     case ButtonClass:
418*4882a593Smuzhiyun                         bi = (XButtonInfoPtr) any;
419*4882a593Smuzhiyun                         info->buttonClass = 1;
420*4882a593Smuzhiyun                         info->numButtons = bi->num_buttons;
421*4882a593Smuzhiyun                         info->ptrFeedbackClass = 1;
422*4882a593Smuzhiyun                         break;
423*4882a593Smuzhiyun                     case ValuatorClass:
424*4882a593Smuzhiyun                         /* This assume all axes are either
425*4882a593Smuzhiyun                          * Absolute or Relative. */
426*4882a593Smuzhiyun                         vi = (XValuatorInfoPtr) any;
427*4882a593Smuzhiyun                         info->valuatorClass = 1;
428*4882a593Smuzhiyun                         if (vi->mode == Absolute)
429*4882a593Smuzhiyun                             info->numAbsAxes = vi->num_axes;
430*4882a593Smuzhiyun                         else
431*4882a593Smuzhiyun                             info->numRelAxes = vi->num_axes;
432*4882a593Smuzhiyun                         for (k = 0; k < vi->num_axes; k++) {
433*4882a593Smuzhiyun                             info->res[k] = vi->axes[k].resolution;
434*4882a593Smuzhiyun                             info->minres[k] = vi->axes[k].resolution;
435*4882a593Smuzhiyun                             info->maxres[k] = vi->axes[k].resolution;
436*4882a593Smuzhiyun                             info->minval[k] = vi->axes[k].min_value;
437*4882a593Smuzhiyun                             info->maxval[k] = vi->axes[k].max_value;
438*4882a593Smuzhiyun                         }
439*4882a593Smuzhiyun                         break;
440*4882a593Smuzhiyun                     case FeedbackClass:
441*4882a593Smuzhiyun                         /* Only keyboard and pointer feedback
442*4882a593Smuzhiyun                          * are handled at this time. */
443*4882a593Smuzhiyun                         break;
444*4882a593Smuzhiyun                     case ProximityClass:
445*4882a593Smuzhiyun                         info->proximityClass = 1;
446*4882a593Smuzhiyun                         break;
447*4882a593Smuzhiyun                     case FocusClass:
448*4882a593Smuzhiyun                         info->focusClass = 1;
449*4882a593Smuzhiyun                         break;
450*4882a593Smuzhiyun                     case OtherClass:
451*4882a593Smuzhiyun                         break;
452*4882a593Smuzhiyun                     }
453*4882a593Smuzhiyun                 }
454*4882a593Smuzhiyun             }
455*4882a593Smuzhiyun         }
456*4882a593Smuzhiyun         XFreeDeviceList(devices);
457*4882a593Smuzhiyun     }
458*4882a593Smuzhiyun     if (display != priv->display)
459*4882a593Smuzhiyun         XCloseDisplay(display);
460*4882a593Smuzhiyun }
461*4882a593Smuzhiyun 
462*4882a593Smuzhiyun /** Obtain the mouse button mapping. */
463*4882a593Smuzhiyun void
dmxCommonMouGetMap(DevicePtr pDev,unsigned char * map,int * nButtons)464*4882a593Smuzhiyun dmxCommonMouGetMap(DevicePtr pDev, unsigned char *map, int *nButtons)
465*4882a593Smuzhiyun {
466*4882a593Smuzhiyun     GETPRIVFROMPDEV;
467*4882a593Smuzhiyun     int i;
468*4882a593Smuzhiyun 
469*4882a593Smuzhiyun     *nButtons = XGetPointerMapping(priv->display, map, DMX_MAX_BUTTONS);
470*4882a593Smuzhiyun     for (i = 0; i <= *nButtons; i++)
471*4882a593Smuzhiyun         map[i] = i;
472*4882a593Smuzhiyun }
473*4882a593Smuzhiyun 
474*4882a593Smuzhiyun static void *
dmxCommonXSelect(DMXScreenInfo * dmxScreen,void * closure)475*4882a593Smuzhiyun dmxCommonXSelect(DMXScreenInfo * dmxScreen, void *closure)
476*4882a593Smuzhiyun {
477*4882a593Smuzhiyun     myPrivate *priv = closure;
478*4882a593Smuzhiyun 
479*4882a593Smuzhiyun     XSelectInput(dmxScreen->beDisplay, dmxScreen->scrnWin, priv->eventMask);
480*4882a593Smuzhiyun     return NULL;
481*4882a593Smuzhiyun }
482*4882a593Smuzhiyun 
483*4882a593Smuzhiyun static void
dmxCommonFdNotify(int fd,int ready,void * data)484*4882a593Smuzhiyun dmxCommonFdNotify(int fd, int ready, void *data)
485*4882a593Smuzhiyun {
486*4882a593Smuzhiyun     /* This should process input on this fd, but instead all
487*4882a593Smuzhiyun      * of that is delayed until the block and wakeup handlers are called
488*4882a593Smuzhiyun      */
489*4882a593Smuzhiyun     ;
490*4882a593Smuzhiyun }
491*4882a593Smuzhiyun 
492*4882a593Smuzhiyun static void *
dmxCommonAddEnabledDevice(DMXScreenInfo * dmxScreen,void * closure)493*4882a593Smuzhiyun dmxCommonAddEnabledDevice(DMXScreenInfo * dmxScreen, void *closure)
494*4882a593Smuzhiyun {
495*4882a593Smuzhiyun     SetNotifyFd(XConnectionNumber(dmxScreen->beDisplay), dmxCommonFdNotify, X_NOTIFY_READ, closure);
496*4882a593Smuzhiyun     return NULL;
497*4882a593Smuzhiyun }
498*4882a593Smuzhiyun 
499*4882a593Smuzhiyun static void *
dmxCommonRemoveEnabledDevice(DMXScreenInfo * dmxScreen,void * closure)500*4882a593Smuzhiyun dmxCommonRemoveEnabledDevice(DMXScreenInfo * dmxScreen, void *closure)
501*4882a593Smuzhiyun {
502*4882a593Smuzhiyun     RemoveNotifyFd(XConnectionNumber(dmxScreen->beDisplay));
503*4882a593Smuzhiyun     return NULL;
504*4882a593Smuzhiyun }
505*4882a593Smuzhiyun 
506*4882a593Smuzhiyun /** Turn \a pDev on (i.e., take input from \a pDev). */
507*4882a593Smuzhiyun int
dmxCommonMouOn(DevicePtr pDev)508*4882a593Smuzhiyun dmxCommonMouOn(DevicePtr pDev)
509*4882a593Smuzhiyun {
510*4882a593Smuzhiyun     GETPRIVFROMPDEV;
511*4882a593Smuzhiyun     GETDMXINPUTFROMPRIV;
512*4882a593Smuzhiyun 
513*4882a593Smuzhiyun     priv->eventMask |= DMX_POINTER_EVENT_MASK;
514*4882a593Smuzhiyun     if (!priv->be) {
515*4882a593Smuzhiyun         XSelectInput(priv->display, priv->window, priv->eventMask);
516*4882a593Smuzhiyun         SetNotifyFd(XConnectionNumber(priv->display), dmxCommonFdNotify,X_NOTIFY_READ, pDev);
517*4882a593Smuzhiyun     }
518*4882a593Smuzhiyun     else {
519*4882a593Smuzhiyun         dmxPropertyIterate(priv->be, dmxCommonXSelect, priv);
520*4882a593Smuzhiyun         dmxPropertyIterate(priv->be, dmxCommonAddEnabledDevice, dmxInput);
521*4882a593Smuzhiyun     }
522*4882a593Smuzhiyun 
523*4882a593Smuzhiyun     return -1;
524*4882a593Smuzhiyun }
525*4882a593Smuzhiyun 
526*4882a593Smuzhiyun /** Turn \a pDev off. */
527*4882a593Smuzhiyun void
dmxCommonMouOff(DevicePtr pDev)528*4882a593Smuzhiyun dmxCommonMouOff(DevicePtr pDev)
529*4882a593Smuzhiyun {
530*4882a593Smuzhiyun     GETPRIVFROMPDEV;
531*4882a593Smuzhiyun     GETDMXINPUTFROMPRIV;
532*4882a593Smuzhiyun 
533*4882a593Smuzhiyun     priv->eventMask &= ~DMX_POINTER_EVENT_MASK;
534*4882a593Smuzhiyun     if (!priv->be) {
535*4882a593Smuzhiyun         RemoveNotifyFd(XConnectionNumber(priv->display));
536*4882a593Smuzhiyun         XSelectInput(priv->display, priv->window, priv->eventMask);
537*4882a593Smuzhiyun     }
538*4882a593Smuzhiyun     else {
539*4882a593Smuzhiyun         dmxPropertyIterate(priv->be, dmxCommonRemoveEnabledDevice, dmxInput);
540*4882a593Smuzhiyun         dmxPropertyIterate(priv->be, dmxCommonXSelect, priv);
541*4882a593Smuzhiyun     }
542*4882a593Smuzhiyun }
543*4882a593Smuzhiyun 
544*4882a593Smuzhiyun /** Given the global coordinates \a x and \a y, determine the screen
545*4882a593Smuzhiyun  * with the lowest number on which those coordinates lie.  If they are
546*4882a593Smuzhiyun  * not on any screen, return -1.  The number returned is an index into
547*4882a593Smuzhiyun  * \a dmxScreenInfo and is between -1 and \a dmxNumScreens - 1,
548*4882a593Smuzhiyun  * inclusive. */
549*4882a593Smuzhiyun int
dmxFindPointerScreen(int x,int y)550*4882a593Smuzhiyun dmxFindPointerScreen(int x, int y)
551*4882a593Smuzhiyun {
552*4882a593Smuzhiyun     int i;
553*4882a593Smuzhiyun 
554*4882a593Smuzhiyun     for (i = 0; i < dmxNumScreens; i++) {
555*4882a593Smuzhiyun         ScreenPtr pScreen = screenInfo.screens[i];
556*4882a593Smuzhiyun 
557*4882a593Smuzhiyun         if (x >= pScreen->x && x < pScreen->x + pScreen->width &&
558*4882a593Smuzhiyun             y >= pScreen->y && y < pScreen->y + pScreen->height)
559*4882a593Smuzhiyun             return i;
560*4882a593Smuzhiyun     }
561*4882a593Smuzhiyun     return -1;
562*4882a593Smuzhiyun }
563*4882a593Smuzhiyun 
564*4882a593Smuzhiyun /** Returns a pointer to the private area for the device that comes just
565*4882a593Smuzhiyun  * prior to \a pDevice in the current \a dmxInput device list.  This is
566*4882a593Smuzhiyun  * used as the private area for the current device in some situations
567*4882a593Smuzhiyun  * (e.g., when a keyboard and mouse form a pair that should share the
568*4882a593Smuzhiyun  * same private area).  If the requested private area cannot be located,
569*4882a593Smuzhiyun  * then NULL is returned. */
570*4882a593Smuzhiyun void *
dmxCommonCopyPrivate(DeviceIntPtr pDevice)571*4882a593Smuzhiyun dmxCommonCopyPrivate(DeviceIntPtr pDevice)
572*4882a593Smuzhiyun {
573*4882a593Smuzhiyun     GETDMXLOCALFROMPDEVICE;
574*4882a593Smuzhiyun     DMXInputInfo *dmxInput = &dmxInputs[dmxLocal->inputIdx];
575*4882a593Smuzhiyun     int i;
576*4882a593Smuzhiyun 
577*4882a593Smuzhiyun     for (i = 0; i < dmxInput->numDevs; i++)
578*4882a593Smuzhiyun         if (dmxInput->devs[i] == dmxLocal && i)
579*4882a593Smuzhiyun             return dmxInput->devs[i - 1]->private;
580*4882a593Smuzhiyun     return NULL;
581*4882a593Smuzhiyun }
582*4882a593Smuzhiyun 
583*4882a593Smuzhiyun /** This routine saves and resets some important state for the backend
584*4882a593Smuzhiyun  * and console device drivers:
585*4882a593Smuzhiyun  * - the modifier map is saved and set to 0 (so DMX controls the LEDs)
586*4882a593Smuzhiyun  * - the key click, bell, led, and repeat masks are saved and set to the
587*4882a593Smuzhiyun  * values that DMX claims to be using
588*4882a593Smuzhiyun  *
589*4882a593Smuzhiyun  * This routine and #dmxCommonRestoreState are used when the pointer
590*4882a593Smuzhiyun  * enters and leaves the console window, or when the backend window is
591*4882a593Smuzhiyun  * active or not active (for a full-screen window, this only happens at
592*4882a593Smuzhiyun  * server startup and server shutdown).
593*4882a593Smuzhiyun  */
594*4882a593Smuzhiyun void
dmxCommonSaveState(void * private)595*4882a593Smuzhiyun dmxCommonSaveState(void *private)
596*4882a593Smuzhiyun {
597*4882a593Smuzhiyun     GETPRIVFROMPRIVATE;
598*4882a593Smuzhiyun     XKeyboardState ks;
599*4882a593Smuzhiyun     unsigned long i;
600*4882a593Smuzhiyun     XModifierKeymap *modmap;
601*4882a593Smuzhiyun 
602*4882a593Smuzhiyun     if (dmxInput->console)
603*4882a593Smuzhiyun         priv = dmxInput->devs[0]->private;
604*4882a593Smuzhiyun     if (!priv->display || priv->stateSaved)
605*4882a593Smuzhiyun         return;
606*4882a593Smuzhiyun     DMXDBG0("dmxCommonSaveState\n");
607*4882a593Smuzhiyun     if (dmxUseXKB && (priv->xkb = XkbAllocKeyboard())) {
608*4882a593Smuzhiyun         if (XkbGetIndicatorMap(priv->display, XkbAllIndicatorsMask, priv->xkb)
609*4882a593Smuzhiyun             || XkbGetNames(priv->display, XkbAllNamesMask, priv->xkb)) {
610*4882a593Smuzhiyun             dmxLogInput(dmxInput, "Could not get XKB information\n");
611*4882a593Smuzhiyun             XkbFreeKeyboard(priv->xkb, 0, True);
612*4882a593Smuzhiyun             priv->xkb = NULL;
613*4882a593Smuzhiyun         }
614*4882a593Smuzhiyun         else {
615*4882a593Smuzhiyun             if (priv->xkb->indicators) {
616*4882a593Smuzhiyun                 priv->savedIndicators = *priv->xkb->indicators;
617*4882a593Smuzhiyun                 for (i = 0; i < XkbNumIndicators; i++)
618*4882a593Smuzhiyun                     if (priv->xkb->indicators->phys_indicators & (1 << i)) {
619*4882a593Smuzhiyun                         priv->xkb->indicators->maps[i].flags
620*4882a593Smuzhiyun                             = XkbIM_NoAutomatic;
621*4882a593Smuzhiyun                     }
622*4882a593Smuzhiyun                 XkbSetIndicatorMap(priv->display, ~0, priv->xkb);
623*4882a593Smuzhiyun             }
624*4882a593Smuzhiyun         }
625*4882a593Smuzhiyun     }
626*4882a593Smuzhiyun 
627*4882a593Smuzhiyun     XGetKeyboardControl(priv->display, &ks);
628*4882a593Smuzhiyun     priv->savedKctrl.click = ks.key_click_percent;
629*4882a593Smuzhiyun     priv->savedKctrl.bell = ks.bell_percent;
630*4882a593Smuzhiyun     priv->savedKctrl.bell_pitch = ks.bell_pitch;
631*4882a593Smuzhiyun     priv->savedKctrl.bell_duration = ks.bell_duration;
632*4882a593Smuzhiyun     priv->savedKctrl.leds = ks.led_mask;
633*4882a593Smuzhiyun     priv->savedKctrl.autoRepeat = ks.global_auto_repeat;
634*4882a593Smuzhiyun     for (i = 0; i < 32; i++)
635*4882a593Smuzhiyun         priv->savedKctrl.autoRepeats[i] = ks.auto_repeats[i];
636*4882a593Smuzhiyun 
637*4882a593Smuzhiyun     dmxCommonKbdSetCtrl(priv->display, &priv->savedKctrl,
638*4882a593Smuzhiyun                         &priv->dmxLocal->kctrl);
639*4882a593Smuzhiyun 
640*4882a593Smuzhiyun     priv->savedModMap = XGetModifierMapping(priv->display);
641*4882a593Smuzhiyun 
642*4882a593Smuzhiyun     modmap = XNewModifiermap(0);
643*4882a593Smuzhiyun     XSetModifierMapping(priv->display, modmap);
644*4882a593Smuzhiyun     if (dmxInput->scrnIdx != -1)
645*4882a593Smuzhiyun         dmxSync(&dmxScreens[dmxInput->scrnIdx], TRUE);
646*4882a593Smuzhiyun     XFreeModifiermap(modmap);
647*4882a593Smuzhiyun 
648*4882a593Smuzhiyun     priv->stateSaved = 1;
649*4882a593Smuzhiyun }
650*4882a593Smuzhiyun 
651*4882a593Smuzhiyun /** This routine restores all the information saved by #dmxCommonSaveState. */
652*4882a593Smuzhiyun void
dmxCommonRestoreState(void * private)653*4882a593Smuzhiyun dmxCommonRestoreState(void *private)
654*4882a593Smuzhiyun {
655*4882a593Smuzhiyun     GETPRIVFROMPRIVATE;
656*4882a593Smuzhiyun     int retcode = -1;
657*4882a593Smuzhiyun     CARD32 start;
658*4882a593Smuzhiyun 
659*4882a593Smuzhiyun     if (dmxInput->console)
660*4882a593Smuzhiyun         priv = dmxInput->devs[0]->private;
661*4882a593Smuzhiyun     if (!priv->stateSaved)
662*4882a593Smuzhiyun         return;
663*4882a593Smuzhiyun     priv->stateSaved = 0;
664*4882a593Smuzhiyun 
665*4882a593Smuzhiyun     DMXDBG0("dmxCommonRestoreState\n");
666*4882a593Smuzhiyun     if (priv->xkb) {
667*4882a593Smuzhiyun         *priv->xkb->indicators = priv->savedIndicators;
668*4882a593Smuzhiyun         XkbSetIndicatorMap(priv->display, ~0, priv->xkb);
669*4882a593Smuzhiyun         XkbFreeKeyboard(priv->xkb, 0, True);
670*4882a593Smuzhiyun         priv->xkb = 0;
671*4882a593Smuzhiyun     }
672*4882a593Smuzhiyun 
673*4882a593Smuzhiyun     for (start = GetTimeInMillis(); GetTimeInMillis() - start < 5000;) {
674*4882a593Smuzhiyun         CARD32 tmp;
675*4882a593Smuzhiyun 
676*4882a593Smuzhiyun         retcode = XSetModifierMapping(priv->display, priv->savedModMap);
677*4882a593Smuzhiyun         if (retcode == MappingSuccess)
678*4882a593Smuzhiyun             break;
679*4882a593Smuzhiyun         if (retcode == MappingBusy)
680*4882a593Smuzhiyun             dmxLogInput(dmxInput, "Keyboard busy, waiting\n");
681*4882a593Smuzhiyun         else
682*4882a593Smuzhiyun             dmxLogInput(dmxInput, "Keyboard error, waiting\n");
683*4882a593Smuzhiyun 
684*4882a593Smuzhiyun         /* Don't generate X11 protocol for a bit */
685*4882a593Smuzhiyun         for (tmp = GetTimeInMillis(); GetTimeInMillis() - tmp < 250;) {
686*4882a593Smuzhiyun             usleep(250);        /* This ends up sleeping only until
687*4882a593Smuzhiyun                                  * the next key press generates an
688*4882a593Smuzhiyun                                  * interruption.  We make the delay
689*4882a593Smuzhiyun                                  * relatively short in case the user
690*4882a593Smuzhiyun                                  * pressed they keys quickly. */
691*4882a593Smuzhiyun         }
692*4882a593Smuzhiyun 
693*4882a593Smuzhiyun     }
694*4882a593Smuzhiyun     if (retcode != MappingSuccess)
695*4882a593Smuzhiyun         dmxLog(dmxWarning, "Unable to restore keyboard modifier state!\n");
696*4882a593Smuzhiyun 
697*4882a593Smuzhiyun     XFreeModifiermap(priv->savedModMap);
698*4882a593Smuzhiyun     priv->savedModMap = NULL;
699*4882a593Smuzhiyun 
700*4882a593Smuzhiyun     dmxCommonKbdSetCtrl(priv->display, NULL, &priv->savedKctrl);
701*4882a593Smuzhiyun     priv->kctrlset = 0;         /* Invalidate copy */
702*4882a593Smuzhiyun }
703