showdesktop.cpp

00001 /*
00002  * Copyright (C) 2003-2004 Adam Geitgey <adam@rootnode.org>
00003  * Copyright (c) 2005 Ryan Nickell <p0z3r@earthlink.net>
00004  *
00005  * This file is part of SuperKaramba.
00006  *
00007  *  SuperKaramba is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  SuperKaramba 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  *  You should have received a copy of the GNU General Public License
00018  *  along with SuperKaramba; if not, write to the Free Software
00019  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020  ****************************************************************************/
00021 #include <kwinmodule.h>
00022 #include <netwm.h>
00023 #include <kwin.h>
00024 
00025 #include "karambaapp.h"
00026 #include "showdesktop.h"
00027 #include "showdesktop.moc"
00028 
00029 ShowDesktop* ShowDesktop::the()
00030 {
00031     static ShowDesktop showDesktop;
00032     return &showDesktop;
00033 }
00034 
00035 ShowDesktop::ShowDesktop()
00036   : QObject()
00037   , showingDesktop( false )
00038   , kWinModule( 0 )
00039 {
00040     kWinModule = new KWinModule( this );
00041 
00042     // on desktop changes or when a window is deiconified, we abort the show desktop mode
00043     connect( kWinModule, SIGNAL(currentDesktopChanged(int)),
00044              SLOT(slotCurrentDesktopChanged(int)));
00045     connect( kWinModule, SIGNAL(windowChanged(WId,unsigned int)),
00046              SLOT(slotWindowChanged(WId,unsigned int)));
00047 }
00048 
00049 void ShowDesktop::slotCurrentDesktopChanged(int)
00050 {
00051     showDesktop( false );
00052 }
00053 
00054 #ifdef KDE_3_3
00055 #define NET_ALL_TYPES_MASK (NET::AllTypesMask)
00056 #else
00057 #define NET_ALL_TYPES_MASK (-1LU)
00058 #endif
00059 
00060 void ShowDesktop::slotWindowChanged(WId w, unsigned int dirty)
00061 {
00062   if (!showingDesktop)
00063     return;
00064 
00065   // SELI this needs checking for kwin_iii (_NET_SHOWING_DESKTOP)
00066   if ( dirty & NET::XAWMState )
00067   {
00068     NETWinInfo inf(qt_xdisplay(), w, qt_xrootwin(),
00069                    NET::XAWMState | NET::WMWindowType);
00070 #ifdef KDE_3_2
00071     NET::WindowType windowType = inf.windowType(NET_ALL_TYPES_MASK);
00072 #else
00073     NET::WindowType windowType = inf.windowType();
00074 #endif
00075     if ((windowType == NET::Normal || windowType == NET::Unknown)
00076         && inf.mappingState() == NET::Visible )
00077     {
00078       // a window was deiconified, abort the show desktop mode.
00079       iconifiedList.clear();
00080       showingDesktop = false;
00081       emit desktopShown( false );
00082     }
00083   }
00084 }
00085 
00086 void ShowDesktop::showDesktop( bool b )
00087 {
00088     if( b == showingDesktop ) return;
00089     showingDesktop = b;
00090 
00091     if ( b ) {
00092         // this code should move to KWin after supporting NETWM1.2
00093         iconifiedList.clear();
00094         const QValueList<WId> windows = kWinModule->windows();
00095         QValueList<WId>::ConstIterator it;
00096         QValueList<WId>::ConstIterator end( windows.end() );
00097         for ( it=windows.begin(); it!=end; ++it ) {
00098             WId w = *it;
00099             NETWinInfo info( qt_xdisplay(), w, qt_xrootwin(),
00100                              NET::XAWMState | NET::WMDesktop );
00101             if ( info.mappingState() == NET::Visible &&
00102                  ( info.desktop() == NETWinInfo::OnAllDesktops
00103                    || info.desktop() == (int) kWinModule->currentDesktop() )
00104                 ) {
00105                 iconifiedList.append( w );
00106             }
00107         }
00108         // find first, hide later, otherwise transients may get minimized
00109         // with the window they're transient for
00110         QValueList<WId>::ConstIterator endInconifiedList( iconifiedList.end() );
00111         for ( it=iconifiedList.begin(); it!=endInconifiedList; ++it ) {
00112             KWin::iconifyWindow( *it, false );
00113         }
00114     } else {
00115         QValueList<WId>::ConstIterator it;
00116         QValueList<WId>::ConstIterator end( iconifiedList.end() );
00117         for ( it=iconifiedList.begin(); it!=end; ++it ) {
00118             KWin::deIconifyWindow( *it, false  );
00119         }
00120     }
00121 
00122     emit desktopShown( showingDesktop );
00123 }
KDE Home | KDE Accessibility Home | Description of Access Keys