diff options
100 files changed, 601 insertions, 696 deletions
diff --git a/com.canonical.Unity.gschema.xml b/com.canonical.Unity.gschema.xml index 52ab08073..c688e18c5 100644 --- a/com.canonical.Unity.gschema.xml +++ b/com.canonical.Unity.gschema.xml @@ -54,6 +54,36 @@ unity top panel</description> </key> </schema> + <schema path="/com/canonical/unity/interface/" id="com.canonical.Unity.Interface" gettext-domain="unity"> + <key type="d" name="text-scale-factor"> + <default>1.0</default> + <range min="0.5" max="3.0"/> + <summary>Font scaling for unity and applications.</summary> + <description>This value defines the global font scaling used by both + unity and applications. It will match the current system font scaling.</description> + </key> + <key type="d" name="cursor-scale-factor"> + <default>1.0</default> + <range min="0.5" max="3.0"/> + <summary>Mouse cursor scaling.</summary> + <description>This value defines the global mouse cursor scaling used by both + unity and applications. Changing this value allows to use a custom scaling + for the mouse cursor.</description> + </key> + <key type="s" name="app-scale-factor-monitor"> + <default>''</default> + <summary>The name of the monitor that controls the global app scaling factor.</summary> + <description>This value defines the monitor that unity will use (if found) as reference + for scaling all the applications.</description> + </key> + <key type="b" name="app-fallback-to-maximum-scale-factor"> + <default>true</default> + <summary>Use the maximum per-monitor scale-factor as application scale factor if no target monitor is found.</summary> + <description>When this is enabled, the applications scale factor will match + the scale factor of the monitor with the greater value, in case the monitor + defined in 'app-scale-factor-monitor' is not provided or available.</description> + </key> + </schema> <schema path="/com/canonical/unity/launcher/" id="com.canonical.Unity.Launcher" gettext-domain="unity"> <key type="as" name="favorites"> <default>[ diff --git a/dash/DashController.cpp b/dash/DashController.cpp index d1acc8df6..0e693c53f 100644 --- a/dash/DashController.cpp +++ b/dash/DashController.cpp @@ -92,7 +92,7 @@ Controller::Controller(Controller::WindowCreator const& create_window) SetupWindow(); UScreen::GetDefault()->changed.connect([this] (int, std::vector<nux::Geometry> const&) { Relayout(true); }); - Settings::Instance().form_factor.changed.connect([this](FormFactor) + form_factor_changed_ = Settings::Instance().form_factor.changed.connect([this] (FormFactor) { if (window_ && view_ && visible_) { diff --git a/dash/DashController.h b/dash/DashController.h index 5705d38da..e3256913c 100644 --- a/dash/DashController.h +++ b/dash/DashController.h @@ -68,7 +68,7 @@ public: bool IsCommandLensOpen() const; nux::Geometry GetInputWindowGeometry(); nux::ObjectPtr<DashView> const& Dash() const; - + int Monitor() const; protected: @@ -108,6 +108,7 @@ private: bool need_show_; connection::Wrapper screen_ungrabbed_slot_; + connection::Wrapper form_factor_changed_; glib::DBusServer dbus_server_; glib::TimeoutSeconds ensure_timeout_; nux::animation::AnimateValue<double> timeline_animator_; diff --git a/dash/DashView.cpp b/dash/DashView.cpp index 25492c106..a2cc68696 100644 --- a/dash/DashView.cpp +++ b/dash/DashView.cpp @@ -547,7 +547,7 @@ void DashView::SetupViews() content_layout_->AddLayout(search_bar_layout_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); search_bar_ = new SearchBar(true); - search_bar_->UpdateScale(cv_->DPIScale()); + search_bar_->scale = cv_->DPIScale(); AddChild(search_bar_); search_bar_->activated.connect(sigc::mem_fun(this, &DashView::OnEntryActivated)); search_bar_->search_changed.connect(sigc::mem_fun(this, &DashView::OnSearchChanged)); @@ -581,10 +581,10 @@ void DashView::OnDPIChanged() UpdateDashViewSize(); for (auto& scope : scope_views_) - scope.second->UpdateScale(scale); + scope.second->scale = scale; - search_bar_->UpdateScale(scale); - scope_bar_->UpdateScale(cv_->DPIScale()); + search_bar_->scale = scale; + scope_bar_->scale = scale; } void DashView::UpdateDashViewSize() @@ -1282,7 +1282,7 @@ void DashView::OnScopeAdded(Scope::Ptr const& scope, int position) nux::ObjectPtr<ScopeView> view(new ScopeView(scope, search_bar_->show_filters())); AddChild(view.GetPointer()); - view->UpdateScale(cv_->DPIScale()); + view->scale = cv_->DPIScale(); view->SetVisible(false); view->result_activated.connect(sigc::mem_fun(this, &DashView::OnResultActivated)); diff --git a/dash/FilterBar.cpp b/dash/FilterBar.cpp index 82bb4d51b..1f477486c 100644 --- a/dash/FilterBar.cpp +++ b/dash/FilterBar.cpp @@ -45,7 +45,7 @@ NUX_IMPLEMENT_OBJECT_TYPE(FilterBar); FilterBar::FilterBar(NUX_FILE_LINE_DECL) : View(NUX_FILE_LINE_PARAM) - , scale_(DEFAULT_SCALE) + , scale(DEFAULT_SCALE) { Init(); } @@ -61,19 +61,14 @@ void FilterBar::Init() nux::LinearLayout* layout = new nux::VLayout(NUX_TRACKER_LOCATION); layout->SetTopAndBottomPadding(style.GetFilterBarTopPadding() - style.GetFilterHighlightPadding()); layout->SetSpaceBetweenChildren(style.GetSpaceBetweenFilterWidgets() - style.GetFilterHighlightPadding()); + scale.changed.connect(sigc::mem_fun(this, &FilterBar::UpdateScale)); SetLayout(layout); } void FilterBar::UpdateScale(double scale) { - if (scale_ != scale) - { - scale_ = scale; - for (auto& filters : filter_map_) - { - filters.second->UpdateScale(scale_); - } - } + for (auto& filters : filter_map_) + filters.second->scale = scale; } void FilterBar::SetFilters(Filters::Ptr const& filters) @@ -90,7 +85,7 @@ void FilterBar::AddFilter(Filter::Ptr const& filter) } FilterExpanderLabel* filter_view = factory_.WidgetForFilter(filter); - filter_view->UpdateScale(scale_); + filter_view->scale = scale(); AddChild(filter_view); filter_map_[filter] = filter_view; GetLayout()->AddView(filter_view, 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL); diff --git a/dash/FilterBar.h b/dash/FilterBar.h index 9508d6871..9c3112b60 100644 --- a/dash/FilterBar.h +++ b/dash/FilterBar.h @@ -44,9 +44,9 @@ public: FilterBar(NUX_FILE_LINE_PROTO); ~FilterBar(); - void SetFilters(Filters::Ptr const& filters); + nux::Property<double> scale; - void UpdateScale(double scale); + void SetFilters(Filters::Ptr const& filters); void AddFilter(Filter::Ptr const& filter); void RemoveFilter(Filter::Ptr const& filter); @@ -63,12 +63,11 @@ protected: private: void Init(); + void UpdateScale(double scale); FilterFactory factory_; Filters::Ptr filters_; std::map<Filter::Ptr, FilterExpanderLabel*> filter_map_; - - double scale_; }; } // namespace dash diff --git a/dash/FilterExpanderLabel.cpp b/dash/FilterExpanderLabel.cpp index a46600ad9..11d7be456 100644 --- a/dash/FilterExpanderLabel.cpp +++ b/dash/FilterExpanderLabel.cpp @@ -86,6 +86,7 @@ NUX_IMPLEMENT_OBJECT_TYPE(FilterExpanderLabel); FilterExpanderLabel::FilterExpanderLabel(std::string const& label, NUX_FILE_LINE_DECL) : nux::View(NUX_FILE_LINE_PARAM) + , scale(DEFAULT_SCALE) , expanded(true) , layout_(nullptr) , top_bar_layout_(nullptr) @@ -95,8 +96,8 @@ FilterExpanderLabel::FilterExpanderLabel(std::string const& label, NUX_FILE_LINE , cairo_label_(nullptr) , raw_label_(label) , label_("label") - , scale_(DEFAULT_SCALE) { + scale.changed.connect(sigc::mem_fun(this, &FilterExpanderLabel::UpdateScale)); expanded.changed.connect(sigc::mem_fun(this, &FilterExpanderLabel::DoExpandChange)); BuildLayout(); } @@ -110,11 +111,7 @@ void FilterExpanderLabel::SetLabel(std::string const& label) void FilterExpanderLabel::UpdateScale(double scale) { - if (scale_ != scale) - { - scale_ = scale; - cairo_label_->SetScale(scale); - } + cairo_label_->SetScale(scale); } void FilterExpanderLabel::SetRightHandView(nux::View* view) diff --git a/dash/FilterExpanderLabel.h b/dash/FilterExpanderLabel.h index 62c0d43a0..74d7c0d32 100644 --- a/dash/FilterExpanderLabel.h +++ b/dash/FilterExpanderLabel.h @@ -59,13 +59,12 @@ public: void SetLabel(std::string const& label); void SetContents(nux::Layout* layout); - void UpdateScale(double scale); - virtual void SetFilter(Filter::Ptr const& filter) = 0; virtual std::string GetFilterType() = 0; nux::View* expander_view() const { return expander_view_; } + nux::Property<double> scale; nux::Property<bool> expanded; protected: @@ -83,6 +82,7 @@ private: void BuildLayout(); void DoExpandChange(bool change); bool ShouldBeHighlighted(); + void UpdateScale(double scale); nux::LinearLayout* layout_; nux::LinearLayout* top_bar_layout_; @@ -99,8 +99,6 @@ private: nux::ObjectPtr<nux::Layout> contents_; std::unique_ptr<nux::AbstractPaintLayer> focus_layer_; - - double scale_; }; } // namespace dash diff --git a/dash/PlacesGroup.cpp b/dash/PlacesGroup.cpp index 414b07e0d..d61f142d9 100755 --- a/dash/PlacesGroup.cpp +++ b/dash/PlacesGroup.cpp @@ -117,6 +117,7 @@ NUX_IMPLEMENT_OBJECT_TYPE(PlacesGroup); PlacesGroup::PlacesGroup(dash::StyleInterface& style) : nux::View(NUX_TRACKER_LOCATION), + scale(DEFAULT_SCALE), _style(style), _child_layout(nullptr), _child_view(nullptr), @@ -126,14 +127,14 @@ PlacesGroup::PlacesGroup(dash::StyleInterface& style) _n_visible_items_in_unexpand_mode(0), _n_total_items(0), _coverflow_enabled(false), - _disabled_header_count(false), - _scale(DEFAULT_SCALE) + _disabled_header_count(false) { SetAcceptKeyNavFocusOnMouseDown(false); SetAcceptKeyNavFocusOnMouseEnter(false); + scale.changed.connect(sigc::mem_fun(this, &PlacesGroup::UpdateScale)); nux::BaseTexture* arrow = _style.GetGroupExpandIcon(); - + _background = _style.GetCategoryBackground(); _background_nofilters = _style.GetCategoryBackgroundNoFilters(); @@ -163,7 +164,7 @@ PlacesGroup::PlacesGroup(dash::StyleInterface& style) _header_view->SetLayout(_header_layout); RawPixel const icon_size = _style.GetCategoryIconSize(); - _icon = new IconTexture("", icon_size.CP(_scale)); + _icon = new IconTexture("", icon_size.CP(scale())); _header_layout->AddView(_icon, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FIX); _text_layout = new nux::HLayout(NUX_TRACKER_LOCATION); @@ -225,43 +226,37 @@ PlacesGroup::UpdatePlacesGroupSize() RawPixel const icon_size = _style.GetCategoryIconSize(); RawPixel const group_top = _style.GetPlacesGroupTopSpace(); - int top_space = group_top.CP(_scale); + int top_space = group_top.CP(scale()); _space_layout->SetMinimumSize(top_space, top_space); _space_layout->SetMaximumSize(top_space, top_space); - _header_layout->SetSpaceBetweenChildren(SPACE_BETWEEN_CHILDREN.CP(_scale)); + _header_layout->SetSpaceBetweenChildren(SPACE_BETWEEN_CHILDREN.CP(scale())); - _icon->SetMinMaxSize(icon_size.CP(_scale), icon_size.CP(_scale)); + _icon->SetMinMaxSize(icon_size.CP(scale()), icon_size.CP(scale())); - _text_layout->SetHorizontalInternalMargin(TEXT_INTERNAL_MARGIN.CP(_scale)); - _expand_layout->SetHorizontalInternalMargin(EXPAND_INTERNAL_MARGIN.CP(_scale)); + _text_layout->SetHorizontalInternalMargin(TEXT_INTERNAL_MARGIN.CP(scale())); + _expand_layout->SetHorizontalInternalMargin(EXPAND_INTERNAL_MARGIN.CP(scale())); } void PlacesGroup::UpdateScale(double scale) { - if (_scale != scale) - { - RawPixel const icon_size = _style.GetCategoryIconSize(); + RawPixel const icon_size = _style.GetCategoryIconSize(); - _scale = scale; - _name->SetScale(_scale); - _expand_label->SetScale(_scale); + _name->SetScale(scale); + _expand_label->SetScale(scale); - _icon->SetSize(icon_size.CP(_scale)); - _icon->ReLoadIcon(); + _icon->SetSize(icon_size.CP(scale)); + _icon->ReLoadIcon(); - // FIXME _expand_icon, needs some work here. Not as easy as _icon + // FIXME _expand_icon, needs some work here. Not as easy as _icon - if (_child_view) - { - _child_view->UpdateScale(scale); - } + if (_child_view) + _child_view->scale = scale; - ComputeContentSize(); - UpdatePlacesGroupSize(); - UpdateResultViewPadding(); - } + ComputeContentSize(); + UpdatePlacesGroupSize(); + UpdateResultViewPadding(); } void @@ -326,8 +321,8 @@ PlacesGroup::UpdateResultViewPadding() RawPixel const result_top_padding = _style.GetPlacesGroupResultTopPadding(); RawPixel const result_left_padding = _style.GetPlacesGroupResultLeftPadding(); - _child_layout->SetTopAndBottomPadding(result_top_padding.CP(_scale), 0); - _child_layout->SetLeftAndRightPadding(result_left_padding.CP(_scale), 0); + _child_layout->SetTopAndBottomPadding(result_top_padding.CP(scale()), 0); + _child_layout->SetLeftAndRightPadding(result_left_padding.CP(scale()), 0); } } @@ -345,7 +340,7 @@ PlacesGroup::SetChildView(dash::ResultView* view) AddChild(view); _child_view = view; - _child_view->UpdateScale(_scale); + _child_view->scale = scale(); _child_layout = new nux::VLayout(); _child_layout->AddView(_child_view, 0); @@ -468,9 +463,9 @@ long PlacesGroup::ComputeContentSize() if (_cached_geometry.GetWidth() != geo.GetWidth()) { _focus_layer.reset(_style.FocusOverlay(geo.width - - kHighlightLeftPadding.CP(_scale) - - kHighlightRightPadding.CP(_scale), - kHighlightHeight.CP(_scale))); + kHighlightLeftPadding.CP(scale()) - + kHighlightRightPadding.CP(scale()), + kHighlightHeight.CP(scale()))); _cached_geometry = geo; } return ret; @@ -489,10 +484,10 @@ void PlacesGroup::Draw(nux::GraphicsEngine& graphics_engine, { nux::Geometry geo(_header_layout->GetGeometry()); geo.width = base.width - - kHighlightRightPadding.CP(_scale) - - kHighlightLeftPadding.CP(_scale); + kHighlightRightPadding.CP(scale()) - + kHighlightLeftPadding.CP(scale()); - geo.x += kHighlightLeftPadding.CP(_scale); + geo.x += kHighlightLeftPadding.CP(scale()); _focus_layer->SetGeometry(geo); _focus_layer->Renderlayer(graphics_engine); diff --git a/dash/PlacesGroup.h b/dash/PlacesGroup.h index 536be4fc1..d99883703 100644 --- a/dash/PlacesGroup.h +++ b/dash/PlacesGroup.h @@ -59,6 +59,8 @@ public: PlacesGroup(dash::StyleInterface& style); + nux::Property<double> scale; + void SetIcon(std::string const& icon); void SetName(std::string const& name); void SetHeaderCountVisible(bool disable); @@ -94,8 +96,6 @@ public: glib::Variant GetCurrentFocus() const; void SetCurrentFocus(glib::Variant const& variant); - void UpdateScale(double scale); - protected: long ComputeContentSize(); @@ -126,6 +126,7 @@ private: void UpdatePlacesGroupSize(); void UpdateResultViewPadding(); + void UpdateScale(double scale); private: std::string _category_id; @@ -166,8 +167,6 @@ private: glib::Source::UniquePtr _relayout_idle; UBusManager _ubus; - double _scale; - friend class TestScopeView; }; diff --git a/dash/ResultRenderer.cpp b/dash/ResultRenderer.cpp index ed8d567e1..c0566b3ba 100644 --- a/dash/ResultRenderer.cpp +++ b/dash/ResultRenderer.cpp @@ -118,7 +118,7 @@ ResultRenderer::ResultRenderer(NUX_FILE_LINE_DECL) : InitiallyUnownedObject(NUX_FILE_LINE_PARAM) , width(50) , height(50) - , scale_(DEFAULT_SCALE) + , scale(DEFAULT_SCALE) {} void ResultRenderer::Render(nux::GraphicsEngine& GfxContext, @@ -147,11 +147,6 @@ nux::NBitmapData* ResultRenderer::GetDndImage(Result const& row) const return graphics.GetBitmap(); } -void ResultRenderer::UpdateScale(double scale) -{ - scale_ = scale; -} - } } diff --git a/dash/ResultRenderer.h b/dash/ResultRenderer.h index b53ad5398..26b47f7e6 100644 --- a/dash/ResultRenderer.h +++ b/dash/ResultRenderer.h @@ -70,15 +70,11 @@ public: // get a image to drag virtual nux::NBitmapData* GetDndImage(Result const& row) const; - virtual void UpdateScale(double scale); - nux::Property<int> width; nux::Property<int> height; + nux::Property<double> scale; sigc::signal<void> NeedsRedraw; - -protected: - double scale_; }; } diff --git a/dash/ResultRendererHorizontalTile.cpp b/dash/ResultRendererHorizontalTile.cpp index 12068f929..8df4476ba 100644 --- a/dash/ResultRendererHorizontalTile.cpp +++ b/dash/ResultRendererHorizontalTile.cpp @@ -30,6 +30,7 @@ #include "unity-shared/CairoTexture.h" #include "unity-shared/TextureCache.h" #include "unity-shared/RawPixel.h" +#include "unity-shared/UnitySettings.h" #include <NuxGraphics/GdkGraphics.h> @@ -37,14 +38,14 @@ namespace unity { namespace { -RawPixel const CARD_VIEW_PADDING = 4_em; -RawPixel const CARD_VIEW_ICON_SIZE = 64_em; -RawPixel const CARD_VIEW_ICON_TEXT_GAP = 10_em; -RawPixel const CARD_VIEW_WIDTH = 277_em; -RawPixel const CARD_VIEW_HEIGHT = 74_em; -RawPixel const CARD_VIEW_HIGHLIGHT_CORNER_RADIUS = 2_em; -RawPixel const CARD_VIEW_ICON_OUTLINE_WIDTH = 1_em; -RawPixel const CARD_VIEW_TEXT_LINE_SPACING = 0_em; +const RawPixel CARD_VIEW_PADDING = 4_em; +const RawPixel CARD_VIEW_ICON_SIZE = 64_em; +const RawPixel CARD_VIEW_ICON_TEXT_GAP = 10_em; +const RawPixel CARD_VIEW_WIDTH = 277_em; +const RawPixel CARD_VIEW_HEIGHT = 74_em; +const RawPixel CARD_VIEW_ICON_OUTLINE_WIDTH = 1_em; +const int CARD_VIEW_HIGHLIGHT_CORNER_RADIUS = 2; +const int CARD_VIEW_TEXT_LINE_SPACING = 0; void RenderTexture(nux::GraphicsEngine& GfxContext, int x, @@ -90,18 +91,13 @@ ResultRendererHorizontalTile::ResultRendererHorizontalTile(NUX_FILE_LINE_DECL) : ResultRendererTile(NUX_FILE_LINE_PARAM) { ReloadTextures(); -} - -void ResultRendererHorizontalTile::UpdateScale(double scale) -{ - ResultRenderer::UpdateScale(scale); - ReloadTextures(); + scale.changed.connect([this] (double) { ReloadTextures(); }); } void ResultRendererHorizontalTile::ReloadTextures() { - width = CARD_VIEW_WIDTH.CP(scale_); - height = CARD_VIEW_HEIGHT.CP(scale_); + width = CARD_VIEW_WIDTH.CP(scale()); + height = CARD_VIEW_HEIGHT.CP(scale()); // pre-load the highlight texture // try and get a texture from the texture cache @@ -134,15 +130,15 @@ void ResultRendererHorizontalTile::Render(nux::GraphicsEngine& GfxContext, nux::TexCoordXForm texxform; int icon_left_hand_side = geometry.x + Padding(); - int icon_top_side = geometry.y + ((geometry.height - CARD_VIEW_ICON_SIZE.CP(scale_)) / 2); + int icon_top_side = geometry.y + ((geometry.height - CARD_VIEW_ICON_SIZE.CP(scale())) / 2); // render overall tile background "rectangle" if (state == ResultRendererState::RESULT_RENDERER_NORMAL) { int x = icon_left_hand_side; int y = icon_top_side; - int w = CARD_VIEW_WIDTH.CP(scale_); - int h = CARD_VIEW_HEIGHT.CP(scale_); + int w = CARD_VIEW_WIDTH.CP(scale()); + int h = CARD_VIEW_HEIGHT.CP(scale()); unsigned int alpha = 0; unsigned int src = 0; @@ -168,8 +164,8 @@ void ResultRendererHorizontalTile::Render(nux::GraphicsEngine& GfxContext, { int x = icon_left_hand_side; int y = icon_top_side; - int w = CARD_VIEW_WIDTH.CP(scale_); - int h = CARD_VIEW_HEIGHT.CP(scale_); + int w = CARD_VIEW_WIDTH.CP(scale()); + int h = CARD_VIEW_HEIGHT.CP(scale()); RenderTexture(GfxContext, x, @@ -185,15 +181,15 @@ void ResultRendererHorizontalTile::Render(nux::GraphicsEngine& GfxContext, // draw the icon if (container->icon) { - int x = icon_left_hand_side + CARD_VIEW_PADDING.CP(scale_) + CARD_VIEW_ICON_OUTLINE_WIDTH.CP(scale_); - int y = icon_top_side + CARD_VIEW_PADDING.CP(scale_) + CARD_VIEW_ICON_OUTLINE_WIDTH.CP(scale_); - int w = CARD_VIEW_ICON_SIZE.CP(scale_); - int h = CARD_VIEW_ICON_SIZE.CP(scale_); + int x = icon_left_hand_side + CARD_VIEW_PADDING.CP(scale()) + CARD_VIEW_ICON_OUTLINE_WIDTH.CP(scale()); + int y = icon_top_side + CARD_VIEW_PADDING.CP(scale()) + CARD_VIEW_ICON_OUTLINE_WIDTH.CP(scale()); + int w = CARD_VIEW_ICON_SIZE.CP(scale()); + int h = CARD_VIEW_ICON_SIZE.CP(scale()); gPainter.Paint2DQuadColor(GfxContext, - x - CARD_VIEW_ICON_OUTLINE_WIDTH.CP(scale_), - y - CARD_VIEW_ICON_OUTLINE_WIDTH.CP(scale_), - w + 2 * CARD_VIEW_ICON_OUTLINE_WIDTH.CP(scale_), - h + 2 * CARD_VIEW_ICON_OUTLINE_WIDTH.CP(scale_), + x - CARD_VIEW_ICON_OUTLINE_WIDTH.CP(scale()), + y - CARD_VIEW_ICON_OUTLINE_WIDTH.CP(scale()), + w + 2 * CARD_VIEW_ICON_OUTLINE_WIDTH.CP(scale()), + h + 2 * CARD_VIEW_ICON_OUTLINE_WIDTH.CP(scale()), nux::color::Black); RenderTexture(GfxContext, x, @@ -209,12 +205,12 @@ void ResultRendererHorizontalTile::Render(nux::GraphicsEngine& GfxContext, if (container->text) { int x = icon_left_hand_side + - CARD_VIEW_PADDING.CP(scale_) + - 2 * CARD_VIEW_ICON_OUTLINE_WIDTH.CP(scale_) + - CARD_VIEW_ICON_SIZE.CP(scale_) + - CARD_VIEW_ICON_TEXT_GAP.CP(scale_); + CARD_VIEW_PADDING.CP(scale()) + + 2 * CARD_VIEW_ICON_OUTLINE_WIDTH.CP(scale()) + + CARD_VIEW_ICON_SIZE.CP(scale()) + + CARD_VIEW_ICON_TEXT_GAP.CP(scale()); - int y = icon_top_side + CARD_VIEW_PADDING.CP(scale_); + int y = icon_top_side + CARD_VIEW_PADDING.CP(scale()); int w = container->text->GetWidth(); int h = container->text->GetHeight(); @@ -234,6 +230,7 @@ nux::BaseTexture* ResultRendererHorizontalTile::DrawHighlight(std::string const& int width, int height) { nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, width, height); + cairo_surface_set_device_scale(cairo_graphics.GetSurface(), scale(), scale()); cairo_t* cr = cairo_graphics.GetInternalContext(); cairo_scale(cr, 1.0f, 1.0f); @@ -249,7 +246,7 @@ nux::BaseTexture* ResultRendererHorizontalTile::DrawHighlight(std::string const& 1.0f, 0.0f, 0.0f, - CARD_VIEW_HIGHLIGHT_CORNER_RADIUS.CP(scale_), + CARD_VIEW_HIGHLIGHT_CORNER_RADIUS, width, height, false); @@ -262,6 +259,7 @@ nux::BaseTexture* ResultRendererHorizontalTile::DrawNormal(std::string const& te int width, int height) { nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, width, height); + cairo_surface_set_device_scale(cairo_graphics.GetSurface(), scale(), scale()); cairo_t* cr = cairo_graphics.GetInternalContext(); cairo_scale(cr, 1.0f, 1.0f); @@ -277,9 +275,9 @@ nux::BaseTexture* ResultRendererHorizontalTile::DrawNormal(std::string const& te 1.0f, 0.0f, 0.0f, - CARD_VIEW_HIGHLIGHT_CORNER_RADIUS.CP(scale_), - width, - height, + CARD_VIEW_HIGHLIGHT_CORNER_RADIUS, + width/scale(), + height/scale(), false); cairo_fill(cr); @@ -301,23 +299,21 @@ void ResultRendererHorizontalTile::LoadText(Result const& row) g_free(comment); nux::CairoGraphics _cairoGraphics(CAIRO_FORMAT_ARGB32, - CARD_VIEW_WIDTH.CP(scale_) - - CARD_VIEW_ICON_SIZE.CP(scale_) - - 2 * CARD_VIEW_ICON_OUTLINE_WIDTH.CP(scale_) - - 2 * CARD_VIEW_PADDING.CP(scale_) - - CARD_VIEW_ICON_TEXT_GAP.CP(scale_), - CARD_VIEW_HEIGHT.CP(scale_) - - 2 * CARD_VIEW_PADDING.CP(scale_)); + CARD_VIEW_WIDTH.CP(scale()) - + CARD_VIEW_ICON_SIZE.CP(scale()) - + 2 * CARD_VIEW_ICON_OUTLINE_WIDTH.CP(scale()) - + 2 * CARD_VIEW_PADDING.CP(scale()) - + CARD_VIEW_ICON_TEXT_GAP.CP(scale()), + CARD_VIEW_HEIGHT.CP(scale()) - + 2 * CARD_VIEW_PADDING.CP(scale())); + cairo_surface_set_device_scale(_cairoGraphics.GetSurface(), scale(), scale()); - cairo_t* cr = _cairoGraphics.GetContext(); + cairo_t* cr = _cairoGraphics.GetInternalContext(); PangoLayout* layout = NULL; PangoFontDescription* desc = NULL; PangoContext* pango_context = NULL; GdkScreen* screen = gdk_screen_get_default(); // not ref'ed - int dpi = -1; - - g_object_get(gtk_settings_get_default(), "gtk-xft-dpi", &dpi, NULL); cairo_set_font_options(cr, gdk_screen_get_font_options(screen)); layout = pango_cairo_create_layout(cr); @@ -328,22 +324,20 @@ void ResultRendererHorizontalTile::LoadText(Result const& row) pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); - pango_layout_set_spacing(layout, CARD_VIEW_TEXT_LINE_SPACING.CP(scale_) * PANGO_SCALE); - pango_layout_set_width(layout, (CARD_VIEW_WIDTH.CP(scale_) - - CARD_VIEW_ICON_SIZE.CP(scale_) - - 2 * CARD_VIEW_ICON_OUTLINE_WIDTH.CP(scale_) - - 2 * CARD_VIEW_PADDING.CP(scale_) - - CARD_VIEW_ICON_TEXT_GAP.CP(scale_)) * PANGO_SCALE); + pango_layout_set_spacing(layout, CARD_VIEW_TEXT_LINE_SPACING * PANGO_SCALE); + pango_layout_set_width(layout, (CARD_VIEW_WIDTH - + CARD_VIEW_ICON_SIZE - + 2 * CARD_VIEW_ICON_OUTLINE_WIDTH - + 2 * CARD_VIEW_PADDING - + CARD_VIEW_ICON_TEXT_GAP) * PANGO_SCALE); pango_layout_set_height(layout, -4); pango_layout_set_markup(layout, final_text.str().c_str(), -1); pango_context = pango_layout_get_context(layout); // is not ref'ed - pango_cairo_context_set_font_options(pango_context, - gdk_screen_get_font_options(screen)); - pango_cairo_context_set_resolution(pango_context, - dpi == -1 ? 96.0f : dpi/(float) PANGO_SCALE); + pango_cairo_context_set_font_options(pango_context, gdk_screen_get_font_options(screen)); + pango_cairo_context_set_resolution(pango_context, 96.0 * Settings::Instance().font_scaling()); pango_layout_context_changed(layout); cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); @@ -356,7 +350,7 @@ void ResultRendererHorizontalTile::LoadText(Result const& row) PangoRectangle logRect = {0, 0, 0, 0}; pango_layout_get_extents(layout, NULL, &logRect); if (pango_layout_get_line_count(layout) < 4) - offset = ((CARD_VIEW_HEIGHT.CP(scale_) - 2 * CARD_VIEW_PADDING.CP(scale_)) - (logRect.height / PANGO_SCALE)) / 2.0; + offset = ((CARD_VIEW_HEIGHT - 2 * CARD_VIEW_PADDING) - (logRect.height / PANGO_SCALE)) / 2.0; cairo_move_to(cr, 0.0f, offset); pango_cairo_show_layout(cr, layout); @@ -364,8 +358,6 @@ void ResultRendererHorizontalTile::LoadText(Result const& row) pango_font_description_free(desc); g_object_unref(layout); - cairo_destroy(cr); - TextureContainer *container = row.renderer<TextureContainer*>(); if (container) container->text = texture_ptr_from_cairo_graphics(_cairoGraphics); @@ -381,11 +373,11 @@ nux::NBitmapData* ResultRendererHorizontalTile::GetDndImage(Result const& row) c int width = gdk_pixbuf_get_width(container->drag_icon); int height = gdk_pixbuf_get_height(container->drag_icon); - if (width != CARD_VIEW_ICON_SIZE.CP(scale_) || height != CARD_VIEW_ICON_SIZE.CP(scale_)) + if (width != CARD_VIEW_ICON_SIZE.CP(scale()) || height != CARD_VIEW_ICON_SIZE.CP(scale())) { nux::GdkGraphics graphics(gdk_pixbuf_scale_simple(container->drag_icon, - CARD_VIEW_ICON_SIZE.CP(scale_), - CARD_VIEW_ICON_SIZE.CP(scale_), + CARD_VIEW_ICON_SIZE.CP(scale()), + CARD_VIEW_ICON_SIZE.CP(scale()), GDK_INTERP_BILINEAR)); bitmap = graphics.GetBitmap(); } diff --git a/dash/ResultRendererHorizontalTile.h b/dash/ResultRendererHorizontalTile.h index 1fdf2e259..e6cd48894 100644 --- a/dash/ResultRendererHorizontalTile.h +++ b/dash/ResultRendererHorizontalTile.h @@ -51,8 +51,6 @@ public: virtual nux::NBitmapData* GetDndImage(Result const& row) const; - void UpdateScale(double scale); - protected: virtual void LoadText(Result const& row); diff --git a/dash/ResultRendererTile.cpp b/dash/ResultRendererTile.cpp index 5075565df..f20a298d0 100644 --- a/dash/ResultRendererTile.cpp +++ b/dash/ResultRendererTile.cpp @@ -32,6 +32,7 @@ #include "unity-shared/DashStyle.h" #include "unity-shared/TextureCache.h" #include "unity-shared/RawPixel.h" +#include "unity-shared/UnitySettings.h" namespace unity { @@ -39,17 +40,16 @@ DECLARE_LOGGER(logger, "unity.dash.results"); namespace { - -std::string const DEFAULT_GICON = ". GThemedIcon text-x-preview"; -RawPixel const PADDING = 6_em; -RawPixel const SPACING = 10_em; -RawPixel const FONT_SIZE = 10_em; -int const FONT_MULTIPLIER = 1024; +const std::string DEFAULT_GICON = ". GThemedIcon text-x-preview"; +const RawPixel PADDING = 6_em; +const RawPixel SPACING = 10_em; +const int FONT_SIZE = 10; +const int FONT_MULTIPLIER = 1024; char const REPLACEMENT_CHAR = '?'; float const CORNER_HIGHTLIGHT_RADIUS = 2.0f; -void RenderTexture(nux::GraphicsEngine& GfxContext, +void RenderTexture(nux::GraphicsEngine& GfxContext, int x, int y, int width, @@ -94,6 +94,7 @@ ResultRendererTile::ResultRendererTile(NUX_FILE_LINE_DECL) : ResultRenderer(NUX_FILE_LINE_PARAM) { UpdateWidthHeight(); + scale.changed.connect([this] (double) { UpdateWidthHeight(); }); } void ResultRendererTile::UpdateWidthHeight() @@ -102,14 +103,8 @@ void ResultRendererTile::UpdateWidthHeight() RawPixel tile_width = style.GetTileWidth(); RawPixel tile_height = style.GetTileHeight(); - width = tile_width.CP(scale_); - height = tile_height.CP(scale_); -} - -void ResultRendererTile::UpdateScale(double scale) -{ - ResultRenderer::UpdateScale(scale); - UpdateWidthHeight(); + width = tile_width.CP(scale()); + height = tile_height.CP(scale()); } void ResultRendererTile::Render(nux::GraphicsEngine& GfxContext, @@ -131,7 +126,7 @@ void ResultRendererTile::Render(nux::GraphicsEngine& GfxContext, RawPixel const tile_highlight_width = style.GetTileIconHightlightWidth(); RawPixel const tile_highlight_height = style.GetTileIconHightlightHeight(); - int tile_icon_size = tile_size.CP(scale_); + int tile_icon_size = tile_size.CP(scale()); // set up our texture mode nux::TexCoordXForm texxform; @@ -148,13 +143,13 @@ void ResultRendererTile::Render(nux::GraphicsEngine& GfxContext, } int icon_left_hand_side = geometry.x + (geometry.width - icon_width) / 2; - int icon_top_side = geometry.y + PADDING.CP(scale_) + (tile_icon_size - icon_height) / 2; + int icon_top_side = geometry.y + PADDING.CP(scale()) + (tile_icon_size - icon_height) / 2; // render highlight if its needed if (container->prelight && state != ResultRendererState::RESULT_RENDERER_NORMAL) { - int highlight_x = (geometry.x + geometry.width/2) - tile_highlight_width.CP(scale_)/2; - int highlight_y = (geometry.y + PADDING.CP(scale_) + tile_icon_size / 2) - tile_highlight_height.CP(scale_)/2; + int highlight_x = (geometry.x + geometry.width/2) - tile_highlight_width.CP(scale())/2; + int highlight_y = (geometry.y + PADDING.CP(scale()) + tile_icon_size / 2) - tile_highlight_height.CP(scale())/2; RenderTexture(GfxContext, highlight_x, @@ -184,10 +179,10 @@ void ResultRendererTile::Render(nux::GraphicsEngine& GfxContext, if (container->text) { RenderTexture(GfxContext, - geometry.x + PADDING.CP(scale_), - geometry.y + tile_icon_size + SPACING.CP(scale_), - tile_width.CP(scale_) - (PADDING.CP(scale_) * 2), - tile_height.CP(scale_) - tile_icon_size - SPACING.CP(scale_), + geometry.x + PADDING.CP(scale()), + geometry.y + tile_icon_size + SPACING.CP(scale()), + tile_width.CP(scale()) - (PADDING.CP(scale()) * 2), + tile_height.CP(scale()) - tile_icon_size - SPACING.CP(scale()), container->text->GetDeviceTexture(), texxform, color, @@ -198,6 +193,7 @@ void ResultRendererTile::Render(nux::GraphicsEngine& GfxContext, nux::BaseTexture* ResultRendererTile::DrawHighlight(std::string const& texid, int width, int height) { nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, width, height); + cairo_surface_set_device_scale(cairo_graphics.GetSurface(), scale(), scale()); cairo_t* cr = cairo_graphics.GetInternalContext(); cairo_scale(cr, 1.0f, 1.0f); @@ -214,8 +210,8 @@ nux::BaseTexture* ResultRendererTile::DrawHighlight(std::string const& texid, in 0.0f, 0.0f, CORNER_HIGHTLIGHT_RADIUS, - width, - height, + width/scale(), + height/scale(), false); cairo_fill(cr); @@ -224,7 +220,7 @@ nux::BaseTexture* ResultRendererTile::DrawHighlight(std::string const& texid, in int ResultRendererTile::Padding() const { - return PADDING.CP(scale_); + return PADDING.CP(scale()); } void ResultRendererTile::Preload(Result const& row) @@ -282,9 +278,8 @@ void ResultRendererTile::LoadIcon(Result const& row) RawPixel const tile_highlight_width = style.GetTileIconHightlightWidth(); RawPixel const tile_highlight_height = style.GetTileIconHightlightHeight(); - std::string icon_hint(row.icon_hint); - std::string icon_name; - icon_name = !icon_hint.empty() ? icon_hint : DEFAULT_GICON; + std::string const& icon_hint = row.icon_hint; + std::string const& icon_name = !icon_hint.empty() ? icon_hint : DEFAULT_GICON; glib::Object<GIcon> icon(g_icon_new_for_string(icon_name.c_str(), NULL)); TextureContainer* container = row.renderer<TextureContainer*>(); @@ -292,10 +287,9 @@ void ResultRendererTile::LoadIcon(Result const& row) if (container) { TextureCache& cache = TextureCache::GetDefault(); - BaseTexturePtr texture_prelight(cache.FindTexture("resultview_prelight", - tile_highlight_width.CP(scale_), - tile_highlight_height.CP(scale_), + tile_highlight_width.CP(scale()), + tile_highlight_height.CP(scale()), sigc::mem_fun(this, &ResultRendererTile::DrawHighlight))); container->prelight = texture_prelight; } @@ -306,13 +300,13 @@ void ResultRendererTile::LoadIcon(Result const& row) { bool use_large_icon = icon.IsType(G_TYPE_FILE_ICON) || !icon.IsType(G_TYPE_THEMED_ICON); container->slot_handle = IconLoader::GetDefault().LoadFromGIconString(icon_name, - tile_size.CP(scale_), + tile_size.CP(scale()), use_large_icon ? - tile_size.CP(scale_) : tile_gsize.CP(scale_), slot); + tile_size.CP(scale()) : tile_gsize.CP(scale()), slot); } else { - container->slot_handle = IconLoader::GetDefault().LoadFromIconName(icon_name, -1, tile_gsize.CP(scale_), slot); + container->slot_handle = IconLoader::GetDefault().LoadFromIconName(icon_name, -1, tile_gsize.CP(scale()), slot); } } @@ -347,7 +341,7 @@ nux::BaseTexture* ResultRendererTile::CreateTextureCallback(std::string const& t float aspect = static_cast<float>(pixbuf_height) / pixbuf_width; // already sanitized width/height so can not be 0.0 if (aspect < 1.0f) { - pixbuf_width = tile_size.CP(scale_); + pixbuf_width = tile_size.CP(scale()); pixbuf_height = pixbuf_width * aspect; if (pixbuf_height > height) @@ -370,6 +364,7 @@ nux::BaseTexture* ResultRendererTile::CreateTextureCallback(std::string const& t } nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, pixbuf_width, pixbuf_height); + cairo_surface_set_device_scale(cairo_graphics.GetSurface(), scale(), scale()); cairo_t* cr = cairo_graphics.GetInternalContext(); cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); @@ -480,32 +475,31 @@ void ResultRendererTile::LoadText(Result const& row) RawPixel const tile_height = style.GetTileHeight(); nux::CairoGraphics _cairoGraphics(CAIRO_FORMAT_ARGB32, - tile_width.CP(scale_) - (PADDING.CP(scale_) * 2), - tile_height.CP(scale_) - tile_size.CP(scale_) - SPACING.CP(scale_)); + tile_width.CP(scale()) - (PADDING.CP(scale()) * 2), + tile_height.CP(scale()) - tile_size.CP(scale()) - SPACING.CP(scale())); + cairo_surface_set_device_scale(_cairoGraphics.GetSurface(), scale(), scale()); - cairo_t* cr = _cairoGraphics.GetContext(); + cairo_t* cr = _cairoGraphics.GetInternalContext(); PangoLayout* layout = NULL; PangoFontDescription* desc = NULL; PangoContext* pango_context = NULL; GdkScreen* screen = gdk_screen_get_default(); // not ref'ed glib::String font; - int dpi = -1; g_object_get(gtk_settings_get_default(), "gtk-font-name", &font, NULL); - g_object_get(gtk_settings_get_default(), "gtk-xft-dpi", &dpi, NULL); cairo_set_font_options(cr, gdk_screen_get_font_options(screen)); layout = pango_cairo_create_layout(cr); desc = pango_font_description_from_string(font.Value()); - pango_font_description_set_size (desc, FONT_SIZE.CP(scale_) * FONT_MULTIPLIER); + pango_font_description_set_size (desc, FONT_SIZE * FONT_MULTIPLIER); pango_layout_set_font_description(layout, desc); pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_START); - pango_layout_set_width(layout, (tile_width.CP(scale_) - (PADDING.CP(scale_) * 2))* PANGO_SCALE); + pango_layout_set_width(layout, (tile_width - (PADDING * 2))* PANGO_SCALE); pango_layout_set_height(layout, -2); // FIXME bug #1239381 @@ -518,10 +512,8 @@ void ResultRendererTile::LoadText(Result const& row) g_free (escaped_text); pango_context = pango_layout_get_context(layout); // is not ref'ed - pango_cairo_context_set_font_options(pango_context, - gdk_screen_get_font_options(screen)); - pango_cairo_context_set_resolution(pango_context, - dpi == -1 ? 96.0f : dpi/(float) PANGO_SCALE); + pango_cairo_context_set_font_options(pango_context, gdk_screen_get_font_options(screen)); + pango_cairo_context_set_resolution(pango_context, 96.0 * Settings::Instance().font_scaling()); pango_layout_context_changed(layout); cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); @@ -536,7 +528,6 @@ void ResultRendererTile::LoadText(Result const& row) // clean up pango_font_description_free(desc); g_object_unref(layout); - cairo_destroy(cr); TextureContainer *container = row.renderer<TextureContainer*>(); if (container) diff --git a/dash/ResultRendererTile.h b/dash/ResultRendererTile.h index 5c41c1419..fab30fae4 100644 --- a/dash/ResultRendererTile.h +++ b/dash/ResultRendererTile.h @@ -72,11 +72,9 @@ public: virtual void Preload(Result const& row); virtual void Unload(Result const& row); - virtual nux::NBitmapData* GetDndImage(Result const& row) const; void ReloadResult(Result const& row); - void UpdateScale(double scale) override; int Padding() const; diff --git a/dash/ResultView.cpp b/dash/ResultView.cpp index d0b9cd193..110f4a5d9 100644 --- a/dash/ResultView.cpp +++ b/dash/ResultView.cpp @@ -27,6 +27,7 @@ #include "unity-shared/IntrospectableWrappers.h" #include "unity-shared/GraphicsUtils.h" +#include "unity-shared/UnitySettings.h" namespace unity { @@ -45,8 +46,8 @@ ResultView::ResultView(NUX_FILE_LINE_DECL) , expanded(true) , desaturation_progress(0.0) , enable_texture_render(false) + , scale(DEFAULT_SCALE) , renderer_(NULL) - , scale_(DEFAULT_SCALE) , cached_result_(nullptr, nullptr, nullptr) { expanded.changed.connect([this](bool value) @@ -60,7 +61,9 @@ ResultView::ResultView(NUX_FILE_LINE_DECL) NeedRedraw(); }); + Settings::Instance().font_scaling.changed.connect(sigc::mem_fun(this, &ResultView::UpdateFontScale)); enable_texture_render.changed.connect(sigc::mem_fun(this, &ResultView::OnEnableRenderToTexture)); + scale.changed.connect(sigc::mem_fun(this, &ResultView::UpdateScale)); } ResultView::~ResultView() @@ -81,21 +84,25 @@ ResultView::~ResultView() void ResultView::UpdateScale(double scale) { - if (scale_ != scale) + if (renderer_) { - scale_ = scale; + renderer_->scale = scale; - if (renderer_) - { - renderer_->UpdateScale(scale_); + for (auto const& result : *result_model_) + renderer_->ReloadResult(result); - for (auto it = result_model_->begin(); it != result_model_->end(); ++it) - { - renderer_->ReloadResult(*it); - } + QueueDraw(); + } +} - NeedRedraw(); - } +void ResultView::UpdateFontScale(double scale) +{ + if (renderer_) + { + for (auto const& result : *result_model_) + renderer_->ReloadResult(result); + + QueueDraw(); } } diff --git a/dash/ResultView.h b/dash/ResultView.h index 0abbb5f91..0b7a578ff 100644 --- a/dash/ResultView.h +++ b/dash/ResultView.h @@ -81,6 +81,8 @@ public: nux::Property<std::string> unique_id; nux::Property<float> desaturation_progress; nux::Property<bool> enable_texture_render; + nux::Property<double> scale; + sigc::signal<void, LocalResult const&, ActivateType, GVariant*> ResultActivated; std::string GetName() const; @@ -88,8 +90,6 @@ public: void AddProperties(debug::IntrospectionData&); IntrospectableList GetIntrospectableChildren(); - virtual void UpdateScale(double scale); - virtual int GetSelectedIndex() const; virtual void SetSelectedIndex(int index); @@ -123,11 +123,11 @@ protected: std::vector<ResultViewTexture::Ptr> result_textures_; - double scale_; - private: void OnRowAdded(DeeModel* model, DeeModelIter* iter); void OnRowRemoved(DeeModel* model, DeeModelIter* iter); + void UpdateScale(double scale); + void UpdateFontScale(double scale); Result cached_result_; connection::Manager result_connections_; diff --git a/dash/ResultViewGrid.cpp b/dash/ResultViewGrid.cpp index ffe47d12f..70872e449 100644 --- a/dash/ResultViewGrid.cpp +++ b/dash/ResultViewGrid.cpp @@ -91,6 +91,7 @@ ResultViewGrid::ResultViewGrid(NUX_FILE_LINE_DECL) selected_index_.changed.connect(needredraw_lambda); expanded.changed.connect([this](bool value) { if (value) all_results_preloaded_ = false; }); results_per_row.changed.connect([this](int value) { if (value > 0) all_results_preloaded_ = false; }); + scale.changed.connect(sigc::mem_fun(this, &ResultViewGrid::UpdateScale)); key_nav_focus_change.connect(sigc::mem_fun(this, &ResultViewGrid::OnKeyNavFocusChange)); key_nav_focus_activate.connect([this] (nux::Area *area) @@ -351,7 +352,7 @@ void ResultViewGrid::SizeReallocate() int width = (items_per_row * renderer_->width) + (padding*2) + ((items_per_row - 1) * horizontal_spacing); int geo_width = GetBaseWidth(); - int extra_width = geo_width - (width + WIDTH_PADDING.CP(scale_) - SCROLLBAR_WIDTH.CP(scale_)); + int extra_width = geo_width - (width + WIDTH_PADDING.CP(scale()) - SCROLLBAR_WIDTH.CP(scale())); if (items_per_row != 1) extra_horizontal_spacing_ = extra_width / (items_per_row - 1); @@ -1013,7 +1014,6 @@ ResultViewGrid::SetSelectedIndex(int index) void ResultViewGrid::UpdateScale(double scale) { - ResultView::UpdateScale(scale); UpdateRenderTextures(); } diff --git a/dash/ResultViewGrid.h b/dash/ResultViewGrid.h index c039c2337..34a854b58 100644 --- a/dash/ResultViewGrid.h +++ b/dash/ResultViewGrid.h @@ -51,7 +51,7 @@ public: virtual int GetSelectedIndex() const; virtual void SetSelectedIndex(int index); - + virtual unsigned GetIndexAtPosition(int x, int y); virtual void Activate(LocalResult const& local_result, int index, ActivateType type); @@ -60,8 +60,6 @@ public: virtual void GetResultDimensions(int& rows, int& columns); - void UpdateScale(double scale); - protected: void MouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); void MouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags); @@ -101,6 +99,7 @@ private: void QueueLazyLoad(); void QueueResultsChanged(); bool DoLazyLoad(); + void UpdateScale(double scale); int GetItemsPerRow(); void SizeReallocate(); @@ -132,7 +131,6 @@ private: UBusManager ubus_; glib::Source::UniquePtr lazy_load_source_; glib::Source::UniquePtr results_changed_idle_; - glib::Source::UniquePtr activate_timer_; }; diff --git a/dash/ScopeBar.cpp b/dash/ScopeBar.cpp index 13ab67bc6..ebe9d82ea 100644 --- a/dash/ScopeBar.cpp +++ b/dash/ScopeBar.cpp @@ -48,16 +48,13 @@ NUX_IMPLEMENT_OBJECT_TYPE(ScopeBar); ScopeBar::ScopeBar() : nux::View(NUX_TRACKER_LOCATION) - , scale_(1.0) + , scale(1.0) { + scale.changed.connect(sigc::mem_fun(this, &ScopeBar::UpdateScale)); SetupBackground(); SetupLayout(); } -ScopeBar::~ScopeBar() -{ -} - void ScopeBar::SetupBackground() { nux::ROPConfig rop; @@ -69,16 +66,11 @@ void ScopeBar::SetupBackground() void ScopeBar::UpdateScale(double scale) { - if (scale_ != scale) - { - scale_ = scale; + SetMinimumHeight(SCOPEBAR_HEIGHT.CP(scale)); + SetMaximumHeight(SCOPEBAR_HEIGHT.CP(scale)); - SetMinimumHeight(SCOPEBAR_HEIGHT.CP(scale_)); - SetMaximumHeight(SCOPEBAR_HEIGHT.CP(scale_)); - - for (auto icon : icons_) - icon->UpdateScale(scale_); - } + for (auto icon : icons_) + icon->scale = scale; } void ScopeBar::SetupLayout() @@ -87,8 +79,8 @@ void ScopeBar::SetupLayout() layout_->SetContentDistribution(nux::MAJOR_POSITION_CENTER); SetLayout(layout_); - SetMinimumHeight(SCOPEBAR_HEIGHT.CP(scale_)); - SetMaximumHeight(SCOPEBAR_HEIGHT.CP(scale_)); + SetMinimumHeight(SCOPEBAR_HEIGHT.CP(scale())); + SetMaximumHeight(SCOPEBAR_HEIGHT.CP(scale())); } void ScopeBar::AddScope(Scope::Ptr const& scope) @@ -96,7 +88,7 @@ void ScopeBar::AddScope(Scope::Ptr const& scope) ScopeBarIcon* icon = new ScopeBarIcon(scope->id, scope->icon_hint); icon->SetVisible(scope->visible); - icon->UpdateScale(scale_); + icon->scale = scale(); scope->visible.changed.connect([icon](bool visible) { icon->SetVisible(visible); } ); icons_.push_back(icon); layout_->AddView(icon, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FIX); @@ -184,7 +176,7 @@ void ScopeBar::DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw int middle = geo.x + geo.width/2; // Nux doesn't draw too well the small triangles, so let's draw a // bigger one and clip part of them using the "-1". - int size = TRIANGLE_SIZE.CP(scale_); + int size = TRIANGLE_SIZE.CP(scale()); int y = base.y - 1; nux::GetPainter().Draw2DTriangleColor(graphics_engine, diff --git a/dash/ScopeBar.h b/dash/ScopeBar.h index bdc2477c7..26b88a235 100644 --- a/dash/ScopeBar.h +++ b/dash/ScopeBar.h @@ -56,15 +56,14 @@ class ScopeBar : public nux::View, public unity::debug::Introspectable public: ScopeBar(); - ~ScopeBar(); + + nux::Property<double> scale; void AddScope(Scope::Ptr const& scope); void Activate(std::string id); void ActivateNext(); void ActivatePrevious(); - void UpdateScale(double scale); - std::string GetActiveScopeId() const; sigc::signal<void, std::string const&> scope_activated; @@ -77,6 +76,7 @@ private: void DrawContent(nux::GraphicsEngine& gfx_context, bool force_draw); void SetActive(ScopeBarIcon* icon); + void UpdateScale(double scale); bool AcceptKeyNavFocus(); std::string GetName() const; @@ -89,8 +89,6 @@ private: nux::HLayout* layout_; LayerPtr bg_layer_; - double scale_; - friend class TestScopeBar; }; diff --git a/dash/ScopeBarIcon.cpp b/dash/ScopeBarIcon.cpp index 4cb81b7f5..fce868a42 100644 --- a/dash/ScopeBarIcon.cpp +++ b/dash/ScopeBarIcon.cpp @@ -42,12 +42,12 @@ ScopeBarIcon::ScopeBarIcon(std::string id_, std::string icon_hint) : IconTexture(icon_hint, TEXTURE_SIZE) , id(id_) , active(false) + , scale(DEFAULT_SCALE) , inactive_opacity_(0.4f) - , scale_(DEFAULT_SCALE) { - SetMinMaxSize(FOCUS_OVERLAY_WIDTH.CP(scale_), FOCUS_OVERLAY_HEIGHT.CP(scale_)); + SetMinMaxSize(FOCUS_OVERLAY_WIDTH.CP(scale()), FOCUS_OVERLAY_HEIGHT.CP(scale())); - focus_layer_.reset(Style::Instance().FocusOverlay(FOCUS_OVERLAY_WIDTH.CP(scale_), FOCUS_OVERLAY_HEIGHT.CP(scale_))); + focus_layer_.reset(Style::Instance().FocusOverlay(FOCUS_OVERLAY_WIDTH.CP(scale()), FOCUS_OVERLAY_HEIGHT.CP(scale()))); SetOpacity(inactive_opacity_); @@ -56,26 +56,21 @@ ScopeBarIcon::ScopeBarIcon(std::string id_, std::string icon_hint) SetAcceptKeyNavFocusOnMouseEnter(true); active.changed.connect(sigc::mem_fun(this, &ScopeBarIcon::OnActiveChanged)); + scale.changed.connect(sigc::mem_fun(this, &ScopeBarIcon::UpdateScale)); key_nav_focus_change.connect([this](nux::Area*, bool, nux::KeyNavDirection){ QueueDraw(); }); } -ScopeBarIcon::~ScopeBarIcon() -{} - void ScopeBarIcon::UpdateScale(double scale) { - if (scale_ != scale) - { - scale_ = scale; - int overlay_width = FOCUS_OVERLAY_WIDTH.CP(scale_); - int overlay_height = FOCUS_OVERLAY_HEIGHT.CP(scale_); + int overlay_width = FOCUS_OVERLAY_WIDTH.CP(scale); + int overlay_height = FOCUS_OVERLAY_HEIGHT.CP(scale); - SetMinMaxSize(overlay_width, overlay_height); - focus_layer_.reset(Style::Instance().FocusOverlay(overlay_width, overlay_height)); + SetMinMaxSize(overlay_width, overlay_height); + focus_layer_.reset(Style::Instance().FocusOverlay(overlay_width, overlay_height)); - SetSize(TEXTURE_SIZE.CP(scale_)); - ReLoadIcon(); - } + SetSize(TEXTURE_SIZE.CP(scale)); + ReLoadIcon(); + QueueDraw(); } void ScopeBarIcon::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) @@ -105,7 +100,6 @@ void ScopeBarIcon::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) int width = 0, height = 0; GetTextureSize(&width, &height); - nux::Color col(1.0f * opacity, 1.0f * opacity, 1.0f * opacity, opacity); nux::TexCoordXForm texxform; texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD); texxform.SetWrap(nux::TEXWRAP_CLAMP_TO_BORDER, nux::TEXWRAP_CLAMP_TO_BORDER); @@ -116,7 +110,7 @@ void ScopeBarIcon::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) height, texture()->GetDeviceTexture(), texxform, - col); + nux::color::White * opacity); graphics_engine.GetRenderStates().SetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor); } diff --git a/dash/ScopeBarIcon.h b/dash/ScopeBarIcon.h index f83afd73e..a9825d168 100644 --- a/dash/ScopeBarIcon.h +++ b/dash/ScopeBarIcon.h @@ -38,16 +38,15 @@ class ScopeBarIcon : public IconTexture NUX_DECLARE_OBJECT_TYPE(ScopeBarIcon, IconTexture); public: ScopeBarIcon(std::string id, std::string icon_hint); - ~ScopeBarIcon(); - - void UpdateScale(double scale); nux::Property<std::string> id; nux::Property<bool> active; + nux::Property<double> scale; private: void Draw(nux::GraphicsEngine& gfx_context, bool force_draw); void OnActiveChanged(bool is_active); + void UpdateScale(double scale); // Introspectable std::string GetName() const; @@ -58,8 +57,6 @@ private: const float inactive_opacity_; LayerPtr focus_layer_; - - double scale_; }; } diff --git a/dash/ScopeView.cpp b/dash/ScopeView.cpp index d765d8b2e..d249ab4ef 100755 --- a/dash/ScopeView.cpp +++ b/dash/ScopeView.cpp @@ -153,6 +153,7 @@ ScopeView::ScopeView(Scope::Ptr const& scope, nux::Area* show_filters) : nux::View(NUX_TRACKER_LOCATION) , filters_expanded(false) , can_refine_search(false) +, scale(DEFAULT_SCALE) , scope_(scope) , no_results_active_(false) , last_good_filter_model_(-1) @@ -160,13 +161,13 @@ ScopeView::ScopeView(Scope::Ptr const& scope, nux::Area* show_filters) , scope_connected_(scope ? scope->connected : false) , search_on_next_connect_(false) , current_focus_category_position_(-1) -, scale_(DEFAULT_SCALE) { SetupViews(show_filters); search_string.SetGetterFunction(sigc::mem_fun(this, &ScopeView::get_search_string)); filters_expanded.changed.connect(sigc::mem_fun(this, &ScopeView::OnScopeFilterExpanded)); view_type.changed.connect(sigc::mem_fun(this, &ScopeView::OnViewTypeChanged)); + scale.changed.connect(sigc::mem_fun(this, &ScopeView::UpdateScale)); auto conn = nux::GetWindowCompositor().key_nav_focus_change.connect(sigc::mem_fun(this, &ScopeView::OnCompositorKeyNavFocusChanged)); key_nav_focus_connection_ = conn_manager_.Add(conn); @@ -215,8 +216,8 @@ ScopeView::ScopeView(Scope::Ptr const& scope, nux::Area* show_filters) (expand_label && expand_label->HasKeyFocus())) { focused_pos.x += child->GetGeometry().x; - focused_pos.y += child->GetGeometry().y - FOCUSED_OFFSET.CP(scale_); - focused_pos.height += FOCUSED_OFFSET.CP(scale_); + focused_pos.y += child->GetGeometry().y - FOCUSED_OFFSET.CP(scale()); + focused_pos.height += FOCUSED_OFFSET.CP(scale()); scroll_view_->ScrollToPosition(focused_pos); break; } @@ -281,27 +282,23 @@ void ScopeView::UpdateScopeViewSize() style.GetFilterBarLeftPadding() + style.GetFilterBarRightPadding(); - layout_->SetSpaceBetweenChildren(scope_filter_space.CP(scale_)); + double scale = this->scale(); + layout_->SetSpaceBetweenChildren(scope_filter_space.CP(scale)); - fscroll_view_->SetMinimumWidth(filter_width.CP(scale_) + right_padding.CP(scale_)); - fscroll_view_->SetMaximumWidth(filter_width.CP(scale_) + right_padding.CP(scale_)); - filter_bar_->SetMinimumWidth(filter_width.CP(scale_)); - filter_bar_->SetMaximumWidth(filter_width.CP(scale_)); + fscroll_view_->SetMinimumWidth(filter_width.CP(scale) + right_padding.CP(scale)); + fscroll_view_->SetMaximumWidth(filter_width.CP(scale) + right_padding.CP(scale)); + filter_bar_->SetMinimumWidth(filter_width.CP(scale)); + filter_bar_->SetMaximumWidth(filter_width.CP(scale)); } void ScopeView::UpdateScale(double scale) { - if (scale_ != scale) - { - scale_ = scale; - - UpdateScopeViewSize(); + UpdateScopeViewSize(); - for (auto& group : category_views_) - group->UpdateScale(scale_); + for (auto& group : category_views_) + group->scale = scale; - filter_bar_->UpdateScale(scale_); - } + filter_bar_->scale = scale; } void ScopeView::SetupCategories(Categories::Ptr const& categories) @@ -464,7 +461,7 @@ void ScopeView::OnCategoryAdded(Category const& category) group->SetIcon(icon_hint); group->SetExpanded(false); group->SetVisible(false); - group->UpdateScale(scale_); + group->scale = scale(); int view_index = category_order_.size(); auto find_view_index = std::find(category_order_.begin(), category_order_.end(), index); @@ -489,8 +486,8 @@ void ScopeView::OnCategoryAdded(Category const& category) { results_view = new ResultViewGrid(NUX_TRACKER_LOCATION); results_view->SetModelRenderer(new ResultRendererHorizontalTile(NUX_TRACKER_LOCATION)); - static_cast<ResultViewGrid*> (results_view)->horizontal_spacing = CARD_VIEW_GAP_HORIZ.CP(scale_); - static_cast<ResultViewGrid*> (results_view)->vertical_spacing = CARD_VIEW_GAP_VERT.CP(scale_); + static_cast<ResultViewGrid*> (results_view)->horizontal_spacing = CARD_VIEW_GAP_HORIZ.CP(scale()); + static_cast<ResultViewGrid*> (results_view)->vertical_spacing = CARD_VIEW_GAP_VERT.CP(scale()); } else { diff --git a/dash/ScopeView.h b/dash/ScopeView.h index 2cebd1a86..ac0659a43 100644 --- a/dash/ScopeView.h +++ b/dash/ScopeView.h @@ -69,6 +69,7 @@ public: nux::Property<bool> filters_expanded; nux::Property<ScopeViewType> view_type; nux::Property<bool> can_refine_search; + nux::Property<double> scale; sigc::signal<void, ResultView::ActivateType, LocalResult const&, GVariant*, std::string const&> result_activated; @@ -86,8 +87,6 @@ public: std::vector<ResultViewTexture::Ptr> GetResultTextureContainers(); void RenderResultTexture(ResultViewTexture::Ptr const& result_texture); - void UpdateScale(double scale); - private: void SetupViews(nux::Area* show_filters); void SetupCategories(Categories::Ptr const& categories); @@ -102,7 +101,7 @@ private: void OnResultRemoved(Result const& result); void OnSearchComplete(std::string const& search_string, glib::HintsMap const& hints, glib::Error const& err); - + void OnGroupExpanded(PlacesGroup* group); void CheckScrollBarState(); void OnColumnsChanged(); @@ -131,10 +130,11 @@ private: void BuildPreview(std::string const& uri, Preview::Ptr model); void UpdateScopeViewSize(); + void UpdateScale(double scale); virtual void Draw(nux::GraphicsEngine& gfx_context, bool force_draw); virtual void DrawContent(nux::GraphicsEngine& gfx_context, bool force_draw); - + virtual bool AcceptKeyNavFocus(); virtual std::string GetName() const; virtual void AddProperties(debug::IntrospectionData&); @@ -190,8 +190,6 @@ private: int current_focus_category_position_; glib::Variant current_focus_variant_; - double scale_; - friend class TestScopeView; }; diff --git a/debian/unity.migrations b/debian/unity.migrations index e8af18774..ea2a19b3a 100644 --- a/debian/unity.migrations +++ b/debian/unity.migrations @@ -1 +1,2 @@ tools/migration-scripts/01_unity_change_dconf_path +tools/migration-scripts/02_unity_setup_text_scale_factor diff --git a/launcher/ApplicationLauncherIcon.cpp b/launcher/ApplicationLauncherIcon.cpp index bf6192394..c80a64f4e 100644 --- a/launcher/ApplicationLauncherIcon.cpp +++ b/launcher/ApplicationLauncherIcon.cpp @@ -393,19 +393,34 @@ void ApplicationLauncherIcon::ActivateLauncherIcon(ActionArg arg) { if (scaleWasActive) // #5 above { - Focus(arg); + if (minimize_window_on_click()) + { + for (auto const& win : GetWindows(WindowFilter::ON_CURRENT_DESKTOP)) + wm.Minimize(win->window_id()); + } + else + { + Focus(arg); + } } else // #2 above { if (arg.source != ActionArg::Source::SWITCHER) { - WindowList windows = GetWindows(WindowFilter::ON_CURRENT_DESKTOP); + bool minimized = false; - if (windows.size() == 1 && minimize_window_on_click) + if (minimize_window_on_click) { - wm.Minimize(windows[0]->window_id()); + WindowList const& windows = GetWindows(WindowFilter::ON_CURRENT_DESKTOP); + + if (windows.size() == 1) + { + wm.Minimize(windows[0]->window_id()); + minimized = true; + } } - else + + if (!minimized) { Spread(true, 0, false); } diff --git a/launcher/QuicklistMenuItem.cpp b/launcher/QuicklistMenuItem.cpp index 629650280..f07c313e1 100644 --- a/launcher/QuicklistMenuItem.cpp +++ b/launcher/QuicklistMenuItem.cpp @@ -22,6 +22,7 @@ #include <gtk/gtk.h> #include "unity-shared/UBusWrapper.h" #include "unity-shared/UBusMessages.h" +#include "unity-shared/UnitySettings.h" #include "QuicklistMenuItem.h" @@ -320,21 +321,9 @@ void QuicklistMenuItem::DrawText(nux::CairoGraphics& cairo, double width, double PangoContext* pangoCtx = pango_layout_get_context(layout); // is not ref'ed pango_cairo_context_set_font_options(pangoCtx, gdk_screen_get_font_options(screen)); - - int dpi = 0; - g_object_get(settings, "gtk-xft-dpi", &dpi, nullptr); - - if (dpi == -1) - { - // use some default DPI-value - pango_cairo_context_set_resolution(pangoCtx, 96.0f); - } - else - { - pango_cairo_context_set_resolution(pangoCtx, static_cast<float>(dpi) / static_cast<float>(PANGO_SCALE)); - } - + pango_cairo_context_set_resolution(pangoCtx, 96.0 * Settings::Instance().font_scaling()); pango_layout_context_changed(layout); + PangoRectangle log_rect = {0, 0, 0, 0}; pango_layout_get_extents(layout, nullptr, &log_rect); diff --git a/panel/PanelIndicatorEntryView.cpp b/panel/PanelIndicatorEntryView.cpp index 42aff3fbf..d147d8c77 100644 --- a/panel/PanelIndicatorEntryView.cpp +++ b/panel/PanelIndicatorEntryView.cpp @@ -469,6 +469,7 @@ void PanelIndicatorEntryView::Refresh() std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font.c_str()), pango_font_description_free); pango_context_set_font_description(context, desc.get()); pango_context_set_language(context, gtk_get_default_language()); + pango_cairo_context_set_resolution(context, 96.0 * Settings::Instance().font_scaling()); label.erase(std::remove(label.begin(), label.end(), '_'), label.end()); layout = pango_layout_new(context); diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index 89c772025..4fe67ac57 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -2855,8 +2855,7 @@ bool UnityWindow::glPaint(const GLWindowPaintAttrib& attrib, { if ((window->type() != CompWindowTypePopupMenuMask || !uScreen->lockscreen_controller_->HasOpenMenu()) && - window->resName() != "onboard" && - !window->minimized()) + !window->minimized() && window->resName() != "onboard") { // For some reasons PAINT_WINDOW_NO_CORE_INSTANCE_MASK doesn't work here // (well, it works too much, as it applies to menus too), so we need @@ -3736,9 +3735,9 @@ void UnityScreen::LockscreenRequested() launcher_controller_->ClearTooltips(); - auto& adapter = PluginAdapter::Default(); - if (adapter.IsScaleActive()) - adapter.TerminateScale(); + auto& wm = WindowManager::Default(); + if (wm.IsScaleActive()) + wm.TerminateScale(); RaiseOSK(); } diff --git a/tests/data/external.gschema.xml b/tests/data/external.gschema.xml index 160b79723..bc37fffab 100644 --- a/tests/data/external.gschema.xml +++ b/tests/data/external.gschema.xml @@ -53,6 +53,21 @@ </key> </schema> + <schema id="org.gnome.desktop.interface" path="/org/gnome/desktop/interface/"> + <key type="u" name="scaling-factor"> + <default>1</default> + </key> + <key type="d" name="text-scaling-factor"> + <default>1.0</default> + </key> + <key type="s" name="font-name"> + <default>'Ubuntu 11'</default> + </key> + <key type="i" name="cursor-size"> + <default>24</default> + </key> + </schema> + <schema id="com.canonical.unity-greeter" path="/com/canonical/unity-greeter/"> <key type="s" name="logo"> <default>'/usr/share/unity-greeter/logo.png'</default> diff --git a/tests/mock-application.h b/tests/mock-application.h index c1759f1cf..4e4c0ad26 100644 --- a/tests/mock-application.h +++ b/tests/mock-application.h @@ -27,7 +27,6 @@ #include "unity-shared/ApplicationManager.h" #include "unity-shared/WindowManager.h" -#include "unity-shared/UnitySettings.h" using namespace testing; @@ -379,7 +378,6 @@ struct TestUnityAppBase : testing::Test unity_app_->actions_log_.clear(); } - unity::Settings settings; MockApplication::Ptr unity_app_; }; diff --git a/tests/test_action_link.cpp b/tests/test_action_link.cpp index 653f53ab4..99e286d71 100644 --- a/tests/test_action_link.cpp +++ b/tests/test_action_link.cpp @@ -22,7 +22,7 @@ #include <gmock/gmock.h> #include <gtest/gtest.h> -#include <unity-shared/StaticCairoText.h> +#include "unity-shared/StaticCairoText.h" #include "dash/previews/ActionLink.cpp" #include "test_utils.h" @@ -75,6 +75,7 @@ class TestActionLink : public ::testing::Test { action_link = new ActionLinkMock("action_id", "display_name"); } + nux::ObjectPtr<ActionLinkMock> action_link; }; diff --git a/tests/test_bfb_launcher_icon.cpp b/tests/test_bfb_launcher_icon.cpp index f0a210e32..e4e0cb3f7 100644 --- a/tests/test_bfb_launcher_icon.cpp +++ b/tests/test_bfb_launcher_icon.cpp @@ -19,8 +19,6 @@ #include <gmock/gmock.h> -#include "unity-shared/UnitySettings.h" - #include "BFBLauncherIcon.h" using namespace unity; @@ -39,7 +37,6 @@ public: struct TestBFBLauncherIcon : testing::Test { - unity::Settings settings; MockBFBLauncherIcon bfb; }; diff --git a/tests/test_dash_controller.cpp b/tests/test_dash_controller.cpp index a562b8f2f..b6f79fc40 100644 --- a/tests/test_dash_controller.cpp +++ b/tests/test_dash_controller.cpp @@ -20,7 +20,6 @@ #include "mock-base-window.h" #include "unity-shared/DashStyle.h" #include "unity-shared/PanelStyle.h" -#include "unity-shared/UnitySettings.h" #include "unity-shared/WindowManager.h" #include "test_utils.h" @@ -46,7 +45,6 @@ protected: nux::animation::AnimationController animation_controller; // required to create hidden secret global variables - Settings unity_settings_; dash::Style dash_style_; panel::Style panel_style_; diff --git a/tests/test_dashview.cpp b/tests/test_dashview.cpp index 16e54c839..684d62c11 100644 --- a/tests/test_dashview.cpp +++ b/tests/test_dashview.cpp @@ -32,10 +32,8 @@ #include "dash/ApplicationStarter.h" #include "unity-shared/DashStyle.h" #include "unity-shared/PanelStyle.h" -#include "unity-shared/UnitySettings.h" #include "test_mock_scope.h" -#include "test_utils.h" using namespace unity; using namespace unity::dash; @@ -70,9 +68,6 @@ public: {} virtual ~TestDashView() {} - virtual void SetUp() { Utils::init_gsettings_test_environment(); } - virtual void TearDown() { Utils::reset_gsettings_test_environment(); } - class MockDashView : public DashView { public: @@ -86,7 +81,6 @@ public: }; protected: - Settings unity_settings_; dash::Style dash_style_; panel::Style panel_style_; MockApplicationStarter::Ptr application_starter_; diff --git a/tests/test_desktop_launcher_icon.cpp b/tests/test_desktop_launcher_icon.cpp index 00c8af58f..9320d280a 100644 --- a/tests/test_desktop_launcher_icon.cpp +++ b/tests/test_desktop_launcher_icon.cpp @@ -19,7 +19,6 @@ #include <gmock/gmock.h> -#include "unity-shared/UnitySettings.h" #include "unity-shared/WindowManager.h" #include "launcher/DesktopLauncherIcon.h" @@ -31,7 +30,6 @@ namespace struct TestDesktopLauncherIcon : testing::Test { - unity::Settings settings; DesktopLauncherIcon icon; }; diff --git a/tests/test_device_launcher_section.cpp b/tests/test_device_launcher_section.cpp index 02afef3d5..4d6e45a8a 100644 --- a/tests/test_device_launcher_section.cpp +++ b/tests/test_device_launcher_section.cpp @@ -22,8 +22,6 @@ #include <gmock/gmock.h> -#include "unity-shared/UnitySettings.h" - #include "DevicesSettings.h" #include "test_mock_devices.h" #include "test_utils.h" @@ -60,7 +58,6 @@ struct TestDeviceLauncherSection : Test , section_(monitor_, devices_settings_, notifications_) {} - unity::Settings settings_; MockVolumeMonitorWrapper::Ptr monitor_; DevicesSettings::Ptr devices_settings_; DeviceNotificationDisplay::Ptr notifications_; diff --git a/tests/test_error_preview.cpp b/tests/test_error_preview.cpp index 94221d427..a339e0d2c 100644 --- a/tests/test_error_preview.cpp +++ b/tests/test_error_preview.cpp @@ -28,7 +28,6 @@ using namespace testing; #include <unity-shared/DashStyle.h> #include <unity-shared/PreviewStyle.h> #include <unity-shared/ThumbnailGenerator.h> -#include "unity-shared/UnitySettings.h" #include <unity-protocol.h> #include "dash/previews/ErrorPreview.h" @@ -100,7 +99,6 @@ class TestErrorPreview : public Test UnityProtocolPreviewPaymentType preview_type; // needed for styles - unity::Settings settings; dash::Style dash_style; }; diff --git a/tests/test_expo_launcher_icon.cpp b/tests/test_expo_launcher_icon.cpp index 69b7789fa..632210ae5 100644 --- a/tests/test_expo_launcher_icon.cpp +++ b/tests/test_expo_launcher_icon.cpp @@ -23,8 +23,6 @@ #include "launcher/ExpoLauncherIcon.h" #include "test_standalone_wm.h" -#include "unity-shared/UnitySettings.h" - using namespace unity; using namespace unity::launcher; @@ -33,7 +31,6 @@ namespace struct TestExpoLauncherIcon : testing::Test { - unity::Settings settings; ExpoLauncherIcon icon; testwrapper::StandaloneWM wm; }; diff --git a/tests/test_favorite_store_gsettings.cpp b/tests/test_favorite_store_gsettings.cpp index 1e0769218..9f9c1b4b0 100644 --- a/tests/test_favorite_store_gsettings.cpp +++ b/tests/test_favorite_store_gsettings.cpp @@ -23,7 +23,6 @@ #include <gmock/gmock.h> #include <glib.h> -#include "test_utils.h" #include "FavoriteStore.h" #include "FavoriteStoreGSettings.h" @@ -77,20 +76,12 @@ public: virtual void SetUp() { - // set the data directory so gsettings can find the schema - Utils::init_gsettings_test_environment(); - favorite_store.reset(new internal::FavoriteStoreGSettings()); // Setting the test values gsettings_client = g_settings_new(SETTINGS_NAME); g_settings_set_strv(gsettings_client, SETTINGS_KEY, base_store_favs); } - - virtual void TearDown() - { - Utils::reset_gsettings_test_environment(); - } }; TEST_F(TestFavoriteStoreGSettings, TestAllocation) diff --git a/tests/test_filter_widgets.cpp b/tests/test_filter_widgets.cpp index 7b33b6bc8..b25a6a28f 100644 --- a/tests/test_filter_widgets.cpp +++ b/tests/test_filter_widgets.cpp @@ -24,7 +24,6 @@ #include <gtest/gtest.h> #include "test_filter_multirange.h" #include "unity-shared/DashStyle.h" -#include "unity-shared/UnitySettings.h" #include <Nux/Nux.h> #include <NuxGraphics/Events.h> @@ -113,7 +112,6 @@ public: FALSE); } - Settings unity_settings_; dash::Style dash_style_; glib::Object<DeeModel> model_; diff --git a/tests/test_gnome_session_manager.cpp b/tests/test_gnome_session_manager.cpp index 0335012d5..bf2e53d33 100644 --- a/tests/test_gnome_session_manager.cpp +++ b/tests/test_gnome_session_manager.cpp @@ -134,8 +134,6 @@ struct TestGnomeSessionManager : testing::Test { static void SetUpTestCase() { - Utils::init_gsettings_test_environment(); - can_shutdown_ = (g_random_int() % 2) ? true : false; can_suspend_ = (g_random_int() % 2) ? true : false; can_hibernate_ = (g_random_int() % 2) ? true : false; @@ -246,8 +244,6 @@ struct TestGnomeSessionManager : testing::Test static void TearDownTestCase() { - Utils::reset_gsettings_test_environment(); - bool cancelled = false; bool closed = false; shell_proxy_->Connect("Canceled", [&cancelled] (GVariant*) { cancelled = true; }); diff --git a/tests/test_gsettings_scopes.cpp b/tests/test_gsettings_scopes.cpp index 18452b398..f71bfca54 100644 --- a/tests/test_gsettings_scopes.cpp +++ b/tests/test_gsettings_scopes.cpp @@ -52,7 +52,6 @@ class TestGSettingsScopes : public testing::Test public: TestGSettingsScopes():scope_added(0),scope_removed(0),scopes_reordered(0) {} - virtual ~TestGSettingsScopes() {} virtual void SetUp() { Utils::init_gsettings_test_environment(); } virtual void TearDown() { Utils::reset_gsettings_test_environment(); } diff --git a/tests/test_hud_button.cpp b/tests/test_hud_button.cpp index 084df315d..67d211f5a 100644 --- a/tests/test_hud_button.cpp +++ b/tests/test_hud_button.cpp @@ -28,7 +28,6 @@ #include "hud/HudButton.h" #include "unity-shared/DashStyle.h" #include "unity-shared/StaticCairoText.h" -#include "unity-shared/UnitySettings.h" using namespace unity; @@ -37,7 +36,6 @@ namespace TEST(TestHudButton, TestLabelOpacity) { - Settings unity_settings; dash::Style dash_style; nux::ObjectPtr<hud::HudButton> button(new hud::HudButton()); nux::Layout* layout = button->GetLayout(); diff --git a/tests/test_hud_controller.cpp b/tests/test_hud_controller.cpp index 99cdd8249..3788addad 100644 --- a/tests/test_hud_controller.cpp +++ b/tests/test_hud_controller.cpp @@ -27,7 +27,6 @@ using namespace testing; #include "mock-base-window.h" #include "unity-shared/DashStyle.h" #include "unity-shared/PanelStyle.h" -#include "unity-shared/UnitySettings.h" #include "unity-shared/WindowManager.h" #include "test_utils.h" using namespace unity; @@ -74,7 +73,6 @@ struct TestHudController : Test protected: // required to create hidden secret global variables - Settings unity_settings_; dash::Style dash_style_; panel::Style panel_style_; diff --git a/tests/test_hud_launcher_icon.cpp b/tests/test_hud_launcher_icon.cpp index 63c45b750..26b8aa978 100644 --- a/tests/test_hud_launcher_icon.cpp +++ b/tests/test_hud_launcher_icon.cpp @@ -21,7 +21,6 @@ #include "HudLauncherIcon.h" -#include "unity-shared/UnitySettings.h" using namespace unity; using namespace unity::launcher; @@ -39,7 +38,6 @@ public: struct TestHudLauncherIcon : testing::Test { - unity::Settings settings; MockHudLauncherIcon hud; }; diff --git a/tests/test_hud_view.cpp b/tests/test_hud_view.cpp index ca76ddcc3..049b5ae3d 100644 --- a/tests/test_hud_view.cpp +++ b/tests/test_hud_view.cpp @@ -31,7 +31,6 @@ #include "hud/HudView.h" #include "unity-shared/DashStyle.h" #include "unity-shared/PanelStyle.h" -#include "unity-shared/UnitySettings.h" using namespace unity; @@ -40,7 +39,6 @@ namespace TEST(TestHudView, TestSetQueries) { - Settings unity_settings; dash::Style dash_style; panel::Style panel_style; nux::ObjectPtr<hud::View> view(new hud::View()); diff --git a/tests/test_launcher.cpp b/tests/test_launcher.cpp index 83cbf5a4b..aeccdfcc2 100644 --- a/tests/test_launcher.cpp +++ b/tests/test_launcher.cpp @@ -29,7 +29,6 @@ using namespace testing; #include "launcher/MockLauncherIcon.h" #include "launcher/Launcher.h" #include "unity-shared/PanelStyle.h" -#include "unity-shared/UnitySettings.h" #include "unity-shared/IconRenderer.h" #include "unity-shared/UBusMessages.h" #include "test_standalone_wm.h" @@ -187,7 +186,6 @@ public: return icons; } - Settings settings; panel::Style panel_style; MockUScreen uscreen; testwrapper::StandaloneWM WM; diff --git a/tests/test_launcher_controller.cpp b/tests/test_launcher_controller.cpp index ebae3101f..b9d884072 100644 --- a/tests/test_launcher_controller.cpp +++ b/tests/test_launcher_controller.cpp @@ -33,7 +33,6 @@ #include "VolumeLauncherIcon.h" #include "SoftwareCenterLauncherIcon.h" #include "PanelStyle.h" -#include "UnitySettings.h" #include "UBusMessages.h" #include "logger_helper.h" #include "test_utils.h" @@ -279,7 +278,6 @@ protected: std::shared_ptr<helper::CaptureLogOutput> logger_output_; MockUScreen uscreen; - Settings settings; panel::Style panel_style; MockFavoriteStore favorite_store; MockXdndManager::Ptr xdnd_manager_; diff --git a/tests/test_launcher_icon.cpp b/tests/test_launcher_icon.cpp index 2bd5dd4c2..c7ba66ed4 100644 --- a/tests/test_launcher_icon.cpp +++ b/tests/test_launcher_icon.cpp @@ -21,7 +21,6 @@ #include <Nux/NuxTimerTickSource.h> #include "LauncherIcon.h" -#include "UnitySettings.h" using namespace unity; using namespace unity::launcher; @@ -71,7 +70,6 @@ struct TestLauncherIcon : Test nux::NuxTimerTickSource tick_source_; nux::animation::AnimationController animation_controller; unsigned animations_tick_; - unity::Settings settings; MockLauncherIcon icon; }; diff --git a/tests/test_launcher_minimize_speed.cpp b/tests/test_launcher_minimize_speed.cpp index 83a2960cc..16fff73c5 100644 --- a/tests/test_launcher_minimize_speed.cpp +++ b/tests/test_launcher_minimize_speed.cpp @@ -22,7 +22,6 @@ #include <gio/gio.h> #include <gtest/gtest.h> -#include "test_utils.h" #include "plugins/unityshell/src/WindowMinimizeSpeedController.h" @@ -36,19 +35,12 @@ class TestLauncherMinimizeSpeed : public Test { public: glib::Object<GSettings> mSettings; - WindowMinimizeSpeedController* mController; - + std::shared_ptr<WindowMinimizeSpeedController> mController; + /* override */ void SetUp() { - Utils::init_gsettings_test_environment(); mSettings = g_settings_new("com.canonical.Unity"); - mController = new WindowMinimizeSpeedController(); - } - - /* override */ void TearDown() - { - Utils::reset_gsettings_test_environment(); - delete mController; + mController = std::make_shared<WindowMinimizeSpeedController>(); } }; diff --git a/tests/test_launcher_tooltip.cpp b/tests/test_launcher_tooltip.cpp index ebf9862d3..e445cfef6 100644 --- a/tests/test_launcher_tooltip.cpp +++ b/tests/test_launcher_tooltip.cpp @@ -25,7 +25,6 @@ #include "unity-shared/StaticCairoText.h" #include "launcher/Tooltip.h" -#include <unity-shared/UnitySettings.h> #include "test_utils.h" namespace unity @@ -73,7 +72,6 @@ class TestTooltip : public ::testing::Test protected: TestTooltip() : Test() { - Settings settings; tooltip = new TooltipMock(); } diff --git a/tests/test_lockscreen_controller.cpp b/tests/test_lockscreen_controller.cpp index 606936273..c3835a2bc 100644 --- a/tests/test_lockscreen_controller.cpp +++ b/tests/test_lockscreen_controller.cpp @@ -30,7 +30,6 @@ using namespace testing; #include "lockscreen/LockScreenSettings.h" #include "unity-shared/PanelStyle.h" #include "unity-shared/UScreen.h" -#include "unity-shared/UnitySettings.h" #include "test_mock_session_manager.h" #include "test_uscreen_mock.h" #include "test_utils.h" @@ -109,7 +108,6 @@ struct TestLockScreenController : Test nux::animation::AnimationController animation_controller; MockUScreen uscreen; - unity::Settings unity_settings; unity::panel::Style panel_style; unity::lockscreen::Settings lockscreen_settings; static glib::DBusServer::Ptr lightdm_; diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 56b8e937c..5321f8e52 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -7,7 +7,7 @@ #include "logger_helper.h" #include "test_utils.h" - +#include "UnitySettings.h" int main(int argc, char** argv) { @@ -22,6 +22,7 @@ int main(int argc, char** argv) gtk_init(&argc, &argv); setlocale(LC_ALL, "C"); + unity::Settings settings; nux::NuxInitialize(0); std::unique_ptr<nux::WindowThread> win_thread(nux::CreateNuxWindow("Tests", diff --git a/tests/test_panel_controller.cpp b/tests/test_panel_controller.cpp index ac9a27804..eea0f2fe1 100644 --- a/tests/test_panel_controller.cpp +++ b/tests/test_panel_controller.cpp @@ -22,7 +22,6 @@ #include "PanelController.h" #include "PanelStyle.h" #include "PanelView.h" -#include "UnitySettings.h" #include "mock_menu_manager.h" #include "test_uscreen_mock.h" #include "launcher/LauncherOptions.h" @@ -43,7 +42,6 @@ struct TestPanelController : public testing::Test } MockUScreen uscreen; - Settings settings; Style panel_style; menu::MockManager::Ptr menus; ui::EdgeBarrierController::Ptr edge_barriers; diff --git a/tests/test_panel_indicator_entry_dropdown_view.cpp b/tests/test_panel_indicator_entry_dropdown_view.cpp index cb9088224..74e7cdb8a 100644 --- a/tests/test_panel_indicator_entry_dropdown_view.cpp +++ b/tests/test_panel_indicator_entry_dropdown_view.cpp @@ -23,7 +23,6 @@ #include <Nux/Nux.h> #include "PanelIndicatorEntryDropdownView.h" #include "PanelStyle.h" -#include "UnitySettings.h" #include "mock_indicators.h" #include "test_standalone_wm.h" @@ -67,7 +66,6 @@ struct TestPanelIndicatorEntryDropdownView : Test return PanelIndicatorEntryView::Ptr(new PanelIndicatorEntryView(entry)); } - Settings settings_; Style style_; MockIndicators::Ptr indicators_; PanelIndicatorEntryDropdownView dropdown; diff --git a/tests/test_panel_indicators_view.cpp b/tests/test_panel_indicators_view.cpp index 19d09d862..aec313f47 100644 --- a/tests/test_panel_indicators_view.cpp +++ b/tests/test_panel_indicators_view.cpp @@ -24,7 +24,6 @@ #include <Nux/HLayout.h> #include "PanelIndicatorsView.h" #include "PanelStyle.h" -#include "UnitySettings.h" #include "mock_indicators.h" namespace unity @@ -52,7 +51,6 @@ struct MockPanelIndicatorsView : PanelIndicatorsView struct TestPanelIndicatorsView : testing::Test { - Settings settings_; Style style_; testing::NiceMock<MockPanelIndicatorsView> indicators; }; diff --git a/tests/test_panel_menu_view.cpp b/tests/test_panel_menu_view.cpp index 13746a732..074aa4803 100644 --- a/tests/test_panel_menu_view.cpp +++ b/tests/test_panel_menu_view.cpp @@ -21,7 +21,6 @@ #include <Nux/Nux.h> #include "PanelMenuView.h" #include "PanelStyle.h" -#include "UnitySettings.h" #include "UBusMessages.h" #include "mock_menu_manager.h" #include "test_standalone_wm.h" @@ -78,7 +77,6 @@ protected: // The order is important, i.e. menu_view needs // panel::Style that needs Settings MockUScreen uscreen; - Settings settings; panel::Style panelStyle; testwrapper::StandaloneWM WM; testing::NiceMock<MockPanelMenuView> menu_view; diff --git a/tests/test_panel_style.cpp b/tests/test_panel_style.cpp index d39fe6a79..3bee7d0c6 100644 --- a/tests/test_panel_style.cpp +++ b/tests/test_panel_style.cpp @@ -25,8 +25,6 @@ #include <Nux/Nux.h> #include "unity-shared/PanelStyle.h" -#include "unity-shared/UnitySettings.h" -#include "test_utils.h" #include "MultiMonitor.h" @@ -42,23 +40,15 @@ class TestPanelStyle : public Test { public: glib::Object<GSettings> gsettings; - Settings unity_settings; std::unique_ptr<panel::Style> panel_style_instance; /* override */ void SetUp() { - Utils::init_gsettings_test_environment(); - gsettings = g_settings_new("org.gnome.desktop.wm.preferences"); g_settings_set_string(gsettings, "titlebar-font", TITLEBAR_FONT.c_str()); panel_style_instance.reset(new panel::Style()); } - - /* override */ void TearDown() - { - Utils::reset_gsettings_test_environment(); - } }; TEST_F(TestPanelStyle, TestGetFontDescription) @@ -80,7 +70,7 @@ TEST_F(TestPanelStyle, TestChangedSignal) sleep(1); ASSERT_TRUE(signal_received); - ASSERT_EQ(panel_style_instance->GetFontDescription(panel::PanelItem::TITLE), "Ubuntu Italic 11"); + ASSERT_EQ(panel_style_instance->GetFontDescription(panel::PanelItem::TITLE), "Ubuntu Italic 11"); g_settings_set_string(gsettings, "titlebar-font", old_font); g_free (old_font); diff --git a/tests/test_panel_view.cpp b/tests/test_panel_view.cpp index d888fbac3..dfba31fae 100644 --- a/tests/test_panel_view.cpp +++ b/tests/test_panel_view.cpp @@ -25,7 +25,6 @@ #include "unity-shared/PanelStyle.h" #include "unity-shared/UBusMessages.h" #include "unity-shared/UBusWrapper.h" -#include "unity-shared/UnitySettings.h" #include "mock_menu_manager.h" #include "test_standalone_wm.h" @@ -39,7 +38,6 @@ using namespace unity::panel; class TestPanelView : public testing::Test { public: - Settings unity_settings_; Style panel_style_; UBusManager ubus_manager_; nux::ObjectPtr<MockableBaseWindow> window_; diff --git a/tests/test_previews_application.cpp b/tests/test_previews_application.cpp index 78dc53743..8a268869e 100644 --- a/tests/test_previews_application.cpp +++ b/tests/test_previews_application.cpp @@ -27,7 +27,6 @@ using namespace testing; #include <unity-shared/DashStyle.h> #include <unity-shared/PreviewStyle.h> #include <unity-shared/ThumbnailGenerator.h> -#include "unity-shared/UnitySettings.h" #include <unity-protocol.h> #include "UnityCore/ApplicationPreview.h" @@ -99,7 +98,6 @@ public: nux::ObjectPtr<nux::BaseWindow> parent_window_; dash::Preview::Ptr preview_model_; - unity::Settings settings; previews::Style panel_style; dash::Style dash_style; ThumbnailGenerator thumbnail_generator; diff --git a/tests/test_previews_generic.cpp b/tests/test_previews_generic.cpp index d8327680d..06699a28c 100644 --- a/tests/test_previews_generic.cpp +++ b/tests/test_previews_generic.cpp @@ -27,7 +27,6 @@ using namespace testing; #include <unity-shared/DashStyle.h> #include <unity-shared/PreviewStyle.h> #include <unity-shared/ThumbnailGenerator.h> -#include "unity-shared/UnitySettings.h" #include <unity-protocol.h> #include "UnityCore/GenericPreview.h" @@ -86,7 +85,6 @@ public: nux::ObjectPtr<nux::BaseWindow> parent_window_; dash::Preview::Ptr preview_model_; - unity::Settings settings; previews::Style panel_style; dash::Style dash_style; ThumbnailGenerator thumbnail_generator; diff --git a/tests/test_previews_movie.cpp b/tests/test_previews_movie.cpp index fb9f71b40..8d8221cff 100644 --- a/tests/test_previews_movie.cpp +++ b/tests/test_previews_movie.cpp @@ -27,7 +27,6 @@ using namespace testing; #include <unity-shared/DashStyle.h> #include <unity-shared/PreviewStyle.h> #include <unity-shared/ThumbnailGenerator.h> -#include "unity-shared/UnitySettings.h" #include <unity-protocol.h> #include "UnityCore/MoviePreview.h" @@ -94,7 +93,6 @@ public: nux::ObjectPtr<nux::BaseWindow> parent_window_; dash::Preview::Ptr preview_model_; - unity::Settings settings; previews::Style panel_style; dash::Style dash_style; ThumbnailGenerator thumbnail_generator; diff --git a/tests/test_previews_music.cpp b/tests/test_previews_music.cpp index 364fbf2c6..04df70066 100644 --- a/tests/test_previews_music.cpp +++ b/tests/test_previews_music.cpp @@ -27,7 +27,6 @@ using namespace testing; #include <unity-shared/DashStyle.h> #include <unity-shared/PreviewStyle.h> #include <unity-shared/ThumbnailGenerator.h> -#include "unity-shared/UnitySettings.h" #include <unity-protocol.h> #include "UnityCore/MusicPreview.h" @@ -89,7 +88,6 @@ public: nux::ObjectPtr<nux::BaseWindow> parent_window_; dash::Preview::Ptr preview_model_; - unity::Settings settings; previews::Style panel_style; dash::Style dash_style; ThumbnailGenerator thumbnail_generator; diff --git a/tests/test_previews_music_payment.cpp b/tests/test_previews_music_payment.cpp index 9d88c0b22..ad14e7952 100644 --- a/tests/test_previews_music_payment.cpp +++ b/tests/test_previews_music_payment.cpp @@ -27,7 +27,6 @@ #include <unity-shared/DashStyle.h> #include <unity-shared/PreviewStyle.h> #include <unity-shared/ThumbnailGenerator.h> -#include "unity-shared/UnitySettings.h" #include <unity-protocol.h> #include "dash/previews/MusicPaymentPreview.h" @@ -125,7 +124,6 @@ class TestMusicPaymentPreview : public ::testing::Test UnityProtocolPreviewPaymentType preview_type; // needed for styles - unity::Settings settings; dash::Style dash_style; }; diff --git a/tests/test_previews_payment.cpp b/tests/test_previews_payment.cpp index 916c7f711..53eecf249 100644 --- a/tests/test_previews_payment.cpp +++ b/tests/test_previews_payment.cpp @@ -28,7 +28,6 @@ #include <unity-shared/PreviewStyle.h> #include <unity-shared/ThumbnailGenerator.h> #include <unity-shared/CoverArt.h> -#include "unity-shared/UnitySettings.h" #include <unity-protocol.h> #include "dash/previews/PaymentPreview.h" @@ -146,7 +145,6 @@ class TestPaymentPreview : public ::testing::Test dash::Preview::Ptr preview_model; // needed for styles - unity::Settings settings; dash::Style dash_style; }; diff --git a/tests/test_previews_social.cpp b/tests/test_previews_social.cpp index 0863ffe42..4c555555f 100644 --- a/tests/test_previews_social.cpp +++ b/tests/test_previews_social.cpp @@ -27,7 +27,6 @@ using namespace testing; #include <unity-shared/DashStyle.h> #include <unity-shared/PreviewStyle.h> #include <unity-shared/ThumbnailGenerator.h> -#include "unity-shared/UnitySettings.h" #include <unity-protocol.h> #include "UnityCore/SocialPreview.h" @@ -84,7 +83,6 @@ public: nux::ObjectPtr<nux::BaseWindow> parent_window_; dash::Preview::Ptr preview_model_; - unity::Settings settings; previews::Style panel_style; dash::Style dash_style; ThumbnailGenerator thumbnail_generator; diff --git a/tests/test_quicklist_manager.cpp b/tests/test_quicklist_manager.cpp index 78d3d1651..a738186b0 100644 --- a/tests/test_quicklist_manager.cpp +++ b/tests/test_quicklist_manager.cpp @@ -24,7 +24,6 @@ #include "launcher/QuicklistManager.h" #include "launcher/QuicklistView.h" -#include "unity-shared/UnitySettings.h" namespace { @@ -44,7 +43,6 @@ struct MockQuicklistView : public unity::QuicklistView TEST(TestQuicklistManager, RegisterQuicklist) { - unity::Settings unity_settings; nux::ObjectWeakPtr<unity::QuicklistView> ptr; { diff --git a/tests/test_quicklist_view.cpp b/tests/test_quicklist_view.cpp index 690a9a262..908cb50bc 100644 --- a/tests/test_quicklist_view.cpp +++ b/tests/test_quicklist_view.cpp @@ -26,7 +26,6 @@ #include "QuicklistMenuItemLabel.h" #include "QuicklistMenuItemRadio.h" #include "QuicklistMenuItemSeparator.h" -#include "unity-shared/UnitySettings.h" using namespace unity; using namespace testing; @@ -76,7 +75,6 @@ struct TestQuicklistView : public Test } } - unity::Settings unity_settings; nux::ObjectPtr<QuicklistView> quicklist; }; diff --git a/tests/test_result_renderer.cpp b/tests/test_result_renderer.cpp index 5b053c215..64d5bcd05 100644 --- a/tests/test_result_renderer.cpp +++ b/tests/test_result_renderer.cpp @@ -23,7 +23,6 @@ #include <glib-object.h> #include "unity-shared/DashStyle.h" -#include "unity-shared/UnitySettings.h" #include "UnityCore/GTKWrapper.h" #include "UnityCore/Result.h" #include "dash/ResultRendererTile.h" @@ -72,7 +71,6 @@ class TestResultRenderer : public testing::Test public: TestResultRenderer() {} - unity::Settings settings; dash::Style style; }; diff --git a/tests/test_scope_bar.cpp b/tests/test_scope_bar.cpp index e4b98e767..86d9b00e3 100644 --- a/tests/test_scope_bar.cpp +++ b/tests/test_scope_bar.cpp @@ -22,7 +22,6 @@ #include <dash/ScopeBar.h> #include "unity-shared/DashStyle.h" -#include "unity-shared/UnitySettings.h" #include "test_mock_scope.h" namespace unity @@ -42,7 +41,6 @@ public: EXPECT_EQ(scope_bar.icons_.size(), size); } - unity::Settings settings; dash::Style style; }; diff --git a/tests/test_scope_view.cpp b/tests/test_scope_view.cpp index 5f834ce88..124059584 100644 --- a/tests/test_scope_view.cpp +++ b/tests/test_scope_view.cpp @@ -22,7 +22,6 @@ #include <dash/ScopeView.h> #include <dash/PlacesGroup.h> #include <unity-shared/DashStyle.h> -#include <unity-shared/UnitySettings.h> #include <UnityCore/Category.h> #include "MockCategories.h" @@ -77,7 +76,6 @@ struct TestScopeView : public ::testing::Test , scope_view_(new FakeScopeView(scope_)) {} - unity::Settings settings; dash::Style style; MockScopeData::Ptr scope_data_; MockScope::Ptr scope_; diff --git a/tests/test_searchbar.cpp b/tests/test_searchbar.cpp index 85f8e95d2..926c831cd 100644 --- a/tests/test_searchbar.cpp +++ b/tests/test_searchbar.cpp @@ -21,7 +21,6 @@ #include <gmock/gmock.h> #include <unity-shared/SearchBarSpinner.h> #include <unity-shared/DashStyle.h> -#include <unity-shared/UnitySettings.h> #include "test_utils.h" using namespace unity; @@ -34,7 +33,6 @@ class TestSearchBar : public ::testing::Test public: TestSearchBar() {} - unity::Settings settings; dash::Style style; }; diff --git a/tests/test_session_controller.cpp b/tests/test_session_controller.cpp index 395406c7e..ce63a1913 100644 --- a/tests/test_session_controller.cpp +++ b/tests/test_session_controller.cpp @@ -24,7 +24,6 @@ #include "SessionController.h" #include "UBusMessages.h" #include "UBusWrapper.h" -#include "UnitySettings.h" #include "WindowManager.h" #include "test_utils.h" @@ -55,7 +54,6 @@ struct TestSessionController : testing::Test nux::NuxTimerTickSource tick_source; nux::animation::AnimationController animation_controller; - unity::Settings settings; MockManager::Ptr manager ; ControllerWrap controller; }; diff --git a/tests/test_session_view.cpp b/tests/test_session_view.cpp index 17d6d9886..45a87c749 100644 --- a/tests/test_session_view.cpp +++ b/tests/test_session_view.cpp @@ -21,7 +21,6 @@ #include "test_mock_session_manager.h" #include "SessionButton.h" #include "SessionView.h" -#include "UnitySettings.h" namespace unity { @@ -91,7 +90,6 @@ struct TestSessionView : testing::Test nux::GetWindowCompositor().SetKeyFocusArea(nullptr); } - unity::Settings settings; MockManager::Ptr manager; ViewWrap view; }; diff --git a/tests/test_shortcut_controller.cpp b/tests/test_shortcut_controller.cpp index bdb612d21..5a0498493 100644 --- a/tests/test_shortcut_controller.cpp +++ b/tests/test_shortcut_controller.cpp @@ -23,7 +23,6 @@ using namespace testing; #include "shortcuts/BaseWindowRaiser.h" #include "shortcuts/ShortcutController.h" -#include "unity-shared/UnitySettings.h" #include "WindowManager.h" #include "UBusMessages.h" using namespace unity; @@ -89,7 +88,6 @@ public: } MockUScreen uscreen; - Settings unity_settings; MockBaseWindowRaiser::Ptr base_window_raiser_; AbstractModeller::Ptr modeller_; NiceMock<MockShortcutController> controller_; diff --git a/tests/test_shortcut_view.cpp b/tests/test_shortcut_view.cpp index 558e6a4f2..e4cee114f 100644 --- a/tests/test_shortcut_view.cpp +++ b/tests/test_shortcut_view.cpp @@ -23,7 +23,6 @@ using namespace testing; #include "ShortcutView.h" #include "ShortcutModel.h" #include "MockShortcutHint.h" -#include "UnitySettings.h" #include "LineSeparator.h" namespace unity @@ -54,7 +53,6 @@ struct TestShortcutView : Test return std::make_shared<Model>(hints); } - Settings settings; MockShortcutView view; }; diff --git a/tests/test_single_monitor_launcher_icon.cpp b/tests/test_single_monitor_launcher_icon.cpp index ebd0b56dc..65eec0bba 100644 --- a/tests/test_single_monitor_launcher_icon.cpp +++ b/tests/test_single_monitor_launcher_icon.cpp @@ -20,7 +20,6 @@ #include <gtest/gtest.h> #include "SingleMonitorLauncherIcon.h" -#include "unity-shared/UnitySettings.h" using namespace unity; using namespace launcher; @@ -30,7 +29,6 @@ namespace struct TestSingleMonitorLauncherIconMock : testing::Test { - unity::Settings settings; }; TEST_F(TestSingleMonitorLauncherIconMock, Construction) diff --git a/tests/test_spread_filter.cpp b/tests/test_spread_filter.cpp index f4fd1e064..f6660d45a 100644 --- a/tests/test_spread_filter.cpp +++ b/tests/test_spread_filter.cpp @@ -23,7 +23,6 @@ #include <NuxCore/AnimationController.h> #include "SpreadFilter.h" -#include "UnitySettings.h" #include "DashStyle.h" #include "test_utils.h" @@ -64,7 +63,6 @@ struct TestSpreadFilter : Test tick_source.tick(big_tick_); } - Settings settings_; dash::Style style_; nux::NuxTimerTickSource tick_source; nux::animation::AnimationController animation_controller; diff --git a/tests/test_switcher_controller.h b/tests/test_switcher_controller.h index 7d3a4a4d4..6ee7dbc23 100644 --- a/tests/test_switcher_controller.h +++ b/tests/test_switcher_controller.h @@ -31,7 +31,6 @@ #include "SwitcherController.h" #include "SwitcherView.h" #include "TimeUtil.h" -#include "unity-shared/UnitySettings.h" #include "mock-base-window.h" #include "test_standalone_wm.h" @@ -92,9 +91,6 @@ class TestSwitcherController : public testing::Test protected: TestSwitcherController(); - // required to create hidden secret global variables before test objects - unity::Settings unity_settings_; - unity::testwrapper::StandaloneWM WM; nux::animation::TickSource tick_source_; nux::animation::AnimationController animation_controller_; diff --git a/tests/test_switcher_view.cpp b/tests/test_switcher_view.cpp index 0fca11f9e..f48d03e21 100644 --- a/tests/test_switcher_view.cpp +++ b/tests/test_switcher_view.cpp @@ -25,7 +25,6 @@ #include "MockLauncherIcon.h" #include "test_standalone_wm.h" #include "unity-shared/IconRenderer.h" -#include "unity-shared/UnitySettings.h" namespace unity { @@ -93,7 +92,6 @@ struct TestSwitcherView : testing::Test } testwrapper::StandaloneWM WM; - unity::Settings settings; testing::NiceMock<MockSwitcherView> switcher; }; diff --git a/tests/test_text_input.cpp b/tests/test_text_input.cpp index 440a1c015..9e6e49f69 100644 --- a/tests/test_text_input.cpp +++ b/tests/test_text_input.cpp @@ -24,7 +24,6 @@ #include "unity-shared/DashStyle.h" #include "unity-shared/TextInput.h" -#include "unity-shared/UnitySettings.h" #include "test_utils.h" using namespace nux; @@ -55,7 +54,6 @@ class TestTextInput : public ::testing::Test pango_entry = entry->GetPangoEntry(); } - unity::Settings unity_settings_; dash::Style dash_style_; nux::ObjectPtr<TextInputMock> entry; StaticCairoText* hint; diff --git a/tests/test_unity_settings.cpp b/tests/test_unity_settings.cpp index ad2b88c66..0bf07858f 100644 --- a/tests/test_unity_settings.cpp +++ b/tests/test_unity_settings.cpp @@ -19,34 +19,46 @@ */ #include <gio/gio.h> -#include <gtest/gtest.h> +#include <gmock/gmock.h> +#include "UnitySettings.h" #include "test_utils.h" -#include "unity-shared/UnitySettings.h" +#include <NuxCore/Logger.h> #include <UnityCore/GLibWrapper.h> namespace { +struct SigReceiver : sigc::trackable +{ + typedef testing::NiceMock<SigReceiver> Nice; + + SigReceiver(std::shared_ptr<unity::Settings> const& settings) + { + settings->form_factor.changed.connect(sigc::mem_fun(this, &SigReceiver::FormFactorChanged)); + } -class TestUnitySettings : public testing::Test + MOCK_CONST_METHOD1(FormFactorChanged, void(unity::FormFactor)); +}; + +struct TestUnitySettings : testing::Test { -public: unity::glib::Object<GSettings> gsettings; - std::unique_ptr<unity::Settings> unity_settings; + std::shared_ptr<unity::Settings> unity_settings; + SigReceiver::Nice sig_receiver; - void SetUp() + TestUnitySettings() + : gsettings(g_settings_new("com.canonical.Unity")) + , unity_settings(std::make_shared<unity::Settings>()) + , sig_receiver(unity_settings) { - Utils::init_gsettings_test_environment(); - gsettings = g_settings_new("com.canonical.Unity"); g_settings_set_enum(gsettings, "form-factor", static_cast<int>(unity::FormFactor::DESKTOP)); - - unity_settings.reset(new unity::Settings); } - void TearDown() + ~TestUnitySettings() { - Utils::reset_gsettings_test_environment(); + sig_receiver.notify_callbacks(); + g_settings_reset(gsettings, "form-factor"); } }; @@ -60,7 +72,7 @@ TEST_F(TestUnitySettings, SetFormFactor) TEST_F(TestUnitySettings, GetFormFactor) { - EXPECT_EQ(unity_settings->form_factor(), unity::FormFactor::DESKTOP); + ASSERT_NE(unity_settings->form_factor(), unity::FormFactor::NETBOOK); g_settings_set_enum(gsettings, "form-factor", static_cast<int>(unity::FormFactor::NETBOOK)); EXPECT_EQ(unity_settings->form_factor(), unity::FormFactor::NETBOOK); @@ -68,42 +80,24 @@ TEST_F(TestUnitySettings, GetFormFactor) TEST_F(TestUnitySettings, FormFactorChangedSignal_Extern) { - bool signal_received = false; - unity::FormFactor new_form_factor; - unity_settings->form_factor.changed.connect([&](unity::FormFactor form_factor) { - signal_received = true; - new_form_factor = form_factor; - }); + EXPECT_CALL(sig_receiver, FormFactorChanged(unity::FormFactor::NETBOOK)); g_settings_set_enum(gsettings, "form-factor", static_cast<int>(unity::FormFactor::NETBOOK)); - Utils::WaitUntilMSec(signal_received); - EXPECT_EQ(new_form_factor, unity::FormFactor::NETBOOK); } TEST_F(TestUnitySettings, FormFactorChangedSignal_Extern_OtherKeys) { - bool signal_received = false; - unity_settings->form_factor.changed.connect([&](unity::FormFactor form_factor) { - signal_received = true; - }); + EXPECT_CALL(sig_receiver, FormFactorChanged(testing::_)).Times(0); g_settings_set_int(gsettings, "minimize-count", 0); Utils::WaitForTimeoutMSec(100); - EXPECT_FALSE(signal_received); } TEST_F(TestUnitySettings, FormFactorChangedSignal_Inter) { - bool signal_received = false; - unity::FormFactor new_form_factor; - unity_settings->form_factor.changed.connect([&](unity::FormFactor form_factor) { - signal_received = true; - new_form_factor = form_factor; - }); + EXPECT_CALL(sig_receiver, FormFactorChanged(unity::FormFactor::NETBOOK)); unity_settings->form_factor = unity::FormFactor::NETBOOK; - Utils::WaitUntilMSec(signal_received); - EXPECT_EQ(new_form_factor, unity::FormFactor::NETBOOK); } } diff --git a/tests/test_unity_window_view.cpp b/tests/test_unity_window_view.cpp index 0768fcc38..f9ac699ef 100644 --- a/tests/test_unity_window_view.cpp +++ b/tests/test_unity_window_view.cpp @@ -19,7 +19,6 @@ #include <gmock/gmock.h> #include "UnityWindowView.h" -#include "UnitySettings.h" #include "WindowManager.h" #include <Nux/VLayout.h> @@ -51,7 +50,6 @@ struct TestUnityWindowView : testing::Test nux::Geometry background_geo_; }; - Settings settings; testing::NiceMock<MockUnityWindowView> view; }; diff --git a/tests/test_volume_launcher_icon.cpp b/tests/test_volume_launcher_icon.cpp index 91a796995..2ff7ba072 100644 --- a/tests/test_volume_launcher_icon.cpp +++ b/tests/test_volume_launcher_icon.cpp @@ -20,7 +20,6 @@ #include <gmock/gmock.h> using namespace testing; -#include "unity-shared/UnitySettings.h" #include "DevicesSettings.h" #include "VolumeLauncherIcon.h" @@ -78,7 +77,6 @@ struct TestVolumeLauncherIcon : public Test return *menuitem; } - unity::Settings u_settings_; MockVolume::Ptr volume_; MockDevicesSettings::Ptr settings_; MockDeviceNotificationDisplay::Ptr notifications_; diff --git a/tests/test_window_buttons.cpp b/tests/test_window_buttons.cpp index a93b4d7da..2d979999f 100644 --- a/tests/test_window_buttons.cpp +++ b/tests/test_window_buttons.cpp @@ -23,7 +23,6 @@ #include <Nux/Nux.h> #include "PanelStyle.h" #include "test_standalone_wm.h" -#include "UnitySettings.h" #include "unity-shared/WindowButtons.h" #include "unity-shared/WindowButtonPriv.h" @@ -60,7 +59,6 @@ struct TestWindowButtons : public testing::Test MOCK_METHOD0(QueueDraw, void()); }; - Settings settings; panel::Style panel_style; testing::NiceMock<MockWindowButtons> wbuttons; testwrapper::StandaloneWM wm; @@ -163,7 +161,6 @@ struct TestWindowButton : public testing::Test MOCK_METHOD0(QueueDraw, void()); }; - Settings settings; panel::Style panel_style; testing::NiceMock<MockWindowButton> button; }; diff --git a/tools/migration-scripts/02_unity_setup_text_scale_factor b/tools/migration-scripts/02_unity_setup_text_scale_factor new file mode 100755 index 000000000..918ebd6a0 --- /dev/null +++ b/tools/migration-scripts/02_unity_setup_text_scale_factor @@ -0,0 +1,39 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Copyright (C) 2014 Canonical +# +# Authors: +# Marco Trevisan <marco.trevisan@canonical.com> +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation; version 3. +# +# This program is distributed in the hope that it will be useful, but WITHOUTa +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +from gi.repository import Gio +import os,sys + +GNOME_UI_SETTINGS = "org.gnome.desktop.interface"; +GNOME_UI_SETTINGS_PATH = "/org/gnome/desktop/interface/" +GNOME_TEXT_SCALE_FACTOR = "text-scaling-factor"; + +if GNOME_UI_SETTINGS not in Gio.Settings.list_schemas(): + print("No gnome desktop interface schemas found, no migration needed") + sys.exit(0) + +ui_settings = Gio.Settings(schema=GNOME_UI_SETTINGS, path=GNOME_UI_SETTINGS_PATH) +text_scale_factor = ui_settings.get_double(GNOME_TEXT_SCALE_FACTOR) + +# gsettings doesn't work directly, the key is somewhat reverted. Work one level under then: dconf! +# ui_settings.set_int(GNOME_TEXT_SCALE_FACTOR, text_scale_factor) +from subprocess import Popen, PIPE, STDOUT +p = Popen(("dconf load "+GNOME_UI_SETTINGS_PATH).split(), stdout=PIPE, stdin=PIPE, stderr=STDOUT) +p.communicate(input="[/]\n"+GNOME_TEXT_SCALE_FACTOR+"={}".format(text_scale_factor).encode('utf-8')) diff --git a/unity-shared/DashStyle.cpp b/unity-shared/DashStyle.cpp index 3d36e46d5..0fcb6a903 100755 --- a/unity-shared/DashStyle.cpp +++ b/unity-shared/DashStyle.cpp @@ -108,9 +108,8 @@ private: } // anon namespace -class Style::Impl +struct Style::Impl : sigc::trackable { -public: Impl(Style* owner); ~Impl(); @@ -165,6 +164,7 @@ public: nux::ButtonVisualState state); void Refresh(); + void UpdateFormFactor(FormFactor); void OnFontChanged(GtkSettings* object, GParamSpec* pspec); // Members @@ -293,11 +293,13 @@ Style::Impl::Impl(Style* owner) (gtk_settings_get_default(), "notify::gtk-font-name", sigc::mem_fun(this, &Impl::OnFontChanged))); - signal_manager_.Add(new glib::Signal<void, GtkSettings*, GParamSpec*> - (gtk_settings_get_default(), - "notify::gtk-xft-dpi", - sigc::mem_fun(this, &Impl::OnFontChanged))); + + auto& settings = Settings::Instance(); + settings.font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &Impl::Refresh))); + settings.form_factor.changed.connect(sigc::mem_fun(this, &Impl::UpdateFormFactor)); + Refresh(); + UpdateFormFactor(settings.form_factor()); // create fallback font-options default_font_options_ = cairo_font_options_create(); @@ -388,11 +390,7 @@ void Style::Impl::Refresh() cairo_t* cr = util_cg.GetInternalContext(); glib::String font_description; - int dpi = 0; - ::g_object_get(settings, - "gtk-font-name", &font_description, - "gtk-xft-dpi", &dpi, - NULL); + ::g_object_get(settings, "gtk-font-name", &font_description, nullptr); PangoFontDescription* desc = ::pango_font_description_from_string(font_description); ::pango_font_description_set_weight(desc, PANGO_WEIGHT_NORMAL); ::pango_font_description_set_size(desc, 9 * PANGO_SCALE); @@ -405,8 +403,7 @@ void Style::Impl::Refresh() GdkScreen* screen = ::gdk_screen_get_default(); ::pango_cairo_context_set_font_options(cxt, ::gdk_screen_get_font_options(screen)); - float pango_scale = PANGO_SCALE; - ::pango_cairo_context_set_resolution(cxt, dpi / pango_scale); + ::pango_cairo_context_set_resolution(cxt, 96.0 * Settings::Instance().font_scaling()); ::pango_layout_context_changed(layout); PangoRectangle log_rect; @@ -419,12 +416,15 @@ void Style::Impl::Refresh() pango_font_description_free(desc); } - void Style::Impl::OnFontChanged(GtkSettings* object, GParamSpec* pspec) { Refresh(); } +void Style::Impl::UpdateFormFactor(FormFactor form_factor) +{ + owner_->always_maximised = (form_factor == FormFactor::NETBOOK || form_factor == FormFactor::TV); +} Style::Style() : always_maximised(false) @@ -438,15 +438,6 @@ Style::Style() { style_instance = this; } - - auto formfactor_lambda = [this] (FormFactor) - { - FormFactor formfactor = Settings::Instance().form_factor(); - always_maximised = (formfactor == FormFactor::NETBOOK || formfactor == FormFactor::TV); - }; - - Settings::Instance().form_factor.changed.connect(formfactor_lambda); - formfactor_lambda(FormFactor()); } Style::~Style () @@ -1384,7 +1375,6 @@ void Style::Impl::GetTextExtents(int& width, PangoFontDescription* desc = NULL; PangoContext* pangoCtx = NULL; PangoRectangle inkRect = {0, 0, 0, 0}; - int dpi = 0; char* fontName = NULL; GdkScreen* screen = gdk_screen_get_default(); // is not ref'ed GtkSettings* settings = gtk_settings_get_default();// is not ref'ed @@ -1423,17 +1413,7 @@ void Style::Impl::GetTextExtents(int& width, pango_cairo_context_set_font_options(pangoCtx, gdk_screen_get_font_options(screen)); - g_object_get(settings, "gtk-xft-dpi", &dpi, NULL); - if (dpi == -1) - { - // use some default DPI-value - pango_cairo_context_set_resolution(pangoCtx, 96.0f); - } - else - { - pango_cairo_context_set_resolution(pangoCtx, - (float) dpi / (float) PANGO_SCALE); - } + pango_cairo_context_set_resolution(pangoCtx, 96.0 * Settings::Instance().font_scaling()); pango_layout_context_changed(layout); pango_layout_get_extents(layout, &inkRect, NULL); @@ -1461,7 +1441,6 @@ void Style::Impl::Text(cairo_t* cr, PangoLayout* layout = NULL; PangoFontDescription* desc = NULL; PangoContext* pangoCtx = NULL; - int dpi = 0; GdkScreen* screen = gdk_screen_get_default(); // not ref'ed GtkSettings* settings = gtk_settings_get_default(); // not ref'ed gchar* fontName = NULL; @@ -1480,7 +1459,7 @@ void Style::Impl::Text(cairo_t* cr, g_object_get(settings, "gtk-font-name", &fontName, NULL); if (!fontName) - desc = pango_font_description_from_string("Sans 10"); + desc = pango_font_description_from_string("Ubuntu 10"); else desc = pango_font_description_from_string(fontName); @@ -1543,17 +1522,7 @@ void Style::Impl::Text(cairo_t* cr, pango_cairo_context_set_font_options(pangoCtx, gdk_screen_get_font_options(screen)); - g_object_get(settings, "gtk-xft-dpi", &dpi, NULL); - if (dpi == -1) - { - // use some default DPI-value - pango_cairo_context_set_resolution(pangoCtx, 96.0f); - } - else - { - pango_cairo_context_set_resolution(pangoCtx, - (float) dpi / (float) PANGO_SCALE); - } + pango_cairo_context_set_resolution(pangoCtx, 96.0 * Settings::Instance().font_scaling()); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_set_source_rgba(cr, color); diff --git a/unity-shared/DecorationStyle.cpp b/unity-shared/DecorationStyle.cpp index e3ff6df85..6904796eb 100644 --- a/unity-shared/DecorationStyle.cpp +++ b/unity-shared/DecorationStyle.cpp @@ -157,6 +157,7 @@ struct Style::Impl parent_->integrated_menus = false; parent_->theme = glib::String(GetSettingValue<gchar*>("gtk-theme-name")).Str(); parent_->font = glib::String(GetSettingValue<gchar*>("gtk-font-name")).Str(); + parent_->font_scale = 1.0; SetTitleFont(); UpdateTitlePangoContext(parent_->title_font); @@ -185,14 +186,12 @@ struct Style::Impl LOG_INFO(logger) << "gtk-font-name changed to " << parent_->font(); }); - signals_.Add<void, GtkSettings*, GParamSpec*>(settings, "notify::gtk-xft-dpi", [this] (GtkSettings*, GParamSpec*) { - title_pango_ctx_ = gdk_pango_context_get_for_screen(gdk_screen_get_default()); - menu_item_pango_ctx_ = gdk_pango_context_get_for_screen(gdk_screen_get_default()); + parent_->font_scale.changed.connect([this] (bool scale) { UpdateTitlePangoContext(parent_->title_font); UpdateMenuItemPangoContext(parent_->font); gtk_style_context_invalidate(ctx_); parent_->theme.changed.emit(parent_->theme()); - LOG_INFO(logger) << "gtk-xft-dpi changed to " << GetSettingValue<int>("gtk-xft-dpi"); + LOG_INFO(logger) << "font scale changed to " << scale; }); signals_.Add<void, GSettings*, gchar*>(settings_, "changed::" + FONT_KEY, [this] (GSettings*, gchar*) { @@ -255,6 +254,7 @@ struct Style::Impl std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font.c_str()), pango_font_description_free); pango_context_set_font_description(ctx, desc.get()); pango_context_set_language(ctx, gtk_get_default_language()); + pango_cairo_context_set_resolution(ctx, 96.0 * parent_->font_scale()); } void UpdateTitlePangoContext(std::string const& font) @@ -508,9 +508,9 @@ struct Style::Impl nux::Size extents; pango_layout_get_pixel_size(layout, &extents.width, &extents.height); - pango_layout_set_height(layout, (h > 0) ? h * PANGO_SCALE : -1); + pango_layout_set_height(layout, (h >= 0) ? h * PANGO_SCALE : -1); - if (extents.width > w) + if (w >= 0 && extents.width > w) { double out_pixels = extents.width - w; double fading_width = std::min<double>(title_fade_, out_pixels); @@ -528,7 +528,7 @@ struct Style::Impl } else { - pango_layout_set_width(layout, w * PANGO_SCALE); + pango_layout_set_width(layout, (w >= 0) ? w * PANGO_SCALE : -1); gtk_render_layout(ctx_, cr, 0, 0, layout); } @@ -571,8 +571,8 @@ struct Style::Impl pango_attr_list_unref(text_attribs); } - pango_layout_set_width(layout, w * PANGO_SCALE); - pango_layout_set_height(layout, (h > 0) ? h * PANGO_SCALE : -1); + pango_layout_set_width(layout, (w >= 0) ? w * PANGO_SCALE : -1); + pango_layout_set_height(layout, (h >= 0) ? h * PANGO_SCALE : -1); gtk_render_layout(ctx_, cr, 0, 0, layout); gtk_style_context_restore(ctx_); diff --git a/unity-shared/DecorationStyle.h b/unity-shared/DecorationStyle.h index ef950ffdb..00c8b13f1 100644 --- a/unity-shared/DecorationStyle.h +++ b/unity-shared/DecorationStyle.h @@ -99,6 +99,7 @@ public: nux::Property<std::string> title_font; nux::Property<bool> integrated_menus; nux::Property<unsigned> grab_wait; + nux::Property<double> font_scale; decoration::Border const& Border() const; decoration::Border const& InputBorder() const; diff --git a/unity-shared/IconLoader.cpp b/unity-shared/IconLoader.cpp index bfa03fae7..021eb6dcf 100644 --- a/unity-shared/IconLoader.cpp +++ b/unity-shared/IconLoader.cpp @@ -35,6 +35,7 @@ #include <UnityCore/GTKWrapper.h> #include "unity-shared/Timer.h" +#include "unity-shared/UnitySettings.h" namespace unity { @@ -313,10 +314,8 @@ private: PangoContext* pango_context = NULL; GdkScreen* screen = gdk_screen_get_default(); // not ref'ed glib::String font; - int dpi = -1; g_object_get(gtk_settings_get_default(), "gtk-font-name", &font, NULL); - g_object_get(gtk_settings_get_default(), "gtk-xft-dpi", &dpi, NULL); cairo_set_font_options(cr, gdk_screen_get_font_options(screen)); layout = pango_cairo_create_layout(cr); std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font), pango_font_description_free); @@ -345,10 +344,8 @@ private: pango_layout_set_markup(layout, escaped_text, -1); pango_context = pango_layout_get_context(layout); // is not ref'ed - pango_cairo_context_set_font_options(pango_context, - gdk_screen_get_font_options(screen)); - pango_cairo_context_set_resolution(pango_context, - dpi == -1 ? 96.0f : dpi/(float) PANGO_SCALE); + pango_cairo_context_set_font_options(pango_context, gdk_screen_get_font_options(screen)); + pango_cairo_context_set_resolution(pango_context, 96.0 * Settings::Instance().font_scaling()); pango_layout_context_changed(layout); // find proper font size @@ -923,11 +920,7 @@ void IconLoader::Impl::CalculateTextHeight(int* width, int* height) cairo_t* cr = util_cg.GetInternalContext(); glib::String font; - int dpi = 0; - g_object_get(settings, - "gtk-font-name", &font, - "gtk-xft-dpi", &dpi, - NULL); + g_object_get(settings, "gtk-font-name", &font, nullptr); std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font), pango_font_description_free); pango_font_description_set_weight(desc.get(), PANGO_WEIGHT_BOLD); pango_font_description_set_size(desc.get(), FONT_SIZE * PANGO_SCALE); @@ -939,7 +932,7 @@ void IconLoader::Impl::CalculateTextHeight(int* width, int* height) PangoContext* cxt = pango_layout_get_context(layout); GdkScreen* screen = gdk_screen_get_default(); pango_cairo_context_set_font_options(cxt, gdk_screen_get_font_options(screen)); - pango_cairo_context_set_resolution(cxt, dpi / (double) PANGO_SCALE); + pango_cairo_context_set_resolution(cxt, 96.0 * Settings::Instance().font_scaling()); pango_layout_context_changed(layout); PangoRectangle log_rect; diff --git a/unity-shared/PlacesOverlayVScrollBar.cpp b/unity-shared/PlacesOverlayVScrollBar.cpp index e16f4b848..b715f62cf 100644 --- a/unity-shared/PlacesOverlayVScrollBar.cpp +++ b/unity-shared/PlacesOverlayVScrollBar.cpp @@ -420,7 +420,7 @@ void PlacesOverlayVScrollBar::UpdateConnectorTexture() nux::color::RedGreenBlue const& connector_bg = nux::color::Gray; nux::CairoGraphics cairoGraphics(CAIRO_FORMAT_ARGB32, width, height); - cr = cairoGraphics.GetContext(); + cr = cairoGraphics.GetInternalContext(); cairo_save(cr); cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); @@ -434,7 +434,6 @@ void PlacesOverlayVScrollBar::UpdateConnectorTexture() cairo_fill_preserve(cr); connector_texture_.Adopt(texture_from_cairo_graphics(cairoGraphics)); - cairo_destroy(cr); QueueDraw(); } diff --git a/unity-shared/SearchBar.cpp b/unity-shared/SearchBar.cpp index 5c2e87a1f..86be017e3 100644 --- a/unity-shared/SearchBar.cpp +++ b/unity-shared/SearchBar.cpp @@ -132,12 +132,12 @@ SearchBar::SearchBar(bool show_filter_hint, NUX_FILE_LINE_DECL) , showing_filters(false) , can_refine_search(false) , live_search_wait(DEFAULT_LIVE_SEARCH_TIMEOUT) + , scale(DEFAULT_SCALE) , show_filter_hint_(show_filter_hint) , expander_view_(nullptr) , show_filters_(nullptr) , last_width_(-1) , last_height_(-1) - , scale_(DEFAULT_SCALE) { dash::Style& style = dash::Style::Instance(); @@ -209,15 +209,15 @@ SearchBar::SearchBar(bool show_filter_hint, NUX_FILE_LINE_DECL) filter_layout_->AddView(show_filters_, 0, nux::MINOR_POSITION_CENTER); arrow_layout_ = new nux::VLayout(); - arrow_top_space_ = new nux::SpaceLayout(ARROW_MIN_WIDTH.CP(scale_), - ARROW_MAX_WIDTH.CP(scale_), - TOP_ARROW_MIN_HEIGHT.CP(scale_), - TOP_ARROW_MAX_HEIGHT.CP(scale_)); + arrow_top_space_ = new nux::SpaceLayout(ARROW_MIN_WIDTH.CP(scale()), + ARROW_MAX_WIDTH.CP(scale()), + TOP_ARROW_MIN_HEIGHT.CP(scale()), + TOP_ARROW_MAX_HEIGHT.CP(scale())); - arrow_bottom_space_ = new nux::SpaceLayout(ARROW_MIN_WIDTH.CP(scale_), - ARROW_MAX_WIDTH.CP(scale_), - BOT_ARROW_MIN_HEIGHT.CP(scale_), - BOT_ARROW_MAX_HEIGHT.CP(scale_)); + arrow_bottom_space_ = new nux::SpaceLayout(ARROW_MIN_WIDTH.CP(scale()), + ARROW_MAX_WIDTH.CP(scale()), + BOT_ARROW_MIN_HEIGHT.CP(scale()), + BOT_ARROW_MAX_HEIGHT.CP(scale())); arrow_layout_->AddView(arrow_top_space_, 0, nux::MINOR_POSITION_CENTER); arrow_layout_->AddView(expand_icon_, 0, nux::MINOR_POSITION_CENTER); @@ -272,6 +272,7 @@ SearchBar::SearchBar(bool show_filter_hint, NUX_FILE_LINE_DECL) im_active.SetGetterFunction(sigc::mem_fun(this, &SearchBar::get_im_active)); im_preedit.SetGetterFunction(sigc::mem_fun(this, &SearchBar::get_im_preedit)); showing_filters.changed.connect(sigc::mem_fun(this, &SearchBar::OnShowingFiltersChanged)); + scale.changed.connect(sigc::mem_fun(this, &SearchBar::UpdateScale)); can_refine_search.changed.connect([this] (bool can_refine) { if (show_filter_hint_) @@ -292,29 +293,29 @@ void SearchBar::UpdateSearchBarSize() RawPixel const icon_width = icon->GetWidth(); RawPixel const icon_height = icon->GetHeight(); - layout_->SetLeftAndRightPadding(LEFT_INTERNAL_PADDING.CP(scale_), - SEARCH_ENTRY_RIGHT_BORDER.CP(scale_)); - layout_->SetSpaceBetweenChildren(SPACE_BETWEEN_ENTRY_AND_HIGHLIGHT.CP(scale_)); + layout_->SetLeftAndRightPadding(LEFT_INTERNAL_PADDING.CP(scale()), + SEARCH_ENTRY_RIGHT_BORDER.CP(scale())); + layout_->SetSpaceBetweenChildren(SPACE_BETWEEN_ENTRY_AND_HIGHLIGHT.CP(scale())); - entry_layout_->SetLeftAndRightPadding(LEFT_PADDING.CP(scale_), - RIGHT_PADDING.CP(scale_)); + entry_layout_->SetLeftAndRightPadding(LEFT_PADDING.CP(scale()), + RIGHT_PADDING.CP(scale())); - spinner_->SetMinMaxSize(icon_width.CP(scale_), icon_height.CP(scale_)); - entry_layout_->SetSpaceBetweenChildren(SPACE_BETWEEN_SPINNER_AND_TEXT.CP(scale_)); + spinner_->SetMinMaxSize(icon_width.CP(scale()), icon_height.CP(scale())); + entry_layout_->SetSpaceBetweenChildren(SPACE_BETWEEN_SPINNER_AND_TEXT.CP(scale())); - pango_entry_->SetFontSize(PANGO_ENTRY_FONT_SIZE.CP(scale_)); + pango_entry_->SetFontSize(PANGO_ENTRY_FONT_SIZE.CP(scale())); if (show_filter_hint_) { - arrow_top_space_->SetMinimumSize(ARROW_MIN_WIDTH.CP(scale_), - TOP_ARROW_MIN_HEIGHT.CP(scale_)); - arrow_top_space_->SetMaximumSize(ARROW_MAX_WIDTH.CP(scale_), - TOP_ARROW_MAX_HEIGHT.CP(scale_)); - - arrow_bottom_space_->SetMinimumSize(ARROW_MIN_WIDTH.CP(scale_), - BOT_ARROW_MIN_HEIGHT.CP(scale_)); - arrow_bottom_space_->SetMaximumSize(ARROW_MAX_WIDTH.CP(scale_), - BOT_ARROW_MAX_HEIGHT.CP(scale_)); + arrow_top_space_->SetMinimumSize(ARROW_MIN_WIDTH.CP(scale()), + TOP_ARROW_MIN_HEIGHT.CP(scale())); + arrow_top_space_->SetMaximumSize(ARROW_MAX_WIDTH.CP(scale()), + TOP_ARROW_MAX_HEIGHT.CP(scale())); + + arrow_bottom_space_->SetMinimumSize(ARROW_MIN_WIDTH.CP(scale()), + BOT_ARROW_MIN_HEIGHT.CP(scale())); + arrow_bottom_space_->SetMaximumSize(ARROW_MAX_WIDTH.CP(scale()), + BOT_ARROW_MAX_HEIGHT.CP(scale())); } // Based on the Font size, the MinHeight is changing in TextEntry. From there the @@ -330,15 +331,10 @@ void SearchBar::UpdateSearchBarSize() void SearchBar::UpdateScale(double scale) { - if (scale_ != scale) - { - scale_ = scale; - - hint_->SetScale(scale_); - show_filters_->SetScale(scale_); + hint_->SetScale(scale); + show_filters_->SetScale(scale); - UpdateSearchBarSize(); - } + UpdateSearchBarSize(); } void SearchBar::OnFontChanged(GtkSettings* settings, GParamSpec* pspec) @@ -450,8 +446,8 @@ void SearchBar::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) nux::Geometry geo(expander_view_->GetGeometry()); - geo.y -= (HIGHLIGHT_HEIGHT.CP(scale_) - geo.height) / 2; - geo.height = HIGHLIGHT_HEIGHT.CP(scale_); + geo.y -= (HIGHLIGHT_HEIGHT.CP(scale()) - geo.height) / 2; + geo.height = HIGHLIGHT_HEIGHT.CP(scale()); if (!highlight_layer_) highlight_layer_.reset(style.FocusOverlay(geo.width, geo.height)); @@ -548,7 +544,7 @@ void SearchBar::UpdateBackground(bool force) geo.width = layered_layout_->GetAbsoluteX() + layered_layout_->GetAbsoluteWidth() - GetAbsoluteX() + - SEARCH_ENTRY_RIGHT_BORDER.CP(scale_); + SEARCH_ENTRY_RIGHT_BORDER.CP(scale()); LOG_TRACE(logger) << "height: " << geo.height << " - " @@ -570,7 +566,7 @@ void SearchBar::UpdateBackground(bool force) cairo_graphics.DrawRoundedRectangle(cr, 1.0f, 0.5, 0.5, - RADIUS.CP(scale_), + RADIUS.CP(scale()), last_width_ - 1, last_height_ - 1, false); diff --git a/unity-shared/SearchBar.h b/unity-shared/SearchBar.h index aea7013e5..853b65ffb 100644 --- a/unity-shared/SearchBar.h +++ b/unity-shared/SearchBar.h @@ -54,8 +54,6 @@ public: void ForceLiveSearch(); void SetSearchFinished(); - void UpdateScale(double scale); - nux::TextEntry* text_entry() const; nux::View* show_filters() const; @@ -66,6 +64,7 @@ public: nux::ROProperty<bool> im_active; nux::ROProperty<bool> im_preedit; nux::Property<unsigned> live_search_wait; + nux::Property<double> scale; sigc::signal<void> activated; sigc::signal<void, std::string const&> search_changed; @@ -99,10 +98,10 @@ private: void AddProperties(debug::IntrospectionData&); bool AcceptKeyNavFocus(); -private: bool ShouldBeHighlighted(); void UpdateSearchBarSize(); - + void UpdateScale(double scale); + std::unique_ptr<nux::AbstractPaintLayer> bg_layer_; std::unique_ptr<nux::AbstractPaintLayer> highlight_layer_; nux::HLayout* layout_; @@ -121,7 +120,6 @@ private: int last_width_; int last_height_; - double scale_; glib::SignalManager sig_manager_; glib::Source::UniquePtr live_search_timeout_; diff --git a/unity-shared/StaticCairoText.cpp b/unity-shared/StaticCairoText.cpp index b3f2010a2..804ad1006 100644 --- a/unity-shared/StaticCairoText.cpp +++ b/unity-shared/StaticCairoText.cpp @@ -36,12 +36,13 @@ #include <UnityCore/GLibWrapper.h> #include "CairoTexture.h" +#include "UnitySettings.h" using namespace nux; namespace unity { -struct StaticCairoText::Impl +struct StaticCairoText::Impl : sigc::trackable { Impl(StaticCairoText* parent, std::string const& text); ~Impl(); @@ -128,8 +129,8 @@ StaticCairoText::Impl::Impl(StaticCairoText* parent, std::string const& text) GtkSettings* settings = gtk_settings_get_default(); // not ref'ed g_signal_connect(settings, "notify::gtk-font-name", (GCallback)FontChanged, this); - g_signal_connect(settings, "notify::gtk-xft-dpi", - (GCallback)FontChanged, this); + + Settings::Instance().font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &Impl::OnFontChanged))); } StaticCairoText::Impl::~Impl() @@ -552,9 +553,7 @@ Size StaticCairoText::Impl::GetTextExtents() const PangoLayout* layout = NULL; PangoFontDescription* desc = NULL; PangoContext* pangoCtx = NULL; - int dpi = 0; GdkScreen* screen = gdk_screen_get_default(); // is not ref'ed - GtkSettings* settings = gtk_settings_get_default(); // is not ref'ed if (!need_new_extent_cache_) { @@ -581,19 +580,8 @@ Size StaticCairoText::Impl::GetTextExtents() const pango_layout_set_spacing(layout, line_spacing_ * PANGO_SCALE); pangoCtx = pango_layout_get_context(layout); // is not ref'ed - pango_cairo_context_set_font_options(pangoCtx, - gdk_screen_get_font_options(screen)); - g_object_get(settings, "gtk-xft-dpi", &dpi, NULL); - if (dpi == -1) - { - // use some default DPI-value - pango_cairo_context_set_resolution(pangoCtx, 96.0f); - } - else - { - pango_cairo_context_set_resolution(pangoCtx, - (float) dpi / (float) PANGO_SCALE); - } + pango_cairo_context_set_font_options(pangoCtx, gdk_screen_get_font_options(screen)); + pango_cairo_context_set_resolution(pangoCtx, 96.0 * Settings::Instance().font_scaling()); pango_layout_context_changed(layout); PangoRectangle ink_rect, logic_rect; @@ -721,9 +709,7 @@ void StaticCairoText::Impl::DrawText(CacheTexture::Ptr const& texture) PangoLayout* layout = NULL; PangoFontDescription* desc = NULL; PangoContext* pangoCtx = NULL; - int dpi = 0; GdkScreen* screen = gdk_screen_get_default(); // not ref'ed - GtkSettings* settings = gtk_settings_get_default(); // not ref'ed std::string text = text_.substr(texture->start_index, texture->length); @@ -746,22 +732,11 @@ void StaticCairoText::Impl::DrawText(CacheTexture::Ptr const& texture) SetAttributes(layout); pangoCtx = pango_layout_get_context(layout); // is not ref'ed - pango_cairo_context_set_font_options(pangoCtx, - gdk_screen_get_font_options(screen)); - g_object_get(settings, "gtk-xft-dpi", &dpi, NULL); - if (dpi == -1) - { - // use some default DPI-value - pango_cairo_context_set_resolution(pangoCtx, 96.0f); - } - else - { - pango_cairo_context_set_resolution(pangoCtx, - (float) dpi / (float) PANGO_SCALE); - } + pango_cairo_context_set_font_options(pangoCtx, gdk_screen_get_font_options(screen)); + pango_cairo_context_set_resolution(pangoCtx, 96.0 * Settings::Instance().font_scaling()); + pango_layout_context_changed(layout); Size result; - pango_layout_context_changed(layout); pango_layout_get_pixel_size(layout, &result.width, &result.height); if (std::ceil(result.width * scale_) > parent_->GetMaximumWidth()) diff --git a/unity-shared/UScreen.cpp b/unity-shared/UScreen.cpp index dcd3311f4..5af3869bf 100644 --- a/unity-shared/UScreen.cpp +++ b/unity-shared/UScreen.cpp @@ -36,10 +36,10 @@ UScreen::UScreen() size_changed_signal_.Connect(screen_, "size-changed", sigc::mem_fun(this, &UScreen::Changed)); monitors_changed_signal_.Connect(screen_, "monitors-changed", sigc::mem_fun(this, &UScreen::Changed)); proxy_.Connect("PrepareForSleep", [this] (GVariant* data) { - bool val; + gboolean val; g_variant_get(data, "(b)", &val); if (!val) - resuming.emit(); + resuming.emit(); }); Refresh(); diff --git a/unity-shared/UnitySettings.cpp b/unity-shared/UnitySettings.cpp index 935e5de62..9ab201a5e 100644 --- a/unity-shared/UnitySettings.cpp +++ b/unity-shared/UnitySettings.cpp @@ -37,12 +37,26 @@ Settings* settings_instance = nullptr; const std::string SETTINGS_NAME = "com.canonical.Unity"; const std::string FORM_FACTOR = "form-factor"; const std::string DOUBLE_CLICK_ACTIVATE = "double-click-activate"; -const std::string SCALE_FACTOR = "scale-factor"; const std::string LIM_KEY = "integrated-menus"; + const std::string LIM_SETTINGS = "com.canonical.Unity.IntegratedMenus"; const std::string CLICK_MOVEMENT_THRESHOLD = "click-movement-threshold"; const std::string DOUBLE_CLICK_WAIT = "double-click-wait"; -const std::string UI_SETTINGS = "com.ubuntu.user-interface"; + +const std::string UI_SETTINGS = "com.canonical.Unity.Interface"; +const std::string TEXT_SCALE_FACTOR = "text-scale-factor"; +const std::string CURSOR_SCALE_FACTOR = "cursor-scale-factor"; +const std::string APP_SCALE_MONITOR = "app-scale-factor-monitor"; +const std::string APP_USE_MAX_SCALE = "app-fallback-to-maximum-scale-factor"; + +const std::string UBUNTU_UI_SETTINGS = "com.ubuntu.user-interface"; +const std::string SCALE_FACTOR = "scale-factor"; + +const std::string GNOME_UI_SETTINGS = "org.gnome.desktop.interface"; +const std::string GNOME_FONT_NAME = "font-name"; +const std::string GNOME_CURSOR_SIZE = "cursor-size"; +const std::string GNOME_SCALE_FACTOR = "scaling-factor"; +const std::string GNOME_TEXT_SCALE_FACTOR = "text-scaling-factor"; const int DEFAULT_LAUNCHER_WIDTH = 64; const double DEFAULT_DPI = 96.0f; @@ -56,42 +70,85 @@ class Settings::Impl : public sigc::trackable public: Impl(Settings* owner) : parent_(owner) - , gsettings_(g_settings_new(SETTINGS_NAME.c_str())) - , ubuntu_settings_(g_settings_new(UI_SETTINGS.c_str())) , usettings_(g_settings_new(SETTINGS_NAME.c_str())) , lim_settings_(g_settings_new(LIM_SETTINGS.c_str())) + , ui_settings_(g_settings_new(UI_SETTINGS.c_str())) + , ubuntu_ui_settings_(g_settings_new(UBUNTU_UI_SETTINGS.c_str())) + , gnome_ui_settings_(g_settings_new(GNOME_UI_SETTINGS.c_str())) , launcher_widths_(monitors::MAX, DEFAULT_LAUNCHER_WIDTH) , cached_form_factor_(FormFactor::DESKTOP) + , cursor_scale_(1.0) , cached_double_click_activate_(true) + , changing_gnome_settings_(false) , lowGfx_(false) { + parent_->form_factor.SetGetterFunction(sigc::mem_fun(this, &Impl::GetFormFactor)); + parent_->form_factor.SetSetterFunction(sigc::mem_fun(this, &Impl::SetFormFactor)); + parent_->double_click_activate.SetGetterFunction(sigc::mem_fun(this, &Impl::GetDoubleClickActivate)); + for (unsigned i = 0; i < monitors::MAX; ++i) - em_converters_.push_back(std::make_shared<EMConverter>()); + em_converters_.emplace_back(std::make_shared<EMConverter>()); CacheFormFactor(); CacheDoubleClickActivate(); - UpdateEMConverter(); + + // The order is important here, DPI is the last thing to be updated UpdateLimSetting(); + UpdateTextScaleFactor(); + UpdateCursorScaleFactor(); + UpdateFontSize(); + UpdateDPI(); - UScreen::GetDefault()->changed.connect(sigc::hide(sigc::hide(sigc::mem_fun(this, &Impl::UpdateEMConverter)))); + UScreen::GetDefault()->changed.connect(sigc::hide(sigc::hide(sigc::mem_fun(this, &Impl::UpdateDPI)))); signals_.Add<void, GSettings*, const gchar*>(usettings_, "changed::" + FORM_FACTOR, [this] (GSettings*, const gchar*) { CacheFormFactor(); - parent_->form_factor.changed.emit(cached_form_factor_); }); signals_.Add<void, GSettings*, const gchar*>(usettings_, "changed::" + DOUBLE_CLICK_ACTIVATE, [this] (GSettings*, const gchar*) { CacheDoubleClickActivate(); parent_->double_click_activate.changed.emit(cached_double_click_activate_); }); - signals_.Add<void, GSettings*, const gchar*>(ubuntu_settings_, "changed::" + SCALE_FACTOR, [this] (GSettings*, const gchar* t) { - UpdateEMConverter(); - }); signals_.Add<void, GSettings*, const gchar*>(usettings_, "changed::" + LIM_KEY, [this] (GSettings*, const gchar*) { UpdateLimSetting(); }); + signals_.Add<void, GSettings*, const gchar*>(ubuntu_ui_settings_, "changed::" + SCALE_FACTOR, [this] (GSettings*, const gchar* t) { + UpdateDPI(); + }); + + signals_.Add<void, GSettings*, const gchar*>(ui_settings_, "changed::" + TEXT_SCALE_FACTOR, [this] (GSettings*, const gchar* t) { + UpdateTextScaleFactor(); + UpdateDPI(); + }); + + signals_.Add<void, GSettings*, const gchar*>(ui_settings_, "changed::" + CURSOR_SCALE_FACTOR, [this] (GSettings*, const gchar* t) { + UpdateCursorScaleFactor(); + UpdateDPI(); + }); + + signals_.Add<void, GSettings*, const gchar*>(ui_settings_, "changed::" + APP_SCALE_MONITOR, [this] (GSettings*, const gchar* t) { + UpdateDPI(); + }); + + signals_.Add<void, GSettings*, const gchar*>(ui_settings_, "changed::" + APP_USE_MAX_SCALE, [this] (GSettings*, const gchar* t) { + UpdateDPI(); + }); + + signals_.Add<void, GSettings*, const gchar*>(gnome_ui_settings_, "changed::" + GNOME_FONT_NAME, [this] (GSettings*, const gchar* t) { + UpdateFontSize(); + UpdateDPI(); + }); + + signals_.Add<void, GSettings*, const gchar*>(gnome_ui_settings_, "changed::" + GNOME_TEXT_SCALE_FACTOR, [this] (GSettings*, const gchar* t) { + if (!changing_gnome_settings_) + { + double new_scale_factor = g_settings_get_double(gnome_ui_settings_, GNOME_TEXT_SCALE_FACTOR.c_str()); + g_settings_set_double(ui_settings_, TEXT_SCALE_FACTOR.c_str(), new_scale_factor); + } + }); + signals_.Add<void, GSettings*, const gchar*>(lim_settings_, "changed", [this] (GSettings*, const gchar*) { UpdateLimSetting(); }); @@ -100,6 +157,7 @@ public: void CacheFormFactor() { int raw_from_factor = g_settings_get_enum(usettings_, FORM_FACTOR.c_str()); + FormFactor new_form_factor; if (raw_from_factor == 0) //Automatic { @@ -107,11 +165,17 @@ public: int primary_monitor = uscreen->GetMonitorWithMouse(); auto const& geo = uscreen->GetMonitorGeometry(primary_monitor); - cached_form_factor_ = geo.height > 799 ? FormFactor::DESKTOP : FormFactor::NETBOOK; + new_form_factor = geo.height > 799 ? FormFactor::DESKTOP : FormFactor::NETBOOK; } else { - cached_form_factor_ = static_cast<FormFactor>(raw_from_factor); + new_form_factor = static_cast<FormFactor>(raw_from_factor); + } + + if (new_form_factor != cached_form_factor_) + { + cached_form_factor_ = new_form_factor; + parent_->form_factor.changed.emit(cached_form_factor_); } } @@ -135,7 +199,7 @@ public: bool SetFormFactor(FormFactor factor) { g_settings_set_enum(usettings_, FORM_FACTOR.c_str(), static_cast<int>(factor)); - return true; + return false; } bool GetDoubleClickActivate() const @@ -148,30 +212,14 @@ public: gint font_size; PangoFontDescription* desc; - desc = pango_font_description_from_string(decoration::Style::Get()->font().c_str()); + glib::String font_name(g_settings_get_string(gnome_ui_settings_, GNOME_FONT_NAME.c_str())); + desc = pango_font_description_from_string(font_name); font_size = pango_font_description_get_size(desc); pango_font_description_free(desc); return font_size / 1024; } - int GetDPI(glib::Variant const& dict, int monitor) const - { - auto* uscreen = UScreen::GetDefault(); - - if (monitor < 0 || monitor >= uscreen->GetPluggedMonitorsNumber()) - return DEFAULT_DPI; - - auto const& monitor_name = UScreen::GetDefault()->GetMonitorName(monitor); - double ui_scale = 1.0f; - int value; - - if (g_variant_lookup(dict, monitor_name.c_str(), "i", &value)) - ui_scale = static_cast<double>(value)/8.0f; - - return (DEFAULT_DPI * ui_scale); - } - void UpdateFontSize() { int font_size = GetFontSize(); @@ -180,41 +228,91 @@ public: em->SetFontSize(font_size); } + void UpdateTextScaleFactor() + { + parent_->font_scaling = g_settings_get_double(ui_settings_, TEXT_SCALE_FACTOR.c_str()); + decoration::Style::Get()->font_scale = parent_->font_scaling(); + } + + void UpdateCursorScaleFactor() + { + cursor_scale_ = g_settings_get_double(ui_settings_, CURSOR_SCALE_FACTOR.c_str()); + } + void UpdateDPI() { - glib::Variant dict; - g_settings_get(ubuntu_settings_, SCALE_FACTOR.c_str(), "@a{si}", &dict); + auto* uscreen = UScreen::GetDefault(); + double min_scale = 4.0; + double max_scale = 0.0; bool any_changed = false; - for (unsigned i = 0; i < em_converters_.size(); ++i) + glib::Variant dict; + g_settings_get(ubuntu_ui_settings_, SCALE_FACTOR.c_str(), "@a{si}", &dict); + + glib::String app_target_monitor(g_settings_get_string(ui_settings_, APP_SCALE_MONITOR.c_str())); + double app_target_scale = 0; + + for (unsigned monitor = 0; monitor < em_converters_.size(); ++monitor) { - int dpi = GetDPI(dict, i); + int dpi = DEFAULT_DPI; + + if (monitor < uscreen->GetMonitors().size()) + { + auto const& monitor_name = uscreen->GetMonitorName(monitor); + double ui_scale = 1.0f; + int value; + + if (g_variant_lookup(dict, monitor_name.c_str(), "i", &value)) + ui_scale = static_cast<double>(value)/8.0f; - if (em_converters_[i]->SetDPI(dpi)) + if (app_target_monitor.Str() == monitor_name) + app_target_scale = ui_scale; + + dpi = DEFAULT_DPI * ui_scale; + min_scale = std::min(min_scale, ui_scale); + max_scale = std::max(max_scale, ui_scale); + } + + if (em_converters_[monitor]->SetDPI(dpi)) any_changed = true; } + if (app_target_scale == 0) + app_target_scale = (g_settings_get_boolean(ui_settings_, APP_USE_MAX_SCALE.c_str())) ? max_scale : min_scale; + + UpdateAppsScaling(app_target_scale); + if (any_changed) parent_->dpi_changed.emit(); } - void UpdateEMConverter() + void UpdateAppsScaling(double scale) { - UpdateFontSize(); - UpdateDPI(); + changing_gnome_settings_ = true; + unsigned integer_scaling = std::max<unsigned>(1, scale); + double point_scaling = scale / static_cast<double>(integer_scaling); + double text_scale_factor = parent_->font_scaling() * point_scaling; + glib::Variant default_cursor_size(g_settings_get_default_value(gnome_ui_settings_, GNOME_CURSOR_SIZE.c_str()), glib::StealRef()); + int cursor_size = std::round(default_cursor_size.GetInt32() * point_scaling * cursor_scale_); + g_settings_set_int(gnome_ui_settings_, GNOME_CURSOR_SIZE.c_str(), cursor_size); + g_settings_set_uint(gnome_ui_settings_, GNOME_SCALE_FACTOR.c_str(), integer_scaling); + g_settings_set_double(gnome_ui_settings_, GNOME_TEXT_SCALE_FACTOR.c_str(), text_scale_factor); + changing_gnome_settings_ = false; } Settings* parent_; - glib::Object<GSettings> gsettings_; - glib::Object<GSettings> ubuntu_settings_; glib::Object<GSettings> usettings_; glib::Object<GSettings> lim_settings_; - glib::Object<GSettings> gnome_settings_; + glib::Object<GSettings> ui_settings_; + glib::Object<GSettings> ubuntu_ui_settings_; + glib::Object<GSettings> gnome_ui_settings_; glib::SignalManager signals_; std::vector<EMConverter::Ptr> em_converters_; std::vector<int> launcher_widths_; FormFactor cached_form_factor_; + double cursor_scale_; bool cached_double_click_activate_; + bool changing_gnome_settings_; bool lowGfx_; }; @@ -229,17 +327,10 @@ Settings::Settings() if (settings_instance) { LOG_ERROR(logger) << "More than one unity::Settings created."; + return; } - else - { - form_factor.SetGetterFunction(sigc::mem_fun(*pimpl, &Impl::GetFormFactor)); - form_factor.SetSetterFunction(sigc::mem_fun(*pimpl, &Impl::SetFormFactor)); - - double_click_activate.SetGetterFunction(sigc::mem_fun(*pimpl, &Impl::GetDoubleClickActivate)); - - settings_instance = this; - } + settings_instance = this; } Settings::~Settings() diff --git a/unity-shared/UnitySettings.h b/unity-shared/UnitySettings.h index 5c333f6c3..4e97e8eb0 100644 --- a/unity-shared/UnitySettings.h +++ b/unity-shared/UnitySettings.h @@ -54,6 +54,7 @@ public: nux::ROProperty<bool> double_click_activate; nux::Property<unsigned> lim_movement_thresold; nux::Property<unsigned> lim_double_click_wait; + nux::Property<double> font_scaling; sigc::signal<void> dpi_changed; |
