SYNERGY-1088 MacOS client ignores prevent sleeping option
This commit is contained in:
parent
2def465256
commit
8dd68abf56
4 changed files with 107 additions and 21 deletions
50
src/lib/platform/OSXPowerManager.cpp
Normal file
50
src/lib/platform/OSXPowerManager.cpp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2012-2021 Symless Ltd.
|
||||
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
||||
*
|
||||
* This package is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* found in the file LICENSE that should have accompanied this file.
|
||||
*
|
||||
* This package 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "OSXPowerManager.h"
|
||||
#include "base/Log.h"
|
||||
|
||||
OSXPowerManager::OSXPowerManager()
|
||||
{
|
||||
}
|
||||
|
||||
OSXPowerManager::~OSXPowerManager()
|
||||
{
|
||||
enableSleep();
|
||||
}
|
||||
|
||||
void OSXPowerManager::disableSleep()
|
||||
{
|
||||
if (!m_sleepPreventionAssertionID) {
|
||||
CFStringRef reasonForActivity = CFSTR("Synergy application");
|
||||
IOReturn result = IOPMAssertionCreateWithName(kIOPMAssertPreventUserIdleDisplaySleep,
|
||||
kIOPMAssertionLevelOn, reasonForActivity,
|
||||
&m_sleepPreventionAssertionID);
|
||||
if (result != kIOReturnSuccess) {
|
||||
m_sleepPreventionAssertionID = 0;
|
||||
LOG((CLOG_ERR "failed to disable system idle sleep"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OSXPowerManager::enableSleep()
|
||||
{
|
||||
if (m_sleepPreventionAssertionID) {
|
||||
IOPMAssertionRelease(m_sleepPreventionAssertionID);
|
||||
}
|
||||
}
|
||||
48
src/lib/platform/OSXPowerManager.h
Normal file
48
src/lib/platform/OSXPowerManager.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2012-2021 Symless Ltd.
|
||||
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
||||
*
|
||||
* This package is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* found in the file LICENSE that should have accompanied this file.
|
||||
*
|
||||
* This package 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef OSXPOWERMANAGER_H
|
||||
#define OSXPOWERMANAGER_H
|
||||
|
||||
#include <IOKit/pwr_mgt/IOPMLib.h>
|
||||
|
||||
class OSXPowerManager
|
||||
{
|
||||
public:
|
||||
OSXPowerManager();
|
||||
~OSXPowerManager();
|
||||
|
||||
/**
|
||||
* @brief Prevents the system from sleep automatically
|
||||
*/
|
||||
void disableSleep();
|
||||
|
||||
/**
|
||||
* @brief Enable automatically sleeping
|
||||
*/
|
||||
void enableSleep();
|
||||
|
||||
OSXPowerManager(const OSXPowerManager&) = delete;
|
||||
OSXPowerManager& operator=(const OSXPowerManager&) = delete;
|
||||
|
||||
private:
|
||||
// handler for assertion preventing the system from going to sleep
|
||||
IOPMAssertionID m_sleepPreventionAssertionID = 0;
|
||||
};
|
||||
|
||||
#endif // OSXPOWERMANAGER_H
|
||||
|
|
@ -19,6 +19,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "platform/OSXClipboard.h"
|
||||
#include "platform/OSXPowerManager.h"
|
||||
#include "synergy/PlatformScreen.h"
|
||||
#include "synergy/DragInformation.h"
|
||||
#include "base/EventTypes.h"
|
||||
|
|
@ -30,7 +31,6 @@
|
|||
#include <mach/mach_port.h>
|
||||
#include <mach/mach_interface.h>
|
||||
#include <mach/mach_init.h>
|
||||
#include <IOKit/pwr_mgt/IOPMLib.h>
|
||||
#include <IOKit/IOMessage.h>
|
||||
|
||||
extern "C" {
|
||||
|
|
@ -347,8 +347,7 @@ private:
|
|||
CondVar<bool>* m_carbonLoopReady;
|
||||
#endif
|
||||
|
||||
// handler for assertion preventing the system from going to sleep
|
||||
IOPMAssertionID m_sleepPreventionAssertionID = 0;
|
||||
OSXPowerManager m_powerManager;
|
||||
|
||||
class OSXScreenImpl* m_impl;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -119,7 +119,11 @@ OSXScreen::OSXScreen(IEventQueue* events, bool isPrimary, bool autoShowHideCurso
|
|||
try {
|
||||
m_screensaver = new OSXScreenSaver(m_events, getEventTarget());
|
||||
m_keyState = new OSXKeyState(m_events);
|
||||
|
||||
|
||||
if (App::instance().argsBase().m_preventSleep) {
|
||||
m_powerManager.disableSleep();
|
||||
}
|
||||
|
||||
// only needed when running as a server.
|
||||
if (m_isPrimary) {
|
||||
|
||||
|
|
@ -175,7 +179,7 @@ OSXScreen::OSXScreen(IEventQueue* events, bool isPrimary, bool autoShowHideCurso
|
|||
if (m_switchEventHandlerRef != 0) {
|
||||
RemoveEventHandler(m_switchEventHandlerRef);
|
||||
}
|
||||
|
||||
|
||||
CGDisplayRemoveReconfigurationCallback(displayReconfigurationCallback, this);
|
||||
|
||||
delete m_keyState;
|
||||
|
|
@ -195,6 +199,7 @@ OSXScreen::OSXScreen(IEventQueue* events, bool isPrimary, bool autoShowHideCurso
|
|||
OSXScreen::~OSXScreen()
|
||||
{
|
||||
disable();
|
||||
|
||||
m_events->adoptBuffer(NULL);
|
||||
m_events->removeHandler(Event::kSystem, m_events->getSystemTarget());
|
||||
|
||||
|
|
@ -754,18 +759,6 @@ OSXScreen::hideCursor()
|
|||
void
|
||||
OSXScreen::enable()
|
||||
{
|
||||
if(App::instance().argsBase().m_preventSleep) {
|
||||
CFStringRef reasonForActivity = CFSTR("Synergy application");
|
||||
|
||||
IOReturn result = IOPMAssertionCreateWithName(kIOPMAssertPreventUserIdleDisplaySleep,
|
||||
kIOPMAssertionLevelOn, reasonForActivity,
|
||||
&m_sleepPreventionAssertionID);
|
||||
if(result != kIOReturnSuccess) {
|
||||
m_sleepPreventionAssertionID = 0;
|
||||
LOG((CLOG_ERR "failed to disable system idle sleep"));
|
||||
}
|
||||
}
|
||||
|
||||
// watch the clipboard
|
||||
m_clipboardTimer = m_events->newTimer(1.0, NULL);
|
||||
m_events->adoptHandler(Event::kTimer, m_clipboardTimer,
|
||||
|
|
@ -815,10 +808,6 @@ OSXScreen::enable()
|
|||
void
|
||||
OSXScreen::disable()
|
||||
{
|
||||
if(App::instance().argsBase().m_preventSleep && m_sleepPreventionAssertionID) {
|
||||
IOPMAssertionRelease(m_sleepPreventionAssertionID);
|
||||
}
|
||||
|
||||
if (m_autoShowHideCursor) {
|
||||
showCursor();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue