mirror of
https://bitbucket.org/smil3y/kde-playground.git
synced 2025-02-23 18:32:51 +00:00
xwallpaper: new fancy wallpaper
hack on top of hack but kewl! Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
e41687d349
commit
c0650fe3f7
5 changed files with 174 additions and 0 deletions
|
@ -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)
|
||||
|
|
26
xwallpaper/CMakeLists.txt
Normal file
26
xwallpaper/CMakeLists.txt
Normal file
|
@ -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}
|
||||
)
|
17
xwallpaper/plasma-wallpaper-xwallpaper.desktop
Normal file
17
xwallpaper/plasma-wallpaper-xwallpaper.desktop
Normal file
|
@ -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
|
||||
|
81
xwallpaper/xwallpaper.cpp
Normal file
81
xwallpaper/xwallpaper.cpp
Normal file
|
@ -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"
|
49
xwallpaper/xwallpaper.h
Normal file
49
xwallpaper/xwallpaper.h
Normal file
|
@ -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
|
Loading…
Add table
Reference in a new issue