Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SYNERGY-856 - Force prevent sleep #7047

Merged
merged 20 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b367746
[UB-856] - Set display as busy
igor-sikachyna Jun 29, 2021
3677db8
Merge remote-tracking branch 'origin' into SYNERGY-856-force-prevent-…
igor-sikachyna Jul 1, 2021
d65fa7a
SYNERGY-856 - Prevent sleep on Mac
igor-sikachyna Jul 1, 2021
9e9864e
SYNERGY-856 - Prevent sleep on Linux
igor-sikachyna Jul 1, 2021
0d20cd9
SYNERGY-856 - Update changelog
igor-sikachyna Jul 1, 2021
675b861
SYNERGY-856 - Set user activity on for Mac to prevent sleep
igor-sikachyna Jul 2, 2021
cae748b
Merge remote-tracking branch 'origin' into SYNERGY-856-force-prevent-…
igor-sikachyna Jul 2, 2021
b8ac5a1
SYNERGY-856 - Prevent screen sleep continuosly
igor-sikachyna Jul 2, 2021
1bc161f
SYNERGY-856 - Try implementing DBus in the server/client
igor-sikachyna Jul 6, 2021
4fd0158
SYNERGY-856 - Move inhibitor to arch instead of gui
igor-sikachyna Jul 6, 2021
ef1973c
Merge branch 'SYNERGY-856-force-prevent-sleep' of github.com:symless/…
igor-sikachyna Jul 6, 2021
6f1f763
Merge remote-tracking branch 'origin' into SYNERGY-856-force-prevent-…
igor-sikachyna Jul 6, 2021
c6f46da
SYNERGY-856 - Undo undesired changes
igor-sikachyna Jul 6, 2021
73f1745
SYNERGY-856 - Undo remaining undersired changes
igor-sikachyna Jul 6, 2021
0eff3ad
SYNERGY-856 - Compile on MacOS
igor-sikachyna Jul 6, 2021
384394f
SYNERGY-856 - Reduce if/else depth
igor-sikachyna Jul 6, 2021
d81b62d
SYNERGY-856 - Remove AppDelegate include
igor-sikachyna Jul 7, 2021
85cae8d
SYNERGY-856 - Update inhibitor code to have more verbose debug output
igor-sikachyna Jul 8, 2021
b2876c6
SYNERGY-856 - Make methods static
igor-sikachyna Jul 8, 2021
5bd1e84
SYNERGY-856 - Remove unused declarations
igor-sikachyna Jul 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Bug fixes:
- #7015 Fix Windows service not starting up after sleep
- #7036 Fix tray icon not changing theme on Big Sur
- #7046 Fix MacOS 10.13 build
- #7047 Fix prevent sleep option on Mac and Windows

Enhancements:
- #6998 Remove functionality related to the screen saver synchronisation
Expand All @@ -19,6 +20,7 @@ Enhancements:
- #7030 | #7041 | #7043 Add user notification for secure input on Mac
- #7044 Apply natural scroll setting independently on each client
- #7040 Support "Kana" and "Eisu" keys on Japanese Apple Pro Keyboard (JIS)
- #7047 Add prevent sleep option support to Linux
===========

v1.14.0-stable
Expand Down
5 changes: 5 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ include_directories (./src)
target_link_libraries (synergy shared)

qt5_use_modules (synergy Core Widgets Network)
if (UNIX AND NOT APPLE)
find_package (Qt5 COMPONENTS DBus)
qt5_use_modules (synergy DBus)
endif()

target_compile_definitions (synergy PRIVATE -DSYNERGY_VERSION_STAGE="${SYNERGY_VERSION_STAGE}")
target_compile_definitions (synergy PRIVATE -DSYNERGY_REVISION="${SYNERGY_REVISION}")

Expand Down
63 changes: 62 additions & 1 deletion src/gui/src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
#include "Zeroconf.h"
#include <QPushButton>

#if defined(Q_OS_LINUX)
#include <QtDBus/QtDBus>
#endif

