move keymap copy to event processing, from enqueuing

Move the keymap copying to event processing time (in
ProcessInputEvents), instead of being at event enqueuing time.
Break SetCore{Pointer,Keyboard} out into separate functions.
Change mieqEnqueue to take a device pointer, that asks for the
_original_ device associated with this event.
This commit is contained in:
Daniel Stone 2006-10-20 00:30:28 +03:00 committed by Daniel Stone
parent a8d3dad9d9
commit aeba855b07
8 changed files with 129 additions and 165 deletions

View File

@ -481,19 +481,19 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
xv->deviceid = kbp->deviceid; xv->deviceid = kbp->deviceid;
switch (final_valuator - i) { switch (final_valuator - i) {
case 6: case 6:
xv->valuator5 = valuators[i+5]; xv->valuator5 = valuators[i + 5];
case 5: case 5:
xv->valuator4 = valuators[i+4]; xv->valuator4 = valuators[i + 4];
case 4: case 4:
xv->valuator3 = valuators[i+3]; xv->valuator3 = valuators[i + 3];
case 3: case 3:
xv->valuator2 = valuators[i+2]; xv->valuator2 = valuators[i + 2];
case 2: case 2:
/* x and y may have been accelerated. */ /* x and y may have been accelerated. */
if (i == 0) if (i == 0)
xv->valuator1 = kbp->root_y; xv->valuator1 = kbp->root_y;
else else
xv->valuator1 = valuators[i+1]; xv->valuator1 = valuators[i + 1];
case 1: case 1:
/* x and y may have been accelerated. */ /* x and y may have been accelerated. */
if (i == 0) if (i == 0)
@ -520,11 +520,47 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
else { else {
events->u.u.detail = 0; events->u.u.detail = 0;
} }
if (inputInfo.pointer->devPrivates[CoreDevicePrivatesIndex].ptr !=
pDev)
inputInfo.pointer->devPrivates[CoreDevicePrivatesIndex].ptr = pDev;
} }
return num_events; return num_events;
} }
void SwitchCoreKeyboard(DeviceIntPtr pDev)
{
KeyClassPtr ckeyc = inputInfo.keyboard->key;
if (inputInfo.keyboard->devPrivates[CoreDevicePrivatesIndex].ptr != pDev) {
memcpy(ckeyc->modifierMap, pDev->key->modifierMap, MAP_LENGTH);
if (ckeyc->modifierKeyMap)
xfree(ckeyc->modifierKeyMap);
ckeyc->modifierKeyMap = xalloc(8 * pDev->key->maxKeysPerModifier);
memcpy(ckeyc->modifierKeyMap, pDev->key->modifierKeyMap,
(8 * pDev->key->maxKeysPerModifier));
ckeyc->maxKeysPerModifier = pDev->key->maxKeysPerModifier;
ckeyc->curKeySyms.minKeyCode = pDev->key->curKeySyms.minKeyCode;
ckeyc->curKeySyms.maxKeyCode = pDev->key->curKeySyms.maxKeyCode;
SetKeySymsMap(&ckeyc->curKeySyms, &pDev->key->curKeySyms);
#ifdef XKB
if (!noXkbExtension && pDev->key->xkbInfo && pDev->key->xkbInfo->desc) {
if (!XkbCopyKeymap(pDev->key->xkbInfo->desc, ckeyc->xkbInfo->desc,
True))
FatalError("Couldn't pivot keymap from device to core!\n");
}
#endif
SendMappingNotify(MappingKeyboard, ckeyc->curKeySyms.minKeyCode,
(ckeyc->curKeySyms.maxKeyCode -
ckeyc->curKeySyms.minKeyCode),
serverClient);
inputInfo.keyboard->devPrivates[CoreDevicePrivatesIndex].ptr = pDev;
}
}
/* Currently a no-op. */
void SwitchCorePointer(DeviceIntPtr pDev)
{
if (inputInfo.pointer->devPrivates[CoreDevicePrivatesIndex].ptr != pDev)
inputInfo.pointer->devPrivates[CoreDevicePrivatesIndex].ptr = pDev;
}

View File

@ -1656,10 +1656,10 @@ char *kdActionNames[] = {
#endif #endif
static void static void
KdQueueEvent (xEvent *ev) KdQueueEvent (DeviceIntPtr pDev, xEvent *ev)
{ {
KdAssertSigioBlocked ("KdQueueEvent"); KdAssertSigioBlocked ("KdQueueEvent");
mieqEnqueue (ev); mieqEnqueue (pDev, ev);
} }
/* We return true if we're stealing the event. */ /* We return true if we're stealing the event. */
@ -1862,7 +1862,7 @@ KdReleaseAllKeys (void)
KdHandleKeyboardEvent(ki, KeyRelease, key); KdHandleKeyboardEvent(ki, KeyRelease, key);
nEvents = GetKeyboardEvents(kdEvents, ki->dixdev, KeyRelease, key); nEvents = GetKeyboardEvents(kdEvents, ki->dixdev, KeyRelease, key);
for (i = 0; i < nEvents; i++) for (i = 0; i < nEvents; i++)
KdQueueEvent (kdEvents + i); KdQueueEvent (ki->dixdev, kdEvents + i);
} }
} }
} }
@ -1934,7 +1934,7 @@ KdEnqueueKeyboardEvent(KdKeyboardInfo *ki,
ErrorF("KdEnqueueKeyboardEvent: got %d events from GKE\n", nEvents); ErrorF("KdEnqueueKeyboardEvent: got %d events from GKE\n", nEvents);
#endif #endif
for (i = 0; i < nEvents; i++) for (i = 0; i < nEvents; i++)
KdQueueEvent(kdEvents + i); KdQueueEvent(ki->dixdev, kdEvents + i);
} }
else { else {
ErrorF("driver %s wanted to post scancode %d outside of [%d, %d]!\n", ErrorF("driver %s wanted to post scancode %d outside of [%d, %d]!\n",
@ -2052,7 +2052,7 @@ _KdEnqueuePointerEvent (KdPointerInfo *pi, int type, int x, int y, int z,
nEvents = GetPointerEvents(kdEvents, pi->dixdev, type, b, absrel, 0, 3, nEvents = GetPointerEvents(kdEvents, pi->dixdev, type, b, absrel, 0, 3,
valuators); valuators);
for (i = 0; i < nEvents; i++) for (i = 0; i < nEvents; i++)
KdQueueEvent(kdEvents + i); KdQueueEvent(pi->dixdev, kdEvents + i);
} }
void void

View File

@ -909,22 +909,6 @@ DGAVTSwitch(void)
Bool Bool
DGAStealKeyEvent(int index, xEvent *e) DGAStealKeyEvent(int index, xEvent *e)
{ {
DGAScreenPtr pScreenPriv;
dgaEvent de;
if(DGAScreenIndex < 0) /* no DGA */
return FALSE;
pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
if(!pScreenPriv || !pScreenPriv->grabKeyboard) /* no direct mode */
return FALSE;
de.u.u.type = e->u.u.type + *XDGAEventBase;
de.u.u.detail = e->u.u.detail;
de.u.event.time = e->u.keyButtonPointer.time;
mieqEnqueue ((xEvent *) &de);
return TRUE;
} }
static int DGAMouseX, DGAMouseY; static int DGAMouseX, DGAMouseY;
@ -932,36 +916,6 @@ static int DGAMouseX, DGAMouseY;
Bool Bool
DGAStealMouseEvent(int index, xEvent *e, int dx, int dy) DGAStealMouseEvent(int index, xEvent *e, int dx, int dy)
{ {
DGAScreenPtr pScreenPriv;
dgaEvent de;
if(DGAScreenIndex < 0) /* no DGA */
return FALSE;
pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
if(!pScreenPriv || !pScreenPriv->grabMouse) /* no direct mode */
return FALSE;
DGAMouseX += dx;
if (DGAMouseX < 0)
DGAMouseX = 0;
else if (DGAMouseX > screenInfo.screens[index]->width)
DGAMouseX = screenInfo.screens[index]->width;
DGAMouseY += dy;
if (DGAMouseY < 0)
DGAMouseY = 0;
else if (DGAMouseY > screenInfo.screens[index]->height)
DGAMouseY = screenInfo.screens[index]->height;
de.u.u.type = e->u.u.type + *XDGAEventBase;
de.u.u.detail = e->u.u.detail;
de.u.event.time = e->u.keyButtonPointer.time;
de.u.event.dx = dx;
de.u.event.dy = dy;
de.u.event.pad1 = DGAMouseX;
de.u.event.pad2 = DGAMouseY;
mieqEnqueue ((xEvent *) &de);
return TRUE;
} }
Bool Bool

View File

@ -104,19 +104,12 @@ extern Bool noXkbExtension;
#define XE_POINTER 1 #define XE_POINTER 1
#define XE_KEYBOARD 2 #define XE_KEYBOARD 2
#define __EqEnqueue(ev) mieqEnqueue(ev) #define EqEnqueue(pDev, ev) { \
#define EqEnqueue(ev) { \
int __sigstate = xf86BlockSIGIO (); \ int __sigstate = xf86BlockSIGIO (); \
__EqEnqueue (ev); \ mieqEnqueue (pDev, ev); \
xf86UnblockSIGIO(__sigstate); \ xf86UnblockSIGIO(__sigstate); \
} }
#define ENQUEUE(ev, code, direction, dev_type) \
(ev)->u.u.detail = (code); \
(ev)->u.u.type = (direction); \
EqEnqueue((ev))
/* /*
* The first of many hacks to get VT switching to work under * The first of many hacks to get VT switching to work under
* Solaris 2.1 for x86. The basic problem is that Solaris is supposed * Solaris 2.1 for x86. The basic problem is that Solaris is supposed
@ -839,7 +832,7 @@ xf86ReleaseKeys(DeviceIntPtr pDev)
else { else {
nevents = GetKeyboardEvents(xf86Events, pDev, KeyRelease, i); nevents = GetKeyboardEvents(xf86Events, pDev, KeyRelease, i);
for (j = 0; j < nevents; j++) for (j = 0; j < nevents; j++)
mieqEnqueue(xf86Events + i); EqEnqueue(pDev, xf86Events + i);
} }
break; break;
} }

View File

@ -656,20 +656,7 @@ xf86PostMotionEvent(DeviceIntPtr device,
valuators); valuators);
for (i = 0; i < nevents; i++) for (i = 0; i < nevents; i++)
mieqEnqueue(xf86Events + i); mieqEnqueue(device, xf86Events + i);
#if 0
if (HAS_MOTION_HISTORY(local)) {
buff = ((char *)local->motion_history +
(sizeof(INT32) * local->dev->valuator->numAxes + sizeof(Time)) * local->last);
}
if (HAS_MOTION_HISTORY(local)) {
local->last = (local->last + 1) % device->valuator->numMotionEvents;
if (local->last == local->first)
local->first = (local->first + 1) % device->valuator->numMotionEvents;
}
#endif
} }
_X_EXPORT void _X_EXPORT void
@ -795,7 +782,7 @@ xf86PostButtonEvent(DeviceIntPtr device,
first_valuator, num_valuators, valuators); first_valuator, num_valuators, valuators);
for (i = 0; i < nevents; i++) for (i = 0; i < nevents; i++)
mieqEnqueue(xf86Events + i); mieqEnqueue(device, xf86Events + i);
} }
_X_EXPORT void _X_EXPORT void
@ -839,7 +826,7 @@ xf86PostKeyEvent(DeviceIntPtr device,
} }
for (i = 0; i < nevents; i++) for (i = 0; i < nevents; i++)
mieqEnqueue(xf86Events + i); mieqEnqueue(device, xf86Events + i);
} }
_X_EXPORT void _X_EXPORT void
@ -858,7 +845,7 @@ xf86PostKeyboardEvent(DeviceIntPtr device,
is_down ? KeyPress : KeyRelease, key_code); is_down ? KeyPress : KeyRelease, key_code);
for (i = 0; i < nevents; i++) for (i = 0; i < nevents; i++)
mieqEnqueue(xf86Events + i); mieqEnqueue(device, xf86Events + i);
} }
/* /*

View File

@ -406,6 +406,9 @@ extern int GetKeyboardValuatorEvents(
int num_valuator, int num_valuator,
int *valuators); int *valuators);
extern void SwitchCoreKeyboard(DeviceIntPtr pDev);
extern void SwitchCorePointer(DeviceIntPtr pDev);
extern DeviceIntPtr LookupDeviceIntRec( extern DeviceIntPtr LookupDeviceIntRec(
CARD8 deviceid); CARD8 deviceid);

View File

@ -173,6 +173,7 @@ extern Bool mieqInit(
); );
extern void mieqEnqueue( extern void mieqEnqueue(
DeviceIntPtr /*pDev*/,
xEventPtr /*e*/ xEventPtr /*e*/
); );

