summarylogtreecommitdiffstats
path: root/minus-backgroundmanager.patch
blob: 9a54da96cfb9e652d636cc26f706833c08f2328d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
--- src/wingpanel/src/PanelWindow.vala	2016-10-21 23:51:49.434036000 +0900
+++ src/wingpanel/src/PanelWindow.vala.new	2016-10-22 00:21:00.991151961 +0900
@@ -86,7 +86,6 @@
     private void on_realize () {
         update_panel_dimensions ();
 
-        Services.BackgroundManager.initialize (this.monitor_number, panel_height);
 
         timeout = Timeout.add (100 / panel_height, animation_step);
     }
@@ -152,7 +152,6 @@
 
     public void set_expanded (bool expanded) {
         if (expand && !this.expanded) {
-            Services.BackgroundManager.get_default ().remember_window ();
 
             this.expanded = true;
 
@@ -163,7 +163,6 @@
 
             this.set_size_request (monitor_width, monitor_height);
         } else if (!expand) {
-            Services.BackgroundManager.get_default ().restore_window ();
 
             this.expanded = false;
 
--- src/wingpanel/src/Widgets/Panel.vala	2016-10-22 00:14:45.485792472 +0900
+++ src/wingpanel/src/Widgets/Panel.vala.new	2016-10-22 00:15:13.386112571 +0900
@@ -25,7 +25,6 @@
     private MenuBar center_menubar;
 
     private Gtk.StyleContext style_context;
-    private Gtk.CssProvider? style_provider = null;
 
     public Panel (Services.PopoverManager popover_manager) {
         Object (popover_manager : popover_manager, orientation: Gtk.Orientation.HORIZONTAL);
@@ -60,7 +60,6 @@
 
         style_context = this.get_style_context ();
 
-        Services.BackgroundManager.get_default ().background_state_changed.connect (update_background);
     }
 
     private void add_indicator (Indicator indicator) {
@@ -228,55 +227,4 @@
         }
     }
 
-    private void update_background (Services.BackgroundState state, uint animation_duration) {
-        if (style_provider == null) {
-            style_provider = new Gtk.CssProvider ();
-            style_context.add_provider (style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
-        }
-
-        string css = """
-            .panel {
-                transition: all %ums ease-in-out;
-            }
-        """.printf (animation_duration);
-
-        try {
-            style_provider.load_from_data (css, css.length);
-        } catch (Error e) {
-            warning ("Parsing own style configuration failed: %s", e.message);
-        }
-
-        switch (state) {
-            case Services.BackgroundState.DARK :
-                style_context.add_class ("color-light");
-                style_context.remove_class ("color-dark");
-                style_context.remove_class ("maximized");
-                style_context.remove_class ("translucent");
-                break;
-            case Services.BackgroundState.LIGHT:
-                style_context.add_class ("color-dark");
-                style_context.remove_class ("color-light");
-                style_context.remove_class ("maximized");
-                style_context.remove_class ("translucent");
-                break;
-            case Services.BackgroundState.MAXIMIZED:
-                style_context.add_class ("maximized");
-                style_context.remove_class ("color-light");
-                style_context.remove_class ("color-dark");
-                style_context.remove_class ("translucent");
-                break;
-            case Services.BackgroundState.TRANSLUCENT_DARK:
-                style_context.add_class ("translucent");
-                style_context.add_class ("color-light");
-                style_context.remove_class ("color-dark");
-                style_context.remove_class ("maximized");
-                break;
-            case Services.BackgroundState.TRANSLUCENT_LIGHT:
-                style_context.add_class ("translucent");
-                style_context.add_class ("color-dark");
-                style_context.remove_class ("color-light");
-                style_context.remove_class ("maximized");
-                break;
-        }
-    }
 }
--- src/wingpanel/src/CMakeLists.txt	2017-10-13 03:28:23.119421691 +0900
+++ src/wingpanel/src/CMakeLists.txt.new	2017-10-13 03:30:12.838158479 +0900
@@ -10,7 +10,6 @@
   Services/IndicatorSorter.vala
   Services/PopoverManager.vala
   Services/Settings.vala
-  Services/BackgroundManager.vala
 )
 
 vala_precompile (CLIENT_VALA_C ${CMAKE_PROJECT_NAME}
--- src/wingpanel/wingpanel-interface/BackgroundManager.vala	2018-05-13 16:35:27.438070885 +0900
+++ /dev/null	2018-05-12 19:49:31.706719886 +0900
@@ -1,204 +0,0 @@
-/*
- * Copyright (c) 2011-2015 Wingpanel Developers (http://launchpad.net/wingpanel)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA.
- */
-
-public enum BackgroundState {
-    LIGHT,
-    DARK,
-    MAXIMIZED,
-    TRANSLUCENT_DARK,
-    TRANSLUCENT_LIGHT
-}
-
-public class WingpanelInterface.BackgroundManager : Object {
-    private const int WALLPAPER_TRANSITION_DURATION = 150;
-    private const double ACUTANCE_THRESHOLD = 8;
-    private const double STD_THRESHOLD = 45;
-    private const double LUMINANCE_THRESHOLD = 180;
-
-    public signal void state_changed (BackgroundState state, uint animation_duration);
-
-    public int monitor { private get; construct; }
-    public int panel_height{ private get; construct; }
-
-    private ulong wallpaper_hook_id;
-
-    private Meta.Workspace? current_workspace = null;
-
-    private BackgroundState current_state = BackgroundState.LIGHT;
-    
-    private Utils.ColorInformation? bk_color_info = null;
-
-    public BackgroundManager (int monitor, int panel_height) {
-        Object (monitor : monitor, panel_height: panel_height);
-
-        connect_signals ();
-        update_bk_color_info.begin ((obj, res) => {
-            update_bk_color_info.end (res);
-            update_current_workspace ();
-        });
-    }
-
-    ~BackgroundManager () {
-        var signal_id = GLib.Signal.lookup ("changed", Main.wm.background_group.get_type ());
-        GLib.Signal.remove_emission_hook (signal_id, wallpaper_hook_id);
-    }
-
-    private void connect_signals () {
-        Main.screen.workspace_switched.connect (() => {
-            update_current_workspace ();
-        });
-
-        var signal_id = GLib.Signal.lookup ("changed", Main.wm.background_group.get_type ());
-
-        wallpaper_hook_id = GLib.Signal.add_emission_hook (signal_id, 0, (ihint, param_values) => {
-            update_bk_color_info.begin ((obj, res) => {
-                update_bk_color_info.end (res);
-                check_for_state_change (WALLPAPER_TRANSITION_DURATION);
-            });
-
-            return true;
-#if VALA_0_42
-        });
-#else
-        }, null);
-#endif
-    }
-
-    private void update_current_workspace () {
-        var workspace = Main.screen.get_workspace_by_index (Main.screen.get_active_workspace_index ());
-
-        if (workspace == null) {
-            warning ("Cannot get active workspace");
-
-            return;
-        }
-
-        if (current_workspace != null) {
-            current_workspace.window_added.disconnect (on_window_added);
-            current_workspace.window_removed.disconnect (on_window_removed);
-        }
-
-        current_workspace = workspace;
-
-        foreach (Meta.Window window in current_workspace.list_windows ()) {
-            if (window.is_on_primary_monitor ()) {
-                register_window (window);
-            }
-        }
-
-        current_workspace.window_added.connect (on_window_added);
-        current_workspace.window_removed.connect (on_window_removed);
-
-        check_for_state_change (AnimationSettings.get_default ().workspace_switch_duration);
-    }
-
-    private void register_window (Meta.Window window) {
-        window.notify["maximized-vertically"].connect (() => {
-            check_for_state_change (AnimationSettings.get_default ().snap_duration);
-        });
-
-        window.notify["minimized"].connect (() => {
-            check_for_state_change (AnimationSettings.get_default ().minimize_duration);
-        });
-    }
-
-    private void on_window_added (Meta.Window window) {
-        register_window (window);
-
-        check_for_state_change (AnimationSettings.get_default ().snap_duration);
-    }
-
-    private void on_window_removed (Meta.Window window) {
-        check_for_state_change (AnimationSettings.get_default ().snap_duration);
-    }
-
-    public async void update_bk_color_info () {
-        SourceFunc callback = update_bk_color_info.callback;
-        Gdk.Rectangle monitor_geometry;
-
-        Gdk.Screen.get_default ().get_monitor_geometry (monitor, out monitor_geometry);
-
-        Utils.get_background_color_information.begin (Main.wm, monitor, 0, 0, monitor_geometry.width, panel_height, (obj, res) => {
-            try {
-                bk_color_info = Utils.get_background_color_information.end (res);
-            } catch (Error e) {
-                warning (e.message);
-            } finally {
-                callback ();
-            }
-        });
-        
-        yield;
-    }
-
-    /**
-     * Check if Wingpanel's background state should change.
-     *
-     * The state is defined as follows:
-     *  - If there's a maximized window, the state should be MAXIMIZED;
-     *  - If no information about the background could be gathered, it should be TRANSLUCENT;
-     *  - If there's too much contrast or sharpness, it should be TRANSLUCENT;
-     *  - If the background is too bright, it should be DARK;
-     *  - Else it should be LIGHT.
-     */
-    private void check_for_state_change (uint animation_duration) {
-        bool has_maximized_window = false;
-
-        foreach (Meta.Window window in current_workspace.list_windows ()) {
-            if (window.get_monitor () == monitor) {
-                if (!window.minimized && window.maximized_vertically) {
-                    has_maximized_window = true;
-                    break;
-                }
-            }
-        }
-
-        BackgroundState new_state;
-
-        if (has_maximized_window) {
-            new_state = BackgroundState.MAXIMIZED;
-        } else if (bk_color_info == null) {
-            new_state = BackgroundState.TRANSLUCENT_LIGHT;
-        } else {
-            var luminance_std = Math.sqrt (bk_color_info.luminance_variance);
-
-            bool bg_is_busy = luminance_std > STD_THRESHOLD ||
-                (bk_color_info.mean_luminance < LUMINANCE_THRESHOLD &&
-                bk_color_info.mean_luminance + 1.645 * luminance_std > LUMINANCE_THRESHOLD ) ||
-                bk_color_info.mean_acutance > ACUTANCE_THRESHOLD;
-
-            bool bg_is_dark = bk_color_info.mean_luminance > LUMINANCE_THRESHOLD;
-            bool bg_is_busy_dark = bk_color_info.mean_luminance * 1.25 > LUMINANCE_THRESHOLD;
-
-            if (bg_is_busy && bg_is_busy_dark) {
-                new_state = BackgroundState.TRANSLUCENT_DARK;
-            } else if (bg_is_busy) {
-                new_state = BackgroundState.TRANSLUCENT_LIGHT;
-            } else if (bg_is_dark) {
-                new_state = BackgroundState.DARK;
-            } else {
-                new_state = BackgroundState.LIGHT;
-            } 
-        }
-
-        if (new_state != current_state) {
-            state_changed (current_state = new_state, animation_duration);
-        }
-    }
-}