on xenial help sign in
move the Alt-LMB handling into DecoratedWindow
commit390f6e33634d95924ae0562ff41e4c047832545d authorLukáš Tinkl <lukas.tinkl@canonical.com> dateThu 8 Sep 2016, 17:52 (10 years ago) parent0478550
7 files changed+40−88
CMakeLists.txt+1−1 plugins/Utils/WindowInputMonitor.cpp+5−28 plugins/Utils/WindowInputMonitor.h+3−8 qml/Shell.qml−15 qml/Stages/DecoratedWindow.qml+29−1 qml/Stages/DesktopStage.qml+1−31 tests/mocks/Utils/WindowInputMonitor.qml+1−4
CMakeLists.txt+1−1
@@ -57,7 +57,7 @@ find_package(Qt5DBus 5.4 REQUIRED)
5757find_package(Qt5Concurrent 5.4 REQUIRED)
5858find_package(Qt5Sql 5.4 REQUIRED)
5959
60−pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=22)
60+pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application>=21)
6161pkg_check_modules(GEONAMES REQUIRED geonames>=0.2)
6262pkg_check_modules(GIO REQUIRED gio-2.0>=2.32)
6363pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32)
plugins/Utils/WindowInputMonitor.cpp+5−28
@@ -56,13 +56,14 @@ bool WindowInputMonitor::eventFilter(QObject *watched, QEvent *event)
5656 Q_ASSERT(watched == static_cast<QObject*>(m_filteredWindow.data()));
5757 Q_UNUSED(watched);
5858
59− return update(event);
59+ update(event);
60+
61+ // We're only monitoring, never filtering out events
62+ return false;
6063}
6164
62−bool WindowInputMonitor::update(QEvent *event)
65+void WindowInputMonitor::update(QEvent *event)
6366{
64− bool result = false; // by default, just monitor
65−
6667 if (event->type() == QEvent::KeyPress) {
6768 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
6869
@@ -80,11 +81,6 @@ bool WindowInputMonitor::update(QEvent *event)
8081 if (keyEvent->key() == m_pressedHomeKey) {
8182 m_pressedHomeKey = 0;
8283 }
83− if (m_movingWindow && keyEvent->modifiers() == Qt::AltModifier) {
84− m_movingWindow = false;
85− result = true;
86− Q_EMIT windowMoveEnded();
87− }
8884
8985 } else if (event->type() == QEvent::TouchBegin) {
9086
@@ -102,26 +98,7 @@ bool WindowInputMonitor::update(QEvent *event)
10298 const QPointF pos = touchEv->touchPoints().last().screenPos();
10399 Q_EMIT touchEnded(pos);
104100 }
105− } else if (event->type() == QEvent::MouseButtonPress) {
106− QMouseEvent * mouseEv = static_cast<QMouseEvent *>(event);
107− if (mouseEv && mouseEv->button() == Qt::LeftButton && mouseEv->modifiers() == Qt::AltModifier) {
108− m_movingWindow = true;
109− result = true;
110− Q_EMIT windowMoveRequested(mouseEv->screenPos());
111− }
112− } else if (event->type() == QEvent::MouseMove && m_movingWindow) {
113− QMouseEvent * mouseEv = static_cast<QMouseEvent *>(event);
114− if (mouseEv) {
115− result = true;
116− Q_EMIT windowMoveUpdated(mouseEv->screenPos());
117− }
118− } else if (event->type() == QEvent::MouseButtonRelease && m_movingWindow) {
119− m_movingWindow = false;
120− result = true;
121− Q_EMIT windowMoveEnded();
122101 }
123−
124− return result;
125102}
126103
127104void WindowInputMonitor::setupFilterOnWindow(QQuickWindow *window)
plugins/Utils/WindowInputMonitor.h+3−8
@@ -36,18 +36,18 @@ class WindowInputMonitor : public QQuickItem
3636 Q_OBJECT
3737public:
3838
39− WindowInputMonitor(QQuickItem *parent = nullptr);
39+ WindowInputMonitor(QQuickItem *parent = 0);
4040
4141 // for testing
4242 WindowInputMonitor(UnityUtil::AbstractTimer *timer,
4343 UnityUtil::AbstractElapsedTimer *elapsedTimer,
44− QQuickItem *parent = nullptr);
44+ QQuickItem *parent = 0);
4545
4646 virtual ~WindowInputMonitor();
4747
4848 bool eventFilter(QObject *watched, QEvent *event) override;
4949
50− bool update(QEvent *event);
50+ void update(QEvent *event);
5151
5252 const qint64 msecsWithoutTouches = 150;
5353
@@ -77,10 +77,6 @@ Q_SIGNALS:
7777 */
7878 void touchEnded(const QPointF &pos);
7979
80− void windowMoveRequested(const QPointF &scenePos);
81− void windowMoveUpdated(const QPointF &scenePos);
82− void windowMoveEnded();
83−
8480private Q_SLOTS:
8581 void setupFilterOnWindow(QQuickWindow *window);
8682 void emitActivatedIfNoTouchesAround();
@@ -96,7 +92,6 @@ private:
9692 // Which Qt::Key from m_homeKeys is currently pressed.
9793 // 0 if none
9894 int m_pressedHomeKey{0};
99− bool m_movingWindow{false};
10095};
10196
10297#endif // UNITY_WINDOWINPUTMONITOR_H
qml/Shell.qml−15
@@ -260,21 +260,6 @@ StyledItem {
260260 cursor.y = mappedCoords.y;
261261 cursor.mouseNeverMoved = false;
262262 }
263− onWindowMoveRequested: {
264− if (applicationsDisplayLoader.item && applicationsDisplayLoader.item.windowMoveRequested) {
265− applicationsDisplayLoader.item.windowMoveRequested(scenePos);
266− }
267− }
268− onWindowMoveUpdated: {
269− if (applicationsDisplayLoader.item && applicationsDisplayLoader.item.windowMoveUpdated) {
270− applicationsDisplayLoader.item.windowMoveUpdated(scenePos);
271− }
272− }
273− onWindowMoveEnded: {
274− if (applicationsDisplayLoader.item && applicationsDisplayLoader.item.windowMoveEnded) {
275− applicationsDisplayLoader.item.windowMoveEnded();
276− }
277− }
278263 }
279264
280265 GSettings {
qml/Stages/DecoratedWindow.qml+29−1
@@ -57,7 +57,6 @@ FocusScope {
5757 readonly property alias dragging: moveHandler.dragging
5858
5959 readonly property Item clientAreaItem: applicationWindow
60− readonly property alias moveHandler: moveHandler
6160
6261 signal closeClicked()
6362 signal maximizeClicked()
@@ -155,4 +154,33 @@ FocusScope {
155154 angle: rotationAngle
156155 }
157156 }
157+
158+ MouseArea {
159+ anchors.fill: applicationWindow
160+ acceptedButtons: Qt.LeftButton
161+ hoverEnabled: true
162+ property bool dragging: false
163+ onPressed: {
164+ if (mouse.button == Qt.LeftButton && mouse.modifiers == Qt.AltModifier) {
165+ moveHandler.handlePressedChanged(true, Qt.LeftButton, mouse.x, mouse.y);
166+ dragging = true;
167+ mouse.accepted = true;
168+ } else {
169+ mouse.accepted = false;
170+ }
171+ }
172+ onPositionChanged: {
173+ if (dragging) {
174+ moveHandler.handlePositionChanged(mouse);
175+ }
176+ }
177+ onReleased: {
178+ if (dragging) {
179+ moveHandler.handlePressedChanged(false, Qt.LeftButton);
180+ root.decorationReleased(); // commits the fake preview max rectangle
181+ moveHandler.handleReleased();
182+ dragging = false;
183+ }
184+ }
185+ }
158186}
qml/Stages/DesktopStage.qml+1−31
@@ -42,35 +42,6 @@ AbstractStage {
4242 }
4343 }
4444
45− // Alt+LMB handlers
46− function windowMoveRequested(scenePos) {
47− var candidate;
48− if (priv.focusedAppDelegate && priv.focusedAppDelegate.contains(mapToItem(priv.focusedAppDelegate, scenePos.x, scenePos.y))) {
49− candidate = priv.focusedAppDelegate;
50− } else {
51− candidate = appContainer.childAt(scenePos.x, scenePos.y);
52− }
53−
54− if (candidate && candidate.moveHandler) {
55− var localPos = mapToItem(candidate, scenePos.x, scenePos.y)
56− candidate.focus = true;
57− candidate.moveHandler.handlePressedChanged(true, Qt.LeftButton, localPos.x, localPos.y);
58− }
59− }
60− function windowMoveUpdated(scenePos) {
61− if (priv.focusedAppDelegate) {
62− var localPos = mapToItem(priv.focusedAppDelegate, scenePos.x, scenePos.y)
63− priv.focusedAppDelegate.moveHandler.handlePositionChanged(localPos);
64− }
65− }
66− function windowMoveEnded() {
67− if (priv.focusedAppDelegate) {
68− priv.focusedAppDelegate.moveHandler.handlePressedChanged(false, Qt.LeftButton);
69− priv.focusedAppDelegate.moveHandler.handleReleased();
70− fakeRectangle.commit();
71− }
72− }
73−
7445 // Used by TutorialRight
7546 property bool spreadShown: spread.state == "altTab"
7647
@@ -379,8 +350,7 @@ AbstractStage {
379350 readonly property var surface: model.surface
380351 readonly property alias resizeArea: resizeArea
381352 readonly property alias focusedSurface: decoratedWindow.focusedSurface
382− readonly property bool dragging: moveHandler.dragging
383− readonly property alias moveHandler: decoratedWindow.moveHandler // for Alt+LMB dragging
353+ readonly property bool dragging: touchControls.overlayShown ? touchControls.dragging : decoratedWindow.dragging
384354
385355 readonly property bool isDash: model.application.appId == "unity8-dash"
386356 readonly property alias clientAreaItem: decoratedWindow.clientAreaItem
tests/mocks/Utils/WindowInputMonitor.qml+1−4
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015-2016 Canonical, Ltd.
2+ * Copyright (C) 2015 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -20,7 +20,4 @@ QtObject {
2020 signal homeKeyActivated()
2121 signal touchBegun()
2222 signal touchEnded(point pos)
23− signal windowMoveRequested(point scenePos)
24− signal windowMoveUpdated(point scenePos)
25− signal windowMoveEnded()
2623}