1 /* This file is part of the KDE project
2 Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2, as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #include "xwallpaper.h"
22 #include <QApplication>
23 #include <QDesktopWidget>
26 static const QString s_xscreensaver = QString::fromLatin1("/usr/libexec/xscreensaver/binaryring");
27 static const int s_updateinterval = 100; // increase to decrease CPU usage
29 XWallpaper::XWallpaper(QObject *parent, const QVariantList &args)
30 : Plasma::Wallpaper(parent, args),
35 m_widget = new QWidget(nullptr, Qt::X11BypassWindowManagerHint);
36 // move it outside the screen space, should the resolution change the widget may be visible but
37 // neither rendering nor grabbing the window works without the winodow being visible
38 const QRect trect = QApplication::desktop()->geometry();
39 m_widget->move(trect.bottom(), trect.right());
42 m_proc = new QProcess(this);
45 QStringList() << "--window-id" << QString::number(qlonglong(m_widget->winId()))
47 if (!m_proc->waitForStarted()) {
48 kWarning() << "Could not start" << s_xscreensaver;
51 kDebug() << "Started" << s_xscreensaver << QString::number(qlonglong(m_widget->winId()));
54 m_timer = new QTimer(this);
55 m_timer->setInterval(s_updateinterval);
56 connect(m_timer, SIGNAL(timeout()), this, SLOT(slotTimeout()));
60 XWallpaper::~XWallpaper()
64 m_proc->waitForFinished();
68 void XWallpaper::paint(QPainter *painter, const QRectF &exposedRect)
70 kDebug() << "Rendering" << s_xscreensaver << targetSizeHint().toSize();
71 const QSize tsize = targetSizeHint().toSize();
72 m_widget->resize(tsize.width(), tsize.height());
73 painter->drawPixmap(QPoint(), QPixmap::grabWindow(m_widget->winId()));
76 void XWallpaper::slotTimeout()
78 emit update(QRectF());
81 #include "moc_xwallpaper.cpp"