aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/programs/Xserver/hw/dmx/input/dmxinputinit.h
blob: c593e267a6c8b24169f92f879747a9068ec91e27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/* $XFree86$ */
/*
 * Copyright 2002 Red Hat Inc., Durham, North Carolina.
 *
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation on the rights to use, copy, modify, merge,
 * publish, distribute, sublicense, and/or sell copies of the Software,
 * and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial
 * portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NON-INFRINGEMENT.  IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/*
 * Authors:
 *   Rickard E. (Rik) Faith <faith@redhat.com>
 *
 */

/** \file
 * Interface for low-level input support.  \see dmxinputinit.c */

#ifndef _DMXINPUTINIT_H_
#define _DMXINPUTINIT_H_

#include "dmx.h"
#include "dmxinput.h"
#include "dmxlog.h"


#define DMX_LOCAL_DEFAULT_KEYBOARD "kbd"
#define DMX_LOCAL_DEFAULT_POINTER  "ps2"
#define DMX_MAX_BUTTONS            256
#define DMX_MOTION_SIZE            256
#define DMX_MAX_VALUATORS          32
#define DMX_MAX_AXES               32
#define DMX_MAX_XINPUT_EVENT_TYPES 100
#define DMX_MAP_ENTRIES            16 /* Must be a power of 2 */
#define DMX_MAP_MASK               (DMX_MAP_ENTRIES - 1)

typedef enum {
    DMX_FUNCTION_GRAB,
    DMX_FUNCTION_TERMINATE,
    DMX_FUNCTION_FINE
} DMXFunctionType;

typedef enum {
    DMX_LOCAL_HIGHLEVEL,
    DMX_LOCAL_KEYBOARD,
    DMX_LOCAL_MOUSE,
    DMX_LOCAL_OTHER
} DMXLocalInputType;

typedef enum {
    DMX_LOCAL_TYPE_LOCAL,
    DMX_LOCAL_TYPE_CONSOLE,
    DMX_LOCAL_TYPE_BACKEND,
    DMX_LOCAL_TYPE_COMMON
} DMXLocalInputExtType;

typedef enum {
    DMX_RELATIVE,
    DMX_ABSOLUTE,
    DMX_ABSOLUTE_CONFINED
} DMXMotionType;

/** Stores information from low-level device that is used to initialize
 * the device at the dix level. */
typedef struct _DMXLocalInitInfo {
    int                  keyboard; /**< Non-zero if the device is a keyboard */
    
    int                  keyClass; /**< Non-zero if keys are present */
    KeySymsRec           keySyms;  /**< Key symbols */
    int                  freemap;  /**< If non-zero, free keySyms.map */
    CARD8                modMap[MAP_LENGTH]; /**< Modifier map */
#ifdef XKB
    XkbDescPtr           xkb;       /**< XKB description */
    XkbComponentNamesRec names;     /**< XKB component names */
    int                  freenames; /**< Non-zero if names should be free'd */
    int                  force;     /**< Do not allow command line override */
#endif

    int                  buttonClass; /**< Non-zero if buttons are present */
    int                  numButtons;  /**< Number of buttons */
    unsigned char        map[DMX_MAX_BUTTONS]; /**< Button map */

    int                  valuatorClass; /**< Non-zero if valuators are
                                         * present */
    int                  numRelAxes;    /**< Number of relative axes */
    int                  numAbsAxes;    /**< Number of absolute axes */
    int                  minval[DMX_MAX_AXES]; /**< Minimum values */
    int                  maxval[DMX_MAX_AXES]; /**< Maximum values */
    int                  res[DMX_MAX_AXES];    /**< Resolution */
    int                  minres[DMX_MAX_AXES]; /**< Minimum resolutions */
    int                  maxres[DMX_MAX_AXES]; /**< Maximum resolutions */

    int                  focusClass;       /**< Non-zero if device can
                                            * cause focus */
    int                  proximityClass;   /**< Non-zero if device
                                            * causes proximity events */
    int                  kbdFeedbackClass; /**< Non-zero if device has
                                            * keyboard feedback */ 
    int                  ptrFeedbackClass; /**< Non-zero if device has
                                            * pointer feedback */
    int                  ledFeedbackClass; /**< Non-zero if device has
                                            * LED indicators */
    int                  belFeedbackClass; /**< Non-zero if device has a
                                            * bell */ 
    int                  intFeedbackClass; /**< Non-zero if device has
                                            * integer feedback */
    int                  strFeedbackClass; /**< Non-zero if device has
                                            * string feedback */

    int                  maxSymbols;          /**< Maximum symbols */
    int                  maxSymbolsSupported; /**< Maximum symbols supported */
    KeySym               *symbols;            /**< Key symbols */
} DMXLocalInitInfo, *DMXLocalInitInfoPtr;

