This repository has been archived by the owner on Jun 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwallpaper.cpp
105 lines (86 loc) · 2.31 KB
/
wallpaper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#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>
Wallpaper::Wallpaper(QWidget *parent)
: QWidget(parent)
{
setAttribute(Qt::WA_TranslucentBackground);
QVBoxLayout *layout = new QVBoxLayout;
layout->setSpacing(0);
layout->setMargin(0);
setLayout(layout);
registerDesktop();
m_mpv = new MpvWidget(this);
m_mpv->setGeometry(geometry());
layout->addWidget(m_mpv);
m_mpv->hide();
m_mpv->setProperty("loop", true);
connect(qApp->desktop(), &QDesktopWidget::resized, this, &Wallpaper::updateGeometry);
QTimer::singleShot(1, this, &Wallpaper::updateGeometry);
QTimer::singleShot(100, this, [=] {
setFile("/home/haruyukilxz/Videos/一択彼女加藤恵.mov");
play();
});
}
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::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::updateGeometry()
{
QTimer::singleShot(100, this, [=] {
const QRect &rec = qApp->desktop()->screenGeometry(qApp->desktop()->primaryScreen());
setGeometry(rec);
m_mpv->move(rect().topLeft());
m_mpv->setFixedSize(size());
lower();
});
}