2013-01-29 19:29:16 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
|
2013-03-21 05:22:46 +01:00
|
|
|
* Copyright 2013 Sebastian Kügler <sebas@kde.org>
|
2013-01-29 19:29:16 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "desktopcorona.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDesktopWidget>
|
2013-03-21 04:03:05 +01:00
|
|
|
#include <QQmlContext>
|
|
|
|
#include <QTimer>
|
2013-03-21 00:59:52 +01:00
|
|
|
|
2013-03-21 01:06:43 +01:00
|
|
|
#include <KLocalizedString>
|
2013-03-05 17:22:00 +01:00
|
|
|
#include <Plasma/Package>
|
2013-02-14 14:39:46 +01:00
|
|
|
|
2013-04-24 22:54:46 +02:00
|
|
|
#include "containmentconfigview.h"
|
2013-02-14 14:39:46 +01:00
|
|
|
#include "panelview.h"
|
2013-01-29 20:45:44 +01:00
|
|
|
#include "view.h"
|
2013-03-07 17:39:10 +01:00
|
|
|
#include "scripting/desktopscriptengine.h"
|
2013-03-26 02:41:58 +01:00
|
|
|
#include "widgetexplorer/widgetexplorerview.h"
|
2013-01-29 19:29:16 +01:00
|
|
|
|
2013-02-14 14:39:46 +01:00
|
|
|
|
2013-01-29 19:29:16 +01:00
|
|
|
static const QString s_panelTemplatesPath("plasma-layout-templates/panels/*");
|
|
|
|
|
|
|
|
DesktopCorona::DesktopCorona(QObject *parent)
|
|
|
|
: Plasma::Corona(parent),
|
2013-03-21 00:59:52 +01:00
|
|
|
m_desktopWidget(QApplication::desktop()),
|
2013-03-21 04:03:05 +01:00
|
|
|
m_widgetExplorerView(0)
|
2013-01-29 19:29:16 +01:00
|
|
|
{
|
2013-03-05 17:22:00 +01:00
|
|
|
m_desktopDefaultsConfig = KConfigGroup(KSharedConfig::openConfig(package().filePath("defaults")), "Desktop");
|
|
|
|
|
2013-05-08 13:52:40 +02:00
|
|
|
m_appConfigSyncTimer = new QTimer(this);
|
|
|
|
m_appConfigSyncTimer->setSingleShot(true);
|
|
|
|
connect(m_appConfigSyncTimer, &QTimer::timeout,
|
|
|
|
this, &DesktopCorona::syncAppConfig);
|
|
|
|
|
|
|
|
|
2013-01-29 19:29:16 +01:00
|
|
|
connect(m_desktopWidget, SIGNAL(resized(int)),
|
|
|
|
this, SLOT(screenResized(int)));
|
|
|
|
connect(m_desktopWidget, SIGNAL(screenCountChanged(int)),
|
|
|
|
this, SLOT(screenCountChanged(int)));
|
|
|
|
connect(m_desktopWidget, SIGNAL(workAreaResized(int)),
|
|
|
|
this, SLOT(workAreaResized(int)));
|
2013-03-21 00:59:52 +01:00
|
|
|
connect(this, &DesktopCorona::containmentAdded, this, &DesktopCorona::handleContainmentAdded);
|
2013-01-29 19:29:16 +01:00
|
|
|
|
2013-02-04 19:47:35 +01:00
|
|
|
connect(this, SIGNAL(screenOwnerChanged(int, int, Plasma::Containment *)),
|
|
|
|
this, SLOT(updateScreenOwner(int, int, Plasma::Containment *)));
|
2013-01-29 19:29:16 +01:00
|
|
|
checkViews();
|
2013-03-21 04:03:05 +01:00
|
|
|
|
2013-03-21 05:04:04 +01:00
|
|
|
//QTimer::singleShot(600, this, SLOT(showWidgetExplorer())); // just for easier debugging
|
2013-01-29 19:29:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DesktopCorona::~DesktopCorona()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-08 13:52:40 +02:00
|
|
|
KSharedConfig::Ptr DesktopCorona::applicationConfig()
|
|
|
|
{
|
|
|
|
return KSharedConfig::openConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopCorona::requestApplicationConfigSync()
|
|
|
|
{
|
|
|
|
// constant controlling how long between requesting a configuration sync
|
|
|
|
// and one happening should occur. currently 10 seconds
|
|
|
|
static const int CONFIG_SYNC_TIMEOUT = 10000;
|
|
|
|
|
|
|
|
m_appConfigSyncTimer->start(CONFIG_SYNC_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
2013-01-29 19:29:16 +01:00
|
|
|
void DesktopCorona::loadDefaultLayout()
|
|
|
|
{
|
2013-03-07 17:39:10 +01:00
|
|
|
WorkspaceScripting::DesktopScriptEngine scriptEngine(this, true);
|
2013-03-13 13:14:25 +01:00
|
|
|
connect(&scriptEngine, &WorkspaceScripting::ScriptEngine::printError,
|
|
|
|
this, &DesktopCorona::printScriptError);
|
|
|
|
connect(&scriptEngine, &WorkspaceScripting::ScriptEngine::print,
|
|
|
|
this, &DesktopCorona::printScriptMessage);
|
2013-03-07 17:39:10 +01:00
|
|
|
|
|
|
|
QString script = package().filePath("defaultlayout");
|
2013-03-07 21:25:30 +01:00
|
|
|
|
2013-03-07 17:39:10 +01:00
|
|
|
QFile file(script);
|
|
|
|
if (file.open(QIODevice::ReadOnly | QIODevice::Text) ) {
|
|
|
|
QString code = file.readAll();
|
|
|
|
qDebug() << "evaluating startup script:" << script;
|
|
|
|
scriptEngine.evaluateScript(code);
|
|
|
|
}
|
2013-01-29 19:29:16 +01:00
|
|
|
}
|
|
|
|
|
2013-03-13 13:30:37 +01:00
|
|
|
void DesktopCorona::processUpdateScripts()
|
|
|
|
{
|
2013-03-13 14:00:51 +01:00
|
|
|
foreach (const QString &script, WorkspaceScripting::ScriptEngine::pendingUpdateScripts(this)) {
|
2013-03-13 13:30:37 +01:00
|
|
|
WorkspaceScripting::DesktopScriptEngine scriptEngine(this, false);
|
|
|
|
scriptEngine.evaluateScript(script);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-29 19:29:16 +01:00
|
|
|
void DesktopCorona::checkScreens(bool signalWhenExists)
|
|
|
|
{
|
|
|
|
// quick sanity check to ensure we have containments for each screen
|
|
|
|
int num = numScreens();
|
|
|
|
for (int i = 0; i < num; ++i) {
|
|
|
|
checkScreen(i, signalWhenExists);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopCorona::checkScreen(int screen, bool signalWhenExists)
|
|
|
|
{
|
|
|
|
// signalWhenExists is there to allow PlasmaApp to know when to create views
|
|
|
|
// it does this only on containment addition, but in the case of a screen being
|
|
|
|
// added and the containment already existing for that screen, no signal is emitted
|
|
|
|
// and so PlasmaApp does not know that it needs to create a view for it. to avoid
|
|
|
|
// taking care of that case in PlasmaApp (which would duplicate some of the code below,
|
|
|
|
// DesktopCorona will, when signalWhenExists is true, emit a containmentAdded signal
|
|
|
|
// even if the containment actually existed prior to this method being called.
|
|
|
|
//
|
|
|
|
//note: hte signal actually triggers view creation only for panels, atm.
|
|
|
|
//desktop views are created in response to containment's screenChanged signal instead, which is
|
|
|
|
//buggy (sometimes the containment thinks it's already on the screen, so no view is created)
|
|
|
|
|
|
|
|
//TODO: restore activities
|
|
|
|
//Activity *currentActivity = activity(m_activityController->currentActivity());
|
|
|
|
//ensure the desktop(s) have a containment and view
|
2013-02-18 18:05:45 +01:00
|
|
|
checkDesktop(/*currentActivity,*/ signalWhenExists, screen);
|
2013-01-29 19:29:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
//ensure the panels get views too
|
|
|
|
if (signalWhenExists) {
|
|
|
|
foreach (Plasma::Containment * c, containments()) {
|
|
|
|
if (c->screen() != screen) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-05-14 18:34:40 +02:00
|
|
|
Plasma::Types::ContainmentType t = c->containmentType();
|
2013-05-10 19:29:13 +02:00
|
|
|
if (t == Plasma::Types::PanelContainment ||
|
|
|
|
t == Plasma::Types::CustomPanelContainment) {
|
2013-01-29 19:29:16 +01:00
|
|
|
emit containmentAdded(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-18 18:05:45 +01:00
|
|
|
void DesktopCorona::checkDesktop(/*Activity *activity,*/ bool signalWhenExists, int screen)
|
2013-01-29 19:29:16 +01:00
|
|
|
{
|
2013-02-18 18:05:45 +01:00
|
|
|
Plasma::Containment *c = /*activity->*/containmentForScreen(screen);
|
2013-02-14 19:56:36 +01:00
|
|
|
|
2013-01-29 19:29:16 +01:00
|
|
|
//TODO: remove following when activities are restored
|
|
|
|
if (!c) {
|
2013-03-05 17:22:00 +01:00
|
|
|
c = createContainment(m_desktopDefaultsConfig.readEntry("Containment", "org.kde.testcontainment"));
|
2013-01-29 19:29:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!c) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-18 18:05:45 +01:00
|
|
|
c->setScreen(screen);
|
2013-02-05 14:55:40 +01:00
|
|
|
if (screen >= 0 || m_views.count() >= screen + 1) {
|
|
|
|
m_views[screen]->setContainment(c);
|
|
|
|
} else {
|
|
|
|
qWarning() << "Invalid screen";
|
|
|
|
}
|
2013-01-29 19:29:16 +01:00
|
|
|
c->flushPendingConstraintsEvents();
|
2013-05-08 13:52:40 +02:00
|
|
|
requestApplicationConfigSync();
|
2013-01-29 19:29:16 +01:00
|
|
|
|
|
|
|
if (signalWhenExists) {
|
|
|
|
emit containmentAdded(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int DesktopCorona::numScreens() const
|
|
|
|
{
|
|
|
|
return m_desktopWidget->screenCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect DesktopCorona::screenGeometry(int id) const
|
|
|
|
{
|
|
|
|
return m_desktopWidget->screenGeometry(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
QRegion DesktopCorona::availableScreenRegion(int id) const
|
|
|
|
{
|
|
|
|
return m_desktopWidget->availableGeometry(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect DesktopCorona::availableScreenRect(int id) const
|
|
|
|
{
|
|
|
|
return m_desktopWidget->availableGeometry(id);
|
|
|
|
}
|
|
|
|
|
2013-03-07 17:39:10 +01:00
|
|
|
PanelView *DesktopCorona::panelView(Plasma::Containment *containment) const
|
|
|
|
{
|
|
|
|
return m_panelViews.value(containment);
|
|
|
|
}
|
2013-01-29 19:29:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
///// SLOTS
|
|
|
|
|
|
|
|
void DesktopCorona::screenCountChanged(int newCount)
|
|
|
|
{
|
|
|
|
qDebug() << "New screen count" << newCount;
|
|
|
|
checkViews();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopCorona::screenResized(int screen)
|
|
|
|
{
|
|
|
|
qDebug() << "Screen resized" << screen;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopCorona::workAreaResized(int screen)
|
|
|
|
{
|
|
|
|
qDebug() << "Work area resized" << screen;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopCorona::checkViews()
|
|
|
|
{
|
|
|
|
if (m_views.count() == m_desktopWidget->screenCount()) {
|
|
|
|
return;
|
|
|
|
} else if (m_views.count() < m_desktopWidget->screenCount()) {
|
|
|
|
for (int i = m_views.count(); i < m_desktopWidget->screenCount(); ++i) {
|
2013-02-12 14:26:34 +01:00
|
|
|
View *view = new View(this);
|
2013-02-15 12:30:32 +01:00
|
|
|
QSurfaceFormat format;
|
2013-02-14 15:46:01 +01:00
|
|
|
view->init();
|
2013-02-14 14:39:46 +01:00
|
|
|
view->show();
|
2013-01-29 20:45:44 +01:00
|
|
|
|
2013-01-29 19:29:16 +01:00
|
|
|
m_views << view;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int i = m_desktopWidget->screenCount(); i < m_views.count(); ++i) {
|
2013-01-29 20:45:44 +01:00
|
|
|
View *view = m_views.last();
|
2013-01-29 19:29:16 +01:00
|
|
|
view->deleteLater();
|
|
|
|
m_views.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//check every containment is in proper view
|
|
|
|
for (int i = 0; i < m_desktopWidget->screenCount(); ++i) {
|
2013-03-26 03:54:35 +01:00
|
|
|
qDebug() << "TODO: Implement loading containments into the views";
|
2013-01-29 19:29:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-04 19:47:35 +01:00
|
|
|
void DesktopCorona::updateScreenOwner(int wasScreen, int isScreen, Plasma::Containment *containment)
|
|
|
|
{
|
2013-03-07 21:25:30 +01:00
|
|
|
qDebug() << "Was screen" << wasScreen << "Is screen" << isScreen <<"Containment" << containment << containment->title();
|
2013-02-14 15:46:01 +01:00
|
|
|
|
2013-05-10 19:29:13 +02:00
|
|
|
if (containment->formFactor() == Plasma::Types::Horizontal ||
|
|
|
|
containment->formFactor() == Plasma::Types::Vertical) {
|
2013-02-14 14:39:46 +01:00
|
|
|
|
|
|
|
if (isScreen >= 0) {
|
|
|
|
m_panelViews[containment] = new PanelView(this);
|
2013-02-14 15:46:01 +01:00
|
|
|
m_panelViews[containment]->init();
|
|
|
|
m_panelViews[containment]->setContainment(containment);
|
2013-02-14 14:39:46 +01:00
|
|
|
m_panelViews[containment]->show();
|
|
|
|
} else {
|
|
|
|
if (m_panelViews.contains(containment)) {
|
|
|
|
m_panelViews[containment]->setContainment(0);
|
|
|
|
m_panelViews[containment]->deleteLater();
|
|
|
|
m_panelViews.remove(containment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Desktop view
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (isScreen < 0 || m_views.count() < isScreen + 1) {
|
|
|
|
qWarning() << "Invalid screen";
|
|
|
|
return;
|
|
|
|
}
|
2013-02-04 19:47:35 +01:00
|
|
|
|
2013-02-14 14:39:46 +01:00
|
|
|
m_views[isScreen]->setContainment(containment);
|
|
|
|
}
|
2013-02-04 19:47:35 +01:00
|
|
|
}
|
|
|
|
|
2013-03-21 00:59:52 +01:00
|
|
|
void DesktopCorona::handleContainmentAdded(Plasma::Containment* c)
|
|
|
|
{
|
2013-04-24 22:54:46 +02:00
|
|
|
connect(c, &Plasma::Containment::showAddWidgetsInterface,
|
|
|
|
this, &DesktopCorona::showWidgetExplorer);
|
2013-03-21 00:59:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopCorona::showWidgetExplorer()
|
|
|
|
{
|
2013-03-21 04:03:05 +01:00
|
|
|
if (!m_widgetExplorerView) {
|
|
|
|
|
2013-03-21 00:59:52 +01:00
|
|
|
QString expqml = package().filePath("widgetexplorer");
|
|
|
|
qDebug() << "Script to load for WidgetExplorer: " << expqml;
|
2013-03-26 02:41:58 +01:00
|
|
|
m_widgetExplorerView = new WidgetExplorerView(expqml);
|
|
|
|
m_widgetExplorerView->init();
|
2013-03-21 00:59:52 +01:00
|
|
|
}
|
2013-03-21 05:04:04 +01:00
|
|
|
Plasma::Containment *c = 0;
|
|
|
|
c = dynamic_cast<Plasma::Containment*>(sender());
|
|
|
|
if (c) {
|
|
|
|
qDebug() << "Found containment.";
|
2013-03-26 02:41:58 +01:00
|
|
|
m_widgetExplorerView->setContainment(c);
|
2013-03-21 05:04:04 +01:00
|
|
|
} else {
|
2013-03-21 05:22:46 +01:00
|
|
|
// FIXME: try harder to find a suitable containment?
|
|
|
|
qWarning() << "containment not set, don't know where to add the applet.";
|
2013-03-21 05:04:04 +01:00
|
|
|
}
|
2013-03-21 04:03:05 +01:00
|
|
|
m_widgetExplorerView->show();
|
2013-03-21 00:59:52 +01:00
|
|
|
}
|
|
|
|
|
2013-05-08 13:52:40 +02:00
|
|
|
void DesktopCorona::syncAppConfig()
|
|
|
|
{
|
|
|
|
qDebug() << "Syncing plasma-shellrc config";
|
|
|
|
applicationConfig()->sync();
|
|
|
|
}
|
|
|
|
|
2013-03-13 13:14:25 +01:00
|
|
|
void DesktopCorona::printScriptError(const QString &error)
|
|
|
|
{
|
|
|
|
qWarning() << error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopCorona::printScriptMessage(const QString &message)
|
|
|
|
{
|
|
|
|
qDebug() << message;
|
|
|
|
}
|
|
|
|
|
2013-05-08 13:52:40 +02:00
|
|
|
#include "moc_desktopcorona.cpp"
|
2013-01-29 19:29:16 +01:00
|
|
|
|