#ifdef HAVE_XWIN_CONFIG_H
#include <xwin-config.h>
#endif
#include "win.h"
#include "inputstr.h"
#include "exevents.h"
#include "xserver-properties.h"
#include "inpututils.h"
static CARD8 const *g_winMouseButtonMap = NULL;
static void
winMouseCtrl (DeviceIntPtr pDevice, PtrCtrl *pCtrl);
static void
winMouseCtrl (DeviceIntPtr pDevice, PtrCtrl *pCtrl)
{
}
int
winMouseProc (DeviceIntPtr pDeviceInt, int iState)
{
int lngMouseButtons, i;
int lngWheelEvents = 2;
CARD8 *map;
DevicePtr pDevice = (DevicePtr) pDeviceInt;
Atom *btn_labels;
Atom axes_labels[2];
switch (iState)
{
case DEVICE_INIT:
lngMouseButtons = GetSystemMetrics(SM_CMOUSEBUTTONS);
if (lngMouseButtons < 3)
lngMouseButtons = 3;
winMsg(X_PROBED, "%d mouse buttons found\n", lngMouseButtons);
map = malloc(sizeof(CARD8) * (lngMouseButtons + lngWheelEvents + 1));
map[0] = 0;
for (i=1; i <= lngMouseButtons + lngWheelEvents; i++)
map[i] = i;
btn_labels = calloc((lngMouseButtons + lngWheelEvents), sizeof(Atom));
btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
InitPointerDeviceStruct (pDevice,
map,
lngMouseButtons + lngWheelEvents,
btn_labels,
winMouseCtrl,
GetMotionHistorySize(),
2,
axes_labels);
free(map);
free(btn_labels);
g_winMouseButtonMap = pDeviceInt->button->map;
break;
case DEVICE_ON:
pDevice->on = TRUE;
break;
case DEVICE_CLOSE:
g_winMouseButtonMap = NULL;
case DEVICE_OFF:
pDevice->on = FALSE;
break;
}
return Success;
}
int
winMouseWheel (ScreenPtr pScreen, int iDeltaZ)
{
winScreenPriv(pScreen);
int button;
if ((pScreenPriv->iDeltaZ > 0
&& iDeltaZ > 0)
|| (pScreenPriv->iDeltaZ < 0
&& iDeltaZ < 0))
{
iDeltaZ += pScreenPriv->iDeltaZ;
pScreenPriv->iDeltaZ = 0;
}
else
{
pScreenPriv->iDeltaZ = 0;
}
if (iDeltaZ >= WHEEL_DELTA || (-1 * iDeltaZ) >= WHEEL_DELTA)
{
pScreenPriv->iDeltaZ = 0;
iDeltaZ /= WHEEL_DELTA;
}
else
{
pScreenPriv->iDeltaZ = iDeltaZ;
return 0;
}
if (iDeltaZ > 0)
{
button = Button4;
}
else
{
button = Button5;
}
if (iDeltaZ < 0)
{
iDeltaZ *= -1;
}
while (iDeltaZ--)
{
winMouseButtonsSendEvent (ButtonPress, button);
winMouseButtonsSendEvent (ButtonRelease, button);
}
return 0;
}
void
winMouseButtonsSendEvent (int iEventType, int iButton)
{
EventListPtr events;
int i, nevents;
ValuatorMask mask;
if (g_winMouseButtonMap)
iButton = g_winMouseButtonMap[iButton];
valuator_mask_zero(&mask);
GetEventList(&events);
nevents = GetPointerEvents(events, g_pwinPointer, iEventType, iButton,
POINTER_RELATIVE, &mask);
for (i = 0; i < nevents; i++)
mieqEnqueue(g_pwinPointer, (InternalEvent*)events[i].event);
#if CYGDEBUG
ErrorF("winMouseButtonsSendEvent: iEventType: %d, iButton: %d, nEvents %d\n",
iEventType, iButton, nevents);
#endif
}
int
winMouseButtonsHandle (ScreenPtr pScreen,
int iEventType, int iButton,
WPARAM wParam)
{
winScreenPriv(pScreen);
winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
if (pScreenInfo->iE3BTimeout == WIN_E3B_OFF)
{
winMouseButtonsSendEvent (iEventType, iButton);
return 0;
}
if (iEventType == ButtonPress
&& pScreenPriv->iE3BCachedPress == 0
&& !pScreenPriv->fE3BFakeButton2Sent)
{
pScreenPriv->iE3BCachedPress = iButton;
SetTimer (pScreenPriv->hwndScreen,
WIN_E3B_TIMER_ID,
pScreenInfo->iE3BTimeout,
NULL);
}
else if (iEventType == ButtonPress
&& pScreenPriv->iE3BCachedPress != 0
&& pScreenPriv->iE3BCachedPress != iButton
&& !pScreenPriv->fE3BFakeButton2Sent)
{
KillTimer (pScreenPriv->hwndScreen, WIN_E3B_TIMER_ID);
pScreenPriv->iE3BCachedPress = 0;
winMouseButtonsSendEvent (ButtonPress, Button2);
pScreenPriv->fE3BFakeButton2Sent = TRUE;
}
else if (iEventType == ButtonRelease
&& pScreenPriv->iE3BCachedPress == iButton)
{
KillTimer (pScreenPriv->hwndScreen, WIN_E3B_TIMER_ID);
pScreenPriv->iE3BCachedPress = 0;
winMouseButtonsSendEvent (ButtonPress, iButton);
winMouseButtonsSendEvent (ButtonRelease, iButton);
}
else if (iEventType == ButtonRelease
&& pScreenPriv->fE3BFakeButton2Sent
&& !(wParam & MK_LBUTTON)
&& !(wParam & MK_RBUTTON))
{
pScreenPriv->fE3BFakeButton2Sent = FALSE;
winMouseButtonsSendEvent (ButtonRelease, Button2);
}
else if (iEventType == ButtonRelease
&& pScreenPriv->iE3BCachedPress == 0
&& !pScreenPriv->fE3BFakeButton2Sent)
{
winMouseButtonsSendEvent (ButtonRelease, iButton);
}
return 0;
}
void winEnqueueMotion(int x, int y)
{
int i, nevents;
int valuators[2];
ValuatorMask mask;
EventListPtr events;
miPointerSetPosition(g_pwinPointer, &x, &y);
valuators[0] = x;
valuators[1] = y;
valuator_mask_set_range(&mask, 0, 2, valuators);
GetEventList(&events);
nevents = GetPointerEvents(events, g_pwinPointer, MotionNotify, 0,
POINTER_ABSOLUTE | POINTER_SCREEN, &mask);
for (i = 0; i < nevents; i++)
mieqEnqueue(g_pwinPointer, (InternalEvent*)events[i].event);
}