-
Notifications
You must be signed in to change notification settings - Fork 0
/
redeyes.c
57 lines (46 loc) · 1.03 KB
/
redeyes.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* Tiny command line util to prevent your Mac from sleeping/screen saving.
* Use however you like.
*/
#include <stdio.h>
#include <IOKit/pwr_mgt/IOPMLib.h>
static IOPMAssertionID assertion_id = 0;
static int sleeping = 0;
int disable_screen_sleep()
{
if (sleeping)
return 0;
IOReturn res;
res = IOPMAssertionCreateWithName(
kIOPMAssertPreventUserIdleDisplaySleep,
kIOPMAssertionLevelOn,
CFSTR("red eyes are beautiful"),
&assertion_id);
sleeping = res == kIOReturnSuccess;
return sleeping;
}
int enable_screen_sleep()
{
if (!sleeping)
return 0;
IOReturn res;
res = IOPMAssertionRelease(assertion_id);
sleeping = !(res == kIOReturnSuccess);
return !sleeping;
}
void sigint_handler()
{
enable_screen_sleep();
printf("red eyes\n");
_exit(0);
}
int main()
{
setbuf(stdout, NULL);
signal(SIGINT, sigint_handler);
if (disable_screen_sleep())
{
printf("no sleep till... ");
for (;;) sleep(60000);
}
return 0;
}