Merge lp:~smspillaz/unity/unity.fix_877778 into lp:unity
- unity.fix_877778
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Andrea Cimitan |
Approved revision: | no longer in the source branch. |
Merged at revision: | 2245 |
Proposed branch: | lp:~smspillaz/unity/unity.fix_877778 |
Merge into: | lp:unity |
Diff against target: |
1721 lines (+1167/-284) 8 files modified
plugins/unityshell/src/UnityShowdesktopHandler.cpp (+215/-0) plugins/unityshell/src/UnityShowdesktopHandler.h (+158/-0) plugins/unityshell/src/inputremover.cpp (+7/-3) plugins/unityshell/src/inputremover.h (+27/-5) plugins/unityshell/src/unityshell.cpp (+180/-228) plugins/unityshell/src/unityshell.h (+37/-47) tests/CMakeLists.txt (+4/-1) tests/test_showdesktop_handler.cpp (+539/-0) |
To merge this branch: | bzr merge lp:~smspillaz/unity/unity.fix_877778 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tim Penhey (community) | Approve | ||
Gord Allott | Pending | ||
Review via email: mp+101065@code.launchpad.net |
This proposal supersedes a proposal from 2012-04-06.
Commit message
Fixes LP #877778 - Introduces tests for UnityShowdeskto
Description of the change
Fixes LP #877778 - Introduces tests for UnityShowdeskto
== Problem ==
See LP #877778 - in fact, Show Desktop mode was completely broken, but the bug there is mainly about the fact that showdesktoped windows would be invisible in the spread. That's now fixed
== Solution ==
Fix UnityShowdeskto
== Test Coverage ==
Split UnityShowdeskto
Gord Allott (gordallott) wrote : Posted in a previous version of this proposal | # |
Tim Penhey (thumper) wrote : Posted in a previous version of this proposal | # |
On Wed 28 Mar 2012 21:47:21 NZDT, Gord Allott wrote:
> Review: Needs Fixing
>
> Great stuff, but needs to conform to our code style :) namely FooBar() methods and _foo instead of mFoo, quick sed should fix it
s/_foo/foo_/
Omer Akram (om26er) wrote : Posted in a previous version of this proposal | # |
has conflicts.
Unity Merger (unity-merger) wrote : Posted in a previous version of this proposal | # |
No commit message specified.
Tim Penhey (thumper) wrote : Posted in a previous version of this proposal | # |
A few style things:
If you are in namespace unity, you should prefix your classes with Unity.
also
s/ ()/()/g
The tests shouldn't be calling the virtual methods. It should be dealing only with the interface methods.
Tim Penhey (thumper) wrote : Posted in a previous version of this proposal | # |
> A few style things:
>
> If you are in namespace unity, you should prefix your classes with Unity.
s/should/should not/
Sam Spilsbury (smspillaz) wrote : Posted in a previous version of this proposal | # |
Style pedantry fixed.
Sam Spilsbury (smspillaz) wrote : Posted in a previous version of this proposal | # |
> The tests shouldn't be calling the virtual methods. It should be dealing only with the interface methods.
As far as I can tell the tests are not calling virtual methods directly (in fact, they can't doing so would raise a compile error ...)
The ON_CALL and EXPECT_CALL macros however do need to be on the virtual methods, because that's what they are mocking.
Tim Penhey (thumper) wrote : Posted in a previous version of this proposal | # |
When testing, entering show desktop, then out again (using Ctrl-Alt-D twice), the title bars of non-maximised windows aren't accepting the mouse, and clicks through. Focusing the window using alt left mouse to move it a bit fixed it.
Tim Penhey (thumper) wrote : | # |
This is fine now. We can fix the style later :)
Unity Merger (unity-merger) wrote : | # |
No commit message specified.
Preview Diff
1 | === added file 'plugins/unityshell/src/UnityShowdesktopHandler.cpp' | |||
2 | --- plugins/unityshell/src/UnityShowdesktopHandler.cpp 1970-01-01 00:00:00 +0000 | |||
3 | +++ plugins/unityshell/src/UnityShowdesktopHandler.cpp 2012-04-06 08:44:20 +0000 | |||
4 | @@ -0,0 +1,215 @@ | |||
5 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
6 | 2 | /* Compiz unity plugin | ||
7 | 3 | * unity.h | ||
8 | 4 | * | ||
9 | 5 | * Copyright (c) 2010-11 Canonical Ltd. | ||
10 | 6 | * | ||
11 | 7 | * This program is free software; you can redistribute it and/or | ||
12 | 8 | * modify it under the terms of the GNU General Public License | ||
13 | 9 | * as published by the Free Software Foundation; either version 3 | ||
14 | 10 | * of the License, or (at your option) any later version. | ||
15 | 11 | * | ||
16 | 12 | * This program is distributed in the hope that it will be useful, | ||
17 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 | 15 | * GNU General Public License for more details. | ||
20 | 16 | * | ||
21 | 17 | * Your own copyright notice would go above. You are free to choose whatever | ||
22 | 18 | * licence you want, just take note that some compiz code is GPL and you will | ||
23 | 19 | * not be able to re-use it if you want to use a different licence. | ||
24 | 20 | */ | ||
25 | 21 | |||
26 | 22 | #include <glib.h> | ||
27 | 23 | #include "UnityShowdesktopHandler.h" | ||
28 | 24 | |||
29 | 25 | namespace unity | ||
30 | 26 | { | ||
31 | 27 | |||
32 | 28 | ShowdesktopHandlerWindowInterface::~ShowdesktopHandlerWindowInterface() | ||
33 | 29 | { | ||
34 | 30 | } | ||
35 | 31 | |||
36 | 32 | /* 300 ms */ | ||
37 | 33 | const unsigned int ShowdesktopHandler::fade_time = 300; | ||
38 | 34 | std::list <ShowdesktopHandlerWindowInterface *> ShowdesktopHandler::animating_windows (0); | ||
39 | 35 | |||
40 | 36 | bool ShowdesktopHandler::ShouldHide (ShowdesktopHandlerWindowInterface *wi) | ||
41 | 37 | { | ||
42 | 38 | if (wi->OverrideRedirect()) | ||
43 | 39 | return false; | ||
44 | 40 | |||
45 | 41 | if (!wi->Managed()) | ||
46 | 42 | return false; | ||
47 | 43 | |||
48 | 44 | if (wi->Grabbed()) | ||
49 | 45 | return false; | ||
50 | 46 | |||
51 | 47 | if (wi->DesktopOrDock()) | ||
52 | 48 | return false; | ||
53 | 49 | |||
54 | 50 | if (wi->SkipTaskbarOrPager()) | ||
55 | 51 | return false; | ||
56 | 52 | |||
57 | 53 | if (wi->Hidden()) | ||
58 | 54 | if ((wi->ShowDesktopMode() || wi->Shaded())) | ||
59 | 55 | return false; | ||
60 | 56 | |||
61 | 57 | return true; | ||
62 | 58 | } | ||
63 | 59 | |||
64 | 60 | guint32 ShowdesktopHandler::inhibiting_xid = 0; | ||
65 | 61 | |||
66 | 62 | void | ||
67 | 63 | ShowdesktopHandler::InhibitLeaveShowdesktopMode (guint32 xid) | ||
68 | 64 | { | ||
69 | 65 | if (!inhibiting_xid) | ||
70 | 66 | inhibiting_xid = xid; | ||
71 | 67 | } | ||
72 | 68 | |||
73 | 69 | void | ||
74 | 70 | ShowdesktopHandler::AllowLeaveShowdesktopMode (guint32 xid) | ||
75 | 71 | { | ||
76 | 72 | if (inhibiting_xid == xid) | ||
77 | 73 | inhibiting_xid = 0; | ||
78 | 74 | } | ||
79 | 75 | |||
80 | 76 | guint32 | ||
81 | 77 | ShowdesktopHandler::InhibitingXid() | ||
82 | 78 | { | ||
83 | 79 | return inhibiting_xid; | ||
84 | 80 | } | ||
85 | 81 | |||
86 | 82 | ShowdesktopHandler::ShowdesktopHandler (ShowdesktopHandlerWindowInterface *wi) : | ||
87 | 83 | showdesktop_handler_window_interface_ (wi), | ||
88 | 84 | remover_ (wi->InputRemover()), | ||
89 | 85 | state_ (StateVisible), | ||
90 | 86 | progress_ (0.0f) | ||
91 | 87 | { | ||
92 | 88 | } | ||
93 | 89 | |||
94 | 90 | ShowdesktopHandler::~ShowdesktopHandler() | ||
95 | 91 | { | ||
96 | 92 | } | ||
97 | 93 | |||
98 | 94 | void ShowdesktopHandler::FadeOut() | ||
99 | 95 | { | ||
100 | 96 | if (state_ != StateVisible && state_ != StateFadeIn) | ||
101 | 97 | return; | ||
102 | 98 | |||
103 | 99 | state_ = ShowdesktopHandler::StateFadeOut; | ||
104 | 100 | progress_ = 0.0f; | ||
105 | 101 | |||
106 | 102 | was_hidden_ = showdesktop_handler_window_interface_->Hidden(); | ||
107 | 103 | |||
108 | 104 | if (!was_hidden_) | ||
109 | 105 | { | ||
110 | 106 | showdesktop_handler_window_interface_->Hide(); | ||
111 | 107 | showdesktop_handler_window_interface_->NotifyHidden(); | ||
112 | 108 | remover_->save(); | ||
113 | 109 | remover_->remove(); | ||
114 | 110 | |||
115 | 111 | if (std::find (animating_windows.begin(), | ||
116 | 112 | animating_windows.end(), | ||
117 | 113 | showdesktop_handler_window_interface_) == animating_windows.end()) | ||
118 | 114 | animating_windows.push_back (showdesktop_handler_window_interface_); | ||
119 | 115 | |||
120 | 116 | } | ||
121 | 117 | } | ||
122 | 118 | |||
123 | 119 | void ShowdesktopHandler::FadeIn() | ||
124 | 120 | { | ||
125 | 121 | if (state_ != StateInvisible && state_ != StateFadeOut) | ||
126 | 122 | return; | ||
127 | 123 | |||
128 | 124 | state_ = ShowdesktopHandler::StateFadeIn; | ||
129 | 125 | |||
130 | 126 | if (!was_hidden_) | ||
131 | 127 | { | ||
132 | 128 | showdesktop_handler_window_interface_->Show(); | ||
133 | 129 | showdesktop_handler_window_interface_->NotifyShown(); | ||
134 | 130 | remover_->restore(); | ||
135 | 131 | |||
136 | 132 | if (std::find (animating_windows.begin(), | ||
137 | 133 | animating_windows.end(), | ||
138 | 134 | showdesktop_handler_window_interface_) == animating_windows.end()) | ||
139 | 135 | animating_windows.push_back(showdesktop_handler_window_interface_); | ||
140 | 136 | } | ||
141 | 137 | } | ||
142 | 138 | |||
143 | 139 | ShowdesktopHandlerWindowInterface::PostPaintAction ShowdesktopHandler::Animate (unsigned int ms) | ||
144 | 140 | { | ||
145 | 141 | float inc = ms / static_cast <float> (fade_time); | ||
146 | 142 | |||
147 | 143 | if (state_ == ShowdesktopHandler::StateFadeOut) | ||
148 | 144 | { | ||
149 | 145 | progress_ += inc; | ||
150 | 146 | if (progress_ >= 1.0f) | ||
151 | 147 | { | ||
152 | 148 | progress_ = 1.0f; | ||
153 | 149 | state_ = StateInvisible; | ||
154 | 150 | } | ||
155 | 151 | } | ||
156 | 152 | else if (state_ == StateFadeIn) | ||
157 | 153 | { | ||
158 | 154 | progress_ -= inc; | ||
159 | 155 | if (progress_ <= 0.0f) | ||
160 | 156 | { | ||
161 | 157 | progress_ = 0.0f; | ||
162 | 158 | state_ = StateVisible; | ||
163 | 159 | } | ||
164 | 160 | } | ||
165 | 161 | else if (state_ == StateVisible) | ||
166 | 162 | return ShowdesktopHandlerWindowInterface::PostPaintAction::Remove; | ||
167 | 163 | else if (state_ == StateInvisible) | ||
168 | 164 | return ShowdesktopHandlerWindowInterface::PostPaintAction::Wait; | ||
169 | 165 | |||
170 | 166 | return ShowdesktopHandlerWindowInterface::PostPaintAction::Damage; | ||
171 | 167 | } | ||
172 | 168 | |||
173 | 169 | void ShowdesktopHandler::PaintOpacity (unsigned short &opacity) | ||
174 | 170 | { | ||
175 | 171 | if (progress_ == 1.0f || progress_ == 0.0f) | ||
176 | 172 | opacity = std::numeric_limits <unsigned short>::max(); | ||
177 | 173 | else | ||
178 | 174 | opacity *= (1.0f - progress_); | ||
179 | 175 | } | ||
180 | 176 | |||
181 | 177 | unsigned int ShowdesktopHandler::GetPaintMask() | ||
182 | 178 | { | ||
183 | 179 | return (progress_ == 1.0f) ? showdesktop_handler_window_interface_->NoCoreInstanceMask() : 0; | ||
184 | 180 | } | ||
185 | 181 | |||
186 | 182 | void ShowdesktopHandler::HandleShapeEvent() | ||
187 | 183 | { | ||
188 | 184 | /* Ignore sent events from the InputRemover */ | ||
189 | 185 | if (remover_) | ||
190 | 186 | { | ||
191 | 187 | remover_->save(); | ||
192 | 188 | remover_->remove(); | ||
193 | 189 | } | ||
194 | 190 | } | ||
195 | 191 | |||
196 | 192 | void ShowdesktopHandler::WindowFocusChangeNotify() | ||
197 | 193 | { | ||
198 | 194 | if (showdesktop_handler_window_interface_->Minimized()) | ||
199 | 195 | { | ||
200 | 196 | for (ShowdesktopHandlerWindowInterface *w : animating_windows) | ||
201 | 197 | w->DisableFocus(); | ||
202 | 198 | |||
203 | 199 | showdesktop_handler_window_interface_->MoveFocusAway(); | ||
204 | 200 | |||
205 | 201 | for (ShowdesktopHandlerWindowInterface *w : animating_windows) | ||
206 | 202 | w->EnableFocus(); | ||
207 | 203 | } | ||
208 | 204 | } | ||
209 | 205 | |||
210 | 206 | void ShowdesktopHandler::UpdateFrameRegion (CompRegion &r) | ||
211 | 207 | { | ||
212 | 208 | r = CompRegion(); | ||
213 | 209 | |||
214 | 210 | /* Ensure no other plugins can touch this frame region */ | ||
215 | 211 | showdesktop_handler_window_interface_->OverrideFrameRegion (r); | ||
216 | 212 | } | ||
217 | 213 | |||
218 | 214 | } | ||
219 | 215 | |||
220 | 0 | 216 | ||
221 | === added file 'plugins/unityshell/src/UnityShowdesktopHandler.h' | |||
222 | --- plugins/unityshell/src/UnityShowdesktopHandler.h 1970-01-01 00:00:00 +0000 | |||
223 | +++ plugins/unityshell/src/UnityShowdesktopHandler.h 2012-04-06 08:44:20 +0000 | |||
224 | @@ -0,0 +1,158 @@ | |||
225 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
226 | 2 | /* Compiz unity plugin | ||
227 | 3 | * unity.h | ||
228 | 4 | * | ||
229 | 5 | * Copyright (c) 2010-11 Canonical Ltd. | ||
230 | 6 | * | ||
231 | 7 | * This program is free software; you can redistribute it and/or | ||
232 | 8 | * modify it under the terms of the GNU General Public License | ||
233 | 9 | * as published by the Free Software Foundation; either version 3 | ||
234 | 10 | * of the License, or (at your option) any later version. | ||
235 | 11 | * | ||
236 | 12 | * This program is distributed in the hope that it will be useful, | ||
237 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
238 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
239 | 15 | * GNU General Public License for more details. | ||
240 | 16 | * | ||
241 | 17 | * Your own copyright notice would go above. You are free to choose whatever | ||
242 | 18 | * licence you want, just take note that some compiz code is GPL and you will | ||
243 | 19 | * not be able to re-use it if you want to use a different licence. | ||
244 | 20 | */ | ||
245 | 21 | #ifndef UNITY_SHOWDESKTOP_HANDLER_H | ||
246 | 22 | #define UNITY_SHOWDESKTOP_HANDLER_H | ||
247 | 23 | |||
248 | 24 | #include <list> | ||
249 | 25 | #include <algorithm> | ||
250 | 26 | #include <core/region.h> | ||
251 | 27 | |||
252 | 28 | #include <gio/gio.h> | ||
253 | 29 | |||
254 | 30 | #include "inputremover.h" | ||
255 | 31 | |||
256 | 32 | namespace unity | ||
257 | 33 | { | ||
258 | 34 | |||
259 | 35 | class ShowdesktopHandlerWindowInterface | ||
260 | 36 | { | ||
261 | 37 | public: | ||
262 | 38 | |||
263 | 39 | enum class PostPaintAction { | ||
264 | 40 | Wait = 0, | ||
265 | 41 | Damage = 1, | ||
266 | 42 | Remove = 2 | ||
267 | 43 | }; | ||
268 | 44 | |||
269 | 45 | virtual ~ShowdesktopHandlerWindowInterface (); | ||
270 | 46 | |||
271 | 47 | void EnableFocus () { DoEnableFocus (); } | ||
272 | 48 | void DisableFocus () { DoDisableFocus (); } | ||
273 | 49 | |||
274 | 50 | bool OverrideRedirect () { return IsOverrideRedirect (); } | ||
275 | 51 | bool Managed () { return IsManaged (); } | ||
276 | 52 | bool Grabbed () { return IsGrabbed (); } | ||
277 | 53 | bool DesktopOrDock () { return IsDesktopOrDock (); } | ||
278 | 54 | bool SkipTaskbarOrPager () { return IsSkipTaskbarOrPager (); } | ||
279 | 55 | bool Hidden () { return IsHidden (); } | ||
280 | 56 | bool Shaded () { return IsShaded (); } | ||
281 | 57 | bool Minimized () { return IsMinimized (); } | ||
282 | 58 | bool ShowDesktopMode () { return IsInShowdesktopMode (); } | ||
283 | 59 | void OverrideFrameRegion (CompRegion &r) { return DoOverrideFrameRegion (r); } | ||
284 | 60 | |||
285 | 61 | void Hide () { DoHide (); } | ||
286 | 62 | void NotifyHidden () { DoNotifyHidden (); } | ||
287 | 63 | void Show () { DoShow (); } | ||
288 | 64 | void NotifyShown () { DoNotifyShown (); } | ||
289 | 65 | void MoveFocusAway () { DoMoveFocusAway (); } | ||
290 | 66 | |||
291 | 67 | PostPaintAction HandleAnimations (unsigned int ms) { return DoHandleAnimations (ms); } | ||
292 | 68 | void AddDamage () { DoAddDamage (); } | ||
293 | 69 | |||
294 | 70 | void DeleteHandler () { DoDeleteHandler (); } | ||
295 | 71 | |||
296 | 72 | unsigned int NoCoreInstanceMask () { return GetNoCoreInstanceMask (); } | ||
297 | 73 | |||
298 | 74 | compiz::WindowInputRemoverInterface::Ptr InputRemover () { return GetInputRemover (); } | ||
299 | 75 | |||
300 | 76 | private: | ||
301 | 77 | |||
302 | 78 | virtual void DoEnableFocus () = 0; | ||
303 | 79 | virtual void DoDisableFocus () = 0; | ||
304 | 80 | |||
305 | 81 | virtual bool IsOverrideRedirect () = 0; | ||
306 | 82 | virtual bool IsManaged () = 0; | ||
307 | 83 | virtual bool IsGrabbed () = 0; | ||
308 | 84 | virtual bool IsDesktopOrDock () = 0; | ||
309 | 85 | |||
310 | 86 | virtual bool IsSkipTaskbarOrPager () = 0; | ||
311 | 87 | virtual bool IsHidden () = 0; | ||
312 | 88 | virtual bool IsInShowdesktopMode () = 0; | ||
313 | 89 | virtual bool IsShaded () = 0; | ||
314 | 90 | |||
315 | 91 | virtual bool IsMinimized () = 0; | ||
316 | 92 | |||
317 | 93 | virtual void DoOverrideFrameRegion (CompRegion &) = 0; | ||
318 | 94 | |||
319 | 95 | virtual void DoHide () = 0; | ||
320 | 96 | virtual void DoNotifyHidden () = 0; | ||
321 | 97 | virtual void DoShow () = 0; | ||
322 | 98 | virtual void DoNotifyShown () = 0; | ||
323 | 99 | |||
324 | 100 | virtual void DoMoveFocusAway () = 0; | ||
325 | 101 | virtual PostPaintAction DoHandleAnimations (unsigned int ms) = 0; | ||
326 | 102 | virtual void DoAddDamage () = 0; | ||
327 | 103 | |||
328 | 104 | virtual void DoDeleteHandler () = 0; | ||
329 | 105 | |||
330 | 106 | virtual unsigned int GetNoCoreInstanceMask () = 0; | ||
331 | 107 | |||
332 | 108 | virtual compiz::WindowInputRemoverInterface::Ptr GetInputRemover () = 0; | ||
333 | 109 | }; | ||
334 | 110 | |||
335 | 111 | class ShowdesktopHandler | ||
336 | 112 | { | ||
337 | 113 | public: | ||
338 | 114 | |||
339 | 115 | ShowdesktopHandler (ShowdesktopHandlerWindowInterface *uwi); | ||
340 | 116 | ~ShowdesktopHandler (); | ||
341 | 117 | |||
342 | 118 | typedef enum { | ||
343 | 119 | StateVisible = 0, | ||
344 | 120 | StateFadeOut = 1, | ||
345 | 121 | StateFadeIn = 2, | ||
346 | 122 | StateInvisible = 3 | ||
347 | 123 | } State; | ||
348 | 124 | |||
349 | 125 | public: | ||
350 | 126 | |||
351 | 127 | void FadeOut (); | ||
352 | 128 | void FadeIn (); | ||
353 | 129 | ShowdesktopHandlerWindowInterface::PostPaintAction Animate (unsigned int ms); | ||
354 | 130 | void PaintOpacity (unsigned short &opacity); | ||
355 | 131 | unsigned int GetPaintMask (); | ||
356 | 132 | void HandleShapeEvent (); | ||
357 | 133 | void WindowFocusChangeNotify (); | ||
358 | 134 | void UpdateFrameRegion (CompRegion &r); | ||
359 | 135 | |||
360 | 136 | ShowdesktopHandler::State GetState (); | ||
361 | 137 | |||
362 | 138 | static const unsigned int fade_time; | ||
363 | 139 | static std::list <ShowdesktopHandlerWindowInterface *> animating_windows; | ||
364 | 140 | static bool ShouldHide (ShowdesktopHandlerWindowInterface *); | ||
365 | 141 | static void InhibitLeaveShowdesktopMode (guint32 xid); | ||
366 | 142 | static void AllowLeaveShowdesktopMode (guint32 xid); | ||
367 | 143 | static guint32 InhibitingXid (); | ||
368 | 144 | |||
369 | 145 | private: | ||
370 | 146 | |||
371 | 147 | ShowdesktopHandlerWindowInterface *showdesktop_handler_window_interface_; | ||
372 | 148 | compiz::WindowInputRemoverInterface::Ptr remover_; | ||
373 | 149 | ShowdesktopHandler::State state_; | ||
374 | 150 | float progress_; | ||
375 | 151 | bool was_hidden_; | ||
376 | 152 | static guint32 inhibiting_xid; | ||
377 | 153 | }; | ||
378 | 154 | |||
379 | 155 | } | ||
380 | 156 | |||
381 | 157 | |||
382 | 158 | #endif | ||
383 | 0 | 159 | ||
384 | === modified file 'plugins/unityshell/src/inputremover.cpp' | |||
385 | --- plugins/unityshell/src/inputremover.cpp 2011-09-28 16:25:42 +0000 | |||
386 | +++ plugins/unityshell/src/inputremover.cpp 2012-04-06 08:44:20 +0000 | |||
387 | @@ -24,6 +24,10 @@ | |||
388 | 24 | #include <cstdio> | 24 | #include <cstdio> |
389 | 25 | #include <cstring> | 25 | #include <cstring> |
390 | 26 | 26 | ||
391 | 27 | compiz::WindowInputRemoverInterface::~WindowInputRemoverInterface () | ||
392 | 28 | { | ||
393 | 29 | } | ||
394 | 30 | |||
395 | 27 | compiz::WindowInputRemover::WindowInputRemover (Display *dpy, | 31 | compiz::WindowInputRemover::WindowInputRemover (Display *dpy, |
396 | 28 | Window xid) : | 32 | Window xid) : |
397 | 29 | mDpy (dpy), | 33 | mDpy (dpy), |
398 | @@ -203,7 +207,7 @@ | |||
399 | 203 | } | 207 | } |
400 | 204 | 208 | ||
401 | 205 | bool | 209 | bool |
403 | 206 | compiz::WindowInputRemover::save () | 210 | compiz::WindowInputRemover::saveInput () |
404 | 207 | { | 211 | { |
405 | 208 | XRectangle *rects; | 212 | XRectangle *rects; |
406 | 209 | int count = 0, ordering; | 213 | int count = 0, ordering; |
407 | @@ -267,7 +271,7 @@ | |||
408 | 267 | } | 271 | } |
409 | 268 | 272 | ||
410 | 269 | bool | 273 | bool |
412 | 270 | compiz::WindowInputRemover::remove () | 274 | compiz::WindowInputRemover::removeInput () |
413 | 271 | { | 275 | { |
414 | 272 | if (!mNInputRects) | 276 | if (!mNInputRects) |
415 | 273 | if (!save ()) | 277 | if (!save ()) |
416 | @@ -290,7 +294,7 @@ | |||
417 | 290 | } | 294 | } |
418 | 291 | 295 | ||
419 | 292 | bool | 296 | bool |
421 | 293 | compiz::WindowInputRemover::restore () | 297 | compiz::WindowInputRemover::restoreInput () |
422 | 294 | { | 298 | { |
423 | 295 | XShapeSelectInput (mDpy, mShapeWindow, NoEventMask); | 299 | XShapeSelectInput (mDpy, mShapeWindow, NoEventMask); |
424 | 296 | 300 | ||
425 | 297 | 301 | ||
426 | === modified file 'plugins/unityshell/src/inputremover.h' | |||
427 | --- plugins/unityshell/src/inputremover.h 2011-09-13 12:52:31 +0000 | |||
428 | +++ plugins/unityshell/src/inputremover.h 2012-04-06 08:44:20 +0000 | |||
429 | @@ -22,6 +22,8 @@ | |||
430 | 22 | #ifndef _COMPIZ_INPUTREMOVER_H | 22 | #ifndef _COMPIZ_INPUTREMOVER_H |
431 | 23 | #define _COMPIZ_INPUTREMOVER_H | 23 | #define _COMPIZ_INPUTREMOVER_H |
432 | 24 | 24 | ||
433 | 25 | #include <memory> | ||
434 | 26 | |||
435 | 25 | #include <X11/Xlib.h> | 27 | #include <X11/Xlib.h> |
436 | 26 | #include <X11/Xatom.h> | 28 | #include <X11/Xatom.h> |
437 | 27 | #include <X11/extensions/shape.h> | 29 | #include <X11/extensions/shape.h> |
438 | @@ -29,19 +31,39 @@ | |||
439 | 29 | // Will be merged back into compiz | 31 | // Will be merged back into compiz |
440 | 30 | namespace compiz { | 32 | namespace compiz { |
441 | 31 | 33 | ||
443 | 32 | class WindowInputRemover | 34 | class WindowInputRemoverInterface |
444 | 35 | { | ||
445 | 36 | public: | ||
446 | 37 | |||
447 | 38 | typedef std::shared_ptr <WindowInputRemoverInterface> Ptr; | ||
448 | 39 | |||
449 | 40 | bool save () { return saveInput (); } | ||
450 | 41 | bool remove () { return removeInput (); } | ||
451 | 42 | bool restore () { return restoreInput (); } | ||
452 | 43 | |||
453 | 44 | virtual ~WindowInputRemoverInterface (); | ||
454 | 45 | |||
455 | 46 | protected: | ||
456 | 47 | |||
457 | 48 | virtual bool saveInput () = 0; | ||
458 | 49 | virtual bool removeInput () = 0; | ||
459 | 50 | virtual bool restoreInput () = 0; | ||
460 | 51 | }; | ||
461 | 52 | |||
462 | 53 | class WindowInputRemover : | ||
463 | 54 | public WindowInputRemoverInterface | ||
464 | 33 | { | 55 | { |
465 | 34 | public: | 56 | public: |
466 | 35 | 57 | ||
467 | 36 | WindowInputRemover (Display *, Window xid); | 58 | WindowInputRemover (Display *, Window xid); |
468 | 37 | ~WindowInputRemover (); | 59 | ~WindowInputRemover (); |
469 | 38 | 60 | ||
470 | 39 | bool save (); | ||
471 | 40 | bool remove (); | ||
472 | 41 | bool restore (); | ||
473 | 42 | |||
474 | 43 | private: | 61 | private: |
475 | 44 | 62 | ||
476 | 63 | bool saveInput (); | ||
477 | 64 | bool removeInput (); | ||
478 | 65 | bool restoreInput (); | ||
479 | 66 | |||
480 | 45 | void sendShapeNotify (); | 67 | void sendShapeNotify (); |
481 | 46 | 68 | ||
482 | 47 | Display *mDpy; | 69 | Display *mDpy; |
483 | 48 | 70 | ||
484 | === modified file 'plugins/unityshell/src/unityshell.cpp' | |||
485 | --- plugins/unityshell/src/unityshell.cpp 2012-04-05 23:28:43 +0000 | |||
486 | +++ plugins/unityshell/src/unityshell.cpp 2012-04-06 08:44:20 +0000 | |||
487 | @@ -963,7 +963,9 @@ | |||
488 | 963 | { | 963 | { |
489 | 964 | for (CompWindow *w : screen->windows ()) | 964 | for (CompWindow *w : screen->windows ()) |
490 | 965 | { | 965 | { |
492 | 966 | if (UnityShowdesktopHandler::shouldHide (w)) | 966 | UnityWindow *uw = UnityWindow::get (w); |
493 | 967 | |||
494 | 968 | if (ShowdesktopHandler::ShouldHide (static_cast <ShowdesktopHandlerWindowInterface *> (uw))) | ||
495 | 967 | { | 969 | { |
496 | 968 | UnityWindow::get (w)->enterShowDesktop (); | 970 | UnityWindow::get (w)->enterShowDesktop (); |
497 | 969 | // the animation plugin does strange things here ... | 971 | // the animation plugin does strange things here ... |
498 | @@ -1000,16 +1002,16 @@ | |||
499 | 1000 | /* Where a window is inhibiting, only allow the window | 1002 | /* Where a window is inhibiting, only allow the window |
500 | 1001 | * that is inhibiting the leave show desktop to actually | 1003 | * that is inhibiting the leave show desktop to actually |
501 | 1002 | * fade in again - all other windows should remain faded out */ | 1004 | * fade in again - all other windows should remain faded out */ |
503 | 1003 | if (!UnityShowdesktopHandler::inhibitingXid ()) | 1005 | if (!ShowdesktopHandler::InhibitingXid ()) |
504 | 1004 | { | 1006 | { |
505 | 1005 | for (CompWindow *cw : screen->windows ()) | 1007 | for (CompWindow *cw : screen->windows ()) |
506 | 1006 | { | 1008 | { |
507 | 1007 | if (cw->inShowDesktopMode ()) | 1009 | if (cw->inShowDesktopMode ()) |
508 | 1008 | { | 1010 | { |
513 | 1009 | UnityWindow::get (cw)->leaveShowDesktop (); | 1011 | UnityWindow::get (cw)->leaveShowDesktop (); |
514 | 1010 | // the animation plugin does strange things here ... | 1012 | // the animation plugin does strange things here ... |
515 | 1011 | // if this notification is sent | 1013 | // if this notification is sent |
516 | 1012 | //cw->windowNotify (CompWindowNotifyLeaveShowDesktopMode); | 1014 | //cw->windowNotify (CompWindowNotifyLeaveShowDesktopMode); |
517 | 1013 | } | 1015 | } |
518 | 1014 | } | 1016 | } |
519 | 1015 | 1017 | ||
520 | @@ -1019,12 +1021,12 @@ | |||
521 | 1019 | } | 1021 | } |
522 | 1020 | else | 1022 | else |
523 | 1021 | { | 1023 | { |
525 | 1022 | CompWindow *cw = screen->findWindow (UnityShowdesktopHandler::inhibitingXid ()); | 1024 | CompWindow *cw = screen->findWindow (ShowdesktopHandler::InhibitingXid ()); |
526 | 1023 | if (cw) | 1025 | if (cw) |
527 | 1024 | { | 1026 | { |
528 | 1025 | if (cw->inShowDesktopMode ()) | 1027 | if (cw->inShowDesktopMode ()) |
529 | 1026 | { | 1028 | { |
531 | 1027 | UnityWindow::get (cw)->leaveShowDesktop (); | 1029 | UnityWindow::get (cw)->leaveShowDesktop (); |
532 | 1028 | } | 1030 | } |
533 | 1029 | } | 1031 | } |
534 | 1030 | } | 1032 | } |
535 | @@ -1033,227 +1035,161 @@ | |||
536 | 1033 | void UnityWindow::enterShowDesktop () | 1035 | void UnityWindow::enterShowDesktop () |
537 | 1034 | { | 1036 | { |
538 | 1035 | if (!mShowdesktopHandler) | 1037 | if (!mShowdesktopHandler) |
540 | 1036 | mShowdesktopHandler = new UnityShowdesktopHandler (window); | 1038 | mShowdesktopHandler = new ShowdesktopHandler (static_cast <ShowdesktopHandlerWindowInterface *> (this)); |
541 | 1037 | 1039 | ||
542 | 1038 | window->setShowDesktopMode (true); | 1040 | window->setShowDesktopMode (true); |
544 | 1039 | mShowdesktopHandler->fadeOut (); | 1041 | mShowdesktopHandler->FadeOut (); |
545 | 1040 | } | 1042 | } |
546 | 1041 | 1043 | ||
547 | 1042 | void UnityWindow::leaveShowDesktop () | 1044 | void UnityWindow::leaveShowDesktop () |
548 | 1043 | { | 1045 | { |
549 | 1044 | if (mShowdesktopHandler) | 1046 | if (mShowdesktopHandler) |
550 | 1045 | { | 1047 | { |
552 | 1046 | mShowdesktopHandler->fadeIn (); | 1048 | mShowdesktopHandler->FadeIn (); |
553 | 1047 | window->setShowDesktopMode (false); | 1049 | window->setShowDesktopMode (false); |
554 | 1048 | delete mShowdesktopHandler; | ||
555 | 1049 | mShowdesktopHandler = NULL; | ||
556 | 1050 | } | 1050 | } |
557 | 1051 | } | 1051 | } |
558 | 1052 | 1052 | ||
559 | 1053 | void UnityWindow::activate () | 1053 | void UnityWindow::activate () |
560 | 1054 | { | 1054 | { |
562 | 1055 | UnityShowdesktopHandler::inhibitLeaveShowdesktopMode (window->id ()); | 1055 | ShowdesktopHandler::InhibitLeaveShowdesktopMode (window->id ()); |
563 | 1056 | window->activate (); | 1056 | window->activate (); |
569 | 1057 | UnityShowdesktopHandler::allowLeaveShowdesktopMode (window->id ()); | 1057 | ShowdesktopHandler::AllowLeaveShowdesktopMode (window->id ()); |
570 | 1058 | } | 1058 | } |
571 | 1059 | 1059 | ||
572 | 1060 | bool UnityWindow::handleAnimations (unsigned int ms) | 1060 | void UnityWindow::DoEnableFocus () |
573 | 1061 | { | 1061 | { |
574 | 1062 | window->focusSetEnabled (this, true); | ||
575 | 1063 | } | ||
576 | 1064 | |||
577 | 1065 | void UnityWindow::DoDisableFocus () | ||
578 | 1066 | { | ||
579 | 1067 | window->focusSetEnabled (this, false); | ||
580 | 1068 | } | ||
581 | 1069 | |||
582 | 1070 | bool UnityWindow::IsOverrideRedirect () | ||
583 | 1071 | { | ||
584 | 1072 | return window->overrideRedirect (); | ||
585 | 1073 | } | ||
586 | 1074 | |||
587 | 1075 | bool UnityWindow::IsManaged () | ||
588 | 1076 | { | ||
589 | 1077 | return window->managed (); | ||
590 | 1078 | } | ||
591 | 1079 | |||
592 | 1080 | bool UnityWindow::IsGrabbed () | ||
593 | 1081 | { | ||
594 | 1082 | return window->grabbed (); | ||
595 | 1083 | } | ||
596 | 1084 | |||
597 | 1085 | bool UnityWindow::IsDesktopOrDock () | ||
598 | 1086 | { | ||
599 | 1087 | return (window->type () & (CompWindowTypeDesktopMask | CompWindowTypeDockMask)); | ||
600 | 1088 | } | ||
601 | 1089 | |||
602 | 1090 | bool UnityWindow::IsSkipTaskbarOrPager () | ||
603 | 1091 | { | ||
604 | 1092 | return (window->state () & (CompWindowStateSkipTaskbarMask | CompWindowStateSkipPagerMask)); | ||
605 | 1093 | } | ||
606 | 1094 | |||
607 | 1095 | bool UnityWindow::IsInShowdesktopMode () | ||
608 | 1096 | { | ||
609 | 1097 | return window->inShowDesktopMode (); | ||
610 | 1098 | } | ||
611 | 1099 | |||
612 | 1100 | bool UnityWindow::IsHidden () | ||
613 | 1101 | { | ||
614 | 1102 | return window->state () & CompWindowStateHiddenMask; | ||
615 | 1103 | } | ||
616 | 1104 | |||
617 | 1105 | bool UnityWindow::IsShaded () | ||
618 | 1106 | { | ||
619 | 1107 | return window->shaded (); | ||
620 | 1108 | } | ||
621 | 1109 | |||
622 | 1110 | bool UnityWindow::IsMinimized () | ||
623 | 1111 | { | ||
624 | 1112 | return window->minimized (); | ||
625 | 1113 | } | ||
626 | 1114 | |||
627 | 1115 | void UnityWindow::DoOverrideFrameRegion (CompRegion ®ion) | ||
628 | 1116 | { | ||
629 | 1117 | unsigned int oldUpdateFrameRegionIndex = window->updateFrameRegionGetCurrentIndex (); | ||
630 | 1118 | |||
631 | 1119 | window->updateFrameRegionSetCurrentIndex (MAXSHORT); | ||
632 | 1120 | window->updateFrameRegion (region); | ||
633 | 1121 | window->updateFrameRegionSetCurrentIndex (oldUpdateFrameRegionIndex); | ||
634 | 1122 | } | ||
635 | 1123 | |||
636 | 1124 | void UnityWindow::DoHide () | ||
637 | 1125 | { | ||
638 | 1126 | window->changeState (window->state () | CompWindowStateHiddenMask); | ||
639 | 1127 | } | ||
640 | 1128 | |||
641 | 1129 | void UnityWindow::DoNotifyHidden () | ||
642 | 1130 | { | ||
643 | 1131 | window->windowNotify (CompWindowNotifyHide); | ||
644 | 1132 | } | ||
645 | 1133 | |||
646 | 1134 | void UnityWindow::DoShow () | ||
647 | 1135 | { | ||
648 | 1136 | window->changeState (window->state () & ~(CompWindowStateHiddenMask)); | ||
649 | 1137 | } | ||
650 | 1138 | |||
651 | 1139 | void UnityWindow::DoNotifyShown () | ||
652 | 1140 | { | ||
653 | 1141 | window->windowNotify (CompWindowNotifyShow); | ||
654 | 1142 | } | ||
655 | 1143 | |||
656 | 1144 | void UnityWindow::DoMoveFocusAway () | ||
657 | 1145 | { | ||
658 | 1146 | window->moveInputFocusToOtherWindow (); | ||
659 | 1147 | } | ||
660 | 1148 | |||
661 | 1149 | ShowdesktopHandlerWindowInterface::PostPaintAction UnityWindow::DoHandleAnimations (unsigned int ms) | ||
662 | 1150 | { | ||
663 | 1151 | ShowdesktopHandlerWindowInterface::PostPaintAction action = ShowdesktopHandlerWindowInterface::PostPaintAction::Wait; | ||
664 | 1152 | |||
665 | 1062 | if (mShowdesktopHandler) | 1153 | if (mShowdesktopHandler) |
826 | 1063 | if (mShowdesktopHandler->animate (ms)) | 1154 | action = mShowdesktopHandler->Animate (ms); |
827 | 1064 | { | 1155 | |
828 | 1065 | delete mShowdesktopHandler; | 1156 | return action; |
829 | 1066 | mShowdesktopHandler = NULL; | 1157 | } |
830 | 1067 | return true; | 1158 | |
831 | 1068 | } | 1159 | void UnityWindow::DoAddDamage () |
832 | 1069 | 1160 | { | |
833 | 1070 | return false; | 1161 | cWindow->addDamage (); |
834 | 1071 | } | 1162 | } |
835 | 1072 | 1163 | ||
836 | 1073 | /* 300 ms */ | 1164 | void UnityWindow::DoDeleteHandler () |
837 | 1074 | const unsigned int UnityShowdesktopHandler::fade_time = 300; | 1165 | { |
838 | 1075 | CompWindowList UnityShowdesktopHandler::animating_windows (0); | 1166 | delete mShowdesktopHandler; |
839 | 1076 | 1167 | mShowdesktopHandler = NULL; | |
840 | 1077 | bool UnityShowdesktopHandler::shouldHide (CompWindow *w) | 1168 | |
841 | 1078 | { | 1169 | window->updateFrameRegion (); |
842 | 1079 | if (w->overrideRedirect ()) | 1170 | } |
843 | 1080 | return false; | 1171 | |
844 | 1081 | 1172 | compiz::WindowInputRemoverInterface::Ptr | |
845 | 1082 | if (!w->managed ()) | 1173 | UnityWindow::GetInputRemover () |
846 | 1083 | return false; | 1174 | { |
847 | 1084 | 1175 | return compiz::WindowInputRemoverInterface::Ptr (new compiz::WindowInputRemover (screen->dpy (), window->id ())); | |
848 | 1085 | if (w->grabbed ()) | 1176 | } |
849 | 1086 | return false; | 1177 | |
850 | 1087 | 1178 | unsigned int | |
851 | 1088 | if (w->wmType () & (CompWindowTypeDesktopMask | | 1179 | UnityWindow::GetNoCoreInstanceMask () |
852 | 1089 | CompWindowTypeDockMask)) | 1180 | { |
853 | 1090 | return false; | 1181 | return PAINT_WINDOW_NO_CORE_INSTANCE_MASK; |
854 | 1091 | 1182 | } | |
855 | 1092 | if (w->state () & (CompWindowStateSkipPagerMask | | 1183 | |
856 | 1093 | CompWindowStateSkipTaskbarMask)) | 1184 | void UnityWindow::handleEvent (XEvent *event) |
857 | 1094 | return false; | 1185 | { |
858 | 1095 | 1186 | if (screen->XShape () && | |
859 | 1096 | if ((w->state () & CompWindowStateHiddenMask)) | 1187 | event->type == screen->shapeEvent () + ShapeNotify && |
700 | 1097 | if (!(w->inShowDesktopMode () || w->shaded ())) | ||
701 | 1098 | return false; | ||
702 | 1099 | |||
703 | 1100 | return true; | ||
704 | 1101 | } | ||
705 | 1102 | |||
706 | 1103 | guint32 UnityShowdesktopHandler::mInhibitingXid = 0; | ||
707 | 1104 | |||
708 | 1105 | void | ||
709 | 1106 | UnityShowdesktopHandler::inhibitLeaveShowdesktopMode (guint32 xid) | ||
710 | 1107 | { | ||
711 | 1108 | if (!mInhibitingXid) | ||
712 | 1109 | mInhibitingXid = xid; | ||
713 | 1110 | } | ||
714 | 1111 | |||
715 | 1112 | void | ||
716 | 1113 | UnityShowdesktopHandler::allowLeaveShowdesktopMode (guint32 xid) | ||
717 | 1114 | { | ||
718 | 1115 | if (mInhibitingXid == xid) | ||
719 | 1116 | mInhibitingXid = 0; | ||
720 | 1117 | } | ||
721 | 1118 | |||
722 | 1119 | guint32 | ||
723 | 1120 | UnityShowdesktopHandler::inhibitingXid () | ||
724 | 1121 | { | ||
725 | 1122 | return mInhibitingXid; | ||
726 | 1123 | } | ||
727 | 1124 | |||
728 | 1125 | UnityShowdesktopHandler::UnityShowdesktopHandler (CompWindow *w) : | ||
729 | 1126 | mWindow (w), | ||
730 | 1127 | mRemover (new compiz::WindowInputRemover (screen->dpy (), w->id ())), | ||
731 | 1128 | mState (Visible), | ||
732 | 1129 | mProgress (0.0f) | ||
733 | 1130 | { | ||
734 | 1131 | } | ||
735 | 1132 | |||
736 | 1133 | UnityShowdesktopHandler::~UnityShowdesktopHandler () | ||
737 | 1134 | { | ||
738 | 1135 | if (mRemover) | ||
739 | 1136 | delete mRemover; | ||
740 | 1137 | } | ||
741 | 1138 | |||
742 | 1139 | void UnityShowdesktopHandler::fadeOut () | ||
743 | 1140 | { | ||
744 | 1141 | mState = UnityShowdesktopHandler::FadeOut; | ||
745 | 1142 | mProgress = 1.0f; | ||
746 | 1143 | |||
747 | 1144 | mWasHidden = mWindow->state () & CompWindowStateHiddenMask; | ||
748 | 1145 | |||
749 | 1146 | if (!mWasHidden) | ||
750 | 1147 | { | ||
751 | 1148 | mWindow->changeState (mWindow->state () | CompWindowStateHiddenMask); | ||
752 | 1149 | mWindow->windowNotify (CompWindowNotifyHide); | ||
753 | 1150 | mRemover->save (); | ||
754 | 1151 | mRemover->remove (); | ||
755 | 1152 | } | ||
756 | 1153 | |||
757 | 1154 | CompositeWindow::get (mWindow)->addDamage (); | ||
758 | 1155 | |||
759 | 1156 | if (std::find (animating_windows.begin(), | ||
760 | 1157 | animating_windows.end(), | ||
761 | 1158 | mWindow) == animating_windows.end()) | ||
762 | 1159 | animating_windows.push_back(mWindow); | ||
763 | 1160 | } | ||
764 | 1161 | |||
765 | 1162 | void UnityShowdesktopHandler::fadeIn () | ||
766 | 1163 | { | ||
767 | 1164 | mState = UnityShowdesktopHandler::FadeIn; | ||
768 | 1165 | |||
769 | 1166 | if (!mWasHidden) | ||
770 | 1167 | { | ||
771 | 1168 | mWindow->changeState (mWindow->state () & ~CompWindowStateHiddenMask); | ||
772 | 1169 | mWindow->windowNotify (CompWindowNotifyShow); | ||
773 | 1170 | mRemover->restore (); | ||
774 | 1171 | } | ||
775 | 1172 | |||
776 | 1173 | CompositeWindow::get (mWindow)->addDamage (); | ||
777 | 1174 | } | ||
778 | 1175 | |||
779 | 1176 | bool UnityShowdesktopHandler::animate (unsigned int ms) | ||
780 | 1177 | { | ||
781 | 1178 | float inc = fade_time / (float) ms; | ||
782 | 1179 | |||
783 | 1180 | if (mState == UnityShowdesktopHandler::FadeOut) | ||
784 | 1181 | { | ||
785 | 1182 | mProgress -= inc; | ||
786 | 1183 | if (mProgress <= 0.0f) | ||
787 | 1184 | { | ||
788 | 1185 | mProgress = 0.0f; | ||
789 | 1186 | mState = Invisible; | ||
790 | 1187 | } | ||
791 | 1188 | else | ||
792 | 1189 | CompositeWindow::get (mWindow)->addDamage (); | ||
793 | 1190 | } | ||
794 | 1191 | else if (mState == FadeIn) | ||
795 | 1192 | { | ||
796 | 1193 | mProgress += inc; | ||
797 | 1194 | if (mProgress >= 1.0f) | ||
798 | 1195 | { | ||
799 | 1196 | mProgress = 1.0f; | ||
800 | 1197 | mState = Visible; | ||
801 | 1198 | |||
802 | 1199 | return true; | ||
803 | 1200 | } | ||
804 | 1201 | else | ||
805 | 1202 | CompositeWindow::get (mWindow)->addDamage (); | ||
806 | 1203 | } | ||
807 | 1204 | |||
808 | 1205 | return false; | ||
809 | 1206 | } | ||
810 | 1207 | |||
811 | 1208 | void UnityShowdesktopHandler::paintAttrib (GLWindowPaintAttrib &attrib) | ||
812 | 1209 | { | ||
813 | 1210 | attrib.opacity = static_cast <int> (static_cast <float> (attrib.opacity) * mProgress); | ||
814 | 1211 | } | ||
815 | 1212 | |||
816 | 1213 | unsigned int UnityShowdesktopHandler::getPaintMask () | ||
817 | 1214 | { | ||
818 | 1215 | return 0; | ||
819 | 1216 | } | ||
820 | 1217 | |||
821 | 1218 | void UnityShowdesktopHandler::handleEvent (XEvent *event) | ||
822 | 1219 | { | ||
823 | 1220 | /* Ignore sent events from the InputRemover */ | ||
824 | 1221 | if (screen->XShape () && event->type == | ||
825 | 1222 | screen->shapeEvent () + ShapeNotify && | ||
860 | 1223 | !event->xany.send_event) | 1188 | !event->xany.send_event) |
861 | 1224 | { | 1189 | { |
894 | 1225 | if (mRemover) | 1190 | if (mShowdesktopHandler) |
895 | 1226 | { | 1191 | mShowdesktopHandler->HandleShapeEvent (); |
896 | 1227 | mRemover->save (); | 1192 | } |
865 | 1228 | mRemover->remove (); | ||
866 | 1229 | } | ||
867 | 1230 | } | ||
868 | 1231 | } | ||
869 | 1232 | |||
870 | 1233 | void UnityShowdesktopHandler::windowNotify (CompWindowNotify n) | ||
871 | 1234 | { | ||
872 | 1235 | if (n == CompWindowNotifyFocusChange && mWindow->minimized ()) | ||
873 | 1236 | { | ||
874 | 1237 | for (CompWindow *w : animating_windows) | ||
875 | 1238 | w->focusSetEnabled (UnityWindow::get (w), false); | ||
876 | 1239 | |||
877 | 1240 | mWindow->moveInputFocusToOtherWindow (); | ||
878 | 1241 | |||
879 | 1242 | for (CompWindow *w : animating_windows) | ||
880 | 1243 | w->focusSetEnabled (UnityWindow::get (w), true); | ||
881 | 1244 | } | ||
882 | 1245 | } | ||
883 | 1246 | |||
884 | 1247 | void UnityShowdesktopHandler::updateFrameRegion (CompRegion &r) | ||
885 | 1248 | { | ||
886 | 1249 | unsigned int oldUpdateFrameRegionIndex; | ||
887 | 1250 | r = CompRegion (); | ||
888 | 1251 | |||
889 | 1252 | /* Ensure no other plugins can touch this frame region */ | ||
890 | 1253 | oldUpdateFrameRegionIndex = mWindow->updateFrameRegionGetCurrentIndex (); | ||
891 | 1254 | mWindow->updateFrameRegionSetCurrentIndex (MAXSHORT); | ||
892 | 1255 | mWindow->updateFrameRegion (r); | ||
893 | 1256 | mWindow->updateFrameRegionSetCurrentIndex (oldUpdateFrameRegionIndex); | ||
897 | 1257 | } | 1193 | } |
898 | 1258 | 1194 | ||
899 | 1259 | /* called whenever we need to repaint parts of the screen */ | 1195 | /* called whenever we need to repaint parts of the screen */ |
900 | @@ -1335,16 +1271,10 @@ | |||
901 | 1335 | 1271 | ||
902 | 1336 | void UnityScreen::preparePaint(int ms) | 1272 | void UnityScreen::preparePaint(int ms) |
903 | 1337 | { | 1273 | { |
904 | 1338 | CompWindowList remove_windows; | ||
905 | 1339 | |||
906 | 1340 | cScreen->preparePaint(ms); | 1274 | cScreen->preparePaint(ms); |
907 | 1341 | 1275 | ||
914 | 1342 | for (CompWindow *w : UnityShowdesktopHandler::animating_windows) | 1276 | for (ShowdesktopHandlerWindowInterface *wi : ShowdesktopHandler::animating_windows) |
915 | 1343 | if (UnityWindow::get (w)->handleAnimations (ms)) | 1277 | wi->HandleAnimations (ms); |
910 | 1344 | remove_windows.push_back(w); | ||
911 | 1345 | |||
912 | 1346 | for (CompWindow *w : remove_windows) | ||
913 | 1347 | UnityShowdesktopHandler::animating_windows.remove (w); | ||
916 | 1348 | 1278 | ||
917 | 1349 | if (damaged) | 1279 | if (damaged) |
918 | 1350 | { | 1280 | { |
919 | @@ -1354,6 +1284,28 @@ | |||
920 | 1354 | 1284 | ||
921 | 1355 | } | 1285 | } |
922 | 1356 | 1286 | ||
923 | 1287 | void UnityScreen::donePaint() | ||
924 | 1288 | { | ||
925 | 1289 | std::list <ShowdesktopHandlerWindowInterface *> remove_windows; | ||
926 | 1290 | |||
927 | 1291 | for (ShowdesktopHandlerWindowInterface *wi : ShowdesktopHandler::animating_windows) | ||
928 | 1292 | { | ||
929 | 1293 | ShowdesktopHandlerWindowInterface::PostPaintAction action = wi->HandleAnimations (0); | ||
930 | 1294 | if (action == ShowdesktopHandlerWindowInterface::PostPaintAction::Remove) | ||
931 | 1295 | remove_windows.push_back(wi); | ||
932 | 1296 | else if (action == ShowdesktopHandlerWindowInterface::PostPaintAction::Damage) | ||
933 | 1297 | wi->AddDamage (); | ||
934 | 1298 | } | ||
935 | 1299 | |||
936 | 1300 | for (ShowdesktopHandlerWindowInterface *wi : remove_windows) | ||
937 | 1301 | { | ||
938 | 1302 | wi->DeleteHandler (); | ||
939 | 1303 | ShowdesktopHandler::animating_windows.remove (wi); | ||
940 | 1304 | } | ||
941 | 1305 | |||
942 | 1306 | cScreen->donePaint (); | ||
943 | 1307 | } | ||
944 | 1308 | |||
945 | 1357 | /* Grab changed nux regions and add damage rects for them */ | 1309 | /* Grab changed nux regions and add damage rects for them */ |
946 | 1358 | void UnityScreen::damageNuxRegions() | 1310 | void UnityScreen::damageNuxRegions() |
947 | 1359 | { | 1311 | { |
948 | @@ -1489,7 +1441,7 @@ | |||
949 | 1489 | break; | 1441 | break; |
950 | 1490 | } | 1442 | } |
951 | 1491 | case MapRequest: | 1443 | case MapRequest: |
953 | 1492 | UnityShowdesktopHandler::inhibitLeaveShowdesktopMode (event->xmaprequest.window); | 1444 | ShowdesktopHandler::InhibitLeaveShowdesktopMode (event->xmaprequest.window); |
954 | 1493 | break; | 1445 | break; |
955 | 1494 | default: | 1446 | default: |
956 | 1495 | if (screen->shapeEvent () + ShapeNotify == event->type) | 1447 | if (screen->shapeEvent () + ShapeNotify == event->type) |
957 | @@ -1501,8 +1453,7 @@ | |||
958 | 1501 | { | 1453 | { |
959 | 1502 | UnityWindow *uw = UnityWindow::get (w); | 1454 | UnityWindow *uw = UnityWindow::get (w); |
960 | 1503 | 1455 | ||
963 | 1504 | if (uw->mShowdesktopHandler) | 1456 | uw->handleEvent(event); |
962 | 1505 | uw->mShowdesktopHandler->handleEvent(event); | ||
964 | 1506 | } | 1457 | } |
965 | 1507 | } | 1458 | } |
966 | 1508 | break; | 1459 | break; |
967 | @@ -1523,7 +1474,7 @@ | |||
968 | 1523 | } | 1474 | } |
969 | 1524 | break; | 1475 | break; |
970 | 1525 | case MapRequest: | 1476 | case MapRequest: |
972 | 1526 | UnityShowdesktopHandler::allowLeaveShowdesktopMode (event->xmaprequest.window); | 1477 | ShowdesktopHandler::AllowLeaveShowdesktopMode (event->xmaprequest.window); |
973 | 1527 | break; | 1478 | break; |
974 | 1528 | } | 1479 | } |
975 | 1529 | 1480 | ||
976 | @@ -2235,8 +2186,8 @@ | |||
977 | 2235 | } | 2186 | } |
978 | 2236 | else if (mShowdesktopHandler) | 2187 | else if (mShowdesktopHandler) |
979 | 2237 | { | 2188 | { |
982 | 2238 | mShowdesktopHandler->paintAttrib (wAttrib); | 2189 | mShowdesktopHandler->PaintOpacity (wAttrib.opacity); |
983 | 2239 | mask |= mShowdesktopHandler->getPaintMask (); | 2190 | mask |= mShowdesktopHandler->GetPaintMask (); |
984 | 2240 | } | 2191 | } |
985 | 2241 | 2192 | ||
986 | 2242 | std::vector<Window> const& tray_xids = uScreen->panel_controller_->GetTrayXids(); | 2193 | std::vector<Window> const& tray_xids = uScreen->panel_controller_->GetTrayXids(); |
987 | @@ -2460,7 +2411,8 @@ | |||
988 | 2460 | } | 2411 | } |
989 | 2461 | else if (mShowdesktopHandler) | 2412 | else if (mShowdesktopHandler) |
990 | 2462 | { | 2413 | { |
992 | 2463 | mShowdesktopHandler->windowNotify (n); | 2414 | if (n == CompWindowNotifyFocusChange) |
993 | 2415 | mShowdesktopHandler->WindowFocusChangeNotify (); | ||
994 | 2464 | } | 2416 | } |
995 | 2465 | 2417 | ||
996 | 2466 | // We do this after the notify to ensure input focus has actually been moved. | 2418 | // We do this after the notify to ensure input focus has actually been moved. |
997 | @@ -2499,7 +2451,7 @@ | |||
998 | 2499 | if (mMinimizeHandler) | 2451 | if (mMinimizeHandler) |
999 | 2500 | mMinimizeHandler->updateFrameRegion (region); | 2452 | mMinimizeHandler->updateFrameRegion (region); |
1000 | 2501 | else if (mShowdesktopHandler) | 2453 | else if (mShowdesktopHandler) |
1002 | 2502 | mShowdesktopHandler->updateFrameRegion (region); | 2454 | mShowdesktopHandler->UpdateFrameRegion (region); |
1003 | 2503 | else | 2455 | else |
1004 | 2504 | window->updateFrameRegion (region); | 2456 | window->updateFrameRegion (region); |
1005 | 2505 | } | 2457 | } |
1006 | @@ -3039,7 +2991,7 @@ | |||
1007 | 3039 | window->minimize (); | 2991 | window->minimize (); |
1008 | 3040 | } | 2992 | } |
1009 | 3041 | 2993 | ||
1011 | 3042 | UnityShowdesktopHandler::animating_windows.remove (window); | 2994 | ShowdesktopHandler::animating_windows.remove (static_cast <ShowdesktopHandlerWindowInterface *> (this)); |
1012 | 3043 | 2995 | ||
1013 | 3044 | if (mShowdesktopHandler) | 2996 | if (mShowdesktopHandler) |
1014 | 3045 | delete mShowdesktopHandler; | 2997 | delete mShowdesktopHandler; |
1015 | 3046 | 2998 | ||
1016 | === modified file 'plugins/unityshell/src/unityshell.h' | |||
1017 | --- plugins/unityshell/src/unityshell.h 2012-04-05 16:10:46 +0000 | |||
1018 | +++ plugins/unityshell/src/unityshell.h 2012-04-06 08:44:20 +0000 | |||
1019 | @@ -50,6 +50,7 @@ | |||
1020 | 50 | #include "SwitcherController.h" | 50 | #include "SwitcherController.h" |
1021 | 51 | #include "UBusWrapper.h" | 51 | #include "UBusWrapper.h" |
1022 | 52 | #include "UnityshellPrivate.h" | 52 | #include "UnityshellPrivate.h" |
1023 | 53 | #include "UnityShowdesktopHandler.h" | ||
1024 | 53 | #ifndef USE_GLES | 54 | #ifndef USE_GLES |
1025 | 54 | #include "ScreenEffectFramebufferObject.h" | 55 | #include "ScreenEffectFramebufferObject.h" |
1026 | 55 | #endif | 56 | #endif |
1027 | @@ -64,51 +65,6 @@ | |||
1028 | 64 | namespace unity | 65 | namespace unity |
1029 | 65 | { | 66 | { |
1030 | 66 | 67 | ||
1031 | 67 | class UnityShowdesktopHandler | ||
1032 | 68 | { | ||
1033 | 69 | public: | ||
1034 | 70 | |||
1035 | 71 | UnityShowdesktopHandler (CompWindow *w); | ||
1036 | 72 | ~UnityShowdesktopHandler (); | ||
1037 | 73 | |||
1038 | 74 | typedef enum { | ||
1039 | 75 | Visible = 0, | ||
1040 | 76 | FadeOut = 1, | ||
1041 | 77 | FadeIn = 2, | ||
1042 | 78 | Invisible = 3 | ||
1043 | 79 | } State; | ||
1044 | 80 | |||
1045 | 81 | public: | ||
1046 | 82 | |||
1047 | 83 | void fadeOut (); | ||
1048 | 84 | void fadeIn (); | ||
1049 | 85 | bool animate (unsigned int ms); | ||
1050 | 86 | void paintAttrib (GLWindowPaintAttrib &attrib); | ||
1051 | 87 | unsigned int getPaintMask (); | ||
1052 | 88 | void handleEvent (XEvent *); | ||
1053 | 89 | void windowNotify (CompWindowNotify n); | ||
1054 | 90 | void updateFrameRegion (CompRegion &r); | ||
1055 | 91 | |||
1056 | 92 | UnityShowdesktopHandler::State state (); | ||
1057 | 93 | |||
1058 | 94 | static const unsigned int fade_time; | ||
1059 | 95 | static CompWindowList animating_windows; | ||
1060 | 96 | static bool shouldHide (CompWindow *); | ||
1061 | 97 | static void inhibitLeaveShowdesktopMode (guint32 xid); | ||
1062 | 98 | static void allowLeaveShowdesktopMode (guint32 xid); | ||
1063 | 99 | static guint32 inhibitingXid (); | ||
1064 | 100 | |||
1065 | 101 | private: | ||
1066 | 102 | |||
1067 | 103 | CompWindow *mWindow; | ||
1068 | 104 | compiz::WindowInputRemover *mRemover; | ||
1069 | 105 | UnityShowdesktopHandler::State mState; | ||
1070 | 106 | float mProgress; | ||
1071 | 107 | bool mWasHidden; | ||
1072 | 108 | static guint32 mInhibitingXid; | ||
1073 | 109 | }; | ||
1074 | 110 | |||
1075 | 111 | |||
1076 | 112 | /* base screen class */ | 68 | /* base screen class */ |
1077 | 113 | class UnityScreen : | 69 | class UnityScreen : |
1078 | 114 | public unity::debug::Introspectable, | 70 | public unity::debug::Introspectable, |
1079 | @@ -145,6 +101,7 @@ | |||
1080 | 145 | 101 | ||
1081 | 146 | void preparePaint (int ms); | 102 | void preparePaint (int ms); |
1082 | 147 | void paintFboForOutput (CompOutput *output); | 103 | void paintFboForOutput (CompOutput *output); |
1083 | 104 | void donePaint (); | ||
1084 | 148 | 105 | ||
1085 | 149 | void RaiseInputWindows(); | 106 | void RaiseInputWindows(); |
1086 | 150 | 107 | ||
1087 | @@ -358,6 +315,7 @@ | |||
1088 | 358 | class UnityWindow : | 315 | class UnityWindow : |
1089 | 359 | public WindowInterface, | 316 | public WindowInterface, |
1090 | 360 | public GLWindowInterface, | 317 | public GLWindowInterface, |
1091 | 318 | public ShowdesktopHandlerWindowInterface, | ||
1092 | 361 | public BaseSwitchWindow, | 319 | public BaseSwitchWindow, |
1093 | 362 | public PluginClassHandler <UnityWindow, CompWindow> | 320 | public PluginClassHandler <UnityWindow, CompWindow> |
1094 | 363 | { | 321 | { |
1095 | @@ -414,18 +372,50 @@ | |||
1096 | 414 | 372 | ||
1097 | 415 | void enterShowDesktop (); | 373 | void enterShowDesktop (); |
1098 | 416 | void leaveShowDesktop (); | 374 | void leaveShowDesktop (); |
1100 | 417 | bool handleAnimations (unsigned int ms); | 375 | bool HandleAnimations (unsigned int ms); |
1101 | 376 | |||
1102 | 377 | void handleEvent (XEvent *event); | ||
1103 | 418 | 378 | ||
1104 | 419 | typedef compiz::CompizMinimizedWindowHandler<UnityScreen, UnityWindow> | 379 | typedef compiz::CompizMinimizedWindowHandler<UnityScreen, UnityWindow> |
1105 | 420 | UnityMinimizedHandler; | 380 | UnityMinimizedHandler; |
1106 | 421 | std::unique_ptr <UnityMinimizedHandler> mMinimizeHandler; | 381 | std::unique_ptr <UnityMinimizedHandler> mMinimizeHandler; |
1107 | 422 | 382 | ||
1109 | 423 | UnityShowdesktopHandler *mShowdesktopHandler; | 383 | ShowdesktopHandler *mShowdesktopHandler; |
1110 | 424 | 384 | ||
1111 | 425 | private: | 385 | private: |
1112 | 426 | 386 | ||
1113 | 427 | guint focusdesktop_handle_; | 387 | guint focusdesktop_handle_; |
1114 | 428 | static gboolean FocusDesktopTimeout(gpointer data); | 388 | static gboolean FocusDesktopTimeout(gpointer data); |
1115 | 389 | |||
1116 | 390 | void DoEnableFocus (); | ||
1117 | 391 | void DoDisableFocus (); | ||
1118 | 392 | |||
1119 | 393 | bool IsOverrideRedirect (); | ||
1120 | 394 | bool IsManaged (); | ||
1121 | 395 | bool IsGrabbed (); | ||
1122 | 396 | bool IsDesktopOrDock (); | ||
1123 | 397 | bool IsSkipTaskbarOrPager (); | ||
1124 | 398 | bool IsHidden (); | ||
1125 | 399 | bool IsInShowdesktopMode (); | ||
1126 | 400 | bool IsShaded (); | ||
1127 | 401 | bool IsMinimized (); | ||
1128 | 402 | void DoOverrideFrameRegion (CompRegion &r); | ||
1129 | 403 | |||
1130 | 404 | void DoHide (); | ||
1131 | 405 | void DoNotifyHidden (); | ||
1132 | 406 | void DoShow (); | ||
1133 | 407 | void DoNotifyShown (); | ||
1134 | 408 | |||
1135 | 409 | void DoAddDamage (); | ||
1136 | 410 | ShowdesktopHandlerWindowInterface::PostPaintAction DoHandleAnimations (unsigned int ms); | ||
1137 | 411 | |||
1138 | 412 | void DoMoveFocusAway (); | ||
1139 | 413 | |||
1140 | 414 | void DoDeleteHandler (); | ||
1141 | 415 | |||
1142 | 416 | unsigned int GetNoCoreInstanceMask (); | ||
1143 | 417 | |||
1144 | 418 | compiz::WindowInputRemoverInterface::Ptr GetInputRemover (); | ||
1145 | 429 | }; | 419 | }; |
1146 | 430 | 420 | ||
1147 | 431 | 421 | ||
1148 | 432 | 422 | ||
1149 | === modified file 'tests/CMakeLists.txt' | |||
1150 | --- tests/CMakeLists.txt 2012-04-06 02:11:51 +0000 | |||
1151 | +++ tests/CMakeLists.txt 2012-04-06 08:44:20 +0000 | |||
1152 | @@ -33,7 +33,8 @@ | |||
1153 | 33 | ) | 33 | ) |
1154 | 34 | add_definitions (${CFLAGS}) | 34 | add_definitions (${CFLAGS}) |
1155 | 35 | 35 | ||
1157 | 36 | set (LIBS ${TEST_UNIT_DEPS_LIBRARIES} "-lunity-core-${UNITY_API_VERSION} -lm") | 36 | set (LIBS ${TEST_UNIT_DEPS_LIBRARIES} "-lunity-core-${UNITY_API_VERSION} -lcompiz_core -lm") |
1158 | 37 | link_libraries (${LIBS}) | ||
1159 | 37 | 38 | ||
1160 | 38 | set (LIB_PATHS ${TEST_UNIT_DEPS_LIBRARY_DIRS}) | 39 | set (LIB_PATHS ${TEST_UNIT_DEPS_LIBRARY_DIRS}) |
1161 | 39 | link_directories (${CMAKE_BINARY_DIR}/UnityCore ${LIB_PATHS}) | 40 | link_directories (${CMAKE_BINARY_DIR}/UnityCore ${LIB_PATHS}) |
1162 | @@ -141,6 +142,7 @@ | |||
1163 | 141 | test_main_xless.cpp | 142 | test_main_xless.cpp |
1164 | 142 | test_grabhandle.cpp | 143 | test_grabhandle.cpp |
1165 | 143 | test_unityshell_private.cpp | 144 | test_unityshell_private.cpp |
1166 | 145 | test_showdesktop_handler.cpp | ||
1167 | 144 | ${UNITY_SRC}/AbstractLauncherIcon.cpp | 146 | ${UNITY_SRC}/AbstractLauncherIcon.cpp |
1168 | 145 | ${UNITY_SRC}/AbstractShortcutHint.h | 147 | ${UNITY_SRC}/AbstractShortcutHint.h |
1169 | 146 | ${UNITY_SRC}/Animator.cpp | 148 | ${UNITY_SRC}/Animator.cpp |
1170 | @@ -161,6 +163,7 @@ | |||
1171 | 161 | ${UNITY_SRC}/Timer.cpp | 163 | ${UNITY_SRC}/Timer.cpp |
1172 | 162 | ${UNITY_SRC}/UnityshellPrivate.cpp | 164 | ${UNITY_SRC}/UnityshellPrivate.cpp |
1173 | 163 | ${UNITY_SRC}/WindowManager.cpp | 165 | ${UNITY_SRC}/WindowManager.cpp |
1174 | 166 | ${UNITY_SRC}/UnityShowdesktopHandler.cpp | ||
1175 | 164 | ${CMAKE_SOURCE_DIR}/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle.cpp | 167 | ${CMAKE_SOURCE_DIR}/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle.cpp |
1176 | 165 | ${CMAKE_SOURCE_DIR}/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-group.cpp | 168 | ${CMAKE_SOURCE_DIR}/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-group.cpp |
1177 | 166 | ${CMAKE_SOURCE_DIR}/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-impl-factory.cpp | 169 | ${CMAKE_SOURCE_DIR}/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-impl-factory.cpp |
1178 | 167 | 170 | ||
1179 | === added file 'tests/test_showdesktop_handler.cpp' | |||
1180 | --- tests/test_showdesktop_handler.cpp 1970-01-01 00:00:00 +0000 | |||
1181 | +++ tests/test_showdesktop_handler.cpp 2012-04-06 08:44:20 +0000 | |||
1182 | @@ -0,0 +1,539 @@ | |||
1183 | 1 | #include <list> | ||
1184 | 2 | #include <algorithm> | ||
1185 | 3 | #include <gtest/gtest.h> | ||
1186 | 4 | #include <gmock/gmock.h> | ||
1187 | 5 | #include <UnityShowdesktopHandler.h> | ||
1188 | 6 | |||
1189 | 7 | using namespace unity; | ||
1190 | 8 | using ::testing::_; | ||
1191 | 9 | using ::testing::Return; | ||
1192 | 10 | using ::testing::Invoke; | ||
1193 | 11 | using ::testing::InSequence; | ||
1194 | 12 | |||
1195 | 13 | compiz::WindowInputRemoverInterface::~WindowInputRemoverInterface () {} | ||
1196 | 14 | |||
1197 | 15 | class MockWindowInputRemover : | ||
1198 | 16 | public compiz::WindowInputRemoverInterface | ||
1199 | 17 | { | ||
1200 | 18 | public: | ||
1201 | 19 | |||
1202 | 20 | MockWindowInputRemover () | ||
1203 | 21 | { | ||
1204 | 22 | ON_CALL (*this, saveInput ()).WillByDefault (Return (true)); | ||
1205 | 23 | ON_CALL (*this, removeInput ()).WillByDefault (Return (true)); | ||
1206 | 24 | ON_CALL (*this, restoreInput ()).WillByDefault (Return (true)); | ||
1207 | 25 | } | ||
1208 | 26 | |||
1209 | 27 | MOCK_METHOD0 (saveInput, bool ()); | ||
1210 | 28 | MOCK_METHOD0 (removeInput, bool ()); | ||
1211 | 29 | MOCK_METHOD0 (restoreInput, bool ()); | ||
1212 | 30 | }; | ||
1213 | 31 | |||
1214 | 32 | class UnityShowdesktopHandlerTest : | ||
1215 | 33 | public ::testing::Test | ||
1216 | 34 | { | ||
1217 | 35 | public: | ||
1218 | 36 | |||
1219 | 37 | ~UnityShowdesktopHandlerTest () | ||
1220 | 38 | { | ||
1221 | 39 | ShowdesktopHandler::animating_windows.clear (); | ||
1222 | 40 | } | ||
1223 | 41 | |||
1224 | 42 | template <class T, class U> static typename T::Ptr makeShared () { return typename T::Ptr (new U); } | ||
1225 | 43 | |||
1226 | 44 | }; | ||
1227 | 45 | |||
1228 | 46 | |||
1229 | 47 | class MockUnityShowdesktopHandlerWindow : | ||
1230 | 48 | public ShowdesktopHandlerWindowInterface | ||
1231 | 49 | { | ||
1232 | 50 | public: | ||
1233 | 51 | |||
1234 | 52 | MockUnityShowdesktopHandlerWindow () | ||
1235 | 53 | { | ||
1236 | 54 | ON_CALL (*this, IsOverrideRedirect ()).WillByDefault (Return (false)); | ||
1237 | 55 | ON_CALL (*this, IsManaged ()).WillByDefault (Return (true)); | ||
1238 | 56 | ON_CALL (*this, IsGrabbed ()).WillByDefault (Return (false)); | ||
1239 | 57 | ON_CALL (*this, IsDesktopOrDock ()).WillByDefault (Return (false)); | ||
1240 | 58 | ON_CALL (*this, IsSkipTaskbarOrPager ()).WillByDefault (Return (false)); | ||
1241 | 59 | ON_CALL (*this, IsHidden ()).WillByDefault (Return (false)); | ||
1242 | 60 | ON_CALL (*this, IsInShowdesktopMode ()).WillByDefault (Return (false)); | ||
1243 | 61 | ON_CALL (*this, IsShaded ()).WillByDefault (Return (false)); | ||
1244 | 62 | ON_CALL (*this, IsMinimized ()).WillByDefault (Return (false)); | ||
1245 | 63 | |||
1246 | 64 | ON_CALL (*this, DoHandleAnimations (_)).WillByDefault (Return (ShowdesktopHandlerWindowInterface::PostPaintAction::Damage)); | ||
1247 | 65 | ON_CALL (*this, GetNoCoreInstanceMask ()).WillByDefault (Return (1)); | ||
1248 | 66 | ON_CALL (*this, GetInputRemover ()).WillByDefault (Invoke (UnityShowdesktopHandlerTest::makeShared<compiz::WindowInputRemoverInterface, MockWindowInputRemover>)); | ||
1249 | 67 | } | ||
1250 | 68 | |||
1251 | 69 | MOCK_METHOD0 (DoEnableFocus, void ()); | ||
1252 | 70 | MOCK_METHOD0 (DoDisableFocus, void ()); | ||
1253 | 71 | MOCK_METHOD0 (IsOverrideRedirect, bool ()); | ||
1254 | 72 | MOCK_METHOD0 (IsManaged, bool ()); | ||
1255 | 73 | MOCK_METHOD0 (IsGrabbed, bool ()); | ||
1256 | 74 | MOCK_METHOD0 (IsDesktopOrDock, bool ()); | ||
1257 | 75 | MOCK_METHOD0 (IsSkipTaskbarOrPager, bool ()); | ||
1258 | 76 | MOCK_METHOD0 (IsHidden, bool ()); | ||
1259 | 77 | MOCK_METHOD0 (IsInShowdesktopMode, bool ()); | ||
1260 | 78 | MOCK_METHOD0 (IsShaded, bool ()); | ||
1261 | 79 | MOCK_METHOD0 (IsMinimized, bool ()); | ||
1262 | 80 | MOCK_METHOD1 (DoOverrideFrameRegion, void (CompRegion &)); | ||
1263 | 81 | MOCK_METHOD0 (DoHide, void ()); | ||
1264 | 82 | MOCK_METHOD0 (DoNotifyHidden, void ()); | ||
1265 | 83 | MOCK_METHOD0 (DoShow, void ()); | ||
1266 | 84 | MOCK_METHOD0 (DoNotifyShown, void ()); | ||
1267 | 85 | MOCK_METHOD0 (DoMoveFocusAway, void ()); | ||
1268 | 86 | MOCK_METHOD1 (DoHandleAnimations, ShowdesktopHandlerWindowInterface::PostPaintAction (unsigned int)); | ||
1269 | 87 | MOCK_METHOD0 (DoAddDamage, void ()); | ||
1270 | 88 | MOCK_METHOD0 (GetNoCoreInstanceMask, unsigned int ()); | ||
1271 | 89 | MOCK_METHOD0 (GetInputRemover, compiz::WindowInputRemoverInterface::Ptr ()); | ||
1272 | 90 | MOCK_METHOD0 (DoDeleteHandler, void ()); | ||
1273 | 91 | }; | ||
1274 | 92 | |||
1275 | 93 | TEST_F(UnityShowdesktopHandlerTest, TestNoORWindowsSD) | ||
1276 | 94 | { | ||
1277 | 95 | MockUnityShowdesktopHandlerWindow mMockWindow; | ||
1278 | 96 | |||
1279 | 97 | EXPECT_CALL (mMockWindow, GetInputRemover ()); | ||
1280 | 98 | |||
1281 | 99 | ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow)); | ||
1282 | 100 | |||
1283 | 101 | EXPECT_CALL (mMockWindow, IsOverrideRedirect ()).WillOnce (Return (true)); | ||
1284 | 102 | EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow)); | ||
1285 | 103 | } | ||
1286 | 104 | |||
1287 | 105 | TEST_F(UnityShowdesktopHandlerTest, TestNoUnmanagedWindowsSD) | ||
1288 | 106 | { | ||
1289 | 107 | MockUnityShowdesktopHandlerWindow mMockWindow; | ||
1290 | 108 | |||
1291 | 109 | EXPECT_CALL (mMockWindow, GetInputRemover ()); | ||
1292 | 110 | |||
1293 | 111 | ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow)); | ||
1294 | 112 | |||
1295 | 113 | EXPECT_CALL (mMockWindow, IsOverrideRedirect ()); | ||
1296 | 114 | EXPECT_CALL (mMockWindow, IsManaged ()).WillOnce (Return (false)); | ||
1297 | 115 | EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow)); | ||
1298 | 116 | } | ||
1299 | 117 | |||
1300 | 118 | TEST_F(UnityShowdesktopHandlerTest, TestNoGrabbedWindowsSD) | ||
1301 | 119 | { | ||
1302 | 120 | MockUnityShowdesktopHandlerWindow mMockWindow; | ||
1303 | 121 | |||
1304 | 122 | EXPECT_CALL (mMockWindow, GetInputRemover ()); | ||
1305 | 123 | |||
1306 | 124 | ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow)); | ||
1307 | 125 | |||
1308 | 126 | EXPECT_CALL (mMockWindow, IsOverrideRedirect ()); | ||
1309 | 127 | EXPECT_CALL (mMockWindow, IsManaged ()); | ||
1310 | 128 | EXPECT_CALL (mMockWindow, IsGrabbed ()).WillOnce (Return (true)); | ||
1311 | 129 | EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow)); | ||
1312 | 130 | } | ||
1313 | 131 | |||
1314 | 132 | TEST_F(UnityShowdesktopHandlerTest, TestNoDesktopOrDockWindowsSD) | ||
1315 | 133 | { | ||
1316 | 134 | MockUnityShowdesktopHandlerWindow mMockWindow; | ||
1317 | 135 | |||
1318 | 136 | EXPECT_CALL (mMockWindow, GetInputRemover ()); | ||
1319 | 137 | |||
1320 | 138 | ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow)); | ||
1321 | 139 | |||
1322 | 140 | EXPECT_CALL (mMockWindow, IsOverrideRedirect ()); | ||
1323 | 141 | EXPECT_CALL (mMockWindow, IsManaged ()); | ||
1324 | 142 | EXPECT_CALL (mMockWindow, IsGrabbed ()); | ||
1325 | 143 | EXPECT_CALL (mMockWindow, IsDesktopOrDock ()).WillOnce (Return (true)); | ||
1326 | 144 | EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow)); | ||
1327 | 145 | } | ||
1328 | 146 | |||
1329 | 147 | TEST_F(UnityShowdesktopHandlerTest, TestNoSkipTaskbarOrPagerWindowsSD) | ||
1330 | 148 | { | ||
1331 | 149 | MockUnityShowdesktopHandlerWindow mMockWindow; | ||
1332 | 150 | |||
1333 | 151 | EXPECT_CALL (mMockWindow, GetInputRemover ()); | ||
1334 | 152 | |||
1335 | 153 | ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow)); | ||
1336 | 154 | |||
1337 | 155 | EXPECT_CALL (mMockWindow, IsOverrideRedirect ()); | ||
1338 | 156 | EXPECT_CALL (mMockWindow, IsManaged ()); | ||
1339 | 157 | EXPECT_CALL (mMockWindow, IsGrabbed ()); | ||
1340 | 158 | EXPECT_CALL (mMockWindow, IsDesktopOrDock ()); | ||
1341 | 159 | EXPECT_CALL (mMockWindow, IsSkipTaskbarOrPager ()).WillOnce (Return (true)); | ||
1342 | 160 | EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow)); | ||
1343 | 161 | } | ||
1344 | 162 | |||
1345 | 163 | TEST_F(UnityShowdesktopHandlerTest, TestHiddenNotSDAndShadedWindowsNoSD) | ||
1346 | 164 | { | ||
1347 | 165 | MockUnityShowdesktopHandlerWindow mMockWindow; | ||
1348 | 166 | |||
1349 | 167 | EXPECT_CALL (mMockWindow, GetInputRemover ()); | ||
1350 | 168 | |||
1351 | 169 | ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow)); | ||
1352 | 170 | |||
1353 | 171 | EXPECT_CALL (mMockWindow, IsOverrideRedirect ()); | ||
1354 | 172 | EXPECT_CALL (mMockWindow, IsManaged ()); | ||
1355 | 173 | EXPECT_CALL (mMockWindow, IsGrabbed ()); | ||
1356 | 174 | EXPECT_CALL (mMockWindow, IsDesktopOrDock ()); | ||
1357 | 175 | EXPECT_CALL (mMockWindow, IsSkipTaskbarOrPager ()); | ||
1358 | 176 | EXPECT_CALL (mMockWindow, IsHidden ()).WillOnce (Return (true)); | ||
1359 | 177 | EXPECT_CALL (mMockWindow, IsInShowdesktopMode ()).WillOnce (Return (false)); | ||
1360 | 178 | EXPECT_CALL (mMockWindow, IsShaded ()).WillOnce (Return (true)); | ||
1361 | 179 | EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow)); | ||
1362 | 180 | } | ||
1363 | 181 | |||
1364 | 182 | TEST_F(UnityShowdesktopHandlerTest, TestHiddenSDAndShadedWindowsNoSD) | ||
1365 | 183 | { | ||
1366 | 184 | MockUnityShowdesktopHandlerWindow mMockWindow; | ||
1367 | 185 | |||
1368 | 186 | EXPECT_CALL (mMockWindow, GetInputRemover ()); | ||
1369 | 187 | |||
1370 | 188 | ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow)); | ||
1371 | 189 | |||
1372 | 190 | EXPECT_CALL (mMockWindow, IsOverrideRedirect ()); | ||
1373 | 191 | EXPECT_CALL (mMockWindow, IsManaged ()); | ||
1374 | 192 | EXPECT_CALL (mMockWindow, IsGrabbed ()); | ||
1375 | 193 | EXPECT_CALL (mMockWindow, IsDesktopOrDock ()); | ||
1376 | 194 | EXPECT_CALL (mMockWindow, IsSkipTaskbarOrPager ()); | ||
1377 | 195 | EXPECT_CALL (mMockWindow, IsHidden ()).WillOnce (Return (true)); | ||
1378 | 196 | EXPECT_CALL (mMockWindow, IsInShowdesktopMode ()).WillOnce (Return (true)); | ||
1379 | 197 | EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow)); | ||
1380 | 198 | } | ||
1381 | 199 | |||
1382 | 200 | TEST_F(UnityShowdesktopHandlerTest, TestHiddenNotSDAndNotShadedWindowsSD) | ||
1383 | 201 | { | ||
1384 | 202 | MockUnityShowdesktopHandlerWindow mMockWindow; | ||
1385 | 203 | |||
1386 | 204 | EXPECT_CALL (mMockWindow, GetInputRemover ()); | ||
1387 | 205 | |||
1388 | 206 | ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow)); | ||
1389 | 207 | |||
1390 | 208 | EXPECT_CALL (mMockWindow, IsOverrideRedirect ()); | ||
1391 | 209 | EXPECT_CALL (mMockWindow, IsManaged ()); | ||
1392 | 210 | EXPECT_CALL (mMockWindow, IsGrabbed ()); | ||
1393 | 211 | EXPECT_CALL (mMockWindow, IsDesktopOrDock ()); | ||
1394 | 212 | EXPECT_CALL (mMockWindow, IsSkipTaskbarOrPager ()); | ||
1395 | 213 | EXPECT_CALL (mMockWindow, IsHidden ()).WillOnce (Return (true)); | ||
1396 | 214 | EXPECT_CALL (mMockWindow, IsInShowdesktopMode ()).WillOnce (Return (false)); | ||
1397 | 215 | EXPECT_CALL (mMockWindow, IsShaded ()).WillOnce (Return (false)); | ||
1398 | 216 | EXPECT_TRUE (ShowdesktopHandler::ShouldHide (&mMockWindow)); | ||
1399 | 217 | } | ||
1400 | 218 | |||
1401 | 219 | class MockWindowInputRemoverTestFadeOut : | ||
1402 | 220 | public compiz::WindowInputRemoverInterface | ||
1403 | 221 | { | ||
1404 | 222 | public: | ||
1405 | 223 | |||
1406 | 224 | MockWindowInputRemoverTestFadeOut () | ||
1407 | 225 | { | ||
1408 | 226 | ON_CALL (*this, saveInput ()).WillByDefault (Return (true)); | ||
1409 | 227 | ON_CALL (*this, removeInput ()).WillByDefault (Return (true)); | ||
1410 | 228 | ON_CALL (*this, restoreInput ()).WillByDefault (Return (true)); | ||
1411 | 229 | |||
1412 | 230 | EXPECT_CALL (*this, saveInput ()).WillOnce (Return (true)); | ||
1413 | 231 | EXPECT_CALL (*this, removeInput ()).WillOnce (Return (true)); | ||
1414 | 232 | } | ||
1415 | 233 | |||
1416 | 234 | MOCK_METHOD0 (saveInput, bool ()); | ||
1417 | 235 | MOCK_METHOD0 (removeInput, bool ()); | ||
1418 | 236 | MOCK_METHOD0 (restoreInput, bool ()); | ||
1419 | 237 | }; | ||
1420 | 238 | |||
1421 | 239 | TEST_F(UnityShowdesktopHandlerTest, TestFadeOutHidesWindow) | ||
1422 | 240 | { | ||
1423 | 241 | MockUnityShowdesktopHandlerWindow mMockWindow; | ||
1424 | 242 | |||
1425 | 243 | EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::makeShared<compiz::WindowInputRemoverInterface, MockWindowInputRemoverTestFadeOut>)); | ||
1426 | 244 | |||
1427 | 245 | ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow)); | ||
1428 | 246 | |||
1429 | 247 | EXPECT_CALL (mMockWindow, IsHidden ()); | ||
1430 | 248 | EXPECT_CALL (mMockWindow, DoHide ()); | ||
1431 | 249 | EXPECT_CALL (mMockWindow, DoNotifyHidden ()); | ||
1432 | 250 | |||
1433 | 251 | mMockHandler.FadeOut (); | ||
1434 | 252 | |||
1435 | 253 | EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1); | ||
1436 | 254 | } | ||
1437 | 255 | |||
1438 | 256 | class MockWindowInputRemoverTestFadeOutAlready : | ||
1439 | 257 | public compiz::WindowInputRemoverInterface | ||
1440 | 258 | { | ||
1441 | 259 | public: | ||
1442 | 260 | |||
1443 | 261 | MockWindowInputRemoverTestFadeOutAlready () | ||
1444 | 262 | { | ||
1445 | 263 | ON_CALL (*this, saveInput ()).WillByDefault (Return (true)); | ||
1446 | 264 | ON_CALL (*this, removeInput ()).WillByDefault (Return (true)); | ||
1447 | 265 | ON_CALL (*this, restoreInput ()).WillByDefault (Return (true)); | ||
1448 | 266 | } | ||
1449 | 267 | |||
1450 | 268 | MOCK_METHOD0 (saveInput, bool ()); | ||
1451 | 269 | MOCK_METHOD0 (removeInput, bool ()); | ||
1452 | 270 | MOCK_METHOD0 (restoreInput, bool ()); | ||
1453 | 271 | }; | ||
1454 | 272 | |||
1455 | 273 | TEST_F(UnityShowdesktopHandlerTest, TestFadeOutOnHiddenDoesntHideWindow) | ||
1456 | 274 | { | ||
1457 | 275 | MockUnityShowdesktopHandlerWindow mMockWindow; | ||
1458 | 276 | |||
1459 | 277 | EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::makeShared<compiz::WindowInputRemoverInterface, MockWindowInputRemoverTestFadeOutAlready>)); | ||
1460 | 278 | |||
1461 | 279 | ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow)); | ||
1462 | 280 | |||
1463 | 281 | EXPECT_CALL (mMockWindow, IsHidden ()).WillOnce (Return (true)); | ||
1464 | 282 | |||
1465 | 283 | mMockHandler.FadeOut (); | ||
1466 | 284 | |||
1467 | 285 | EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 0); | ||
1468 | 286 | } | ||
1469 | 287 | |||
1470 | 288 | TEST_F(UnityShowdesktopHandlerTest, TestFadeOutAlreadyFadedDoesntHideWindow) | ||
1471 | 289 | { | ||
1472 | 290 | MockUnityShowdesktopHandlerWindow mMockWindow; | ||
1473 | 291 | |||
1474 | 292 | EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::makeShared<compiz::WindowInputRemoverInterface, MockWindowInputRemoverTestFadeOut>)); | ||
1475 | 293 | |||
1476 | 294 | ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow)); | ||
1477 | 295 | |||
1478 | 296 | EXPECT_CALL (mMockWindow, IsHidden ()); | ||
1479 | 297 | EXPECT_CALL (mMockWindow, DoHide ()); | ||
1480 | 298 | EXPECT_CALL (mMockWindow, DoNotifyHidden ()); | ||
1481 | 299 | |||
1482 | 300 | mMockHandler.FadeOut (); | ||
1483 | 301 | mMockHandler.FadeOut (); | ||
1484 | 302 | |||
1485 | 303 | EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1); | ||
1486 | 304 | } | ||
1487 | 305 | |||
1488 | 306 | TEST_F(UnityShowdesktopHandlerTest, TestFadeInNonFadedDoesntShowWindow) | ||
1489 | 307 | { | ||
1490 | 308 | MockUnityShowdesktopHandlerWindow mMockWindow; | ||
1491 | 309 | |||
1492 | 310 | EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::makeShared<compiz::WindowInputRemoverInterface, MockWindowInputRemoverTestFadeOutAlready>)); | ||
1493 | 311 | |||
1494 | 312 | ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow)); | ||
1495 | 313 | |||
1496 | 314 | mMockHandler.FadeIn (); | ||
1497 | 315 | |||
1498 | 316 | EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 0); | ||
1499 | 317 | } | ||
1500 | 318 | |||
1501 | 319 | class MockWindowInputRemoverTestFadeOutFadeIn : | ||
1502 | 320 | public compiz::WindowInputRemoverInterface | ||
1503 | 321 | { | ||
1504 | 322 | public: | ||
1505 | 323 | |||
1506 | 324 | MockWindowInputRemoverTestFadeOutFadeIn () | ||
1507 | 325 | { | ||
1508 | 326 | ON_CALL (*this, saveInput ()).WillByDefault (Return (true)); | ||
1509 | 327 | ON_CALL (*this, removeInput ()).WillByDefault (Return (true)); | ||
1510 | 328 | ON_CALL (*this, restoreInput ()).WillByDefault (Return (true)); | ||
1511 | 329 | |||
1512 | 330 | EXPECT_CALL (*this, saveInput ()).WillOnce (Return (true)); | ||
1513 | 331 | EXPECT_CALL (*this, removeInput ()).WillOnce (Return (true)); | ||
1514 | 332 | EXPECT_CALL (*this, restoreInput ()).WillOnce (Return (true)); | ||
1515 | 333 | } | ||
1516 | 334 | |||
1517 | 335 | MOCK_METHOD0 (saveInput, bool ()); | ||
1518 | 336 | MOCK_METHOD0 (removeInput, bool ()); | ||
1519 | 337 | MOCK_METHOD0 (restoreInput, bool ()); | ||
1520 | 338 | }; | ||
1521 | 339 | |||
1522 | 340 | TEST_F(UnityShowdesktopHandlerTest, TestFadeOutHidesWindowFadeInShowsWindow) | ||
1523 | 341 | { | ||
1524 | 342 | MockUnityShowdesktopHandlerWindow mMockWindow; | ||
1525 | 343 | |||
1526 | 344 | EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::makeShared<compiz::WindowInputRemoverInterface, MockWindowInputRemoverTestFadeOutFadeIn>)); | ||
1527 | 345 | |||
1528 | 346 | ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow)); | ||
1529 | 347 | |||
1530 | 348 | EXPECT_CALL (mMockWindow, IsHidden ()); | ||
1531 | 349 | EXPECT_CALL (mMockWindow, DoHide ()); | ||
1532 | 350 | EXPECT_CALL (mMockWindow, DoNotifyHidden ()); | ||
1533 | 351 | |||
1534 | 352 | mMockHandler.FadeOut (); | ||
1535 | 353 | |||
1536 | 354 | EXPECT_CALL (mMockWindow, DoShow ()); | ||
1537 | 355 | EXPECT_CALL (mMockWindow, DoNotifyShown ()); | ||
1538 | 356 | |||
1539 | 357 | mMockHandler.FadeIn (); | ||
1540 | 358 | |||
1541 | 359 | EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1); | ||
1542 | 360 | } | ||
1543 | 361 | |||
1544 | 362 | TEST_F(UnityShowdesktopHandlerTest, TestAnimationPostPaintActions) | ||
1545 | 363 | { | ||
1546 | 364 | MockUnityShowdesktopHandlerWindow mMockWindow; | ||
1547 | 365 | |||
1548 | 366 | EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::makeShared<compiz::WindowInputRemoverInterface, MockWindowInputRemoverTestFadeOutFadeIn>)); | ||
1549 | 367 | |||
1550 | 368 | ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow)); | ||
1551 | 369 | |||
1552 | 370 | EXPECT_CALL (mMockWindow, IsHidden ()); | ||
1553 | 371 | EXPECT_CALL (mMockWindow, DoHide ()); | ||
1554 | 372 | EXPECT_CALL (mMockWindow, DoNotifyHidden ()); | ||
1555 | 373 | |||
1556 | 374 | mMockHandler.FadeOut (); | ||
1557 | 375 | |||
1558 | 376 | EXPECT_CALL (mMockWindow, DoShow ()); | ||
1559 | 377 | EXPECT_CALL (mMockWindow, DoNotifyShown ()); | ||
1560 | 378 | |||
1561 | 379 | for (unsigned int i = 0; i < ShowdesktopHandler::fade_time; i++) | ||
1562 | 380 | { | ||
1563 | 381 | ShowdesktopHandlerWindowInterface::PostPaintAction action = mMockHandler.Animate (1); | ||
1564 | 382 | |||
1565 | 383 | if (i == 300) | ||
1566 | 384 | EXPECT_EQ (action, ShowdesktopHandlerWindowInterface::PostPaintAction::Wait); | ||
1567 | 385 | else | ||
1568 | 386 | EXPECT_EQ (action, ShowdesktopHandlerWindowInterface::PostPaintAction::Damage); | ||
1569 | 387 | } | ||
1570 | 388 | |||
1571 | 389 | mMockHandler.FadeIn (); | ||
1572 | 390 | |||
1573 | 391 | for (unsigned int i = 0; i < ShowdesktopHandler::fade_time; i++) | ||
1574 | 392 | { | ||
1575 | 393 | ShowdesktopHandlerWindowInterface::PostPaintAction action = mMockHandler.Animate (1); | ||
1576 | 394 | |||
1577 | 395 | if (i == 300) | ||
1578 | 396 | EXPECT_EQ (action, ShowdesktopHandlerWindowInterface::PostPaintAction::Remove); | ||
1579 | 397 | else | ||
1580 | 398 | EXPECT_EQ (action, ShowdesktopHandlerWindowInterface::PostPaintAction::Damage); | ||
1581 | 399 | } | ||
1582 | 400 | |||
1583 | 401 | EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1); | ||
1584 | 402 | } | ||
1585 | 403 | |||
1586 | 404 | TEST_F(UnityShowdesktopHandlerTest, TestAnimationOpacity) | ||
1587 | 405 | { | ||
1588 | 406 | MockUnityShowdesktopHandlerWindow mMockWindow; | ||
1589 | 407 | |||
1590 | 408 | EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::makeShared<compiz::WindowInputRemoverInterface, MockWindowInputRemoverTestFadeOutFadeIn>)); | ||
1591 | 409 | |||
1592 | 410 | ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow)); | ||
1593 | 411 | |||
1594 | 412 | EXPECT_CALL (mMockWindow, IsHidden ()); | ||
1595 | 413 | EXPECT_CALL (mMockWindow, DoHide ()); | ||
1596 | 414 | EXPECT_CALL (mMockWindow, DoNotifyHidden ()); | ||
1597 | 415 | |||
1598 | 416 | mMockHandler.FadeOut (); | ||
1599 | 417 | |||
1600 | 418 | EXPECT_CALL (mMockWindow, DoShow ()); | ||
1601 | 419 | EXPECT_CALL (mMockWindow, DoNotifyShown ()); | ||
1602 | 420 | |||
1603 | 421 | /* The funny expectations here are to account for rounding errors that would | ||
1604 | 422 | * otherwise make testing the code painful */ | ||
1605 | 423 | |||
1606 | 424 | for (unsigned int i = 0; i < ShowdesktopHandler::fade_time; i++) | ||
1607 | 425 | { | ||
1608 | 426 | unsigned short opacity = std::numeric_limits <unsigned short>::max (); | ||
1609 | 427 | mMockHandler.PaintOpacity (opacity); | ||
1610 | 428 | |||
1611 | 429 | mMockHandler.Animate (1); | ||
1612 | 430 | |||
1613 | 431 | if (i == 300) | ||
1614 | 432 | EXPECT_EQ (opacity, std::numeric_limits <unsigned short>::max ()); | ||
1615 | 433 | else | ||
1616 | 434 | { | ||
1617 | 435 | float rem = opacity - std::numeric_limits <unsigned short>::max () * (1.0f - i / static_cast <float> (ShowdesktopHandler::fade_time)); | ||
1618 | 436 | EXPECT_TRUE (rem <= 1.0f && rem >= -1.0f); | ||
1619 | 437 | } | ||
1620 | 438 | } | ||
1621 | 439 | |||
1622 | 440 | mMockHandler.FadeIn (); | ||
1623 | 441 | |||
1624 | 442 | for (unsigned int i = 0; i < ShowdesktopHandler::fade_time; i++) | ||
1625 | 443 | { | ||
1626 | 444 | unsigned short opacity = std::numeric_limits <unsigned short>::max (); | ||
1627 | 445 | mMockHandler.PaintOpacity (opacity); | ||
1628 | 446 | |||
1629 | 447 | mMockHandler.Animate (1); | ||
1630 | 448 | |||
1631 | 449 | if (i == 300) | ||
1632 | 450 | EXPECT_EQ (opacity, std::numeric_limits <unsigned short>::max ()); | ||
1633 | 451 | else | ||
1634 | 452 | { | ||
1635 | 453 | float rem = opacity - std::numeric_limits <unsigned short>::max () * (i / static_cast <float> (ShowdesktopHandler::fade_time)); | ||
1636 | 454 | EXPECT_TRUE (rem <= 1.0f && rem >= -1.0f); | ||
1637 | 455 | } | ||
1638 | 456 | } | ||
1639 | 457 | |||
1640 | 458 | EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1); | ||
1641 | 459 | } | ||
1642 | 460 | |||
1643 | 461 | TEST_F(UnityShowdesktopHandlerTest, TestAnimationPaintMasks) | ||
1644 | 462 | { | ||
1645 | 463 | MockUnityShowdesktopHandlerWindow mMockWindow; | ||
1646 | 464 | |||
1647 | 465 | EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::makeShared<compiz::WindowInputRemoverInterface, MockWindowInputRemoverTestFadeOutFadeIn>)); | ||
1648 | 466 | |||
1649 | 467 | ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow)); | ||
1650 | 468 | |||
1651 | 469 | EXPECT_CALL (mMockWindow, IsHidden ()); | ||
1652 | 470 | EXPECT_CALL (mMockWindow, DoHide ()); | ||
1653 | 471 | EXPECT_CALL (mMockWindow, DoNotifyHidden ()); | ||
1654 | 472 | |||
1655 | 473 | mMockHandler.FadeOut (); | ||
1656 | 474 | |||
1657 | 475 | EXPECT_CALL (mMockWindow, DoShow ()); | ||
1658 | 476 | EXPECT_CALL (mMockWindow, DoNotifyShown ()); | ||
1659 | 477 | EXPECT_CALL (mMockWindow, GetNoCoreInstanceMask ()); | ||
1660 | 478 | |||
1661 | 479 | mMockHandler.Animate (ShowdesktopHandler::fade_time); | ||
1662 | 480 | |||
1663 | 481 | EXPECT_EQ (mMockHandler.GetPaintMask (), 1); | ||
1664 | 482 | |||
1665 | 483 | mMockHandler.FadeIn (); | ||
1666 | 484 | |||
1667 | 485 | mMockHandler.Animate (ShowdesktopHandler::fade_time); | ||
1668 | 486 | |||
1669 | 487 | EXPECT_EQ (mMockHandler.GetPaintMask (), 0); | ||
1670 | 488 | |||
1671 | 489 | EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1); | ||
1672 | 490 | } | ||
1673 | 491 | |||
1674 | 492 | class MockWindowInputRemoverTestFadeOutFadeInWithShapeEvent : | ||
1675 | 493 | public compiz::WindowInputRemoverInterface | ||
1676 | 494 | { | ||
1677 | 495 | public: | ||
1678 | 496 | |||
1679 | 497 | MockWindowInputRemoverTestFadeOutFadeInWithShapeEvent () | ||
1680 | 498 | { | ||
1681 | 499 | ON_CALL (*this, saveInput ()).WillByDefault (Return (true)); | ||
1682 | 500 | ON_CALL (*this, removeInput ()).WillByDefault (Return (true)); | ||
1683 | 501 | ON_CALL (*this, restoreInput ()).WillByDefault (Return (true)); | ||
1684 | 502 | |||
1685 | 503 | InSequence s; | ||
1686 | 504 | |||
1687 | 505 | EXPECT_CALL (*this, saveInput ()).WillOnce (Return (true)); | ||
1688 | 506 | EXPECT_CALL (*this, removeInput ()).WillOnce (Return (true)); | ||
1689 | 507 | EXPECT_CALL (*this, saveInput ()).WillOnce (Return (true)); | ||
1690 | 508 | EXPECT_CALL (*this, removeInput ()).WillOnce (Return (true)); | ||
1691 | 509 | EXPECT_CALL (*this, restoreInput ()).WillOnce (Return (true)); | ||
1692 | 510 | } | ||
1693 | 511 | |||
1694 | 512 | MOCK_METHOD0 (saveInput, bool ()); | ||
1695 | 513 | MOCK_METHOD0 (removeInput, bool ()); | ||
1696 | 514 | MOCK_METHOD0 (restoreInput, bool ()); | ||
1697 | 515 | }; | ||
1698 | 516 | |||
1699 | 517 | TEST_F(UnityShowdesktopHandlerTest, TestShapeEvent) | ||
1700 | 518 | { | ||
1701 | 519 | MockUnityShowdesktopHandlerWindow mMockWindow; | ||
1702 | 520 | |||
1703 | 521 | EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::makeShared<compiz::WindowInputRemoverInterface, MockWindowInputRemoverTestFadeOutFadeInWithShapeEvent>)); | ||
1704 | 522 | |||
1705 | 523 | ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow)); | ||
1706 | 524 | |||
1707 | 525 | EXPECT_CALL (mMockWindow, IsHidden ()); | ||
1708 | 526 | EXPECT_CALL (mMockWindow, DoHide ()); | ||
1709 | 527 | EXPECT_CALL (mMockWindow, DoNotifyHidden ()); | ||
1710 | 528 | |||
1711 | 529 | mMockHandler.FadeOut (); | ||
1712 | 530 | |||
1713 | 531 | EXPECT_CALL (mMockWindow, DoShow ()); | ||
1714 | 532 | EXPECT_CALL (mMockWindow, DoNotifyShown ()); | ||
1715 | 533 | |||
1716 | 534 | mMockHandler.HandleShapeEvent (); | ||
1717 | 535 | |||
1718 | 536 | mMockHandler.FadeIn (); | ||
1719 | 537 | |||
1720 | 538 | EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1); | ||
1721 | 539 | } |
Great stuff, but needs to conform to our code style :) namely FooBar() methods and _foo instead of mFoo, quick sed should fix it