Merge lp:~3v1n0/unity/autohide-intellihide into lp:unity

Proposed by Marco Trevisan (Treviño) on 2011-02-09
Status: Merged
Merged at revision: 834
Proposed branch: lp:~3v1n0/unity/autohide-intellihide
Merge into: lp:unity
Diff against target: 316 lines (+94/-43)
4 files modified
src/Launcher.cpp (+54/-31)
src/Launcher.h (+13/-3)
src/unityshell.cpp (+5/-5)
unityshell.xml.in (+22/-4)
To merge this branch: bzr merge lp:~3v1n0/unity/autohide-intellihide
Reviewer Review Type Date Requested Status
Jason Smith (community) 2011-02-09 Approve on 2011-02-09
Review via email: mp+49010@code.launchpad.net

Description of the Change

This branch includes the changes to allow to set different types of Hiding for the Unity Launcher bar. I've changed the old "autohide" option to "hide_mode", so now you can set these kinds of hide modes:
 - Never: never hide the launcher bar
 - Always: always hide the launcher bar
 - Automatically: hide the bar only if no window currently
   opened is over the launcher bar (like the "old" autohide)
 - When Needed: hide the bar only when the focussed window
   is over the launcher bar (also known as "intelli-hide").

For the "When Needed" feature, I also had to include the support for the "focussed" window in PluginAdapter (it tracks the latest focussed window on every change).

You can see an example of how it works here: http://go.3v1n0.net/e6cm7c

To post a comment you must log in.
lp:~3v1n0/unity/autohide-intellihide updated on 2011-02-09
839. By Marco Trevisan (Treviño) on 2011-02-09

Plugin Adapter Focussed window is not needed, using Compiz activeWindow()

Compiz already knows which is the focussed / active window, using
it instead of my PluginAdapter implementation!

Marco Trevisan (Treviño) (3v1n0) wrote :

I've removed the PluginAdapter focussed window implementation (this was the code: http://paste.ubuntu.com/564958/), since Compiz already gives us that information via the activeWindow function.

