Merge lp:~3v1n0/unity-greeter/shutdown-buttons-fixes into lp:unity-greeter

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Robert Ancell
Approved revision: 1020
Merged at revision: 1019
Proposed branch: lp:~3v1n0/unity-greeter/shutdown-buttons-fixes
Merge into: lp:unity-greeter
Diff against target: 216 lines (+71/-35)
2 files modified
data/Makefile.am (+2/-1)
src/shutdown-dialog.vala (+69/-34)
To merge this branch: bzr merge lp:~3v1n0/unity-greeter/shutdown-buttons-fixes
Reviewer Review Type Date Requested Status
Robert Ancell Approve
Review via email: mp+194725@code.launchpad.net

Commit message

ShutdownDialog: match the close button state and fix paddings

Description of the change

The close button didn't update to match the current button state (prelighted or activated), code updated to make it work. Some code cleanup of the DialogButton class as well.

Fixed the main vbox margings to match the real unity dialogs and fixed the internal padding of the dialog buttons.
Unfortunately, this was caused by the theming of the GtkButton and the fastest way I found was to just ignore theming for such buttons not to re-implement buttons logic by scratch.

Here's how it looks after these fixes: http://i.imgur.com/0ibwtkE.png (it was http://i.imgur.com/UUoSMUC.png)

To post a comment you must log in.
Revision history for this message
Robert Ancell (robert-ancell) wrote :

Looks good!

review: Approve
Revision history for this message
Robert Ancell (robert-ancell) wrote :

Actually if I hold down the pointer on the close button I get a "missing image" icon.

review: Needs Fixing
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

> Actually if I hold down the pointer on the close button I get a "missing
> image" icon.

That's weird... It works here... It didn't find the new dialog_close_press.png in your installation path?

Revision history for this message
Robert Ancell (robert-ancell) wrote :

It's missing from data/Makefile.am

1020. By Marco Trevisan (Treviño)

data/Makefile.am: add missing dialog_close_press.png file

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

> It's missing from data/Makefile.am

Indeed! I'm too used to unity's cmake automatic management of the resource files... :)
Fix pushed.

Revision history for this message
Robert Ancell (robert-ancell) :
review: Approve
1021. By Marco Trevisan (Treviño)

ShutdownDialog: override the DialogButton style with one with no paddings or border

