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

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Andrea Azzarone
Approved revision: no longer in the source branch.
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
Andrea Azzarone (community) Approve
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.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Andrea Azzarone (azzar1) wrote :

LGTM.

review: Approve
Revision history for this message
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
=== modified file 'debian/control'
--- debian/control 2015-08-24 16:03:38 +0000
+++ debian/control 2015-10-22 13:08:28 +0000
@@ -3,7 +3,7 @@
3Priority: optional3Priority: optional
4Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>4Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
5Build-Depends: cmake,5Build-Depends: cmake,
6 compiz-dev (>= 1:0.9.11),6 compiz-dev (>= 1:0.9.12.2),
7 debhelper (>= 9.0.0~),7 debhelper (>= 9.0.0~),
8 dbus-test-runner,8 dbus-test-runner,
9 dh-migrations,9 dh-migrations,
1010
=== modified file 'decorations/DecorationsDataPool.cpp'
--- decorations/DecorationsDataPool.cpp 2014-04-02 15:12:16 +0000
+++ decorations/DecorationsDataPool.cpp 2015-10-22 13:08:28 +0000
@@ -67,7 +67,6 @@
6767
68DataPool::DataPool()68DataPool::DataPool()
69{69{
70 SetupCursors();
71 SetupTextures();70 SetupTextures();
7271
73 CompSize glow_size(texture::GLOW_SIZE, texture::GLOW_SIZE);72 CompSize glow_size(texture::GLOW_SIZE, texture::GLOW_SIZE);
@@ -78,13 +77,6 @@
78 unity::Settings::Instance().dpi_changed.connect(cb);77 unity::Settings::Instance().dpi_changed.connect(cb);
79}78}
8079
81DataPool::~DataPool()
82{
83 auto* dpy = screen->dpy();
84 for (auto cursor : edge_cursors_)
85 XFreeCursor(dpy, cursor);
86}
87
88DataPool::Ptr const& DataPool::Get()80DataPool::Ptr const& DataPool::Get()
89{81{
90 if (instance_)82 if (instance_)
@@ -99,16 +91,9 @@
99 instance_.reset();91 instance_.reset();
100}92}
10193
102void DataPool::SetupCursors()
103{
104 auto* dpy = screen->dpy();
105 for (unsigned c = 0; c < edge_cursors_.size(); ++c)
106 edge_cursors_[c] = XCreateFontCursor(dpy, EdgeTypeToCursorShape(Edge::Type(c)));
107}
108
109Cursor DataPool::EdgeCursor(Edge::Type type) const94Cursor DataPool::EdgeCursor(Edge::Type type) const
110{95{
111 return edge_cursors_[unsigned(type)];96 return screen->cursorCache(EdgeTypeToCursorShape(type));
112}97}
11398
114void DataPool::SetupTextures()99void DataPool::SetupTextures()
115100
=== modified file 'decorations/DecorationsDataPool.h'
--- decorations/DecorationsDataPool.h 2014-04-02 15:12:16 +0000
+++ decorations/DecorationsDataPool.h 2015-10-22 13:08:28 +0000
@@ -36,7 +36,7 @@
3636
37 static DataPool::Ptr const& Get();37 static DataPool::Ptr const& Get();
38 static void Reset();38 static void Reset();
39 virtual ~DataPool();39 virtual ~DataPool() = default;
4040
41 Cursor EdgeCursor(Edge::Type) const;41 Cursor EdgeCursor(Edge::Type) const;
42 cu::SimpleTexture::Ptr const& GlowTexture() const;42 cu::SimpleTexture::Ptr const& GlowTexture() const;
@@ -48,10 +48,8 @@
48 DataPool(DataPool const&) = delete;48 DataPool(DataPool const&) = delete;
49 DataPool& operator=(DataPool const&) = delete;49 DataPool& operator=(DataPool const&) = delete;
5050
51 void SetupCursors();
52 void SetupTextures();51 void SetupTextures();
5352
54 std::array<Cursor, size_t(Edge::Type::Size)> edge_cursors_;
55 cu::SimpleTexture::Ptr glow_texture_;53 cu::SimpleTexture::Ptr glow_texture_;
5654
57 typedef std::array<std::array<cu::SimpleTexture::Ptr, size_t(WidgetState::Size)>, size_t(WindowButtonType::Size)> WindowButtonsArray;55 typedef std::array<std::array<cu::SimpleTexture::Ptr, size_t(WidgetState::Size)>, size_t(WindowButtonType::Size)> WindowButtonsArray;
5856
=== modified file 'panel/PanelTitlebarGrabAreaView.cpp'
--- panel/PanelTitlebarGrabAreaView.cpp 2014-04-02 21:42:44 +0000
+++ panel/PanelTitlebarGrabAreaView.cpp 2015-10-22 13:08:28 +0000
@@ -24,6 +24,7 @@
24#include <X11/cursorfont.h>24#include <X11/cursorfont.h>
25#include "unity-shared/UnitySettings.h"25#include "unity-shared/UnitySettings.h"
26#include "unity-shared/DecorationStyle.h"26#include "unity-shared/DecorationStyle.h"
27#include "unity-shared/WindowManager.h"
27#include "PanelTitlebarGrabAreaView.h"28#include "PanelTitlebarGrabAreaView.h"
2829
2930
@@ -48,12 +49,6 @@
48 });49 });
49}50}
5051
51PanelTitlebarGrabArea::~PanelTitlebarGrabArea()
52{
53 if (grab_cursor_)
54 XFreeCursor(nux::GetGraphicsDisplay()->GetX11Display(), grab_cursor_);
55}
56
57void PanelTitlebarGrabArea::SetGrabbed(bool enabled)52void PanelTitlebarGrabArea::SetGrabbed(bool enabled)
58{53{
59 auto display = nux::GetGraphicsDisplay()->GetX11Display();54 auto display = nux::GetGraphicsDisplay()->GetX11Display();
@@ -64,13 +59,12 @@
6459
65 if (enabled && !grab_cursor_)60 if (enabled && !grab_cursor_)
66 {61 {
67 grab_cursor_ = XCreateFontCursor(display, XC_fleur);62 grab_cursor_ = WindowManager::Default().GetCachedCursor(XC_fleur);
68 XDefineCursor(display, panel_window->GetInputWindowId(), grab_cursor_);63 XDefineCursor(display, panel_window->GetInputWindowId(), grab_cursor_);
69 }64 }
70 else if (!enabled && grab_cursor_)65 else if (!enabled && grab_cursor_)
71 {66 {
72 XUndefineCursor(display, panel_window->GetInputWindowId());67 XUndefineCursor(display, panel_window->GetInputWindowId());
73 XFreeCursor(display, grab_cursor_);
74 grab_cursor_ = None;68 grab_cursor_ = None;
75 }69 }
76}70}
7771
=== modified file 'panel/PanelTitlebarGrabAreaView.h'
--- panel/PanelTitlebarGrabAreaView.h 2014-04-02 21:42:44 +0000
+++ panel/PanelTitlebarGrabAreaView.h 2015-10-22 13:08:28 +0000
@@ -38,7 +38,6 @@
3838
39public:39public:
40 PanelTitlebarGrabArea();40 PanelTitlebarGrabArea();
41 ~PanelTitlebarGrabArea();
4241
43 void SetGrabbed(bool enabled);42 void SetGrabbed(bool enabled);
44 bool IsGrabbed();43 bool IsGrabbed();
4544
=== modified file 'plugins/unityshell/src/UnityGestureBroker.cpp'
--- plugins/unityshell/src/UnityGestureBroker.cpp 2013-04-04 23:26:31 +0000
+++ plugins/unityshell/src/UnityGestureBroker.cpp 2015-10-22 13:08:28 +0000
@@ -24,27 +24,13 @@
24#include "UnityGestureTarget.h"24#include "UnityGestureTarget.h"
25#include "WindowGestureTarget.h"25#include "WindowGestureTarget.h"
2626
27#include <X11/cursorfont.h>
28
29UnityGestureBroker::UnityGestureBroker()27UnityGestureBroker::UnityGestureBroker()
30 : nux::GestureBroker()28 : nux::GestureBroker()
31{29{
32 g_assert(WindowGestureTarget::fleur_cursor == 0);
33 WindowGestureTarget::fleur_cursor = XCreateFontCursor (screen->dpy (), XC_fleur);
34
35 unity_target.reset(new UnityGestureTarget);30 unity_target.reset(new UnityGestureTarget);
36 gestural_window_switcher_.reset(new unity::GesturalWindowSwitcher);31 gestural_window_switcher_.reset(new unity::GesturalWindowSwitcher);
37}32}
3833
39UnityGestureBroker::~UnityGestureBroker()
40{
41 if (WindowGestureTarget::fleur_cursor)
42 {
43 XFreeCursor (screen->dpy (), WindowGestureTarget::fleur_cursor);
44 WindowGestureTarget::fleur_cursor = 0;
45 }
46}
47
48std::vector<nux::ShPtGestureTarget>34std::vector<nux::ShPtGestureTarget>
49UnityGestureBroker::FindGestureTargets(const nux::GestureEvent &event)35UnityGestureBroker::FindGestureTargets(const nux::GestureEvent &event)
50{36{
5137
=== modified file 'plugins/unityshell/src/UnityGestureBroker.h'
--- plugins/unityshell/src/UnityGestureBroker.h 2012-08-14 12:48:21 +0000
+++ plugins/unityshell/src/UnityGestureBroker.h 2015-10-22 13:08:28 +0000
@@ -32,7 +32,7 @@
32{32{
33public:33public:
34 UnityGestureBroker();34 UnityGestureBroker();
35 virtual ~UnityGestureBroker();35 virtual ~UnityGestureBroker() = default;
3636
37private:37private:
38 std::vector<nux::ShPtGestureTarget>38 std::vector<nux::ShPtGestureTarget>
3939
=== modified file 'plugins/unityshell/src/WindowGestureTarget.cpp'
--- plugins/unityshell/src/WindowGestureTarget.cpp 2013-07-01 21:42:50 +0000
+++ plugins/unityshell/src/WindowGestureTarget.cpp 2015-10-22 13:08:28 +0000
@@ -23,6 +23,7 @@
23#include "WindowGestureTarget.h"23#include "WindowGestureTarget.h"
2424
25#include <Nux/Nux.h> // otherwise unityshell.h inclusion will cause failures25#include <Nux/Nux.h> // otherwise unityshell.h inclusion will cause failures
26#include <X11/cursorfont.h>
26#include "unityshell.h"27#include "unityshell.h"
2728
28// To make the gesture tests pass, this has to be a local include.29// To make the gesture tests pass, this has to be a local include.
@@ -30,8 +31,6 @@
3031
31using namespace nux;32using namespace nux;
3233
33Cursor WindowGestureTarget::fleur_cursor = 0;
34
35WindowGestureTarget::WindowGestureTarget(CompWindow *window)34WindowGestureTarget::WindowGestureTarget(CompWindow *window)
36 : window_(window), drag_grab_(0), started_window_move_(false),35 : window_(window), drag_grab_(0), started_window_move_(false),
37 window_restored_by_pinch_(false)36 window_restored_by_pinch_(false)
@@ -138,7 +137,7 @@
138{137{
139 if (!event.IsDirectTouch())138 if (!event.IsDirectTouch())
140 {139 {
141 drag_grab_ = screen->pushGrab(fleur_cursor, "unity");140 drag_grab_ = screen->pushGrab(screen->cursorCache(XC_fleur), "unity");
142 window_->grabNotify(window_->serverGeometry().x(),141 window_->grabNotify(window_->serverGeometry().x(),
143 window_->serverGeometry().y(),142 window_->serverGeometry().y(),
144 0,143 0,
145144
=== modified file 'plugins/unityshell/src/WindowGestureTarget.h'
--- plugins/unityshell/src/WindowGestureTarget.h 2013-07-01 21:42:50 +0000
+++ plugins/unityshell/src/WindowGestureTarget.h 2015-10-22 13:08:28 +0000
@@ -36,8 +36,6 @@
3636
37 virtual nux::GestureDeliveryRequest GestureEvent(const nux::GestureEvent &event);37 virtual nux::GestureDeliveryRequest GestureEvent(const nux::GestureEvent &event);
3838
39 static Cursor fleur_cursor;
40
41 CompWindow *window() {return window_;}39 CompWindow *window() {return window_;}
42 private:40 private:
43 virtual bool Equals(const nux::GestureTarget& other) const;41 virtual bool Equals(const nux::GestureTarget& other) const;
4442
=== modified file 'tests/MockWindowManager.h'
--- tests/MockWindowManager.h 2015-01-21 15:28:59 +0000
+++ tests/MockWindowManager.h 2015-10-22 13:08:28 +0000
@@ -101,6 +101,7 @@
101101
102 MOCK_CONST_METHOD1(GetWindowName, std::string(Window));102 MOCK_CONST_METHOD1(GetWindowName, std::string(Window));
103 MOCK_CONST_METHOD1(IsOnscreenKeyboard, bool(Window));103 MOCK_CONST_METHOD1(IsOnscreenKeyboard, bool(Window));
104 MOCK_CONST_METHOD1(GetCachedCursor, Cursor(unsigned int));
104105
105 MOCK_METHOD1(AddProperties, void(GVariantBuilder*));106 MOCK_METHOD1(AddProperties, void(GVariantBuilder*));
106};107};
107108
=== modified file 'tests/test-gestures/WindowGestureTargetMock.h'
--- tests/test-gestures/WindowGestureTargetMock.h 2012-07-27 20:20:29 +0000
+++ tests/test-gestures/WindowGestureTargetMock.h 2015-10-22 13:08:28 +0000
@@ -32,7 +32,6 @@
32 CompWindowMock *window;32 CompWindowMock *window;
33 std::list<nux::GestureEvent> events_received;33 std::list<nux::GestureEvent> events_received;
3434
35 static Cursor fleur_cursor;
36 private:35 private:
37 virtual bool Equals(const nux::GestureTarget& other) const36 virtual bool Equals(const nux::GestureTarget& other) const
38 {37 {
3938
=== modified file 'tests/test-gestures/compiz_mock/core/screen.h'
--- tests/test-gestures/compiz_mock/core/screen.h 2012-07-27 20:20:29 +0000
+++ tests/test-gestures/compiz_mock/core/screen.h 2015-10-22 13:08:28 +0000
@@ -58,6 +58,7 @@
58 }58 }
5959
60 Cursor invisibleCursor() {return 1;}60 Cursor invisibleCursor() {return 1;}
61 Cursor cursorCache(unsigned int) {return 0;}
6162
62 int width_;63 int width_;
63 int height_;64 int height_;
6465
=== modified file 'tests/test-gestures/test_gestures_main.cpp'
--- tests/test-gestures/test_gestures_main.cpp 2012-07-27 20:24:01 +0000
+++ tests/test-gestures/test_gestures_main.cpp 2015-10-22 13:08:28 +0000
@@ -46,7 +46,6 @@
46 g_gesture_event_reject_count[gesture_id_] + 1;46 g_gesture_event_reject_count[gesture_id_] + 1;
47}47}
4848
49Cursor WindowGestureTargetMock::fleur_cursor = 0;
50std::set<WindowGestureTargetMock*> g_window_target_mocks;49std::set<WindowGestureTargetMock*> g_window_target_mocks;
5150
52int main(int argc, char** argv)51int main(int argc, char** argv)
5352
=== modified file 'unity-shared/IMTextEntry.cpp'
--- unity-shared/IMTextEntry.cpp 2014-05-26 14:58:52 +0000
+++ unity-shared/IMTextEntry.cpp 2015-10-22 13:08:28 +0000
@@ -19,7 +19,9 @@
19 */19 */
2020
21#include "IMTextEntry.h"21#include "IMTextEntry.h"
22#include "WindowManager.h"
22#include <gtk/gtk.h>23#include <gtk/gtk.h>
24#include <X11/cursorfont.h>
2325
24namespace unity26namespace unity
25{27{
@@ -28,7 +30,30 @@
28IMTextEntry::IMTextEntry()30IMTextEntry::IMTextEntry()
29 : TextEntry("", NUX_TRACKER_LOCATION)31 : TextEntry("", NUX_TRACKER_LOCATION)
30 , clipboard_enabled(true)32 , clipboard_enabled(true)
31{}33{
34 // Let's override the nux RecvMouse{Enter,Leave} using the hard way
35 mouse_enter.clear();
36 mouse_leave.clear();
37
38 mouse_enter.connect([this] (int, int, unsigned long, unsigned long) {
39 auto dpy = nux::GetGraphicsDisplay()->GetX11Display();
40 auto window = static_cast<nux::BaseWindow*>(GetTopLevelViewWindow());
41
42 if (dpy && window)
43 {
44 auto cursor = WindowManager::Default().GetCachedCursor(XC_xterm);
45 XDefineCursor(dpy, window->GetInputWindowId(), cursor);
46 }
47 });
48
49 mouse_leave.connect([this] (int, int, unsigned long, unsigned long) {
50 auto dpy = nux::GetGraphicsDisplay()->GetX11Display();
51 auto window = static_cast<nux::BaseWindow*>(GetTopLevelViewWindow());
52
53 if (dpy && window)
54 XUndefineCursor(dpy, window->GetInputWindowId());
55 });
56}
3257
33void IMTextEntry::CopyClipboard()58void IMTextEntry::CopyClipboard()
34{59{
3560
=== modified file 'unity-shared/PluginAdapter.cpp'
--- unity-shared/PluginAdapter.cpp 2015-09-10 13:23:47 +0000
+++ unity-shared/PluginAdapter.cpp 2015-10-22 13:08:28 +0000
@@ -1486,6 +1486,11 @@
1486 _last_focused_window = NULL;1486 _last_focused_window = NULL;
1487}1487}
14881488
1489Cursor PluginAdapter::GetCachedCursor(unsigned int cursor_name) const
1490{
1491 return screen->cursorCache(cursor_name);
1492}
1493
1489void PluginAdapter::UnmapAllNoNuxWindowsSync()1494void PluginAdapter::UnmapAllNoNuxWindowsSync()
1490{1495{
1491 for (auto const& window : m_Screen->windows())1496 for (auto const& window : m_Screen->windows())
14921497
=== modified file 'unity-shared/PluginAdapter.h'
--- unity-shared/PluginAdapter.h 2015-06-05 16:39:31 +0000
+++ unity-shared/PluginAdapter.h 2015-10-22 13:08:28 +0000
@@ -194,6 +194,8 @@
194194
195 Window GetTopWindowAbove(Window xid) const;195 Window GetTopWindowAbove(Window xid) const;
196196
197 Cursor GetCachedCursor(unsigned int) const;
198
197 void UnmapAllNoNuxWindowsSync();199 void UnmapAllNoNuxWindowsSync();
198 static bool IsNuxWindow(CompWindow* value);200 static bool IsNuxWindow(CompWindow* value);
199201
200202
=== modified file 'unity-shared/StandaloneWindowManager.cpp'
--- unity-shared/StandaloneWindowManager.cpp 2015-06-05 16:39:31 +0000
+++ unity-shared/StandaloneWindowManager.cpp 2015-10-22 13:08:28 +0000
@@ -742,6 +742,11 @@
742 return standalone_windows_;742 return standalone_windows_;
743}743}
744744
745Cursor StandaloneWindowManager::GetCachedCursor(unsigned int cursor_name) const
746{
747 return 0;
748}
749
745void StandaloneWindowManager::SetCurrentViewport(nux::Point const& vp)750void StandaloneWindowManager::SetCurrentViewport(nux::Point const& vp)
746{751{
747 current_vp_ = vp;752 current_vp_ = vp;
748753
=== modified file 'unity-shared/StandaloneWindowManager.h'
--- unity-shared/StandaloneWindowManager.h 2015-06-05 16:39:31 +0000
+++ unity-shared/StandaloneWindowManager.h 2015-10-22 13:08:28 +0000
@@ -181,6 +181,8 @@
181 void SetCurrentViewport(nux::Point const& vp);181 void SetCurrentViewport(nux::Point const& vp);
182 void SetWorkareaGeometry(nux::Geometry const& geo);182 void SetWorkareaGeometry(nux::Geometry const& geo);
183183
184 Cursor GetCachedCursor(unsigned int cursor_name) const;
185
184 void ResetStatus();186 void ResetStatus();
185187
186protected:188protected:
187189
=== modified file 'unity-shared/WindowManager.h'
--- unity-shared/WindowManager.h 2015-06-05 16:39:31 +0000
+++ unity-shared/WindowManager.h 2015-10-22 13:08:28 +0000
@@ -171,6 +171,8 @@
171 virtual std::string GetStringProperty(Window, Atom) const = 0;171 virtual std::string GetStringProperty(Window, Atom) const = 0;
172 virtual std::vector<long> GetCardinalProperty(Window, Atom) const = 0;172 virtual std::vector<long> GetCardinalProperty(Window, Atom) const = 0;
173173
174 virtual Cursor GetCachedCursor(unsigned int cursor_name) const = 0;
175
174 virtual void UnmapAllNoNuxWindowsSync() = 0;176 virtual void UnmapAllNoNuxWindowsSync() = 0;
175177
176178