Merge lp:~3v1n0/unity/compiz-average-color 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: 4244
Proposed branch: lp:~3v1n0/unity/compiz-average-color
Merge into: lp:unity
Diff against target: 364 lines (+63/-114)
7 files modified
debian/control (+2/-1)
plugins/unityshell/src/unityshell.cpp (+31/-46)
plugins/unityshell/src/unityshell.h (+2/-1)
tools/CMakeLists.txt (+1/-1)
tools/compiz_config_profile_setter.c (+2/-2)
unity-shared/BGHash.cpp (+22/-59)
unity-shared/BGHash.h (+3/-4)
To merge this branch: bzr merge lp:~3v1n0/unity/compiz-average-color
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Review via email: mp+326571@code.launchpad.net

Commit message

BGHash, UnityScreen: get desktop averageColor from compiz

compiz now supports getting this value, let's use it instead of
doing this again here.

Description of the change

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

LGTM.

review: Approve

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 2017-06-19 09:00:18 +0000
3+++ debian/control 2017-07-03 15:31:53 +0000
4@@ -3,9 +3,10 @@
5 Priority: optional
6 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
7 Build-Depends: cmake,
8- compiz-dev (>= 1:0.9.12.2),
9+ compiz-dev (>= 1:0.9.13.1+17.10.20170630),
10 debhelper (>= 9.0.0~),
11 dbus-test-runner,
12+ dbus-x11,
13 dh-migrations,
14 dh-translations (>= 94),
15 dh-python,
16
17=== modified file 'plugins/unityshell/src/unityshell.cpp'
18--- plugins/unityshell/src/unityshell.cpp 2017-04-05 07:58:57 +0000
19+++ plugins/unityshell/src/unityshell.cpp 2017-07-03 15:31:53 +0000
20@@ -482,9 +482,10 @@
21
22 Introspectable::AddChild(deco_manager_.get());
23 auto const& deco_style = decoration::Style::Get();
24- auto deco_style_cb = sigc::hide(sigc::mem_fun(this, &UnityScreen::OnDecorationStyleChanged));
25+ auto deco_style_cb = sigc::hide(sigc::mem_fun(this, &UnityScreen::UpdateDecorationStyle));
26 deco_style->theme.changed.connect(deco_style_cb);
27 deco_style->title_font.changed.connect(deco_style_cb);
28+ UpdateDecorationStyle();
29
30 minimize_speed_controller_.DurationChanged.connect(
31 sigc::mem_fun(this, &UnityScreen::OnMinimizeDurationChanged)
32@@ -864,17 +865,28 @@
33 wy = y + (last_bound.height - height) / 2;
34 }
35
36-void UnityScreen::OnDecorationStyleChanged()
37+void UnityScreen::UpdateDecorationStyle()
38 {
39 for (UnityWindow* uwin : fake_decorated_windows_)
40 uwin->CleanupCachedTextures();
41
42- auto const& style = decoration::Style::Get();
43- deco_manager_->shadow_offset = style->ShadowOffset();
44- deco_manager_->active_shadow_color = style->ActiveShadowColor();
45- deco_manager_->active_shadow_radius = style->ActiveShadowRadius();
46- deco_manager_->inactive_shadow_color = style->InactiveShadowColor();
47- deco_manager_->inactive_shadow_radius = style->InactiveShadowRadius();
48+ if (optionGetOverrideDecorationTheme())
49+ {
50+ deco_manager_->active_shadow_color = NuxColorFromCompizColor(optionGetActiveShadowColor());
51+ deco_manager_->inactive_shadow_color = NuxColorFromCompizColor(optionGetInactiveShadowColor());
52+ deco_manager_->active_shadow_radius = optionGetActiveShadowRadius();
53+ deco_manager_->inactive_shadow_radius = optionGetInactiveShadowRadius();
54+ deco_manager_->shadow_offset = nux::Point(optionGetShadowXOffset(), optionGetShadowYOffset());
55+ }
56+ else
57+ {
58+ auto const& style = decoration::Style::Get();
59+ deco_manager_->shadow_offset = style->ShadowOffset();
60+ deco_manager_->active_shadow_color = style->ActiveShadowColor();
61+ deco_manager_->active_shadow_radius = style->ActiveShadowRadius();
62+ deco_manager_->inactive_shadow_color = style->InactiveShadowColor();
63+ deco_manager_->inactive_shadow_radius = style->InactiveShadowRadius();
64+ }
65 }
66
67 void UnityScreen::DamageBlurUpdateRegion(nux::Geometry const& blur_update)
68@@ -2061,13 +2073,6 @@
69 case MapRequest:
70 ShowdesktopHandler::InhibitLeaveShowdesktopMode (event->xmaprequest.window);
71 break;
72- case PropertyNotify:
73- if (bghash_ && event->xproperty.window == GDK_ROOT_WINDOW() &&
74- event->xproperty.atom == bghash_->ColorAtomId())
75- {
76- bghash_->RefreshColor();
77- }
78- break;
79 default:
80 if (screen->shapeEvent() + ShapeNotify == event->type)
81 {
82@@ -3617,43 +3622,16 @@
83 break;
84 }
85 case UnityshellOptions::OverrideDecorationTheme:
86- if (optionGetOverrideDecorationTheme())
87- {
88- deco_manager_->active_shadow_color = NuxColorFromCompizColor(optionGetActiveShadowColor());
89- deco_manager_->inactive_shadow_color = NuxColorFromCompizColor(optionGetInactiveShadowColor());
90- deco_manager_->active_shadow_radius = optionGetActiveShadowRadius();
91- deco_manager_->inactive_shadow_radius = optionGetInactiveShadowRadius();
92- deco_manager_->shadow_offset = nux::Point(optionGetShadowXOffset(), optionGetShadowYOffset());
93- }
94- else
95- {
96- OnDecorationStyleChanged();
97- }
98- break;
99 case UnityshellOptions::ActiveShadowColor:
100- if (optionGetOverrideDecorationTheme())
101- deco_manager_->active_shadow_color = NuxColorFromCompizColor(optionGetActiveShadowColor());
102- break;
103+ case UnityshellOptions::ActiveShadowRadius:
104 case UnityshellOptions::InactiveShadowColor:
105- if (optionGetOverrideDecorationTheme())
106- deco_manager_->inactive_shadow_color = NuxColorFromCompizColor(optionGetInactiveShadowColor());
107- break;
108- case UnityshellOptions::ActiveShadowRadius:
109- if (optionGetOverrideDecorationTheme())
110- deco_manager_->active_shadow_radius = optionGetActiveShadowRadius();
111- break;
112 case UnityshellOptions::InactiveShadowRadius:
113- if (optionGetOverrideDecorationTheme())
114- deco_manager_->inactive_shadow_radius = optionGetInactiveShadowRadius();
115- break;
116 case UnityshellOptions::ShadowXOffset:
117- if (optionGetOverrideDecorationTheme())
118- deco_manager_->shadow_offset = nux::Point(optionGetShadowXOffset(), optionGetShadowYOffset());
119- break;
120 case UnityshellOptions::ShadowYOffset:
121- if (optionGetOverrideDecorationTheme())
122- deco_manager_->shadow_offset = nux::Point(optionGetShadowXOffset(), optionGetShadowYOffset());
123+ {
124+ UpdateDecorationStyle();
125 break;
126+ }
127 case UnityshellOptions::LauncherHideMode:
128 {
129 launcher_options->hide_mode = (launcher::LauncherHideMode) optionGetLauncherHideMode();
130@@ -3854,6 +3832,12 @@
131 ScheduleRelayout(500);
132 }
133
134+void UnityScreen::averageColorChangeNotify(const unsigned short *color)
135+{
136+ bghash_->UpdateColor(color, nux::animation::Animation::State::Running);
137+ screen->averageColorChangeNotify (color);
138+}
139+
140 bool UnityScreen::layoutSlotsAndAssignWindows()
141 {
142 auto const& scaled_windows = sScreen->getWindows();
143@@ -4078,6 +4062,7 @@
144 nux::GetWindowCompositor().sigHiddenViewWindow.connect(sigc::mem_fun(this, &UnityScreen::OnViewHidden));
145
146 bghash_.reset(new BGHash());
147+ bghash_->UpdateColor(screen->averageColor(), nux::animation::Animation::State::Stopped);
148 LOG_INFO(logger) << "InitUnityComponents-BGHash " << timer.ElapsedSeconds() << "s";
149
150 auto xdnd_collection_window = std::make_shared<XdndCollectionWindowImp>();
151
152=== modified file 'plugins/unityshell/src/unityshell.h'
153--- plugins/unityshell/src/unityshell.h 2017-01-09 15:09:26 +0000
154+++ plugins/unityshell/src/unityshell.h 2017-07-03 15:31:53 +0000
155@@ -163,6 +163,7 @@
156 bool initPluginForScreen(CompPlugin* p) override;
157
158 void outputChangeNotify() override;
159+ void averageColorChangeNotify(const unsigned short *color) override;
160
161 CompAction::Vector& getActions() override;
162
163@@ -282,7 +283,7 @@
164
165 bool SaveInputThenFocus(const guint xid);
166
167- void OnDecorationStyleChanged();
168+ void UpdateDecorationStyle();
169
170 void InitGesturesSupport();
171 void UpdateGesturesSupport();
172
173=== modified file 'tools/CMakeLists.txt'
174--- tools/CMakeLists.txt 2017-03-27 19:33:50 +0000
175+++ tools/CMakeLists.txt 2017-07-03 15:31:53 +0000
176@@ -21,7 +21,7 @@
177 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CFLAGS}")
178 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CFLAGS}")
179
180-set(LIBS ${UAPSC_DEPS_LIBRARIES})
181+set(LIBS ${UAPSC_DEPS_LIBRARIES} -lm)
182
183 set(LIB_PATHS ${UAPSC_DEPS_LIBRARY_DIRS})
184 link_directories(${LIB_PATHS})
185
186=== modified file 'tools/compiz_config_profile_setter.c'
187--- tools/compiz_config_profile_setter.c 2017-04-25 17:58:23 +0000
188+++ tools/compiz_config_profile_setter.c 2017-07-03 15:31:53 +0000
189@@ -130,7 +130,7 @@
190 static gboolean
191 set_compiz_profile (CCSContext *ccs_context, const gchar *profile_name)
192 {
193- CCSPluginList plugins;
194+ CCSPluginList plugins, p;
195 const char *ccs_backend;
196
197 ccs_backend = ccsGetBackend (ccs_context);
198@@ -144,7 +144,7 @@
199
200 plugins = ccsContextGetPlugins (ccs_context);
201
202- for (CCSPluginList p = plugins; p; p = p->next)
203+ for (p = plugins; p; p = p->next)
204 {
205 CCSPlugin* plugin = p->data;
206 ccsReadPluginSettings (plugin);
207
208=== modified file 'unity-shared/BGHash.cpp'
209--- unity-shared/BGHash.cpp 2016-07-04 14:51:28 +0000
210+++ unity-shared/BGHash.cpp 2017-07-03 15:31:53 +0000
211@@ -1,5 +1,5 @@
212 /*
213- * Copyright (C) 2011-2012 Canonical Ltd
214+ * Copyright (C) 2011-2017 Canonical Ltd
215 *
216 * This program is free software: you can redistribute it and/or modify
217 * it under the terms of the GNU General Public License version 3 as
218@@ -14,6 +14,7 @@
219 * along with this program. If not, see <http://www.gnu.org/licenses/>.
220 *
221 * Authored by: Gordon Allott <gord.alott@canonical.com>
222+ * Marco Trevisan <marco.trevisan@canonical.com>
223 */
224
225
226@@ -23,18 +24,13 @@
227 #include "unity-shared/UnitySettings.h"
228 #include "unity-shared/WindowManager.h"
229
230-#ifndef XA_STRING
231-#define XA_STRING ((Atom) 31)
232-#endif
233-
234-DECLARE_LOGGER(logger, "unity.bghash");
235+namespace na = nux::animation;
236
237 namespace unity
238 {
239-
240 namespace
241 {
242- Atom COLORS_ATOM = 0;
243+ DECLARE_LOGGER(logger, "unity.bghash");
244 const unsigned TRANSITION_DURATION = 500;
245 }
246
247@@ -42,77 +38,44 @@
248 : transition_animator_(Settings::Instance().low_gfx() ? 0 : TRANSITION_DURATION)
249 , override_color_(nux::color::Transparent)
250 {
251- COLORS_ATOM = gdk_x11_get_xatom_by_name("_GNOME_BACKGROUND_REPRESENTATIVE_COLORS");
252 transition_animator_.updated.connect(sigc::mem_fun(this, &BGHash::OnTransitionUpdated));
253 WindowManager::Default().average_color = unity::colors::Aubergine;
254- RefreshColor(/* skip_animation */ true);
255
256 Settings::Instance().low_gfx.changed.connect(sigc::track_obj([this] (bool low_gfx) {
257 transition_animator_.SetDuration(low_gfx ? 0 : TRANSITION_DURATION);
258 }, *this));
259 }
260
261-uint64_t BGHash::ColorAtomId() const
262-{
263- return COLORS_ATOM;
264-}
265-
266 void BGHash::OverrideColor(nux::Color const& color)
267 {
268 override_color_ = color;
269- RefreshColor();
270+ TransitionToNewColor(override_color_, nux::animation::Animation::State::Running);
271 }
272
273-void BGHash::RefreshColor(bool skip_animation)
274+void BGHash::UpdateColor(const unsigned short *color, na::Animation::State animate)
275 {
276 if (override_color_.alpha > 0.0f)
277 {
278- TransitionToNewColor(override_color_, skip_animation);
279- return;
280- }
281-
282- // XXX: move this part to PluginAdapter
283- Atom real_type;
284- gint result;
285- gint real_format;
286- gulong items_read;
287- gulong items_left;
288- gchar* colors;
289- Display* display;
290- GdkRGBA color_gdk;
291-
292- colors = nullptr;
293- display = gdk_x11_display_get_xdisplay(gdk_display_get_default());
294-
295- gdk_error_trap_push();
296- result = XGetWindowProperty (display,
297- GDK_ROOT_WINDOW(),
298- COLORS_ATOM,
299- 0L,
300- G_MAXLONG,
301- False,
302- XA_STRING,
303- &real_type,
304- &real_format,
305- &items_read,
306- &items_left,
307- (guchar **) &colors);
308- gdk_flush ();
309- gdk_error_trap_pop_ignored ();
310-
311- if (result == Success && items_read)
312- {
313- gdk_rgba_parse(&color_gdk, colors);
314- nux::Color new_color(color_gdk.red, color_gdk.green, color_gdk.blue, 1.0f);
315- TransitionToNewColor(MatchColor(new_color), skip_animation);
316- }
317-
318- XFree(colors);
319+ TransitionToNewColor(override_color_, animate);
320+ return;
321+ }
322+
323+ if (!color)
324+ return;
325+
326+ nux::Color new_color;
327+ const double MAX_USHORT = std::numeric_limits<unsigned short>::max ();
328+ new_color.red = color[0] / MAX_USHORT;
329+ new_color.green = color[1] / MAX_USHORT;
330+ new_color.blue = color[2] / MAX_USHORT;
331+
332+ TransitionToNewColor(MatchColor(new_color), animate);
333 }
334
335-void BGHash::TransitionToNewColor(nux::color::Color const& new_color, bool skip_animation)
336+void BGHash::TransitionToNewColor(nux::color::Color const& new_color, na::Animation::State animate)
337 {
338 auto const& current_color = WindowManager::Default().average_color();
339+ bool skip_animation = (animate != na::Animation::State::Running);
340 LOG_DEBUG(logger) << "transitioning from: " << current_color.red << " to " << new_color.red;
341
342 transition_animator_.Stop();
343
344=== modified file 'unity-shared/BGHash.h'
345--- unity-shared/BGHash.h 2016-07-04 14:51:28 +0000
346+++ unity-shared/BGHash.h 2017-07-03 15:31:53 +0000
347@@ -36,14 +36,13 @@
348 BGHash();
349
350 nux::Color CurrentColor() const;
351- uint64_t ColorAtomId() const;
352- void RefreshColor(bool skip_animation = false);
353+ void UpdateColor(const unsigned short *compiz_color, nux::animation::Animation::State);
354 void OverrideColor(nux::Color const& color);
355
356 private:
357+ void TransitionToNewColor(nux::Color const& new_color, nux::animation::Animation::State);
358+ nux::Color MatchColor(nux::Color const& base_color) const;
359 void OnTransitionUpdated(nux::Color const& new_color);
360- void TransitionToNewColor(nux::Color const& new_color, bool skip_animation = false);
361- nux::Color MatchColor(nux::Color const& base_color) const;
362
363 private:
364 nux::animation::AnimateValue<nux::Color> transition_animator_;