-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmode.cpp
More file actions
158 lines (136 loc) · 4.05 KB
/
mode.cpp
File metadata and controls
158 lines (136 loc) · 4.05 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <iostream>
#include <fstream>
#include "mode.h"
#include "monitor_setup.h"
#include "edid.h"
namespace schrandr {
Mode::Mode()
{}
void Mode::add_screen(Screen s)
{
screens_.push_back(s);
}
std::vector<Screen> Mode::get_screens() const
{
return screens_;
}
int Mode::eraseCrtc(const xcb_randr_crtc_t &crtc)
{
int deleted = 0;
for (auto screen : screens_) {
deleted += screen.eraseCrtc(crtc);
}
return deleted;
}
Output Mode::getOutputByEdid(const Edid &edid) const
{
for (const auto &screen : screens_) {
for (const auto &crtc : screen.get_crtcs()) {
for (const auto &output : crtc.outputs) {
if (output.edid == edid) {
return output;
}
}
}
}
Output empty;
return empty;
}
std::vector<Output> Mode::getActiveOutputs() const
{
std::vector<Output> res;
for (const auto &screen : screens_) {
for (const auto &crtc : screen.get_crtcs()) {
for (const auto &output : crtc.outputs) {
res.push_back(output);
}
}
}
return res;
}
std::ostream& operator<<(std::ostream &out, const Output &op)
{
out << "\t\tOutput: " << op.output << "\n\t\tEDID: "
<< op.edid.to_string() << "\n\t\tName: " << op.name << "\n";
return out;
}
CRTC Mode::getCrtcByOutput(const xcb_randr_output_t &output) const
{
for (const auto &screen : screens_) {
for (const auto &crtc : screen.get_crtcs()) {
for (const auto &op : crtc.outputs) {
std::cout << "Output: " << op.output << std::endl;
if (op.output == output) {
return crtc;
}
}
}
}
CRTC empty;
return empty;
}
bool CRTC::hasSameEdids(const CRTC &crtc) const
{
std::vector<Edid> self, other;
for (const auto &op : outputs) {
self.push_back(op.edid);
}
for (const auto &op : crtc.outputs) {
other.push_back(op.edid);
}
std::sort(self.begin(), self.end());
std::sort(other.begin(), other.end());
return self == other;
}
bool CRTC::isEmpty() const
{
return outputs.empty();
}
std::ostream& operator<<(std::ostream &out, const CRTC &crtc)
{
out << "CRTC " << crtc.crtc << "\n\tX|Y: " << crtc.x << "|" << crtc.y
<< "\n\tMode: " << crtc.mode << "\n\tOutputs:\n";
for (const auto &op : crtc.outputs) {
out << op;
}
return out;
}
int Screen::eraseCrtc(const xcb_randr_crtc_t &crtc)
{
int preSize = crtcs_.size();
crtcs_.erase(std::remove_if(crtcs_.begin(), crtcs_.end(),
[&crtc](CRTC i) { return (i.crtc == crtc); }), crtcs_.end());
return preSize - crtcs_.size();
}
void Screen::add_crtc(CRTC c)
{
crtcs_.push_back(c);
}
std::vector<CRTC> Screen::get_crtcs()const
{
return crtcs_;
}
bool Screen::operator==(const Screen &lhs)
{
return std::tie(width, height, width_mm, height_mm)
== std::tie(lhs.width, lhs.height, lhs.width_mm, lhs.height_mm);
}
bool Screen::operator!=(const Screen &lhs)
{
return !operator==(lhs);
}
MonitorSetup Mode::get_monitor_setup() const
{
MonitorSetup res;
for (const auto &screen : screens_) {
for (const auto &crtc : screen.get_crtcs()) {
for (const auto &output : crtc.outputs) {
if (!output.edid.to_string().empty()) {
res.add_edid(output.edid);
}
}
}
}
return res;
}
}