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