Fix mouse extra button mapping on macOS

Previously extra mouse buttons apart from left, right and middle
buttons, were mapped incorrectly with an offset of -1. This resulted in
the first extra button being recognized as the middle button, the
second extra button as the first extra button, etc.

Fix consists in using a binary shift with proper offset to create
the corresponding Qt::MouseButton value.

[ChangeLog][macOS] Fixed extra mouse buttons to be mapped to
correct Qt::MouseButton values.

Change-Id: I9e6084586cd4737a172b7706a805211f0edff749
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Alexandru Croitor 2016-11-22 15:35:24 +01:00
parent fc893d949c
commit 1b1686d194

View File

@ -281,16 +281,8 @@ NSRect qt_mac_flipRect(const QRect &rect)
Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum)
{
if (buttonNum == 0)
return Qt::LeftButton;
if (buttonNum == 1)
return Qt::RightButton;
if (buttonNum == 2)
return Qt::MiddleButton;
if (buttonNum >= 3 && buttonNum <= 31) { // handle XButton1 and higher via logical shift
return Qt::MouseButton(uint(Qt::MiddleButton) << (buttonNum - 3));
}
// else error: buttonNum too high, or negative
if (buttonNum >= 0 && buttonNum <= 31)
return Qt::MouseButton(1 << buttonNum);
return Qt::NoButton;
}