kcms/tabbox: Add mock-up object for KWin.DesktopBackground

The window switcher previews don't use the actual quick components
the KWin plugin provides, but mock-up objects of those.

Add a mock-up component for `KWin.DesktopBackground`, which is just
a thumbnail of the desktop default image but stretched to cover the
whole parent size.

This fixes the previews for flip&cover window switchers.

BUG: 479552
FIXED-IN: 5.93.0
wilder/Plasma/6.2
Ismael Asensio 2 years ago
parent c1e09f65c9
commit 3572e6f0e7
  1. 23
      src/kcms/tabbox/layoutpreview.cpp
  2. 20
      src/kcms/tabbox/layoutpreview.h

@ -33,6 +33,7 @@ LayoutPreview::LayoutPreview(const QString &path, bool showDesktopThumbnail, QOb
QQmlComponent *component = new QQmlComponent(engine, this);
qmlRegisterType<WindowThumbnailItem>("org.kde.kwin", 3, 0, "WindowThumbnail");
qmlRegisterType<SwitcherItem>("org.kde.kwin", 3, 0, "TabBoxSwitcher");
qmlRegisterType<DesktopBackground>("org.kde.kwin", 3, 0, "DesktopBackground");
qmlRegisterAnonymousType<QAbstractItemModel>("org.kde.kwin", 3);
component->loadUrl(QUrl::fromLocalFile(path));
if (component->isError()) {
@ -246,6 +247,28 @@ void SwitcherItem::decrementIndex()
setCurrentIndex(index);
}
DesktopBackground::DesktopBackground(QQuickItem *parent)
: WindowThumbnailItem(parent)
{
setWId(WindowThumbnailItem::Desktop);
connect(this, &QQuickItem::windowChanged, this, &DesktopBackground::stretchToScreen);
stretchToScreen();
};
void DesktopBackground::stretchToScreen()
{
const QQuickWindow *w = window();
if (!w) {
return;
}
const QScreen *screen = w->screen();
if (!screen) {
return;
}
setImplicitSize(screen->size().width(), screen->size().height());
};
} // namespace KWin
} // namespace TabBox

@ -149,5 +149,25 @@ inline QObject *SwitcherItem::item() const
return m_item;
}
class DesktopBackground : public WindowThumbnailItem
{
Q_OBJECT
Q_PROPERTY(QVariant activity MEMBER m_activity)
Q_PROPERTY(QVariant desktop MEMBER m_desktop)
Q_PROPERTY(QString outputName MEMBER m_outputName)
public:
DesktopBackground(QQuickItem *parent = nullptr);
private Q_SLOTS:
void stretchToScreen();
private:
// Just for mock-up purposes.
QVariant m_activity;
QVariant m_desktop;
QString m_outputName;
};
} // namespace TabBox
} // namespace KWin

Loading…
Cancel
Save