Merge lp:~mhr3/unity/respect-icon-size-hint into lp:unity

Proposed by Michal Hruby
Status: Merged
Approved by: Michal Hruby
Approved revision: no longer in the source branch.
Merged at revision: 2820
Proposed branch: lp:~mhr3/unity/respect-icon-size-hint
Merge into: lp:unity
Diff against target: 82 lines (+38/-10)
1 file modified
unity-shared/IconLoader.cpp (+38/-10)
To merge this branch: bzr merge lp:~mhr3/unity/respect-icon-size-hint
Reviewer Review Type Date Requested Status
Nick Dedekind (community) Approve
jenkins continuous-integration Pending
Review via email: mp+128899@code.launchpad.net

Commit message

Respect use-small-icon hint set on UnityProtocolAnnotatedIcon

Description of the change

Respect icon size hint set on UnityProtocolAnnotatedIcon - if the hint is set, the icon will be rendered at 2/3 of the requested size, yet the ribbon will be painted at full size of the icon.

To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :

Screenshot of how apps lens' "More suggestions" will look like with this: http://ubuntuone.com/2fUNZHBaOlK2eoJ22porzK

Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

Code-wise, looks ok; and even though it's a pretty nasty hack, I don't see any other way around it.

But on a side note:

I was under the impression that using libunity private is strictly limited to UnityCore? In which case this class should be moved there.

struct IconLoaderTask

This should be a class, not a struct. And it's starting to get confusing with members vs locals. From the diff it doesn't look like this should compile because you changed the max_width to base_max_width, but are still using max_width in the function. Members should have trailing '_'. I realise it's not part of the bug, but it could definitely use an code refactor.

review: Approve
Revision history for this message
Michal Hruby (mhr3) wrote :

