Commit a8897a8d authored by Ronan's avatar Ronan

feat(DesktopTools): can disable screen saver on MacOs

parent e888eb27
......@@ -232,6 +232,7 @@ if (APPLE)
src/app/single-application/SingleApplication.cpp
src/components/core/messages-count-notifier/MessagesCountNotifierMacOs.m
src/components/other/desktop-tools/DesktopToolsMacOs.cpp
src/components/other/desktop-tools/screen-saver/ScreenSaverMacOs.m
)
list(APPEND HEADERS
src/app/single-application/SingleApplicationPrivate.hpp
......@@ -400,7 +401,7 @@ foreach (package ${QT5_PACKAGES_OPTIONAL})
endforeach ()
if (APPLE)
list(APPEND LIBRARIES "-framework Cocoa")
list(APPEND LIBRARIES "-framework Cocoa -framework IOKit")
endif ()
target_include_directories(${APP_LIBRARY} SYSTEM PRIVATE ${INCLUDED_DIRECTORIES})
......
......@@ -188,7 +188,9 @@ void App::initContentApp () {
Cli::executeCommand(command);
});
mustBeIconified = mParser->isSet("iconified");
#ifndef Q_OS_MACOS
mustBeIconified = mParser->isSet("iconified");
#endif // ifndef Q_OS_MACOS
mColors = new Colors(this);
}
......
......@@ -25,16 +25,16 @@
#include "AbstractMessagesCountNotifier.hpp"
extern "C" void notifyUnreadMessagesCountMacOS (int n);
// =============================================================================
extern "C" void notifyUnreadMessagesCountMacOs (int n);
class MessagesCountNotifier : public AbstractMessagesCountNotifier {
public:
MessagesCountNotifier (QObject *parent = Q_NULLPTR) : AbstractMessagesCountNotifier(parent) {}
void notifyUnreadMessagesCount (int n) override {
notifyUnreadMessagesCountMacOS(n);
notifyUnreadMessagesCountMacOs(n);
}
};
......
......@@ -24,7 +24,7 @@
// =============================================================================
void notifyUnreadMessagesCountMacOS (int n) {
void notifyUnreadMessagesCountMacOs (int n) {
NSString *badgeStr = (n > 0) ? [NSString stringWithFormat:@"%d", n] : @"";
[[NSApp dockTile] setBadgeLabel:badgeStr];
}
......@@ -21,9 +21,13 @@
*/
#include "DesktopToolsMacOs.hpp"
#include <QDebug>
// =============================================================================
extern "C" bool enableScreenSaverMacOs ();
extern "C" bool disableScreenSaverMacOs ();
DesktopTools::DesktopTools (QObject *parent) : QObject(parent) {}
DesktopTools::~DesktopTools () {
......@@ -35,9 +39,11 @@ bool DesktopTools::getScreenSaverStatus () const {
}
void DesktopTools::setScreenSaverStatus (bool status) {
if (status == mScreenSaverStatus)
return;
qDebug() << "SCREENSAVER " << status;
// TODO: Deal with me.
emit screenSaverStatusChanged(status);
if (status != mScreenSaverStatus && (status ? enableScreenSaverMacOs() : disableScreenSaverMacOs())) {
qDebug() << "SCREENSAVER INT " << status;
mScreenSaverStatus = status;
emit screenSaverStatusChanged(mScreenSaverStatus);
}
}
......@@ -63,7 +63,7 @@ void ScreenSaverDBus::setScreenSaverStatus (bool status) {
return;
}
QDBusMessage reply(mBus.call("Inhibit", QCoreApplication::applicationName(), "Inhibit asked for video stream."));
QDBusMessage reply(mBus.call("Inhibit", QCoreApplication::applicationName(), "Inhibit asked for video stream"));
if (reply.type() == QDBusMessage::ErrorMessage) {
if (reply.errorName() != QLatin1String("org.freedesktop.DBus.Error.ServiceUnknown"))
qWarning() << QStringLiteral("Inhibit screen saver failed: `%1: %2`.")
......
/*
* ScreenSaverMacOS.m
* 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: August 3, 2018
* Author: Ronan Abhamon
*/
#import <IOKit/pwr_mgt/IOPMLib.h>
// =============================================================================
static bool ScreenSaverEnabled = true;
static IOPMAssertionID AssertionID;
bool enableScreenSaverMacOs () {
if (ScreenSaverEnabled)
return true;
ScreenSaverEnabled = IOPMAssertionRelease(AssertionID) == kIOReturnSuccess;
return ScreenSaverEnabled;
}
bool disableScreenSaverMacOs () {
if (!ScreenSaverEnabled)
return true;
ScreenSaverEnabled = IOPMAssertionCreateWithName(
kIOPMAssertionTypeNoDisplaySleep,
kIOPMAssertionLevelOn,
CFSTR("Inhibit asked for video stream"),
&AssertionID
) != kIOReturnSuccess;
return !ScreenSaverEnabled;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment