Merge lp:~3v1n0/unity/use-cursor-cache into lp:unity

Proposed by Marco Trevisan (Treviño) on 2015-10-21
Status: Merged
Approved by: Andrea Azzarone on 2015-10-21
Approved revision: 4016
Merged at revision: 4032
Proposed branch: lp:~3v1n0/unity/use-cursor-cache
Merge into: lp:unity
Diff against target: 383 lines (+52/-52)
19 files modified
debian/control (+1/-1)
decorations/DecorationsDataPool.cpp (+1/-16)
decorations/DecorationsDataPool.h (+1/-3)
panel/PanelTitlebarGrabAreaView.cpp (+2/-8)
panel/PanelTitlebarGrabAreaView.h (+0/-1)
plugins/unityshell/src/UnityGestureBroker.cpp (+0/-14)
plugins/unityshell/src/UnityGestureBroker.h (+1/-1)
plugins/unityshell/src/WindowGestureTarget.cpp (+2/-3)
plugins/unityshell/src/WindowGestureTarget.h (+0/-2)
tests/MockWindowManager.h (+1/-0)
tests/test-gestures/WindowGestureTargetMock.h (+0/-1)
tests/test-gestures/compiz_mock/core/screen.h (+1/-0)
tests/test-gestures/test_gestures_main.cpp (+0/-1)
unity-shared/IMTextEntry.cpp (+26/-1)
unity-shared/PluginAdapter.cpp (+5/-0)
unity-shared/PluginAdapter.h (+2/-0)
unity-shared/StandaloneWindowManager.cpp (+5/-0)
unity-shared/StandaloneWindowManager.h (+2/-0)
unity-shared/WindowManager.h (+2/-0)
To merge this branch: bzr merge lp:~3v1n0/unity/use-cursor-cache
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing on 2015-10-22
Andrea Azzarone (community) 2015-10-21 Approve on 2015-10-21
Review via email: mp+275192@code.launchpad.net

Commit message

Unity: use compiz cursorCache to get properly updated cursors

We avoid duplicating instances and they're automatically recreated
when the system cursor setting change.

Description of the change

To post a comment you must log in.
lp:~3v1n0/unity/use-cursor-cache updated on 2015-10-21
4015. By Marco Trevisan (Treviño) on 2015-10-21

MockWindowManager: add definition for GetCachedCursor

4016. By Marco Trevisan (Treviño) on 2015-10-21

IMTextEntry: use GetCachedCursor to get proper cursor

PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Andrea Azzarone (azzar1) wrote :

LGTM.

review: Approve
lp:~3v1n0/unity/use-cursor-cache updated on 2015-10-22
4017. By Marco Trevisan (Treviño) on 2015-10-22

CompScreenMock: define cursorCache

PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2015-08-24 16:03:38 +0000
3+++ debian/control 2015-10-22 13:08:28 +0000
4@@ -3,7 +3,7 @@
5 Priority: optional
6 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
7 Build-Depends: cmake,
8- compiz-dev (>= 1:0.9.11),
9+ compiz-dev (>= 1:0.9.12.2),
10 debhelper (>= 9.0.0~),
11 dbus-test-runner,
12 dh-migrations,
13
14=== modified file 'decorations/DecorationsDataPool.cpp'
15--- decorations/DecorationsDataPool.cpp 2014-04-02 15:12:16 +0000
16+++ decorations/DecorationsDataPool.cpp 2015-10-22 13:08:28 +0000
17@@ -67,7 +67,6 @@
18
19 DataPool::DataPool()
20 {
21- SetupCursors();
22 SetupTextures();
23
24 CompSize glow_size(texture::GLOW_SIZE, texture::GLOW_SIZE);
25@@ -78,13 +77,6 @@
26 unity::Settings::Instance().dpi_changed.connect(cb);
27 }
28
29-DataPool::~DataPool()
30-{
31- auto* dpy = screen->dpy();
32- for (auto cursor : edge_cursors_)
33- XFreeCursor(dpy, cursor);
34-}
35-
36 DataPool::Ptr const& DataPool::Get()
37 {
38 if (instance_)
39@@ -99,16 +91,9 @@
40 instance_.reset();
41 }
42
43-void DataPool::SetupCursors()
44-{
45- auto* dpy = screen->dpy();
46- for (unsigned c = 0; c < edge_cursors_.size(); ++c)
47- edge_cursors_[c] = XCreateFontCursor(dpy, EdgeTypeToCursorShape(Edge::Type(c)));
48-}
49-
50 Cursor DataPool::EdgeCursor(Edge::Type type) const
51 {
52- return edge_cursors_[unsigned(type)];
53+ return screen->cursorCache(EdgeTypeToCursorShape(type));
54 }
55
56 void DataPool::SetupTextures()
57
58=== modified file 'decorations/DecorationsDataPool.h'
59--- decorations/DecorationsDataPool.h 2014-04-02 15:12:16 +0000
60+++ decorations/DecorationsDataPool.h 2015-10-22 13:08:28 +0000
61@@ -36,7 +36,7 @@
62
63 static DataPool::Ptr const& Get();
64 static void Reset();
65- virtual ~DataPool();
66+ virtual ~DataPool() = default;
67
68 Cursor EdgeCursor(Edge::Type) const;
69 cu::SimpleTexture::Ptr const& GlowTexture() const;
70@@ -48,10 +48,8 @@
71 DataPool(DataPool const&) = delete;
72 DataPool& operator=(DataPool const&) = delete;
73
74- void SetupCursors();
75 void SetupTextures();
76
77- std::array<Cursor, size_t(Edge::Type::Size)> edge_cursors_;
78 cu::SimpleTexture::Ptr glow_texture_;
79
80 typedef std::array<std::array<cu::SimpleTexture::Ptr, size_t(WidgetState::Size)>, size_t(WindowButtonType::Size)> WindowButtonsArray;
81
82=== modified file 'panel/PanelTitlebarGrabAreaView.cpp'
83--- panel/PanelTitlebarGrabAreaView.cpp 2014-04-02 21:42:44 +0000
84+++ panel/PanelTitlebarGrabAreaView.cpp 2015-10-22 13:08:28 +0000
85@@ -24,6 +24,7 @@
86 #include <X11/cursorfont.h>
87 #include "unity-shared/UnitySettings.h"
88 #include "unity-shared/DecorationStyle.h"
89+#include "unity-shared/WindowManager.h"
90 #include "PanelTitlebarGrabAreaView.h"
91
92
93@@ -48,12 +49,6 @@
94 });
95 }
96
97-PanelTitlebarGrabArea::~PanelTitlebarGrabArea()
98-{
99- if (grab_cursor_)
100- XFreeCursor(nux::GetGraphicsDisplay()->GetX11Display(), grab_cursor_);
101-}
102-
103 void PanelTitlebarGrabArea::SetGrabbed(bool enabled)
104 {
105 auto display = nux::GetGraphicsDisplay()->GetX11Display();
106@@ -64,13 +59,12 @@
107
108 if (enabled && !grab_cursor_)
109 {
110- grab_cursor_ = XCreateFontCursor(display, XC_fleur);
111+ grab_cursor_ = WindowManager::Default().GetCachedCursor(XC_fleur);
112 XDefineCursor(display, panel_window->GetInputWindowId(), grab_cursor_);
113 }
114 else if (!enabled && grab_cursor_)
115 {
116 XUndefineCursor(display, panel_window->GetInputWindowId());
117- XFreeCursor(display, grab_cursor_);
118 grab_cursor_ = None;
119 }
120 }
121
122=== modified file 'panel/PanelTitlebarGrabAreaView.h'
123--- panel/PanelTitlebarGrabAreaView.h 2014-04-02 21:42:44 +0000
124+++ panel/PanelTitlebarGrabAreaView.h 2015-10-22 13:08:28 +0000
125@@ -38,7 +38,6 @@
126
127 public:
128 PanelTitlebarGrabArea();
129- ~PanelTitlebarGrabArea();
130
131 void SetGrabbed(bool enabled);
132 bool IsGrabbed();
133
134=== modified file 'plugins/unityshell/src/UnityGestureBroker.cpp'
135--- plugins/unityshell/src/UnityGestureBroker.cpp 2013-04-04 23:26:31 +0000
136+++ plugins/unityshell/src/UnityGestureBroker.cpp 2015-10-22 13:08:28 +0000
137@@ -24,27 +24,13 @@
138 #include "UnityGestureTarget.h"
139 #include "WindowGestureTarget.h"
140
141-#include <X11/cursorfont.h>
142-
143 UnityGestureBroker::UnityGestureBroker()
144 : nux::GestureBroker()
145 {
146- g_assert(WindowGestureTarget::fleur_cursor == 0);
147- WindowGestureTarget::fleur_cursor = XCreateFontCursor (screen->dpy (), XC_fleur);
148-
149 unity_target.reset(new UnityGestureTarget);
150 gestural_window_switcher_.reset(new unity::GesturalWindowSwitcher);
151 }
152
153-UnityGestureBroker::~UnityGestureBroker()
154-{
155- if (WindowGestureTarget::fleur_cursor)
156- {
157- XFreeCursor (screen->dpy (), WindowGestureTarget::fleur_cursor);
158- WindowGestureTarget::fleur_cursor = 0;
159- }
160-}
161-
162 std::vector<nux::ShPtGestureTarget>
163 UnityGestureBroker::FindGestureTargets(const nux::GestureEvent &event)
164 {
165
166=== modified file 'plugins/unityshell/src/UnityGestureBroker.h'
167--- plugins/unityshell/src/UnityGestureBroker.h 2012-08-14 12:48:21 +0000
168+++ plugins/unityshell/src/UnityGestureBroker.h 2015-10-22 13:08:28 +0000
169@@ -32,7 +32,7 @@
170 {
171 public:
172 UnityGestureBroker();
173- virtual ~UnityGestureBroker();
174+ virtual ~UnityGestureBroker() = default;
175
176 private:
177 std::vector<nux::ShPtGestureTarget>
178
179=== modified file 'plugins/unityshell/src/WindowGestureTarget.cpp'
180--- plugins/unityshell/src/WindowGestureTarget.cpp 2013-07-01 21:42:50 +0000
181+++ plugins/unityshell/src/WindowGestureTarget.cpp 2015-10-22 13:08:28 +0000
182@@ -23,6 +23,7 @@
183 #include "WindowGestureTarget.h"
184
185 #include <Nux/Nux.h> // otherwise unityshell.h inclusion will cause failures
186+#include <X11/cursorfont.h>
187 #include "unityshell.h"
188
189 // To make the gesture tests pass, this has to be a local include.
190@@ -30,8 +31,6 @@
191
192 using namespace nux;
193
194-Cursor WindowGestureTarget::fleur_cursor = 0;
195-
196 WindowGestureTarget::WindowGestureTarget(CompWindow *window)
197 : window_(window), drag_grab_(0), started_window_move_(false),
198 window_restored_by_pinch_(false)
199@@ -138,7 +137,7 @@
200 {
201 if (!event.IsDirectTouch())
202 {
203- drag_grab_ = screen->pushGrab(fleur_cursor, "unity");
204+ drag_grab_ = screen->pushGrab(screen->cursorCache(XC_fleur), "unity");
205 window_->grabNotify(window_->serverGeometry().x(),
206 window_->serverGeometry().y(),
207 0,
208
209=== modified file 'plugins/unityshell/src/WindowGestureTarget.h'
210--- plugins/unityshell/src/WindowGestureTarget.h 2013-07-01 21:42:50 +0000
211+++ plugins/unityshell/src/WindowGestureTarget.h 2015-10-22 13:08:28 +0000
212@@ -36,8 +36,6 @@
213
214 virtual nux::GestureDeliveryRequest GestureEvent(const nux::GestureEvent &event);
215
216- static Cursor fleur_cursor;
217-
218 CompWindow *window() {return window_;}
219 private:
220 virtual bool Equals(const nux::GestureTarget& other) const;
221
222=== modified file 'tests/MockWindowManager.h'
223--- tests/MockWindowManager.h 2015-01-21 15:28:59 +0000
224+++ tests/MockWindowManager.h 2015-10-22 13:08:28 +0000
225@@ -101,6 +101,7 @@
226
227 MOCK_CONST_METHOD1(GetWindowName, std::string(Window));
228 MOCK_CONST_METHOD1(IsOnscreenKeyboard, bool(Window));
229+ MOCK_CONST_METHOD1(GetCachedCursor, Cursor(unsigned int));
230
231 MOCK_METHOD1(AddProperties, void(GVariantBuilder*));
232 };
233
234=== modified file 'tests/test-gestures/WindowGestureTargetMock.h'
235--- tests/test-gestures/WindowGestureTargetMock.h 2012-07-27 20:20:29 +0000
236+++ tests/test-gestures/WindowGestureTargetMock.h 2015-10-22 13:08:28 +0000
237@@ -32,7 +32,6 @@
238 CompWindowMock *window;
239 std::list<nux::GestureEvent> events_received;
240
241- static Cursor fleur_cursor;
242 private:
243 virtual bool Equals(const nux::GestureTarget& other) const
244 {
245
246=== modified file 'tests/test-gestures/compiz_mock/core/screen.h'
247--- tests/test-gestures/compiz_mock/core/screen.h 2012-07-27 20:20:29 +0000
248+++ tests/test-gestures/compiz_mock/core/screen.h 2015-10-22 13:08:28 +0000
249@@ -58,6 +58,7 @@
250 }
251
252 Cursor invisibleCursor() {return 1;}
253+ Cursor cursorCache(unsigned int) {return 0;}
254
255 int width_;
256 int height_;
257
258=== modified file 'tests/test-gestures/test_gestures_main.cpp'
259--- tests/test-gestures/test_gestures_main.cpp 2012-07-27 20:24:01 +0000
260+++ tests/test-gestures/test_gestures_main.cpp 2015-10-22 13:08:28 +0000
261@@ -46,7 +46,6 @@
262 g_gesture_event_reject_count[gesture_id_] + 1;
263 }
264
265-Cursor WindowGestureTargetMock::fleur_cursor = 0;
266 std::set<WindowGestureTargetMock*> g_window_target_mocks;
267
268 int main(int argc, char** argv)
269
270=== modified file 'unity-shared/IMTextEntry.cpp'
271--- unity-shared/IMTextEntry.cpp 2014-05-26 14:58:52 +0000
272+++ unity-shared/IMTextEntry.cpp 2015-10-22 13:08:28 +0000
273@@ -19,7 +19,9 @@
274 */
275
276 #include "IMTextEntry.h"
277+#include "WindowManager.h"
278 #include <gtk/gtk.h>
279+#include <X11/cursorfont.h>
280
281 namespace unity
282 {
283@@ -28,7 +30,30 @@
284 IMTextEntry::IMTextEntry()
285 : TextEntry("", NUX_TRACKER_LOCATION)
286 , clipboard_enabled(true)
287-{}
288+{
289+ // Let's override the nux RecvMouse{Enter,Leave} using the hard way
290+ mouse_enter.clear();
291+ mouse_leave.clear();
292+
293+ mouse_enter.connect([this] (int, int, unsigned long, unsigned long) {
294+ auto dpy = nux::GetGraphicsDisplay()->GetX11Display();
295+ auto window = static_cast<nux::BaseWindow*>(GetTopLevelViewWindow());
296+
297+ if (dpy && window)
298+ {
299+ auto cursor = WindowManager::Default().GetCachedCursor(XC_xterm);
300+ XDefineCursor(dpy, window->GetInputWindowId(), cursor);
301+ }
302+ });
303+
304+ mouse_leave.connect([this] (int, int, unsigned long, unsigned long) {
305+ auto dpy = nux::GetGraphicsDisplay()->GetX11Display();
306+ auto window = static_cast<nux::BaseWindow*>(GetTopLevelViewWindow());
307+
308+ if (dpy && window)
309+ XUndefineCursor(dpy, window->GetInputWindowId());
310+ });
311+}
312
313 void IMTextEntry::CopyClipboard()
314 {
315
316=== modified file 'unity-shared/PluginAdapter.cpp'
317--- unity-shared/PluginAdapter.cpp 2015-09-10 13:23:47 +0000
318+++ unity-shared/PluginAdapter.cpp 2015-10-22 13:08:28 +0000
319@@ -1486,6 +1486,11 @@
320 _last_focused_window = NULL;
321 }
322
323+Cursor PluginAdapter::GetCachedCursor(unsigned int cursor_name) const
324+{
325+ return screen->cursorCache(cursor_name);
326+}
327+
328 void PluginAdapter::UnmapAllNoNuxWindowsSync()
329 {
330 for (auto const& window : m_Screen->windows())
331
332=== modified file 'unity-shared/PluginAdapter.h'
333--- unity-shared/PluginAdapter.h 2015-06-05 16:39:31 +0000
334+++ unity-shared/PluginAdapter.h 2015-10-22 13:08:28 +0000
335@@ -194,6 +194,8 @@
336
337 Window GetTopWindowAbove(Window xid) const;
338
339+ Cursor GetCachedCursor(unsigned int) const;
340+
341 void UnmapAllNoNuxWindowsSync();
342 static bool IsNuxWindow(CompWindow* value);
343
344
345=== modified file 'unity-shared/StandaloneWindowManager.cpp'
346--- unity-shared/StandaloneWindowManager.cpp 2015-06-05 16:39:31 +0000
347+++ unity-shared/StandaloneWindowManager.cpp 2015-10-22 13:08:28 +0000
348@@ -742,6 +742,11 @@
349 return standalone_windows_;
350 }
351
352+Cursor StandaloneWindowManager::GetCachedCursor(unsigned int cursor_name) const
353+{
354+ return 0;
355+}
356+
357 void StandaloneWindowManager::SetCurrentViewport(nux::Point const& vp)
358 {
359 current_vp_ = vp;
360
361=== modified file 'unity-shared/StandaloneWindowManager.h'
362--- unity-shared/StandaloneWindowManager.h 2015-06-05 16:39:31 +0000
363+++ unity-shared/StandaloneWindowManager.h 2015-10-22 13:08:28 +0000
364@@ -181,6 +181,8 @@
365 void SetCurrentViewport(nux::Point const& vp);
366 void SetWorkareaGeometry(nux::Geometry const& geo);
367
368+ Cursor GetCachedCursor(unsigned int cursor_name) const;
369+
370 void ResetStatus();
371
372 protected:
373
374=== modified file 'unity-shared/WindowManager.h'
375--- unity-shared/WindowManager.h 2015-06-05 16:39:31 +0000
376+++ unity-shared/WindowManager.h 2015-10-22 13:08:28 +0000
377@@ -171,6 +171,8 @@
378 virtual std::string GetStringProperty(Window, Atom) const = 0;
379 virtual std::vector<long> GetCardinalProperty(Window, Atom) const = 0;
380
381+ virtual Cursor GetCachedCursor(unsigned int cursor_name) const = 0;
382+
383 virtual void UnmapAllNoNuxWindowsSync() = 0;
384
385