Merge lp:~diego-rocha-comp/wingpanel/fix-1473563 into lp:~wingpanel-devs/wingpanel/trunk

Proposed by Diego Rocha
Status: Merged
Approved by: Cody Garver
Approved revision: 109
Merged at revision: 109
Proposed branch: lp:~diego-rocha-comp/wingpanel/fix-1473563
Merge into: lp:~wingpanel-devs/wingpanel/trunk
Diff against target: 342 lines (+102/-51)
6 files modified
src/Services/BackgroundManager.vala (+3/-2)
src/Widgets/Panel.vala (+9/-2)
wingpanel-interface/BackgroundManager.vala (+54/-14)
wingpanel-interface/CMakeLists.txt (+1/-1)
wingpanel-interface/DBusServer.vala (+4/-4)
wingpanel-interface/Utils.vala (+31/-28)
To merge this branch: bzr merge lp:~diego-rocha-comp/wingpanel/fix-1473563
Reviewer Review Type Date Requested Status
WingPanel Devs Pending
Review via email: mp+286452@code.launchpad.net

Commit message

Improve the logic used to define the panel's style by accounting for luminance, contrast and sharpness, and adding the TRANSLUCENT state.

This new state is used when the desktop wallpaper is complex or has high contrast.

Description of the change

Improves the logic used to define the panel's style by accounting for luminance, contrast and sharpness, and adding the TRANSLUCENT state.

This new state is used when the desktop wallpaper is complex or has high contrast.

Depends on https://code.launchpad.net/~diego-rocha-comp/egtk/fix-1473563/+merge/286451

To post a comment you must log in.
108. By Diego Rocha

backgroundmanager: added TRANSLUCENT state and improved state selection logic

109. By Diego Rocha

