diff --git a/src/lib/platform/MSWindowsPowerManager.cpp b/src/lib/platform/MSWindowsPowerManager.cpp
new file mode 100644
index 000000000..4d0b24eab
--- /dev/null
+++ b/src/lib/platform/MSWindowsPowerManager.cpp
@@ -0,0 +1,37 @@
+/*
+ * 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 .
+ */
+#include "MSWindowsPowerManager.h"
+#include "arch/win32/ArchMiscWindows.h"
+
+MSWindowsPowerManager::~MSWindowsPowerManager()
+{
+ enableSleep();
+}
+
+void MSWindowsPowerManager::disableSleep()
+{
+ ArchMiscWindows::addBusyState(ArchMiscWindows::kSYSTEM);
+ ArchMiscWindows::addBusyState(ArchMiscWindows::kDISPLAY);
+}
+
+void MSWindowsPowerManager::enableSleep()
+{
+ // allow the system to enter power saving mode
+ ArchMiscWindows::removeBusyState(ArchMiscWindows::kSYSTEM);
+ ArchMiscWindows::removeBusyState(ArchMiscWindows::kDISPLAY);
+}
diff --git a/src/lib/platform/MSWindowsPowerManager.h b/src/lib/platform/MSWindowsPowerManager.h
new file mode 100644
index 000000000..42eaa9ede
--- /dev/null
+++ b/src/lib/platform/MSWindowsPowerManager.h
@@ -0,0 +1,38 @@
+/*
+ * 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 .
+ */
+#ifndef MSWINDOWSPOWERMANAGER_H
+#define MSWINDOWSPOWERMANAGER_H
+
+
+class MSWindowsPowerManager
+{
+public:
+ ~MSWindowsPowerManager();
+
+ /**
+ * @brief Prevents the system from sleep automatically
+ */
+ void disableSleep();
+
+ /**
+ * @brief Enable automatically sleeping
+ */
+ void enableSleep();
+};
+
+#endif // MSWINDOWSPOWERMANAGER_H
diff --git a/src/lib/platform/MSWindowsScreen.cpp b/src/lib/platform/MSWindowsScreen.cpp
index ac1ca8be3..f630c65d5 100644
--- a/src/lib/platform/MSWindowsScreen.cpp
+++ b/src/lib/platform/MSWindowsScreen.cpp
@@ -164,6 +164,10 @@ MSWindowsScreen::MSWindowsScreen(
LOG((CLOG_ERR "failed to get desktop path, no drop target available, error=%d", GetLastError()));
}
+ if (App::instance().argsBase().m_preventSleep) {
+ m_powerManager.disableSleep();
+ }
+
OleInitialize(0);
m_dropWindow = createDropWindow(m_class, "DropWindow");
m_dropTarget = new MSWindowsDropTarget();
@@ -248,11 +252,6 @@ MSWindowsScreen::enable()
// watch jump zones
m_hook.setMode(kHOOK_WATCH_JUMP_ZONE);
}
-
- if (App::instance().argsBase().m_preventSleep) {
- ArchMiscWindows::addBusyState(ArchMiscWindows::kSYSTEM);
- ArchMiscWindows::addBusyState(ArchMiscWindows::kDISPLAY);
- }
}
void
@@ -268,11 +267,6 @@ MSWindowsScreen::disable()
// enable special key sequences on win95 family
enableSpecialKeys(true);
}
- else {
- // allow the system to enter power saving mode
- ArchMiscWindows::removeBusyState(ArchMiscWindows::kSYSTEM);
- ArchMiscWindows::removeBusyState(ArchMiscWindows::kDISPLAY);
- }
// tell key state
m_keyState->disable();
@@ -2086,4 +2080,4 @@ MSWindowsScreen::updateScrollDirection()
});
scrollDirectionUpdateThread.detach();
}
-}
\ No newline at end of file
+}
diff --git a/src/lib/platform/MSWindowsScreen.h b/src/lib/platform/MSWindowsScreen.h
index d72889cfa..dbab41285 100644
--- a/src/lib/platform/MSWindowsScreen.h
+++ b/src/lib/platform/MSWindowsScreen.h
@@ -19,6 +19,7 @@
#pragma once
#include "platform/MSWindowsHook.h"
+#include "platform/MSWindowsPowerManager.h"
#include "synergy/PlatformScreen.h"
#include "synergy/DragInformation.h"
#include "platform/synwinhk.h"
@@ -374,4 +375,5 @@ private:
// -1 for natural scrolling direction, 1 otherwise
SInt32 m_scrollDirectionMouse = 1;
SInt32 m_scrollDirectionTouchpad = 1;
+ MSWindowsPowerManager m_powerManager;
};