2 * Copyright (c) 2008 NVIDIA, Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Make sure that XTHREADS is defined, so that the
26 * LockDisplay/UnlockDisplay macros are expanded properly and the
27 * libXNVCtrl library properly protects the Display connection.
30 #if !defined(XTHREADS)
38 #include <X11/Xlibint.h>
39 #include <X11/Xutil.h>
40 #include <X11/extensions/Xext.h>
41 #include <X11/extensions/extutil.h>
42 #include "NVCtrlLib.h"
43 #include "nv_control.h"
45 #define NVCTRL_EXT_EXISTS 1
46 #define NVCTRL_EXT_NEED_TARGET_SWAP 2
47 #define NVCTRL_EXT_64_BIT_ATTRIBUTES 4
48 #define NVCTRL_EXT_NEED_CHECK (1 << (sizeof(XPointer) - 1))
50 static XExtensionInfo _nvctrl_ext_info_data
;
51 static XExtensionInfo
*nvctrl_ext_info
= &_nvctrl_ext_info_data
;
52 static /* const */ char *nvctrl_extension_name
= NV_CONTROL_NAME
;
54 #define XNVCTRLCheckExtension(dpy,i,val) \
55 XextCheckExtension (dpy, i, nvctrl_extension_name, val)
56 #define XNVCTRLSimpleCheckExtension(dpy,i) \
57 XextSimpleCheckExtension (dpy, i, nvctrl_extension_name)
59 static int close_display();
60 static uintptr_t version_flags(Display
*dpy
, XExtDisplayInfo
*info
);
61 static Bool
wire_to_event();
62 static /* const */ XExtensionHooks nvctrl_extension_hooks
= {
67 NULL
, /* create_font */
69 close_display
, /* close_display */
70 wire_to_event
, /* wire_to_event */
71 NULL
, /* event_to_wire */
73 NULL
, /* error_string */
76 static XEXT_GENERATE_FIND_DISPLAY (find_display
, nvctrl_ext_info
,
77 nvctrl_extension_name
,
78 &nvctrl_extension_hooks
,
80 (XPointer
)NVCTRL_EXT_NEED_CHECK
)
82 static XEXT_GENERATE_CLOSE_DISPLAY (close_display
, nvctrl_ext_info
)
85 * NV-CONTROL versions 1.8 and 1.9 pack the target_type and target_id
86 * fields in reversed order. In order to talk to one of these servers,
87 * we need to swap these fields.
90 static void XNVCTRLCheckTargetData(Display
*dpy
, XExtDisplayInfo
*info
,
91 int *target_type
, int *target_id
)
93 uintptr_t flags
= version_flags(dpy
, info
);
95 /* We need to swap the target_type and target_id */
96 if (flags
& NVCTRL_EXT_NEED_TARGET_SWAP
) {
99 *target_type
= *target_id
;
105 Bool
XNVCTRLQueryExtension (
110 XExtDisplayInfo
*info
= find_display (dpy
);
112 if (XextHasExtension(info
)) {
113 if (event_basep
) *event_basep
= info
->codes
->first_event
;
114 if (error_basep
) *error_basep
= info
->codes
->first_error
;
122 * Retrieve any cached flags that depend on the version of the NV-CONTROL
126 static uintptr_t version_flags(Display
*dpy
, XExtDisplayInfo
*info
)
128 uintptr_t data
= (uintptr_t)info
->data
;
130 /* If necessary, determine the NV-CONTROL version */
131 if (data
& NVCTRL_EXT_NEED_CHECK
) {
134 if (XNVCTRLQueryVersion(dpy
, &major
, &minor
)) {
135 data
|= NVCTRL_EXT_EXISTS
;
136 if (major
== 1 && (minor
== 8 || minor
== 9)) {
137 data
|= NVCTRL_EXT_NEED_TARGET_SWAP
;
139 if ((major
> 1) || ((major
== 1) && (minor
> 20))) {
140 data
|= NVCTRL_EXT_64_BIT_ATTRIBUTES
;
144 info
->data
= (XPointer
)data
;
150 Bool
XNVCTRLQueryVersion (
155 XExtDisplayInfo
*info
= find_display (dpy
);
156 xnvCtrlQueryExtensionReply rep
;
157 xnvCtrlQueryExtensionReq
*req
;
159 if(!XextHasExtension(info
))
162 XNVCTRLCheckExtension (dpy
, info
, False
);
165 GetReq (nvCtrlQueryExtension
, req
);
166 req
->reqType
= info
->codes
->major_opcode
;
167 req
->nvReqType
= X_nvCtrlQueryExtension
;
168 if (!_XReply (dpy
, (xReply
*) &rep
, 0, xTrue
)) {
173 if (major
) *major
= rep
.major
;
174 if (minor
) *minor
= rep
.minor
;
181 Bool
XNVCTRLIsNvScreen (
185 XExtDisplayInfo
*info
= find_display (dpy
);
186 xnvCtrlIsNvReply rep
;
190 if(!XextHasExtension(info
))
193 XNVCTRLCheckExtension (dpy
, info
, False
);
196 GetReq (nvCtrlIsNv
, req
);
197 req
->reqType
= info
->codes
->major_opcode
;
198 req
->nvReqType
= X_nvCtrlIsNv
;
199 req
->screen
= screen
;
200 if (!_XReply (dpy
, (xReply
*) &rep
, 0, xTrue
)) {
212 Bool
XNVCTRLQueryTargetCount (
217 XExtDisplayInfo
*info
= find_display (dpy
);
218 xnvCtrlQueryTargetCountReply rep
;
219 xnvCtrlQueryTargetCountReq
*req
;
221 if(!XextHasExtension(info
))
224 XNVCTRLCheckExtension (dpy
, info
, False
);
227 GetReq (nvCtrlQueryTargetCount
, req
);
228 req
->reqType
= info
->codes
->major_opcode
;
229 req
->nvReqType
= X_nvCtrlQueryTargetCount
;
230 req
->target_type
= target_type
;
231 if (!_XReply (dpy
, (xReply
*) &rep
, 0, xTrue
)) {
236 if (value
) *value
= rep
.count
;
243 void XNVCTRLSetTargetAttribute (
247 unsigned int display_mask
,
248 unsigned int attribute
,
251 XExtDisplayInfo
*info
= find_display (dpy
);
252 xnvCtrlSetAttributeReq
*req
;
254 XNVCTRLSimpleCheckExtension (dpy
, info
);
255 XNVCTRLCheckTargetData(dpy
, info
, &target_type
, &target_id
);
258 GetReq (nvCtrlSetAttribute
, req
);
259 req
->reqType
= info
->codes
->major_opcode
;
260 req
->nvReqType
= X_nvCtrlSetAttribute
;
261 req
->target_type
= target_type
;
262 req
->target_id
= target_id
;
263 req
->display_mask
= display_mask
;
264 req
->attribute
= attribute
;
270 void XNVCTRLSetAttribute (
273 unsigned int display_mask
,
274 unsigned int attribute
,
277 XNVCTRLSetTargetAttribute (dpy
, NV_CTRL_TARGET_TYPE_X_SCREEN
, screen
,
278 display_mask
, attribute
, value
);
282 Bool
XNVCTRLSetTargetAttributeAndGetStatus (
286 unsigned int display_mask
,
287 unsigned int attribute
,
290 XExtDisplayInfo
*info
= find_display (dpy
);
291 xnvCtrlSetAttributeAndGetStatusReq
*req
;
292 xnvCtrlSetAttributeAndGetStatusReply rep
;
295 if(!XextHasExtension(info
))
298 XNVCTRLCheckExtension (dpy
, info
, False
);
301 GetReq (nvCtrlSetAttributeAndGetStatus
, req
);
302 req
->reqType
= info
->codes
->major_opcode
;
303 req
->nvReqType
= X_nvCtrlSetAttributeAndGetStatus
;
304 req
->target_type
= target_type
;
305 req
->target_id
= target_id
;
306 req
->display_mask
= display_mask
;
307 req
->attribute
= attribute
;
309 if (!_XReply (dpy
, (xReply
*) &rep
, 0, False
)) {
321 Bool
XNVCTRLSetAttributeAndGetStatus (
324 unsigned int display_mask
,
325 unsigned int attribute
,
328 return XNVCTRLSetTargetAttributeAndGetStatus(dpy
,
329 NV_CTRL_TARGET_TYPE_X_SCREEN
,
330 screen
, display_mask
,
335 Bool
XNVCTRLQueryTargetAttribute (
339 unsigned int display_mask
,
340 unsigned int attribute
,
343 XExtDisplayInfo
*info
= find_display (dpy
);
344 xnvCtrlQueryAttributeReply rep
;
345 xnvCtrlQueryAttributeReq
*req
;
348 if(!XextHasExtension(info
))
351 XNVCTRLCheckExtension (dpy
, info
, False
);
352 XNVCTRLCheckTargetData(dpy
, info
, &target_type
, &target_id
);
355 GetReq (nvCtrlQueryAttribute
, req
);
356 req
->reqType
= info
->codes
->major_opcode
;
357 req
->nvReqType
= X_nvCtrlQueryAttribute
;
358 req
->target_type
= target_type
;
359 req
->target_id
= target_id
;
360 req
->display_mask
= display_mask
;
361 req
->attribute
= attribute
;
362 if (!_XReply (dpy
, (xReply
*) &rep
, 0, xTrue
)) {
368 if (exists
&& value
) *value
= rep
.value
;
374 Bool
XNVCTRLQueryAttribute (
377 unsigned int display_mask
,
378 unsigned int attribute
,
381 return XNVCTRLQueryTargetAttribute(dpy
, NV_CTRL_TARGET_TYPE_X_SCREEN
,
382 screen
, display_mask
, attribute
, value
);
386 Bool
XNVCTRLQueryTargetAttribute64 (
390 unsigned int display_mask
,
391 unsigned int attribute
,
394 XExtDisplayInfo
*info
= find_display(dpy
);
395 xnvCtrlQueryAttribute64Reply rep
;
396 xnvCtrlQueryAttributeReq
*req
;
399 if (!XextHasExtension(info
))
402 XNVCTRLCheckExtension(dpy
, info
, False
);
403 XNVCTRLCheckTargetData(dpy
, info
, &target_type
, &target_id
);
406 GetReq(nvCtrlQueryAttribute
, req
);
407 req
->reqType
= info
->codes
->major_opcode
;
408 req
->nvReqType
= X_nvCtrlQueryAttribute64
;
409 req
->target_type
= target_type
;
410 req
->target_id
= target_id
;
411 req
->display_mask
= display_mask
;
412 req
->attribute
= attribute
;
413 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xTrue
)) {
419 if (exists
&& value
) *value
= rep
.value_64
;
426 Bool
XNVCTRLQueryTargetStringAttribute (
430 unsigned int display_mask
,
431 unsigned int attribute
,
434 XExtDisplayInfo
*info
= find_display (dpy
);
435 xnvCtrlQueryStringAttributeReply rep
;
436 xnvCtrlQueryStringAttributeReq
*req
;
438 int length
, numbytes
, slop
;
440 if (!ptr
) return False
;
442 if(!XextHasExtension(info
))
445 XNVCTRLCheckExtension (dpy
, info
, False
);
446 XNVCTRLCheckTargetData(dpy
, info
, &target_type
, &target_id
);
449 GetReq (nvCtrlQueryStringAttribute
, req
);
450 req
->reqType
= info
->codes
->major_opcode
;
451 req
->nvReqType
= X_nvCtrlQueryStringAttribute
;
452 req
->target_type
= target_type
;
453 req
->target_id
= target_id
;
454 req
->display_mask
= display_mask
;
455 req
->attribute
= attribute
;
456 if (!_XReply (dpy
, (xReply
*) &rep
, 0, False
)) {
466 *ptr
= (char *) Xmalloc(numbytes
);
468 if (!exists
|| !*ptr
) {
469 _XEatData(dpy
, length
);
474 _XRead(dpy
, (char *) *ptr
, numbytes
);
475 if (slop
) _XEatData(dpy
, 4-slop
);
482 Bool
XNVCTRLQueryStringAttribute (
485 unsigned int display_mask
,
486 unsigned int attribute
,
489 return XNVCTRLQueryTargetStringAttribute(dpy
, NV_CTRL_TARGET_TYPE_X_SCREEN
,
490 screen
, display_mask
,
495 Bool
XNVCTRLSetTargetStringAttribute (
499 unsigned int display_mask
,
500 unsigned int attribute
,
503 XExtDisplayInfo
*info
= find_display (dpy
);
504 xnvCtrlSetStringAttributeReq
*req
;
505 xnvCtrlSetStringAttributeReply rep
;
509 if(!XextHasExtension(info
))
512 XNVCTRLCheckExtension (dpy
, info
, False
);
514 size
= strlen(ptr
)+1;
517 GetReq (nvCtrlSetStringAttribute
, req
);
518 req
->reqType
= info
->codes
->major_opcode
;
519 req
->nvReqType
= X_nvCtrlSetStringAttribute
;
520 req
->target_type
= target_type
;
521 req
->target_id
= target_id
;
522 req
->display_mask
= display_mask
;
523 req
->attribute
= attribute
;
524 req
->length
+= ((size
+ 3) & ~3) >> 2;
525 req
->num_bytes
= size
;
526 Data(dpy
, ptr
, size
);
528 if (!_XReply (dpy
, (xReply
*) &rep
, 0, False
)) {
540 Bool
XNVCTRLSetStringAttribute (
543 unsigned int display_mask
,
544 unsigned int attribute
,
547 return XNVCTRLSetTargetStringAttribute(dpy
, NV_CTRL_TARGET_TYPE_X_SCREEN
,
548 screen
, display_mask
,
553 static Bool
XNVCTRLQueryValidTargetAttributeValues32 (
555 XExtDisplayInfo
*info
,
558 unsigned int display_mask
,
559 unsigned int attribute
,
560 NVCTRLAttributeValidValuesRec
*values
562 xnvCtrlQueryValidAttributeValuesReply rep
;
563 xnvCtrlQueryValidAttributeValuesReq
*req
;
567 GetReq (nvCtrlQueryValidAttributeValues
, req
);
568 req
->reqType
= info
->codes
->major_opcode
;
569 req
->nvReqType
= X_nvCtrlQueryValidAttributeValues
;
570 req
->target_type
= target_type
;
571 req
->target_id
= target_id
;
572 req
->display_mask
= display_mask
;
573 req
->attribute
= attribute
;
574 if (!_XReply (dpy
, (xReply
*) &rep
, 0, xTrue
)) {
581 values
->type
= rep
.attr_type
;
582 if (rep
.attr_type
== ATTRIBUTE_TYPE_RANGE
) {
583 values
->u
.range
.min
= rep
.min
;
584 values
->u
.range
.max
= rep
.max
;
586 if (rep
.attr_type
== ATTRIBUTE_TYPE_INT_BITS
) {
587 values
->u
.bits
.ints
= rep
.bits
;
589 values
->permissions
= rep
.perms
;
597 Bool
XNVCTRLQueryValidTargetStringAttributeValues (
601 unsigned int display_mask
,
602 unsigned int attribute
,
603 NVCTRLAttributeValidValuesRec
*values
605 XExtDisplayInfo
*info
= find_display(dpy
);
607 xnvCtrlQueryValidAttributeValuesReply rep
;
608 xnvCtrlQueryValidAttributeValuesReq
*req
;
610 if (!values
) return False
;
612 if (!XextHasExtension(info
))
615 XNVCTRLCheckExtension(dpy
, info
, False
);
618 GetReq (nvCtrlQueryValidAttributeValues
, req
);
619 req
->reqType
= info
->codes
->major_opcode
;
620 req
->nvReqType
= X_nvCtrlQueryValidStringAttributeValues
;
621 req
->target_type
= target_type
;
622 req
->target_id
= target_id
;
623 req
->display_mask
= display_mask
;
624 req
->attribute
= attribute
;
625 if (!_XReply(dpy
, (xReply
*)&rep
, 0, xTrue
)) {
632 values
->type
= rep
.attr_type
;
633 values
->permissions
= rep
.perms
;
641 static Bool
XNVCTRLQueryValidTargetAttributeValues64 (
643 XExtDisplayInfo
*info
,
646 unsigned int display_mask
,
647 unsigned int attribute
,
648 NVCTRLAttributeValidValuesRec
*values
650 xnvCtrlQueryValidAttributeValues64Reply rep
;
651 xnvCtrlQueryValidAttributeValuesReq
*req
;
655 GetReq(nvCtrlQueryValidAttributeValues
, req
);
656 req
->reqType
= info
->codes
->major_opcode
;
657 req
->nvReqType
= X_nvCtrlQueryValidAttributeValues64
;
658 req
->target_type
= target_type
;
659 req
->target_id
= target_id
;
660 req
->display_mask
= display_mask
;
661 req
->attribute
= attribute
;
662 if (!_XReply(dpy
, (xReply
*)&rep
,
663 sz_xnvCtrlQueryValidAttributeValues64Reply_extra
,
671 values
->type
= rep
.attr_type
;
672 if (rep
.attr_type
== ATTRIBUTE_TYPE_RANGE
) {
673 values
->u
.range
.min
= rep
.min_64
;
674 values
->u
.range
.max
= rep
.max_64
;
676 if (rep
.attr_type
== ATTRIBUTE_TYPE_INT_BITS
) {
677 values
->u
.bits
.ints
= rep
.bits_64
;
679 values
->permissions
= rep
.perms
;
686 Bool
XNVCTRLQueryValidTargetAttributeValues (
690 unsigned int display_mask
,
691 unsigned int attribute
,
692 NVCTRLAttributeValidValuesRec
*values
694 XExtDisplayInfo
*info
= find_display(dpy
);
698 if (!values
) return False
;
700 if (!XextHasExtension(info
))
703 XNVCTRLCheckExtension(dpy
, info
, False
);
704 XNVCTRLCheckTargetData(dpy
, info
, &target_type
, &target_id
);
706 flags
= version_flags(dpy
,info
);
708 if (!(flags
& NVCTRL_EXT_EXISTS
))
711 if (flags
& NVCTRL_EXT_64_BIT_ATTRIBUTES
) {
712 exists
= XNVCTRLQueryValidTargetAttributeValues64(dpy
, info
,
719 exists
= XNVCTRLQueryValidTargetAttributeValues32(dpy
, info
,
730 Bool
XNVCTRLQueryValidAttributeValues (
733 unsigned int display_mask
,
734 unsigned int attribute
,
735 NVCTRLAttributeValidValuesRec
*values
737 return XNVCTRLQueryValidTargetAttributeValues(dpy
,
738 NV_CTRL_TARGET_TYPE_X_SCREEN
,
739 screen
, display_mask
,
744 static Bool
QueryAttributePermissionsInternal (
746 unsigned int attribute
,
747 NVCTRLAttributePermissionsRec
*permissions
,
750 XExtDisplayInfo
*info
= find_display (dpy
);
751 xnvCtrlQueryAttributePermissionsReply rep
;
752 xnvCtrlQueryAttributePermissionsReq
*req
;
755 if(!XextHasExtension(info
))
758 XNVCTRLCheckExtension (dpy
, info
, False
);
761 GetReq(nvCtrlQueryAttributePermissions
, req
);
762 req
->reqType
= info
->codes
->major_opcode
;
763 req
->nvReqType
= reqType
;
764 req
->attribute
= attribute
;
765 if (!_XReply (dpy
, (xReply
*) &rep
, 0, xTrue
)) {
771 if (exists
&& permissions
) {
772 permissions
->type
= rep
.attr_type
;
773 permissions
->permissions
= rep
.perms
;
781 Bool
XNVCTRLQueryAttributePermissions (
783 unsigned int attribute
,
784 NVCTRLAttributePermissionsRec
*permissions
786 return QueryAttributePermissionsInternal(dpy
,
789 X_nvCtrlQueryAttributePermissions
);
793 Bool
XNVCTRLQueryStringAttributePermissions (
795 unsigned int attribute
,
796 NVCTRLAttributePermissionsRec
*permissions
798 return QueryAttributePermissionsInternal(dpy
,
801 X_nvCtrlQueryStringAttributePermissions
);
805 Bool
XNVCTRLQueryBinaryDataAttributePermissions (
807 unsigned int attribute
,
808 NVCTRLAttributePermissionsRec
*permissions
810 return QueryAttributePermissionsInternal(dpy
,
813 X_nvCtrlQueryBinaryDataAttributePermissions
);
817 Bool
XNVCTRLQueryStringOperationAttributePermissions (
819 unsigned int attribute
,
820 NVCTRLAttributePermissionsRec
*permissions
822 return QueryAttributePermissionsInternal(dpy
,
825 X_nvCtrlQueryStringOperationAttributePermissions
);
829 void XNVCTRLSetGvoColorConversion (
832 float colorMatrix
[3][3],
833 float colorOffset
[3],
836 XExtDisplayInfo
*info
= find_display (dpy
);
837 xnvCtrlSetGvoColorConversionReq
*req
;
839 XNVCTRLSimpleCheckExtension (dpy
, info
);
842 GetReq (nvCtrlSetGvoColorConversion
, req
);
843 req
->reqType
= info
->codes
->major_opcode
;
844 req
->nvReqType
= X_nvCtrlSetGvoColorConversion
;
845 req
->screen
= screen
;
847 req
->cscMatrix_y_r
= colorMatrix
[0][0];
848 req
->cscMatrix_y_g
= colorMatrix
[0][1];
849 req
->cscMatrix_y_b
= colorMatrix
[0][2];
851 req
->cscMatrix_cr_r
= colorMatrix
[1][0];
852 req
->cscMatrix_cr_g
= colorMatrix
[1][1];
853 req
->cscMatrix_cr_b
= colorMatrix
[1][2];
855 req
->cscMatrix_cb_r
= colorMatrix
[2][0];
856 req
->cscMatrix_cb_g
= colorMatrix
[2][1];
857 req
->cscMatrix_cb_b
= colorMatrix
[2][2];
859 req
->cscOffset_y
= colorOffset
[0];
860 req
->cscOffset_cr
= colorOffset
[1];
861 req
->cscOffset_cb
= colorOffset
[2];
863 req
->cscScale_y
= colorScale
[0];
864 req
->cscScale_cr
= colorScale
[1];
865 req
->cscScale_cb
= colorScale
[2];
872 Bool
XNVCTRLQueryGvoColorConversion (
875 float colorMatrix
[3][3],
876 float colorOffset
[3],
879 XExtDisplayInfo
*info
= find_display (dpy
);
880 xnvCtrlQueryGvoColorConversionReply rep
;
881 xnvCtrlQueryGvoColorConversionReq
*req
;
883 if(!XextHasExtension(info
))
886 XNVCTRLCheckExtension (dpy
, info
, False
);
890 GetReq (nvCtrlQueryGvoColorConversion
, req
);
891 req
->reqType
= info
->codes
->major_opcode
;
892 req
->nvReqType
= X_nvCtrlQueryGvoColorConversion
;
893 req
->screen
= screen
;
895 if (!_XReply(dpy
, (xReply
*) &rep
, 0, xFalse
)) {
901 _XRead(dpy
, (char *)(colorMatrix
), 36);
902 _XRead(dpy
, (char *)(colorOffset
), 12);
903 _XRead(dpy
, (char *)(colorScale
), 12);
912 Bool
XNVCtrlSelectTargetNotify (
919 XExtDisplayInfo
*info
= find_display (dpy
);
920 xnvCtrlSelectTargetNotifyReq
*req
;
922 if(!XextHasExtension (info
))
925 XNVCTRLCheckExtension (dpy
, info
, False
);
928 GetReq (nvCtrlSelectTargetNotify
, req
);
929 req
->reqType
= info
->codes
->major_opcode
;
930 req
->nvReqType
= X_nvCtrlSelectTargetNotify
;
931 req
->target_type
= target_type
;
932 req
->target_id
= target_id
;
933 req
->notifyType
= notify_type
;
942 Bool
XNVCtrlSelectNotify (
948 XExtDisplayInfo
*info
= find_display (dpy
);
949 xnvCtrlSelectNotifyReq
*req
;
951 if(!XextHasExtension (info
))
954 XNVCTRLCheckExtension (dpy
, info
, False
);
957 GetReq (nvCtrlSelectNotify
, req
);
958 req
->reqType
= info
->codes
->major_opcode
;
959 req
->nvReqType
= X_nvCtrlSelectNotify
;
960 req
->screen
= screen
;
961 req
->notifyType
= type
;
969 Bool
XNVCTRLQueryTargetBinaryData (
973 unsigned int display_mask
,
974 unsigned int attribute
,
978 XExtDisplayInfo
*info
= find_display (dpy
);
979 xnvCtrlQueryBinaryDataReply rep
;
980 xnvCtrlQueryBinaryDataReq
*req
;
982 int length
, numbytes
, slop
;
984 if (!ptr
) return False
;
986 if(!XextHasExtension(info
))
989 XNVCTRLCheckExtension (dpy
, info
, False
);
990 XNVCTRLCheckTargetData(dpy
, info
, &target_type
, &target_id
);
993 GetReq (nvCtrlQueryBinaryData
, req
);
994 req
->reqType
= info
->codes
->major_opcode
;
995 req
->nvReqType
= X_nvCtrlQueryBinaryData
;
996 req
->target_type
= target_type
;
997 req
->target_id
= target_id
;
998 req
->display_mask
= display_mask
;
999 req
->attribute
= attribute
;
1000 if (!_XReply (dpy
, (xReply
*) &rep
, 0, False
)) {
1001 UnlockDisplay (dpy
);
1005 length
= rep
.length
;
1007 slop
= numbytes
& 3;
1010 *ptr
= (unsigned char *) Xmalloc(numbytes
);
1012 if (!exists
|| !*ptr
) {
1013 _XEatData(dpy
, length
);
1014 UnlockDisplay (dpy
);
1018 _XRead(dpy
, (char *) *ptr
, numbytes
);
1019 if (slop
) _XEatData(dpy
, 4-slop
);
1021 if (len
) *len
= numbytes
;
1022 UnlockDisplay (dpy
);
1027 Bool
XNVCTRLQueryBinaryData (
1030 unsigned int display_mask
,
1031 unsigned int attribute
,
1032 unsigned char **ptr
,
1035 return XNVCTRLQueryTargetBinaryData(dpy
, NV_CTRL_TARGET_TYPE_X_SCREEN
,
1036 screen
, display_mask
,
1037 attribute
, ptr
, len
);
1040 Bool
XNVCTRLStringOperation (
1044 unsigned int display_mask
,
1045 unsigned int attribute
,
1049 XExtDisplayInfo
*info
= find_display(dpy
);
1050 xnvCtrlStringOperationReq
*req
;
1051 xnvCtrlStringOperationReply rep
;
1053 int inSize
, outSize
, length
, slop
;
1055 if (!XextHasExtension(info
))
1063 XNVCTRLCheckExtension(dpy
, info
, False
);
1064 XNVCTRLCheckTargetData(dpy
, info
, &target_type
, &target_id
);
1067 inSize
= strlen(pIn
) + 1;
1073 GetReq(nvCtrlStringOperation
, req
);
1075 req
->reqType
= info
->codes
->major_opcode
;
1076 req
->nvReqType
= X_nvCtrlStringOperation
;
1077 req
->target_type
= target_type
;
1078 req
->target_id
= target_id
;
1079 req
->display_mask
= display_mask
;
1080 req
->attribute
= attribute
;
1082 req
->length
+= ((inSize
+ 3) & ~3) >> 2;
1083 req
->num_bytes
= inSize
;
1086 Data(dpy
, pIn
, inSize
);
1089 if (!_XReply (dpy
, (xReply
*) &rep
, 0, False
)) {
1095 length
= rep
.length
;
1096 outSize
= rep
.num_bytes
;
1099 if (outSize
) *ppOut
= (char *) Xmalloc(outSize
);
1102 _XEatData(dpy
, length
);
1104 _XRead(dpy
, (char *) *ppOut
, outSize
);
1105 if (slop
) _XEatData(dpy
, 4-slop
);
1117 static Bool
wire_to_event (Display
*dpy
, XEvent
*host
, xEvent
*wire
)
1119 XExtDisplayInfo
*info
= find_display (dpy
);
1121 xnvctrlEvent
*event
;
1122 XNVCtrlEventTarget
*reTarget
;
1123 xnvctrlEventTarget
*eventTarget
;
1124 XNVCtrlEventTargetAvailability
*reTargetAvailability
;
1125 XNVCtrlStringEventTarget
*reTargetString
;
1126 XNVCtrlBinaryEventTarget
*reTargetBinary
;
1128 XNVCTRLCheckExtension (dpy
, info
, False
);
1130 switch ((wire
->u
.u
.type
& 0x7F) - info
->codes
->first_event
) {
1131 case ATTRIBUTE_CHANGED_EVENT
:
1132 re
= (XNVCtrlEvent
*) host
;
1133 event
= (xnvctrlEvent
*) wire
;
1134 re
->attribute_changed
.type
= event
->u
.u
.type
& 0x7F;
1135 re
->attribute_changed
.serial
=
1136 _XSetLastRequestRead(dpy
, (xGenericReply
*) event
);
1137 re
->attribute_changed
.send_event
= ((event
->u
.u
.type
& 0x80) != 0);
1138 re
->attribute_changed
.display
= dpy
;
1139 re
->attribute_changed
.time
= event
->u
.attribute_changed
.time
;
1140 re
->attribute_changed
.screen
= event
->u
.attribute_changed
.screen
;
1141 re
->attribute_changed
.display_mask
=
1142 event
->u
.attribute_changed
.display_mask
;
1143 re
->attribute_changed
.attribute
= event
->u
.attribute_changed
.attribute
;
1144 re
->attribute_changed
.value
= event
->u
.attribute_changed
.value
;
1146 case TARGET_ATTRIBUTE_CHANGED_EVENT
:
1147 reTarget
= (XNVCtrlEventTarget
*) host
;
1148 eventTarget
= (xnvctrlEventTarget
*) wire
;
1149 reTarget
->attribute_changed
.type
= eventTarget
->u
.u
.type
& 0x7F;
1150 reTarget
->attribute_changed
.serial
=
1151 _XSetLastRequestRead(dpy
, (xGenericReply
*) eventTarget
);
1152 reTarget
->attribute_changed
.send_event
=
1153 ((eventTarget
->u
.u
.type
& 0x80) != 0);
1154 reTarget
->attribute_changed
.display
= dpy
;
1155 reTarget
->attribute_changed
.time
=
1156 eventTarget
->u
.attribute_changed
.time
;
1157 reTarget
->attribute_changed
.target_type
=
1158 eventTarget
->u
.attribute_changed
.target_type
;
1159 reTarget
->attribute_changed
.target_id
=
1160 eventTarget
->u
.attribute_changed
.target_id
;
1161 reTarget
->attribute_changed
.display_mask
=
1162 eventTarget
->u
.attribute_changed
.display_mask
;
1163 reTarget
->attribute_changed
.attribute
=
1164 eventTarget
->u
.attribute_changed
.attribute
;
1165 reTarget
->attribute_changed
.value
=
1166 eventTarget
->u
.attribute_changed
.value
;
1168 case TARGET_ATTRIBUTE_AVAILABILITY_CHANGED_EVENT
:
1169 reTargetAvailability
= (XNVCtrlEventTargetAvailability
*) host
;
1170 eventTarget
= (xnvctrlEventTarget
*) wire
;
1171 reTargetAvailability
->attribute_changed
.type
=
1172 eventTarget
->u
.u
.type
& 0x7F;
1173 reTargetAvailability
->attribute_changed
.serial
=
1174 _XSetLastRequestRead(dpy
, (xGenericReply
*) eventTarget
);
1175 reTargetAvailability
->attribute_changed
.send_event
=
1176 ((eventTarget
->u
.u
.type
& 0x80) != 0);
1177 reTargetAvailability
->attribute_changed
.display
= dpy
;
1178 reTargetAvailability
->attribute_changed
.time
=
1179 eventTarget
->u
.availability_changed
.time
;
1180 reTargetAvailability
->attribute_changed
.target_type
=
1181 eventTarget
->u
.availability_changed
.target_type
;
1182 reTargetAvailability
->attribute_changed
.target_id
=
1183 eventTarget
->u
.availability_changed
.target_id
;
1184 reTargetAvailability
->attribute_changed
.display_mask
=
1185 eventTarget
->u
.availability_changed
.display_mask
;
1186 reTargetAvailability
->attribute_changed
.attribute
=
1187 eventTarget
->u
.availability_changed
.attribute
;
1188 reTargetAvailability
->attribute_changed
.availability
=
1189 eventTarget
->u
.availability_changed
.availability
;
1190 reTargetAvailability
->attribute_changed
.value
=
1191 eventTarget
->u
.availability_changed
.value
;
1193 case TARGET_STRING_ATTRIBUTE_CHANGED_EVENT
:
1194 reTargetString
= (XNVCtrlStringEventTarget
*) host
;
1195 eventTarget
= (xnvctrlEventTarget
*) wire
;
1196 reTargetString
->attribute_changed
.type
= eventTarget
->u
.u
.type
& 0x7F;
1197 reTargetString
->attribute_changed
.serial
=
1198 _XSetLastRequestRead(dpy
, (xGenericReply
*) eventTarget
);
1199 reTargetString
->attribute_changed
.send_event
=
1200 ((eventTarget
->u
.u
.type
& 0x80) != 0);
1201 reTargetString
->attribute_changed
.display
= dpy
;
1202 reTargetString
->attribute_changed
.time
=
1203 eventTarget
->u
.attribute_changed
.time
;
1204 reTargetString
->attribute_changed
.target_type
=
1205 eventTarget
->u
.attribute_changed
.target_type
;
1206 reTargetString
->attribute_changed
.target_id
=
1207 eventTarget
->u
.attribute_changed
.target_id
;
1208 reTargetString
->attribute_changed
.display_mask
=
1209 eventTarget
->u
.attribute_changed
.display_mask
;
1210 reTargetString
->attribute_changed
.attribute
=
1211 eventTarget
->u
.attribute_changed
.attribute
;
1213 case TARGET_BINARY_ATTRIBUTE_CHANGED_EVENT
:
1214 reTargetBinary
= (XNVCtrlBinaryEventTarget
*) host
;
1215 eventTarget
= (xnvctrlEventTarget
*) wire
;
1216 reTargetBinary
->attribute_changed
.type
= eventTarget
->u
.u
.type
& 0x7F;
1217 reTargetBinary
->attribute_changed
.serial
=
1218 _XSetLastRequestRead(dpy
, (xGenericReply
*) eventTarget
);
1219 reTargetBinary
->attribute_changed
.send_event
=
1220 ((eventTarget
->u
.u
.type
& 0x80) != 0);
1221 reTargetBinary
->attribute_changed
.display
= dpy
;
1222 reTargetBinary
->attribute_changed
.time
=
1223 eventTarget
->u
.attribute_changed
.time
;
1224 reTargetBinary
->attribute_changed
.target_type
=
1225 eventTarget
->u
.attribute_changed
.target_type
;
1226 reTargetBinary
->attribute_changed
.target_id
=
1227 eventTarget
->u
.attribute_changed
.target_id
;
1228 reTargetBinary
->attribute_changed
.display_mask
=
1229 eventTarget
->u
.attribute_changed
.display_mask
;
1230 reTargetBinary
->attribute_changed
.attribute
=
1231 eventTarget
->u
.attribute_changed
.attribute
;