Merge lp:~dandrader/qtmir/keyState into lp:qtmir

Proposed by Daniel d'Andrada on 2017-03-24
Status: Merged
Approved by: Gerry Boland on 2017-03-24
Approved revision: 629
Merged at revision: 630
Proposed branch: lp:~dandrader/qtmir/keyState
Merge into: lp:qtmir
Prerequisite: lp:~gerboland/qtmir/availableDesktopAreaTrial
Diff against target: 211 lines (+115/-6)
3 files modified
src/modules/Unity/Application/mirsurface.cpp (+94/-4)
src/modules/Unity/Application/mirsurface.h (+20/-1)
src/platforms/mirserver/eventbuilder.h (+1/-1)
To merge this branch: bzr merge lp:~dandrader/qtmir/keyState
Reviewer Review Type Date Requested Status
Gerry Boland (community) 2017-03-24 Approve on 2017-03-24
Unity8 CI Bot continuous-integration 2017-03-24 Approve on 2017-03-24
Review via email: mp+320930@code.launchpad.net

This proposal supersedes a proposal from 2017-03-22.

Commit message

Ensure the window that got a key down also gets the corresponding key up

Otherwise it will be left in a inconsistent state (with a pressed key hanging around).

QQuickWindow's input dispatching doesn't guarantee that for its QQuickItem.
So we have to do it ourselves.

This can happen when qml active focus changes in response to a key press.
Eg: client creates a child window in response to a Ctrl+O. By the time the user
releases the Ctrl, active focus will already be in the child window, so the child window
will get the release event instead of the top-level one.

Description of the change

* Are there any related MPs required for this MP to build/function as expected? Please list.
https://code.launchpad.net/~dandrader/unity8/childWindowFocus/+merge/320712

To post a comment you must log in.
Gerry Boland (gerboland) wrote : Posted in a previous version of this proposal

If the surface looses active focus, don't we inform Mir? Why not send the key release event then? Would be more efficient than checking on every key_up

Also, please avoid using singleton pattern, it makes testing impossible. And speaking of which, can you add test?

review: Needs Information
Daniel d'Andrada (dandrader) wrote : Posted in a previous version of this proposal

On 20/03/2017 14:08, Gerry Boland wrote:
> Review: Needs Information
>
> If the surface looses active focus, don't we inform Mir?

It's the other way around. Mir surface focus is what drives qml active
focus. Nowadays qml active focus by itself doesn't carry much meaning in
terms of window management.

> Why not send the key release event then? Would be more efficient than checking on every key_up

Because the key is actually still pressed. If the same window gets focus
again moments later and only then the key is lifted the client would
receive a second key_up event. Unless we keep track of what lies we have
told already to the clients or devise some other special rules.

> Also, please avoid using singleton pattern, it makes testing impossible.

Yeah, that was the easiest (laziest) way to get the two talking (event
feeder and policy). Will see if I can get something nicer. Suggestions?

But before I spend too much time on the implementation details of this
MP I would like to get feedback on the overall approach first.

> And speaking of which, can you add test?

For WindowManagementPolicy?

Gerry Boland (gerboland) wrote : Posted in a previous version of this proposal

> On 20/03/2017 14:08, Gerry Boland wrote:
> > Review: Needs Information
> >
> > If the surface looses active focus, don't we inform Mir?
>
> It's the other way around. Mir surface focus is what drives qml active
> focus. Nowadays qml active focus by itself doesn't carry much meaning in
> terms of window management.

There are more things in the QML scene that just MirSurfaces that can get activeFocus though. When activeFocus does switch to the search box in the AppDrawer (as example), we are indeed telling Mir somehow that the MirSurface has not got input focus (I just tested gedit, the cursor does stop flashing when the text box in the app drawer is focused). Since this bug occurs due to focus changing while modifier key is down, my initial thinking was we could use the focus change to implement a workaround.

What I don't know is if the WMpolicy if notified when the MirSurface it has selected to be focused has lost actual input focus (activeFocus). Do you know?

> > Why not send the key release event then? Would be more efficient than
> checking on every key_up
>
> Because the key is actually still pressed. If the same window gets focus
> again moments later and only then the key is lifted the client would
> receive a second key_up event. Unless we keep track of what lies we have
> told already to the clients or devise some other special rules.

