Merge lp:~mterry/unity-greeter/button-fixups into lp:unity-greeter

Proposed by Michael Terry
Status: Merged
Approved by: Robert Ancell
Approved revision: 629
Merged at revision: 645
Proposed branch: lp:~mterry/unity-greeter/button-fixups
Merge into: lp:unity-greeter
Diff against target: 457 lines (+231/-107)
8 files modified
src/Makefile.am (+2/-0)
src/dash-box.vala (+3/-3)
src/dash-button.vala (+4/-2)
src/flat-button.vala (+66/-0)
src/main-window.vala (+2/-2)
src/prompt-box.vala (+2/-3)
src/session-list.vala (+21/-97)
src/toggle-box.vala (+131/-0)
To merge this branch: bzr merge lp:~mterry/unity-greeter/button-fixups
Reviewer Review Type Date Requested Status
Unity Greeter Development Team Pending
Review via email: mp+131085@code.launchpad.net

Description of the change

This makes the buttons like the session change button in the greeter act "flat" (no visual change when clicked or moused over), while still letting a focus border appear when navigating with the keyboard.

It also adds a border around the session chooser list like the mockups have.

One unfortunate thing is that in order to achieve the flat look, I needed to override "pressed" and "released" methods in Gtk.Button which are marked deprecated by vala. (They are deprecated for API use, but they are internally used and I needed to override those functions specifically.) I could not find a way to shut valac up about it. So this branch adds two warnings to the build.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Makefile.am'
2--- src/Makefile.am 2012-08-30 16:15:45 +0000
3+++ src/Makefile.am 2012-10-23 20:05:32 +0000
4@@ -16,6 +16,7 @@
5 fadable.vala \
6 fadable-box.vala \
7 fading-label.vala \
8+ flat-button.vala \
9 greeter-list.vala \
10 list-stack.vala \
11 main-window.vala \
12@@ -26,6 +27,7 @@
13 remote-login-service.vala \
14 settings.vala \
15 settings-daemon.vala \
16+ toggle-box.vala \
17 unity-greeter.vala \
18 user-list.vala \
19 user-prompt-box.vala
20
21=== modified file 'src/dash-box.vala'
22--- src/dash-box.vala 2012-08-27 22:30:33 +0000
23+++ src/dash-box.vala 2012-10-23 20:05:32 +0000
24@@ -228,9 +228,9 @@
25 return base.draw (c);
26 }
27
28- private void cairo_rounded_rectangle (Cairo.Context c, double x, double y,
29- double width, double height,
30- double radius)
31+ public static void cairo_rounded_rectangle (Cairo.Context c, double x,
32+ double y, double width,
33+ double height, double radius)
34 {
35 var w = width - radius * 2;
36 var h = height - radius * 2;
37
38=== modified file 'src/dash-button.vala'
39--- src/dash-button.vala 2012-08-27 22:30:33 +0000
40+++ src/dash-button.vala 2012-10-23 20:05:32 +0000
41@@ -17,7 +17,7 @@
42 * Authors: Michael Terry <michael.terry@canonical.com>
43 */
44
45-public class DashButton : Gtk.Button, Fadable
46+public class DashButton : FlatButton, Fadable
47 {
48 protected FadeTracker fade_tracker { get; protected set; }
49 private Gtk.Label text_label;
50@@ -67,7 +67,9 @@
51 try
52 {
53 var style = new Gtk.CssProvider ();
54- style.load_from_data ("* {padding: 8px;}", -1);
55+ style.load_from_data ("* {padding: 8px;
56+ -GtkWidget-focus-line-width: 0px;
57+ }", -1);
58 this.get_style_context ().add_provider (style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
59 }
60 catch (Error e)
61
62=== added file 'src/flat-button.vala'
63--- src/flat-button.vala 1970-01-01 00:00:00 +0000
64+++ src/flat-button.vala 2012-10-23 20:05:32 +0000
65@@ -0,0 +1,66 @@
66+/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 4 -*-
67+ *
68+ * Copyright (C) 2012 Canonical Ltd
69+ *
70+ * This program is free software: you can redistribute it and/or modify
71+ * it under the terms of the GNU General Public License version 3 as
72+ * published by the Free Software Foundation.
73+ *
74+ * This program is distributed in the hope that it will be useful,
75+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
76+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
77+ * GNU General Public License for more details.
78+ *
79+ * You should have received a copy of the GNU General Public License
80+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
81+ *
82+ * Authors: Michael Terry <michael.terry@canonical.com>
83+ */
84+
85+public class FlatButton : Gtk.Button
86+{
87+ private bool did_press;
88+
89+ construct
90+ {
91+ UnityGreeter.add_style_class (this);
92+ try
93+ {
94+ var style = new Gtk.CssProvider ();
95+ style.load_from_data ("* {-GtkButton-child-displacement-x: 0px;
96+ -GtkButton-child-displacement-y: 0px;
97+ -GtkWidget-focus-line-width: 1px;
98+ }", -1);
99+ get_style_context ().add_provider (style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
100+ }
101+ catch (Error e)
102+ {
103+ debug ("Internal error loading session chooser style: %s", e.message);
104+ }
105+ }
106+
107+ public override bool draw (Cairo.Context c)
108+ {
109+ // Make sure we don't react to mouse hovers
110+ unset_state_flags (Gtk.StateFlags.PRELIGHT);
111+ return base.draw (c);
112+ }
113+
114+ public override void pressed ()
115+ {
116+ // Do nothing. The normal handler sets priv->button_down which
117+ // internally causes draw() to draw a special border and background
118+ // that we don't want.
119+ did_press = true;
120+ }
121+
122+ public override void released ()
123+ {
124+ if (did_press)
125+ {
126+ base.pressed (); // fake an insta-click
127+ did_press = false;
128+ }
129+ base.released ();
130+ }
131+}
132
133=== modified file 'src/main-window.vala'
134--- src/main-window.vala 2012-09-12 14:43:30 +0000
135+++ src/main-window.vala 2012-10-23 20:05:32 +0000
136@@ -105,12 +105,12 @@
137 align.show ();
138 hbox.add (align);
139
140- back_button = new Gtk.Button ();
141+ back_button = new FlatButton ();
142+ back_button.focus_on_click = false;
143 var image = new Gtk.Image.from_file (Path.build_filename (Config.PKGDATADIR, "arrow_left.png", null));
144 image.show ();
145 back_button.set_size_request (grid_size - GreeterList.BORDER * 2, grid_size - GreeterList.BORDER * 2);
146 back_button.add (image);
147- UnityGreeter.add_style_class (back_button);
148 back_button.clicked.connect (pop_list);
149 align.add (back_button);
150
151
152=== modified file 'src/prompt-box.vala'
153--- src/prompt-box.vala 2012-10-22 20:46:56 +0000
154+++ src/prompt-box.vala 2012-10-23 20:05:32 +0000
155@@ -52,7 +52,7 @@
156 protected Gtk.Grid name_grid;
157 private ActiveIndicator active_indicator;
158 protected FadingLabel name_label;
159- protected Gtk.Button option_button;
160+ protected FlatButton option_button;
161 private CachedImage option_image;
162 private CachedImage message_image;
163
164@@ -203,7 +203,7 @@
165 align.show ();
166 name_grid.attach (align, COL_NAME_MESSAGE, ROW_NAME, 1, 1);
167
168- option_button = new Gtk.Button ();
169+ option_button = new FlatButton ();
170 option_button.hexpand = true;
171 option_button.halign = Gtk.Align.END;
172 option_button.valign = Gtk.Align.START;
173@@ -214,7 +214,6 @@
174 option_button.clicked.connect (option_button_clicked_cb);
175 option_image = new CachedImage (null);
176 option_image.show ();
177- UnityGreeter.add_style_class (option_button);
178 try
179 {
180 var style = new Gtk.CssProvider ();
181
182=== modified file 'src/session-list.vala'
183--- src/session-list.vala 2012-10-22 20:12:58 +0000
184+++ src/session-list.vala 2012-10-23 20:05:32 +0000
185@@ -27,115 +27,39 @@
186 Object (id: id, session: session, default_session: default_session);
187 }
188
189+ private ToggleBox box;
190+
191 construct
192 {
193 label = _("Select desktop environment");
194+ name_label.vexpand = false;
195+
196+ box = new ToggleBox (default_session, session);
197
198 if (UnityGreeter.singleton.test_mode)
199 {
200- add_session ("gnome", "GNOME");
201- add_session ("kde", "KDE");
202- add_session ("ubuntu", "Ubuntu");
203+ box.add_item ("gnome", "GNOME", SessionList.get_badge ("gnome"));
204+ box.add_item ("kde", "KDE", SessionList.get_badge ("kde"));
205+ box.add_item ("ubuntu", "Ubuntu", SessionList.get_badge ("ubuntu"));
206 }
207 else
208 {
209 foreach (var session in LightDM.get_sessions ())
210 {
211 debug ("Adding session %s (%s)", session.key, session.name);
212- add_session (session.key, session.name);
213- }
214- }
215-
216- name_label.vexpand = false;
217- }
218-
219- private void add_session (string key, string name_in)
220- {
221- var item = new Gtk.Button ();
222- item.clicked.connect (button_clicked_cb);
223- UnityGreeter.add_style_class (item);
224-
225- var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
226-
227- var pixbuf = SessionList.get_badge (key);
228- if (pixbuf != null)
229- {
230- var image = new CachedImage (pixbuf);
231- hbox.pack_start (image, false, false, 0);
232- }
233-
234- var name = name_in;
235- if (key == default_session)
236- {
237- /* Translators: %s is a session name like KDE or Ubuntu */
238- name = _("%s (Default)").printf (name);
239- }
240-
241- var label = new Gtk.Label (null);
242- label.set_markup ("<span font=\"Ubuntu 13\">%s</span>".printf (name));
243- label.halign = Gtk.Align.START;
244- hbox.pack_start (label, true, true, 0);
245-
246- item.hexpand = true;
247- item.add (hbox);
248- hbox.show_all ();
249-
250- try
251- {
252- /* Tighten padding on buttons to not be so large */
253- var style = new Gtk.CssProvider ();
254- style.load_from_data ("* {padding: 8px;}", -1);
255- item.get_style_context ().add_provider (style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
256- }
257- catch (Error e)
258- {
259- debug ("Internal error loading session chooser style: %s", e.message);
260- }
261-
262- item.set_data<string> ("session-list-key", key);
263- attach_item (item);
264- }
265-
266- private void set_button_highlighted (Gtk.Widget button, bool highlight)
267- {
268- Gdk.RGBA? color = null;
269- if (highlight)
270- color = { 0.5f, 0.5f, 0.5f, 0.4f };
271- button.override_background_color (Gtk.StateFlags.NORMAL, color);
272- }
273-
274- private void button_clicked_cb (Gtk.Button button)
275- {
276- foreach_prompt_widget ((w) =>
277- {
278- set_button_highlighted (w, (w == button));
279- });
280- respond ({ button.get_data<string> ("session-list-key") });
281- }
282-
283- public override void grab_focus ()
284- {
285- var done = false;
286- Gtk.Widget best = null;
287- foreach_prompt_widget ((w) =>
288- {
289- if (done)
290- return;
291- if (best == null)
292- best = w; /* first button wins, all else considered */
293- var key = w.get_data<string> ("session-list-key");
294- if (session == key || (session == null && default_session == key))
295- {
296- best = w;
297- done = true;
298- }
299- });
300-
301- if (best != null)
302- {
303- best.grab_focus ();
304- set_button_highlighted (best, true);
305- }
306+ box.add_item (session.key, session.name, SessionList.get_badge (session.key));
307+ }
308+ }
309+
310+ box.notify["selected-key"].connect (selected_cb);
311+ box.show ();
312+
313+ attach_item (box);
314+ }
315+
316+ private void selected_cb ()
317+ {
318+ respond ({ box.selected_key });
319 }
320 }
321
322
323=== added file 'src/toggle-box.vala'
324--- src/toggle-box.vala 1970-01-01 00:00:00 +0000
325+++ src/toggle-box.vala 2012-10-23 20:05:32 +0000
326@@ -0,0 +1,131 @@
327+/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 4 -*-
328+ *
329+ * Copyright (C) 2012 Canonical Ltd
330+ *
331+ * This program is free software: you can redistribute it and/or modify
332+ * it under the terms of the GNU General Public License version 3 as
333+ * published by the Free Software Foundation.
334+ *
335+ * This program is distributed in the hope that it will be useful,
336+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
337+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
338+ * GNU General Public License for more details.
339+ *
340+ * You should have received a copy of the GNU General Public License
341+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
342+ *
343+ * Authors: Michael Terry <michael.terry@canonical.com>
344+ */
345+
346+public class ToggleBox : Gtk.Box
347+{
348+ public string default_key {get; construct;}
349+ public string starting_key {get; construct;}
350+ public string selected_key {get; protected set;}
351+
352+ public ToggleBox (string? default_key, string? starting_key)
353+ {
354+ Object (default_key: default_key, starting_key: starting_key,
355+ selected_key: starting_key);
356+ }
357+
358+ public void add_item (string key, string label, Gdk.Pixbuf? icon)
359+ {
360+ var item = make_button (key, label, icon);
361+
362+ if (get_children () == null ||
363+ (starting_key == null && default_key == key) ||
364+ starting_key == key)
365+ select (item);
366+
367+ item.show ();
368+ add (item);
369+ }
370+
371+ private Gtk.Button selected_button;
372+
373+ construct
374+ {
375+ orientation = Gtk.Orientation.VERTICAL;
376+ }
377+
378+ public override bool draw (Cairo.Context c)
379+ {
380+ Gtk.Allocation allocation;
381+ get_allocation (out allocation);
382+
383+ DashBox.cairo_rounded_rectangle (c, 0, 0, allocation.width,
384+ allocation.height, 0.1 * grid_size);
385+ c.set_source_rgba (0.5, 0.5, 0.5, 0.5);
386+ c.set_line_width (1);
387+ c.stroke ();
388+
389+ return base.draw (c);
390+ }
391+
392+ private void select (Gtk.Button button)
393+ {
394+ if (selected_button != null)
395+ selected_button.relief = Gtk.ReliefStyle.NONE;
396+ selected_button = button;
397+ selected_button.relief = Gtk.ReliefStyle.NORMAL;
398+ selected_key = selected_button.get_data<string> ("toggle-list-key");
399+ }
400+
401+ private Gtk.Button make_button (string key, string name_in, Gdk.Pixbuf? icon)
402+ {
403+ var item = new FlatButton ();
404+ item.relief = Gtk.ReliefStyle.NONE;
405+ item.clicked.connect (button_clicked_cb);
406+
407+ var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
408+
409+ if (icon != null)
410+ {
411+ var image = new CachedImage (icon);
412+ hbox.pack_start (image, false, false, 0);
413+ }
414+
415+ var name = name_in;
416+ if (key == default_key)
417+ {
418+ /* Translators: %s is a session name like KDE or Ubuntu */
419+ name = _("%s (Default)").printf (name);
420+ }
421+
422+ var label = new Gtk.Label (null);
423+ label.set_markup ("<span font=\"Ubuntu 13\">%s</span>".printf (name));
424+ label.halign = Gtk.Align.START;
425+ hbox.pack_start (label, true, true, 0);
426+
427+ item.hexpand = true;
428+ item.add (hbox);
429+ hbox.show_all ();
430+
431+ try
432+ {
433+ /* Tighten padding on buttons to not be so large */
434+ var style = new Gtk.CssProvider ();
435+ style.load_from_data ("* {padding: 8px;}", -1);
436+ item.get_style_context ().add_provider (style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
437+ }
438+ catch (Error e)
439+ {
440+ debug ("Internal error loading session chooser style: %s", e.message);
441+ }
442+
443+ item.set_data<string> ("toggle-list-key", key);
444+ return item;
445+ }
446+
447+ private void button_clicked_cb (Gtk.Button button)
448+ {
449+ selected_key = button.get_data<string> ("toggle-list-key");
450+ }
451+
452+ public override void grab_focus ()
453+ {
454+ if (selected_button != null)
455+ selected_button.grab_focus ();
456+ }
457+}

Subscribers

People subscribed via source and target branches