From 305b01edf928fc204c148d3d9d9cd72909908750 Mon Sep 17 00:00:00 2001 From: crs Date: Sun, 18 Aug 2002 17:31:48 +0000 Subject: [PATCH] no longer sending fake events for unmapped logical buttons. --- lib/client/CXWindowsSecondaryScreen.cpp | 51 +++++++++++++++++++------ lib/client/CXWindowsSecondaryScreen.h | 4 ++ 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/lib/client/CXWindowsSecondaryScreen.cpp b/lib/client/CXWindowsSecondaryScreen.cpp index 364a234a..80429c49 100644 --- a/lib/client/CXWindowsSecondaryScreen.cpp +++ b/lib/client/CXWindowsSecondaryScreen.cpp @@ -114,17 +114,23 @@ CXWindowsSecondaryScreen::keyUp(KeyID key, KeyModifierMask mask) void CXWindowsSecondaryScreen::mouseDown(ButtonID button) { - CDisplayLock display(m_screen); - XTestFakeButtonEvent(display, mapButton(button), True, CurrentTime); - XSync(display, False); + const unsigned int xButton = mapButton(button); + if (xButton != 0) { + CDisplayLock display(m_screen); + XTestFakeButtonEvent(display, xButton, True, CurrentTime); + XSync(display, False); + } } void CXWindowsSecondaryScreen::mouseUp(ButtonID button) { - CDisplayLock display(m_screen); - XTestFakeButtonEvent(display, mapButton(button), False, CurrentTime); - XSync(display, False); + const unsigned int xButton = mapButton(button); + if (xButton != 0) { + CDisplayLock display(m_screen); + XTestFakeButtonEvent(display, xButton, False, CurrentTime); + XSync(display, False); + } } void @@ -137,7 +143,10 @@ void CXWindowsSecondaryScreen::mouseWheel(SInt32 delta) { // choose button depending on rotation direction - const unsigned int button = (delta >= 0) ? 4 : 5; + const unsigned int xButton = mapButton((delta >= 0) ? 4 : 5); + if (xButton == 0) { + return; + } // now use absolute value of delta if (delta < 0) { @@ -147,8 +156,8 @@ CXWindowsSecondaryScreen::mouseWheel(SInt32 delta) // send as many clicks as necessary CDisplayLock display(m_screen); for (; delta >= 120; delta -= 120) { - XTestFakeButtonEvent(display, button, True, CurrentTime); - XTestFakeButtonEvent(display, button, False, CurrentTime); + XTestFakeButtonEvent(display, xButton, True, CurrentTime); + XTestFakeButtonEvent(display, xButton, False, CurrentTime); } XSync(display, False); } @@ -359,8 +368,17 @@ CXWindowsSecondaryScreen::setToggleState(KeyModifierMask mask) unsigned int CXWindowsSecondaryScreen::mapButton(ButtonID id) const { - // FIXME -- should use button mapping? - return static_cast(id); + if (id < 1 || id > sizeof(m_buttons) / sizeof(m_buttons[0])) { + // out of range + return 0; + } + else if (m_buttons[id - 1] == 0) { + // button not mapped + return 0; + } + else { + return static_cast(id); + } } KeyModifierMask @@ -830,6 +848,17 @@ CXWindowsSecondaryScreen::updateKeys() { CDisplayLock display(m_screen); + // get pointer mapping + static const UInt32 maxButtons = sizeof(m_buttons) / sizeof(m_buttons[0]); + unsigned char tmpButtons[sizeof(m_buttons) / sizeof(m_buttons[0])]; + UInt32 numButtons = XGetPointerMapping(display, tmpButtons, maxButtons); + for (UInt32 i = 0; i < maxButtons; ++i) { + m_buttons[i] = 0; + } + for (UInt32 i = 0; i < numButtons; ++i) { + m_buttons[tmpButtons[i] - 1] = i + 1; + } + // ask server which keys are pressed char keys[32]; XQueryKeymap(display, keys); diff --git a/lib/client/CXWindowsSecondaryScreen.h b/lib/client/CXWindowsSecondaryScreen.h index 556de6b4..2d20be82 100644 --- a/lib/client/CXWindowsSecondaryScreen.h +++ b/lib/client/CXWindowsSecondaryScreen.h @@ -113,6 +113,10 @@ private: // set entries indicate keys that are pressed. indexed by keycode. bool m_keys[256]; + // logical to physical button mapping. m_buttons[i] gives the + // physical button for logical button i+1. + unsigned char m_buttons[5]; + // current active modifiers (X key masks) unsigned int m_mask;