Simplify screensaver inhibit API and fix OSX compatibility
This commit is contained in:
parent
a3eed5839f
commit
4b5d16554b
@ -23,16 +23,14 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
ARDOUR_UI_UTILS::enable_screensaver ()
|
ARDOUR_UI_UTILS::inhibit_screensaver (bool inhibit)
|
||||||
{
|
{
|
||||||
|
if (inhibit) {
|
||||||
SetThreadExecutionState (ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED | ES_CONTINUOUS);
|
SetThreadExecutionState (ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED | ES_CONTINUOUS);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
void
|
|
||||||
ARDOUR_UI_UTILS::disable_screensaver ()
|
|
||||||
{
|
|
||||||
SetThreadExecutionState (ES_CONTINUOUS);
|
SetThreadExecutionState (ES_CONTINUOUS);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#elif defined __APPLE__
|
#elif defined __APPLE__
|
||||||
|
|
||||||
@ -42,23 +40,26 @@ static IOReturn success = kIOReturnError;
|
|||||||
static IOPMAssertionID assertion_id;
|
static IOPMAssertionID assertion_id;
|
||||||
|
|
||||||
void
|
void
|
||||||
ARDOUR_UI_UTILS::enable_screensaver ()
|
ARDOUR_UI_UTILS::inhibit_screensaver (bool inhibit)
|
||||||
{
|
{
|
||||||
static const CFStringRef name = CFSTR("Ardour DAW");
|
if (inhibit == (success == kIOReturnSuccess)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inhibit) {
|
||||||
/* kIOPMAssertionTypeNoDisplaySleep prevents display sleep,
|
/* kIOPMAssertionTypeNoDisplaySleep prevents display sleep,
|
||||||
* kIOPMAssertionTypeNoIdleSleep prevents idle sleep
|
* kIOPMAssertionTypeNoIdleSleep prevents idle sleep
|
||||||
*/
|
*/
|
||||||
|
#ifdef __ppc__ /* OS X 10.5 compat API */
|
||||||
|
success = IOPMAssertionCreate (kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, &assertion_id);
|
||||||
|
#else
|
||||||
|
static const CFStringRef name = CFSTR("Ardour DAW");
|
||||||
success = IOPMAssertionCreateWithName (kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, name, &assertion_id);
|
success = IOPMAssertionCreateWithName (kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, name, &assertion_id);
|
||||||
}
|
#endif
|
||||||
|
} else {
|
||||||
void
|
|
||||||
ARDOUR_UI_UTILS::disable_screensaver ()
|
|
||||||
{
|
|
||||||
if (success != kIOReturnSuccess) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (kIOReturnSuccess == IOPMAssertionRelease (assertion_id)) {
|
if (kIOReturnSuccess == IOPMAssertionRelease (assertion_id)) {
|
||||||
success = kIOReturnError;
|
success = kIOReturnError; // mark as inactive
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,15 +89,13 @@ xdg_screensaver_reset ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ARDOUR_UI_UTILS::enable_screensaver ()
|
ARDOUR_UI_UTILS::inhibit_screensaver (bool inhibit)
|
||||||
{
|
|
||||||
glib_timer = Glib::signal_timeout().connect_seconds (sigc::ptr_fun (&xdg_screensaver_reset), 45, Glib::PRIORITY_DEFAULT_IDLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ARDOUR_UI_UTILS::disable_screensaver ()
|
|
||||||
{
|
{
|
||||||
glib_timer.disconnect ();
|
glib_timer.disconnect ();
|
||||||
|
if (inhibit) {
|
||||||
|
xdg_screensaver_reset ();
|
||||||
|
glib_timer = Glib::signal_timeout().connect_seconds (sigc::ptr_fun (&xdg_screensaver_reset), 45, Glib::PRIORITY_DEFAULT_IDLE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -107,8 +107,7 @@ bool windows_overlap (Gtk::Window *a, Gtk::Window *b);
|
|||||||
bool overwrite_file_dialog (Gtk::Window& parent, std::string title, std::string text);
|
bool overwrite_file_dialog (Gtk::Window& parent, std::string title, std::string text);
|
||||||
bool running_from_source_tree ();
|
bool running_from_source_tree ();
|
||||||
|
|
||||||
void enable_screensaver ();
|
void inhibit_screensaver (bool);
|
||||||
void disable_screensaver ();
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
#endif /* __ardour_gtk_utils_h__ */
|
#endif /* __ardour_gtk_utils_h__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user