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
=== modified file 'libunity-2d-private/src/pointerbarrier.cpp'
--- libunity-2d-private/src/pointerbarrier.cpp 2012-03-02 10:38:40 +0000
+++ libunity-2d-private/src/pointerbarrier.cpp 2012-04-03 09:17:21 +0000
@@ -30,6 +30,7 @@
30 , m_barrier(0)30 , m_barrier(0)
31 , m_triggerDirection(TriggerFromAnywhere)31 , m_triggerDirection(TriggerFromAnywhere)
32 , m_triggerZoneEnabled(false)32 , m_triggerZoneEnabled(false)
33 , m_triggerOnly(false)
33 , m_threshold(-1)34 , m_threshold(-1)
34 , m_maxVelocityMultiplier(-1)35 , m_maxVelocityMultiplier(-1)
35 , m_decayRate(-1)36 , m_decayRate(-1)
@@ -151,6 +152,19 @@
151 }152 }
152}153}
153154
155bool PointerBarrierWrapper::triggerOnly() const
156{
157 return m_triggerOnly;
158}
159
160void PointerBarrierWrapper::setTriggerOnly(bool triggerOnly)
161{
162 if (triggerOnly != m_triggerOnly) {
163 m_triggerOnly = triggerOnly;
164 Q_EMIT triggerOnlyChanged(triggerOnly);
165 }
166}
167
154void PointerBarrierWrapper::createBarrier()168void PointerBarrierWrapper::createBarrier()
155{169{
156 if (m_threshold < 0) {170 if (m_threshold < 0) {
@@ -194,6 +208,13 @@
194 if (!m_smoothingTimer->isActive()) {208 if (!m_smoothingTimer->isActive()) {
195 m_smoothingTimer->start();209 m_smoothingTimer->start();
196 }210 }
211
212 if (m_triggerOnly && !isLastEventAgainstTrigger()) {
213 // We got to the barrier from the non triggering direction
214 // Release it so the mouse can continue its travel
215 Display *display = QX11Info::display();
216 XFixesBarrierReleasePointer (display, m_barrier, m_lastEventId);
217 }
197}218}
198219
199int PointerBarrierWrapper::threshold() const220int PointerBarrierWrapper::threshold() const
@@ -288,18 +309,7 @@
288 }309 }
289 const int velocity = qMin<qreal>(600 * m_maxVelocityMultiplier, m_smoothingAccumulator / m_smoothingCount);310 const int velocity = qMin<qreal>(600 * m_maxVelocityMultiplier, m_smoothingAccumulator / m_smoothingCount);
290311
291 bool againstTrigger = false;312 if (isLastEventAgainstTrigger()) {
292 if (m_triggerZoneEnabled && m_triggerZoneP1.x() == m_triggerZoneP2.x() && m_triggerZoneP1.y() <= m_lastEventY && m_triggerZoneP2.y() >= m_lastEventY) {
293 againstTrigger = m_triggerDirection == TriggerFromAnywhere ||
294 (m_triggerDirection == TriggerFromRight && m_lastEventX >= m_triggerZoneP1.x()) ||
295 (m_triggerDirection == TriggerFromLeft && m_lastEventX < m_triggerZoneP1.x());
296 }
297 if (m_triggerZoneEnabled && m_triggerZoneP1.y() == m_triggerZoneP2.y() && m_triggerZoneP1.x() <= m_lastEventX && m_triggerZoneP2.x() >= m_lastEventX) {
298 againstTrigger = m_triggerDirection == TriggerFromAnywhere ||
299 (m_triggerDirection == TriggerFromTop && m_lastEventY >= m_triggerZoneP1.y()) ||
300 (m_triggerDirection == TriggerFromBottom && m_lastEventY < m_triggerZoneP1.y());
301 }
302 if (againstTrigger) {
303 if (m_triggerValue.addAndCheckExceedingTarget(velocity)) {313 if (m_triggerValue.addAndCheckExceedingTarget(velocity)) {
304 Q_EMIT triggered();314 Q_EMIT triggered();
305 }315 }
@@ -358,4 +368,20 @@
358368
359}369}
360370
371bool PointerBarrierWrapper::isLastEventAgainstTrigger() const
372{
373 bool againstTrigger = false;
374 if (m_triggerZoneEnabled && m_triggerZoneP1.x() == m_triggerZoneP2.x() && m_triggerZoneP1.y() <= m_lastEventY && m_triggerZoneP2.y() >= m_lastEventY) {
375 againstTrigger = m_triggerDirection == TriggerFromAnywhere ||
376 (m_triggerDirection == TriggerFromRight && m_lastEventX >= m_triggerZoneP1.x()) ||
377 (m_triggerDirection == TriggerFromLeft && m_lastEventX < m_triggerZoneP1.x());
378 }
379 if (m_triggerZoneEnabled && m_triggerZoneP1.y() == m_triggerZoneP2.y() && m_triggerZoneP1.x() <= m_lastEventX && m_triggerZoneP2.x() >= m_lastEventX) {
380 againstTrigger = m_triggerDirection == TriggerFromAnywhere ||
381 (m_triggerDirection == TriggerFromTop && m_lastEventY >= m_triggerZoneP1.y()) ||
382 (m_triggerDirection == TriggerFromBottom && m_lastEventY < m_triggerZoneP1.y());
383 }
384 return againstTrigger;
385}
386
361#include <pointerbarrier.moc>387#include <pointerbarrier.moc>
362388
=== modified file 'libunity-2d-private/src/pointerbarrier.h'
--- libunity-2d-private/src/pointerbarrier.h 2012-03-02 10:38:40 +0000
+++ libunity-2d-private/src/pointerbarrier.h 2012-04-03 09:17:21 +0000
@@ -36,6 +36,7 @@
36 Q_PROPERTY(QPointF triggerZoneP2 READ triggerZoneP2 WRITE setTriggerZoneP2 NOTIFY triggerZoneP2Changed)36 Q_PROPERTY(QPointF triggerZoneP2 READ triggerZoneP2 WRITE setTriggerZoneP2 NOTIFY triggerZoneP2Changed)
37 Q_PROPERTY(TriggerDirection triggerDirection READ triggerDirection WRITE setTriggerDirection NOTIFY triggerDirectionChanged)37 Q_PROPERTY(TriggerDirection triggerDirection READ triggerDirection WRITE setTriggerDirection NOTIFY triggerDirectionChanged)
38 Q_PROPERTY(bool triggerZoneEnabled READ triggerZoneEnabled WRITE setTriggerZoneEnabled NOTIFY triggerZoneEnabledChanged)38 Q_PROPERTY(bool triggerZoneEnabled READ triggerZoneEnabled WRITE setTriggerZoneEnabled NOTIFY triggerZoneEnabledChanged)
39 Q_PROPERTY(bool triggerOnly READ triggerOnly WRITE setTriggerOnly NOTIFY triggerOnlyChanged)
39 Q_PROPERTY(int threshold READ threshold WRITE setThreshold NOTIFY thresholdChanged)40 Q_PROPERTY(int threshold READ threshold WRITE setThreshold NOTIFY thresholdChanged)
40 Q_PROPERTY(int maxVelocityMultiplier READ maxVelocityMultiplier WRITE setMaxVelocityMultiplier NOTIFY maxVelocityMultiplierChanged)41 Q_PROPERTY(int maxVelocityMultiplier READ maxVelocityMultiplier WRITE setMaxVelocityMultiplier NOTIFY maxVelocityMultiplierChanged)
41 Q_PROPERTY(int decayRate READ decayRate WRITE setDecayRate NOTIFY decayRateChanged)42 Q_PROPERTY(int decayRate READ decayRate WRITE setDecayRate NOTIFY decayRateChanged)
@@ -75,6 +76,9 @@
75 bool triggerZoneEnabled() const;76 bool triggerZoneEnabled() const;
76 void setTriggerZoneEnabled(bool enabled);77 void setTriggerZoneEnabled(bool enabled);
7778
79 bool triggerOnly() const;
80 void setTriggerOnly(bool triggerOnly);
81
78 int threshold() const;82 int threshold() const;
79 void setThreshold(int threshold);83 void setThreshold(int threshold);
8084
@@ -99,6 +103,7 @@
99 void triggerZoneP2Changed(const QPointF &p2);103 void triggerZoneP2Changed(const QPointF &p2);
100 void triggerDirectionChanged(TriggerDirection direction);104 void triggerDirectionChanged(TriggerDirection direction);
101 void triggerZoneEnabledChanged(bool changed);105 void triggerZoneEnabledChanged(bool changed);
106 void triggerOnlyChanged(bool triggerOnly);
102 void thresholdChanged(int threshold);107 void thresholdChanged(int threshold);
103 void maxVelocityMultiplierChanged(qreal maxVelocityMultiplier);108 void maxVelocityMultiplierChanged(qreal maxVelocityMultiplier);
104 void decayRateChanged(int decayRate);109 void decayRateChanged(int decayRate);
@@ -125,6 +130,8 @@
125130
126 bool isPointAlignmentCorrect() const;131 bool isPointAlignmentCorrect() const;
127132
133 bool isLastEventAgainstTrigger() const;
134
128 PointerBarrier m_barrier;135 PointerBarrier m_barrier;
129136
130 QPointF m_p1;137 QPointF m_p1;
@@ -133,6 +140,7 @@
133 QPointF m_triggerZoneP2;140 QPointF m_triggerZoneP2;
134 TriggerDirection m_triggerDirection;141 TriggerDirection m_triggerDirection;
135 bool m_triggerZoneEnabled;142 bool m_triggerZoneEnabled;
143 bool m_triggerOnly;
136 int m_threshold;144 int m_threshold;
137 qreal m_maxVelocityMultiplier;145 qreal m_maxVelocityMultiplier;
138 int m_decayRate;146 int m_decayRate;
139147
=== modified file 'libunity-2d-private/tests/pointerbarriertest.cpp'
--- libunity-2d-private/tests/pointerbarriertest.cpp 2012-03-12 10:11:56 +0000
+++ libunity-2d-private/tests/pointerbarriertest.cpp 2012-04-03 09:17:21 +0000
@@ -305,6 +305,61 @@
305 QCOMPARE(brokenSpy.count(), 0);305 QCOMPARE(brokenSpy.count(), 0);
306 QCOMPARE(triggeredSpy.count(), 0);306 QCOMPARE(triggeredSpy.count(), 0);
307 }307 }
308
309 void testTriggerOnly()
310 {
311 Display *display = QX11Info::display();
312 PointerBarrierWrapper barrier;
313
314 QSignalSpy brokenSpy(&barrier, SIGNAL(broken()));
315 QSignalSpy triggeredSpy(&barrier, SIGNAL(triggered()));
316
317 XTestFakeMotionEvent(display, -1, 50, 50, 0);
318 QCOMPARE(QCursor::pos(), QPoint(50, 50));
319
320 barrier.setP1(QPointF(100, 0));
321 barrier.setP2(QPointF(100, 100));
322 barrier.setTriggerZoneP1(QPointF(100, 0));
323 barrier.setTriggerZoneP2(QPointF(100, 100));
324 barrier.setTriggerZoneEnabled(true);
325 barrier.setTriggerOnly(true);
326 barrier.setTriggerDirection(PointerBarrierWrapper::TriggerFromRight);
327 barrier.setThreshold(6500);
328 barrier.setMaxVelocityMultiplier(2);
329 barrier.setDecayRate(1500);
330 barrier.setTriggerPressure(2000);
331 barrier.setBreakPressure(2000);
332
333 for (int i = 0; i < 100; ++i) {
334 XTestFakeRelativeMotionEvent(display, 1, 0, 0);
335 QTest::qWait(1);
336 }
337
338 // We are not stopped by the barrier because
339 // we are not hitting it from the trigger direction
340 QVERIFY(QCursor::pos() != QPoint(99, 50));
341
342 QCOMPARE(brokenSpy.count(), 0);
343 QCOMPARE(triggeredSpy.count(), 0);
344
345 QTest::qWait(100); // Wait until X reenables the barrier
346
347 XTestFakeRelativeMotionEvent(display, -300, 0, 0);
348 // We are stopped by the barrier and instead in 50, 50 we are in 100, 50
349 QCOMPARE(QCursor::pos(), QPoint(100, 50));
350
351 QCOMPARE(brokenSpy.count(), 0);
352 QCOMPARE(triggeredSpy.count(), 0);
353
354 for (int i = 0; i < 10; ++i) {
355 XTestFakeRelativeMotionEvent(display, -100, 0, 0);
356 QTest::qWait(100);
357 }
358 // We have triggered the barrier and are still there
359 QCOMPARE(QCursor::pos(), QPoint(100, 50));
360 QCOMPARE(brokenSpy.count(), 0);
361 QVERIFY(triggeredSpy.count() >= 1);
362 }
308};363};
309364
310UAPP_TEST_MAIN(PointerBarrierTest)365UAPP_TEST_MAIN(PointerBarrierTest)
311366
=== modified file 'shell/Shell.qml'
--- shell/Shell.qml 2012-04-03 09:17:21 +0000
+++ shell/Shell.qml 2012-04-03 09:17:21 +0000
@@ -282,6 +282,7 @@
282 id: leftBarrier282 id: leftBarrier
283 triggerDirection: Utils.isLeftToRight() ? PointerBarrier.TriggerFromRight : PointerBarrier.TriggerFromLeft283 triggerDirection: Utils.isLeftToRight() ? PointerBarrier.TriggerFromRight : PointerBarrier.TriggerFromLeft
284 triggerZoneEnabled: enableTrigger && !launcherLoader.visibilityController.shown284 triggerZoneEnabled: enableTrigger && !launcherLoader.visibilityController.shown
285 triggerOnly: enableTrigger && !enableSticky
285 p1: Qt.point(x, declarativeView.screen.geometry.y)286 p1: Qt.point(x, declarativeView.screen.geometry.y)
286 p2: Qt.point(x, declarativeView.screen.geometry.y + declarativeView.screen.geometry.height)287 p2: Qt.point(x, declarativeView.screen.geometry.y + declarativeView.screen.geometry.height)
287 triggerZoneP1: Qt.point(x, declarativeView.globalPosition.y)288 triggerZoneP1: Qt.point(x, declarativeView.globalPosition.y)

Subscribers

People subscribed via source and target branches