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

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Brandon Schaefer
Approved revision: no longer in the source branch.
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 (community) continuous-integration Needs Fixing
Brandon Schaefer (community) Approve
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.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

LGTM

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
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
=== modified file 'launcher/LauncherIcon.cpp'
--- launcher/LauncherIcon.cpp 2014-08-27 22:39:22 +0000
+++ launcher/LauncherIcon.cpp 2014-08-27 22:39:22 +0000
@@ -60,10 +60,8 @@
60const std::string PRESENT_TIMEOUT = "present-timeout";60const std::string PRESENT_TIMEOUT = "present-timeout";
61const std::string QUIRK_DELAY_TIMEOUT = "quirk-delay-timeout";61const std::string QUIRK_DELAY_TIMEOUT = "quirk-delay-timeout";
6262
63const int COUNT_WIDTH = 32;63const int COUNT_FONT_SIZE = 11;
64const int COUNT_HEIGHT = 16;64const int COUNT_PADDING = 2;
65const int COUNT_FONT_WIDTH = COUNT_WIDTH - 4;
66const int COUNT_FONT_HEIGHT = COUNT_HEIGHT - 5;
67}65}
6866
69NUX_IMPLEMENT_OBJECT_TYPE(LauncherIcon);67NUX_IMPLEMENT_OBJECT_TYPE(LauncherIcon);
@@ -103,8 +101,11 @@
103 mouse_down.connect(sigc::mem_fun(this, &LauncherIcon::RecvMouseDown));101 mouse_down.connect(sigc::mem_fun(this, &LauncherIcon::RecvMouseDown));
104 mouse_up.connect(sigc::mem_fun(this, &LauncherIcon::RecvMouseUp));102 mouse_up.connect(sigc::mem_fun(this, &LauncherIcon::RecvMouseUp));
105 mouse_click.connect(sigc::mem_fun(this, &LauncherIcon::RecvMouseClick));103 mouse_click.connect(sigc::mem_fun(this, &LauncherIcon::RecvMouseClick));
106 Settings::Instance().dpi_changed.connect(sigc::mem_fun(this, &LauncherIcon::CleanCountTextures));104
107 icon_size.changed.connect(sigc::hide(sigc::mem_fun(this, &LauncherIcon::CleanCountTextures)));105 auto const& count_rebuild_cb = sigc::mem_fun(this, &LauncherIcon::CleanCountTextures);
106 Settings::Instance().dpi_changed.connect(count_rebuild_cb);
107 Settings::Instance().font_scaling.changed.connect(sigc::hide(count_rebuild_cb));
108 icon_size.changed.connect(sigc::hide(count_rebuild_cb));
108109
109 for (unsigned i = 0; i < monitors::MAX; ++i)110 for (unsigned i = 0; i < monitors::MAX; ++i)
110 {111 {
@@ -1031,41 +1032,44 @@
1031void LauncherIcon::CleanCountTextures()1032void LauncherIcon::CleanCountTextures()
1032{1033{
1033 _counts.clear();1034 _counts.clear();
1035 EmitNeedsRedraw();
1034}1036}
10351037
1036BaseTexturePtr LauncherIcon::DrawCountTexture(unsigned count, double scale)1038BaseTexturePtr LauncherIcon::DrawCountTexture(unsigned count, double scale)
1037{1039{
1038 auto const& count_text = (count / 10000 != 0) ? "****" : std::to_string(count);
1039
1040 glib::Object<PangoContext> pango_ctx(gdk_pango_context_get());1040 glib::Object<PangoContext> pango_ctx(gdk_pango_context_get());
1041 glib::Object<PangoLayout> layout(pango_layout_new(pango_ctx));1041 glib::Object<PangoLayout> layout(pango_layout_new(pango_ctx));
10421042
1043 glib::String font_name;1043 glib::String font_name;
1044 g_object_get(gtk_settings_get_default(), "gtk-font-name", &font_name, nullptr);1044 g_object_get(gtk_settings_get_default(), "gtk-font-name", &font_name, nullptr);
1045 std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font_name), pango_font_description_free);1045 std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font_name), pango_font_description_free);
1046 pango_font_description_set_absolute_size(desc.get(), pango_units_from_double(COUNT_FONT_HEIGHT));1046 int font_size = pango_units_from_double(Settings::Instance().font_scaling() * COUNT_FONT_SIZE);
1047 pango_font_description_set_absolute_size(desc.get(), font_size);
1047 pango_layout_set_font_description(layout, desc.get());1048 pango_layout_set_font_description(layout, desc.get());
10481049
1049 pango_layout_set_width(layout, pango_units_from_double(COUNT_FONT_WIDTH));1050 pango_layout_set_width(layout, pango_units_from_double(icon_size() * 0.75));
1050 pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);1051 pango_layout_set_height(layout, -1);
1051 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);1052 pango_layout_set_wrap(layout, PANGO_WRAP_CHAR);
1052 pango_layout_set_markup_with_accel(layout, count_text.c_str(), -1, '_', nullptr);1053 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_MIDDLE);
1054 pango_layout_set_text(layout, std::to_string(count).c_str(), -1);
10531055
1054 PangoRectangle ink_rect;1056 PangoRectangle ink_rect;
1055 pango_layout_get_pixel_extents(layout, &ink_rect, nullptr);1057 pango_layout_get_pixel_extents(layout, &ink_rect, nullptr);
10561058
1057 /* DRAW OUTLINE */1059 /* DRAW OUTLINE */
1058 float radius = COUNT_HEIGHT / 2.0f - 1.0f;1060 const float height = ink_rect.height + COUNT_PADDING * 4;
1059 float inset = radius + 1.0f;1061 const float inset = height / 2.0;
1062 const float radius = inset - 1.0f;
1063 const float width = ink_rect.width + inset + COUNT_PADDING * 2;
10601064
1061 nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, std::round(COUNT_WIDTH * scale), std::round(COUNT_HEIGHT * scale));1065 nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, std::round(width * scale), std::round(height * scale));
1062 cairo_surface_set_device_scale(cg.GetSurface(), scale, scale);1066 cairo_surface_set_device_scale(cg.GetSurface(), scale, scale);
1063 cairo_t* cr = cg.GetInternalContext();1067 cairo_t* cr = cg.GetInternalContext();
10641068
1065 cairo_move_to(cr, inset, COUNT_HEIGHT - 1.0f);1069 cairo_move_to(cr, inset, height - 1.0f);
1066 cairo_arc(cr, inset, inset, radius, 0.5 * M_PI, 1.5 * M_PI);1070 cairo_arc(cr, inset, inset, radius, 0.5 * M_PI, 1.5 * M_PI);
1067 cairo_arc(cr, COUNT_WIDTH - inset, inset, radius, 1.5 * M_PI, 0.5 * M_PI);1071 cairo_arc(cr, width - inset, inset, radius, 1.5 * M_PI, 0.5 * M_PI);
1068 cairo_line_to(cr, inset, COUNT_HEIGHT - 1.0f);1072 cairo_line_to(cr, inset, height - 1.0f);
10691073
1070 cairo_set_source_rgba(cr, 0.35f, 0.35f, 0.35f, 1.0f);1074 cairo_set_source_rgba(cr, 0.35f, 0.35f, 0.35f, 1.0f);
1071 cairo_fill_preserve(cr);1075 cairo_fill_preserve(cr);
@@ -1077,8 +1081,8 @@
1077 cairo_set_line_width(cr, 1.0f);1081 cairo_set_line_width(cr, 1.0f);
10781082
1079 /* DRAW TEXT */1083 /* DRAW TEXT */
1080 cairo_move_to(cr, (COUNT_WIDTH - ink_rect.width) / 2.0 - ink_rect.x,1084 cairo_move_to(cr, (width - ink_rect.width) / 2.0 - ink_rect.x,
1081 (COUNT_HEIGHT - ink_rect.height) / 2.0 - ink_rect.y);1085 (height - ink_rect.height) / 2.0 - ink_rect.y);
1082 pango_cairo_show_layout(cr, layout);1086 pango_cairo_show_layout(cr, layout);
10831087
1084 return texture_ptr_from_cairo_graphics(cg);1088 return texture_ptr_from_cairo_graphics(cg);
@@ -1177,7 +1181,6 @@
1177 return;1181 return;
11781182
1179 CleanCountTextures();1183 CleanCountTextures();
1180 EmitNeedsRedraw();
1181}1184}
11821185
1183void1186void
@@ -1208,7 +1211,6 @@
1208LauncherIcon::OnRemoteCountVisibleChanged(LauncherEntryRemote* remote)1211LauncherIcon::OnRemoteCountVisibleChanged(LauncherEntryRemote* remote)
1209{1212{
1210 CleanCountTextures();1213 CleanCountTextures();
1211 EmitNeedsRedraw();
1212}1214}
12131215
1214void1216void
12151217
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2014-02-20 20:52:57 +0000
+++ tests/CMakeLists.txt 2014-08-27 22:39:22 +0000
@@ -131,7 +131,6 @@
131 test_favorite_store_gsettings.cpp131 test_favorite_store_gsettings.cpp
132 test_favorite_store_private.cpp132 test_favorite_store_private.cpp
133 test_launcher_entry_remote.cpp133 test_launcher_entry_remote.cpp
134 test_launcher_model.cpp
135 test_launcher_options.cpp134 test_launcher_options.cpp
136 test_layout_system.cpp135 test_layout_system.cpp
137 test_model_iterator.cpp136 test_model_iterator.cpp
@@ -242,6 +241,7 @@
242 test_launcher_hover_machine.cpp241 test_launcher_hover_machine.cpp
243 test_launcher_icon.cpp242 test_launcher_icon.cpp
244 test_launcher_minimize_speed.cpp243 test_launcher_minimize_speed.cpp
244 test_launcher_model.cpp
245 test_launcher_tooltip.cpp245 test_launcher_tooltip.cpp
246 test_lockscreen_controller.cpp246 test_lockscreen_controller.cpp
247 test_panel_controller.cpp247 test_panel_controller.cpp
248248
=== modified file 'tests/test_main_xless.cpp'
--- tests/test_main_xless.cpp 2013-02-21 10:47:14 +0000
+++ tests/test_main_xless.cpp 2014-08-27 22:39:22 +0000
@@ -3,18 +3,17 @@
3#include <NuxCore/Logger.h>3#include <NuxCore/Logger.h>
4#include <Nux/Nux.h>4#include <Nux/Nux.h>
5#include <config.h>5#include <config.h>
66#include "test_utils.h"
77
8const gchar* LOCAL_DATA_DIR = BUILDDIR"/tests/data:/usr/share";8const gchar* LOCAL_DATA_DIR = BUILDDIR"/tests/data:/usr/share";
99
10int main(int argc, char** argv)10int main(int argc, char** argv)
11{11{
12 ::testing::InitGoogleTest(&argc, argv);12 ::testing::InitGoogleTest(&argc, argv);
13#if G_ENCODE_VERSION (GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION) <= GLIB_VERSION_2_3413
14 g_type_init();
15#endif
16 setlocale(LC_ALL, "C");14 setlocale(LC_ALL, "C");
1715 g_setenv("LC_ALL", "C", TRUE);
16 Utils::init_gsettings_test_environment();
18 g_setenv("XDG_DATA_DIRS", LOCAL_DATA_DIR, TRUE);17 g_setenv("XDG_DATA_DIRS", LOCAL_DATA_DIR, TRUE);
1918
20 // Slightly higher as we're more likely to test things we know will fail19 // Slightly higher as we're more likely to test things we know will fail
2120
=== modified file 'unity-shared/IconRenderer.cpp'
--- unity-shared/IconRenderer.cpp 2014-08-27 22:39:22 +0000
+++ unity-shared/IconRenderer.cpp 2014-08-27 22:39:22 +0000
@@ -366,7 +366,7 @@
366 it->logical_center == launcher_icon->LastLogicalCenter(monitor) &&366 it->logical_center == launcher_icon->LastLogicalCenter(monitor) &&
367 it->rotation == launcher_icon->LastRotation(monitor) &&367 it->rotation == launcher_icon->LastRotation(monitor) &&
368 it->skip == launcher_icon->WasSkipping(monitor) &&368 it->skip == launcher_icon->WasSkipping(monitor) &&
369 (launcher_icon->Count() != 0) == launcher_icon->HadCount(monitor) &&369 launcher_icon->Count() == launcher_icon->LastCount(monitor) &&
370 (launcher_icon->Emblem() != nullptr) == launcher_icon->HadEmblem(monitor))370 (launcher_icon->Emblem() != nullptr) == launcher_icon->HadEmblem(monitor))
371 {371 {
372 continue;372 continue;
@@ -376,7 +376,7 @@
376 launcher_icon->RememberRotation(monitor, it->rotation);376 launcher_icon->RememberRotation(monitor, it->rotation);
377 launcher_icon->RememberSkip(monitor, it->skip);377 launcher_icon->RememberSkip(monitor, it->skip);
378 launcher_icon->RememberEmblem(monitor, launcher_icon->Emblem() != nullptr);378 launcher_icon->RememberEmblem(monitor, launcher_icon->Emblem() != nullptr);
379 launcher_icon->RememberCount(monitor, launcher_icon->Count() != 0);379 launcher_icon->RememberCount(monitor, launcher_icon->Count());
380380
381 float w = icon_size;381 float w = icon_size;
382 float h = icon_size;382 float h = icon_size;
383383
=== modified file 'unity-shared/IconTextureSource.cpp'
--- unity-shared/IconTextureSource.cpp 2014-08-27 22:39:22 +0000
+++ unity-shared/IconTextureSource.cpp 2014-08-27 22:39:22 +0000
@@ -19,6 +19,7 @@
1919
20#include "IconTextureSource.h"20#include "IconTextureSource.h"
21#include "MultiMonitor.h"21#include "MultiMonitor.h"
22#include "unity-shared/UnitySettings.h"
2223
23namespace unity24namespace unity
24{25{
@@ -34,12 +35,16 @@
34IconTextureSource::IconTextureSource()35IconTextureSource::IconTextureSource()
35 : skip_(RENDERERS_SIZE, false)36 : skip_(RENDERERS_SIZE, false)
36 , had_emblem_(RENDERERS_SIZE, false)37 , had_emblem_(RENDERERS_SIZE, false)
37 , had_count_(RENDERERS_SIZE, false)38 , last_count_(RENDERERS_SIZE, 0)
38 , last_render_center_(RENDERERS_SIZE)39 , last_render_center_(RENDERERS_SIZE)
39 , last_logical_center_(RENDERERS_SIZE)40 , last_logical_center_(RENDERERS_SIZE)
40 , last_rotation_(RENDERERS_SIZE)41 , last_rotation_(RENDERERS_SIZE)
41 , transformations_(RENDERERS_SIZE, decltype(transformations_)::value_type(TRANSFORM_SIZE, std::vector<nux::Vector4>(4)))42 , transformations_(RENDERERS_SIZE, decltype(transformations_)::value_type(TRANSFORM_SIZE, std::vector<nux::Vector4>(4)))
42{}43{
44 auto reset_count_cb = sigc::mem_fun(this, &IconTextureSource::ResetLastCount);
45 Settings::Instance().dpi_changed.connect(reset_count_cb);
46 Settings::Instance().font_scaling.changed.connect(sigc::hide(reset_count_cb));
47}
4348
44std::vector<nux::Vector4> & IconTextureSource::GetTransform(TransformIndex index, int monitor)49std::vector<nux::Vector4> & IconTextureSource::GetTransform(TransformIndex index, int monitor)
45{50{
@@ -92,14 +97,14 @@
92 return had_emblem_[monitor];97 return had_emblem_[monitor];
93}98}
9499
95void IconTextureSource::RememberCount(int monitor, bool has_count)100void IconTextureSource::RememberCount(int monitor, unsigned count)
96{101{
97 had_count_[monitor] = has_count;102 last_count_[monitor] = count;
98}103}
99104
100bool IconTextureSource::HadCount(int monitor) const105unsigned IconTextureSource::LastCount(int monitor) const
101{106{
102 return had_count_[monitor];107 return last_count_[monitor];
103}108}
104109
105unsigned IconTextureSource::Count() const110unsigned IconTextureSource::Count() const
@@ -107,6 +112,11 @@
107 return 0;112 return 0;
108}113}
109114
115void IconTextureSource::ResetLastCount()
116{
117 std::fill(last_count_.begin(), last_count_.end(), 0);
118}
119
110nux::BaseTexture* IconTextureSource::Emblem() const120nux::BaseTexture* IconTextureSource::Emblem() const
111{121{
112 return nullptr;122 return nullptr;
113123
=== modified file 'unity-shared/IconTextureSource.h'
--- unity-shared/IconTextureSource.h 2014-08-27 22:39:22 +0000
+++ unity-shared/IconTextureSource.h 2014-08-27 22:39:22 +0000
@@ -46,7 +46,7 @@
46 };46 };
4747
48 IconTextureSource();48 IconTextureSource();
49 virtual ~IconTextureSource() {}49 virtual ~IconTextureSource() = default;
5050
51 std::vector<nux::Vector4> & GetTransform(TransformIndex index, int monitor);51 std::vector<nux::Vector4> & GetTransform(TransformIndex index, int monitor);
5252
@@ -62,8 +62,8 @@
62 void RememberEmblem(int monitor, bool has_emblem);62 void RememberEmblem(int monitor, bool has_emblem);
63 bool HadEmblem(int monitor) const;63 bool HadEmblem(int monitor) const;
6464
65 void RememberCount(int monitor, bool has_count);65 void RememberCount(int monitor, unsigned count);
66 bool HadCount(int monitor) const;66 unsigned LastCount(int monitor) const;
6767
68 virtual nux::Color BackgroundColor() const = 0;68 virtual nux::Color BackgroundColor() const = 0;
69 virtual nux::Color GlowColor() = 0;69 virtual nux::Color GlowColor() = 0;
@@ -74,9 +74,11 @@
74 virtual nux::BaseTexture* Emblem() const;74 virtual nux::BaseTexture* Emblem() const;
7575
76private:76private:
77 void ResetLastCount();
78
77 std::vector<bool> skip_;79 std::vector<bool> skip_;
78 std::vector<bool> had_emblem_;80 std::vector<bool> had_emblem_;
79 std::vector<bool> had_count_;81 std::vector<unsigned> last_count_;
80 std::vector<nux::Point3> last_render_center_;82 std::vector<nux::Point3> last_render_center_;
81 std::vector<nux::Point3> last_logical_center_;83 std::vector<nux::Point3> last_logical_center_;
82 std::vector<nux::Vector3> last_rotation_;84 std::vector<nux::Vector3> last_rotation_;