diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2017-06-30 03:55:44 +0200 |
|---|---|---|
| committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2017-06-30 03:55:44 +0200 |
| commit | 0e4c7bc9d33fe23d39b4829dd82e36a46bebdb47 (patch) | |
| tree | aa4bfed8f8891ae04a1e37e4c57b0b9c9e6af086 | |
| parent | d8012e18d112bbd165ceae41abd0ff8a35e0d4ba (diff) | |
BGHash, UnityScreen: get desktop averageColor from compiz
compiz now supports getting this value, let's use it instead of doing this again here. (bzr r4243.1.2)
| -rw-r--r-- | plugins/unityshell/src/unityshell.cpp | 14 | ||||
| -rw-r--r-- | plugins/unityshell/src/unityshell.h | 1 | ||||
| -rw-r--r-- | unity-shared/BGHash.cpp | 73 | ||||
| -rw-r--r-- | unity-shared/BGHash.h | 7 |
4 files changed, 29 insertions, 66 deletions
diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index 41aed941d..d0edf67ee 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -2061,13 +2061,6 @@ void UnityScreen::handleEvent(XEvent* event) case MapRequest: ShowdesktopHandler::InhibitLeaveShowdesktopMode (event->xmaprequest.window); break; - case PropertyNotify: - if (bghash_ && event->xproperty.window == GDK_ROOT_WINDOW() && - event->xproperty.atom == bghash_->ColorAtomId()) - { - bghash_->RefreshColor(); - } - break; default: if (screen->shapeEvent() + ShapeNotify == event->type) { @@ -3854,6 +3847,12 @@ void UnityScreen::outputChangeNotify() ScheduleRelayout(500); } +void UnityScreen::averageColorChangeNotify(const unsigned short *color) +{ + bghash_->UpdateColor(color, nux::animation::Animation::State::Running); + screen->averageColorChangeNotify (color); +} + bool UnityScreen::layoutSlotsAndAssignWindows() { auto const& scaled_windows = sScreen->getWindows(); @@ -4078,6 +4077,7 @@ void UnityScreen::InitUnityComponents() nux::GetWindowCompositor().sigHiddenViewWindow.connect(sigc::mem_fun(this, &UnityScreen::OnViewHidden)); bghash_.reset(new BGHash()); + bghash_->UpdateColor(screen->averageColor(), nux::animation::Animation::State::Stopped); LOG_INFO(logger) << "InitUnityComponents-BGHash " << timer.ElapsedSeconds() << "s"; auto xdnd_collection_window = std::make_shared<XdndCollectionWindowImp>(); diff --git a/plugins/unityshell/src/unityshell.h b/plugins/unityshell/src/unityshell.h index a630a99c0..72016c616 100644 --- a/plugins/unityshell/src/unityshell.h +++ b/plugins/unityshell/src/unityshell.h @@ -163,6 +163,7 @@ protected: bool initPluginForScreen(CompPlugin* p) override; void outputChangeNotify() override; + void averageColorChangeNotify(const unsigned short *color) override; CompAction::Vector& getActions() override; diff --git a/unity-shared/BGHash.cpp b/unity-shared/BGHash.cpp index d681404da..818d9a95d 100644 --- a/unity-shared/BGHash.cpp +++ b/unity-shared/BGHash.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2012 Canonical Ltd + * Copyright (C) 2011-2017 Canonical Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -14,6 +14,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * * Authored by: Gordon Allott <gord.alott@canonical.com> + * Marco Trevisan <marco.trevisan@canonical.com> */ @@ -23,18 +24,13 @@ #include "unity-shared/UnitySettings.h" #include "unity-shared/WindowManager.h" -#ifndef XA_STRING -#define XA_STRING ((Atom) 31) -#endif - -DECLARE_LOGGER(logger, "unity.bghash"); +namespace na = nux::animation; namespace unity { - namespace { - Atom COLORS_ATOM = 0; + DECLARE_LOGGER(logger, "unity.bghash"); const unsigned TRANSITION_DURATION = 500; } @@ -42,77 +38,44 @@ BGHash::BGHash() : transition_animator_(Settings::Instance().low_gfx() ? 0 : TRANSITION_DURATION) , override_color_(nux::color::Transparent) { - COLORS_ATOM = gdk_x11_get_xatom_by_name("_GNOME_BACKGROUND_REPRESENTATIVE_COLORS"); transition_animator_.updated.connect(sigc::mem_fun(this, &BGHash::OnTransitionUpdated)); WindowManager::Default().average_color = unity::colors::Aubergine; - RefreshColor(/* skip_animation */ true); Settings::Instance().low_gfx.changed.connect(sigc::track_obj([this] (bool low_gfx) { transition_animator_.SetDuration(low_gfx ? 0 : TRANSITION_DURATION); }, *this)); } -uint64_t BGHash::ColorAtomId() const -{ - return COLORS_ATOM; -} - void BGHash::OverrideColor(nux::Color const& color) { override_color_ = color; - RefreshColor(); + TransitionToNewColor(override_color_, nux::animation::Animation::State::Running); } -void BGHash::RefreshColor(bool skip_animation) +void BGHash::UpdateColor(const unsigned short *color, na::Animation::State animate) { if (override_color_.alpha > 0.0f) { - TransitionToNewColor(override_color_, skip_animation); + TransitionToNewColor(override_color_, animate); return; } - // XXX: move this part to PluginAdapter - Atom real_type; - gint result; - gint real_format; - gulong items_read; - gulong items_left; - gchar* colors; - Display* display; - GdkRGBA color_gdk; - - colors = nullptr; - display = gdk_x11_display_get_xdisplay(gdk_display_get_default()); - - gdk_error_trap_push(); - result = XGetWindowProperty (display, - GDK_ROOT_WINDOW(), - COLORS_ATOM, - 0L, - G_MAXLONG, - False, - XA_STRING, - &real_type, - &real_format, - &items_read, - &items_left, - (guchar **) &colors); - gdk_flush (); - gdk_error_trap_pop_ignored (); - - if (result == Success && items_read) - { - gdk_rgba_parse(&color_gdk, colors); - nux::Color new_color(color_gdk.red, color_gdk.green, color_gdk.blue, 1.0f); - TransitionToNewColor(MatchColor(new_color), skip_animation); - } + if (!color) + return; + + nux::Color new_color; + const double MAX_USHORT = std::numeric_limits<unsigned short>::max (); + new_color.red = color[0] / MAX_USHORT; + new_color.green = color[1] / MAX_USHORT; + new_color.blue = color[2] / MAX_USHORT; - XFree(colors); + TransitionToNewColor(MatchColor(new_color), animate); } -void BGHash::TransitionToNewColor(nux::color::Color const& new_color, bool skip_animation) +void BGHash::TransitionToNewColor(nux::color::Color const& new_color, na::Animation::State animate) { auto const& current_color = WindowManager::Default().average_color(); + bool skip_animation = (animate != na::Animation::State::Running); LOG_DEBUG(logger) << "transitioning from: " << current_color.red << " to " << new_color.red; transition_animator_.Stop(); diff --git a/unity-shared/BGHash.h b/unity-shared/BGHash.h index 1c981c5a4..695c6b200 100644 --- a/unity-shared/BGHash.h +++ b/unity-shared/BGHash.h @@ -36,14 +36,13 @@ namespace unity BGHash(); nux::Color CurrentColor() const; - uint64_t ColorAtomId() const; - void RefreshColor(bool skip_animation = false); + void UpdateColor(const unsigned short *compiz_color, nux::animation::Animation::State); void OverrideColor(nux::Color const& color); private: - void OnTransitionUpdated(nux::Color const& new_color); - void TransitionToNewColor(nux::Color const& new_color, bool skip_animation = false); + void TransitionToNewColor(nux::Color const& new_color, nux::animation::Animation::State); nux::Color MatchColor(nux::Color const& base_color) const; + void OnTransitionUpdated(nux::Color const& new_color); private: nux::animation::AnimateValue<nux::Color> transition_animator_; |
