forked from linuxdeepin/deepin-screensaver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreensaverview.cpp
More file actions
103 lines (84 loc) · 2.63 KB
/
Copy pathscreensaverview.cpp
File metadata and controls
103 lines (84 loc) · 2.63 KB
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
// SPDX-FileCopyrightText: 2019~ 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "screensaverview.h"
#include "imageprovider.h"
#include <QPixmap>
#include <QProcess>
#include <QQmlEngine>
#include <QCoreApplication>
#include <QDir>
#include <QDebug>
#include <QDateTime>
Q_GLOBAL_STATIC(QQmlEngine, qmlEngineGlobal)
static QQmlEngine *globalEngine()
{
if (!qmlEngineGlobal.exists()) {
qmlEngineGlobal->addImageProvider("deepin-screensaver", new ImageProvider());
// 添加插件载入路径,方便屏保应用携带插件扩展功能
qmlEngineGlobal->addImportPath("file://" LIB_PATH "/qml/imports");
qmlEngineGlobal->addImportPath("qrc:/deepin-screensaver/qml/imports");
qmlEngineGlobal->addImportPath(QString("file://%1/.local/lib/%2/qml/imports").arg(QDir::homePath(), qApp->applicationName()));
}
return qmlEngineGlobal;
}
ScreenSaverView::ScreenSaverView(QWindow *parent)
: QQuickView(globalEngine(), parent)
{
}
ScreenSaverView::~ScreenSaverView()
{
stop();
}
bool ScreenSaverView::start(const QString &filePath)
{
stop();
if (filePath.endsWith(".qml")) {
setSource(QUrl(filePath));
} else {
if (!m_process) {
m_process = new QProcess(this);
m_process->setProcessChannelMode(QProcess::ForwardedChannels);
}
create();
m_process->start(filePath, {"-window-id", QString::number(winId())}, QIODevice::ReadOnly);
if (!m_process->waitForStarted(3000)) {
qDebug() << "Failed on start:" << m_process->program() << ", error string:" << m_process->errorString();
return false;
}
}
return true;
}
void ScreenSaverView::stop()
{
if (m_process && m_process->state() != QProcess::NotRunning) {
m_process->terminate();
m_process->waitForFinished();
}
// 清理qml的播放
setSource(QUrl());
// 清理窗口背景色
setColor(Qt::black);
}
bool ScreenSaverView::event(QEvent *event)
{
switch (event->type()) {
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
case QEvent::MouseMove:
case QEvent::MouseButtonDblClick:
//case QEvent::FocusOut: /* Multiple screen will be triggered, causing the screensaver window to exit */
case QEvent::ApplicationStateChange:
case QEvent::TouchBegin:
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
case QEvent::TouchCancel:
case QEvent::KeyPress:
case QEvent::KeyRelease:
emit inputEvent(event->type());
break;
default:
break;
}
return QQuickView::event(event);
}