Commit | Line | Data |
---|---|---|
a09e091a JB |
1 | /* |
2 | * Copyright 2003 Red Hat Inc., Durham, North Carolina. | |
3 | * | |
4 | * All Rights Reserved. | |
5 | * | |
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: | |
13 | * | |
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. | |
17 | * | |
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 | |
25 | * SOFTWARE. | |
26 | */ | |
27 | ||
28 | /* | |
29 | * Authors: | |
30 | * Rickard E. (Rik) Faith <faith@redhat.com> | |
31 | */ | |
32 | ||
33 | /** \file | |
34 | * | |
35 | * This file implements a mapping from remote XInput event types to Xdmx | |
36 | * XInput event types. | |
37 | * | |
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. | |
41 | * | |
42 | * The client-side X11/extensions/XInput.h file defines macros with THE | |
43 | * EXACT SAME Device* names! | |
44 | * | |
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. | |
49 | */ | |
50 | ||
51 | #ifdef HAVE_DMX_CONFIG_H | |
52 | #include <dmx-config.h> | |
53 | #endif | |
54 | ||
55 | #include "dmxinputinit.h" | |
56 | #include "dmxmap.h" | |
57 | ||
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. */ | |
62 | void | |
63 | dmxMapInsert(DMXLocalInputInfoPtr dmxLocal, int remoteEvent, int serverEvent) | |
64 | { | |
65 | int hash = remoteEvent & DMX_MAP_MASK; | |
66 | int i; | |
67 | ||
68 | /* Return if this has already been mapped */ | |
69 | if (dmxLocal->map[hash].remote == remoteEvent | |
70 | && dmxLocal->map[hash].server == serverEvent) | |
71 | return; | |
72 | ||
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; | |
79 | return; | |
80 | } | |
81 | } | |
82 | dmxLog(dmxWarning, | |
83 | "Out of map entries, cannot map remove event type %d\n", | |
84 | remoteEvent); | |
85 | } | |
86 | else { | |
87 | dmxLocal->map[hash].remote = remoteEvent; | |
88 | dmxLocal->map[hash].server = serverEvent; | |
89 | } | |
90 | } | |
91 | ||
92 | /** Remove all mappings there were inserted with #dmxMapInsert. */ | |
93 | void | |
94 | dmxMapClear(DMXLocalInputInfoPtr dmxLocal) | |
95 | { | |
96 | int i; | |
97 | ||
98 | for (i = 0; i < DMX_MAP_ENTRIES; i++) | |
99 | dmxLocal->map[i].remote = 0; | |
100 | dmxLocal->mapOptimize = 1; | |
101 | } | |
102 | ||
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 | |
107 | * returned. */ | |
108 | int | |
109 | dmxMapLookup(DMXLocalInputInfoPtr dmxLocal, int remoteEvent) | |
110 | { | |
111 | int hash = remoteEvent & DMX_MAP_MASK; | |
112 | int serverEvent = -1; | |
113 | int i; | |
114 | ||
115 | if (dmxLocal->mapOptimize && dmxLocal->map[hash].remote == remoteEvent) { | |
116 | serverEvent = dmxLocal->map[hash].server; | |
117 | } | |
118 | else { | |
119 | for (i = 0; i < DMX_MAP_ENTRIES; i++) | |
120 | if (dmxLocal->map[i].remote == remoteEvent) { | |
121 | serverEvent = dmxLocal->map[hash].server; | |
122 | break; | |
123 | } | |
124 | } | |
125 | ||
126 | return serverEvent; | |
127 | } |