summarylogtreecommitdiffstats
path: root/autohide.patch
blob: 57adbd6a47c88ec8b243ffa3f271e96bb92662e2 (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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
diff --git a/./.travis.yml b/../wingpanel-qq/wingpanel-qq/.travis.yml
index 20a23ed..409aceb 100644
--- a/./.travis.yml
+++ b/../wingpanel-qq/wingpanel-qq/.travis.yml
@@ -4,7 +4,7 @@ services:
  - docker

 env:
- - DEPENDENCY_PACKAGES="libgala-dev libgee-0.8-dev libgirepository1.0-dev libglib2.0-dev libgranite-dev libgtk-3-dev meson valac"
+ - DEPENDENCY_PACKAGES="libgala-dev libgee-0.8-dev libgirepository1.0-dev libglib2.0-dev libgranite-dev libgtk-3-dev libwnck-3-dev meson valac"

 install:
  - docker pull elementary/docker:juno-unstable
diff --git a/./CMakeLists.txt b/../wingpanel-qq/wingpanel-qq/CMakeLists.txt
index 2309c8b..878fc26 100644
--- a/./CMakeLists.txt
+++ b/../wingpanel-qq/wingpanel-qq/CMakeLists.txt
@@ -76,6 +76,7 @@ set (LIB_PACKAGES
   gee-0.8
   gmodule-2.0
   gtk+-3.0
+  libwnck-3.0
 )

 set (LIB_PKG
@@ -84,11 +85,15 @@ set (LIB_PKG
   gee-0.8
   gmodule-2.0
   gtk+-3.0>=3.22
+  libwnck-3.0>=3.14
 )
 find_package(PkgConfig)

 pkg_check_modules (LIB REQUIRED ${LIB_PKG})

+add_definitions (-DWNCK_I_KNOW_THIS_IS_UNSTABLE ${WNCK_CFLAGS})
+link_libraries (${WNCK_LIBRARIES})
+
 set (GLOBAL_VALAC_OPTIONS
   --vapidir=${CMAKE_BINARY_DIR}/lib
   --vapidir=vapi
diff --git a/./meson.build b/../wingpanel-qq/wingpanel-qq/meson.build
index 4f0f279..19b4f65 100644
--- a/./meson.build
+++ b/../wingpanel-qq/wingpanel-qq/meson.build
@@ -14,7 +14,8 @@ add_project_arguments([

 add_project_arguments([
         '-DGETTEXT_PACKAGE="wingpanel"',
-        '-DG_LOG_DOMAIN="wingpanel"'
+        '-DG_LOG_DOMAIN="wingpanel"',
+        '-DWNCK_I_KNOW_THIS_IS_UNSTABLE'
     ],
     language: 'c'
 )
@@ -29,6 +30,7 @@ gio_dep = dependency('gio-2.0')
 gio_unix_dep = dependency('gio-unix-2.0')
 gmodule_dep = dependency('gmodule-2.0')
 gtk_dep = dependency('gtk+-3.0', version: '>=3.10')
+libwnck_dep = dependency('libwnck-3.0', version: '>=3.14')
 gee_dep = dependency('gee-0.8')
 granite_dep = dependency('granite')

diff --git a/./schemas/io.elementary.desktop.wingpanel.gschema.xml b/../wingpanel-qq/wingpanel-qq/schemas/io.elementary.desktop.wingpanel.gschema.xml
index a309a1d..aa150f7 100644
--- a/./schemas/io.elementary.desktop.wingpanel.gschema.xml
+++ b/../wingpanel-qq/wingpanel-qq/schemas/io.elementary.desktop.wingpanel.gschema.xml
@@ -6,5 +6,23 @@
 			<summary>Sets if the panel uses transparency.</summary>
 			<description>Disable this to provide higher contrasts and make indicators better readable.</description>
 		</key>
+		<key type="s" name="autohide">
+			<choices>
+				<choice value='Autohide'/>
+				<choice value='Float'/>
+				<choice value='Dodge'/>
+				<choice value='Dodge-Float'/>
+				<choice value='Disabled'/>
+			</choices>
+			<default>'Disabled'</default>
+			<summary>Sets if and how the panel will autohide.</summary>
+			<description>Enable this to increase available desktop area and reduce clutter.</description>
+		</key>
+		<key type="i" name="delay">
+			<range min="0" max="1000"/>
+			<default>200</default>
+			<summary>Sets how long before the panel will autohide in milliseconds.</summary>
+			<description>Increase or decrease this value to your preference.</description>
+		</key>
 	</schema>
 </schemalist>
diff --git a/./src/PanelWindow.vala b/../wingpanel-qq/wingpanel-qq/src/PanelWindow.vala
index 162c54a..e06472f 100644
--- a/./src/PanelWindow.vala
+++ b/../wingpanel-qq/wingpanel-qq/src/PanelWindow.vala
@@ -29,6 +29,13 @@ public class Wingpanel.PanelWindow : Gtk.Window {
     private int panel_height;
     private bool expanded = false;
     private int panel_displacement;
+    private uint shrink_timeout = 0;
+    private uint timeout;
+    private bool hiding = false;
+    private bool delay = false;
+    private string autohide = Services.PanelSettings.get_default ().autohide;
+    private int autohide_delay = Services.PanelSettings.get_default ().delay;
+    private Wnck.Screen wnck_screen = Wnck.Screen.get_default ();

     public PanelWindow (Gtk.Application application) {
         Object (
@@ -70,16 +77,65 @@ public class Wingpanel.PanelWindow : Gtk.Window {
         application.add_accelerator ("<Control>Tab", "app.cycle", null);
         application.add_accelerator ("<Control><Shift>Tab", "app.cycle-back", null);

+        Services.PanelSettings.get_default ().notify["autohide"].connect (() => {
+            autohide = Services.PanelSettings.get_default ().autohide;
+            update_autohide_mode ();
+        });
+
+        Services.PanelSettings.get_default ().notify["delay"].connect (() => {
+            autohide_delay = Services.PanelSettings.get_default ().delay;
+        });
+
         add (panel);
     }

     private bool animation_step () {
-        if (panel_displacement <= panel_height * (-1)) {
-            return false;
+        if (hiding) {
+            if (popover_manager.current_indicator != null) {
+                timeout = 0;
+                return false;
+            }
+            if (panel_displacement >= -1) {
+                timeout = 0;
+                update_struts ();
+                this.enter_notify_event.connect (show_panel);
+                this.motion_notify_event.connect (show_panel);
+                delay = true;
+                return false;
+            }
+            panel_displacement++;
+        } else {
+            if (panel_displacement <= panel_height * (-1)) {
+                timeout = 0;
+                switch (autohide) {
+                    case "Autohide":
+                        update_struts ();
+                        this.leave_notify_event.connect (hide_panel);
+                        break;
+                    case "Float":
+                        this.leave_notify_event.connect (hide_panel);
+                        break;
+                    case "Dodge":
+                        update_struts ();
+                        if (should_hide_active_change (wnck_screen.get_active_window()))
+                            this.leave_notify_event.connect (hide_panel);
+
+                        break;
+                    case "Dodge-Float":
+                        if (should_hide_active_change (wnck_screen.get_active_window()))
+                            this.leave_notify_event.connect (hide_panel);
+
+                        break;
+                    default:
+                        this.leave_notify_event.disconnect (hide_panel);
+                        update_struts ();
+                        break;
+                }
+                return false;
+            }
+            panel_displacement--;
         }

-        panel_displacement--;
-
         update_panel_dimensions ();

         return true;
@@ -90,7 +146,128 @@ public class Wingpanel.PanelWindow : Gtk.Window {

         Services.BackgroundManager.initialize (this.monitor_number, panel_height);

-        Timeout.add (300 / panel_height, animation_step);
+        update_autohide_mode ();
+    }
+
+    private void active_window_changed (Wnck.Window? prev_active_window) {
+        unowned Wnck.Window? active_window = wnck_screen.get_active_window();
+        update_visibility_active_change (active_window);
+
+        if (prev_active_window != null)
+            prev_active_window.state_changed.disconnect (active_window_state_changed);
+        if (active_window != null)
+            active_window.state_changed.connect (active_window_state_changed);
+    }
+
+    private void active_workspace_changed (Wnck.Workspace? prev_active_workspace) {
+        unowned Wnck.Window? active_window = wnck_screen.get_active_window();
+        update_visibility_active_change (active_window);
+    }
+
+    private void viewports_changed (Wnck.Screen? screen) {
+        unowned Wnck.Window? active_window = wnck_screen.get_active_window();
+        update_visibility_active_change (active_window);
+    }
+
+    private void active_window_state_changed (Wnck.Window? window,
+            Wnck.WindowState changed_mask, Wnck.WindowState new_state) {
+        update_visibility_active_change (window);
+    }
+
+    private void update_visibility_active_change (Wnck.Window? active_window) {
+        if (should_hide_active_change (active_window)) {
+            this.leave_notify_event.connect (hide_panel);
+            delay = false;
+            hide_panel ();
+        } else {
+            this.leave_notify_event.disconnect (hide_panel);
+            delay = false;
+            show_panel ();
+        }
+    }
+
+    private bool should_hide_active_change (Wnck.Window? active_window) {
+        unowned Wnck.Workspace active_workspace = wnck_screen.get_active_workspace ();
+
+        return ((active_window != null) && !active_window.is_minimized () && right_type (active_window)
+                && active_window.is_visible_on_workspace (active_workspace)
+                && active_window.is_in_viewport (active_workspace)
+                && is_maximized_at_all (active_window));
+    }
+
+    private bool right_type (Wnck.Window? active_window) {
+        unowned Wnck.WindowType type = active_window.get_window_type ();
+        return (type == Wnck.WindowType.NORMAL || type == Wnck.WindowType.DIALOG
+                || type == Wnck.WindowType.TOOLBAR || type == Wnck.WindowType.UTILITY);
+    }
+
+    private bool is_maximized_at_all (Wnck.Window window) {
+        return (window.is_maximized_horizontally ()
+                || window.is_maximized_vertically ()
+                || window.is_fullscreen ());
+    }
+
+    private bool hide_panel () {
+        if (timeout > 0) {
+            Source.remove (timeout);
+        }
+        hiding = true;
+        if (delay) {
+            Thread.usleep (autohide_delay * 1000);
+        }
+        timeout = Timeout.add (100 / panel_height, animation_step);
+        return true;
+    }
+
+    private bool show_panel () {
+        if (timeout > 0) {
+            Source.remove (timeout);
+        }
+        this.enter_notify_event.disconnect (show_panel);
+        this.motion_notify_event.disconnect (show_panel);
+        hiding = false;
+        if (autohide != "Disabled") {
+            if (delay) {
+                Thread.usleep (autohide_delay * 1000);
+            }
+            timeout = Timeout.add (100 / panel_height, animation_step);
+        } else {
+            timeout = Timeout.add (300 / panel_height, animation_step);
+        }
+        return true;
+    }
+
+    private void update_autohide_mode () {
+        switch (autohide) {
+            case "Autohide":
+            case "Float":
+                delay = true;
+                wnck_screen.active_window_changed.disconnect (active_window_changed);
+                wnck_screen.active_workspace_changed.disconnect (active_workspace_changed);
+                wnck_screen.viewports_changed.disconnect (viewports_changed);
+                hide_panel ();
+                break;
+            case "Dodge":
+            case "Dodge-Float":
+                delay = false;
+                if (!should_hide_active_change (wnck_screen.get_active_window())) {
+                    this.leave_notify_event.disconnect (hide_panel);
+                    show_panel ();
+                } else {
+                    hide_panel ();
+                }
+                wnck_screen.active_window_changed.connect (active_window_changed);
+                wnck_screen.active_workspace_changed.connect (active_workspace_changed);
+                wnck_screen.viewports_changed.connect (viewports_changed);
+                break;
+            default:
+                this.leave_notify_event.connect (hide_panel);
+                wnck_screen.active_window_changed.disconnect (active_window_changed);
+                wnck_screen.active_workspace_changed.disconnect (active_workspace_changed);
+                wnck_screen.viewports_changed.disconnect (viewports_changed);
+                show_panel ();
+                break;
+        }
     }

     private void update_panel_dimensions () {
@@ -110,7 +287,6 @@ public class Wingpanel.PanelWindow : Gtk.Window {

         this.move (monitor_x, monitor_y - (panel_height + panel_displacement));

-        update_struts ();
     }

     private void update_visual () {
diff --git a/./src/Services/Settings.vala b/../wingpanel-qq/wingpanel-qq/src/Services/Settings.vala
index 6d8f0f1..e138162 100644
--- a/./src/Services/Settings.vala
+++ b/../wingpanel-qq/wingpanel-qq/src/Services/Settings.vala
@@ -23,6 +23,10 @@ namespace Wingpanel.Services {

         public bool use_transparency { get; set; }

+        public string autohide { get; set; }
+
+        public int delay { get; set; }
+
         public PanelSettings () {
             base ("io.elementary.desktop.wingpanel");
         }
diff --git a/./src/meson.build b/../wingpanel-qq/wingpanel-qq/src/meson.build
index 3703e53..b3b1b39 100644
--- a/./src/meson.build
+++ b/../wingpanel-qq/wingpanel-qq/src/meson.build
@@ -16,6 +16,7 @@ wingpanel_files = files(
 wingpanel_deps = [
     libwingpanel_dep,
     granite_dep,
+    libwnck_dep,
 ]

 executable(meson.project_name(),