Skip to content

Commit 0f47802

Browse files
author
rekols
committed
fix: don't sleep while playing.
Change-Id: I0e35356fe91b0f6cf159325ba7c68731584ed961
1 parent ebf1a19 commit 0f47802

File tree

4 files changed

+86
-24
lines changed

4 files changed

+86
-24
lines changed

src/common/mainwindow.cpp

+52-20
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,30 @@ MainWindow::MainWindow(QWidget *parent)
628628
qDebug() << __func__ << _engine->state();
629629
if (_engine->state() == PlayerEngine::CoreState::Playing) {
630630
_miniPlayBtn->setObjectName("MiniPauseBtn");
631+
632+
if (_lastCookie > 0) {
633+
utils::UnInhibitStandby(_lastCookie);
634+
qDebug() << "uninhibit cookie" << _lastCookie;
635+
_lastCookie = 0;
636+
}
637+
if (_powerCookie > 0) {
638+
utils::UnInhibitPower(_powerCookie);
639+
_powerCookie = 0;
640+
}
641+
_lastCookie = utils::InhibitStandby();
642+
_powerCookie = utils::InhibitPower();
631643
} else {
632644
_miniPlayBtn->setObjectName("MiniPlayBtn");
645+
646+
if (_lastCookie > 0) {
647+
utils::UnInhibitStandby(_lastCookie);
648+
qDebug() << "uninhibit cookie" << _lastCookie;
649+
_lastCookie = 0;
650+
}
651+
if (_powerCookie > 0) {
652+
utils::UnInhibitPower(_powerCookie);
653+
_powerCookie = 0;
654+
}
633655
}
634656
_miniPlayBtn->setStyleSheet(_miniPlayBtn->styleSheet());
635657
});
@@ -851,26 +873,26 @@ void MainWindow::onWindowStateChanged()
851873
{
852874
qDebug() << windowState();
853875

854-
if (!isFullScreen()) {
855-
qApp->restoreOverrideCursor();
856-
if (_lastCookie > 0) {
857-
utils::UnInhibitStandby(_lastCookie);
858-
qDebug() << "uninhibit cookie" << _lastCookie;
859-
_lastCookie = 0;
860-
}
861-
if (_listener) _listener->setEnabled(!isMaximized() && !_miniMode);
862-
} else {
863-
qApp->setOverrideCursor(Qt::BlankCursor);
864-
865-
if (_lastCookie > 0) {
866-
utils::UnInhibitStandby(_lastCookie);
867-
qDebug() << "uninhibit cookie" << _lastCookie;
868-
_lastCookie = 0;
869-
}
870-
_lastCookie = utils::InhibitStandby();
871-
qDebug() << "inhibit cookie" << _lastCookie;
872-
if (_listener) _listener->setEnabled(false);
873-
}
876+
// if (!isFullScreen()) {
877+
// qApp->restoreOverrideCursor();
878+
// if (_lastCookie > 0) {
879+
// utils::UnInhibitStandby(_lastCookie);
880+
// qDebug() << "uninhibit cookie" << _lastCookie;
881+
// _lastCookie = 0;
882+
// }
883+
// if (_listener) _listener->setEnabled(!isMaximized() && !_miniMode);
884+
// } else {
885+
// qApp->setOverrideCursor(Qt::BlankCursor);
886+
887+
// if (_lastCookie > 0) {
888+
// utils::UnInhibitStandby(_lastCookie);
889+
// qDebug() << "uninhibit cookie" << _lastCookie;
890+
// _lastCookie = 0;
891+
// }
892+
// _lastCookie = utils::InhibitStandby();
893+
// qDebug() << "inhibit cookie" << _lastCookie;
894+
// if (_listener) _listener->setEnabled(false);
895+
// }
874896
if (!_miniMode && !isFullScreen()) {
875897
_titlebar->setVisible(_toolbox->isVisible());
876898
} else {
@@ -969,6 +991,16 @@ MainWindow::~MainWindow()
969991
disconnect(_engine, 0, 0, 0);
970992
disconnect(&_engine->playlist(), 0, 0, 0);
971993

994+
if (_lastCookie > 0) {
995+
utils::UnInhibitStandby(_lastCookie);
996+
qDebug() << "uninhibit cookie" << _lastCookie;
997+
_lastCookie = 0;
998+
}
999+
if (_powerCookie > 0) {
1000+
utils::UnInhibitPower(_powerCookie);
1001+
_powerCookie = 0;
1002+
}
1003+
9721004
#ifdef USE_DXCB
9731005
if (_evm) {
9741006
disconnect(_evm, 0, 0, 0);

src/common/mainwindow.h

+1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ protected slots:
216216
Qt::WindowStates _lastWindowState {Qt::WindowNoState};
217217

218218
uint32_t _lastCookie {0};
219+
uint32_t _powerCookie {0};
219220

220221
MainWindowEventListener *_listener {nullptr};
221222
NotificationWidget *_nwShot {nullptr};

src/libdmr/utils.cpp

+30-4
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,11 @@ QPixmap MakeRoundedPixmap(QSize sz, QPixmap pm, qreal rx, qreal ry, qint64 time)
292292

293293
uint32_t InhibitStandby()
294294
{
295-
QDBusInterface iface("org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver",
296-
"org.freedesktop.ScreenSaver");
295+
QDBusInterface iface("org.freedesktop.ScreenSaver",
296+
"/org/freedesktop/ScreenSaver",
297+
"org.freedesktop.ScreenSaver");
297298
QDBusReply<uint32_t> reply = iface.call("Inhibit", "deepin-movie", "playing in fullscreen");
299+
298300
if (reply.isValid()) {
299301
return reply.value();
300302
}
@@ -305,8 +307,32 @@ uint32_t InhibitStandby()
305307

306308
void UnInhibitStandby(uint32_t cookie)
307309
{
308-
QDBusInterface iface("org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver",
309-
"org.freedesktop.ScreenSaver");
310+
QDBusInterface iface("org.freedesktop.ScreenSaver",
311+
"/org/freedesktop/ScreenSaver",
312+
"org.freedesktop.ScreenSaver");
313+
iface.call("UnInhibit", cookie);
314+
}
315+
316+
uint32_t InhibitPower()
317+
{
318+
QDBusInterface iface("org.freedesktop.PowerManagement",
319+
"/org/freedesktop/PowerManagement",
320+
"org.freedesktop.PowerManagement");
321+
QDBusReply<uint32_t> reply = iface.call("Inhibit", "deepin-movie", "playing in fullscreen");
322+
323+
if (reply.isValid()) {
324+
return reply.value();
325+
}
326+
327+
qDebug() << reply.error().message();
328+
return 0;
329+
}
330+
331+
void UnInhibitPower(uint32_t cookie)
332+
{
333+
QDBusInterface iface("org.freedesktop.PowerManagement",
334+
"/org/freedesktop/PowerManagement",
335+
"org.freedesktop.PowerManagement");
310336
iface.call("UnInhibit", cookie);
311337
}
312338

src/libdmr/utils.h

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ namespace utils {
5050
uint32_t InhibitStandby();
5151
void UnInhibitStandby(uint32_t cookie);
5252

53+
uint32_t InhibitPower();
54+
void UnInhibitPower(uint32_t cookie);
55+
5356
void MoveToCenter(QWidget* w);
5457

5558
QString Time2str(qint64 seconds);

0 commit comments

Comments
 (0)