Now handling any number of pointer buttons.

This commit is contained in:
crs 2002-12-15 22:39:59 +00:00
parent 2559dd2f05
commit 9c70921525
2 changed files with 24 additions and 7 deletions

View File

@ -424,7 +424,7 @@ CXWindowsSecondaryScreen::getToggleState() const
unsigned int unsigned int
CXWindowsSecondaryScreen::mapButton(ButtonID id) const CXWindowsSecondaryScreen::mapButton(ButtonID id) const
{ {
if (id < 1 || id > sizeof(m_buttons) / sizeof(m_buttons[0])) { if (id < 1 || id > m_buttons.size()) {
// out of range // out of range
return 0; return 0;
} }
@ -886,17 +886,34 @@ CXWindowsSecondaryScreen::updateKeys()
{ {
CDisplayLock display(m_screen); CDisplayLock display(m_screen);
// get pointer mapping // query the button mapping
static const UInt32 maxButtons = sizeof(m_buttons) / sizeof(m_buttons[0]); UInt32 numButtons = XGetPointerMapping(display, NULL, 0);
unsigned char tmpButtons[sizeof(m_buttons) / sizeof(m_buttons[0])]; unsigned char* tmpButtons = new unsigned char[numButtons];
UInt32 numButtons = XGetPointerMapping(display, tmpButtons, maxButtons); XGetPointerMapping(display, tmpButtons, numButtons);
for (UInt32 i = 0; i < maxButtons; ++i) {
// find the largest logical button id
unsigned char maxButton = 0;
for (UInt32 i = 0; i < numButtons; ++i) {
if (tmpButtons[i] > maxButton) {
maxButton = tmpButtons[i];
}
}
// allocate button array
m_buttons.resize(maxButton);
// fill in button array values. m_buttons[i] is the physical
// button number for logical button i+1.
for (UInt32 i = 0; i < numButtons; ++i) {
m_buttons[i] = 0; m_buttons[i] = 0;
} }
for (UInt32 i = 0; i < numButtons; ++i) { for (UInt32 i = 0; i < numButtons; ++i) {
m_buttons[tmpButtons[i] - 1] = i + 1; m_buttons[tmpButtons[i] - 1] = i + 1;
} }
// clean up
delete[] tmpButtons;
// ask server which keys are pressed // ask server which keys are pressed
char keys[32]; char keys[32];
XQueryKeymap(display, keys); XQueryKeymap(display, keys);

View File

@ -130,7 +130,7 @@ private:
// logical to physical button mapping. m_buttons[i] gives the // logical to physical button mapping. m_buttons[i] gives the
// physical button for logical button i+1. // physical button for logical button i+1.
unsigned char m_buttons[5]; std::vector<unsigned char> m_buttons;
// current active modifiers (X key masks) // current active modifiers (X key masks)
unsigned int m_mask; unsigned int m_mask;