This properly fixes the extra padding we had around our buttons

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/Makefile.am'
2--- data/Makefile.am 2013-10-21 04:26:35 +0000
3+++ data/Makefile.am 2013-11-13 05:19:20 +0000
4@@ -9,8 +9,9 @@
5 arrow_left.png \
6 arrow_right.png \
7 cof.png \
8+ dialog_close.png \
9 dialog_close_highlight.png \
10- dialog_close.png \
11+ dialog_close_press.png \
12 gnome_badge.png \
13 hibernate_highlight.png \
14 hibernate.png \
15
16=== added file 'data/dialog_close_press.png'
17Binary files data/dialog_close_press.png 1970-01-01 00:00:00 +0000 and data/dialog_close_press.png 2013-11-13 05:19:20 +0000 differ
18=== modified file 'src/shutdown-dialog.vala'
19--- src/shutdown-dialog.vala 2013-11-05 04:14:44 +0000
20+++ src/shutdown-dialog.vala 2013-11-13 05:19:20 +0000
21@@ -34,9 +34,10 @@
22 private Cairo.Pattern? corner_pattern = null;
23 private Cairo.Pattern? left_pattern = null;
24 private Cairo.Pattern? top_pattern = null;
25-
26+
27 private const int BORDER_SIZE = 30;
28 private const int CLOSE_OFFSET = 3;
29+ private const int BUTTON_TEXT_SPACE = 9;
30
31 private Gtk.Box vbox;
32 private DialogButton close_button;
33@@ -48,7 +49,10 @@
34 vbox.visible = true;
35 add (vbox);
36
37- vbox.border_width = 20;
38+ vbox.margin_top = 10;
39+ vbox.margin_left = 22;
40+ vbox.margin_right = 18;
41+ vbox.margin_bottom = 0;
42
43 var title_label = new Gtk.Label (_("Shutdown"));
44 title_label.override_font (Pango.FontDescription.from_string ("Ubuntu Light 15"));
45@@ -58,7 +62,9 @@
46
47 string text;
48 if (type == ShutdownDialogType.SHUTDOWN)
49+ {
50 text = _("Goodbye. Would you like to…");
51+ }
52 else
53 {
54 text = _("Are you sure you want to shut down the computer?");
55@@ -147,7 +153,7 @@
56 });
57 }
58
59- close_button = new DialogButton (Path.build_filename (Config.PKGDATADIR, "dialog_close.png"), Path.build_filename (Config.PKGDATADIR, "dialog_close_highlight.png"));
60+ close_button = new DialogButton (Path.build_filename (Config.PKGDATADIR, "dialog_close.png"), Path.build_filename (Config.PKGDATADIR, "dialog_close_highlight.png"), Path.build_filename (Config.PKGDATADIR, "dialog_close_press.png"));
61 close_button.can_focus = false;
62 close_button.clicked.connect (() => { close (); });
63 close_button.visible = true;
64@@ -193,7 +199,7 @@
65 a.x = content_allocation.x - BORDER_SIZE + CLOSE_OFFSET;
66 a.y = content_allocation.y - BORDER_SIZE + CLOSE_OFFSET;
67 a.width = minimum_width;
68- a.height = minimum_height;
69+ a.height = minimum_height;
70 close_button.size_allocate (a);
71 }
72
73@@ -211,8 +217,8 @@
74 top_pattern.set_extend (Cairo.Extend.REPEAT);
75 }
76
77- var width = vbox.get_allocated_width () + 20 * 2 + BORDER_SIZE * 2;
78- var height = vbox.get_allocated_height () + 20 * 2 + BORDER_SIZE * 2;
79+ var width = vbox.get_allocated_width () + BORDER_SIZE * 2 + vbox.margin_left + vbox.margin_right;
80+ var height = vbox.get_allocated_height () + BORDER_SIZE * 2 + vbox.margin_top + vbox.margin_bottom;
81
82 /* Darken background */
83 c.set_source_rgba (0, 0, 0, 0.25);
84@@ -289,10 +295,10 @@
85 c.fill ();
86
87 /* Background */
88- DashBox.cairo_rounded_rectangle (c, 20, 20, width - 40, height - 40, 5);
89+ DashBox.cairo_rounded_rectangle (c, 20, 20, width - 40, height - 40, 4);
90 c.set_source_rgba (0, 0, 0, 0.75);
91 c.fill ();
92-
93+
94 c.restore ();
95
96 return base.draw (c);
97@@ -308,15 +314,12 @@
98
99 private DialogButton add_button (string text, string inactive_filename, string active_filename)
100 {
101- var b = new Gtk.Box (Gtk.Orientation.VERTICAL, 9);
102+ var b = new Gtk.Box (Gtk.Orientation.VERTICAL, BUTTON_TEXT_SPACE);
103 b.visible = true;
104 button_box.pack_start (b, false, false, 0);
105
106 var label = new Gtk.Label (text);
107- label.visible = true;
108- label.override_font (Pango.FontDescription.from_string ("Ubuntu Light 12"));
109- label.override_color (Gtk.StateFlags.NORMAL, { 1.0f, 1.0f, 1.0f, 0.0f });
110- var button = new DialogButton (inactive_filename, active_filename, label);
111+ var button = new DialogButton (inactive_filename, active_filename, null, label);
112 button.visible = true;
113
114 b.pack_start (button, false, false, 0);
115@@ -329,22 +332,47 @@
116 private class DialogButton : Gtk.Button
117 {
118 private string inactive_filename;
119- private string active_filename;
120+ private string focused_filename;
121+ private string? active_filename;
122 private Gtk.Image i;
123 private Gtk.Label? l;
124-
125- public DialogButton (string inactive_filename, string active_filename, Gtk.Label? label = null)
126+
127+ public DialogButton (string inactive_filename, string focused_filename, string? active_filename, Gtk.Label? label = null)
128 {
129 this.inactive_filename = inactive_filename;
130+ this.focused_filename = focused_filename;
131 this.active_filename = active_filename;
132- l = label;
133 relief = Gtk.ReliefStyle.NONE;
134 focus_on_click = false;
135 i = new Gtk.Image.from_file (inactive_filename);
136 i.visible = true;
137 add (i);
138+
139+ l = label;
140+
141+ if (l != null)
142+ {
143+ l.visible = true;
144+ l.override_font (Pango.FontDescription.from_string ("Ubuntu Light 12"));
145+ l.override_color (Gtk.StateFlags.NORMAL, { 1.0f, 1.0f, 1.0f, 0.0f });
146+ l.override_color (Gtk.StateFlags.FOCUSED, { 1.0f, 1.0f, 1.0f, 1.0f });
147+ l.override_color (Gtk.StateFlags.ACTIVE, { 1.0f, 1.0f, 1.0f, 1.0f });
148+ }
149+
150+ UnityGreeter.add_style_class (this);
151+ try
152+ {
153+ // Remove the default GtkButton paddings and border
154+ var style = new Gtk.CssProvider ();
155+ style.load_from_data ("* {padding: 0px 0px 0px 0px; border: 0px; }", -1);
156+ get_style_context ().add_provider (style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
157+ }
158+ catch (Error e)
159+ {
160+ debug ("Internal error loading session chooser style: %s", e.message);
161+ }
162 }
163-
164+
165 public override bool enter_notify_event (Gdk.EventCrossing event)
166 {
167 grab_focus ();
168@@ -357,25 +385,32 @@
169 return base.leave_notify_event (event);
170 }
171
172- public override bool focus_in_event (Gdk.EventFocus event)
173- {
174- i.set_from_file (active_filename);
175- if (l != null)
176- l.override_color (Gtk.StateFlags.NORMAL, { 1.0f, 1.0f, 1.0f, 1.0f });
177- return base.focus_in_event (event);
178- }
179-
180- public override bool focus_out_event (Gdk.EventFocus event)
181- {
182- i.set_from_file (inactive_filename);
183- if (l != null)
184- l.override_color (Gtk.StateFlags.NORMAL, { 1.0f, 1.0f, 1.0f, 0.0f });
185- return base.focus_out_event (event);
186- }
187-
188 public override bool draw (Cairo.Context c)
189 {
190 i.draw (c);
191 return true;
192 }
193+
194+ public override void state_flags_changed (Gtk.StateFlags previous_state)
195+ {
196+ var new_flags = get_state_flags ();
197+
198+ if ((new_flags & Gtk.StateFlags.PRELIGHT) != 0 && !can_focus ||
199+ (new_flags & Gtk.StateFlags.FOCUSED) != 0)
200+ {
201+ if ((new_flags & Gtk.StateFlags.ACTIVE) != 0 && active_filename != null)
202+ i.set_from_file (active_filename);
203+ else
204+ i.set_from_file (focused_filename);
205+ }
206+ else
207+ {
208+ i.set_from_file (inactive_filename);
209+ }
210+
211+ if (l != null)
212+ l.set_state_flags (new_flags, true);
213+
214+ base.state_flags_changed (previous_state);
215+ }
216 }

Subscribers

People subscribed via source and target branches