Merge lp:~aacid/unity-2d/non_sticky_barrier_on_non_activation_side into lp:unity-2d

Proposed by Albert Astals Cid
Status: Merged
Approved by: Albert Astals Cid
Approved revision: 1036
Merged at revision: 1037
Proposed branch: lp:~aacid/unity-2d/non_sticky_barrier_on_non_activation_side
Merge into: lp:unity-2d
Prerequisite: lp:~aacid/unity-2d/sticky_edges
Diff against target: 211 lines (+102/-12)
4 files modified
libunity-2d-private/src/pointerbarrier.cpp (+38/-12)
libunity-2d-private/src/pointerbarrier.h (+8/-0)
libunity-2d-private/tests/pointerbarriertest.cpp (+55/-0)
shell/Shell.qml (+1/-0)
To merge this branch: bzr merge lp:~aacid/unity-2d/non_sticky_barrier_on_non_activation_side
Reviewer Review Type Date Requested Status
Paweł Stołowski (community) Approve
Review via email: mp+100571@code.launchpad.net

Commit message

Add the triggerOnly property to pointer barriers this way you can make a barrier release itself when the mouse travels the barrier in the non trigger direction

Description of the change

Add the triggerOnly property to pointer barriers this way you can make a barrier release itself when the mouse travels the barrier in the non trigger direction

To post a comment you must log in.
Revision history for this message
Paweł Stołowski (stolowski) wrote :

Looks good and works as advertised!

review: Approve
Revision history for this message
Unity Merger (unity-merger) wrote :