typedef pointer (*dmxCreatePrivateProcPtr)(DeviceIntPtr);
typedef void    (*dmxDestroyPrivateProcPtr)(pointer);
                
typedef void    (*dmxInitProcPtr)(DevicePtr);
typedef void    (*dmxReInitProcPtr)(DevicePtr);
typedef void    (*dmxLateReInitProcPtr)(DevicePtr);
typedef void    (*dmxGetInfoProcPtr)(DevicePtr, DMXLocalInitInfoPtr);
typedef int     (*dmxOnProcPtr)(DevicePtr);
typedef void    (*dmxOffProcPtr)(DevicePtr);
typedef void    (*dmxUpdatePositionProcPtr)(pointer, int x, int y);
                
typedef void    (*dmxVTPreSwitchProcPtr)(pointer);  /* Turn I/O Off */
typedef void    (*dmxVTPostSwitchProcPtr)(pointer); /* Turn I/O On */
typedef void    (*dmxVTSwitchReturnProcPtr)(pointer);
typedef int     (*dmxVTSwitchProcPtr)(pointer, int vt,
                                      dmxVTSwitchReturnProcPtr, pointer);
                
typedef void    (*dmxMotionProcPtr)(DevicePtr,
                                    int *valuators,
                                    int firstAxis,
                                    int axesCount,
                                    DMXMotionType type,
                                    DMXBlockType block);
typedef void    (*dmxEnqueueProcPtr)(DevicePtr, int type, int detail,
                                     KeySym keySym, XEvent *e,
                                     DMXBlockType block);
typedef int     (*dmxCheckSpecialProcPtr)(DevicePtr, KeySym keySym);
typedef void    (*dmxCollectEventsProcPtr)(DevicePtr,
                                           dmxMotionProcPtr,
                                           dmxEnqueueProcPtr,
                                           dmxCheckSpecialProcPtr,
                                           DMXBlockType);
typedef void    (*dmxProcessInputProcPtr)(pointer);
typedef void    (*dmxUpdateInfoProcPtr)(pointer, DMXUpdateType, WindowPtr);
typedef int     (*dmxFunctionsProcPtr)(pointer, DMXFunctionType);
                
typedef void    (*dmxKBCtrlProcPtr)(DevicePtr, KeybdCtrl *ctrl);
typedef void    (*dmxMCtrlProcPtr)(DevicePtr, PtrCtrl *ctrl);
typedef void    (*dmxKBBellProcPtr)(DevicePtr, int percent,
                                    int volume, int pitch, int duration);

/** Stores a mapping between the device id on the remote X server and
 * the id on the DMX server */
typedef struct _DMXEventMap {
    int remote;                 /**< Event number on remote X server */
    int server;                 /**< Event number (unbiased) on DMX server */
} DMXEventMap;

/** This is the device-independent structure used by the low-level input
 * routines.  The contents are not exposed to top-level .c files (except
 * dmxextensions.c).  \see dmxinput.h \see dmxextensions.c */
