Support 31 mouse buttons (with platform plugins xcb and xlib).

This commit includes changes for mouse button support within the XCB
and XLIB platform plugins. Support in other platform plugins will be
added in the future. The namespace update is prerequisite to compile
the the Plugins, and the update in qguiapplication.cpp is required for
the enhancements to actually work.

Task-number: QTBUG-22642
Change-Id: Ie18fca3b9c86d0b6abbf2103a4f8582e6ce83e7d
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
This commit is contained in:
Rick Stockton 2011-11-09 21:02:18 -08:00 committed by Qt by Nokia
parent beaf6b16a9
commit a329fc574b
4 changed files with 88 additions and 14 deletions

View File

@ -155,8 +155,37 @@ public:
MidButton = 0x00000004, // ### Qt 5: remove me
MiddleButton = MidButton,
XButton1 = 0x00000008,
BackButton = XButton1,
ExtraButton1 = XButton1,
XButton2 = 0x00000010,
MouseButtonMask = 0x000000ff
ForwardButton = XButton2,
ExtraButton2 = XButton2,
TaskButton = 0x00000020,
ExtraButton3 = TaskButton,
ExtraButton4 = 0x00000040,
ExtraButton5 = 0x00000080,
ExtraButton6 = 0x00000100,
ExtraButton7 = 0x00000200,
ExtraButton8 = 0x00000400,
ExtraButton9 = 0x00000800,
ExtraButton10 = 0x00001000,
ExtraButton11 = 0x00002000,
ExtraButton12 = 0x00004000,
ExtraButton13 = 0x00008000,
ExtraButton14 = 0x00010000,
ExtraButton15 = 0x00020000,
ExtraButton16 = 0x00040000,
ExtraButton17 = 0x00080000,
ExtraButton18 = 0x00100000,
ExtraButton19 = 0x00200000,
ExtraButton20 = 0x00400000,
ExtraButton21 = 0x00800000,
ExtraButton22 = 0x01000000,
ExtraButton23 = 0x02000000,
ExtraButton24 = 0x04000000,
MaxMouseButton = ExtraButton24,
// 4 high-order bits remain available for future use (0x08000000 through 0x40000000).
MouseButtonMask = 0xffffffff,
};
Q_DECLARE_FLAGS(MouseButtons, MouseButton)

View File

@ -316,7 +316,7 @@ static void init_plugins(const QList<QByteArray> &pluginList)
else
plugin = QGenericPluginFactory::create(QLatin1String(pluginSpec.mid(0, colonPos)),
QLatin1String(pluginSpec.mid(colonPos+1)));
qDebug() << " created" << plugin;
qDebug() << " created" << plugin;
if (plugin)
QGuiApplicationPrivate::generic_plugin_list.append(plugin);
}
@ -618,9 +618,9 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
qAbs(globalPoint.y() - mousePressY) > mouse_double_click_distance)
mousePressButton = Qt::NoButton;
}
else { // check to see if a new button has been pressed/released
else { // Check to see if a new button has been pressed/released.
for (int check = Qt::LeftButton;
check <= Qt::XButton2;
check <= Qt::MaxMouseButton;
check = check << 1) {
if (check & stateChange) {
button = Qt::MouseButton(check);
@ -628,7 +628,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
}
}
if (button == Qt::NoButton) {
// Ignore mouse events that don't change the current state
// Ignore mouse events that don't change the current state.
return;
}
buttons = e->buttons;

View File

@ -1265,14 +1265,35 @@ static Qt::MouseButtons translateMouseButtons(int s)
static Qt::MouseButton translateMouseButton(xcb_button_t s)
{
switch (s) {
case 1:
return Qt::LeftButton;
case 2:
return Qt::MidButton;
case 3:
return Qt::RightButton;
default:
return Qt::NoButton;
case 1: return Qt::LeftButton;
case 2: return Qt::MidButton;
case 3: return Qt::RightButton;
// Button values 4-7 were already handled as Wheel events, and won't occur here.
case 8: return Qt::BackButton; // Also known as Qt::ExtraButton1
case 9: return Qt::ForwardButton; // Also known as Qt::ExtraButton2
case 10: return Qt::ExtraButton3;
case 11: return Qt::ExtraButton4;
case 12: return Qt::ExtraButton5;
case 13: return Qt::ExtraButton6;
case 14: return Qt::ExtraButton7;
case 15: return Qt::ExtraButton8;
case 16: return Qt::ExtraButton9;
case 17: return Qt::ExtraButton10;
case 18: return Qt::ExtraButton11;
case 19: return Qt::ExtraButton12;
case 20: return Qt::ExtraButton13;
case 21: return Qt::ExtraButton14;
case 22: return Qt::ExtraButton15;
case 23: return Qt::ExtraButton16;
case 24: return Qt::ExtraButton17;
case 25: return Qt::ExtraButton18;
case 26: return Qt::ExtraButton19;
case 27: return Qt::ExtraButton20;
case 28: return Qt::ExtraButton21;
case 29: return Qt::ExtraButton22;
case 30: return Qt::ExtraButton23;
case 31: return Qt::ExtraButton24;
default: return Qt::NoButton;
}
}
@ -1286,7 +1307,7 @@ void QXcbWindow::handleButtonPressEvent(const xcb_button_press_event_t *event)
Qt::KeyboardModifiers modifiers = connection()->keyboard()->translateModifiers(event->state);
if (event->detail >= 4 && event->detail <= 7) {
//logic borrowed from qapplication_x11.cpp
// Logic borrowed from qapplication_x11.cpp
int delta = 120 * ((event->detail == 4 || event->detail == 6) ? 1 : -1);
bool hor = (((event->detail == 4 || event->detail == 5)
&& (modifiers & Qt::AltModifier))

View File

@ -221,6 +221,30 @@ void QXlibWindow::handleMouseEvent(QEvent::Type type, XButtonEvent *e)
}
return;
}
case 8: button = Qt::BackButton; break; // Also known as Qt::ExtraButton1
case 9: button = Qt::ForwardButton; break; // Also known as Qt::ExtraButton2
case 10: button = Qt::ExtraButton3; break;
case 11: button = Qt::ExtraButton4; break;
case 12: button = Qt::ExtraButton5; break;
case 13: button = Qt::ExtraButton6; break;
case 14: button = Qt::ExtraButton7; break;
case 15: button = Qt::ExtraButton8; break;
case 16: button = Qt::ExtraButton9; break;
case 17: button = Qt::ExtraButton10; break;
case 18: button = Qt::ExtraButton11; break;
case 19: button = Qt::ExtraButton12; break;
case 20: button = Qt::ExtraButton13; break;
case 21: button = Qt::ExtraButton14; break;
case 22: button = Qt::ExtraButton15; break;
case 23: button = Qt::ExtraButton16; break;
case 24: button = Qt::ExtraButton17; break;
case 25: button = Qt::ExtraButton18; break;
case 26: button = Qt::ExtraButton19; break;
case 27: button = Qt::ExtraButton20; break;
case 28: button = Qt::ExtraButton21; break;
case 29: button = Qt::ExtraButton22; break;
case 30: button = Qt::ExtraButton23; break;
case 31: button = Qt::ExtraButton24; break;
default: break;
}
}