on xenial help sign in
drop the unneeded and misleading receiver argument, better method name.
commit69344b9abb3ead6d5e7d3fb63cd8f264e5869c7f authorMichael Zanetti <michael.zanetti@canonical.com> dateWed 13 Jan 2016, 19:43 (11 years ago) parentb20a894
3 files changed+8−9
plugins/Utils/inputeventgenerator.cpp+2−2 plugins/Utils/inputeventgenerator.h+4−5 qml/Components/PhysicalKeysMapper.qml+2−2
plugins/Utils/inputeventgenerator.cpp+2−2
@@ -25,10 +25,10 @@ InputEventGenerator::InputEventGenerator(QQuickItem *parent)
2525{
2626}
2727
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)
2929{
3030 QEvent::Type type = pressed ? QEvent::KeyPress : QEvent::KeyRelease;
3131 QKeyEvent ev(type, key, modifier, nativeScanCode, 0, 0, text);
3232 ev.setTimestamp(timestamp);
33− QCoreApplication::sendEvent(receiver->window(), &ev);
33+ QCoreApplication::sendEvent(window(), &ev);
3434}
plugins/Utils/inputeventgenerator.h+4−5
@@ -22,7 +22,7 @@
2222#include <QDateTime>
2323
2424/**
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.
2626 */
2727class InputEventGenerator : public QQuickItem
2828{
@@ -31,11 +31,10 @@ public:
3131 InputEventGenerator(QQuickItem *parent = 0);
3232
3333 /**
34− * Generate and post and event to the scene. Note that the event will not be dispatched directly to the "receiver" but
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.
34+ * Generate and post and event to the scene. The key event will be sent to the scene the Generator
35+ * lives in and it will be dispatched through the regular event/focus queue.
3736 */
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());
3938};
4039
4140#endif // INPUTEVENTGENERATOR_H
qml/Components/PhysicalKeysMapper.qml+2−2
@@ -75,7 +75,7 @@ Item {
7575 if (d.altPressed && !d.altTabPressed && event.key !== Qt.Key_Tab && event.key !== Qt.Key_Alt && !d.altPressInjected) {
7676 // ALT is pressed and another key that is not Tab has been received. Re-inject the alt pressed event
7777 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);
7979 }
8080
8181 if (event.key == Qt.Key_PowerDown || event.key == Qt.Key_PowerOff) {
@@ -146,7 +146,7 @@ Item {
146146 } else if (d.altPressed && !d.altPressInjected) {
147147 // Alt was released but nothing else. Let's inject a pressed event and also forward the release.
148148 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);
150150 d.altPressInjected = false;
151151 }
152152 d.altPressed = false;