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
1=== modified file 'src/Launcher.cpp'
2--- src/Launcher.cpp 2011-02-23 12:20:41 +0000
3+++ src/Launcher.cpp 2011-02-24 09:32:15 +0000
4@@ -292,6 +292,10 @@
5 _arrow_rtl = nux::CreateTexture2DFromFile (PKGDATADIR"/launcher_arrow_rtl.png", -1, true);
6 _arrow_empty_rtl = nux::CreateTexture2DFromFile (PKGDATADIR"/launcher_arrow_outline_rtl.png", -1, true);
7
8+ for (int i = 0; i < MAX_SUPERKEY_LABELS - 1; i++)
9+ _superkey_labels[i] = cairoToTexture2D ((char) ('1' + i), LAUNCHER_ICON_SIZE, LAUNCHER_ICON_SIZE);
10+ _superkey_labels[9] = cairoToTexture2D ((char) ('0'), LAUNCHER_ICON_SIZE, LAUNCHER_ICON_SIZE);
11+
12 _enter_y = 0;
13 _dnd_security = 15;
14 _launcher_drag_delta = 0;
15@@ -351,7 +355,11 @@
16
17 Launcher::~Launcher()
18 {
19-
20+ for (int i = 0; i < MAX_SUPERKEY_LABELS; i++)
21+ {
22+ if (_superkey_labels[i])
23+ _superkey_labels[i]->UnReference ();
24+ }
25 }
26
27 /* Introspection */
28@@ -362,6 +370,120 @@
29 }
30
31 void
32+Launcher::DrawRoundedRectangle (cairo_t* cr,
33+ double aspect,
34+ double x,
35+ double y,
36+ double cornerRadius,
37+ double width,
38+ double height)
39+{
40+ double radius = cornerRadius / aspect;
41+
42+ // top-left, right of the corner
43+ cairo_move_to (cr, x + radius, y);
44+
45+ // top-right, left of the corner
46+ cairo_line_to (cr, x + width - radius, y);
47+
48+ // top-right, below the corner
49+ cairo_arc (cr,
50+ x + width - radius,
51+ y + radius,
52+ radius,
53+ -90.0f * G_PI / 180.0f,
54+ 0.0f * G_PI / 180.0f);
55+
56+ // bottom-right, above the corner
57+ cairo_line_to (cr, x + width, y + height - radius);
58+
59+ // bottom-right, left of the corner
60+ cairo_arc (cr,
61+ x + width - radius,
62+ y + height - radius,
63+ radius,
64+ 0.0f * G_PI / 180.0f,
65+ 90.0f * G_PI / 180.0f);
66+
67+ // bottom-left, right of the corner
68+ cairo_line_to (cr, x + radius, y + height);
69+
70+ // bottom-left, above the corner
71+ cairo_arc (cr,
72+ x + radius,
73+ y + height - radius,
74+ radius,
75+ 90.0f * G_PI / 180.0f,
76+ 180.0f * G_PI / 180.0f);
77+
78+ // top-left, right of the corner
79+ cairo_arc (cr,
80+ x + radius,
81+ y + radius,
82+ radius,
83+ 180.0f * G_PI / 180.0f,
84+ 270.0f * G_PI / 180.0f);
85+}
86+
87+nux::BaseTexture*
88+Launcher::cairoToTexture2D (const char label, int width, int height)
89+{
90+ nux::BaseTexture* texture = NULL;
91+ nux::CairoGraphics* cg = new nux::CairoGraphics (CAIRO_FORMAT_ARGB32,
92+ width,
93+ height);
94+ cairo_t* cr = cg->GetContext ();
95+ PangoLayout* layout = NULL;
96+ PangoContext* pangoCtx = NULL;
97+ PangoFontDescription* desc = NULL;
98+ GtkSettings* settings = gtk_settings_get_default (); // not ref'ed
99+ gchar* fontName = NULL;
100+ double label_x = 18.0f;
101+ double label_y = 18.0f;
102+ double label_w = 18.0f;
103+ double label_h = 18.0f;
104+ double label_r = 3.0f;
105+
106+ cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
107+ cairo_paint (cr);
108+ cairo_scale (cr, 1.0f, 1.0f);
109+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
110+ DrawRoundedRectangle (cr, 1.0f, label_x, label_y, label_r, label_w, label_h);
111+ cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.65f);
112+ cairo_fill (cr);
113+
114+ layout = pango_cairo_create_layout (cr);
115+ g_object_get (settings, "gtk-font-name", &fontName, NULL);
116+ desc = pango_font_description_from_string (fontName);
117+ pango_font_description_set_size (desc, 11 * PANGO_SCALE);
118+ pango_layout_set_font_description (layout, desc);
119+ pango_layout_set_text (layout, &label, 1);
120+ pangoCtx = pango_layout_get_context (layout); // is not ref'ed
121+
122+ PangoRectangle logRect;
123+ PangoRectangle inkRect;
124+ pango_layout_get_extents (layout, &inkRect, &logRect);
125+
126+ /* position and paint text */
127+ cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f);
128+ double x = label_x - ((logRect.width / PANGO_SCALE) - label_w) / 2.0f;
129+ double y = label_y - ((logRect.height / PANGO_SCALE) - label_h) / 2.0f - 1;
130+ cairo_move_to (cr, x, y);
131+ pango_cairo_show_layout (cr, layout);
132+
133+ nux::NBitmapData* bitmap = cg->GetBitmap ();
134+ texture = nux::GetThreadGLDeviceFactory()->CreateSystemCapableTexture ();
135+ texture->Update (bitmap);
136+ delete bitmap;
137+ delete cg;
138+ g_object_unref (layout);
139+ pango_font_description_free (desc);
140+ g_free (fontName);
141+
142+ return texture;
143+}
144+
145+void
146 Launcher::startKeyNavMode ()
147 {
148 _navmod_show_launcher = true;
149@@ -1184,6 +1306,7 @@
150 void Launcher::StartKeyShowLauncher ()
151 {
152 _super_show_launcher = true;
153+ QueueDraw ();
154 SetTimeStruct (&_times[TIME_TAP_SUPER], NULL, ANIM_DURATION_SHORT);
155 EnsureHiddenState ();
156 }
157@@ -1194,6 +1317,7 @@
158 clock_gettime (CLOCK_MONOTONIC, &current);
159
160 _super_show_launcher = false;
161+ QueueDraw ();
162
163 // it's a tap on super
164 if (TimeDelta (&current, &_times[TIME_TAP_SUPER]) < ANIM_DURATION_SHORT)
165@@ -1682,6 +1806,10 @@
166 // needs to be disconnected
167 icon->needs_redraw.connect (sigc::mem_fun(this, &Launcher::OnIconNeedsRedraw));
168
169+ guint64 shortcut = icon->GetShortcut ();
170+ if (shortcut != 0 && !g_ascii_isdigit ((gchar) shortcut))
171+ icon->SetSuperkeyLabel (cairoToTexture2D ((gchar) shortcut, LAUNCHER_ICON_SIZE, LAUNCHER_ICON_SIZE));
172+
173 AddChild (icon);
174 }
175
176@@ -2090,6 +2218,51 @@
177 nux::Color (0xFFFFFFFF),
178 arg.alpha,
179 arg.icon->_xform_coords["Glow"]);
180+
181+ /* draw superkey-shortcut label */
182+ if (_super_show_launcher)
183+ {
184+ guint64 shortcut = arg.icon->GetShortcut ();
185+
186+ /* deal with dynamic labels for places, which can be set via the locale */
187+ if (shortcut != 0 && !g_ascii_isdigit ((gchar) shortcut))
188+ {
189+ RenderIcon (GfxContext,
190+ arg,
191+ arg.icon->GetSuperkeyLabel ()->GetDeviceTexture (),
192+ nux::Color (0xFFFFFFFF),
193+ arg.alpha,
194+ arg.icon->_xform_coords["Tile"]);
195+ }
196+ else
197+ {
198+ /* deal with the hardcoded labels used for the first 10 icons on the launcher */
199+ gchar key = (gchar) shortcut;
200+ int index = -1;
201+
202+ switch (key)
203+ {
204+ case '1': index = 0; break;
205+ case '2': index = 1; break;
206+ case '3': index = 2; break;
207+ case '4': index = 3; break;
208+ case '5': index = 4; break;
209+ case '6': index = 5; break;
210+ case '7': index = 6; break;
211+ case '8': index = 7; break;
212+ case '9': index = 8; break;
213+ case '0': index = 9; break;
214+ }
215+
216+ if (index != -1)
217+ RenderIcon (GfxContext,
218+ arg,
219+ _superkey_labels[index]->GetDeviceTexture (),
220+ nux::Color (0xFFFFFFFF),
221+ arg.alpha,
222+ arg.icon->_xform_coords["Tile"]);
223+ }
224+ }
225 }
226
227 void Launcher::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
228@@ -2426,7 +2599,10 @@
229 unsigned long key_state)
230 {
231 if (_super_show_launcher)
232+ {
233 RecvKeyPressed (key_sym, key_code, key_state);
234+ QueueDraw ();
235+ }
236 }
237
238 void
239
240=== modified file 'src/Launcher.h'
241--- src/Launcher.h 2011-02-23 11:18:17 +0000
242+++ src/Launcher.h 2011-02-24 09:32:15 +0000
243@@ -38,6 +38,9 @@
244 #define ANIM_DURATION 200
245 #define ANIM_DURATION_LONG 350
246
247+#define MAX_SUPERKEY_LABELS 10
248+#define LAUNCHER_ICON_SIZE 54
249+
250 class LauncherModel;
251 class QuicklistView;
252 class LauncherIcon;
253@@ -341,7 +344,21 @@
254
255 void SetOffscreenRenderTarget (nux::IntrusiveSP<nux::IOpenGLBaseTexture> texture);
256 void RestoreSystemRenderTarget ();
257-
258+
259+ void
260+ DrawRoundedRectangle (cairo_t* cr,
261+ double aspect,
262+ double x,
263+ double y,
264+ double cornerRadius,
265+ double width,
266+ double height);
267+
268+ nux::BaseTexture*
269+ cairoToTexture2D (const char label,
270+ int width,
271+ int height);
272+
273 std::list<char *> StringToUriList (char * input);
274
275 nux::HLayout* m_Layout;
276@@ -421,6 +438,8 @@
277 nux::BaseTexture* _arrow_empty_ltr;
278 nux::BaseTexture* _arrow_empty_rtl;
279
280+ nux::BaseTexture* _superkey_labels[MAX_SUPERKEY_LABELS];
281+
282 nux::IntrusiveSP<nux::IOpenGLBaseTexture> _offscreen_drag_texture;
283 nux::IntrusiveSP<nux::IOpenGLBaseTexture> _offscreen_progress_texture;
284
285
286=== modified file 'src/LauncherIcon.cpp'
287--- src/LauncherIcon.cpp 2011-02-23 10:21:23 +0000
288+++ src/LauncherIcon.cpp 2011-02-24 09:32:15 +0000
289@@ -73,6 +73,7 @@
290 _shortcut = 0;
291
292 _emblem = 0;
293+ _superkey_label = 0;
294
295 _quicklist = new QuicklistView ();
296 _quicklist_is_initialized = false;
297@@ -106,6 +107,9 @@
298 if (_center_stabilize_handle)
299 g_source_remove (_center_stabilize_handle);
300 _center_stabilize_handle = 0;
301+
302+ if (_superkey_label)
303+ _superkey_label->UnReference ();
304 }
305
306 bool
307@@ -688,6 +692,24 @@
308 needs_redraw.emit (this);
309 }
310
311+void
312+LauncherIcon::SetSuperkeyLabel (nux::BaseTexture* label)
313+{
314+ if (_superkey_label == label)
315+ return;
316+
317+ if (_superkey_label)
318+ _superkey_label->UnReference ();
319+
320+ _superkey_label = label;
321+}
322+
323+nux::BaseTexture*
324+LauncherIcon::GetSuperkeyLabel ()
325+{
326+ return _superkey_label;
327+}
328+
329 void
330 LauncherIcon::SetEmblemIconName (const char *name)
331 {
332
333=== modified file 'src/LauncherIcon.h'
334--- src/LauncherIcon.h 2011-02-22 17:05:31 +0000
335+++ src/LauncherIcon.h 2011-02-24 09:32:15 +0000
336@@ -176,6 +176,8 @@
337 void SetSortPriority (int priority);
338
339 void SetEmblem (nux::BaseTexture *emblem);
340+ void SetSuperkeyLabel (nux::BaseTexture* label);
341+ nux::BaseTexture* GetSuperkeyLabel ();
342
343 virtual std::list<DbusmenuMenuitem *> GetMenus ();
344 virtual nux::BaseTexture * GetTextureForSize (int size) = 0;
345@@ -258,6 +260,7 @@
346 IconType _icon_type;
347
348 nux::BaseTexture* _emblem;
349+ nux::BaseTexture* _superkey_label;
350
351 bool _quirks[QUIRK_LAST];
352 struct timespec _quirk_times[QUIRK_LAST];