Merge lp:~3v1n0/unity/hud-dynamic-icon-size into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 2328
Proposed branch: lp:~3v1n0/unity/hud-dynamic-icon-size
Merge into: lp:unity
Diff against target: 353 lines (+70/-37)
9 files modified
plugins/unityshell/src/HudController.cpp (+15/-8)
plugins/unityshell/src/HudController.h (+3/-0)
plugins/unityshell/src/HudIcon.cpp (+15/-11)
plugins/unityshell/src/HudIcon.h (+4/-2)
plugins/unityshell/src/HudView.cpp (+21/-11)
plugins/unityshell/src/HudView.h (+1/-2)
plugins/unityshell/src/IconTexture.cpp (+3/-0)
plugins/unityshell/src/IconTexture.h (+1/-1)
plugins/unityshell/src/unityshell.cpp (+7/-2)
To merge this branch: bzr merge lp:~3v1n0/unity/hud-dynamic-icon-size
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Andrea Cimitan design Pending
Review via email: mp+103038@code.launchpad.net

Commit message

Hud: update the icon size to match the launcher icon size when in auto-hide mode

Plus prevent a couple of crashes

Description of the change

When the launcher is in autohide mode the HUD should update the icon size to follow the launcher icon size.

To do that, now unityshell updates two HudController properties that controls the icon size and the tile size, then we update the HudIcon values accordingly. The HUD icon is now using also a padding that, in case of big icon sizes, makes the HUD to increase its size, keeping the icon far from its borders.

Also I've prevented a couple of crashes in IconTexture and HudView.

Since this is a pure visual change, no testing is needed. Here the fixes:

Hud 48px (standard) icon: http://i.imgur.com/tNoWc.png
Hud 64px icon: http://i.imgur.com/ks3OH.png
Hud 32px icon: http://i.imgur.com/IAIgk.png

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

code looks good.

review: Approve
Revision history for this message
Andrea Cimitan (cimi) wrote :

