Back to index

unity  6.0.0
UnityShowdesktopHandler.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /* Compiz unity plugin
00003  * unity.h
00004  *
00005  * Copyright (c) 2010-11 Canonical Ltd.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 3
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * Your own copyright notice would go above. You are free to choose whatever
00018  * licence you want, just take note that some compiz code is GPL and you will
00019  * not be able to re-use it if you want to use a different licence.
00020  */
00021 
00022 #include <glib.h>
00023 #include "UnityShowdesktopHandler.h"
00024 
00025 namespace unity
00026 {
00027 
00028 ShowdesktopHandlerWindowInterface::~ShowdesktopHandlerWindowInterface()
00029 {
00030 }
00031 
00032 /* 300 ms */
00033 const unsigned int ShowdesktopHandler::fade_time = 300;
00034 std::list <ShowdesktopHandlerWindowInterface *> ShowdesktopHandler::animating_windows (0);
00035 
00036 bool ShowdesktopHandler::ShouldHide (ShowdesktopHandlerWindowInterface *wi)
00037 {
00038   if (wi->OverrideRedirect())
00039     return false;
00040 
00041   if (!wi->Managed())
00042     return false;
00043 
00044   if (wi->Grabbed())
00045     return false;
00046 
00047   if (wi->DesktopOrDock())
00048    return false;
00049 
00050   if (wi->SkipTaskbarOrPager())
00051     return false;
00052 
00053   if (wi->Hidden())
00054     if ((wi->ShowDesktopMode() || wi->Shaded() || wi->Minimized()))
00055       return false;
00056 
00057   return true;
00058 }
00059 
00060 guint32 ShowdesktopHandler::inhibiting_xid = 0;
00061 
00062 void
00063 ShowdesktopHandler::InhibitLeaveShowdesktopMode (guint32 xid)
00064 {
00065   if (!inhibiting_xid)
00066     inhibiting_xid = xid;
00067 }
00068 
00069 void
00070 ShowdesktopHandler::AllowLeaveShowdesktopMode (guint32 xid)
00071 {
00072   if (inhibiting_xid == xid)
00073     inhibiting_xid = 0;
00074 }
00075 
00076 guint32
00077 ShowdesktopHandler::InhibitingXid()
00078 {
00079   return inhibiting_xid;
00080 }
00081 
00082 ShowdesktopHandler::ShowdesktopHandler (ShowdesktopHandlerWindowInterface *wi, compiz::WindowInputRemoverLockAcquireInterface *lock_acquire_interface) :
00083   showdesktop_handler_window_interface_ (wi),
00084   lock_acquire_interface_ (lock_acquire_interface),
00085   remover_(),
00086   state_ (StateVisible),
00087   progress_ (0.0f)
00088 {
00089 }
00090 
00091 ShowdesktopHandler::~ShowdesktopHandler()
00092 {
00093 }
00094 
00095 void ShowdesktopHandler::FadeOut()
00096 {
00097   if (state_ != StateVisible && state_ != StateFadeIn)
00098     return;
00099 
00100   state_ = ShowdesktopHandler::StateFadeOut;
00101   progress_ = 0.0f;
00102 
00103   was_hidden_ = showdesktop_handler_window_interface_->Hidden();
00104 
00105   if (!was_hidden_)
00106   {
00107     showdesktop_handler_window_interface_->Hide();
00108     showdesktop_handler_window_interface_->NotifyHidden();
00109     remover_ = lock_acquire_interface_->InputRemover();
00110 
00111     if (std::find (animating_windows.begin(),
00112                    animating_windows.end(),
00113                  showdesktop_handler_window_interface_) == animating_windows.end())
00114       animating_windows.push_back (showdesktop_handler_window_interface_);
00115 
00116   }
00117 }
00118 
00119 void ShowdesktopHandler::FadeIn()
00120 {
00121   if (state_ != StateInvisible && state_ != StateFadeOut)
00122     return;
00123 
00124   state_ = ShowdesktopHandler::StateFadeIn;
00125 
00126   if (!was_hidden_)
00127   {
00128     showdesktop_handler_window_interface_->Show();
00129     showdesktop_handler_window_interface_->NotifyShown();
00130     remover_.reset();
00131 
00132     if (std::find (animating_windows.begin(),
00133                    animating_windows.end(),
00134                  showdesktop_handler_window_interface_) == animating_windows.end())
00135       animating_windows.push_back(showdesktop_handler_window_interface_);
00136   }
00137 }
00138 
00139 ShowdesktopHandlerWindowInterface::PostPaintAction ShowdesktopHandler::Animate (unsigned int ms)
00140 {
00141   float inc = ms / static_cast <float> (fade_time);
00142 
00143   if (state_ == ShowdesktopHandler::StateFadeOut)
00144   {
00145     progress_ += inc;
00146     if (progress_ >= 1.0f)
00147     {
00148       progress_ = 1.0f;
00149       state_ = StateInvisible;
00150     }
00151   }
00152   else if (state_ == StateFadeIn)
00153   {
00154     progress_ -= inc;
00155     if (progress_ <= 0.0f)
00156     {
00157       progress_ = 0.0f;
00158       state_ = StateVisible;
00159     }
00160   }
00161   else if (state_ == StateVisible)
00162     return ShowdesktopHandlerWindowInterface::PostPaintAction::Remove;
00163   else if (state_ == StateInvisible)
00164     return ShowdesktopHandlerWindowInterface::PostPaintAction::Wait;
00165 
00166   return ShowdesktopHandlerWindowInterface::PostPaintAction::Damage;
00167 }
00168 
00169 void ShowdesktopHandler::PaintOpacity (unsigned short &opacity)
00170 {
00171   if (progress_ == 1.0f || progress_ == 0.0f)
00172     opacity = std::numeric_limits <unsigned short>::max();
00173   else
00174     opacity *= (1.0f - progress_);
00175 }
00176 
00177 unsigned int ShowdesktopHandler::GetPaintMask()
00178 {
00179   return (progress_ == 1.0f) ? showdesktop_handler_window_interface_->NoCoreInstanceMask() : 0;
00180 }
00181 
00182 void ShowdesktopHandler::HandleShapeEvent()
00183 {
00184   /* Ignore sent events from the InputRemover */
00185   if (remover_)
00186   {
00187     remover_->refresh();
00188   }
00189 }
00190 
00191 void ShowdesktopHandler::WindowFocusChangeNotify()
00192 {
00193   if (showdesktop_handler_window_interface_->Minimized())
00194   {
00195     for (ShowdesktopHandlerWindowInterface *w : animating_windows)
00196       w->DisableFocus();
00197 
00198     showdesktop_handler_window_interface_->MoveFocusAway();
00199 
00200     for (ShowdesktopHandlerWindowInterface *w : animating_windows)
00201       w->EnableFocus();
00202   }
00203 }
00204 
00205 void ShowdesktopHandler::UpdateFrameRegion (CompRegion &r)
00206 {
00207   r = CompRegion();
00208 
00209   /* Ensure no other plugins can touch this frame region */
00210   showdesktop_handler_window_interface_->OverrideFrameRegion (r);
00211 }
00212 
00213 }
00214