summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2018-10-08 10:56:25 +0200
committerLiang Qi <liang.qi@qt.io>2018-10-08 10:56:25 +0200
commit7344987c20d13710af89300f9b39e06397ec592a (patch)
tree4c12e46adefd3aee9d2ce479923fe56bab483764 /src/plugins/platforms
parent8ad5967793f43bda2c38e3f9dddd3d2b6fef5390 (diff)
parent29208fa07c1b9f656ea2535696828385b7832226 (diff)
Merge remote-tracking branch 'origin/5.12' into dev
Conflicts: src/widgets/styles/qstylesheetstyle.cpp Change-Id: I3a503b44ae413fbc0a90f4af70b8f84daffd86ad
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r--src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm10
-rw-r--r--src/plugins/platforms/cocoa/qcocoaglcontext.h3
-rw-r--r--src/plugins/platforms/cocoa/qcocoaglcontext.mm37
-rw-r--r--src/plugins/platforms/cocoa/qcocoakeymapper.h13
-rw-r--r--src/plugins/platforms/cocoa/qcocoakeymapper.mm19
-rw-r--r--src/plugins/platforms/eglfs/deviceintegration/eglfs_brcm/eglfs_brcm.pro1
-rw-r--r--src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/eglfs_kms.pro1
-rw-r--r--src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/eglfs_kms_egldevice.pro1
-rw-r--r--src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/eglfs_kms_support.pro1
-rw-r--r--src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_vsp2/eglfs_kms_vsp2.pro1
-rw-r--r--src/plugins/platforms/eglfs/deviceintegration/eglfs_mali/eglfs_mali.pro1
-rw-r--r--src/plugins/platforms/eglfs/deviceintegration/eglfs_rcar/eglfs_rcar.pro1
-rw-r--r--src/plugins/platforms/eglfs/deviceintegration/eglfs_viv/eglfs_viv.pro1
-rw-r--r--src/plugins/platforms/eglfs/deviceintegration/eglfs_viv_wl/eglfs_viv_wl.pro1
-rw-r--r--src/plugins/platforms/eglfs/deviceintegration/eglfs_x11/eglfs_x11.pro1
-rw-r--r--src/plugins/platforms/eglfs/eglfsdeviceintegration.pro2
-rw-r--r--src/plugins/platforms/wasm/qwasmeventtranslator.cpp29
-rw-r--r--src/plugins/platforms/windows/qwindowspointerhandler.cpp58
18 files changed, 131 insertions, 50 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm
index 33b102f3eb..8c0af97a68 100644
--- a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm
+++ b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm
@@ -108,8 +108,6 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSFontPanelDelegate);
[mFontPanel setRestorable:NO];
[mFontPanel setDelegate:self];
- [NSFontManager sharedFontManager].target = self; // Action is changeFont:
-
[mFontPanel retain];
}
return self;
@@ -119,7 +117,6 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSFontPanelDelegate);
{
[mStolenContentView release];
[mFontPanel setDelegate:nil];
- [NSFontManager sharedFontManager].target = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
@@ -224,6 +221,13 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSFontPanelDelegate);
return (mResultCode == NSModalResponseOK);
}
+// Future proofing in case _NSTargetForSendAction checks this
+// property before sending us the changeFont: message.
+- (BOOL)worksWhenModal
+{
+ return YES;
+}
+
- (QPlatformDialogHelper::DialogCode)dialogResultCode
{
return (mResultCode == NSModalResponseOK) ? QPlatformDialogHelper::Accepted : QPlatformDialogHelper::Rejected;
diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.h b/src/plugins/platforms/cocoa/qcocoaglcontext.h
index cef5892989..eefb1cd0fb 100644
--- a/src/plugins/platforms/cocoa/qcocoaglcontext.h
+++ b/src/plugins/platforms/cocoa/qcocoaglcontext.h
@@ -41,6 +41,7 @@
#define QCOCOAGLCONTEXT_H
#include <QtCore/QPointer>
+#include <QtCore/private/qcore_mac_p.h>
#include <qpa/qplatformopenglcontext.h>
#include <QtGui/QOpenGLContext>
#include <QtGui/QWindow>
@@ -79,6 +80,8 @@ private:
NSOpenGLContext *m_shareContext = nil;
QSurfaceFormat m_format;
bool m_didCheckForSoftwareContext = false;
+ QVarLengthArray<QMacScopedObserver, 3> m_updateObservers;
+ QAtomicInt m_needsUpdate = false;
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm
index 069429796e..1e1b3907ed 100644
--- a/src/plugins/platforms/cocoa/qcocoaglcontext.mm
+++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm
@@ -41,7 +41,6 @@
#include "qcocoawindow.h"
#include "qcocoahelpers.h"
#include <qdebug.h>
-#include <QtCore/private/qcore_mac_p.h>
#include <QtPlatformHeaders/qcocoanativecontext.h>
#include <dlfcn.h>
@@ -351,7 +350,8 @@ bool QCocoaGLContext::makeCurrent(QPlatformSurface *surface)
}
}
- update();
+ if (m_needsUpdate.fetchAndStoreRelaxed(false))
+ update();
}
return true;
@@ -383,13 +383,44 @@ bool QCocoaGLContext::setDrawable(QPlatformSurface *surface)
if (view == m_context.view)
return true;
+ // Setting the drawable may happen on a separate thread as a result of
+ // a call to makeCurrent, so we need to set up the observers before we
+ // associate the view with the context. That way we will guarantee that
+ // as long as the view is the drawable of the context we will know about
+ // any updates to the view that require surface invalidation.
+
+ auto updateCallback = [this, view]() {
+ Q_ASSERT(QThread::currentThread() == qApp->thread());
+ if (m_context.view != view)
+ return;
+ m_needsUpdate = true;
+ };
+
+ m_updateObservers.clear();
+
+ if (view.layer) {
+ m_updateObservers.append(QMacScopedObserver(view, NSViewFrameDidChangeNotification, updateCallback));
+ m_updateObservers.append(QMacScopedObserver(view.window, NSWindowDidChangeScreenNotification, updateCallback));
+ } else {
+ m_updateObservers.append(QMacScopedObserver(view, NSViewGlobalFrameDidChangeNotification, updateCallback));
+ }
+
+ m_updateObservers.append(QMacScopedObserver([NSApplication sharedApplication],
+ NSApplicationDidChangeScreenParametersNotification, updateCallback));
+
+ // If any of the observers fire at this point it's fine. We check the
+ // view association (atomically) in the update callback, and skip the
+ // update if we haven't associated yet. Setting the drawable below will
+ // have the same effect as an update.
+
+ // Now we are ready to associate the view with the context
if ((m_context.view = view) != view) {
qCInfo(lcQpaOpenGLContext) << "Failed to set" << view << "as drawable for" << m_context;
+ m_updateObservers.clear();
return false;
}
qCInfo(lcQpaOpenGLContext) << "Set drawable for" << m_context << "to" << m_context.view;
-
return true;
}
diff --git a/src/plugins/platforms/cocoa/qcocoakeymapper.h b/src/plugins/platforms/cocoa/qcocoakeymapper.h
index a75e275077..2624f19978 100644
--- a/src/plugins/platforms/cocoa/qcocoakeymapper.h
+++ b/src/plugins/platforms/cocoa/qcocoakeymapper.h
@@ -89,15 +89,12 @@ public:
void clearMappings();
private:
- QCFType<TISInputSourceRef> currentInputSource;
+ QCFType<TISInputSourceRef> currentInputSource = nullptr;
- enum { NullMode, UnicodeMode, OtherMode } keyboard_mode;
- union {
- const UCKeyboardLayout *unicode;
- void *other;
- } keyboard_layout_format;
- KeyboardLayoutKind keyboard_kind;
- UInt32 keyboard_dead;
+ enum { NullMode, UnicodeMode, OtherMode } keyboard_mode = NullMode;
+ const UCKeyboardLayout *keyboard_layout_format = nullptr;
+ KeyboardLayoutKind keyboard_kind = kKLKCHRuchrKind;
+ UInt32 keyboard_dead = 0;
KeyboardLayoutItem *keyLayout[256];
};
diff --git a/src/plugins/platforms/cocoa/qcocoakeymapper.mm b/src/plugins/platforms/cocoa/qcocoakeymapper.mm
index 5e279a400b..350ae4b9be 100644
--- a/src/plugins/platforms/cocoa/qcocoakeymapper.mm
+++ b/src/plugins/platforms/cocoa/qcocoakeymapper.mm
@@ -341,8 +341,6 @@ static int qt_mac_get_key(int modif, const QChar &key, int virtualKey)
QCocoaKeyMapper::QCocoaKeyMapper()
{
memset(keyLayout, 0, sizeof(keyLayout));
- keyboard_layout_format.unicode = 0;
- currentInputSource = 0;
}
QCocoaKeyMapper::~QCocoaKeyMapper()
@@ -371,12 +369,19 @@ bool QCocoaKeyMapper::updateKeyboard()
keyboard_kind = LMGetKbdType();
if (uchrData) {
- keyboard_layout_format.unicode = uchrData;
+ keyboard_layout_format = uchrData;
keyboard_mode = UnicodeMode;
+ } else {
+ keyboard_layout_format = nullptr;
+ keyboard_mode = NullMode;
}
currentInputSource = source;
keyboard_dead = 0;
+ const auto newMode = keyboard_mode;
+ deleteLayouts();
+ keyboard_mode = newMode;
+
return true;
}
@@ -399,10 +404,8 @@ void QCocoaKeyMapper::clearMappings()
void QCocoaKeyMapper::updateKeyMap(unsigned short macVirtualKey, QChar unicodeKey)
{
- if (updateKeyboard()) {
- // ### Qt 4 did this:
- // QKeyMapper::changeKeyboard();
- }
+ updateKeyboard();
+
if (keyLayout[macVirtualKey])
return;
@@ -414,7 +417,7 @@ void QCocoaKeyMapper::updateKeyMap(unsigned short macVirtualKey, QChar unicodeKe
keyLayout[macVirtualKey]->qtKey[i] = 0;
const UInt32 keyModifier = ((qt_mac_get_mac_modifiers(ModsTbl[i]) >> 8) & 0xFF);
- OSStatus err = UCKeyTranslate(keyboard_layout_format.unicode, macVirtualKey, kUCKeyActionDown, keyModifier,
+ OSStatus err = UCKeyTranslate(keyboard_layout_format, macVirtualKey, kUCKeyActionDown, keyModifier,
keyboard_kind, 0, &keyboard_dead, buffer_size, &out_buffer_size, buffer);
if (err == noErr && out_buffer_size) {
const QChar unicode(buffer[0]);
diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_brcm/eglfs_brcm.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_brcm/eglfs_brcm.pro
index fee67da2de..aa487be8c0 100644
--- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_brcm/eglfs_brcm.pro
+++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_brcm/eglfs_brcm.pro
@@ -6,7 +6,6 @@ INCLUDEPATH += $$PWD/../../api
CONFIG += egl
LIBS += -lbcm_host
-QMAKE_LFLAGS += $$QMAKE_LFLAGS_NOUNDEF
# Avoid X11 header collision, use generic EGL native types
DEFINES += QT_EGL_NO_X11
diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/eglfs_kms.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/eglfs_kms.pro
index 43170a3875..f5c2c0ed89 100644
--- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/eglfs_kms.pro
+++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/eglfs_kms.pro
@@ -13,7 +13,6 @@ DEFINES += QT_EGL_NO_X11
QMAKE_USE += gbm drm
CONFIG += egl
-QMAKE_LFLAGS += $$QMAKE_LFLAGS_NOUNDEF
SOURCES += $$PWD/qeglfskmsgbmmain.cpp \
$$PWD/qeglfskmsgbmintegration.cpp \
diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/eglfs_kms_egldevice.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/eglfs_kms_egldevice.pro
index 36f037ac6c..a6145c07e6 100644
--- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/eglfs_kms_egldevice.pro
+++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/eglfs_kms_egldevice.pro
@@ -9,7 +9,6 @@ DEFINES += QT_EGL_NO_X11
QMAKE_USE += drm
CONFIG += egl
-QMAKE_LFLAGS += $$QMAKE_LFLAGS_NOUNDEF
SOURCES += $$PWD/qeglfskmsegldevicemain.cpp \
$$PWD/qeglfskmsegldeviceintegration.cpp \
diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/eglfs_kms_support.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/eglfs_kms_support.pro
index 4d1321079c..40806b6a9b 100644
--- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/eglfs_kms_support.pro
+++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_support/eglfs_kms_support.pro
@@ -11,7 +11,6 @@ DEFINES += QT_EGL_NO_X11
QMAKE_USE += drm
CONFIG += egl
-QMAKE_LFLAGS += $$QMAKE_LFLAGS_NOUNDEF
SOURCES += $$PWD/qeglfskmsintegration.cpp \
$$PWD/qeglfskmsdevice.cpp \
diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_vsp2/eglfs_kms_vsp2.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_vsp2/eglfs_kms_vsp2.pro
index 826c2f989f..f63b768a38 100644
--- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_vsp2/eglfs_kms_vsp2.pro
+++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_vsp2/eglfs_kms_vsp2.pro
@@ -13,7 +13,6 @@ DEFINES += QT_EGL_NO_X11
QMAKE_USE += gbm drm v4l2
CONFIG += egl
-QMAKE_LFLAGS += $$QMAKE_LFLAGS_NOUNDEF
SOURCES += $$PWD/qeglfskmsvsp2main.cpp \
$$PWD/qeglfskmsvsp2integration.cpp \
diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_mali/eglfs_mali.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_mali/eglfs_mali.pro
index 5e6f636e2b..3261a6dbba 100644
--- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_mali/eglfs_mali.pro
+++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_mali/eglfs_mali.pro
@@ -7,7 +7,6 @@ DEFINES += QT_EGL_NO_X11
INCLUDEPATH += $$PWD/../../api
CONFIG += egl
-QMAKE_LFLAGS += $$QMAKE_LFLAGS_NOUNDEF
SOURCES += $$PWD/qeglfsmalimain.cpp \
$$PWD/qeglfsmaliintegration.cpp
diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_rcar/eglfs_rcar.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_rcar/eglfs_rcar.pro
index 04236449a0..62acd51cea 100644
--- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_rcar/eglfs_rcar.pro
+++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_rcar/eglfs_rcar.pro
@@ -5,7 +5,6 @@ QT += core-private gui-private eglfsdeviceintegration-private
INCLUDEPATH += $$PWD/../../api
CONFIG += egl
DEFINES += LINUX=1 EGL_API_FB=1
-QMAKE_LFLAGS += $$QMAKE_LFLAGS_NOUNDEF
SOURCES += $$PWD/qeglfsrcarmain.cpp \
$$PWD/qeglfsrcarintegration.cpp
diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv/eglfs_viv.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv/eglfs_viv.pro
index f9cce8d48b..8d3be9c2ac 100644
--- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv/eglfs_viv.pro
+++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv/eglfs_viv.pro
@@ -5,7 +5,6 @@ QT += core-private gui-private eglfsdeviceintegration-private
INCLUDEPATH += $$PWD/../../api
CONFIG += egl
DEFINES += LINUX=1 EGL_API_FB=1
-QMAKE_LFLAGS += $$QMAKE_LFLAGS_NOUNDEF
SOURCES += $$PWD/qeglfsvivmain.cpp \
$$PWD/qeglfsvivintegration.cpp
diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv_wl/eglfs_viv_wl.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv_wl/eglfs_viv_wl.pro
index 065a103376..45d73e1eb8 100644
--- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv_wl/eglfs_viv_wl.pro
+++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv_wl/eglfs_viv_wl.pro
@@ -5,7 +5,6 @@ QT += core-private gui-private eglfsdeviceintegration-private
INCLUDEPATH += $$PWD/../../api
CONFIG += egl
DEFINES += LINUX=1 EGL_API_FB=1
-QMAKE_LFLAGS += $$QMAKE_LFLAGS_NOUNDEF
SOURCES += $$PWD/qeglfsvivwlmain.cpp \
$$PWD/qeglfsvivwlintegration.cpp
diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_x11/eglfs_x11.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_x11/eglfs_x11.pro
index 391f63615b..acbd1cc785 100644
--- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_x11/eglfs_x11.pro
+++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_x11/eglfs_x11.pro
@@ -9,7 +9,6 @@ INCLUDEPATH += $$PWD/../../api
CONFIG += egl
QMAKE_USE += xcb_xlib
-QMAKE_LFLAGS += $$QMAKE_LFLAGS_NOUNDEF
SOURCES += $$PWD/qeglfsx11main.cpp \
$$PWD/qeglfsx11integration.cpp
diff --git a/src/plugins/platforms/eglfs/eglfsdeviceintegration.pro b/src/plugins/platforms/eglfs/eglfsdeviceintegration.pro
index 187cbc025f..8bb7b614f1 100644
--- a/src/plugins/platforms/eglfs/eglfsdeviceintegration.pro
+++ b/src/plugins/platforms/eglfs/eglfsdeviceintegration.pro
@@ -27,8 +27,6 @@ DEFINES += QT_BUILD_EGL_DEVICE_LIB
include($$PWD/api/api.pri)
-QMAKE_LFLAGS += $$QMAKE_LFLAGS_NOUNDEF
-
!isEmpty(EGLFS_PLATFORM_HOOKS_SOURCES) {
HEADERS += $$EGLFS_PLATFORM_HOOKS_HEADERS
SOURCES += $$EGLFS_PLATFORM_HOOKS_SOURCES
diff --git a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp
index 95bedf701c..cc48c15b64 100644
--- a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp
+++ b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp
@@ -39,15 +39,27 @@
#include <QtCore/qobject.h>
#include <QtCore/qdeadlinetimer.h>
+#include <emscripten/bind.h>
#include <iostream>
QT_BEGIN_NAMESPACE
+using namespace emscripten;
// macOS CTRL <-> META switching. We most likely want to enable
// the existing switching code in QtGui, but for now do it here.
static bool g_usePlatformMacCtrlMetaSwitching = false;
+bool g_useNaturalScrolling = false;
+
+void setNaturalScrolling(bool use) {
+ g_useNaturalScrolling = use;
+}
+
+EMSCRIPTEN_BINDINGS(mouse_module) {
+ function("setNaturalScrolling", &setNaturalScrolling);
+}
+
QWasmEventTranslator::QWasmEventTranslator(QObject *parent)
: QObject(parent)
, draggedWindow(nullptr)
@@ -84,6 +96,20 @@ QWasmEventTranslator::QWasmEventTranslator(QObject *parent)
Platform(EM_ASM_INT("if (navigator.platform.includes(\"Mac\")) return 1; return 0;"));
g_usePlatformMacCtrlMetaSwitching = (platform == MacOSPlatform);
+
+ if (platform == MacOSPlatform) {
+ g_useNaturalScrolling = true; //make this default on macOS
+ EM_ASM(
+ if (window.safari !== undefined) {//this only works on safari
+ Module["canvas"].addEventListener('wheel', mouseWheelEvent);
+ function mouseWheelEvent(e) {
+ if (event.webkitDirectionInvertedFromDevice) {
+ Module.setNaturalScrolling(event.webkitDirectionInvertedFromDevice);
+ }
+ }
+ }
+ );
+ }
}
template <typename Event>
@@ -449,6 +475,9 @@ int QWasmEventTranslator::wheel_cb(int eventType, const EmscriptenWheelEvent *wh
break;
};
+ if (g_useNaturalScrolling) //macOS platform has document oriented scrolling
+ scrollFactor = -scrollFactor;
+
Qt::KeyboardModifiers modifiers = translateMouseEventModifier(&mouseEvent);
auto timestamp = mouseEvent.timestamp;
QPoint globalPoint(mouseEvent.canvasX, mouseEvent.canvasY);
diff --git a/src/plugins/platforms/windows/qwindowspointerhandler.cpp b/src/plugins/platforms/windows/qwindowspointerhandler.cpp
index 7ead14822a..c5acc38e7c 100644
--- a/src/plugins/platforms/windows/qwindowspointerhandler.cpp
+++ b/src/plugins/platforms/windows/qwindowspointerhandler.cpp
@@ -61,6 +61,8 @@
#include <QtCore/qloggingcategory.h>
#include <QtCore/qoperatingsystemversion.h>
+#include <algorithm>
+
#include <windowsx.h>
QT_BEGIN_NAMESPACE
@@ -184,41 +186,65 @@ static void getMouseEventInfo(UINT message, POINTER_BUTTON_CHANGE_TYPE changeTyp
{POINTER_CHANGE_FIFTHBUTTON_UP, Qt::XButton2},
};
- static const QHash<UINT, QEvent::Type> eventMapping {
- {WM_POINTERUPDATE, QEvent::MouseMove},
- {WM_POINTERDOWN, QEvent::MouseButtonPress},
- {WM_POINTERUP, QEvent::MouseButtonRelease},
- {WM_NCPOINTERUPDATE, QEvent::NonClientAreaMouseMove},
- {WM_NCPOINTERDOWN, QEvent::NonClientAreaMouseButtonPress},
- {WM_NCPOINTERUP, QEvent::NonClientAreaMouseButtonRelease},
- {WM_POINTERWHEEL, QEvent::Wheel},
- {WM_POINTERHWHEEL, QEvent::Wheel},
+ static const POINTER_BUTTON_CHANGE_TYPE downChanges[] = {
+ POINTER_CHANGE_FIRSTBUTTON_DOWN,
+ POINTER_CHANGE_SECONDBUTTON_DOWN,
+ POINTER_CHANGE_THIRDBUTTON_DOWN,
+ POINTER_CHANGE_FOURTHBUTTON_DOWN,
+ POINTER_CHANGE_FIFTHBUTTON_DOWN,
+ };
+
+ static const POINTER_BUTTON_CHANGE_TYPE upChanges[] = {
+ POINTER_CHANGE_FIRSTBUTTON_UP,
+ POINTER_CHANGE_SECONDBUTTON_UP,
+ POINTER_CHANGE_THIRDBUTTON_UP,
+ POINTER_CHANGE_FOURTHBUTTON_UP,
+ POINTER_CHANGE_FIFTHBUTTON_UP,
};
if (!eventType || !mouseButton)
return;
- if (message == WM_POINTERDOWN || message == WM_POINTERUP || message == WM_NCPOINTERDOWN || message == WM_NCPOINTERUP)
- *mouseButton = buttonMapping.value(changeType, Qt::NoButton);
- else
- *mouseButton = Qt::NoButton;
+ const bool nonClient = message == WM_NCPOINTERUPDATE ||
+ message == WM_NCPOINTERDOWN ||
+ message == WM_NCPOINTERUP;
+
+ if (std::find(std::begin(downChanges),
+ std::end(downChanges), changeType) < std::end(downChanges)) {
+ *eventType = nonClient ? QEvent::NonClientAreaMouseButtonPress :
+ QEvent::MouseButtonPress;
+ } else if (std::find(std::begin(upChanges),
+ std::end(upChanges), changeType) < std::end(upChanges)) {
+ *eventType = nonClient ? QEvent::NonClientAreaMouseButtonRelease :
+ QEvent::MouseButtonRelease;
+ } else if (message == WM_POINTERWHEEL || message == WM_POINTERHWHEEL) {
+ *eventType = QEvent::Wheel;
+ } else {
+ *eventType = nonClient ? QEvent::NonClientAreaMouseMove :
+ QEvent::MouseMove;
+ }
- *eventType = eventMapping.value(message, QEvent::None);
+ *mouseButton = buttonMapping.value(changeType, Qt::NoButton);
// Pointer messages lack a double click indicator. Check if this is the case here.
- if (message == WM_POINTERDOWN) {
+ if (*eventType == QEvent::MouseButtonPress ||
+ *eventType == QEvent::NonClientAreaMouseButtonPress) {
static LONG lastTime = 0;
static Qt::MouseButton lastButton = Qt::NoButton;
+ static QEvent::Type lastEvent = QEvent::None;
static QPoint lastPos;
LONG messageTime = GetMessageTime();
if (*mouseButton == lastButton
+ && *eventType == lastEvent
&& messageTime - lastTime < (LONG)GetDoubleClickTime()
&& qAbs(globalPos.x() - lastPos.x()) < GetSystemMetrics(SM_CXDOUBLECLK)
&& qAbs(globalPos.y() - lastPos.y()) < GetSystemMetrics(SM_CYDOUBLECLK)) {
- *eventType = QEvent::MouseButtonDblClick;
+ *eventType = nonClient ? QEvent::NonClientAreaMouseButtonDblClick :
+ QEvent::MouseButtonDblClick;
}
lastTime = messageTime;
lastButton = *mouseButton;
+ lastEvent = *eventType;
lastPos = globalPos;
}
}