hw/xwin: Map extra mouse buttons 1 and 2 to X buttons 8 and 9

Map extra mouse buttons 1 and 2 to X buttons 8 and 9, as conventional, leaving X
buttons 6 and 7 for tilt wheel.

Also add button labels for buttons 6, 7, 8 and 9 and change btn_labels in from a
dynamic allocation to a fixed one of the required size for all the labels we
use.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
This commit is contained in:
Jon TURNEY 2013-02-21 17:10:45 +00:00
parent c9d7b9516f
commit cf9c777ee0
4 changed files with 23 additions and 13 deletions

View File

@ -65,10 +65,10 @@ int
winMouseProc(DeviceIntPtr pDeviceInt, int iState)
{
int lngMouseButtons, i;
int lngWheelEvents = 2;
int lngWheelEvents = 4;
CARD8 *map;
DevicePtr pDevice = (DevicePtr) pDeviceInt;
Atom *btn_labels;
Atom btn_labels[9];
Atom axes_labels[2];
switch (iState) {
@ -80,15 +80,23 @@ winMouseProc(DeviceIntPtr pDeviceInt, int iState)
/* 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 ...
* TILT_LEFT:6 TILT_RIGHT:7
* XBUTTON 1:8 XBUTTON 2:9 (most commonly 'back' and 'forward')
* ...
*
* The current Windows API only defines 2 extra buttons, so we don't
* expect more than 5 buttons to be reported, but more than that
* should be handled correctly
*/
/*
* To map scroll wheel correctly we need at least the 3 normal buttons
*/
if (lngMouseButtons < 3)
lngMouseButtons = 3;
/* allocate memory:
* number of buttons + 2x mouse wheel event + 1 extra (offset for map)
/* allocate memory:
* number of buttons + 4 x mouse wheel event + 1 extra (offset for map)
*/
map = malloc(sizeof(CARD8) * (lngMouseButtons + lngWheelEvents + 1));
@ -97,12 +105,15 @@ winMouseProc(DeviceIntPtr pDeviceInt, int iState)
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);
btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);
btn_labels[7] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_BACK);
btn_labels[8] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_FORWARD);
axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
@ -114,7 +125,6 @@ winMouseProc(DeviceIntPtr pDeviceInt, int iState)
winMouseCtrl,
GetMotionHistorySize(), 2, axes_labels);
free(map);
free(btn_labels);
g_winMouseButtonMap = pDeviceInt->button->map;
break;

View File

@ -661,7 +661,7 @@ winTopLevelWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
break;
SetCapture(hwnd);
return winMouseButtonsHandle(s_pScreen, ButtonPress, HIWORD(wParam) + 5,
return winMouseButtonsHandle(s_pScreen, ButtonPress, HIWORD(wParam) + 7,
wParam);
case WM_XBUTTONUP:
@ -670,7 +670,7 @@ winTopLevelWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
ReleaseCapture();
winStartMousePolling(s_pScreenPriv);
return winMouseButtonsHandle(s_pScreen, ButtonRelease,
HIWORD(wParam) + 5, wParam);
HIWORD(wParam) + 7, wParam);
case WM_MOUSEWHEEL:
if (SendMessage

View File

@ -649,13 +649,13 @@ winMWExtWMWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput)
break;
SetCapture(hwnd);
return winMouseButtonsHandle(pScreen, ButtonPress, HIWORD(wParam) + 5,
return winMouseButtonsHandle(pScreen, ButtonPress, HIWORD(wParam) + 7,
wParam);
case WM_XBUTTONUP:
if (pScreenPriv == NULL || pScreenInfo->fIgnoreInput)
break;
ReleaseCapture();
return winMouseButtonsHandle(pScreen, ButtonRelease, HIWORD(wParam) + 5,
return winMouseButtonsHandle(pScreen, ButtonRelease, HIWORD(wParam) + 7,
wParam);
case WM_MOUSEWHEEL:

View File

@ -894,7 +894,7 @@ winWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
#endif
)
SetCapture(hwnd);
return winMouseButtonsHandle(s_pScreen, ButtonPress, HIWORD(wParam) + 5,
return winMouseButtonsHandle(s_pScreen, ButtonPress, HIWORD(wParam) + 7,
wParam);
case WM_XBUTTONUP:
if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
@ -906,7 +906,7 @@ winWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
)
ReleaseCapture();
return winMouseButtonsHandle(s_pScreen, ButtonRelease,
HIWORD(wParam) + 5, wParam);
HIWORD(wParam) + 7, wParam);
case WM_TIMER:
if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)