Merge lp:~smspillaz/unity/unity.fix_877778 into lp:unity

Proposed by Sam Spilsbury on 2012-04-06
Status: Merged
Approved by: Andrea Cimitan on 2012-04-06
Approved revision: 2178
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
Reviewer Review Type Date Requested Status
Tim Penhey (community) 2012-04-06 Approve on 2012-04-06
Gord Allott 2012-04-06 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 UnityShowdesktopHandler

Description of the change

Fixes LP #877778 - Introduces tests for UnityShowdesktopHandler

== 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 UnityShowdesktopHandler brokenness, namely the animation going in the wrong direction, damage being applied at the wrong time, handlers not being removed when they should be. Also use PAINT_WINDOW_NO_CORE_INSTANCE_MASK when the window is fully transparent and set the opacity to MAXINT (since the scale plugin uses this to bypass the no paint mask)

== Test Coverage ==

Split UnityShowdesktopHandler out into a separate file, created UnityShowdesktopHandlerWindowInterface, UnityWindow inmplements this, test coverage created in test_showdesktop_handler.cpp using Google Mock and Google Test. Also see AP tests.

To post a comment you must log in.
Gord Allott (gordallott) wrote : Posted in a previous version of this proposal

Great stuff, but needs to conform to our code style :) namely FooBar() methods and _foo instead of mFoo, quick sed should fix it

review: Needs Fixing
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.

review: Needs Fixing
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.

review: Needs Fixing
Tim Penhey (thumper) wrote :

This is fine now. We can fix the style later :)

review: Approve
Unity Merger (unity-merger) wrote :

