Merge lp:~unity-team/unity/edge-barrier-autohide-fix into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Brandon Schaefer
Approved revision: no longer in the source branch.
Merged at revision: 3140
Proposed branch: lp:~unity-team/unity/edge-barrier-autohide-fix
Merge into: lp:unity
Diff against target: 776 lines (+320/-117)
9 files modified
launcher/EdgeBarrierController.cpp (+55/-48)
launcher/EdgeBarrierController.h (+10/-4)
launcher/EdgeBarrierControllerPrivate.h (+57/-0)
launcher/Launcher.cpp (+9/-7)
launcher/Launcher.h (+1/-1)
launcher/PointerBarrier.cpp (+1/-0)
launcher/PointerBarrier.h (+1/-0)
tests/test_edge_barrier_controller.cpp (+114/-41)
tests/test_launcher.cpp (+72/-16)
To merge this branch: bzr merge lp:~unity-team/unity/edge-barrier-autohide-fix
Reviewer Review Type Date Requested Status
Brandon Schaefer (community) Approve
PS Jenkins bot (community) continuous-integration Needs Fixing
Review via email: mp+147252@code.launchpad.net

This proposal supersedes a proposal from 2013-02-06.

Commit message

EdgeBarrierController: add multiple types of subscriber results, fix edges on autohide

Now when sticky keys are disabled, and the launcher is set to autohide, the mouse will hit both sides of the screen (instead of just the left side of the barrier); at that point we'll release the events coming from the launcher-less side of the monitor, but we'll use them to temporary keep the barrier "broken".

Description of the change

=== Problem ===
When sticky keys are set to off only the left side of the barrier blocks the mouse. This means when moving the mouse from the LEFT screen to the RIGHT screen it will skip the barrier.

=== Fix ===
Just use direction::BOTH for both cases.
So we'll release the events coming from the launcher-less side of the monitor, but we'll use them to temporary keep the barrier "broken".

Initially based on lp:~brandontschaefer/unity/lp.1064945-fix

=== Test ===
Added new unit tests, updated old ones.

