Merge lp:~brandontschaefer/unity/move-pointer-barrier-to-xi-1.6.99.1 into lp:unity

Proposed by Brandon Schaefer
Status: Merged
Merged at revision: 3407
Proposed branch: lp:~brandontschaefer/unity/move-pointer-barrier-to-xi-1.6.99.1
Merge into: lp:unity
Diff against target: 703 lines (+261/-152)
8 files modified
CMakeLists.txt (+2/-1)
debian/changelog (+4/-3)
debian/control (+1/-0)
launcher/EdgeBarrierController.cpp (+126/-3)
launcher/EdgeBarrierControllerPrivate.h (+9/-0)
launcher/PointerBarrier.cpp (+82/-94)
launcher/PointerBarrier.h (+7/-5)
tests/test_pointer_barrier.cpp (+30/-46)
To merge this branch: bzr merge lp:~brandontschaefer/unity/move-pointer-barrier-to-xi-1.6.99.1
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Andrea Azzarone (community) Approve
Review via email: mp+150175@code.launchpad.net

Commit message

Move unity to the new libxi changes, along with the new 1.14 xserver.

Description of the change

Some big changes. Updating pointer barrier logic new versions of xfixes and xi (1.6.99.1).

Had to move a bunch of things around, due to the fact that we didn't handle any kind of XI2 events before. Also re worked somethings so they only run once now...before we had a bunch of things being ran every time a barrier was being created that was not necessary.

So now the new logic, simplified:
Mouse hits barrier, XIBarrierEvent generated and sent off.
Nux receives XEvent and passes it back to EdgeBarrierController.cpp::HandleEventCB
In HandleEventCB we check to see of the opcode matches, if so pass it to HandleEvent
In HandleEvent we check if its a type XI_BarrierHit
If so, then find the barrier wrapper the event belongs to.
(XGetEventData works onces per event, so the logic we had before didn't work).
From here we pass it to PointerBarrier.cpp::HandleBarrierEvent,
Here we are pretty much back to where we were before the changed :).

To post a comment you must log in.
Revision history for this message
Andrea Azzarone (azzar1) :
review: Approve
Revision history for this message
Sebastien Bacher (seb128) wrote :

trying to build with the old libxfixes it fails on:

"/usr/include/X11/extensions/XInput2.h:173:22: error: conflicting declaration ‘typedef unsigned int BarrierEventID’
  typedef unsigned int BarrierEventID;

the requirement/build-depends on that one should probably be bumped as well

works fine otherwise ;-)

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:3175
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~brandontschaefer/unity/move-pointer-barrier-to-xi-1.6.99.1/+merge/150175/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/unity-ci/182/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/unity-saucy-amd64-ci/70/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/unity-saucy-armhf-ci/70/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/unity-saucy-i386-ci/70/console

