Implement QWindowsKeyMapper in terms of QPlatformKeyMapper
Change-Id: I060ca9613d49bb85a2cf8d4f808b2b5b1c0bdcd5 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>bb10
parent
d5c867ee29
commit
64e1744a57
|
|
@ -481,9 +481,9 @@ bool QWindowsContext::useRTLExtensions() const
|
|||
return d->m_keyMapper.useRTLExtensions();
|
||||
}
|
||||
|
||||
QList<int> QWindowsContext::possibleKeys(const QKeyEvent *e) const
|
||||
QPlatformKeyMapper *QWindowsContext::keyMapper() const
|
||||
{
|
||||
return d->m_keyMapper.possibleKeys(e);
|
||||
return &d->m_keyMapper;
|
||||
}
|
||||
|
||||
QWindowsContext::HandleBaseWindowHash &QWindowsContext::windows()
|
||||
|
|
@ -1441,7 +1441,7 @@ bool QWindowsContext::handleContextMenuEvent(QWindow *window, const MSG &msg)
|
|||
}
|
||||
|
||||
QWindowSystemInterface::handleContextMenuEvent(window, mouseTriggered, pos, globalPos,
|
||||
QWindowsKeyMapper::queryKeyboardModifiers());
|
||||
keyMapper()->queryKeyboardModifiers());
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1462,7 +1462,7 @@ void QWindowsContext::handleExitSizeMove(QWindow *window)
|
|||
const Qt::MouseButtons appButtons = QGuiApplication::mouseButtons();
|
||||
if (currentButtons == appButtons)
|
||||
return;
|
||||
const Qt::KeyboardModifiers keyboardModifiers = QWindowsKeyMapper::queryKeyboardModifiers();
|
||||
const Qt::KeyboardModifiers keyboardModifiers = keyMapper()->queryKeyboardModifiers();
|
||||
const QPoint globalPos = QWindowsCursor::mousePosition();
|
||||
const QPlatformWindow *platWin = window->handle();
|
||||
const QPoint localPos = platWin->mapFromGlobal(globalPos);
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ Q_DECLARE_LOGGING_CATEGORY(lcQpaScreen)
|
|||
class QWindow;
|
||||
class QPlatformScreen;
|
||||
class QPlatformWindow;
|
||||
class QPlatformKeyMapper;
|
||||
class QWindowsMenuBar;
|
||||
class QWindowsScreenManager;
|
||||
class QWindowsTabletSupport;
|
||||
|
|
@ -43,7 +44,6 @@ struct QWindowsContextPrivate;
|
|||
class QPoint;
|
||||
class QKeyEvent;
|
||||
class QPointingDevice;
|
||||
|
||||
class QWindowsContext
|
||||
{
|
||||
Q_DISABLE_COPY_MOVE(QWindowsContext)
|
||||
|
|
@ -128,7 +128,7 @@ public:
|
|||
unsigned systemInfo() const;
|
||||
|
||||
bool useRTLExtensions() const;
|
||||
QList<int> possibleKeys(const QKeyEvent *e) const;
|
||||
QPlatformKeyMapper *keyMapper() const;
|
||||
|
||||
HandleBaseWindowHash &windows();
|
||||
|
||||
|
|
|
|||
|
|
@ -526,7 +526,8 @@ QWindowsOleDropTarget::DragLeave()
|
|||
|
||||
qCDebug(lcQpaMime) << __FUNCTION__ << ' ' << m_window;
|
||||
|
||||
lastModifiers = QWindowsKeyMapper::queryKeyboardModifiers();
|
||||
const auto *keyMapper = QWindowsContext::instance()->keyMapper();
|
||||
lastModifiers = keyMapper->queryKeyboardModifiers();
|
||||
lastButtons = QWindowsMouseHandler::queryMouseButtons();
|
||||
|
||||
QWindowSystemInterface::handleDrag(m_window, nullptr, QPoint(), Qt::IgnoreAction,
|
||||
|
|
|
|||
|
|
@ -565,14 +565,9 @@ QVariant QWindowsIntegration::styleHint(QPlatformIntegration::StyleHint hint) co
|
|||
return QPlatformIntegration::styleHint(hint);
|
||||
}
|
||||
|
||||
Qt::KeyboardModifiers QWindowsIntegration::queryKeyboardModifiers() const
|
||||
QPlatformKeyMapper *QWindowsIntegration::keyMapper() const
|
||||
{
|
||||
return QWindowsKeyMapper::queryKeyboardModifiers();
|
||||
}
|
||||
|
||||
QList<int> QWindowsIntegration::possibleKeys(const QKeyEvent *e) const
|
||||
{
|
||||
return d->m_context.possibleKeys(e);
|
||||
return d->m_context.keyMapper();
|
||||
}
|
||||
|
||||
#if QT_CONFIG(clipboard)
|
||||
|
|
|
|||
|
|
@ -82,8 +82,7 @@ public:
|
|||
QPlatformServices *services() const override;
|
||||
QVariant styleHint(StyleHint hint) const override;
|
||||
|
||||
Qt::KeyboardModifiers queryKeyboardModifiers() const override;
|
||||
QList<int> possibleKeys(const QKeyEvent *e) const override;
|
||||
QPlatformKeyMapper *keyMapper() const override;
|
||||
|
||||
static QWindowsIntegration *instance() { return m_instance; }
|
||||
|
||||
|
|
|
|||
|
|
@ -540,33 +540,6 @@ QDebug operator<<(QDebug d, const KeyboardLayoutItem &k)
|
|||
d << ')';
|
||||
return d;
|
||||
}
|
||||
|
||||
// Helpers to format a list of int as Qt key sequence
|
||||
class formatKeys
|
||||
{
|
||||
public:
|
||||
explicit formatKeys(const QList<int> &keys) : m_keys(keys) {}
|
||||
|
||||
private:
|
||||
friend QDebug operator<<(QDebug d, const formatKeys &keys);
|
||||
const QList<int> &m_keys;
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug d, const formatKeys &k)
|
||||
{
|
||||
QDebugStateSaver saver(d);
|
||||
d.nospace();
|
||||
d << '(';
|
||||
for (int i =0, size = k.m_keys.size(); i < size; ++i) {
|
||||
if (i)
|
||||
d << ", ";
|
||||
d << QKeySequence(k.m_keys.at(i));
|
||||
}
|
||||
d << ')';
|
||||
return d;
|
||||
}
|
||||
#else // !QT_NO_DEBUG_STREAM
|
||||
static int formatKeys(const QList<int> &) { return 0; }
|
||||
#endif // QT_NO_DEBUG_STREAM
|
||||
|
||||
/**
|
||||
|
|
@ -1347,7 +1320,7 @@ bool QWindowsKeyMapper::translateKeyEventInternal(QWindow *window, MSG msg,
|
|||
return result;
|
||||
}
|
||||
|
||||
Qt::KeyboardModifiers QWindowsKeyMapper::queryKeyboardModifiers()
|
||||
Qt::KeyboardModifiers QWindowsKeyMapper::queryKeyboardModifiers() const
|
||||
{
|
||||
Qt::KeyboardModifiers modifiers = Qt::NoModifier;
|
||||
if (GetKeyState(VK_SHIFT) < 0)
|
||||
|
|
@ -1361,9 +1334,9 @@ Qt::KeyboardModifiers QWindowsKeyMapper::queryKeyboardModifiers()
|
|||
return modifiers;
|
||||
}
|
||||
|
||||
QList<int> QWindowsKeyMapper::possibleKeys(const QKeyEvent *e) const
|
||||
QList<QKeyCombination> QWindowsKeyMapper::possibleKeyCombinations(const QKeyEvent *e) const
|
||||
{
|
||||
QList<int> result;
|
||||
QList<QKeyCombination> result;
|
||||
|
||||
|
||||
const quint32 nativeVirtualKey = e->nativeVirtualKey();
|
||||
|
|
@ -1377,31 +1350,34 @@ QList<int> QWindowsKeyMapper::possibleKeys(const QKeyEvent *e) const
|
|||
quint32 baseKey = kbItem.qtKey[0];
|
||||
Qt::KeyboardModifiers keyMods = e->modifiers();
|
||||
if (baseKey == Qt::Key_Return && (e->nativeModifiers() & ExtendedKey)) {
|
||||
result << (Qt::Key_Enter | keyMods).toCombined();
|
||||
result << (Qt::Key_Enter | keyMods);
|
||||
return result;
|
||||
}
|
||||
result << int(baseKey) + int(keyMods); // The base key is _always_ valid, of course
|
||||
|
||||
// The base key is _always_ valid, of course
|
||||
result << QKeyCombination::fromCombined(int(baseKey) + int(keyMods));
|
||||
|
||||
for (size_t i = 1; i < NumMods; ++i) {
|
||||
Qt::KeyboardModifiers neededMods = ModsTbl[i];
|
||||
quint32 key = kbItem.qtKey[i];
|
||||
if (key && key != baseKey && ((keyMods & neededMods) == neededMods)) {
|
||||
const Qt::KeyboardModifiers missingMods = keyMods & ~neededMods;
|
||||
const int matchedKey = int(key) + int(missingMods);
|
||||
const auto it =
|
||||
std::find_if(result.begin(), result.end(),
|
||||
[key] (int k) { return (k & ~Qt::KeyboardModifierMask) == key; });
|
||||
const auto matchedKey = QKeyCombination::fromCombined(int(key) + int(missingMods));
|
||||
const auto it = std::find_if(result.begin(), result.end(),
|
||||
[key](auto keyCombination) {
|
||||
return keyCombination.key() == key;
|
||||
});
|
||||
// QTBUG-67200: Use the match with the least modifiers (prefer
|
||||
// Shift+9 over Alt + Shift + 9) resulting in more missing modifiers.
|
||||
if (it == result.end())
|
||||
result << matchedKey;
|
||||
else if (missingMods > Qt::KeyboardModifiers(*it & Qt::KeyboardModifierMask))
|
||||
else if (missingMods > it->keyboardModifiers())
|
||||
*it = matchedKey;
|
||||
}
|
||||
}
|
||||
qCDebug(lcQpaEvents) << __FUNCTION__ << e << "nativeVirtualKey="
|
||||
<< Qt::showbase << Qt::hex << e->nativeVirtualKey() << Qt::dec << Qt::noshowbase
|
||||
<< e->modifiers() << kbItem << "\n returns" << formatKeys(result);
|
||||
<< e->modifiers() << kbItem << "\n returns" << result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
|
||||
#include <QtCore/qlocale.h>
|
||||
|
||||
#include <qpa/qplatformkeymapper.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QKeyEvent;
|
||||
|
|
@ -33,7 +35,7 @@ struct KeyboardLayoutItem {
|
|||
quint32 qtKey[NumQtKeys]; // Can by any Qt::Key_<foo>, or unicode character
|
||||
};
|
||||
|
||||
class QWindowsKeyMapper
|
||||
class QWindowsKeyMapper : public QPlatformKeyMapper
|
||||
{
|
||||
Q_DISABLE_COPY_MOVE(QWindowsKeyMapper)
|
||||
public:
|
||||
|
|
@ -53,8 +55,8 @@ public:
|
|||
QWindow *keyGrabber() const { return m_keyGrabber; }
|
||||
void setKeyGrabber(QWindow *w) { m_keyGrabber = w; }
|
||||
|
||||
static Qt::KeyboardModifiers queryKeyboardModifiers();
|
||||
QList<int> possibleKeys(const QKeyEvent *e) const;
|
||||
Qt::KeyboardModifiers queryKeyboardModifiers() const override;
|
||||
QList<QKeyCombination> possibleKeyCombinations(const QKeyEvent *e) const override;
|
||||
|
||||
private:
|
||||
bool translateKeyEventInternal(QWindow *receiver, MSG msg, bool grab, LRESULT *lResult);
|
||||
|
|
|
|||
|
|
@ -268,7 +268,8 @@ bool QWindowsMouseHandler::translateMouseEvent(QWindow *window, HWND hwnd,
|
|||
}
|
||||
}
|
||||
|
||||
const Qt::KeyboardModifiers keyModifiers = QWindowsKeyMapper::queryKeyboardModifiers();
|
||||
const auto *keyMapper = QWindowsContext::instance()->keyMapper();
|
||||
const Qt::KeyboardModifiers keyModifiers = keyMapper->queryKeyboardModifiers();
|
||||
const MouseEvent mouseEvent = eventFromMsg(msg);
|
||||
Qt::MouseButtons buttons;
|
||||
|
||||
|
|
@ -629,10 +630,11 @@ bool QWindowsMouseHandler::translateTouchEvent(QWindow *window, HWND,
|
|||
if (allStates == QEventPoint::State::Released)
|
||||
m_touchInputIDToTouchPointID.clear();
|
||||
|
||||
const auto *keyMapper = QWindowsContext::instance()->keyMapper();
|
||||
QWindowSystemInterface::handleTouchEvent(window,
|
||||
m_touchDevice.data(),
|
||||
touchPoints,
|
||||
QWindowsKeyMapper::queryKeyboardModifiers());
|
||||
keyMapper->queryKeyboardModifiers());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -428,8 +428,9 @@ bool QWindowsPointerHandler::translateTouchEvent(QWindow *window, HWND hwnd,
|
|||
return false;
|
||||
|
||||
if (msg.message == WM_POINTERCAPTURECHANGED) {
|
||||
const auto *keyMapper = QWindowsContext::instance()->keyMapper();
|
||||
QWindowSystemInterface::handleTouchCancelEvent(window, m_touchDevice.data(),
|
||||
QWindowsKeyMapper::queryKeyboardModifiers());
|
||||
keyMapper->queryKeyboardModifiers());
|
||||
m_lastTouchPoints.clear();
|
||||
return true;
|
||||
}
|
||||
|
|
@ -539,8 +540,9 @@ bool QWindowsPointerHandler::translateTouchEvent(QWindow *window, HWND hwnd,
|
|||
if (allStates == QEventPoint::State::Released)
|
||||
m_touchInputIDToTouchPointID.clear();
|
||||
|
||||
const auto *keyMapper = QWindowsContext::instance()->keyMapper();
|
||||
QWindowSystemInterface::handleTouchEvent(window, m_touchDevice.data(), touchPoints,
|
||||
QWindowsKeyMapper::queryKeyboardModifiers());
|
||||
keyMapper->queryKeyboardModifiers());
|
||||
return false; // Allow mouse messages to be generated.
|
||||
}
|
||||
|
||||
|
|
@ -673,7 +675,8 @@ bool QWindowsPointerHandler::translatePenEvent(QWindow *window, HWND hwnd, QtWin
|
|||
wumPlatformWindow->applyCursor();
|
||||
}
|
||||
}
|
||||
const Qt::KeyboardModifiers keyModifiers = QWindowsKeyMapper::queryKeyboardModifiers();
|
||||
const auto *keyMapper = QWindowsContext::instance()->keyMapper();
|
||||
const Qt::KeyboardModifiers keyModifiers = keyMapper->queryKeyboardModifiers();
|
||||
|
||||
QWindowSystemInterface::handleTabletEvent(target, device.data(),
|
||||
localPos, hiResGlobalPos, mouseButtons,
|
||||
|
|
@ -762,7 +765,8 @@ bool QWindowsPointerHandler::translateMouseEvent(QWindow *window,
|
|||
: QWindowsGeometryHint::mapFromGlobal(targetHwnd, globalPos);
|
||||
}
|
||||
|
||||
const Qt::KeyboardModifiers keyModifiers = QWindowsKeyMapper::queryKeyboardModifiers();
|
||||
const auto *keyMapper = QWindowsContext::instance()->keyMapper();
|
||||
const Qt::KeyboardModifiers keyModifiers = keyMapper->queryKeyboardModifiers();
|
||||
QWindow *currentWindowUnderPointer = getWindowUnderPointer(window, globalPos);
|
||||
|
||||
if (et == QtWindows::MouseWheelEvent)
|
||||
|
|
|
|||
|
|
@ -595,7 +595,8 @@ bool QWindowsTabletSupport::translateTabletPacketEvent()
|
|||
<< "mode=" << m_mode;
|
||||
}
|
||||
|
||||
const Qt::KeyboardModifiers keyboardModifiers = QWindowsKeyMapper::queryKeyboardModifiers();
|
||||
const auto *keyMapper = QWindowsContext::instance()->keyMapper();
|
||||
const Qt::KeyboardModifiers keyboardModifiers = keyMapper->queryKeyboardModifiers();
|
||||
|
||||
for (int i = 0; i < packetCount ; ++i) {
|
||||
const PACKET &packet = localPacketBuf[i];
|
||||
|
|
|
|||
Loading…
Reference in New Issue