fix: handle back mouse on xwindows and windows
based on : 9f15b1bcf2
fixes: #5682
This commit is contained in:
parent
403c4ad9b9
commit
05c050b81e
5 changed files with 26 additions and 43 deletions
|
|
@ -28,4 +28,4 @@ static const ButtonID kMacButtonRight = 2;
|
||||||
static const ButtonID kMacButtonMiddle = 3;
|
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;
|
flags = press ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kButtonExtra0 + 0:
|
case kButtonExtra0:
|
||||||
data = XBUTTON1;
|
data = XBUTTON1;
|
||||||
flags = press ? MOUSEEVENTF_XDOWN : MOUSEEVENTF_XUP;
|
flags = press ? MOUSEEVENTF_XDOWN : MOUSEEVENTF_XUP;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kButtonExtra0 + 1:
|
case kButtonExtra1:
|
||||||
data = XBUTTON2;
|
data = XBUTTON2;
|
||||||
flags = press ? MOUSEEVENTF_XDOWN : MOUSEEVENTF_XUP;
|
flags = press ? MOUSEEVENTF_XDOWN : MOUSEEVENTF_XUP;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -1506,13 +1506,13 @@ ButtonID MSWindowsScreen::mapButtonFromEvent(WPARAM msg, LPARAM button) const
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case XBUTTON1:
|
case XBUTTON1:
|
||||||
if (GetSystemMetrics(SM_CMOUSEBUTTONS) >= 4) {
|
if (GetSystemMetrics(SM_CMOUSEBUTTONS) >= 4) {
|
||||||
return kButtonExtra0 + 0;
|
return kButtonExtra0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XBUTTON2:
|
case XBUTTON2:
|
||||||
if (GetSystemMetrics(SM_CMOUSEBUTTONS) >= 5) {
|
if (GetSystemMetrics(SM_CMOUSEBUTTONS) >= 5) {
|
||||||
return kButtonExtra0 + 1;
|
return kButtonExtra1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -318,7 +318,7 @@ private:
|
||||||
HotKeyToIDMap m_hotKeyToIDMap;
|
HotKeyToIDMap m_hotKeyToIDMap;
|
||||||
|
|
||||||
// map of button state
|
// 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
|
// 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
|
// 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
|
ButtonID XWindowsScreen::mapButtonFromX(const XButtonEvent *event) const
|
||||||
{
|
{
|
||||||
unsigned int button = event->button;
|
switch (unsigned int button = event->button; button) {
|
||||||
|
case 1:
|
||||||
// first three buttons map to 1, 2, 3 (kButtonLeft, Middle, Right)
|
case 2:
|
||||||
if (button >= 1 && button <= 3) {
|
case 3:
|
||||||
return static_cast<ButtonID>(button);
|
return static_cast<ButtonID>(button); // Handle Left, Middle and Right buttons
|
||||||
}
|
case 8:
|
||||||
|
return kButtonExtra0; // Mouse 4
|
||||||
// buttons 4 and 5 are ignored here. they're used for the wheel.
|
case 9:
|
||||||
// buttons 6, 7, etc and up map to 4, 5, etc.
|
return kButtonExtra1; // Mouse 5
|
||||||
else if (button >= 6) {
|
default:
|
||||||
return static_cast<ButtonID>(button - 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// unknown button
|
|
||||||
else {
|
|
||||||
return kButtonNone;
|
return kButtonNone;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int XWindowsScreen::mapButtonToX(ButtonID id) const
|
unsigned int XWindowsScreen::mapButtonToX(ButtonID id) const
|
||||||
{
|
{
|
||||||
// map button -1 to button 4 (+wheel)
|
switch (id) {
|
||||||
if (id == static_cast<ButtonID>(-1)) {
|
case kButtonLeft:
|
||||||
id = 4;
|
case kButtonRight:
|
||||||
}
|
case kButtonMiddle:
|
||||||
|
return static_cast<uint>(id);
|
||||||
// map button -2 to button 5 (-wheel)
|
case kButtonExtra0:
|
||||||
else if (id == static_cast<ButtonID>(-2)) {
|
return 8;
|
||||||
id = 5;
|
case kButtonExtra1:
|
||||||
}
|
return 9;
|
||||||
|
default:
|
||||||
// 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
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// map button
|
|
||||||
return static_cast<unsigned int>(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void XWindowsScreen::warpCursorNoFlush(int32_t x, int32_t y)
|
void XWindowsScreen::warpCursorNoFlush(int32_t x, int32_t y)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue