From 1b1686d194731d940a40112635647536ac8ee676 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 22 Nov 2016 15:35:24 +0100 Subject: [PATCH] Fix mouse extra button mapping on macOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ø --- src/plugins/platforms/cocoa/qcocoahelpers.mm | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index 01fbb7bad2..3ab6b641fa 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -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; }