Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/dbusscreensaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ bool DBusScreenSaver::Preview(const QString &name, int staysOn, bool preview)
const QDir &moduleDir = m_screenSaverNameToDir.value(name);
if (!QFile::exists(moduleDir.absoluteFilePath(name)))
return false;

m_previewing = preview;

if (preview) {
if (x11event) {
QAbstractEventDispatcher::instance()->removeNativeEventFilter(x11event.data());
Expand All @@ -228,7 +231,7 @@ bool DBusScreenSaver::Preview(const QString &name, int staysOn, bool preview)

for (ScreenSaverWindow *window : m_windowMap) {
if (staysOn) {
window->setFlags(window->flags() | Qt::WindowStaysOnTopHint, !preview);
window->setFlags(window->flags() | Qt::WindowStaysOnTopHint, true);
} else {
window->setFlags(window->flags() | Qt::WindowStaysOnBottomHint, false);
}
Expand All @@ -242,11 +245,7 @@ bool DBusScreenSaver::Preview(const QString &name, int staysOn, bool preview)
window->start(moduleDir.absoluteFilePath(name));
}

if (!preview) {
connect(window, &ScreenSaverWindow::inputEvent, this, &DBusScreenSaver::stop, Qt::UniqueConnection);
} else {
disconnect(window, &ScreenSaverWindow::inputEvent, this, &DBusScreenSaver::stop);
}
connect(window, &ScreenSaverWindow::inputEvent, this, &DBusScreenSaver::onInputEventReceived, Qt::UniqueConnection);

window->show();
}
Expand Down Expand Up @@ -457,6 +456,7 @@ void DBusScreenSaver::Stop(bool lock)
#endif

emit isRunningChanged(false);
m_previewing = false;
}

void DBusScreenSaver::stop()
Expand Down Expand Up @@ -651,6 +651,17 @@ void DBusScreenSaver::onConfigChanged(const QString &key)
setCurrentScreenSaver(screenSaver);
}

void DBusScreenSaver::onInputEventReceived(QEvent::Type type)
{
if (m_previewing) {
if (type == QEvent::MouseMove) { // 预览时鼠标移动不退出
return;
}
}
qInfo() << QDateTime::currentDateTime().toString() << "receive input evnet and will quit:" << type;
Stop();
}

void DBusScreenSaver::clearResourceList()
{
for (const QString &name : m_resourceList) {
Expand Down
2 changes: 2 additions & 0 deletions src/dbusscreensaver.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class DBusScreenSaver : public QObject
Q_SLOT void onSessionPropertyChanged(const QString &interface, const QVariantMap &changed_properties, const QDBusMessage &message);
Q_SLOT void onDBusPropertyChanged(const QString &interface, const QVariantMap &changed_properties, const QDBusMessage &message);
Q_SLOT void onConfigChanged(const QString &key);
Q_SLOT void onInputEventReceived(QEvent::Type type);

void clearResourceList();
void ensureWindowMap();
Expand Down Expand Up @@ -111,6 +112,7 @@ class DBusScreenSaver : public QObject
QScopedPointer<QDBusInterface> m_powerInterface;

static const QStringList m_dbusProperties;
bool m_previewing = false;
};

#endif // DBUSSCREENSAVER_H
1 change: 0 additions & 1 deletion src/screensaverview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ bool ScreenSaverView::event(QEvent *event)
case QEvent::TouchCancel:
case QEvent::KeyPress:
case QEvent::KeyRelease:
qInfo() << QDateTime::currentDateTime().toString() << "receive input evnet and will quit:" << event->type();
emit inputEvent(event->type());
break;

Expand Down