+1 on the need of refactoring IconLoader*, but since this is intended for 6.0 series too, let's keep it simple so far.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'unity-shared/IconLoader.cpp'
--- unity-shared/IconLoader.cpp 2012-09-28 08:30:15 +0000
+++ unity-shared/IconLoader.cpp 2012-10-10 10:30:27 +0000
@@ -212,15 +212,27 @@
212212
213 if (icon.IsType(UNITY_PROTOCOL_TYPE_ANNOTATED_ICON))213 if (icon.IsType(UNITY_PROTOCOL_TYPE_ANNOTATED_ICON))
214 {214 {
215 UnityProtocolAnnotatedIcon *anno;215 glib::Object<UnityProtocolAnnotatedIcon> anno(glib::object_cast<UnityProtocolAnnotatedIcon>(icon));
216 anno = UNITY_PROTOCOL_ANNOTATED_ICON(icon.RawPtr());
217 GIcon* base_icon = unity_protocol_annotated_icon_get_icon(anno);216 GIcon* base_icon = unity_protocol_annotated_icon_get_icon(anno);
218 glib::String gicon_string(g_icon_to_string(base_icon));217 glib::String gicon_string(g_icon_to_string(base_icon));
219218
219 // ensure that annotated icons aren't cached by the IconLoader
220 no_cache = true;220 no_cache = true;
221 auto helper_slot = sigc::bind(sigc::mem_fun(this, &IconLoaderTask::BaseIconLoaded), glib::object_cast<UnityProtocolAnnotatedIcon>(icon));221
222 int base_icon_width = max_width > 0 ? max_width - RIBBON_PADDING * 2 : -1;222 auto helper_slot = sigc::bind(sigc::mem_fun(this, &IconLoaderTask::BaseIconLoaded), anno);
223 int base_icon_height = base_icon_width < 0 ? max_height - RIBBON_PADDING *2 : max_height;223 int base_icon_width, base_icon_height;
224 if (unity_protocol_annotated_icon_get_use_small_icon(anno))
225 {
226 // FIXME: although this pretends to be generic, we're just making
227 // sure that icons requested to have 96px will be 64
228 base_icon_width = max_width > 0 ? max_width * 2 / 3 : max_width;
229 base_icon_height = max_height > 0 ? max_height * 2 / 3 : max_height;
230 }
231 else
232 {
233 base_icon_width = max_width > 0 ? max_width - RIBBON_PADDING * 2 : -1;
234 base_icon_height = base_icon_width < 0 ? max_height - RIBBON_PADDING *2 : max_height;
235 }
224 helper_handle = impl->LoadFromGIconString(gicon_string.Str(),236 helper_handle = impl->LoadFromGIconString(gicon_string.Str(),
225 base_icon_width,237 base_icon_width,
226 base_icon_height,238 base_icon_height,
@@ -518,7 +530,7 @@
518 }530 }
519531
520 void BaseIconLoaded(std::string const& base_icon_string,532 void BaseIconLoaded(std::string const& base_icon_string,
521 int max_width, int max_height,533 int base_max_width, int base_max_height,
522 glib::Object<GdkPixbuf> const& base_pixbuf,534 glib::Object<GdkPixbuf> const& base_pixbuf,
523 glib::Object<UnityProtocolAnnotatedIcon> const& anno_icon)535 glib::Object<UnityProtocolAnnotatedIcon> const& anno_icon)
524 {536 {
@@ -529,16 +541,32 @@
529 "' size: " << gdk_pixbuf_get_width(base_pixbuf) << 'x' <<541 "' size: " << gdk_pixbuf_get_width(base_pixbuf) << 'x' <<
530 gdk_pixbuf_get_height(base_pixbuf);542 gdk_pixbuf_get_height(base_pixbuf);
531543
544 int result_width, result_height, dest_x, dest_y;
545 if (unity_protocol_annotated_icon_get_use_small_icon(anno_icon))
546 {
547 result_width = max_width > 0 ? max_width : MAX(max_height, gdk_pixbuf_get_width(base_pixbuf));
548 result_height = max_height > 0 ? max_height : MAX(max_width, gdk_pixbuf_get_height(base_pixbuf));
549
550 dest_x = (result_width - gdk_pixbuf_get_width(base_pixbuf)) / 2;
551 dest_y = (result_height - gdk_pixbuf_get_height(base_pixbuf)) / 2;
552 }
553 else
554 {
555 result_width = gdk_pixbuf_get_width(base_pixbuf) + RIBBON_PADDING * 2;
556 result_height = gdk_pixbuf_get_height(base_pixbuf);
557
558 dest_x = RIBBON_PADDING;
559 dest_y = 0;
560 }
532 // we need extra space for the ribbon561 // we need extra space for the ribbon
533 result = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 562 result = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8,
534 gdk_pixbuf_get_width(base_pixbuf) + RIBBON_PADDING * 2,563 result_width, result_height);
535 gdk_pixbuf_get_height(base_pixbuf));
536 gdk_pixbuf_fill(result, 0x0);564 gdk_pixbuf_fill(result, 0x0);
537 gdk_pixbuf_copy_area(base_pixbuf, 0, 0,565 gdk_pixbuf_copy_area(base_pixbuf, 0, 0,
538 gdk_pixbuf_get_width(base_pixbuf),566 gdk_pixbuf_get_width(base_pixbuf),
539 gdk_pixbuf_get_height(base_pixbuf),567 gdk_pixbuf_get_height(base_pixbuf),
540 result,568 result,
541 RIBBON_PADDING, 0);569 dest_x, dest_y);
542 // FIXME: can we composite the pixbuf in helper thread?570 // FIXME: can we composite the pixbuf in helper thread?
543 UnityProtocolCategoryType category = unity_protocol_annotated_icon_get_category(anno_icon);571 UnityProtocolCategoryType category = unity_protocol_annotated_icon_get_category(anno_icon);
544 auto helper_slot = sigc::bind(sigc::mem_fun(this, &IconLoaderTask::CategoryIconLoaded), anno_icon);572 auto helper_slot = sigc::bind(sigc::mem_fun(this, &IconLoaderTask::CategoryIconLoaded), anno_icon);