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
1=== modified file 'plugins/unityshell/src/HudController.cpp'
2--- plugins/unityshell/src/HudController.cpp 2012-04-19 03:43:22 +0000
3+++ plugins/unityshell/src/HudController.cpp 2012-04-23 02:07:20 +0000
4@@ -170,6 +170,16 @@
5 }
6 }
7
8+void Controller::SetIcon(std::string const& icon_name)
9+{
10+ LOG_DEBUG(logger) << "setting icon to - " << icon_name;
11+
12+ if (view_)
13+ view_->SetIcon(icon_name, tile_size, icon_size, launcher_width - tile_size);
14+
15+ ubus.SendMessage(UBUS_HUD_ICON_CHANGED, g_variant_new_string(icon_name.c_str()));
16+}
17+
18 nux::BaseWindow* Controller::window() const
19 {
20 return window_;
21@@ -300,7 +310,7 @@
22 {
23 // Windows list stack for all the monitors
24 GList *windows = bamf_matcher_get_window_stack_for_monitor(matcher, -1);
25-
26+
27 // Reset values, in case we can't find a window ie. empty current desktop
28 active_xid = 0;
29 active_win = nullptr;
30@@ -326,6 +336,7 @@
31
32 g_list_free(windows);
33 }
34+
35 BamfApplication* active_app = bamf_matcher_get_application_for_window(matcher, active_win);
36
37 if (BAMF_IS_VIEW(active_app))
38@@ -340,8 +351,7 @@
39 }
40
41 LOG_DEBUG(logger) << "Taking application icon: " << focused_app_icon_;
42- ubus.SendMessage(UBUS_HUD_ICON_CHANGED, g_variant_new_string(focused_app_icon_.c_str()));
43- view_->SetIcon(focused_app_icon_);
44+ SetIcon(focused_app_icon_);
45
46 window_->ShowWindow(true);
47 window_->PushToFront();
48@@ -493,8 +503,7 @@
49 void Controller::OnQuerySelected(Query::Ptr query)
50 {
51 LOG_DEBUG(logger) << "Selected query, " << query->formatted_text;
52- view_->SetIcon(query->icon_name);
53- ubus.SendMessage(UBUS_HUD_ICON_CHANGED, g_variant_new_string(query->icon_name.c_str()));
54+ SetIcon(query->icon_name);
55 }
56
57 void Controller::OnQueriesFinished(Hud::Queries queries)
58@@ -510,9 +519,7 @@
59 }
60 }
61
62- LOG_DEBUG(logger) << "setting icon to - " << icon_name;
63- view_->SetIcon(icon_name);
64- ubus.SendMessage(UBUS_HUD_ICON_CHANGED, g_variant_new_string(icon_name.c_str()));
65+ SetIcon(icon_name);
66 }
67
68 // Introspectable
69
70=== modified file 'plugins/unityshell/src/HudController.h'
71--- plugins/unityshell/src/HudController.h 2012-04-02 00:16:21 +0000
72+++ plugins/unityshell/src/HudController.h 2012-04-23 02:07:20 +0000
73@@ -48,6 +48,8 @@
74 nux::BaseWindow* window() const;
75
76 nux::Property<int> launcher_width;
77+ nux::Property<int> icon_size;
78+ nux::Property<int> tile_size;
79 nux::Property<bool> launcher_locked_out;
80 nux::Property<bool> multiple_launchers;
81
82@@ -65,6 +67,7 @@
83 void SetupWindow();
84 void SetupHudView();
85 void RegisterUBusInterests();
86+ void SetIcon(std::string const& icon_name);
87
88 int GetTargetMonitor();
89 bool IsLockedToLauncher(int monitor);
90
91=== modified file 'plugins/unityshell/src/HudIcon.cpp'
92--- plugins/unityshell/src/HudIcon.cpp 2012-04-03 11:44:41 +0000
93+++ plugins/unityshell/src/HudIcon.cpp 2012-04-23 02:07:20 +0000
94@@ -1,5 +1,5 @@
95 /*
96- * Copyright (C) 2010 Canonical Ltd
97+ * Copyright (C) 2010-2012 Canonical Ltd
98 *
99 * This program is free software: you can redistribute it and/or modify
100 * it under the terms of the GNU General Public License version 3 as
101@@ -14,6 +14,7 @@
102 * along with this program. If not, see <http://www.gnu.org/licenses/>.
103 *
104 * Authored by: Gord Allott <gord.allott@canonical.com>
105+ * Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
106 */
107
108
109@@ -24,8 +25,7 @@
110 namespace
111 {
112 nux::logging::Logger logger("unity.hud.icon");
113- const unsigned int tile_margin = 4;
114- const unsigned int minimum_width = 64;
115+ const unsigned int vertical_padding = 4;
116 }
117
118 namespace unity
119@@ -33,13 +33,9 @@
120 namespace hud
121 {
122
123-Icon::Icon(std::string const& icon_name, unsigned int size)
124- : IconTexture(icon_name, size, true)
125+Icon::Icon()
126+ : IconTexture("", 0, true)
127 {
128- int tile_size = size + tile_margin * 2;
129- SetMinimumWidth(minimum_width);
130- SetMinimumHeight(tile_size);
131- icon_renderer_.SetTargetSize(tile_size, size, 0);
132 background_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_back_54.png", -1, true));
133 gloss_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_shine_54.png", -1, true));
134 edge_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_edge_54.png", -1, true));
135@@ -53,6 +49,14 @@
136 });
137 }
138
139+void Icon::SetIcon(std::string const& icon_name, unsigned int icon_size, unsigned int tile_size)
140+{
141+ IconTexture::SetByIconName(icon_name, icon_size);
142+ icon_renderer_.SetTargetSize(tile_size, icon_size, 0);
143+ SetMinimumWidth(tile_size);
144+ SetMinimumHeight(tile_size + vertical_padding * 2);
145+}
146+
147 void Icon::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
148 {
149 if (texture() == nullptr)
150@@ -63,8 +67,8 @@
151 arg.colorify = nux::color::White;
152 arg.running_arrow = true;
153 arg.running_on_viewport = true;
154- arg.render_center = nux::Point3(32, 32, 0);
155- arg.logical_center = nux::Point3(52, 50, 0);
156+ arg.render_center = nux::Point3(GetMinimumWidth() / 2.0f, GetMinimumHeight() / 2.0f, 0.0f);
157+ arg.logical_center = arg.render_center;
158 arg.window_indicators = true;
159 arg.backlight_intensity = 1.0f;
160 arg.alpha = 1.0f;
161
162=== modified file 'plugins/unityshell/src/HudIcon.h'
163--- plugins/unityshell/src/HudIcon.h 2012-04-01 00:00:45 +0000
164+++ plugins/unityshell/src/HudIcon.h 2012-04-23 02:07:20 +0000
165@@ -34,8 +34,10 @@
166 class Icon : public unity::IconTexture
167 {
168 public:
169- typedef nux::ObjectPtr<IconTexture> Ptr;
170- Icon(std::string const& icon_name, unsigned int size);
171+ typedef nux::ObjectPtr<Icon> Ptr;
172+ Icon();
173+
174+ void SetIcon(std::string const& icon_name, unsigned int icon_size, unsigned int tile_size);
175
176 protected:
177 void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
178
179=== modified file 'plugins/unityshell/src/HudView.cpp'
180--- plugins/unityshell/src/HudView.cpp 2012-04-11 14:57:40 +0000
181+++ plugins/unityshell/src/HudView.cpp 2012-04-23 02:07:20 +0000
182@@ -39,11 +39,10 @@
183 namespace
184 {
185 nux::logging::Logger logger("unity.hud.view");
186-const int icon_size = 46;
187 const int grow_anim_length = 90 * 1000;
188 const int pause_before_grow_length = 32 * 1000;
189
190-const int default_width = 1024;
191+const int default_width = 960;
192 const int default_height = 276;
193 const int content_width = 941;
194
195@@ -126,6 +125,9 @@
196 {
197 RemoveChild((*button).GetPointer());
198 }
199+
200+ if (timeline_id_)
201+ g_source_remove(timeline_id_);
202 }
203
204 void View::ProcessGrowShrink()
205@@ -175,7 +177,7 @@
206
207 void View::Relayout()
208 {
209- nux::Geometry geo = GetGeometry();
210+ nux::Geometry const& geo = GetGeometry();
211 content_geo_ = GetBestFitGeometry(geo);
212 LOG_DEBUG(logger) << "content_geo: " << content_geo_.width << "x" << content_geo_.height;
213
214@@ -267,10 +269,20 @@
215 QueueDraw();
216 }
217
218-void View::SetIcon(std::string icon_name)
219+void View::SetIcon(std::string icon_name, unsigned int tile_size, unsigned int size, unsigned int padding)
220 {
221+ if (!icon_)
222+ return;
223+
224 LOG_DEBUG(logger) << "Setting icon to " << icon_name;
225- icon_->SetByIconName(icon_name, icon_size);
226+
227+ icon_->SetIcon(icon_name, size, tile_size);
228+ icon_->SetMinimumWidth(tile_size + padding);
229+
230+ /* We need to compute this value manually, since the _content_layout height changes */
231+ int content_height = search_bar_->GetBaseHeight() + top_padding + bottom_padding;
232+ icon_->SetMinimumHeight(std::max(icon_->GetMinimumHeight(), content_height));
233+
234 QueueDraw();
235 }
236
237@@ -307,10 +319,8 @@
238 int width = default_width;
239 int height = default_height;
240
241- if (!show_embedded_icon_)
242- {
243- width -= icon_->GetGeometry().width;
244- }
245+ if (show_embedded_icon_)
246+ width += icon_->GetGeometry().width;
247
248 LOG_DEBUG (logger) << "best fit is, " << width << ", " << height;
249
250@@ -343,7 +353,7 @@
251 layout_ = new nux::HLayout();
252 {
253 // fill layout with icon
254- icon_ = new Icon("", icon_size);
255+ icon_ = new Icon();
256 {
257 AddChild(icon_.GetPointer());
258 layout_->AddView(icon_.GetPointer(), 0, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
259@@ -457,7 +467,7 @@
260
261 if (timeline_need_more_draw_ && !timeline_id_)
262 {
263- timeline_id_ = g_timeout_add(0, [] (gpointer data) -> gboolean
264+ timeline_id_ = g_idle_add([] (gpointer data) -> gboolean
265 {
266 View *self = static_cast<View*>(data);
267 self->QueueDraw();
268
269=== modified file 'plugins/unityshell/src/HudView.h'
270--- plugins/unityshell/src/HudView.h 2012-04-02 16:06:18 +0000
271+++ plugins/unityshell/src/HudView.h 2012-04-23 02:07:20 +0000
272@@ -53,7 +53,7 @@
273 nux::View* default_focus() const;
274
275 void SetQueries(Hud::Queries queries);
276- void SetIcon(std::string icon_name);
277+ void SetIcon(std::string icon_name, unsigned int tile_size, unsigned int size, unsigned int padding);
278 void ShowEmbeddedIcon(bool show);
279
280 void AboutToShow();
281@@ -123,4 +123,3 @@
282 }
283 }
284 #endif
285-
286
287=== modified file 'plugins/unityshell/src/IconTexture.cpp'
288--- plugins/unityshell/src/IconTexture.cpp 2012-04-11 01:08:15 +0000
289+++ plugins/unityshell/src/IconTexture.cpp 2012-04-23 02:07:20 +0000
290@@ -46,6 +46,7 @@
291 IconTexture::IconTexture(nux::BaseTexture* texture, guint width, guint height)
292 : TextureArea(NUX_TRACKER_LOCATION),
293 _accept_key_nav_focus(false),
294+ _pixbuf_cached(nullptr),
295 _size(height),
296 _texture_cached(texture),
297 _texture_width(width),
298@@ -60,6 +61,7 @@
299 IconTexture::IconTexture(std::string const& icon_name, unsigned int size, bool defer_icon_loading)
300 : TextureArea(NUX_TRACKER_LOCATION),
301 _accept_key_nav_focus(false),
302+ _pixbuf_cached(nullptr),
303 _icon_name(!icon_name.empty() ? icon_name : DEFAULT_ICON),
304 _size(size),
305 _texture_width(0),
306@@ -167,6 +169,7 @@
307 }
308 else
309 {
310+ _pixbuf_cached = nullptr;
311 _loading = false;
312
313 // Protects against a missing default icon, we only request it if icon_name
314
315=== modified file 'plugins/unityshell/src/IconTexture.h'
316--- plugins/unityshell/src/IconTexture.h 2012-04-11 00:57:41 +0000
317+++ plugins/unityshell/src/IconTexture.h 2012-04-23 02:07:20 +0000
318@@ -63,7 +63,7 @@
319 std::string GetName() const;
320 void AddProperties(GVariantBuilder* builder);
321 virtual bool DoCanFocus();
322- GdkPixbuf* _pixbuf_cached;
323+ GdkPixbuf* _pixbuf_cached;
324
325 protected:
326 void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
327
328=== modified file 'plugins/unityshell/src/unityshell.cpp'
329--- plugins/unityshell/src/unityshell.cpp 2012-04-21 21:32:26 +0000
330+++ plugins/unityshell/src/unityshell.cpp 2012-04-23 02:07:20 +0000
331@@ -2643,9 +2643,12 @@
332 launcher_options->icon_size = optionGetIconSize();
333 launcher_options->tile_size = optionGetIconSize() + 6;
334
335+ hud_controller_->icon_size = launcher_options->icon_size();
336+ hud_controller_->tile_size = launcher_options->tile_size();
337+
338+ /* The launcher geometry includes 1px used to draw the right margin
339+ * that must not be considered when drawing an overlay */
340 hud_controller_->launcher_width = launcher_controller_->launcher().GetAbsoluteWidth() - 1;
341- /* The launcher geometry includes 1px used to draw the right margin
342- * that must not be considered when drawing the dash */
343 dash_controller_->launcher_width = launcher_controller_->launcher().GetAbsoluteWidth() - 1;
344
345 if (p)
346@@ -2838,6 +2841,8 @@
347 auto hide_mode = (unity::launcher::LauncherHideMode) optionGetLauncherHideMode();
348 hud_controller_->launcher_locked_out = (hide_mode == unity::launcher::LauncherHideMode::LAUNCHER_HIDE_NEVER);
349 hud_controller_->multiple_launchers = (optionGetNumLaunchers() == 0);
350+ hud_controller_->icon_size = launcher_controller_->options()->icon_size();
351+ hud_controller_->tile_size = launcher_controller_->options()->tile_size();
352 AddChild(hud_controller_.get());
353 LOG_INFO(logger) << "initLauncher-hud " << timer.ElapsedSeconds() << "s";
354