1 #include <stdio.h>
2 #include <unistd.h>
3 #include <algorithm>
5 #include <kms++/kms++.h>
6 #include <kms++util/kms++util.h>
8 using namespace std;
9 using namespace kms;
11 static const char* usage_str =
12 "Usage: kmsblank [OPTION]...\n\n"
13 "Blank screen(s)\n\n"
14 "Options:\n"
15 " --device=DEVICE DEVICE is the path to DRM card to open\n"
16 " -c, --connector=CONN CONN is <connector>\n"
17 " -t, --time=TIME blank/unblank in TIME intervals\n"
18 "\n"
19 "<connector> can be given by index (<idx>) or id (@<id>).\n"
20 "<connector> can also be given by name.\n"
21 ;
23 static void usage()
24 {
25 puts(usage_str);
26 }
28 int main(int argc, char **argv)
29 {
30 string dev_path = "/dev/dri/card0";
32 vector<string> conn_strs;
33 uint32_t time = 0;
35 OptionSet optionset = {
36 Option("|device=", [&dev_path](string s)
37 {
38 dev_path = s;
39 }),
40 Option("c|connector=", [&conn_strs](string str)
41 {
42 conn_strs.push_back(str);
43 }),
44 Option("t|time=", [&time](string str)
45 {
46 time = stoul(str);
47 }),
48 Option("h|help", []()
49 {
50 usage();
51 exit(-1);
52 }),
53 };
55 optionset.parse(argc, argv);
57 if (optionset.params().size() > 0) {
58 usage();
59 exit(-1);
60 }
62 Card card(dev_path);
64 vector<Connector*> conns;
66 if (conn_strs.size() > 0) {
67 for (string s : conn_strs) {
68 auto c = resolve_connector(card, s);
69 if (!c)
70 EXIT("Failed to resolve connector '%s'", s.c_str());
71 conns.push_back(c);
72 }
73 } else {
74 conns = card.get_connectors();
75 }
77 bool blank = true;
79 while (true) {
80 for (Connector* conn : conns) {
81 if (!conn->connected()) {
82 printf("Connector %u not connected\n", conn->idx());
83 continue;
84 }
86 printf("Connector %u: %sblank\n", conn->idx(), blank ? "" : "un");
87 int r = conn->set_prop_value("DPMS", blank ? 3 : 0);
88 if (r)
89 EXIT("Failed to set DPMS: %d", r);
90 }
92 if (time == 0)
93 break;
95 usleep(1000 * time);
97 blank = !blank;
98 }
100 printf("press enter to exit\n");
102 getchar();
103 }