No proposals found for merge of lp:~aacid/unity-2d/sticky_edges into lp:unity-2d.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libunity-2d-private/src/pointerbarrier.cpp'
2--- libunity-2d-private/src/pointerbarrier.cpp 2012-03-02 10:38:40 +0000
3+++ libunity-2d-private/src/pointerbarrier.cpp 2012-04-03 09:17:21 +0000
4@@ -30,6 +30,7 @@
5 , m_barrier(0)
6 , m_triggerDirection(TriggerFromAnywhere)
7 , m_triggerZoneEnabled(false)
8+ , m_triggerOnly(false)
9 , m_threshold(-1)
10 , m_maxVelocityMultiplier(-1)
11 , m_decayRate(-1)
12@@ -151,6 +152,19 @@
13 }
14 }
15
16+bool PointerBarrierWrapper::triggerOnly() const
17+{
18+ return m_triggerOnly;
19+}
20+
21+void PointerBarrierWrapper::setTriggerOnly(bool triggerOnly)
22+{
23+ if (triggerOnly != m_triggerOnly) {
24+ m_triggerOnly = triggerOnly;
25+ Q_EMIT triggerOnlyChanged(triggerOnly);
26+ }
27+}
28+
29 void PointerBarrierWrapper::createBarrier()
30 {
31 if (m_threshold < 0) {
32@@ -194,6 +208,13 @@
33 if (!m_smoothingTimer->isActive()) {
34 m_smoothingTimer->start();
35 }
36+
37+ if (m_triggerOnly && !isLastEventAgainstTrigger()) {
38+ // We got to the barrier from the non triggering direction
39+ // Release it so the mouse can continue its travel
40+ Display *display = QX11Info::display();
41+ XFixesBarrierReleasePointer (display, m_barrier, m_lastEventId);
42+ }
43 }
44
45 int PointerBarrierWrapper::threshold() const
46@@ -288,18 +309,7 @@
47 }
48 const int velocity = qMin<qreal>(600 * m_maxVelocityMultiplier, m_smoothingAccumulator / m_smoothingCount);
49
50- bool againstTrigger = false;
51- if (m_triggerZoneEnabled && m_triggerZoneP1.x() == m_triggerZoneP2.x() && m_triggerZoneP1.y() <= m_lastEventY && m_triggerZoneP2.y() >= m_lastEventY) {
52- againstTrigger = m_triggerDirection == TriggerFromAnywhere ||
53- (m_triggerDirection == TriggerFromRight && m_lastEventX >= m_triggerZoneP1.x()) ||
54- (m_triggerDirection == TriggerFromLeft && m_lastEventX < m_triggerZoneP1.x());
55- }
56- if (m_triggerZoneEnabled && m_triggerZoneP1.y() == m_triggerZoneP2.y() && m_triggerZoneP1.x() <= m_lastEventX && m_triggerZoneP2.x() >= m_lastEventX) {
57- againstTrigger = m_triggerDirection == TriggerFromAnywhere ||
58- (m_triggerDirection == TriggerFromTop && m_lastEventY >= m_triggerZoneP1.y()) ||
59- (m_triggerDirection == TriggerFromBottom && m_lastEventY < m_triggerZoneP1.y());
60- }
61- if (againstTrigger) {
62+ if (isLastEventAgainstTrigger()) {
63 if (m_triggerValue.addAndCheckExceedingTarget(velocity)) {
64 Q_EMIT triggered();
65 }
66@@ -358,4 +368,20 @@
67
68 }
69
70+bool PointerBarrierWrapper::isLastEventAgainstTrigger() const
71+{
72+ bool againstTrigger = false;
73+ if (m_triggerZoneEnabled && m_triggerZoneP1.x() == m_triggerZoneP2.x() && m_triggerZoneP1.y() <= m_lastEventY && m_triggerZoneP2.y() >= m_lastEventY) {
74+ againstTrigger = m_triggerDirection == TriggerFromAnywhere ||
75+ (m_triggerDirection == TriggerFromRight && m_lastEventX >= m_triggerZoneP1.x()) ||
76+ (m_triggerDirection == TriggerFromLeft && m_lastEventX < m_triggerZoneP1.x());
77+ }
78+ if (m_triggerZoneEnabled && m_triggerZoneP1.y() == m_triggerZoneP2.y() && m_triggerZoneP1.x() <= m_lastEventX && m_triggerZoneP2.x() >= m_lastEventX) {
79+ againstTrigger = m_triggerDirection == TriggerFromAnywhere ||
80+ (m_triggerDirection == TriggerFromTop && m_lastEventY >= m_triggerZoneP1.y()) ||
81+ (m_triggerDirection == TriggerFromBottom && m_lastEventY < m_triggerZoneP1.y());
82+ }
83+ return againstTrigger;
84+}
85+
86 #include <pointerbarrier.moc>
87
88=== modified file 'libunity-2d-private/src/pointerbarrier.h'
89--- libunity-2d-private/src/pointerbarrier.h 2012-03-02 10:38:40 +0000
90+++ libunity-2d-private/src/pointerbarrier.h 2012-04-03 09:17:21 +0000
91@@ -36,6 +36,7 @@
92 Q_PROPERTY(QPointF triggerZoneP2 READ triggerZoneP2 WRITE setTriggerZoneP2 NOTIFY triggerZoneP2Changed)
93 Q_PROPERTY(TriggerDirection triggerDirection READ triggerDirection WRITE setTriggerDirection NOTIFY triggerDirectionChanged)
94 Q_PROPERTY(bool triggerZoneEnabled READ triggerZoneEnabled WRITE setTriggerZoneEnabled NOTIFY triggerZoneEnabledChanged)
95+ Q_PROPERTY(bool triggerOnly READ triggerOnly WRITE setTriggerOnly NOTIFY triggerOnlyChanged)
96 Q_PROPERTY(int threshold READ threshold WRITE setThreshold NOTIFY thresholdChanged)
97 Q_PROPERTY(int maxVelocityMultiplier READ maxVelocityMultiplier WRITE setMaxVelocityMultiplier NOTIFY maxVelocityMultiplierChanged)
98 Q_PROPERTY(int decayRate READ decayRate WRITE setDecayRate NOTIFY decayRateChanged)
99@@ -75,6 +76,9 @@
100 bool triggerZoneEnabled() const;
101 void setTriggerZoneEnabled(bool enabled);
102
103+ bool triggerOnly() const;
104+ void setTriggerOnly(bool triggerOnly);
105+
106 int threshold() const;
107 void setThreshold(int threshold);
108
109@@ -99,6 +103,7 @@
110 void triggerZoneP2Changed(const QPointF &p2);
111 void triggerDirectionChanged(TriggerDirection direction);
112 void triggerZoneEnabledChanged(bool changed);
113+ void triggerOnlyChanged(bool triggerOnly);
114 void thresholdChanged(int threshold);
115 void maxVelocityMultiplierChanged(qreal maxVelocityMultiplier);
116 void decayRateChanged(int decayRate);
117@@ -125,6 +130,8 @@
118
119 bool isPointAlignmentCorrect() const;
120
121+ bool isLastEventAgainstTrigger() const;
122+
123 PointerBarrier m_barrier;
124
125 QPointF m_p1;
126@@ -133,6 +140,7 @@
127 QPointF m_triggerZoneP2;
128 TriggerDirection m_triggerDirection;
129 bool m_triggerZoneEnabled;
130+ bool m_triggerOnly;
131 int m_threshold;
132 qreal m_maxVelocityMultiplier;
133 int m_decayRate;
134
135=== modified file 'libunity-2d-private/tests/pointerbarriertest.cpp'
136--- libunity-2d-private/tests/pointerbarriertest.cpp 2012-03-12 10:11:56 +0000
137+++ libunity-2d-private/tests/pointerbarriertest.cpp 2012-04-03 09:17:21 +0000
138@@ -305,6 +305,61 @@
139 QCOMPARE(brokenSpy.count(), 0);
140 QCOMPARE(triggeredSpy.count(), 0);
141 }
142+
143+ void testTriggerOnly()
144+ {
145+ Display *display = QX11Info::display();
146+ PointerBarrierWrapper barrier;
147+
148+ QSignalSpy brokenSpy(&barrier, SIGNAL(broken()));
149+ QSignalSpy triggeredSpy(&barrier, SIGNAL(triggered()));
150+
151+ XTestFakeMotionEvent(display, -1, 50, 50, 0);
152+ QCOMPARE(QCursor::pos(), QPoint(50, 50));
153+
154+ barrier.setP1(QPointF(100, 0));
155+ barrier.setP2(QPointF(100, 100));
156+ barrier.setTriggerZoneP1(QPointF(100, 0));
157+ barrier.setTriggerZoneP2(QPointF(100, 100));
158+ barrier.setTriggerZoneEnabled(true);
159+ barrier.setTriggerOnly(true);
160+ barrier.setTriggerDirection(PointerBarrierWrapper::TriggerFromRight);
161+ barrier.setThreshold(6500);
162+ barrier.setMaxVelocityMultiplier(2);
163+ barrier.setDecayRate(1500);
164+ barrier.setTriggerPressure(2000);
165+ barrier.setBreakPressure(2000);
166+
167+ for (int i = 0; i < 100; ++i) {
168+ XTestFakeRelativeMotionEvent(display, 1, 0, 0);
169+ QTest::qWait(1);
170+ }
171+
172+ // We are not stopped by the barrier because
173+ // we are not hitting it from the trigger direction
174+ QVERIFY(QCursor::pos() != QPoint(99, 50));
175+
176+ QCOMPARE(brokenSpy.count(), 0);
177+ QCOMPARE(triggeredSpy.count(), 0);
178+
179+ QTest::qWait(100); // Wait until X reenables the barrier
180+
181+ XTestFakeRelativeMotionEvent(display, -300, 0, 0);
182+ // We are stopped by the barrier and instead in 50, 50 we are in 100, 50
183+ QCOMPARE(QCursor::pos(), QPoint(100, 50));
184+
185+ QCOMPARE(brokenSpy.count(), 0);
186+ QCOMPARE(triggeredSpy.count(), 0);
187+
188+ for (int i = 0; i < 10; ++i) {
189+ XTestFakeRelativeMotionEvent(display, -100, 0, 0);
190+ QTest::qWait(100);
191+ }
192+ // We have triggered the barrier and are still there
193+ QCOMPARE(QCursor::pos(), QPoint(100, 50));
194+ QCOMPARE(brokenSpy.count(), 0);
195+ QVERIFY(triggeredSpy.count() >= 1);
196+ }
197 };
198
199 UAPP_TEST_MAIN(PointerBarrierTest)
200
201=== modified file 'shell/Shell.qml'
202--- shell/Shell.qml 2012-04-03 09:17:21 +0000
203+++ shell/Shell.qml 2012-04-03 09:17:21 +0000
204@@ -282,6 +282,7 @@
205 id: leftBarrier
206 triggerDirection: Utils.isLeftToRight() ? PointerBarrier.TriggerFromRight : PointerBarrier.TriggerFromLeft
207 triggerZoneEnabled: enableTrigger && !launcherLoader.visibilityController.shown
208+ triggerOnly: enableTrigger && !enableSticky
209 p1: Qt.point(x, declarativeView.screen.geometry.y)
210 p2: Qt.point(x, declarativeView.screen.geometry.y + declarativeView.screen.geometry.height)
211 triggerZoneP1: Qt.point(x, declarativeView.globalPosition.y)

Subscribers

People subscribed via source and target branches