fix: handle back mouse on xwindows and windows
based on : 9f15b1bcf2
fixes: #5682
This commit is contained in:
@ -28,4 +28,4 @@ static const ButtonID kMacButtonRight = 2;
|
||||
static const ButtonID kMacButtonMiddle = 3;
|
||||
//@}
|
||||
|
||||
static const uint8_t NumButtonIDs = 5;
|
||||
static const uint8_t NumButtonIDs = 6;
|
||||
|
||||
@ -272,12 +272,12 @@ void MSWindowsDesks::fakeMouseButton(ButtonID button, bool press)
|
||||
flags = press ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP;
|
||||
break;
|
||||
|
||||
case kButtonExtra0 + 0:
|
||||
case kButtonExtra0:
|
||||
data = XBUTTON1;
|
||||
flags = press ? MOUSEEVENTF_XDOWN : MOUSEEVENTF_XUP;
|
||||
break;
|
||||
|
||||
case kButtonExtra0 + 1:
|
||||
case kButtonExtra1:
|
||||
data = XBUTTON2;
|
||||
flags = press ? MOUSEEVENTF_XDOWN : MOUSEEVENTF_XUP;
|
||||
break;
|
||||
|
||||
@ -1506,13 +1506,13 @@ ButtonID MSWindowsScreen::mapButtonFromEvent(WPARAM msg, LPARAM button) const
|
||||
switch (button) {
|
||||
case XBUTTON1:
|
||||
if (GetSystemMetrics(SM_CMOUSEBUTTONS) >= 4) {
|
||||
return kButtonExtra0 + 0;
|
||||
return kButtonExtra0;
|
||||
}
|
||||
break;
|
||||
|
||||
case XBUTTON2:
|
||||
if (GetSystemMetrics(SM_CMOUSEBUTTONS) >= 5) {
|
||||
return kButtonExtra0 + 1;
|
||||
return kButtonExtra1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -318,7 +318,7 @@ private:
|
||||
HotKeyToIDMap m_hotKeyToIDMap;
|
||||
|
||||
// map of button state
|
||||
bool m_buttons[1 + kButtonExtra0 + 1];
|
||||
bool m_buttons[NumButtonIDs];
|
||||
|
||||
// m_hasMouse is true if there's a mouse attached to the system or
|
||||
// mouse keys is simulating one. we track this so we can force the
|
||||
|
||||
@ -1743,51 +1743,34 @@ KeyID XWindowsScreen::mapKeyFromX(XKeyEvent *event) const
|
||||
|
||||
ButtonID XWindowsScreen::mapButtonFromX(const XButtonEvent *event) const
|
||||
{
|
||||
unsigned int button = event->button;
|
||||
|
||||
// first three buttons map to 1, 2, 3 (kButtonLeft, Middle, Right)
|
||||
if (button >= 1 && button <= 3) {
|
||||
return static_cast<ButtonID>(button);
|
||||
}
|
||||
|
||||
// buttons 4 and 5 are ignored here. they're used for the wheel.
|
||||
// buttons 6, 7, etc and up map to 4, 5, etc.
|
||||
else if (button >= 6) {
|
||||
return static_cast<ButtonID>(button - 2);
|
||||
}
|
||||
|
||||
// unknown button
|
||||
else {
|
||||
switch (unsigned int button = event->button; button) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
return static_cast<ButtonID>(button); // Handle Left, Middle and Right buttons
|
||||
case 8:
|
||||
return kButtonExtra0; // Mouse 4
|
||||
case 9:
|
||||
return kButtonExtra1; // Mouse 5
|
||||
default:
|
||||
return kButtonNone;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int XWindowsScreen::mapButtonToX(ButtonID id) const
|
||||
{
|
||||
// map button -1 to button 4 (+wheel)
|
||||
if (id == static_cast<ButtonID>(-1)) {
|
||||
id = 4;
|
||||
}
|
||||
|
||||
// map button -2 to button 5 (-wheel)
|
||||
else if (id == static_cast<ButtonID>(-2)) {
|
||||
id = 5;
|
||||
}
|
||||
|
||||
// map buttons 4, 5, etc. to 6, 7, etc. to make room for buttons
|
||||
// 4 and 5 used to simulate the mouse wheel.
|
||||
else if (id >= 4) {
|
||||
id += 2;
|
||||
}
|
||||
|
||||
// check button is in legal range
|
||||
if (id < 1 || id > m_buttons.size()) {
|
||||
// out of range
|
||||
switch (id) {
|
||||
case kButtonLeft:
|
||||
case kButtonRight:
|
||||
case kButtonMiddle:
|
||||
return static_cast<uint>(id);
|
||||
case kButtonExtra0:
|
||||
return 8;
|
||||
case kButtonExtra1:
|
||||
return 9;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
// map button
|
||||
return static_cast<unsigned int>(id);
|
||||
}
|
||||
|
||||
void XWindowsScreen::warpCursorNoFlush(int32_t x, int32_t y)
|
||||
|
||||
Reference in New Issue
Block a user