2 * Copyright 2008 Petri Damsten <damu@iki.fi>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "showdesktop.h"
19 #include <plasma/widgets/iconwidget.h>
20 #include <plasma/containment.h>
21 #include <plasma/tooltipmanager.h>
22 #include <KGlobalSettings>
24 #include <kwindowsystem.h>
26 #include <KIconLoader>
29 #include <QGraphicsLinearLayout>
31 ShowDesktop::ShowDesktop(QObject *parent, const QVariantList &args)
32 : Plasma::Applet(parent, args), m_wm2ShowingDesktop(false)
34 , m_down(false), m_goingDown(false)
37 setAspectRatioMode(Plasma::ConstrainedSquare);
38 int iconSize = IconSize(KIconLoader::Desktop);
39 resize(iconSize * 2, iconSize * 2);
41 connect(&m_timer, SIGNAL(timeout()), this, SLOT(minimizeAll()));
44 ShowDesktop::~ShowDesktop()
48 void ShowDesktop::init()
50 connect(this, SIGNAL(activate()), this, SLOT(minimizeAll()));
52 QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(this);
53 layout->setContentsMargins(0, 0, 0, 0);
54 layout->setSpacing(0);
56 Plasma::IconWidget *icon = new Plasma::IconWidget(KIcon("user-desktop"), QString(), this);
57 layout->addItem(icon);
58 registerAsDragHandle(icon);
59 connect(icon, SIGNAL(clicked()), this, SLOT(minimizeAll()));
61 Plasma::ToolTipContent toolTipData(i18n("Show the Desktop"),
62 i18n("Minimize all open windows and show the Desktop"),
63 icon->icon().pixmap(IconSize(KIconLoader::Desktop)));
64 Plasma::ToolTipManager::self()->setContent(this, toolTipData);
66 NETRootInfo info(QX11Info::display(), NET::Supported);
67 m_wm2ShowingDesktop = info.isSupported(NET::WM2ShowingDesktop);
70 if (m_wm2ShowingDesktop) {
71 connect(KWindowSystem::self(), SIGNAL(activeWindowChanged(WId)), this, SLOT(reset()));
75 connect(KGlobalSettings::self(), SIGNAL(iconChanged(int)),
76 this, SLOT(iconSizeChanged(int)));
79 void ShowDesktop::minimizeAll()
82 if (m_wm2ShowingDesktop) {
83 NETRootInfo info(QX11Info::display(), 0);
87 info.setShowingDesktop(m_down);
88 // NETRootInfo::showingDesktop() returns always false
89 QTimer::singleShot(500, this, SLOT(delay()));
91 info.setShowingDesktop(true);
96 void ShowDesktop::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
102 void ShowDesktop::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
106 #ifndef MINIMIZE_ONLY
108 void ShowDesktop::delay()
113 void ShowDesktop::reset()
120 QSizeF ShowDesktop::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
122 if (which == Qt::PreferredSize) {
125 switch (formFactor()) {
127 case Plasma::MediaCenter:
128 iconSize = IconSize(KIconLoader::Desktop);
131 case Plasma::Horizontal:
132 case Plasma::Vertical:
133 iconSize = IconSize(KIconLoader::Panel);
137 return QSizeF(iconSize, iconSize);
140 return Plasma::Applet::sizeHint(which, constraint);
143 void ShowDesktop::iconSizeChanged(int group)
145 if (group == KIconLoader::Desktop || group == KIconLoader::Panel) {
152 #include "moc_showdesktop.cpp"