on xenial help sign in
drop the unneeded and misleading receiver argument, better method name.
69344b9Michael Zanetti
plugins/Utils/inputeventgenerator.cpp+2−2
@@ -25,10 +25,10 @@ InputEventGenerator::InputEventGenerator(QQuickItem *parent)
25{
25{
26}
26}
27
27
28−void InputEventGenerator::generateEvent(QQuickItem *receiver, Qt::Key key, bool pressed, Qt::KeyboardModifiers modifier, quint64 timestamp, quint32 nativeScanCode, const QString &text)
28+void InputEventGenerator::generateKeyEvent(Qt::Key key, bool pressed, Qt::KeyboardModifiers modifier, quint64 timestamp, quint32 nativeScanCode, const QString &text)
29{
29{
30 QEvent::Type type = pressed ? QEvent::KeyPress : QEvent::KeyRelease;
30 QEvent::Type type = pressed ? QEvent::KeyPress : QEvent::KeyRelease;
31 QKeyEvent ev(type, key, modifier, nativeScanCode, 0, 0, text);
31 QKeyEvent ev(type, key, modifier, nativeScanCode, 0, 0, text);
32 ev.setTimestamp(timestamp);
32 ev.setTimestamp(timestamp);
33− QCoreApplication::sendEvent(receiver->window(), &ev);
33+ QCoreApplication::sendEvent(window(), &ev);
34}
34}
plugins/Utils/inputeventgenerator.h+4−5
@@ -22,7 +22,7 @@
22#include <QDateTime>
22#include <QDateTime>
23
23
24/**
24/**
25− * \brief This class allows injecting Key events into the scene.
25+ * \brief This class allows injecting Key events into the scene it lives in.
26 */
26 */
27class InputEventGenerator : public QQuickItem
27class InputEventGenerator : public QQuickItem
28{
28{
@@ -31,11 +31,10 @@ public:
31 InputEventGenerator(QQuickItem *parent = 0);
31 InputEventGenerator(QQuickItem *parent = 0);
32
32
33 /**
33 /**
34− * Generate and post and event to the scene. Note that the event will not be dispatched directly to the "receiver" but
34+ * Generate and post and event to the scene. The key event will be sent to the scene the Generator
35− * instead to the window where the item is located. With that, the whole scene will receive the keypress and it will
36− * be dispatched through the regular event/focus queue.
35+ * lives in and it will be dispatched through the regular event/focus queue.
37 */
36 */
38− Q_INVOKABLE void generateEvent(QQuickItem *receiver, Qt::Key key, bool pressed, Qt::KeyboardModifiers modifiers = Qt::NoModifier, quint64 timestamp = QDateTime::currentMSecsSinceEpoch(), quint32 nativeScanCode = 0, const QString &text = QString());
37+ Q_INVOKABLE void generateKeyEvent(Qt::Key key, bool pressed, Qt::KeyboardModifiers modifiers = Qt::NoModifier, quint64 timestamp = QDateTime::currentMSecsSinceEpoch(), quint32 nativeScanCode = 0, const QString &text = QString());
39};
38};
40
39
41#endif // INPUTEVENTGENERATOR_H
40#endif // INPUTEVENTGENERATOR_H
qml/Components/PhysicalKeysMapper.qml+2−2
@@ -75,7 +75,7 @@ Item {
75 if (d.altPressed && !d.altTabPressed && event.key !== Qt.Key_Tab && event.key !== Qt.Key_Alt && !d.altPressInjected) {
75 if (d.altPressed && !d.altTabPressed && event.key !== Qt.Key_Tab && event.key !== Qt.Key_Alt && !d.altPressInjected) {
76 // ALT is pressed and another key that is not Tab has been received. Re-inject the alt pressed event
76 // ALT is pressed and another key that is not Tab has been received. Re-inject the alt pressed event
77 d.altPressInjected = true;
77 d.altPressInjected = true;
78− inputEventGenerator.generateEvent(root, Qt.Key_Alt, true, Qt.NoModifier, currentEventTimestamp - 1, 56);
78+ inputEventGenerator.generateKeyEvent(Qt.Key_Alt, true, Qt.NoModifier, currentEventTimestamp - 1, 56);
79 }
79 }
80
80
81 if (event.key == Qt.Key_PowerDown || event.key == Qt.Key_PowerOff) {
81 if (event.key == Qt.Key_PowerDown || event.key == Qt.Key_PowerOff) {
@@ -146,7 +146,7 @@ Item {
146 } else if (d.altPressed && !d.altPressInjected) {
146 } else if (d.altPressed && !d.altPressInjected) {
147 // Alt was released but nothing else. Let's inject a pressed event and also forward the release.
147 // Alt was released but nothing else. Let's inject a pressed event and also forward the release.
148 d.altPressInjected = true;
148 d.altPressInjected = true;
149− inputEventGenerator.generateEvent(root, Qt.Key_Alt, true, Qt.AltModifer, currentEventTimestamp, 56);
149+ inputEventGenerator.generateKeyEvent(Qt.Key_Alt, true, Qt.AltModifer, currentEventTimestamp, 56);
150 d.altPressInjected = false;
150 d.altPressInjected = false;
151 }
151 }
152 d.altPressed = false;
152 d.altPressed = false;