diff --git a/shell/desktopview.cpp b/shell/desktopview.cpp index 974c25c33..2352fe46e 100644 --- a/shell/desktopview.cpp +++ b/shell/desktopview.cpp @@ -1,320 +1,342 @@ /* * Copyright 2013 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, 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 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 "desktopview.h" #include "containmentconfigview.h" #include "shellcorona.h" #include "krunner_interface.h" #include #include #include +#include #include #include #include #include +#include #include #include #include DesktopView::DesktopView(Plasma::Corona *corona, QScreen *targetScreen) : PlasmaQuick::ContainmentView(corona, nullptr), m_windowType(Desktop), m_shellSurface(nullptr) { if (targetScreen) { setScreenToFollow(targetScreen); setScreen(targetScreen); setGeometry(targetScreen->geometry()); } setFlags(Qt::Window | Qt::FramelessWindowHint); setTitle(corona->kPackage().metadata().name()); setIcon(QIcon::fromTheme(corona->kPackage().metadata().iconName())); rootContext()->setContextProperty(QStringLiteral("desktop"), this); setSource(corona->kPackage().fileUrl("views", QStringLiteral("Desktop.qml"))); connect(this, &QWindow::screenChanged, this, &DesktopView::adaptToScreen); QObject::connect(corona, &Plasma::Corona::kPackageChanged, this, &DesktopView::coronaPackageChanged); + KActivities::Controller *m_activityController = new KActivities::Controller(this); + + QObject::connect(m_activityController, &KActivities::Controller::activityAdded, + this, &DesktopView::candidateContainmentsChanged); + QObject::connect(m_activityController, &KActivities::Controller::activityRemoved, + this, &DesktopView::candidateContainmentsChanged); + if (QQuickWindow::sceneGraphBackend() != QLatin1String("software")) { connect(this, &DesktopView::sceneGraphInitialized, this, [this, corona]() { // check whether the GL Context supports OpenGL // Note: hasOpenGLShaderPrograms is broken, see QTBUG--39730 if (!QOpenGLShaderProgram::hasOpenGLShaderPrograms(openglContext())) { qWarning() << "GLSL not available, Plasma won't be functional"; QMetaObject::invokeMethod(corona, "showOpenGLNotCompatibleWarning", Qt::QueuedConnection); } }, Qt::DirectConnection); } } DesktopView::~DesktopView() { } void DesktopView::showEvent(QShowEvent* e) { QQuickWindow::showEvent(e); adaptToScreen(); } void DesktopView::setScreenToFollow(QScreen *screen) { if (screen == m_screenToFollow) { return; } m_screenToFollow = screen; setScreen(screen); adaptToScreen(); } QScreen *DesktopView::screenToFollow() const { return m_screenToFollow; } void DesktopView::adaptToScreen() { ensureWindowType(); //This happens sometimes, when shutting down the process if (!m_screenToFollow || m_oldScreen==m_screenToFollow) { return; } if(m_oldScreen) { disconnect(m_oldScreen.data(), &QScreen::geometryChanged, this, &DesktopView::screenGeometryChanged); } // qDebug() << "adapting to screen" << m_screenToFollow->name() << this; if(m_oldScreen) { disconnect(m_oldScreen.data(), &QScreen::geometryChanged, this, &DesktopView::screenGeometryChanged); } if (m_windowType == Desktop || m_windowType == WindowedDesktop) { screenGeometryChanged(); connect(m_screenToFollow.data(), &QScreen::geometryChanged, this, &DesktopView::screenGeometryChanged, Qt::UniqueConnection); } m_oldScreen = m_screenToFollow; } DesktopView::WindowType DesktopView::windowType() const { return m_windowType; } void DesktopView::setWindowType(DesktopView::WindowType type) { if (m_windowType == type) { return; } m_windowType = type; adaptToScreen(); emit windowTypeChanged(); } void DesktopView::ensureWindowType() { //This happens sometimes, when shutting down the process if (!screen()) { return; } if (m_windowType == Window) { setFlags(Qt::Window); KWindowSystem::setType(winId(), NET::Normal); KWindowSystem::clearState(winId(), NET::FullScreen); if (m_shellSurface) { m_shellSurface->setRole(KWayland::Client::PlasmaShellSurface::Role::Normal); m_shellSurface->setSkipTaskbar(false); } } else if (m_windowType == Desktop) { setFlags(Qt::Window | Qt::FramelessWindowHint); KWindowSystem::setType(winId(), NET::Desktop); KWindowSystem::setState(winId(), NET::KeepBelow); if (m_shellSurface) { m_shellSurface->setRole(KWayland::Client::PlasmaShellSurface::Role::Desktop); m_shellSurface->setSkipTaskbar(true); } } else if (m_windowType == WindowedDesktop) { KWindowSystem::setType(winId(), NET::Normal); KWindowSystem::clearState(winId(), NET::FullScreen); setFlags(Qt::FramelessWindowHint | flags()); if (m_shellSurface) { m_shellSurface->setRole(KWayland::Client::PlasmaShellSurface::Role::Normal); m_shellSurface->setSkipTaskbar(false); } } else if (m_windowType == FullScreen) { setFlags(Qt::Window); KWindowSystem::setType(winId(), NET::Normal); KWindowSystem::setState(winId(), NET::FullScreen); if (m_shellSurface) { m_shellSurface->setRole(KWayland::Client::PlasmaShellSurface::Role::Normal); m_shellSurface->setSkipTaskbar(false); } } } DesktopView::SessionType DesktopView::sessionType() const { if (qobject_cast(corona())) { return ShellSession; } else { return ApplicationSession; } } +QVariantMap DesktopView::candidateContainmentsGraphicItems() const +{ + QVariantMap map; + if (!containment()) { + return map; + } + + for (auto cont : corona()->containmentsForScreen(containment()->screen())) { + map[cont->activity()] = cont->property("_plasma_graphicObject"); + } + return map; +} + bool DesktopView::event(QEvent *e) { if (e->type() == QEvent::PlatformSurface) { switch (static_cast(e)->surfaceEventType()) { case QPlatformSurfaceEvent::SurfaceCreated: setupWaylandIntegration(); ensureWindowType(); break; case QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed: delete m_shellSurface; m_shellSurface = nullptr; break; } } return PlasmaQuick::ContainmentView::event(e); } void DesktopView::keyPressEvent(QKeyEvent *e) { ContainmentView::keyPressEvent(e); if (e->isAccepted()) { return; } if (e->key() == Qt::Key_Escape && KWindowSystem::showingDesktop()) { KWindowSystem::setShowingDesktop(false); e->accept(); return; } // When a key is pressed on desktop when nothing else is active forward the key to krunner if (!e->modifiers() || e->modifiers() == Qt::ShiftModifier) { const QString text = e->text().trimmed(); if (!text.isEmpty() && text[0].isPrint()) { const QString interface(QStringLiteral("org.kde.krunner")); if (!KAuthorized::authorize(QStringLiteral("run_command"))) { return; } org::kde::krunner::App krunner(interface, QStringLiteral("/App"), QDBusConnection::sessionBus()); krunner.query(text); e->accept(); return; } } } void DesktopView::showConfigurationInterface(Plasma::Applet *applet) { if (m_configView) { if (m_configView->applet() != applet) { m_configView->hide(); m_configView->deleteLater(); } else { m_configView->show(); m_configView->requestActivate(); return; } } if (!applet || !applet->containment()) { return; } Plasma::Containment *cont = qobject_cast(applet); if (cont && cont->isContainment() && cont->containmentType() == Plasma::Types::DesktopContainment) { m_configView = new ContainmentConfigView(cont); //if we changed containment with the config open, relaunch the config dialog but for the new containment //third arg is used to disconnect when the config closes connect(this, &ContainmentView::containmentChanged, m_configView.data(), [this]() { showConfigurationInterface(containment()); }); } else { m_configView = new PlasmaQuick::ConfigView(applet); } m_configView.data()->init(); m_configView.data()->setTransientParent(this); m_configView.data()->show(); } void DesktopView::screenGeometryChanged() { const QRect geo = m_screenToFollow->geometry(); // qDebug() << "newGeometry" << this << geo << geometry(); setGeometry(geo); setMinimumSize(geo.size()); setMaximumSize(geo.size()); if (m_shellSurface) { m_shellSurface->setPosition(geo.topLeft()); } } void DesktopView::coronaPackageChanged(const KPackage::Package &package) { setContainment(nullptr); setSource(package.fileUrl("views", QStringLiteral("Desktop.qml"))); } void DesktopView::setupWaylandIntegration() { if (m_shellSurface) { // already setup return; } if (ShellCorona *c = qobject_cast(corona())) { using namespace KWayland::Client; PlasmaShell *interface = c->waylandPlasmaShellInterface(); if (!interface) { return; } Surface *s = Surface::fromWindow(this); if (!s) { return; } m_shellSurface = interface->createSurface(s, this); m_shellSurface->setPosition(m_screenToFollow->geometry().topLeft()); } } diff --git a/shell/desktopview.h b/shell/desktopview.h index dc9ab54ec..074afafe0 100644 --- a/shell/desktopview.h +++ b/shell/desktopview.h @@ -1,104 +1,110 @@ /* * Copyright 2013 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, 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 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. */ #ifndef DESKTOVIEW_H #define DESKTOVIEW_H #include #include #include namespace KWayland { namespace Client { class PlasmaShellSurface; } } class DesktopView : public PlasmaQuick::ContainmentView { Q_OBJECT Q_PROPERTY(WindowType windowType READ windowType WRITE setWindowType NOTIFY windowTypeChanged) //What kind of plasma session we're in: are we in a full workspace, an application?... Q_PROPERTY(SessionType sessionType READ sessionType CONSTANT) + + Q_PROPERTY(QVariantMap candidateContainments READ candidateContainmentsGraphicItems NOTIFY candidateContainmentsChanged) + public: enum WindowType { Window, /** The window is a normal resizable window with titlebar and appears in the taskbar */ FullScreen, /** The window is fullscreen and goes over all the other windows */ Desktop, /** The window is the desktop layer, under everything else, doesn't appear in the taskbar */ WindowedDesktop /** full screen and borderless as Desktop, but can be brought in front and appears in the taskbar */ }; Q_ENUM(WindowType) enum SessionType { ApplicationSession, /** our session is a normal application */ ShellSession /** We are running as the primary user interface of this machine */ }; Q_ENUM(SessionType) explicit DesktopView(Plasma::Corona *corona, QScreen *targetScreen = nullptr); ~DesktopView() override; /*This is different from screen() as is always there, even if the window is temporarly outside the screen or if is hidden: only plasmashell will ever change this property, unlike QWindow::screen()*/ void setScreenToFollow(QScreen *screen); QScreen *screenToFollow() const; void adaptToScreen(); void showEvent(QShowEvent*) override; WindowType windowType() const; void setWindowType(WindowType type); SessionType sessionType() const; + QVariantMap candidateContainmentsGraphicItems() const; + protected: bool event(QEvent *e) override; void keyPressEvent(QKeyEvent *e) override; protected Q_SLOTS: /** * It will be called when the configuration is requested */ void showConfigurationInterface(Plasma::Applet *applet) override; private Q_SLOTS: void screenGeometryChanged(); Q_SIGNALS: void stayBehindChanged(); void windowTypeChanged(); + void candidateContainmentsChanged(); private: void coronaPackageChanged(const KPackage::Package &package); void ensureWindowType(); void setupWaylandIntegration(); QPointer m_configView; QPointer m_oldScreen; QPointer m_screenToFollow; WindowType m_windowType; KWayland::Client::PlasmaShellSurface *m_shellSurface; }; #endif // DESKTOVIEW_H