summaryrefslogtreecommitdiff
diff options
-rw-r--r--dash/DashController.cpp2
-rw-r--r--dash/DashView.cpp13
-rw-r--r--panel/WindowButtons.cpp13
-rw-r--r--panel/WindowButtons.h3
-rwxr-xr-xunity-shared/DashStyle.cpp8
-rw-r--r--unity-shared/OverlayRenderer.cpp6
-rw-r--r--unity-shared/PanelStyle.cpp6
-rw-r--r--unity-shared/UnitySettings.cpp114
-rw-r--r--unity-shared/UnitySettings.h12
-rw-r--r--unity-standalone/StandaloneUnity.cpp2
10 files changed, 84 insertions, 95 deletions
diff --git a/dash/DashController.cpp b/dash/DashController.cpp
index 8030eff45..59228f6f2 100644
--- a/dash/DashController.cpp
+++ b/dash/DashController.cpp
@@ -74,7 +74,7 @@ Controller::Controller()
SetupWindow();
- Settings::Instance().changed.connect([&]()
+ Settings::Instance().form_factor.changed.connect([this](FormFactor)
{
if (window_ && view_ && visible_)
{
diff --git a/dash/DashView.cpp b/dash/DashView.cpp
index 2f48005a8..a0f1debbb 100644
--- a/dash/DashView.cpp
+++ b/dash/DashView.cpp
@@ -98,7 +98,10 @@ DashView::DashView()
SetupViews();
SetupUBusConnections();
- Settings::Instance().changed.connect(sigc::mem_fun(this, &DashView::Relayout));
+ Settings::Instance().form_factor.changed.connect([this](FormFactor) {
+ Relayout();
+ });
+
lenses_.lens_added.connect(sigc::mem_fun(this, &DashView::OnLensAdded));
mouse_down.connect(sigc::mem_fun(this, &DashView::OnMouseButtonDown));
preview_state_machine_.PreviewActivated.connect(sigc::mem_fun(this, &DashView::BuildPreview));
@@ -424,7 +427,7 @@ void DashView::OnMouseButtonDown(int x, int y, unsigned long button, unsigned lo
dash::Style& style = dash::Style::Instance();
nux::Geometry geo(content_geo_);
- if (Settings::Instance().GetFormFactor() == FormFactor::DESKTOP)
+ if (Settings::Instance().form_factor() == FormFactor::DESKTOP)
{
geo.width += style.GetDashRightTileWidth();
geo.height += style.GetDashBottomTileHeight();
@@ -856,11 +859,11 @@ void DashView::AddProperties(GVariantBuilder* builder)
std::string form_factor("unknown");
- if (Settings::Instance().GetFormFactor() == FormFactor::NETBOOK)
+ if (Settings::Instance().form_factor() == FormFactor::NETBOOK)
form_factor = "netbook";
- else if (Settings::Instance().GetFormFactor() == FormFactor::DESKTOP)
+ else if (Settings::Instance().form_factor() == FormFactor::DESKTOP)
form_factor = "desktop";
- else if (Settings::Instance().GetFormFactor() == FormFactor::TV)
+ else if (Settings::Instance().form_factor() == FormFactor::TV)
form_factor = "tv";
unity::variant::BuilderWrapper wrapper(builder);
diff --git a/panel/WindowButtons.cpp b/panel/WindowButtons.cpp
index 2f2c149dd..6d8e7d15b 100644
--- a/panel/WindowButtons.cpp
+++ b/panel/WindowButtons.cpp
@@ -395,7 +395,7 @@ WindowButtons::WindowButtons()
ubus_manager_.RegisterInterest(UBUS_OVERLAY_SHOWN, sigc::mem_fun(this, &WindowButtons::OnOverlayShown));
ubus_manager_.RegisterInterest(UBUS_OVERLAY_HIDDEN, sigc::mem_fun(this, &WindowButtons::OnOverlayHidden));
- Settings::Instance().changed.connect(sigc::mem_fun(this, &WindowButtons::OnDashSettingsUpdated));
+ Settings::Instance().form_factor.changed.connect(sigc::mem_fun(this, &WindowButtons::OnDashSettingsUpdated));
}
nux::Area* WindowButtons::FindAreaUnderMouse(const nux::Point& mouse, nux::NuxEventType event_type)
@@ -470,7 +470,7 @@ void WindowButtons::OnRestoreClicked(nux::Button *button)
if (win_button->IsOverlayOpen())
{
- Settings::Instance().SetFormFactor(FormFactor::DESKTOP);
+ Settings::Instance().form_factor = FormFactor::DESKTOP;
}
else
{
@@ -494,7 +494,7 @@ void WindowButtons::OnMaximizeClicked(nux::Button *button)
if (win_button->IsOverlayOpen())
{
- Settings::Instance().SetFormFactor(FormFactor::NETBOOK);
+ Settings::Instance().form_factor = FormFactor::NETBOOK;
}
maximize_clicked.emit();
@@ -550,7 +550,7 @@ void WindowButtons::OnOverlayShown(GVariant* data)
if (restore_button && maximize_button)
{
Settings &dash_settings = Settings::Instance();
- bool maximizable = (dash_settings.GetFormFactor() == FormFactor::DESKTOP);
+ bool maximizable = (dash_settings.form_factor() == FormFactor::DESKTOP);
restore_button->SetEnabled(can_maximise);
maximize_button->SetEnabled(can_maximise);
@@ -645,7 +645,7 @@ void WindowButtons::OnOverlayHidden(GVariant* data)
}
}
-void WindowButtons::OnDashSettingsUpdated()
+void WindowButtons::OnDashSettingsUpdated(FormFactor form_factor)
{
WindowButton* maximize_button = nullptr;
WindowButton* restore_button = nullptr;
@@ -672,8 +672,7 @@ void WindowButtons::OnDashSettingsUpdated()
if (restore_button && restore_button->IsOverlayOpen() && maximize_button)
{
- Settings &dash_settings = Settings::Instance();
- bool maximizable = (dash_settings.GetFormFactor() == FormFactor::DESKTOP);
+ bool maximizable = (form_factor == FormFactor::DESKTOP);
if (maximizable != maximize_button->IsVisible())
{
diff --git a/panel/WindowButtons.h b/panel/WindowButtons.h
index b798d7b57..41e708bfe 100644
--- a/panel/WindowButtons.h
+++ b/panel/WindowButtons.h
@@ -26,6 +26,7 @@
#include "unity-shared/UBusWrapper.h"
#include "unity-shared/Introspectable.h"
+#include "unity-shared/UnitySettings.h"
namespace unity
{
@@ -70,7 +71,7 @@ private:
void OnMaximizeClicked(nux::Button *button);
void OnOverlayShown(GVariant* data);
void OnOverlayHidden(GVariant* data);
- void OnDashSettingsUpdated();
+ void OnDashSettingsUpdated(FormFactor form_factor);
int monitor_;
double opacity_;
diff --git a/unity-shared/DashStyle.cpp b/unity-shared/DashStyle.cpp
index 27c730f0c..ca33ddc2a 100755
--- a/unity-shared/DashStyle.cpp
+++ b/unity-shared/DashStyle.cpp
@@ -426,14 +426,14 @@ Style::Style()
style_instance = this;
}
- auto formfactor_lambda = [this] ()
+ auto formfactor_lambda = [this] (FormFactor)
{
- FormFactor formfactor = Settings::Instance().GetFormFactor();
+ FormFactor formfactor = Settings::Instance().form_factor();
always_maximised = (formfactor == FormFactor::NETBOOK || formfactor == FormFactor::TV);
};
- Settings::Instance().changed.connect(formfactor_lambda);
- formfactor_lambda();
+ Settings::Instance().form_factor.changed.connect(formfactor_lambda);
+ formfactor_lambda(FormFactor());
}
Style::~Style ()
diff --git a/unity-shared/OverlayRenderer.cpp b/unity-shared/OverlayRenderer.cpp
index 24978e04e..9f2a6697c 100644
--- a/unity-shared/OverlayRenderer.cpp
+++ b/unity-shared/OverlayRenderer.cpp
@@ -438,7 +438,7 @@ void OverlayRendererImpl::Draw(nux::GraphicsEngine& gfx_context, nux::Geometry c
bool paint_blur = BackgroundEffectHelper::blur_type != BLUR_NONE;
nux::Geometry geo(content_geo);
- int excess_border = (Settings::Instance().GetFormFactor() != FormFactor::NETBOOK || force_edges) ? EXCESS_BORDER : 0;
+ int excess_border = (Settings::Instance().form_factor() != FormFactor::NETBOOK || force_edges) ? EXCESS_BORDER : 0;
nux::Geometry larger_content_geo = content_geo;
larger_content_geo.OffsetSize(excess_border, excess_border);
@@ -578,7 +578,7 @@ void OverlayRendererImpl::Draw(nux::GraphicsEngine& gfx_context, nux::Geometry c
}
- if (Settings::Instance().GetFormFactor() != FormFactor::NETBOOK || force_edges)
+ if (Settings::Instance().form_factor() != FormFactor::NETBOOK || force_edges)
{
// Paint the edges
{
@@ -835,7 +835,7 @@ void OverlayRendererImpl::DrawContent(nux::GraphicsEngine& gfx_context, nux::Geo
nux::Geometry geo = geometry;
bgs = 0;
- int excess_border = (Settings::Instance().GetFormFactor() != FormFactor::NETBOOK) ? EXCESS_BORDER : 0;
+ int excess_border = (Settings::Instance().form_factor() != FormFactor::NETBOOK) ? EXCESS_BORDER : 0;
nux::Geometry larger_content_geo = content_geo;
larger_content_geo.OffsetSize(excess_border, excess_border);
diff --git a/unity-shared/PanelStyle.cpp b/unity-shared/PanelStyle.cpp
index 2d64af4f0..885500567 100644
--- a/unity-shared/PanelStyle.cpp
+++ b/unity-shared/PanelStyle.cpp
@@ -73,12 +73,12 @@ Style::Style()
style_instance = this;
}
- if (Settings::Instance().GetFormFactor() == FormFactor::TV)
+ if (Settings::Instance().form_factor() == FormFactor::TV)
panel_height = 0;
- Settings::Instance().changed.connect([this]()
+ Settings::Instance().form_factor.changed.connect([this](FormFactor form_factor)
{
- if (Settings::Instance().GetFormFactor() == FormFactor::TV)
+ if (form_factor == FormFactor::TV)
panel_height = 0;
});
diff --git a/unity-shared/UnitySettings.cpp b/unity-shared/UnitySettings.cpp
index 540944367..a082672bd 100644
--- a/unity-shared/UnitySettings.cpp
+++ b/unity-shared/UnitySettings.cpp
@@ -32,73 +32,70 @@ namespace
nux::logging::Logger logger("unity");
Settings* settings_instance = nullptr;
-const char* const FORM_FACTOR = "form-factor";
+
+const std::string SETTINGS_NAME = "com.canonical.Unity";
+const std::string FORM_FACTOR = "form-factor";
}
+//
+// Start private implementation
+//
class Settings::Impl
{
-public:
- Impl(Settings* owner);
-
- FormFactor GetFormFactor() const;
- void SetFormFactor(FormFactor factor);
-
-private:
- void Refresh();
-
-private:
- Settings* owner_;
- glib::Object<GSettings> settings_;
- FormFactor form_factor_;
-
- glib::Signal<void, GSettings*, gchar* > form_factor_changed_;
-
-};
-
-
-Settings::Impl::Impl(Settings* owner)
- : owner_(owner)
- , settings_(g_settings_new("com.canonical.Unity"))
- , form_factor_(FormFactor::DESKTOP)
-{
- form_factor_changed_.Connect(settings_, "changed::minimize-count", [this] (GSettings*, gchar*) {
- Refresh();
- });
- Refresh();
-}
+public:
+ Impl(Settings* owner)
+ : parent_(owner)
+ , gsettings_(g_settings_new(SETTINGS_NAME.c_str()))
+ , cached_form_factor_(FormFactor::DESKTOP)
+ {
+ CacheFormFactor();
-void Settings::Impl::Refresh()
-{
- int raw_from_factor = g_settings_get_enum(settings_, FORM_FACTOR);
+ form_factor_changed_.Connect(gsettings_, "changed::" + FORM_FACTOR, [this] (GSettings*, gchar*) {
+ CacheFormFactor();
+ parent_->form_factor.changed.emit(cached_form_factor_);
+ });
+ }
- if (raw_from_factor == 0) //Automatic
+ void CacheFormFactor()
{
- UScreen *uscreen = UScreen::GetDefault();
- int primary_monitor = uscreen->GetMonitorWithMouse();
- auto geo = uscreen->GetMonitorGeometry(primary_monitor);
+ int raw_from_factor = g_settings_get_enum(gsettings_, FORM_FACTOR.c_str());
+
+ if (raw_from_factor == 0) //Automatic
+ {
+ auto uscreen = UScreen::GetDefault();
+ int primary_monitor = uscreen->GetMonitorWithMouse();
+ auto const& geo = uscreen->GetMonitorGeometry(primary_monitor);
+
+ cached_form_factor_ = geo.height > 799 ? FormFactor::DESKTOP : FormFactor::NETBOOK;
+ }
+ else
+ {
+ cached_form_factor_ = static_cast<FormFactor>(raw_from_factor);
+ }
+ }
- form_factor_ = geo.height > 799 ? FormFactor::DESKTOP : FormFactor::NETBOOK;
+ FormFactor GetFormFactor() const
+ {
+ return cached_form_factor_;
}
- else
+
+ bool SetFormFactor(FormFactor factor)
{
- form_factor_ = static_cast<FormFactor>(raw_from_factor);
+ g_settings_set_enum(gsettings_, FORM_FACTOR.c_str(), static_cast<int>(factor));
+ return true;
}
- owner_->changed.emit();
-}
+ Settings* parent_;
+ glib::Object<GSettings> gsettings_;
+ FormFactor cached_form_factor_;
-FormFactor Settings::Impl::GetFormFactor() const
-{
- return form_factor_;
-}
+ glib::Signal<void, GSettings*, gchar* > form_factor_changed_;
+};
-void Settings::Impl::SetFormFactor(FormFactor factor)
-{
- form_factor_ = factor;
- g_settings_set_enum(settings_, FORM_FACTOR, static_cast<int>(factor));
- owner_->changed.emit();
-}
+//
+// End private implementation
+//
Settings::Settings()
: is_standalone(false)
@@ -110,6 +107,9 @@ Settings::Settings()
}
else
{
+ form_factor.SetGetterFunction(sigc::mem_fun(*pimpl, &Impl::GetFormFactor));
+ form_factor.SetSetterFunction(sigc::mem_fun(*pimpl, &Impl::SetFormFactor));
+
settings_instance = this;
}
}
@@ -130,15 +130,5 @@ Settings& Settings::Instance()
return *settings_instance;
}
-FormFactor Settings::GetFormFactor() const
-{
- return pimpl->GetFormFactor();
-}
-
-void Settings::SetFormFactor(FormFactor factor)
-{
- pimpl->SetFormFactor(factor);
-}
-
} // namespace unity
diff --git a/unity-shared/UnitySettings.h b/unity-shared/UnitySettings.h
index 010459668..7fc387644 100644
--- a/unity-shared/UnitySettings.h
+++ b/unity-shared/UnitySettings.h
@@ -17,8 +17,8 @@
* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
*/
-#ifndef UNITY_SETTINGS_H
-#define UNITY_SETTINGS_H
+#ifndef UNITYSHELL_SETTINGS_H
+#define UNITYSHELL_SETTINGS_H
#include <memory>
#include <sigc++/signal.h>
@@ -30,7 +30,7 @@ namespace unity
enum class FormFactor
{
DESKTOP = 1,
- NETBOOK = 2,
+ NETBOOK,
TV
};
@@ -42,12 +42,8 @@ public:
static Settings& Instance();
- // NOTE: could potentially refactor this into a nux::Property
- FormFactor GetFormFactor() const;
- void SetFormFactor(FormFactor factor);
-
+ nux::RWProperty<FormFactor> form_factor;
nux::Property<bool> is_standalone;
- sigc::signal<void> changed;
private:
class Impl;
diff --git a/unity-standalone/StandaloneUnity.cpp b/unity-standalone/StandaloneUnity.cpp
index a5dba677c..fc5421fce 100644
--- a/unity-standalone/StandaloneUnity.cpp
+++ b/unity-standalone/StandaloneUnity.cpp
@@ -160,7 +160,7 @@ int main(int argc, char **argv)
// The instances for the pseudo-singletons.
Settings settings;
settings.is_standalone = true;
- if (force_tv) Settings::Instance().SetFormFactor(FormFactor::TV);
+ if (force_tv) Settings::Instance().form_factor(FormFactor::TV);
PluginAdapter::Initialize(NULL);
dash::Style dash_style;