backgroundmanager: load background color information before checking for initial state

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Services/BackgroundManager.vala'
--- src/Services/BackgroundManager.vala 2015-12-02 20:52:48 +0000
+++ src/Services/BackgroundManager.vala 2016-02-19 22:10:36 +0000
@@ -21,7 +21,8 @@
21 public enum BackgroundState {21 public enum BackgroundState {
22 LIGHT,22 LIGHT,
23 DARK,23 DARK,
24 MAXIMIZED24 MAXIMIZED,
25 TRANSLUCENT
25 }26 }
2627
27 [DBus (name = "org.pantheon.gala.WingpanelInterface")]28 [DBus (name = "org.pantheon.gala.WingpanelInterface")]
@@ -113,4 +114,4 @@
113 return instance;114 return instance;
114 }115 }
115 }116 }
116}
117\ No newline at end of file117\ No newline at end of file
118}
118119
=== modified file 'src/Widgets/Panel.vala'
--- src/Widgets/Panel.vala 2015-10-21 21:48:36 +0000
+++ src/Widgets/Panel.vala 2016-02-19 22:10:36 +0000
@@ -18,8 +18,6 @@
18 */18 */
1919
20public class Wingpanel.Widgets.Panel : Gtk.Box {20public class Wingpanel.Widgets.Panel : Gtk.Box {
21 private static const double ALPHA_ANIMATION_STEP = 0.05;
22
23 public Services.PopoverManager popover_manager { get; construct; }21 public Services.PopoverManager popover_manager { get; construct; }
2422
25 private IndicatorMenuBar right_menubar;23 private IndicatorMenuBar right_menubar;
@@ -126,16 +124,25 @@
126 style_context.add_class ("color-light");124 style_context.add_class ("color-light");
127 style_context.remove_class ("color-dark");125 style_context.remove_class ("color-dark");
128 style_context.remove_class ("maximized");126 style_context.remove_class ("maximized");
127 style_context.remove_class ("translucent");
129 break;128 break;
130 case Services.BackgroundState.LIGHT:129 case Services.BackgroundState.LIGHT:
131 style_context.add_class ("color-dark");130 style_context.add_class ("color-dark");
132 style_context.remove_class ("color-light");131 style_context.remove_class ("color-light");
133 style_context.remove_class ("maximized");132 style_context.remove_class ("maximized");
133 style_context.remove_class ("translucent");
134 break;134 break;
135 case Services.BackgroundState.MAXIMIZED:135 case Services.BackgroundState.MAXIMIZED:
136 style_context.add_class ("maximized");136 style_context.add_class ("maximized");
137 style_context.remove_class ("color-light");137 style_context.remove_class ("color-light");
138 style_context.remove_class ("color-dark");138 style_context.remove_class ("color-dark");
139 style_context.remove_class ("translucent");
140 break;
141 case Services.BackgroundState.TRANSLUCENT:
142 style_context.add_class ("translucent");
143 style_context.remove_class ("color-light");
144 style_context.remove_class ("color-dark");
145 style_context.remove_class ("maximized");
139 break;146 break;
140 }147 }
141 }148 }
142149
=== renamed file 'wingpanel-interface/AlphaManager.vala' => 'wingpanel-interface/BackgroundManager.vala'
--- wingpanel-interface/AlphaManager.vala 2015-12-02 20:28:08 +0000
+++ wingpanel-interface/BackgroundManager.vala 2016-02-19 22:10:36 +0000
@@ -20,11 +20,15 @@
20public enum BackgroundState {20public enum BackgroundState {
21 LIGHT,21 LIGHT,
22 DARK,22 DARK,
23 MAXIMIZED23 MAXIMIZED,
24 TRANSLUCENT
24}25}
2526
26public class WingpanelInterface.AlphaManager : Object {27public class WingpanelInterface.BackgroundManager : Object {
27 private const int WALLPAPER_TRANSITION_DURATION = 150;28 private const int WALLPAPER_TRANSITION_DURATION = 150;
29 private const double ACUTANCE_THRESHOLD = 8;
30 private const double STD_THRESHOLD = 45;
31 private const double LUMINANCE_THRESHOLD = 180;
2832
29 public signal void state_changed (BackgroundState state, uint animation_duration);33 public signal void state_changed (BackgroundState state, uint animation_duration);
3034
@@ -36,16 +40,20 @@
36 private Meta.Workspace? current_workspace = null;40 private Meta.Workspace? current_workspace = null;
3741
38 private BackgroundState current_state = BackgroundState.LIGHT;42 private BackgroundState current_state = BackgroundState.LIGHT;
39 private bool needs_dark_background = false;43
44 private Utils.ColorInformation? bk_color_info = null;
4045
41 public AlphaManager (int monitor, int panel_height) {46 public BackgroundManager (int monitor, int panel_height) {
42 Object (monitor : monitor, panel_height: panel_height);47 Object (monitor : monitor, panel_height: panel_height);
4348
44 connect_signals ();49 connect_signals ();
45 update_current_workspace ();50 update_bk_color_info.begin ((obj, res) => {
51 update_bk_color_info.end (res);
52 update_current_workspace ();
53 });
46 }54 }
4755
48 ~AlphaManager () {56 ~BackgroundManager () {
49 var signal_id = GLib.Signal.lookup ("changed", Main.wm.background_group.get_type ());57 var signal_id = GLib.Signal.lookup ("changed", Main.wm.background_group.get_type ());
50 GLib.Signal.remove_emission_hook (signal_id, wallpaper_hook_id);58 GLib.Signal.remove_emission_hook (signal_id, wallpaper_hook_id);
51 }59 }
@@ -58,7 +66,10 @@
58 var signal_id = GLib.Signal.lookup ("changed", Main.wm.background_group.get_type ());66 var signal_id = GLib.Signal.lookup ("changed", Main.wm.background_group.get_type ());
5967
60 wallpaper_hook_id = GLib.Signal.add_emission_hook (signal_id, 0, (ihint, param_values) => {68 wallpaper_hook_id = GLib.Signal.add_emission_hook (signal_id, 0, (ihint, param_values) => {
61 update_alpha_state.begin ();69 update_bk_color_info.begin ((obj, res) => {
70 update_bk_color_info.end (res);
71 check_for_state_change (WALLPAPER_TRANSITION_DURATION);
72 });
6273
63 return true;74 return true;
64 }, null);75 }, null);
@@ -112,14 +123,35 @@
112 check_for_state_change (AnimationSettings.get_default ().snap_duration);123 check_for_state_change (AnimationSettings.get_default ().snap_duration);
113 }124 }
114125
115 public async void update_alpha_state () {126 public async void update_bk_color_info () {
116 Utils.background_needed.begin (Main.wm, monitor, panel_height, (obj, res) => {127 SourceFunc callback = update_bk_color_info.callback;
117 needs_dark_background = Utils.background_needed.end (res);128 Gdk.Rectangle monitor_geometry;
118129
119 check_for_state_change (WALLPAPER_TRANSITION_DURATION);130 Gdk.Screen.get_default ().get_monitor_geometry (monitor, out monitor_geometry);
131
132 Utils.get_background_color_information.begin (Main.wm, monitor, 0, 0, monitor_geometry.width, panel_height, (obj, res) => {
133 try {
134 bk_color_info = Utils.get_background_color_information.end (res);
135 } catch (Error e) {
136 warning (e.message);
137 } finally {
138 callback ();
139 }
120 });140 });
141
142 yield;
121 }143 }
122144
145 /**
146 * Check if Wingpanel's background state should change.
147 *
148 * The state is defined as follows:
149 * - If there's a maximized window, the state should be MAXIMIZED;
150 * - If no information about the background could be gathered, it should be TRANSLUCENT;
151 * - If there's too much contrast or sharpness, it should be TRANSLUCENT;
152 * - If the background is too bright, it should be DARK;
153 * - Else it should be LIGHT.
154 */
123 private void check_for_state_change (uint animation_duration) {155 private void check_for_state_change (uint animation_duration) {
124 bool has_maximized_window = false;156 bool has_maximized_window = false;
125157
@@ -136,12 +168,20 @@
136168
137 if (has_maximized_window) {169 if (has_maximized_window) {
138 new_state = BackgroundState.MAXIMIZED;170 new_state = BackgroundState.MAXIMIZED;
171 } else if (bk_color_info == null) {
172 new_state = BackgroundState.TRANSLUCENT;
139 } else {173 } else {
140 new_state = needs_dark_background ? BackgroundState.DARK : BackgroundState.LIGHT;174 var luminance_std = Math.sqrt (bk_color_info.luminance_variance);
175
176 new_state = luminance_std > STD_THRESHOLD ||
177 (bk_color_info.mean_luminance < LUMINANCE_THRESHOLD &&
178 bk_color_info.mean_luminance + 1.645 * luminance_std > LUMINANCE_THRESHOLD ) ||
179 bk_color_info.mean_acutance > ACUTANCE_THRESHOLD ? BackgroundState.TRANSLUCENT :
180 bk_color_info.mean_luminance > LUMINANCE_THRESHOLD ? BackgroundState.DARK : BackgroundState.LIGHT;
141 }181 }
142182
143 if (new_state != current_state) {183 if (new_state != current_state) {
144 state_changed (current_state = new_state, animation_duration);184 state_changed (current_state = new_state, animation_duration);
145 }185 }
146 }186 }
147}
148\ No newline at end of file187\ No newline at end of file
188}
149189
=== modified file 'wingpanel-interface/CMakeLists.txt'
--- wingpanel-interface/CMakeLists.txt 2015-05-25 16:19:07 +0000
+++ wingpanel-interface/CMakeLists.txt 2016-02-19 22:10:36 +0000
@@ -14,7 +14,7 @@
14vala_precompile (VALA_C ${WINGPANELINTERFACE}14vala_precompile (VALA_C ${WINGPANELINTERFACE}
15 Main.vala15 Main.vala
16 DBusServer.vala16 DBusServer.vala
17 AlphaManager.vala17 BackgroundManager.vala
18 FocusManager.vala18 FocusManager.vala
19 Settings.vala19 Settings.vala
20 Utils.vala20 Utils.vala
2121
=== modified file 'wingpanel-interface/DBusServer.vala'
--- wingpanel-interface/DBusServer.vala 2015-10-20 23:43:37 +0000
+++ wingpanel-interface/DBusServer.vala 2016-02-19 22:10:36 +0000
@@ -19,13 +19,13 @@
1919
20[DBus (name = "org.pantheon.gala.WingpanelInterface")]20[DBus (name = "org.pantheon.gala.WingpanelInterface")]
21public class WingpanelInterface.DBusServer : Object {21public class WingpanelInterface.DBusServer : Object {
22 private AlphaManager alpha_manager;22 private BackgroundManager background_manager;
2323
24 public signal void state_changed (BackgroundState state, uint animation_duration);24 public signal void state_changed (BackgroundState state, uint animation_duration);
2525
26 public void initialize (int monitor, int panel_height) {26 public void initialize (int monitor, int panel_height) {
27 alpha_manager = new AlphaManager (monitor, panel_height);27 background_manager = new BackgroundManager (monitor, panel_height);
28 alpha_manager.state_changed.connect ((state, animation_duration) => {28 background_manager.state_changed.connect ((state, animation_duration) => {
29 state_changed (state, animation_duration);29 state_changed (state, animation_duration);
30 });30 });
31 }31 }
@@ -37,4 +37,4 @@
37 public void restore_focused_window () {37 public void restore_focused_window () {
38 FocusManager.get_default ().restore_focused_window ();38 FocusManager.get_default ().restore_focused_window ();
39 }39 }
40}
41\ No newline at end of file40\ No newline at end of file
41}
4242
=== modified file 'wingpanel-interface/Utils.vala'
--- wingpanel-interface/Utils.vala 2015-10-20 14:07:04 +0000
+++ wingpanel-interface/Utils.vala 2016-02-19 22:10:36 +0000
@@ -25,8 +25,6 @@
25namespace WingpanelInterface.Utils {25namespace WingpanelInterface.Utils {
26 private const double SATURATION_WEIGHT = 1.5;26 private const double SATURATION_WEIGHT = 1.5;
27 private const double WEIGHT_THRESHOLD = 1.0;27 private const double WEIGHT_THRESHOLD = 1.0;
28 private const double MIN_VARIANCE = 50;
29 private const double MIN_LUM = 25;
3028
31 private class DummyOffscreenEffect : Clutter.OffscreenEffect {29 private class DummyOffscreenEffect : Clutter.OffscreenEffect {
32 public signal void done_painting ();30 public signal void done_painting ();
@@ -41,8 +39,9 @@
41 double average_red;39 double average_red;
42 double average_green;40 double average_green;
43 double average_blue;41 double average_blue;
44 double mean;42 double mean_luminance;
45 double variance;43 double luminance_variance;
44 double mean_acutance;
46 }45 }
4746
48 public async ColorInformation get_background_color_information (Gala.WindowManager wm, int monitor,47 public async ColorInformation get_background_color_information (Gala.WindowManager wm, int monitor,
@@ -68,7 +67,7 @@
68 throw new DBusError.INVALID_ARGS ("Invalid rectangle specified: %i, %i, %i, %i".printf (x_start, y_start, width, height));67 throw new DBusError.INVALID_ARGS ("Invalid rectangle specified: %i, %i, %i, %i".printf (x_start, y_start, width, height));
69 }68 }
7069
71 double variance = 0, mean = 0, rTotal = 0, gTotal = 0, bTotal = 0;70 double mean_acutance = 0, variance = 0, mean = 0, rTotal = 0, gTotal = 0, bTotal = 0;
72 ulong paint_signal_handler = 0;71 ulong paint_signal_handler = 0;
7372
74 paint_signal_handler = effect.done_painting.connect (() => {73 paint_signal_handler = effect.done_painting.connect (() => {
@@ -77,6 +76,7 @@
7776
78 var texture = (Cogl.Texture)effect.get_texture ();77 var texture = (Cogl.Texture)effect.get_texture ();
79 var pixels = new uint8[texture.get_width () * texture.get_height () * 4];78 var pixels = new uint8[texture.get_width () * texture.get_height () * 4];
79 var pixel_lums = new double[texture.get_width () * texture.get_height ()];
8080
81 CoglFixes.texture_get_data (texture, Cogl.PixelFormat.BGRA_8888_PRE, 0, pixels);81 CoglFixes.texture_get_data (texture, Cogl.PixelFormat.BGRA_8888_PRE, 0, pixels);
8282
@@ -100,7 +100,9 @@
100 uint8 g = pixels[i + 1];100 uint8 g = pixels[i + 1];
101 uint8 b = pixels[i + 2];101 uint8 b = pixels[i + 2];
102102
103 pixel = (0.3 * r + 0.6 * g + 0.11 * b) - 128f;103 pixel = (0.3 * r + 0.59 * g + 0.11 * b) ;
104
105 pixel_lums[y * width + x] = pixel;
104106
105 min = uint8.min (r, uint8.min (g, b));107 min = uint8.min (r, uint8.min (g, b));
106 max = uint8.max (r, uint8.max (g, b));108 max = uint8.max (r, uint8.max (g, b));
@@ -123,6 +125,21 @@
123 mean_squares += pixel * pixel;125 mean_squares += pixel * pixel;
124 }126 }
125 }127 }
128
129 for (int y = y_start + 1; y < height - 1; y++) {
130 for (int x = x_start + 1; x < width - 1; x++) {
131 var acutance =
132 (pixel_lums[y * width + x] * 4) -
133 (
134 pixel_lums[y * width + x - 1] +
135 pixel_lums[y * width + x + 1] +
136 pixel_lums[(y - 1) * width + x] +
137 pixel_lums[(y + 1) * width + x]
138 );
139
140 mean_acutance += acutance > 0 ? acutance : -acutance;
141 }
142 }
126143
127 scoreTotal /= size;144 scoreTotal /= size;
128 bTotal /= size;145 bTotal /= size;
@@ -163,9 +180,11 @@
163 }180 }
164181
165 mean /= size;182 mean /= size;
166 mean_squares *= mean_squares / size;183 mean_squares = mean_squares / size;
167184
168 variance = Math.sqrt (mean_squares - mean * mean) / (double)size;185 variance = (mean_squares - (mean * mean));
186
187 mean_acutance /= (width - 2) * (height - 2);
169188
170 get_background_color_information.callback ();189 get_background_color_information.callback ();
171 });190 });
@@ -174,23 +193,7 @@
174193
175 yield;194 yield;
176195
177 return { rTotal, gTotal, bTotal, mean, variance };
178 }
179
180 public async bool background_needed (Gala.WindowManager wm, int screen, int panel_height) {
181 Gdk.Rectangle monitor_geometry;
182 ColorInformation? color_info = null;
183
184 Gdk.Screen.get_default ().get_monitor_geometry (screen, out monitor_geometry);
185
186 try {
187 color_info = yield get_background_color_information (wm, screen, 0, 0, monitor_geometry.width, panel_height);
188 } catch (Error e) {
189 warning (e.message);
190
191 return false;
192 }
193
194 return color_info != null && (color_info.mean > MIN_LUM || color_info.variance > MIN_VARIANCE);
195 }
196}
197\ No newline at end of file196\ No newline at end of file
197 return { rTotal, gTotal, bTotal, mean, variance, mean_acutance };
198 }
199
200}

Subscribers

People subscribed via source and target branches

to all changes: