Merge lp:~canonical-dx-team/unity/unity.fix-646712 into lp:unity

Proposed by Mirco Müller
Status: Merged
Merged at revision: 885
Proposed branch: lp:~canonical-dx-team/unity/unity.fix-646712
Merge into: lp:unity
Diff against target: 352 lines (+222/-2)
4 files modified
src/Launcher.cpp (+177/-1)
src/Launcher.h (+20/-1)
src/LauncherIcon.cpp (+22/-0)
src/LauncherIcon.h (+3/-0)
To merge this branch: bzr merge lp:~canonical-dx-team/unity/unity.fix-646712
Reviewer Review Type Date Requested Status
Didier Roche-Tolomelli Approve
Review via email: mp+50899@code.launchpad.net

Description of the change

This branch makes the superkey-overlays show up on the launcher, if the Super-key is held down. The first 10 icons get labels and trash-can and workspace-switcher get special labels.

To post a comment you must log in.
Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

160 + if (_super_show_launcher)
(and following)… Can you please avoid by any mean to hardcode the keys?
The places can set dynamic values in their .place file for that for instance, so it won't scale. We will probably change the "t" and "w" shortcut as well. So having them in one place is better.

if you go over the model, I think you can get both the index and the shortcut.

review: Needs Fixing
Revision history for this message
Mirco Müller (macslow) wrote :

I didn't know about the dynamic-mapping for trashcan, workspaces-switcher and places.

Revision history for this message
Mirco Müller (macslow) wrote :

Fixed

Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