To post a comment you must log in.
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Awesome, looks good, and works well :).

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Brandon Schaefer (brandontschaefer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'launcher/EdgeBarrierController.cpp'
--- launcher/EdgeBarrierController.cpp 2012-12-11 23:38:30 +0000
+++ launcher/EdgeBarrierController.cpp 2013-02-08 01:02:23 +0000
@@ -19,6 +19,7 @@
19 */19 */
2020
21#include "EdgeBarrierController.h"21#include "EdgeBarrierController.h"
22#include "EdgeBarrierControllerPrivate.h"
22#include "Decaymulator.h"23#include "Decaymulator.h"
23#include "unity-shared/UScreen.h"24#include "unity-shared/UScreen.h"
24#include "UnityCore/GLibSource.h"25#include "UnityCore/GLibSource.h"
@@ -26,23 +27,6 @@
26namespace unity {27namespace unity {
27namespace ui {28namespace ui {
2829
29struct EdgeBarrierController::Impl
30{
31 Impl(EdgeBarrierController *parent);
32
33 void ResizeBarrierList(std::vector<nux::Geometry> const& layout);
34 void SetupBarriers(std::vector<nux::Geometry> const& layout);
35
36 void OnPointerBarrierEvent(PointerBarrierWrapper* owner, BarrierEvent::Ptr event);
37 void BarrierRelease(PointerBarrierWrapper* owner, int event);
38
39 std::vector<PointerBarrierWrapper::Ptr> barriers_;
40 std::vector<EdgeBarrierSubscriber*> subscribers_;
41 Decaymulator decaymulator_;
42 glib::Source::UniquePtr release_timeout_;
43 float edge_overcome_pressure_;
44 EdgeBarrierController* parent_;
45};
4630
47EdgeBarrierController::Impl::Impl(EdgeBarrierController *parent)31EdgeBarrierController::Impl::Impl(EdgeBarrierController *parent)
48 : edge_overcome_pressure_(0)32 : edge_overcome_pressure_(0)
@@ -106,7 +90,7 @@
10690
107 barrier->DestroyBarrier();91 barrier->DestroyBarrier();
10892
109 if (!edge_resist && (subscribers_[i] == nullptr || parent_->options()->hide_mode() == launcher::LauncherHideMode::LAUNCHER_HIDE_NEVER))93 if (!edge_resist && parent_->options()->hide_mode() == launcher::LauncherHideMode::LAUNCHER_HIDE_NEVER)
110 continue;94 continue;
11195
112 barrier->x1 = monitor.x;96 barrier->x1 = monitor.x;
@@ -118,11 +102,6 @@
118 barrier->threshold = parent_->options()->edge_stop_velocity();102 barrier->threshold = parent_->options()->edge_stop_velocity();
119 barrier->max_velocity_multiplier = parent_->options()->edge_responsiveness();103 barrier->max_velocity_multiplier = parent_->options()->edge_responsiveness();
120104
121 if (edge_resist)
122 barrier->direction = BarrierDirection::BOTH;
123 else
124 barrier->direction = BarrierDirection::LEFT;
125
126 barrier->ConstructBarrier();105 barrier->ConstructBarrier();
127 }106 }
128107
@@ -133,7 +112,22 @@
133 edge_overcome_pressure_ = parent_->options()->edge_overcome_pressure() * overcome_responsiveness_mult;112 edge_overcome_pressure_ = parent_->options()->edge_overcome_pressure() * overcome_responsiveness_mult;
134}113}
135114
136void EdgeBarrierController::Impl::OnPointerBarrierEvent(PointerBarrierWrapper* owner, BarrierEvent::Ptr event)115void EdgeBarrierController::Impl::BarrierReset()
116{
117 decaymulator_.value = 0;
118}
119
120void EdgeBarrierController::Impl::BarrierPush(PointerBarrierWrapper* owner, BarrierEvent::Ptr const& event)
121{
122 decaymulator_.value = decaymulator_.value + event->velocity;
123
124 if (decaymulator_.value > edge_overcome_pressure_)
125 {
126 BarrierRelease(owner, event->event_id);
127 }
128}
129
130void EdgeBarrierController::Impl::OnPointerBarrierEvent(PointerBarrierWrapper* owner, BarrierEvent::Ptr const& event)
137{131{
138 if (owner->released)132 if (owner->released)
139 {133 {
@@ -142,28 +136,41 @@
142 }136 }
143137
144 unsigned int monitor = owner->index;138 unsigned int monitor = owner->index;
145 bool process = true;139 auto result = EdgeBarrierSubscriber::Result::IGNORED;
146140
147 if (monitor < subscribers_.size())141 if (monitor < subscribers_.size())
148 {142 {
149 auto subscriber = subscribers_[monitor];143 auto subscriber = subscribers_[monitor];
150144
151 if (subscriber && subscriber->HandleBarrierEvent(owner, event))145 if (subscriber)
152 process = false;146 result = subscriber->HandleBarrierEvent(owner, event);
153 }147 }
154148
155 if (process && owner->x1 > 0)149 switch (result)
156 {150 {
157 decaymulator_.value = decaymulator_.value + event->velocity;151 case EdgeBarrierSubscriber::Result::HANDLED:
158152 BarrierReset();
159 if (decaymulator_.value > edge_overcome_pressure_ || (!parent_->sticky_edges() && !subscribers_[monitor]))153 break;
160 {154
155 case EdgeBarrierSubscriber::Result::ALREADY_HANDLED:
156 BarrierPush(owner, event);
157 break;
158
159 case EdgeBarrierSubscriber::Result::IGNORED:
160 if (parent_->sticky_edges())
161 {
162 BarrierPush(owner, event);
163 }
164 else
165 {
166 owner->release_once = true;
167 BarrierRelease(owner, event->event_id);
168 }
169 break;
170
171 case EdgeBarrierSubscriber::Result::NEEDS_RELEASE:
161 BarrierRelease(owner, event->event_id);172 BarrierRelease(owner, event->event_id);
162 }173 break;
163 }
164 else
165 {
166 decaymulator_.value = 0;
167 }174 }
168}175}
169176
@@ -171,13 +178,18 @@
171{178{
172 owner->ReleaseBarrier(event);179 owner->ReleaseBarrier(event);
173 owner->released = true;180 owner->released = true;
174 decaymulator_.value = 0;181 BarrierReset();
175182
176 unsigned duration = parent_->options()->edge_passed_disabled_ms;183 if (!owner->release_once() ||
177 release_timeout_.reset(new glib::Timeout(duration, [owner] {184 (owner->release_once() && (!release_timeout_ || !release_timeout_->IsRunning())))
178 owner->released = false;185 {
179 return false;186 unsigned duration = parent_->options()->edge_passed_disabled_ms;
180 }));187 release_timeout_.reset(new glib::Timeout(duration, [owner] {
188 owner->released = false;
189 owner->release_once = false;
190 return false;
191 }));
192 }
181}193}
182194
183EdgeBarrierController::EdgeBarrierController()195EdgeBarrierController::EdgeBarrierController()
@@ -217,10 +229,5 @@
217 return pimpl->subscribers_[monitor];229 return pimpl->subscribers_[monitor];
218}230}
219231
220void EdgeBarrierController::ProcessBarrierEvent(PointerBarrierWrapper* owner, BarrierEvent::Ptr event)
221{
222 pimpl->OnPointerBarrierEvent(owner, event);
223}
224
225}232}
226}233}
227234
=== modified file 'launcher/EdgeBarrierController.h'
--- launcher/EdgeBarrierController.h 2012-11-23 02:11:30 +0000
+++ launcher/EdgeBarrierController.h 2013-02-08 01:02:23 +0000
@@ -28,7 +28,15 @@
2828
29struct EdgeBarrierSubscriber29struct EdgeBarrierSubscriber
30{30{
31 virtual bool HandleBarrierEvent(PointerBarrierWrapper* owner, BarrierEvent::Ptr event) = 0;31 enum class Result
32 {
33 IGNORED,
34 HANDLED,
35 ALREADY_HANDLED,
36 NEEDS_RELEASE
37 };
38
39 virtual Result HandleBarrierEvent(PointerBarrierWrapper* owner, BarrierEvent::Ptr event) = 0;
32};40};
3341
34class EdgeBarrierController : public sigc::trackable42class EdgeBarrierController : public sigc::trackable
@@ -44,12 +52,10 @@
44 void Unsubscribe(EdgeBarrierSubscriber* subscriber, unsigned int monitor);52 void Unsubscribe(EdgeBarrierSubscriber* subscriber, unsigned int monitor);
45 EdgeBarrierSubscriber* GetSubscriber(unsigned int monitor);53 EdgeBarrierSubscriber* GetSubscriber(unsigned int monitor);
4654
47protected:
48 void ProcessBarrierEvent(PointerBarrierWrapper* owner, BarrierEvent::Ptr event);
49
50private:55private:
51 struct Impl;56 struct Impl;
52 std::unique_ptr<Impl> pimpl;57 std::unique_ptr<Impl> pimpl;
58 friend class TestEdgeBarrierController;
53};59};
5460
55}61}
5662
=== added file 'launcher/EdgeBarrierControllerPrivate.h'
--- launcher/EdgeBarrierControllerPrivate.h 1970-01-01 00:00:00 +0000
+++ launcher/EdgeBarrierControllerPrivate.h 2013-02-08 01:02:23 +0000
@@ -0,0 +1,57 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2012-2013 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Jason Smith <jason.smith@canonical.com>
18 * Marco Trevisan <marco.trevisan@canonical.com>
19 */
20
21#ifndef EDGE_BARRIER_CONTROLLER_IMPL_PRIVATE
22#define EDGE_BARRIER_CONTROLLER_IMPL_PRIVATE
23
24#include "Decaymulator.h"
25#include "UnityCore/GLibSource.h"
26
27namespace unity
28{
29namespace ui
30{
31
32// NOTE: This private header is not part of the public interface
33struct EdgeBarrierController::Impl
34{
35 Impl(EdgeBarrierController *parent);
36
37 void ResizeBarrierList(std::vector<nux::Geometry> const& layout);
38 void SetupBarriers(std::vector<nux::Geometry> const& layout);
39
40 void OnPointerBarrierEvent(PointerBarrierWrapper* owner, BarrierEvent::Ptr const& event);
41 void BarrierPush(PointerBarrierWrapper* owner, BarrierEvent::Ptr const& event);
42 void BarrierRelease(PointerBarrierWrapper* owner, int event);
43 void BarrierReset();
44
45 std::vector<PointerBarrierWrapper::Ptr> barriers_;
46 std::vector<EdgeBarrierSubscriber*> subscribers_;
47 Decaymulator decaymulator_;
48 glib::Source::UniquePtr release_timeout_;
49 float edge_overcome_pressure_;
50 EdgeBarrierController* parent_;
51};
52
53} //namespace ui
54} //namespace unity
55
56
57#endif // EDGE_BARRIER_CONTROLLER_IMPL_PRIVATE
058
=== modified file 'launcher/Launcher.cpp'
--- launcher/Launcher.cpp 2013-02-01 22:53:42 +0000
+++ launcher/Launcher.cpp 2013-02-08 01:02:23 +0000
@@ -2252,19 +2252,21 @@
22522252
2253#ifdef USE_X112253#ifdef USE_X11
22542254
2255bool Launcher::HandleBarrierEvent(ui::PointerBarrierWrapper* owner, ui::BarrierEvent::Ptr event)2255ui::EdgeBarrierSubscriber::Result Launcher::HandleBarrierEvent(ui::PointerBarrierWrapper* owner, ui::BarrierEvent::Ptr event)
2256{2256{
2257 if (_hide_machine.GetQuirk(LauncherHideMachine::EXTERNAL_DND_ACTIVE))2257 if (_hide_machine.GetQuirk(LauncherHideMachine::EXTERNAL_DND_ACTIVE))
2258 {2258 {
2259 owner->ReleaseBarrier(event->event_id);2259 return ui::EdgeBarrierSubscriber::Result::NEEDS_RELEASE;
2260 return true;
2261 }2260 }
22622261
2263 nux::Geometry const& abs_geo = GetAbsoluteGeometry();2262 nux::Geometry const& abs_geo = GetAbsoluteGeometry();
22642263
2265 bool apply_to_reveal = false;2264 bool apply_to_reveal = false;
2266 if (_hidden && event->x >= abs_geo.x && event->x <= abs_geo.x + abs_geo.width)2265 if (event->x >= abs_geo.x && event->x <= abs_geo.x + abs_geo.width)
2267 {2266 {
2267 if (!_hidden)
2268 return ui::EdgeBarrierSubscriber::Result::ALREADY_HANDLED;
2269
2268 if (options()->reveal_trigger == RevealTrigger::EDGE)2270 if (options()->reveal_trigger == RevealTrigger::EDGE)
2269 {2271 {
2270 if (event->y >= abs_geo.y)2272 if (event->y >= abs_geo.y)
@@ -2288,15 +2290,15 @@
2288 &root_y_return, &win_x_return, &win_y_return, &mask_return))2290 &root_y_return, &win_x_return, &win_y_return, &mask_return))
2289 {2291 {
2290 if (mask_return & (Button1Mask | Button3Mask))2292 if (mask_return & (Button1Mask | Button3Mask))
2291 apply_to_reveal = false;2293 return ui::EdgeBarrierSubscriber::Result::NEEDS_RELEASE;
2292 }2294 }
2293 }2295 }
22942296
2295 if (!apply_to_reveal)2297 if (!apply_to_reveal)
2296 return false;2298 return ui::EdgeBarrierSubscriber::Result::IGNORED;
22972299
2298 _hide_machine.AddRevealPressure(event->velocity);2300 _hide_machine.AddRevealPressure(event->velocity);
2299 return true;2301 return ui::EdgeBarrierSubscriber::Result::HANDLED;
2300}2302}
23012303
2302#endif2304#endif
23032305
=== modified file 'launcher/Launcher.h'
--- launcher/Launcher.h 2013-02-01 22:53:42 +0000
+++ launcher/Launcher.h 2013-02-08 01:02:23 +0000
@@ -210,7 +210,7 @@
210#endif210#endif
211211
212#ifdef USE_X11212#ifdef USE_X11
213 bool HandleBarrierEvent(ui::PointerBarrierWrapper* owner, ui::BarrierEvent::Ptr event);213 ui::EdgeBarrierSubscriber::Result HandleBarrierEvent(ui::PointerBarrierWrapper* owner, ui::BarrierEvent::Ptr event);
214#endif214#endif
215215
216 void OnPluginStateChanged();216 void OnPluginStateChanged();
217217
=== modified file 'launcher/PointerBarrier.cpp'
--- launcher/PointerBarrier.cpp 2012-07-19 01:22:13 +0000
+++ launcher/PointerBarrier.cpp 2013-02-08 01:02:23 +0000
@@ -38,6 +38,7 @@
38PointerBarrierWrapper::PointerBarrierWrapper()38PointerBarrierWrapper::PointerBarrierWrapper()
39 : active(false)39 : active(false)
40 , released(false)40 , released(false)
41 , release_once(false)
41 , smoothing(75)42 , smoothing(75)
42 , max_velocity_multiplier(1.0f)43 , max_velocity_multiplier(1.0f)
43 , direction(BOTH)44 , direction(BOTH)
4445
=== modified file 'launcher/PointerBarrier.h'
--- launcher/PointerBarrier.h 2012-07-19 01:22:13 +0000
+++ launcher/PointerBarrier.h 2013-02-08 01:02:23 +0000
@@ -70,6 +70,7 @@
7070
71 nux::Property<bool> active;71 nux::Property<bool> active;
72 nux::Property<bool> released;72 nux::Property<bool> released;
73 nux::Property<bool> release_once;
7374
74 nux::Property<int> smoothing;75 nux::Property<int> smoothing;
7576
7677
=== modified file 'tests/test_edge_barrier_controller.cpp'
--- tests/test_edge_barrier_controller.cpp 2012-09-13 10:56:42 +0000
+++ tests/test_edge_barrier_controller.cpp 2013-02-08 01:02:23 +0000
@@ -23,6 +23,7 @@
23#include "test_uscreen_mock.h"23#include "test_uscreen_mock.h"
2424
25#include "EdgeBarrierController.h"25#include "EdgeBarrierController.h"
26#include "EdgeBarrierControllerPrivate.h"
2627
27using namespace unity;28using namespace unity;
28using namespace unity::ui;29using namespace unity::ui;
@@ -46,35 +47,25 @@
46 MOCK_METHOD1(ReleaseBarrier, void(int));47 MOCK_METHOD1(ReleaseBarrier, void(int));
47};48};
4849
49class MockEdgeBarrierController : public EdgeBarrierController
50{
51public:
52 void ProcessBarrierEvent(PointerBarrierWrapper* owner, BarrierEvent::Ptr event)
53 {
54 EdgeBarrierController::ProcessBarrierEvent(owner, event);
55 }
56
57 EdgeBarrierSubscriber* GetSubscriber(unsigned int monitor)
58 {
59 return EdgeBarrierController::GetSubscriber(monitor);
60 }
61};
62
63class TestBarrierSubscriber : public EdgeBarrierSubscriber50class TestBarrierSubscriber : public EdgeBarrierSubscriber
64{51{
65public:52public:
66 TestBarrierSubscriber(bool handles = false)53 TestBarrierSubscriber(EdgeBarrierSubscriber::Result result = EdgeBarrierSubscriber::Result::IGNORED)
67 : handles_(handles)54 : handle_result_(result)
68 {}55 {}
6956
70 bool HandleBarrierEvent(PointerBarrierWrapper* owner, BarrierEvent::Ptr event)57 EdgeBarrierSubscriber::Result HandleBarrierEvent(PointerBarrierWrapper* owner, BarrierEvent::Ptr event)
71 {58 {
72 return handles_;59 return handle_result_;
73 }60 }
7461
75 bool handles_;62 EdgeBarrierSubscriber::Result handle_result_;
76};63};
7764
65} // namespace
66
67namespace unity {
68namespace ui {
78class TestEdgeBarrierController : public Test69class TestEdgeBarrierController : public Test
79{70{
80public:71public:
@@ -93,16 +84,32 @@
93 }84 }
94 }85 }
9586
87 void ProcessBarrierEvent(PointerBarrierWrapper* owner, BarrierEvent::Ptr event)
88 {
89 GetPrivateImpl()->OnPointerBarrierEvent(owner, event);
90 }
91
92 EdgeBarrierController::Impl* GetPrivateImpl() const
93 {
94 return bc.pimpl.get();
95 }
96
96 BarrierEvent::Ptr MakeBarrierEvent(int id, bool breaker)97 BarrierEvent::Ptr MakeBarrierEvent(int id, bool breaker)
97 {98 {
98 int velocity = breaker ? std::numeric_limits<int>::max() : bc.options()->edge_overcome_pressure() - 1;99 int velocity = breaker ? std::numeric_limits<int>::max() : bc.options()->edge_overcome_pressure() - 1;
99 return std::make_shared<BarrierEvent>(0, 1, velocity, id);100 return std::make_shared<BarrierEvent>(0, 1, velocity, id);
100 }101 }
101102
103
102 TestBarrierSubscriber subscribers_[max_num_monitors];104 TestBarrierSubscriber subscribers_[max_num_monitors];
103 MockUScreen uscreen;105 MockUScreen uscreen;
104 MockEdgeBarrierController bc;106 EdgeBarrierController bc;
105};107};
108} // namespace ui
109} // namespace unity
110
111namespace
112{
106113
107TEST_F(TestEdgeBarrierController, Construction)114TEST_F(TestEdgeBarrierController, Construction)
108{115{
@@ -129,7 +136,7 @@
129136
130TEST_F(TestEdgeBarrierController, SubscriberReplace)137TEST_F(TestEdgeBarrierController, SubscriberReplace)
131{138{
132 TestBarrierSubscriber handling_subscriber(true);139 TestBarrierSubscriber handling_subscriber(EdgeBarrierSubscriber::Result::HANDLED);
133 bc.Subscribe(&handling_subscriber, 0);140 bc.Subscribe(&handling_subscriber, 0);
134 EXPECT_EQ(bc.GetSubscriber(0), &handling_subscriber);141 EXPECT_EQ(bc.GetSubscriber(0), &handling_subscriber);
135}142}
@@ -138,28 +145,29 @@
138{145{
139 int monitor = 0;146 int monitor = 0;
140147
141 TestBarrierSubscriber handling_subscriber(true);148 TestBarrierSubscriber handling_subscriber(EdgeBarrierSubscriber::Result::HANDLED);
142 bc.Subscribe(&handling_subscriber, monitor);149 bc.Subscribe(&handling_subscriber, monitor);
143150
144 MockPointerBarrier owner(monitor);151 MockPointerBarrier owner(monitor);
145 auto breaking_barrier_event = MakeBarrierEvent(0, true);152 auto breaking_barrier_event = MakeBarrierEvent(0, true);
146153
147 EXPECT_CALL(owner, ReleaseBarrier(_)).Times(0);154 EXPECT_CALL(owner, ReleaseBarrier(_)).Times(0);
148 bc.ProcessBarrierEvent(&owner, breaking_barrier_event);155 ProcessBarrierEvent(&owner, breaking_barrier_event);
156 EXPECT_EQ(GetPrivateImpl()->decaymulator_.value(), 0);
149}157}
150158
151TEST_F(TestEdgeBarrierController, ProcessHandledEventOnReleasedBarrier)159TEST_F(TestEdgeBarrierController, ProcessHandledEventOnReleasedBarrier)
152{160{
153 int monitor = max_num_monitors-1;161 int monitor = max_num_monitors-1;
154162
155 TestBarrierSubscriber handling_subscriber(true);163 TestBarrierSubscriber handling_subscriber(EdgeBarrierSubscriber::Result::HANDLED);
156 bc.Subscribe(&handling_subscriber, monitor);164 bc.Subscribe(&handling_subscriber, monitor);
157165
158 MockPointerBarrier owner(monitor, true);166 MockPointerBarrier owner(monitor, true);
159 auto breaking_barrier_event = MakeBarrierEvent(5, true);167 auto breaking_barrier_event = MakeBarrierEvent(5, true);
160168
161 EXPECT_CALL(owner, ReleaseBarrier(5)).Times(1);169 EXPECT_CALL(owner, ReleaseBarrier(5)).Times(1);
162 bc.ProcessBarrierEvent(&owner, breaking_barrier_event);170 ProcessBarrierEvent(&owner, breaking_barrier_event);
163}171}
164172
165TEST_F(TestEdgeBarrierController, ProcessUnHandledEventBreakingBarrier)173TEST_F(TestEdgeBarrierController, ProcessUnHandledEventBreakingBarrier)
@@ -171,7 +179,7 @@
171 auto breaking_barrier_event = MakeBarrierEvent(breaking_id, true);179 auto breaking_barrier_event = MakeBarrierEvent(breaking_id, true);
172180
173 EXPECT_CALL(owner, ReleaseBarrier(breaking_id));181 EXPECT_CALL(owner, ReleaseBarrier(breaking_id));
174 bc.ProcessBarrierEvent(&owner, breaking_barrier_event);182 ProcessBarrierEvent(&owner, breaking_barrier_event);
175}183}
176184
177TEST_F(TestEdgeBarrierController, ProcessUnHandledEventBreakingBarrierOnMaxMonitor)185TEST_F(TestEdgeBarrierController, ProcessUnHandledEventBreakingBarrierOnMaxMonitor)
@@ -181,11 +189,8 @@
181 MockPointerBarrier owner(monitor);189 MockPointerBarrier owner(monitor);
182 auto breaking_barrier_event = MakeBarrierEvent(0, true);190 auto breaking_barrier_event = MakeBarrierEvent(0, true);
183191
184 // This was leading to a crash, see bug #1020075
185 // you can reproduce this repeating this test multiple times using the
186 // --gtest_repeat=X command line
187 EXPECT_CALL(owner, ReleaseBarrier(_));192 EXPECT_CALL(owner, ReleaseBarrier(_));
188 bc.ProcessBarrierEvent(&owner, breaking_barrier_event);193 ProcessBarrierEvent(&owner, breaking_barrier_event);
189}194}
190195
191TEST_F(TestEdgeBarrierController, ProcessUnHandledEventNotBreakingBarrier)196TEST_F(TestEdgeBarrierController, ProcessUnHandledEventNotBreakingBarrier)
@@ -197,7 +202,7 @@
197 auto not_breaking_barrier_event = MakeBarrierEvent(not_breaking_id, false);202 auto not_breaking_barrier_event = MakeBarrierEvent(not_breaking_id, false);
198203
199 EXPECT_CALL(owner, ReleaseBarrier(not_breaking_id)).Times(0);204 EXPECT_CALL(owner, ReleaseBarrier(not_breaking_id)).Times(0);
200 bc.ProcessBarrierEvent(&owner, not_breaking_barrier_event);205 ProcessBarrierEvent(&owner, not_breaking_barrier_event);
201}206}
202207
203TEST_F(TestEdgeBarrierController, ProcessUnHandledEventOnReleasedBarrier)208TEST_F(TestEdgeBarrierController, ProcessUnHandledEventOnReleasedBarrier)
@@ -209,7 +214,69 @@
209 auto not_breaking_barrier_event = MakeBarrierEvent(not_breaking_id, false);214 auto not_breaking_barrier_event = MakeBarrierEvent(not_breaking_id, false);
210215
211 EXPECT_CALL(owner, ReleaseBarrier(not_breaking_id));216 EXPECT_CALL(owner, ReleaseBarrier(not_breaking_id));
212 bc.ProcessBarrierEvent(&owner, not_breaking_barrier_event);217 ProcessBarrierEvent(&owner, not_breaking_barrier_event);
218}
219
220TEST_F(TestEdgeBarrierController, ProcessAlreadyHandledEvent)
221{
222 int monitor = g_random_int_range(0, max_num_monitors);
223
224 MockPointerBarrier owner(monitor);
225 subscribers_[monitor].handle_result_ = EdgeBarrierSubscriber::Result::ALREADY_HANDLED;
226
227 auto event = MakeBarrierEvent(g_random_int(), false);
228
229 EXPECT_CALL(owner, ReleaseBarrier(_)).Times(0);
230 ProcessBarrierEvent(&owner, event);
231 EXPECT_EQ(GetPrivateImpl()->decaymulator_.value(), event->velocity);
232}
233
234TEST_F(TestEdgeBarrierController, ProcessIgnoredEventWithStickyEdges)
235{
236 int monitor = g_random_int_range(0, max_num_monitors);
237
238 bc.sticky_edges = true;
239 MockPointerBarrier owner(monitor);
240 subscribers_[monitor].handle_result_ = EdgeBarrierSubscriber::Result::IGNORED;
241
242 auto event = MakeBarrierEvent(g_random_int(), false);
243
244 EXPECT_CALL(owner, ReleaseBarrier(_)).Times(0);
245 ProcessBarrierEvent(&owner, event);
246 EXPECT_FALSE(owner.released());
247 EXPECT_FALSE(owner.release_once());
248 EXPECT_EQ(GetPrivateImpl()->decaymulator_.value(), event->velocity);
249}
250
251TEST_F(TestEdgeBarrierController, ProcessIgnoredEventWithOutStickyEdges)
252{
253 int monitor = g_random_int_range(0, max_num_monitors);
254
255 bc.sticky_edges = false;
256 MockPointerBarrier owner(monitor);
257 subscribers_[monitor].handle_result_ = EdgeBarrierSubscriber::Result::IGNORED;
258
259 auto event = MakeBarrierEvent(g_random_int(), false);
260
261 EXPECT_CALL(owner, ReleaseBarrier(event->event_id));
262 ProcessBarrierEvent(&owner, event);
263 EXPECT_TRUE(owner.released());
264 EXPECT_TRUE(owner.release_once());
265 EXPECT_EQ(GetPrivateImpl()->decaymulator_.value(), 0);
266}
267
268TEST_F(TestEdgeBarrierController, ProcessNeedsReleaseEvent)
269{
270 int monitor = g_random_int_range(0, max_num_monitors);
271
272 MockPointerBarrier owner(monitor);
273 subscribers_[monitor].handle_result_ = EdgeBarrierSubscriber::Result::NEEDS_RELEASE;
274
275 auto event = MakeBarrierEvent(g_random_int(), false);
276
277 EXPECT_CALL(owner, ReleaseBarrier(event->event_id));
278 ProcessBarrierEvent(&owner, event);
279 EXPECT_EQ(GetPrivateImpl()->decaymulator_.value(), 0);
213}280}
214281
215TEST_F(TestEdgeBarrierController, BreakingEdgeTemporaryReleasesBarrier)282TEST_F(TestEdgeBarrierController, BreakingEdgeTemporaryReleasesBarrier)
@@ -217,7 +284,7 @@
217 MockPointerBarrier owner;284 MockPointerBarrier owner;
218285
219 EXPECT_CALL(owner, ReleaseBarrier(1));286 EXPECT_CALL(owner, ReleaseBarrier(1));
220 bc.ProcessBarrierEvent(&owner, MakeBarrierEvent(1, true));287 ProcessBarrierEvent(&owner, MakeBarrierEvent(1, true));
221 ASSERT_TRUE(owner.released());288 ASSERT_TRUE(owner.released());
222289
223 Utils::WaitForTimeoutMSec(bc.options()->edge_passed_disabled_ms);290 Utils::WaitForTimeoutMSec(bc.options()->edge_passed_disabled_ms);
@@ -228,30 +295,30 @@
228{295{
229 MockPointerBarrier owner;296 MockPointerBarrier owner;
230 int monitor = 0;297 int monitor = 0;
231 subscribers_[monitor].handles_ = false;298 subscribers_[monitor].handle_result_ = EdgeBarrierSubscriber::Result::IGNORED;
232299
233 EXPECT_CALL(owner, ReleaseBarrier(5));300 EXPECT_CALL(owner, ReleaseBarrier(5));
234 bc.ProcessBarrierEvent(&owner, MakeBarrierEvent(5, true));301 ProcessBarrierEvent(&owner, MakeBarrierEvent(5, true));
235 ASSERT_TRUE(owner.released());302 ASSERT_TRUE(owner.released());
236303
237 subscribers_[monitor].handles_ = false;304 subscribers_[monitor].handle_result_ = EdgeBarrierSubscriber::Result::IGNORED;
238 EXPECT_CALL(owner, ReleaseBarrier(6));305 EXPECT_CALL(owner, ReleaseBarrier(6));
239 bc.ProcessBarrierEvent(&owner, MakeBarrierEvent(6, false));306 ProcessBarrierEvent(&owner, MakeBarrierEvent(6, false));
240}307}
241308
242TEST_F(TestEdgeBarrierController, BreakingEdgeTemporaryReleasesBarrierForHandledEvents)309TEST_F(TestEdgeBarrierController, BreakingEdgeTemporaryReleasesBarrierForHandledEvents)
243{310{
244 MockPointerBarrier owner;311 MockPointerBarrier owner;
245 int monitor = 0;312 int monitor = 0;
246 subscribers_[monitor].handles_ = false;313 subscribers_[monitor].handle_result_ = EdgeBarrierSubscriber::Result::IGNORED;
247314
248 EXPECT_CALL(owner, ReleaseBarrier(5));315 EXPECT_CALL(owner, ReleaseBarrier(5));
249 bc.ProcessBarrierEvent(&owner, MakeBarrierEvent(5, true));316 ProcessBarrierEvent(&owner, MakeBarrierEvent(5, true));
250 ASSERT_TRUE(owner.released());317 ASSERT_TRUE(owner.released());
251318
252 subscribers_[monitor].handles_ = true;319 subscribers_[monitor].handle_result_ = EdgeBarrierSubscriber::Result::HANDLED;
253 EXPECT_CALL(owner, ReleaseBarrier(6)).Times(1);320 EXPECT_CALL(owner, ReleaseBarrier(6)).Times(1);
254 bc.ProcessBarrierEvent(&owner, MakeBarrierEvent(6, true));321 ProcessBarrierEvent(&owner, MakeBarrierEvent(6, true));
255}322}
256323
257TEST_F(TestEdgeBarrierController, StickyEdgePropertyProxiesLauncherOption)324TEST_F(TestEdgeBarrierController, StickyEdgePropertyProxiesLauncherOption)
@@ -269,4 +336,10 @@
269 EXPECT_TRUE(bc.options()->edge_resist());336 EXPECT_TRUE(bc.options()->edge_resist());
270}337}
271338
339TEST_F(TestEdgeBarrierController, TestTheDirectionIsAlawysSetToBothSides)
340{
341 for (auto barrier : GetPrivateImpl()->barriers_)
342 ASSERT_EQ(barrier->direction, BarrierDirection::BOTH);
343}
344
272}345}
273346
=== modified file 'tests/test_launcher.cpp'
--- tests/test_launcher.cpp 2013-02-01 22:53:42 +0000
+++ tests/test_launcher.cpp 2013-02-08 01:02:23 +0000
@@ -54,11 +54,6 @@
54 MOCK_METHOD1(Stick, void(bool));54 MOCK_METHOD1(Stick, void(bool));
55};55};
5656
57struct MockPointerBarrierWrapper : ui::PointerBarrierWrapper
58{
59 MOCK_METHOD1(ReleaseBarrier, void(int event_id));
60};
61
62}57}
6358
64class TestLauncher : public Test59class TestLauncher : public Test
@@ -96,10 +91,12 @@
96 using Launcher::ProcessDndLeave;91 using Launcher::ProcessDndLeave;
97 using Launcher::ProcessDndMove;92 using Launcher::ProcessDndMove;
98 using Launcher::ProcessDndDrop;93 using Launcher::ProcessDndDrop;
99 using Launcher::_drag_icon_position;
100
101 using Launcher::IconStartingBlinkValue;94 using Launcher::IconStartingBlinkValue;
102 using Launcher::IconStartingPulseValue;95 using Launcher::IconStartingPulseValue;
96 using Launcher::HandleBarrierEvent;
97 using Launcher::SetHidden;
98 using Launcher::_drag_icon_position;
99
103100
104 void FakeProcessDndMove(int x, int y, std::list<std::string> uris)101 void FakeProcessDndMove(int x, int y, std::list<std::string> uris)
105 {102 {
@@ -119,11 +116,6 @@
119116
120 _dnd_hovered_icon = MouseIconIntersection(x, y);117 _dnd_hovered_icon = MouseIconIntersection(x, y);
121 }118 }
122
123 bool HandleBarrierEvent(ui::PointerBarrierWrapper* barrier, ui::BarrierEvent::Ptr event)
124 {
125 return Launcher::HandleBarrierEvent(barrier, event);
126 }
127 };119 };
128120
129 TestLauncher()121 TestLauncher()
@@ -454,15 +446,79 @@
454 EXPECT_FALSE(mouse_entered);446 EXPECT_FALSE(mouse_entered);
455}447}
456448
457TEST_F(TestLauncher, EdgeResistDuringDnd)449TEST_F(TestLauncher, EdgeReleasesDuringDnd)
458{450{
459 auto barrier = std::make_shared<MockPointerBarrierWrapper>();451 auto barrier = std::make_shared<ui::PointerBarrierWrapper>();
460 auto event = std::make_shared<ui::BarrierEvent>(0, 0, 0, 100);452 auto event = std::make_shared<ui::BarrierEvent>(0, 0, 0, 100);
461453
462 launcher_->DndStarted("");454 launcher_->DndStarted("");
463455
464 EXPECT_CALL(*barrier, ReleaseBarrier(100));456 EXPECT_EQ(launcher_->HandleBarrierEvent(barrier.get(), event),
465 EXPECT_TRUE(launcher_->HandleBarrierEvent(barrier.get(), event));457 ui::EdgeBarrierSubscriber::Result::NEEDS_RELEASE);
458}
459
460TEST_F(TestLauncher, EdgeBarriersIgnoreEvents)
461{
462 auto const& launcher_geo = launcher_->GetAbsoluteGeometry();
463 auto barrier = std::make_shared<ui::PointerBarrierWrapper>();
464 auto event = std::make_shared<ui::BarrierEvent>(0, 0, 0, 100);
465 launcher_->SetHidden(true);
466
467 event->x = launcher_geo.x-1;
468 event->y = launcher_geo.y;
469 EXPECT_EQ(launcher_->HandleBarrierEvent(barrier.get(), event),
470 ui::EdgeBarrierSubscriber::Result::IGNORED);
471
472 event->x = launcher_geo.x+launcher_geo.width+1;
473 event->y = launcher_geo.y;
474 EXPECT_EQ(launcher_->HandleBarrierEvent(barrier.get(), event),
475 ui::EdgeBarrierSubscriber::Result::IGNORED);
476
477 options_->reveal_trigger = RevealTrigger::EDGE;
478 event->x = launcher_geo.x+launcher_geo.width/2;
479 event->y = launcher_geo.y - 1;
480 EXPECT_EQ(launcher_->HandleBarrierEvent(barrier.get(), event),
481 ui::EdgeBarrierSubscriber::Result::IGNORED);
482
483 options_->reveal_trigger = RevealTrigger::CORNER;
484 event->x = launcher_geo.x+launcher_geo.width/2;
485 event->y = launcher_geo.y;
486 EXPECT_EQ(launcher_->HandleBarrierEvent(barrier.get(), event),
487 ui::EdgeBarrierSubscriber::Result::IGNORED);
488}
489
490TEST_F(TestLauncher, EdgeBarriersHandlesEvent)
491{
492 auto const& launcher_geo = launcher_->GetAbsoluteGeometry();
493 auto barrier = std::make_shared<ui::PointerBarrierWrapper>();
494 auto event = std::make_shared<ui::BarrierEvent>(0, 0, 0, 100);
495 launcher_->SetHidden(true);
496
497 options_->reveal_trigger = RevealTrigger::EDGE;
498
499 for (int x = launcher_geo.x; x < launcher_geo.x+launcher_geo.width; ++x)
500 {
501 for (int y = launcher_geo.y; y < launcher_geo.y+launcher_geo.height; ++y)
502 {
503 event->x = x;
504 event->y = y;
505 ASSERT_EQ(launcher_->HandleBarrierEvent(barrier.get(), event),
506 ui::EdgeBarrierSubscriber::Result::HANDLED);
507 }
508 }
509
510 options_->reveal_trigger = RevealTrigger::CORNER;
511
512 for (int x = launcher_geo.x; x < launcher_geo.x+launcher_geo.width; ++x)
513 {
514 for (int y = launcher_geo.y-10; y < launcher_geo.y; ++y)
515 {
516 event->x = x;
517 event->y = y;
518 ASSERT_EQ(launcher_->HandleBarrierEvent(barrier.get(), event),
519 ui::EdgeBarrierSubscriber::Result::HANDLED);
520 }
521 }
466}522}
467523
468TEST_F(TestLauncher, DndIsSpecialRequest)524TEST_F(TestLauncher, DndIsSpecialRequest)