代码拉取完成,页面将自动刷新
同步操作将从 depend/fantascene-dynamic-wallpaper 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "wallpaper.h"
#include <QFileDialog>
#include <QStandardPaths>
#include <QApplication>
#include <QtX11Extras/QX11Info>
#include <QScreen>
#include <xcb/xcb.h>
#include <xcb/xcb_ewmh.h>
#include <QApplication>
#include <QPainter>
#include <QTimer>
#include <QGraphicsOpacityEffect>
#include <QDesktopWidget>
#include <QDebug>
#include <QLabel>
#include <QDBusConnection>
#include "application.h"
Wallpaper::Wallpaper(QString path, int currentScreen, QWidget *parent)
: QWidget(parent)
, m_currentPath(path)
, m_currentScreen(currentScreen)
{
setAttribute(Qt::WA_TranslucentBackground);
QHBoxLayout *layout = new QHBoxLayout;
layout->setSpacing(0);
layout->setMargin(0);
setLayout(layout);
registerDesktop();
m_mpv = new MpvWidget(this);
m_mpv->setGeometry(geometry());
m_mpv->setGeometry(geometry());
m_mpv->setGeometry(geometry());
layout->addWidget(m_mpv);
m_mpv->hide();
m_mpv->setProperty("loop", true);
m_mpv->setProperty("panscan", 1);
m_mpv->setGeometry(geometry());
connect(dApp, &Application::refreshPix, this, &Wallpaper::slotrefreshPix);
connect(dApp, &Application::setScreenMode, this, &Wallpaper::slotsetScreenMode);
connect(qApp->desktop(), &QDesktopWidget::resized, this, &Wallpaper::updateGeometry);
connect(dApp, &Application::setPlayPath, this, &Wallpaper::setFile);
connect(dApp, &Application::setMpvPlay, this, &Wallpaper::play);
connect(dApp, &Application::setMpvpause, this, &Wallpaper::pause);
connect(dApp, &Application::setMpvstop, this, &Wallpaper::stop);
connect(dApp, &Application::setMpvVolume, this, &Wallpaper::setVolume);
connect(dApp, &Application::setScreen, this, &Wallpaper::setScreen);
connect(dApp, &Application::sigupdateGeometry, this, &Wallpaper::updateGeometry);
connect(dApp, &Application::setMpvValue, this, &Wallpaper::slotSetMpvValue);
QDBusConnection::sessionBus().connect("com.deepin.SessionManager", "/com/deepin/SessionManager",
"org.freedesktop.DBus.Properties", "PropertiesChanged", this,
SLOT(onSysLockState(QString, QVariantMap, QStringList)));
QTimer::singleShot(1, this, &Wallpaper::updateGeometry);
QTimer::singleShot(1000, this, [ = ] {
int index = 0;
int index1 = 0;
qDebug() << "ssss" << index1;
for (const QString &arg : qApp->arguments())
{
if (index != 0) {
if (QFileInfo(arg).isFile()) {
setFile(arg);
play();
index1++;
qDebug() << "ssss1" << index1;
}
}
index++;
}
qDebug() << "ssss2" << index1;
if (index1 == 0)
{
QString playPath = "/opt/durapps/deepin-dreamscene-ui/09.mp4";
if (!m_currentPath.isEmpty()) {
if (QFileInfo(m_currentPath).isFile()) {
playPath = m_currentPath;
}
}
setFile(playPath);
play();
m_currentPath = QFileInfo(m_currentPath).filePath();
emit dApp->pathChanged(m_currentPath);
}
if (qApp->desktop()->screenCount() > 1 && IdCopyScreen == dApp->m_cuurentMode)
{
m_label2 = new QLabel();
layout->addWidget(m_label2);
}
});
setVolume(0);
}
void Wallpaper::changeScreenMode(ScreenMode mode)
{
switch (mode) {
case IdCopyScreen: {
if (qApp->desktop()->screenCount() > 1) {
if (nullptr == m_label2) {
m_label2 = new QLabel();
m_label2->setVisible(true);
}
layout()->addWidget(m_label2);
}
break;
}
case IdlayoutScreen: {
if (nullptr != m_label2) {
layout()->removeWidget(m_label2);
delete m_label2 ;
m_label2 = nullptr;
}
break;
}
case IdManualSet: {
if (nullptr != m_label2) {
layout()->removeWidget(m_label2);
delete m_label2 ;
m_label2 = nullptr;
}
break;
}
default:
break;
}
//暂时调用两次,为保证切换顺利
QTimer::singleShot(10, [ = ] {
updateGeometry();
});
updateGeometry();
}
void Wallpaper::setScreen(const int &index)
{
m_currentScreen = index;
}
void Wallpaper::setFile(const QString &path)
{
m_mpv->show();
m_mpv->command(QStringList() << "loadfile" << path);
m_mpv->setProperty("pause", true);
}
void Wallpaper::setVolume(const qint32 volume)
{
m_mpv->setProperty("volume", volume);
}
void Wallpaper::clear()
{
stop();
hide();
}
void Wallpaper::play()
{
m_mpv->show();
m_mpv->setProperty("pause", false);
}
void Wallpaper::pause()
{
m_mpv->setProperty("pause", true);
}
void Wallpaper::stop()
{
m_mpv->setProperty("stop", true);
}
void Wallpaper::slotrefreshPix(const QPixmap &pix)
{
if (m_label2) {
m_label2->setPixmap(pix);
}
}
void Wallpaper::slotsetScreenMode(const QString &mode)
{
if (mode == "复制") {
if (dApp->m_cuurentMode != IdCopyScreen) {
dApp->m_cuurentMode = IdCopyScreen;
changeScreenMode(dApp->m_cuurentMode);
}
} else if (mode == "扩展") {
if (dApp->m_cuurentMode != IdlayoutScreen) {
dApp->m_cuurentMode = IdlayoutScreen;
changeScreenMode(dApp->m_cuurentMode);
}
} else if (mode == "手动设置尺寸") {
if (dApp->m_cuurentMode != IdManualSet) {
dApp->m_cuurentMode = IdManualSet;
changeScreenMode(dApp->m_cuurentMode);
}
}
}
void Wallpaper::registerDesktop()
{
xcb_ewmh_connection_t m_ewmh_connection;
xcb_intern_atom_cookie_t *cookie = xcb_ewmh_init_atoms(QX11Info::connection(), &m_ewmh_connection);
xcb_ewmh_init_atoms_replies(&m_ewmh_connection, cookie, NULL);
xcb_atom_t atoms[1];
atoms[0] = m_ewmh_connection._NET_WM_WINDOW_TYPE_DESKTOP;
xcb_ewmh_set_wm_window_type(&m_ewmh_connection, winId(), 1, atoms);
QTimer::singleShot(1, this, [ = ] {
show();
lower();
});
}
void Wallpaper::onSysLockState(QString, QVariantMap key2value, QStringList)
{
if (key2value.value("Locked").value<bool>()) {
pause();
} else {
play();
}
}
void Wallpaper::slotSetMpvValue(const QString &key, const QString &value)
{
m_mpv->setProperty(key, value);
}
#include <QDesktopWidget>
#include <QGuiApplication>
void Wallpaper::updateGeometry()
{
// QTimer::singleShot(100, this, [ = ] {
dApp->m_currentScreenNum = dApp->desktop()->screenCount();
QRect rec;
QSize size1(0, 0);
rec = qApp->desktop()->screenGeometry(qApp->desktop()->primaryScreen());
QRect rec2 = qApp->desktop()->screenGeometry();
QRect deskRect = qApp->desktop()->availableGeometry();
rec = deskRect;
if (dApp->m_cuurentMode == IdCopyScreen) {
rec = QRect(0, 0, rec.width(), rec.height());
size1.setWidth(rec.width());
size1.setHeight(rec.height());
} else if (dApp->m_cuurentMode == IdlayoutScreen) {
rec = QRect(0, 0, rec.width() * dApp->desktop()->screenCount(), rec.height());
size1.setWidth(rec.width());
size1.setHeight(rec.height());
} else if (dApp->m_cuurentMode == IdManualSet) {
rec = dApp->m_manual;
size1.setWidth(dApp->m_manual.width());
size1.setHeight(dApp->m_manual.height());
}
this->setGeometry(rec);
// m_mpv->setGeometry(rec2);
qDebug() << this->size();
m_mpv->move(rect().topLeft());
m_mpv->setFixedSize(size1);
lower();
// });
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。