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@redhat.com>
31 *
32 */
33
34/** \file
35 *
36 * This code implements a low-level device driver for a USB mouse. */
37
38#ifdef HAVE_DMX_CONFIG_H
39#include <dmx-config.h>
40#endif
41
42#include "usb-private.h"
43
44/*****************************************************************************/
45/* Define some macros to make it easier to move this file to another
46 * part of the Xserver tree.  All calls to the dmx* layer are #defined
47 * here for the .c file.  The .h file will also have to be edited. */
48#include "usb-mouse.h"
49
50#define GETPRIV       myPrivate *priv                            \
51                      = ((DMXLocalInputInfoPtr)(pDev->devicePrivate))->private
52
53#define LOG0(f)       dmxLog(dmxDebug,f)
54#define LOG1(f,a)     dmxLog(dmxDebug,f,a)
55#define LOG2(f,a,b)   dmxLog(dmxDebug,f,a,b)
56#define LOG3(f,a,b,c) dmxLog(dmxDebug,f,a,b,c)
57#define FATAL0(f)     dmxLog(dmxFatal,f)
58#define FATAL1(f,a)   dmxLog(dmxFatal,f,a)
59#define FATAL2(f,a,b) dmxLog(dmxFatal,f,a,b)
60#define MOTIONPROC    dmxMotionProcPtr
61#define ENQUEUEPROC   dmxEnqueueProcPtr
62#define CHECKPROC     dmxCheckSpecialProcPtr
63#define BLOCK         DMXBlockType
64
65/* End of interface definitions. */
66/*****************************************************************************/
67
68/** Read the USB device using #usbRead. */
69void mouUSBRead(DevicePtr pDev,
70                MOTIONPROC motion,
71                ENQUEUEPROC enqueue,
72                CHECKPROC checkspecial,
73                BLOCK block)
74{
75    usbRead(pDev, motion, enqueue, BTN_MISC, block);
76}
77
78/** Initialize \a pDev using #usbInit. */
79void mouUSBInit(DevicePtr pDev)
80{
81    usbInit(pDev, usbMouse);
82}
83
84/** Turn \a pDev on (i.e., take input from \a pDev). */
85int mouUSBOn(DevicePtr pDev)
86{
87    GETPRIV;
88
89    if (priv->fd < 0) mouUSBInit(pDev);
90    return priv->fd;
91}
92
93static void mouUSBGetMap(DevicePtr pDev, unsigned char *map, int *nButtons)
94{
95    int i;
96
97    if (nButtons) *nButtons = 5;
98    if (map) for (i = 0; i <= *nButtons; i++) map[i] = i;
99}
100
101/** Fill the \a info structure with information needed to initialize \a
102 * pDev. */
103void mouUSBGetInfo(DevicePtr pDev, DMXLocalInitInfoPtr info)
104{
105    static KeySym keyboard_mapping = NoSymbol;
106
107    info->buttonClass        = 1;
108    mouUSBGetMap(pDev, info->map, &info->numButtons);
109    info->valuatorClass      = 1;
110    info->numRelAxes         = 2;
111    info->minval[0]          = 0;
112    info->maxval[0]          = 0;
113    info->res[0]             = 1;
114    info->minres[0]          = 0;
115    info->maxres[0]          = 1;
116    info->ptrFeedbackClass   = 1;
117
118                                /* Some USB mice devices return key
119                                 * events from their pair'd
120                                 * keyboard...  */
121    info->keyClass           = 1;
122    info->keySyms.minKeyCode = 8;
123    info->keySyms.maxKeyCode = 8;
124    info->keySyms.mapWidth   = 1;
125    info->keySyms.map        = &keyboard_mapping;
126}
127