2 * Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
3 * Copyright 2007 Matt Broadstone <mbroadst@gmail.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Library General Public License version 2 as
7 * published by the Free Software Foundation
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 Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "rootwidget.h"
22 #include <QApplication>
23 #include <QDesktopWidget>
24 #include <QVBoxLayout>
26 #include <KWindowSystem>
30 #include "plasma/corona.h"
31 #include "plasma/plasma.h"
32 #include "plasma/svg.h"
33 #include "plasma/theme.h"
35 #include "desktopview.h"
36 #include "dashboardview.h"
37 #include "plasmaapp.h"
40 RootWidget::RootWidget()
43 setFocusPolicy(Qt::NoFocus
);
45 // create a containment for each screen
46 QDesktopWidget
*desktop
= QApplication::desktop();
47 int numScreens
= desktop
->numScreens();
48 for (int i
= 0; i
< numScreens
; ++i
) {
52 Plasma::Corona
* corona
= PlasmaApp::self()->corona();
53 connect(corona
, SIGNAL(newScreen(int)), this, SLOT(createDesktopView(int)));
55 //TODO: Make the shortcut configurable
56 KAction
*showAction
= new KAction( this );
57 showAction
->setText( i18n( "Show Dashboard" ) );
58 showAction
->setGlobalShortcut( KShortcut( Qt::CTRL
+ Qt::Key_F12
) );
59 connect( showAction
, SIGNAL( triggered() ), this, SLOT( toggleDashboard() ) );
62 void RootWidget::toggleDashboard()
64 int currentScreen
= 0;
65 if (QApplication::desktop()->numScreens() > 1) {
66 currentScreen
= QApplication::desktop()->screenNumber(QCursor::pos());
69 if (currentScreen
> m_desktops
.count() - 1) {
70 kWarning() << "we don't have a DesktopView for the current screen!";
74 m_desktops
[currentScreen
]->toggleDashboard();
77 void RootWidget::setAsDesktop(bool setAsDesktop
)
80 setWindowFlags(windowFlags() | Qt::FramelessWindowHint
);
82 KWindowSystem::setOnAllDesktops(winId(), true);
83 KWindowSystem::setType(winId(), NET::Desktop
);
86 QRect desktopGeometry
= QApplication::desktop()->geometry();
88 if (geometry() != desktopGeometry
) {
89 setGeometry(desktopGeometry
);
92 connect(QApplication::desktop(), SIGNAL(resized(int)), SLOT(adjustSize(int)));
94 setWindowFlags(windowFlags() & ~Qt::FramelessWindowHint
);
96 KWindowSystem::setOnAllDesktops(winId(), false);
97 KWindowSystem::setType(winId(), NET::Normal
);
99 disconnect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(adjustSize()));
103 bool RootWidget::isDesktop() const
105 return KWindowInfo(winId(), NET::WMWindowType
).windowType(NET::Desktop
);
108 RootWidget::~RootWidget()
112 void RootWidget::adjustSize(int screen
)
114 QDesktopWidget
*desktop
= QApplication::desktop();
115 setGeometry(desktop
->geometry());
117 foreach (DesktopView
*view
, m_desktops
) {
118 if (view
->screen() == screen
) {
124 void RootWidget::createDesktopView(int screen
)
126 // we have a new screen. neat.
127 DesktopView
*view
= new DesktopView(screen
, this);
128 view
->setGeometry(QApplication::desktop()->screenGeometry(screen
));
129 m_desktops
.append(view
);
132 #include "rootwidget.moc"