Screenshots are fine

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/unityshell/src/HudController.cpp'
--- plugins/unityshell/src/HudController.cpp 2012-04-19 03:43:22 +0000
+++ plugins/unityshell/src/HudController.cpp 2012-04-23 02:07:20 +0000
@@ -170,6 +170,16 @@
170 }170 }
171}171}
172172
173void Controller::SetIcon(std::string const& icon_name)
174{
175 LOG_DEBUG(logger) << "setting icon to - " << icon_name;
176
177 if (view_)
178 view_->SetIcon(icon_name, tile_size, icon_size, launcher_width - tile_size);
179
180 ubus.SendMessage(UBUS_HUD_ICON_CHANGED, g_variant_new_string(icon_name.c_str()));
181}
182
173nux::BaseWindow* Controller::window() const183nux::BaseWindow* Controller::window() const
174{184{
175 return window_;185 return window_;
@@ -300,7 +310,7 @@
300 {310 {
301 // Windows list stack for all the monitors311 // Windows list stack for all the monitors
302 GList *windows = bamf_matcher_get_window_stack_for_monitor(matcher, -1);312 GList *windows = bamf_matcher_get_window_stack_for_monitor(matcher, -1);
303 313
304 // Reset values, in case we can't find a window ie. empty current desktop314 // Reset values, in case we can't find a window ie. empty current desktop
305 active_xid = 0;315 active_xid = 0;
306 active_win = nullptr;316 active_win = nullptr;
@@ -326,6 +336,7 @@
326336
327 g_list_free(windows);337 g_list_free(windows);
328 }338 }
339
329 BamfApplication* active_app = bamf_matcher_get_application_for_window(matcher, active_win);340 BamfApplication* active_app = bamf_matcher_get_application_for_window(matcher, active_win);
330341
331 if (BAMF_IS_VIEW(active_app))342 if (BAMF_IS_VIEW(active_app))
@@ -340,8 +351,7 @@
340 }351 }
341352
342 LOG_DEBUG(logger) << "Taking application icon: " << focused_app_icon_;353 LOG_DEBUG(logger) << "Taking application icon: " << focused_app_icon_;
343 ubus.SendMessage(UBUS_HUD_ICON_CHANGED, g_variant_new_string(focused_app_icon_.c_str())); 354 SetIcon(focused_app_icon_);
344 view_->SetIcon(focused_app_icon_);
345355
346 window_->ShowWindow(true);356 window_->ShowWindow(true);
347 window_->PushToFront();357 window_->PushToFront();
@@ -493,8 +503,7 @@
493void Controller::OnQuerySelected(Query::Ptr query)503void Controller::OnQuerySelected(Query::Ptr query)
494{504{
495 LOG_DEBUG(logger) << "Selected query, " << query->formatted_text;505 LOG_DEBUG(logger) << "Selected query, " << query->formatted_text;
496 view_->SetIcon(query->icon_name);506 SetIcon(query->icon_name);
497 ubus.SendMessage(UBUS_HUD_ICON_CHANGED, g_variant_new_string(query->icon_name.c_str()));
498}507}
499508
500void Controller::OnQueriesFinished(Hud::Queries queries)509void Controller::OnQueriesFinished(Hud::Queries queries)
@@ -510,9 +519,7 @@
510 }519 }
511 }520 }
512521
513 LOG_DEBUG(logger) << "setting icon to - " << icon_name;522 SetIcon(icon_name);
514 view_->SetIcon(icon_name);
515 ubus.SendMessage(UBUS_HUD_ICON_CHANGED, g_variant_new_string(icon_name.c_str()));
516}523}
517524
518// Introspectable525// Introspectable
519526
=== modified file 'plugins/unityshell/src/HudController.h'
--- plugins/unityshell/src/HudController.h 2012-04-02 00:16:21 +0000
+++ plugins/unityshell/src/HudController.h 2012-04-23 02:07:20 +0000
@@ -48,6 +48,8 @@
48 nux::BaseWindow* window() const;48 nux::BaseWindow* window() const;
4949
50 nux::Property<int> launcher_width;50 nux::Property<int> launcher_width;
51 nux::Property<int> icon_size;
52 nux::Property<int> tile_size;
51 nux::Property<bool> launcher_locked_out;53 nux::Property<bool> launcher_locked_out;
52 nux::Property<bool> multiple_launchers;54 nux::Property<bool> multiple_launchers;
5355
@@ -65,6 +67,7 @@
65 void SetupWindow();67 void SetupWindow();
66 void SetupHudView();68 void SetupHudView();
67 void RegisterUBusInterests();69 void RegisterUBusInterests();
70 void SetIcon(std::string const& icon_name);
6871
69 int GetTargetMonitor();72 int GetTargetMonitor();
70 bool IsLockedToLauncher(int monitor);73 bool IsLockedToLauncher(int monitor);
7174
=== modified file 'plugins/unityshell/src/HudIcon.cpp'
--- plugins/unityshell/src/HudIcon.cpp 2012-04-03 11:44:41 +0000
+++ plugins/unityshell/src/HudIcon.cpp 2012-04-23 02:07:20 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2010 Canonical Ltd2 * Copyright (C) 2010-2012 Canonical Ltd
3 *3 *
4 * This program is free software: you can redistribute it and/or modify4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as5 * it under the terms of the GNU General Public License version 3 as
@@ -14,6 +14,7 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *15 *
16 * Authored by: Gord Allott <gord.allott@canonical.com>16 * Authored by: Gord Allott <gord.allott@canonical.com>
17 * Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
17 */18 */
1819
1920
@@ -24,8 +25,7 @@
24namespace25namespace
25{26{
26 nux::logging::Logger logger("unity.hud.icon");27 nux::logging::Logger logger("unity.hud.icon");
27 const unsigned int tile_margin = 4;28 const unsigned int vertical_padding = 4;
28 const unsigned int minimum_width = 64;
29}29}
3030
31namespace unity31namespace unity
@@ -33,13 +33,9 @@
33namespace hud33namespace hud
34{34{
3535
36Icon::Icon(std::string const& icon_name, unsigned int size)36Icon::Icon()
37 : IconTexture(icon_name, size, true)37 : IconTexture("", 0, true)
38{38{
39 int tile_size = size + tile_margin * 2;
40 SetMinimumWidth(minimum_width);
41 SetMinimumHeight(tile_size);
42 icon_renderer_.SetTargetSize(tile_size, size, 0);
43 background_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_back_54.png", -1, true));39 background_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_back_54.png", -1, true));
44 gloss_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_shine_54.png", -1, true));40 gloss_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_shine_54.png", -1, true));
45 edge_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_edge_54.png", -1, true));41 edge_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_edge_54.png", -1, true));
@@ -53,6 +49,14 @@
53 });49 });
54}50}
5551
52void Icon::SetIcon(std::string const& icon_name, unsigned int icon_size, unsigned int tile_size)
53{
54 IconTexture::SetByIconName(icon_name, icon_size);
55 icon_renderer_.SetTargetSize(tile_size, icon_size, 0);
56 SetMinimumWidth(tile_size);
57 SetMinimumHeight(tile_size + vertical_padding * 2);
58}
59
56void Icon::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)60void Icon::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
57{61{
58 if (texture() == nullptr)62 if (texture() == nullptr)
@@ -63,8 +67,8 @@
63 arg.colorify = nux::color::White;67 arg.colorify = nux::color::White;
64 arg.running_arrow = true;68 arg.running_arrow = true;
65 arg.running_on_viewport = true;69 arg.running_on_viewport = true;
66 arg.render_center = nux::Point3(32, 32, 0);70 arg.render_center = nux::Point3(GetMinimumWidth() / 2.0f, GetMinimumHeight() / 2.0f, 0.0f);
67 arg.logical_center = nux::Point3(52, 50, 0);71 arg.logical_center = arg.render_center;
68 arg.window_indicators = true;72 arg.window_indicators = true;
69 arg.backlight_intensity = 1.0f;73 arg.backlight_intensity = 1.0f;
70 arg.alpha = 1.0f;74 arg.alpha = 1.0f;
7175
=== modified file 'plugins/unityshell/src/HudIcon.h'
--- plugins/unityshell/src/HudIcon.h 2012-04-01 00:00:45 +0000
+++ plugins/unityshell/src/HudIcon.h 2012-04-23 02:07:20 +0000
@@ -34,8 +34,10 @@
34class Icon : public unity::IconTexture34class Icon : public unity::IconTexture
35{35{
36public:36public:
37 typedef nux::ObjectPtr<IconTexture> Ptr;37 typedef nux::ObjectPtr<Icon> Ptr;
38 Icon(std::string const& icon_name, unsigned int size);38 Icon();
39
40 void SetIcon(std::string const& icon_name, unsigned int icon_size, unsigned int tile_size);
3941
40protected:42protected:
41 void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);43 void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
4244
=== modified file 'plugins/unityshell/src/HudView.cpp'
--- plugins/unityshell/src/HudView.cpp 2012-04-11 14:57:40 +0000
+++ plugins/unityshell/src/HudView.cpp 2012-04-23 02:07:20 +0000
@@ -39,11 +39,10 @@
39namespace39namespace
40{40{
41nux::logging::Logger logger("unity.hud.view");41nux::logging::Logger logger("unity.hud.view");
42const int icon_size = 46;
43const int grow_anim_length = 90 * 1000;42const int grow_anim_length = 90 * 1000;
44const int pause_before_grow_length = 32 * 1000;43const int pause_before_grow_length = 32 * 1000;
4544
46const int default_width = 1024;45const int default_width = 960;
47const int default_height = 276;46const int default_height = 276;
48const int content_width = 941;47const int content_width = 941;
4948
@@ -126,6 +125,9 @@
126 {125 {
127 RemoveChild((*button).GetPointer());126 RemoveChild((*button).GetPointer());
128 }127 }
128
129 if (timeline_id_)
130 g_source_remove(timeline_id_);
129}131}
130132
131void View::ProcessGrowShrink()133void View::ProcessGrowShrink()
@@ -175,7 +177,7 @@
175177
176void View::Relayout()178void View::Relayout()
177{179{
178 nux::Geometry geo = GetGeometry();180 nux::Geometry const& geo = GetGeometry();
179 content_geo_ = GetBestFitGeometry(geo);181 content_geo_ = GetBestFitGeometry(geo);
180 LOG_DEBUG(logger) << "content_geo: " << content_geo_.width << "x" << content_geo_.height;182 LOG_DEBUG(logger) << "content_geo: " << content_geo_.width << "x" << content_geo_.height;
181183
@@ -267,10 +269,20 @@
267 QueueDraw();269 QueueDraw();
268}270}
269271
270void View::SetIcon(std::string icon_name)272void View::SetIcon(std::string icon_name, unsigned int tile_size, unsigned int size, unsigned int padding)
271{273{
274 if (!icon_)
275 return;
276
272 LOG_DEBUG(logger) << "Setting icon to " << icon_name;277 LOG_DEBUG(logger) << "Setting icon to " << icon_name;
273 icon_->SetByIconName(icon_name, icon_size);278
279 icon_->SetIcon(icon_name, size, tile_size);
280 icon_->SetMinimumWidth(tile_size + padding);
281
282 /* We need to compute this value manually, since the _content_layout height changes */
283 int content_height = search_bar_->GetBaseHeight() + top_padding + bottom_padding;
284 icon_->SetMinimumHeight(std::max(icon_->GetMinimumHeight(), content_height));
285
274 QueueDraw();286 QueueDraw();
275}287}
276288
@@ -307,10 +319,8 @@
307 int width = default_width;319 int width = default_width;
308 int height = default_height;320 int height = default_height;
309321
310 if (!show_embedded_icon_)322 if (show_embedded_icon_)
311 {323 width += icon_->GetGeometry().width;
312 width -= icon_->GetGeometry().width;
313 }
314324
315 LOG_DEBUG (logger) << "best fit is, " << width << ", " << height;325 LOG_DEBUG (logger) << "best fit is, " << width << ", " << height;
316326
@@ -343,7 +353,7 @@
343 layout_ = new nux::HLayout();353 layout_ = new nux::HLayout();
344 {354 {
345 // fill layout with icon355 // fill layout with icon
346 icon_ = new Icon("", icon_size);356 icon_ = new Icon();
347 {357 {
348 AddChild(icon_.GetPointer());358 AddChild(icon_.GetPointer());
349 layout_->AddView(icon_.GetPointer(), 0, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);359 layout_->AddView(icon_.GetPointer(), 0, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
@@ -457,7 +467,7 @@
457467
458 if (timeline_need_more_draw_ && !timeline_id_)468 if (timeline_need_more_draw_ && !timeline_id_)
459 {469 {
460 timeline_id_ = g_timeout_add(0, [] (gpointer data) -> gboolean470 timeline_id_ = g_idle_add([] (gpointer data) -> gboolean
461 {471 {
462 View *self = static_cast<View*>(data);472 View *self = static_cast<View*>(data);
463 self->QueueDraw();473 self->QueueDraw();
464474
=== modified file 'plugins/unityshell/src/HudView.h'
--- plugins/unityshell/src/HudView.h 2012-04-02 16:06:18 +0000
+++ plugins/unityshell/src/HudView.h 2012-04-23 02:07:20 +0000
@@ -53,7 +53,7 @@
53 nux::View* default_focus() const;53 nux::View* default_focus() const;
5454
55 void SetQueries(Hud::Queries queries);55 void SetQueries(Hud::Queries queries);
56 void SetIcon(std::string icon_name);56 void SetIcon(std::string icon_name, unsigned int tile_size, unsigned int size, unsigned int padding);
57 void ShowEmbeddedIcon(bool show);57 void ShowEmbeddedIcon(bool show);
5858
59 void AboutToShow();59 void AboutToShow();
@@ -123,4 +123,3 @@
123}123}
124}124}
125#endif125#endif
126
127126
=== modified file 'plugins/unityshell/src/IconTexture.cpp'
--- plugins/unityshell/src/IconTexture.cpp 2012-04-11 01:08:15 +0000
+++ plugins/unityshell/src/IconTexture.cpp 2012-04-23 02:07:20 +0000
@@ -46,6 +46,7 @@
46IconTexture::IconTexture(nux::BaseTexture* texture, guint width, guint height)46IconTexture::IconTexture(nux::BaseTexture* texture, guint width, guint height)
47 : TextureArea(NUX_TRACKER_LOCATION),47 : TextureArea(NUX_TRACKER_LOCATION),
48 _accept_key_nav_focus(false),48 _accept_key_nav_focus(false),
49 _pixbuf_cached(nullptr),
49 _size(height),50 _size(height),
50 _texture_cached(texture),51 _texture_cached(texture),
51 _texture_width(width),52 _texture_width(width),
@@ -60,6 +61,7 @@
60IconTexture::IconTexture(std::string const& icon_name, unsigned int size, bool defer_icon_loading)61IconTexture::IconTexture(std::string const& icon_name, unsigned int size, bool defer_icon_loading)
61 : TextureArea(NUX_TRACKER_LOCATION),62 : TextureArea(NUX_TRACKER_LOCATION),
62 _accept_key_nav_focus(false),63 _accept_key_nav_focus(false),
64 _pixbuf_cached(nullptr),
63 _icon_name(!icon_name.empty() ? icon_name : DEFAULT_ICON),65 _icon_name(!icon_name.empty() ? icon_name : DEFAULT_ICON),
64 _size(size),66 _size(size),
65 _texture_width(0),67 _texture_width(0),
@@ -167,6 +169,7 @@
167 }169 }
168 else170 else
169 {171 {
172 _pixbuf_cached = nullptr;
170 _loading = false;173 _loading = false;
171174
172 // Protects against a missing default icon, we only request it if icon_name175 // Protects against a missing default icon, we only request it if icon_name
173176
=== modified file 'plugins/unityshell/src/IconTexture.h'
--- plugins/unityshell/src/IconTexture.h 2012-04-11 00:57:41 +0000
+++ plugins/unityshell/src/IconTexture.h 2012-04-23 02:07:20 +0000
@@ -63,7 +63,7 @@
63 std::string GetName() const;63 std::string GetName() const;
64 void AddProperties(GVariantBuilder* builder);64 void AddProperties(GVariantBuilder* builder);
65 virtual bool DoCanFocus();65 virtual bool DoCanFocus();
66 GdkPixbuf* _pixbuf_cached;66 GdkPixbuf* _pixbuf_cached;
6767
68protected:68protected:
69 void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);69 void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
7070
=== modified file 'plugins/unityshell/src/unityshell.cpp'
--- plugins/unityshell/src/unityshell.cpp 2012-04-21 21:32:26 +0000
+++ plugins/unityshell/src/unityshell.cpp 2012-04-23 02:07:20 +0000
@@ -2643,9 +2643,12 @@
2643 launcher_options->icon_size = optionGetIconSize();2643 launcher_options->icon_size = optionGetIconSize();
2644 launcher_options->tile_size = optionGetIconSize() + 6;2644 launcher_options->tile_size = optionGetIconSize() + 6;
26452645
2646 hud_controller_->icon_size = launcher_options->icon_size();
2647 hud_controller_->tile_size = launcher_options->tile_size();
2648
2649 /* The launcher geometry includes 1px used to draw the right margin
2650 * that must not be considered when drawing an overlay */
2646 hud_controller_->launcher_width = launcher_controller_->launcher().GetAbsoluteWidth() - 1;2651 hud_controller_->launcher_width = launcher_controller_->launcher().GetAbsoluteWidth() - 1;
2647 /* The launcher geometry includes 1px used to draw the right margin
2648 * that must not be considered when drawing the dash */
2649 dash_controller_->launcher_width = launcher_controller_->launcher().GetAbsoluteWidth() - 1;2652 dash_controller_->launcher_width = launcher_controller_->launcher().GetAbsoluteWidth() - 1;
26502653
2651 if (p)2654 if (p)
@@ -2838,6 +2841,8 @@
2838 auto hide_mode = (unity::launcher::LauncherHideMode) optionGetLauncherHideMode();2841 auto hide_mode = (unity::launcher::LauncherHideMode) optionGetLauncherHideMode();
2839 hud_controller_->launcher_locked_out = (hide_mode == unity::launcher::LauncherHideMode::LAUNCHER_HIDE_NEVER);2842 hud_controller_->launcher_locked_out = (hide_mode == unity::launcher::LauncherHideMode::LAUNCHER_HIDE_NEVER);
2840 hud_controller_->multiple_launchers = (optionGetNumLaunchers() == 0);2843 hud_controller_->multiple_launchers = (optionGetNumLaunchers() == 0);
2844 hud_controller_->icon_size = launcher_controller_->options()->icon_size();
2845 hud_controller_->tile_size = launcher_controller_->options()->tile_size();
2841 AddChild(hud_controller_.get());2846 AddChild(hud_controller_.get());
2842 LOG_INFO(logger) << "initLauncher-hud " << timer.ElapsedSeconds() << "s";2847 LOG_INFO(logger) << "initLauncher-hud " << timer.ElapsedSeconds() << "s";
28432848