1
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_mouse.c,v 3.17 2002/05/31 18:46:02 dawes Exp $ */
3
* (c) Copyright 1994,1999,2000 by Holger Veit
5
* Modified (c) 1996 Sebastien Marineau <marineau@genie.uottawa.ca>
7
* Permission is hereby granted, free of charge, to any person obtaining a
8
* copy of this software and associated documentation files (the "Software"),
9
* to deal in the Software without restriction, including without limitation
10
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
11
* and/or sell copies of the Software, and to permit persons to whom the
12
* Software is furnished to do so, subject to the following conditions:
14
* The above copyright notice and this permission notice shall be included in
15
* all copies or substantial portions of the Software.
17
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
* HOLGER VEIT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
* Except as contained in this notice, the name of Holger Veit shall not be
26
* used in advertising or otherwise to promote the sale, use or other dealings
27
* in this Software without prior written authorization from Holger Veit.
30
/* $XConsortium: os2_mouse.c /main/10 1996/10/27 11:48:51 kaleb $ */
38
#include "scrnintstr.h"
42
#define INCL_DOSFILEMGR
43
#define INCL_DOSQUEUES
48
#include "xf86_OSlib.h"
49
#include "xf86Config.h"
51
#include "xf86Xinput.h"
52
#include "xf86OSmouse.h"
53
#include "mipointer.h"
56
SupportedInterfaces(void)
61
static const char* internalNames[] = {
73
CheckProtocol(const char *protocol)
77
for (i = 0; internalNames[i]; i++)
78
if (xf86NameCmp(protocol, internalNames[i]) == 0)
90
SetupAuto(InputInfoPtr pInfo, int *protoPara)
98
InputInfoPtr iinfoPtr;
100
BOOL HandleValid=FALSE;
101
extern BOOL SwitchedToWPS;
102
extern CARD32 LastSwitchTime;
103
void os2MouseEventThread(void* arg);
106
os2MouseReadInput(InputInfoPtr pInfo)
109
ULONG postCount,dataLength;
115
REQUESTDATA requestData;
117
MouseDevPtr pMse = pInfo->private;
119
if (!HandleValid) return;
120
while((rc = DosReadQueue(hMouseQueue,
121
&requestData,&dataLength,&dummy,
122
0L,1L,&elemPriority,hMouseSem)) == 0) {
123
dx = requestData.ulData;
124
(void)DosReadQueue(hMouseQueue,
125
&requestData,&dataLength,&dummy,
126
0L,1L,&elemPriority,hMouseSem);
127
dy = requestData.ulData;
128
(void)DosReadQueue(hMouseQueue,
129
&requestData,&dataLength,&dummy,
130
0L,1L,&elemPriority,hMouseSem);
131
state = requestData.ulData;
132
(void)DosReadQueue(hMouseQueue,
133
&requestData,&dataLength,&dummy,
134
0L,1L,&elemPriority,hMouseSem);
135
if (requestData.ulData != 0xFFFFFFFF)
137
"Unexpected mouse event tag, %d\n",
140
/* Contrary to other systems, OS/2 has mouse buttons *
141
* in the proper order, so we reverse them before *
142
* sending the event. */
144
buttons = ((state & 0x06) ? 4 : 0) |
145
((state & 0x18) ? 1 : 0) |
146
((state & 0x60) ? 2 : 0);
147
pMse->PostEvent(pInfo, buttons, dx, dy, 0, 0);
149
DosResetEventSem(hMouseSem,&postCount);
152
int os2MouseProc(DeviceIntPtr pPointer, int what)
155
USHORT nbuttons, state;
156
unsigned char map[MSE_MAXBUTTONS + 1];
159
InputInfoPtr pInfo = pPointer->public.devicePrivate;
160
MouseDevPtr pMse = pInfo->private;
161
pMse->device = pPointer;
165
pPointer->public.on = FALSE;
167
rc = MouOpen((PSZ)0, &hMouse);
169
xf86Msg(X_WARNING,"%s: cannot open mouse, rc=%d\n",
174
/* flush mouse queue */
178
rc = MouGetNumButtons(&nbuttons, hMouse);
180
xf86Msg(X_INFO,"%s: Mouse has %d button(s).\n",
181
pInfo->name,nbuttons);
182
if (nbuttons==2) nbuttons++;
184
for (i = 1; i<=nbuttons; i++)
187
InitPointerDeviceStruct((DevicePtr)pPointer, map, nbuttons,
188
miPointerGetMotionEvents, pMse->Ctrl,
189
miPointerGetMotionBufferSize());
192
xf86InitValuatorAxisStruct(pPointer, 0, 0, -1, 1, 0, 1);
193
xf86InitValuatorDefaults(pPointer, 0);
195
InitValuatorAxisStruct(pPointer, 1, 0, -1, 1, 0, 1);
196
xf86InitValuatorDefaults(pPointer, 1);
197
xf86MotionHistoryAllocate(pInfo);
199
/* OK, we are ready to start up the mouse thread ! */
201
rc = DosCreateEventSem(NULL,&hMouseSem,DC_SEM_SHARED,TRUE);
203
xf86Msg(X_ERROR,"%s: could not create mouse queue semaphore, rc=%d\n",
205
MouseTid = _beginthread(os2MouseEventThread,NULL,0x4000,(void *)pInfo);
207
"%s: Started Mouse event thread, Tid=%d\n",
208
pInfo->name, MouseTid);
209
DosSetPriority(2,3,0,MouseTid);
216
if (!HandleValid) return -1;
217
pMse->lastButtons = 0;
218
pMse->emulateState = 0;
219
pPointer->public.on = TRUE;
221
rc = MouSetDevStatus(&state,hMouse);
223
rc = MouSetEventMask(&state,hMouse);
229
if (!HandleValid) return -1;
230
pPointer->public.on = FALSE;
232
MouSetDevStatus(&state,hMouse);
234
MouSetEventMask(&state,hMouse);
235
if (what == DEVICE_CLOSE) {
236
/* Comment out for now as this seems to break server */
249
int os2MouseQueueQuery()
251
/* Now we check for activity on mouse handles */
252
ULONG numElements,postCount;
254
if (!HandleValid) return(1);
255
DosResetEventSem(hMouseSem,&postCount);
256
(void)DosQueryQueue(hMouseQueue,&numElements);
257
if (numElements>0) { /* Something in mouse queue! */
258
return 0; /* Will this work? */
263
void os2MouseEventThread(void *arg)
272
iinfoPtr = (InputInfoPtr)arg;
273
pMse = iinfoPtr->private;
275
sprintf(queueName,"\\QUEUES\\XF86MOU\\%d",getpid());
276
rc = DosCreateQueue(&hMouseQueue,0L,queueName);
277
xf86Msg(X_INFO,"Mouse Queue created, rc=%d\n",rc);
278
(void)DosPurgeQueue(hMouseQueue);
282
rc = MouReadEventQue(&mev,&waitflg,hMouse);
285
"Bad return code from mouse driver, rc=%d\n",
287
xf86Msg(X_ERROR,"Mouse aborting!\n");
291
queueParam = mev.col;
292
if ((rc = DosWriteQueue(hMouseQueue,queueParam,0L,NULL,0L)))
294
queueParam = mev.row;
295
if ((rc = DosWriteQueue(hMouseQueue,queueParam,0L,NULL,0L)))
298
if ((rc = DosWriteQueue(hMouseQueue,queueParam,0L,NULL,0L)))
300
queueParam = 0xFFFFFFFF;
301
if ((rc = DosWriteQueue(hMouseQueue,queueParam,0L,NULL,0L)))
305
"An unrecoverable error in mouse queue has occured, rc=%d. Mouse is shutting down.\n",
307
DosCloseQueue(hMouseQueue);
312
os2MousePreInit(InputInfoPtr pInfo, const char* protocol, int flags)
314
MouseDevPtr pMse = pInfo->private;
316
pMse->protocol = protocol;
317
xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, protocol);
319
/* Collect the options, and process the common options. */
320
xf86CollectInputOptions(pInfo, NULL, NULL);
321
xf86ProcessCommonOptions(pInfo, pInfo->options);
323
/* Process common mouse options (like Emulate3Buttons, etc). */
324
pMse->CommonOptions(pInfo);
326
/* Setup the local procs. */
327
pInfo->device_control = os2MouseProc;
328
pInfo->read_input = os2MouseReadInput;
330
pInfo->flags |= XI86_CONFIGURED;
335
xf86OSMouseInit(int flags)
339
p = xcalloc(sizeof(OSMouseInfoRec), 1);
342
p->SupportedInterfaces = SupportedInterfaces;
343
p->BuiltinNames = BuiltinNames;
344
p->DefaultProtocol = DefaultProtocol;
345
p->CheckProtocol = CheckProtocol;
346
p->PreInit = os2MousePreInit;
347
p->SetupAuto = SetupAuto;
351
void xf86OsMouseEvents()
354
ULONG postCount,dataLength;
360
REQUESTDATA requestData;
362
MouseDevPtr pMse = iinfoPtr->private;
364
if (!HandleValid) return;
365
while((rc = DosReadQueue(hMouseQueue,
366
&requestData,&dataLength,&dummy,
367
0L,1L,&elemPriority,hMouseSem)) == 0) {
368
dx = requestData.ulData;
369
(void)DosReadQueue(hMouseQueue,
370
&requestData,&dataLength,&dummy,
371
0L,1L,&elemPriority,hMouseSem);
372
dy = requestData.ulData;
373
(void)DosReadQueue(hMouseQueue,
374
&requestData,&dataLength,&dummy,
375
0L,1L,&elemPriority,hMouseSem);
376
state = requestData.ulData;
377
(void)DosReadQueue(hMouseQueue,
378
&requestData,&dataLength,&dummy,
379
0L,1L,&elemPriority,hMouseSem);
380
if (requestData.ulData != 0xFFFFFFFF)
382
"Unexpected mouse event tag, %d\n",
385
/* Contrary to other systems, OS/2 has mouse buttons *
386
* in the proper order, so we reverse them before *
387
* sending the event. */
389
buttons = ((state & 0x06) ? 4 : 0) |
390
((state & 0x18) ? 1 : 0) |
391
((state & 0x60) ? 2 : 0);
392
pMse->PostEvent(iinfoPtr, buttons, dx, dy, 0, 0);
394
DosResetEventSem(hMouseSem,&postCount);