2
* Copyright 2002 by Brian Goines (bgoines78@comcast.net)
4
* Permission to use, copy, modify, distribute, and sell this software and its
5
* documentation for any purpose is hereby granted without fee, provided that
6
* the above copyright notice appear in all copies and that both that
7
* copyright notice and this permission notice appear in supporting
8
* documentation, and that the name of Brian Goines not be used in
9
* advertising or publicity pertaining to distribution of the software without
10
* specific, written prior permission. Brian Goines makes no
11
* representations about the suitability of this software for any purpose. It
12
* is provided "as is" without express or implied warranty.
14
* BRIAN GOINES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16
* EVENT SHALL FREDERIC LEPIED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20
* PERFORMANCE OF THIS SOFTWARE.
23
/* $XFree86: xc/programs/Xserver/hw/xfree86/input/jamstudio/js_x.c,v 1.2 2002/11/15 16:05:25 tsi Exp $ */
25
#include <sys/types.h>
26
#include "xf86Version.h"
27
#if XF86_VERSION_CURRENT >= XF86_VERSION_NUMERIC(3,9,0,0,0)
32
#include "xf86_ansic.h"
33
#include "xf86_OSproc.h"
34
#include "xf86Xinput.h"
35
#include "exevents.h" /* Needed for InitValuator/Proximity stuff */
36
#include "mipointer.h"
39
#include "xf86Module.h"
42
#define JSX_XCOORD 65584
43
#define JSX_YCOORD 65585
44
#define JSX_PRESS 852016
45
#define JSX_BTN 852034
47
#define SYSCALL(call) while(((call) == -1) && (errno == EINTR))
75
JS_XDevRec, *JS_XDevPtr;
78
xf86JS_XReadInput(LocalDevicePtr local)
80
JS_XDevPtr priv = local->private;
81
struct hiddev_event event;
82
int x = priv->jsxOldX, y = priv->jsxOldY, press = priv->jsxOldPress;
83
int btn = priv->jsxOldBtn, len = 0;
84
int btn_notify = priv->jsxOldNotify;
87
SYSCALL(len = read(local->fd, &event, sizeof(struct hiddev_event)));
88
if (len < sizeof(struct hiddev_event))
91
while ((len = read(local->fd, &event, sizeof(struct hiddev_event)))
92
== sizeof(struct hiddev_event)) {
101
press = event.value / priv->jsxPressDiv;
104
priv->jsxOldBtn = btn = event.value;
109
x = x < priv->jsxMaxX ? x : priv->jsxMaxX;
111
y = y < priv->jsxMaxY ? y : priv->jsxMaxY;
112
press = press > 0 ? press : 0;
113
press = press < priv->jsxPressMax ? press : priv->jsxPressMax;
115
if ((press > priv->jsxPressMin) && (btn == 1))
120
if ((x != priv->jsxOldX) || (y != priv->jsxOldY)
121
|| (press != priv->jsxOldPress)) {
122
xf86PostMotionEvent(local->dev, 1, 0, 3, x, y, press);
125
priv->jsxOldPress = press;
127
if (btn_notify != priv->jsxOldNotify) {
128
xf86PostButtonEvent(local->dev, 0, 1, btn_notify, 0, 3, x, y, press);
129
priv->jsxOldNotify = btn_notify;
134
xf86JS_XConnect(DeviceIntPtr pJS_X)
136
LocalDevicePtr local = (LocalDevicePtr) pJS_X->public.devicePrivate;
137
JS_XDevPtr priv = local->private;
139
local->fd = xf86OpenSerial(local->options);
140
InitValuatorAxisStruct(pJS_X, 0, priv->jsxMinX, priv->jsxMaxX,
141
priv->jsxMaxX / 7.5, 0, priv->jsxMaxX / 7.5);
142
InitValuatorAxisStruct(pJS_X, 1, priv->jsxMinY, priv->jsxMaxY,
143
priv->jsxMaxY / 5.5, 0, priv->jsxMaxY / 5.5);
144
InitValuatorAxisStruct(pJS_X, 2, priv->jsxPressMin, priv->jsxPressMax,
146
return (local->fd > 0);
150
xf86JS_XConvert(LocalDevicePtr local, int first, int num, int v0, int v1,
151
int v2, int v3, int v4, int v5, int *x, int *y)
153
JS_XDevPtr priv = local->private;
157
width = miPointerCurrentScreen()->width;
158
height = miPointerCurrentScreen()->height;
160
deltaX=(float)width/priv->jsxMaxX; deltaY=(float)height/priv->jsxMaxY;
162
deltaX = priv->jsxMaxX / width;
163
deltaY = priv->jsxMaxY / height;
166
xf86XInputSetScreen(local, 0, *x, *y);
171
xf86JS_XControlProc(DeviceIntPtr device, PtrCtrl * ctrl)
177
xf86JS_XProc(DeviceIntPtr pJS_X, int operation)
179
LocalDevicePtr local = (LocalDevicePtr) pJS_X->public.devicePrivate;
180
int nbaxes = 3; /* X Y Pressure */
181
int nbuttons = 1; /* This this is necessary for most apps to work. */
182
CARD8 map[2] = { 0, 1 };
186
if (InitButtonClassDeviceStruct(pJS_X, nbuttons, map) == FALSE)
188
if (InitFocusClassDeviceStruct(pJS_X) == FALSE)
190
if (InitPtrFeedbackClassDeviceStruct(pJS_X, xf86JS_XControlProc) ==
193
if (InitProximityClassDeviceStruct(pJS_X) == FALSE)
195
if (InitValuatorClassDeviceStruct(pJS_X, nbaxes, xf86GetMotionEvents,
197
Absolute | OutOfProximity) == FALSE)
200
xf86MotionHistoryAllocate(local);
201
xf86JS_XConnect(pJS_X);
205
xf86JS_XConnect(pJS_X);
206
xf86AddEnabledDevice(local);
207
pJS_X->public.on = TRUE;
211
xf86RemoveEnabledDevice(local);
214
SYSCALL(close(local->fd));
219
xf86Msg(X_ERROR, "JamStudio: Unhandled operation number %d.\n",
227
xf86JS_XChangeControl(LocalDevicePtr local, xDeviceCtl * control)
233
xf86JS_XSwitchMode(ClientPtr client, DeviceIntPtr dev, int mode)
238
static LocalDevicePtr
239
xf86JS_XAllocate(InputDriverPtr drv)
241
LocalDevicePtr local = xf86AllocateInput(drv, 0);
242
JS_XDevPtr priv = xalloc(sizeof(JS_XDevRec));
244
memset(priv, 0, sizeof(JS_XDevRec));
245
local->name = "JAMSTUDIO";
247
local->device_control = xf86JS_XProc;
248
local->read_input = xf86JS_XReadInput;
249
local->close_proc = NULL;
250
local->control_proc = xf86JS_XChangeControl;
251
local->switch_mode = xf86JS_XSwitchMode;
252
local->conversion_proc = xf86JS_XConvert;
256
local->private = priv;
257
local->type_name = "JamStudio";
258
local->history_size = 0;
259
local->old_x = local->old_y = -1;
262
priv->jsxTimeout = 0;
263
priv->jsxDevice = NULL;
266
priv->jsxOldPress = priv->jsxOldBtn = priv->jsxOldNotify = -1;
267
priv->jsxMaxX = 8000;
268
priv->jsxMaxY = 6000;
271
priv->jsxPressMin = 5;
272
priv->jsxPressMax = 127;
273
priv->jsxPressDiv = 2;
279
xf86JS_XUnInit(InputDriverPtr drv, LocalDevicePtr local, int flags)
281
JS_XDevPtr priv = local->private;
283
xf86JS_XProc(local->dev, DEVICE_CLOSE);
285
xf86DeleteInput(local, 0);
289
xf86JS_XInit(InputDriverPtr drv, IDevPtr dev, int flags)
291
LocalDevicePtr local = NULL;
292
JS_XDevPtr priv = NULL;
295
if ((local = xf86JS_XAllocate(drv)) == NULL) {
296
xf86Msg(X_ERROR, "Could not allocate local device.\n");
299
if (local->private == NULL) {
300
xf86Msg(X_ERROR, "Could not allocate private structure.\n");
304
local->conf_idev = dev;
305
xf86CollectInputOptions(local, NULL, NULL);
306
options = local->options;
307
local->name = dev->identifier;
308
priv = (JS_XDevPtr) local->private;
309
priv->jsxDevice = xf86FindOptionValue(options, "Device");
310
xf86ProcessCommonOptions(local, local->options);
311
if (!priv->jsxDevice) {
312
xf86Msg(X_ERROR, "JamStudio: No Device specified.\n");
315
priv->jsxMaxX = xf86SetIntOption(options, "MaxX", 8000);
316
priv->jsxMaxY = xf86SetIntOption(options, "MaxY", 6000);
317
priv->jsxMinX = xf86SetIntOption(options, "MinX", 0);
318
priv->jsxMinY = xf86SetIntOption(options, "MinY", 0);
319
priv->jsxPressMax = xf86SetIntOption(options, "PressMax", 127);
320
priv->jsxPressMin = xf86SetIntOption(options, "PressMin", 5);
321
priv->jsxPressDiv = xf86SetIntOption(options, "PressDiv", 2);
322
local->flags |= XI86_POINTER_CAPABLE | XI86_CONFIGURED;
326
InputDriverRec JAMSTUDIO =
327
{ 1, "js_x", NULL, xf86JS_XInit, xf86JS_XUnInit, NULL, 0 };
332
xf86JS_XUnplug(pointer p)
338
xf86JS_XPlug(pointer module, pointer options, int *errmaj, int *errmin)
340
xf86AddInputDriver(&JAMSTUDIO, module, 0);
344
static XF86ModuleVersionInfo xf86JS_XVersionRec = {
349
XF86_VERSION_CURRENT,
354
{0, 0, 0, 0} /* signature, to be patched into the file by a tool */
357
XF86ModuleData js_xModuleData = { &xf86JS_XVersionRec,