Approved!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Launcher.cpp'
--- src/Launcher.cpp 2011-02-23 12:20:41 +0000
+++ src/Launcher.cpp 2011-02-24 09:32:15 +0000
@@ -292,6 +292,10 @@
292 _arrow_rtl = nux::CreateTexture2DFromFile (PKGDATADIR"/launcher_arrow_rtl.png", -1, true);292 _arrow_rtl = nux::CreateTexture2DFromFile (PKGDATADIR"/launcher_arrow_rtl.png", -1, true);
293 _arrow_empty_rtl = nux::CreateTexture2DFromFile (PKGDATADIR"/launcher_arrow_outline_rtl.png", -1, true);293 _arrow_empty_rtl = nux::CreateTexture2DFromFile (PKGDATADIR"/launcher_arrow_outline_rtl.png", -1, true);
294294
295 for (int i = 0; i < MAX_SUPERKEY_LABELS - 1; i++)
296 _superkey_labels[i] = cairoToTexture2D ((char) ('1' + i), LAUNCHER_ICON_SIZE, LAUNCHER_ICON_SIZE);
297 _superkey_labels[9] = cairoToTexture2D ((char) ('0'), LAUNCHER_ICON_SIZE, LAUNCHER_ICON_SIZE);
298
295 _enter_y = 0;299 _enter_y = 0;
296 _dnd_security = 15;300 _dnd_security = 15;
297 _launcher_drag_delta = 0;301 _launcher_drag_delta = 0;
@@ -351,7 +355,11 @@
351355
352Launcher::~Launcher()356Launcher::~Launcher()
353{357{
354358 for (int i = 0; i < MAX_SUPERKEY_LABELS; i++)
359 {
360 if (_superkey_labels[i])
361 _superkey_labels[i]->UnReference ();
362 }
355}363}
356364
357/* Introspection */365/* Introspection */
@@ -362,6 +370,120 @@
362}370}
363371
364void372void
373Launcher::DrawRoundedRectangle (cairo_t* cr,
374 double aspect,
375 double x,
376 double y,
377 double cornerRadius,
378 double width,
379 double height)
380{
381 double radius = cornerRadius / aspect;
382
383 // top-left, right of the corner
384 cairo_move_to (cr, x + radius, y);
385
386 // top-right, left of the corner
387 cairo_line_to (cr, x + width - radius, y);
388
389 // top-right, below the corner
390 cairo_arc (cr,
391 x + width - radius,
392 y + radius,
393 radius,
394 -90.0f * G_PI / 180.0f,
395 0.0f * G_PI / 180.0f);
396
397 // bottom-right, above the corner
398 cairo_line_to (cr, x + width, y + height - radius);
399
400 // bottom-right, left of the corner
401 cairo_arc (cr,
402 x + width - radius,
403 y + height - radius,
404 radius,
405 0.0f * G_PI / 180.0f,
406 90.0f * G_PI / 180.0f);
407
408 // bottom-left, right of the corner
409 cairo_line_to (cr, x + radius, y + height);
410
411 // bottom-left, above the corner
412 cairo_arc (cr,
413 x + radius,
414 y + height - radius,
415 radius,
416 90.0f * G_PI / 180.0f,
417 180.0f * G_PI / 180.0f);
418
419 // top-left, right of the corner
420 cairo_arc (cr,
421 x + radius,
422 y + radius,
423 radius,
424 180.0f * G_PI / 180.0f,
425 270.0f * G_PI / 180.0f);
426}
427
428nux::BaseTexture*
429Launcher::cairoToTexture2D (const char label, int width, int height)
430{
431 nux::BaseTexture* texture = NULL;
432 nux::CairoGraphics* cg = new nux::CairoGraphics (CAIRO_FORMAT_ARGB32,
433 width,
434 height);
435 cairo_t* cr = cg->GetContext ();
436 PangoLayout* layout = NULL;
437 PangoContext* pangoCtx = NULL;
438 PangoFontDescription* desc = NULL;
439 GtkSettings* settings = gtk_settings_get_default (); // not ref'ed
440 gchar* fontName = NULL;
441 double label_x = 18.0f;
442 double label_y = 18.0f;
443 double label_w = 18.0f;
444 double label_h = 18.0f;
445 double label_r = 3.0f;
446
447 cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
448 cairo_paint (cr);
449 cairo_scale (cr, 1.0f, 1.0f);
450 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
451 DrawRoundedRectangle (cr, 1.0f, label_x, label_y, label_r, label_w, label_h);
452 cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.65f);
453 cairo_fill (cr);
454
455 layout = pango_cairo_create_layout (cr);
456 g_object_get (settings, "gtk-font-name", &fontName, NULL);
457 desc = pango_font_description_from_string (fontName);
458 pango_font_description_set_size (desc, 11 * PANGO_SCALE);
459 pango_layout_set_font_description (layout, desc);
460 pango_layout_set_text (layout, &label, 1);
461 pangoCtx = pango_layout_get_context (layout); // is not ref'ed
462
463 PangoRectangle logRect;
464 PangoRectangle inkRect;
465 pango_layout_get_extents (layout, &inkRect, &logRect);
466
467 /* position and paint text */
468 cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f);
469 double x = label_x - ((logRect.width / PANGO_SCALE) - label_w) / 2.0f;
470 double y = label_y - ((logRect.height / PANGO_SCALE) - label_h) / 2.0f - 1;
471 cairo_move_to (cr, x, y);
472 pango_cairo_show_layout (cr, layout);
473
474 nux::NBitmapData* bitmap = cg->GetBitmap ();
475 texture = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture ();
476 texture->Update (bitmap);
477 delete bitmap;
478 delete cg;
479 g_object_unref (layout);
480 pango_font_description_free (desc);
481 g_free (fontName);
482
483 return texture;
484}
485
486void
365Launcher::startKeyNavMode ()487Launcher::startKeyNavMode ()
366{488{
367 _navmod_show_launcher = true;489 _navmod_show_launcher = true;
@@ -1184,6 +1306,7 @@
1184void Launcher::StartKeyShowLauncher ()1306void Launcher::StartKeyShowLauncher ()
1185{1307{
1186 _super_show_launcher = true;1308 _super_show_launcher = true;
1309 QueueDraw ();
1187 SetTimeStruct (&_times[TIME_TAP_SUPER], NULL, ANIM_DURATION_SHORT);1310 SetTimeStruct (&_times[TIME_TAP_SUPER], NULL, ANIM_DURATION_SHORT);
1188 EnsureHiddenState ();1311 EnsureHiddenState ();
1189}1312}
@@ -1194,6 +1317,7 @@
1194 clock_gettime (CLOCK_MONOTONIC, &current); 1317 clock_gettime (CLOCK_MONOTONIC, &current);
11951318
1196 _super_show_launcher = false;1319 _super_show_launcher = false;
1320 QueueDraw ();
11971321
1198 // it's a tap on super1322 // it's a tap on super
1199 if (TimeDelta (&current, &_times[TIME_TAP_SUPER]) < ANIM_DURATION_SHORT)1323 if (TimeDelta (&current, &_times[TIME_TAP_SUPER]) < ANIM_DURATION_SHORT)
@@ -1682,6 +1806,10 @@
1682 // needs to be disconnected1806 // needs to be disconnected
1683 icon->needs_redraw.connect (sigc::mem_fun(this, &Launcher::OnIconNeedsRedraw));1807 icon->needs_redraw.connect (sigc::mem_fun(this, &Launcher::OnIconNeedsRedraw));
16841808
1809 guint64 shortcut = icon->GetShortcut ();
1810 if (shortcut != 0 && !g_ascii_isdigit ((gchar) shortcut))
1811 icon->SetSuperkeyLabel (cairoToTexture2D ((gchar) shortcut, LAUNCHER_ICON_SIZE, LAUNCHER_ICON_SIZE));
1812
1685 AddChild (icon);1813 AddChild (icon);
1686}1814}
16871815
@@ -2090,6 +2218,51 @@
2090 nux::Color (0xFFFFFFFF),2218 nux::Color (0xFFFFFFFF),
2091 arg.alpha,2219 arg.alpha,
2092 arg.icon->_xform_coords["Glow"]);2220 arg.icon->_xform_coords["Glow"]);
2221
2222 /* draw superkey-shortcut label */
2223 if (_super_show_launcher)
2224 {
2225 guint64 shortcut = arg.icon->GetShortcut ();
2226
2227 /* deal with dynamic labels for places, which can be set via the locale */
2228 if (shortcut != 0 && !g_ascii_isdigit ((gchar) shortcut))
2229 {
2230 RenderIcon (GfxContext,
2231 arg,
2232 arg.icon->GetSuperkeyLabel ()->GetDeviceTexture (),
2233 nux::Color (0xFFFFFFFF),
2234 arg.alpha,
2235 arg.icon->_xform_coords["Tile"]);
2236 }
2237 else
2238 {
2239 /* deal with the hardcoded labels used for the first 10 icons on the launcher */
2240 gchar key = (gchar) shortcut;
2241 int index = -1;
2242
2243 switch (key)
2244 {
2245 case '1': index = 0; break;
2246 case '2': index = 1; break;
2247 case '3': index = 2; break;
2248 case '4': index = 3; break;
2249 case '5': index = 4; break;
2250 case '6': index = 5; break;
2251 case '7': index = 6; break;
2252 case '8': index = 7; break;
2253 case '9': index = 8; break;
2254 case '0': index = 9; break;
2255 }
2256
2257 if (index != -1)
2258 RenderIcon (GfxContext,
2259 arg,
2260 _superkey_labels[index]->GetDeviceTexture (),
2261 nux::Color (0xFFFFFFFF),
2262 arg.alpha,
2263 arg.icon->_xform_coords["Tile"]);
2264 }
2265 }
2093}2266}
20942267
2095void Launcher::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)2268void Launcher::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
@@ -2426,7 +2599,10 @@
2426 unsigned long key_state)2599 unsigned long key_state)
2427{2600{
2428 if (_super_show_launcher)2601 if (_super_show_launcher)
2602 {
2429 RecvKeyPressed (key_sym, key_code, key_state);2603 RecvKeyPressed (key_sym, key_code, key_state);
2604 QueueDraw ();
2605 }
2430}2606}
24312607
2432void2608void
24332609
=== modified file 'src/Launcher.h'
--- src/Launcher.h 2011-02-23 11:18:17 +0000
+++ src/Launcher.h 2011-02-24 09:32:15 +0000
@@ -38,6 +38,9 @@
38#define ANIM_DURATION 20038#define ANIM_DURATION 200
39#define ANIM_DURATION_LONG 35039#define ANIM_DURATION_LONG 350
4040
41#define MAX_SUPERKEY_LABELS 10
42#define LAUNCHER_ICON_SIZE 54
43
41class LauncherModel;44class LauncherModel;
42class QuicklistView;45class QuicklistView;
43class LauncherIcon;46class LauncherIcon;
@@ -341,7 +344,21 @@
341344
342 void SetOffscreenRenderTarget (nux::IntrusiveSP<nux::IOpenGLBaseTexture> texture);345 void SetOffscreenRenderTarget (nux::IntrusiveSP<nux::IOpenGLBaseTexture> texture);
343 void RestoreSystemRenderTarget ();346 void RestoreSystemRenderTarget ();
344 347
348 void
349 DrawRoundedRectangle (cairo_t* cr,
350 double aspect,
351 double x,
352 double y,
353 double cornerRadius,
354 double width,
355 double height);
356
357 nux::BaseTexture*
358 cairoToTexture2D (const char label,
359 int width,
360 int height);
361
345 std::list<char *> StringToUriList (char * input);362 std::list<char *> StringToUriList (char * input);
346363
347 nux::HLayout* m_Layout;364 nux::HLayout* m_Layout;
@@ -421,6 +438,8 @@
421 nux::BaseTexture* _arrow_empty_ltr;438 nux::BaseTexture* _arrow_empty_ltr;
422 nux::BaseTexture* _arrow_empty_rtl;439 nux::BaseTexture* _arrow_empty_rtl;
423440
441 nux::BaseTexture* _superkey_labels[MAX_SUPERKEY_LABELS];
442
424 nux::IntrusiveSP<nux::IOpenGLBaseTexture> _offscreen_drag_texture;443 nux::IntrusiveSP<nux::IOpenGLBaseTexture> _offscreen_drag_texture;
425 nux::IntrusiveSP<nux::IOpenGLBaseTexture> _offscreen_progress_texture;444 nux::IntrusiveSP<nux::IOpenGLBaseTexture> _offscreen_progress_texture;
426445
427446
=== modified file 'src/LauncherIcon.cpp'
--- src/LauncherIcon.cpp 2011-02-23 10:21:23 +0000
+++ src/LauncherIcon.cpp 2011-02-24 09:32:15 +0000
@@ -73,6 +73,7 @@
73 _shortcut = 0;73 _shortcut = 0;
74 74
75 _emblem = 0;75 _emblem = 0;
76 _superkey_label = 0;
7677
77 _quicklist = new QuicklistView ();78 _quicklist = new QuicklistView ();
78 _quicklist_is_initialized = false;79 _quicklist_is_initialized = false;
@@ -106,6 +107,9 @@
106 if (_center_stabilize_handle)107 if (_center_stabilize_handle)
107 g_source_remove (_center_stabilize_handle);108 g_source_remove (_center_stabilize_handle);
108 _center_stabilize_handle = 0;109 _center_stabilize_handle = 0;
110
111 if (_superkey_label)
112 _superkey_label->UnReference ();
109}113}
110114
111bool115bool
@@ -688,6 +692,24 @@
688 needs_redraw.emit (this);692 needs_redraw.emit (this);
689}693}
690694
695void
696LauncherIcon::SetSuperkeyLabel (nux::BaseTexture* label)
697{
698 if (_superkey_label == label)
699 return;
700
701 if (_superkey_label)
702 _superkey_label->UnReference ();
703
704 _superkey_label = label;
705}
706
707nux::BaseTexture*
708LauncherIcon::GetSuperkeyLabel ()
709{
710 return _superkey_label;
711}
712
691void 713void
692LauncherIcon::SetEmblemIconName (const char *name)714LauncherIcon::SetEmblemIconName (const char *name)
693{715{
694716
=== modified file 'src/LauncherIcon.h'
--- src/LauncherIcon.h 2011-02-22 17:05:31 +0000
+++ src/LauncherIcon.h 2011-02-24 09:32:15 +0000
@@ -176,6 +176,8 @@
176 void SetSortPriority (int priority);176 void SetSortPriority (int priority);
177177
178 void SetEmblem (nux::BaseTexture *emblem);178 void SetEmblem (nux::BaseTexture *emblem);
179 void SetSuperkeyLabel (nux::BaseTexture* label);
180 nux::BaseTexture* GetSuperkeyLabel ();
179181
180 virtual std::list<DbusmenuMenuitem *> GetMenus ();182 virtual std::list<DbusmenuMenuitem *> GetMenus ();
181 virtual nux::BaseTexture * GetTextureForSize (int size) = 0;183 virtual nux::BaseTexture * GetTextureForSize (int size) = 0;
@@ -258,6 +260,7 @@
258 IconType _icon_type;260 IconType _icon_type;
259 261
260 nux::BaseTexture* _emblem;262 nux::BaseTexture* _emblem;
263 nux::BaseTexture* _superkey_label;
261 264
262 bool _quirks[QUIRK_LAST];265 bool _quirks[QUIRK_LAST];
263 struct timespec _quirk_times[QUIRK_LAST];266 struct timespec _quirk_times[QUIRK_LAST];