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

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Andrea Azzarone
Approved revision: no longer in the source branch.
Merged at revision: 4029
Proposed branch: lp:~3v1n0/unity/use-cursor-cache
Merge into: lp:unity/7.3
Diff against target: 430 lines (+58/-58)
20 files modified
dash/previews/CMakeLists.txt (+6/-6)
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
Andrea Azzarone (community) Approve
Review via email: mp+279306@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

Backporting to Wily

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

Preview Diff

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

Subscribers

People subscribed via source and target branches