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
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2012-08-30 16:15:45 +0000
+++ src/Makefile.am 2012-10-23 20:05:32 +0000
@@ -16,6 +16,7 @@
16 fadable.vala \16 fadable.vala \
17 fadable-box.vala \17 fadable-box.vala \
18 fading-label.vala \18 fading-label.vala \
19 flat-button.vala \
19 greeter-list.vala \20 greeter-list.vala \
20 list-stack.vala \21 list-stack.vala \
21 main-window.vala \22 main-window.vala \
@@ -26,6 +27,7 @@
26 remote-login-service.vala \27 remote-login-service.vala \
27 settings.vala \28 settings.vala \
28 settings-daemon.vala \29 settings-daemon.vala \
30 toggle-box.vala \
29 unity-greeter.vala \31 unity-greeter.vala \
30 user-list.vala \32 user-list.vala \
31 user-prompt-box.vala33 user-prompt-box.vala
3234
=== modified file 'src/dash-box.vala'
--- src/dash-box.vala 2012-08-27 22:30:33 +0000
+++ src/dash-box.vala 2012-10-23 20:05:32 +0000
@@ -228,9 +228,9 @@
228 return base.draw (c);228 return base.draw (c);
229 }229 }
230230
231 private void cairo_rounded_rectangle (Cairo.Context c, double x, double y,231 public static void cairo_rounded_rectangle (Cairo.Context c, double x,
232 double width, double height,232 double y, double width,
233 double radius)233 double height, double radius)
234 {234 {
235 var w = width - radius * 2;235 var w = width - radius * 2;
236 var h = height - radius * 2;236 var h = height - radius * 2;
237237
=== modified file 'src/dash-button.vala'
--- src/dash-button.vala 2012-08-27 22:30:33 +0000
+++ src/dash-button.vala 2012-10-23 20:05:32 +0000
@@ -17,7 +17,7 @@
17 * Authors: Michael Terry <michael.terry@canonical.com>17 * Authors: Michael Terry <michael.terry@canonical.com>
18 */18 */
1919
20public class DashButton : Gtk.Button, Fadable20public class DashButton : FlatButton, Fadable
21{21{
22 protected FadeTracker fade_tracker { get; protected set; }22 protected FadeTracker fade_tracker { get; protected set; }
23 private Gtk.Label text_label;23 private Gtk.Label text_label;
@@ -67,7 +67,9 @@
67 try67 try
68 {68 {
69 var style = new Gtk.CssProvider ();69 var style = new Gtk.CssProvider ();
70 style.load_from_data ("* {padding: 8px;}", -1);70 style.load_from_data ("* {padding: 8px;
71 -GtkWidget-focus-line-width: 0px;
72 }", -1);
71 this.get_style_context ().add_provider (style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);73 this.get_style_context ().add_provider (style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
72 }74 }
73 catch (Error e)75 catch (Error e)
7476
=== added file 'src/flat-button.vala'
--- src/flat-button.vala 1970-01-01 00:00:00 +0000
+++ src/flat-button.vala 2012-10-23 20:05:32 +0000
@@ -0,0 +1,66 @@
1/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 4 -*-
2 *
3 * Copyright (C) 2012 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Michael Terry <michael.terry@canonical.com>
18 */
19
20public class FlatButton : Gtk.Button
21{
22 private bool did_press;
23
24 construct
25 {
26 UnityGreeter.add_style_class (this);
27 try
28 {
29 var style = new Gtk.CssProvider ();
30 style.load_from_data ("* {-GtkButton-child-displacement-x: 0px;
31 -GtkButton-child-displacement-y: 0px;
32 -GtkWidget-focus-line-width: 1px;
33 }", -1);
34 get_style_context ().add_provider (style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
35 }
36 catch (Error e)
37 {
38 debug ("Internal error loading session chooser style: %s", e.message);
39 }
40 }
41
42 public override bool draw (Cairo.Context c)
43 {
44 // Make sure we don't react to mouse hovers
45 unset_state_flags (Gtk.StateFlags.PRELIGHT);
46 return base.draw (c);
47 }
48
49 public override void pressed ()
50 {
51 // Do nothing. The normal handler sets priv->button_down which
52 // internally causes draw() to draw a special border and background
53 // that we don't want.
54 did_press = true;
55 }
56
57 public override void released ()
58 {
59 if (did_press)
60 {
61 base.pressed (); // fake an insta-click
62 did_press = false;
63 }
64 base.released ();
65 }
66}
067
=== modified file 'src/main-window.vala'
--- src/main-window.vala 2012-09-12 14:43:30 +0000
+++ src/main-window.vala 2012-10-23 20:05:32 +0000
@@ -105,12 +105,12 @@
105 align.show ();105 align.show ();
106 hbox.add (align);106 hbox.add (align);
107107
108 back_button = new Gtk.Button ();108 back_button = new FlatButton ();
109 back_button.focus_on_click = false;
109 var image = new Gtk.Image.from_file (Path.build_filename (Config.PKGDATADIR, "arrow_left.png", null));110 var image = new Gtk.Image.from_file (Path.build_filename (Config.PKGDATADIR, "arrow_left.png", null));
110 image.show ();111 image.show ();
111 back_button.set_size_request (grid_size - GreeterList.BORDER * 2, grid_size - GreeterList.BORDER * 2);112 back_button.set_size_request (grid_size - GreeterList.BORDER * 2, grid_size - GreeterList.BORDER * 2);
112 back_button.add (image);113 back_button.add (image);
113 UnityGreeter.add_style_class (back_button);
114 back_button.clicked.connect (pop_list);114 back_button.clicked.connect (pop_list);
115 align.add (back_button);115 align.add (back_button);
116116
117117
=== modified file 'src/prompt-box.vala'
--- src/prompt-box.vala 2012-10-22 20:46:56 +0000
+++ src/prompt-box.vala 2012-10-23 20:05:32 +0000
@@ -52,7 +52,7 @@
52 protected Gtk.Grid name_grid;52 protected Gtk.Grid name_grid;
53 private ActiveIndicator active_indicator;53 private ActiveIndicator active_indicator;
54 protected FadingLabel name_label;54 protected FadingLabel name_label;
55 protected Gtk.Button option_button;55 protected FlatButton option_button;
56 private CachedImage option_image;56 private CachedImage option_image;
57 private CachedImage message_image;57 private CachedImage message_image;
5858
@@ -203,7 +203,7 @@
203 align.show ();203 align.show ();
204 name_grid.attach (align, COL_NAME_MESSAGE, ROW_NAME, 1, 1);204 name_grid.attach (align, COL_NAME_MESSAGE, ROW_NAME, 1, 1);
205205
206 option_button = new Gtk.Button ();206 option_button = new FlatButton ();
207 option_button.hexpand = true;207 option_button.hexpand = true;
208 option_button.halign = Gtk.Align.END;208 option_button.halign = Gtk.Align.END;
209 option_button.valign = Gtk.Align.START;209 option_button.valign = Gtk.Align.START;
@@ -214,7 +214,6 @@
214 option_button.clicked.connect (option_button_clicked_cb);214 option_button.clicked.connect (option_button_clicked_cb);
215 option_image = new CachedImage (null);215 option_image = new CachedImage (null);
216 option_image.show ();216 option_image.show ();
217 UnityGreeter.add_style_class (option_button);
218 try217 try
219 {218 {
220 var style = new Gtk.CssProvider ();219 var style = new Gtk.CssProvider ();
221220
=== modified file 'src/session-list.vala'
--- src/session-list.vala 2012-10-22 20:12:58 +0000
+++ src/session-list.vala 2012-10-23 20:05:32 +0000
@@ -27,115 +27,39 @@
27 Object (id: id, session: session, default_session: default_session);27 Object (id: id, session: session, default_session: default_session);
28 }28 }
2929
30 private ToggleBox box;
31
30 construct32 construct
31 {33 {
32 label = _("Select desktop environment");34 label = _("Select desktop environment");
35 name_label.vexpand = false;
36
37 box = new ToggleBox (default_session, session);
3338
34 if (UnityGreeter.singleton.test_mode)39 if (UnityGreeter.singleton.test_mode)
35 {40 {
36 add_session ("gnome", "GNOME");41 box.add_item ("gnome", "GNOME", SessionList.get_badge ("gnome"));
37 add_session ("kde", "KDE");42 box.add_item ("kde", "KDE", SessionList.get_badge ("kde"));
38 add_session ("ubuntu", "Ubuntu");43 box.add_item ("ubuntu", "Ubuntu", SessionList.get_badge ("ubuntu"));
39 }44 }
40 else45 else
41 {46 {
42 foreach (var session in LightDM.get_sessions ())47 foreach (var session in LightDM.get_sessions ())
43 {48 {
44 debug ("Adding session %s (%s)", session.key, session.name);49 debug ("Adding session %s (%s)", session.key, session.name);
45 add_session (session.key, session.name);50 box.add_item (session.key, session.name, SessionList.get_badge (session.key));
46 }51 }
47 }52 }
4853
49 name_label.vexpand = false;54 box.notify["selected-key"].connect (selected_cb);
50 }55 box.show ();
5156
52 private void add_session (string key, string name_in)57 attach_item (box);
53 {58 }
54 var item = new Gtk.Button ();59
55 item.clicked.connect (button_clicked_cb);60 private void selected_cb ()
56 UnityGreeter.add_style_class (item);61 {
5762 respond ({ box.selected_key });
58 var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
59
60 var pixbuf = SessionList.get_badge (key);
61 if (pixbuf != null)
62 {
63 var image = new CachedImage (pixbuf);
64 hbox.pack_start (image, false, false, 0);
65 }
66
67 var name = name_in;
68 if (key == default_session)
69 {
70 /* Translators: %s is a session name like KDE or Ubuntu */
71 name = _("%s (Default)").printf (name);
72 }
73
74 var label = new Gtk.Label (null);
75 label.set_markup ("<span font=\"Ubuntu 13\">%s</span>".printf (name));
76 label.halign = Gtk.Align.START;
77 hbox.pack_start (label, true, true, 0);
78
79 item.hexpand = true;
80 item.add (hbox);
81 hbox.show_all ();
82
83 try
84 {
85 /* Tighten padding on buttons to not be so large */
86 var style = new Gtk.CssProvider ();
87 style.load_from_data ("* {padding: 8px;}", -1);
88 item.get_style_context ().add_provider (style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
89 }
90 catch (Error e)
91 {
92 debug ("Internal error loading session chooser style: %s", e.message);
93 }
94
95 item.set_data<string> ("session-list-key", key);
96 attach_item (item);
97 }
98
99 private void set_button_highlighted (Gtk.Widget button, bool highlight)
100 {
101 Gdk.RGBA? color = null;
102 if (highlight)
103 color = { 0.5f, 0.5f, 0.5f, 0.4f };
104 button.override_background_color (Gtk.StateFlags.NORMAL, color);
105 }
106
107 private void button_clicked_cb (Gtk.Button button)
108 {
109 foreach_prompt_widget ((w) =>
110 {
111 set_button_highlighted (w, (w == button));
112 });
113 respond ({ button.get_data<string> ("session-list-key") });
114 }
115
116 public override void grab_focus ()
117 {
118 var done = false;
119 Gtk.Widget best = null;
120 foreach_prompt_widget ((w) =>
121 {
122 if (done)
123 return;
124 if (best == null)
125 best = w; /* first button wins, all else considered */
126 var key = w.get_data<string> ("session-list-key");
127 if (session == key || (session == null && default_session == key))
128 {
129 best = w;
130 done = true;
131 }
132 });
133
134 if (best != null)
135 {
136 best.grab_focus ();
137 set_button_highlighted (best, true);
138 }
139 }63 }
140}64}
14165
14266
=== added file 'src/toggle-box.vala'
--- src/toggle-box.vala 1970-01-01 00:00:00 +0000
+++ src/toggle-box.vala 2012-10-23 20:05:32 +0000
@@ -0,0 +1,131 @@
1/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 4 -*-
2 *
3 * Copyright (C) 2012 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Michael Terry <michael.terry@canonical.com>
18 */
19
20public class ToggleBox : Gtk.Box
21{
22 public string default_key {get; construct;}
23 public string starting_key {get; construct;}
24 public string selected_key {get; protected set;}
25
26 public ToggleBox (string? default_key, string? starting_key)
27 {
28 Object (default_key: default_key, starting_key: starting_key,
29 selected_key: starting_key);
30 }
31
32 public void add_item (string key, string label, Gdk.Pixbuf? icon)
33 {
34 var item = make_button (key, label, icon);
35
36 if (get_children () == null ||
37 (starting_key == null && default_key == key) ||
38 starting_key == key)
39 select (item);
40
41 item.show ();
42 add (item);
43 }
44
45 private Gtk.Button selected_button;
46
47 construct
48 {
49 orientation = Gtk.Orientation.VERTICAL;
50 }
51
52 public override bool draw (Cairo.Context c)
53 {
54 Gtk.Allocation allocation;
55 get_allocation (out allocation);
56
57 DashBox.cairo_rounded_rectangle (c, 0, 0, allocation.width,
58 allocation.height, 0.1 * grid_size);
59 c.set_source_rgba (0.5, 0.5, 0.5, 0.5);
60 c.set_line_width (1);
61 c.stroke ();
62
63 return base.draw (c);
64 }
65
66 private void select (Gtk.Button button)
67 {
68 if (selected_button != null)
69 selected_button.relief = Gtk.ReliefStyle.NONE;
70 selected_button = button;
71 selected_button.relief = Gtk.ReliefStyle.NORMAL;
72 selected_key = selected_button.get_data<string> ("toggle-list-key");
73 }
74
75 private Gtk.Button make_button (string key, string name_in, Gdk.Pixbuf? icon)
76 {
77 var item = new FlatButton ();
78 item.relief = Gtk.ReliefStyle.NONE;
79 item.clicked.connect (button_clicked_cb);
80
81 var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
82
83 if (icon != null)
84 {
85 var image = new CachedImage (icon);
86 hbox.pack_start (image, false, false, 0);
87 }
88
89 var name = name_in;
90 if (key == default_key)
91 {
92 /* Translators: %s is a session name like KDE or Ubuntu */
93 name = _("%s (Default)").printf (name);
94 }
95
96 var label = new Gtk.Label (null);
97 label.set_markup ("<span font=\"Ubuntu 13\">%s</span>".printf (name));
98 label.halign = Gtk.Align.START;
99 hbox.pack_start (label, true, true, 0);
100
101 item.hexpand = true;
102 item.add (hbox);
103 hbox.show_all ();
104
105 try
106 {
107 /* Tighten padding on buttons to not be so large */
108 var style = new Gtk.CssProvider ();
109 style.load_from_data ("* {padding: 8px;}", -1);
110 item.get_style_context ().add_provider (style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
111 }
112 catch (Error e)
113 {
114 debug ("Internal error loading session chooser style: %s", e.message);
115 }
116
117 item.set_data<string> ("toggle-list-key", key);
118 return item;
119 }
120
121 private void button_clicked_cb (Gtk.Button button)
122 {
123 selected_key = button.get_data<string> ("toggle-list-key");
124 }
125
126 public override void grab_focus ()
127 {
128 if (selected_button != null)
129 selected_button.grab_focus ();
130 }
131}

Subscribers

People subscribed via source and target branches