~gerboland/qtmir/small-hooks-change

« back to all changes in this revision

Viewing changes to src/modules/Unity/Application/mirsurface.h

  • Committer: Bileto Bot
  • Author(s): Daniel d'Andrada
  • Date: 2017-03-28 17:12:39 UTC
  • mfrom: (625.1.4 keyState)
  • Revision ID: ci-train-bot@canonical.com-20170328171239-nd8gj4bz4srkgof1
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. (LP: #1671072)

Approved by: Gerry Boland, Unity8 CI Bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2015-2016 Canonical, Ltd.
 
2
 * Copyright (C) 2015-2017 Canonical, Ltd.
3
3
 *
4
4
 * This program is free software: you can redistribute it and/or modify it under
5
5
 * the terms of the GNU Lesser General Public License version 3, as published by
29
29
#include <QWeakPointer>
30
30
#include <QSet>
31
31
#include <QTimer>
 
32
#include <QVector>
 
33
#include <QKeyEvent>
32
34
 
33
35
#include "mirbuffersgtexture.h"
34
36
#include "windowcontrollerinterface.h"
214
216
    QPoint convertLocalToDisplayCoords(const QPoint &localPos) const;
215
217
    void updatePosition();
216
218
 
 
219
    // Handling of missing key release events from Qt
 
220
    bool isKeyPressed(quint32 nativeVirtualKey) const;
 
221
    void forgetPressedKey(quint32 nativeVirtualKey);
 
222
    void releaseAllPressedKeys();
 
223
 
217
224
    const miral::Window m_window;
218
225
    const std::shared_ptr<ExtraWindowInfo> m_extraInfo;
219
226
    QString m_name;
281
288
    MirSurface *m_parentSurface;
282
289
 
283
290
    MirSurfaceListModel *m_childSurfaceList;
 
291
 
 
292
    // Track all keys that we told our mir window are currently pressed
 
293
    struct PressedKey {
 
294
        PressedKey() {}
 
295
        PressedKey(QKeyEvent *qtEvent, qint64 msecsSinceReference);
 
296
        quint32 nativeVirtualKey{0};
 
297
        quint32 nativeScanCode{0};
 
298
        ulong timestamp{0};
 
299
        MirInputDeviceId deviceId{0};
 
300
        qint64 msecsSinceReference{0};
 
301
    };
 
302
    QVector<PressedKey> m_pressedKeys;
284
303
};
285
304
 
286
305
} // namespace qtmir