no longer sending fake events for unmapped logical buttons.

This commit is contained in:
crs 2002-08-18 17:31:48 +00:00
parent f49b186722
commit 305b01edf9
2 changed files with 44 additions and 11 deletions

View File

@ -114,18 +114,24 @@ CXWindowsSecondaryScreen::keyUp(KeyID key, KeyModifierMask mask)
void
CXWindowsSecondaryScreen::mouseDown(ButtonID button)
{
const unsigned int xButton = mapButton(button);
if (xButton != 0) {
CDisplayLock display(m_screen);
XTestFakeButtonEvent(display, mapButton(button), True, CurrentTime);
XTestFakeButtonEvent(display, xButton, True, CurrentTime);
XSync(display, False);
}
}
void
CXWindowsSecondaryScreen::mouseUp(ButtonID button)
{
const unsigned int xButton = mapButton(button);
if (xButton != 0) {
CDisplayLock display(m_screen);
XTestFakeButtonEvent(display, mapButton(button), False, CurrentTime);
XTestFakeButtonEvent(display, xButton, False, CurrentTime);
XSync(display, False);
}
}
void
CXWindowsSecondaryScreen::mouseMove(SInt32 x, SInt32 y)
@ -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,9 +368,18 @@ CXWindowsSecondaryScreen::setToggleState(KeyModifierMask mask)
unsigned int
CXWindowsSecondaryScreen::mapButton(ButtonID id) const
{
// FIXME -- should use button mapping?
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<unsigned int>(id);
}
}
KeyModifierMask
CXWindowsSecondaryScreen::mapKey(Keystrokes& keys, KeyCode& keycode,
@ -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);

View File

@ -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;