diff --git a/shell/desktopview.cpp b/shell/desktopview.cpp index 08c1c32a1..644cf4fdd 100644 --- a/shell/desktopview.cpp +++ b/shell/desktopview.cpp @@ -35,9 +35,8 @@ DesktopView::DesktopView(ShellCorona *corona) : PlasmaQuick::View(corona, 0), m_corona(corona), - m_stayBehind(false), - m_fillScreen(false), - m_dashboardShown(false) + m_dashboardShown(false), + m_windowType(Desktop) { setTitle(i18n("Desktop")); setIcon(QIcon::fromTheme("user-desktop")); @@ -45,7 +44,7 @@ DesktopView::DesktopView(ShellCorona *corona) setSource(QUrl::fromLocalFile(corona->package().filePath("views", "Desktop.qml"))); //For some reason, if I connect the method directly it doesn't get called, I think it's for the lack of argument - connect(this, &QWindow::screenChanged, this, [=](QScreen*) { adaptToScreen(); ensureStayBehind(); }); + connect(this, &QWindow::screenChanged, this, [=](QScreen*) { adaptToScreen(); ensureWindowType(); }); QObject::connect(corona, &Plasma::Corona::packageChanged, this, &DesktopView::coronaPackageChanged); @@ -65,39 +64,6 @@ DesktopView::~DesktopView() { } -bool DesktopView::stayBehind() const -{ - return m_stayBehind; -} - -void DesktopView::setStayBehind(bool stayBehind) -{ - if (ShellManager::s_forceWindowed || stayBehind == m_stayBehind) { - return; - } - - m_stayBehind = stayBehind; - ensureStayBehind(); - - emit stayBehindChanged(); -} - -bool DesktopView::fillScreen() const -{ - return m_fillScreen; -} - -void DesktopView::setFillScreen(bool fillScreen) -{ - if (ShellManager::s_forceWindowed || fillScreen == m_fillScreen) { - return; - } - - m_fillScreen = fillScreen; - adaptToScreen(); - emit fillScreenChanged(); -} - void DesktopView::showEvent(QShowEvent* e) { adaptToScreen(); @@ -112,7 +78,7 @@ void DesktopView::adaptToScreen() } // qDebug() << "adapting to screen" << screen()->name() << this; - if (m_fillScreen) { + if (m_windowType != Normal && !ShellManager::s_forceWindowed) { setGeometry(screen()->geometry()); setMinimumSize(screen()->geometry().size()); setMaximumSize(screen()->geometry().size()); @@ -126,22 +92,47 @@ void DesktopView::adaptToScreen() m_oldScreen = screen(); } -void DesktopView::ensureStayBehind() +DesktopView::WindowType DesktopView::windowType() const +{ + return m_windowType; +} + +void DesktopView::setWindowType(DesktopView::WindowType type) +{ + if (m_windowType == type) { + return; + } + + m_windowType = type; + + ensureWindowType(); + adaptToScreen(); + + emit windowTypeChanged(); +} + +void DesktopView::ensureWindowType() { //This happens sometimes, when shutting down the process - if (!screen()) + if (!screen()) { return; - if (m_stayBehind) { + } + + if (m_windowType == Normal || ShellManager::s_forceWindowed) { + KWindowSystem::setType(winId(), NET::Normal); + KWindowSystem::clearState(winId(), NET::FullScreen); + } else if (m_windowType == Desktop) { KWindowSystem::setType(winId(), NET::Desktop); - } else { + } else if (m_windowType == FullScreen) { KWindowSystem::setType(winId(), NET::Normal); + KWindowSystem::setState(winId(), NET::FullScreen); } } void DesktopView::setDashboardShown(bool shown) { if (shown) { - if (m_stayBehind) { + if (m_windowType == Desktop) { KWindowSystem::setType(winId(), NET::Normal); KWindowSystem::clearState(winId(), NET::KeepBelow); KWindowSystem::setState(winId(), NET::SkipTaskbar|NET::SkipPager); @@ -153,7 +144,7 @@ void DesktopView::setDashboardShown(bool shown) KWindowSystem::forceActiveWindow(winId()); } else { - if (m_stayBehind) { + if (m_windowType == Desktop) { KWindowSystem::setType(winId(), NET::Desktop); KWindowSystem::setState(winId(), NET::SkipTaskbar|NET::SkipPager|NET::KeepBelow); } @@ -173,6 +164,8 @@ bool DesktopView::event(QEvent *e) if (m_dashboardShown && ke->key() == Qt::Key_Escape) { static_cast(corona())->setDashboardShown(false); } + } else if (e->type() == QEvent::Show || e->type() == QEvent::FocusIn) { + ensureWindowType(); } else if (e->type() == QEvent::Close) { //prevent ALT+F4 from killing the shell e->ignore(); diff --git a/shell/desktopview.h b/shell/desktopview.h index 6aeeeb680..08e678b37 100644 --- a/shell/desktopview.h +++ b/shell/desktopview.h @@ -29,27 +29,31 @@ class ShellCorona; class DesktopView : public PlasmaQuick::View { Q_OBJECT - Q_PROPERTY(bool stayBehind READ stayBehind WRITE setStayBehind NOTIFY stayBehindChanged) - Q_PROPERTY(bool fillScreen READ fillScreen WRITE setFillScreen NOTIFY fillScreenChanged) //the qml part doesn't need to be able to write it, hide for now Q_PROPERTY(bool dashboardShown READ isDashboardShown NOTIFY dashboardShownChanged) + Q_PROPERTY(WindowType windowType READ windowType WRITE setWindowType NOTIFY windowTypeChanged) + public: + enum WindowType { + Normal, + Desktop, + FullScreen + }; + Q_ENUMS(WindowType) + explicit DesktopView(ShellCorona *corona); virtual ~DesktopView(); - bool stayBehind() const; - void setStayBehind(bool stayBehind); - - bool fillScreen() const; - void setFillScreen(bool fillScreen); - void setDashboardShown(bool shown); bool isDashboardShown() const; void adaptToScreen(); virtual void showEvent(QShowEvent*); + WindowType windowType() const; + void setWindowType(WindowType type); + protected: bool event(QEvent *e); void keyPressEvent(QKeyEvent *e); @@ -65,17 +69,17 @@ Q_SIGNALS: void stayBehindChanged(); void fillScreenChanged(); void dashboardShownChanged(); + void windowTypeChanged(); private: void coronaPackageChanged(const Plasma::Package &package); - void ensureStayBehind(); + void ensureWindowType(); QPointer m_configView; QPointer m_oldScreen; ShellCorona *m_corona; - bool m_stayBehind : 1; - bool m_fillScreen : 1; bool m_dashboardShown : 1; + WindowType m_windowType; }; #endif // DESKTOVIEW_H diff --git a/shell/shellcorona.cpp b/shell/shellcorona.cpp index eeb01af59..a3d988614 100644 --- a/shell/shellcorona.cpp +++ b/shell/shellcorona.cpp @@ -77,6 +77,7 @@ ShellCorona::ShellCorona(QObject *parent) m_screenConfiguration(nullptr), m_loading(false) { + qmlRegisterUncreatableType("org.kde.plasma.shell", 2, 0, "DesktopView", "It is not possible to create objects of type DesktopView"); m_lookAndFeelPackage = Plasma::PluginLoader::self()->loadPackage("Plasma/LookAndFeel"); KConfigGroup cg(KSharedConfig::openConfig("kdeglobals"), "KDE"); const QString packageName = cg.readEntry("LookAndFeelPackage", QString());