diff --git a/hw/xwin/ChangeLog b/hw/xwin/ChangeLog index 9ddb0eb8e..2e3dd19a8 100644 --- a/hw/xwin/ChangeLog +++ b/hw/xwin/ChangeLog @@ -1,3 +1,11 @@ +2004-10-02 Alexander Gottwald + + * winmouse.c (winMouseProc): + Make sure buttons 1-3 are mouse buttons and wheel events are 4-5 + Document code + Replace ErrorF with appropriate winMsg + use a symbolic name for the wheel event offset + 2004-10-01 Alexander Gottwald * wincreatewnd.c (winCreateBoundingWindowWindowed): diff --git a/hw/xwin/winmouse.c b/hw/xwin/winmouse.c index 6411d7989..93b38acd4 100644 --- a/hw/xwin/winmouse.c +++ b/hw/xwin/winmouse.c @@ -65,21 +65,39 @@ int winMouseProc (DeviceIntPtr pDeviceInt, int iState) { int lngMouseButtons, i; + int lngWheelEvents = 2; CARD8 *map; DevicePtr pDevice = (DevicePtr) pDeviceInt; switch (iState) { case DEVICE_INIT: + /* Get number of mouse buttons */ lngMouseButtons = GetSystemMetrics(SM_CMOUSEBUTTONS); - ErrorF ("%d mouse buttons found\n", lngMouseButtons); - map = malloc(sizeof(CARD8) * (lngMouseButtons + 1 + 2)); - - for (i=1; i <= lngMouseButtons + 2; i++) + + /* Mapping of windows events to X events: + * LEFT:1 MIDDLE:2 RIGHT:3 + * SCROLL_UP:4 SCROLL_DOWN:5 + * XBUTTON 1:6 XBUTTON 2:7 ... + * + * To map scroll wheel correctly we need at least the 3 normal buttons + */ + if (lngMouseButtons < 3) + lngMouseButtons = 3; + winMsg(X_PROBED, "%d mouse buttons found\n", lngMouseButtons); + + /* allocate memory: + * number of buttons + 2x mouse wheel event + 1 extra (offset for map) + */ + map = malloc(sizeof(CARD8) * (lngMouseButtons + lngWheelEvents + 1)); + + /* initalize button map */ + map[0] = 0; + for (i=1; i <= lngMouseButtons + lngWheelEvents; i++) map[i] = i; InitPointerDeviceStruct (pDevice, map, - lngMouseButtons + 2, /* Buttons 4 and 5 are mouse wheel events */ + lngMouseButtons + lngWheelEvents, miPointerGetMotionEvents, winMouseCtrl, miPointerGetMotionBufferSize ());