if (pMse->emulate3Buttons
if ((pMse->emulate3Buttons || pMse->emulate3ButtonsSoft)
MouseDoPostEvent(InputInfoPtr pInfo, int buttons, int dx, int dy){    MouseDevPtr pMse;    int truebuttons, emulateButtons;    int id, change;    int emuWheelDelta, emuWheelButton, emuWheelButtonMask;    pMse = pInfo->private;    truebuttons = buttons;    if (pMse->protocolID == PROT_MMHIT)	buttons = reverseBits(hitachMap, buttons);    else	buttons = reverseBits(reverseMap, buttons);    /* Intercept wheel emulation. */    if (pMse->emulateWheel && (buttons & pMse->wheelButtonMask)) {	/* Y axis movement */	if (pMse->negativeY != MSE_NOAXISMAP) {	    pMse->wheelYDistance += dy;	    if (pMse->wheelYDistance < 0) {		emuWheelDelta = -pMse->wheelInertia;		emuWheelButton = pMse->negativeY;	    } else {		emuWheelDelta = pMse->wheelInertia;		emuWheelButton = pMse->positiveY;	    }	    emuWheelButtonMask = 1 << (emuWheelButton - 1);	    while (abs(pMse->wheelYDistance) > pMse->wheelInertia) {		pMse->wheelYDistance -= emuWheelDelta;		/*		 * Synthesize the press and release, but not when the button		 * to be synthesized is already pressed "for real".		 */		if (!(emuWheelButtonMask & buttons) ||		    (emuWheelButtonMask & pMse->wheelButtonMask)) {		    xf86PostButtonEvent(pInfo->dev, 0, emuWheelButton, 1, 0, 0);		    xf86PostButtonEvent(pInfo->dev, 0, emuWheelButton, 0, 0, 0);		}	    }	}	/* X axis movement */	if (pMse->negativeX != MSE_NOAXISMAP) {	    pMse->wheelXDistance += dx;	    if (pMse->wheelXDistance < 0) {		emuWheelDelta = -pMse->wheelInertia;		emuWheelButton = pMse->negativeX;	    } else {		emuWheelDelta = pMse->wheelInertia;		emuWheelButton = pMse->positiveX;	    }	    emuWheelButtonMask = 1 << (emuWheelButton - 1);	    while (abs(pMse->wheelXDistance) > pMse->wheelInertia) {		pMse->wheelXDistance -= emuWheelDelta;		/*		 * Synthesize the press and release, but not when the button		 * to be synthesized is already pressed "for real".		 */		if (!(emuWheelButtonMask & buttons) ||		    (emuWheelButtonMask & pMse->wheelButtonMask)) {		    xf86PostButtonEvent(pInfo->dev, 0, emuWheelButton, 1, 0, 0);		    xf86PostButtonEvent(pInfo->dev, 0, emuWheelButton, 0, 0, 0);		}	    }	}	/* Absorb the mouse movement and the wheel button press. */	dx = 0;	dy = 0;	buttons &= ~pMse->wheelButtonMask;    }    if (dx || dy)	xf86PostMotionEvent(pInfo->dev, 0, 0, 2, dx, dy);    if (truebuttons != pMse->lastButtons) {	if (pMse->protocolID == PROT_MMHIT)	    change = buttons ^ reverseBits(hitachMap, pMse->lastButtons);	else	    change = buttons ^ reverseBits(reverseMap, pMse->lastButtons);	/*	 * adjust buttons state for drag locks!	 * if there is drag locks	 */        if (pMse->pDragLock) {      	    DragLockPtr   pLock;	    int tarOfGoingDown, tarOfDown;	    int realbuttons;	    /* get drag lock block */	    pLock = pMse->pDragLock;	    /* save real buttons */	    realbuttons = buttons;	    /* if drag lock used */	    /* state of drag lock buttons not seen always up */	    buttons &= ~pLock->lockButtonsM;	    /*	     * if lock buttons being depressed changes state of	     * targets simulatedDown.	     */	    tarOfGoingDown = lock2targetMap(pLock,				realbuttons & change & pLock->lockButtonsM);	    pLock->simulatedDown ^= tarOfGoingDown;	    /* targets of drag locks down */	    tarOfDown = lock2targetMap(pLock,				realbuttons & pLock->lockButtonsM);	    /*	     * when simulatedDown set and target pressed, 	     * simulatedDown goes false 	     */	    pLock->simulatedDown &= ~(realbuttons & change);	    /*	     * if master drag lock released  	     * then master drag lock state on	     */	    pLock->masterTS |= (~realbuttons & change) & pLock->masterLockM;	    /* if master state, buttons going down are simulatedDown */	    if (pLock->masterTS) 		pLock->simulatedDown |= (realbuttons & change);	    /* if any button pressed, no longer in master drag lock state */	    if (realbuttons & change)		pLock->masterTS = 0;	    /* if simulatedDown or drag lock down, simulate down */	    buttons |= (pLock->simulatedDown | tarOfDown);	    /* master button not seen */	    buttons &= ~(pLock->masterLockM);	    /* buttons changed since last time */	    change = buttons ^ pLock->lockLastButtons;	    /* save this time for next last time. */	    pLock->lockLastButtons = buttons;	}        if (pMse->emulate3Buttons	    && (!(buttons & 0x02) || Emulate3ButtonsSoft(pInfo))) {            /* handle all but buttons 1 & 3 normally */            change &= ~05;            /* emulate the third button by the other two */            emulateButtons = (buttons & 01) | ((buttons &04) >> 1);            if ((id = stateTab[pMse->emulateState][emulateButtons][0]) != 0)                xf86PostButtonEvent(pInfo->dev, 0, abs(id), (id >= 0), 0, 0);            if ((id = stateTab[pMse->emulateState][emulateButtons][1]) != 0)                xf86PostButtonEvent(pInfo->dev, 0, abs(id), (id >= 0), 0, 0);            pMse->emulateState =                stateTab[pMse->emulateState][emulateButtons][2];            if (stateTab[pMse->emulateState][4][0] != 0) {		pMse->emulate3Expires = GetTimeInMillis () + pMse->emulate3Timeout;		pMse->emulate3Pending = TRUE;            } else {		pMse->emulate3Pending = FALSE;            }        }	while (change) {	    id = ffs(change);	    change &= ~(1 << (id - 1));	    xf86PostButtonEvent(pInfo->dev, 0, id,				(buttons & (1 << (id - 1))), 0, 0);	}        pMse->lastButtons = truebuttons;    }}