Merge lp:~3v1n0/unity/adaptive-icon-count into lp:unity

Proposed by Marco Trevisan (Treviño) on 2014-08-25
Status: Merged
Approved by: Brandon Schaefer on 2014-08-26
Approved revision: 3861
Merged at revision: 3862
Proposed branch: lp:~3v1n0/unity/adaptive-icon-count
Merge into: lp:unity
Prerequisite: lp:~3v1n0/unity/icons-emblem-scaling
Diff against target: 283 lines (+54/-41)
6 files modified
launcher/LauncherIcon.cpp (+25/-23)
tests/CMakeLists.txt (+1/-1)
tests/test_main_xless.cpp (+4/-5)
unity-shared/IconRenderer.cpp (+2/-2)
unity-shared/IconTextureSource.cpp (+16/-6)
unity-shared/IconTextureSource.h (+6/-4)
To merge this branch: bzr merge lp:~3v1n0/unity/adaptive-icon-count
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing on 2014-08-28
Brandon Schaefer (community) 2014-08-25 Approve on 2014-08-26
Review via email: mp+232146@code.launchpad.net

This proposal supersedes a proposal from 2014-08-25.

Commit message

LauncherIcon: make the Icon count width depending on the text value width

Description of the change

LauncherIcon: make the Icon count width depending on the text value width

To post a comment you must log in.
lp:~3v1n0/unity/adaptive-icon-count updated on 2014-08-25
3861. By Marco Trevisan (Treviño) on 2014-08-25

LauncherIcon: setting text is enough for count, no need accel

PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Brandon Schaefer (brandontschaefer) wrote :

LGTM

review: Approve
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
lp:~3v1n0/unity/adaptive-icon-count updated on 2014-08-26
3862. By Marco Trevisan (Treviño) on 2014-08-26

LauncherIcon: honour the text scaling when drawing the launcher icon count emblem

And update it when it changes.

3863. By Marco Trevisan (Treviño) on 2014-08-26

IconTextureSource: reset the cached count value when scaling settings change

In this way we make sure we properly reset the icons matrices

PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
lp:~3v1n0/unity/adaptive-icon-count updated on 2014-08-27
3864. By Marco Trevisan (Treviño) on 2014-08-27

TestLauncherModel: move to XTests

PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/LauncherIcon.cpp'
2--- launcher/LauncherIcon.cpp 2014-08-27 22:39:22 +0000
3+++ launcher/LauncherIcon.cpp 2014-08-27 22:39:22 +0000
4@@ -60,10 +60,8 @@
5 const std::string PRESENT_TIMEOUT = "present-timeout";
6 const std::string QUIRK_DELAY_TIMEOUT = "quirk-delay-timeout";
7
8-const int COUNT_WIDTH = 32;
9-const int COUNT_HEIGHT = 16;
10-const int COUNT_FONT_WIDTH = COUNT_WIDTH - 4;
11-const int COUNT_FONT_HEIGHT = COUNT_HEIGHT - 5;
12+const int COUNT_FONT_SIZE = 11;
13+const int COUNT_PADDING = 2;
14 }
15
16 NUX_IMPLEMENT_OBJECT_TYPE(LauncherIcon);
17@@ -103,8 +101,11 @@
18 mouse_down.connect(sigc::mem_fun(this, &LauncherIcon::RecvMouseDown));
19 mouse_up.connect(sigc::mem_fun(this, &LauncherIcon::RecvMouseUp));
20 mouse_click.connect(sigc::mem_fun(this, &LauncherIcon::RecvMouseClick));
21- Settings::Instance().dpi_changed.connect(sigc::mem_fun(this, &LauncherIcon::CleanCountTextures));
22- icon_size.changed.connect(sigc::hide(sigc::mem_fun(this, &LauncherIcon::CleanCountTextures)));
23+
24+ auto const& count_rebuild_cb = sigc::mem_fun(this, &LauncherIcon::CleanCountTextures);
25+ Settings::Instance().dpi_changed.connect(count_rebuild_cb);
26+ Settings::Instance().font_scaling.changed.connect(sigc::hide(count_rebuild_cb));
27+ icon_size.changed.connect(sigc::hide(count_rebuild_cb));
28
29 for (unsigned i = 0; i < monitors::MAX; ++i)
30 {
31@@ -1031,41 +1032,44 @@
32 void LauncherIcon::CleanCountTextures()
33 {
34 _counts.clear();
35+ EmitNeedsRedraw();
36 }
37
38 BaseTexturePtr LauncherIcon::DrawCountTexture(unsigned count, double scale)
39 {
40- auto const& count_text = (count / 10000 != 0) ? "****" : std::to_string(count);
41-
42 glib::Object<PangoContext> pango_ctx(gdk_pango_context_get());
43 glib::Object<PangoLayout> layout(pango_layout_new(pango_ctx));
44
45 glib::String font_name;
46 g_object_get(gtk_settings_get_default(), "gtk-font-name", &font_name, nullptr);
47 std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font_name), pango_font_description_free);
48- pango_font_description_set_absolute_size(desc.get(), pango_units_from_double(COUNT_FONT_HEIGHT));
49+ int font_size = pango_units_from_double(Settings::Instance().font_scaling() * COUNT_FONT_SIZE);
50+ pango_font_description_set_absolute_size(desc.get(), font_size);
51 pango_layout_set_font_description(layout, desc.get());
52
53- pango_layout_set_width(layout, pango_units_from_double(COUNT_FONT_WIDTH));
54- pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
55- pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
56- pango_layout_set_markup_with_accel(layout, count_text.c_str(), -1, '_', nullptr);
57+ pango_layout_set_width(layout, pango_units_from_double(icon_size() * 0.75));
58+ pango_layout_set_height(layout, -1);
59+ pango_layout_set_wrap(layout, PANGO_WRAP_CHAR);
60+ pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_MIDDLE);
61+ pango_layout_set_text(layout, std::to_string(count).c_str(), -1);
62
63 PangoRectangle ink_rect;
64 pango_layout_get_pixel_extents(layout, &ink_rect, nullptr);
65
66 /* DRAW OUTLINE */
67- float radius = COUNT_HEIGHT / 2.0f - 1.0f;
68- float inset = radius + 1.0f;
69+ const float height = ink_rect.height + COUNT_PADDING * 4;
70+ const float inset = height / 2.0;
71+ const float radius = inset - 1.0f;
72+ const float width = ink_rect.width + inset + COUNT_PADDING * 2;
73
74- nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, std::round(COUNT_WIDTH * scale), std::round(COUNT_HEIGHT * scale));
75+ nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, std::round(width * scale), std::round(height * scale));
76 cairo_surface_set_device_scale(cg.GetSurface(), scale, scale);
77 cairo_t* cr = cg.GetInternalContext();
78
79- cairo_move_to(cr, inset, COUNT_HEIGHT - 1.0f);
80+ cairo_move_to(cr, inset, height - 1.0f);
81 cairo_arc(cr, inset, inset, radius, 0.5 * M_PI, 1.5 * M_PI);
82- cairo_arc(cr, COUNT_WIDTH - inset, inset, radius, 1.5 * M_PI, 0.5 * M_PI);
83- cairo_line_to(cr, inset, COUNT_HEIGHT - 1.0f);
84+ cairo_arc(cr, width - inset, inset, radius, 1.5 * M_PI, 0.5 * M_PI);
85+ cairo_line_to(cr, inset, height - 1.0f);
86
87 cairo_set_source_rgba(cr, 0.35f, 0.35f, 0.35f, 1.0f);
88 cairo_fill_preserve(cr);
89@@ -1077,8 +1081,8 @@
90 cairo_set_line_width(cr, 1.0f);
91
92 /* DRAW TEXT */
93- cairo_move_to(cr, (COUNT_WIDTH - ink_rect.width) / 2.0 - ink_rect.x,
94- (COUNT_HEIGHT - ink_rect.height) / 2.0 - ink_rect.y);
95+ cairo_move_to(cr, (width - ink_rect.width) / 2.0 - ink_rect.x,
96+ (height - ink_rect.height) / 2.0 - ink_rect.y);
97 pango_cairo_show_layout(cr, layout);
98
99 return texture_ptr_from_cairo_graphics(cg);
100@@ -1177,7 +1181,6 @@
101 return;
102
103 CleanCountTextures();
104- EmitNeedsRedraw();
105 }
106
107 void
108@@ -1208,7 +1211,6 @@
109 LauncherIcon::OnRemoteCountVisibleChanged(LauncherEntryRemote* remote)
110 {
111 CleanCountTextures();
112- EmitNeedsRedraw();
113 }
114
115 void
116
117=== modified file 'tests/CMakeLists.txt'
118--- tests/CMakeLists.txt 2014-02-20 20:52:57 +0000
119+++ tests/CMakeLists.txt 2014-08-27 22:39:22 +0000
120@@ -131,7 +131,6 @@
121 test_favorite_store_gsettings.cpp
122 test_favorite_store_private.cpp
123 test_launcher_entry_remote.cpp
124- test_launcher_model.cpp
125 test_launcher_options.cpp
126 test_layout_system.cpp
127 test_model_iterator.cpp
128@@ -242,6 +241,7 @@
129 test_launcher_hover_machine.cpp
130 test_launcher_icon.cpp
131 test_launcher_minimize_speed.cpp
132+ test_launcher_model.cpp
133 test_launcher_tooltip.cpp
134 test_lockscreen_controller.cpp
135 test_panel_controller.cpp
136
137=== modified file 'tests/test_main_xless.cpp'
138--- tests/test_main_xless.cpp 2013-02-21 10:47:14 +0000
139+++ tests/test_main_xless.cpp 2014-08-27 22:39:22 +0000
140@@ -3,18 +3,17 @@
141 #include <NuxCore/Logger.h>
142 #include <Nux/Nux.h>
143 #include <config.h>
144-
145+#include "test_utils.h"
146
147 const gchar* LOCAL_DATA_DIR = BUILDDIR"/tests/data:/usr/share";
148
149 int main(int argc, char** argv)
150 {
151 ::testing::InitGoogleTest(&argc, argv);
152-#if G_ENCODE_VERSION (GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION) <= GLIB_VERSION_2_34
153- g_type_init();
154-#endif
155+
156 setlocale(LC_ALL, "C");
157-
158+ g_setenv("LC_ALL", "C", TRUE);
159+ Utils::init_gsettings_test_environment();
160 g_setenv("XDG_DATA_DIRS", LOCAL_DATA_DIR, TRUE);
161
162 // Slightly higher as we're more likely to test things we know will fail
163
164=== modified file 'unity-shared/IconRenderer.cpp'
165--- unity-shared/IconRenderer.cpp 2014-08-27 22:39:22 +0000
166+++ unity-shared/IconRenderer.cpp 2014-08-27 22:39:22 +0000
167@@ -366,7 +366,7 @@
168 it->logical_center == launcher_icon->LastLogicalCenter(monitor) &&
169 it->rotation == launcher_icon->LastRotation(monitor) &&
170 it->skip == launcher_icon->WasSkipping(monitor) &&
171- (launcher_icon->Count() != 0) == launcher_icon->HadCount(monitor) &&
172+ launcher_icon->Count() == launcher_icon->LastCount(monitor) &&
173 (launcher_icon->Emblem() != nullptr) == launcher_icon->HadEmblem(monitor))
174 {
175 continue;
176@@ -376,7 +376,7 @@
177 launcher_icon->RememberRotation(monitor, it->rotation);
178 launcher_icon->RememberSkip(monitor, it->skip);
179 launcher_icon->RememberEmblem(monitor, launcher_icon->Emblem() != nullptr);
180- launcher_icon->RememberCount(monitor, launcher_icon->Count() != 0);
181+ launcher_icon->RememberCount(monitor, launcher_icon->Count());
182
183 float w = icon_size;
184 float h = icon_size;
185
186=== modified file 'unity-shared/IconTextureSource.cpp'
187--- unity-shared/IconTextureSource.cpp 2014-08-27 22:39:22 +0000
188+++ unity-shared/IconTextureSource.cpp 2014-08-27 22:39:22 +0000
189@@ -19,6 +19,7 @@
190
191 #include "IconTextureSource.h"
192 #include "MultiMonitor.h"
193+#include "unity-shared/UnitySettings.h"
194
195 namespace unity
196 {
197@@ -34,12 +35,16 @@
198 IconTextureSource::IconTextureSource()
199 : skip_(RENDERERS_SIZE, false)
200 , had_emblem_(RENDERERS_SIZE, false)
201- , had_count_(RENDERERS_SIZE, false)
202+ , last_count_(RENDERERS_SIZE, 0)
203 , last_render_center_(RENDERERS_SIZE)
204 , last_logical_center_(RENDERERS_SIZE)
205 , last_rotation_(RENDERERS_SIZE)
206 , transformations_(RENDERERS_SIZE, decltype(transformations_)::value_type(TRANSFORM_SIZE, std::vector<nux::Vector4>(4)))
207-{}
208+{
209+ auto reset_count_cb = sigc::mem_fun(this, &IconTextureSource::ResetLastCount);
210+ Settings::Instance().dpi_changed.connect(reset_count_cb);
211+ Settings::Instance().font_scaling.changed.connect(sigc::hide(reset_count_cb));
212+}
213
214 std::vector<nux::Vector4> & IconTextureSource::GetTransform(TransformIndex index, int monitor)
215 {
216@@ -92,14 +97,14 @@
217 return had_emblem_[monitor];
218 }
219
220-void IconTextureSource::RememberCount(int monitor, bool has_count)
221+void IconTextureSource::RememberCount(int monitor, unsigned count)
222 {
223- had_count_[monitor] = has_count;
224+ last_count_[monitor] = count;
225 }
226
227-bool IconTextureSource::HadCount(int monitor) const
228+unsigned IconTextureSource::LastCount(int monitor) const
229 {
230- return had_count_[monitor];
231+ return last_count_[monitor];
232 }
233
234 unsigned IconTextureSource::Count() const
235@@ -107,6 +112,11 @@
236 return 0;
237 }
238
239+void IconTextureSource::ResetLastCount()
240+{
241+ std::fill(last_count_.begin(), last_count_.end(), 0);
242+}
243+
244 nux::BaseTexture* IconTextureSource::Emblem() const
245 {
246 return nullptr;
247
248=== modified file 'unity-shared/IconTextureSource.h'
249--- unity-shared/IconTextureSource.h 2014-08-27 22:39:22 +0000
250+++ unity-shared/IconTextureSource.h 2014-08-27 22:39:22 +0000
251@@ -46,7 +46,7 @@
252 };
253
254 IconTextureSource();
255- virtual ~IconTextureSource() {}
256+ virtual ~IconTextureSource() = default;
257
258 std::vector<nux::Vector4> & GetTransform(TransformIndex index, int monitor);
259
260@@ -62,8 +62,8 @@
261 void RememberEmblem(int monitor, bool has_emblem);
262 bool HadEmblem(int monitor) const;
263
264- void RememberCount(int monitor, bool has_count);
265- bool HadCount(int monitor) const;
266+ void RememberCount(int monitor, unsigned count);
267+ unsigned LastCount(int monitor) const;
268
269 virtual nux::Color BackgroundColor() const = 0;
270 virtual nux::Color GlowColor() = 0;
271@@ -74,9 +74,11 @@
272 virtual nux::BaseTexture* Emblem() const;
273
274 private:
275+ void ResetLastCount();
276+
277 std::vector<bool> skip_;
278 std::vector<bool> had_emblem_;
279- std::vector<bool> had_count_;
280+ std::vector<unsigned> last_count_;
281 std::vector<nux::Point3> last_render_center_;
282 std::vector<nux::Point3> last_logical_center_;
283 std::vector<nux::Vector3> last_rotation_;