-
Notifications
You must be signed in to change notification settings - Fork 2
/
ddcutilController.cpp
228 lines (174 loc) · 8.43 KB
/
ddcutilController.cpp
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#include "ddcutilController.h"
DDCutilController::DDCutilController()
{
QList<DDCA_Display_Handle> m_displayHandleList = QList<DDCA_Display_Handle>();
QList<DDCA_Display_Info> m_displayInfoList = QList<DDCA_Display_Info>();
//QList<DDCA_Capabilities> m_parsedCapabilities_perDisp = QList<DDCA_Capabilities>();
QList<QMap<QString, int>*> m_descrToVcp_perDisp = QList<QMap<QString, int>*>();
QList<QMap<int, QMap<int, QString>*>*> m_vcpTovcpValueWithDescr_perDisp =
QList<QMap<int, QMap<int, QString>*>*>();
}
void DDCutilController::detect(){
DDCA_Status rc;
DDCA_Display_Identifier did;
DDCA_Display_Ref dref;
DDCA_Display_Handle dh = NULL; // initialize to avoid clang analyzer warning
qDebug()<<"\nCheck for monitors using ddca_get_displays()...\n";
// Inquire about detected monitors.
DDCA_Display_Info_List * dlist;
ddca_get_display_info_list2(false, &dlist);
qDebug()<<"ddca_get_displays() returned "<< dlist;
qDebug()<<dlist->ct << "display(s) were detected";
for(int iDisp=0;iDisp<dlist->ct;iDisp++)
{
qDebug()<<"\nCreate a Display Identifier for display"<<iDisp <<
" : "<< dlist->info[iDisp].model_name;
m_displayInfoList.append(dlist->info[iDisp]);
rc = ddca_create_dispno_display_identifier(iDisp+1, &did); // ddcutil uses 1 paded indexing for displays
char * did_repr = ddca_did_repr(did);
qDebug()<<"did="<<did_repr;
qDebug()<<"Create a display reference from the display identifier...";
rc = ddca_create_display_ref(did, &dref);
if (rc != 0) {
qDebug()<<"ddca_create_display_ref() returned "<<
rc<< " ("<<ddca_rc_name(rc) <<
"): "<< ddca_rc_desc(rc);
}
else {
char * dref_repr = ddca_did_repr(dref);
qDebug()<<"dref= " << dref_repr;
qDebug()<<"Open the display reference, creating a display handle...";
rc = ddca_open_display(dref, &dh);
if (rc != 0) {
qDebug()<<"ddca_open_display"<< rc;
}
else {
qDebug()<<"adding handle to list";
m_displayHandleList.append(dh);
qDebug()<<"handles nb: "<<m_displayHandleList.count();
char* capabilityString;
DDCA_Capabilities* parsedCapabilities;
ddca_get_capabilities_string(dh, &capabilityString);
ddca_parse_capabilities_string(capabilityString, &parsedCapabilities);
qDebug()<<parsedCapabilities->vcp_code_ct << "capabilities have been parsed";
m_descrToVcp_perDisp.append(new QMap<QString, int>);
m_vcpTovcpValueWithDescr_perDisp.append(new QMap<int, QMap<int, QString>*>);
//fill the feature description to vcp LUT
DDCA_Version_Feature_Info* featureInfo;
for(int iVcp=0;iVcp<parsedCapabilities->vcp_code_ct;iVcp++)
{
int vcpCode=parsedCapabilities->vcp_codes[iVcp].feature_code;
m_vcpTovcpValueWithDescr_perDisp.at(iDisp)->insert(vcpCode, new QMap<int, QString>);
m_descrToVcp_perDisp.at(iDisp)->insert(
QString(ddca_get_feature_name(vcpCode)), vcpCode);
ddca_get_feature_info_by_display(m_displayHandleList.at(iDisp), vcpCode, &featureInfo);
if(featureInfo != NULL)
{
qDebug()<<featureInfo->feature_code<<":"<<featureInfo->desc<<featureInfo->feature_flags;
if(featureInfo->feature_flags & (DDCA_SIMPLE_NC | DDCA_COMPLEX_NC))
{
if (!featureInfo->sl_values)
continue;
for(int iVcpVal=0;featureInfo->sl_values[iVcpVal].value_code!=0;++iVcpVal)
{
qDebug()<<"\t"<<featureInfo->sl_values[iVcpVal].value_code
<<":"<< featureInfo->sl_values[iVcpVal].value_name;
bool thisVcpValIsSupported=false;
for(int iSupportedVcpVal=0; iSupportedVcpVal<parsedCapabilities->vcp_codes[iVcp].value_ct; iSupportedVcpVal++)
{
if(parsedCapabilities->vcp_codes[iVcp].values[iSupportedVcpVal]
==featureInfo->sl_values[iVcpVal].value_code)
{
thisVcpValIsSupported=true;
}
}
if(thisVcpValIsSupported)
{
m_vcpTovcpValueWithDescr_perDisp.at(iDisp)->value(vcpCode)->insert(
featureInfo->sl_values[iVcpVal].value_code,
featureInfo->sl_values[iVcpVal].value_name);
qDebug()<<"ADDED !";
}
}
}
}
}
qDebug()<<"done";
//is this needed ? are variables created in the method automatically free'd ?
ddca_free_parsed_capabilities(parsedCapabilities);
}
}
ddca_free_display_ref(&dref);
ddca_free_display_identifier(&did);
}
qDebug()<<"done with display";
}
unsigned int DDCutilController::monitorNumber() const
{
return m_displayHandleList.count();
}
//bool DDCutilController::isSupported() const
//{
// // if (!m_resources) {
// // return false;
// // }
// // auto *outputs = xcb_randr_get_screen_resources_current_outputs(m_resources.data());
// // for (int i = 0; i < m_resources->num_outputs; ++i) {
// // if (backlight_get(outputs[i]) != -1) {
// // return true;
// // }
// // }
// // return false;
//}
long DDCutilController::brightness(const unsigned int dispIdx) const
{
//FIXME: gets value for display 1
DDCA_Any_Vcp_Value *returnValue;
DDCA_Status rc;
rc = ddca_get_any_vcp_value_using_explicit_type(m_displayHandleList.at(dispIdx),
m_descrToVcp_perDisp.at(dispIdx)->value("Brightness"),
DDCA_NON_TABLE_VCP_VALUE, &returnValue);
if (rc != 0)
return 0;
return (long)VALREC_CUR_VAL(returnValue);
}
long DDCutilController::brightnessMax(const unsigned int dispIdx) const
{
DDCA_Any_Vcp_Value *returnValue;
DDCA_Status rc;
rc = ddca_get_any_vcp_value_using_explicit_type(m_displayHandleList.at(dispIdx),
m_descrToVcp_perDisp.at(dispIdx)->value("Brightness"),
DDCA_NON_TABLE_VCP_VALUE, &returnValue);
if (rc != 0)
return 0;
return (long)VALREC_MAX_VAL(returnValue);
}
QList<QString> DDCutilController::whitePointList(const unsigned int dispIdx) const
{
return m_vcpTovcpValueWithDescr_perDisp.at(dispIdx)
->value( m_descrToVcp_perDisp.at(dispIdx)->value("Select color preset") )
->values();
}
void DDCutilController::setBrightness(const unsigned int dispIdx, long value)
{
int rc;
rc = ddca_set_continuous_vcp_value(m_displayHandleList.at(dispIdx),
m_descrToVcp_perDisp.at(dispIdx)->value("Brightness"),
(int)value);
qDebug()<<"set brightness returned: "<<rc;
}
QString DDCutilController::nameForDisplay(const unsigned int dispIdx)
{
return QString(m_displayInfoList.at(dispIdx).model_name);
}
void DDCutilController::setWhitepoint(const unsigned int dispIdx, const QString &newWhitepoint)
{
int rc;
qDebug()<<"trying to set new whitepoint:" << newWhitepoint;
rc = ddca_set_continuous_vcp_value(m_displayHandleList.at(dispIdx),
m_descrToVcp_perDisp.at(dispIdx)->value("Select color preset"),
m_vcpTovcpValueWithDescr_perDisp.at(dispIdx)
->value(m_descrToVcp_perDisp.at(dispIdx)
->value("Select color preset"))->key(newWhitepoint));
qDebug()<<"set whitepoint returned: "<<rc;
}