1 /* darwin-input.c -- code to manage the input event queue
2 $Id: darwin-input.c,v 1.4 2002/12/13 00:22:51 jharper Exp $ */
5 * Copyright (c) 2001-2002 Torrey T. Lyons. All Rights Reserved.
6 * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * Except as contained in this notice, the name(s) of the above copyright
27 * holders shall not be used in advertising or otherwise to promote the sale,
28 * use or other dealings in this Software without prior written authorization.
33 #include "mipointer.h" // mi software cursor
37 #define QUEUE_SIZE 256
40 pthread_mutex_t mutex;
42 /* DIX looks at these two integer values, when they're equal
43 it won't call ProcessInputEvents (). */
44 HWEventQueueType head, tail;
46 xEvent events[QUEUE_SIZE];
49 /* fd[0] = reading, fd[1] = writing */
50 static int event_fd[2];
53 DarwinEnqueueEvent (const xEvent *e)
56 int need_write = FALSE;
58 pthread_mutex_lock (&event_queue.mutex);
60 oldtail = (event_queue.tail - 1) % QUEUE_SIZE;
62 if (e->u.u.type == MotionNotify
63 && event_queue.tail != event_queue.head
64 && event_queue.events[oldtail].u.u.type == MotionNotify)
66 /* Two adjacent motion notify events. Coalesce them. */
68 memcpy (&event_queue.events[oldtail], e, sizeof (xEvent));
72 newtail = (event_queue.tail + 1) % QUEUE_SIZE;
74 if (newtail != event_queue.head)
76 memcpy (&event_queue.events[event_queue.tail], e, sizeof (xEvent));
77 event_queue.tail = newtail;
82 pthread_mutex_unlock (&event_queue.mutex);
85 write (event_fd[1], &need_write, sizeof (need_write));
89 DarwinDequeueEvent (xEvent *e)
94 pthread_mutex_lock (&event_queue.mutex);
96 if (event_queue.head != event_queue.tail)
98 memcpy (e, &event_queue.events[event_queue.head], sizeof (xEvent));
99 event_queue.head = (event_queue.head + 1) % QUEUE_SIZE;
103 pthread_mutex_unlock (&event_queue.mutex);
106 read (event_fd[0], &unused, sizeof (unused));
112 DarwinInputPreInit (void)
114 if (pipe (event_fd) != 0)
120 event_queue.head = event_queue.tail = 0;
121 pthread_mutex_init (&event_queue.mutex, NULL);
125 DarwinInputInit (void)
127 SetInputCheck (&event_queue.head, &event_queue.tail);
132 =============================================================================
134 mouse and keyboard callbacks
136 =============================================================================
140 * DarwinChangePointerControl
141 * Set mouse acceleration and thresholding
142 * FIXME: We currently ignore the threshold in ctrl->threshold.
144 static void DarwinChangePointerControl(DeviceIntPtr device, PtrCtrl *ctrl)
146 /* do nothing here */
152 * Handle the initialization, etc. of a mouse
155 int DarwinMouseProc(DeviceIntPtr pPointer, int what)
162 pPointer->public.on = FALSE;
170 InitPointerDeviceStruct( (DevicePtr)pPointer,
172 5, // numbuttons (4 & 5 are scroll wheel)
173 miPointerGetMotionEvents,
174 DarwinChangePointerControl,
179 pPointer->public.on = TRUE;
180 AddEnabledDevice(event_fd[0]);
185 pPointer->public.on = FALSE;
186 RemoveEnabledDevice(event_fd[0]);
197 int DarwinKeybdProc(DeviceIntPtr pDev, int onoff)
201 DarwinKeyboardInit( pDev );
204 pDev->public.on = TRUE;
205 AddEnabledDevice(event_fd[0]);
208 pDev->public.on = FALSE;
209 RemoveEnabledDevice(event_fd[0]);