Home | History | Annotate | Line # | Download | only in input
      1 /*
      2  * Copyright 2002 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 (at) redhat.com>
     31  *
     32  */
     33 
     34 /** \file
     35  * Interface for low-level input support.  \see dmxinputinit.c */
     36 
     37 #ifndef _DMXINPUTINIT_H_
     38 #define _DMXINPUTINIT_H_
     39 
     40 #include "dmx.h"
     41 #include "dmxinput.h"
     42 #include "dmxlog.h"
     43 
     44 
     45 #define DMX_LOCAL_DEFAULT_KEYBOARD "kbd"
     46 #define DMX_LOCAL_DEFAULT_POINTER  "ps2"
     47 #define DMX_MAX_BUTTONS            256
     48 #define DMX_MOTION_SIZE            256
     49 #define DMX_MAX_VALUATORS          32
     50 #define DMX_MAX_AXES               32
     51 #define DMX_MAX_XINPUT_EVENT_TYPES 100
     52 #define DMX_MAP_ENTRIES            16 /* Must be a power of 2 */
     53 #define DMX_MAP_MASK               (DMX_MAP_ENTRIES - 1)
     54 
     55 typedef enum {
     56     DMX_FUNCTION_GRAB,
     57     DMX_FUNCTION_TERMINATE,
     58     DMX_FUNCTION_FINE
     59 } DMXFunctionType;
     60 
     61 typedef enum {
     62     DMX_LOCAL_HIGHLEVEL,
     63     DMX_LOCAL_KEYBOARD,
     64     DMX_LOCAL_MOUSE,
     65     DMX_LOCAL_OTHER
     66 } DMXLocalInputType;
     67 
     68 typedef enum {
     69     DMX_LOCAL_TYPE_LOCAL,
     70     DMX_LOCAL_TYPE_CONSOLE,
     71     DMX_LOCAL_TYPE_BACKEND,
     72     DMX_LOCAL_TYPE_COMMON
     73 } DMXLocalInputExtType;
     74 
     75 typedef enum {
     76     DMX_RELATIVE,
     77     DMX_ABSOLUTE,
     78     DMX_ABSOLUTE_CONFINED
     79 } DMXMotionType;
     80 
     81 /** Stores information from low-level device that is used to initialize
     82  * the device at the dix level. */
     83 typedef struct _DMXLocalInitInfo {
     84     int                  keyboard; /**< Non-zero if the device is a keyboard */
     85 
     86     int                  keyClass; /**< Non-zero if keys are present */
     87     KeySymsRec           keySyms;  /**< Key symbols */
     88     int                  freemap;  /**< If non-zero, free keySyms.map */
     89     CARD8                modMap[MAP_LENGTH]; /**< Modifier map */
     90     XkbDescPtr           xkb;       /**< XKB description */
     91     XkbComponentNamesRec names;     /**< XKB component names */
     92     int                  freenames; /**< Non-zero if names should be free'd */
     93     int                  force;     /**< Do not allow command line override */
     94 
     95     int                  buttonClass; /**< Non-zero if buttons are present */
     96     int                  numButtons;  /**< Number of buttons */
     97     unsigned char        map[DMX_MAX_BUTTONS]; /**< Button map */
     98 
     99     int                  valuatorClass; /**< Non-zero if valuators are
    100                                          * present */
    101     int                  numRelAxes;    /**< Number of relative axes */
    102     int                  numAbsAxes;    /**< Number of absolute axes */
    103     int                  minval[DMX_MAX_AXES]; /**< Minimum values */
    104     int                  maxval[DMX_MAX_AXES]; /**< Maximum values */
    105     int                  res[DMX_MAX_AXES];    /**< Resolution */
    106     int                  minres[DMX_MAX_AXES]; /**< Minimum resolutions */
    107     int                  maxres[DMX_MAX_AXES]; /**< Maximum resolutions */
    108 
    109     int                  focusClass;       /**< Non-zero if device can
    110                                             * cause focus */
    111     int                  proximityClass;   /**< Non-zero if device
    112                                             * causes proximity events */
    113     int                  kbdFeedbackClass; /**< Non-zero if device has
    114                                             * keyboard feedback */
    115     int                  ptrFeedbackClass; /**< Non-zero if device has
    116                                             * pointer feedback */
    117     int                  ledFeedbackClass; /**< Non-zero if device has
    118                                             * LED indicators */
    119     int                  belFeedbackClass; /**< Non-zero if device has a
    120                                             * bell */
    121     int                  intFeedbackClass; /**< Non-zero if device has
    122                                             * integer feedback */
    123     int                  strFeedbackClass; /**< Non-zero if device has
    124                                             * string feedback */
    125 
    126     int                  maxSymbols;          /**< Maximum symbols */
    127     int                  maxSymbolsSupported; /**< Maximum symbols supported */
    128     KeySym               *symbols;            /**< Key symbols */
    129 } DMXLocalInitInfo, *DMXLocalInitInfoPtr;
    130 
    131 typedef pointer (*dmxCreatePrivateProcPtr)(DeviceIntPtr);
    132 typedef void    (*dmxDestroyPrivateProcPtr)(pointer);
    133 
    134 typedef void    (*dmxInitProcPtr)(DevicePtr);
    135 typedef void    (*dmxReInitProcPtr)(DevicePtr);
    136 typedef void    (*dmxLateReInitProcPtr)(DevicePtr);
    137 typedef void    (*dmxGetInfoProcPtr)(DevicePtr, DMXLocalInitInfoPtr);
    138 typedef int     (*dmxOnProcPtr)(DevicePtr);
    139 typedef void    (*dmxOffProcPtr)(DevicePtr);
    140 typedef void    (*dmxUpdatePositionProcPtr)(pointer, int x, int y);
    141 
    142 typedef void    (*dmxVTPreSwitchProcPtr)(pointer);  /* Turn I/O Off */
    143 typedef void    (*dmxVTPostSwitchProcPtr)(pointer); /* Turn I/O On */
    144 typedef void    (*dmxVTSwitchReturnProcPtr)(pointer);
    145 typedef int     (*dmxVTSwitchProcPtr)(pointer, int vt,
    146                                       dmxVTSwitchReturnProcPtr, pointer);
    147 
    148 typedef void    (*dmxMotionProcPtr)(DevicePtr,
    149                                     int *valuators,
    150                                     int firstAxis,
    151                                     int axesCount,
    152                                     DMXMotionType type,
    153                                     DMXBlockType block);
    154 typedef void    (*dmxEnqueueProcPtr)(DevicePtr, int type, int detail,
    155                                      KeySym keySym, XEvent *e,
    156                                      DMXBlockType block);
    157 typedef int     (*dmxCheckSpecialProcPtr)(DevicePtr, KeySym keySym);
    158 typedef void    (*dmxCollectEventsProcPtr)(DevicePtr,
    159                                            dmxMotionProcPtr,
    160                                            dmxEnqueueProcPtr,
    161                                            dmxCheckSpecialProcPtr,
    162                                            DMXBlockType);
    163 typedef void    (*dmxProcessInputProcPtr)(pointer);
    164 typedef void    (*dmxUpdateInfoProcPtr)(pointer, DMXUpdateType, WindowPtr);
    165 typedef int     (*dmxFunctionsProcPtr)(pointer, DMXFunctionType);
    166 
    167 typedef void    (*dmxKBCtrlProcPtr)(DevicePtr, KeybdCtrl *ctrl);
    168 typedef void    (*dmxMCtrlProcPtr)(DevicePtr, PtrCtrl *ctrl);
    169 typedef void    (*dmxKBBellProcPtr)(DevicePtr, int percent,
    170                                     int volume, int pitch, int duration);
    171 
    172 /** Stores a mapping between the device id on the remote X server and
    173  * the id on the DMX server */
    174 typedef struct _DMXEventMap {
    175     int remote;                 /**< Event number on remote X server */
    176     int server;                 /**< Event number (unbiased) on DMX server */
    177 } DMXEventMap;
    178 
    179 /** This is the device-independent structure used by the low-level input
    180  * routines.  The contents are not exposed to top-level .c files (except
    181  * dmxextensions.c).  \see dmxinput.h \see dmxextensions.c */
    182 typedef struct _DMXLocalInputInfo {
    183     const char               *name;   /**< Device name */
    184     DMXLocalInputType        type;    /**< Device type  */
    185     DMXLocalInputExtType     extType; /**< Extended device type */
    186     int                      binding; /**< Count of how many consecutive
    187                                        * structs are bound to the same
    188                                        * device */
    189 
    190                                 /* Low-level (e.g., keyboard/mouse drivers) */
    191 
    192     dmxCreatePrivateProcPtr  create_private;  /**< Create
    193                                                * device-dependent
    194                                                * private */
    195     dmxDestroyPrivateProcPtr destroy_private; /**< Destroy
    196                                                * device-dependent
    197                                                * private */
    198     dmxInitProcPtr           init;            /**< Initialize device  */
    199     dmxReInitProcPtr         reinit;          /**< Reinitialize device
    200                                                * (during a
    201                                                * reconfiguration) */
    202     dmxLateReInitProcPtr     latereinit;      /**< Reinitialize a device
    203                                                * (called very late
    204                                                * during a
    205                                                * reconfiguration) */
    206     dmxGetInfoProcPtr        get_info;        /**< Get device information */
    207     dmxOnProcPtr             on;              /**< Turn device on */
    208     dmxOffProcPtr            off;             /**< Turn device off */
    209     dmxUpdatePositionProcPtr update_position; /**< Called when another
    210                                                * device updates the
    211                                                * cursor position */
    212     dmxVTPreSwitchProcPtr    vt_pre_switch;   /**< Called before a VT switch */
    213     dmxVTPostSwitchProcPtr   vt_post_switch;  /**< Called after a VT switch */
    214     dmxVTSwitchProcPtr       vt_switch;       /**< Causes a VT switch */
    215 
    216     dmxCollectEventsProcPtr  collect_events;  /**< Collect and enqueue
    217                                                * events from the
    218                                                * device*/
    219     dmxProcessInputProcPtr   process_input;   /**< Process event (from
    220                                                * queue)  */
    221     dmxFunctionsProcPtr      functions;
    222     dmxUpdateInfoProcPtr     update_info;     /**< Update window layout
    223                                                * information */
    224 
    225     dmxMCtrlProcPtr          mCtrl;           /**< Pointer control */
    226     dmxKBCtrlProcPtr         kCtrl;           /**< Keyboard control */
    227     dmxKBBellProcPtr         kBell;           /**< Bell control */
    228 
    229     pointer                  private;         /**< Device-dependent private  */
    230     int                      isCore;          /**< Is a DMX core device  */
    231     int                      sendsCore;       /**< Sends DMX core events */
    232     KeybdCtrl                kctrl;           /**< Keyboard control */
    233     PtrCtrl                  mctrl;           /**< Pointer control */
    234 
    235     DeviceIntPtr             pDevice;         /**< X-level device  */
    236     int                      inputIdx;        /**< High-level index */
    237     int                      lastX, lastY;    /**< Last known position;
    238                                                * for XInput in
    239                                                * dmxevents.c */
    240 
    241     int                      head;            /**< XInput motion history
    242                                                * head */
    243     int                      tail;            /**< XInput motion history
    244                                                * tail */
    245     unsigned long            *history;        /**< XInput motion history */
    246     int                      *valuators;      /**< Cache of previous values */
    247 
    248                                 /* for XInput ChangePointerDevice */
    249     int                      (*savedMotionProc)(DeviceIntPtr,
    250                                                 xTimecoord *,
    251                                                 unsigned long,
    252                                                 unsigned long,
    253                                                 ScreenPtr);
    254     int                      savedMotionEvents; /**< Saved motion events */
    255     int                      savedSendsCore;    /**< Saved sends-core flag */
    256 
    257     DMXEventMap              map[DMX_MAP_ENTRIES]; /**< XInput device id map */
    258     int                      mapOptimize;          /**< XInput device id
    259                                                     * map
    260                                                     * optimization */
    261 
    262     long                     deviceId;    /**< device id on remote side,
    263                                            * if any */
    264     const char               *deviceName; /**< devive name on remote
    265                                            * side, if any */
    266 } DMXLocalInputInfoRec;
    267 
    268 extern DMXLocalInputInfoPtr dmxLocalCorePointer, dmxLocalCoreKeyboard;
    269 
    270 extern void                 dmxLocalInitInput(DMXInputInfo *dmxInput);
    271 extern DMXLocalInputInfoPtr dmxInputCopyLocal(DMXInputInfo *dmxInput,
    272                                               DMXLocalInputInfoPtr s);
    273 
    274 extern void dmxChangePointerControl(DeviceIntPtr pDevice, PtrCtrl *ctrl);
    275 extern void dmxKeyboardKbdCtrlProc(DeviceIntPtr pDevice, KeybdCtrl *ctrl);
    276 extern void dmxKeyboardBellProc(int percent, DeviceIntPtr pDevice,
    277                                 pointer ctrl, int unknown);
    278 
    279 extern int  dmxInputExtensionErrorHandler(Display *dsp, _Xconst char *name,
    280                                           _Xconst char *reason);
    281 
    282 extern int          dmxInputDetach(DMXInputInfo *dmxInput);
    283 extern void         dmxInputDetachAll(DMXScreenInfo *dmxScreen);
    284 extern int          dmxInputDetachId(int id);
    285 extern DMXInputInfo *dmxInputLocateId(int id);
    286 extern int          dmxInputAttachConsole(const char *name, int isCore,
    287                                           int *id);
    288 extern int          dmxInputAttachBackend(int physicalScreen, int isCore,
    289                                           int *id);
    290 
    291 #endif
    292