aboutsummaryrefslogtreecommitdiffstats
blob: 0b51810ad35adda489254ba0cace2bb1f25e44ff (plain) (blame)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <stdio.h>
#include <unistd.h>
#include <algorithm>

#include <kms++/kms++.h>
#include <kms++util/kms++util.h>

using namespace std;
using namespace kms;

static const char* usage_str =
		"Usage: kmsblank [OPTION]...\n\n"
		"Blank screen(s)\n\n"
		"Options:\n"
		"      --device=DEVICE       DEVICE is the path to DRM card to open\n"
		"  -c, --connector=CONN      CONN is <connector>\n"
		"  -t, --time=TIME           blank/unblank in TIME intervals\n"
		"\n"
		"<connector> can be given by index (<idx>) or id (@<id>).\n"
		"<connector> can also be given by name.\n"
		;

static void usage()
{
	puts(usage_str);
}

int main(int argc, char **argv)
{
	string dev_path = "/dev/dri/card0";

	vector<string> conn_strs;
	uint32_t time = 0;

	OptionSet optionset = {
		Option("|device=", [&dev_path](string s)
		{
			dev_path = s;
		}),
		Option("c|connector=", [&conn_strs](string str)
		{
			conn_strs.push_back(str);
		}),
		Option("t|time=", [&time](string str)
		{
			time = stoul(str);
		}),
		Option("h|help", []()
		{
			usage();
			exit(-1);
		}),
	};

	optionset.parse(argc, argv);

	if (optionset.params().size() > 0) {
		usage();
		exit(-1);
	}

	Card card(dev_path);
	ResourceManager resman(card);

	vector<Connector*> conns;

	if (conn_strs.size() > 0) {
		for (string s : conn_strs) {
			auto c = resman.reserve_connector(s);
			if (!c)
				EXIT("Failed to resolve connector '%s'", s.c_str());
			conns.push_back(c);
		}
	} else {
		conns = card.get_connectors();
	}

	bool blank = true;

	while (true) {
		for (Connector* conn : conns) {
			if (!conn->connected()) {
				printf("Connector %u not connected\n", conn->idx());
				continue;
			}

			printf("Connector %u: %sblank\n", conn->idx(), blank ? "" : "un");
			int r = conn->set_prop_value("DPMS", blank ? 3 : 0);
			if (r)
				EXIT("Failed to set DPMS: %d", r);
		}

		if (time == 0)
			break;

		usleep(1000 * time);

		blank = !blank;
	}

	printf("press enter to exit\n");

	getchar();
}