Click here to trigger a rebuild:
http://s-jenkins:8080/job/unity-ci/182/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Timo Jyrinki (timo-jyrinki) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2013-06-26 14:29:55 +0000
+++ CMakeLists.txt 2013-07-03 16:16:23 +0000
@@ -10,7 +10,7 @@
10set (PROJECT_NAME "unity")10set (PROJECT_NAME "unity")
11set (UNITY_MAJOR 7)11set (UNITY_MAJOR 7)
12set (UNITY_MINOR 0)12set (UNITY_MINOR 0)
13set (UNITY_MICRO 1)13set (UNITY_MICRO 2)
14set (UNITY_VERSION "${UNITY_MAJOR}.${UNITY_MINOR}.${UNITY_MICRO}")14set (UNITY_VERSION "${UNITY_MAJOR}.${UNITY_MINOR}.${UNITY_MICRO}")
15set (UNITY_API_VERSION "6.0")15set (UNITY_API_VERSION "6.0")
16set (UNITY_COMPONENTS_VERSION "6")16set (UNITY_COMPONENTS_VERSION "6")
@@ -244,6 +244,7 @@
244 libgeis244 libgeis
245 x11245 x11
246 xfixes246 xfixes
247 xi>=1.6.99.1
247 xrender>=0.9248 xrender>=0.9
248 )249 )
249endif ()250endif ()
250251
=== modified file 'debian/changelog'
--- debian/changelog 2013-07-03 04:03:34 +0000
+++ debian/changelog 2013-07-03 16:16:23 +0000
@@ -401,9 +401,6 @@
401unity (7.0.0daily13.05.08ubuntu.unity.next-0ubuntu1) raring; urgency=low401unity (7.0.0daily13.05.08ubuntu.unity.next-0ubuntu1) raring; urgency=low
402402
403 * Automatic snapshot from revision 3317 (ubuntu-unity/next)403 * Automatic snapshot from revision 3317 (ubuntu-unity/next)
404
405 -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Wed, 08 May 2013 04:57:49 +0000
406
407unity (7.0.0daily13.05.01.1ubuntu.unity.next-0ubuntu1) raring; urgency=low404unity (7.0.0daily13.05.01.1ubuntu.unity.next-0ubuntu1) raring; urgency=low
408405
409 [ Sebastien Bacher ]406 [ Sebastien Bacher ]
@@ -942,6 +939,10 @@
942 [ Automatic PS uploader ]939 [ Automatic PS uploader ]
943 * Automatic snapshot from revision 3140940 * Automatic snapshot from revision 3140
944941
942 [ Brandon Schaefer ]
943 * Moved PointerBarrier logic to the new xserver 1.14 (libXi 1.6.99.1)
944 version.
945
945 -- Automatic PS uploader <ps-jenkins@lists.canonical.com> Fri, 08 Feb 2013 04:02:00 +0000946 -- Automatic PS uploader <ps-jenkins@lists.canonical.com> Fri, 08 Feb 2013 04:02:00 +0000
946947
947unity (6.12.0daily13.02.07-0ubuntu1) raring; urgency=low948unity (6.12.0daily13.02.07-0ubuntu1) raring; urgency=low
948949
=== modified file 'debian/control'
--- debian/control 2013-07-02 09:30:43 +0000
+++ debian/control 2013-07-03 16:16:23 +0000
@@ -44,6 +44,7 @@
44 libunity-scopes-json-def-desktop,44 libunity-scopes-json-def-desktop,
45 libzeitgeist-dev (>= 0.3.18),45 libzeitgeist-dev (>= 0.3.18),
46 libxfixes-dev (>= 1:5.0-4ubuntu4),46 libxfixes-dev (>= 1:5.0-4ubuntu4),
47 libxi-dev (>= 1.6.99.1),
47 libxpathselect-dev (>=1.3),48 libxpathselect-dev (>=1.3),
48 libgtest-dev,49 libgtest-dev,
49 google-mock,50 google-mock,
5051
=== modified file 'launcher/EdgeBarrierController.cpp'
--- launcher/EdgeBarrierController.cpp 2013-04-02 01:57:03 +0000
+++ launcher/EdgeBarrierController.cpp 2013-07-03 16:16:23 +0000
@@ -21,6 +21,7 @@
21#include "EdgeBarrierController.h"21#include "EdgeBarrierController.h"
22#include "EdgeBarrierControllerPrivate.h"22#include "EdgeBarrierControllerPrivate.h"
23#include "Decaymulator.h"23#include "Decaymulator.h"
24#include <NuxCore/Logger.h>
24#include "unity-shared/UScreen.h"25#include "unity-shared/UScreen.h"
25#include "UnityCore/GLibSource.h"26#include "UnityCore/GLibSource.h"
2627
@@ -32,11 +33,50 @@
32namespace33namespace
33{34{
34 int const Y_BREAK_BUFFER = 20;35 int const Y_BREAK_BUFFER = 20;
35}36 int const MAJOR = 2;
3637 int const MINOR = 3;
38}
39
40DECLARE_LOGGER(logger, "unity.edge_barrier_controller");
41
42int GetXI2OpCode()
43{
44 Display *dpy = nux::GetGraphicsDisplay()->GetX11Display();
45
46 int opcode, event_base, error_base;
47 if (!XQueryExtension(dpy, "XFIXES",
48 &opcode,
49 &event_base,
50 &error_base))
51 {
52 LOG_ERROR(logger) << "Missing XFixes";
53 return -1;
54 }
55
56 if (!XQueryExtension (dpy, "XInputExtension",
57 &opcode,
58 &event_base,
59 &error_base))
60 {
61 LOG_ERROR(logger) << "Missing XInput";
62 return -1;
63 }
64
65 int maj = MAJOR;
66 int min = MINOR;
67
68 if (XIQueryVersion(dpy, &maj, &min) == BadRequest)
69 {
70 LOG_ERROR(logger) << "Need XInput version 2.3";
71 return -1;
72 }
73
74 return opcode;
75}
3776
38EdgeBarrierController::Impl::Impl(EdgeBarrierController *parent)77EdgeBarrierController::Impl::Impl(EdgeBarrierController *parent)
39 : edge_overcome_pressure_(0)78 : xi2_opcode_(-1)
79 , edge_overcome_pressure_(0)
40 , parent_(parent)80 , parent_(parent)
41{81{
42 UScreen *uscreen = UScreen::GetDefault();82 UScreen *uscreen = UScreen::GetDefault();
@@ -68,6 +108,13 @@
68 });108 });
69 SetupBarriers(UScreen::GetDefault()->GetMonitors());109 SetupBarriers(UScreen::GetDefault()->GetMonitors());
70 });110 });
111
112 xi2_opcode_ = GetXI2OpCode();
113}
114
115EdgeBarrierController::Impl::~Impl()
116{
117 nux::GetGraphicsDisplay()->RemoveEventFilter(this);
71}118}
72119
73void EdgeBarrierController::Impl::ResizeBarrierList(std::vector<nux::Geometry> const& layout)120void EdgeBarrierController::Impl::ResizeBarrierList(std::vector<nux::Geometry> const& layout)
@@ -86,6 +133,18 @@
86 }133 }
87}134}
88135
136void SetupXI2Events()
137{
138 Display *dpy = nux::GetGraphicsDisplay()->GetX11Display();
139
140 unsigned char mask_bits[XIMaskLen (XI_LASTEVENT)] = { 0 };
141 XIEventMask mask = { XIAllMasterDevices, sizeof (mask_bits), mask_bits };
142
143 XISetMask(mask.mask, XI_BarrierHit);
144 XISetMask(mask.mask, XI_BarrierLeave);
145 XISelectEvents (dpy, DefaultRootWindow(dpy), &mask, 1);
146}
147
89void EdgeBarrierController::Impl::SetupBarriers(std::vector<nux::Geometry> const& layout)148void EdgeBarrierController::Impl::SetupBarriers(std::vector<nux::Geometry> const& layout)
90{149{
91 bool edge_resist = parent_->sticky_edges();150 bool edge_resist = parent_->sticky_edges();
@@ -112,6 +171,9 @@
112 barrier->ConstructBarrier();171 barrier->ConstructBarrier();
113 }172 }
114173
174 SetupXI2Events();
175 AddEventFilter();
176
115 float decay_responsiveness_mult = ((parent_->options()->edge_responsiveness() - 1) * .3f) + 1;177 float decay_responsiveness_mult = ((parent_->options()->edge_responsiveness() - 1) * .3f) + 1;
116 decaymulator_.rate_of_decay = parent_->options()->edge_decay_rate() * decay_responsiveness_mult;178 decaymulator_.rate_of_decay = parent_->options()->edge_decay_rate() * decay_responsiveness_mult;
117179
@@ -119,6 +181,67 @@
119 edge_overcome_pressure_ = parent_->options()->edge_overcome_pressure() * overcome_responsiveness_mult;181 edge_overcome_pressure_ = parent_->options()->edge_overcome_pressure() * overcome_responsiveness_mult;
120}182}
121183
184void EdgeBarrierController::Impl::AddEventFilter()
185{
186 // Remove an old one, if it exists
187 nux::GetGraphicsDisplay()->RemoveEventFilter(this);
188
189 nux::GraphicsDisplay::EventFilterArg event_filter;
190 event_filter.filter = &HandleEventCB;
191 event_filter.data = this;
192
193 nux::GetGraphicsDisplay()->AddEventFilter(event_filter);
194}
195
196bool EdgeBarrierController::Impl::HandleEvent(XEvent xevent)
197{
198 Display *dpy = nux::GetGraphicsDisplay()->GetX11Display();
199 XGenericEventCookie *cookie = &xevent.xcookie;
200 bool ret = false;
201
202 switch (cookie->evtype)
203 {
204 case (XI_BarrierHit):
205 {
206 if (XGetEventData(dpy, cookie))
207 {
208 XIBarrierEvent* barrier_event = (XIBarrierEvent*)cookie->data;
209 PointerBarrierWrapper::Ptr wrapper = FindBarrierEventOwner(barrier_event);
210
211 if (wrapper)
212 ret = wrapper->HandleBarrierEvent(barrier_event);
213 }
214
215 XFreeEventData(dpy, cookie);
216 break;
217 }
218 default:
219 break;
220 }
221
222 return ret;
223}
224
225bool EdgeBarrierController::Impl::HandleEventCB(XEvent xevent, void* data)
226{
227 auto edge_barrier_controller = static_cast<EdgeBarrierController::Impl*>(data);
228 int const xi2_opcode = edge_barrier_controller->xi2_opcode_;
229
230 if (xevent.type != GenericEvent || xevent.xcookie.extension != xi2_opcode)
231 return false;
232
233 return edge_barrier_controller->HandleEvent(xevent);
234}
235
236PointerBarrierWrapper::Ptr EdgeBarrierController::Impl::FindBarrierEventOwner(XIBarrierEvent* barrier_event)
237{
238 for (auto barrier : barriers_)
239 if (barrier->OwnsBarrierEvent(barrier_event->barrier))
240 return barrier;
241
242 return nullptr;
243}
244
122void EdgeBarrierController::Impl::BarrierReset()245void EdgeBarrierController::Impl::BarrierReset()
123{246{
124 decaymulator_.value = 0;247 decaymulator_.value = 0;
125248
=== modified file 'launcher/EdgeBarrierControllerPrivate.h'
--- launcher/EdgeBarrierControllerPrivate.h 2013-02-13 19:21:49 +0000
+++ launcher/EdgeBarrierControllerPrivate.h 2013-07-03 16:16:23 +0000
@@ -33,6 +33,7 @@
33struct EdgeBarrierController::Impl33struct EdgeBarrierController::Impl
34{34{
35 Impl(EdgeBarrierController *parent);35 Impl(EdgeBarrierController *parent);
36 ~Impl();
3637
37 void ResizeBarrierList(std::vector<nux::Geometry> const& layout);38 void ResizeBarrierList(std::vector<nux::Geometry> const& layout);
38 void SetupBarriers(std::vector<nux::Geometry> const& layout);39 void SetupBarriers(std::vector<nux::Geometry> const& layout);
@@ -44,10 +45,18 @@
4445
45 bool EventIsInsideYBreakZone(BarrierEvent::Ptr const& event);46 bool EventIsInsideYBreakZone(BarrierEvent::Ptr const& event);
4647
48 void AddEventFilter();
49
50 PointerBarrierWrapper::Ptr FindBarrierEventOwner(XIBarrierEvent* barrier_event);
51
52 static bool HandleEventCB(XEvent event, void* data);
53 bool HandleEvent(XEvent event);
54
47 std::vector<PointerBarrierWrapper::Ptr> barriers_;55 std::vector<PointerBarrierWrapper::Ptr> barriers_;
48 std::vector<EdgeBarrierSubscriber*> subscribers_;56 std::vector<EdgeBarrierSubscriber*> subscribers_;
49 Decaymulator decaymulator_;57 Decaymulator decaymulator_;
50 glib::Source::UniquePtr release_timeout_;58 glib::Source::UniquePtr release_timeout_;
59 int xi2_opcode_;
51 float edge_overcome_pressure_;60 float edge_overcome_pressure_;
52 EdgeBarrierController* parent_;61 EdgeBarrierController* parent_;
53};62};
5463
=== modified file 'launcher/PointerBarrier.cpp'
--- launcher/PointerBarrier.cpp 2013-02-11 23:57:09 +0000
+++ launcher/PointerBarrier.cpp 2013-07-03 16:16:23 +0000
@@ -13,12 +13,14 @@
13*13*
14* You should have received a copy of the GNU General Public License14* 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/>.15* along with this program. If not, see <http://www.gnu.org/licenses/>.
16*
17* Authored by: Jason Smith <jason.smith@canonical.com>
18* Brandon Schaefer <brandon.schaefer@canonical.com>
19*
16*/20*/
1721
18#include <unistd.h>22#include <unistd.h>
19#include <stdlib.h>23#include <stdlib.h>
20#include <stdio.h>
21#include <X11/extensions/Xfixes.h>
2224
23#include "PointerBarrier.h"25#include "PointerBarrier.h"
2426
@@ -27,14 +29,6 @@
27namespace ui29namespace ui
28{30{
2931
30namespace local
31{
32namespace
33{
34 bool is_selected_for = false;
35}
36}
37
38PointerBarrierWrapper::PointerBarrierWrapper()32PointerBarrierWrapper::PointerBarrierWrapper()
39 : active(false)33 : active(false)
40 , released(false)34 , released(false)
@@ -42,10 +36,11 @@
42 , smoothing(75)36 , smoothing(75)
43 , max_velocity_multiplier(1.0f)37 , max_velocity_multiplier(1.0f)
44 , direction(BOTH)38 , direction(BOTH)
45 , event_base_(0)39 , xi2_opcode_(0)
46 , last_event_(0)40 , last_event_(0)
41 , current_device_(0)
47 , first_event_(false)42 , first_event_(false)
48 , barrier(0)43 , barrier_(0)
49 , smoothing_count_(0)44 , smoothing_count_(0)
50 , smoothing_accum_(0)45 , smoothing_accum_(0)
51{}46{}
@@ -62,34 +57,14 @@
6257
63 Display *dpy = nux::GetGraphicsDisplay()->GetX11Display();58 Display *dpy = nux::GetGraphicsDisplay()->GetX11Display();
6459
65 int error_base;60 barrier_ = XFixesCreatePointerBarrier(dpy,
66 XFixesQueryExtension(dpy, &event_base_, &error_base);61 DefaultRootWindow(dpy),
6762 x1, y1,
68 int maj,min;63 x2, y2,
69 XFixesQueryVersion(dpy, &maj, &min);64 static_cast<int>(direction),
7065 0, NULL);
71 barrier = XFixesCreatePointerBarrierVelocity(dpy,
72 DefaultRootWindow(dpy),
73 x1, y1,
74 x2, y2,
75 static_cast<int>(direction),
76 threshold,
77 0,
78 NULL);
79
80 if (!local::is_selected_for)
81 {
82 XFixesSelectBarrierInput(dpy, DefaultRootWindow(dpy), 0xdeadbeef);
83 local::is_selected_for = true;
84 }
8566
86 active = true;67 active = true;
87
88 nux::GraphicsDisplay::EventFilterArg event_filter;
89 event_filter.filter = &PointerBarrierWrapper::HandleEventWrapper;
90 event_filter.data = this;
91
92 nux::GetGraphicsDisplay()->AddEventFilter(event_filter);
93}68}
9469
95void PointerBarrierWrapper::DestroyBarrier()70void PointerBarrierWrapper::DestroyBarrier()
@@ -100,14 +75,13 @@
100 active = false;75 active = false;
10176
102 Display *dpy = nux::GetGraphicsDisplay()->GetX11Display();77 Display *dpy = nux::GetGraphicsDisplay()->GetX11Display();
103 XFixesDestroyPointerBarrier(dpy, barrier);78 XFixesDestroyPointerBarrier(dpy, barrier_);
104
105 nux::GetGraphicsDisplay()->RemoveEventFilter(this);
106}79}
10780
108void PointerBarrierWrapper::ReleaseBarrier(int event_id)81void PointerBarrierWrapper::ReleaseBarrier(int event_id)
109{82{
110 XFixesBarrierReleasePointer(nux::GetGraphicsDisplay()->GetX11Display(), barrier, event_id);83 Display *dpy = nux::GetGraphicsDisplay()->GetX11Display();
84 XIBarrierReleasePointer(dpy, current_device_, barrier_, event_id);
111}85}
11286
113void PointerBarrierWrapper::EmitCurrentData(int event_id, int x, int y)87void PointerBarrierWrapper::EmitCurrentData(int event_id, int x, int y)
@@ -134,63 +108,77 @@
134 return first_event_;108 return first_event_;
135}109}
136110
137bool PointerBarrierWrapper::HandleEvent(XEvent xevent)111int GetEventVelocity(XIBarrierEvent* event)
138{112{
139 if (xevent.type - event_base_ == XFixesBarrierNotify)113 double dx, dy;
140 {114 double speed;
141 auto notify_event = reinterpret_cast<XFixesBarrierNotifyEvent*>(&xevent);115 unsigned int millis;
142116
143 if (notify_event->barrier == barrier && notify_event->subtype == XFixesBarrierHitNotify)117 dx = event->dx;
118 dy = event->dy;
119
120 // Sometimes dtime is 0, if so we don't want to divide by zero!
121 millis = event->dtime ?: 1;
122
123 speed = sqrt(dx * dx + dy * dy) / millis * 1000;
124
125 return speed;
126}
127
128bool PointerBarrierWrapper::OwnsBarrierEvent(PointerBarrier const barrier) const
129{
130 return barrier_ == barrier;
131}
132
133bool PointerBarrierWrapper::HandleBarrierEvent(XIBarrierEvent* barrier_event)
134{
135 int velocity = GetEventVelocity(barrier_event);
136 smoothing_accum_ += velocity;
137 smoothing_count_++;
138
139 current_device_ = barrier_event->deviceid;
140
141 if (velocity > threshold)
142 {
143 smoothing_timeout_.reset();
144 ReleaseBarrier(barrier_event->eventid);
145 }
146 else if (released)
147 {
148 /* If the barrier is released, just emit the current event without
149 * waiting, so there won't be any delay on releasing the barrier. */
150 smoothing_timeout_.reset();
151
152 SendBarrierEvent(barrier_event->root_x, barrier_event->root_y,
153 velocity, barrier_event->eventid);
154 }
155 else if (!smoothing_timeout_)
156 {
157 int x = barrier_event->root_x;
158 int y = barrier_event->root_y;
159 int event = barrier_event->eventid;
160
161 // If we are a new event, don't delay sending the first event
162 if (last_event_ != event)
144 {163 {
145 smoothing_accum_ += notify_event->velocity;164 first_event_ = true;
146 smoothing_count_++;165 last_event_ = event;
147166
148 if (released)167 SendBarrierEvent(barrier_event->root_x, barrier_event->root_y,
149 {168 velocity, barrier_event->eventid);
150 /* If the barrier is released, just emit the current event without169
151 * waiting, so there won't be any delay on releasing the barrier. */170 first_event_ = false;
152 smoothing_timeout_.reset();
153
154 SendBarrierEvent(notify_event->x, notify_event->y,
155 notify_event->velocity, notify_event->event_id);
156 }
157 else if (!smoothing_timeout_)
158 {
159 int x = notify_event->x;
160 int y = notify_event->y;
161 int event = notify_event->event_id;
162
163 // If we are a new event, don't delay sending the first event
164 if (last_event_ != event)
165 {
166 first_event_ = true;
167 last_event_ = event;
168
169 SendBarrierEvent(notify_event->x, notify_event->y,
170 notify_event->velocity, notify_event->event_id);
171
172 first_event_ = false;
173 }
174
175 smoothing_timeout_.reset(new glib::Timeout(smoothing, [this, event, x, y] () {
176 EmitCurrentData(event, x, y);
177
178 smoothing_timeout_.reset();
179 return false;
180 }));
181 }
182 }171 }
183172
184 return notify_event->barrier == barrier;173 smoothing_timeout_.reset(new glib::Timeout(smoothing, [this, event, x, y] () {
174 EmitCurrentData(event, x, y);
175
176 smoothing_timeout_.reset();
177 return false;
178 }));
185 }179 }
186180
187 return false;181 return true;
188}
189
190bool PointerBarrierWrapper::HandleEventWrapper(XEvent event, void* data)
191{
192 PointerBarrierWrapper* wrapper = (PointerBarrierWrapper*)data;
193 return wrapper->HandleEvent(event);
194}182}
195183
196}184}
197185
=== modified file 'launcher/PointerBarrier.h'
--- launcher/PointerBarrier.h 2013-02-11 23:57:09 +0000
+++ launcher/PointerBarrier.h 2013-07-03 16:16:23 +0000
@@ -23,6 +23,7 @@
23#include <Nux/Nux.h>23#include <Nux/Nux.h>
24#include <X11/Xlib.h>24#include <X11/Xlib.h>
25#include <X11/extensions/Xfixes.h>25#include <X11/extensions/Xfixes.h>
26#include <X11/extensions/XInput2.h>
26#include <UnityCore/GLibSource.h>27#include <UnityCore/GLibSource.h>
2728
28namespace unity29namespace unity
@@ -88,19 +89,20 @@
8889
89 bool IsFirstEvent() const;90 bool IsFirstEvent() const;
9091
92 bool OwnsBarrierEvent(PointerBarrier const barrier) const;
93 bool HandleBarrierEvent(XIBarrierEvent* barrier_event);
94
91protected:95protected:
92 void EmitCurrentData(int event_id, int x, int y);96 void EmitCurrentData(int event_id, int x, int y);
93 bool HandleEvent(XEvent event);
9497
95private:98private:
96 static bool HandleEventWrapper(XEvent event, void* data);
97
98 void SendBarrierEvent(int x, int y, int velocity, int event_id);99 void SendBarrierEvent(int x, int y, int velocity, int event_id);
99100
100 int event_base_;101 int xi2_opcode_;
101 int last_event_;102 int last_event_;
103 int current_device_;
102 bool first_event_;104 bool first_event_;
103 PointerBarrier barrier;105 PointerBarrier barrier_;
104106
105 int smoothing_count_;107 int smoothing_count_;
106 int smoothing_accum_;108 int smoothing_accum_;
107109
=== modified file 'tests/test_pointer_barrier.cpp'
--- tests/test_pointer_barrier.cpp 2013-02-12 23:48:23 +0000
+++ tests/test_pointer_barrier.cpp 2013-07-03 16:16:23 +0000
@@ -15,6 +15,7 @@
15 * <http://www.gnu.org/licenses/>15 * <http://www.gnu.org/licenses/>
16 *16 *
17 * Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com>17 * Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com>
18 * Brandon Schaefer <brandon.schaefer@canonical.com>
18 *19 *
19 */20 */
2021
@@ -32,20 +33,21 @@
32class MockPointerBarrier : public PointerBarrierWrapper33class MockPointerBarrier : public PointerBarrierWrapper
33{34{
34public:35public:
35 bool HandleEvent(XEvent ev) { return PointerBarrierWrapper::HandleEvent(ev); }36 bool HandleBarrierEvent(XIBarrierEvent* b_ev) { return PointerBarrierWrapper::HandleBarrierEvent(b_ev); }
36};37};
3738
38XFixesBarrierNotifyEvent GetGenericEvent (unsigned int id)39XIBarrierEvent GetGenericEvent (unsigned int id)
39{40{
40 XFixesBarrierNotifyEvent ev;41 XIBarrierEvent ev;
4142
42 ev.type = XFixesBarrierNotify;43 ev.evtype = GenericEvent;
43 ev.subtype = XFixesBarrierHitNotify;
44 ev.barrier = 0;44 ev.barrier = 0;
45 ev.event_id = id;45 ev.eventid = id;
46 ev.x = 555;46 ev.root_x = 555;
47 ev.y = 333;47 ev.root_y = 333;
48 ev.velocity = std::numeric_limits<int>::max();48 ev.dx = 10;
49 ev.dy = 10;
50 ev.dtime = 15;
4951
50 return ev;52 return ev;
51}53}
@@ -70,29 +72,11 @@
70 EXPECT_EQ(bev.event_id, 4);72 EXPECT_EQ(bev.event_id, 4);
71}73}
7274
73TEST(TestPointerBarrier, HandleInvalidEvents)
74{
75 MockPointerBarrier pb;
76 XFixesBarrierNotifyEvent ev;
77 auto xev = reinterpret_cast<XEvent*>(&ev);
78
79 ev.type = XFixesBarrierNotify + 1;
80 EXPECT_FALSE(pb.HandleEvent(*xev));
81
82 ev.type = XFixesBarrierNotify;
83 ev.subtype = XFixesBarrierHitNotify + 1;
84 ev.barrier = 1;
85 EXPECT_FALSE(pb.HandleEvent(*xev));
86
87 ev.barrier = 0;
88 EXPECT_TRUE(pb.HandleEvent(*xev));
89}
90
91TEST(TestPointerBarrier, HandleHitNotifyEvents)75TEST(TestPointerBarrier, HandleHitNotifyEvents)
92{76{
93 MockPointerBarrier pb;77 MockPointerBarrier pb;
94 XFixesBarrierNotifyEvent ev = GetGenericEvent(0xdeadbeef);78 pb.threshold = 1000;
95 auto xev = reinterpret_cast<XEvent*>(&ev);79 XIBarrierEvent ev = GetGenericEvent(0xdeadbeef);
9680
97 bool got_event = false;81 bool got_event = false;
9882
@@ -102,14 +86,14 @@
102 got_event = true;86 got_event = true;
10387
104 EXPECT_EQ(pbw, &pb);88 EXPECT_EQ(pbw, &pb);
105 EXPECT_EQ(bev->x, ev.x);89 EXPECT_EQ(bev->x, ev.root_x);
106 EXPECT_EQ(bev->y, ev.y);90 EXPECT_EQ(bev->y, ev.root_y);
107 EXPECT_EQ(bev->velocity, 600 * pb.max_velocity_multiplier);91 EXPECT_EQ(bev->velocity, 600 * pb.max_velocity_multiplier);
108 EXPECT_EQ(bev->event_id, ev.event_id);92 EXPECT_EQ(bev->event_id, ev.eventid);
109 }93 }
110 });94 });
11195
112 EXPECT_TRUE(pb.HandleEvent(*xev));96 EXPECT_TRUE(pb.HandleBarrierEvent(&ev));
113 EXPECT_FALSE(got_event);97 EXPECT_FALSE(got_event);
11498
115 Utils::WaitForTimeoutMSec(pb.smoothing());99 Utils::WaitForTimeoutMSec(pb.smoothing());
@@ -120,30 +104,30 @@
120TEST(TestPointerBarrier, HandleHitNotifyReleasedEvents)104TEST(TestPointerBarrier, HandleHitNotifyReleasedEvents)
121{105{
122 MockPointerBarrier pb;106 MockPointerBarrier pb;
123 XFixesBarrierNotifyEvent ev = GetGenericEvent(0xabba);107 pb.threshold = 1000;
124 auto xev = reinterpret_cast<XEvent*>(&ev);108 XIBarrierEvent ev = GetGenericEvent(0xabba);
125 bool got_event = false;109 bool got_event = false;
126110
127 pb.barrier_event.connect([&] (PointerBarrierWrapper* pbw, BarrierEvent::Ptr bev) {111 pb.barrier_event.connect([&] (PointerBarrierWrapper* pbw, BarrierEvent::Ptr bev) {
128 got_event = true;112 got_event = true;
129113
130 EXPECT_EQ(pbw, &pb);114 EXPECT_EQ(pbw, &pb);
131 EXPECT_EQ(bev->x, ev.x);115 EXPECT_EQ(bev->x, ev.root_x);
132 EXPECT_EQ(bev->y, ev.y);116 EXPECT_EQ(bev->y, ev.root_y);
133 EXPECT_EQ(bev->velocity, ev.velocity);117 EXPECT_GT(bev->velocity, 0);
134 EXPECT_EQ(bev->event_id, ev.event_id);118 EXPECT_EQ(bev->event_id, ev.eventid);
135 });119 });
136120
137 pb.released = true;121 pb.released = true;
138 EXPECT_TRUE(pb.HandleEvent(*xev));122 EXPECT_TRUE(pb.HandleBarrierEvent(&ev));
139 EXPECT_TRUE(got_event);123 EXPECT_TRUE(got_event);
140}124}
141125
142TEST(TestPointerBarrier, ReciveFirstEvent)126TEST(TestPointerBarrier, ReciveFirstEvent)
143{127{
144 MockPointerBarrier pb;128 MockPointerBarrier pb;
145 XFixesBarrierNotifyEvent ev = GetGenericEvent(0xabba);129 pb.threshold = 1000;
146 auto xev = reinterpret_cast<XEvent*>(&ev);130 XIBarrierEvent ev = GetGenericEvent(0xabba);
147131
148 bool first_is_true = false;132 bool first_is_true = false;
149133
@@ -151,15 +135,15 @@
151 first_is_true = true;135 first_is_true = true;
152 });136 });
153137
154 EXPECT_TRUE(pb.HandleEvent(*xev));138 EXPECT_TRUE(pb.HandleBarrierEvent(&ev));
155 EXPECT_TRUE(first_is_true);139 EXPECT_TRUE(first_is_true);
156}140}
157141
158TEST(TestPointerBarrier, ReciveSecondEventFirstFalse)142TEST(TestPointerBarrier, ReciveSecondEventFirstFalse)
159{143{
160 MockPointerBarrier pb;144 MockPointerBarrier pb;
161 XFixesBarrierNotifyEvent ev = GetGenericEvent(0xabba);145 pb.threshold = 1000;
162 auto xev = reinterpret_cast<XEvent*>(&ev);146 XIBarrierEvent ev = GetGenericEvent(0xabba);
163 int events_recived = 0;147 int events_recived = 0;
164148
165 pb.barrier_event.connect([&] (PointerBarrierWrapper* pbw, BarrierEvent::Ptr bev) {149 pb.barrier_event.connect([&] (PointerBarrierWrapper* pbw, BarrierEvent::Ptr bev) {
@@ -171,7 +155,7 @@
171 EXPECT_FALSE(pbw->IsFirstEvent());155 EXPECT_FALSE(pbw->IsFirstEvent());
172 });156 });
173157
174 EXPECT_TRUE(pb.HandleEvent(*xev));158 EXPECT_TRUE(pb.HandleBarrierEvent(&ev));
175159
176 Utils::WaitForTimeoutMSec(pb.smoothing());160 Utils::WaitForTimeoutMSec(pb.smoothing());
177161