This appears to be a QML subtlety we're working around, as a non-QML Qt shell would not suffer from this issue, right? So could the MirSurfaceItem keep track of the key state itself? If the MSI looses activeFocus, it send key-release to the client. Then if it gets focus again, check if key is still down (not sure how tbh, maybe QML sends the key to the Item again immediately??), and if so, re-send it to client.

I'm not 100% certain what is the best approach yet.

> > Also, please avoid using singleton pattern, it makes testing impossible.
>
> Yeah, that was the easiest (laziest) way to get the two talking (event
> feeder and policy). Will see if I can get something nicer. Suggestions?

Nothing better than the usual piping an object around, so everyone who needs it gets a pointer to it. Sorry :(

> But before I spend too much time on the implementation details of this
> MP I would like to get feedback on the overall approach first.

Ah ok, I hope I've supplied that at least

>
> > And speaking of which, can you add test?
>
> For WindowManagementPolicy?

More the logic you're adding. But please ignore me until you settle on the approach you want.

Daniel d'Andrada (dandrader) wrote : Posted in a previous version of this proposal

On 21/03/2017 09:37, Gerry Boland wrote:
> This appears to be a QML subtlety we're working around, as a non-QML Qt shell would not suffer from this issue, right?

Yes. As I said, QQuickWindow input dispatching not perfectly suited for
shells.

> So could the MirSurfaceItem keep track of the key state itself?
Sure.

> If the MSI looses activeFocus, it send key-release to the client. Then if it gets focus again, check if key is still down (not sure how tbh, maybe QML sends the key to the Item again immediately??), and if so, re-send it to client.

It can't check the key state, but it can ignore a key-up for a key that
it didn't tell its surface it was down (because lied or whatever).

> I'm not 100% certain what is the best approach yet.

Working around QQuickWindow input dispatching will never be beautiful. So, should I go for the MirSurfaceItem-based key filtering/manipulation?

I'm fine either way. I put in the policy to avoid sending fake input to clients and as a general rule-of-thumb of "putting things in the miral policy"/"keep the policy in the loop".

Gerry Boland (gerboland) wrote : Posted in a previous version of this proposal

I think I'd prefer using MirSurfaceItem-based key filtering. Since it's working around the QQuickWindow/QML problem, it makes sense to me to confine the workaround in code only used in code exposed to QQuickWindow/QML.

Gerry Boland (gerboland) wrote : Posted in a previous version of this proposal

+++ src/modules/Unity/Application/mirsurface.h
Could you move the implementation of the PressedKey constructor into the cpp file please, it is big enough a header file.

+++ src/modules/Unity/Application/mirsurface.cpp
You're using QElapsedTimer to get the current value of the monotonic clock, yes? If so, we really only need one QElapsedTimer everywhere, so could make it static singeton and add a static function that calls msecsSinceReference on it and returns the val. wdyt?

Code makes sense, I just need to test. It does need a big comment explaining why we're doing this though. Do the QtWayland guys have the same issue, wonder if they do a similar fix or not...

Daniel d'Andrada (dandrader) wrote : Posted in a previous version of this proposal

> +++ src/modules/Unity/Application/mirsurface.h
> Could you move the implementation of the PressedKey constructor into the cpp
> file please, it is big enough a header file.

Done.

>
> +++ src/modules/Unity/Application/mirsurface.cpp
> You're using QElapsedTimer to get the current value of the monotonic clock,
> yes? If so, we really only need one QElapsedTimer everywhere, so could make it
> static singeton and add a static function that calls msecsSinceReference on it
> and returns the val. wdyt?

Right. Done.

> Code makes sense, I just need to test. It does need a big comment explaining
> why we're doing this though. Do the QtWayland guys have the same issue, wonder
> if they do a similar fix or not...

Added a big fat comment.

Unity8 CI Bot (unity8-ci-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Unity8 CI Bot (unity8-ci-bot) wrote : Posted in a previous version of this proposal

FAILED: Continuous integration, rev:627
https://unity8-jenkins.ubuntu.com/job/lp-qtmir-ci/619/
Executed test runs:
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build/4645/console
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/4673
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/4500/console
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/4500
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/4500/artifact/output/*zip*/output.zip
    FAILURE: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/4500/console
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/4500
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/4500/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/4500
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/4500/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/4500
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/4500/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-qtmir-ci/619/rebuild

review: Needs Fixing (continuous-integration)
Unity8 CI Bot (unity8-ci-bot) wrote : Posted in a previous version of this proposal

PASSED: Continuous integration, rev:627
https://unity8-jenkins.ubuntu.com/job/lp-qtmir-ci/627/
Executed test runs:
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build/4669
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/4697
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/4520
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/4520/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/4520
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/4520/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/4520
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/4520/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/4520
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/4520/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/4520
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/4520/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/4520
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/4520/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-qtmir-ci/627/rebuild

review: Approve (continuous-integration)
Unity8 CI Bot (unity8-ci-bot) wrote :

PASSED: Continuous integration, rev:627
https://unity8-jenkins.ubuntu.com/job/lp-qtmir-ci/629/
Executed test runs:
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build/4679
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/4707
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/4530
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/4530/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/4530
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/4530/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/4530
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/4530/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/4530
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/4530/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/4530
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/4530/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/4530
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/4530/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-qtmir-ci/629/rebuild

review: Approve (continuous-integration)
Gerry Boland (gerboland) wrote :

How about using the anonymous namespace we have? I can stick this in there

static qint64 msecsSinceReference()
{
    static QElapsedTimer elapsedTimer;
    elapsedTimer.start();
    return elapsedTimer.msecsSinceReference();
}

and it works ok. After all it is just a function to return a timestamp, which is a purely internal implementation thing that doesn't need to be a class member IMO.

+ if (m_focused) {
   releaseAllPressedKeys();
Why not on unfocus?

lp:~dandrader/qtmir/keyState updated on 2017-03-24
628. By Daniel d'Andrada on 2017-03-24

Some refactoring as per review feedback

629. By Daniel d'Andrada on 2017-03-24

update copyright header

Daniel d'Andrada (dandrader) wrote :

On 24/03/2017 15:37, Gerry Boland wrote:
> How about using the anonymous namespace we have? I can stick this in there
>
> static qint64 msecsSinceReference()
> {
> static QElapsedTimer elapsedTimer;
> elapsedTimer.start();
> return elapsedTimer.msecsSinceReference();
> }
>
> and it works ok. After all it is just a function to return a timestamp, which is a purely internal implementation thing that doesn't need to be a class member IMO.

Yes, makes for less code. Done.

> + if (m_focused) {
> releaseAllPressedKeys();
> Why not on unfocus?

Because an unfocused surface, by definition, shouldn't be receiving
input events.

Unity8 CI Bot (unity8-ci-bot) wrote :

PASSED: Continuous integration, rev:629
https://unity8-jenkins.ubuntu.com/job/lp-qtmir-ci/633/
Executed test runs:
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build/4694
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-0-fetch/4722
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/4545
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=xenial+overlay/4545/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/4545
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=amd64,release=zesty/4545/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/4545
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=xenial+overlay/4545/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/4545
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=armhf,release=zesty/4545/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/4545
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=xenial+overlay/4545/artifact/output/*zip*/output.zip
    SUCCESS: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/4545
        deb: https://unity8-jenkins.ubuntu.com/job/build-2-binpkg/arch=i386,release=zesty/4545/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://unity8-jenkins.ubuntu.com/job/lp-qtmir-ci/633/rebuild

review: Approve (continuous-integration)
Gerry Boland (gerboland) wrote :

> Because an unfocused surface, by definition, shouldn't be receiving
> input events.
Yeah. Not ideal, but as we have no reliable way to send those events just before a surface is send the unfocus event, this is the best that can be done.

Tested and works ok

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/modules/Unity/Application/mirsurface.cpp'
2--- src/modules/Unity/Application/mirsurface.cpp 2017-03-24 18:56:33 +0000
3+++ src/modules/Unity/Application/mirsurface.cpp 2017-03-24 18:56:33 +0000
4@@ -41,6 +41,7 @@
5 #include <logging.h>
6
7 // Qt
8+#include <QElapsedTimer>
9 #include <QQmlEngine>
10 #include <QScreen>
11
12@@ -68,8 +69,16 @@
13 };
14 Q_DECLARE_FLAGS(DirtyStates, DirtyState)
15
16+qint64 msecsSinceReference()
17+{
18+ static QElapsedTimer elapsedTimer;
19+ elapsedTimer.start();
20+ return elapsedTimer.msecsSinceReference();
21+}
22+
23 } // namespace {
24
25+
26 class MirSurface::SurfaceObserverImpl : public SurfaceObserver, public mir::scene::SurfaceObserver
27 {
28 public:
29@@ -409,6 +418,25 @@
30
31 m_focused = value;
32 Q_EMIT focusedChanged(value);
33+
34+ if (m_focused) {
35+ /*
36+ Ensure the window that got a key down also gets the corresponding key up
37+
38+ Otherwise it will be left in a inconsistent state (with a pressed key hanging around).
39+
40+ QQuickWindow's input dispatching doesn't guarantee that for its QQuickItems.
41+ So we have to do it ourselves.
42+
43+ This can happen when qml active focus changes in response to a key press.
44+ Eg: client creates a child window in response to a Ctrl+O. By the time the user
45+ releases the Ctrl, active focus will already be in the child window, so the child window
46+ will get the release event instead of the top-level one. To solve this, once the top-level
47+ window gets active focus again, we synthesize KeyRelease events for all keys this window
48+ thinks are still pressed.
49+ */
50+ releaseAllPressedKeys();
51+ }
52 }
53
54 void MirSurface::setViewActiveFocus(qintptr viewId, bool value)
55@@ -661,6 +689,18 @@
56
57 void MirSurface::keyPressEvent(QKeyEvent *qtEvent)
58 {
59+ {
60+ if (!qtEvent->isAutoRepeat()) {
61+ Q_ASSERT(!isKeyPressed(qtEvent->nativeVirtualKey()));
62+ PressedKey pressedKey(qtEvent, msecsSinceReference());
63+ auto info = EventBuilder::instance()->findInfo(qtEvent->timestamp());
64+ if (info) {
65+ pressedKey.deviceId = info->deviceId;
66+ }
67+ m_pressedKeys.append(std::move(pressedKey));
68+ }
69+ }
70+
71 auto ev = EventBuilder::instance()->makeMirEvent(qtEvent);
72 auto ev1 = reinterpret_cast<MirKeyboardEvent const*>(ev.get());
73 m_controller->deliverKeyboardEvent(m_window, ev1);
74@@ -669,10 +709,14 @@
75
76 void MirSurface::keyReleaseEvent(QKeyEvent *qtEvent)
77 {
78- auto ev = EventBuilder::instance()->makeMirEvent(qtEvent);
79- auto ev1 = reinterpret_cast<MirKeyboardEvent const*>(ev.get());
80- m_controller->deliverKeyboardEvent(m_window, ev1);
81- qtEvent->accept();
82+ if (isKeyPressed(qtEvent->nativeVirtualKey())) {
83+ forgetPressedKey(qtEvent->nativeVirtualKey());
84+ auto ev = EventBuilder::instance()->makeMirEvent(qtEvent);
85+ auto ev1 = reinterpret_cast<MirKeyboardEvent const*>(ev.get());
86+ m_controller->deliverKeyboardEvent(m_window, ev1);
87+ } else {
88+ // don't send a release event for a key for which we did not send a press in the first place
89+ }
90 }
91
92 void MirSurface::touchEvent(Qt::KeyboardModifiers mods,
93@@ -1264,3 +1308,49 @@
94 QPoint point(m_surface->top_left().x.as_int(),m_surface->top_left().y.as_int());
95 setPosition(point);
96 }
97+
98+bool MirSurface::isKeyPressed(quint32 nativeVirtualKey) const
99+{
100+ for (const auto &pressedKey : m_pressedKeys) {
101+ if (pressedKey.nativeVirtualKey == nativeVirtualKey) {
102+ return true;
103+ }
104+ }
105+ return false;
106+}
107+
108+void MirSurface::forgetPressedKey(quint32 nativeVirtualKey)
109+{
110+ for (int i = 0; i < m_pressedKeys.count(); ++i) {
111+ if (m_pressedKeys[i].nativeVirtualKey == nativeVirtualKey) {
112+ m_pressedKeys.removeAt(i);
113+ return;
114+ }
115+ }
116+}
117+
118+void MirSurface::releaseAllPressedKeys()
119+{
120+ for (auto &pressedKey : m_pressedKeys) {
121+ auto deltaMs = (ulong)(msecsSinceReference() - pressedKey.msecsSinceReference);
122+ ulong timestamp = pressedKey.timestamp + deltaMs;
123+ std::vector<uint8_t> cookie{};
124+
125+ auto ev = mir::events::make_event(pressedKey.deviceId,
126+ uncompressTimestamp<qtmir::Timestamp>(qtmir::Timestamp(timestamp)),
127+ cookie, mir_keyboard_action_up, pressedKey.nativeVirtualKey, pressedKey.nativeScanCode,
128+ mir_input_event_modifier_none);
129+
130+ auto ev1 = reinterpret_cast<MirKeyboardEvent const*>(ev.get());
131+ m_controller->deliverKeyboardEvent(m_window, ev1);
132+ }
133+ m_pressedKeys.clear();
134+}
135+
136+MirSurface::PressedKey::PressedKey(QKeyEvent *qtEvent, qint64 msecsSinceReference)
137+ : nativeVirtualKey(qtEvent->nativeVirtualKey())
138+ , nativeScanCode(qtEvent->nativeScanCode())
139+ , timestamp(qtEvent->timestamp())
140+ , msecsSinceReference(msecsSinceReference)
141+{
142+}
143
144=== modified file 'src/modules/Unity/Application/mirsurface.h'
145--- src/modules/Unity/Application/mirsurface.h 2017-03-24 18:56:33 +0000
146+++ src/modules/Unity/Application/mirsurface.h 2017-03-24 18:56:33 +0000
147@@ -1,5 +1,5 @@
148 /*
149- * Copyright (C) 2015-2016 Canonical, Ltd.
150+ * Copyright (C) 2015-2017 Canonical, Ltd.
151 *
152 * This program is free software: you can redistribute it and/or modify it under
153 * the terms of the GNU Lesser General Public License version 3, as published by
154@@ -29,6 +29,8 @@
155 #include <QWeakPointer>
156 #include <QSet>
157 #include <QTimer>
158+#include <QVector>
159+#include <QKeyEvent>
160
161 #include "mirbuffersgtexture.h"
162 #include "windowcontrollerinterface.h"
163@@ -214,6 +216,11 @@
164 QPoint convertLocalToDisplayCoords(const QPoint &localPos) const;
165 void updatePosition();
166
167+ // Handling of missing key release events from Qt
168+ bool isKeyPressed(quint32 nativeVirtualKey) const;
169+ void forgetPressedKey(quint32 nativeVirtualKey);
170+ void releaseAllPressedKeys();
171+
172 const miral::Window m_window;
173 const std::shared_ptr<ExtraWindowInfo> m_extraInfo;
174 QString m_name;
175@@ -281,6 +288,18 @@
176 MirSurface *m_parentSurface;
177
178 MirSurfaceListModel *m_childSurfaceList;
179+
180+ // Track all keys that we told our mir window are currently pressed
181+ struct PressedKey {
182+ PressedKey() {}
183+ PressedKey(QKeyEvent *qtEvent, qint64 msecsSinceReference);
184+ quint32 nativeVirtualKey{0};
185+ quint32 nativeScanCode{0};
186+ ulong timestamp{0};
187+ MirInputDeviceId deviceId{0};
188+ qint64 msecsSinceReference{0};
189+ };
190+ QVector<PressedKey> m_pressedKeys;
191 };
192
193 } // namespace qtmir
194
195=== modified file 'src/platforms/mirserver/eventbuilder.h'
196--- src/platforms/mirserver/eventbuilder.h 2017-03-03 10:39:24 +0000
197+++ src/platforms/mirserver/eventbuilder.h 2017-03-24 18:56:33 +0000
198@@ -69,7 +69,6 @@
199 const QList<QTouchEvent::TouchPoint> &qtTouchPoints,
200 Qt::TouchPointStates /* qtTouchPointStates */,
201 ulong qtTimestamp);
202-private:
203 class EventInfo {
204 public:
205 void store(const MirInputEvent *mirInputEvent, ulong qtTimestamp);
206@@ -82,6 +81,7 @@
207
208 EventInfo *findInfo(ulong qtTimestamp);
209
210+private:
211 mir::EventUPtr makeMirEvent(QInputEvent *qtEvent, int x, int y, MirPointerButtons buttons);
212
213

Subscribers

People subscribed via source and target branches