No commit message specified.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'plugins/unityshell/src/UnityShowdesktopHandler.cpp'
--- plugins/unityshell/src/UnityShowdesktopHandler.cpp 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/UnityShowdesktopHandler.cpp 2012-04-06 08:44:20 +0000
@@ -0,0 +1,215 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/* Compiz unity plugin
3 * unity.h
4 *
5 * Copyright (c) 2010-11 Canonical Ltd.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * Your own copyright notice would go above. You are free to choose whatever
18 * licence you want, just take note that some compiz code is GPL and you will
19 * not be able to re-use it if you want to use a different licence.
20 */
21
22#include <glib.h>
23#include "UnityShowdesktopHandler.h"
24
25namespace unity
26{
27
28ShowdesktopHandlerWindowInterface::~ShowdesktopHandlerWindowInterface()
29{
30}
31
32/* 300 ms */
33const unsigned int ShowdesktopHandler::fade_time = 300;
34std::list <ShowdesktopHandlerWindowInterface *> ShowdesktopHandler::animating_windows (0);
35
36bool ShowdesktopHandler::ShouldHide (ShowdesktopHandlerWindowInterface *wi)
37{
38 if (wi->OverrideRedirect())
39 return false;
40
41 if (!wi->Managed())
42 return false;
43
44 if (wi->Grabbed())
45 return false;
46
47 if (wi->DesktopOrDock())
48 return false;
49
50 if (wi->SkipTaskbarOrPager())
51 return false;
52
53 if (wi->Hidden())
54 if ((wi->ShowDesktopMode() || wi->Shaded()))
55 return false;
56
57 return true;
58}
59
60guint32 ShowdesktopHandler::inhibiting_xid = 0;
61
62void
63ShowdesktopHandler::InhibitLeaveShowdesktopMode (guint32 xid)
64{
65 if (!inhibiting_xid)
66 inhibiting_xid = xid;
67}
68
69void
70ShowdesktopHandler::AllowLeaveShowdesktopMode (guint32 xid)
71{
72 if (inhibiting_xid == xid)
73 inhibiting_xid = 0;
74}
75
76guint32
77ShowdesktopHandler::InhibitingXid()
78{
79 return inhibiting_xid;
80}
81
82ShowdesktopHandler::ShowdesktopHandler (ShowdesktopHandlerWindowInterface *wi) :
83 showdesktop_handler_window_interface_ (wi),
84 remover_ (wi->InputRemover()),
85 state_ (StateVisible),
86 progress_ (0.0f)
87{
88}
89
90ShowdesktopHandler::~ShowdesktopHandler()
91{
92}
93
94void ShowdesktopHandler::FadeOut()
95{
96 if (state_ != StateVisible && state_ != StateFadeIn)
97 return;
98
99 state_ = ShowdesktopHandler::StateFadeOut;
100 progress_ = 0.0f;
101
102 was_hidden_ = showdesktop_handler_window_interface_->Hidden();
103
104 if (!was_hidden_)
105 {
106 showdesktop_handler_window_interface_->Hide();
107 showdesktop_handler_window_interface_->NotifyHidden();
108 remover_->save();
109 remover_->remove();
110
111 if (std::find (animating_windows.begin(),
112 animating_windows.end(),
113 showdesktop_handler_window_interface_) == animating_windows.end())
114 animating_windows.push_back (showdesktop_handler_window_interface_);
115
116 }
117}
118
119void ShowdesktopHandler::FadeIn()
120{
121 if (state_ != StateInvisible && state_ != StateFadeOut)
122 return;
123
124 state_ = ShowdesktopHandler::StateFadeIn;
125
126 if (!was_hidden_)
127 {
128 showdesktop_handler_window_interface_->Show();
129 showdesktop_handler_window_interface_->NotifyShown();
130 remover_->restore();
131
132 if (std::find (animating_windows.begin(),
133 animating_windows.end(),
134 showdesktop_handler_window_interface_) == animating_windows.end())
135 animating_windows.push_back(showdesktop_handler_window_interface_);
136 }
137}
138
139ShowdesktopHandlerWindowInterface::PostPaintAction ShowdesktopHandler::Animate (unsigned int ms)
140{
141 float inc = ms / static_cast <float> (fade_time);
142
143 if (state_ == ShowdesktopHandler::StateFadeOut)
144 {
145 progress_ += inc;
146 if (progress_ >= 1.0f)
147 {
148 progress_ = 1.0f;
149 state_ = StateInvisible;
150 }
151 }
152 else if (state_ == StateFadeIn)
153 {
154 progress_ -= inc;
155 if (progress_ <= 0.0f)
156 {
157 progress_ = 0.0f;
158 state_ = StateVisible;
159 }
160 }
161 else if (state_ == StateVisible)
162 return ShowdesktopHandlerWindowInterface::PostPaintAction::Remove;
163 else if (state_ == StateInvisible)
164 return ShowdesktopHandlerWindowInterface::PostPaintAction::Wait;
165
166 return ShowdesktopHandlerWindowInterface::PostPaintAction::Damage;
167}
168
169void ShowdesktopHandler::PaintOpacity (unsigned short &opacity)
170{
171 if (progress_ == 1.0f || progress_ == 0.0f)
172 opacity = std::numeric_limits <unsigned short>::max();
173 else
174 opacity *= (1.0f - progress_);
175}
176
177unsigned int ShowdesktopHandler::GetPaintMask()
178{
179 return (progress_ == 1.0f) ? showdesktop_handler_window_interface_->NoCoreInstanceMask() : 0;
180}
181
182void ShowdesktopHandler::HandleShapeEvent()
183{
184 /* Ignore sent events from the InputRemover */
185 if (remover_)
186 {
187 remover_->save();
188 remover_->remove();
189 }
190}
191
192void ShowdesktopHandler::WindowFocusChangeNotify()
193{
194 if (showdesktop_handler_window_interface_->Minimized())
195 {
196 for (ShowdesktopHandlerWindowInterface *w : animating_windows)
197 w->DisableFocus();
198
199 showdesktop_handler_window_interface_->MoveFocusAway();
200
201 for (ShowdesktopHandlerWindowInterface *w : animating_windows)
202 w->EnableFocus();
203 }
204}
205
206void ShowdesktopHandler::UpdateFrameRegion (CompRegion &r)
207{
208 r = CompRegion();
209
210 /* Ensure no other plugins can touch this frame region */
211 showdesktop_handler_window_interface_->OverrideFrameRegion (r);
212}
213
214}
215
0216
=== added file 'plugins/unityshell/src/UnityShowdesktopHandler.h'
--- plugins/unityshell/src/UnityShowdesktopHandler.h 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/UnityShowdesktopHandler.h 2012-04-06 08:44:20 +0000
@@ -0,0 +1,158 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/* Compiz unity plugin
3 * unity.h
4 *
5 * Copyright (c) 2010-11 Canonical Ltd.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * Your own copyright notice would go above. You are free to choose whatever
18 * licence you want, just take note that some compiz code is GPL and you will
19 * not be able to re-use it if you want to use a different licence.
20 */
21#ifndef UNITY_SHOWDESKTOP_HANDLER_H
22#define UNITY_SHOWDESKTOP_HANDLER_H
23
24#include <list>
25#include <algorithm>
26#include <core/region.h>
27
28#include <gio/gio.h>
29
30#include "inputremover.h"
31
32namespace unity
33{
34
35class ShowdesktopHandlerWindowInterface
36{
37 public:
38
39 enum class PostPaintAction {
40 Wait = 0,
41 Damage = 1,
42 Remove = 2
43 };
44
45 virtual ~ShowdesktopHandlerWindowInterface ();
46
47 void EnableFocus () { DoEnableFocus (); }
48 void DisableFocus () { DoDisableFocus (); }
49
50 bool OverrideRedirect () { return IsOverrideRedirect (); }
51 bool Managed () { return IsManaged (); }
52 bool Grabbed () { return IsGrabbed (); }
53 bool DesktopOrDock () { return IsDesktopOrDock (); }
54 bool SkipTaskbarOrPager () { return IsSkipTaskbarOrPager (); }
55 bool Hidden () { return IsHidden (); }
56 bool Shaded () { return IsShaded (); }
57 bool Minimized () { return IsMinimized (); }
58 bool ShowDesktopMode () { return IsInShowdesktopMode (); }
59 void OverrideFrameRegion (CompRegion &r) { return DoOverrideFrameRegion (r); }
60
61 void Hide () { DoHide (); }
62 void NotifyHidden () { DoNotifyHidden (); }
63 void Show () { DoShow (); }
64 void NotifyShown () { DoNotifyShown (); }
65 void MoveFocusAway () { DoMoveFocusAway (); }
66
67 PostPaintAction HandleAnimations (unsigned int ms) { return DoHandleAnimations (ms); }
68 void AddDamage () { DoAddDamage (); }
69
70 void DeleteHandler () { DoDeleteHandler (); }
71
72 unsigned int NoCoreInstanceMask () { return GetNoCoreInstanceMask (); }
73
74 compiz::WindowInputRemoverInterface::Ptr InputRemover () { return GetInputRemover (); }
75
76 private:
77
78 virtual void DoEnableFocus () = 0;
79 virtual void DoDisableFocus () = 0;
80
81 virtual bool IsOverrideRedirect () = 0;
82 virtual bool IsManaged () = 0;
83 virtual bool IsGrabbed () = 0;
84 virtual bool IsDesktopOrDock () = 0;
85
86 virtual bool IsSkipTaskbarOrPager () = 0;
87 virtual bool IsHidden () = 0;
88 virtual bool IsInShowdesktopMode () = 0;
89 virtual bool IsShaded () = 0;
90
91 virtual bool IsMinimized () = 0;
92
93 virtual void DoOverrideFrameRegion (CompRegion &) = 0;
94
95 virtual void DoHide () = 0;
96 virtual void DoNotifyHidden () = 0;
97 virtual void DoShow () = 0;
98 virtual void DoNotifyShown () = 0;
99
100 virtual void DoMoveFocusAway () = 0;
101 virtual PostPaintAction DoHandleAnimations (unsigned int ms) = 0;
102 virtual void DoAddDamage () = 0;
103
104 virtual void DoDeleteHandler () = 0;
105
106 virtual unsigned int GetNoCoreInstanceMask () = 0;
107
108 virtual compiz::WindowInputRemoverInterface::Ptr GetInputRemover () = 0;
109};
110
111class ShowdesktopHandler
112{
113 public:
114
115 ShowdesktopHandler (ShowdesktopHandlerWindowInterface *uwi);
116 ~ShowdesktopHandler ();
117
118 typedef enum {
119 StateVisible = 0,
120 StateFadeOut = 1,
121 StateFadeIn = 2,
122 StateInvisible = 3
123 } State;
124
125public:
126
127 void FadeOut ();
128 void FadeIn ();
129 ShowdesktopHandlerWindowInterface::PostPaintAction Animate (unsigned int ms);
130 void PaintOpacity (unsigned short &opacity);
131 unsigned int GetPaintMask ();
132 void HandleShapeEvent ();
133 void WindowFocusChangeNotify ();
134 void UpdateFrameRegion (CompRegion &r);
135
136 ShowdesktopHandler::State GetState ();
137
138 static const unsigned int fade_time;
139 static std::list <ShowdesktopHandlerWindowInterface *> animating_windows;
140 static bool ShouldHide (ShowdesktopHandlerWindowInterface *);
141 static void InhibitLeaveShowdesktopMode (guint32 xid);
142 static void AllowLeaveShowdesktopMode (guint32 xid);
143 static guint32 InhibitingXid ();
144
145private:
146
147 ShowdesktopHandlerWindowInterface *showdesktop_handler_window_interface_;
148 compiz::WindowInputRemoverInterface::Ptr remover_;
149 ShowdesktopHandler::State state_;
150 float progress_;
151 bool was_hidden_;
152 static guint32 inhibiting_xid;
153};
154
155}
156
157
158#endif
0159
=== modified file 'plugins/unityshell/src/inputremover.cpp'
--- plugins/unityshell/src/inputremover.cpp 2011-09-28 16:25:42 +0000
+++ plugins/unityshell/src/inputremover.cpp 2012-04-06 08:44:20 +0000
@@ -24,6 +24,10 @@
24#include <cstdio>24#include <cstdio>
25#include <cstring>25#include <cstring>
2626
27compiz::WindowInputRemoverInterface::~WindowInputRemoverInterface ()
28{
29}
30
27compiz::WindowInputRemover::WindowInputRemover (Display *dpy,31compiz::WindowInputRemover::WindowInputRemover (Display *dpy,
28 Window xid) :32 Window xid) :
29 mDpy (dpy),33 mDpy (dpy),
@@ -203,7 +207,7 @@
203}207}
204208
205bool209bool
206compiz::WindowInputRemover::save ()210compiz::WindowInputRemover::saveInput ()
207{211{
208 XRectangle *rects;212 XRectangle *rects;
209 int count = 0, ordering;213 int count = 0, ordering;
@@ -267,7 +271,7 @@
267}271}
268272
269bool273bool
270compiz::WindowInputRemover::remove ()274compiz::WindowInputRemover::removeInput ()
271{275{
272 if (!mNInputRects)276 if (!mNInputRects)
273 if (!save ())277 if (!save ())
@@ -290,7 +294,7 @@
290}294}
291295
292bool296bool
293compiz::WindowInputRemover::restore ()297compiz::WindowInputRemover::restoreInput ()
294{298{
295 XShapeSelectInput (mDpy, mShapeWindow, NoEventMask);299 XShapeSelectInput (mDpy, mShapeWindow, NoEventMask);
296300
297301
=== modified file 'plugins/unityshell/src/inputremover.h'
--- plugins/unityshell/src/inputremover.h 2011-09-13 12:52:31 +0000
+++ plugins/unityshell/src/inputremover.h 2012-04-06 08:44:20 +0000
@@ -22,6 +22,8 @@
22#ifndef _COMPIZ_INPUTREMOVER_H22#ifndef _COMPIZ_INPUTREMOVER_H
23#define _COMPIZ_INPUTREMOVER_H23#define _COMPIZ_INPUTREMOVER_H
2424
25#include <memory>
26
25#include <X11/Xlib.h>27#include <X11/Xlib.h>
26#include <X11/Xatom.h>28#include <X11/Xatom.h>
27#include <X11/extensions/shape.h>29#include <X11/extensions/shape.h>
@@ -29,19 +31,39 @@
29// Will be merged back into compiz31// Will be merged back into compiz
30namespace compiz {32namespace compiz {
3133
32class WindowInputRemover34class WindowInputRemoverInterface
35{
36 public:
37
38 typedef std::shared_ptr <WindowInputRemoverInterface> Ptr;
39
40 bool save () { return saveInput (); }
41 bool remove () { return removeInput (); }
42 bool restore () { return restoreInput (); }
43
44 virtual ~WindowInputRemoverInterface ();
45
46 protected:
47
48 virtual bool saveInput () = 0;
49 virtual bool removeInput () = 0;
50 virtual bool restoreInput () = 0;
51};
52
53class WindowInputRemover :
54 public WindowInputRemoverInterface
33{55{
34public:56public:
3557
36 WindowInputRemover (Display *, Window xid);58 WindowInputRemover (Display *, Window xid);
37 ~WindowInputRemover ();59 ~WindowInputRemover ();
3860
39 bool save ();
40 bool remove ();
41 bool restore ();
42
43private:61private:
4462
63 bool saveInput ();
64 bool removeInput ();
65 bool restoreInput ();
66
45 void sendShapeNotify ();67 void sendShapeNotify ();
4668
47 Display *mDpy;69 Display *mDpy;
4870
=== modified file 'plugins/unityshell/src/unityshell.cpp'
--- plugins/unityshell/src/unityshell.cpp 2012-04-05 23:28:43 +0000
+++ plugins/unityshell/src/unityshell.cpp 2012-04-06 08:44:20 +0000
@@ -963,7 +963,9 @@
963{963{
964 for (CompWindow *w : screen->windows ())964 for (CompWindow *w : screen->windows ())
965 {965 {
966 if (UnityShowdesktopHandler::shouldHide (w))966 UnityWindow *uw = UnityWindow::get (w);
967
968 if (ShowdesktopHandler::ShouldHide (static_cast <ShowdesktopHandlerWindowInterface *> (uw)))
967 {969 {
968 UnityWindow::get (w)->enterShowDesktop ();970 UnityWindow::get (w)->enterShowDesktop ();
969 // the animation plugin does strange things here ...971 // the animation plugin does strange things here ...
@@ -1000,16 +1002,16 @@
1000 /* Where a window is inhibiting, only allow the window1002 /* Where a window is inhibiting, only allow the window
1001 * that is inhibiting the leave show desktop to actually1003 * that is inhibiting the leave show desktop to actually
1002 * fade in again - all other windows should remain faded out */1004 * fade in again - all other windows should remain faded out */
1003 if (!UnityShowdesktopHandler::inhibitingXid ())1005 if (!ShowdesktopHandler::InhibitingXid ())
1004 {1006 {
1005 for (CompWindow *cw : screen->windows ())1007 for (CompWindow *cw : screen->windows ())
1006 {1008 {
1007 if (cw->inShowDesktopMode ())1009 if (cw->inShowDesktopMode ())
1008 {1010 {
1009 UnityWindow::get (cw)->leaveShowDesktop ();1011 UnityWindow::get (cw)->leaveShowDesktop ();
1010 // the animation plugin does strange things here ...1012 // the animation plugin does strange things here ...
1011 // if this notification is sent1013 // if this notification is sent
1012 //cw->windowNotify (CompWindowNotifyLeaveShowDesktopMode);1014 //cw->windowNotify (CompWindowNotifyLeaveShowDesktopMode);
1013 }1015 }
1014 }1016 }
10151017
@@ -1019,12 +1021,12 @@
1019 }1021 }
1020 else1022 else
1021 {1023 {
1022 CompWindow *cw = screen->findWindow (UnityShowdesktopHandler::inhibitingXid ());1024 CompWindow *cw = screen->findWindow (ShowdesktopHandler::InhibitingXid ());
1023 if (cw)1025 if (cw)
1024 {1026 {
1025 if (cw->inShowDesktopMode ())1027 if (cw->inShowDesktopMode ())
1026 {1028 {
1027 UnityWindow::get (cw)->leaveShowDesktop ();1029 UnityWindow::get (cw)->leaveShowDesktop ();
1028 }1030 }
1029 }1031 }
1030 }1032 }
@@ -1033,227 +1035,161 @@
1033void UnityWindow::enterShowDesktop ()1035void UnityWindow::enterShowDesktop ()
1034{1036{
1035 if (!mShowdesktopHandler)1037 if (!mShowdesktopHandler)
1036 mShowdesktopHandler = new UnityShowdesktopHandler (window);1038 mShowdesktopHandler = new ShowdesktopHandler (static_cast <ShowdesktopHandlerWindowInterface *> (this));
10371039
1038 window->setShowDesktopMode (true);1040 window->setShowDesktopMode (true);
1039 mShowdesktopHandler->fadeOut ();1041 mShowdesktopHandler->FadeOut ();
1040}1042}
10411043
1042void UnityWindow::leaveShowDesktop ()1044void UnityWindow::leaveShowDesktop ()
1043{1045{
1044 if (mShowdesktopHandler)1046 if (mShowdesktopHandler)
1045 {1047 {
1046 mShowdesktopHandler->fadeIn ();1048 mShowdesktopHandler->FadeIn ();
1047 window->setShowDesktopMode (false);1049 window->setShowDesktopMode (false);
1048 delete mShowdesktopHandler;
1049 mShowdesktopHandler = NULL;
1050 }1050 }
1051}1051}
10521052
1053void UnityWindow::activate ()1053void UnityWindow::activate ()
1054{1054{
1055 UnityShowdesktopHandler::inhibitLeaveShowdesktopMode (window->id ());1055 ShowdesktopHandler::InhibitLeaveShowdesktopMode (window->id ());
1056 window->activate ();1056 window->activate ();
1057 UnityShowdesktopHandler::allowLeaveShowdesktopMode (window->id ());1057 ShowdesktopHandler::AllowLeaveShowdesktopMode (window->id ());
1058}1058}
10591059
1060bool UnityWindow::handleAnimations (unsigned int ms)1060void UnityWindow::DoEnableFocus ()
1061{1061{
1062 window->focusSetEnabled (this, true);
1063}
1064
1065void UnityWindow::DoDisableFocus ()
1066{
1067 window->focusSetEnabled (this, false);
1068}
1069
1070bool UnityWindow::IsOverrideRedirect ()
1071{
1072 return window->overrideRedirect ();
1073}
1074
1075bool UnityWindow::IsManaged ()
1076{
1077 return window->managed ();
1078}
1079
1080bool UnityWindow::IsGrabbed ()
1081{
1082 return window->grabbed ();
1083}
1084
1085bool UnityWindow::IsDesktopOrDock ()
1086{
1087 return (window->type () & (CompWindowTypeDesktopMask | CompWindowTypeDockMask));
1088}
1089
1090bool UnityWindow::IsSkipTaskbarOrPager ()
1091{
1092 return (window->state () & (CompWindowStateSkipTaskbarMask | CompWindowStateSkipPagerMask));
1093}
1094
1095bool UnityWindow::IsInShowdesktopMode ()
1096{
1097 return window->inShowDesktopMode ();
1098}
1099
1100bool UnityWindow::IsHidden ()
1101{
1102 return window->state () & CompWindowStateHiddenMask;
1103}
1104
1105bool UnityWindow::IsShaded ()
1106{
1107 return window->shaded ();
1108}
1109
1110bool UnityWindow::IsMinimized ()
1111{
1112 return window->minimized ();
1113}
1114
1115void UnityWindow::DoOverrideFrameRegion (CompRegion &region)
1116{
1117 unsigned int oldUpdateFrameRegionIndex = window->updateFrameRegionGetCurrentIndex ();
1118
1119 window->updateFrameRegionSetCurrentIndex (MAXSHORT);
1120 window->updateFrameRegion (region);
1121 window->updateFrameRegionSetCurrentIndex (oldUpdateFrameRegionIndex);
1122}
1123
1124void UnityWindow::DoHide ()
1125{
1126 window->changeState (window->state () | CompWindowStateHiddenMask);
1127}
1128
1129void UnityWindow::DoNotifyHidden ()
1130{
1131 window->windowNotify (CompWindowNotifyHide);
1132}
1133
1134void UnityWindow::DoShow ()
1135{
1136 window->changeState (window->state () & ~(CompWindowStateHiddenMask));
1137}
1138
1139void UnityWindow::DoNotifyShown ()
1140{
1141 window->windowNotify (CompWindowNotifyShow);
1142}
1143
1144void UnityWindow::DoMoveFocusAway ()
1145{
1146 window->moveInputFocusToOtherWindow ();
1147}
1148
1149ShowdesktopHandlerWindowInterface::PostPaintAction UnityWindow::DoHandleAnimations (unsigned int ms)
1150{
1151 ShowdesktopHandlerWindowInterface::PostPaintAction action = ShowdesktopHandlerWindowInterface::PostPaintAction::Wait;
1152
1062 if (mShowdesktopHandler)1153 if (mShowdesktopHandler)
1063 if (mShowdesktopHandler->animate (ms))1154 action = mShowdesktopHandler->Animate (ms);
1064 {1155
1065 delete mShowdesktopHandler;1156 return action;
1066 mShowdesktopHandler = NULL;1157}
1067 return true;1158
1068 }1159void UnityWindow::DoAddDamage ()
10691160{
1070 return false;1161 cWindow->addDamage ();
1071}1162}
10721163
1073/* 300 ms */1164void UnityWindow::DoDeleteHandler ()
1074const unsigned int UnityShowdesktopHandler::fade_time = 300;1165{
1075CompWindowList UnityShowdesktopHandler::animating_windows (0);1166 delete mShowdesktopHandler;
10761167 mShowdesktopHandler = NULL;
1077bool UnityShowdesktopHandler::shouldHide (CompWindow *w)1168
1078{1169 window->updateFrameRegion ();
1079 if (w->overrideRedirect ())1170}
1080 return false;1171
10811172compiz::WindowInputRemoverInterface::Ptr
1082 if (!w->managed ())1173UnityWindow::GetInputRemover ()
1083 return false;1174{
10841175 return compiz::WindowInputRemoverInterface::Ptr (new compiz::WindowInputRemover (screen->dpy (), window->id ()));
1085 if (w->grabbed ())1176}
1086 return false;1177
10871178unsigned int
1088 if (w->wmType () & (CompWindowTypeDesktopMask |1179UnityWindow::GetNoCoreInstanceMask ()
1089 CompWindowTypeDockMask))1180{
1090 return false;1181 return PAINT_WINDOW_NO_CORE_INSTANCE_MASK;
10911182}
1092 if (w->state () & (CompWindowStateSkipPagerMask |1183
1093 CompWindowStateSkipTaskbarMask))1184void UnityWindow::handleEvent (XEvent *event)
1094 return false;1185{
10951186 if (screen->XShape () &&
1096 if ((w->state () & CompWindowStateHiddenMask))1187 event->type == screen->shapeEvent () + ShapeNotify &&
1097 if (!(w->inShowDesktopMode () || w->shaded ()))
1098 return false;
1099
1100 return true;
1101}
1102
1103guint32 UnityShowdesktopHandler::mInhibitingXid = 0;
1104
1105void
1106UnityShowdesktopHandler::inhibitLeaveShowdesktopMode (guint32 xid)
1107{
1108 if (!mInhibitingXid)
1109 mInhibitingXid = xid;
1110}
1111
1112void
1113UnityShowdesktopHandler::allowLeaveShowdesktopMode (guint32 xid)
1114{
1115 if (mInhibitingXid == xid)
1116 mInhibitingXid = 0;
1117}
1118
1119guint32
1120UnityShowdesktopHandler::inhibitingXid ()
1121{
1122 return mInhibitingXid;
1123}
1124
1125UnityShowdesktopHandler::UnityShowdesktopHandler (CompWindow *w) :
1126 mWindow (w),
1127 mRemover (new compiz::WindowInputRemover (screen->dpy (), w->id ())),
1128 mState (Visible),
1129 mProgress (0.0f)
1130{
1131}
1132
1133UnityShowdesktopHandler::~UnityShowdesktopHandler ()
1134{
1135 if (mRemover)
1136 delete mRemover;
1137}
1138
1139void UnityShowdesktopHandler::fadeOut ()
1140{
1141 mState = UnityShowdesktopHandler::FadeOut;
1142 mProgress = 1.0f;
1143
1144 mWasHidden = mWindow->state () & CompWindowStateHiddenMask;
1145
1146 if (!mWasHidden)
1147 {
1148 mWindow->changeState (mWindow->state () | CompWindowStateHiddenMask);
1149 mWindow->windowNotify (CompWindowNotifyHide);
1150 mRemover->save ();
1151 mRemover->remove ();
1152 }
1153
1154 CompositeWindow::get (mWindow)->addDamage ();
1155
1156 if (std::find (animating_windows.begin(),
1157 animating_windows.end(),
1158 mWindow) == animating_windows.end())
1159 animating_windows.push_back(mWindow);
1160}
1161
1162void UnityShowdesktopHandler::fadeIn ()
1163{
1164 mState = UnityShowdesktopHandler::FadeIn;
1165
1166 if (!mWasHidden)
1167 {
1168 mWindow->changeState (mWindow->state () & ~CompWindowStateHiddenMask);
1169 mWindow->windowNotify (CompWindowNotifyShow);
1170 mRemover->restore ();
1171 }
1172
1173 CompositeWindow::get (mWindow)->addDamage ();
1174}
1175
1176bool UnityShowdesktopHandler::animate (unsigned int ms)
1177{
1178 float inc = fade_time / (float) ms;
1179
1180 if (mState == UnityShowdesktopHandler::FadeOut)
1181 {
1182 mProgress -= inc;
1183 if (mProgress <= 0.0f)
1184 {
1185 mProgress = 0.0f;
1186 mState = Invisible;
1187 }
1188 else
1189 CompositeWindow::get (mWindow)->addDamage ();
1190 }
1191 else if (mState == FadeIn)
1192 {
1193 mProgress += inc;
1194 if (mProgress >= 1.0f)
1195 {
1196 mProgress = 1.0f;
1197 mState = Visible;
1198
1199 return true;
1200 }
1201 else
1202 CompositeWindow::get (mWindow)->addDamage ();
1203 }
1204
1205 return false;
1206}
1207
1208void UnityShowdesktopHandler::paintAttrib (GLWindowPaintAttrib &attrib)
1209{
1210 attrib.opacity = static_cast <int> (static_cast <float> (attrib.opacity) * mProgress);
1211}
1212
1213unsigned int UnityShowdesktopHandler::getPaintMask ()
1214{
1215 return 0;
1216}
1217
1218void UnityShowdesktopHandler::handleEvent (XEvent *event)
1219{
1220 /* Ignore sent events from the InputRemover */
1221 if (screen->XShape () && event->type ==
1222 screen->shapeEvent () + ShapeNotify &&
1223 !event->xany.send_event)1188 !event->xany.send_event)
1224 {1189 {
1225 if (mRemover)1190 if (mShowdesktopHandler)
1226 {1191 mShowdesktopHandler->HandleShapeEvent ();
1227 mRemover->save ();1192 }
1228 mRemover->remove ();
1229 }
1230 }
1231}
1232
1233void UnityShowdesktopHandler::windowNotify (CompWindowNotify n)
1234{
1235 if (n == CompWindowNotifyFocusChange && mWindow->minimized ())
1236 {
1237 for (CompWindow *w : animating_windows)
1238 w->focusSetEnabled (UnityWindow::get (w), false);
1239
1240 mWindow->moveInputFocusToOtherWindow ();
1241
1242 for (CompWindow *w : animating_windows)
1243 w->focusSetEnabled (UnityWindow::get (w), true);
1244 }
1245}
1246
1247void UnityShowdesktopHandler::updateFrameRegion (CompRegion &r)
1248{
1249 unsigned int oldUpdateFrameRegionIndex;
1250 r = CompRegion ();
1251
1252 /* Ensure no other plugins can touch this frame region */
1253 oldUpdateFrameRegionIndex = mWindow->updateFrameRegionGetCurrentIndex ();
1254 mWindow->updateFrameRegionSetCurrentIndex (MAXSHORT);
1255 mWindow->updateFrameRegion (r);
1256 mWindow->updateFrameRegionSetCurrentIndex (oldUpdateFrameRegionIndex);
1257}1193}
12581194
1259/* called whenever we need to repaint parts of the screen */1195/* called whenever we need to repaint parts of the screen */
@@ -1335,16 +1271,10 @@
13351271
1336void UnityScreen::preparePaint(int ms)1272void UnityScreen::preparePaint(int ms)
1337{1273{
1338 CompWindowList remove_windows;
1339
1340 cScreen->preparePaint(ms);1274 cScreen->preparePaint(ms);
13411275
1342 for (CompWindow *w : UnityShowdesktopHandler::animating_windows)1276 for (ShowdesktopHandlerWindowInterface *wi : ShowdesktopHandler::animating_windows)
1343 if (UnityWindow::get (w)->handleAnimations (ms))1277 wi->HandleAnimations (ms);
1344 remove_windows.push_back(w);
1345
1346 for (CompWindow *w : remove_windows)
1347 UnityShowdesktopHandler::animating_windows.remove (w);
13481278
1349 if (damaged)1279 if (damaged)
1350 {1280 {
@@ -1354,6 +1284,28 @@
13541284
1355}1285}
13561286
1287void UnityScreen::donePaint()
1288{
1289 std::list <ShowdesktopHandlerWindowInterface *> remove_windows;
1290
1291 for (ShowdesktopHandlerWindowInterface *wi : ShowdesktopHandler::animating_windows)
1292 {
1293 ShowdesktopHandlerWindowInterface::PostPaintAction action = wi->HandleAnimations (0);
1294 if (action == ShowdesktopHandlerWindowInterface::PostPaintAction::Remove)
1295 remove_windows.push_back(wi);
1296 else if (action == ShowdesktopHandlerWindowInterface::PostPaintAction::Damage)
1297 wi->AddDamage ();
1298 }
1299
1300 for (ShowdesktopHandlerWindowInterface *wi : remove_windows)
1301 {
1302 wi->DeleteHandler ();
1303 ShowdesktopHandler::animating_windows.remove (wi);
1304 }
1305
1306 cScreen->donePaint ();
1307}
1308
1357/* Grab changed nux regions and add damage rects for them */1309/* Grab changed nux regions and add damage rects for them */
1358void UnityScreen::damageNuxRegions()1310void UnityScreen::damageNuxRegions()
1359{1311{
@@ -1489,7 +1441,7 @@
1489 break;1441 break;
1490 }1442 }
1491 case MapRequest:1443 case MapRequest:
1492 UnityShowdesktopHandler::inhibitLeaveShowdesktopMode (event->xmaprequest.window);1444 ShowdesktopHandler::InhibitLeaveShowdesktopMode (event->xmaprequest.window);
1493 break;1445 break;
1494 default:1446 default:
1495 if (screen->shapeEvent () + ShapeNotify == event->type)1447 if (screen->shapeEvent () + ShapeNotify == event->type)
@@ -1501,8 +1453,7 @@
1501 {1453 {
1502 UnityWindow *uw = UnityWindow::get (w);1454 UnityWindow *uw = UnityWindow::get (w);
15031455
1504 if (uw->mShowdesktopHandler)1456 uw->handleEvent(event);
1505 uw->mShowdesktopHandler->handleEvent(event);
1506 }1457 }
1507 }1458 }
1508 break;1459 break;
@@ -1523,7 +1474,7 @@
1523 }1474 }
1524 break;1475 break;
1525 case MapRequest:1476 case MapRequest:
1526 UnityShowdesktopHandler::allowLeaveShowdesktopMode (event->xmaprequest.window);1477 ShowdesktopHandler::AllowLeaveShowdesktopMode (event->xmaprequest.window);
1527 break;1478 break;
1528 }1479 }
15291480
@@ -2235,8 +2186,8 @@
2235 }2186 }
2236 else if (mShowdesktopHandler)2187 else if (mShowdesktopHandler)
2237 {2188 {
2238 mShowdesktopHandler->paintAttrib (wAttrib);2189 mShowdesktopHandler->PaintOpacity (wAttrib.opacity);
2239 mask |= mShowdesktopHandler->getPaintMask ();2190 mask |= mShowdesktopHandler->GetPaintMask ();
2240 }2191 }
22412192
2242 std::vector<Window> const& tray_xids = uScreen->panel_controller_->GetTrayXids();2193 std::vector<Window> const& tray_xids = uScreen->panel_controller_->GetTrayXids();
@@ -2460,7 +2411,8 @@
2460 }2411 }
2461 else if (mShowdesktopHandler)2412 else if (mShowdesktopHandler)
2462 {2413 {
2463 mShowdesktopHandler->windowNotify (n);2414 if (n == CompWindowNotifyFocusChange)
2415 mShowdesktopHandler->WindowFocusChangeNotify ();
2464 }2416 }
24652417
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.
@@ -2499,7 +2451,7 @@
2499 if (mMinimizeHandler)2451 if (mMinimizeHandler)
2500 mMinimizeHandler->updateFrameRegion (region);2452 mMinimizeHandler->updateFrameRegion (region);
2501 else if (mShowdesktopHandler)2453 else if (mShowdesktopHandler)
2502 mShowdesktopHandler->updateFrameRegion (region);2454 mShowdesktopHandler->UpdateFrameRegion (region);
2503 else2455 else
2504 window->updateFrameRegion (region);2456 window->updateFrameRegion (region);
2505}2457}
@@ -3039,7 +2991,7 @@
3039 window->minimize ();2991 window->minimize ();
3040 }2992 }
30412993
3042 UnityShowdesktopHandler::animating_windows.remove (window);2994 ShowdesktopHandler::animating_windows.remove (static_cast <ShowdesktopHandlerWindowInterface *> (this));
30432995
3044 if (mShowdesktopHandler)2996 if (mShowdesktopHandler)
3045 delete mShowdesktopHandler;2997 delete mShowdesktopHandler;
30462998
=== modified file 'plugins/unityshell/src/unityshell.h'
--- plugins/unityshell/src/unityshell.h 2012-04-05 16:10:46 +0000
+++ plugins/unityshell/src/unityshell.h 2012-04-06 08:44:20 +0000
@@ -50,6 +50,7 @@
50#include "SwitcherController.h"50#include "SwitcherController.h"
51#include "UBusWrapper.h"51#include "UBusWrapper.h"
52#include "UnityshellPrivate.h"52#include "UnityshellPrivate.h"
53#include "UnityShowdesktopHandler.h"
53#ifndef USE_GLES54#ifndef USE_GLES
54#include "ScreenEffectFramebufferObject.h"55#include "ScreenEffectFramebufferObject.h"
55#endif56#endif
@@ -64,51 +65,6 @@
64namespace unity65namespace unity
65{66{
6667
67class UnityShowdesktopHandler
68{
69 public:
70
71 UnityShowdesktopHandler (CompWindow *w);
72 ~UnityShowdesktopHandler ();
73
74 typedef enum {
75 Visible = 0,
76 FadeOut = 1,
77 FadeIn = 2,
78 Invisible = 3
79 } State;
80
81public:
82
83 void fadeOut ();
84 void fadeIn ();
85 bool animate (unsigned int ms);
86 void paintAttrib (GLWindowPaintAttrib &attrib);
87 unsigned int getPaintMask ();
88 void handleEvent (XEvent *);
89 void windowNotify (CompWindowNotify n);
90 void updateFrameRegion (CompRegion &r);
91
92 UnityShowdesktopHandler::State state ();
93
94 static const unsigned int fade_time;
95 static CompWindowList animating_windows;
96 static bool shouldHide (CompWindow *);
97 static void inhibitLeaveShowdesktopMode (guint32 xid);
98 static void allowLeaveShowdesktopMode (guint32 xid);
99 static guint32 inhibitingXid ();
100
101private:
102
103 CompWindow *mWindow;
104 compiz::WindowInputRemover *mRemover;
105 UnityShowdesktopHandler::State mState;
106 float mProgress;
107 bool mWasHidden;
108 static guint32 mInhibitingXid;
109};
110
111
112/* base screen class */68/* base screen class */
113class UnityScreen :69class UnityScreen :
114 public unity::debug::Introspectable,70 public unity::debug::Introspectable,
@@ -145,6 +101,7 @@
145101
146 void preparePaint (int ms);102 void preparePaint (int ms);
147 void paintFboForOutput (CompOutput *output);103 void paintFboForOutput (CompOutput *output);
104 void donePaint ();
148105
149 void RaiseInputWindows();106 void RaiseInputWindows();
150107
@@ -358,6 +315,7 @@
358class UnityWindow :315class UnityWindow :
359 public WindowInterface,316 public WindowInterface,
360 public GLWindowInterface,317 public GLWindowInterface,
318 public ShowdesktopHandlerWindowInterface,
361 public BaseSwitchWindow,319 public BaseSwitchWindow,
362 public PluginClassHandler <UnityWindow, CompWindow>320 public PluginClassHandler <UnityWindow, CompWindow>
363{321{
@@ -414,18 +372,50 @@
414372
415 void enterShowDesktop ();373 void enterShowDesktop ();
416 void leaveShowDesktop ();374 void leaveShowDesktop ();
417 bool handleAnimations (unsigned int ms);375 bool HandleAnimations (unsigned int ms);
376
377 void handleEvent (XEvent *event);
418378
419 typedef compiz::CompizMinimizedWindowHandler<UnityScreen, UnityWindow>379 typedef compiz::CompizMinimizedWindowHandler<UnityScreen, UnityWindow>
420 UnityMinimizedHandler;380 UnityMinimizedHandler;
421 std::unique_ptr <UnityMinimizedHandler> mMinimizeHandler;381 std::unique_ptr <UnityMinimizedHandler> mMinimizeHandler;
422382
423 UnityShowdesktopHandler *mShowdesktopHandler;383 ShowdesktopHandler *mShowdesktopHandler;
424384
425private:385private:
426386
427 guint focusdesktop_handle_;387 guint focusdesktop_handle_;
428 static gboolean FocusDesktopTimeout(gpointer data);388 static gboolean FocusDesktopTimeout(gpointer data);
389
390 void DoEnableFocus ();
391 void DoDisableFocus ();
392
393 bool IsOverrideRedirect ();
394 bool IsManaged ();
395 bool IsGrabbed ();
396 bool IsDesktopOrDock ();
397 bool IsSkipTaskbarOrPager ();
398 bool IsHidden ();
399 bool IsInShowdesktopMode ();
400 bool IsShaded ();
401 bool IsMinimized ();
402 void DoOverrideFrameRegion (CompRegion &r);
403
404 void DoHide ();
405 void DoNotifyHidden ();
406 void DoShow ();
407 void DoNotifyShown ();
408
409 void DoAddDamage ();
410 ShowdesktopHandlerWindowInterface::PostPaintAction DoHandleAnimations (unsigned int ms);
411
412 void DoMoveFocusAway ();
413
414 void DoDeleteHandler ();
415
416 unsigned int GetNoCoreInstanceMask ();
417
418 compiz::WindowInputRemoverInterface::Ptr GetInputRemover ();
429};419};
430420
431421
432422
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2012-04-06 02:11:51 +0000
+++ tests/CMakeLists.txt 2012-04-06 08:44:20 +0000
@@ -33,7 +33,8 @@
33 )33 )
34add_definitions (${CFLAGS})34add_definitions (${CFLAGS})
3535
36set (LIBS ${TEST_UNIT_DEPS_LIBRARIES} "-lunity-core-${UNITY_API_VERSION} -lm")36set (LIBS ${TEST_UNIT_DEPS_LIBRARIES} "-lunity-core-${UNITY_API_VERSION} -lcompiz_core -lm")
37link_libraries (${LIBS})
3738
38set (LIB_PATHS ${TEST_UNIT_DEPS_LIBRARY_DIRS})39set (LIB_PATHS ${TEST_UNIT_DEPS_LIBRARY_DIRS})
39link_directories (${CMAKE_BINARY_DIR}/UnityCore ${LIB_PATHS})40link_directories (${CMAKE_BINARY_DIR}/UnityCore ${LIB_PATHS})
@@ -141,6 +142,7 @@
141 test_main_xless.cpp142 test_main_xless.cpp
142 test_grabhandle.cpp143 test_grabhandle.cpp
143 test_unityshell_private.cpp144 test_unityshell_private.cpp
145 test_showdesktop_handler.cpp
144 ${UNITY_SRC}/AbstractLauncherIcon.cpp146 ${UNITY_SRC}/AbstractLauncherIcon.cpp
145 ${UNITY_SRC}/AbstractShortcutHint.h147 ${UNITY_SRC}/AbstractShortcutHint.h
146 ${UNITY_SRC}/Animator.cpp148 ${UNITY_SRC}/Animator.cpp
@@ -161,6 +163,7 @@
161 ${UNITY_SRC}/Timer.cpp163 ${UNITY_SRC}/Timer.cpp
162 ${UNITY_SRC}/UnityshellPrivate.cpp164 ${UNITY_SRC}/UnityshellPrivate.cpp
163 ${UNITY_SRC}/WindowManager.cpp165 ${UNITY_SRC}/WindowManager.cpp
166 ${UNITY_SRC}/UnityShowdesktopHandler.cpp
164 ${CMAKE_SOURCE_DIR}/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle.cpp167 ${CMAKE_SOURCE_DIR}/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle.cpp
165 ${CMAKE_SOURCE_DIR}/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-group.cpp168 ${CMAKE_SOURCE_DIR}/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-group.cpp
166 ${CMAKE_SOURCE_DIR}/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-impl-factory.cpp169 ${CMAKE_SOURCE_DIR}/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle-impl-factory.cpp
167170
=== added file 'tests/test_showdesktop_handler.cpp'
--- tests/test_showdesktop_handler.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_showdesktop_handler.cpp 2012-04-06 08:44:20 +0000
@@ -0,0 +1,539 @@
1#include <list>
2#include <algorithm>
3#include <gtest/gtest.h>
4#include <gmock/gmock.h>
5#include <UnityShowdesktopHandler.h>
6
7using namespace unity;
8using ::testing::_;
9using ::testing::Return;
10using ::testing::Invoke;
11using ::testing::InSequence;
12
13compiz::WindowInputRemoverInterface::~WindowInputRemoverInterface () {}
14
15class MockWindowInputRemover :
16 public compiz::WindowInputRemoverInterface
17{
18 public:
19
20 MockWindowInputRemover ()
21 {
22 ON_CALL (*this, saveInput ()).WillByDefault (Return (true));
23 ON_CALL (*this, removeInput ()).WillByDefault (Return (true));
24 ON_CALL (*this, restoreInput ()).WillByDefault (Return (true));
25 }
26
27 MOCK_METHOD0 (saveInput, bool ());
28 MOCK_METHOD0 (removeInput, bool ());
29 MOCK_METHOD0 (restoreInput, bool ());
30};
31
32class UnityShowdesktopHandlerTest :
33 public ::testing::Test
34{
35public:
36
37 ~UnityShowdesktopHandlerTest ()
38 {
39 ShowdesktopHandler::animating_windows.clear ();
40 }
41
42 template <class T, class U> static typename T::Ptr makeShared () { return typename T::Ptr (new U); }
43
44};
45
46
47class MockUnityShowdesktopHandlerWindow :
48 public ShowdesktopHandlerWindowInterface
49{
50 public:
51
52 MockUnityShowdesktopHandlerWindow ()
53 {
54 ON_CALL (*this, IsOverrideRedirect ()).WillByDefault (Return (false));
55 ON_CALL (*this, IsManaged ()).WillByDefault (Return (true));
56 ON_CALL (*this, IsGrabbed ()).WillByDefault (Return (false));
57 ON_CALL (*this, IsDesktopOrDock ()).WillByDefault (Return (false));
58 ON_CALL (*this, IsSkipTaskbarOrPager ()).WillByDefault (Return (false));
59 ON_CALL (*this, IsHidden ()).WillByDefault (Return (false));
60 ON_CALL (*this, IsInShowdesktopMode ()).WillByDefault (Return (false));
61 ON_CALL (*this, IsShaded ()).WillByDefault (Return (false));
62 ON_CALL (*this, IsMinimized ()).WillByDefault (Return (false));
63
64 ON_CALL (*this, DoHandleAnimations (_)).WillByDefault (Return (ShowdesktopHandlerWindowInterface::PostPaintAction::Damage));
65 ON_CALL (*this, GetNoCoreInstanceMask ()).WillByDefault (Return (1));
66 ON_CALL (*this, GetInputRemover ()).WillByDefault (Invoke (UnityShowdesktopHandlerTest::makeShared<compiz::WindowInputRemoverInterface, MockWindowInputRemover>));
67 }
68
69 MOCK_METHOD0 (DoEnableFocus, void ());
70 MOCK_METHOD0 (DoDisableFocus, void ());
71 MOCK_METHOD0 (IsOverrideRedirect, bool ());
72 MOCK_METHOD0 (IsManaged, bool ());
73 MOCK_METHOD0 (IsGrabbed, bool ());
74 MOCK_METHOD0 (IsDesktopOrDock, bool ());
75 MOCK_METHOD0 (IsSkipTaskbarOrPager, bool ());
76 MOCK_METHOD0 (IsHidden, bool ());
77 MOCK_METHOD0 (IsInShowdesktopMode, bool ());
78 MOCK_METHOD0 (IsShaded, bool ());
79 MOCK_METHOD0 (IsMinimized, bool ());
80 MOCK_METHOD1 (DoOverrideFrameRegion, void (CompRegion &));
81 MOCK_METHOD0 (DoHide, void ());
82 MOCK_METHOD0 (DoNotifyHidden, void ());
83 MOCK_METHOD0 (DoShow, void ());
84 MOCK_METHOD0 (DoNotifyShown, void ());
85 MOCK_METHOD0 (DoMoveFocusAway, void ());
86 MOCK_METHOD1 (DoHandleAnimations, ShowdesktopHandlerWindowInterface::PostPaintAction (unsigned int));
87 MOCK_METHOD0 (DoAddDamage, void ());
88 MOCK_METHOD0 (GetNoCoreInstanceMask, unsigned int ());
89 MOCK_METHOD0 (GetInputRemover, compiz::WindowInputRemoverInterface::Ptr ());
90 MOCK_METHOD0 (DoDeleteHandler, void ());
91};
92
93TEST_F(UnityShowdesktopHandlerTest, TestNoORWindowsSD)
94{
95 MockUnityShowdesktopHandlerWindow mMockWindow;
96
97 EXPECT_CALL (mMockWindow, GetInputRemover ());
98
99 ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow));
100
101 EXPECT_CALL (mMockWindow, IsOverrideRedirect ()).WillOnce (Return (true));
102 EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
103}
104
105TEST_F(UnityShowdesktopHandlerTest, TestNoUnmanagedWindowsSD)
106{
107 MockUnityShowdesktopHandlerWindow mMockWindow;
108
109 EXPECT_CALL (mMockWindow, GetInputRemover ());
110
111 ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow));
112
113 EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
114 EXPECT_CALL (mMockWindow, IsManaged ()).WillOnce (Return (false));
115 EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
116}
117
118TEST_F(UnityShowdesktopHandlerTest, TestNoGrabbedWindowsSD)
119{
120 MockUnityShowdesktopHandlerWindow mMockWindow;
121
122 EXPECT_CALL (mMockWindow, GetInputRemover ());
123
124 ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow));
125
126 EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
127 EXPECT_CALL (mMockWindow, IsManaged ());
128 EXPECT_CALL (mMockWindow, IsGrabbed ()).WillOnce (Return (true));
129 EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
130}
131
132TEST_F(UnityShowdesktopHandlerTest, TestNoDesktopOrDockWindowsSD)
133{
134 MockUnityShowdesktopHandlerWindow mMockWindow;
135
136 EXPECT_CALL (mMockWindow, GetInputRemover ());
137
138 ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow));
139
140 EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
141 EXPECT_CALL (mMockWindow, IsManaged ());
142 EXPECT_CALL (mMockWindow, IsGrabbed ());
143 EXPECT_CALL (mMockWindow, IsDesktopOrDock ()).WillOnce (Return (true));
144 EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
145}
146
147TEST_F(UnityShowdesktopHandlerTest, TestNoSkipTaskbarOrPagerWindowsSD)
148{
149 MockUnityShowdesktopHandlerWindow mMockWindow;
150
151 EXPECT_CALL (mMockWindow, GetInputRemover ());
152
153 ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow));
154
155 EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
156 EXPECT_CALL (mMockWindow, IsManaged ());
157 EXPECT_CALL (mMockWindow, IsGrabbed ());
158 EXPECT_CALL (mMockWindow, IsDesktopOrDock ());
159 EXPECT_CALL (mMockWindow, IsSkipTaskbarOrPager ()).WillOnce (Return (true));
160 EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
161}
162
163TEST_F(UnityShowdesktopHandlerTest, TestHiddenNotSDAndShadedWindowsNoSD)
164{
165 MockUnityShowdesktopHandlerWindow mMockWindow;
166
167 EXPECT_CALL (mMockWindow, GetInputRemover ());
168
169 ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow));
170
171 EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
172 EXPECT_CALL (mMockWindow, IsManaged ());
173 EXPECT_CALL (mMockWindow, IsGrabbed ());
174 EXPECT_CALL (mMockWindow, IsDesktopOrDock ());
175 EXPECT_CALL (mMockWindow, IsSkipTaskbarOrPager ());
176 EXPECT_CALL (mMockWindow, IsHidden ()).WillOnce (Return (true));
177 EXPECT_CALL (mMockWindow, IsInShowdesktopMode ()).WillOnce (Return (false));
178 EXPECT_CALL (mMockWindow, IsShaded ()).WillOnce (Return (true));
179 EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
180}
181
182TEST_F(UnityShowdesktopHandlerTest, TestHiddenSDAndShadedWindowsNoSD)
183{
184 MockUnityShowdesktopHandlerWindow mMockWindow;
185
186 EXPECT_CALL (mMockWindow, GetInputRemover ());
187
188 ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow));
189
190 EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
191 EXPECT_CALL (mMockWindow, IsManaged ());
192 EXPECT_CALL (mMockWindow, IsGrabbed ());
193 EXPECT_CALL (mMockWindow, IsDesktopOrDock ());
194 EXPECT_CALL (mMockWindow, IsSkipTaskbarOrPager ());
195 EXPECT_CALL (mMockWindow, IsHidden ()).WillOnce (Return (true));
196 EXPECT_CALL (mMockWindow, IsInShowdesktopMode ()).WillOnce (Return (true));
197 EXPECT_FALSE (ShowdesktopHandler::ShouldHide (&mMockWindow));
198}
199
200TEST_F(UnityShowdesktopHandlerTest, TestHiddenNotSDAndNotShadedWindowsSD)
201{
202 MockUnityShowdesktopHandlerWindow mMockWindow;
203
204 EXPECT_CALL (mMockWindow, GetInputRemover ());
205
206 ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow));
207
208 EXPECT_CALL (mMockWindow, IsOverrideRedirect ());
209 EXPECT_CALL (mMockWindow, IsManaged ());
210 EXPECT_CALL (mMockWindow, IsGrabbed ());
211 EXPECT_CALL (mMockWindow, IsDesktopOrDock ());
212 EXPECT_CALL (mMockWindow, IsSkipTaskbarOrPager ());
213 EXPECT_CALL (mMockWindow, IsHidden ()).WillOnce (Return (true));
214 EXPECT_CALL (mMockWindow, IsInShowdesktopMode ()).WillOnce (Return (false));
215 EXPECT_CALL (mMockWindow, IsShaded ()).WillOnce (Return (false));
216 EXPECT_TRUE (ShowdesktopHandler::ShouldHide (&mMockWindow));
217}
218
219class MockWindowInputRemoverTestFadeOut :
220 public compiz::WindowInputRemoverInterface
221{
222 public:
223
224 MockWindowInputRemoverTestFadeOut ()
225 {
226 ON_CALL (*this, saveInput ()).WillByDefault (Return (true));
227 ON_CALL (*this, removeInput ()).WillByDefault (Return (true));
228 ON_CALL (*this, restoreInput ()).WillByDefault (Return (true));
229
230 EXPECT_CALL (*this, saveInput ()).WillOnce (Return (true));
231 EXPECT_CALL (*this, removeInput ()).WillOnce (Return (true));
232 }
233
234 MOCK_METHOD0 (saveInput, bool ());
235 MOCK_METHOD0 (removeInput, bool ());
236 MOCK_METHOD0 (restoreInput, bool ());
237};
238
239TEST_F(UnityShowdesktopHandlerTest, TestFadeOutHidesWindow)
240{
241 MockUnityShowdesktopHandlerWindow mMockWindow;
242
243 EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::makeShared<compiz::WindowInputRemoverInterface, MockWindowInputRemoverTestFadeOut>));
244
245 ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow));
246
247 EXPECT_CALL (mMockWindow, IsHidden ());
248 EXPECT_CALL (mMockWindow, DoHide ());
249 EXPECT_CALL (mMockWindow, DoNotifyHidden ());
250
251 mMockHandler.FadeOut ();
252
253 EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
254}
255
256class MockWindowInputRemoverTestFadeOutAlready :
257 public compiz::WindowInputRemoverInterface
258{
259 public:
260
261 MockWindowInputRemoverTestFadeOutAlready ()
262 {
263 ON_CALL (*this, saveInput ()).WillByDefault (Return (true));
264 ON_CALL (*this, removeInput ()).WillByDefault (Return (true));
265 ON_CALL (*this, restoreInput ()).WillByDefault (Return (true));
266 }
267
268 MOCK_METHOD0 (saveInput, bool ());
269 MOCK_METHOD0 (removeInput, bool ());
270 MOCK_METHOD0 (restoreInput, bool ());
271};
272
273TEST_F(UnityShowdesktopHandlerTest, TestFadeOutOnHiddenDoesntHideWindow)
274{
275 MockUnityShowdesktopHandlerWindow mMockWindow;
276
277 EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::makeShared<compiz::WindowInputRemoverInterface, MockWindowInputRemoverTestFadeOutAlready>));
278
279 ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow));
280
281 EXPECT_CALL (mMockWindow, IsHidden ()).WillOnce (Return (true));
282
283 mMockHandler.FadeOut ();
284
285 EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 0);
286}
287
288TEST_F(UnityShowdesktopHandlerTest, TestFadeOutAlreadyFadedDoesntHideWindow)
289{
290 MockUnityShowdesktopHandlerWindow mMockWindow;
291
292 EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::makeShared<compiz::WindowInputRemoverInterface, MockWindowInputRemoverTestFadeOut>));
293
294 ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow));
295
296 EXPECT_CALL (mMockWindow, IsHidden ());
297 EXPECT_CALL (mMockWindow, DoHide ());
298 EXPECT_CALL (mMockWindow, DoNotifyHidden ());
299
300 mMockHandler.FadeOut ();
301 mMockHandler.FadeOut ();
302
303 EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
304}
305
306TEST_F(UnityShowdesktopHandlerTest, TestFadeInNonFadedDoesntShowWindow)
307{
308 MockUnityShowdesktopHandlerWindow mMockWindow;
309
310 EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::makeShared<compiz::WindowInputRemoverInterface, MockWindowInputRemoverTestFadeOutAlready>));
311
312 ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow));
313
314 mMockHandler.FadeIn ();
315
316 EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 0);
317}
318
319class MockWindowInputRemoverTestFadeOutFadeIn :
320 public compiz::WindowInputRemoverInterface
321{
322 public:
323
324 MockWindowInputRemoverTestFadeOutFadeIn ()
325 {
326 ON_CALL (*this, saveInput ()).WillByDefault (Return (true));
327 ON_CALL (*this, removeInput ()).WillByDefault (Return (true));
328 ON_CALL (*this, restoreInput ()).WillByDefault (Return (true));
329
330 EXPECT_CALL (*this, saveInput ()).WillOnce (Return (true));
331 EXPECT_CALL (*this, removeInput ()).WillOnce (Return (true));
332 EXPECT_CALL (*this, restoreInput ()).WillOnce (Return (true));
333 }
334
335 MOCK_METHOD0 (saveInput, bool ());
336 MOCK_METHOD0 (removeInput, bool ());
337 MOCK_METHOD0 (restoreInput, bool ());
338};
339
340TEST_F(UnityShowdesktopHandlerTest, TestFadeOutHidesWindowFadeInShowsWindow)
341{
342 MockUnityShowdesktopHandlerWindow mMockWindow;
343
344 EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::makeShared<compiz::WindowInputRemoverInterface, MockWindowInputRemoverTestFadeOutFadeIn>));
345
346 ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow));
347
348 EXPECT_CALL (mMockWindow, IsHidden ());
349 EXPECT_CALL (mMockWindow, DoHide ());
350 EXPECT_CALL (mMockWindow, DoNotifyHidden ());
351
352 mMockHandler.FadeOut ();
353
354 EXPECT_CALL (mMockWindow, DoShow ());
355 EXPECT_CALL (mMockWindow, DoNotifyShown ());
356
357 mMockHandler.FadeIn ();
358
359 EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
360}
361
362TEST_F(UnityShowdesktopHandlerTest, TestAnimationPostPaintActions)
363{
364 MockUnityShowdesktopHandlerWindow mMockWindow;
365
366 EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::makeShared<compiz::WindowInputRemoverInterface, MockWindowInputRemoverTestFadeOutFadeIn>));
367
368 ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow));
369
370 EXPECT_CALL (mMockWindow, IsHidden ());
371 EXPECT_CALL (mMockWindow, DoHide ());
372 EXPECT_CALL (mMockWindow, DoNotifyHidden ());
373
374 mMockHandler.FadeOut ();
375
376 EXPECT_CALL (mMockWindow, DoShow ());
377 EXPECT_CALL (mMockWindow, DoNotifyShown ());
378
379 for (unsigned int i = 0; i < ShowdesktopHandler::fade_time; i++)
380 {
381 ShowdesktopHandlerWindowInterface::PostPaintAction action = mMockHandler.Animate (1);
382
383 if (i == 300)
384 EXPECT_EQ (action, ShowdesktopHandlerWindowInterface::PostPaintAction::Wait);
385 else
386 EXPECT_EQ (action, ShowdesktopHandlerWindowInterface::PostPaintAction::Damage);
387 }
388
389 mMockHandler.FadeIn ();
390
391 for (unsigned int i = 0; i < ShowdesktopHandler::fade_time; i++)
392 {
393 ShowdesktopHandlerWindowInterface::PostPaintAction action = mMockHandler.Animate (1);
394
395 if (i == 300)
396 EXPECT_EQ (action, ShowdesktopHandlerWindowInterface::PostPaintAction::Remove);
397 else
398 EXPECT_EQ (action, ShowdesktopHandlerWindowInterface::PostPaintAction::Damage);
399 }
400
401 EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
402}
403
404TEST_F(UnityShowdesktopHandlerTest, TestAnimationOpacity)
405{
406 MockUnityShowdesktopHandlerWindow mMockWindow;
407
408 EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::makeShared<compiz::WindowInputRemoverInterface, MockWindowInputRemoverTestFadeOutFadeIn>));
409
410 ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow));
411
412 EXPECT_CALL (mMockWindow, IsHidden ());
413 EXPECT_CALL (mMockWindow, DoHide ());
414 EXPECT_CALL (mMockWindow, DoNotifyHidden ());
415
416 mMockHandler.FadeOut ();
417
418 EXPECT_CALL (mMockWindow, DoShow ());
419 EXPECT_CALL (mMockWindow, DoNotifyShown ());
420
421 /* The funny expectations here are to account for rounding errors that would
422 * otherwise make testing the code painful */
423
424 for (unsigned int i = 0; i < ShowdesktopHandler::fade_time; i++)
425 {
426 unsigned short opacity = std::numeric_limits <unsigned short>::max ();
427 mMockHandler.PaintOpacity (opacity);
428
429 mMockHandler.Animate (1);
430
431 if (i == 300)
432 EXPECT_EQ (opacity, std::numeric_limits <unsigned short>::max ());
433 else
434 {
435 float rem = opacity - std::numeric_limits <unsigned short>::max () * (1.0f - i / static_cast <float> (ShowdesktopHandler::fade_time));
436 EXPECT_TRUE (rem <= 1.0f && rem >= -1.0f);
437 }
438 }
439
440 mMockHandler.FadeIn ();
441
442 for (unsigned int i = 0; i < ShowdesktopHandler::fade_time; i++)
443 {
444 unsigned short opacity = std::numeric_limits <unsigned short>::max ();
445 mMockHandler.PaintOpacity (opacity);
446
447 mMockHandler.Animate (1);
448
449 if (i == 300)
450 EXPECT_EQ (opacity, std::numeric_limits <unsigned short>::max ());
451 else
452 {
453 float rem = opacity - std::numeric_limits <unsigned short>::max () * (i / static_cast <float> (ShowdesktopHandler::fade_time));
454 EXPECT_TRUE (rem <= 1.0f && rem >= -1.0f);
455 }
456 }
457
458 EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
459}
460
461TEST_F(UnityShowdesktopHandlerTest, TestAnimationPaintMasks)
462{
463 MockUnityShowdesktopHandlerWindow mMockWindow;
464
465 EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::makeShared<compiz::WindowInputRemoverInterface, MockWindowInputRemoverTestFadeOutFadeIn>));
466
467 ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow));
468
469 EXPECT_CALL (mMockWindow, IsHidden ());
470 EXPECT_CALL (mMockWindow, DoHide ());
471 EXPECT_CALL (mMockWindow, DoNotifyHidden ());
472
473 mMockHandler.FadeOut ();
474
475 EXPECT_CALL (mMockWindow, DoShow ());
476 EXPECT_CALL (mMockWindow, DoNotifyShown ());
477 EXPECT_CALL (mMockWindow, GetNoCoreInstanceMask ());
478
479 mMockHandler.Animate (ShowdesktopHandler::fade_time);
480
481 EXPECT_EQ (mMockHandler.GetPaintMask (), 1);
482
483 mMockHandler.FadeIn ();
484
485 mMockHandler.Animate (ShowdesktopHandler::fade_time);
486
487 EXPECT_EQ (mMockHandler.GetPaintMask (), 0);
488
489 EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
490}
491
492class MockWindowInputRemoverTestFadeOutFadeInWithShapeEvent :
493 public compiz::WindowInputRemoverInterface
494{
495 public:
496
497 MockWindowInputRemoverTestFadeOutFadeInWithShapeEvent ()
498 {
499 ON_CALL (*this, saveInput ()).WillByDefault (Return (true));
500 ON_CALL (*this, removeInput ()).WillByDefault (Return (true));
501 ON_CALL (*this, restoreInput ()).WillByDefault (Return (true));
502
503 InSequence s;
504
505 EXPECT_CALL (*this, saveInput ()).WillOnce (Return (true));
506 EXPECT_CALL (*this, removeInput ()).WillOnce (Return (true));
507 EXPECT_CALL (*this, saveInput ()).WillOnce (Return (true));
508 EXPECT_CALL (*this, removeInput ()).WillOnce (Return (true));
509 EXPECT_CALL (*this, restoreInput ()).WillOnce (Return (true));
510 }
511
512 MOCK_METHOD0 (saveInput, bool ());
513 MOCK_METHOD0 (removeInput, bool ());
514 MOCK_METHOD0 (restoreInput, bool ());
515};
516
517TEST_F(UnityShowdesktopHandlerTest, TestShapeEvent)
518{
519 MockUnityShowdesktopHandlerWindow mMockWindow;
520
521 EXPECT_CALL (mMockWindow, GetInputRemover ()).WillOnce (Invoke (UnityShowdesktopHandlerTest::makeShared<compiz::WindowInputRemoverInterface, MockWindowInputRemoverTestFadeOutFadeInWithShapeEvent>));
522
523 ShowdesktopHandler mMockHandler (static_cast <ShowdesktopHandlerWindowInterface *> (&mMockWindow));
524
525 EXPECT_CALL (mMockWindow, IsHidden ());
526 EXPECT_CALL (mMockWindow, DoHide ());
527 EXPECT_CALL (mMockWindow, DoNotifyHidden ());
528
529 mMockHandler.FadeOut ();
530
531 EXPECT_CALL (mMockWindow, DoShow ());
532 EXPECT_CALL (mMockWindow, DoNotifyShown ());
533
534 mMockHandler.HandleShapeEvent ();
535
536 mMockHandler.FadeIn ();
537
538 EXPECT_EQ (ShowdesktopHandler::animating_windows.size (), 1);
539}