OSDN Git Service

xwallpaper: new fancy wallpaper
authorIvailo Monev <xakepa10@gmail.com>
Fri, 11 Aug 2023 20:14:49 +0000 (23:14 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Fri, 11 Aug 2023 20:15:20 +0000 (23:15 +0300)
hack on top of hack but kewl!

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
CMakeLists.txt
xwallpaper/CMakeLists.txt [new file with mode: 0644]
xwallpaper/plasma-wallpaper-xwallpaper.desktop [new file with mode: 0644]
xwallpaper/xwallpaper.cpp [new file with mode: 0644]
xwallpaper/xwallpaper.h [new file with mode: 0644]

index d33e1ee..6e9b48c 100644 (file)
@@ -31,3 +31,4 @@ macro_optional_add_subdirectory (knetpkg)
 macro_optional_add_subdirectory (kfirewall)
 macro_optional_add_subdirectory (khash)
 macro_optional_add_subdirectory (kprintjobs)
+macro_optional_add_subdirectory (xwallpaper)
diff --git a/xwallpaper/CMakeLists.txt b/xwallpaper/CMakeLists.txt
new file mode 100644 (file)
index 0000000..c1d79ba
--- /dev/null
@@ -0,0 +1,26 @@
+project(plasma-wallpaper-xwallpaper)
+
+if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
+    include(FeatureSummary)
+
+    find_package(KDELibs4 4.23.0 REQUIRED)
+
+    include_directories(${KDE4_INCLUDES})
+    add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
+endif()
+
+set(xwallpaper_SRCS
+    xwallpaper.cpp
+)
+
+kde4_add_plugin(plasma_wallpaper_xwallpaper ${xwallpaper_SRCS})
+target_link_libraries(plasma_wallpaper_xwallpaper KDE4::plasma KDE4::kdeui)
+
+install(
+    TARGETS plasma_wallpaper_xwallpaper
+    DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}
+)
+install(
+    FILES plasma-wallpaper-xwallpaper.desktop
+    DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
+)
diff --git a/xwallpaper/plasma-wallpaper-xwallpaper.desktop b/xwallpaper/plasma-wallpaper-xwallpaper.desktop
new file mode 100644 (file)
index 0000000..48c78f9
--- /dev/null
@@ -0,0 +1,17 @@
+[Desktop Entry]
+Name=XScreensaver as wallpaper
+Comment=XScreensaver as wallpaper
+Type=Service
+Icon=xorg
+ServiceTypes=Plasma/Wallpaper
+
+X-KDE-Library=plasma_wallpaper_xwallpaper
+X-KDE-PluginInfo-Author=Ivailo Monev
+X-KDE-PluginInfo-Email=xakepa10@gmail.com
+X-KDE-PluginInfo-Name=org.kde.xwallpaper
+X-KDE-PluginInfo-Version=0.1
+X-KDE-PluginInfo-Website=
+X-KDE-PluginInfo-Depends=
+X-KDE-PluginInfo-License=GPL
+X-KDE-PluginInfo-EnabledByDefault=true
+
diff --git a/xwallpaper/xwallpaper.cpp b/xwallpaper/xwallpaper.cpp
new file mode 100644 (file)
index 0000000..889ed1f
--- /dev/null
@@ -0,0 +1,81 @@
+/*  This file is part of the KDE project
+    Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License version 2, as published by the Free Software Foundation.
+
+    This library 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
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#include "xwallpaper.h"
+
+#include <QX11Info>
+#include <QApplication>
+#include <QDesktopWidget>
+#include <KDebug>
+
+static const QString s_xscreensaver = QString::fromLatin1("/usr/libexec/xscreensaver/binaryring");
+static const int s_updateinterval = 100; // increase to decrease CPU usage
+
+XWallpaper::XWallpaper(QObject *parent, const QVariantList &args)
+    : Plasma::Wallpaper(parent, args),
+    m_widget(nullptr),
+    m_proc(nullptr),
+    m_timer(nullptr)
+{
+    m_widget = new QWidget(nullptr, Qt::X11BypassWindowManagerHint);
+    // move it outside the screen space, should the resolution change the widget may be visible but
+    // neither rendering nor grabbing the window works without the winodow being visible
+    const QRect trect = QApplication::desktop()->geometry();
+    m_widget->move(trect.bottom(), trect.right());
+    m_widget->show();
+
+    m_proc = new QProcess(this);
+    m_proc->start(
+        s_xscreensaver,
+        QStringList() << "--window-id" << QString::number(qlonglong(m_widget->winId()))
+    );
+    if (!m_proc->waitForStarted()) {
+        kWarning() << "Could not start" << s_xscreensaver;
+        return;
+    } else {
+        kDebug() << "Started" << s_xscreensaver << QString::number(qlonglong(m_widget->winId()));
+    }
+
+    m_timer = new QTimer(this);
+    m_timer->setInterval(s_updateinterval);
+    connect(m_timer, SIGNAL(timeout()), this, SLOT(slotTimeout()));
+    m_timer->start();
+}
+
+XWallpaper::~XWallpaper()
+{
+    m_timer->stop();
+    m_proc->terminate();
+    m_proc->waitForFinished();
+    delete m_widget;
+}
+
+void XWallpaper::paint(QPainter *painter, const QRectF &exposedRect)
+{
+    kDebug() << "Rendering" << s_xscreensaver << targetSizeHint().toSize();
+    const QSize tsize = targetSizeHint().toSize();
+    m_widget->resize(tsize.width(), tsize.height());
+    painter->drawPixmap(QPoint(), QPixmap::grabWindow(m_widget->winId()));
+}
+
+void XWallpaper::slotTimeout()
+{
+    emit update(QRectF());
+}
+
+#include "moc_xwallpaper.cpp"
diff --git a/xwallpaper/xwallpaper.h b/xwallpaper/xwallpaper.h
new file mode 100644 (file)
index 0000000..92e9513
--- /dev/null
@@ -0,0 +1,49 @@
+/*  This file is part of the KDE project
+    Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License version 2, as published by the Free Software Foundation.
+
+    This library 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
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public License
+    along with this library; see the file COPYING.LIB.  If not, write to
+    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+    Boston, MA 02110-1301, USA.
+*/
+
+#ifndef XWALLPAPER_H
+#define XWALLPAPER_H
+
+#include <QWidget>
+#include <QProcess>
+#include <QTimer>
+#include <Plasma/Wallpaper>
+#include <Plasma/DataEngine>
+
+class XWallpaper : public Plasma::Wallpaper
+{
+    Q_OBJECT
+
+public:
+    XWallpaper(QObject* parent, const QVariantList& args);
+    ~XWallpaper();
+
+    void paint(QPainter* painter, const QRectF &exposedRect);
+
+private Q_SLOTS:
+    void slotTimeout();
+
+private:
+    QWidget* m_widget;
+    QProcess* m_proc;
+    QTimer* m_timer;
+};
+
+K_EXPORT_PLASMA_WALLPAPER(xwallpaper, XWallpaper)
+
+#endif // XWALLPAPER_H