expose a WindowType api to Desktop.qml

wilder-5.14
Marco Martin 12 years ago
parent 5da102003d
commit 162297b7e1
  1. 81
      shell/desktopview.cpp
  2. 26
      shell/desktopview.h
  3. 1
      shell/shellcorona.cpp

@ -35,9 +35,8 @@
DesktopView::DesktopView(ShellCorona *corona) DesktopView::DesktopView(ShellCorona *corona)
: PlasmaQuick::View(corona, 0), : PlasmaQuick::View(corona, 0),
m_corona(corona), m_corona(corona),
m_stayBehind(false), m_dashboardShown(false),
m_fillScreen(false), m_windowType(Desktop)
m_dashboardShown(false)
{ {
setTitle(i18n("Desktop")); setTitle(i18n("Desktop"));
setIcon(QIcon::fromTheme("user-desktop")); setIcon(QIcon::fromTheme("user-desktop"));
@ -45,7 +44,7 @@ DesktopView::DesktopView(ShellCorona *corona)
setSource(QUrl::fromLocalFile(corona->package().filePath("views", "Desktop.qml"))); 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 //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, QObject::connect(corona, &Plasma::Corona::packageChanged,
this, &DesktopView::coronaPackageChanged); 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) void DesktopView::showEvent(QShowEvent* e)
{ {
adaptToScreen(); adaptToScreen();
@ -112,7 +78,7 @@ void DesktopView::adaptToScreen()
} }
// qDebug() << "adapting to screen" << screen()->name() << this; // qDebug() << "adapting to screen" << screen()->name() << this;
if (m_fillScreen) { if (m_windowType != Normal && !ShellManager::s_forceWindowed) {
setGeometry(screen()->geometry()); setGeometry(screen()->geometry());
setMinimumSize(screen()->geometry().size()); setMinimumSize(screen()->geometry().size());
setMaximumSize(screen()->geometry().size()); setMaximumSize(screen()->geometry().size());
@ -126,22 +92,47 @@ void DesktopView::adaptToScreen()
m_oldScreen = screen(); 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 //This happens sometimes, when shutting down the process
if (!screen()) if (!screen()) {
return; 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); KWindowSystem::setType(winId(), NET::Desktop);
} else { } else if (m_windowType == FullScreen) {
KWindowSystem::setType(winId(), NET::Normal); KWindowSystem::setType(winId(), NET::Normal);
KWindowSystem::setState(winId(), NET::FullScreen);
} }
} }
void DesktopView::setDashboardShown(bool shown) void DesktopView::setDashboardShown(bool shown)
{ {
if (shown) { if (shown) {
if (m_stayBehind) { if (m_windowType == Desktop) {
KWindowSystem::setType(winId(), NET::Normal); KWindowSystem::setType(winId(), NET::Normal);
KWindowSystem::clearState(winId(), NET::KeepBelow); KWindowSystem::clearState(winId(), NET::KeepBelow);
KWindowSystem::setState(winId(), NET::SkipTaskbar|NET::SkipPager); KWindowSystem::setState(winId(), NET::SkipTaskbar|NET::SkipPager);
@ -153,7 +144,7 @@ void DesktopView::setDashboardShown(bool shown)
KWindowSystem::forceActiveWindow(winId()); KWindowSystem::forceActiveWindow(winId());
} else { } else {
if (m_stayBehind) { if (m_windowType == Desktop) {
KWindowSystem::setType(winId(), NET::Desktop); KWindowSystem::setType(winId(), NET::Desktop);
KWindowSystem::setState(winId(), NET::SkipTaskbar|NET::SkipPager|NET::KeepBelow); 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) { if (m_dashboardShown && ke->key() == Qt::Key_Escape) {
static_cast<ShellCorona *>(corona())->setDashboardShown(false); static_cast<ShellCorona *>(corona())->setDashboardShown(false);
} }
} else if (e->type() == QEvent::Show || e->type() == QEvent::FocusIn) {
ensureWindowType();
} else if (e->type() == QEvent::Close) { } else if (e->type() == QEvent::Close) {
//prevent ALT+F4 from killing the shell //prevent ALT+F4 from killing the shell
e->ignore(); e->ignore();

@ -29,27 +29,31 @@ class ShellCorona;
class DesktopView : public PlasmaQuick::View class DesktopView : public PlasmaQuick::View
{ {
Q_OBJECT 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 //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(bool dashboardShown READ isDashboardShown NOTIFY dashboardShownChanged)
Q_PROPERTY(WindowType windowType READ windowType WRITE setWindowType NOTIFY windowTypeChanged)
public: public:
enum WindowType {
Normal,
Desktop,
FullScreen
};
Q_ENUMS(WindowType)
explicit DesktopView(ShellCorona *corona); explicit DesktopView(ShellCorona *corona);
virtual ~DesktopView(); virtual ~DesktopView();
bool stayBehind() const;
void setStayBehind(bool stayBehind);
bool fillScreen() const;
void setFillScreen(bool fillScreen);
void setDashboardShown(bool shown); void setDashboardShown(bool shown);
bool isDashboardShown() const; bool isDashboardShown() const;
void adaptToScreen(); void adaptToScreen();
virtual void showEvent(QShowEvent*); virtual void showEvent(QShowEvent*);
WindowType windowType() const;
void setWindowType(WindowType type);
protected: protected:
bool event(QEvent *e); bool event(QEvent *e);
void keyPressEvent(QKeyEvent *e); void keyPressEvent(QKeyEvent *e);
@ -65,17 +69,17 @@ Q_SIGNALS:
void stayBehindChanged(); void stayBehindChanged();
void fillScreenChanged(); void fillScreenChanged();
void dashboardShownChanged(); void dashboardShownChanged();
void windowTypeChanged();
private: private:
void coronaPackageChanged(const Plasma::Package &package); void coronaPackageChanged(const Plasma::Package &package);
void ensureStayBehind(); void ensureWindowType();
QPointer<PlasmaQuick::ConfigView> m_configView; QPointer<PlasmaQuick::ConfigView> m_configView;
QPointer<QScreen> m_oldScreen; QPointer<QScreen> m_oldScreen;
ShellCorona *m_corona; ShellCorona *m_corona;
bool m_stayBehind : 1;
bool m_fillScreen : 1;
bool m_dashboardShown : 1; bool m_dashboardShown : 1;
WindowType m_windowType;
}; };
#endif // DESKTOVIEW_H #endif // DESKTOVIEW_H

@ -77,6 +77,7 @@ ShellCorona::ShellCorona(QObject *parent)
m_screenConfiguration(nullptr), m_screenConfiguration(nullptr),
m_loading(false) m_loading(false)
{ {
qmlRegisterUncreatableType<DesktopView>("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"); m_lookAndFeelPackage = Plasma::PluginLoader::self()->loadPackage("Plasma/LookAndFeel");
KConfigGroup cg(KSharedConfig::openConfig("kdeglobals"), "KDE"); KConfigGroup cg(KSharedConfig::openConfig("kdeglobals"), "KDE");
const QString packageName = cg.readEntry("LookAndFeelPackage", QString()); const QString packageName = cg.readEntry("LookAndFeelPackage", QString());

Loading…
Cancel
Save