summarylogtreecommitdiffstats
path: root/autohide-evbox.patch
blob: e5a8cee933c44116f8fc9fcf20fc97b2b3c41167 (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
--- src/wingpanel/schemas/org.pantheon.desktop.wingpanel.gschema.xml	2017-12-26 14:53:03.354809958 +0900
+++ src/wingpanel/schemas/org.pantheon.desktop.wingpanel.gschema.xml.new	2018-01-21 23:41:18.703206040 +0900
@@ -6,5 +6,10 @@
 			<summary>Sets if the panel uses transparency.</summary>
 			<description>Disable this to provide higher contrasts and make indicators better readable.</description>
 		</key>
+		<key type="b" name="autohide">
+			<default>false</default>
+			<summary>Sets if the panel will autohide.</summary>
+			<description>Enable this to increase available desktop area and reduce clutter.</description>
+		</key>
 	</schema>
 </schemalist>
--- src/wingpanel/src/Services/Settings.vala	2017-12-26 14:53:03.354809958 +0900
+++ src/wingpanel/src/Services/Settings.vala.new	2018-01-21 23:46:25.919860486 +0900
@@ -23,6 +23,8 @@
 
         public bool use_transparency { get; set; }
 
+        public bool autohide { get; set; }
+
         public PanelSettings () {
             base ("org.pantheon.desktop.wingpanel");
         }
--- src/wingpanel/src/PanelWindow.vala	2017-06-01 02:18:32.090889031 +0900
+++ src/wingpanel/src/PanelWindow.vala.patched	2017-06-01 02:11:40.814767918 +0900
@@ -22,4 +22,9 @@
 
     private Widgets.Panel panel;
+
+    private Gtk.EventBox box;
+
+    uint timeout;
+
     private int monitor_number;
     private int monitor_width;
@@ -35,6 +35,7 @@
     private bool expanded = false;
     private int panel_displacement;
     private uint shrink_timeout = 0;
+    private bool autohide = Services.PanelSettings.get_default ().autohide;
 
     public PanelWindow (Gtk.Application application) {
         Object (
@@ -61,6 +61,9 @@
         update_visual ();
 
         popover_manager = new Services.PopoverManager (this);
+ 
+        box = new Gtk.EventBox();
+        box.add_events (Gdk.EventMask.ENTER_NOTIFY_MASK | Gdk.EventMask.LEAVE_NOTIFY_MASK);
 
         panel = new Widgets.Panel (popover_manager);
         panel.realize.connect (on_realize);
@@ -80,17 +83,40 @@
         application.add_accelerator ("<Control>Tab", "app.cycle", null);
         application.add_accelerator ("<Control><Shift>Tab", "app.cycle-back", null);
 
-        add (panel);
+        box.add(panel);
+        if (autohide == true) {
+            box.enter_notify_event.connect (reactivate);
+            box.leave_notify_event.connect (on_idle);
+        }
+
+        add (box);
     }
 
     private bool animation_step () {
         if (panel_displacement <= panel_height * (-1)) {
+            timeout = 0;
             return false;
         }
 
         panel_displacement--;

+        if (autohide == false) { 
-        update_panel_dimensions ();
+            update_panel_dimensions ();
+        }
+        animate_panel ();
+
+        return true;
+    }
+
+    private bool animation_unstep () {
+        if (panel_displacement >= -1 || popover_manager.current_indicator != null) {
+            timeout = 0;
+            return false;
+        }
+
+        panel_displacement++;
+
+        animate_panel ();
 
         return true;
     }
@@ -85,7 +110,32 @@
 
         Services.BackgroundManager.get_default ().initialize (this.monitor_number, panel_height);
 
-        Timeout.add (300 / panel_height, animation_step);
+        if (autohide == false) { 
+            timeout = Timeout.add (300 / panel_height, animation_step);
+        } else {
+            panel_displacement--;
+            animate_panel ();
+        }
+    }
+
+    private bool on_idle () {
+        if (timeout > 0) {
+            Source.remove (timeout);
+        }
+
+        timeout = Timeout.add (100 / panel_height, animation_unstep);
+
+        return true;
+    }
+
+    private bool reactivate () {
+        if (timeout > 0) {
+            Source.remove (timeout);
+        }
+
+        timeout = Timeout.add (100 / panel_height, animation_step);
+
+        return true;
     }
 
     private void update_panel_dimensions () {
@@ -108,6 +153,24 @@
         update_struts ();
     }
 
+    private void animate_panel () {
+        panel_height = panel.get_allocated_height ();
+
+        monitor_number = screen.get_primary_monitor ();
+        Gdk.Rectangle monitor_dimensions;
+        this.screen.get_monitor_geometry (monitor_number, out monitor_dimensions);
+
+        monitor_width = monitor_dimensions.width;
+        monitor_height = monitor_dimensions.height;
+
+        this.set_size_request (monitor_width, (popover_manager.current_indicator != null ? monitor_height : -1));
+
+        monitor_x = monitor_dimensions.x;
+        monitor_y = monitor_dimensions.y;
+
+        this.move (monitor_x, monitor_y - (panel_height + panel_displacement));
+    }
+
     private void update_visual () {
         var visual = this.screen.get_rgba_visual ();