Let me know if should re-include the PluginAdapter window_focussed management (maybe it could be useful for other implementations, here's the patch: http://paste.ubuntu.com/564961/)

Jason Smith (jassmith) wrote :

+1 going to rename some of this but good otherwise

Jason Smith (jassmith) wrote :

+1 forgot to hit the accept button

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Launcher.cpp'
2--- src/Launcher.cpp 2011-02-08 03:35:21 +0000
3+++ src/Launcher.cpp 2011-02-09 12:55:32 +0000
4@@ -248,6 +248,7 @@
5 _launcher_action_state = ACTION_NONE;
6 _launch_animation = LAUNCH_ANIMATION_NONE;
7 _urgent_animation = URGENT_ANIMATION_NONE;
8+ _hidemode = LAUNCHER_HIDE_NEVER;
9 _icon_under_mouse = NULL;
10 _icon_mouse_down = NULL;
11 _drag_icon = NULL;
12@@ -281,7 +282,6 @@
13 _autoscroll_handle = 0;
14 _floating = false;
15 _hovered = false;
16- _autohide = false;
17 _hidden = false;
18 _was_hidden = false;
19 _mouse_inside_launcher = false;
20@@ -390,9 +390,8 @@
21 g_variant_builder_add (builder, "{sv}", "dnd-delta", g_variant_new_int32 (_dnd_delta_y));
22 g_variant_builder_add (builder, "{sv}", "floating", g_variant_new_boolean (_floating));
23 g_variant_builder_add (builder, "{sv}", "hovered", g_variant_new_boolean (_hovered));
24- g_variant_builder_add (builder, "{sv}", "autohide", g_variant_new_boolean (_autohide));
25+ g_variant_builder_add (builder, "{sv}", "hidemode", g_variant_new_int32 (_hidemode));
26 g_variant_builder_add (builder, "{sv}", "hidden", g_variant_new_boolean (_hidden));
27- g_variant_builder_add (builder, "{sv}", "autohide", g_variant_new_boolean (_autohide));
28 g_variant_builder_add (builder, "{sv}", "mouse-inside-launcher", g_variant_new_boolean (_mouse_inside_launcher));
29 }
30
31@@ -435,7 +434,7 @@
32
33 float Launcher::AutohideProgress (struct timespec const &current)
34 {
35- if (!_autohide)
36+ if (_hidemode == LAUNCHER_HIDE_NEVER)
37 return 0.0f;
38
39 if (_hidden)
40@@ -974,7 +973,7 @@
41
42 float autohide_progress = AutohideProgress (current);
43 float autohide_offset = 0.0f;
44- if (_autohide && autohide_progress > 0.0f)
45+ if (_hidemode != LAUNCHER_HIDE_NEVER && autohide_progress > 0.0f)
46 {
47 autohide_offset -= geo.width * autohide_progress;
48 }
49@@ -982,7 +981,7 @@
50 // Inform the painter where to paint the box
51 box_geo = geo;
52
53- if (_autohide)
54+ if (_hidemode != LAUNCHER_HIDE_NEVER)
55 box_geo.x += autohide_offset;
56
57 // The functional position we wish to represent for these icons is not smooth. Rather than introducing
58@@ -1145,44 +1144,68 @@
59 SetHidden (false);
60 }
61
62+bool
63+Launcher::CheckIntersectWindow (CompWindow *window)
64+{
65+ nux::Geometry geo = GetGeometry ();
66+ int intersect_types = CompWindowTypeNormalMask | CompWindowTypeDialogMask |
67+ CompWindowTypeModalDialogMask | CompWindowTypeUtilMask;
68+
69+ if (!window || !(window->type () & intersect_types) || !window->isMapped () || !window->isViewable ())
70+ return false;
71+
72+ if (CompRegion (window->inputRect ()).intersects (CompRect (geo.x, geo.y, geo.width, geo.height)))
73+ return true;
74+
75+ return false;
76+}
77+
78 void
79 Launcher::CheckWindowOverLauncher ()
80 {
81 CompWindowList window_list = _screen->windows ();
82 CompWindowList::iterator it;
83- nux::Geometry geo = GetGeometry ();
84-
85- for (it = window_list.begin (); it != window_list.end (); it++)
86- {
87- CompWindow *window = *it;
88- int intersect_types = CompWindowTypeNormalMask | CompWindowTypeDialogMask |
89- CompWindowTypeModalDialogMask | CompWindowTypeUtilMask;
90-
91- if (!(window->type () & intersect_types) || !window->isMapped () || !window->isViewable ())
92- continue;
93-
94- if (CompRegion (window->inputRect ()).intersects (CompRect (geo.x, geo.y, geo.width, geo.height)))
95+ CompWindow *window = NULL;
96+
97+ if (_hidemode == LAUNCHER_HIDE_WHEN_NEEDED)
98+ {
99+ window = _screen->findWindow (_screen->activeWindow ());
100+ if (!CheckIntersectWindow (window))
101+ window = NULL;
102+ }
103+ else
104+ {
105+ for (it = window_list.begin (); it != window_list.end (); it++)
106 {
107- _window_over_launcher = true;
108- EnsureHiddenState ();
109- return;
110+ if (CheckIntersectWindow (*it)) {
111+ window = *it;
112+ break;
113+ }
114 }
115 }
116
117- _window_over_launcher = false;
118+ _window_over_launcher = (window != NULL);
119 EnsureHiddenState ();
120 }
121
122 void
123 Launcher::OnWindowMaybeIntellihide (guint32 xid)
124 {
125- if (_autohide)
126- CheckWindowOverLauncher ();
127+ if (_hidemode != LAUNCHER_HIDE_NEVER)
128+ {
129+ if (_hidemode == LAUNCHER_HIDE_ALWAYS)
130+ {
131+ _window_over_launcher = true;
132+ EnsureHiddenState ();
133+ }
134+ else
135+ CheckWindowOverLauncher ();
136+ }
137 }
138
139 void Launcher::SetupAutohideTimer ()
140 {
141- if (_autohide)
142+ if (_hidemode != LAUNCHER_HIDE_NEVER)
143 {
144 if (_autohide_handle > 0)
145 g_source_remove (_autohide_handle);
146@@ -1190,9 +1213,9 @@
147 }
148 }
149
150-bool Launcher::AutohideEnabled ()
151+Launcher::LauncherHideMode Launcher::GetHideMode ()
152 {
153- return _autohide;
154+ return _hidemode;
155 }
156
157 /* End Launcher Show/Hide logic */
158@@ -1207,12 +1230,12 @@
159 return false;
160 }
161
162-void Launcher::SetAutohide (bool autohide)
163+void Launcher::SetHideMode (LauncherHideMode hidemode)
164 {
165- if (_autohide == autohide)
166+ if (_hidemode == hidemode)
167 return;
168
169- if (autohide)
170+ if (hidemode != LAUNCHER_HIDE_NEVER)
171 {
172 _parent->InputWindowEnableStruts(false);
173 }
174@@ -1223,7 +1246,7 @@
175 _parent->InputWindowEnableStruts(true);
176 }
177
178- _autohide = autohide;
179+ _hidemode = hidemode;
180 EnsureAnimation ();
181 }
182
183
184=== modified file 'src/Launcher.h'
185--- src/Launcher.h 2011-02-08 03:35:21 +0000
186+++ src/Launcher.h 2011-02-09 12:55:32 +0000
187@@ -49,6 +49,14 @@
188 public:
189 typedef enum
190 {
191+ LAUNCHER_HIDE_NEVER,
192+ LAUNCHER_HIDE_ALWAYS,
193+ LAUNCHER_HIDE_AUTOMATICALLY,
194+ LAUNCHER_HIDE_WHEN_NEEDED,
195+ } LauncherHideMode;
196+
197+ typedef enum
198+ {
199 LAUNCH_ANIMATION_NONE,
200 LAUNCH_ANIMATION_PULSE,
201 LAUNCH_ANIMATION_BLINK,
202@@ -81,8 +89,8 @@
203
204 void SetFloating (bool floating);
205
206- void SetAutohide (bool autohide);
207- bool AutohideEnabled ();
208+ void SetHideMode (LauncherHideMode hidemode);
209+ LauncherHideMode GetHideMode ();
210
211 void StartKeyShowLauncher ();
212 void EndKeyShowLauncher ();
213@@ -191,6 +199,7 @@
214 static gboolean OnScrollTimeout (gpointer data);
215
216 void CheckWindowOverLauncher ();
217+ bool CheckIntersectWindow (CompWindow *window);
218
219 float DnDStartProgress (struct timespec const &current);
220 float DnDExitProgress (struct timespec const &current);
221@@ -305,7 +314,6 @@
222
223 bool _hovered;
224 bool _floating;
225- bool _autohide;
226 bool _hidden;
227 bool _was_hidden;
228 bool _mouse_inside_launcher;
229@@ -323,6 +331,8 @@
230 float _launcher_top_y;
231 float _launcher_bottom_y;
232
233+ LauncherHideMode _hidemode;
234+
235 LauncherActionState _launcher_action_state;
236 LaunchAnimation _launch_animation;
237 UrgentAnimation _urgent_animation;
238
239=== modified file 'src/unityshell.cpp'
240--- src/unityshell.cpp 2011-02-07 15:09:36 +0000
241+++ src/unityshell.cpp 2011-02-09 12:55:32 +0000
242@@ -461,8 +461,8 @@
243 {
244 switch (num)
245 {
246- case UnityshellOptions::LauncherAutohide:
247- launcher->SetAutohide (optionGetLauncherAutohide ());
248+ case UnityshellOptions::LauncherHideMode:
249+ launcher->SetHideMode ((Launcher::LauncherHideMode) optionGetLauncherHideMode ());
250 break;
251 case UnityshellOptions::BacklightAlwaysOn:
252 launcher->SetBacklightAlwaysOn (optionGetBacklightAlwaysOn ());
253@@ -537,7 +537,7 @@
254
255 debugger = new DebugDBusInterface (this);
256
257- optionSetLauncherAutohideNotify (boost::bind (&UnityScreen::optionChanged, this, _1, _2));
258+ optionSetLauncherHideModeNotify (boost::bind (&UnityScreen::optionChanged, this, _1, _2));
259 optionSetBacklightAlwaysOnNotify (boost::bind (&UnityScreen::optionChanged, this, _1, _2));
260 optionSetLaunchAnimationNotify (boost::bind (&UnityScreen::optionChanged, this, _1, _2));
261 optionSetUrgentAnimationNotify (boost::bind (&UnityScreen::optionChanged, this, _1, _2));
262@@ -566,7 +566,7 @@
263 {
264 UnityScreen *self = (UnityScreen*) data;
265
266- if (!self->launcher->AutohideEnabled ())
267+ if (self->launcher->GetHideMode () == Launcher::LAUNCHER_HIDE_NEVER)
268 {
269 self->launcherWindow->InputWindowEnableStruts(false);
270 self->launcherWindow->InputWindowEnableStruts(true);
271@@ -641,7 +641,7 @@
272 /* Setup Places */
273 self->placesController = new PlacesController ();
274
275- self->launcher->SetAutohide (true);
276+ self->launcher->SetHideMode (Launcher::LAUNCHER_HIDE_AUTOMATICALLY);
277 self->launcher->SetLaunchAnimation (Launcher::LAUNCH_ANIMATION_PULSE);
278 self->launcher->SetUrgentAnimation (Launcher::URGENT_ANIMATION_WIGGLE);
279 g_timeout_add (2000, &UnityScreen::strutHackTimeout, self);
280
281=== modified file 'unityshell.xml.in'
282--- unityshell.xml.in 2011-02-01 10:26:05 +0000
283+++ unityshell.xml.in 2011-02-09 12:55:32 +0000
284@@ -39,10 +39,28 @@
285 <options>
286 <group>
287 <_short>Behaviour</_short>
288- <option name="launcher_autohide" type="bool">
289- <_short>Autohide Launcher</_short>
290- <_long>Make the launcher hide automatically after some time inactive</_long>
291- <default>true</default>
292+ <option name="launcher_hide_mode" type="int">
293+ <_short>Hide Launcher</_short>
294+ <_long>Make the launcher hide automatically after some time of inactivity: always or just when the focussed window is not over the launcher</_long>
295+ <min>0</min>
296+ <max>3</max>
297+ <default>1</default>
298+ <desc>
299+ <value>0</value>
300+ <_name>Never</_name>
301+ </desc>
302+ <desc>
303+ <value>1</value>
304+ <_name>Always</_name>
305+ </desc>
306+ <desc>
307+ <value>2</value>
308+ <_name>Automatically</_name>
309+ </desc>
310+ <desc>
311+ <value>3</value>
312+ <_name>When Needed</_name>
313+ </desc>
314 </option>
315 <option name="show_launcher" type="key">
316 <_short>Key to show the launcher</_short>