typedef struct _DMXLocalInputInfo {
    const char               *name;   /**< Device name */
    DMXLocalInputType        type;    /**< Device type  */
    DMXLocalInputExtType     extType; /**< Extended device type */
    int                      binding; /**< Count of how many consecutive
                                       * structs are bound to the same
                                       * device */
    
                                /* Low-level (e.g., keyboard/mouse drivers) */

    dmxCreatePrivateProcPtr  create_private;  /**< Create
                                               * device-dependent
                                               * private */
    dmxDestroyPrivateProcPtr destroy_private; /**< Destroy
                                               * device-dependent
                                               * private */
    dmxInitProcPtr           init;            /**< Initialize device  */
    dmxReInitProcPtr         reinit;          /**< Reinitialize device
                                               * (during a
                                               * reconfiguration) */
    dmxLateReInitProcPtr     latereinit;      /**< Reinitialize a device
                                               * (called very late
                                               * during a
                                               * reconfiguration) */
    dmxGetInfoProcPtr        get_info;        /**< Get device information */
    dmxOnProcPtr             on;              /**< Turn device on */
    dmxOffProcPtr            off;             /**< Turn device off */
    dmxUpdatePositionProcPtr update_position; /**< Called when another
                                               * device updates the
                                               * cursor position */
    dmxVTPreSwitchProcPtr    vt_pre_switch;   /**< Called before a VT switch */
    dmxVTPostSwitchProcPtr   vt_post_switch;  /**< Called after a VT switch */
    dmxVTSwitchProcPtr       vt_switch;       /**< Causes a VT switch */

    dmxCollectEventsProcPtr  collect_events;  /**< Collect and enqueue
                                               * events from the
                                               * device*/
    dmxProcessInputProcPtr   process_input;   /**< Process event (from
                                               * queue)  */
    dmxFunctionsProcPtr      functions;
    dmxUpdateInfoProcPtr     update_info;     /**< Update window layout
                                               * information */

    dmxMCtrlProcPtr          mCtrl;           /**< Pointer control */
    dmxKBCtrlProcPtr         kCtrl;           /**< Keyboard control */
    dmxKBBellProcPtr         kBell;           /**< Bell control */

    pointer                  private;         /**< Device-dependent private  */
    int                      isCore;          /**< Is a DMX core device  */
    int                      sendsCore;       /**< Sends DMX core events */
    KeybdCtrl                kctrl;           /**< Keyboard control */
    PtrCtrl                  mctrl;           /**< Pointer control */

    DeviceIntPtr             pDevice;         /**< X-level device  */
    int                      inputIdx;        /**< High-level index */
    int                      lastX, lastY;    /**< Last known position;
                                               * for XInput in
                                               * dmxevents.c */ 

    int                      head;            /**< XInput motion history
                                               * head */
    int                      tail;            /**< XInput motion history
                                               * tail */
    unsigned long            *history;        /**< XInput motion history */
    int                      *valuators;      /**< Cache of previous values */
    
                                /* for XInput ChangePointerDevice */
    int                      (*savedMotionProc)(DeviceIntPtr,
                                                xTimecoord *,
                                                unsigned long,
                                                unsigned long,
                                                ScreenPtr);
    int                      savedMotionEvents; /**< Saved motion events */
    int                      savedSendsCore;    /**< Saved sends-core flag */

    DMXEventMap              map[DMX_MAP_ENTRIES]; /**< XInput device id map */
    int                      mapOptimize;          /**< XInput device id
                                                    * map
                                                    * optimization */

    long                     deviceId;    /**< device id on remote side,
                                           * if any */
    const char               *deviceName; /**< devive name on remote
                                           * side, if any */
} DMXLocalInputInfoRec;

extern DMXLocalInputInfoPtr dmxLocalCorePointer, dmxLocalCoreKeyboard;

extern void                 dmxLocalInitInput(DMXInputInfo *dmxInput);
extern DMXLocalInputInfoPtr dmxInputCopyLocal(DMXInputInfo *dmxInput,
                                              DMXLocalInputInfoPtr s);

extern void dmxChangePointerControl(DeviceIntPtr pDevice, PtrCtrl *ctrl);
extern void dmxKeyboardKbdCtrlProc(DeviceIntPtr pDevice, KeybdCtrl *ctrl);
extern void dmxKeyboardBellProc(int percent, DeviceIntPtr pDevice,
                                pointer ctrl, int unknown);

extern int  dmxInputExtensionErrorHandler(Display *dsp, char *name,
                                          char *reason);

extern int          dmxInputDetach(DMXInputInfo *dmxInput);
extern void         dmxInputDetachAll(DMXScreenInfo *dmxScreen);
extern int          dmxInputDetachId(int id);
extern DMXInputInfo *dmxInputLocateId(int id);
extern int          dmxInputAttachConsole(const char *name, int isCore,
                                          int *id);
extern int          dmxInputAttachBackend(int physicalScreen, int isCore,
                                          int *id);

#endif