From 5593b36b81d94af4815517bc4dcf6727399f1f81 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Thu, 21 Jun 2018 16:15:41 +0200 Subject: [PATCH] feat(Incall): disable screen saver on fullscreen video call (Windows) --- CMakeLists.txt | 2 + src/app/App.cpp | 1 + src/components/Components.hpp | 1 + .../other/desktop-tools/DesktopTools.cpp | 67 +++++++++++++++++++ .../other/desktop-tools/DesktopTools.hpp | 49 ++++++++++++++ ui/views/App/Calls/Incall.js | 2 + ui/views/App/Calls/IncallFullscreenWindow.qml | 3 + 7 files changed, 125 insertions(+) create mode 100644 src/components/other/desktop-tools/DesktopTools.cpp create mode 100644 src/components/other/desktop-tools/DesktopTools.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 142d4f92d..dee234b81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,6 +147,7 @@ set(SOURCES src/components/notifier/Notifier.cpp src/components/other/clipboard/Clipboard.cpp src/components/other/colors/Colors.cpp + src/components/other/desktop-tools/DesktopTools.cpp src/components/other/text-to-speech/TextToSpeech.cpp src/components/other/units/Units.cpp src/components/presence/OwnPresenceModel.cpp @@ -205,6 +206,7 @@ set(HEADERS src/components/notifier/Notifier.hpp src/components/other/clipboard/Clipboard.hpp src/components/other/colors/Colors.hpp + src/components/other/desktop-tools/DesktopTools.hpp src/components/other/text-to-speech/TextToSpeech.hpp src/components/other/units/Units.hpp src/components/presence/OwnPresenceModel.hpp diff --git a/src/app/App.cpp b/src/app/App.cpp index 622dad94b..6da77a7e1 100644 --- a/src/app/App.cpp +++ b/src/app/App.cpp @@ -424,6 +424,7 @@ void App::registerToolTypes () { qInfo() << QStringLiteral("Registering tool types..."); registerToolType("Clipboard"); + registerToolType("DesktopTools"); registerToolType("TextToSpeech"); registerToolType("Units"); } diff --git a/src/components/Components.hpp b/src/components/Components.hpp index 7738bda1a..5fd463470 100644 --- a/src/components/Components.hpp +++ b/src/components/Components.hpp @@ -56,6 +56,7 @@ #include "other/colors/Colors.hpp" #include "other/clipboard/Clipboard.hpp" +#include "other/desktop-tools/DesktopTools.hpp" #include "other/text-to-speech/TextToSpeech.hpp" #include "other/units/Units.hpp" diff --git a/src/components/other/desktop-tools/DesktopTools.cpp b/src/components/other/desktop-tools/DesktopTools.cpp new file mode 100644 index 000000000..fe59113ad --- /dev/null +++ b/src/components/other/desktop-tools/DesktopTools.cpp @@ -0,0 +1,67 @@ +/* + * DesktopTools.cpp + * Copyright (C) 2017-2018 Belledonne Communications, Grenoble, France + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Created on: June 21, 2018 + * Author: Ronan Abhamon + */ + +#include +#include + +#ifdef Q_OS_WIN + #include +#endif // ifdef Q_OS_WIN + +#include "DesktopTools.hpp" + +// ============================================================================= + +DesktopTools::DesktopTools (QObject *parent) : QObject(parent) {} + +DesktopTools::~DesktopTools () { + setScreenSaverStatus(true); +} + +bool DesktopTools::getScreenSaverStatus () const { + return mScreenSaverStatus; +} + +#ifdef Q_OS_WIN + +void DesktopTools::setScreenSaverStatus (bool status) { + if (status == mScreenSaverStatus) + return; + + if (!status) { + qInfo() << "Disable screen saver."; + SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED); + } else { + qInfo() << "Enable screen saver."; + SetThreadExecutionState(ES_CONTINUOUS); + } + + emit screenSaverStatusChanged(status); +} + +#else + +void DesktopTools::setScreenSaverStatus (bool) { + emit screenSaverStatusChanged(true); +} + +#endif // ifdef Q_OS_WIN diff --git a/src/components/other/desktop-tools/DesktopTools.hpp b/src/components/other/desktop-tools/DesktopTools.hpp new file mode 100644 index 000000000..101cabd85 --- /dev/null +++ b/src/components/other/desktop-tools/DesktopTools.hpp @@ -0,0 +1,49 @@ +/* + * DesktopTools.hpp + * Copyright (C) 2017-2018 Belledonne Communications, Grenoble, France + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Created on: June 21, 2018 + * Author: Ronan Abhamon + */ + +#ifndef DESKTOP_TOOLS_H_ +#define DESKTOP_TOOLS_H_ + +#include + +// ============================================================================= + +class DesktopTools : public QObject { + Q_OBJECT; + + Q_PROPERTY(bool screenSaverStatus READ getScreenSaverStatus WRITE setScreenSaverStatus NOTIFY screenSaverStatusChanged); + +public: + DesktopTools (QObject *parent = Q_NULLPTR); + ~DesktopTools (); + + bool getScreenSaverStatus () const; + void setScreenSaverStatus (bool status); + +signals: + void screenSaverStatusChanged (bool status); + +private: + bool mScreenSaverStatus = true; +}; + +#endif // DESKTOP_TOOLS_H_ diff --git a/ui/views/App/Calls/Incall.js b/ui/views/App/Calls/Incall.js index e0771cbe7..5d6ee1dd1 100644 --- a/ui/views/App/Calls/Incall.js +++ b/ui/views/App/Calls/Incall.js @@ -2,6 +2,7 @@ // `Incall.qml` Logic. // ============================================================================= +.import DesktopTools 1.0 as DesktopTools .import Linphone 1.0 as Linphone .import 'qrc:/ui/scripts/Utils/utils.js' as Utils @@ -115,6 +116,7 @@ function showFullscreen () { return } + DesktopTools.DesktopTools.screenSaverStatus = false incall._fullscreen = Utils.openWindow(Qt.resolvedUrl('IncallFullscreenWindow.qml'), window, { properties: { caller: incall diff --git a/ui/views/App/Calls/IncallFullscreenWindow.qml b/ui/views/App/Calls/IncallFullscreenWindow.qml index 9bb5fbf7b..06ab750aa 100644 --- a/ui/views/App/Calls/IncallFullscreenWindow.qml +++ b/ui/views/App/Calls/IncallFullscreenWindow.qml @@ -4,6 +4,7 @@ import QtQuick.Window 2.2 import Common 1.0 import Common.Styles 1.0 +import DesktopTools 1.0 import Linphone 1.0 import Utils 1.0 @@ -25,6 +26,8 @@ Window { // --------------------------------------------------------------------------- function exit (cb) { + DesktopTools.screenSaverStatus = true + // `exit` is called by `Incall.qml`. // The `window` id can be null if the window was closed in this view. if (!window) {