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
=== modified file 'debian/control'
--- debian/control 2017-06-19 09:00:18 +0000
+++ debian/control 2017-07-03 15:31:53 +0000
@@ -3,9 +3,10 @@
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.12.2),6 compiz-dev (>= 1:0.9.13.1+17.10.20170630),
7 debhelper (>= 9.0.0~),7 debhelper (>= 9.0.0~),
8 dbus-test-runner,8 dbus-test-runner,
9 dbus-x11,
9 dh-migrations,10 dh-migrations,
10 dh-translations (>= 94),11 dh-translations (>= 94),
11 dh-python,12 dh-python,
1213
=== modified file 'plugins/unityshell/src/unityshell.cpp'
--- plugins/unityshell/src/unityshell.cpp 2017-04-05 07:58:57 +0000
+++ plugins/unityshell/src/unityshell.cpp 2017-07-03 15:31:53 +0000
@@ -482,9 +482,10 @@
482482
483 Introspectable::AddChild(deco_manager_.get());483 Introspectable::AddChild(deco_manager_.get());
484 auto const& deco_style = decoration::Style::Get();484 auto const& deco_style = decoration::Style::Get();
485 auto deco_style_cb = sigc::hide(sigc::mem_fun(this, &UnityScreen::OnDecorationStyleChanged));485 auto deco_style_cb = sigc::hide(sigc::mem_fun(this, &UnityScreen::UpdateDecorationStyle));
486 deco_style->theme.changed.connect(deco_style_cb);486 deco_style->theme.changed.connect(deco_style_cb);
487 deco_style->title_font.changed.connect(deco_style_cb);487 deco_style->title_font.changed.connect(deco_style_cb);
488 UpdateDecorationStyle();
488489
489 minimize_speed_controller_.DurationChanged.connect(490 minimize_speed_controller_.DurationChanged.connect(
490 sigc::mem_fun(this, &UnityScreen::OnMinimizeDurationChanged)491 sigc::mem_fun(this, &UnityScreen::OnMinimizeDurationChanged)
@@ -864,17 +865,28 @@
864 wy = y + (last_bound.height - height) / 2;865 wy = y + (last_bound.height - height) / 2;
865}866}
866867
867void UnityScreen::OnDecorationStyleChanged()868void UnityScreen::UpdateDecorationStyle()
868{869{
869 for (UnityWindow* uwin : fake_decorated_windows_)870 for (UnityWindow* uwin : fake_decorated_windows_)
870 uwin->CleanupCachedTextures();871 uwin->CleanupCachedTextures();
871872
872 auto const& style = decoration::Style::Get();873 if (optionGetOverrideDecorationTheme())
873 deco_manager_->shadow_offset = style->ShadowOffset();874 {
874 deco_manager_->active_shadow_color = style->ActiveShadowColor();875 deco_manager_->active_shadow_color = NuxColorFromCompizColor(optionGetActiveShadowColor());
875 deco_manager_->active_shadow_radius = style->ActiveShadowRadius();876 deco_manager_->inactive_shadow_color = NuxColorFromCompizColor(optionGetInactiveShadowColor());
876 deco_manager_->inactive_shadow_color = style->InactiveShadowColor();877 deco_manager_->active_shadow_radius = optionGetActiveShadowRadius();
877 deco_manager_->inactive_shadow_radius = style->InactiveShadowRadius();878 deco_manager_->inactive_shadow_radius = optionGetInactiveShadowRadius();
879 deco_manager_->shadow_offset = nux::Point(optionGetShadowXOffset(), optionGetShadowYOffset());
880 }
881 else
882 {
883 auto const& style = decoration::Style::Get();
884 deco_manager_->shadow_offset = style->ShadowOffset();
885 deco_manager_->active_shadow_color = style->ActiveShadowColor();
886 deco_manager_->active_shadow_radius = style->ActiveShadowRadius();
887 deco_manager_->inactive_shadow_color = style->InactiveShadowColor();
888 deco_manager_->inactive_shadow_radius = style->InactiveShadowRadius();
889 }
878}890}
879891
880void UnityScreen::DamageBlurUpdateRegion(nux::Geometry const& blur_update)892void UnityScreen::DamageBlurUpdateRegion(nux::Geometry const& blur_update)
@@ -2061,13 +2073,6 @@
2061 case MapRequest:2073 case MapRequest:
2062 ShowdesktopHandler::InhibitLeaveShowdesktopMode (event->xmaprequest.window);2074 ShowdesktopHandler::InhibitLeaveShowdesktopMode (event->xmaprequest.window);
2063 break;2075 break;
2064 case PropertyNotify:
2065 if (bghash_ && event->xproperty.window == GDK_ROOT_WINDOW() &&
2066 event->xproperty.atom == bghash_->ColorAtomId())
2067 {
2068 bghash_->RefreshColor();
2069 }
2070 break;
2071 default:2076 default:
2072 if (screen->shapeEvent() + ShapeNotify == event->type)2077 if (screen->shapeEvent() + ShapeNotify == event->type)
2073 {2078 {
@@ -3617,43 +3622,16 @@
3617 break;3622 break;
3618 }3623 }
3619 case UnityshellOptions::OverrideDecorationTheme:3624 case UnityshellOptions::OverrideDecorationTheme:
3620 if (optionGetOverrideDecorationTheme())
3621 {
3622 deco_manager_->active_shadow_color = NuxColorFromCompizColor(optionGetActiveShadowColor());
3623 deco_manager_->inactive_shadow_color = NuxColorFromCompizColor(optionGetInactiveShadowColor());
3624 deco_manager_->active_shadow_radius = optionGetActiveShadowRadius();
3625 deco_manager_->inactive_shadow_radius = optionGetInactiveShadowRadius();
3626 deco_manager_->shadow_offset = nux::Point(optionGetShadowXOffset(), optionGetShadowYOffset());
3627 }
3628 else
3629 {
3630 OnDecorationStyleChanged();
3631 }
3632 break;
3633 case UnityshellOptions::ActiveShadowColor:3625 case UnityshellOptions::ActiveShadowColor:
3634 if (optionGetOverrideDecorationTheme())3626 case UnityshellOptions::ActiveShadowRadius:
3635 deco_manager_->active_shadow_color = NuxColorFromCompizColor(optionGetActiveShadowColor());
3636 break;
3637 case UnityshellOptions::InactiveShadowColor:3627 case UnityshellOptions::InactiveShadowColor:
3638 if (optionGetOverrideDecorationTheme())
3639 deco_manager_->inactive_shadow_color = NuxColorFromCompizColor(optionGetInactiveShadowColor());
3640 break;
3641 case UnityshellOptions::ActiveShadowRadius:
3642 if (optionGetOverrideDecorationTheme())
3643 deco_manager_->active_shadow_radius = optionGetActiveShadowRadius();
3644 break;
3645 case UnityshellOptions::InactiveShadowRadius:3628 case UnityshellOptions::InactiveShadowRadius:
3646 if (optionGetOverrideDecorationTheme())
3647 deco_manager_->inactive_shadow_radius = optionGetInactiveShadowRadius();
3648 break;
3649 case UnityshellOptions::ShadowXOffset:3629 case UnityshellOptions::ShadowXOffset:
3650 if (optionGetOverrideDecorationTheme())
3651 deco_manager_->shadow_offset = nux::Point(optionGetShadowXOffset(), optionGetShadowYOffset());
3652 break;
3653 case UnityshellOptions::ShadowYOffset:3630 case UnityshellOptions::ShadowYOffset:
3654 if (optionGetOverrideDecorationTheme())3631 {
3655 deco_manager_->shadow_offset = nux::Point(optionGetShadowXOffset(), optionGetShadowYOffset());3632 UpdateDecorationStyle();
3656 break;3633 break;
3634 }
3657 case UnityshellOptions::LauncherHideMode:3635 case UnityshellOptions::LauncherHideMode:
3658 {3636 {
3659 launcher_options->hide_mode = (launcher::LauncherHideMode) optionGetLauncherHideMode();3637 launcher_options->hide_mode = (launcher::LauncherHideMode) optionGetLauncherHideMode();
@@ -3854,6 +3832,12 @@
3854 ScheduleRelayout(500);3832 ScheduleRelayout(500);
3855}3833}
38563834
3835void UnityScreen::averageColorChangeNotify(const unsigned short *color)
3836{
3837 bghash_->UpdateColor(color, nux::animation::Animation::State::Running);
3838 screen->averageColorChangeNotify (color);
3839}
3840
3857bool UnityScreen::layoutSlotsAndAssignWindows()3841bool UnityScreen::layoutSlotsAndAssignWindows()
3858{3842{
3859 auto const& scaled_windows = sScreen->getWindows();3843 auto const& scaled_windows = sScreen->getWindows();
@@ -4078,6 +4062,7 @@
4078 nux::GetWindowCompositor().sigHiddenViewWindow.connect(sigc::mem_fun(this, &UnityScreen::OnViewHidden));4062 nux::GetWindowCompositor().sigHiddenViewWindow.connect(sigc::mem_fun(this, &UnityScreen::OnViewHidden));
40794063
4080 bghash_.reset(new BGHash());4064 bghash_.reset(new BGHash());
4065 bghash_->UpdateColor(screen->averageColor(), nux::animation::Animation::State::Stopped);
4081 LOG_INFO(logger) << "InitUnityComponents-BGHash " << timer.ElapsedSeconds() << "s";4066 LOG_INFO(logger) << "InitUnityComponents-BGHash " << timer.ElapsedSeconds() << "s";
40824067
4083 auto xdnd_collection_window = std::make_shared<XdndCollectionWindowImp>();4068 auto xdnd_collection_window = std::make_shared<XdndCollectionWindowImp>();
40844069
=== modified file 'plugins/unityshell/src/unityshell.h'
--- plugins/unityshell/src/unityshell.h 2017-01-09 15:09:26 +0000
+++ plugins/unityshell/src/unityshell.h 2017-07-03 15:31:53 +0000
@@ -163,6 +163,7 @@
163 bool initPluginForScreen(CompPlugin* p) override;163 bool initPluginForScreen(CompPlugin* p) override;
164164
165 void outputChangeNotify() override;165 void outputChangeNotify() override;
166 void averageColorChangeNotify(const unsigned short *color) override;
166167
167 CompAction::Vector& getActions() override;168 CompAction::Vector& getActions() override;
168169
@@ -282,7 +283,7 @@
282283
283 bool SaveInputThenFocus(const guint xid);284 bool SaveInputThenFocus(const guint xid);
284285
285 void OnDecorationStyleChanged();286 void UpdateDecorationStyle();
286287
287 void InitGesturesSupport();288 void InitGesturesSupport();
288 void UpdateGesturesSupport();289 void UpdateGesturesSupport();
289290
=== modified file 'tools/CMakeLists.txt'
--- tools/CMakeLists.txt 2017-03-27 19:33:50 +0000
+++ tools/CMakeLists.txt 2017-07-03 15:31:53 +0000
@@ -21,7 +21,7 @@
21set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CFLAGS}")21set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CFLAGS}")
22set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CFLAGS}")22set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CFLAGS}")
2323
24set(LIBS ${UAPSC_DEPS_LIBRARIES})24set(LIBS ${UAPSC_DEPS_LIBRARIES} -lm)
2525
26set(LIB_PATHS ${UAPSC_DEPS_LIBRARY_DIRS})26set(LIB_PATHS ${UAPSC_DEPS_LIBRARY_DIRS})
27link_directories(${LIB_PATHS})27link_directories(${LIB_PATHS})
2828
=== modified file 'tools/compiz_config_profile_setter.c'
--- tools/compiz_config_profile_setter.c 2017-04-25 17:58:23 +0000
+++ tools/compiz_config_profile_setter.c 2017-07-03 15:31:53 +0000
@@ -130,7 +130,7 @@
130static gboolean130static gboolean
131set_compiz_profile (CCSContext *ccs_context, const gchar *profile_name)131set_compiz_profile (CCSContext *ccs_context, const gchar *profile_name)
132{132{
133 CCSPluginList plugins;133 CCSPluginList plugins, p;
134 const char *ccs_backend;134 const char *ccs_backend;
135135
136 ccs_backend = ccsGetBackend (ccs_context);136 ccs_backend = ccsGetBackend (ccs_context);
@@ -144,7 +144,7 @@
144144
145 plugins = ccsContextGetPlugins (ccs_context);145 plugins = ccsContextGetPlugins (ccs_context);
146146
147 for (CCSPluginList p = plugins; p; p = p->next)147 for (p = plugins; p; p = p->next)
148 {148 {
149 CCSPlugin* plugin = p->data;149 CCSPlugin* plugin = p->data;
150 ccsReadPluginSettings (plugin);150 ccsReadPluginSettings (plugin);
151151
=== modified file 'unity-shared/BGHash.cpp'
--- unity-shared/BGHash.cpp 2016-07-04 14:51:28 +0000
+++ unity-shared/BGHash.cpp 2017-07-03 15:31:53 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2011-2012 Canonical Ltd2 * Copyright (C) 2011-2017 Canonical Ltd
3 *3 *
4 * This program is free software: you can redistribute it and/or modify4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as5 * it under the terms of the GNU General Public License version 3 as
@@ -14,6 +14,7 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *15 *
16 * Authored by: Gordon Allott <gord.alott@canonical.com>16 * Authored by: Gordon Allott <gord.alott@canonical.com>
17 * Marco Trevisan <marco.trevisan@canonical.com>
17 */18 */
1819
1920
@@ -23,18 +24,13 @@
23#include "unity-shared/UnitySettings.h"24#include "unity-shared/UnitySettings.h"
24#include "unity-shared/WindowManager.h"25#include "unity-shared/WindowManager.h"
2526
26#ifndef XA_STRING27namespace na = nux::animation;
27#define XA_STRING ((Atom) 31)
28#endif
29
30DECLARE_LOGGER(logger, "unity.bghash");
3128
32namespace unity29namespace unity
33{30{
34
35namespace31namespace
36{32{
37 Atom COLORS_ATOM = 0;33 DECLARE_LOGGER(logger, "unity.bghash");
38 const unsigned TRANSITION_DURATION = 500;34 const unsigned TRANSITION_DURATION = 500;
39}35}
4036
@@ -42,77 +38,44 @@
42 : transition_animator_(Settings::Instance().low_gfx() ? 0 : TRANSITION_DURATION)38 : transition_animator_(Settings::Instance().low_gfx() ? 0 : TRANSITION_DURATION)
43 , override_color_(nux::color::Transparent)39 , override_color_(nux::color::Transparent)
44{40{
45 COLORS_ATOM = gdk_x11_get_xatom_by_name("_GNOME_BACKGROUND_REPRESENTATIVE_COLORS");
46 transition_animator_.updated.connect(sigc::mem_fun(this, &BGHash::OnTransitionUpdated));41 transition_animator_.updated.connect(sigc::mem_fun(this, &BGHash::OnTransitionUpdated));
47 WindowManager::Default().average_color = unity::colors::Aubergine;42 WindowManager::Default().average_color = unity::colors::Aubergine;
48 RefreshColor(/* skip_animation */ true);
4943
50 Settings::Instance().low_gfx.changed.connect(sigc::track_obj([this] (bool low_gfx) {44 Settings::Instance().low_gfx.changed.connect(sigc::track_obj([this] (bool low_gfx) {
51 transition_animator_.SetDuration(low_gfx ? 0 : TRANSITION_DURATION);45 transition_animator_.SetDuration(low_gfx ? 0 : TRANSITION_DURATION);
52 }, *this));46 }, *this));
53}47}
5448
55uint64_t BGHash::ColorAtomId() const
56{
57 return COLORS_ATOM;
58}
59
60void BGHash::OverrideColor(nux::Color const& color)49void BGHash::OverrideColor(nux::Color const& color)
61{50{
62 override_color_ = color;51 override_color_ = color;
63 RefreshColor();52 TransitionToNewColor(override_color_, nux::animation::Animation::State::Running);
64}53}
6554
66void BGHash::RefreshColor(bool skip_animation)55void BGHash::UpdateColor(const unsigned short *color, na::Animation::State animate)
67{56{
68 if (override_color_.alpha > 0.0f)57 if (override_color_.alpha > 0.0f)
69 {58 {
70 TransitionToNewColor(override_color_, skip_animation);59 TransitionToNewColor(override_color_, animate);
71 return;60 return;
72 }61 }
7362
74 // XXX: move this part to PluginAdapter63 if (!color)
75 Atom real_type;64 return;
76 gint result;65
77 gint real_format;66 nux::Color new_color;
78 gulong items_read;67 const double MAX_USHORT = std::numeric_limits<unsigned short>::max ();
79 gulong items_left;68 new_color.red = color[0] / MAX_USHORT;
80 gchar* colors;69 new_color.green = color[1] / MAX_USHORT;
81 Display* display;70 new_color.blue = color[2] / MAX_USHORT;
82 GdkRGBA color_gdk;71
8372 TransitionToNewColor(MatchColor(new_color), animate);
84 colors = nullptr;
85 display = gdk_x11_display_get_xdisplay(gdk_display_get_default());
86
87 gdk_error_trap_push();
88 result = XGetWindowProperty (display,
89 GDK_ROOT_WINDOW(),
90 COLORS_ATOM,
91 0L,
92 G_MAXLONG,
93 False,
94 XA_STRING,
95 &real_type,
96 &real_format,
97 &items_read,
98 &items_left,
99 (guchar **) &colors);
100 gdk_flush ();
101 gdk_error_trap_pop_ignored ();
102
103 if (result == Success && items_read)
104 {
105 gdk_rgba_parse(&color_gdk, colors);
106 nux::Color new_color(color_gdk.red, color_gdk.green, color_gdk.blue, 1.0f);
107 TransitionToNewColor(MatchColor(new_color), skip_animation);
108 }
109
110 XFree(colors);
111}73}
11274
113void BGHash::TransitionToNewColor(nux::color::Color const& new_color, bool skip_animation)75void BGHash::TransitionToNewColor(nux::color::Color const& new_color, na::Animation::State animate)
114{76{
115 auto const& current_color = WindowManager::Default().average_color();77 auto const& current_color = WindowManager::Default().average_color();
78 bool skip_animation = (animate != na::Animation::State::Running);
116 LOG_DEBUG(logger) << "transitioning from: " << current_color.red << " to " << new_color.red;79 LOG_DEBUG(logger) << "transitioning from: " << current_color.red << " to " << new_color.red;
11780
118 transition_animator_.Stop();81 transition_animator_.Stop();
11982
=== modified file 'unity-shared/BGHash.h'
--- unity-shared/BGHash.h 2016-07-04 14:51:28 +0000
+++ unity-shared/BGHash.h 2017-07-03 15:31:53 +0000
@@ -36,14 +36,13 @@
36 BGHash();36 BGHash();
3737
38 nux::Color CurrentColor() const;38 nux::Color CurrentColor() const;
39 uint64_t ColorAtomId() const;39 void UpdateColor(const unsigned short *compiz_color, nux::animation::Animation::State);
40 void RefreshColor(bool skip_animation = false);
41 void OverrideColor(nux::Color const& color);40 void OverrideColor(nux::Color const& color);
4241
43 private:42 private:
43 void TransitionToNewColor(nux::Color const& new_color, nux::animation::Animation::State);
44 nux::Color MatchColor(nux::Color const& base_color) const;
44 void OnTransitionUpdated(nux::Color const& new_color);45 void OnTransitionUpdated(nux::Color const& new_color);
45 void TransitionToNewColor(nux::Color const& new_color, bool skip_animation = false);
46 nux::Color MatchColor(nux::Color const& base_color) const;
4746
48 private:47 private:
49 nux::animation::AnimateValue<nux::Color> transition_animator_;48 nux::animation::AnimateValue<nux::Color> transition_animator_;