2003-11-14 16:54:54 +01: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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-09-06 15:20:55 +02:00
|
|
|
#if HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
#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 "inpututils.h"
|
|
|
|
#include "mi.h"
|
|
|
|
#include "mipointer.h"
|
|
|
|
#include "scrnintstr.h"
|
|
|
|
#include <X11/extensions/XI.h>
|
|
|
|
#include <X11/extensions/XIproto.h>
|
|
|
|
#include <X11/extensions/geproto.h>
|
|
|
|
#include "extinit.h"
|
|
|
|
#include "exglobals.h"
|
|
|
|
#include "eventstr.h"
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2007-01-03 21:05:35 +01:00
|
|
|
#ifdef DPMSExtension
|
2012-03-21 20:55:09 +01:00
|
|
|
#include "dpmsproc.h"
|
|
|
|
#include <X11/extensions/dpmsconst.h>
|
2007-01-03 21:05:35 +01:00
|
|
|
#endif
|
|
|
|
|
2011-10-16 07:51:30 +02:00
|
|
|
/* Maximum size should be initial size multiplied by a power of 2 */
|
2013-10-29 17:09:27 +01:00
|
|
|
#define QUEUE_INITIAL_SIZE 512
|
2011-10-18 06:16:37 +02:00
|
|
|
#define QUEUE_RESERVED_SIZE 64
|
2011-10-16 07:51:30 +02:00
|
|
|
#define QUEUE_MAXIMUM_SIZE 4096
|
|
|
|
#define QUEUE_DROP_BACKTRACE_FREQUENCY 100
|
|
|
|
#define QUEUE_DROP_BACKTRACE_MAX 10
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2007-04-26 08:28:50 +02:00
|
|
|
#define EnqueueScreen(dev) dev->spriteInfo->sprite->pEnqueueScreen
|
|
|
|
#define DequeueScreen(dev) dev->spriteInfo->sprite->pDequeueScreen
|
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
typedef struct _Event {
|
2012-03-21 20:55:09 +01:00
|
|
|
InternalEvent *events;
|
|
|
|
ScreenPtr pScreen;
|
|
|
|
DeviceIntPtr pDev; /* device this event _originated_ from */
|
2003-11-14 16:54:54 +01:00
|
|
|
} EventRec, *EventPtr;
|
|
|
|
|
|
|
|
typedef struct _EventQueue {
|
2012-03-21 20:55:09 +01:00
|
|
|
HWEventQueueType head, tail; /* long for SetInputCheck */
|
|
|
|
CARD32 lastEventTime; /* to avoid time running backwards */
|
|
|
|
int lastMotion; /* device ID if last event motion? */
|
|
|
|
EventRec *events; /* our queue as an array */
|
|
|
|
size_t nevents; /* the number of buckets in our queue */
|
|
|
|
size_t dropped; /* counter for number of consecutive dropped events */
|
|
|
|
mieqHandler handlers[128]; /* custom event handler */
|
2003-11-14 16:54:54 +01:00
|
|
|
} EventQueueRec, *EventQueuePtr;
|
|
|
|
|
|
|
|
static EventQueueRec miEventQueue;
|
|
|
|
|
2020-09-16 23:55:17 +02:00
|
|
|
static CallbackListPtr miCallbacksWhenDrained = NULL;
|
|
|
|
|
2011-10-16 07:51:30 +02:00
|
|
|
static size_t
|
2012-03-21 20:55:09 +01:00
|
|
|
mieqNumEnqueued(EventQueuePtr eventQueue)
|
|
|
|
{
|
2011-10-16 07:51:30 +02:00
|
|
|
size_t n_enqueued = 0;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2011-10-16 07:51:30 +02:00
|
|
|
if (eventQueue->nevents) {
|
|
|
|
/* % is not well-defined with negative numbers... sigh */
|
|
|
|
n_enqueued = eventQueue->tail - eventQueue->head + eventQueue->nevents;
|
|
|
|
if (n_enqueued >= eventQueue->nevents)
|
|
|
|
n_enqueued -= eventQueue->nevents;
|
|
|
|
}
|
|
|
|
return n_enqueued;
|
|
|
|
}
|
|
|
|
|
2015-12-09 04:53:36 +01:00
|
|
|
/* Pre-condition: Called with input_lock held */
|
2011-10-16 07:51:30 +02:00
|
|
|
static Bool
|
2012-03-21 20:55:09 +01:00
|
|
|
mieqGrowQueue(EventQueuePtr eventQueue, size_t new_nevents)
|
|
|
|
{
|
2011-10-16 07:51:30 +02:00
|
|
|
size_t i, n_enqueued, first_hunk;
|
|
|
|
EventRec *new_events;
|
|
|
|
|
|
|
|
if (!eventQueue) {
|
|
|
|
ErrorF("[mi] mieqGrowQueue called with a NULL eventQueue\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_nevents <= eventQueue->nevents)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
new_events = calloc(new_nevents, sizeof(EventRec));
|
|
|
|
if (new_events == NULL) {
|
|
|
|
ErrorF("[mi] mieqGrowQueue memory allocation error.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
n_enqueued = mieqNumEnqueued(eventQueue);
|
|
|
|
|
|
|
|
/* First copy the existing events */
|
|
|
|
first_hunk = eventQueue->nevents - eventQueue->head;
|
2019-10-15 19:16:17 +02:00
|
|
|
if (eventQueue->events) {
|
|
|
|
memcpy(new_events,
|
|
|
|
&eventQueue->events[eventQueue->head],
|
|
|
|
first_hunk * sizeof(EventRec));
|
|
|
|
memcpy(&new_events[first_hunk],
|
|
|
|
eventQueue->events, eventQueue->head * sizeof(EventRec));
|
|
|
|
}
|
2011-10-16 07:51:30 +02:00
|
|
|
|
|
|
|
/* Initialize the new portion */
|
|
|
|
for (i = eventQueue->nevents; i < new_nevents; i++) {
|
2012-03-21 20:55:09 +01:00
|
|
|
InternalEvent *evlist = InitEventList(1);
|
|
|
|
|
2011-10-16 07:51:30 +02:00
|
|
|
if (!evlist) {
|
|
|
|
size_t j;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2011-10-16 07:51:30 +02:00
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
FreeEventList(new_events[j].events, 1);
|
|
|
|
free(new_events);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
new_events[i].events = evlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* And update our record */
|
|
|
|
eventQueue->tail = n_enqueued;
|
|
|
|
eventQueue->head = 0;
|
|
|
|
eventQueue->nevents = new_nevents;
|
|
|
|
free(eventQueue->events);
|
|
|
|
eventQueue->events = new_events;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
Bool
|
2007-04-09 23:33:15 +02:00
|
|
|
mieqInit(void)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2011-10-16 07:51:30 +02:00
|
|
|
memset(&miEventQueue, 0, sizeof(miEventQueue));
|
2012-03-21 20:55:09 +01:00
|
|
|
miEventQueue.lastEventTime = GetTimeInMillis();
|
2011-10-16 07:51:30 +02:00
|
|
|
|
2015-12-09 04:53:36 +01:00
|
|
|
input_lock();
|
2012-03-21 20:55:09 +01:00
|
|
|
if (!mieqGrowQueue(&miEventQueue, QUEUE_INITIAL_SIZE))
|
|
|
|
FatalError("Could not allocate event queue.\n");
|
2015-12-09 04:53:36 +01:00
|
|
|
input_unlock();
|
2008-12-01 12:20:48 +01:00
|
|
|
|
2006-10-19 23:30:28 +02:00
|
|
|
SetInputCheck(&miEventQueue.head, &miEventQueue.tail);
|
2003-11-14 16:54:54 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2009-09-18 03:14:31 +02:00
|
|
|
mieqFini(void)
|
2008-04-30 10:27:48 +02:00
|
|
|
{
|
|
|
|
int i;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
for (i = 0; i < miEventQueue.nevents; i++) {
|
|
|
|
if (miEventQueue.events[i].events != NULL) {
|
|
|
|
FreeEventList(miEventQueue.events[i].events, 1);
|
|
|
|
miEventQueue.events[i].events = NULL;
|
|
|
|
}
|
2009-09-18 03:14:31 +02:00
|
|
|
}
|
2011-10-16 07:51:30 +02:00
|
|
|
free(miEventQueue.events);
|
2008-04-30 10:27:48 +02:00
|
|
|
}
|
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
/*
|
|
|
|
* Must be reentrant with ProcessInputEvents. Assumption: mieqEnqueue
|
2015-12-09 04:53:36 +01:00
|
|
|
* will never be interrupted. Must be called with input_lock held
|
2003-11-14 16:54:54 +01:00
|
|
|
*/
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2009-01-30 05:34:02 +01:00
|
|
|
mieqEnqueue(DeviceIntPtr pDev, InternalEvent *e)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
unsigned int oldtail = miEventQueue.tail;
|
|
|
|
InternalEvent *evt;
|
|
|
|
int isMotion = 0;
|
|
|
|
int evlen;
|
|
|
|
Time time;
|
|
|
|
size_t n_enqueued;
|
2007-06-19 09:50:52 +02:00
|
|
|
|
2011-05-05 00:48:19 +02:00
|
|
|
verify_internal_event(e);
|
2009-02-16 07:34:05 +01:00
|
|
|
|
2011-10-18 06:16:37 +02:00
|
|
|
n_enqueued = mieqNumEnqueued(&miEventQueue);
|
|
|
|
|
2006-11-16 05:41:14 +01:00
|
|
|
/* avoid merging events from different devices */
|
2009-05-20 09:02:50 +02:00
|
|
|
if (e->any.type == ET_Motion)
|
2006-11-16 05:41:14 +01:00
|
|
|
isMotion = pDev->id;
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2006-07-20 22:39:54 +02:00
|
|
|
if (isMotion && isMotion == miEventQueue.lastMotion &&
|
|
|
|
oldtail != miEventQueue.head) {
|
2011-10-16 07:51:30 +02:00
|
|
|
oldtail = (oldtail - 1) % miEventQueue.nevents;
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
2015-12-09 04:53:36 +01:00
|
|
|
else if (n_enqueued + 1 == miEventQueue.nevents) {
|
|
|
|
if (!mieqGrowQueue(&miEventQueue, miEventQueue.nevents << 1)) {
|
|
|
|
/* Toss events which come in late. Usually this means your server's
|
2016-06-07 21:52:15 +02:00
|
|
|
* stuck in an infinite loop in the main thread.
|
2015-12-09 04:53:36 +01:00
|
|
|
*/
|
|
|
|
miEventQueue.dropped++;
|
|
|
|
if (miEventQueue.dropped == 1) {
|
|
|
|
ErrorFSigSafe("[mi] EQ overflowing. Additional events will be "
|
|
|
|
"discarded until existing events are processed.\n");
|
|
|
|
xorg_backtrace();
|
|
|
|
ErrorFSigSafe("[mi] These backtraces from mieqEnqueue may point to "
|
|
|
|
"a culprit higher up the stack.\n");
|
|
|
|
ErrorFSigSafe("[mi] mieq is *NOT* the cause. It is a victim.\n");
|
|
|
|
}
|
|
|
|
else if (miEventQueue.dropped % QUEUE_DROP_BACKTRACE_FREQUENCY == 0 &&
|
|
|
|
miEventQueue.dropped / QUEUE_DROP_BACKTRACE_FREQUENCY <=
|
|
|
|
QUEUE_DROP_BACKTRACE_MAX) {
|
|
|
|
ErrorFSigSafe("[mi] EQ overflow continuing. %zu events have been "
|
|
|
|
"dropped.\n", miEventQueue.dropped);
|
|
|
|
if (miEventQueue.dropped / QUEUE_DROP_BACKTRACE_FREQUENCY ==
|
|
|
|
QUEUE_DROP_BACKTRACE_MAX) {
|
|
|
|
ErrorFSigSafe("[mi] No further overflow reports will be "
|
|
|
|
"reported until the clog is cleared.\n");
|
|
|
|
}
|
|
|
|
xorg_backtrace();
|
2009-08-08 19:18:10 +02:00
|
|
|
}
|
2015-12-09 04:53:36 +01:00
|
|
|
return;
|
2011-10-16 07:51:30 +02:00
|
|
|
}
|
2015-12-09 04:53:36 +01:00
|
|
|
oldtail = miEventQueue.tail;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2006-07-20 22:39:54 +02:00
|
|
|
|
2009-05-20 09:02:50 +02:00
|
|
|
evlen = e->any.length;
|
2007-05-02 06:20:09 +02:00
|
|
|
evt = miEventQueue.events[oldtail].events;
|
2011-04-14 14:05:41 +02:00
|
|
|
memcpy(evt, e, evlen);
|
2006-07-20 22:39:54 +02:00
|
|
|
|
2009-05-20 09:02:50 +02:00
|
|
|
time = e->any.time;
|
2006-10-19 23:30:28 +02:00
|
|
|
/* Make sure that event times don't go backwards - this
|
|
|
|
* is "unnecessary", but very useful. */
|
2009-01-30 05:34:02 +01:00
|
|
|
if (time < miEventQueue.lastEventTime &&
|
|
|
|
miEventQueue.lastEventTime - time < 10000)
|
2009-05-20 09:02:50 +02:00
|
|
|
e->any.time = miEventQueue.lastEventTime;
|
2006-09-30 16:05:46 +02:00
|
|
|
|
2011-04-14 14:05:41 +02:00
|
|
|
miEventQueue.lastEventTime = evt->any.time;
|
2009-07-26 05:17:25 +02:00
|
|
|
miEventQueue.events[oldtail].pScreen = pDev ? EnqueueScreen(pDev) : NULL;
|
2006-07-20 22:39:54 +02:00
|
|
|
miEventQueue.events[oldtail].pDev = pDev;
|
|
|
|
|
|
|
|
miEventQueue.lastMotion = isMotion;
|
2011-10-16 07:51:30 +02:00
|
|
|
miEventQueue.tail = (oldtail + 1) % miEventQueue.nevents;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
2011-08-01 01:52:38 +02:00
|
|
|
/**
|
|
|
|
* Changes the screen reference events are being enqueued from.
|
|
|
|
* Input events are enqueued with a screen reference and dequeued and
|
|
|
|
* processed with a (potentially different) screen reference.
|
|
|
|
* This function is called whenever a new event has changed screen but is
|
|
|
|
* still logically on the previous screen as seen by the client.
|
|
|
|
* This usually happens whenever the visible cursor moves across screen
|
|
|
|
* boundaries during event generation, before the same event is processed
|
|
|
|
* and sent down the wire.
|
|
|
|
*
|
|
|
|
* @param pDev The device that triggered a screen change.
|
|
|
|
* @param pScreen The new screen events are being enqueued for.
|
|
|
|
* @param set_dequeue_screen If TRUE, pScreen is set as both enqueue screen
|
|
|
|
* and dequeue screen.
|
|
|
|
*/
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2011-08-01 01:52:38 +02:00
|
|
|
mieqSwitchScreen(DeviceIntPtr pDev, ScreenPtr pScreen, Bool set_dequeue_screen)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2007-04-26 08:28:50 +02:00
|
|
|
EnqueueScreen(pDev) = pScreen;
|
2011-08-01 01:52:38 +02:00
|
|
|
if (set_dequeue_screen)
|
2009-08-08 19:18:10 +02:00
|
|
|
DequeueScreen(pDev) = pScreen;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2007-03-20 23:10:38 +01:00
|
|
|
mieqSetHandler(int event, mieqHandler handler)
|
|
|
|
{
|
2018-08-27 22:34:20 +02:00
|
|
|
if (handler && miEventQueue.handlers[event] != handler)
|
2007-12-07 10:49:43 +01:00
|
|
|
ErrorF("[mi] mieq: warning: overriding existing handler %p with %p for "
|
2007-03-20 23:10:38 +01:00
|
|
|
"event %d\n", miEventQueue.handlers[event], handler, event);
|
|
|
|
|
|
|
|
miEventQueue.handlers[event] = handler;
|
|
|
|
}
|
|
|
|
|
2007-11-08 02:21:03 +01:00
|
|
|
/**
|
|
|
|
* Change the device id of the given event to the given device's id.
|
|
|
|
*/
|
|
|
|
static void
|
2012-03-21 20:55:09 +01:00
|
|
|
ChangeDeviceID(DeviceIntPtr dev, InternalEvent *event)
|
2007-11-08 02:21:03 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
switch (event->any.type) {
|
|
|
|
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:
|
|
|
|
case ET_TouchBegin:
|
|
|
|
case ET_TouchUpdate:
|
|
|
|
case ET_TouchEnd:
|
|
|
|
event->device_event.deviceid = dev->id;
|
|
|
|
break;
|
|
|
|
case ET_TouchOwnership:
|
|
|
|
event->touch_ownership_event.deviceid = dev->id;
|
|
|
|
break;
|
2018-02-18 10:58:34 +01:00
|
|
|
#ifdef XFreeXDGA
|
2012-03-21 20:55:09 +01:00
|
|
|
case ET_DGAEvent:
|
|
|
|
break;
|
2009-06-11 14:15:05 +02:00
|
|
|
#endif
|
2012-03-21 20:55:09 +01:00
|
|
|
case ET_RawKeyPress:
|
|
|
|
case ET_RawKeyRelease:
|
|
|
|
case ET_RawButtonPress:
|
|
|
|
case ET_RawButtonRelease:
|
|
|
|
case ET_RawMotion:
|
|
|
|
case ET_RawTouchBegin:
|
|
|
|
case ET_RawTouchEnd:
|
|
|
|
case ET_RawTouchUpdate:
|
|
|
|
event->raw_event.deviceid = dev->id;
|
|
|
|
break;
|
2012-11-01 21:06:40 +01:00
|
|
|
case ET_BarrierHit:
|
|
|
|
case ET_BarrierLeave:
|
|
|
|
event->barrier_event.deviceid = dev->id;
|
|
|
|
break;
|
2012-03-21 20:55:09 +01:00
|
|
|
default:
|
|
|
|
ErrorF("[mi] Unknown event type (%d), cannot change id.\n",
|
|
|
|
event->any.type);
|
2009-01-30 05:34:02 +01:00
|
|
|
}
|
2007-11-08 02:21:03 +01:00
|
|
|
}
|
|
|
|
|
2009-01-08 02:53:30 +01:00
|
|
|
static void
|
2009-01-30 05:34:02 +01:00
|
|
|
FixUpEventForMaster(DeviceIntPtr mdev, DeviceIntPtr sdev,
|
2012-03-21 20:55:09 +01:00
|
|
|
InternalEvent *original, InternalEvent *master)
|
2009-01-08 02:53:30 +01:00
|
|
|
{
|
2011-05-05 00:48:19 +02:00
|
|
|
verify_internal_event(original);
|
|
|
|
verify_internal_event(master);
|
2009-01-08 02:53:30 +01: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 */
|
2009-05-20 09:02:50 +02:00
|
|
|
if (original->any.type == ET_ButtonPress ||
|
2012-03-21 20:55:09 +01:00
|
|
|
original->any.type == ET_ButtonRelease) {
|
2009-09-18 02:03:02 +02:00
|
|
|
int btn = original->device_event.detail.button;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2009-01-08 02:53:30 +01:00
|
|
|
if (!sdev->button)
|
2012-03-21 20:55:09 +01:00
|
|
|
return; /* Should never happen */
|
2009-01-08 02:53:30 +01:00
|
|
|
|
2009-09-18 02:03:02 +02:00
|
|
|
master->device_event.detail.button = sdev->button->map[btn];
|
2009-01-08 02:53:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-08 02:21:03 +01:00
|
|
|
/**
|
|
|
|
* Copy the given event into master.
|
2009-01-08 02:53:30 +01:00
|
|
|
* @param sdev The slave device the original event comes from
|
2007-11-08 02:21:03 +01:00
|
|
|
* @param original The event as it came from the EQ
|
2009-07-28 08:51:14 +02:00
|
|
|
* @param copy The event after being copied
|
2009-05-20 02:55:03 +02:00
|
|
|
* @return The master device or NULL if the device is a floating slave.
|
2007-11-08 02:21:03 +01:00
|
|
|
*/
|
2009-05-20 02:55:03 +02:00
|
|
|
DeviceIntPtr
|
|
|
|
CopyGetMasterEvent(DeviceIntPtr sdev,
|
2012-03-21 20:55:09 +01:00
|
|
|
InternalEvent *original, InternalEvent *copy)
|
2007-11-08 02:21:03 +01:00
|
|
|
{
|
2009-05-20 02:55:03 +02:00
|
|
|
DeviceIntPtr mdev;
|
2009-05-20 09:02:50 +02:00
|
|
|
int len = original->any.length;
|
2010-09-03 03:54:41 +02:00
|
|
|
int type = original->any.type;
|
2012-03-21 20:55:09 +01:00
|
|
|
int mtype; /* which master type? */
|
2008-12-01 12:20:48 +01:00
|
|
|
|
2011-05-05 00:48:19 +02:00
|
|
|
verify_internal_event(original);
|
2009-02-16 07:34:05 +01:00
|
|
|
|
2009-09-28 02:08:12 +02:00
|
|
|
/* ET_XQuartz has sdev == NULL */
|
2011-02-11 03:47:37 +01:00
|
|
|
if (!sdev || IsMaster(sdev) || IsFloating(sdev))
|
2009-05-20 02:55:03 +02:00
|
|
|
return NULL;
|
|
|
|
|
2018-02-18 10:58:34 +01:00
|
|
|
#ifdef XFreeXDGA
|
2010-09-03 03:54:41 +02:00
|
|
|
if (type == ET_DGAEvent)
|
|
|
|
type = original->dga_event.subtype;
|
|
|
|
#endif
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
switch (type) {
|
|
|
|
case ET_KeyPress:
|
|
|
|
case ET_KeyRelease:
|
|
|
|
mtype = MASTER_KEYBOARD;
|
|
|
|
break;
|
|
|
|
case ET_ButtonPress:
|
|
|
|
case ET_ButtonRelease:
|
|
|
|
case ET_Motion:
|
|
|
|
case ET_ProximityIn:
|
|
|
|
case ET_ProximityOut:
|
|
|
|
mtype = MASTER_POINTER;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mtype = MASTER_ATTACHED;
|
|
|
|
break;
|
2009-05-20 02:55:03 +02:00
|
|
|
}
|
2008-12-01 12:20:48 +01:00
|
|
|
|
2011-02-18 02:45:29 +01:00
|
|
|
mdev = GetMaster(sdev, mtype);
|
2009-07-28 08:51:14 +02:00
|
|
|
memcpy(copy, original, len);
|
|
|
|
ChangeDeviceID(mdev, copy);
|
|
|
|
FixUpEventForMaster(mdev, sdev, original, copy);
|
2009-05-20 02:55:03 +02:00
|
|
|
|
|
|
|
return mdev;
|
2009-01-30 05:34:02 +01:00
|
|
|
}
|
2009-01-08 02:53:30 +01:00
|
|
|
|
2011-12-14 22:57:47 +01:00
|
|
|
static void
|
|
|
|
mieqMoveToNewScreen(DeviceIntPtr dev, ScreenPtr screen, DeviceEvent *event)
|
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
if (dev && screen && screen != DequeueScreen(dev)) {
|
2011-12-14 22:57:47 +01:00
|
|
|
int x = 0, y = 0;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2011-12-14 22:57:47 +01:00
|
|
|
DequeueScreen(dev) = screen;
|
|
|
|
x = event->root_x;
|
|
|
|
y = event->root_y;
|
2012-03-21 20:55:09 +01:00
|
|
|
NewCurrentScreen(dev, DequeueScreen(dev), x, y);
|
2011-12-14 22:57:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-10 03:45:49 +01: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
|
2012-03-21 20:55:09 +01:00
|
|
|
mieqProcessDeviceEvent(DeviceIntPtr dev, InternalEvent *event, ScreenPtr screen)
|
2009-02-10 03:45:49 +01:00
|
|
|
{
|
|
|
|
mieqHandler handler;
|
|
|
|
DeviceIntPtr master;
|
2012-03-21 20:55:09 +01:00
|
|
|
InternalEvent mevent; /* master event */
|
2009-02-10 03:45:49 +01:00
|
|
|
|
2011-05-05 00:48:19 +02:00
|
|
|
verify_internal_event(event);
|
2009-02-16 07:34:05 +01:00
|
|
|
|
2014-05-21 02:07:31 +02:00
|
|
|
/* refuse events from disabled devices */
|
2014-07-20 02:08:09 +02:00
|
|
|
if (dev && !dev->enabled)
|
2014-06-06 05:38:44 +02:00
|
|
|
return;
|
2014-05-21 02:07:31 +02:00
|
|
|
|
2009-02-10 03:45:49 +01:00
|
|
|
/* Custom event handler */
|
2009-05-20 09:02:50 +02:00
|
|
|
handler = miEventQueue.handlers[event->any.type];
|
2009-02-10 03:45:49 +01:00
|
|
|
|
2009-08-05 20:02:29 +02:00
|
|
|
switch (event->any.type) {
|
|
|
|
/* Catch events that include valuator information and check if they
|
|
|
|
* are changing the screen */
|
2012-03-21 20:55:09 +01:00
|
|
|
case ET_Motion:
|
|
|
|
case ET_KeyPress:
|
|
|
|
case ET_KeyRelease:
|
|
|
|
case ET_ButtonPress:
|
|
|
|
case ET_ButtonRelease:
|
|
|
|
if (!handler)
|
|
|
|
mieqMoveToNewScreen(dev, screen, &event->device_event);
|
|
|
|
break;
|
|
|
|
case ET_TouchBegin:
|
|
|
|
case ET_TouchUpdate:
|
|
|
|
case ET_TouchEnd:
|
|
|
|
if (!handler && (event->device_event.flags & TOUCH_POINTER_EMULATED))
|
|
|
|
mieqMoveToNewScreen(dev, screen, &event->device_event);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2009-02-10 03:45:49 +01:00
|
|
|
}
|
2009-08-05 20:02:29 +02:00
|
|
|
master = CopyGetMasterEvent(dev, event, &mevent);
|
2009-02-10 03:45:49 +01:00
|
|
|
|
2009-08-05 20:02:29 +02:00
|
|
|
if (master)
|
2011-02-18 03:28:43 +01:00
|
|
|
master->lastSlave = dev;
|
2009-07-14 13:42:19 +02:00
|
|
|
|
2009-08-05 20:02:29 +02:00
|
|
|
/* If someone's registered a custom event handler, let them
|
|
|
|
* steal it. */
|
2012-03-21 20:55:09 +01:00
|
|
|
if (handler) {
|
|
|
|
int screenNum = dev &&
|
|
|
|
DequeueScreen(dev) ? DequeueScreen(dev)->myNum : (screen ? screen->
|
|
|
|
myNum : 0);
|
2009-08-05 20:02:29 +02:00
|
|
|
handler(screenNum, event, dev);
|
|
|
|
/* Check for the SD's master in case the device got detached
|
|
|
|
* during event processing */
|
2011-02-11 03:47:37 +01:00
|
|
|
if (master && !IsFloating(dev))
|
2009-08-05 20:02:29 +02:00
|
|
|
handler(screenNum, &mevent, master);
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
|
|
|
else {
|
2009-08-05 20:02:29 +02:00
|
|
|
/* process slave first, then master */
|
|
|
|
dev->public.processInputProc(event, dev);
|
2009-02-10 03:45:49 +01:00
|
|
|
|
2009-08-05 20:02:29 +02:00
|
|
|
/* Check for the SD's master in case the device got detached
|
|
|
|
* during event processing */
|
2011-02-11 03:47:37 +01:00
|
|
|
if (master && !IsFloating(dev))
|
2009-08-05 20:02:29 +02:00
|
|
|
master->public.processInputProc(&mevent, master);
|
2009-02-10 03:45:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-19 23:30:28 +02:00
|
|
|
/* Call this from ProcessInputEvents(). */
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2007-04-09 23:33:15 +02:00
|
|
|
mieqProcessInputEvents(void)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2006-10-19 23:30:28 +02:00
|
|
|
EventRec *e = NULL;
|
2008-11-04 05:57:30 +01:00
|
|
|
ScreenPtr screen;
|
2012-06-20 20:52:33 +02:00
|
|
|
InternalEvent event;
|
2012-03-21 20:55:09 +01:00
|
|
|
DeviceIntPtr dev = NULL, master = NULL;
|
2012-06-20 20:52:34 +02:00
|
|
|
static Bool inProcessInputEvents = FALSE;
|
2006-10-19 23:30:28 +02:00
|
|
|
|
2015-12-08 20:37:51 +01:00
|
|
|
input_lock();
|
2011-10-16 07:51:30 +02:00
|
|
|
|
2012-06-20 20:52:34 +02:00
|
|
|
/*
|
|
|
|
* report an error if mieqProcessInputEvents() is called recursively;
|
|
|
|
* this can happen, e.g., if something in the mieqProcessDeviceEvent()
|
|
|
|
* call chain calls UpdateCurrentTime() instead of UpdateCurrentTimeIf()
|
|
|
|
*/
|
|
|
|
BUG_WARN_MSG(inProcessInputEvents, "[mi] mieqProcessInputEvents() called recursively.\n");
|
|
|
|
inProcessInputEvents = TRUE;
|
|
|
|
|
2011-10-16 07:51:30 +02:00
|
|
|
if (miEventQueue.dropped) {
|
2012-03-21 20:55:09 +01:00
|
|
|
ErrorF("[mi] EQ processing has resumed after %lu dropped events.\n",
|
2013-11-15 14:00:29 +01:00
|
|
|
(unsigned long) miEventQueue.dropped);
|
2012-03-21 20:55:09 +01:00
|
|
|
ErrorF
|
2015-07-02 20:16:21 +02:00
|
|
|
("[mi] This may be caused by a misbehaving driver monopolizing the server's resources.\n");
|
2011-10-16 07:51:30 +02:00
|
|
|
miEventQueue.dropped = 0;
|
|
|
|
}
|
|
|
|
|
2006-10-19 23:30:28 +02:00
|
|
|
while (miEventQueue.head != miEventQueue.tail) {
|
|
|
|
e = &miEventQueue.events[miEventQueue.head];
|
2008-11-04 05:57:30 +01:00
|
|
|
|
2011-04-14 14:05:41 +02:00
|
|
|
event = *e->events;
|
2012-03-21 20:55:09 +01:00
|
|
|
dev = e->pDev;
|
|
|
|
screen = e->pScreen;
|
2008-11-04 05:57:30 +01:00
|
|
|
|
2011-10-16 07:51:30 +02:00
|
|
|
miEventQueue.head = (miEventQueue.head + 1) % miEventQueue.nevents;
|
2007-06-11 09:23:18 +02:00
|
|
|
|
2015-12-08 20:37:51 +01:00
|
|
|
input_unlock();
|
2009-02-10 03:45:49 +01:00
|
|
|
|
2011-02-18 02:45:29 +01:00
|
|
|
master = (dev) ? GetMaster(dev, MASTER_ATTACHED) : NULL;
|
2008-11-04 05:57:30 +01:00
|
|
|
|
2008-11-19 19:55:29 +01:00
|
|
|
if (screenIsSaved == SCREEN_SAVER_ON)
|
2012-03-21 20:55:09 +01:00
|
|
|
dixSaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
|
2008-11-19 19:55:29 +01:00
|
|
|
#ifdef DPMSExtension
|
|
|
|
else if (DPMSPowerLevel != DPMSModeOn)
|
|
|
|
SetScreenSaverTimer();
|
|
|
|
|
|
|
|
if (DPMSPowerLevel != DPMSModeOn)
|
|
|
|
DPMSSet(serverClient, DPMSModeOn);
|
|
|
|
#endif
|
|
|
|
|
2011-04-14 14:05:41 +02:00
|
|
|
mieqProcessDeviceEvent(dev, &event, screen);
|
2006-12-18 06:03:54 +01:00
|
|
|
|
|
|
|
/* Update the sprite now. Next event may be from different device. */
|
2012-12-19 18:42:38 +01:00
|
|
|
if (master &&
|
|
|
|
(event.any.type == ET_Motion ||
|
|
|
|
((event.any.type == ET_TouchBegin ||
|
|
|
|
event.any.type == ET_TouchUpdate) &&
|
|
|
|
event.device_event.flags & TOUCH_POINTER_EMULATED)))
|
2008-11-04 05:57:30 +01:00
|
|
|
miPointerUpdateSprite(dev);
|
2009-01-11 10:56:45 +01:00
|
|
|
|
2015-12-08 20:37:51 +01:00
|
|
|
input_lock();
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2012-06-20 20:52:34 +02:00
|
|
|
|
|
|
|
inProcessInputEvents = FALSE;
|
|
|
|
|
2020-09-16 23:55:17 +02:00
|
|
|
CallCallbacks(&miCallbacksWhenDrained, NULL);
|
|
|
|
|
|
|
|
input_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void mieqAddCallbackOnDrained(CallbackProcPtr callback, void *param)
|
|
|
|
{
|
|
|
|
input_lock();
|
|
|
|
AddCallback(&miCallbacksWhenDrained, callback, param);
|
|
|
|
input_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void mieqRemoveCallbackOnDrained(CallbackProcPtr callback, void *param)
|
|
|
|
{
|
|
|
|
input_lock();
|
|
|
|
DeleteCallback(&miCallbacksWhenDrained, callback, param);
|
2015-12-08 20:37:51 +01:00
|
|
|
input_unlock();
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|