diff options
Diffstat (limited to 'dix')
-rw-r--r-- | dix/Makefile.am | 1 | ||||
-rw-r--r-- | dix/deprecated.c | 18 | ||||
-rw-r--r-- | dix/devices.c | 105 | ||||
-rw-r--r-- | dix/dispatch.c | 150 | ||||
-rw-r--r-- | dix/dixfonts.c | 12 | ||||
-rw-r--r-- | dix/enterleave.c | 44 | ||||
-rw-r--r-- | dix/enterleave.h | 6 | ||||
-rw-r--r-- | dix/eventconvert.c | 238 | ||||
-rw-r--r-- | dix/events.c | 251 | ||||
-rw-r--r-- | dix/extension.c | 2 | ||||
-rw-r--r-- | dix/getevents.c | 160 | ||||
-rw-r--r-- | dix/grabs.c | 2 | ||||
-rw-r--r-- | dix/inpututils.c | 20 | ||||
-rw-r--r-- | dix/main.c | 6 | ||||
-rw-r--r-- | dix/property.c | 62 | ||||
-rw-r--r-- | dix/protocol.txt | 30 | ||||
-rw-r--r-- | dix/ptrveloc.c | 393 | ||||
-rw-r--r-- | dix/registry.c | 2 | ||||
-rw-r--r-- | dix/resource.c | 12 | ||||
-rw-r--r-- | dix/swaprep.c | 4 | ||||
-rw-r--r-- | dix/window.c | 11 |
21 files changed, 912 insertions, 617 deletions
diff --git a/dix/Makefile.am b/dix/Makefile.am index ab702f790..13e5dedd7 100644 --- a/dix/Makefile.am +++ b/dix/Makefile.am @@ -18,7 +18,6 @@ libdix_la_SOURCES = \ enterleave.c \ enterleave.h \ events.c \ - eventconvert.h \ eventconvert.c \ extension.c \ ffs.c \ diff --git a/dix/deprecated.c b/dix/deprecated.c index 8123886ca..21d0f574d 100644 --- a/dix/deprecated.c +++ b/dix/deprecated.c @@ -162,22 +162,4 @@ LookupIDByClass(XID id, RESTYPE classes) return val; } -/* replaced by dixLookupResourceBy{Type,Class} */ -_X_EXPORT int -dixLookupResource (pointer *result, XID id, RESTYPE rtype, - ClientPtr client, Mask mode) -{ - Bool istype = ((rtype & TypeMask) && (rtype != RC_ANY)) || (rtype == RT_NONE); - - static int warn = 1; - if (warn > 0 && --warn) - ErrorF("Warning: dixLookupResource() " - "is deprecated. Please convert your driver/module " - "to use dixLookupResourceByType/dixLookupResourceByClass().\n"); - if (istype) - return dixLookupResourceByType (result, id, rtype, client, mode); - else - return dixLookupResourceByClass (result, id, rtype, client, mode); -} - /* end deprecated functions */ diff --git a/dix/devices.c b/dix/devices.c index b237e03b1..0be3d58ab 100644 --- a/dix/devices.c +++ b/dix/devices.c @@ -72,6 +72,7 @@ SOFTWARE. #include "swaprep.h" #include "dixevents.h" #include "mipointer.h" +#include "eventstr.h" #include <X11/extensions/XI.h> #include <X11/extensions/XI2.h> @@ -93,21 +94,7 @@ DevPrivateKey CoreDevicePrivateKey = &CoreDevicePrivateKeyIndex; /* Used to store classes currently not in use by an MD */ static int UnusedClassesPrivateKeyIndex; DevPrivateKey UnusedClassesPrivateKey = &UnusedClassesPrivateKeyIndex; -/* Used to store if a device is an XTest Virtual device */ -static int XTstDevicePrivateKeyIndex; -DevPrivateKey XTstDevicePrivateKey = &XTstDevicePrivateKeyIndex; -/** - * vxtstpointer - * is the virtual pointer for XTest. It is the first slave - * device of the VCP. - * vxtstkeyboard - * is the virtual keyboard for XTest. It is the first slave - * device of the VCK - * - * Neither of these devices can be deleted. - */ -DeviceIntPtr vxtstpointer, vxtstkeyboard; static void RecalculateMasterButtons(DeviceIntPtr slave); @@ -447,6 +434,8 @@ DisableDevice(DeviceIntPtr dev, BOOL sendevent) } OsReleaseSignals(); + LeaveWindow(dev); + SetFocusOut(dev); *prev = dev->next; dev->next = inputInfo.off_devices; @@ -528,7 +517,7 @@ CoreKeyboardCtl(DeviceIntPtr pDev, KeybdCtrl *ctrl) /** * Device control function for the Virtual Core Keyboard. */ -static int +int CoreKeyboardProc(DeviceIntPtr pDev, int what) { @@ -557,7 +546,7 @@ CoreKeyboardProc(DeviceIntPtr pDev, int what) /** * Device control function for the Virtual Core Pointer. */ -static int +int CorePointerProc(DeviceIntPtr pDev, int what) { #define NBUTTONS 7 @@ -624,6 +613,7 @@ InitCoreDevices(void) { if (AllocDevicePair(serverClient, "Virtual core", &inputInfo.pointer, &inputInfo.keyboard, + CorePointerProc, CoreKeyboardProc, TRUE) != Success) FatalError("Failed to allocate core devices"); @@ -634,24 +624,7 @@ InitCoreDevices(void) !EnableDevice(inputInfo.keyboard, TRUE)) FatalError("Failed to enable core devices."); - /* - Allocate an virtual slave device for xtest events, this - is a slave device to inputInfo master devices - */ - if(AllocXtstDevice(serverClient, "Virtual core", - &vxtstpointer, - &vxtstkeyboard) != Success) - FatalError("Failed to allocate XTst devices"); - - if (ActivateDevice(vxtstpointer, TRUE) != Success || - ActivateDevice(vxtstkeyboard, TRUE) != Success) - FatalError("Failed to activate xtst core devices."); - if (!EnableDevice(vxtstpointer, TRUE) || - !EnableDevice(vxtstkeyboard, TRUE)) - FatalError("Failed to enable xtst core devices."); - - AttachDevice(NULL, vxtstpointer, inputInfo.pointer); - AttachDevice(NULL, vxtstkeyboard, inputInfo.keyboard); + InitXTestDevices(); } /** @@ -1172,6 +1145,8 @@ InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons, Atom* labels, butc->sourceid = dev->id; for (i = 1; i <= numButtons; i++) butc->map[i] = map[i]; + for (i = numButtons + 1; i < MAP_LENGTH; i++) + butc->map[i] = i; memcpy(butc->labels, labels, numButtons * sizeof(Atom)); dev->button = butc; return TRUE; @@ -1225,7 +1200,7 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels, dev->last.numValuators = numAxes; if (IsMaster(dev) || /* do not accelerate master or xtest devices */ - dixLookupPrivate(&dev->devPrivates, XTstDevicePrivateKey )) + IsXTestDevice(dev, NULL)) InitPointerAccelerationScheme(dev, PtrAccelNoOp); else InitPointerAccelerationScheme(dev, PtrAccelDefault); @@ -1530,7 +1505,7 @@ ProcSetModifierMapping(ClientPtr client) REQUEST_AT_LEAST_SIZE(xSetModifierMappingReq); if (client->req_len != ((stuff->numKeyPerModifier << 1) + - (sizeof (xSetModifierMappingReq) >> 2))) + bytes_to_int32(sizeof(xSetModifierMappingReq)))) return BadLength; rep.type = X_Reply; @@ -1589,7 +1564,7 @@ ProcChangeKeyboardMapping(ClientPtr client) int rc; REQUEST_AT_LEAST_SIZE(xChangeKeyboardMappingReq); - len = client->req_len - (sizeof(xChangeKeyboardMappingReq) >> 2); + len = client->req_len - bytes_to_int32(sizeof(xChangeKeyboardMappingReq)); if (len != (stuff->keyCodes * stuff->keySymsPerKeyCode)) return BadLength; @@ -1648,7 +1623,8 @@ ProcSetPointerMapping(ClientPtr client) REQUEST(xSetPointerMappingReq); REQUEST_AT_LEAST_SIZE(xSetPointerMappingReq); - if (client->req_len != (sizeof(xSetPointerMappingReq)+stuff->nElts+3) >> 2) + if (client->req_len != + bytes_to_int32(sizeof(xSetPointerMappingReq) + stuff->nElts)) return BadLength; rep.type = X_Reply; rep.length = 0; @@ -2227,7 +2203,7 @@ ProcGetMotionEvents(ClientPtr client) nEvents++; } } - rep.length = nEvents * (sizeof(xTimecoord) >> 2); + rep.length = nEvents * bytes_to_int32(sizeof(xTimecoord)); rep.nEvents = nEvents; WriteReplyToClient(client, sizeof(xGetMotionEventsReply), &rep); if (nEvents) @@ -2389,11 +2365,6 @@ AttachDevice(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr master) InitializeSprite(dev, currentRoot); dev->spriteInfo->spriteOwner = FALSE; dev->spriteInfo->paired = dev; - - /* Floating an SD makes it appear to XI 1 clients */ - SendDevicePresenceEvent(dev->id, DeviceAdded); - if (dev->enabled) - SendDevicePresenceEvent(dev->id, DeviceEnabled); } else { dev->spriteInfo->sprite = master->spriteInfo->sprite; @@ -2401,14 +2372,6 @@ AttachDevice(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr master) dev->spriteInfo->spriteOwner = FALSE; RecalculateMasterButtons(master); - - if (!oldmaster) - { - /* Attaching a floating SD makes it disappear to XI 1 clients */ - if (dev->enabled) - SendDevicePresenceEvent(dev->id, DeviceDisabled); - SendDevicePresenceEvent(dev->id, DeviceRemoved); - } } /* If we were connected to master device before, this MD may need to @@ -2498,15 +2461,18 @@ GetMaster(DeviceIntPtr dev, int which) */ int AllocDevicePair (ClientPtr client, char* name, - DeviceIntPtr* ptr, DeviceIntPtr* keybd, - Bool master) + DeviceIntPtr* ptr, + DeviceIntPtr* keybd, + DeviceProc ptr_proc, + DeviceProc keybd_proc, + Bool master) { DeviceIntPtr pointer; DeviceIntPtr keyboard; ClassesPtr classes; *ptr = *keybd = NULL; - pointer = AddInputDevice(client, CorePointerProc, TRUE); + pointer = AddInputDevice(client, ptr_proc, TRUE); if (!pointer) return BadAlloc; @@ -2526,7 +2492,7 @@ AllocDevicePair (ClientPtr client, char* name, pointer->last.slave = NULL; pointer->type = (master) ? MASTER_POINTER : SLAVE; - keyboard = AddInputDevice(client, CoreKeyboardProc, TRUE); + keyboard = AddInputDevice(client, keybd_proc, TRUE); if (!keyboard) { RemoveDevice(pointer, FALSE); @@ -2562,30 +2528,3 @@ AllocDevicePair (ClientPtr client, char* name, return Success; } -/** - * Allocate a device pair that is initialised as a slave - * device with properties that identify the devices as belonging - * to XTest subsystem. - * This only creates the pair, Activate/Enable Device - * still need to be called. - */ -int AllocXtstDevice (ClientPtr client, char* name, - DeviceIntPtr* ptr, DeviceIntPtr* keybd) -{ - int retval; - int len = strlen(name); - char *xtstname = xcalloc(len + 6, 1 ); - - strncpy( xtstname, name, len); - strncat( xtstname, " Xtst", 5 ); - - retval = AllocDevicePair( client, xtstname, ptr, keybd, FALSE); - if ( retval == Success ){ - dixSetPrivate(&((*ptr)->devPrivates), XTstDevicePrivateKey, (void *)True ); - dixSetPrivate(&((*keybd)->devPrivates), XTstDevicePrivateKey,(void *)True); - } - - xfree( xtstname ); - - return retval; -} diff --git a/dix/dispatch.c b/dix/dispatch.c index 53daee21d..b9768d7b4 100644 --- a/dix/dispatch.c +++ b/dix/dispatch.c @@ -246,6 +246,7 @@ long SmartScheduleSlice = SMART_SCHEDULE_DEFAULT_INTERVAL; long SmartScheduleInterval = SMART_SCHEDULE_DEFAULT_INTERVAL; long SmartScheduleMaxSlice = SMART_SCHEDULE_MAX_SLICE; long SmartScheduleTime; +int SmartScheduleLatencyLimited = 0; static ClientPtr SmartLastClient; static int SmartLastIndex[SMART_MAX_PRIORITY-SMART_MIN_PRIORITY+1]; @@ -316,7 +317,7 @@ SmartScheduleClient (int *clientReady, int nready) /* * Adjust slice */ - if (nready == 1) + if (nready == 1 && SmartScheduleLatencyLimited == 0) { /* * If it's been a long time since another client @@ -336,6 +337,23 @@ SmartScheduleClient (int *clientReady, int nready) return best; } +void +EnableLimitedSchedulingLatency(void) +{ + ++SmartScheduleLatencyLimited; + SmartScheduleSlice = SmartScheduleInterval; +} + +void +DisableLimitedSchedulingLatency(void) +{ + --SmartScheduleLatencyLimited; + + /* protect against bugs */ + if (SmartScheduleLatencyLimited < 0) + SmartScheduleLatencyLimited = 0; +} + #define MAJOROP ((xReq *)client->requestBuffer)->reqType void @@ -355,6 +373,7 @@ Dispatch(void) if (!clientReady) return; + SmartScheduleSlice = SmartScheduleInterval; while (!dispatchException) { if (*icheck[0] != *icheck[1]) @@ -459,6 +478,7 @@ Dispatch(void) KillAllClients(); xfree(clientReady); dispatchException &= ~DE_RESET; + SmartScheduleLatencyLimited = 0; } #undef MAJOROP @@ -517,7 +537,7 @@ CreateConnectionBlock(void) QueryMinMaxKeyCodes(&setup.minKeyCode, &setup.maxKeyCode); lenofblock = sizeof(xConnSetup) + - ((setup.nbytesVendor + 3) & ~3) + + pad_to_int32(setup.nbytesVendor) + (setup.numFormats * sizeof(xPixmapFormat)) + (setup.numRoots * sizeof(xWindowRoot)); ConnectionInfo = xalloc(lenofblock); @@ -642,7 +662,7 @@ ProcCreateWindow(ClientPtr client) rc = dixLookupWindow(&pParent, stuff->parent, client, DixAddAccess); if (rc != Success) return rc; - len = client->req_len - (sizeof(xCreateWindowReq) >> 2); + len = client->req_len - bytes_to_int32(sizeof(xCreateWindowReq)); if (Ones(stuff->mask) != len) return BadLength; if (!stuff->width || !stuff->height) @@ -685,7 +705,7 @@ ProcChangeWindowAttributes(ClientPtr client) rc = dixLookupWindow(&pWin, stuff->window, client, access_mode); if (rc != Success) return rc; - len = client->req_len - (sizeof(xChangeWindowAttributesReq) >> 2); + len = client->req_len - bytes_to_int32(sizeof(xChangeWindowAttributesReq)); if (len != Ones(stuff->valueMask)) return BadLength; result = ChangeWindowAttributes(pWin, @@ -889,7 +909,7 @@ ProcConfigureWindow(ClientPtr client) DixManageAccess|DixSetAttrAccess); if (rc != Success) return rc; - len = client->req_len - (sizeof(xConfigureWindowReq) >> 2); + len = client->req_len - bytes_to_int32(sizeof(xConfigureWindowReq)); if (Ones((Mask)stuff->mask) != len) return BadLength; result = ConfigureWindow(pWin, (Mask)stuff->mask, (XID *) &stuff[1], @@ -1017,7 +1037,7 @@ ProcQueryTree(ClientPtr client) } reply.nChildren = numChildren; - reply.length = (numChildren * sizeof(Window)) >> 2; + reply.length = bytes_to_int32(numChildren * sizeof(Window)); WriteReplyToClient(client, sizeof(xQueryTreeReply), &reply); if (numChildren) @@ -1074,7 +1094,7 @@ ProcGetAtomName(ClientPtr client) len = strlen(str); memset(&reply, 0, sizeof(xGetAtomNameReply)); reply.type = X_Reply; - reply.length = (len + 3) >> 2; + reply.length = bytes_to_int32(len); reply.sequenceNumber = client->sequence; reply.nameLength = len; WriteReplyToClient(client, sizeof(xGetAtomNameReply), &reply); @@ -1347,7 +1367,7 @@ ProcQueryFont(ClientPtr client) } reply->type = X_Reply; - reply->length = (rlength - sizeof(xGenericReply)) >> 2; + reply->length = bytes_to_int32(rlength - sizeof(xGenericReply)); reply->sequenceNumber = client->sequence; QueryFont( pFont, reply, nprotoxcistructs); @@ -1381,7 +1401,7 @@ ProcQueryTextExtents(ClientPtr client) if (rc != Success) return (rc == BadValue) ? BadFont: rc; - length = client->req_len - (sizeof(xQueryTextExtentsReq) >> 2); + length = client->req_len - bytes_to_int32(sizeof(xQueryTextExtentsReq)); length = length << 1; if (stuff->oddLength) { @@ -1549,7 +1569,7 @@ ProcCreateGC(ClientPtr client) if (rc != Success) return rc; - len = client->req_len - (sizeof(xCreateGCReq) >> 2); + len = client->req_len - bytes_to_int32(sizeof(xCreateGCReq)); if (len != Ones(stuff->mask)) return BadLength; pGC = (GC *)CreateGC(pDraw, stuff->mask, (XID *) &stuff[1], &error, @@ -1574,7 +1594,7 @@ ProcChangeGC(ClientPtr client) if (result != Success) return result; - len = client->req_len - (sizeof(xChangeGCReq) >> 2); + len = client->req_len - bytes_to_int32(sizeof(xChangeGCReq)); if (len != Ones(stuff->mask)) return BadLength; @@ -1824,7 +1844,7 @@ ProcPolyPoint(ClientPtr client) return BadValue; } VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); - npoint = ((client->req_len << 2) - sizeof(xPolyPointReq)) >> 2; + npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyPointReq)); if (npoint) (*pGC->ops->PolyPoint)(pDraw, pGC, stuff->coordMode, npoint, (xPoint *) &stuff[1]); @@ -1847,7 +1867,7 @@ ProcPolyLine(ClientPtr client) return BadValue; } VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); - npoint = ((client->req_len << 2) - sizeof(xPolyLineReq)) >> 2; + npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyLineReq)); if (npoint > 1) (*pGC->ops->Polylines)(pDraw, pGC, stuff->coordMode, npoint, (DDXPointPtr) &stuff[1]); @@ -1935,7 +1955,7 @@ ProcFillPoly(ClientPtr client) } VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); - things = ((client->req_len << 2) - sizeof(xFillPolyReq)) >> 2; + things = bytes_to_int32((client->req_len << 2) - sizeof(xFillPolyReq)); if (things) (*pGC->ops->FillPolygon) (pDraw, pGC, stuff->shape, stuff->coordMode, things, @@ -2079,8 +2099,8 @@ ProcPutImage(ClientPtr client) tmpImage = (char *)&stuff[1]; lengthProto = length; - if (((((lengthProto * stuff->height) + (unsigned)3) >> 2) + - (sizeof(xPutImageReq) >> 2)) != client->req_len) + if ((bytes_to_int32(lengthProto * stuff->height) + + bytes_to_int32(sizeof(xPutImageReq))) != client->req_len) return BadLength; ReformatImage (tmpImage, lengthProto * stuff->height, @@ -2099,9 +2119,11 @@ DoGetImage(ClientPtr client, int format, Drawable drawable, int x, int y, int width, int height, Mask planemask, xGetImageReply **im_return) { - DrawablePtr pDraw; + DrawablePtr pDraw, pBoundingDraw; int nlines, linesPerBuf, rc; - int linesDone; + int linesDone; + /* coordinates relative to the bounding drawable */ + int relx, rely; long widthBytesLine, length; Mask plane = 0; char *pBuf; @@ -2118,35 +2140,59 @@ DoGetImage(ClientPtr client, int format, Drawable drawable, return rc; memset(&xgi, 0, sizeof(xGetImageReply)); + + relx = x; + rely = y; + if(pDraw->type == DRAWABLE_WINDOW) { - if( /* check for being viewable */ - !((WindowPtr) pDraw)->realized || - /* check for being on screen */ - pDraw->x + x < 0 || - pDraw->x + x + width > pDraw->pScreen->width || - pDraw->y + y < 0 || - pDraw->y + y + height > pDraw->pScreen->height || - /* check for being inside of border */ - x < - wBorderWidth((WindowPtr)pDraw) || - x + width > wBorderWidth((WindowPtr)pDraw) + (int)pDraw->width || - y < -wBorderWidth((WindowPtr)pDraw) || - y + height > wBorderWidth ((WindowPtr)pDraw) + (int)pDraw->height - ) - return(BadMatch); - xgi.visual = wVisual (((WindowPtr) pDraw)); + WindowPtr pWin = (WindowPtr)pDraw; + + /* "If the drawable is a window, the window must be viewable ... or a + * BadMatch error results" */ + if (!pWin->viewable) + return BadMatch; + + relx += pDraw->x; + rely += pDraw->y; + + if (pDraw->pScreen->GetWindowPixmap) { + PixmapPtr pPix = (*pDraw->pScreen->GetWindowPixmap) (pWin); + + pBoundingDraw = &pPix->drawable; +#ifdef COMPOSITE + relx -= pPix->screen_x; + rely -= pPix->screen_y; +#endif + } + else + { + pBoundingDraw = (DrawablePtr)WindowTable[pDraw->pScreen->myNum]; + } + + xgi.visual = wVisual (pWin); } else { - if(x < 0 || - x+width > (int)pDraw->width || - y < 0 || - y+height > (int)pDraw->height - ) - return(BadMatch); + pBoundingDraw = pDraw; xgi.visual = None; } + /* "If the drawable is a pixmap, the given rectangle must be wholly + * contained within the pixmap, or a BadMatch error results. If the + * drawable is a window [...] it must be the case that if there were no + * inferiors or overlapping windows, the specified rectangle of the window + * would be fully visible on the screen and wholly contained within the + * outside edges of the window, or a BadMatch error results." + * + * We relax the window case slightly to mean that the rectangle must exist + * within the bounds of the window's backing pixmap. In particular, this + * means that a GetImage request may succeed or fail with BadMatch depending + * on whether any of its ancestor windows are redirected. */ + if(relx < 0 || relx + width > (int)pBoundingDraw->width || + rely < 0 || rely + height > (int)pBoundingDraw->height) + return BadMatch; + xgi.type = X_Reply; xgi.sequenceNumber = client->sequence; xgi.depth = pDraw->depth; @@ -2180,7 +2226,7 @@ DoGetImage(ClientPtr client, int format, Drawable drawable, *(xGetImageReply *)pBuf = xgi; pBuf += sz_xGetImageReply; } else { - xgi.length = (xgi.length + 3) >> 2; + xgi.length = bytes_to_int32(xgi.length); if (widthBytesLine == 0 || height == 0) linesPerBuf = 0; else if (widthBytesLine >= IMAGE_BUFSIZE) @@ -2742,7 +2788,7 @@ ProcAllocColorCells (ClientPtr client) #endif { accr.type = X_Reply; - accr.length = length >> 2; + accr.length = bytes_to_int32(length); accr.sequenceNumber = client->sequence; accr.nPixels = npixels; accr.nMasks = nmasks; @@ -2806,7 +2852,7 @@ ProcAllocColorPlanes(ClientPtr client) else return rc; } - acpr.length = length >> 2; + acpr.length = bytes_to_int32(length); #ifdef PANORAMIX if (noPanoramiXExtension || !pcmp->pScreen->myNum) #endif @@ -2841,7 +2887,7 @@ ProcFreeColors(ClientPtr client) if(pcmp->flags & AllAllocated) return(BadAccess); - count = ((client->req_len << 2)- sizeof(xFreeColorsReq)) >> 2; + count = bytes_to_int32((client->req_len << 2) - sizeof(xFreeColorsReq)); rc = FreeColors(pcmp, client->index, count, (Pixel *)&stuff[1], (Pixel)stuff->planeMask); if (client->noClientException != Success) @@ -2944,7 +2990,7 @@ ProcQueryColors(ClientPtr client) xrgb *prgbs; xQueryColorsReply qcr; - count = ((client->req_len << 2) - sizeof(xQueryColorsReq)) >> 2; + count = bytes_to_int32((client->req_len << 2) - sizeof(xQueryColorsReq)); prgbs = xcalloc(1, count * sizeof(xrgb)); if(!prgbs && count) return(BadAlloc); @@ -2961,7 +3007,7 @@ ProcQueryColors(ClientPtr client) } memset(&qcr, 0, sizeof(xQueryColorsReply)); qcr.type = X_Reply; - qcr.length = (count * sizeof(xrgb)) >> 2; + qcr.length = bytes_to_int32(count * sizeof(xrgb)); qcr.sequenceNumber = client->sequence; qcr.nColors = count; WriteReplyToClient(client, sizeof(xQueryColorsReply), &qcr); @@ -3331,7 +3377,7 @@ ProcListHosts(ClientPtr client) reply.type = X_Reply; reply.sequenceNumber = client->sequence; reply.nHosts = nHosts; - reply.length = len >> 2; + reply.length = bytes_to_int32(len); WriteReplyToClient(client, sizeof(xListHostsReply), &reply); if (nHosts) { @@ -3464,7 +3510,7 @@ ProcGetFontPath(ClientPtr client) reply.type = X_Reply; reply.sequenceNumber = client->sequence; - reply.length = (stringLens + numpaths + 3) >> 2; + reply.length = bytes_to_int32(stringLens + numpaths); reply.nPaths = numpaths; WriteReplyToClient(client, sizeof(xGetFontPathReply), &reply); @@ -3693,7 +3739,7 @@ ClientPtr NextAvailableClient(pointer ospriv) return (ClientPtr)NULL; } data.reqType = 1; - data.length = (sz_xReq + sz_xConnClientPrefix) >> 2; + data.length = bytes_to_int32(sz_xReq + sz_xConnClientPrefix); if (!InsertFakeRequest(client, (char *)&data, sz_xReq)) { FreeClientResources(client); @@ -3733,8 +3779,8 @@ ProcInitialConnection(ClientPtr client) SwapConnClientPrefix(prefix); } stuff->reqType = 2; - stuff->length += ((prefix->nbytesAuthProto + (unsigned)3) >> 2) + - ((prefix->nbytesAuthString + (unsigned)3) >> 2); + stuff->length += bytes_to_int32(prefix->nbytesAuthProto) + + bytes_to_int32(prefix->nbytesAuthString); if (client->swapped) { swaps(&stuff->length, whichbyte); @@ -3758,7 +3804,7 @@ SendConnSetup(ClientPtr client, char *reason) csp.success = xFalse; csp.lengthReason = strlen(reason); - csp.length = (csp.lengthReason + (unsigned)3) >> 2; + csp.length = bytes_to_int32(csp.lengthReason); csp.majorVersion = X_PROTOCOL; csp.minorVersion = X_PROTOCOL_REVISION; if (client->swapped) @@ -3849,7 +3895,7 @@ ProcEstablishConnection(ClientPtr client) prefix = (xConnClientPrefix *)((char *)stuff + sz_xReq); auth_proto = (char *)prefix + sz_xConnClientPrefix; - auth_string = auth_proto + ((prefix->nbytesAuthProto + 3) & ~3); + auth_string = auth_proto + pad_to_int32(prefix->nbytesAuthProto); if ((prefix->majorVersion != X_PROTOCOL) || (prefix->minorVersion != X_PROTOCOL_REVISION)) reason = "Protocol version mismatch"; diff --git a/dix/dixfonts.c b/dix/dixfonts.c index 8b6e7a329..7d7ae71de 100644 --- a/dix/dixfonts.c +++ b/dix/dixfonts.c @@ -792,7 +792,7 @@ finish: memset(&reply, 0, sizeof(xListFontsReply)); reply.type = X_Reply; - reply.length = (stringLens + nnames + 3) >> 2; + reply.length = bytes_to_int32(stringLens + nnames); reply.nFonts = nnames; reply.sequenceNumber = client->sequence; @@ -817,7 +817,7 @@ finish: } } nnames = reply.nFonts; - reply.length = (stringLens + nnames + 3) >> 2; + reply.length = bytes_to_int32(stringLens + nnames); client->pSwapReplyFunc = ReplySwapVector[X_ListFonts]; WriteSwappedDataToClient(client, sizeof(xListFontsReply), &reply); (void) WriteToClient(client, stringLens + nnames, bufferStart); @@ -1057,9 +1057,9 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c) namelen = strlen(name); } reply->type = X_Reply; - reply->length = (sizeof *reply - sizeof(xGenericReply) + + reply->length = bytes_to_int32(sizeof *reply - sizeof(xGenericReply) + pFontInfo->nprops * sizeof(xFontProp) + - namelen + 3) >> 2; + namelen); reply->sequenceNumber = client->sequence; reply->nameLength = namelen; reply->minBounds = pFontInfo->ink_minbounds; @@ -1097,8 +1097,8 @@ finish: bzero((char *) &finalReply, sizeof(xListFontsWithInfoReply)); finalReply.type = X_Reply; finalReply.sequenceNumber = client->sequence; - finalReply.length = (sizeof(xListFontsWithInfoReply) - - sizeof(xGenericReply)) >> 2; + finalReply.length = bytes_to_int32(sizeof(xListFontsWithInfoReply) + - sizeof(xGenericReply)); WriteSwappedDataToClient(client, length, &finalReply); bail: if (c->slept) diff --git a/dix/enterleave.c b/dix/enterleave.c index 488a94388..c08cc3100 100644 --- a/dix/enterleave.c +++ b/dix/enterleave.c @@ -166,8 +166,8 @@ EnterWindow(DeviceIntPtr dev, WindowPtr win, int mode) /** * Unset the presence flag for dev to mark that it is not in 'win' anymore. */ -static void -LeaveWindow(DeviceIntPtr dev, WindowPtr win, int mode) +void +LeaveWindow(DeviceIntPtr dev) { PointerWindows[dev->id] = NULL; } @@ -185,7 +185,7 @@ SetFocusIn(DeviceIntPtr dev, WindowPtr win) * Unset the presence flag for dev to mark that it is not in 'win' anymore. */ void -SetFocusOut(DeviceIntPtr dev, WindowPtr win) +SetFocusOut(DeviceIntPtr dev) { FocusWindows[dev->id] = NULL; } @@ -215,11 +215,10 @@ CommonAncestor( * Send enter notifies to all windows between 'ancestor' and 'child' (excluding * both). Events are sent running up the window hierarchy. This function * recurses. - * - * @param core If TRUE, core events are sent, otherwise XI events will be sent. */ static void DeviceEnterNotifies(DeviceIntPtr dev, + int sourceid, WindowPtr ancestor, WindowPtr child, int mode, @@ -229,8 +228,8 @@ DeviceEnterNotifies(DeviceIntPtr dev, if (ancestor == parent) return; - DeviceEnterNotifies(dev, ancestor, parent, mode, detail); - DeviceEnterLeaveEvent(dev, XI_Enter, mode, detail, parent, + DeviceEnterNotifies(dev, sourceid, ancestor, parent, mode, detail); + DeviceEnterLeaveEvent(dev, sourceid, XI_Enter, mode, detail, parent, child->drawable.id); } @@ -325,6 +324,7 @@ CoreLeaveNotifies(DeviceIntPtr dev, */ static void DeviceLeaveNotifies(DeviceIntPtr dev, + int sourceid, WindowPtr child, WindowPtr ancestor, int mode, @@ -336,7 +336,7 @@ DeviceLeaveNotifies(DeviceIntPtr dev, return; for (win = child->parent; win != ancestor; win = win->parent) { - DeviceEnterLeaveEvent(dev, XI_Leave, mode, detail, win, + DeviceEnterLeaveEvent(dev, sourceid, XI_Leave, mode, detail, win, child->drawable.id); child = win; } @@ -550,7 +550,7 @@ CoreEnterLeaveEvents(DeviceIntPtr dev, if (!IsMaster(dev)) return; - LeaveWindow(dev, from, mode); + LeaveWindow(dev); if (IsParent(from, to)) CoreEnterLeaveToDescendant(dev, from, to, mode); @@ -564,30 +564,31 @@ CoreEnterLeaveEvents(DeviceIntPtr dev, static void DeviceEnterLeaveEvents(DeviceIntPtr dev, + int sourceid, WindowPtr from, WindowPtr to, int mode) { if (IsParent(from, to)) { - DeviceEnterLeaveEvent(dev, XI_Leave, mode, NotifyInferior, from, None); - DeviceEnterNotifies(dev, from, to, mode, NotifyVirtual); - DeviceEnterLeaveEvent(dev, XI_Enter, mode, NotifyAncestor, to, None); + DeviceEnterLeaveEvent(dev, sourceid, XI_Leave, mode, NotifyInferior, from, None); + DeviceEnterNotifies(dev, sourceid, from, to, mode, NotifyVirtual); + DeviceEnterLeaveEvent(dev, sourceid, XI_Enter, mode, NotifyAncestor, to, None); } else if (IsParent(to, from)) { - DeviceEnterLeaveEvent(dev, XI_Leave, mode, NotifyAncestor, from, None); - DeviceLeaveNotifies(dev, from, to, mode, NotifyVirtual); - DeviceEnterLeaveEvent(dev, XI_Enter, mode, NotifyInferior, to, None); + DeviceEnterLeaveEvent(dev, sourceid, XI_Leave, mode, NotifyAncestor, from, None); + DeviceLeaveNotifies(dev, sourceid, from, to, mode, NotifyVirtual); + DeviceEnterLeaveEvent(dev, sourceid, XI_Enter, mode, NotifyInferior, to, None); } else { /* neither from nor to is descendent of the other */ WindowPtr common = CommonAncestor(to, from); /* common == NullWindow ==> different screens */ - DeviceEnterLeaveEvent(dev, XI_Leave, mode, NotifyNonlinear, from, None); - DeviceLeaveNotifies(dev, from, common, mode, NotifyNonlinearVirtual); - DeviceEnterNotifies(dev, common, to, mode, NotifyNonlinearVirtual); - DeviceEnterLeaveEvent(dev, XI_Enter, mode, NotifyNonlinear, to, None); + DeviceEnterLeaveEvent(dev, sourceid, XI_Leave, mode, NotifyNonlinear, from, None); + DeviceLeaveNotifies(dev, sourceid, from, common, mode, NotifyNonlinearVirtual); + DeviceEnterNotifies(dev, sourceid, common, to, mode, NotifyNonlinearVirtual); + DeviceEnterLeaveEvent(dev, sourceid, XI_Enter, mode, NotifyNonlinear, to, None); } } @@ -600,6 +601,7 @@ DeviceEnterLeaveEvents(DeviceIntPtr dev, */ void DoEnterLeaveEvents(DeviceIntPtr pDev, + int sourceid, WindowPtr fromWin, WindowPtr toWin, int mode) @@ -612,7 +614,7 @@ DoEnterLeaveEvents(DeviceIntPtr pDev, if (mode != XINotifyPassiveGrab && mode != XINotifyPassiveUngrab) CoreEnterLeaveEvents(pDev, fromWin, toWin, mode); - DeviceEnterLeaveEvents(pDev, fromWin, toWin, mode); + DeviceEnterLeaveEvents(pDev, sourceid, fromWin, toWin, mode); } /** @@ -1221,7 +1223,7 @@ CoreFocusEvents(DeviceIntPtr dev, if (!IsMaster(dev)) return; - SetFocusOut(dev, from); + SetFocusOut(dev); if (((to == NullWindow) || (to == PointerRootWin)) && ((from == NullWindow) || (from == PointerRootWin))) diff --git a/dix/enterleave.h b/dix/enterleave.h index edca38664..471f4efaa 100644 --- a/dix/enterleave.h +++ b/dix/enterleave.h @@ -33,6 +33,7 @@ extern void DoEnterLeaveEvents( DeviceIntPtr pDev, + int sourceid, WindowPtr fromWin, WindowPtr toWin, int mode @@ -64,6 +65,7 @@ extern void CoreEnterLeaveEvent(DeviceIntPtr mouse, WindowPtr pWin, Window child); extern void DeviceEnterLeaveEvent(DeviceIntPtr mouse, + int sourceid, int type, int mode, int detail, @@ -74,6 +76,7 @@ extern void EnterWindow(DeviceIntPtr dev, WindowPtr win, int mode); +extern void LeaveWindow(DeviceIntPtr dev); extern void CoreFocusEvent(DeviceIntPtr kbd, int type, @@ -90,6 +93,5 @@ extern void DeviceFocusEvent(DeviceIntPtr kbd, extern void SetFocusIn(DeviceIntPtr kbd, WindowPtr win); -extern void SetFocusOut(DeviceIntPtr dev, - WindowPtr win); +extern void SetFocusOut(DeviceIntPtr dev); #endif /* _ENTERLEAVE_H_ */ diff --git a/dix/eventconvert.c b/dix/eventconvert.c index ac2b0c310..21eed40e1 100644 --- a/dix/eventconvert.c +++ b/dix/eventconvert.c @@ -42,7 +42,7 @@ #include "dix.h" #include "inputstr.h" #include "misc.h" -#include "events.h" +#include "eventstr.h" #include "exglobals.h" #include "eventconvert.h" #include "xiquerydevice.h" @@ -52,9 +52,38 @@ static int countValuators(DeviceEvent *ev, int *first); static int getValuatorEvents(DeviceEvent *ev, deviceValuator *xv); static int eventToKeyButtonPointer(DeviceEvent *ev, xEvent **xi, int *count); -static int eventToClassesChanged(DeviceChangedEvent *ev, xEvent **dcce); +static int eventToDeviceChanged(DeviceChangedEvent *ev, xEvent **dcce); static int eventToDeviceEvent(DeviceEvent *ev, xEvent **xi); static int eventToRawEvent(RawDeviceEvent *ev, xEvent **xi); + +/* Do not use, read comments below */ +BOOL EventIsKeyRepeat(xEvent *event); + +/** + * Hack to allow detectable autorepeat for core and XI1 events. + * The sequence number is unused until we send to the client and can be + * misused to store data. More or less, anyway. + * + * Do not use this. It may change any time without warning, eat your babies + * and piss on your cat. + */ +static void +EventSetKeyRepeatFlag(xEvent *event, BOOL on) +{ + event->u.u.sequenceNumber = on; +} + +/** + * Check if the event was marked as a repeat event before. + * NOTE: This is a nasty hack and should NOT be used by anyone else but + * TryClientEvents. + */ +BOOL +EventIsKeyRepeat(xEvent *event) +{ + return !!event->u.u.sequenceNumber; +} + /** * Convert the given event to the respective core event. * @@ -90,11 +119,16 @@ EventToCore(InternalEvent *event, xEvent *core) core->u.keyButtonPointer.rootX = e->root_x; core->u.keyButtonPointer.rootY = e->root_y; core->u.keyButtonPointer.state = e->corestate; + EventSetKeyRepeatFlag(core, (e->type == ET_KeyPress && e->key_repeat)); } break; case ET_ProximityIn: case ET_ProximityOut: - case ET_Raw: + case ET_RawKeyPress: + case ET_RawKeyRelease: + case ET_RawButtonPress: + case ET_RawButtonRelease: + case ET_RawMotion: return BadMatch; default: /* XXX: */ @@ -135,10 +169,16 @@ EventToXI(InternalEvent *ev, xEvent **xi, int *count) case ET_ProximityOut: return eventToKeyButtonPointer((DeviceEvent*)ev, xi, count); case ET_DeviceChanged: - case ET_Raw: + case ET_RawKeyPress: + case ET_RawKeyRelease: + case ET_RawButtonPress: + case ET_RawButtonRelease: + case ET_RawMotion: *count = 0; *xi = NULL; return BadMatch; + default: + break; } ErrorF("[dix] EventToXI: Not implemented for %d \n", ev->any.type); @@ -181,10 +221,15 @@ EventToXI2(InternalEvent *ev, xEvent **xi) *xi = NULL; return BadMatch; case ET_DeviceChanged: - return eventToClassesChanged((DeviceChangedEvent*)ev, xi); - case ET_Raw: + return eventToDeviceChanged((DeviceChangedEvent*)ev, xi); + case ET_RawKeyPress: + case ET_RawKeyRelease: + case ET_RawButtonPress: + case ET_RawButtonRelease: + case ET_RawMotion: return eventToRawEvent((RawDeviceEvent*)ev, xi); - + default: + break; } ErrorF("[dix] EventToXI2: Not implemented for %d \n", ev->any.type); @@ -222,6 +267,8 @@ eventToKeyButtonPointer(DeviceEvent *ev, xEvent **xi, int *count) kbp->root_y = ev->root_y; kbp->deviceid = ev->deviceid; kbp->state = ev->corestate; + EventSetKeyRepeatFlag((xEvent*)kbp, + (ev->type == ET_KeyPress && ev->key_repeat)); if (num_events > 1) kbp->deviceid |= MORE_EVENTS; @@ -235,6 +282,8 @@ eventToKeyButtonPointer(DeviceEvent *ev, xEvent **xi, int *count) case ET_KeyRelease: kbp->type = DeviceKeyRelease; break; case ET_ProximityIn: kbp->type = ProximityIn; break; case ET_ProximityOut: kbp->type = ProximityOut; break; + default: + break; } if (num_events > 1) @@ -323,38 +372,135 @@ getValuatorEvents(DeviceEvent *ev, deviceValuator *xv) return (num_valuators + 5) / 6; } + static int -eventToClassesChanged(DeviceChangedEvent *ev, xEvent **xi) +appendKeyInfo(DeviceChangedEvent *dce, xXIKeyInfo* info) { - int len = sizeof(xEvent); - DeviceIntPtr slave; - int rc; - xXIDeviceChangedEvent *dce; + uint32_t *kc; + int i; - rc = dixLookupDevice(&slave, ev->new_slaveid, - serverClient, DixReadAccess); + info->type = XIKeyClass; + info->num_keycodes = dce->keys.max_keycode - dce->keys.min_keycode + 1; + info->length = sizeof(xXIKeyInfo)/4 + info->num_keycodes; + info->sourceid = dce->sourceid; - if (rc != Success) - return rc; + kc = (uint32_t*)&info[1]; + for (i = 0; i < info->num_keycodes; i++) + *kc++ = i + dce->keys.min_keycode; - len += SizeDeviceClasses(slave); + return info->length * 4; +} - *xi = xcalloc(1, len); - if (!(*xi)) +static int +appendButtonInfo(DeviceChangedEvent *dce, xXIButtonInfo *info) +{ + unsigned char *bits; + int mask_len; + + mask_len = bytes_to_int32(bits_to_bytes(dce->buttons.num_buttons)); + + info->type = XIButtonClass; + info->num_buttons = dce->buttons.num_buttons; + info->length = bytes_to_int32(sizeof(xXIButtonInfo)) + + info->num_buttons + mask_len; + info->sourceid = dce->sourceid; + + bits = (unsigned char*)&info[1]; + memset(bits, 0, mask_len * 4); + /* FIXME: is_down? */ + + bits += mask_len * 4; + memcpy(bits, dce->buttons.names, dce->buttons.num_buttons * sizeof(Atom)); + + return info->length * 4; +} + +static int +appendValuatorInfo(DeviceChangedEvent *dce, xXIValuatorInfo *info, int axisnumber) +{ + info->type = XIValuatorClass; + info->length = sizeof(xXIValuatorInfo)/4; + info->label = dce->valuators[axisnumber].name; + info->min.integral = dce->valuators[axisnumber].min; + info->min.frac = 0; + info->max.integral = dce->valuators[axisnumber].max; + info->max.frac = 0; + /* FIXME: value */ + info->value.integral = 0; + info->value.frac = 0; + info->resolution = dce->valuators[axisnumber].resolution; + info->number = axisnumber; + info->mode = dce->valuators[axisnumber].mode; /* Server doesn't have per-axis mode yet */ + info->sourceid = dce->sourceid; + + return info->length * 4; +} + +static int +eventToDeviceChanged(DeviceChangedEvent *dce, xEvent **xi) +{ + xXIDeviceChangedEvent *dcce; + int len = sizeof(xXIDeviceChangedEvent); + int nkeys; + char *ptr; + + if (dce->buttons.num_buttons) + { + len += sizeof(xXIButtonInfo); + len += dce->buttons.num_buttons * sizeof(Atom); /* button names */ + len += pad_to_int32(bits_to_bytes(dce->buttons.num_buttons)); + } + if (dce->num_valuators) + len += sizeof(xXIValuatorInfo) * dce->num_valuators; + + nkeys = (dce->keys.max_keycode > 0) ? + dce->keys.max_keycode - dce->keys.min_keycode + 1 : 0; + if (nkeys > 0) + { + len += sizeof(xXIKeyInfo); + len += sizeof(CARD32) * nkeys; /* keycodes */ + } + + dcce = xcalloc(1, len); + if (!dcce) + { + ErrorF("[Xi] BadAlloc in SendDeviceChangedEvent.\n"); return BadAlloc; + } + + dcce->type = GenericEvent; + dcce->extension = IReqCode; + dcce->evtype = XI_DeviceChanged; + dcce->time = dce->time; + dcce->deviceid = dce->deviceid; + dcce->sourceid = dce->sourceid; + dcce->reason = (dce->flags & DEVCHANGE_DEVICE_CHANGE) ? XIDeviceChange : XISlaveSwitch; + dcce->num_classes = 0; + dcce->length = bytes_to_int32(len - sizeof(xEvent)); + + ptr = (char*)&dcce[1]; + if (dce->buttons.num_buttons) + { + dcce->num_classes++; + ptr += appendButtonInfo(dce, (xXIButtonInfo*)ptr); + } + + if (nkeys) + { + dcce->num_classes++; + ptr += appendKeyInfo(dce, (xXIKeyInfo*)ptr); + } - dce = (xXIDeviceChangedEvent*)(*xi); - dce->type = GenericEvent; - dce->extension = IReqCode; - dce->evtype = XI_DeviceChanged; - dce->time = GetTimeInMillis(); - dce->sourceid = slave->id; - dce->reason = XISlaveSwitch; - dce->length = (len - sizeof(xEvent))/4; + if (dce->num_valuators) + { + int i; + + dcce->num_classes += dce->num_valuators; + for (i = 0; i < dce->num_valuators; i++) + ptr += appendValuatorInfo(dce, (xXIValuatorInfo*)ptr, i); + } - /* FIXME: this should come from the event, not from the device. See - * CreateClassesChangedEvent */ - ListDeviceClasses(slave, (char*)&dce[1], &dce->num_classes); + *xi = (xEvent*)dcce; return Success; } @@ -389,13 +535,13 @@ eventToDeviceEvent(DeviceEvent *ev, xEvent **xi) /* FIXME: this should just send the buttons we have, not MAX_BUTTONs. Same * with MAX_VALUATORS below */ /* btlen is in 4 byte units */ - btlen = (((MAX_BUTTONS + 7)/8) + 3)/4; + btlen = bytes_to_int32(bits_to_bytes(MAX_BUTTONS)); len += btlen * 4; /* buttonmask len */ vallen = count_bits(ev->valuators.mask, sizeof(ev->valuators.mask)/sizeof(ev->valuators.mask[0])); len += vallen * 2 * sizeof(uint32_t); /* axisvalues */ - vallen = (((MAX_VALUATORS + 7)/8) + 3)/4; + vallen = bytes_to_int32(bits_to_bytes(MAX_VALUATORS)); len += vallen * 4; /* valuators mask */ *xi = xcalloc(1, len); @@ -404,7 +550,7 @@ eventToDeviceEvent(DeviceEvent *ev, xEvent **xi) xde->extension = IReqCode; xde->evtype = GetXI2Type((InternalEvent*)ev); xde->time = ev->time; - xde->length = (len - sizeof(xEvent) + 3)/4; + xde->length = bytes_to_int32(len - sizeof(xEvent)); xde->detail = ev->detail.button; xde->root = ev->root; xde->buttons_len = btlen; @@ -414,13 +560,18 @@ eventToDeviceEvent(DeviceEvent *ev, xEvent **xi) xde->root_x = FP1616(ev->root_x, ev->root_x_frac); xde->root_y = FP1616(ev->root_y, ev->root_y_frac); + if (ev->key_repeat) + xde->flags |= XIKeyRepeat; + xde->mods.base_mods = ev->mods.base; xde->mods.latched_mods = ev->mods.latched; xde->mods.locked_mods = ev->mods.locked; + xde->mods.effective_mods = ev->mods.effective; xde->group.base_group = ev->group.base; xde->group.latched_group = ev->group.latched; xde->group.locked_group = ev->group.locked; + xde->group.effective_group = ev->group.effective; ptr = (char*)&xde[1]; for (i = 0; i < sizeof(ev->buttons) * 8; i++) @@ -454,10 +605,10 @@ eventToRawEvent(RawDeviceEvent *ev, xEvent **xi) char *ptr; FP3232 *axisval; - nvals = count_bits(ev->valuators.mask, sizeof(ev->valuators.mask)/sizeof(ev->valuators.mask[0])); - len += nvals * (2 * sizeof(uint32_t)) * 2; /* 8 byte per valuator, once - raw, once processed */ - vallen = (((MAX_VALUATORS + 7)/8) + 3)/4; + nvals = count_bits(ev->valuators.mask, sizeof(ev->valuators.mask)); + len += nvals * sizeof(FP3232) * 2; /* 8 byte per valuator, once + raw, once processed */ + vallen = bytes_to_int32(bits_to_bytes(MAX_VALUATORS)); len += vallen * 4; /* valuators mask */ *xi = xcalloc(1, len); @@ -466,8 +617,7 @@ eventToRawEvent(RawDeviceEvent *ev, xEvent **xi) raw->extension = IReqCode; raw->evtype = GetXI2Type((InternalEvent*)ev); raw->time = ev->time; - raw->length = (len - sizeof(xEvent) + 3)/4; - raw->eventtype = ev->subtype; + raw->length = bytes_to_int32(len - sizeof(xEvent)); raw->detail = ev->detail.button; raw->deviceid = ev->deviceid; raw->valuators_len = vallen; @@ -505,6 +655,8 @@ GetCoreType(InternalEvent *event) case ET_ButtonRelease: coretype = ButtonRelease; break; case ET_KeyPress: coretype = KeyPress; break; case ET_KeyRelease: coretype = KeyRelease; break; + default: + break; } return coretype; } @@ -526,6 +678,8 @@ GetXIType(InternalEvent *event) case ET_KeyRelease: xitype = DeviceKeyRelease; break; case ET_ProximityIn: xitype = ProximityIn; break; case ET_ProximityOut: xitype = ProximityOut; break; + default: + break; } return xitype; } @@ -550,7 +704,11 @@ GetXI2Type(InternalEvent *event) case ET_Leave: xi2type = XI_Leave; break; case ET_Hierarchy: xi2type = XI_HierarchyChanged; break; case ET_DeviceChanged: xi2type = XI_DeviceChanged; break; - case ET_Raw: xi2type = XI_RawEvent; break; + case ET_RawKeyPress: xi2type = XI_RawKeyPress; break; + case ET_RawKeyRelease: xi2type = XI_RawKeyRelease; break; + case ET_RawButtonPress: xi2type = XI_RawButtonPress; break; + case ET_RawButtonRelease: xi2type = XI_RawButtonRelease; break; + case ET_RawMotion: xi2type = XI_RawMotion; break; case ET_FocusIn: xi2type = XI_FocusIn; break; case ET_FocusOut: xi2type = XI_FocusOut; break; default: diff --git a/dix/events.c b/dix/events.c index 87d2ef746..bb5520af9 100644 --- a/dix/events.c +++ b/dix/events.c @@ -117,7 +117,6 @@ of the copyright holder. #endif #include <X11/X.h> -#include <X11/keysym.h> #include "misc.h" #include "resource.h" #include <X11/Xproto.h> @@ -135,9 +134,6 @@ of the copyright holder. #include <X11/extensions/XKBproto.h> #include "xkbsrv.h" -/* XKB FIXME: why is this here? */ -extern Bool XkbFilterEvents(ClientPtr, int, xEvent *); - #include "xace.h" #ifdef XSERVER_DTRACE @@ -167,6 +163,7 @@ typedef const char *string; #include "geext.h" #include "geint.h" +#include "eventstr.h" #include "enterleave.h" #include "eventconvert.h" @@ -233,6 +230,9 @@ static Bool CheckPassiveGrabsOnWindow(WindowPtr pWin, DeviceEvent *event, BOOL checkCore); +/** Key repeat hack. Do not use but in TryClientEvents */ +extern BOOL EventIsKeyRepeat(xEvent *event); + /** * Main input device struct. * inputInfo.pointer @@ -1551,7 +1551,8 @@ ActivatePointerGrab(DeviceIntPtr mouse, GrabPtr grab, Bool isPassive = autoGrab & ~ImplicitGrabMask; /* slave devices need to float for the duration of the grab. */ - if (!(autoGrab & ImplicitGrabMask) && !IsMaster(mouse)) + if (grab->grabtype == GRABTYPE_XI2 && + !(autoGrab & ImplicitGrabMask) && !IsMaster(mouse)) DetachFromMaster(mouse); if (grab->confineTo) @@ -1562,7 +1563,7 @@ ActivatePointerGrab(DeviceIntPtr mouse, GrabPtr grab, mouse->spriteInfo->sprite->hotPhys.y = 0; ConfineCursorToWindow(mouse, grab->confineTo, FALSE, TRUE); } - DoEnterLeaveEvents(mouse, oldWin, grab->window, NotifyGrab); + DoEnterLeaveEvents(mouse, mouse->id, oldWin, grab->window, NotifyGrab); mouse->valuator->motionHintWindow = NullWindow; if (syncEvents.playingEvents) grabinfo->grabTime = syncEvents.time; @@ -1601,7 +1602,7 @@ DeactivatePointerGrab(DeviceIntPtr mouse) if (dev->deviceGrab.sync.other == grab) dev->deviceGrab.sync.other = NullGrab; } - DoEnterLeaveEvents(mouse, grab->window, + DoEnterLeaveEvents(mouse, mouse->id, grab->window, mouse->spriteInfo->sprite->win, NotifyUngrab); if (grab->confineTo) ConfineCursorToWindow(mouse, RootWindow(mouse), FALSE, FALSE); @@ -1609,7 +1610,7 @@ DeactivatePointerGrab(DeviceIntPtr mouse) if (grab->cursor) FreeCursor(grab->cursor, (Cursor)0); - if (!wasImplicit) + if (!wasImplicit && grab->grabtype == GRABTYPE_XI2) ReattachToOldMaster(mouse); ComputeFreezes(); @@ -1627,7 +1628,9 @@ ActivateKeyboardGrab(DeviceIntPtr keybd, GrabPtr grab, TimeStamp time, Bool pass WindowPtr oldWin; /* slave devices need to float for the duration of the grab. */ - if (!(passive & ImplicitGrabMask) && !IsMaster(keybd)) + if (grab->grabtype == GRABTYPE_XI2 && + !(passive & ImplicitGrabMask) && + !IsMaster(keybd)) DetachFromMaster(keybd); if (grabinfo->grab) @@ -1680,7 +1683,7 @@ DeactivateKeyboardGrab(DeviceIntPtr keybd) } DoFocusEvents(keybd, grab->window, focusWin, NotifyUngrab); - if (!wasImplicit) + if (!wasImplicit && grab->grabtype == GRABTYPE_XI2) ReattachToOldMaster(keybd); ComputeFreezes(); @@ -1924,70 +1927,124 @@ TryClientEvents (ClientPtr client, DeviceIntPtr dev, xEvent *pEvents, int type; #ifdef DEBUG_EVENTS - ErrorF("[dix] Event([%d, %d], mask=0x%x), client=%d", - pEvents->u.u.type, pEvents->u.u.detail, mask, client->index); + ErrorF("[dix] Event([%d, %d], mask=0x%lx), client=%d%s", + pEvents->u.u.type, pEvents->u.u.detail, mask, + client ? client->index : -1, + (client && client->clientGone) ? " (gone)" : ""); #endif - if ((client) && (client != serverClient) && (!client->clientGone) && - ((filter == CantBeFiltered) || (mask & filter))) - { - if (grab && !SameClient(grab, client)) - return -1; /* don't send, but notify caller */ - type = pEvents->u.u.type; - if (type == MotionNotify) - { - if (mask & PointerMotionHintMask) - { - if (WID(dev->valuator->motionHintWindow) == - pEvents->u.keyButtonPointer.event) - { + + if (!client || client == serverClient || client->clientGone) { #ifdef DEBUG_EVENTS - ErrorF("[dix] \n"); - ErrorF("[dix] motionHintWindow == keyButtonPointer.event\n"); + ErrorF(" not delivered to fake/dead client\n"); #endif - return 1; /* don't send, but pretend we did */ - } - pEvents->u.u.detail = NotifyHint; - } - else - { - pEvents->u.u.detail = NotifyNormal; - } - } - else - { - if ((type == DeviceMotionNotify) && - MaybeSendDeviceMotionNotifyHint - ((deviceKeyButtonPointer*)pEvents, mask) != 0) - return 1; - } - type &= 0177; - if (type != KeymapNotify) - { - /* all extension events must have a sequence number */ - for (i = 0; i < count; i++) - pEvents[i].u.u.sequenceNumber = client->sequence; - } + return 0; + } - if (BitIsOn(criticalEvents, type)) - { - if (client->smart_priority < SMART_MAX_PRIORITY) - client->smart_priority++; - SetCriticalOutputPending(); - } + if (filter != CantBeFiltered && !(mask & filter)) + { + #ifdef DEBUG_EVENTS + ErrorF(" filtered\n"); + #endif + return 0; + } - WriteEventsToClient(client, count, pEvents); + if (grab && !SameClient(grab, client)) + { #ifdef DEBUG_EVENTS - ErrorF("[dix] delivered\n"); + ErrorF(" not delivered due to grab\n"); #endif - return 1; + return -1; /* don't send, but notify caller */ } - else + + type = pEvents->u.u.type; + if (type == MotionNotify) { + if (mask & PointerMotionHintMask) + { + if (WID(dev->valuator->motionHintWindow) == + pEvents->u.keyButtonPointer.event) + { #ifdef DEBUG_EVENTS - ErrorF("[dix] \n"); + ErrorF("[dix] \n"); + ErrorF("[dix] motionHintWindow == keyButtonPointer.event\n"); #endif - return 0; + return 1; /* don't send, but pretend we did */ + } + pEvents->u.u.detail = NotifyHint; + } + else + { + pEvents->u.u.detail = NotifyNormal; + } } + else if (type == DeviceMotionNotify) + { + if (MaybeSendDeviceMotionNotifyHint((deviceKeyButtonPointer*)pEvents, + mask) != 0) + return 1; + } else if (type == KeyPress) + { + if (EventIsKeyRepeat(pEvents)) + { + if (!_XkbWantsDetectableAutoRepeat(client)) + { + xEvent release = *pEvents; + release.u.u.type = KeyRelease; + release.u.u.sequenceNumber = client->sequence; + WriteEventsToClient(client, 1, &release); +#ifdef DEBUG_EVENTS + ErrorF(" (plus fake core release for repeat)"); +#endif + } else + { +#ifdef DEBUG_EVENTS + ErrorF(" (detectable autorepeat for core)"); +#endif + } + } + + } else if (type == DeviceKeyPress) + { + if (EventIsKeyRepeat(pEvents)) + { + if (!_XkbWantsDetectableAutoRepeat(client)) + { + deviceKeyButtonPointer release = *(deviceKeyButtonPointer *)pEvents; + release.type = DeviceKeyRelease; + release.sequenceNumber = client->sequence; +#ifdef DEBUG_EVENTS + ErrorF(" (plus fake xi1 release for repeat)"); +#endif + WriteEventsToClient(client, 1, (xEvent *) &release); + } + else { +#ifdef DEBUG_EVENTS + ErrorF(" (detectable autorepeat for core)"); +#endif + } + } + } + + type &= 0177; + if (type != KeymapNotify) + { + /* all extension events must have a sequence number */ + for (i = 0; i < count; i++) + pEvents[i].u.u.sequenceNumber = client->sequence; + } + + if (BitIsOn(criticalEvents, type)) + { + if (client->smart_priority < SMART_MAX_PRIORITY) + client->smart_priority++; + SetCriticalOutputPending(); + } + + WriteEventsToClient(client, count, pEvents); +#ifdef DEBUG_EVENTS + ErrorF("[dix] delivered\n"); +#endif + return 1; } @@ -2288,7 +2345,14 @@ FixUpEventFromWindow( { xXIDeviceEvent* event = (xXIDeviceEvent*)xE; - if (event->evtype == XI_RawEvent) + if (event->evtype == XI_RawKeyPress || + event->evtype == XI_RawKeyRelease || + event->evtype == XI_RawButtonPress || + event->evtype == XI_RawButtonRelease || + event->evtype == XI_RawMotion || + event->evtype == XI_DeviceChanged || + event->evtype == XI_HierarchyChanged || + event->evtype == XI_PropertyEvent) return; event->root = RootWindow(pDev)->drawable.id; @@ -2740,7 +2804,7 @@ ActivateFocusInGrab(DeviceIntPtr dev, WindowPtr old, WindowPtr win) if (dev->deviceGrab.grab->window == win || IsParent(dev->deviceGrab.grab->window, win)) return FALSE; - DoEnterLeaveEvents(dev, old, win, XINotifyPassiveUngrab); + DoEnterLeaveEvents(dev, dev->id, old, win, XINotifyPassiveUngrab); (*dev->deviceGrab.DeactivateGrab)(dev); } @@ -2757,7 +2821,7 @@ ActivateFocusInGrab(DeviceIntPtr dev, WindowPtr old, WindowPtr win) event.detail.button = 0; rc = CheckPassiveGrabsOnWindow(win, dev, &event, FALSE); if (rc) - DoEnterLeaveEvents(dev, old, win, XINotifyPassiveUngrab); + DoEnterLeaveEvents(dev, dev->id, old, win, XINotifyPassiveUngrab); return rc; } @@ -2780,7 +2844,7 @@ ActivateEnterGrab(DeviceIntPtr dev, WindowPtr old, WindowPtr win) if (dev->deviceGrab.grab->window == win || IsParent(dev->deviceGrab.grab->window, win)) return FALSE; - DoEnterLeaveEvents(dev, old, win, XINotifyPassiveUngrab); + DoEnterLeaveEvents(dev, dev->id, old, win, XINotifyPassiveUngrab); (*dev->deviceGrab.DeactivateGrab)(dev); } @@ -2794,7 +2858,7 @@ ActivateEnterGrab(DeviceIntPtr dev, WindowPtr old, WindowPtr win) event.detail.button = 0; rc = CheckPassiveGrabsOnWindow(win, dev, &event, FALSE); if (rc) - DoEnterLeaveEvents(dev, old, win, XINotifyPassiveGrab); + DoEnterLeaveEvents(dev, dev->id, old, win, XINotifyPassiveGrab); return rc; } @@ -2909,12 +2973,16 @@ CheckMotion(DeviceEvent *ev, DeviceIntPtr pDev) if (newSpriteWin != prevSpriteWin) { - if (!ev) + int sourceid; + if (!ev) { UpdateCurrentTimeIf(); + sourceid = pDev->id; /* when from WindowsRestructured */ + } else + sourceid = ev->sourceid; if (prevSpriteWin != NullWindow) { if (!ActivateEnterGrab(pDev, prevSpriteWin, newSpriteWin)) - DoEnterLeaveEvents(pDev, prevSpriteWin, + DoEnterLeaveEvents(pDev, sourceid, prevSpriteWin, newSpriteWin, NotifyNormal); } /* set pSprite->win after ActivateEnterGrab, otherwise @@ -2937,7 +3005,7 @@ WindowsRestructured(void) DeviceIntPtr pDev = inputInfo.devices; while(pDev) { - if (DevHasCursor(pDev)) + if (IsMaster(pDev) || !pDev->u.master) CheckMotion(NULL, pDev); pDev = pDev->next; } @@ -3543,6 +3611,7 @@ CheckPassiveGrabsOnWindow( { DeviceIntPtr gdev; XkbSrvInfoPtr xkbi = NULL; + Mask mask = 0; gdev= grab->modifierDevice; if (grab->grabtype == GRABTYPE_CORE) @@ -3570,8 +3639,6 @@ CheckPassiveGrabsOnWindow( /* Check for XI2 and XI grabs first */ tempGrab.type = GetXI2Type((InternalEvent*)event); tempGrab.grabtype = GRABTYPE_XI2; - if (event->type == ET_KeyPress) - tempGrab.detail.exact = XkbGetKeysym(device, event); if (GrabMatchesSecond(&tempGrab, grab, FALSE)) match = XI2_MATCH; @@ -3659,6 +3726,7 @@ CheckPassiveGrabsOnWindow( } xE = &core; count = 1; + mask = grab->eventMask; } else if (match & XI2_MATCH) { rc = EventToXI2((InternalEvent*)event, &xE); @@ -3670,6 +3738,16 @@ CheckPassiveGrabsOnWindow( continue; } count = 1; + + /* FIXME: EventToXI2 returns NULL for enter events, so + * dereferencing the event is bad. Internal event types are + * aligned with core events, so the else clause is valid. + * long-term we should use internal events for enter/focus + * as well */ + if (xE) + mask = grab->xi2mask[device->id][((xGenericEvent*)xE)->evtype/8]; + else if (event->type == XI_Enter || event->type == XI_FocusIn) + mask = grab->xi2mask[device->id][event->type/8]; } else { rc = EventToXI((InternalEvent*)event, &xE, &count); @@ -3680,6 +3758,7 @@ CheckPassiveGrabsOnWindow( "(%d, %d).\n", device->name, event->type, rc); continue; } + mask = grab->eventMask; } (*grabinfo->ActivateGrab)(device, grab, currentTime, TRUE); @@ -3688,8 +3767,7 @@ CheckPassiveGrabsOnWindow( { FixUpEventFromWindow(device, xE, grab->window, None, TRUE); - TryClientEvents(rClient(grab), device, xE, count, - GetEventFilter(device, xE), + TryClientEvents(rClient(grab), device, xE, count, mask, GetEventFilter(device, xE), grab); } @@ -4404,6 +4482,7 @@ CoreEnterLeaveEvent( void DeviceEnterLeaveEvent( DeviceIntPtr mouse, + int sourceid, int type, int mode, int detail, @@ -4420,8 +4499,8 @@ DeviceEnterLeaveEvent( (mode == XINotifyPassiveUngrab && type == XI_Enter)) return; - btlen = (mouse->button) ? (mouse->button->numButtons + 7)/8 : 0; - btlen = (btlen + 3)/4; + btlen = (mouse->button) ? bits_to_bytes(mouse->button->numButtons) : 0; + btlen = bytes_to_int32(btlen); len = sizeof(xXIEnterEvent) + btlen * 4; event = xcalloc(1, len); @@ -4433,7 +4512,7 @@ DeviceEnterLeaveEvent( event->detail = detail; event->time = currentTime.milliseconds; event->deviceid = mouse->id; - event->sourceid = 0; /*XXX */ + event->sourceid = sourceid; event->mode = mode; event->root_x = FP1616(mouse->spriteInfo->sprite->hot.x, 0); event->root_y = FP1616(mouse->spriteInfo->sprite->hot.y, 0); @@ -5261,7 +5340,7 @@ ProcUngrabKey(ClientPtr client) int rc; REQUEST_SIZE_MATCH(xUngrabKeyReq); - rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixReadAccess); + rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixGetAttrAccess); if (rc != Success) return rc; @@ -5729,8 +5808,8 @@ WriteEventsToClient(ClientPtr pClient, int count, xEvent *events) int i, eventlength = sizeof(xEvent); - if (!XkbFilterEvents(pClient, count, events)) - return; + /* Let XKB rewrite the state, as it depends on client preferences. */ + XkbFilterEvents(pClient, count, events); #ifdef PANORAMIX if(!noPanoramiXExtension && @@ -5842,21 +5921,25 @@ WriteEventsToClient(ClientPtr pClient, int count, xEvent *events) * PickPointer()). * If a keyboard is needed, the first keyboard paired with the CP is used. */ -Bool +int SetClientPointer(ClientPtr client, DeviceIntPtr device) { + int rc = XaceHook(XACE_DEVICE_ACCESS, client, device, DixUseAccess); + if (rc != Success) + return rc; + if (!IsMaster(device)) { ErrorF("[dix] Need master device for ClientPointer. This is a bug.\n"); - return FALSE; + return BadDevice; } else if (!device->spriteInfo->spriteOwner) { ErrorF("[dix] Device %d does not have a sprite. " "Cannot be ClientPointer\n", device->id); - return FALSE; + return BadDevice; } client->clientPtr = device; - return TRUE; + return Success; } /* PickPointer will pick an appropriate pointer for the given client. diff --git a/dix/extension.c b/dix/extension.c index c768ccb84..fb83af148 100644 --- a/dix/extension.c +++ b/dix/extension.c @@ -324,7 +324,7 @@ ProcListExtensions(ClientPtr client) for (j = extensions[i]->num_aliases; --j >= 0;) total_length += strlen(extensions[i]->aliases[j]) + 1; } - reply.length = (total_length + 3) >> 2; + reply.length = bytes_to_int32(total_length); buffer = bufptr = xalloc(total_length); if (!buffer) return(BadAlloc); diff --git a/dix/getevents.c b/dix/getevents.c index 7c018c14d..2912c1e85 100644 --- a/dix/getevents.c +++ b/dix/getevents.c @@ -43,7 +43,7 @@ #include "globals.h" #include "dixevents.h" #include "mipointer.h" -#include "events.h" +#include "eventstr.h" #include "eventconvert.h" #include <X11/extensions/XKBproto.h> @@ -138,14 +138,12 @@ init_event(DeviceIntPtr dev, DeviceEvent* event, Time ms) } static void -init_raw(DeviceIntPtr dev, RawDeviceEvent *event, Time ms, int subtype, - int detail) +init_raw(DeviceIntPtr dev, RawDeviceEvent *event, Time ms, int type, int detail) { memset(event, 0, sizeof(RawDeviceEvent)); event->header = ET_Internal; event->length = sizeof(RawDeviceEvent); - event->type = ET_Raw; - event->subtype = subtype; + event->type = ET_RawKeyPress - ET_KeyPress + type; event->time = ms; event->deviceid = dev->id; event->sourceid = dev->id; @@ -157,10 +155,9 @@ set_raw_valuators(RawDeviceEvent *event, int first, int num, int *valuators, int { int i; for (i = first; i < first + num; i++) - { SetBit(event->valuators.mask, i); - data[i] = valuators[i - first]; - } + + memcpy(&data[first], valuators, num * sizeof(uint32_t)); } @@ -175,8 +172,8 @@ set_valuators(DeviceIntPtr dev, DeviceEvent* event, int first_valuator, SetBit(event->valuators.mask, i); if (dev->valuator->mode == Absolute) SetBit(event->valuators.mode, i); - event->valuators.data_frac[first_valuator + i] = - dev->last.remainder[first_valuator + i] * (1 << 16) * (1 << 16); + event->valuators.data_frac[i] = + dev->last.remainder[i] * (1 << 16) * (1 << 16); } memcpy(&event->valuators.data[first_valuator], @@ -196,19 +193,15 @@ CreateClassesChangedEvent(EventList* event, dce = (DeviceChangedEvent*)event->event; memset(dce, 0, sizeof(DeviceChangedEvent)); - dce->deviceid = master->id; + dce->deviceid = slave->id; + dce->masterid = master->id; dce->header = ET_Internal; dce->length = sizeof(DeviceChangedEvent); dce->type = ET_DeviceChanged; dce->time = ms; dce->flags = type; - if (master->last.slave) - { - dce->flags |= DEVCHANGE_HAS_OLD_SLAVE; - dce->old_slaveid = master->last.slave->id; - } - dce->flags |= DEVCHANGE_HAS_NEW_SLAVE; - dce->new_slaveid = slave->id; + dce->flags |= DEVCHANGE_SLAVE_SWITCH; + dce->sourceid = slave->id; if (slave->button) { @@ -240,10 +233,11 @@ CreateClassesChangedEvent(EventList* event, * Rescale the coord between the two axis ranges. */ static int -rescaleValuatorAxis(int coord, AxisInfoPtr from, AxisInfoPtr to, +rescaleValuatorAxis(int coord, float remainder, float *remainder_return, AxisInfoPtr from, AxisInfoPtr to, int defmax) { - int fmin = 0, tmin = 0, fmax = defmax, tmax = defmax; + int fmin = 0, tmin = 0, fmax = defmax, tmax = defmax, coord_return; + float value; if(from && from->min_value < from->max_value) { fmin = from->min_value; @@ -254,14 +248,23 @@ rescaleValuatorAxis(int coord, AxisInfoPtr from, AxisInfoPtr to, tmax = to->max_value; } - if(fmin == tmin && fmax == tmax) + if(fmin == tmin && fmax == tmax) { + if (remainder_return) + *remainder_return = remainder; return coord; + } - if(fmax == fmin) /* avoid division by 0 */ + if(fmax == fmin) { /* avoid division by 0 */ + if (remainder_return) + *remainder_return = 0.0; return 0; + } - return lroundf(((float)(coord - fmin)) * (tmax - tmin) / - (fmax - fmin)) + tmin; + value = (coord + remainder - fmin) * (tmax - tmin) / (fmax - fmin) + tmin; + coord_return = lroundf(value); + if (remainder_return) + *remainder_return = value - coord_return; + return coord_return; } /** @@ -289,9 +292,11 @@ updateSlaveDeviceCoords(DeviceIntPtr master, DeviceIntPtr pDev) /* scale back to device coordinates */ if(pDev->valuator->numAxes > 0) - pDev->last.valuators[0] = rescaleValuatorAxis(pDev->last.valuators[0], NULL, pDev->valuator->axes + 0, scr->width); + pDev->last.valuators[0] = rescaleValuatorAxis(pDev->last.valuators[0], pDev->last.remainder[0], + &pDev->last.remainder[0], NULL, pDev->valuator->axes + 0, scr->width); if(pDev->valuator->numAxes > 1) - pDev->last.valuators[1] = rescaleValuatorAxis(pDev->last.valuators[1], NULL, pDev->valuator->axes + 1, scr->height); + pDev->last.valuators[1] = rescaleValuatorAxis(pDev->last.valuators[1], pDev->last.remainder[1], + &pDev->last.remainder[0], NULL, pDev->valuator->axes + 1, scr->height); /* calculate the other axis as well based on info from the old * slave-device. If the old slave had less axes than this one, @@ -304,6 +309,8 @@ updateSlaveDeviceCoords(DeviceIntPtr master, DeviceIntPtr pDev) else pDev->last.valuators[i] = rescaleValuatorAxis(pDev->last.valuators[i], + pDev->last.remainder[i], + &pDev->last.remainder[i], lastSlave->valuator->axes + i, pDev->valuator->axes + i, 0); } @@ -410,7 +417,7 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start, /* scale to screen coords */ to = &core_axis; to->max_value = pScreen->width; - coord = rescaleValuatorAxis(coord, &from, to, pScreen->width); + coord = rescaleValuatorAxis(coord, 0.0, NULL, &from, to, pScreen->width); memcpy(corebuf, &coord, sizeof(INT16)); corebuf++; @@ -421,7 +428,7 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start, memcpy(&coord, icbuf++, sizeof(INT32)); to->max_value = pScreen->height; - coord = rescaleValuatorAxis(coord, &from, to, pScreen->height); + coord = rescaleValuatorAxis(coord, 0.0, NULL, &from, to, pScreen->height); memcpy(corebuf, &coord, sizeof(INT16)); } else if (IsMaster(pDev)) @@ -456,7 +463,7 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start, dflt = 0; /* scale from stored range into current range */ - coord = rescaleValuatorAxis(coord, &from, to, 0); + coord = rescaleValuatorAxis(coord, 0.0, NULL, &from, to, 0); memcpy(ocbuf, &coord, sizeof(INT32)); ocbuf++; } @@ -556,13 +563,11 @@ updateMotionHistory(DeviceIntPtr pDev, CARD32 ms, int first_valuator, */ int GetMaximumEventsNum(void) { - /* One base event -- device, plus valuator events. */ - int ret = 1 + MAX_VALUATOR_EVENTS; - - /* One possible DeviceClassesChangedEvent */ - ret++; - - return ret; + /* One raw event + * One device event + * One possible device changed event + */ + return 3; } @@ -596,10 +601,9 @@ static void clipValuators(DeviceIntPtr pDev, int first_valuator, int num_valuators, int *valuators) { - AxisInfoPtr axes = pDev->valuator->axes + first_valuator; int i; - for (i = 0; i < num_valuators; i++, axes++) + for (i = 0; i < num_valuators; i++) clipAxis(pDev, i + first_valuator, &(valuators[i])); } @@ -745,56 +749,69 @@ accelPointer(DeviceIntPtr dev, int first, int num, int *valuators, CARD32 ms) * @param dev The device to be moved. * @param x Pointer to current x-axis value, may be modified. * @param y Pointer to current y-axis value, may be modified. + * @param x_frac Fractional part of current x-axis value, may be modified. + * @param y_frac Fractional part of current y-axis value, may be modified. * @param scr Screen the device's sprite is currently on. * @param screenx Screen x coordinate the sprite is on after the update. * @param screeny Screen y coordinate the sprite is on after the update. + * @param screenx_frac Fractional part of screen x coordinate, as above. + * @param screeny_frac Fractional part of screen y coordinate, as above. */ static void -positionSprite(DeviceIntPtr dev, int *x, int *y, - ScreenPtr scr, int *screenx, int *screeny) +positionSprite(DeviceIntPtr dev, int *x, int *y, float x_frac, float y_frac, + ScreenPtr scr, int *screenx, int *screeny, float *screenx_frac, float *screeny_frac) { + int old_screenx, old_screeny; + /* scale x&y to screen */ - if (dev->valuator->numAxes > 0) - *screenx = rescaleValuatorAxis(*x, dev->valuator->axes + 0, NULL, scr->width); - else + if (dev->valuator->numAxes > 0) { + *screenx = rescaleValuatorAxis(*x, x_frac, screenx_frac, + dev->valuator->axes + 0, NULL, scr->width); + } else { *screenx = dev->last.valuators[0]; + *screenx_frac = dev->last.remainder[0]; + } - if (dev->valuator->numAxes > 1 ) - *screeny = rescaleValuatorAxis(*y, dev->valuator->axes + 1, NULL, scr->height); - else + if (dev->valuator->numAxes > 1) { + *screeny = rescaleValuatorAxis(*y, y_frac, screeny_frac, + dev->valuator->axes + 1, NULL, scr->height); + } else { *screeny = dev->last.valuators[1]; + *screeny_frac = dev->last.remainder[1]; + } - dev->last.valuators[0] = *screenx; - dev->last.valuators[1] = *screeny; - + old_screenx = *screenx; + old_screeny = *screeny; /* This takes care of crossing screens for us, as well as clipping * to the current screen. */ - miPointerSetPosition(dev, &dev->last.valuators[0], &dev->last.valuators[1]); + miPointerSetPosition(dev, screenx, screeny); if (dev->u.master) { - dev->u.master->last.valuators[0] = dev->last.valuators[0]; - dev->u.master->last.valuators[1] = dev->last.valuators[1]; + dev->u.master->last.valuators[0] = *screenx; + dev->u.master->last.valuators[1] = *screeny; + dev->u.master->last.remainder[0] = *screenx_frac; + dev->u.master->last.remainder[1] = *screeny_frac; } /* Crossed screen? Scale back to device coordiantes */ - if(*screenx != dev->last.valuators[0]) + if(*screenx != old_screenx) { scr = miPointerGetScreen(dev); - *x = rescaleValuatorAxis(dev->last.valuators[0], NULL, + *x = rescaleValuatorAxis(*screenx, *screenx_frac, &x_frac, NULL, dev->valuator->axes + 0, scr->width); - *screenx = dev->last.valuators[0]; } - if(*screeny != dev->last.valuators[1]) + if(*screeny != old_screeny) { scr = miPointerGetScreen(dev); - *screeny = dev->last.valuators[1]; - *y = rescaleValuatorAxis(dev->last.valuators[1], NULL, + *y = rescaleValuatorAxis(*screeny, *screeny_frac, &y_frac, NULL, dev->valuator->axes + 1, scr->height); } /* dropy x/y (device coordinates) back into valuators for next event */ dev->last.valuators[0] = *x; dev->last.valuators[1] = *y; + dev->last.remainder[0] = x_frac; + dev->last.remainder[1] = y_frac; } /** @@ -1017,8 +1034,9 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, CARD32 ms; DeviceEvent *event; RawDeviceEvent *raw; - int x = 0, y = 0, /* switches between device and screen coords */ + int x = 0, y = 0, /* device coords */ cx, cy; /* only screen coordinates */ + float x_frac = 0.0, y_frac = 0.0, cx_frac, cy_frac; ScreenPtr scr = miPointerGetScreen(pDev); /* refuse events from disabled devices */ @@ -1050,26 +1068,32 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, if (flags & POINTER_SCREEN) /* valuators are in screen coords */ { - valuators[0] = rescaleValuatorAxis(valuators[0], NULL, - pDev->valuator->axes + 0, - scr->width); - if (num_valuators > 1) - valuators[1] = rescaleValuatorAxis(valuators[1], NULL, + if (num_valuators >= 1 && first_valuator == 0) + valuators[0] = rescaleValuatorAxis(valuators[0], 0.0, &x_frac, NULL, + pDev->valuator->axes + 0, + scr->width); + if (first_valuator <= 1 && num_valuators >= (2 - first_valuator)) + valuators[1 - first_valuator] = rescaleValuatorAxis(valuators[1 - first_valuator], 0.0, &y_frac, NULL, pDev->valuator->axes + 1, scr->height); } moveAbsolute(pDev, &x, &y, first_valuator, num_valuators, valuators); } else { - if (flags & POINTER_ACCELERATE) + if (flags & POINTER_ACCELERATE) { accelPointer(pDev, first_valuator, num_valuators, valuators, ms); + /* The pointer acceleration code modifies the fractional part + * in-place, so we need to extract this information first */ + x_frac = pDev->last.remainder[0]; + y_frac = pDev->last.remainder[1]; + } moveRelative(pDev, &x, &y, first_valuator, num_valuators, valuators); } set_raw_valuators(raw, first_valuator, num_valuators, valuators, raw->valuators.data); - positionSprite(pDev, &x, &y, scr, &cx, &cy); + positionSprite(pDev, &x, &y, x_frac, y_frac, scr, &cx, &cy, &cx_frac, &cy_frac); updateHistory(pDev, first_valuator, num_valuators, ms); /* Update the valuators with the true value sent to the client*/ @@ -1102,8 +1126,8 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, event->root_x = cx; /* root_x/y always in screen coords */ event->root_y = cy; - event->root_x_frac = pDev->last.remainder[0]; - event->root_y_frac = pDev->last.remainder[1]; + event->root_x_frac = cx_frac; + event->root_y_frac = cy_frac; set_valuators(pDev, event, first_valuator, num_valuators, valuators); diff --git a/dix/grabs.c b/dix/grabs.c index 06d6d037c..4a351d647 100644 --- a/dix/grabs.c +++ b/dix/grabs.c @@ -451,7 +451,7 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab) any_modifier = (pMinuendGrab->grabtype == GRABTYPE_XI2) ? (unsigned int)XIAnyModifier : (unsigned int)AnyModifier; any_key = (pMinuendGrab->grabtype == GRABTYPE_XI2) ? - (unsigned int)XIAnyKeysym : (unsigned int)AnyKey; + (unsigned int)XIAnyKeycode : (unsigned int)AnyKey; ndels = nadds = nups = 0; ok = TRUE; for (grab = wPassiveGrabs(pMinuendGrab->window); diff --git a/dix/inpututils.c b/dix/inpututils.c index 79b6ab7c7..4848c1bc2 100644 --- a/dix/inpututils.c +++ b/dix/inpututils.c @@ -45,21 +45,21 @@ check_butmap_change(DeviceIntPtr dev, CARD8 *map, int len, CARD32 *errval_out, int i, ret; if (!dev || !dev->button) + { + client->errorValue = (dev) ? dev->id : 0; return BadDevice; + } ret = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixManageAccess); if (ret != Success) + { + client->errorValue = dev->id; return ret; + } for (i = 0; i < len; i++) { if (dev->button->map[i + 1] != map[i] && dev->button->down[i + 1]) return MappingBusy; - - if (map[i] < 1 || map[i] > 255) { - if (errval_out) - *errval_out = map[i]; - return -1; - } } return Success; @@ -107,7 +107,7 @@ do_butmap_change(DeviceIntPtr dev, CARD8 *map, int len, ClientPtr client) * to the requested device, faithfully ignores any errors encountered while * trying to apply the map to its master/slaves. */ -_X_EXPORT int +int ApplyPointerMapping(DeviceIntPtr dev, CARD8 *map, int len, ClientPtr client) { int ret; @@ -227,7 +227,7 @@ do_modmap_change(ClientPtr client, DeviceIntPtr dev, CARD8 *modmap) static int build_modmap_from_modkeymap(CARD8 *modmap, KeyCode *modkeymap, int max_keys_per_mod) { - int i, mod = 0, len = max_keys_per_mod * 8; + int i, len = max_keys_per_mod * 8; memset(modmap, 0, MAP_LENGTH); @@ -241,9 +241,7 @@ static int build_modmap_from_modkeymap(CARD8 *modmap, KeyCode *modkeymap, if (modmap[modkeymap[i]]) return BadValue; - if (!(i % max_keys_per_mod)) - mod++; - modmap[modkeymap[i]] = mod; + modmap[modkeymap[i]] = 1 << (i / max_keys_per_mod); } return Success; diff --git a/dix/main.c b/dix/main.c index 25b085e88..f96245a4b 100644 --- a/dix/main.c +++ b/dix/main.c @@ -82,6 +82,7 @@ Equipment Corporation. #include <X11/X.h> #include <X11/Xos.h> /* for unistd.h */ #include <X11/Xproto.h> +#include <pixman.h> #include "scrnintstr.h" #include "misc.h" #include "os.h" @@ -111,8 +112,7 @@ Equipment Corporation. #endif #ifdef DPMSExtension -#define DPMS_SERVER -#include <X11/extensions/dpms.h> +#include <X11/extensions/dpmsconst.h> #include "dpmsproc.h" #endif @@ -139,6 +139,8 @@ int main(int argc, char *argv[], char *envp[]) InitRegions(); + pixman_disable_out_of_bounds_workaround(); + CheckUserParameters(argc, argv, envp); CheckUserAuthorization(); diff --git a/dix/property.c b/dix/property.c index 0929dca17..9ec5dc6ae 100644 --- a/dix/property.c +++ b/dix/property.c @@ -218,7 +218,7 @@ ProcChangeProperty(ClientPtr client) return BadValue; } len = stuff->nUnits; - if (len > ((0xffffffff - sizeof(xChangePropertyReq)) >> 2)) + if (len > bytes_to_int32(0xffffffff - sizeof(xChangePropertyReq))) return BadLength; sizeInBytes = format>>3; totalSize = len * sizeInBytes; @@ -253,8 +253,9 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, pointer value, Bool sendevent) { PropertyPtr pProp; + PropertyRec savedProp; int sizeInBytes, totalSize, rc; - pointer data; + unsigned char *data; Mask access_mode; sizeInBytes = format>>3; @@ -277,12 +278,11 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, xfree(pProp); return(BadAlloc); } + memcpy(data, value, totalSize); pProp->propertyName = property; pProp->type = type; pProp->format = format; pProp->data = data; - if (len) - memmove((char *)data, (char *)value, totalSize); pProp->size = len; pProp->devPrivates = NULL; rc = XaceHookPropertyAccess(pClient, pWin, &pProp, @@ -307,17 +307,17 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, return(BadMatch); if ((pProp->type != type) && (mode != PropModeReplace)) return(BadMatch); + + /* save the old values for later */ + savedProp = *pProp; + if (mode == PropModeReplace) { - if (totalSize != pProp->size * (pProp->format >> 3)) - { - data = (pointer)xrealloc(pProp->data, totalSize); - if (!data && len) - return(BadAlloc); - pProp->data = data; - } - if (len) - memmove((char *)pProp->data, (char *)value, totalSize); + data = xalloc(totalSize); + if (!data && len) + return(BadAlloc); + memcpy(data, value, totalSize); + pProp->data = data; pProp->size = len; pProp->type = type; pProp->format = format; @@ -328,14 +328,12 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, } else if (mode == PropModeAppend) { - data = (pointer)xrealloc(pProp->data, - sizeInBytes * (len + pProp->size)); + data = xalloc((pProp->size + len) * sizeInBytes); if (!data) return(BadAlloc); + memcpy(data, pProp->data, pProp->size * sizeInBytes); + memcpy(data + pProp->size * sizeInBytes, value, totalSize); pProp->data = data; - memmove(&((char *)data)[pProp->size * sizeInBytes], - (char *)value, - totalSize); pProp->size += len; } else if (mode == PropModePrepend) @@ -343,13 +341,27 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, data = xalloc(sizeInBytes * (len + pProp->size)); if (!data) return(BadAlloc); - memmove(&((char *)data)[totalSize], (char *)pProp->data, - (int)(pProp->size * sizeInBytes)); - memmove((char *)data, (char *)value, totalSize); - xfree(pProp->data); + memcpy(data + totalSize, pProp->data, pProp->size * sizeInBytes); + memcpy(data, value, totalSize); pProp->data = data; pProp->size += len; } + + /* Allow security modules to check the new content */ + access_mode |= DixPostAccess; + rc = XaceHookPropertyAccess(pClient, pWin, &pProp, access_mode); + if (rc == Success) + { + if (savedProp.data != pProp->data) + xfree(savedProp.data); + } + else + { + if (savedProp.data != pProp->data) + xfree(pProp->data); + *pProp = savedProp; + return rc; + } } else return rc; @@ -462,7 +474,7 @@ ProcGetProperty(ClientPtr client) } rc = dixLookupWindow(&pWin, stuff->window, client, win_mode); if (rc != Success) - return rc; + return (rc == BadMatch) ? BadWindow : rc; if (!ValidAtom(stuff->property)) { @@ -525,7 +537,7 @@ ProcGetProperty(ClientPtr client) reply.bytesAfter = n - (ind + len); reply.format = pProp->format; - reply.length = (len + 3) >> 2; + reply.length = bytes_to_int32(len); reply.nItems = len / (pProp->format / 8 ); reply.propertyType = pProp->type; @@ -599,7 +611,7 @@ ProcListProperties(ClientPtr client) xlpr.type = X_Reply; xlpr.nProperties = numProps; - xlpr.length = (numProps * sizeof(Atom)) >> 2; + xlpr.length = bytes_to_int32(numProps * sizeof(Atom)); xlpr.sequenceNumber = client->sequence; WriteReplyToClient(client, sizeof(xGenericReply), &xlpr); if (numProps) diff --git a/dix/protocol.txt b/dix/protocol.txt index 364f13e31..8e152edaa 100644 --- a/dix/protocol.txt +++ b/dix/protocol.txt @@ -116,6 +116,14 @@ R004 DPMS:Enable R005 DPMS:Disable R006 DPMS:ForceLevel R007 DPMS:Info +R000 DRI2:QueryVersion +R001 DRI2:Connect +R002 DRI2:Authenticate +R003 DRI2:CreateDrawable +R004 DRI2:DestroyDrawable +R005 DRI2:GetBuffers +R006 DRI2:CopyRegion +R007 DRI2:GetBuffersWithFormat R000 Extended-Visual-Information:QueryVersion R001 Extended-Visual-Information:GetVisualInfo R000 FontCache:QueryVersion @@ -590,6 +598,7 @@ V031 X11:SelectionNotify V032 X11:ColormapNotify V033 X11:ClientMessage V034 X11:MappingNotify +V035 X11:GenericEvent E000 X11:Success E001 X11:BadRequest E002 X11:BadValue @@ -948,6 +957,27 @@ R036 XInputExtension:ListDeviceProperties R037 XInputExtension:ChangeDeviceProperty R038 XInputExtension:DeleteDeviceProperty R039 XInputExtension:GetDeviceProperty +R040 XInputExtension:QueryPointer +R041 XInputExtension:WarpPointer +R042 XInputExtension:ChangeCursor +R043 XInputExtension:ChangeHierarchy +R044 XInputExtension:SetClientPointer +R045 XInputExtension:GetClientPointer +R046 XInputExtension:SelectEvents +R047 XInputExtension:QueryVersion +R048 XInputExtension:QueryDevice +R049 XInputExtension:SetFocus +R050 XInputExtension:GetFocus +R051 XInputExtension:GrabDevice +R052 XInputExtension:UngrabDevice +R053 XInputExtension:AllowEvents +R054 XInputExtension:PassiveGrabDevice +R055 XInputExtension:PassiveUngrabDevice +R056 XInputExtension:ListProperties +R057 XInputExtension:ChangeProperty +R058 XInputExtension:DeleteProperty +R059 XInputExtension:GetProperty +R060 XInputExtension:GetSelectedEvents V000 XInputExtension:DeviceValuator V001 XInputExtension:DeviceKeyPress V002 XInputExtension:DeviceKeyRelease diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c index dd264770a..37c8e5178 100644 --- a/dix/ptrveloc.c +++ b/dix/ptrveloc.c @@ -61,12 +61,12 @@ /* fwds */ int -SetAccelerationProfile(DeviceVelocityPtr s, int profile_num); +SetAccelerationProfile(DeviceVelocityPtr vel, int profile_num); static float -SimpleSmoothProfile(DeviceVelocityPtr pVel, float velocity, +SimpleSmoothProfile(DeviceIntPtr dev, DeviceVelocityPtr vel, float velocity, float threshold, float acc); static PointerAccelerationProfileFunc -GetAccelerationProfile(DeviceVelocityPtr s, int profile_num); +GetAccelerationProfile(DeviceVelocityPtr vel, int profile_num); /*#define PTRACCEL_DEBUGGING*/ @@ -87,31 +87,31 @@ GetAccelerationProfile(DeviceVelocityPtr s, int profile_num); * Init struct so it should match the average case */ void -InitVelocityData(DeviceVelocityPtr s) +InitVelocityData(DeviceVelocityPtr vel) { - memset(s, 0, sizeof(DeviceVelocityRec)); - - s->corr_mul = 10.0; /* dots per 10 milisecond should be usable */ - s->const_acceleration = 1.0; /* no acceleration/deceleration */ - s->reset_time = 300; - s->use_softening = 1; - s->min_acceleration = 1.0; /* don't decelerate */ - s->max_rel_diff = 0.2; - s->max_diff = 1.0; - s->initial_range = 2; - s->average_accel = TRUE; - SetAccelerationProfile(s, AccelProfileClassic); - InitTrackers(s, 16); + memset(vel, 0, sizeof(DeviceVelocityRec)); + + vel->corr_mul = 10.0; /* dots per 10 milisecond should be usable */ + vel->const_acceleration = 1.0; /* no acceleration/deceleration */ + vel->reset_time = 300; + vel->use_softening = 1; + vel->min_acceleration = 1.0; /* don't decelerate */ + vel->max_rel_diff = 0.2; + vel->max_diff = 1.0; + vel->initial_range = 2; + vel->average_accel = TRUE; + SetAccelerationProfile(vel, AccelProfileClassic); + InitTrackers(vel, 16); } /** * Clean up */ -static void -FreeVelocityData(DeviceVelocityPtr s){ - xfree(s->tracker); - SetAccelerationProfile(s, PROFILE_UNINITIALIZE); +void +FreeVelocityData(DeviceVelocityPtr vel){ + xfree(vel->tracker); + SetAccelerationProfile(vel, PROFILE_UNINITIALIZE); } @@ -119,15 +119,15 @@ FreeVelocityData(DeviceVelocityPtr s){ * dix uninit helper, called through scheme */ void -AccelerationDefaultCleanup(DeviceIntPtr pDev) +AccelerationDefaultCleanup(DeviceIntPtr dev) { /*sanity check*/ - if( pDev->valuator->accelScheme.AccelSchemeProc == acceleratePointerPredictable - && pDev->valuator->accelScheme.accelData != NULL){ - pDev->valuator->accelScheme.AccelSchemeProc = NULL; - FreeVelocityData(pDev->valuator->accelScheme.accelData); - xfree(pDev->valuator->accelScheme.accelData); - pDev->valuator->accelScheme.accelData = NULL; + if( dev->valuator->accelScheme.AccelSchemeProc == acceleratePointerPredictable + && dev->valuator->accelScheme.accelData != NULL){ + dev->valuator->accelScheme.AccelSchemeProc = NULL; + FreeVelocityData(dev->valuator->accelScheme.accelData); + xfree(dev->valuator->accelScheme.accelData); + dev->valuator->accelScheme.accelData = NULL; } } @@ -143,7 +143,7 @@ static int AccelSetProfileProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val, BOOL checkOnly) { - DeviceVelocityPtr pVel; + DeviceVelocityPtr vel; int profile, *ptr = &profile; int rc; int nelem = 1; @@ -151,8 +151,8 @@ AccelSetProfileProperty(DeviceIntPtr dev, Atom atom, if (atom != XIGetKnownProperty(ACCEL_PROP_PROFILE_NUMBER)) return Success; - pVel = GetDevicePredictableAccelData(dev); - if (!pVel) + vel = GetDevicePredictableAccelData(dev); + if (!vel) return BadValue; rc = XIPropToInt(val, &nelem, &ptr); @@ -161,18 +161,18 @@ AccelSetProfileProperty(DeviceIntPtr dev, Atom atom, if (rc) return rc; - if (GetAccelerationProfile(pVel, profile) == NULL) + if (GetAccelerationProfile(vel, profile) == NULL) return BadValue; } else - SetAccelerationProfile(pVel, profile); + SetAccelerationProfile(vel, profile); return Success; } static void -AccelInitProfileProperty(DeviceIntPtr dev, DeviceVelocityPtr pVel) +AccelInitProfileProperty(DeviceIntPtr dev, DeviceVelocityPtr vel) { - int profile = pVel->statistics.profile_number; + int profile = vel->statistics.profile_number; Atom prop_profile_number = XIGetKnownProperty(ACCEL_PROP_PROFILE_NUMBER); XIChangeDeviceProperty(dev, prop_profile_number, XA_INTEGER, 32, @@ -188,7 +188,7 @@ static int AccelSetDecelProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val, BOOL checkOnly) { - DeviceVelocityPtr pVel; + DeviceVelocityPtr vel; float v, *ptr = &v; int rc; int nelem = 1; @@ -196,8 +196,8 @@ AccelSetDecelProperty(DeviceIntPtr dev, Atom atom, if (atom != XIGetKnownProperty(ACCEL_PROP_CONSTANT_DECELERATION)) return Success; - pVel = GetDevicePredictableAccelData(dev); - if (!pVel) + vel = GetDevicePredictableAccelData(dev); + if (!vel) return BadValue; rc = XIPropToFloat(val, &nelem, &ptr); @@ -209,15 +209,15 @@ AccelSetDecelProperty(DeviceIntPtr dev, Atom atom, } if(v >= 1.0f) - pVel->const_acceleration = 1/v; + vel->const_acceleration = 1/v; return Success; } static void -AccelInitDecelProperty(DeviceIntPtr dev, DeviceVelocityPtr pVel) +AccelInitDecelProperty(DeviceIntPtr dev, DeviceVelocityPtr vel) { - float fval = 1.0/pVel->const_acceleration; + float fval = 1.0/vel->const_acceleration; Atom prop_const_decel = XIGetKnownProperty(ACCEL_PROP_CONSTANT_DECELERATION); XIChangeDeviceProperty(dev, prop_const_decel, XIGetKnownProperty(XATOM_FLOAT), 32, @@ -234,7 +234,7 @@ static int AccelSetAdaptDecelProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val, BOOL checkOnly) { - DeviceVelocityPtr pVel; + DeviceVelocityPtr veloc; float v, *ptr = &v; int rc; int nelem = 1; @@ -242,8 +242,8 @@ AccelSetAdaptDecelProperty(DeviceIntPtr dev, Atom atom, if (atom != XIGetKnownProperty(ACCEL_PROP_ADAPTIVE_DECELERATION)) return Success; - pVel = GetDevicePredictableAccelData(dev); - if (!pVel) + veloc = GetDevicePredictableAccelData(dev); + if (!veloc) return BadValue; rc = XIPropToFloat(val, &nelem, &ptr); @@ -255,15 +255,15 @@ AccelSetAdaptDecelProperty(DeviceIntPtr dev, Atom atom, } if(v >= 1.0f) - pVel->min_acceleration = 1/v; + veloc->min_acceleration = 1/v; return Success; } static void -AccelInitAdaptDecelProperty(DeviceIntPtr dev, DeviceVelocityPtr pVel) +AccelInitAdaptDecelProperty(DeviceIntPtr dev, DeviceVelocityPtr vel) { - float fval = 1.0/pVel->min_acceleration; + float fval = 1.0/vel->min_acceleration; Atom prop_adapt_decel = XIGetKnownProperty(ACCEL_PROP_ADAPTIVE_DECELERATION); XIChangeDeviceProperty(dev, prop_adapt_decel, XIGetKnownProperty(XATOM_FLOAT), 32, @@ -280,7 +280,7 @@ static int AccelSetScaleProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val, BOOL checkOnly) { - DeviceVelocityPtr pVel; + DeviceVelocityPtr vel; float v, *ptr = &v; int rc; int nelem = 1; @@ -288,8 +288,8 @@ AccelSetScaleProperty(DeviceIntPtr dev, Atom atom, if (atom != XIGetKnownProperty(ACCEL_PROP_VELOCITY_SCALING)) return Success; - pVel = GetDevicePredictableAccelData(dev); - if (!pVel) + vel = GetDevicePredictableAccelData(dev); + if (!vel) return BadValue; rc = XIPropToFloat(val, &nelem, &ptr); @@ -302,15 +302,15 @@ AccelSetScaleProperty(DeviceIntPtr dev, Atom atom, } if(v > 0) - pVel->corr_mul = v; + vel->corr_mul = v; return Success; } static void -AccelInitScaleProperty(DeviceIntPtr dev, DeviceVelocityPtr pVel) +AccelInitScaleProperty(DeviceIntPtr dev, DeviceVelocityPtr vel) { - float fval = pVel->corr_mul; + float fval = vel->corr_mul; Atom prop_velo_scale = XIGetKnownProperty(ACCEL_PROP_VELOCITY_SCALING); XIChangeDeviceProperty(dev, prop_velo_scale, XIGetKnownProperty(XATOM_FLOAT), 32, @@ -320,17 +320,17 @@ AccelInitScaleProperty(DeviceIntPtr dev, DeviceVelocityPtr pVel) } BOOL -InitializePredictableAccelerationProperties(DeviceIntPtr device) +InitializePredictableAccelerationProperties(DeviceIntPtr dev) { - DeviceVelocityPtr pVel = GetDevicePredictableAccelData(device); + DeviceVelocityPtr vel = GetDevicePredictableAccelData(dev); - if(!pVel) + if(!vel) return FALSE; - AccelInitProfileProperty(device, pVel); - AccelInitDecelProperty(device, pVel); - AccelInitAdaptDecelProperty(device, pVel); - AccelInitScaleProperty(device, pVel); + AccelInitProfileProperty(dev, vel); + AccelInitDecelProperty(dev, vel); + AccelInitAdaptDecelProperty(dev, vel); + AccelInitScaleProperty(dev, vel); return TRUE; } @@ -339,16 +339,16 @@ InitializePredictableAccelerationProperties(DeviceIntPtr device) ********************/ void -InitTrackers(DeviceVelocityPtr s, int ntracker) +InitTrackers(DeviceVelocityPtr vel, int ntracker) { if(ntracker < 1){ ErrorF("(dix ptracc) invalid number of trackers\n"); return; } - xfree(s->tracker); - s->tracker = (MotionTrackerPtr)xalloc(ntracker * sizeof(MotionTracker)); - memset(s->tracker, 0, ntracker * sizeof(MotionTracker)); - s->num_tracker = ntracker; + xfree(vel->tracker); + vel->tracker = (MotionTrackerPtr)xalloc(ntracker * sizeof(MotionTracker)); + memset(vel->tracker, 0, ntracker * sizeof(MotionTracker)); + vel->num_tracker = ntracker; } /** @@ -437,22 +437,22 @@ GetDirection(int dx, int dy){ #define TRACKER_INDEX(s, d) (((s)->num_tracker + (s)->cur_tracker - (d)) % (s)->num_tracker) static inline void -FeedTrackers(DeviceVelocityPtr s, int dx, int dy, int cur_t) +FeedTrackers(DeviceVelocityPtr vel, int dx, int dy, int cur_t) { int n; - for(n = 0; n < s->num_tracker; n++){ - s->tracker[n].dx += dx; - s->tracker[n].dy += dy; + for(n = 0; n < vel->num_tracker; n++){ + vel->tracker[n].dx += dx; + vel->tracker[n].dy += dy; } - n = (s->cur_tracker + 1) % s->num_tracker; - s->tracker[n].dx = 0; - s->tracker[n].dy = 0; - s->tracker[n].time = cur_t; - s->tracker[n].dir = GetDirection(dx, dy); + n = (vel->cur_tracker + 1) % vel->num_tracker; + vel->tracker[n].dx = 0; + vel->tracker[n].dy = 0; + vel->tracker[n].time = cur_t; + vel->tracker[n].dir = GetDirection(dx, dy); DebugAccelF("(dix prtacc) motion [dx: %i dy: %i dir:%i diff: %i]\n", - dx, dy, s->tracker[n].dir, - cur_t - s->tracker[s->cur_tracker].time); - s->cur_tracker = n; + dx, dy, vel->tracker[n].dir, + cur_t - vel->tracker[vel->cur_tracker].time); + vel->cur_tracker = n; } /** @@ -461,11 +461,11 @@ FeedTrackers(DeviceVelocityPtr s, int dx, int dy, int cur_t) * This assumes linear motion. */ static float -CalcTracker(DeviceVelocityPtr s, int offset, int cur_t){ - int index = TRACKER_INDEX(s, offset); - float dist = sqrt( s->tracker[index].dx * s->tracker[index].dx - + s->tracker[index].dy * s->tracker[index].dy); - int dtime = cur_t - s->tracker[index].time; +CalcTracker(DeviceVelocityPtr vel, int offset, int cur_t){ + int index = TRACKER_INDEX(vel, offset); + float dist = sqrt( vel->tracker[index].dx * vel->tracker[index].dx + + vel->tracker[index].dy * vel->tracker[index].dy); + int dtime = cur_t - vel->tracker[index].time; if(dtime > 0) return (dist / dtime); else @@ -479,19 +479,19 @@ CalcTracker(DeviceVelocityPtr s, int offset, int cur_t){ * May return 0. */ static float -QueryTrackers(DeviceVelocityPtr s, int cur_t){ +QueryTrackers(DeviceVelocityPtr vel, int cur_t){ int n, offset, dir = 255, i = -1, age_ms; /* initial velocity: a low-offset, valid velocity */ float iveloc = 0, res = 0, tmp, vdiff; - float vfac = s->corr_mul * s->const_acceleration; /* premultiply */ + float vfac = vel->corr_mul * vel->const_acceleration; /* premultiply */ /* loop from current to older data */ - for(offset = 1; offset < s->num_tracker; offset++){ - n = TRACKER_INDEX(s, offset); + for(offset = 1; offset < vel->num_tracker; offset++){ + n = TRACKER_INDEX(vel, offset); - age_ms = cur_t - s->tracker[n].time; + age_ms = cur_t - vel->tracker[n].time; /* bail out if data is too old and protect from overrun */ - if (age_ms >= s->reset_time || age_ms < 0) { + if (age_ms >= vel->reset_time || age_ms < 0) { DebugAccelF("(dix prtacc) query: tracker too old\n"); break; } @@ -502,7 +502,7 @@ QueryTrackers(DeviceVelocityPtr s, int cur_t){ * even more precision we could subdivide as a final step, so possible * non-linearities are accounted for. */ - dir &= s->tracker[n].dir; + dir &= vel->tracker[n].dir; if(dir == 0){ DebugAccelF("(dix prtacc) query: no longer linear\n"); /* instead of breaking it we might also inspect the partition after, @@ -510,16 +510,16 @@ QueryTrackers(DeviceVelocityPtr s, int cur_t){ break; } - tmp = CalcTracker(s, offset, cur_t) * vfac; + tmp = CalcTracker(vel, offset, cur_t) * vfac; - if ((iveloc == 0 || offset <= s->initial_range) && tmp != 0) { + if ((iveloc == 0 || offset <= vel->initial_range) && tmp != 0) { /* set initial velocity and result */ res = iveloc = tmp; i = offset; } else if (iveloc != 0 && tmp != 0) { vdiff = fabs(iveloc - tmp); - if (vdiff <= s->max_diff || - vdiff/(iveloc + tmp) < s->max_rel_diff) { + if (vdiff <= vel->max_diff || + vdiff/(iveloc + tmp) < vel->max_rel_diff) { /* we're in range with the initial velocity, * so this result is likely better * (it contains more information). */ @@ -534,17 +534,17 @@ QueryTrackers(DeviceVelocityPtr s, int cur_t){ } } } - if(offset == s->num_tracker){ + if(offset == vel->num_tracker){ DebugAccelF("(dix prtacc) query: last tracker in effect\n"); - i = s->num_tracker-1; + i = vel->num_tracker-1; } if(i>=0){ - n = TRACKER_INDEX(s, i); + n = TRACKER_INDEX(vel, i); DebugAccelF("(dix prtacc) result: offset %i [dx: %i dy: %i diff: %i]\n", i, - s->tracker[n].dx, - s->tracker[n].dy, - cur_t - s->tracker[n].time); + vel->tracker[n].dx, + vel->tracker[n].dy, + cur_t - vel->tracker[n].time); } return res; } @@ -555,22 +555,22 @@ QueryTrackers(DeviceVelocityPtr s, int cur_t){ * Perform velocity approximation based on 2D 'mickeys' (mouse motion delta). * return true if non-visible state reset is suggested */ -static short +short ProcessVelocityData2D( - DeviceVelocityPtr s, + DeviceVelocityPtr vel, int dx, int dy, int time) { float velocity; - s->last_velocity = s->velocity; + vel->last_velocity = vel->velocity; - FeedTrackers(s, dx, dy, time); + FeedTrackers(vel, dx, dy, time); - velocity = QueryTrackers(s, time); + velocity = QueryTrackers(vel, time); - s->velocity = velocity; + vel->velocity = velocity; return velocity == 0; } @@ -594,41 +594,42 @@ ApplySimpleSoftening(int od, int d) static void ApplySofteningAndConstantDeceleration( - DeviceVelocityPtr s, + DeviceVelocityPtr vel, int dx, int dy, float* fdx, float* fdy, short do_soften) { - if (do_soften && s->use_softening) { - *fdx = ApplySimpleSoftening(s->last_dx, dx); - *fdy = ApplySimpleSoftening(s->last_dy, dy); + if (do_soften && vel->use_softening) { + *fdx = ApplySimpleSoftening(vel->last_dx, dx); + *fdy = ApplySimpleSoftening(vel->last_dy, dy); } else { *fdx = dx; *fdy = dy; } - *fdx *= s->const_acceleration; - *fdy *= s->const_acceleration; + *fdx *= vel->const_acceleration; + *fdy *= vel->const_acceleration; } /* * compute the acceleration for given velocity and enforce min_acceleartion */ -static float +float BasicComputeAcceleration( - DeviceVelocityPtr pVel, + DeviceIntPtr dev, + DeviceVelocityPtr vel, float velocity, float threshold, float acc){ float result; - result = pVel->Profile(pVel, velocity, threshold, acc); + result = vel->Profile(dev, vel, velocity, threshold, acc); /* enforce min_acceleration */ - if (result < pVel->min_acceleration) - result = pVel->min_acceleration; + if (result < vel->min_acceleration) + result = vel->min_acceleration; return result; } @@ -637,6 +638,7 @@ BasicComputeAcceleration( */ static float ComputeAcceleration( + DeviceIntPtr dev, DeviceVelocityPtr vel, float threshold, float acc){ @@ -655,9 +657,11 @@ ComputeAcceleration( * current and previous velocity. * Though being the more natural choice, it causes a minor delay * in comparison, so it can be disabled. */ - res = BasicComputeAcceleration(vel, vel->velocity, threshold, acc); - res += BasicComputeAcceleration(vel, vel->last_velocity, threshold, acc); - res += 4.0f * BasicComputeAcceleration(vel, + res = BasicComputeAcceleration( + dev, vel, vel->velocity, threshold, acc); + res += BasicComputeAcceleration( + dev, vel, vel->last_velocity, threshold, acc); + res += 4.0f * BasicComputeAcceleration(dev, vel, (vel->last_velocity + vel->velocity) / 2, threshold, acc); res /= 6.0f; @@ -665,7 +669,8 @@ ComputeAcceleration( vel->velocity, vel->last_velocity, res); return res; }else{ - res = BasicComputeAcceleration(vel, vel->velocity, threshold, acc); + res = BasicComputeAcceleration(dev, vel, + vel->velocity, threshold, acc); DebugAccelF("(dix ptracc) profile sample [%.2f] is %.3f\n", vel->velocity, res); return res; @@ -682,7 +687,8 @@ ComputeAcceleration( */ static float PolynomialAccelerationProfile( - DeviceVelocityPtr pVel, + DeviceIntPtr dev, + DeviceVelocityPtr vel, float velocity, float ignored, float acc) @@ -697,18 +703,21 @@ PolynomialAccelerationProfile( */ static float ClassicProfile( - DeviceVelocityPtr pVel, + DeviceIntPtr dev, + DeviceVelocityPtr vel, float velocity, float threshold, float acc) { - if (threshold) { - return SimpleSmoothProfile (pVel, + if (threshold > 0) { + return SimpleSmoothProfile (dev, + vel, velocity, threshold, acc); } else { - return PolynomialAccelerationProfile (pVel, + return PolynomialAccelerationProfile (dev, + vel, velocity, 0, acc); @@ -726,7 +735,8 @@ ClassicProfile( */ static float PowerProfile( - DeviceVelocityPtr pVel, + DeviceIntPtr dev, + DeviceVelocityPtr vel, float velocity, float threshold, float acc) @@ -736,9 +746,9 @@ PowerProfile( acc = (acc-1.0) * 0.1f + 1.0; /* without this, acc of 2 is unuseable */ if (velocity <= threshold) - return pVel->min_acceleration; + return vel->min_acceleration; vel_dist = velocity - threshold; - return (pow(acc, vel_dist)) * pVel->min_acceleration; + return (pow(acc, vel_dist)) * vel->min_acceleration; } @@ -763,7 +773,8 @@ CalcPenumbralGradient(float x){ */ static float SimpleSmoothProfile( - DeviceVelocityPtr pVel, + DeviceIntPtr dev, + DeviceVelocityPtr vel, float velocity, float threshold, float acc) @@ -788,7 +799,8 @@ SimpleSmoothProfile( */ static float SmoothLinearProfile( - DeviceVelocityPtr pVel, + DeviceIntPtr dev, + DeviceVelocityPtr vel, float velocity, float threshold, float acc) @@ -811,14 +823,15 @@ SmoothLinearProfile( res = nv * 2.0f / M_PI /* steepness of gradient at 0.5 */ + 1.0f; /* gradient crosses 2|1 */ } - res += pVel->min_acceleration; + res += vel->min_acceleration; return res; } static float LinearProfile( - DeviceVelocityPtr pVel, + DeviceIntPtr dev, + DeviceVelocityPtr vel, float velocity, float threshold, float acc) @@ -829,7 +842,8 @@ LinearProfile( static float NoProfile( - DeviceVelocityPtr pVel, + DeviceIntPtr dev, + DeviceVelocityPtr vel, float velocity, float threshold, float acc) @@ -839,14 +853,14 @@ NoProfile( static PointerAccelerationProfileFunc GetAccelerationProfile( - DeviceVelocityPtr s, + DeviceVelocityPtr vel, int profile_num) { switch(profile_num){ case AccelProfileClassic: return ClassicProfile; case AccelProfileDeviceSpecific: - return s->deviceSpecificProfile; + return vel->deviceSpecificProfile; case AccelProfilePolynomial: return PolynomialAccelerationProfile; case AccelProfileSmoothLinear: @@ -876,23 +890,23 @@ GetAccelerationProfile( */ int SetAccelerationProfile( - DeviceVelocityPtr s, + DeviceVelocityPtr vel, int profile_num) { PointerAccelerationProfileFunc profile; - profile = GetAccelerationProfile(s, profile_num); + profile = GetAccelerationProfile(vel, profile_num); if(profile == NULL && profile_num != PROFILE_UNINITIALIZE) return FALSE; - if(s->profile_private != NULL){ + if(vel->profile_private != NULL){ /* Here one could free old profile-private data */ - xfree(s->profile_private); - s->profile_private = NULL; + xfree(vel->profile_private); + vel->profile_private = NULL; } /* Here one could init profile-private data */ - s->Profile = profile; - s->statistics.profile_number = profile_num; + vel->Profile = profile; + vel->statistics.profile_number = profile_num; return TRUE; } @@ -912,11 +926,11 @@ SetAccelerationProfile( */ void SetDeviceSpecificAccelerationProfile( - DeviceVelocityPtr s, + DeviceVelocityPtr vel, PointerAccelerationProfileFunc profile) { - if(s) - s->deviceSpecificProfile = profile; + if(vel) + vel->deviceSpecificProfile = profile; } /** @@ -925,19 +939,19 @@ SetDeviceSpecificAccelerationProfile( */ DeviceVelocityPtr GetDevicePredictableAccelData( - DeviceIntPtr pDev) + DeviceIntPtr dev) { /*sanity check*/ - if(!pDev){ + if(!dev){ ErrorF("[dix] accel: DeviceIntPtr was NULL"); return NULL; } - if( pDev->valuator && - pDev->valuator->accelScheme.AccelSchemeProc == + if( dev->valuator && + dev->valuator->accelScheme.AccelSchemeProc == acceleratePointerPredictable && - pDev->valuator->accelScheme.accelData != NULL){ + dev->valuator->accelScheme.accelData != NULL){ - return (DeviceVelocityPtr)pDev->valuator->accelScheme.accelData; + return (DeviceVelocityPtr)dev->valuator->accelScheme.accelData; } return NULL; } @@ -953,7 +967,7 @@ GetDevicePredictableAccelData( */ void acceleratePointerPredictable( - DeviceIntPtr pDev, + DeviceIntPtr dev, int first_valuator, int num_valuators, int *valuators, @@ -963,7 +977,7 @@ acceleratePointerPredictable( int dx = 0, dy = 0; int *px = NULL, *py = NULL; DeviceVelocityPtr velocitydata = - (DeviceVelocityPtr) pDev->valuator->accelScheme.accelData; + (DeviceVelocityPtr) dev->valuator->accelScheme.accelData; float fdx, fdy, tmp; /* no need to init */ Bool soften = TRUE; @@ -990,12 +1004,12 @@ acceleratePointerPredictable( soften = FALSE; } - if (pDev->ptrfeed && pDev->ptrfeed->ctrl.num) { + if (dev->ptrfeed && dev->ptrfeed->ctrl.num) { /* invoke acceleration profile to determine acceleration */ - mult = ComputeAcceleration (velocitydata, - pDev->ptrfeed->ctrl.threshold, - (float)pDev->ptrfeed->ctrl.num / - (float)pDev->ptrfeed->ctrl.den); + mult = ComputeAcceleration (dev, velocitydata, + dev->ptrfeed->ctrl.threshold, + (float)dev->ptrfeed->ctrl.num / + (float)dev->ptrfeed->ctrl.den); if(mult != 1.0 || velocitydata->const_acceleration != 1.0) { ApplySofteningAndConstantDeceleration( velocitydata, @@ -1004,21 +1018,22 @@ acceleratePointerPredictable( (mult > 1.0) && soften); if (dx) { - tmp = mult * fdx + pDev->last.remainder[0]; + tmp = mult * fdx + dev->last.remainder[0]; /* Since it may not be apparent: lrintf() does not offer * strong statements about rounding; however because we * process each axis conditionally, there's no danger * of a toggling remainder. Its lack of guarantees likely * makes it faster on the average target. */ *px = lrintf(tmp); - pDev->last.remainder[0] = tmp - (float)*px; + dev->last.remainder[0] = tmp - (float)*px; } if (dy) { - tmp = mult * fdy + pDev->last.remainder[1]; + tmp = mult * fdy + dev->last.remainder[1]; *py = lrintf(tmp); - pDev->last.remainder[1] = tmp - (float)*py; + dev->last.remainder[1] = tmp - (float)*py; } - DebugAccelF("pos (%i | %i) remainders x: %.3f y: %.3f delta x:%.3f y:%.3f\n", *px, *py, pDev->last.remainder[0], pDev->last.remainder[1], fdx, fdy); + DebugAccelF("pos (%i | %i) remainders x: %.3f y: %.3f delta x:%.3f y:%.3f\n", + *px, *py, dev->last.remainder[0], dev->last.remainder[1], fdx, fdy); } } } @@ -1035,7 +1050,7 @@ acceleratePointerPredictable( */ void acceleratePointerLightweight( - DeviceIntPtr pDev, + DeviceIntPtr dev, int first_valuator, int num_valuators, int *valuators, @@ -1060,48 +1075,48 @@ acceleratePointerLightweight( if (!dx && !dy) return; - if (pDev->ptrfeed && pDev->ptrfeed->ctrl.num) { + if (dev->ptrfeed && dev->ptrfeed->ctrl.num) { /* modeled from xf86Events.c */ - if (pDev->ptrfeed->ctrl.threshold) { - if ((abs(dx) + abs(dy)) >= pDev->ptrfeed->ctrl.threshold) { - pDev->last.remainder[0] = ((float)dx * - (float)(pDev->ptrfeed->ctrl.num)) / - (float)(pDev->ptrfeed->ctrl.den) + - pDev->last.remainder[0]; + if (dev->ptrfeed->ctrl.threshold) { + if ((abs(dx) + abs(dy)) >= dev->ptrfeed->ctrl.threshold) { + dev->last.remainder[0] = ((float)dx * + (float)(dev->ptrfeed->ctrl.num)) / + (float)(dev->ptrfeed->ctrl.den) + + dev->last.remainder[0]; if (px) { - *px = (int)pDev->last.remainder[0]; - pDev->last.remainder[0] = pDev->last.remainder[0] - + *px = (int)dev->last.remainder[0]; + dev->last.remainder[0] = dev->last.remainder[0] - (float)(*px); } - pDev->last.remainder[1] = ((float)dy * - (float)(pDev->ptrfeed->ctrl.num)) / - (float)(pDev->ptrfeed->ctrl.den) + - pDev->last.remainder[1]; + dev->last.remainder[1] = ((float)dy * + (float)(dev->ptrfeed->ctrl.num)) / + (float)(dev->ptrfeed->ctrl.den) + + dev->last.remainder[1]; if (py) { - *py = (int)pDev->last.remainder[1]; - pDev->last.remainder[1] = pDev->last.remainder[1] - + *py = (int)dev->last.remainder[1]; + dev->last.remainder[1] = dev->last.remainder[1] - (float)(*py); } } } else { mult = pow((float)dx * (float)dx + (float)dy * (float)dy, - ((float)(pDev->ptrfeed->ctrl.num) / - (float)(pDev->ptrfeed->ctrl.den) - 1.0) / + ((float)(dev->ptrfeed->ctrl.num) / + (float)(dev->ptrfeed->ctrl.den) - 1.0) / 2.0) / 2.0; if (dx) { - pDev->last.remainder[0] = mult * (float)dx + - pDev->last.remainder[0]; - *px = (int)pDev->last.remainder[0]; - pDev->last.remainder[0] = pDev->last.remainder[0] - + dev->last.remainder[0] = mult * (float)dx + + dev->last.remainder[0]; + *px = (int)dev->last.remainder[0]; + dev->last.remainder[0] = dev->last.remainder[0] - (float)(*px); } if (dy) { - pDev->last.remainder[1] = mult * (float)dy + - pDev->last.remainder[1]; - *py = (int)pDev->last.remainder[1]; - pDev->last.remainder[1] = pDev->last.remainder[1] - + dev->last.remainder[1] = mult * (float)dy + + dev->last.remainder[1]; + *py = (int)dev->last.remainder[1]; + dev->last.remainder[1] = dev->last.remainder[1] - (float)(*py); } } diff --git a/dix/registry.c b/dix/registry.c index a519cff6b..ec853b37f 100644 --- a/dix/registry.c +++ b/dix/registry.c @@ -1,6 +1,6 @@ /************************************************************ -Author: Eamon Walsh <ewalsh@epoch.ncsc.mil> +Author: Eamon Walsh <ewalsh@tycho.nsa.gov> Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that diff --git a/dix/resource.c b/dix/resource.c index 73bc3a998..d3641df8d 100644 --- a/dix/resource.c +++ b/dix/resource.c @@ -707,7 +707,8 @@ LookupClientResourceComplex( pointer cdata ){ ResourcePtr *resources; - ResourcePtr this; + ResourcePtr this, next; + pointer value; int i; if (!client) @@ -715,10 +716,13 @@ LookupClientResourceComplex( resources = clientTable[client->index].resources; for (i = 0; i < clientTable[client->index].buckets; i++) { - for (this = resources[i]; this; this = this->next) { + for (this = resources[i]; this; this = next) { + next = this->next; if (!type || this->type == type) { - if((*func)(this->value, this->id, cdata)) - return this->value; + /* workaround func freeing the type as DRI1 does */ + value = this->value; + if((*func)(value, this->id, cdata)) + return value; } } } diff --git a/dix/swaprep.c b/dix/swaprep.c index 86242168f..12c6dbd26 100644 --- a/dix/swaprep.c +++ b/dix/swaprep.c @@ -731,7 +731,7 @@ SLHostsExtend(ClientPtr pClient, int size, char *buf) int len = host->length; char n; swaps (&host->length, n); - bufT += sizeof (xHostEntry) + (((len + 3) >> 2) << 2); + bufT += sizeof (xHostEntry) + pad_to_int32(len); } (void)WriteToClient (pClient, size, buf); } @@ -1222,7 +1222,7 @@ SwapConnSetupInfo( pInfoT += sizeof(xConnSetup); /* Copy the vendor string */ - i = (pConnSetup->nbytesVendor + 3) & ~3; + i = pad_to_int32(pConnSetup->nbytesVendor); memcpy(pInfoT, pInfo, i); pInfo += i; pInfoT += i; diff --git a/dix/window.c b/dix/window.c index 99b594b63..caff1cbff 100644 --- a/dix/window.c +++ b/dix/window.c @@ -1457,8 +1457,8 @@ GetWindowAttributes(WindowPtr pWin, ClientPtr client, xGetWindowAttributesReply wa->backingStore = NotUseful; else wa->backingStore = pWin->backingStore; - wa->length = (sizeof(xGetWindowAttributesReply) - - sizeof(xGenericReply)) >> 2; + wa->length = bytes_to_int32(sizeof(xGetWindowAttributesReply) - + sizeof(xGenericReply)); wa->sequenceNumber = client->sequence; wa->backingBitPlanes = wBackingBitPlanes (pWin); wa->backingPixel = wBackingPixel (pWin); @@ -3128,8 +3128,6 @@ dixSaveScreens(ClientPtr client, int on, int mode) if (on == SCREEN_SAVER_FORCER) { - UpdateCurrentTimeIf(); - lastDeviceEventTime = currentTime; if (mode == ScreenSaverReset) what = SCREEN_SAVER_OFF; else @@ -3388,7 +3386,7 @@ CheckWindowOptionalNeed (WindowPtr w) WindowOptPtr optional; WindowOptPtr parentOptional; - if (!w->parent) + if (!w->parent || !w->optional) return; optional = w->optional; if (optional->dontPropagateMask != DontPropagateMasks[w->dontPropagate]) @@ -3543,7 +3541,7 @@ ChangeWindowDeviceCursor(WindowPtr pWin, pWin->optional->deviceCursors = pNode->next; xfree(pNode); - return Success; + goto out; } } else @@ -3588,6 +3586,7 @@ ChangeWindowDeviceCursor(WindowPtr pWin, } } +out: if (pWin->realized) WindowHasNewCursor(pWin); |