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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
|
/*
* nvidia-settings: A tool for configuring the NVIDIA X driver on Unix
* and Linux systems.
*
* Copyright (C) 2004 NVIDIA Corporation.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of Version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See Version 2
* of the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the:
*
* Free Software Foundation, Inc.
* 59 Temple Place - Suite 330
* Boston, MA 02111-1307, USA
*
*/
#include "NvCtrlAttributes.h"
#include "NvCtrlAttributesPrivate.h"
#include "NVCtrlLib.h"
#include "msg.h"
#include <stdlib.h>
#include <string.h>
/*
* NvCtrlInitNvControlAttributes() - check for the NV-CONTROL
* extension and make sure we have an adequate version. Returns a
* malloced and initialized NvCtrlNvControlAttributes structure if
* successful, or NULL otherwise.
*/
NvCtrlNvControlAttributes *
NvCtrlInitNvControlAttributes (NvCtrlAttributePrivateHandle *h)
{
NvCtrlNvControlAttributes *nv;
int ret, major, minor, event, error;
ret = XNVCTRLQueryExtension (h->dpy, &event, &error);
if (ret != True) {
nv_warning_msg("NV-CONTROL extension not found on this Display.");
return NULL;
}
ret = XNVCTRLQueryVersion (h->dpy, &major, &minor);
if (ret != True) {
nv_error_msg("Failed to query NV-CONTROL extension version.");
return NULL;
}
if (major < NV_MINMAJOR || (major == NV_MINMAJOR && minor < NV_MINMINOR)) {
nv_error_msg("NV-CONTROL extension version %d.%d is too old; "
"the minimimum required version is %d.%d.",
major, minor, NV_MINMAJOR, NV_MINMINOR);
return NULL;
}
if (h->target_type == NV_CTRL_TARGET_TYPE_X_SCREEN) {
ret = XNVCTRLIsNvScreen (h->dpy, h->target_id);
if (ret != True) {
nv_warning_msg("NV-CONTROL extension not present on screen %d "
"of this Display.", h->target_id);
return NULL;
}
}
nv = (NvCtrlNvControlAttributes *)
calloc(1, sizeof (NvCtrlNvControlAttributes));
ret = XNVCtrlSelectTargetNotify(h->dpy, h->target_type, h->target_id,
TARGET_ATTRIBUTE_CHANGED_EVENT, True);
if (ret != True) {
nv_warning_msg("Unable to select attribute changed NV-CONTROL "
"events.");
}
/*
* TARGET_ATTRIBUTE_AVAILABILITY_CHANGED_EVENT was added in NV-CONTROL
* 1.15
*/
if (((major > 1) || ((major == 1) && (minor >= 15)))) {
ret = XNVCtrlSelectTargetNotify(h->dpy, h->target_type, h->target_id,
TARGET_ATTRIBUTE_AVAILABILITY_CHANGED_EVENT,
True);
if (ret != True) {
nv_warning_msg("Unable to select attribute changed NV-CONTROL "
"events.");
}
}
/*
* TARGET_STRING_ATTRIBUTE_CHANGED_EVENT was added in NV-CONTROL
* 1.16
*/
if (((major > 1) || ((major == 1) && (minor >= 16)))) {
ret = XNVCtrlSelectTargetNotify(h->dpy, h->target_type, h->target_id,
TARGET_STRING_ATTRIBUTE_CHANGED_EVENT,
True);
if (ret != True) {
nv_warning_msg("Unable to select attribute changed NV-CONTROL string"
"events.");
}
}
nv->event_base = event;
nv->error_base = error;
nv->major_version = major;
nv->minor_version = minor;
return (nv);
} /* NvCtrlInitNvControlAttributes() */
ReturnStatus NvCtrlNvControlQueryTargetCount(NvCtrlAttributePrivateHandle *h,
int target_type, int *val)
{
int ret;
ret = XNVCTRLQueryTargetCount(h->dpy, target_type, val);
return (ret) ? NvCtrlSuccess : NvCtrlError;
} /* NvCtrlNvControlQueryTargetCount() */
ReturnStatus NvCtrlNvControlGetAttribute (NvCtrlAttributePrivateHandle *h,
unsigned int display_mask,
int attr, int *val)
{
if (attr <= NV_CTRL_LAST_ATTRIBUTE) {
if (XNVCTRLQueryTargetAttribute (h->dpy, h->target_type, h->target_id,
display_mask, attr, val)) {
return NvCtrlSuccess;
} else {
return NvCtrlAttributeNotAvailable;
}
}
if ((attr >= NV_CTRL_ATTR_NV_BASE) &&
(attr <= NV_CTRL_ATTR_NV_LAST_ATTRIBUTE)) {
if (!h->nv) return NvCtrlMissingExtension;
switch (attr) {
case NV_CTRL_ATTR_NV_MAJOR_VERSION:
*val = h->nv->major_version;
return NvCtrlSuccess;
case NV_CTRL_ATTR_NV_MINOR_VERSION:
*val = h->nv->minor_version;
return NvCtrlSuccess;
}
}
return NvCtrlNoAttribute;
} /* NvCtrlNvControlGetAttribute() */
ReturnStatus NvCtrlNvControlSetAttribute (NvCtrlAttributePrivateHandle *h,
unsigned int display_mask,
int attr, int val)
{
if (attr <= NV_CTRL_LAST_ATTRIBUTE) {
XNVCTRLSetTargetAttribute (h->dpy, h->target_type, h->target_id,
display_mask, attr, val);
XFlush (h->dpy);
return NvCtrlSuccess;
}
return NvCtrlNoAttribute;
} /* NvCtrlNvControlSetAttribute() */
ReturnStatus
NvCtrlNvControlSetAttributeWithReply(NvCtrlAttributePrivateHandle *h,
unsigned int display_mask,
int attr, int val)
{
Bool bRet;
/* XNVCTRLSetAttributeAndGetStatus() only works on X screens */
if (h->target_type != NV_CTRL_TARGET_TYPE_X_SCREEN) {
return NvCtrlError;
}
if (attr <= NV_CTRL_LAST_ATTRIBUTE) {
bRet = XNVCTRLSetAttributeAndGetStatus(h->dpy, h->target_id,
display_mask, attr, val);
if (bRet) {
return NvCtrlSuccess;
} else {
return NvCtrlError;
}
}
return NvCtrlNoAttribute;
} /* NvCtrlNvControlSetAttributeWithReply() */
ReturnStatus NvCtrlNvControlGetValidAttributeValues
(NvCtrlAttributePrivateHandle *h,
unsigned int display_mask,
int attr, NVCTRLAttributeValidValuesRec *val)
{
if (attr <= NV_CTRL_LAST_ATTRIBUTE) {
if (XNVCTRLQueryValidTargetAttributeValues (h->dpy, h->target_type,
h->target_id, display_mask,
attr, val)) {
return NvCtrlSuccess;
} else {
return NvCtrlAttributeNotAvailable;
}
}
return NvCtrlNoAttribute;
} /* NvCtrlNvControlGetValidAttributeValues() */
ReturnStatus
NvCtrlNvControlGetStringAttribute (NvCtrlAttributePrivateHandle *h,
unsigned int display_mask,
int attr, char **ptr)
{
/* Validate */
if (!h || !h->dpy) {
return NvCtrlBadHandle;
}
if (attr == NV_CTRL_STRING_NV_CONTROL_VERSION) {
char str[16];
if (h->target_type != NV_CTRL_TARGET_TYPE_X_SCREEN) {
return NvCtrlBadHandle;
}
sprintf(str, "%d.%d", h->nv->major_version, h->nv->minor_version);
*ptr = strdup(str);
return NvCtrlSuccess;
}
if (attr <= NV_CTRL_STRING_LAST_ATTRIBUTE) {
if (XNVCTRLQueryTargetStringAttribute (h->dpy, h->target_type,
h->target_id, display_mask,
attr, ptr)) {
return NvCtrlSuccess;
} else {
return NvCtrlAttributeNotAvailable;
}
}
return NvCtrlNoAttribute;
} /* NvCtrlNvControlGetStringAttribute() */
ReturnStatus
NvCtrlNvControlSetStringAttribute (NvCtrlAttributePrivateHandle *h,
unsigned int display_mask,
int attr, char *ptr, int *ret)
{
int tmp_int; /* Temp storage if ret is not specified */
if (h->target_type != NV_CTRL_TARGET_TYPE_X_SCREEN) {
return NvCtrlBadHandle;
}
if (attr <= NV_CTRL_LAST_ATTRIBUTE) {
if ( !ret ) {
ret = &tmp_int;
}
*ret =
XNVCTRLSetStringAttribute (h->dpy, h->target_id, display_mask,
attr, ptr);
if ( *ret ) {
return NvCtrlSuccess;
} else {
return NvCtrlAttributeNotAvailable;
}
}
return NvCtrlNoAttribute;
} /* NvCtrlNvControlSetStringAttribute() */
ReturnStatus
NvCtrlNvControlGetBinaryAttribute(NvCtrlAttributePrivateHandle *h,
unsigned int display_mask, int attr,
unsigned char **data, int *len)
{
Bool bret;
if (!h->nv) return NvCtrlMissingExtension;
/* the X_nvCtrlQueryBinaryData opcode was added in 1.7 */
if ((h->nv->major_version < 1) ||
((h->nv->major_version == 1) && (h->nv->minor_version < 7))) {
return NvCtrlNoAttribute;
}
bret = XNVCTRLQueryTargetBinaryData (h->dpy, h->target_type, h->target_id,
display_mask, attr, data, len);
if (!bret) {
return NvCtrlError;
} else {
return NvCtrlSuccess;
}
} /* NvCtrlNvControlGetBinaryAttribute() */
ReturnStatus
NvCtrlNvControlStringOperation(NvCtrlAttributePrivateHandle *h,
unsigned int display_mask, int attr,
char *ptrIn, char **ptrOut)
{
if (attr <= NV_CTRL_STRING_OPERATION_LAST_ATTRIBUTE) {
if (XNVCTRLStringOperation (h->dpy, h->target_type,
h->target_id, display_mask,
attr, ptrIn, ptrOut)) {
return NvCtrlSuccess;
} else {
return NvCtrlAttributeNotAvailable;
}
}
return NvCtrlNoAttribute;
} /* NvCtrlNvControlStringOperation() */
ReturnStatus
NvCtrlSetGvoColorConversion(NvCtrlAttributeHandle *handle,
float colorMatrix[3][3],
float colorOffset[3],
float colorScale[3])
{
NvCtrlAttributePrivateHandle *h;
if (!handle) return NvCtrlBadHandle;
h = (NvCtrlAttributePrivateHandle *) handle;
if (!h->nv) return NvCtrlMissingExtension;
if (h->target_type != NV_CTRL_TARGET_TYPE_X_SCREEN) return NvCtrlBadHandle;
XNVCTRLSetGvoColorConversion(h->dpy,
h->target_id,
colorMatrix,
colorOffset,
colorScale);
return NvCtrlSuccess;
} /* NvCtrlNvControlSetGvoColorConversion() */
ReturnStatus
NvCtrlGetGvoColorConversion(NvCtrlAttributeHandle *handle,
float colorMatrix[3][3],
float colorOffset[3],
float colorScale[3])
{
NvCtrlAttributePrivateHandle *h;
Bool bRet;
if (!handle) return NvCtrlBadHandle;
h = (NvCtrlAttributePrivateHandle *) handle;
if (!h->nv) return NvCtrlMissingExtension;
if (h->target_type != NV_CTRL_TARGET_TYPE_X_SCREEN) return NvCtrlBadHandle;
bRet = XNVCTRLQueryGvoColorConversion(h->dpy,
h->target_id,
colorMatrix,
colorOffset,
colorScale);
if (!bRet) {
return NvCtrlError;
} else {
return NvCtrlSuccess;
}
} /* NvCtrlNvControlGetGvoColorConversion() */
|