2 * Copyright (C) 2019 Robin Gareus <robin@gareus.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #ifdef PLATFORM_WINDOWS
22 /* http://www.blackwasp.co.uk/DisableScreensaver.aspx */
26 ARDOUR_UI_UTILS::inhibit_screensaver (bool inhibit)
29 SetThreadExecutionState (ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED | ES_CONTINUOUS);
31 SetThreadExecutionState (ES_CONTINUOUS);
35 #elif defined __APPLE__
37 #include <IOKit/pwr_mgt/IOPMLib.h>
39 static IOReturn success = kIOReturnError;
40 static IOPMAssertionID assertion_id;
43 ARDOUR_UI_UTILS::inhibit_screensaver (bool inhibit)
45 if (inhibit == (success == kIOReturnSuccess)) {
50 /* kIOPMAssertionTypeNoDisplaySleep prevents display sleep,
51 * kIOPMAssertionTypeNoIdleSleep prevents idle sleep
53 #ifdef __ppc__ /* OS X 10.5 compat API */
54 success = IOPMAssertionCreate (kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, &assertion_id);
56 static const CFStringRef name = CFSTR("Ardour DAW");
57 success = IOPMAssertionCreateWithName (kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, name, &assertion_id);
60 if (kIOReturnSuccess == IOPMAssertionRelease (assertion_id)) {
61 success = kIOReturnError; // mark as inactive
66 #else /* Linux / X11 */
69 #include "ardour/system_exec.h"
71 static sigc::connection glib_timer;
74 xdg_screensaver_reset ()
76 char** args = (char**) malloc (5 * sizeof(char*));
77 args[0] = strdup ("/bin/sh");
78 args[1] = strdup ("-c");
79 args[2] = strdup ("xdg-screensaver");
80 args[3] = strdup ("reset");
83 ARDOUR::SystemExec xdg_exec ("/bin/sh", args);
84 if (xdg_exec.start ()) {
88 return true; /* keep going */
92 ARDOUR_UI_UTILS::inhibit_screensaver (bool inhibit)
94 glib_timer.disconnect ();
96 xdg_screensaver_reset ();
97 glib_timer = Glib::signal_timeout().connect_seconds (sigc::ptr_fun (&xdg_screensaver_reset), 45, Glib::PRIORITY_DEFAULT_IDLE);