on xenial help sign in
move the Alt-LMB handling into DecoratedWindow
390f6e3Lukáš Tinkl
CMakeLists.txt+1−1
@@ -57,7 +57,7 @@ find_package(Qt5DBus 5.4 REQUIRED)
57find_package(Qt5Concurrent 5.4 REQUIRED)
57find_package(Qt5Concurrent 5.4 REQUIRED)
58find_package(Qt5Sql 5.4 REQUIRED)
58find_package(Qt5Sql 5.4 REQUIRED)
59
59
60−pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=22)
60+pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application>=21)
61pkg_check_modules(GEONAMES REQUIRED geonames>=0.2)
61pkg_check_modules(GEONAMES REQUIRED geonames>=0.2)
62pkg_check_modules(GIO REQUIRED gio-2.0>=2.32)
62pkg_check_modules(GIO REQUIRED gio-2.0>=2.32)
63pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32)
63pkg_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)
56 Q_ASSERT(watched == static_cast<QObject*>(m_filteredWindow.data()));
56 Q_ASSERT(watched == static_cast<QObject*>(m_filteredWindow.data()));
57 Q_UNUSED(watched);
57 Q_UNUSED(watched);
58
58
59− return update(event);
59+ update(event);
60+
61+ // We're only monitoring, never filtering out events
62+ return false;
60}
63}
61
64
62−bool WindowInputMonitor::update(QEvent *event)
65+void WindowInputMonitor::update(QEvent *event)
63{
66{
64− bool result = false; // by default, just monitor
65−
66 if (event->type() == QEvent::KeyPress) {
67 if (event->type() == QEvent::KeyPress) {
67 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
68 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
68
69
@@ -80,11 +81,6 @@ bool WindowInputMonitor::update(QEvent *event)
80 if (keyEvent->key() == m_pressedHomeKey) {
81 if (keyEvent->key() == m_pressedHomeKey) {
81 m_pressedHomeKey = 0;
82 m_pressedHomeKey = 0;
82 }
83 }
83− if (m_movingWindow && keyEvent->modifiers() == Qt::AltModifier) {
84− m_movingWindow = false;
85− result = true;
86− Q_EMIT windowMoveEnded();
87− }
88
84
89 } else if (event->type() == QEvent::TouchBegin) {
85 } else if (event->type() == QEvent::TouchBegin) {
90
86
@@ -102,26 +98,7 @@ bool WindowInputMonitor::update(QEvent *event)
102 const QPointF pos = touchEv->touchPoints().last().screenPos();
98 const QPointF pos = touchEv->touchPoints().last().screenPos();
103 Q_EMIT touchEnded(pos);
99 Q_EMIT touchEnded(pos);
104 }
100 }
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();
122 }
101 }
123−
124− return result;
125}
102}
126
103
127void WindowInputMonitor::setupFilterOnWindow(QQuickWindow *window)
104void WindowInputMonitor::setupFilterOnWindow(QQuickWindow *window)
plugins/Utils/WindowInputMonitor.h+3−8
@@ -36,18 +36,18 @@ class WindowInputMonitor : public QQuickItem
36 Q_OBJECT
36 Q_OBJECT
37public:
37public:
38
38
39− WindowInputMonitor(QQuickItem *parent = nullptr);
39+ WindowInputMonitor(QQuickItem *parent = 0);
40
40
41 // for testing
41 // for testing
42 WindowInputMonitor(UnityUtil::AbstractTimer *timer,
42 WindowInputMonitor(UnityUtil::AbstractTimer *timer,
43 UnityUtil::AbstractElapsedTimer *elapsedTimer,
43 UnityUtil::AbstractElapsedTimer *elapsedTimer,
44− QQuickItem *parent = nullptr);
44+ QQuickItem *parent = 0);
45
45
46 virtual ~WindowInputMonitor();
46 virtual ~WindowInputMonitor();
47
47
48 bool eventFilter(QObject *watched, QEvent *event) override;
48 bool eventFilter(QObject *watched, QEvent *event) override;
49
49
50− bool update(QEvent *event);
50+ void update(QEvent *event);
51
51
52 const qint64 msecsWithoutTouches = 150;
52 const qint64 msecsWithoutTouches = 150;
53
53
@@ -77,10 +77,6 @@ Q_SIGNALS:
77 */
77 */
78 void touchEnded(const QPointF &pos);
78 void touchEnded(const QPointF &pos);
79
79
80− void windowMoveRequested(const QPointF &scenePos);
81− void windowMoveUpdated(const QPointF &scenePos);
82− void windowMoveEnded();
83−
84private Q_SLOTS:
80private Q_SLOTS:
85 void setupFilterOnWindow(QQuickWindow *window);
81 void setupFilterOnWindow(QQuickWindow *window);
86 void emitActivatedIfNoTouchesAround();
82 void emitActivatedIfNoTouchesAround();
@@ -96,7 +92,6 @@ private:
96 // Which Qt::Key from m_homeKeys is currently pressed.
92 // Which Qt::Key from m_homeKeys is currently pressed.
97 // 0 if none
93 // 0 if none
98 int m_pressedHomeKey{0};
94 int m_pressedHomeKey{0};
99− bool m_movingWindow{false};
100};
95};
101
96
102#endif // UNITY_WINDOWINPUTMONITOR_H
97#endif // UNITY_WINDOWINPUTMONITOR_H
qml/Shell.qml−15
@@ -260,21 +260,6 @@ StyledItem {
260 cursor.y = mappedCoords.y;
260 cursor.y = mappedCoords.y;
261 cursor.mouseNeverMoved = false;
261 cursor.mouseNeverMoved = false;
262 }
262 }
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− }
278 }
263 }
279
264
280 GSettings {
265 GSettings {
qml/Stages/DecoratedWindow.qml+29−1
@@ -57,7 +57,6 @@ FocusScope {
57 readonly property alias dragging: moveHandler.dragging
57 readonly property alias dragging: moveHandler.dragging
58
58
59 readonly property Item clientAreaItem: applicationWindow
59 readonly property Item clientAreaItem: applicationWindow
60− readonly property alias moveHandler: moveHandler
61
60
62 signal closeClicked()
61 signal closeClicked()
63 signal maximizeClicked()
62 signal maximizeClicked()
@@ -155,4 +154,33 @@ FocusScope {
155 angle: rotationAngle
154 angle: rotationAngle
156 }
155 }
157 }
156 }
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+ }
158}
186}
qml/Stages/DesktopStage.qml+1−31
@@ -42,35 +42,6 @@ AbstractStage {
42 }
42 }
43 }
43 }
44
44
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−
74 // Used by TutorialRight
45 // Used by TutorialRight
75 property bool spreadShown: spread.state == "altTab"
46 property bool spreadShown: spread.state == "altTab"
76
47
@@ -379,8 +350,7 @@ AbstractStage {
379 readonly property var surface: model.surface
350 readonly property var surface: model.surface
380 readonly property alias resizeArea: resizeArea
351 readonly property alias resizeArea: resizeArea
381 readonly property alias focusedSurface: decoratedWindow.focusedSurface
352 readonly property alias focusedSurface: decoratedWindow.focusedSurface
382− readonly property bool dragging: moveHandler.dragging
353+ readonly property bool dragging: touchControls.overlayShown ? touchControls.dragging : decoratedWindow.dragging
383− readonly property alias moveHandler: decoratedWindow.moveHandler // for Alt+LMB dragging
384
354
385 readonly property bool isDash: model.application.appId == "unity8-dash"
355 readonly property bool isDash: model.application.appId == "unity8-dash"
386 readonly property alias clientAreaItem: decoratedWindow.clientAreaItem
356 readonly property alias clientAreaItem: decoratedWindow.clientAreaItem
tests/mocks/Utils/WindowInputMonitor.qml+1−4
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2015-2016 Canonical, Ltd.
2+ * Copyright (C) 2015 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
@@ -20,7 +20,4 @@ QtObject {
20 signal homeKeyActivated()
20 signal homeKeyActivated()
21 signal touchBegun()
21 signal touchBegun()
22 signal touchEnded(point pos)
22 signal touchEnded(point pos)
23− signal windowMoveRequested(point scenePos)
24− signal windowMoveUpdated(point scenePos)
25− signal windowMoveEnded()
26}
23}