1706f2543Smrg/* 2706f2543Smrg * Copyright 2002 Red Hat Inc., Durham, North Carolina. 3706f2543Smrg * 4706f2543Smrg * All Rights Reserved. 5706f2543Smrg * 6706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining 7706f2543Smrg * a copy of this software and associated documentation files (the 8706f2543Smrg * "Software"), to deal in the Software without restriction, including 9706f2543Smrg * without limitation on the rights to use, copy, modify, merge, 10706f2543Smrg * publish, distribute, sublicense, and/or sell copies of the Software, 11706f2543Smrg * and to permit persons to whom the Software is furnished to do so, 12706f2543Smrg * subject to the following conditions: 13706f2543Smrg * 14706f2543Smrg * The above copyright notice and this permission notice (including the 15706f2543Smrg * next paragraph) shall be included in all copies or substantial 16706f2543Smrg * portions of the Software. 17706f2543Smrg * 18706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19706f2543Smrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20706f2543Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21706f2543Smrg * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS 22706f2543Smrg * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 23706f2543Smrg * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 24706f2543Smrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25706f2543Smrg * SOFTWARE. 26706f2543Smrg */ 27706f2543Smrg 28706f2543Smrg/* 29706f2543Smrg * Authors: 30706f2543Smrg * Rickard E. (Rik) Faith <faith@redhat.com> 31706f2543Smrg * 32706f2543Smrg */ 33706f2543Smrg 34706f2543Smrg/** \file 35706f2543Smrg * 36706f2543Smrg * This code implements a low-level device driver for a USB mouse. */ 37706f2543Smrg 38706f2543Smrg#ifdef HAVE_DMX_CONFIG_H 39706f2543Smrg#include <dmx-config.h> 40706f2543Smrg#endif 41706f2543Smrg 42706f2543Smrg#include "usb-private.h" 43706f2543Smrg 44706f2543Smrg/*****************************************************************************/ 45706f2543Smrg/* Define some macros to make it easier to move this file to another 46706f2543Smrg * part of the Xserver tree. All calls to the dmx* layer are #defined 47706f2543Smrg * here for the .c file. The .h file will also have to be edited. */ 48706f2543Smrg#include "usb-mouse.h" 49706f2543Smrg 50706f2543Smrg#define GETPRIV myPrivate *priv \ 51706f2543Smrg = ((DMXLocalInputInfoPtr)(pDev->devicePrivate))->private 52706f2543Smrg 53706f2543Smrg#define LOG0(f) dmxLog(dmxDebug,f) 54706f2543Smrg#define LOG1(f,a) dmxLog(dmxDebug,f,a) 55706f2543Smrg#define LOG2(f,a,b) dmxLog(dmxDebug,f,a,b) 56706f2543Smrg#define LOG3(f,a,b,c) dmxLog(dmxDebug,f,a,b,c) 57706f2543Smrg#define FATAL0(f) dmxLog(dmxFatal,f) 58706f2543Smrg#define FATAL1(f,a) dmxLog(dmxFatal,f,a) 59706f2543Smrg#define FATAL2(f,a,b) dmxLog(dmxFatal,f,a,b) 60706f2543Smrg#define MOTIONPROC dmxMotionProcPtr 61706f2543Smrg#define ENQUEUEPROC dmxEnqueueProcPtr 62706f2543Smrg#define CHECKPROC dmxCheckSpecialProcPtr 63706f2543Smrg#define BLOCK DMXBlockType 64706f2543Smrg 65706f2543Smrg/* End of interface definitions. */ 66706f2543Smrg/*****************************************************************************/ 67706f2543Smrg 68706f2543Smrg/** Read the USB device using #usbRead. */ 69706f2543Smrgvoid mouUSBRead(DevicePtr pDev, 70706f2543Smrg MOTIONPROC motion, 71706f2543Smrg ENQUEUEPROC enqueue, 72706f2543Smrg CHECKPROC checkspecial, 73706f2543Smrg BLOCK block) 74706f2543Smrg{ 75706f2543Smrg usbRead(pDev, motion, enqueue, BTN_MISC, block); 76706f2543Smrg} 77706f2543Smrg 78706f2543Smrg/** Initialize \a pDev using #usbInit. */ 79706f2543Smrgvoid mouUSBInit(DevicePtr pDev) 80706f2543Smrg{ 81706f2543Smrg usbInit(pDev, usbMouse); 82706f2543Smrg} 83706f2543Smrg 84706f2543Smrg/** Turn \a pDev on (i.e., take input from \a pDev). */ 85706f2543Smrgint mouUSBOn(DevicePtr pDev) 86706f2543Smrg{ 87706f2543Smrg GETPRIV; 88706f2543Smrg 89706f2543Smrg if (priv->fd < 0) mouUSBInit(pDev); 90706f2543Smrg return priv->fd; 91706f2543Smrg} 92706f2543Smrg 93706f2543Smrgstatic void mouUSBGetMap(DevicePtr pDev, unsigned char *map, int *nButtons) 94706f2543Smrg{ 95706f2543Smrg int i; 96706f2543Smrg 97706f2543Smrg if (nButtons) *nButtons = 5; 98706f2543Smrg if (map) for (i = 0; i <= *nButtons; i++) map[i] = i; 99706f2543Smrg} 100706f2543Smrg 101706f2543Smrg/** Fill the \a info structure with information needed to initialize \a 102706f2543Smrg * pDev. */ 103706f2543Smrgvoid mouUSBGetInfo(DevicePtr pDev, DMXLocalInitInfoPtr info) 104706f2543Smrg{ 105706f2543Smrg static KeySym keyboard_mapping = NoSymbol; 106706f2543Smrg 107706f2543Smrg info->buttonClass = 1; 108706f2543Smrg mouUSBGetMap(pDev, info->map, &info->numButtons); 109706f2543Smrg info->valuatorClass = 1; 110706f2543Smrg info->numRelAxes = 2; 111706f2543Smrg info->minval[0] = 0; 112706f2543Smrg info->maxval[0] = 0; 113706f2543Smrg info->res[0] = 1; 114706f2543Smrg info->minres[0] = 0; 115706f2543Smrg info->maxres[0] = 1; 116706f2543Smrg info->ptrFeedbackClass = 1; 117706f2543Smrg 118706f2543Smrg /* Some USB mice devices return key 119706f2543Smrg * events from their pair'd 120706f2543Smrg * keyboard... */ 121706f2543Smrg info->keyClass = 1; 122706f2543Smrg info->keySyms.minKeyCode = 8; 123706f2543Smrg info->keySyms.maxKeyCode = 8; 124706f2543Smrg info->keySyms.mapWidth = 1; 125706f2543Smrg info->keySyms.map = &keyboard_mapping; 126706f2543Smrg} 127