2006-11-26 11:13:41 -07:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
Copyright 1990, 1998 The Open Group
|
|
|
|
|
|
|
|
Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
the above copyright notice appear in all copies and that both that
|
|
|
|
copyright notice and this permission notice appear in supporting
|
|
|
|
documentation.
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
Except as contained in this notice, the name of The Open Group shall not be
|
|
|
|
used in advertising or otherwise to promote the sale, use or other dealings
|
|
|
|
in this Software without prior written authorization from The Open Group.
|
|
|
|
*
|
|
|
|
* Author: Keith Packard, MIT X Consortium
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mieq.c
|
|
|
|
*
|
|
|
|
* Machine independent event queue
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
# include <X11/X.h>
|
|
|
|
# include <X11/Xmd.h>
|
|
|
|
# include <X11/Xproto.h>
|
|
|
|
# include "misc.h"
|
|
|
|
# include "windowstr.h"
|
|
|
|
# include "pixmapstr.h"
|
|
|
|
# include "inputstr.h"
|
|
|
|
# include "mi.h"
|
2007-11-24 10:55:21 -07:00
|
|
|
# include "mipointer.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
# include "scrnintstr.h"
|
2007-11-24 10:55:21 -07:00
|
|
|
# include <X11/extensions/XI.h>
|
|
|
|
# include <X11/extensions/XIproto.h>
|
2009-09-06 13:44:18 -06:00
|
|
|
# include <X11/extensions/geproto.h>
|
2007-11-24 10:55:21 -07:00
|
|
|
# include "extinit.h"
|
|
|
|
# include "exglobals.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
# include "eventstr.h"
|
2007-11-24 10:55:21 -07:00
|
|
|
|
|
|
|
#ifdef DPMSExtension
|
|
|
|
# include "dpmsproc.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
# include <X11/extensions/dpmsconst.h>
|
2007-11-24 10:55:21 -07:00
|
|
|
#endif
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
#define QUEUE_SIZE 512
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
#define EnqueueScreen(dev) dev->spriteInfo->sprite->pEnqueueScreen
|
|
|
|
#define DequeueScreen(dev) dev->spriteInfo->sprite->pDequeueScreen
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
typedef struct _Event {
|
2009-09-06 13:44:18 -06:00
|
|
|
EventListPtr events;
|
2007-11-24 10:55:21 -07:00
|
|
|
ScreenPtr pScreen;
|
|
|
|
DeviceIntPtr pDev; /* device this event _originated_ from */
|
2006-11-26 11:13:41 -07:00
|
|
|
} EventRec, *EventPtr;
|
|
|
|
|
|
|
|
typedef struct _EventQueue {
|
2007-11-24 10:55:21 -07:00
|
|
|
HWEventQueueType head, tail; /* long for SetInputCheck */
|
|
|
|
CARD32 lastEventTime; /* to avoid time running backwards */
|
|
|
|
int lastMotion; /* device ID if last event motion? */
|
|
|
|
EventRec events[QUEUE_SIZE]; /* static allocation for signals */
|
|
|
|
mieqHandler handlers[128]; /* custom event handler */
|
2006-11-26 11:13:41 -07:00
|
|
|
} EventQueueRec, *EventQueuePtr;
|
|
|
|
|
|
|
|
static EventQueueRec miEventQueue;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
#ifdef XQUARTZ
|
|
|
|
#include <pthread.h>
|
|
|
|
static pthread_mutex_t miEventQueueMutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
|
|
|
extern BOOL serverInitComplete;
|
|
|
|
extern pthread_mutex_t serverInitCompleteMutex;
|
|
|
|
extern pthread_cond_t serverInitCompleteCond;
|
|
|
|
|
|
|
|
static inline void wait_for_server_init(void) {
|
|
|
|
/* If the server hasn't finished initializing, wait for it... */
|
|
|
|
if(!serverInitComplete) {
|
|
|
|
pthread_mutex_lock(&serverInitCompleteMutex);
|
|
|
|
while(!serverInitComplete)
|
|
|
|
pthread_cond_wait(&serverInitCompleteCond, &serverInitCompleteMutex);
|
|
|
|
pthread_mutex_unlock(&serverInitCompleteMutex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
Bool
|
2007-11-24 10:55:21 -07:00
|
|
|
mieqInit(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2007-11-24 10:55:21 -07:00
|
|
|
int i;
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
miEventQueue.head = miEventQueue.tail = 0;
|
|
|
|
miEventQueue.lastEventTime = GetTimeInMillis ();
|
|
|
|
miEventQueue.lastMotion = FALSE;
|
2007-11-24 10:55:21 -07:00
|
|
|
for (i = 0; i < 128; i++)
|
|
|
|
miEventQueue.handlers[i] = NULL;
|
2009-09-06 13:44:18 -06:00
|
|
|
for (i = 0; i < QUEUE_SIZE; i++)
|
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
if (miEventQueue.events[i].events == NULL) {
|
|
|
|
EventListPtr evlist = InitEventList(1);
|
|
|
|
if (!evlist)
|
|
|
|
FatalError("Could not allocate event queue.\n");
|
|
|
|
miEventQueue.events[i].events = evlist;
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
SetInputCheck(&miEventQueue.head, &miEventQueue.tail);
|
2006-11-26 11:13:41 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
void
|
2010-07-27 13:02:24 -06:00
|
|
|
mieqFini(void)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < QUEUE_SIZE; i++)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
if (miEventQueue.events[i].events != NULL) {
|
|
|
|
FreeEventList(miEventQueue.events[i].events, 1);
|
|
|
|
miEventQueue.events[i].events = NULL;
|
|
|
|
}
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
/*
|
|
|
|
* Must be reentrant with ProcessInputEvents. Assumption: mieqEnqueue
|
|
|
|
* will never be interrupted. If this is called from both signal
|
|
|
|
* handlers and regular code, make sure the signal is suspended when
|
|
|
|
* called from regular code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2010-07-27 13:02:24 -06:00
|
|
|
mieqEnqueue(DeviceIntPtr pDev, InternalEvent *e)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
unsigned int oldtail = miEventQueue.tail;
|
|
|
|
EventListPtr evt;
|
2007-11-24 10:55:21 -07:00
|
|
|
int isMotion = 0;
|
2009-09-06 13:44:18 -06:00
|
|
|
int evlen;
|
2010-07-27 13:02:24 -06:00
|
|
|
Time time;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
#ifdef XQUARTZ
|
|
|
|
wait_for_server_init();
|
|
|
|
pthread_mutex_lock(&miEventQueueMutex);
|
|
|
|
#endif
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
CHECKEVENT(e);
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/* avoid merging events from different devices */
|
2010-07-27 13:02:24 -06:00
|
|
|
if (e->any.type == ET_Motion)
|
2007-11-24 10:55:21 -07:00
|
|
|
isMotion = pDev->id;
|
|
|
|
|
|
|
|
if (isMotion && isMotion == miEventQueue.lastMotion &&
|
|
|
|
oldtail != miEventQueue.head) {
|
2010-07-27 13:02:24 -06:00
|
|
|
oldtail = (oldtail - 1) % QUEUE_SIZE;
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
else {
|
2010-07-27 13:02:24 -06:00
|
|
|
static int stuck = 0;
|
|
|
|
/* Toss events which come in late. Usually this means your server's
|
2007-11-24 10:55:21 -07:00
|
|
|
* stuck in an infinite loop somewhere, but SIGIO is still getting
|
|
|
|
* handled. */
|
2010-07-27 13:02:24 -06:00
|
|
|
if (((oldtail + 1) % QUEUE_SIZE) == miEventQueue.head) {
|
|
|
|
if (!stuck) {
|
|
|
|
ErrorF("[mi] EQ overflowing. The server is probably stuck "
|
|
|
|
"in an infinite loop.\n");
|
|
|
|
xorg_backtrace();
|
|
|
|
stuck = 1;
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
#ifdef XQUARTZ
|
2010-07-27 13:02:24 -06:00
|
|
|
pthread_mutex_unlock(&miEventQueueMutex);
|
2009-09-06 13:44:18 -06:00
|
|
|
#endif
|
2010-07-27 13:02:24 -06:00
|
|
|
return;
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
stuck = 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
evlen = e->any.length;
|
2009-09-06 13:44:18 -06:00
|
|
|
evt = miEventQueue.events[oldtail].events;
|
|
|
|
if (evt->evlen < evlen)
|
|
|
|
{
|
|
|
|
evt->evlen = evlen;
|
|
|
|
evt->event = xrealloc(evt->event, evt->evlen);
|
|
|
|
if (!evt->event)
|
|
|
|
{
|
|
|
|
ErrorF("[mi] Running out of memory. Tossing event.\n");
|
|
|
|
#ifdef XQUARTZ
|
|
|
|
pthread_mutex_unlock(&miEventQueueMutex);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(evt->event, e, evlen);
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
time = e->any.time;
|
2007-11-24 10:55:21 -07:00
|
|
|
/* Make sure that event times don't go backwards - this
|
|
|
|
* is "unnecessary", but very useful. */
|
2010-07-27 13:02:24 -06:00
|
|
|
if (time < miEventQueue.lastEventTime &&
|
|
|
|
miEventQueue.lastEventTime - time < 10000)
|
|
|
|
e->any.time = miEventQueue.lastEventTime;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
miEventQueue.lastEventTime = ((InternalEvent*)evt->event)->any.time;
|
|
|
|
miEventQueue.events[oldtail].pScreen = pDev ? EnqueueScreen(pDev) : NULL;
|
2007-11-24 10:55:21 -07:00
|
|
|
miEventQueue.events[oldtail].pDev = pDev;
|
|
|
|
|
|
|
|
miEventQueue.lastMotion = isMotion;
|
2009-09-06 13:44:18 -06:00
|
|
|
miEventQueue.tail = (oldtail + 1) % QUEUE_SIZE;
|
|
|
|
#ifdef XQUARTZ
|
|
|
|
pthread_mutex_unlock(&miEventQueueMutex);
|
|
|
|
#endif
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-06 13:44:18 -06:00
|
|
|
mieqSwitchScreen(DeviceIntPtr pDev, ScreenPtr pScreen, Bool fromDIX)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
#ifdef XQUARTZ
|
|
|
|
pthread_mutex_lock(&miEventQueueMutex);
|
|
|
|
#endif
|
|
|
|
EnqueueScreen(pDev) = pScreen;
|
2006-11-26 11:13:41 -07:00
|
|
|
if (fromDIX)
|
2010-07-27 13:02:24 -06:00
|
|
|
DequeueScreen(pDev) = pScreen;
|
2009-09-06 13:44:18 -06:00
|
|
|
#ifdef XQUARTZ
|
|
|
|
pthread_mutex_unlock(&miEventQueueMutex);
|
|
|
|
#endif
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
void
|
|
|
|
mieqSetHandler(int event, mieqHandler handler)
|
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
#ifdef XQUARTZ
|
|
|
|
pthread_mutex_lock(&miEventQueueMutex);
|
|
|
|
#endif
|
2007-11-24 10:55:21 -07:00
|
|
|
if (handler && miEventQueue.handlers[event])
|
2009-09-06 13:44:18 -06:00
|
|
|
ErrorF("[mi] mieq: warning: overriding existing handler %p with %p for "
|
2007-11-24 10:55:21 -07:00
|
|
|
"event %d\n", miEventQueue.handlers[event], handler, event);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
miEventQueue.handlers[event] = handler;
|
2009-09-06 13:44:18 -06:00
|
|
|
#ifdef XQUARTZ
|
|
|
|
pthread_mutex_unlock(&miEventQueueMutex);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the device id of the given event to the given device's id.
|
|
|
|
*/
|
|
|
|
static void
|
2010-07-27 13:02:24 -06:00
|
|
|
ChangeDeviceID(DeviceIntPtr dev, InternalEvent* event)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
switch(event->any.type)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
case ET_Motion:
|
|
|
|
case ET_KeyPress:
|
|
|
|
case ET_KeyRelease:
|
|
|
|
case ET_ButtonPress:
|
|
|
|
case ET_ButtonRelease:
|
|
|
|
case ET_ProximityIn:
|
|
|
|
case ET_ProximityOut:
|
|
|
|
case ET_Hierarchy:
|
|
|
|
case ET_DeviceChanged:
|
|
|
|
event->device_event.deviceid = dev->id;
|
|
|
|
break;
|
|
|
|
#if XFreeXDGA
|
|
|
|
case ET_DGAEvent:
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case ET_RawKeyPress:
|
|
|
|
case ET_RawKeyRelease:
|
|
|
|
case ET_RawButtonPress:
|
|
|
|
case ET_RawButtonRelease:
|
|
|
|
case ET_RawMotion:
|
|
|
|
event->raw_event.deviceid = dev->id;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ErrorF("[mi] Unknown event type (%d), cannot change id.\n",
|
|
|
|
event->any.type);
|
|
|
|
}
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
static void
|
2010-07-27 13:02:24 -06:00
|
|
|
FixUpEventForMaster(DeviceIntPtr mdev, DeviceIntPtr sdev,
|
|
|
|
InternalEvent* original, InternalEvent *master)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
CHECKEVENT(original);
|
|
|
|
CHECKEVENT(master);
|
2009-09-06 13:44:18 -06:00
|
|
|
/* Ensure chained button mappings, i.e. that the detail field is the
|
|
|
|
* value of the mapped button on the SD, not the physical button */
|
2010-07-27 13:02:24 -06:00
|
|
|
if (original->any.type == ET_ButtonPress ||
|
|
|
|
original->any.type == ET_ButtonRelease)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
int btn = original->device_event.detail.button;
|
2009-09-06 13:44:18 -06:00
|
|
|
if (!sdev->button)
|
|
|
|
return; /* Should never happen */
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
master->device_event.detail.button = sdev->button->map[btn];
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy the given event into master.
|
|
|
|
* @param sdev The slave device the original event comes from
|
|
|
|
* @param original The event as it came from the EQ
|
2010-07-27 13:02:24 -06:00
|
|
|
* @param copy The event after being copied
|
|
|
|
* @return The master device or NULL if the device is a floating slave.
|
2009-09-06 13:44:18 -06:00
|
|
|
*/
|
2010-07-27 13:02:24 -06:00
|
|
|
DeviceIntPtr
|
|
|
|
CopyGetMasterEvent(DeviceIntPtr sdev,
|
|
|
|
InternalEvent* original, InternalEvent *copy)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
DeviceIntPtr mdev;
|
|
|
|
int len = original->any.length;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
CHECKEVENT(original);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/* ET_XQuartz has sdev == NULL */
|
|
|
|
if (!sdev || !sdev->u.master)
|
|
|
|
return NULL;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
switch(original->any.type)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
case ET_KeyPress:
|
|
|
|
case ET_KeyRelease:
|
|
|
|
mdev = GetMaster(sdev, MASTER_KEYBOARD);
|
|
|
|
break;
|
|
|
|
case ET_ButtonPress:
|
|
|
|
case ET_ButtonRelease:
|
|
|
|
case ET_Motion:
|
|
|
|
case ET_ProximityIn:
|
|
|
|
case ET_ProximityOut:
|
|
|
|
mdev = GetMaster(sdev, MASTER_POINTER);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mdev = sdev->u.master;
|
|
|
|
break;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
memcpy(copy, original, len);
|
|
|
|
ChangeDeviceID(mdev, copy);
|
|
|
|
FixUpEventForMaster(mdev, sdev, original, copy);
|
|
|
|
|
|
|
|
return mdev;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/**
|
|
|
|
* Post the given @event through the device hierarchy, as appropriate.
|
|
|
|
* Use this function if an event must be posted for a given device during the
|
|
|
|
* usual event processing cycle.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
mieqProcessDeviceEvent(DeviceIntPtr dev,
|
|
|
|
InternalEvent *event,
|
|
|
|
ScreenPtr screen)
|
|
|
|
{
|
|
|
|
mieqHandler handler;
|
|
|
|
int x = 0, y = 0;
|
|
|
|
DeviceIntPtr master;
|
|
|
|
InternalEvent mevent; /* master event */
|
|
|
|
|
|
|
|
CHECKEVENT(event);
|
|
|
|
|
|
|
|
/* Custom event handler */
|
|
|
|
handler = miEventQueue.handlers[event->any.type];
|
|
|
|
|
|
|
|
switch (event->any.type) {
|
|
|
|
/* Catch events that include valuator information and check if they
|
|
|
|
* are changing the screen */
|
|
|
|
case ET_Motion:
|
|
|
|
case ET_KeyPress:
|
|
|
|
case ET_KeyRelease:
|
|
|
|
case ET_ButtonPress:
|
|
|
|
case ET_ButtonRelease:
|
|
|
|
if (dev && screen && screen != DequeueScreen(dev) && !handler) {
|
|
|
|
DequeueScreen(dev) = screen;
|
|
|
|
x = event->device_event.root_x;
|
|
|
|
y = event->device_event.root_y;
|
|
|
|
NewCurrentScreen (dev, DequeueScreen(dev), x, y);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
master = CopyGetMasterEvent(dev, event, &mevent);
|
|
|
|
|
|
|
|
if (master)
|
|
|
|
master->u.lastSlave = dev;
|
|
|
|
|
|
|
|
/* If someone's registered a custom event handler, let them
|
|
|
|
* steal it. */
|
|
|
|
if (handler)
|
|
|
|
{
|
|
|
|
int screenNum = dev && DequeueScreen(dev) ? DequeueScreen(dev)->myNum : (screen ? screen->myNum : 0);
|
|
|
|
handler(screenNum, event, dev);
|
|
|
|
/* Check for the SD's master in case the device got detached
|
|
|
|
* during event processing */
|
|
|
|
if (master && dev->u.master)
|
|
|
|
handler(screenNum, &mevent, master);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
/* process slave first, then master */
|
|
|
|
dev->public.processInputProc(event, dev);
|
|
|
|
|
|
|
|
/* Check for the SD's master in case the device got detached
|
|
|
|
* during event processing */
|
|
|
|
if (master && dev->u.master)
|
|
|
|
master->public.processInputProc(&mevent, master);
|
|
|
|
}
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
/* Call this from ProcessInputEvents(). */
|
|
|
|
void
|
|
|
|
mieqProcessInputEvents(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2007-11-24 10:55:21 -07:00
|
|
|
EventRec *e = NULL;
|
2010-07-27 13:02:24 -06:00
|
|
|
int evlen;
|
2009-09-06 13:44:18 -06:00
|
|
|
ScreenPtr screen;
|
2010-07-27 13:02:24 -06:00
|
|
|
static InternalEvent *event = NULL;
|
2009-09-06 13:44:18 -06:00
|
|
|
static size_t event_size = 0;
|
|
|
|
DeviceIntPtr dev = NULL,
|
|
|
|
master = NULL;
|
|
|
|
|
|
|
|
#ifdef XQUARTZ
|
|
|
|
pthread_mutex_lock(&miEventQueueMutex);
|
|
|
|
#endif
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
while (miEventQueue.head != miEventQueue.tail) {
|
2009-09-06 13:44:18 -06:00
|
|
|
e = &miEventQueue.events[miEventQueue.head];
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
evlen = e->events->evlen;
|
|
|
|
if(evlen > event_size)
|
|
|
|
event = xrealloc(event, evlen);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
if (!event)
|
|
|
|
FatalError("[mi] No memory left for event processing.\n");
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
memcpy(event, e->events->event, evlen);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
|
|
|
|
dev = e->pDev;
|
|
|
|
screen = e->pScreen;
|
|
|
|
|
|
|
|
miEventQueue.head = (miEventQueue.head + 1) % QUEUE_SIZE;
|
|
|
|
|
|
|
|
#ifdef XQUARTZ
|
|
|
|
pthread_mutex_unlock(&miEventQueueMutex);
|
|
|
|
#endif
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
master = (dev && !IsMaster(dev) && dev->u.master) ? dev->u.master : NULL;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
if (screenIsSaved == SCREEN_SAVER_ON)
|
2008-11-02 08:26:08 -07:00
|
|
|
dixSaveScreens (serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
|
2007-11-24 10:55:21 -07:00
|
|
|
#ifdef DPMSExtension
|
|
|
|
else if (DPMSPowerLevel != DPMSModeOn)
|
|
|
|
SetScreenSaverTimer();
|
|
|
|
|
|
|
|
if (DPMSPowerLevel != DPMSModeOn)
|
2008-11-02 08:26:08 -07:00
|
|
|
DPMSSet(serverClient, DPMSModeOn);
|
2007-11-24 10:55:21 -07:00
|
|
|
#endif
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
mieqProcessDeviceEvent(dev, event, screen);
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/* Update the sprite now. Next event may be from different device. */
|
2010-07-27 13:02:24 -06:00
|
|
|
if (event->any.type == ET_Motion && master)
|
2009-09-06 13:44:18 -06:00
|
|
|
miPointerUpdateSprite(dev);
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
#ifdef XQUARTZ
|
|
|
|
pthread_mutex_lock(&miEventQueueMutex);
|
|
|
|
#endif
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
#ifdef XQUARTZ
|
|
|
|
pthread_mutex_unlock(&miEventQueueMutex);
|
|
|
|
#endif
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|