igor-sikachyna marked this conversation as resolved.
Show resolved Hide resolved
#if defined(Q_OS_MAC)
#include "OSXHelpers.h"
#endif
Expand Down Expand Up @@ -661,7 +665,6 @@ void MainWindow::startSynergy()

args << "-f" << "--no-tray" << "--debug" << appConfig().logLevelText();


args << "--name" << appConfig().screenName();

if (desktopMode)
Expand Down Expand Up @@ -718,6 +721,9 @@ void MainWindow::startSynergy()
if (m_AppConfig->getPreventSleep())
{
args << "--prevent-sleep";
#ifdef Q_OS_LINUX
setSleepPreventionState(true);
#endif
igor-sikachyna marked this conversation as resolved.
Show resolved Hide resolved
}

// put a space between last log output and new instance.
Expand Down Expand Up @@ -988,6 +994,10 @@ void MainWindow::stopSynergy()
stopDesktop();
}

#ifdef Q_OS_LINUX
setSleepPreventionState(false);
#endif

setSynergyState(synergyDisconnected);

// reset so that new connects cause auto-hide.
Expand Down Expand Up @@ -1504,3 +1514,54 @@ void MainWindow::on_m_pButtonConnect_clicked()
on_m_pButtonApply_clicked();
}

#ifdef Q_OS_LINUX
void
MainWindow::setSleepPreventionState(bool state)
{
static const std::array<QString, 2> services =
{
"org.freedesktop.ScreenSaver",
"org.gnome.SessionManager"
};
static const std::array<QString, 2> paths =
{
"/org/freedesktop/ScreenSaver",
"/org/gnome/SessionManager"
};

static std::array<uint, 2> cookies;

QDBusConnection bus = QDBusConnection::sessionBus();
if(bus.isConnected())
{
for(int i = 0; i < services.size() ; i++)
{
QDBusInterface screenSaverInterface( services[i], paths[i],services[i], bus);

if (!screenSaverInterface.isValid())
continue;

QDBusReply<uint> reply;

if(state)
{
reply = screenSaverInterface.call("Inhibit", "nzuri-video Downloader", "REASON");
igor-sikachyna marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
reply = screenSaverInterface.call("UnInhibit", cookies[i]);
}

if (reply.isValid())
{
cookies[i] = reply.value();
}
else
{
QDBusError error =reply.error();
appendLogDebug(error.message() + " : " + error.name());
}
}
}
}
#endif
3 changes: 3 additions & 0 deletions src/gui/src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ public slots:
#ifdef Q_OS_MAC
void checkOSXNotification(const QString& line);
#endif
#ifdef Q_OS_LINUX
void setSleepPreventionState(bool state);
#endif
#ifndef SYNERGY_ENTERPRISE
void checkLicense(const QString& line);
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/lib/platform/MSWindowsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ MSWindowsScreen::enable()

if (App::instance().argsBase().m_preventSleep) {
ArchMiscWindows::addBusyState(ArchMiscWindows::kSYSTEM);
ArchMiscWindows::addBusyState(ArchMiscWindows::kDISPLAY);
}
}

Expand All @@ -270,6 +271,7 @@ MSWindowsScreen::disable()
else {
// allow the system to enter power saving mode
ArchMiscWindows::removeBusyState(ArchMiscWindows::kSYSTEM);
ArchMiscWindows::removeBusyState(ArchMiscWindows::kDISPLAY);
}

// tell key state
Expand Down
6 changes: 4 additions & 2 deletions src/lib/platform/OSXScreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,10 @@
{
if(App::instance().argsBase().m_preventSleep) {
CFStringRef reasonForActivity = CFSTR("Synergy application");
IOReturn result = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep,
kIOPMAssertionLevelOn, reasonForActivity, &m_sleepPreventionAssertionID);

IOReturn result = IOPMAssertionCreateWithName(kIOPMAssertPreventUserIdleDisplaySleep,
kIOPMAssertionLevelOn, reasonForActivity,
&m_sleepPreventionAssertionID);
if(result != kIOReturnSuccess) {
m_sleepPreventionAssertionID = 0;
LOG((CLOG_ERR "failed to disable system idle sleep"));
Expand Down