146
mi/mieq.c
View File

@ -73,14 +73,14 @@ typedef struct _EventQueue {
static EventQueueRec miEventQueue; static EventQueueRec miEventQueue;
Bool Bool
mieqInit () mieqInit()
{ {
miEventQueue.head = miEventQueue.tail = 0; miEventQueue.head = miEventQueue.tail = 0;
miEventQueue.lastEventTime = GetTimeInMillis (); miEventQueue.lastEventTime = GetTimeInMillis ();
miEventQueue.lastMotion = FALSE; miEventQueue.lastMotion = FALSE;
miEventQueue.pEnqueueScreen = screenInfo.screens[0]; miEventQueue.pEnqueueScreen = screenInfo.screens[0];
miEventQueue.pDequeueScreen = miEventQueue.pEnqueueScreen; miEventQueue.pDequeueScreen = miEventQueue.pEnqueueScreen;
SetInputCheck (&miEventQueue.head, &miEventQueue.tail); SetInputCheck(&miEventQueue.head, &miEventQueue.tail);
return TRUE; return TRUE;
} }
@ -92,57 +92,39 @@ mieqInit ()
*/ */
void void
mieqEnqueue (xEvent *e) mieqEnqueue(DeviceIntPtr pDev, xEvent *e)
{ {
HWEventQueueType oldtail = miEventQueue.tail, newtail; HWEventQueueType oldtail = miEventQueue.tail, newtail;
int isMotion = 0; int isMotion = 0;
DeviceIntPtr pDev = NULL;
deviceKeyButtonPointer *kbp = (deviceKeyButtonPointer *) e;
deviceValuator *v = (deviceValuator *) e; deviceValuator *v = (deviceValuator *) e;
EventPtr laste = &miEventQueue.events[oldtail - 1]; EventPtr laste = &miEventQueue.events[oldtail - 1];
deviceKeyButtonPointer *lastkbp = (deviceKeyButtonPointer *) deviceKeyButtonPointer *lastkbp = (deviceKeyButtonPointer *)
&laste->event[0]; &laste->event[0];
if (e->u.u.type == MotionNotify) { if (e->u.u.type == MotionNotify)
pDev = inputInfo.pointer; isMotion = inputInfo.pointer->id;
isMotion = inputInfo.pointer->id & DEVICE_BITS; else if (e->u.u.type == DeviceMotionNotify)
} isMotion = pDev->id;
else if (e->u.u.type == KeyPress || e->u.u.type == KeyRelease) {
pDev = inputInfo.keyboard;
}
else if (e->u.u.type == ButtonPress || e->u.u.type == ButtonRelease) {
pDev = inputInfo.pointer;
}
else {
pDev = LookupDeviceIntRec(kbp->deviceid & DEVICE_BITS);
/* We silently steal valuator events: just tack them on to the last /* We silently steal valuator events: just tack them on to the last
* motion event they need to be attached to. Sigh. */ * motion event they need to be attached to. Sigh. */
if (e->u.u.type == DeviceValuator) { if (e->u.u.type == DeviceValuator) {
if (laste->nevents > 6) { if (laste->nevents > 6) {
ErrorF("mieqEnqueue: more than six valuator events; dropping.\n"); ErrorF("mieqEnqueue: more than six valuator events; dropping.\n");
return;
}
if (oldtail == miEventQueue.head ||
!(lastkbp->type == DeviceMotionNotify ||
lastkbp->type == DeviceButtonPress ||
lastkbp->type == DeviceButtonRelease) ||
((lastkbp->deviceid & DEVICE_BITS) !=
(v->deviceid & DEVICE_BITS))) {
ErrorF("mieqEnequeue: out-of-order valuator event; dropping.\n");
return;
}
memcpy(&(laste->event[laste->nevents++]), e, sizeof(xEvent));
return; return;
} }
else if (e->u.u.type == DeviceMotionNotify) { if (oldtail == miEventQueue.head ||
isMotion = pDev->id & DEVICE_BITS; !(lastkbp->type == DeviceMotionNotify ||
lastkbp->type == DeviceButtonPress ||
lastkbp->type == DeviceButtonRelease) ||
(lastkbp->deviceid != v->deviceid)) {
ErrorF("mieqEnequeue: out-of-order valuator event; dropping.\n");
return;
} }
memcpy(&(laste->event[laste->nevents++]), e, sizeof(xEvent));
return;
} }
if (!pDev)
FatalError("Couldn't find device for event!\n");
if (isMotion && isMotion == miEventQueue.lastMotion && if (isMotion && isMotion == miEventQueue.lastMotion &&
oldtail != miEventQueue.head) { oldtail != miEventQueue.head) {
if (oldtail == 0) if (oldtail == 0)
@ -164,10 +146,8 @@ mieqEnqueue (xEvent *e)
memcpy(&(miEventQueue.events[oldtail].event[0]), e, sizeof(xEvent)); memcpy(&(miEventQueue.events[oldtail].event[0]), e, sizeof(xEvent));
miEventQueue.events[oldtail].nevents = 1; miEventQueue.events[oldtail].nevents = 1;
/* /* Make sure that event times don't go backwards - this
* Make sure that event times don't go backwards - this * is "unnecessary", but very useful. */
* is "unnecessary", but very useful
*/
if (e->u.keyButtonPointer.time < miEventQueue.lastEventTime && if (e->u.keyButtonPointer.time < miEventQueue.lastEventTime &&
miEventQueue.lastEventTime - e->u.keyButtonPointer.time < 10000) miEventQueue.lastEventTime - e->u.keyButtonPointer.time < 10000)
miEventQueue.events[oldtail].event[0].u.keyButtonPointer.time = miEventQueue.events[oldtail].event[0].u.keyButtonPointer.time =
@ -182,49 +162,59 @@ mieqEnqueue (xEvent *e)
} }
void void
mieqSwitchScreen (ScreenPtr pScreen, Bool fromDIX) mieqSwitchScreen(ScreenPtr pScreen, Bool fromDIX)
{ {
miEventQueue.pEnqueueScreen = pScreen; miEventQueue.pEnqueueScreen = pScreen;
if (fromDIX) if (fromDIX)
miEventQueue.pDequeueScreen = pScreen; miEventQueue.pDequeueScreen = pScreen;
} }
/* /* Call this from ProcessInputEvents(). */
* Call this from ProcessInputEvents() void
*/ mieqProcessInputEvents()
void mieqProcessInputEvents ()
{ {
EventRec *e; EventRec *e = NULL;
int x, y; int x = 0, y = 0;
DeviceIntPtr dev = NULL;
while (miEventQueue.head != miEventQueue.tail) while (miEventQueue.head != miEventQueue.tail) {
{ if (screenIsSaved == SCREEN_SAVER_ON)
if (screenIsSaved == SCREEN_SAVER_ON) SaveScreens (SCREEN_SAVER_OFF, ScreenSaverReset);
SaveScreens (SCREEN_SAVER_OFF, ScreenSaverReset);
e = &miEventQueue.events[miEventQueue.head]; e = &miEventQueue.events[miEventQueue.head];
/* /* Assumption - screen switching can only occur on motion events. */
* Assumption - screen switching can only occur on motion events if (e->pScreen != miEventQueue.pDequeueScreen) {
*/ miEventQueue.pDequeueScreen = e->pScreen;
if (e->pScreen != miEventQueue.pDequeueScreen) x = e->event[0].u.keyButtonPointer.rootX;
{ y = e->event[0].u.keyButtonPointer.rootY;
miEventQueue.pDequeueScreen = e->pScreen; if (miEventQueue.head == QUEUE_SIZE - 1)
x = e->event[0].u.keyButtonPointer.rootX; miEventQueue.head = 0;
y = e->event[0].u.keyButtonPointer.rootY; else
if (miEventQueue.head == QUEUE_SIZE - 1) ++miEventQueue.head;
miEventQueue.head = 0; NewCurrentScreen (miEventQueue.pDequeueScreen, x, y);
else }
++miEventQueue.head; else {
NewCurrentScreen (miEventQueue.pDequeueScreen, x, y); if (miEventQueue.head == QUEUE_SIZE - 1)
} miEventQueue.head = 0;
else else
{ ++miEventQueue.head;
if (miEventQueue.head == QUEUE_SIZE - 1)
miEventQueue.head = 0; if (e->event[0].u.u.type == KeyPress ||
else e->event[0].u.u.type == KeyRelease) {
++miEventQueue.head; SwitchCoreKeyboard(e->pDev);
(*e->pDev->public.processInputProc)(e->event, e->pDev, e->nevents); dev = inputInfo.keyboard;
} }
else if (e->event[0].u.u.type == MotionNotify ||
e->event[0].u.u.type == ButtonPress ||
e->event[0].u.u.type == ButtonRelease) {
SwitchCorePointer(e->pDev);
dev = inputInfo.pointer;
}
else {
dev = e->pDev;
}
dev->public.processInputProc(e->event, dev, e->nevents);
}
} }
} }