Merge lp:~3v1n0/unity-greeter/shutdown-better-bg-color into lp:unity-greeter

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Robert Ancell
Approved revision: 1056
Merged at revision: 1027
Proposed branch: lp:~3v1n0/unity-greeter/shutdown-better-bg-color
Merge into: lp:unity-greeter
Diff against target: 128 lines (+76/-6)
2 files modified
src/fixes.vapi (+5/-0)
src/shutdown-dialog.vala (+71/-6)
To merge this branch: bzr merge lp:~3v1n0/unity-greeter/shutdown-better-bg-color
Reviewer Review Type Date Requested Status
Robert Ancell Approve
Review via email: mp+195150@code.launchpad.net

Commit message

ShutdownDialog: apply the same unity color corrections to the average color

Background base color should now match exactly the shell color.

Description of the change

Improved the average color, applying the same corrections we do in UnityShell.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/fixes.vapi'
2--- src/fixes.vapi 2013-11-05 04:14:44 +0000
3+++ src/fixes.vapi 2013-11-13 22:26:46 +0000
4@@ -62,4 +62,9 @@
5 namespace Gtk
6 {
7 public void socket_add_id (Gtk.Socket socket, int id);
8+
9+ namespace RGB
10+ {
11+ public void to_hsv (double r, double g, double b, out double h, out double s, out double v);
12+ }
13 }
14
15=== modified file 'src/shutdown-dialog.vala'
16--- src/shutdown-dialog.vala 2013-11-13 05:53:45 +0000
17+++ src/shutdown-dialog.vala 2013-11-13 22:26:46 +0000
18@@ -42,10 +42,11 @@
19 private const int BORDER_EXTERNAL_SIZE = BORDER_SIZE - BORDER_INTERNAL_SIZE;
20 private const int CLOSE_OFFSET = 3;
21 private const int BUTTON_TEXT_SPACE = 9;
22- private const int BLUR_RADIUS = 4;
23+ private const int BLUR_RADIUS = 8;
24
25 private Monitor monitor;
26 private weak Background background;
27+ private Gdk.RGBA avg_color;
28
29 private Gtk.Box vbox;
30 private DialogButton close_button;
31@@ -61,7 +62,8 @@
32 {
33 background = bg;
34 background.notify["alpha"].connect (rebuild_background);
35- background.notify["average-color"].connect (rebuild_background);
36+ background.notify["average-color"].connect (update_background_color);
37+ update_background_color ();
38
39 // This event box covers the monitor size, and closes the dialog on click.
40 monitor_events = new Gtk.EventBox ();
41@@ -232,6 +234,72 @@
42 queue_draw ();
43 }
44
45+ private void update_background_color ()
46+ {
47+ // Apply the same color corrections we do in Unity
48+ // For reference, see unity's unity-shared/BGHash.cpp
49+ double hue, saturation, value;
50+ const double COLOR_ALPHA = 0.72f;
51+
52+ Gdk.RGBA color = background.average_color;
53+ Gtk.RGB.to_hsv (color.red, color.green, color.blue,
54+ out hue, out saturation, out value);
55+
56+ if (saturation < 0.08)
57+ {
58+ // Got a grayscale image
59+ avg_color = {0.18f, 0.20f, 0.21f, COLOR_ALPHA };
60+ }
61+ else
62+ {
63+ const Gdk.RGBA[] cmp_colors =
64+ {
65+ {84/255.0f, 14/255.0f, 68/255.0f, 1.0f},
66+ {110/255.0f, 11/255.0f, 42/255.0f, 1.0f},
67+ {132/255.0f, 22/255.0f, 23/255.0f, 1.0f},
68+ {132/255.0f, 55/255.0f, 27/255.0f, 1.0f},
69+ {134/255.0f, 77/255.0f, 32/255.0f, 1.0f},
70+ {133/255.0f, 127/255.0f, 49/255.0f, 1.0f},
71+ {29/255.0f, 99/255.0f, 49/255.0f, 1.0f},
72+ {17/255.0f, 88/255.0f, 46/255.0f, 1.0f},
73+ {14/255.0f, 89/255.0f, 85/255.0f, 1.0f},
74+ {25/255.0f, 43/255.0f, 89/255.0f, 1.0f},
75+ {27/255.0f, 19/255.0f, 76/255.0f, 1.0f},
76+ {2/255.0f, 192/255.0f, 212/255.0f, 1.0f}
77+ };
78+
79+ avg_color = {0, 0, 0, 1};
80+ double closest_diff = 200.0f;
81+
82+ foreach (var c in cmp_colors)
83+ {
84+ double cmp_hue, cmp_sat, cmp_value;
85+ Gtk.RGB.to_hsv (c.red, c.green, c.blue,
86+ out cmp_hue, out cmp_sat, out cmp_value);
87+ double color_diff = Math.fabs (hue - cmp_hue);
88+
89+ if (color_diff < closest_diff)
90+ {
91+ avg_color = c;
92+ closest_diff = color_diff;
93+ }
94+ }
95+
96+ double new_hue, new_saturation, new_value;
97+ Gtk.RGB.to_hsv (avg_color.red, avg_color.green, avg_color.blue,
98+ out new_hue, out new_saturation, out new_value);
99+
100+ saturation = double.min (saturation, new_saturation);
101+ saturation *= (2.0f - saturation);
102+ value = double.min (double.min (value, new_value), 0.26f);
103+ Gtk.HSV.to_rgb (hue, saturation, value,
104+ out avg_color.red, out avg_color.green, out avg_color.blue);
105+ avg_color.alpha = COLOR_ALPHA;
106+ }
107+
108+ rebuild_background ();
109+ }
110+
111 public void set_active_monitor (Monitor m)
112 {
113 if (m == this.monitor || m.equals (this.monitor))
114@@ -329,13 +397,10 @@
115 c.save ();
116 c.translate (x, y);
117
118- var avg_color = background.average_color;
119 CairoUtils.rounded_rectangle (c, 0, 0, width, height, 4);
120 c.set_source_surface (bg_surface, 0, 0);
121 c.fill_preserve ();
122- c.set_source_rgba (0.0, 0.0, 0.0, 0.55f);
123- c.fill_preserve ();
124- c.set_source_rgba (avg_color.red, avg_color.green, avg_color.blue, 0.35);
125+ c.set_source_rgba (avg_color.red, avg_color.green, avg_color.blue, avg_color.alpha);
126 c.fill ();
127
128 c.restore();

Subscribers

People subscribed via source and target branches