add virtual core devices to DIX

Add virtual core devices, with proper keymaps etc, to the DIX.
This commit is contained in:
Daniel Stone 2006-07-20 16:39:54 -04:00 committed by Daniel Stone
parent 737e6e4836
commit 1987af8c49
9 changed files with 414 additions and 152 deletions

View File

@ -80,6 +80,13 @@ SOFTWARE.
#include "swaprep.h" #include "swaprep.h"
#include "dixevents.h" #include "dixevents.h"
#ifdef XINPUT
#include <X11/extensions/XIproto.h>
#include "exglobals.h"
#endif
int CoreDevicePrivatesIndex = 0, CoreDevicePrivatesGeneration = -1;
DeviceIntPtr DeviceIntPtr
AddInputDevice(DeviceProc deviceProc, Bool autoStart) AddInputDevice(DeviceProc deviceProc, Bool autoStart)
{ {
@ -87,7 +94,7 @@ AddInputDevice(DeviceProc deviceProc, Bool autoStart)
if (inputInfo.numDevices >= MAX_DEVICES) if (inputInfo.numDevices >= MAX_DEVICES)
return (DeviceIntPtr)NULL; return (DeviceIntPtr)NULL;
dev = (DeviceIntPtr) xalloc(sizeof(DeviceIntRec)); dev = (DeviceIntPtr) xcalloc(sizeof(DeviceIntRec), 1);
if (!dev) if (!dev)
return (DeviceIntPtr)NULL; return (DeviceIntPtr)NULL;
dev->name = (char *)NULL; dev->name = (char *)NULL;
@ -113,19 +120,21 @@ AddInputDevice(DeviceProc deviceProc, Bool autoStart)
dev->button = (ButtonClassPtr)NULL; dev->button = (ButtonClassPtr)NULL;
dev->focus = (FocusClassPtr)NULL; dev->focus = (FocusClassPtr)NULL;
dev->proximity = (ProximityClassPtr)NULL; dev->proximity = (ProximityClassPtr)NULL;
dev->touchscreen = (TouchscreenClassPtr)NULL;
dev->kbdfeed = (KbdFeedbackPtr)NULL; dev->kbdfeed = (KbdFeedbackPtr)NULL;
dev->ptrfeed = (PtrFeedbackPtr)NULL; dev->ptrfeed = (PtrFeedbackPtr)NULL;
dev->intfeed = (IntegerFeedbackPtr)NULL; dev->intfeed = (IntegerFeedbackPtr)NULL;
dev->stringfeed = (StringFeedbackPtr)NULL; dev->stringfeed = (StringFeedbackPtr)NULL;
dev->bell = (BellFeedbackPtr)NULL; dev->bell = (BellFeedbackPtr)NULL;
dev->leds = (LedFeedbackPtr)NULL; dev->leds = (LedFeedbackPtr)NULL;
dev->next = inputInfo.off_devices;
#ifdef XKB #ifdef XKB
dev->xkb_interest = NULL; dev->xkb_interest = NULL;
#endif #endif
dev->nPrivates = 0; dev->nPrivates = 0;
dev->devPrivates = NULL; dev->devPrivates = NULL;
dev->unwrapProc = NULL; dev->unwrapProc = NULL;
dev->coreEvents = TRUE;
dev->next = inputInfo.off_devices;
inputInfo.off_devices = dev; inputInfo.off_devices = dev;
return dev; return dev;
} }
@ -134,14 +143,20 @@ Bool
EnableDevice(register DeviceIntPtr dev) EnableDevice(register DeviceIntPtr dev)
{ {
register DeviceIntPtr *prev; register DeviceIntPtr *prev;
int ret;
for (prev = &inputInfo.off_devices; for (prev = &inputInfo.off_devices;
*prev && (*prev != dev); *prev && (*prev != dev);
prev = &(*prev)->next) prev = &(*prev)->next)
; ;
if ((*prev != dev) || !dev->inited || if ((*prev != dev) || !dev->inited ||
((*dev->deviceProc)(dev, DEVICE_ON) != Success)) ((ret = (*dev->deviceProc)(dev, DEVICE_ON)) != Success)) {
ErrorF("couldn't enable device %d\n", dev->id);
#ifdef DEBUG
ErrorF("prev is %p, dev is %p, dev->inited is %d, ret is %d\n", prev, dev, dev->inited, ret);
#endif
return FALSE; return FALSE;
}
*prev = dev->next; *prev = dev->next;
dev->next = inputInfo.devices; dev->next = inputInfo.devices;
inputInfo.devices = dev; inputInfo.devices = dev;
@ -166,23 +181,221 @@ DisableDevice(register DeviceIntPtr dev)
return TRUE; return TRUE;
} }
int
ActivateDevice(DeviceIntPtr dev)
{
int ret = Success;
#ifdef XINPUT
devicePresenceNotify ev;
DeviceIntRec dummyDev;
#endif
if (!dev || !dev->deviceProc)
return BadImplementation;
ret = (*dev->deviceProc) (dev, DEVICE_INIT);
dev->inited = (ret == Success);
#ifdef XINPUT
ev.type = DevicePresenceNotify;
ev.time = currentTime.milliseconds;
dummyDev.id = 0;
SendEventToAllWindows(&dummyDev, DevicePresenceNotifyMask,
&ev, 1);
#endif
return ret;
}
static void
CoreKeyboardBell(int volume, DeviceIntPtr pDev, pointer ctrl, int something)
{
return;
}
static void
CoreKeyboardCtl(DeviceIntPtr pDev, KeybdCtrl *ctrl)
{
return;
}
static int
CoreKeyboardProc(DeviceIntPtr pDev, int what)
{
CARD8 *modMap;
KeySymsRec keySyms;
#ifdef XKB
XkbComponentNamesRec names;
#endif
switch (what) {
case DEVICE_INIT:
keySyms.minKeyCode = 8;
keySyms.maxKeyCode = 255;
keySyms.mapWidth = 4;
keySyms.map = (KeySym *)xcalloc(sizeof(KeySym),
(keySyms.maxKeyCode -
keySyms.minKeyCode) *
keySyms.mapWidth);
if (!keySyms.map) {
ErrorF("Couldn't allocate core keymap\n");
return BadAlloc;
}
modMap = (CARD8 *)xalloc(MAP_LENGTH);
if (!modMap) {
ErrorF("Couldn't allocate core modifier map\n");
return BadAlloc;
}
bzero((char *)modMap, MAP_LENGTH);
#ifdef XKB
if (!noXkbExtension) {
bzero(&names, sizeof(names));
XkbSetRulesDflts("base", "pc105", "us", NULL, NULL);
XkbInitKeyboardDeviceStruct(pDev, &names, &keySyms, modMap,
CoreKeyboardBell, CoreKeyboardCtl);
}
else
#endif
InitKeyboardDeviceStruct((DevicePtr)pDev, &keySyms, modMap,
CoreKeyboardBell, CoreKeyboardCtl);
break;
case DEVICE_CLOSE:
/* This, uh, probably requires some explanation.
* Press a key on another keyboard.
* Watch its xkbInfo get pivoted into core's.
* Kill the server.
* Watch the first device's xkbInfo get freed.
* Try to free ours, which points to same.
*
* ... yeah.
*/
pDev->key->xkbInfo = NULL;
break;
default:
break;
}
return Success;
}
static int
CorePointerProc(DeviceIntPtr pDev, int what)
{
BYTE map[33];
int i = 0;
switch (what) {
case DEVICE_INIT:
for (i = 1; i <= 32; i++)
map[i] = i;
/* we don't keep history, for now. */
InitPointerDeviceStruct((DevicePtr)pDev, map, 32,
NULL, (PtrCtrlProcPtr)NoopDDA,
0, 2);
pDev->valuator->axisVal[0] = screenInfo.screens[0]->width / 2;
pDev->valuator->lastx = pDev->valuator->axisVal[0];
pDev->valuator->axisVal[1] = screenInfo.screens[0]->height / 2;
pDev->valuator->lasty = pDev->valuator->axisVal[1];
break;
default:
break;
}
return Success;
}
void
InitCoreDevices()
{
register DeviceIntPtr dev;
if (CoreDevicePrivatesGeneration != serverGeneration) {
CoreDevicePrivatesIndex = AllocateDevicePrivateIndex();
CoreDevicePrivatesGeneration = serverGeneration;
}
if (!inputInfo.keyboard) {
dev = AddInputDevice(CoreKeyboardProc, TRUE);
if (!dev)
FatalError("Failed to allocate core keyboard");
dev->name = strdup("Virtual core keyboard");
#ifdef XKB
dev->public.processInputProc = CoreProcessKeyboardEvent;
dev->public.realInputProc = CoreProcessKeyboardEvent;
if (!noXkbExtension)
XkbSetExtension(dev, ProcessKeyboardEvent);
#else
dev->public.processInputProc = ProcessKeyboardEvent;
dev->public.realInputProc = ProcessKeyboardEvent;
#endif
dev->ActivateGrab = ActivateKeyboardGrab;
dev->DeactivateGrab = DeactivateKeyboardGrab;
dev->coreEvents = FALSE;
if (!AllocateDevicePrivate(dev, CoreDevicePrivatesIndex))
FatalError("Couldn't allocate keyboard devPrivates\n");
dev->devPrivates[CoreDevicePrivatesIndex].ptr = NULL;
(void)ActivateDevice(dev);
inputInfo.keyboard = dev;
}
if (!inputInfo.pointer) {
dev = AddInputDevice(CorePointerProc, TRUE);
if (!dev)
FatalError("Failed to allocate core pointer");
dev->name = strdup("Virtual core pointer");
#ifdef XKB
dev->public.processInputProc = CoreProcessPointerEvent;
dev->public.realInputProc = CoreProcessPointerEvent;
if (!noXkbExtension)
XkbSetExtension(dev, ProcessPointerEvent);
#else
dev->public.processInputProc = ProcessPointerEvent;
dev->public.realInputProc = ProcessPointerEvent;
#endif
dev->ActivateGrab = ActivatePointerGrab;
dev->DeactivateGrab = DeactivatePointerGrab;
dev->coreEvents = FALSE;
if (!AllocateDevicePrivate(dev, CoreDevicePrivatesIndex))
FatalError("Couldn't allocate pointer devPrivates\n");
dev->devPrivates[CoreDevicePrivatesIndex].ptr = NULL;
(void)ActivateDevice(dev);
inputInfo.pointer = dev;
}
}
int int
InitAndStartDevices() InitAndStartDevices()
{ {
register DeviceIntPtr dev, next; register DeviceIntPtr dev, next;
for (dev = inputInfo.off_devices; dev; dev = dev->next) for (dev = inputInfo.off_devices; dev; dev = dev->next) {
dev->inited = ((*dev->deviceProc)(dev, DEVICE_INIT) == Success); #ifdef DEBUG
ErrorF("(dix) initialising device %d\n", dev->id);
#endif
ActivateDevice(dev);
#ifdef DEBUG
ErrorF("(dix) finished device %d, inited is %d\n", dev->id, dev->inited);
#endif
}
for (dev = inputInfo.off_devices; dev; dev = next) for (dev = inputInfo.off_devices; dev; dev = next)
{ {
#ifdef DEBUG
ErrorF("(dix) enabling device %d\n", dev->id);
#endif
next = dev->next; next = dev->next;
if (dev->inited && dev->startup) if (dev->inited && dev->startup)
(void)EnableDevice(dev); (void)EnableDevice(dev);
#ifdef DEBUG
ErrorF("(dix) finished device %d\n", dev->id);
#endif
} }
for (dev = inputInfo.devices; for (dev = inputInfo.devices;
dev && (dev != inputInfo.keyboard); dev && (dev != inputInfo.keyboard);
dev = dev->next) dev = dev->next)
;
if (!dev || (dev != inputInfo.keyboard)) { if (!dev || (dev != inputInfo.keyboard)) {
ErrorF("No core keyboard\n"); ErrorF("No core keyboard\n");
return BadImplementation; return BadImplementation;
@ -210,9 +423,10 @@ CloseDevice(register DeviceIntPtr dev)
if (dev->inited) if (dev->inited)
(void)(*dev->deviceProc)(dev, DEVICE_CLOSE); (void)(*dev->deviceProc)(dev, DEVICE_CLOSE);
xfree(dev->name); xfree(dev->name);
if (dev->key)
{ if (dev->key) {
#ifdef XKB #ifdef XKB
if (dev->key->xkbInfo) if (dev->key->xkbInfo)
XkbFreeInfo(dev->key->xkbInfo); XkbFreeInfo(dev->key->xkbInfo);
@ -221,20 +435,27 @@ CloseDevice(register DeviceIntPtr dev)
xfree(dev->key->modifierKeyMap); xfree(dev->key->modifierKeyMap);
xfree(dev->key); xfree(dev->key);
} }
if (dev->valuator)
xfree(dev->valuator); xfree(dev->valuator);
if (dev->button) {
#ifdef XKB #ifdef XKB
if ((dev->button)&&(dev->button->xkb_acts)) if (dev->button->xkb_acts)
xfree(dev->button->xkb_acts); xfree(dev->button->xkb_acts);
#endif #endif
xfree(dev->button); xfree(dev->button);
if (dev->focus) }
{
if (dev->focus) {
xfree(dev->focus->trace); xfree(dev->focus->trace);
xfree(dev->focus); xfree(dev->focus);
} }
if (dev->proximity)
xfree(dev->proximity); xfree(dev->proximity);
for (k=dev->kbdfeed; k; k=knext)
{ for (k = dev->kbdfeed; k; k = knext) {
knext = k->next; knext = k->next;
#ifdef XKB #ifdef XKB
if (k->xkb_sli) if (k->xkb_sli)
@ -242,30 +463,30 @@ CloseDevice(register DeviceIntPtr dev)
#endif #endif
xfree(k); xfree(k);
} }
for (p=dev->ptrfeed; p; p=pnext)
{ for (p = dev->ptrfeed; p; p = pnext) {
pnext = p->next; pnext = p->next;
xfree(p); xfree(p);
} }
for (i=dev->intfeed; i; i=inext)
{ for (i = dev->intfeed; i; i = inext) {
inext = i->next; inext = i->next;
xfree(i); xfree(i);
} }
for (s=dev->stringfeed; s; s=snext)
{ for (s = dev->stringfeed; s; s = snext) {
snext = s->next; snext = s->next;
xfree(s->ctrl.symbols_supported); xfree(s->ctrl.symbols_supported);
xfree(s->ctrl.symbols_displayed); xfree(s->ctrl.symbols_displayed);
xfree(s); xfree(s);
} }
for (b=dev->bell; b; b=bnext)
{ for (b = dev->bell; b; b = bnext) {
bnext = b->next; bnext = b->next;
xfree(b); xfree(b);
} }
for (l=dev->leds; l; l=lnext)
{ for (l = dev->leds; l; l = lnext) {
lnext = l->next; lnext = l->next;
#ifdef XKB #ifdef XKB
if (l->xkb_sli) if (l->xkb_sli)
@ -273,11 +494,12 @@ CloseDevice(register DeviceIntPtr dev)
#endif #endif
xfree(l); xfree(l);
} }
#ifdef XKB #ifdef XKB
while (dev->xkb_interest) { while (dev->xkb_interest)
XkbRemoveResourceClient((DevicePtr)dev,dev->xkb_interest->resource); XkbRemoveResourceClient((DevicePtr)dev,dev->xkb_interest->resource);
}
#endif #endif
xfree(dev->sync.event); xfree(dev->sync.event);
xfree(dev); xfree(dev);
} }
@ -303,26 +525,42 @@ CloseDownDevices()
inputInfo.pointer = NULL; inputInfo.pointer = NULL;
} }
void int
RemoveDevice(register DeviceIntPtr dev) RemoveDevice(DeviceIntPtr dev)
{ {
register DeviceIntPtr prev,tmp,next; DeviceIntPtr prev,tmp,next;
int ret = BadMatch;
#ifdef XINPUT
devicePresenceNotify ev;
DeviceIntRec dummyDev;
#endif
#ifdef DEBUG
ErrorF("want to remove device %p, kb is %p, pointer is %p\n", dev, inputInfo.keyboard, inputInfo.pointer);
#endif
if (!dev)
return BadImplementation;
prev = NULL; prev = NULL;
for (tmp = inputInfo.devices; tmp; (prev = tmp), (tmp = next)) { for (tmp = inputInfo.devices; tmp; (prev = tmp), (tmp = next)) {
next = tmp->next; next = tmp->next;
if (tmp == dev) { if (tmp == dev) {
CloseDevice(tmp); CloseDevice(tmp);
if (prev==NULL) if (prev==NULL)
inputInfo.devices = next; inputInfo.devices = next;
else else
prev->next = next; prev->next = next;
inputInfo.numDevices--; inputInfo.numDevices--;
if (inputInfo.keyboard == tmp) if (inputInfo.keyboard == tmp)
inputInfo.keyboard = NULL; inputInfo.keyboard = NULL;
else if (inputInfo.pointer == tmp) else if (inputInfo.pointer == tmp)
inputInfo.pointer = NULL; inputInfo.pointer = NULL;
return;
ret = Success;
} }
} }
@ -331,20 +569,34 @@ RemoveDevice(register DeviceIntPtr dev)
next = tmp->next; next = tmp->next;
if (tmp == dev) { if (tmp == dev) {
CloseDevice(tmp); CloseDevice(tmp);
if (prev == NULL) if (prev == NULL)
inputInfo.off_devices = next; inputInfo.off_devices = next;
else else
prev->next = next; prev->next = next;
inputInfo.numDevices--; inputInfo.numDevices--;
if (inputInfo.keyboard == tmp) if (inputInfo.keyboard == tmp)
inputInfo.keyboard = NULL; inputInfo.keyboard = NULL;
else if (inputInfo.pointer == tmp) else if (inputInfo.pointer == tmp)
inputInfo.pointer = NULL; inputInfo.pointer = NULL;
return;
ret = Success;
} }
} }
ErrorF("Internal Error! Attempt to remove a non-existent device\n");
return; #ifdef XINPUT
if (ret == Success) {
ev.type = DevicePresenceNotify;
ev.time = currentTime.milliseconds;
dummyDev.id = 0;
SendEventToAllWindows(&dummyDev, DevicePresenceNotifyMask,
&ev, 1);
}
#endif
return ret;
} }
int int
@ -356,47 +608,13 @@ NumMotionEvents()
void void
RegisterPointerDevice(DeviceIntPtr device) RegisterPointerDevice(DeviceIntPtr device)
{ {
inputInfo.pointer = device; RegisterOtherDevice(device);
#ifdef XKB
device->public.processInputProc = CoreProcessPointerEvent;
device->public.realInputProc = CoreProcessPointerEvent;
if (!noXkbExtension)
XkbSetExtension(device,ProcessPointerEvent);
#else
device->public.processInputProc = ProcessPointerEvent;
device->public.realInputProc = ProcessPointerEvent;
#endif
device->ActivateGrab = ActivatePointerGrab;
device->DeactivateGrab = DeactivatePointerGrab;
if (!device->name)
{
char *p = "pointer";
device->name = (char *)xalloc(strlen(p) + 1);
strcpy(device->name, p);
}
} }
void void
RegisterKeyboardDevice(DeviceIntPtr device) RegisterKeyboardDevice(DeviceIntPtr device)
{ {
inputInfo.keyboard = device; RegisterOtherDevice(device);
#ifdef XKB
device->public.processInputProc = CoreProcessKeyboardEvent;
device->public.realInputProc = CoreProcessKeyboardEvent;
if (!noXkbExtension)
XkbSetExtension(device,ProcessKeyboardEvent);
#else
device->public.processInputProc = ProcessKeyboardEvent;
device->public.realInputProc = ProcessKeyboardEvent;
#endif
device->ActivateGrab = ActivateKeyboardGrab;
device->DeactivateGrab = DeactivateKeyboardGrab;
if (!device->name)
{
char *k = "keyboard";
device->name = (char *)xalloc(strlen(k) + 1);
strcpy(device->name, k);
}
} }
_X_EXPORT DevicePtr _X_EXPORT DevicePtr
@ -441,8 +659,8 @@ SetKeySymsMap(register KeySymsPtr dst, register KeySymsPtr src)
{ {
int i, j; int i, j;
int rowDif = src->minKeyCode - dst->minKeyCode; int rowDif = src->minKeyCode - dst->minKeyCode;
/* if keysym map size changes, grow map first */
/* if keysym map size changes, grow map first */
if (src->mapWidth < dst->mapWidth) if (src->mapWidth < dst->mapWidth)
{ {
for (i = src->minKeyCode; i <= src->maxKeyCode; i++) for (i = src->minKeyCode; i <= src->maxKeyCode; i++)
@ -808,12 +1026,13 @@ InitIntegerFeedbackClassDeviceStruct (DeviceIntPtr dev, IntegerCtrlProcPtr contr
_X_EXPORT Bool _X_EXPORT Bool
InitPointerDeviceStruct(DevicePtr device, CARD8 *map, int numButtons, InitPointerDeviceStruct(DevicePtr device, CARD8 *map, int numButtons,
ValuatorMotionProcPtr motionProc, ValuatorMotionProcPtr motionProc,
PtrCtrlProcPtr controlProc, int numMotionEvents) PtrCtrlProcPtr controlProc, int numMotionEvents,
int numAxes)
{ {
DeviceIntPtr dev = (DeviceIntPtr)device; DeviceIntPtr dev = (DeviceIntPtr)device;
return(InitButtonClassDeviceStruct(dev, numButtons, map) && return(InitButtonClassDeviceStruct(dev, numButtons, map) &&
InitValuatorClassDeviceStruct(dev, 2, motionProc, InitValuatorClassDeviceStruct(dev, numAxes, motionProc,
numMotionEvents, 0) && numMotionEvents, 0) &&
InitPtrFeedbackClassDeviceStruct(dev, controlProc)); InitPtrFeedbackClassDeviceStruct(dev, controlProc));
} }

View File

@ -134,6 +134,7 @@ of the copyright holder.
#include "globals.h" #include "globals.h"
#ifdef XKB #ifdef XKB
#include <X11/extensions/XKBproto.h>
#include <X11/extensions/XKBsrv.h> #include <X11/extensions/XKBsrv.h>
extern Bool XkbFilterEvents(ClientPtr, int, xEvent *); extern Bool XkbFilterEvents(ClientPtr, int, xEvent *);
#endif #endif
@ -159,14 +160,13 @@ xEvent *xeviexE;
#include <X11/extensions/XIproto.h> #include <X11/extensions/XIproto.h>
#include "exglobals.h" #include "exglobals.h"
#include "exevents.h" #include "exevents.h"
#include "exglobals.h"
#include "extnsionst.h" #include "extnsionst.h"
#include "dixevents.h" #include "dixevents.h"
#include "dixgrabs.h" #include "dixgrabs.h"
#include "dispatch.h" #include "dispatch.h"
int CoreDevicePrivatesIndex = 0, CoreDevicePrivatesGeneration = -1;
#define EXTENSION_EVENT_BASE 64 #define EXTENSION_EVENT_BASE 64
#define NoSuchEvent 0x80000000 /* so doesn't match NoEventMask */ #define NoSuchEvent 0x80000000 /* so doesn't match NoEventMask */

View File

@ -398,6 +398,7 @@ main(int argc, char *argv[], char *envp[])
if (!CreateRootWindow(pScreen)) if (!CreateRootWindow(pScreen))
FatalError("failed to create root window"); FatalError("failed to create root window");
} }
InitCoreDevices();
InitInput(argc, argv); InitInput(argc, argv);
if (InitAndStartDevices() != Success) if (InitAndStartDevices() != Success)
FatalError("failed to initialize core devices"); FatalError("failed to initialize core devices");

View File

@ -176,6 +176,9 @@ extern DeviceIntPtr AddInputDevice(
extern Bool EnableDevice( extern Bool EnableDevice(
DeviceIntPtr /*device*/); DeviceIntPtr /*device*/);
extern Bool ActivateDevice(
DeviceIntPtr /*device*/);
extern Bool DisableDevice( extern Bool DisableDevice(
DeviceIntPtr /*device*/); DeviceIntPtr /*device*/);
@ -183,7 +186,7 @@ extern int InitAndStartDevices(void);
extern void CloseDownDevices(void); extern void CloseDownDevices(void);
extern void RemoveDevice( extern int RemoveDevice(
DeviceIntPtr /*dev*/); DeviceIntPtr /*dev*/);
extern int NumMotionEvents(void); extern int NumMotionEvents(void);
@ -233,6 +236,9 @@ extern Bool InitValuatorClassDeviceStruct(
int /*numMotionEvents*/, int /*numMotionEvents*/,
int /*mode*/); int /*mode*/);
extern Bool InitTouchscreenClassDeviceStruct(
DeviceIntPtr /*device*/);
extern Bool InitFocusClassDeviceStruct( extern Bool InitFocusClassDeviceStruct(
DeviceIntPtr /*device*/); DeviceIntPtr /*device*/);
@ -302,7 +308,8 @@ extern Bool InitPointerDeviceStruct(
int /*numButtons*/, int /*numButtons*/,
ValuatorMotionProcPtr /*motionProc*/, ValuatorMotionProcPtr /*motionProc*/,
PtrCtrlProcPtr /*controlProc*/, PtrCtrlProcPtr /*controlProc*/,
int /*numMotionEvents*/); int /*numMotionEvents*/,
int /*numAxes*/);
extern Bool InitKeyboardDeviceStruct( extern Bool InitKeyboardDeviceStruct(
DevicePtr /*device*/, DevicePtr /*device*/,

View File

@ -68,6 +68,8 @@ SOFTWARE.
#define POINTER_ABSOLUTE (1 << 2) #define POINTER_ABSOLUTE (1 << 2)
#define POINTER_ACCELERATE (1 << 3) #define POINTER_ACCELERATE (1 << 3)
extern int CoreDevicePrivatesIndex, CoreDevicePrivatesGeneration;
/* Kludge: OtherClients and InputClients must be compatible, see code */ /* Kludge: OtherClients and InputClients must be compatible, see code */
typedef struct _OtherClients { typedef struct _OtherClients {

View File

@ -171,8 +171,7 @@ typedef struct _DeviceRec *DevicePtr;
#endif #endif
extern Bool mieqInit( extern Bool mieqInit(
DevicePtr /*pKbd*/, void
DevicePtr /*pPtr*/
); );
extern void mieqEnqueue( extern void mieqEnqueue(

131
mi/mieq.c
View File

@ -43,21 +43,27 @@ in this Software without prior written authorization from The Open Group.
# include "pixmapstr.h" # include "pixmapstr.h"
# include "inputstr.h" # include "inputstr.h"
# include "mi.h" # include "mi.h"
# include "mipointer.h"
# include "scrnintstr.h" # include "scrnintstr.h"
# include <X11/extensions/XI.h>
# include <X11/extensions/XIproto.h>
# include "extinit.h"
# include "exglobals.h"
#define QUEUE_SIZE 256 #define QUEUE_SIZE 256
typedef struct _Event { typedef struct _Event {
xEvent event; xEvent event[2];
int nevents;
ScreenPtr pScreen; ScreenPtr pScreen;
DeviceIntPtr pDev;
} EventRec, *EventPtr; } EventRec, *EventPtr;
typedef struct _EventQueue { typedef struct _EventQueue {
HWEventQueueType head, tail; /* long for SetInputCheck */ HWEventQueueType head, tail; /* long for SetInputCheck */
CARD32 lastEventTime; /* to avoid time running backwards */ CARD32 lastEventTime; /* to avoid time running backwards */
Bool lastMotion; int lastMotion; /* device ID if last event motion? */
EventRec events[QUEUE_SIZE]; /* static allocation for signals */ EventRec events[QUEUE_SIZE]; /* static allocation for signals */
DevicePtr pKbd, pPtr; /* device pointer, to get funcs */
ScreenPtr pEnqueueScreen; /* screen events are being delivered to */ ScreenPtr pEnqueueScreen; /* screen events are being delivered to */
ScreenPtr pDequeueScreen; /* screen events are being dispatched to */ ScreenPtr pDequeueScreen; /* screen events are being dispatched to */
} EventQueueRec, *EventQueuePtr; } EventQueueRec, *EventQueuePtr;
@ -65,13 +71,10 @@ typedef struct _EventQueue {
static EventQueueRec miEventQueue; static EventQueueRec miEventQueue;
Bool Bool
mieqInit (pKbd, pPtr) mieqInit ()
DevicePtr pKbd, pPtr;
{ {
miEventQueue.head = miEventQueue.tail = 0; miEventQueue.head = miEventQueue.tail = 0;
miEventQueue.lastEventTime = GetTimeInMillis (); miEventQueue.lastEventTime = GetTimeInMillis ();
miEventQueue.pKbd = pKbd;
miEventQueue.pPtr = pPtr;
miEventQueue.lastMotion = FALSE; miEventQueue.lastMotion = FALSE;
miEventQueue.pEnqueueScreen = screenInfo.screens[0]; miEventQueue.pEnqueueScreen = screenInfo.screens[0];
miEventQueue.pDequeueScreen = miEventQueue.pEnqueueScreen; miEventQueue.pDequeueScreen = miEventQueue.pEnqueueScreen;
@ -87,32 +90,83 @@ mieqInit (pKbd, pPtr)
*/ */
void void
mieqEnqueue (e) mieqEnqueue (xEvent *e)
xEvent *e;
{ {
HWEventQueueType oldtail, newtail; HWEventQueueType oldtail = miEventQueue.tail, newtail;
Bool isMotion; int isMotion = 0;
DeviceIntPtr pDev = NULL;
deviceKeyButtonPointer *kbp = (deviceKeyButtonPointer *) e;
deviceValuator *v = (deviceValuator *) e;
EventPtr laste = &miEventQueue.events[oldtail - 1];
deviceKeyButtonPointer *lastkbp = (deviceKeyButtonPointer *)
&laste->event[0];
oldtail = miEventQueue.tail; ErrorF("mieqEnqueue: slamming an event on to the queue from %d\n", kbp->deviceid & DEVICE_BITS);
isMotion = e->u.u.type == MotionNotify; if (e->u.u.type == MotionNotify) {
if (isMotion && miEventQueue.lastMotion && oldtail != miEventQueue.head) miPointerAbsoluteCursor(e->u.keyButtonPointer.rootX,
{ e->u.keyButtonPointer.rootY,
e->u.keyButtonPointer.time);
pDev = inputInfo.pointer;
isMotion = inputInfo.pointer->id & DEVICE_BITS;
}
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
* motion event they need to be attached to. Sigh. */
if (e->u.u.type == DeviceValuator) {
if (laste->nevents >= 6) {
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;
}
laste->event[laste->nevents++] = *e;
ErrorF("put a valuator event into the queue\n");
return;
}
else if (e->u.u.type == DeviceMotionNotify) {
isMotion = pDev->id & DEVICE_BITS;
}
}
if (!pDev)
FatalError("Couldn't find device for event!\n");
if (isMotion && isMotion == miEventQueue.lastMotion &&
oldtail != miEventQueue.head) {
if (oldtail == 0) if (oldtail == 0)
oldtail = QUEUE_SIZE; oldtail = QUEUE_SIZE;
oldtail = oldtail - 1; oldtail = oldtail - 1;
} }
else else {
{
newtail = oldtail + 1; newtail = oldtail + 1;
if (newtail == QUEUE_SIZE) if (newtail == QUEUE_SIZE)
newtail = 0; newtail = 0;
/* Toss events which come in late */ /* Toss events which come in late */
if (newtail == miEventQueue.head) if (newtail == miEventQueue.head) {
ErrorF("tossed event which came in late\n");
return; return;
}
miEventQueue.tail = newtail; miEventQueue.tail = newtail;
} }
miEventQueue.lastMotion = isMotion;
miEventQueue.events[oldtail].event = *e; miEventQueue.events[oldtail].event[0] = *e;
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
@ -120,18 +174,23 @@ mieqEnqueue (e)
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.u.keyButtonPointer.time = ErrorF("mieq: rewinding event time from %d to %d\n",
miEventQueue.lastEventTime,
miEventQueue.events[oldtail].event[0].u.keyButtonPointer.time);
miEventQueue.events[oldtail].event[0].u.keyButtonPointer.time =
miEventQueue.lastEventTime; miEventQueue.lastEventTime;
} }
miEventQueue.lastEventTime = miEventQueue.lastEventTime =
miEventQueue.events[oldtail].event.u.keyButtonPointer.time; miEventQueue.events[oldtail].event[0].u.keyButtonPointer.time;
miEventQueue.events[oldtail].pScreen = miEventQueue.pEnqueueScreen; miEventQueue.events[oldtail].pScreen = miEventQueue.pEnqueueScreen;
miEventQueue.events[oldtail].pDev = pDev;
miEventQueue.lastMotion = isMotion;
ErrorF("bottom of mieqEnqueue\n");
} }
void void
mieqSwitchScreen (pScreen, fromDIX) mieqSwitchScreen (ScreenPtr pScreen, Bool fromDIX)
ScreenPtr pScreen;
Bool fromDIX;
{ {
miEventQueue.pEnqueueScreen = pScreen; miEventQueue.pEnqueueScreen = pScreen;
if (fromDIX) if (fromDIX)
@ -146,7 +205,8 @@ void mieqProcessInputEvents ()
{ {
EventRec *e; EventRec *e;
int x, y; int x, y;
xEvent xe;
ErrorF("mieqPIE: head %p, tail %p\n", miEventQueue.head, miEventQueue.tail);
while (miEventQueue.head != miEventQueue.tail) while (miEventQueue.head != miEventQueue.tail)
{ {
@ -160,8 +220,8 @@ void mieqProcessInputEvents ()
if (e->pScreen != miEventQueue.pDequeueScreen) if (e->pScreen != miEventQueue.pDequeueScreen)
{ {
miEventQueue.pDequeueScreen = e->pScreen; miEventQueue.pDequeueScreen = e->pScreen;
x = e->event.u.keyButtonPointer.rootX; x = e->event[0].u.keyButtonPointer.rootX;
y = e->event.u.keyButtonPointer.rootY; y = e->event[0].u.keyButtonPointer.rootY;
if (miEventQueue.head == QUEUE_SIZE - 1) if (miEventQueue.head == QUEUE_SIZE - 1)
miEventQueue.head = 0; miEventQueue.head = 0;
else else
@ -170,23 +230,12 @@ void mieqProcessInputEvents ()
} }
else else
{ {
xe = e->event;
if (miEventQueue.head == QUEUE_SIZE - 1) if (miEventQueue.head == QUEUE_SIZE - 1)
miEventQueue.head = 0; miEventQueue.head = 0;
else else
++miEventQueue.head; ++miEventQueue.head;
switch (xe.u.u.type) ErrorF("calling pIP from mieqPIE\n");
{ (*e->pDev->public.processInputProc)(e->event, e->pDev, e->nevents);
case KeyPress:
case KeyRelease:
(*miEventQueue.pKbd->processInputProc)
(&xe, (DeviceIntPtr)miEventQueue.pKbd, 1);
break;
default:
(*miEventQueue.pPtr->processInputProc)
(&xe, (DeviceIntPtr)miEventQueue.pPtr, 1);
break;
}
} }
} }
} }

View File

@ -490,12 +490,6 @@ miPointerMove (pScreen, x, y, time)
miPointer.y = y; miPointer.y = y;
miPointer.pScreen = pScreen; miPointer.pScreen = pScreen;
xE.u.u.type = MotionNotify;
xE.u.keyButtonPointer.rootX = x;
xE.u.keyButtonPointer.rootY = y;
xE.u.keyButtonPointer.time = time;
(*pScreenPriv->screenFuncs->EnqueueEvent) (&xE);
end = miPointer.history_end; end = miPointer.history_end;
start = miPointer.history_start; start = miPointer.history_start;
prev = end - 1; prev = end - 1;
@ -521,11 +515,3 @@ miPointerMove (pScreen, x, y, time)
history->event.time = time; history->event.time = time;
history->pScreen = pScreen; history->pScreen = pScreen;
} }
void
miRegisterPointerDevice (pScreen, pDevice)
ScreenPtr pScreen;
DeviceIntPtr pDevice;
{
miPointer.pPointer = (DevicePtr)pDevice;
}

View File

@ -50,7 +50,6 @@ typedef struct {
Bool confined; /* pointer can't change screens */ Bool confined; /* pointer can't change screens */
int x, y; /* hot spot location */ int x, y; /* hot spot location */
int devx, devy; /* sprite position */ int devx, devy; /* sprite position */
DevicePtr pPointer; /* pointer device structure */
miHistoryRec history[MOTION_SIZE]; miHistoryRec history[MOTION_SIZE];
int history_start, history_end; int history_start, history_end;
} miPointerRec, *miPointerPtr; } miPointerRec, *miPointerPtr;