2 * Copyright 2003 Red Hat Inc., Durham, North Carolina.
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation on the rights to use, copy, modify, merge,
10 * publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * Rickard E. (Rik) Faith <faith@redhat.com>
35 * This file implements a mapping from remote XInput event types to Xdmx
38 * The exglobals.h file defines global server-side variables with names
39 * Device* to be integers that hold the value of the type of the
40 * server-side XInput extension event.
42 * The client-side X11/extensions/XInput.h file defines macros with THE
43 * EXACT SAME Device* names!
45 * Using those macros to extract remote server event type values from
46 * the (opaque) XDevice structure is appropriate, but makes a direct
47 * mapping to the Device* integers impossible. So we use the normalized
48 * XI_Device* names for these routines.
51 #ifdef HAVE_DMX_CONFIG_H
52 #include <dmx-config.h>
55 #include "dmxinputinit.h"
58 /** Create a mapping from \a remoteEvent to \a serverEvent. The \a
59 * remoteEvent is the type returned from the remote server. The \a
60 * serverEvent is from the XI_* list of events in
61 * include/extensions/XIproto.h. */
63 dmxMapInsert(DMXLocalInputInfoPtr dmxLocal
, int remoteEvent
, int serverEvent
)
65 int hash
= remoteEvent
& DMX_MAP_MASK
;
68 /* Return if this has already been mapped */
69 if (dmxLocal
->map
[hash
].remote
== remoteEvent
70 && dmxLocal
->map
[hash
].server
== serverEvent
)
73 if (dmxLocal
->map
[hash
].remote
) {
74 dmxLocal
->mapOptimize
= 0;
75 for (i
= 0; i
< DMX_MAP_ENTRIES
; i
++) {
76 if (!dmxLocal
->map
[i
].remote
) {
77 dmxLocal
->map
[i
].remote
= remoteEvent
;
78 dmxLocal
->map
[i
].server
= serverEvent
;
83 "Out of map entries, cannot map remove event type %d\n",
87 dmxLocal
->map
[hash
].remote
= remoteEvent
;
88 dmxLocal
->map
[hash
].server
= serverEvent
;
92 /** Remove all mappings there were inserted with #dmxMapInsert. */
94 dmxMapClear(DMXLocalInputInfoPtr dmxLocal
)
98 for (i
= 0; i
< DMX_MAP_ENTRIES
; i
++)
99 dmxLocal
->map
[i
].remote
= 0;
100 dmxLocal
->mapOptimize
= 1;
103 /** Lookup a mapping for \a remoteEvent. The \a remoteEvent is the type
104 * returned from the remote server. The return value is that which was
105 * passed into #dmxMapInsert (i.e., a value from the XI_* list in
106 * include/extensions/XIproto.h). If a mapping is not available, -1 is
109 dmxMapLookup(DMXLocalInputInfoPtr dmxLocal
, int remoteEvent
)
111 int hash
= remoteEvent
& DMX_MAP_MASK
;
112 int serverEvent
= -1;
115 if (dmxLocal
->mapOptimize
&& dmxLocal
->map
[hash
].remote
== remoteEvent
) {
116 serverEvent
= dmxLocal
->map
[hash
].server
;
119 for (i
= 0; i
< DMX_MAP_ENTRIES
; i
++)
120 if (dmxLocal
->map
[i
].remote
== remoteEvent
) {
121 serverEvent
= dmxLocal
->map
[hash
].server
;