From adada166031688b6ed10b993b4fe194b2bc226a3 Mon Sep 17 00:00:00 2001 From: spycrab Date: Mon, 1 Jan 2018 21:15:26 +0000 Subject: [PATCH] Qt: Toggle Screensaver --- Source/Core/DolphinQt2/MainWindow.cpp | 17 +++++++++++++++++ Source/Core/DolphinQt2/MainWindow.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/Source/Core/DolphinQt2/MainWindow.cpp b/Source/Core/DolphinQt2/MainWindow.cpp index 99e762cdb8..90b475071b 100644 --- a/Source/Core/DolphinQt2/MainWindow.cpp +++ b/Source/Core/DolphinQt2/MainWindow.cpp @@ -338,6 +338,7 @@ void MainWindow::Play(const std::optional& savestate_path) if (Core::GetState() == Core::State::Paused) { Core::SetState(Core::State::Running); + EnableScreenSaver(false); } else { @@ -345,6 +346,7 @@ void MainWindow::Play(const std::optional& savestate_path) if (selection) { StartGame(selection->GetFilePath(), savestate_path); + EnableScreenSaver(false); } else { @@ -352,6 +354,7 @@ void MainWindow::Play(const std::optional& savestate_path) if (!default_path.isEmpty() && QFile::exists(default_path)) { StartGame(default_path, savestate_path); + EnableScreenSaver(false); } else { @@ -364,6 +367,7 @@ void MainWindow::Play(const std::optional& savestate_path) void MainWindow::Pause() { Core::SetState(Core::State::Paused); + EnableScreenSaver(true); } void MainWindow::OnStopComplete() @@ -441,6 +445,7 @@ bool MainWindow::RequestStop() void MainWindow::ForceStop() { BootManager::Stop(); + EnableScreenSaver(true); } void MainWindow::Reset() @@ -801,6 +806,18 @@ void MainWindow::NetPlayQuit() Settings::Instance().ResetNetPlayServer(); } +void MainWindow::EnableScreenSaver(bool enable) +{ +#if defined(HAVE_XRANDR) && HAVE_XRANDR + UICommon::EnableScreenSaver( + static_cast(QGuiApplication::platformNativeInterface()->nativeResourceForWindow( + "display", windowHandle())), + winId(), enable); +#else + UICommon::EnableScreenSaver(enable); +#endif +} + bool MainWindow::eventFilter(QObject* object, QEvent* event) { if (event->type() == QEvent::Close) diff --git a/Source/Core/DolphinQt2/MainWindow.h b/Source/Core/DolphinQt2/MainWindow.h index a230a2322f..5c042f7fe8 100644 --- a/Source/Core/DolphinQt2/MainWindow.h +++ b/Source/Core/DolphinQt2/MainWindow.h @@ -115,6 +115,8 @@ private: void OnStopRecording(); void OnExportRecording(); + void EnableScreenSaver(bool enable); + void OnStopComplete(); void dragEnterEvent(QDragEnterEvent* event) override; void dropEvent(QDropEvent* event) override;