xref: /haiku/src/bin/dpms.cpp (revision 8195a5a835117ab2da405e0d477153570b75d921)
1 /*
2  * dpms CLI tool
3  * (c) François Revol, revol@free.fr
4  */
5 
6 #include <stdio.h>
7 #include <Application.h>
8 #include <Accelerant.h>
9 #include <Screen.h>
10 
11 int usage(char *prog)
12 {
13 	printf("%s on|standby|suspend|off|caps|state\n", prog);
14 	printf("on|standby|suspend|off\tsets corresponding state\n");
15 	printf("caps\tprints capabilities\n");
16 	printf("state\tprints the current state\n");
17 	return 1;
18 }
19 
20 int main(int argc, char **argv)
21 {
22 	BApplication app("application/x-vnd.mmu_man.dpms");
23 	BScreen bs;
24 	if (argc < 2)
25 		return usage(argv[0]);
26 	if (!strcmp(argv[1], "on"))
27 		bs.SetDPMS(B_DPMS_ON);
28 	else if (!strcmp(argv[1], "standby"))
29 		bs.SetDPMS(B_DPMS_STAND_BY);
30 	else if (!strcmp(argv[1], "suspend"))
31 		bs.SetDPMS(B_DPMS_SUSPEND);
32 	else if (!strcmp(argv[1], "off"))
33 		bs.SetDPMS(B_DPMS_OFF);
34 	else if (!strcmp(argv[1], "caps")) {
35 		uint32 caps = bs.DPMSCapabilites(); // nice typo...
36 		printf("dpms capabilities: %s%s%s%s\n", (caps & B_DPMS_ON)?("on"):(""),
37 							(caps & B_DPMS_STAND_BY)?(", standby"):(""),
38 							(caps & B_DPMS_SUSPEND)?(", suspend"):(""),
39 							(caps & B_DPMS_OFF)?(", off"):(""));
40 	} else if (!strcmp(argv[1], "state")) {
41 		uint32 st = bs.DPMSState();
42 		printf("%s\n", (st & B_DPMS_ON)?("on"):
43 				((st & B_DPMS_STAND_BY)?("standby"):
44 				 ((st & B_DPMS_SUSPEND)?("suspend"):
45 				  ((st & B_DPMS_OFF)?("off"):("?")))));
46 	} else
47 		return usage(argv[0]);
48 	return 0;
49 }
50