xref: /aosp_15_r20/external/angle/src/third_party/libXNVCtrl/NVCtrl.c (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker /*
2*8975f5c5SAndroid Build Coastguard Worker  * Copyright (c) 2008 NVIDIA, Corporation
3*8975f5c5SAndroid Build Coastguard Worker  *
4*8975f5c5SAndroid Build Coastguard Worker  * Permission is hereby granted, free of charge, to any person obtaining a copy
5*8975f5c5SAndroid Build Coastguard Worker  * of this software and associated documentation files (the "Software"), to deal
6*8975f5c5SAndroid Build Coastguard Worker  * in the Software without restriction, including without limitation the rights
7*8975f5c5SAndroid Build Coastguard Worker  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8*8975f5c5SAndroid Build Coastguard Worker  * copies of the Software, and to permit persons to whom the Software is
9*8975f5c5SAndroid Build Coastguard Worker  * furnished to do so, subject to the following conditions:
10*8975f5c5SAndroid Build Coastguard Worker  *
11*8975f5c5SAndroid Build Coastguard Worker  * The above copyright notice and this permission notice (including the next
12*8975f5c5SAndroid Build Coastguard Worker  * paragraph) shall be included in all copies or substantial portions of the
13*8975f5c5SAndroid Build Coastguard Worker  * Software.
14*8975f5c5SAndroid Build Coastguard Worker  *
15*8975f5c5SAndroid Build Coastguard Worker  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*8975f5c5SAndroid Build Coastguard Worker  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*8975f5c5SAndroid Build Coastguard Worker  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18*8975f5c5SAndroid Build Coastguard Worker  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*8975f5c5SAndroid Build Coastguard Worker  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20*8975f5c5SAndroid Build Coastguard Worker  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21*8975f5c5SAndroid Build Coastguard Worker  * SOFTWARE.
22*8975f5c5SAndroid Build Coastguard Worker  */
23*8975f5c5SAndroid Build Coastguard Worker 
24*8975f5c5SAndroid Build Coastguard Worker /*
25*8975f5c5SAndroid Build Coastguard Worker  * Make sure that XTHREADS is defined, so that the
26*8975f5c5SAndroid Build Coastguard Worker  * LockDisplay/UnlockDisplay macros are expanded properly and the
27*8975f5c5SAndroid Build Coastguard Worker  * libXNVCtrl library properly protects the Display connection.
28*8975f5c5SAndroid Build Coastguard Worker  */
29*8975f5c5SAndroid Build Coastguard Worker 
30*8975f5c5SAndroid Build Coastguard Worker #if !defined(XTHREADS)
31*8975f5c5SAndroid Build Coastguard Worker #define XTHREADS
32*8975f5c5SAndroid Build Coastguard Worker #endif /* XTHREADS */
33*8975f5c5SAndroid Build Coastguard Worker 
34*8975f5c5SAndroid Build Coastguard Worker #define NEED_EVENTS
35*8975f5c5SAndroid Build Coastguard Worker #define NEED_REPLIES
36*8975f5c5SAndroid Build Coastguard Worker #include <stdint.h>
37*8975f5c5SAndroid Build Coastguard Worker #include <stdlib.h>
38*8975f5c5SAndroid Build Coastguard Worker #include <X11/Xlibint.h>
39*8975f5c5SAndroid Build Coastguard Worker #include <X11/Xutil.h>
40*8975f5c5SAndroid Build Coastguard Worker #include <X11/extensions/Xext.h>
41*8975f5c5SAndroid Build Coastguard Worker #include <X11/extensions/extutil.h>
42*8975f5c5SAndroid Build Coastguard Worker #include "NVCtrlLib.h"
43*8975f5c5SAndroid Build Coastguard Worker #include "nv_control.h"
44*8975f5c5SAndroid Build Coastguard Worker 
45*8975f5c5SAndroid Build Coastguard Worker #define NVCTRL_EXT_EXISTS              1
46*8975f5c5SAndroid Build Coastguard Worker #define NVCTRL_EXT_NEED_TARGET_SWAP    2
47*8975f5c5SAndroid Build Coastguard Worker #define NVCTRL_EXT_64_BIT_ATTRIBUTES   4
48*8975f5c5SAndroid Build Coastguard Worker #define NVCTRL_EXT_NEED_CHECK          (1 << (sizeof(XPointer) - 1))
49*8975f5c5SAndroid Build Coastguard Worker 
50*8975f5c5SAndroid Build Coastguard Worker static XExtensionInfo _nvctrl_ext_info_data;
51*8975f5c5SAndroid Build Coastguard Worker static XExtensionInfo *nvctrl_ext_info = &_nvctrl_ext_info_data;
52*8975f5c5SAndroid Build Coastguard Worker static const char *nvctrl_extension_name = NV_CONTROL_NAME;
53*8975f5c5SAndroid Build Coastguard Worker 
54*8975f5c5SAndroid Build Coastguard Worker #define XNVCTRLCheckExtension(dpy,i,val) \
55*8975f5c5SAndroid Build Coastguard Worker   XextCheckExtension (dpy, i, nvctrl_extension_name, val)
56*8975f5c5SAndroid Build Coastguard Worker #define XNVCTRLSimpleCheckExtension(dpy,i) \
57*8975f5c5SAndroid Build Coastguard Worker   XextSimpleCheckExtension (dpy, i, nvctrl_extension_name)
58*8975f5c5SAndroid Build Coastguard Worker 
59*8975f5c5SAndroid Build Coastguard Worker static int close_display();
60*8975f5c5SAndroid Build Coastguard Worker static uintptr_t version_flags(Display *dpy, XExtDisplayInfo *info);
61*8975f5c5SAndroid Build Coastguard Worker static Bool wire_to_event();
62*8975f5c5SAndroid Build Coastguard Worker static /* const */ XExtensionHooks nvctrl_extension_hooks = {
63*8975f5c5SAndroid Build Coastguard Worker     NULL,                               /* create_gc */
64*8975f5c5SAndroid Build Coastguard Worker     NULL,                               /* copy_gc */
65*8975f5c5SAndroid Build Coastguard Worker     NULL,                               /* flush_gc */
66*8975f5c5SAndroid Build Coastguard Worker     NULL,                               /* free_gc */
67*8975f5c5SAndroid Build Coastguard Worker     NULL,                               /* create_font */
68*8975f5c5SAndroid Build Coastguard Worker     NULL,                               /* free_font */
69*8975f5c5SAndroid Build Coastguard Worker     close_display,                      /* close_display */
70*8975f5c5SAndroid Build Coastguard Worker     wire_to_event,                      /* wire_to_event */
71*8975f5c5SAndroid Build Coastguard Worker     NULL,                               /* event_to_wire */
72*8975f5c5SAndroid Build Coastguard Worker     NULL,                               /* error */
73*8975f5c5SAndroid Build Coastguard Worker     NULL,                               /* error_string */
74*8975f5c5SAndroid Build Coastguard Worker };
75*8975f5c5SAndroid Build Coastguard Worker 
76*8975f5c5SAndroid Build Coastguard Worker static XEXT_GENERATE_FIND_DISPLAY (find_display, nvctrl_ext_info,
77*8975f5c5SAndroid Build Coastguard Worker                                    nvctrl_extension_name,
78*8975f5c5SAndroid Build Coastguard Worker                                    &nvctrl_extension_hooks,
79*8975f5c5SAndroid Build Coastguard Worker                                    NV_CONTROL_EVENTS,
80*8975f5c5SAndroid Build Coastguard Worker                                    (XPointer)NVCTRL_EXT_NEED_CHECK)
81*8975f5c5SAndroid Build Coastguard Worker 
XEXT_GENERATE_CLOSE_DISPLAY(close_display,nvctrl_ext_info)82*8975f5c5SAndroid Build Coastguard Worker static XEXT_GENERATE_CLOSE_DISPLAY (close_display, nvctrl_ext_info)
83*8975f5c5SAndroid Build Coastguard Worker 
84*8975f5c5SAndroid Build Coastguard Worker /*
85*8975f5c5SAndroid Build Coastguard Worker  * NV-CONTROL versions 1.8 and 1.9 pack the target_type and target_id
86*8975f5c5SAndroid Build Coastguard Worker  * fields in reversed order.  In order to talk to one of these servers,
87*8975f5c5SAndroid Build Coastguard Worker  * we need to swap these fields.
88*8975f5c5SAndroid Build Coastguard Worker  */
89*8975f5c5SAndroid Build Coastguard Worker 
90*8975f5c5SAndroid Build Coastguard Worker static void XNVCTRLCheckTargetData(Display *dpy, XExtDisplayInfo *info,
91*8975f5c5SAndroid Build Coastguard Worker                                    int *target_type, int *target_id)
92*8975f5c5SAndroid Build Coastguard Worker {
93*8975f5c5SAndroid Build Coastguard Worker     uintptr_t flags = version_flags(dpy, info);
94*8975f5c5SAndroid Build Coastguard Worker 
95*8975f5c5SAndroid Build Coastguard Worker     /* We need to swap the target_type and target_id */
96*8975f5c5SAndroid Build Coastguard Worker     if (flags & NVCTRL_EXT_NEED_TARGET_SWAP) {
97*8975f5c5SAndroid Build Coastguard Worker         int tmp;
98*8975f5c5SAndroid Build Coastguard Worker         tmp = *target_type;
99*8975f5c5SAndroid Build Coastguard Worker         *target_type = *target_id;
100*8975f5c5SAndroid Build Coastguard Worker         *target_id = tmp;
101*8975f5c5SAndroid Build Coastguard Worker     }
102*8975f5c5SAndroid Build Coastguard Worker }
103*8975f5c5SAndroid Build Coastguard Worker 
104*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLQueryExtension(Display * dpy,int * event_basep,int * error_basep)105*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLQueryExtension (
106*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
107*8975f5c5SAndroid Build Coastguard Worker     int *event_basep,
108*8975f5c5SAndroid Build Coastguard Worker     int *error_basep
109*8975f5c5SAndroid Build Coastguard Worker ){
110*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info = find_display (dpy);
111*8975f5c5SAndroid Build Coastguard Worker 
112*8975f5c5SAndroid Build Coastguard Worker     if (XextHasExtension(info)) {
113*8975f5c5SAndroid Build Coastguard Worker         if (event_basep) *event_basep = info->codes->first_event;
114*8975f5c5SAndroid Build Coastguard Worker         if (error_basep) *error_basep = info->codes->first_error;
115*8975f5c5SAndroid Build Coastguard Worker         return True;
116*8975f5c5SAndroid Build Coastguard Worker     } else {
117*8975f5c5SAndroid Build Coastguard Worker         return False;
118*8975f5c5SAndroid Build Coastguard Worker     }
119*8975f5c5SAndroid Build Coastguard Worker }
120*8975f5c5SAndroid Build Coastguard Worker 
121*8975f5c5SAndroid Build Coastguard Worker /*
122*8975f5c5SAndroid Build Coastguard Worker  * Retrieve any cached flags that depend on the version of the NV-CONTROL
123*8975f5c5SAndroid Build Coastguard Worker  * extension.
124*8975f5c5SAndroid Build Coastguard Worker  */
125*8975f5c5SAndroid Build Coastguard Worker 
version_flags(Display * dpy,XExtDisplayInfo * info)126*8975f5c5SAndroid Build Coastguard Worker static uintptr_t version_flags(Display *dpy, XExtDisplayInfo *info)
127*8975f5c5SAndroid Build Coastguard Worker {
128*8975f5c5SAndroid Build Coastguard Worker     uintptr_t data = (uintptr_t)info->data;
129*8975f5c5SAndroid Build Coastguard Worker 
130*8975f5c5SAndroid Build Coastguard Worker     /* If necessary, determine the NV-CONTROL version */
131*8975f5c5SAndroid Build Coastguard Worker     if (data & NVCTRL_EXT_NEED_CHECK) {
132*8975f5c5SAndroid Build Coastguard Worker         int major, minor;
133*8975f5c5SAndroid Build Coastguard Worker         data = 0;
134*8975f5c5SAndroid Build Coastguard Worker         if (XNVCTRLQueryVersion(dpy, &major, &minor)) {
135*8975f5c5SAndroid Build Coastguard Worker             data |= NVCTRL_EXT_EXISTS;
136*8975f5c5SAndroid Build Coastguard Worker             if (major == 1 && (minor == 8 || minor == 9)) {
137*8975f5c5SAndroid Build Coastguard Worker                 data |= NVCTRL_EXT_NEED_TARGET_SWAP;
138*8975f5c5SAndroid Build Coastguard Worker             }
139*8975f5c5SAndroid Build Coastguard Worker             if ((major > 1) || ((major == 1) && (minor > 20))) {
140*8975f5c5SAndroid Build Coastguard Worker                 data |= NVCTRL_EXT_64_BIT_ATTRIBUTES;
141*8975f5c5SAndroid Build Coastguard Worker             }
142*8975f5c5SAndroid Build Coastguard Worker         }
143*8975f5c5SAndroid Build Coastguard Worker 
144*8975f5c5SAndroid Build Coastguard Worker         info->data = (XPointer)data;
145*8975f5c5SAndroid Build Coastguard Worker     }
146*8975f5c5SAndroid Build Coastguard Worker 
147*8975f5c5SAndroid Build Coastguard Worker     return data;
148*8975f5c5SAndroid Build Coastguard Worker }
149*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLQueryVersion(Display * dpy,int * major,int * minor)150*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLQueryVersion (
151*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
152*8975f5c5SAndroid Build Coastguard Worker     int *major,
153*8975f5c5SAndroid Build Coastguard Worker     int *minor
154*8975f5c5SAndroid Build Coastguard Worker ){
155*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info = find_display (dpy);
156*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryExtensionReply rep;
157*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryExtensionReq   *req;
158*8975f5c5SAndroid Build Coastguard Worker 
159*8975f5c5SAndroid Build Coastguard Worker     if(!XextHasExtension(info))
160*8975f5c5SAndroid Build Coastguard Worker         return False;
161*8975f5c5SAndroid Build Coastguard Worker 
162*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckExtension (dpy, info, False);
163*8975f5c5SAndroid Build Coastguard Worker 
164*8975f5c5SAndroid Build Coastguard Worker     LockDisplay (dpy);
165*8975f5c5SAndroid Build Coastguard Worker     GetReq (nvCtrlQueryExtension, req);
166*8975f5c5SAndroid Build Coastguard Worker     req->reqType = info->codes->major_opcode;
167*8975f5c5SAndroid Build Coastguard Worker     req->nvReqType = X_nvCtrlQueryExtension;
168*8975f5c5SAndroid Build Coastguard Worker     if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
169*8975f5c5SAndroid Build Coastguard Worker         UnlockDisplay (dpy);
170*8975f5c5SAndroid Build Coastguard Worker         SyncHandle ();
171*8975f5c5SAndroid Build Coastguard Worker         return False;
172*8975f5c5SAndroid Build Coastguard Worker     }
173*8975f5c5SAndroid Build Coastguard Worker     if (major) *major = rep.major;
174*8975f5c5SAndroid Build Coastguard Worker     if (minor) *minor = rep.minor;
175*8975f5c5SAndroid Build Coastguard Worker     UnlockDisplay (dpy);
176*8975f5c5SAndroid Build Coastguard Worker     SyncHandle ();
177*8975f5c5SAndroid Build Coastguard Worker     return True;
178*8975f5c5SAndroid Build Coastguard Worker }
179*8975f5c5SAndroid Build Coastguard Worker 
180*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLIsNvScreen(Display * dpy,int screen)181*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLIsNvScreen (
182*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
183*8975f5c5SAndroid Build Coastguard Worker     int screen
184*8975f5c5SAndroid Build Coastguard Worker ){
185*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info = find_display (dpy);
186*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlIsNvReply rep;
187*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlIsNvReq   *req;
188*8975f5c5SAndroid Build Coastguard Worker     Bool isnv;
189*8975f5c5SAndroid Build Coastguard Worker 
190*8975f5c5SAndroid Build Coastguard Worker     if(!XextHasExtension(info))
191*8975f5c5SAndroid Build Coastguard Worker         return False;
192*8975f5c5SAndroid Build Coastguard Worker 
193*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckExtension (dpy, info, False);
194*8975f5c5SAndroid Build Coastguard Worker 
195*8975f5c5SAndroid Build Coastguard Worker     LockDisplay (dpy);
196*8975f5c5SAndroid Build Coastguard Worker     GetReq (nvCtrlIsNv, req);
197*8975f5c5SAndroid Build Coastguard Worker     req->reqType = info->codes->major_opcode;
198*8975f5c5SAndroid Build Coastguard Worker     req->nvReqType = X_nvCtrlIsNv;
199*8975f5c5SAndroid Build Coastguard Worker     req->screen = screen;
200*8975f5c5SAndroid Build Coastguard Worker     if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
201*8975f5c5SAndroid Build Coastguard Worker         UnlockDisplay (dpy);
202*8975f5c5SAndroid Build Coastguard Worker         SyncHandle ();
203*8975f5c5SAndroid Build Coastguard Worker         return False;
204*8975f5c5SAndroid Build Coastguard Worker     }
205*8975f5c5SAndroid Build Coastguard Worker     isnv = rep.isnv;
206*8975f5c5SAndroid Build Coastguard Worker     UnlockDisplay (dpy);
207*8975f5c5SAndroid Build Coastguard Worker     SyncHandle ();
208*8975f5c5SAndroid Build Coastguard Worker     return isnv;
209*8975f5c5SAndroid Build Coastguard Worker }
210*8975f5c5SAndroid Build Coastguard Worker 
211*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLQueryTargetCount(Display * dpy,int target_type,int * value)212*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLQueryTargetCount (
213*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
214*8975f5c5SAndroid Build Coastguard Worker     int target_type,
215*8975f5c5SAndroid Build Coastguard Worker     int *value
216*8975f5c5SAndroid Build Coastguard Worker ){
217*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info = find_display (dpy);
218*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryTargetCountReply  rep;
219*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryTargetCountReq   *req;
220*8975f5c5SAndroid Build Coastguard Worker 
221*8975f5c5SAndroid Build Coastguard Worker     if(!XextHasExtension(info))
222*8975f5c5SAndroid Build Coastguard Worker         return False;
223*8975f5c5SAndroid Build Coastguard Worker 
224*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckExtension (dpy, info, False);
225*8975f5c5SAndroid Build Coastguard Worker 
226*8975f5c5SAndroid Build Coastguard Worker     LockDisplay (dpy);
227*8975f5c5SAndroid Build Coastguard Worker     GetReq (nvCtrlQueryTargetCount, req);
228*8975f5c5SAndroid Build Coastguard Worker     req->reqType = info->codes->major_opcode;
229*8975f5c5SAndroid Build Coastguard Worker     req->nvReqType = X_nvCtrlQueryTargetCount;
230*8975f5c5SAndroid Build Coastguard Worker     req->target_type = target_type;
231*8975f5c5SAndroid Build Coastguard Worker     if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
232*8975f5c5SAndroid Build Coastguard Worker         UnlockDisplay (dpy);
233*8975f5c5SAndroid Build Coastguard Worker         SyncHandle ();
234*8975f5c5SAndroid Build Coastguard Worker         return False;
235*8975f5c5SAndroid Build Coastguard Worker     }
236*8975f5c5SAndroid Build Coastguard Worker     if (value) *value = rep.count;
237*8975f5c5SAndroid Build Coastguard Worker     UnlockDisplay (dpy);
238*8975f5c5SAndroid Build Coastguard Worker     SyncHandle ();
239*8975f5c5SAndroid Build Coastguard Worker     return True;
240*8975f5c5SAndroid Build Coastguard Worker }
241*8975f5c5SAndroid Build Coastguard Worker 
242*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLSetTargetAttribute(Display * dpy,int target_type,int target_id,unsigned int display_mask,unsigned int attribute,int value)243*8975f5c5SAndroid Build Coastguard Worker void XNVCTRLSetTargetAttribute (
244*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
245*8975f5c5SAndroid Build Coastguard Worker     int target_type,
246*8975f5c5SAndroid Build Coastguard Worker     int target_id,
247*8975f5c5SAndroid Build Coastguard Worker     unsigned int display_mask,
248*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
249*8975f5c5SAndroid Build Coastguard Worker     int value
250*8975f5c5SAndroid Build Coastguard Worker ){
251*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info = find_display (dpy);
252*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlSetAttributeReq *req;
253*8975f5c5SAndroid Build Coastguard Worker 
254*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLSimpleCheckExtension (dpy, info);
255*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckTargetData(dpy, info, &target_type, &target_id);
256*8975f5c5SAndroid Build Coastguard Worker 
257*8975f5c5SAndroid Build Coastguard Worker     LockDisplay (dpy);
258*8975f5c5SAndroid Build Coastguard Worker     GetReq (nvCtrlSetAttribute, req);
259*8975f5c5SAndroid Build Coastguard Worker     req->reqType = info->codes->major_opcode;
260*8975f5c5SAndroid Build Coastguard Worker     req->nvReqType = X_nvCtrlSetAttribute;
261*8975f5c5SAndroid Build Coastguard Worker     req->target_type = target_type;
262*8975f5c5SAndroid Build Coastguard Worker     req->target_id = target_id;
263*8975f5c5SAndroid Build Coastguard Worker     req->display_mask = display_mask;
264*8975f5c5SAndroid Build Coastguard Worker     req->attribute = attribute;
265*8975f5c5SAndroid Build Coastguard Worker     req->value = value;
266*8975f5c5SAndroid Build Coastguard Worker     UnlockDisplay (dpy);
267*8975f5c5SAndroid Build Coastguard Worker     SyncHandle ();
268*8975f5c5SAndroid Build Coastguard Worker }
269*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLSetAttribute(Display * dpy,int screen,unsigned int display_mask,unsigned int attribute,int value)270*8975f5c5SAndroid Build Coastguard Worker void XNVCTRLSetAttribute (
271*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
272*8975f5c5SAndroid Build Coastguard Worker     int screen,
273*8975f5c5SAndroid Build Coastguard Worker     unsigned int display_mask,
274*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
275*8975f5c5SAndroid Build Coastguard Worker     int value
276*8975f5c5SAndroid Build Coastguard Worker ){
277*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLSetTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, screen,
278*8975f5c5SAndroid Build Coastguard Worker                                display_mask, attribute, value);
279*8975f5c5SAndroid Build Coastguard Worker }
280*8975f5c5SAndroid Build Coastguard Worker 
281*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLSetTargetAttributeAndGetStatus(Display * dpy,int target_type,int target_id,unsigned int display_mask,unsigned int attribute,int value)282*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLSetTargetAttributeAndGetStatus (
283*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
284*8975f5c5SAndroid Build Coastguard Worker     int target_type,
285*8975f5c5SAndroid Build Coastguard Worker     int target_id,
286*8975f5c5SAndroid Build Coastguard Worker     unsigned int display_mask,
287*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
288*8975f5c5SAndroid Build Coastguard Worker     int value
289*8975f5c5SAndroid Build Coastguard Worker ){
290*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info = find_display (dpy);
291*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlSetAttributeAndGetStatusReq *req;
292*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlSetAttributeAndGetStatusReply rep;
293*8975f5c5SAndroid Build Coastguard Worker     Bool success;
294*8975f5c5SAndroid Build Coastguard Worker 
295*8975f5c5SAndroid Build Coastguard Worker     if(!XextHasExtension(info))
296*8975f5c5SAndroid Build Coastguard Worker         return False;
297*8975f5c5SAndroid Build Coastguard Worker 
298*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckExtension (dpy, info, False);
299*8975f5c5SAndroid Build Coastguard Worker 
300*8975f5c5SAndroid Build Coastguard Worker     LockDisplay (dpy);
301*8975f5c5SAndroid Build Coastguard Worker     GetReq (nvCtrlSetAttributeAndGetStatus, req);
302*8975f5c5SAndroid Build Coastguard Worker     req->reqType = info->codes->major_opcode;
303*8975f5c5SAndroid Build Coastguard Worker     req->nvReqType = X_nvCtrlSetAttributeAndGetStatus;
304*8975f5c5SAndroid Build Coastguard Worker     req->target_type = target_type;
305*8975f5c5SAndroid Build Coastguard Worker     req->target_id = target_id;
306*8975f5c5SAndroid Build Coastguard Worker     req->display_mask = display_mask;
307*8975f5c5SAndroid Build Coastguard Worker     req->attribute = attribute;
308*8975f5c5SAndroid Build Coastguard Worker     req->value = value;
309*8975f5c5SAndroid Build Coastguard Worker     if (!_XReply (dpy, (xReply *) &rep, 0, False)) {
310*8975f5c5SAndroid Build Coastguard Worker         UnlockDisplay (dpy);
311*8975f5c5SAndroid Build Coastguard Worker         SyncHandle ();
312*8975f5c5SAndroid Build Coastguard Worker         return False;
313*8975f5c5SAndroid Build Coastguard Worker     }
314*8975f5c5SAndroid Build Coastguard Worker     UnlockDisplay (dpy);
315*8975f5c5SAndroid Build Coastguard Worker     SyncHandle ();
316*8975f5c5SAndroid Build Coastguard Worker 
317*8975f5c5SAndroid Build Coastguard Worker     success = rep.flags;
318*8975f5c5SAndroid Build Coastguard Worker     return success;
319*8975f5c5SAndroid Build Coastguard Worker }
320*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLSetAttributeAndGetStatus(Display * dpy,int screen,unsigned int display_mask,unsigned int attribute,int value)321*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLSetAttributeAndGetStatus (
322*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
323*8975f5c5SAndroid Build Coastguard Worker     int screen,
324*8975f5c5SAndroid Build Coastguard Worker     unsigned int display_mask,
325*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
326*8975f5c5SAndroid Build Coastguard Worker     int value
327*8975f5c5SAndroid Build Coastguard Worker ){
328*8975f5c5SAndroid Build Coastguard Worker     return XNVCTRLSetTargetAttributeAndGetStatus(dpy,
329*8975f5c5SAndroid Build Coastguard Worker                                                  NV_CTRL_TARGET_TYPE_X_SCREEN,
330*8975f5c5SAndroid Build Coastguard Worker                                                  screen, display_mask,
331*8975f5c5SAndroid Build Coastguard Worker                                                  attribute, value);
332*8975f5c5SAndroid Build Coastguard Worker }
333*8975f5c5SAndroid Build Coastguard Worker 
334*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLQueryTargetAttribute(Display * dpy,int target_type,int target_id,unsigned int display_mask,unsigned int attribute,int * value)335*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLQueryTargetAttribute (
336*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
337*8975f5c5SAndroid Build Coastguard Worker     int target_type,
338*8975f5c5SAndroid Build Coastguard Worker     int target_id,
339*8975f5c5SAndroid Build Coastguard Worker     unsigned int display_mask,
340*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
341*8975f5c5SAndroid Build Coastguard Worker     int *value
342*8975f5c5SAndroid Build Coastguard Worker ){
343*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info = find_display (dpy);
344*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryAttributeReply rep;
345*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryAttributeReq   *req;
346*8975f5c5SAndroid Build Coastguard Worker     Bool exists;
347*8975f5c5SAndroid Build Coastguard Worker 
348*8975f5c5SAndroid Build Coastguard Worker     if(!XextHasExtension(info))
349*8975f5c5SAndroid Build Coastguard Worker         return False;
350*8975f5c5SAndroid Build Coastguard Worker 
351*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckExtension (dpy, info, False);
352*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckTargetData(dpy, info, &target_type, &target_id);
353*8975f5c5SAndroid Build Coastguard Worker 
354*8975f5c5SAndroid Build Coastguard Worker     LockDisplay (dpy);
355*8975f5c5SAndroid Build Coastguard Worker     GetReq (nvCtrlQueryAttribute, req);
356*8975f5c5SAndroid Build Coastguard Worker     req->reqType = info->codes->major_opcode;
357*8975f5c5SAndroid Build Coastguard Worker     req->nvReqType = X_nvCtrlQueryAttribute;
358*8975f5c5SAndroid Build Coastguard Worker     req->target_type = target_type;
359*8975f5c5SAndroid Build Coastguard Worker     req->target_id = target_id;
360*8975f5c5SAndroid Build Coastguard Worker     req->display_mask = display_mask;
361*8975f5c5SAndroid Build Coastguard Worker     req->attribute = attribute;
362*8975f5c5SAndroid Build Coastguard Worker     if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
363*8975f5c5SAndroid Build Coastguard Worker         UnlockDisplay (dpy);
364*8975f5c5SAndroid Build Coastguard Worker         SyncHandle ();
365*8975f5c5SAndroid Build Coastguard Worker         return False;
366*8975f5c5SAndroid Build Coastguard Worker     }
367*8975f5c5SAndroid Build Coastguard Worker     exists = rep.flags;
368*8975f5c5SAndroid Build Coastguard Worker     if (exists && value) *value = rep.value;
369*8975f5c5SAndroid Build Coastguard Worker     UnlockDisplay (dpy);
370*8975f5c5SAndroid Build Coastguard Worker     SyncHandle ();
371*8975f5c5SAndroid Build Coastguard Worker     return exists;
372*8975f5c5SAndroid Build Coastguard Worker }
373*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLQueryAttribute(Display * dpy,int screen,unsigned int display_mask,unsigned int attribute,int * value)374*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLQueryAttribute (
375*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
376*8975f5c5SAndroid Build Coastguard Worker     int screen,
377*8975f5c5SAndroid Build Coastguard Worker     unsigned int display_mask,
378*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
379*8975f5c5SAndroid Build Coastguard Worker     int *value
380*8975f5c5SAndroid Build Coastguard Worker ){
381*8975f5c5SAndroid Build Coastguard Worker     return XNVCTRLQueryTargetAttribute(dpy, NV_CTRL_TARGET_TYPE_X_SCREEN,
382*8975f5c5SAndroid Build Coastguard Worker                                        screen, display_mask, attribute, value);
383*8975f5c5SAndroid Build Coastguard Worker }
384*8975f5c5SAndroid Build Coastguard Worker 
385*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLQueryTargetAttribute64(Display * dpy,int target_type,int target_id,unsigned int display_mask,unsigned int attribute,int64_t * value)386*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLQueryTargetAttribute64 (
387*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
388*8975f5c5SAndroid Build Coastguard Worker     int target_type,
389*8975f5c5SAndroid Build Coastguard Worker     int target_id,
390*8975f5c5SAndroid Build Coastguard Worker     unsigned int display_mask,
391*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
392*8975f5c5SAndroid Build Coastguard Worker     int64_t *value
393*8975f5c5SAndroid Build Coastguard Worker ){
394*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info = find_display(dpy);
395*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryAttribute64Reply rep;
396*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryAttributeReq *req;
397*8975f5c5SAndroid Build Coastguard Worker     Bool exists;
398*8975f5c5SAndroid Build Coastguard Worker 
399*8975f5c5SAndroid Build Coastguard Worker     if (!XextHasExtension(info))
400*8975f5c5SAndroid Build Coastguard Worker         return False;
401*8975f5c5SAndroid Build Coastguard Worker 
402*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckExtension(dpy, info, False);
403*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckTargetData(dpy, info, &target_type, &target_id);
404*8975f5c5SAndroid Build Coastguard Worker 
405*8975f5c5SAndroid Build Coastguard Worker     LockDisplay(dpy);
406*8975f5c5SAndroid Build Coastguard Worker     GetReq(nvCtrlQueryAttribute, req);
407*8975f5c5SAndroid Build Coastguard Worker     req->reqType = info->codes->major_opcode;
408*8975f5c5SAndroid Build Coastguard Worker     req->nvReqType = X_nvCtrlQueryAttribute64;
409*8975f5c5SAndroid Build Coastguard Worker     req->target_type = target_type;
410*8975f5c5SAndroid Build Coastguard Worker     req->target_id = target_id;
411*8975f5c5SAndroid Build Coastguard Worker     req->display_mask = display_mask;
412*8975f5c5SAndroid Build Coastguard Worker     req->attribute = attribute;
413*8975f5c5SAndroid Build Coastguard Worker     if (!_XReply(dpy, (xReply *)&rep, 0, xTrue)) {
414*8975f5c5SAndroid Build Coastguard Worker         UnlockDisplay(dpy);
415*8975f5c5SAndroid Build Coastguard Worker         SyncHandle();
416*8975f5c5SAndroid Build Coastguard Worker         return False;
417*8975f5c5SAndroid Build Coastguard Worker     }
418*8975f5c5SAndroid Build Coastguard Worker     exists = rep.flags;
419*8975f5c5SAndroid Build Coastguard Worker     if (exists && value) *value = rep.value_64;
420*8975f5c5SAndroid Build Coastguard Worker     UnlockDisplay(dpy);
421*8975f5c5SAndroid Build Coastguard Worker     SyncHandle();
422*8975f5c5SAndroid Build Coastguard Worker     return exists;
423*8975f5c5SAndroid Build Coastguard Worker }
424*8975f5c5SAndroid Build Coastguard Worker 
425*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLQueryTargetStringAttribute(Display * dpy,int target_type,int target_id,unsigned int display_mask,unsigned int attribute,char ** ptr)426*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLQueryTargetStringAttribute (
427*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
428*8975f5c5SAndroid Build Coastguard Worker     int target_type,
429*8975f5c5SAndroid Build Coastguard Worker     int target_id,
430*8975f5c5SAndroid Build Coastguard Worker     unsigned int display_mask,
431*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
432*8975f5c5SAndroid Build Coastguard Worker     char **ptr
433*8975f5c5SAndroid Build Coastguard Worker ){
434*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info = find_display (dpy);
435*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryStringAttributeReply rep;
436*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryStringAttributeReq   *req;
437*8975f5c5SAndroid Build Coastguard Worker     Bool exists;
438*8975f5c5SAndroid Build Coastguard Worker     int length, numbytes, slop;
439*8975f5c5SAndroid Build Coastguard Worker 
440*8975f5c5SAndroid Build Coastguard Worker     if (!ptr) return False;
441*8975f5c5SAndroid Build Coastguard Worker 
442*8975f5c5SAndroid Build Coastguard Worker     if(!XextHasExtension(info))
443*8975f5c5SAndroid Build Coastguard Worker         return False;
444*8975f5c5SAndroid Build Coastguard Worker 
445*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckExtension (dpy, info, False);
446*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckTargetData(dpy, info, &target_type, &target_id);
447*8975f5c5SAndroid Build Coastguard Worker 
448*8975f5c5SAndroid Build Coastguard Worker     LockDisplay (dpy);
449*8975f5c5SAndroid Build Coastguard Worker     GetReq (nvCtrlQueryStringAttribute, req);
450*8975f5c5SAndroid Build Coastguard Worker     req->reqType = info->codes->major_opcode;
451*8975f5c5SAndroid Build Coastguard Worker     req->nvReqType = X_nvCtrlQueryStringAttribute;
452*8975f5c5SAndroid Build Coastguard Worker     req->target_type = target_type;
453*8975f5c5SAndroid Build Coastguard Worker     req->target_id = target_id;
454*8975f5c5SAndroid Build Coastguard Worker     req->display_mask = display_mask;
455*8975f5c5SAndroid Build Coastguard Worker     req->attribute = attribute;
456*8975f5c5SAndroid Build Coastguard Worker     if (!_XReply (dpy, (xReply *) &rep, 0, False)) {
457*8975f5c5SAndroid Build Coastguard Worker         UnlockDisplay (dpy);
458*8975f5c5SAndroid Build Coastguard Worker         SyncHandle ();
459*8975f5c5SAndroid Build Coastguard Worker         return False;
460*8975f5c5SAndroid Build Coastguard Worker     }
461*8975f5c5SAndroid Build Coastguard Worker     length = rep.length;
462*8975f5c5SAndroid Build Coastguard Worker     numbytes = rep.n;
463*8975f5c5SAndroid Build Coastguard Worker     slop = numbytes & 3;
464*8975f5c5SAndroid Build Coastguard Worker     exists = rep.flags;
465*8975f5c5SAndroid Build Coastguard Worker     if (exists) {
466*8975f5c5SAndroid Build Coastguard Worker         *ptr = (char *) Xmalloc(numbytes);
467*8975f5c5SAndroid Build Coastguard Worker     }
468*8975f5c5SAndroid Build Coastguard Worker     if (!exists || !*ptr) {
469*8975f5c5SAndroid Build Coastguard Worker         _XEatData(dpy, length);
470*8975f5c5SAndroid Build Coastguard Worker         UnlockDisplay (dpy);
471*8975f5c5SAndroid Build Coastguard Worker         SyncHandle ();
472*8975f5c5SAndroid Build Coastguard Worker         return False;
473*8975f5c5SAndroid Build Coastguard Worker     } else {
474*8975f5c5SAndroid Build Coastguard Worker         _XRead(dpy, (char *) *ptr, numbytes);
475*8975f5c5SAndroid Build Coastguard Worker         if (slop) _XEatData(dpy, 4-slop);
476*8975f5c5SAndroid Build Coastguard Worker     }
477*8975f5c5SAndroid Build Coastguard Worker     UnlockDisplay (dpy);
478*8975f5c5SAndroid Build Coastguard Worker     SyncHandle ();
479*8975f5c5SAndroid Build Coastguard Worker     return exists;
480*8975f5c5SAndroid Build Coastguard Worker }
481*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLQueryStringAttribute(Display * dpy,int screen,unsigned int display_mask,unsigned int attribute,char ** ptr)482*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLQueryStringAttribute (
483*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
484*8975f5c5SAndroid Build Coastguard Worker     int screen,
485*8975f5c5SAndroid Build Coastguard Worker     unsigned int display_mask,
486*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
487*8975f5c5SAndroid Build Coastguard Worker     char **ptr
488*8975f5c5SAndroid Build Coastguard Worker ){
489*8975f5c5SAndroid Build Coastguard Worker     return XNVCTRLQueryTargetStringAttribute(dpy, NV_CTRL_TARGET_TYPE_X_SCREEN,
490*8975f5c5SAndroid Build Coastguard Worker                                              screen, display_mask,
491*8975f5c5SAndroid Build Coastguard Worker                                              attribute, ptr);
492*8975f5c5SAndroid Build Coastguard Worker }
493*8975f5c5SAndroid Build Coastguard Worker 
494*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLSetTargetStringAttribute(Display * dpy,int target_type,int target_id,unsigned int display_mask,unsigned int attribute,char * ptr)495*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLSetTargetStringAttribute (
496*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
497*8975f5c5SAndroid Build Coastguard Worker     int target_type,
498*8975f5c5SAndroid Build Coastguard Worker     int target_id,
499*8975f5c5SAndroid Build Coastguard Worker     unsigned int display_mask,
500*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
501*8975f5c5SAndroid Build Coastguard Worker     char *ptr
502*8975f5c5SAndroid Build Coastguard Worker ){
503*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info = find_display (dpy);
504*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlSetStringAttributeReq *req;
505*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlSetStringAttributeReply rep;
506*8975f5c5SAndroid Build Coastguard Worker     int size;
507*8975f5c5SAndroid Build Coastguard Worker     Bool success;
508*8975f5c5SAndroid Build Coastguard Worker 
509*8975f5c5SAndroid Build Coastguard Worker     if(!XextHasExtension(info))
510*8975f5c5SAndroid Build Coastguard Worker         return False;
511*8975f5c5SAndroid Build Coastguard Worker 
512*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckExtension (dpy, info, False);
513*8975f5c5SAndroid Build Coastguard Worker 
514*8975f5c5SAndroid Build Coastguard Worker     size = strlen(ptr)+1;
515*8975f5c5SAndroid Build Coastguard Worker 
516*8975f5c5SAndroid Build Coastguard Worker     LockDisplay (dpy);
517*8975f5c5SAndroid Build Coastguard Worker     GetReq (nvCtrlSetStringAttribute, req);
518*8975f5c5SAndroid Build Coastguard Worker     req->reqType = info->codes->major_opcode;
519*8975f5c5SAndroid Build Coastguard Worker     req->nvReqType = X_nvCtrlSetStringAttribute;
520*8975f5c5SAndroid Build Coastguard Worker     req->target_type = target_type;
521*8975f5c5SAndroid Build Coastguard Worker     req->target_id = target_id;
522*8975f5c5SAndroid Build Coastguard Worker     req->display_mask = display_mask;
523*8975f5c5SAndroid Build Coastguard Worker     req->attribute = attribute;
524*8975f5c5SAndroid Build Coastguard Worker     req->length += ((size + 3) & ~3) >> 2;
525*8975f5c5SAndroid Build Coastguard Worker     req->num_bytes = size;
526*8975f5c5SAndroid Build Coastguard Worker     Data(dpy, ptr, size);
527*8975f5c5SAndroid Build Coastguard Worker 
528*8975f5c5SAndroid Build Coastguard Worker     if (!_XReply (dpy, (xReply *) &rep, 0, False)) {
529*8975f5c5SAndroid Build Coastguard Worker         UnlockDisplay (dpy);
530*8975f5c5SAndroid Build Coastguard Worker         SyncHandle ();
531*8975f5c5SAndroid Build Coastguard Worker         return False;
532*8975f5c5SAndroid Build Coastguard Worker     }
533*8975f5c5SAndroid Build Coastguard Worker     UnlockDisplay (dpy);
534*8975f5c5SAndroid Build Coastguard Worker     SyncHandle ();
535*8975f5c5SAndroid Build Coastguard Worker 
536*8975f5c5SAndroid Build Coastguard Worker     success = rep.flags;
537*8975f5c5SAndroid Build Coastguard Worker     return success;
538*8975f5c5SAndroid Build Coastguard Worker }
539*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLSetStringAttribute(Display * dpy,int screen,unsigned int display_mask,unsigned int attribute,char * ptr)540*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLSetStringAttribute (
541*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
542*8975f5c5SAndroid Build Coastguard Worker     int screen,
543*8975f5c5SAndroid Build Coastguard Worker     unsigned int display_mask,
544*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
545*8975f5c5SAndroid Build Coastguard Worker     char *ptr
546*8975f5c5SAndroid Build Coastguard Worker ){
547*8975f5c5SAndroid Build Coastguard Worker     return XNVCTRLSetTargetStringAttribute(dpy, NV_CTRL_TARGET_TYPE_X_SCREEN,
548*8975f5c5SAndroid Build Coastguard Worker                                            screen, display_mask,
549*8975f5c5SAndroid Build Coastguard Worker                                            attribute, ptr);
550*8975f5c5SAndroid Build Coastguard Worker }
551*8975f5c5SAndroid Build Coastguard Worker 
552*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLQueryValidTargetAttributeValues32(Display * dpy,XExtDisplayInfo * info,int target_type,int target_id,unsigned int display_mask,unsigned int attribute,NVCTRLAttributeValidValuesRec * values)553*8975f5c5SAndroid Build Coastguard Worker static Bool XNVCTRLQueryValidTargetAttributeValues32 (
554*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
555*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info,
556*8975f5c5SAndroid Build Coastguard Worker     int target_type,
557*8975f5c5SAndroid Build Coastguard Worker     int target_id,
558*8975f5c5SAndroid Build Coastguard Worker     unsigned int display_mask,
559*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
560*8975f5c5SAndroid Build Coastguard Worker     NVCTRLAttributeValidValuesRec *values
561*8975f5c5SAndroid Build Coastguard Worker ){
562*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryValidAttributeValuesReply rep;
563*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryValidAttributeValuesReq   *req;
564*8975f5c5SAndroid Build Coastguard Worker     Bool exists;
565*8975f5c5SAndroid Build Coastguard Worker 
566*8975f5c5SAndroid Build Coastguard Worker     LockDisplay (dpy);
567*8975f5c5SAndroid Build Coastguard Worker     GetReq (nvCtrlQueryValidAttributeValues, req);
568*8975f5c5SAndroid Build Coastguard Worker     req->reqType = info->codes->major_opcode;
569*8975f5c5SAndroid Build Coastguard Worker     req->nvReqType = X_nvCtrlQueryValidAttributeValues;
570*8975f5c5SAndroid Build Coastguard Worker     req->target_type = target_type;
571*8975f5c5SAndroid Build Coastguard Worker     req->target_id = target_id;
572*8975f5c5SAndroid Build Coastguard Worker     req->display_mask = display_mask;
573*8975f5c5SAndroid Build Coastguard Worker     req->attribute = attribute;
574*8975f5c5SAndroid Build Coastguard Worker     if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
575*8975f5c5SAndroid Build Coastguard Worker         UnlockDisplay (dpy);
576*8975f5c5SAndroid Build Coastguard Worker         SyncHandle ();
577*8975f5c5SAndroid Build Coastguard Worker         return False;
578*8975f5c5SAndroid Build Coastguard Worker     }
579*8975f5c5SAndroid Build Coastguard Worker     exists = rep.flags;
580*8975f5c5SAndroid Build Coastguard Worker     if (exists) {
581*8975f5c5SAndroid Build Coastguard Worker         values->type = rep.attr_type;
582*8975f5c5SAndroid Build Coastguard Worker         if (rep.attr_type == ATTRIBUTE_TYPE_RANGE) {
583*8975f5c5SAndroid Build Coastguard Worker             values->u.range.min = rep.min;
584*8975f5c5SAndroid Build Coastguard Worker             values->u.range.max = rep.max;
585*8975f5c5SAndroid Build Coastguard Worker         }
586*8975f5c5SAndroid Build Coastguard Worker         if (rep.attr_type == ATTRIBUTE_TYPE_INT_BITS) {
587*8975f5c5SAndroid Build Coastguard Worker             values->u.bits.ints = rep.bits;
588*8975f5c5SAndroid Build Coastguard Worker         }
589*8975f5c5SAndroid Build Coastguard Worker         values->permissions = rep.perms;
590*8975f5c5SAndroid Build Coastguard Worker     }
591*8975f5c5SAndroid Build Coastguard Worker     UnlockDisplay (dpy);
592*8975f5c5SAndroid Build Coastguard Worker     SyncHandle ();
593*8975f5c5SAndroid Build Coastguard Worker     return exists;
594*8975f5c5SAndroid Build Coastguard Worker }
595*8975f5c5SAndroid Build Coastguard Worker 
596*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLQueryValidTargetStringAttributeValues(Display * dpy,int target_type,int target_id,unsigned int display_mask,unsigned int attribute,NVCTRLAttributeValidValuesRec * values)597*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLQueryValidTargetStringAttributeValues (
598*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
599*8975f5c5SAndroid Build Coastguard Worker     int target_type,
600*8975f5c5SAndroid Build Coastguard Worker     int target_id,
601*8975f5c5SAndroid Build Coastguard Worker     unsigned int display_mask,
602*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
603*8975f5c5SAndroid Build Coastguard Worker     NVCTRLAttributeValidValuesRec *values
604*8975f5c5SAndroid Build Coastguard Worker ){
605*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info = find_display(dpy);
606*8975f5c5SAndroid Build Coastguard Worker     Bool exists;
607*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryValidAttributeValuesReply rep;
608*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryValidAttributeValuesReq   *req;
609*8975f5c5SAndroid Build Coastguard Worker 
610*8975f5c5SAndroid Build Coastguard Worker     if (!values) return False;
611*8975f5c5SAndroid Build Coastguard Worker 
612*8975f5c5SAndroid Build Coastguard Worker     if (!XextHasExtension(info))
613*8975f5c5SAndroid Build Coastguard Worker         return False;
614*8975f5c5SAndroid Build Coastguard Worker 
615*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckExtension(dpy, info, False);
616*8975f5c5SAndroid Build Coastguard Worker 
617*8975f5c5SAndroid Build Coastguard Worker     LockDisplay(dpy);
618*8975f5c5SAndroid Build Coastguard Worker     GetReq (nvCtrlQueryValidAttributeValues, req);
619*8975f5c5SAndroid Build Coastguard Worker     req->reqType = info->codes->major_opcode;
620*8975f5c5SAndroid Build Coastguard Worker     req->nvReqType = X_nvCtrlQueryValidStringAttributeValues;
621*8975f5c5SAndroid Build Coastguard Worker     req->target_type = target_type;
622*8975f5c5SAndroid Build Coastguard Worker     req->target_id = target_id;
623*8975f5c5SAndroid Build Coastguard Worker     req->display_mask = display_mask;
624*8975f5c5SAndroid Build Coastguard Worker     req->attribute = attribute;
625*8975f5c5SAndroid Build Coastguard Worker     if (!_XReply(dpy, (xReply *)&rep, 0, xTrue)) {
626*8975f5c5SAndroid Build Coastguard Worker         UnlockDisplay(dpy);
627*8975f5c5SAndroid Build Coastguard Worker         SyncHandle();
628*8975f5c5SAndroid Build Coastguard Worker         return False;
629*8975f5c5SAndroid Build Coastguard Worker     }
630*8975f5c5SAndroid Build Coastguard Worker     exists = rep.flags;
631*8975f5c5SAndroid Build Coastguard Worker     if (exists) {
632*8975f5c5SAndroid Build Coastguard Worker         values->type = rep.attr_type;
633*8975f5c5SAndroid Build Coastguard Worker         values->permissions = rep.perms;
634*8975f5c5SAndroid Build Coastguard Worker     }
635*8975f5c5SAndroid Build Coastguard Worker     UnlockDisplay(dpy);
636*8975f5c5SAndroid Build Coastguard Worker     SyncHandle();
637*8975f5c5SAndroid Build Coastguard Worker     return exists;
638*8975f5c5SAndroid Build Coastguard Worker }
639*8975f5c5SAndroid Build Coastguard Worker 
640*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLQueryValidTargetAttributeValues64(Display * dpy,XExtDisplayInfo * info,int target_type,int target_id,unsigned int display_mask,unsigned int attribute,NVCTRLAttributeValidValuesRec * values)641*8975f5c5SAndroid Build Coastguard Worker static Bool XNVCTRLQueryValidTargetAttributeValues64 (
642*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
643*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info,
644*8975f5c5SAndroid Build Coastguard Worker     int target_type,
645*8975f5c5SAndroid Build Coastguard Worker     int target_id,
646*8975f5c5SAndroid Build Coastguard Worker     unsigned int display_mask,
647*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
648*8975f5c5SAndroid Build Coastguard Worker     NVCTRLAttributeValidValuesRec *values
649*8975f5c5SAndroid Build Coastguard Worker ){
650*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryValidAttributeValues64Reply rep;
651*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryValidAttributeValuesReq *req;
652*8975f5c5SAndroid Build Coastguard Worker     Bool exists;
653*8975f5c5SAndroid Build Coastguard Worker 
654*8975f5c5SAndroid Build Coastguard Worker     LockDisplay(dpy);
655*8975f5c5SAndroid Build Coastguard Worker     GetReq(nvCtrlQueryValidAttributeValues, req);
656*8975f5c5SAndroid Build Coastguard Worker     req->reqType = info->codes->major_opcode;
657*8975f5c5SAndroid Build Coastguard Worker     req->nvReqType = X_nvCtrlQueryValidAttributeValues64;
658*8975f5c5SAndroid Build Coastguard Worker     req->target_type = target_type;
659*8975f5c5SAndroid Build Coastguard Worker     req->target_id = target_id;
660*8975f5c5SAndroid Build Coastguard Worker     req->display_mask = display_mask;
661*8975f5c5SAndroid Build Coastguard Worker     req->attribute = attribute;
662*8975f5c5SAndroid Build Coastguard Worker     if (!_XReply(dpy, (xReply *)&rep,
663*8975f5c5SAndroid Build Coastguard Worker                  sz_xnvCtrlQueryValidAttributeValues64Reply_extra,
664*8975f5c5SAndroid Build Coastguard Worker                  xTrue)) {
665*8975f5c5SAndroid Build Coastguard Worker         UnlockDisplay(dpy);
666*8975f5c5SAndroid Build Coastguard Worker         SyncHandle();
667*8975f5c5SAndroid Build Coastguard Worker         return False;
668*8975f5c5SAndroid Build Coastguard Worker     }
669*8975f5c5SAndroid Build Coastguard Worker     exists = rep.flags;
670*8975f5c5SAndroid Build Coastguard Worker     if (exists) {
671*8975f5c5SAndroid Build Coastguard Worker         values->type = rep.attr_type;
672*8975f5c5SAndroid Build Coastguard Worker         if (rep.attr_type == ATTRIBUTE_TYPE_RANGE) {
673*8975f5c5SAndroid Build Coastguard Worker             values->u.range.min = rep.min_64;
674*8975f5c5SAndroid Build Coastguard Worker             values->u.range.max = rep.max_64;
675*8975f5c5SAndroid Build Coastguard Worker         }
676*8975f5c5SAndroid Build Coastguard Worker         if (rep.attr_type == ATTRIBUTE_TYPE_INT_BITS) {
677*8975f5c5SAndroid Build Coastguard Worker             values->u.bits.ints = rep.bits_64;
678*8975f5c5SAndroid Build Coastguard Worker         }
679*8975f5c5SAndroid Build Coastguard Worker         values->permissions = rep.perms;
680*8975f5c5SAndroid Build Coastguard Worker     }
681*8975f5c5SAndroid Build Coastguard Worker     UnlockDisplay(dpy);
682*8975f5c5SAndroid Build Coastguard Worker     SyncHandle();
683*8975f5c5SAndroid Build Coastguard Worker     return exists;
684*8975f5c5SAndroid Build Coastguard Worker }
685*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLQueryValidTargetAttributeValues(Display * dpy,int target_type,int target_id,unsigned int display_mask,unsigned int attribute,NVCTRLAttributeValidValuesRec * values)686*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLQueryValidTargetAttributeValues (
687*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
688*8975f5c5SAndroid Build Coastguard Worker     int target_type,
689*8975f5c5SAndroid Build Coastguard Worker     int target_id,
690*8975f5c5SAndroid Build Coastguard Worker     unsigned int display_mask,
691*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
692*8975f5c5SAndroid Build Coastguard Worker     NVCTRLAttributeValidValuesRec *values
693*8975f5c5SAndroid Build Coastguard Worker ){
694*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info = find_display(dpy);
695*8975f5c5SAndroid Build Coastguard Worker     Bool exists;
696*8975f5c5SAndroid Build Coastguard Worker     uintptr_t flags;
697*8975f5c5SAndroid Build Coastguard Worker 
698*8975f5c5SAndroid Build Coastguard Worker     if (!values) return False;
699*8975f5c5SAndroid Build Coastguard Worker 
700*8975f5c5SAndroid Build Coastguard Worker     if (!XextHasExtension(info))
701*8975f5c5SAndroid Build Coastguard Worker         return False;
702*8975f5c5SAndroid Build Coastguard Worker 
703*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckExtension(dpy, info, False);
704*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckTargetData(dpy, info, &target_type, &target_id);
705*8975f5c5SAndroid Build Coastguard Worker 
706*8975f5c5SAndroid Build Coastguard Worker     flags = version_flags(dpy,info);
707*8975f5c5SAndroid Build Coastguard Worker 
708*8975f5c5SAndroid Build Coastguard Worker     if (!(flags & NVCTRL_EXT_EXISTS))
709*8975f5c5SAndroid Build Coastguard Worker         return False;
710*8975f5c5SAndroid Build Coastguard Worker 
711*8975f5c5SAndroid Build Coastguard Worker     if (flags & NVCTRL_EXT_64_BIT_ATTRIBUTES) {
712*8975f5c5SAndroid Build Coastguard Worker         exists = XNVCTRLQueryValidTargetAttributeValues64(dpy, info,
713*8975f5c5SAndroid Build Coastguard Worker                                                           target_type,
714*8975f5c5SAndroid Build Coastguard Worker                                                           target_id,
715*8975f5c5SAndroid Build Coastguard Worker                                                           display_mask,
716*8975f5c5SAndroid Build Coastguard Worker                                                           attribute,
717*8975f5c5SAndroid Build Coastguard Worker                                                           values);
718*8975f5c5SAndroid Build Coastguard Worker     } else {
719*8975f5c5SAndroid Build Coastguard Worker         exists = XNVCTRLQueryValidTargetAttributeValues32(dpy, info,
720*8975f5c5SAndroid Build Coastguard Worker                                                           target_type,
721*8975f5c5SAndroid Build Coastguard Worker                                                           target_id,
722*8975f5c5SAndroid Build Coastguard Worker                                                           display_mask,
723*8975f5c5SAndroid Build Coastguard Worker                                                           attribute,
724*8975f5c5SAndroid Build Coastguard Worker                                                           values);
725*8975f5c5SAndroid Build Coastguard Worker     }
726*8975f5c5SAndroid Build Coastguard Worker     return exists;
727*8975f5c5SAndroid Build Coastguard Worker }
728*8975f5c5SAndroid Build Coastguard Worker 
729*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLQueryValidAttributeValues(Display * dpy,int screen,unsigned int display_mask,unsigned int attribute,NVCTRLAttributeValidValuesRec * values)730*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLQueryValidAttributeValues (
731*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
732*8975f5c5SAndroid Build Coastguard Worker     int screen,
733*8975f5c5SAndroid Build Coastguard Worker     unsigned int display_mask,
734*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
735*8975f5c5SAndroid Build Coastguard Worker     NVCTRLAttributeValidValuesRec *values
736*8975f5c5SAndroid Build Coastguard Worker ){
737*8975f5c5SAndroid Build Coastguard Worker     return XNVCTRLQueryValidTargetAttributeValues(dpy,
738*8975f5c5SAndroid Build Coastguard Worker                                                   NV_CTRL_TARGET_TYPE_X_SCREEN,
739*8975f5c5SAndroid Build Coastguard Worker                                                   screen, display_mask,
740*8975f5c5SAndroid Build Coastguard Worker                                                   attribute, values);
741*8975f5c5SAndroid Build Coastguard Worker }
742*8975f5c5SAndroid Build Coastguard Worker 
743*8975f5c5SAndroid Build Coastguard Worker 
QueryAttributePermissionsInternal(Display * dpy,unsigned int attribute,NVCTRLAttributePermissionsRec * permissions,unsigned int reqType)744*8975f5c5SAndroid Build Coastguard Worker static Bool QueryAttributePermissionsInternal (
745*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
746*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
747*8975f5c5SAndroid Build Coastguard Worker     NVCTRLAttributePermissionsRec *permissions,
748*8975f5c5SAndroid Build Coastguard Worker     unsigned int reqType
749*8975f5c5SAndroid Build Coastguard Worker ){
750*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info = find_display (dpy);
751*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryAttributePermissionsReply rep;
752*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryAttributePermissionsReq *req;
753*8975f5c5SAndroid Build Coastguard Worker     Bool exists;
754*8975f5c5SAndroid Build Coastguard Worker 
755*8975f5c5SAndroid Build Coastguard Worker     if(!XextHasExtension(info))
756*8975f5c5SAndroid Build Coastguard Worker         return False;
757*8975f5c5SAndroid Build Coastguard Worker 
758*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckExtension (dpy, info, False);
759*8975f5c5SAndroid Build Coastguard Worker 
760*8975f5c5SAndroid Build Coastguard Worker     LockDisplay(dpy);
761*8975f5c5SAndroid Build Coastguard Worker     GetReq(nvCtrlQueryAttributePermissions, req);
762*8975f5c5SAndroid Build Coastguard Worker     req->reqType = info->codes->major_opcode;
763*8975f5c5SAndroid Build Coastguard Worker     req->nvReqType = reqType;
764*8975f5c5SAndroid Build Coastguard Worker     req->attribute = attribute;
765*8975f5c5SAndroid Build Coastguard Worker     if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
766*8975f5c5SAndroid Build Coastguard Worker         UnlockDisplay (dpy);
767*8975f5c5SAndroid Build Coastguard Worker         SyncHandle();
768*8975f5c5SAndroid Build Coastguard Worker         return False;
769*8975f5c5SAndroid Build Coastguard Worker     }
770*8975f5c5SAndroid Build Coastguard Worker     exists = rep.flags;
771*8975f5c5SAndroid Build Coastguard Worker     if (exists && permissions) {
772*8975f5c5SAndroid Build Coastguard Worker         permissions->type = rep.attr_type;
773*8975f5c5SAndroid Build Coastguard Worker         permissions->permissions = rep.perms;
774*8975f5c5SAndroid Build Coastguard Worker     }
775*8975f5c5SAndroid Build Coastguard Worker     UnlockDisplay(dpy);
776*8975f5c5SAndroid Build Coastguard Worker     SyncHandle();
777*8975f5c5SAndroid Build Coastguard Worker     return exists;
778*8975f5c5SAndroid Build Coastguard Worker }
779*8975f5c5SAndroid Build Coastguard Worker 
780*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLQueryAttributePermissions(Display * dpy,unsigned int attribute,NVCTRLAttributePermissionsRec * permissions)781*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLQueryAttributePermissions (
782*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
783*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
784*8975f5c5SAndroid Build Coastguard Worker     NVCTRLAttributePermissionsRec *permissions
785*8975f5c5SAndroid Build Coastguard Worker ){
786*8975f5c5SAndroid Build Coastguard Worker     return QueryAttributePermissionsInternal(dpy,
787*8975f5c5SAndroid Build Coastguard Worker                                              attribute,
788*8975f5c5SAndroid Build Coastguard Worker                                              permissions,
789*8975f5c5SAndroid Build Coastguard Worker                                              X_nvCtrlQueryAttributePermissions);
790*8975f5c5SAndroid Build Coastguard Worker }
791*8975f5c5SAndroid Build Coastguard Worker 
792*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLQueryStringAttributePermissions(Display * dpy,unsigned int attribute,NVCTRLAttributePermissionsRec * permissions)793*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLQueryStringAttributePermissions (
794*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
795*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
796*8975f5c5SAndroid Build Coastguard Worker     NVCTRLAttributePermissionsRec *permissions
797*8975f5c5SAndroid Build Coastguard Worker ){
798*8975f5c5SAndroid Build Coastguard Worker     return QueryAttributePermissionsInternal(dpy,
799*8975f5c5SAndroid Build Coastguard Worker                                              attribute,
800*8975f5c5SAndroid Build Coastguard Worker                                              permissions,
801*8975f5c5SAndroid Build Coastguard Worker                                              X_nvCtrlQueryStringAttributePermissions);
802*8975f5c5SAndroid Build Coastguard Worker }
803*8975f5c5SAndroid Build Coastguard Worker 
804*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLQueryBinaryDataAttributePermissions(Display * dpy,unsigned int attribute,NVCTRLAttributePermissionsRec * permissions)805*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLQueryBinaryDataAttributePermissions (
806*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
807*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
808*8975f5c5SAndroid Build Coastguard Worker     NVCTRLAttributePermissionsRec *permissions
809*8975f5c5SAndroid Build Coastguard Worker ){
810*8975f5c5SAndroid Build Coastguard Worker     return QueryAttributePermissionsInternal(dpy,
811*8975f5c5SAndroid Build Coastguard Worker                                              attribute,
812*8975f5c5SAndroid Build Coastguard Worker                                              permissions,
813*8975f5c5SAndroid Build Coastguard Worker                                              X_nvCtrlQueryBinaryDataAttributePermissions);
814*8975f5c5SAndroid Build Coastguard Worker }
815*8975f5c5SAndroid Build Coastguard Worker 
816*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLQueryStringOperationAttributePermissions(Display * dpy,unsigned int attribute,NVCTRLAttributePermissionsRec * permissions)817*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLQueryStringOperationAttributePermissions (
818*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
819*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
820*8975f5c5SAndroid Build Coastguard Worker     NVCTRLAttributePermissionsRec *permissions
821*8975f5c5SAndroid Build Coastguard Worker ){
822*8975f5c5SAndroid Build Coastguard Worker     return QueryAttributePermissionsInternal(dpy,
823*8975f5c5SAndroid Build Coastguard Worker                                              attribute,
824*8975f5c5SAndroid Build Coastguard Worker                                              permissions,
825*8975f5c5SAndroid Build Coastguard Worker                                              X_nvCtrlQueryStringOperationAttributePermissions);
826*8975f5c5SAndroid Build Coastguard Worker }
827*8975f5c5SAndroid Build Coastguard Worker 
828*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLSetGvoColorConversion(Display * dpy,int screen,float colorMatrix[3][3],float colorOffset[3],float colorScale[3])829*8975f5c5SAndroid Build Coastguard Worker void XNVCTRLSetGvoColorConversion (
830*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
831*8975f5c5SAndroid Build Coastguard Worker     int screen,
832*8975f5c5SAndroid Build Coastguard Worker     float colorMatrix[3][3],
833*8975f5c5SAndroid Build Coastguard Worker     float colorOffset[3],
834*8975f5c5SAndroid Build Coastguard Worker     float colorScale[3]
835*8975f5c5SAndroid Build Coastguard Worker ){
836*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info = find_display (dpy);
837*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlSetGvoColorConversionReq *req;
838*8975f5c5SAndroid Build Coastguard Worker 
839*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLSimpleCheckExtension (dpy, info);
840*8975f5c5SAndroid Build Coastguard Worker 
841*8975f5c5SAndroid Build Coastguard Worker     LockDisplay (dpy);
842*8975f5c5SAndroid Build Coastguard Worker     GetReq (nvCtrlSetGvoColorConversion, req);
843*8975f5c5SAndroid Build Coastguard Worker     req->reqType = info->codes->major_opcode;
844*8975f5c5SAndroid Build Coastguard Worker     req->nvReqType = X_nvCtrlSetGvoColorConversion;
845*8975f5c5SAndroid Build Coastguard Worker     req->screen = screen;
846*8975f5c5SAndroid Build Coastguard Worker 
847*8975f5c5SAndroid Build Coastguard Worker     req->cscMatrix_y_r = colorMatrix[0][0];
848*8975f5c5SAndroid Build Coastguard Worker     req->cscMatrix_y_g = colorMatrix[0][1];
849*8975f5c5SAndroid Build Coastguard Worker     req->cscMatrix_y_b = colorMatrix[0][2];
850*8975f5c5SAndroid Build Coastguard Worker 
851*8975f5c5SAndroid Build Coastguard Worker     req->cscMatrix_cr_r = colorMatrix[1][0];
852*8975f5c5SAndroid Build Coastguard Worker     req->cscMatrix_cr_g = colorMatrix[1][1];
853*8975f5c5SAndroid Build Coastguard Worker     req->cscMatrix_cr_b = colorMatrix[1][2];
854*8975f5c5SAndroid Build Coastguard Worker 
855*8975f5c5SAndroid Build Coastguard Worker     req->cscMatrix_cb_r = colorMatrix[2][0];
856*8975f5c5SAndroid Build Coastguard Worker     req->cscMatrix_cb_g = colorMatrix[2][1];
857*8975f5c5SAndroid Build Coastguard Worker     req->cscMatrix_cb_b = colorMatrix[2][2];
858*8975f5c5SAndroid Build Coastguard Worker 
859*8975f5c5SAndroid Build Coastguard Worker     req->cscOffset_y  = colorOffset[0];
860*8975f5c5SAndroid Build Coastguard Worker     req->cscOffset_cr = colorOffset[1];
861*8975f5c5SAndroid Build Coastguard Worker     req->cscOffset_cb = colorOffset[2];
862*8975f5c5SAndroid Build Coastguard Worker 
863*8975f5c5SAndroid Build Coastguard Worker     req->cscScale_y  = colorScale[0];
864*8975f5c5SAndroid Build Coastguard Worker     req->cscScale_cr = colorScale[1];
865*8975f5c5SAndroid Build Coastguard Worker     req->cscScale_cb = colorScale[2];
866*8975f5c5SAndroid Build Coastguard Worker 
867*8975f5c5SAndroid Build Coastguard Worker     UnlockDisplay (dpy);
868*8975f5c5SAndroid Build Coastguard Worker     SyncHandle ();
869*8975f5c5SAndroid Build Coastguard Worker }
870*8975f5c5SAndroid Build Coastguard Worker 
871*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLQueryGvoColorConversion(Display * dpy,int screen,float colorMatrix[3][3],float colorOffset[3],float colorScale[3])872*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLQueryGvoColorConversion (
873*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
874*8975f5c5SAndroid Build Coastguard Worker     int screen,
875*8975f5c5SAndroid Build Coastguard Worker     float colorMatrix[3][3],
876*8975f5c5SAndroid Build Coastguard Worker     float colorOffset[3],
877*8975f5c5SAndroid Build Coastguard Worker     float colorScale[3]
878*8975f5c5SAndroid Build Coastguard Worker ){
879*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info = find_display (dpy);
880*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryGvoColorConversionReply rep;
881*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryGvoColorConversionReq *req;
882*8975f5c5SAndroid Build Coastguard Worker 
883*8975f5c5SAndroid Build Coastguard Worker     if(!XextHasExtension(info))
884*8975f5c5SAndroid Build Coastguard Worker         return False;
885*8975f5c5SAndroid Build Coastguard Worker 
886*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckExtension (dpy, info, False);
887*8975f5c5SAndroid Build Coastguard Worker 
888*8975f5c5SAndroid Build Coastguard Worker     LockDisplay (dpy);
889*8975f5c5SAndroid Build Coastguard Worker 
890*8975f5c5SAndroid Build Coastguard Worker     GetReq (nvCtrlQueryGvoColorConversion, req);
891*8975f5c5SAndroid Build Coastguard Worker     req->reqType = info->codes->major_opcode;
892*8975f5c5SAndroid Build Coastguard Worker     req->nvReqType = X_nvCtrlQueryGvoColorConversion;
893*8975f5c5SAndroid Build Coastguard Worker     req->screen = screen;
894*8975f5c5SAndroid Build Coastguard Worker 
895*8975f5c5SAndroid Build Coastguard Worker     if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
896*8975f5c5SAndroid Build Coastguard Worker         UnlockDisplay (dpy);
897*8975f5c5SAndroid Build Coastguard Worker         SyncHandle ();
898*8975f5c5SAndroid Build Coastguard Worker         return False;
899*8975f5c5SAndroid Build Coastguard Worker     }
900*8975f5c5SAndroid Build Coastguard Worker 
901*8975f5c5SAndroid Build Coastguard Worker     _XRead(dpy, (char *)(colorMatrix), 36);
902*8975f5c5SAndroid Build Coastguard Worker     _XRead(dpy, (char *)(colorOffset), 12);
903*8975f5c5SAndroid Build Coastguard Worker     _XRead(dpy, (char *)(colorScale), 12);
904*8975f5c5SAndroid Build Coastguard Worker 
905*8975f5c5SAndroid Build Coastguard Worker     UnlockDisplay (dpy);
906*8975f5c5SAndroid Build Coastguard Worker     SyncHandle ();
907*8975f5c5SAndroid Build Coastguard Worker 
908*8975f5c5SAndroid Build Coastguard Worker     return True;
909*8975f5c5SAndroid Build Coastguard Worker }
910*8975f5c5SAndroid Build Coastguard Worker 
911*8975f5c5SAndroid Build Coastguard Worker 
XNVCtrlSelectTargetNotify(Display * dpy,int target_type,int target_id,int notify_type,Bool onoff)912*8975f5c5SAndroid Build Coastguard Worker Bool XNVCtrlSelectTargetNotify (
913*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
914*8975f5c5SAndroid Build Coastguard Worker     int target_type,
915*8975f5c5SAndroid Build Coastguard Worker     int target_id,
916*8975f5c5SAndroid Build Coastguard Worker     int notify_type,
917*8975f5c5SAndroid Build Coastguard Worker     Bool onoff
918*8975f5c5SAndroid Build Coastguard Worker ){
919*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info = find_display (dpy);
920*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlSelectTargetNotifyReq *req;
921*8975f5c5SAndroid Build Coastguard Worker 
922*8975f5c5SAndroid Build Coastguard Worker     if(!XextHasExtension (info))
923*8975f5c5SAndroid Build Coastguard Worker         return False;
924*8975f5c5SAndroid Build Coastguard Worker 
925*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckExtension (dpy, info, False);
926*8975f5c5SAndroid Build Coastguard Worker 
927*8975f5c5SAndroid Build Coastguard Worker     LockDisplay (dpy);
928*8975f5c5SAndroid Build Coastguard Worker     GetReq (nvCtrlSelectTargetNotify, req);
929*8975f5c5SAndroid Build Coastguard Worker     req->reqType = info->codes->major_opcode;
930*8975f5c5SAndroid Build Coastguard Worker     req->nvReqType = X_nvCtrlSelectTargetNotify;
931*8975f5c5SAndroid Build Coastguard Worker     req->target_type = target_type;
932*8975f5c5SAndroid Build Coastguard Worker     req->target_id = target_id;
933*8975f5c5SAndroid Build Coastguard Worker     req->notifyType = notify_type;
934*8975f5c5SAndroid Build Coastguard Worker     req->onoff = onoff;
935*8975f5c5SAndroid Build Coastguard Worker     UnlockDisplay (dpy);
936*8975f5c5SAndroid Build Coastguard Worker     SyncHandle ();
937*8975f5c5SAndroid Build Coastguard Worker 
938*8975f5c5SAndroid Build Coastguard Worker     return True;
939*8975f5c5SAndroid Build Coastguard Worker }
940*8975f5c5SAndroid Build Coastguard Worker 
941*8975f5c5SAndroid Build Coastguard Worker 
XNVCtrlSelectNotify(Display * dpy,int screen,int type,Bool onoff)942*8975f5c5SAndroid Build Coastguard Worker Bool XNVCtrlSelectNotify (
943*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
944*8975f5c5SAndroid Build Coastguard Worker     int screen,
945*8975f5c5SAndroid Build Coastguard Worker     int type,
946*8975f5c5SAndroid Build Coastguard Worker     Bool onoff
947*8975f5c5SAndroid Build Coastguard Worker ){
948*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info = find_display (dpy);
949*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlSelectNotifyReq *req;
950*8975f5c5SAndroid Build Coastguard Worker 
951*8975f5c5SAndroid Build Coastguard Worker     if(!XextHasExtension (info))
952*8975f5c5SAndroid Build Coastguard Worker         return False;
953*8975f5c5SAndroid Build Coastguard Worker 
954*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckExtension (dpy, info, False);
955*8975f5c5SAndroid Build Coastguard Worker 
956*8975f5c5SAndroid Build Coastguard Worker     LockDisplay (dpy);
957*8975f5c5SAndroid Build Coastguard Worker     GetReq (nvCtrlSelectNotify, req);
958*8975f5c5SAndroid Build Coastguard Worker     req->reqType = info->codes->major_opcode;
959*8975f5c5SAndroid Build Coastguard Worker     req->nvReqType = X_nvCtrlSelectNotify;
960*8975f5c5SAndroid Build Coastguard Worker     req->screen = screen;
961*8975f5c5SAndroid Build Coastguard Worker     req->notifyType = type;
962*8975f5c5SAndroid Build Coastguard Worker     req->onoff = onoff;
963*8975f5c5SAndroid Build Coastguard Worker     UnlockDisplay (dpy);
964*8975f5c5SAndroid Build Coastguard Worker     SyncHandle ();
965*8975f5c5SAndroid Build Coastguard Worker 
966*8975f5c5SAndroid Build Coastguard Worker     return True;
967*8975f5c5SAndroid Build Coastguard Worker }
968*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLQueryTargetBinaryData(Display * dpy,int target_type,int target_id,unsigned int display_mask,unsigned int attribute,unsigned char ** ptr,int * len)969*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLQueryTargetBinaryData (
970*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
971*8975f5c5SAndroid Build Coastguard Worker     int target_type,
972*8975f5c5SAndroid Build Coastguard Worker     int target_id,
973*8975f5c5SAndroid Build Coastguard Worker     unsigned int display_mask,
974*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
975*8975f5c5SAndroid Build Coastguard Worker     unsigned char **ptr,
976*8975f5c5SAndroid Build Coastguard Worker     int *len
977*8975f5c5SAndroid Build Coastguard Worker ){
978*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info = find_display (dpy);
979*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryBinaryDataReply rep;
980*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlQueryBinaryDataReq   *req;
981*8975f5c5SAndroid Build Coastguard Worker     Bool exists;
982*8975f5c5SAndroid Build Coastguard Worker     int length, numbytes, slop;
983*8975f5c5SAndroid Build Coastguard Worker 
984*8975f5c5SAndroid Build Coastguard Worker     if (!ptr) return False;
985*8975f5c5SAndroid Build Coastguard Worker 
986*8975f5c5SAndroid Build Coastguard Worker     if(!XextHasExtension(info))
987*8975f5c5SAndroid Build Coastguard Worker         return False;
988*8975f5c5SAndroid Build Coastguard Worker 
989*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckExtension (dpy, info, False);
990*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckTargetData(dpy, info, &target_type, &target_id);
991*8975f5c5SAndroid Build Coastguard Worker 
992*8975f5c5SAndroid Build Coastguard Worker     LockDisplay (dpy);
993*8975f5c5SAndroid Build Coastguard Worker     GetReq (nvCtrlQueryBinaryData, req);
994*8975f5c5SAndroid Build Coastguard Worker     req->reqType = info->codes->major_opcode;
995*8975f5c5SAndroid Build Coastguard Worker     req->nvReqType = X_nvCtrlQueryBinaryData;
996*8975f5c5SAndroid Build Coastguard Worker     req->target_type = target_type;
997*8975f5c5SAndroid Build Coastguard Worker     req->target_id = target_id;
998*8975f5c5SAndroid Build Coastguard Worker     req->display_mask = display_mask;
999*8975f5c5SAndroid Build Coastguard Worker     req->attribute = attribute;
1000*8975f5c5SAndroid Build Coastguard Worker     if (!_XReply (dpy, (xReply *) &rep, 0, False)) {
1001*8975f5c5SAndroid Build Coastguard Worker         UnlockDisplay (dpy);
1002*8975f5c5SAndroid Build Coastguard Worker         SyncHandle ();
1003*8975f5c5SAndroid Build Coastguard Worker         return False;
1004*8975f5c5SAndroid Build Coastguard Worker     }
1005*8975f5c5SAndroid Build Coastguard Worker     length = rep.length;
1006*8975f5c5SAndroid Build Coastguard Worker     numbytes = rep.n;
1007*8975f5c5SAndroid Build Coastguard Worker     slop = numbytes & 3;
1008*8975f5c5SAndroid Build Coastguard Worker     exists = rep.flags;
1009*8975f5c5SAndroid Build Coastguard Worker     if (exists) {
1010*8975f5c5SAndroid Build Coastguard Worker         *ptr = (unsigned char *) Xmalloc(numbytes);
1011*8975f5c5SAndroid Build Coastguard Worker     }
1012*8975f5c5SAndroid Build Coastguard Worker     if (!exists || !*ptr) {
1013*8975f5c5SAndroid Build Coastguard Worker         _XEatData(dpy, length);
1014*8975f5c5SAndroid Build Coastguard Worker         UnlockDisplay (dpy);
1015*8975f5c5SAndroid Build Coastguard Worker         SyncHandle ();
1016*8975f5c5SAndroid Build Coastguard Worker         return False;
1017*8975f5c5SAndroid Build Coastguard Worker     } else {
1018*8975f5c5SAndroid Build Coastguard Worker         _XRead(dpy, (char *) *ptr, numbytes);
1019*8975f5c5SAndroid Build Coastguard Worker         if (slop) _XEatData(dpy, 4-slop);
1020*8975f5c5SAndroid Build Coastguard Worker     }
1021*8975f5c5SAndroid Build Coastguard Worker     if (len) *len = numbytes;
1022*8975f5c5SAndroid Build Coastguard Worker     UnlockDisplay (dpy);
1023*8975f5c5SAndroid Build Coastguard Worker     SyncHandle ();
1024*8975f5c5SAndroid Build Coastguard Worker     return exists;
1025*8975f5c5SAndroid Build Coastguard Worker }
1026*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLQueryBinaryData(Display * dpy,int screen,unsigned int display_mask,unsigned int attribute,unsigned char ** ptr,int * len)1027*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLQueryBinaryData (
1028*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
1029*8975f5c5SAndroid Build Coastguard Worker     int screen,
1030*8975f5c5SAndroid Build Coastguard Worker     unsigned int display_mask,
1031*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
1032*8975f5c5SAndroid Build Coastguard Worker     unsigned char **ptr,
1033*8975f5c5SAndroid Build Coastguard Worker     int *len
1034*8975f5c5SAndroid Build Coastguard Worker ){
1035*8975f5c5SAndroid Build Coastguard Worker     return XNVCTRLQueryTargetBinaryData(dpy, NV_CTRL_TARGET_TYPE_X_SCREEN,
1036*8975f5c5SAndroid Build Coastguard Worker                                         screen, display_mask,
1037*8975f5c5SAndroid Build Coastguard Worker                                         attribute, ptr, len);
1038*8975f5c5SAndroid Build Coastguard Worker }
1039*8975f5c5SAndroid Build Coastguard Worker 
XNVCTRLStringOperation(Display * dpy,int target_type,int target_id,unsigned int display_mask,unsigned int attribute,char * pIn,char ** ppOut)1040*8975f5c5SAndroid Build Coastguard Worker Bool XNVCTRLStringOperation (
1041*8975f5c5SAndroid Build Coastguard Worker     Display *dpy,
1042*8975f5c5SAndroid Build Coastguard Worker     int target_type,
1043*8975f5c5SAndroid Build Coastguard Worker     int target_id,
1044*8975f5c5SAndroid Build Coastguard Worker     unsigned int display_mask,
1045*8975f5c5SAndroid Build Coastguard Worker     unsigned int attribute,
1046*8975f5c5SAndroid Build Coastguard Worker     char *pIn,
1047*8975f5c5SAndroid Build Coastguard Worker     char **ppOut
1048*8975f5c5SAndroid Build Coastguard Worker ) {
1049*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info = find_display(dpy);
1050*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlStringOperationReq *req;
1051*8975f5c5SAndroid Build Coastguard Worker     xnvCtrlStringOperationReply rep;
1052*8975f5c5SAndroid Build Coastguard Worker     Bool ret;
1053*8975f5c5SAndroid Build Coastguard Worker     int inSize, outSize, length, slop;
1054*8975f5c5SAndroid Build Coastguard Worker 
1055*8975f5c5SAndroid Build Coastguard Worker     if (!XextHasExtension(info))
1056*8975f5c5SAndroid Build Coastguard Worker         return False;
1057*8975f5c5SAndroid Build Coastguard Worker 
1058*8975f5c5SAndroid Build Coastguard Worker     if (!ppOut)
1059*8975f5c5SAndroid Build Coastguard Worker         return False;
1060*8975f5c5SAndroid Build Coastguard Worker 
1061*8975f5c5SAndroid Build Coastguard Worker     *ppOut = NULL;
1062*8975f5c5SAndroid Build Coastguard Worker 
1063*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckExtension(dpy, info, False);
1064*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckTargetData(dpy, info, &target_type, &target_id);
1065*8975f5c5SAndroid Build Coastguard Worker 
1066*8975f5c5SAndroid Build Coastguard Worker     if (pIn) {
1067*8975f5c5SAndroid Build Coastguard Worker         inSize = strlen(pIn) + 1;
1068*8975f5c5SAndroid Build Coastguard Worker     } else {
1069*8975f5c5SAndroid Build Coastguard Worker         inSize = 0;
1070*8975f5c5SAndroid Build Coastguard Worker     }
1071*8975f5c5SAndroid Build Coastguard Worker 
1072*8975f5c5SAndroid Build Coastguard Worker     LockDisplay(dpy);
1073*8975f5c5SAndroid Build Coastguard Worker     GetReq(nvCtrlStringOperation, req);
1074*8975f5c5SAndroid Build Coastguard Worker 
1075*8975f5c5SAndroid Build Coastguard Worker     req->reqType = info->codes->major_opcode;
1076*8975f5c5SAndroid Build Coastguard Worker     req->nvReqType = X_nvCtrlStringOperation;
1077*8975f5c5SAndroid Build Coastguard Worker     req->target_type = target_type;
1078*8975f5c5SAndroid Build Coastguard Worker     req->target_id = target_id;
1079*8975f5c5SAndroid Build Coastguard Worker     req->display_mask = display_mask;
1080*8975f5c5SAndroid Build Coastguard Worker     req->attribute = attribute;
1081*8975f5c5SAndroid Build Coastguard Worker 
1082*8975f5c5SAndroid Build Coastguard Worker     req->length += ((inSize + 3) & ~3) >> 2;
1083*8975f5c5SAndroid Build Coastguard Worker     req->num_bytes = inSize;
1084*8975f5c5SAndroid Build Coastguard Worker 
1085*8975f5c5SAndroid Build Coastguard Worker     if (pIn) {
1086*8975f5c5SAndroid Build Coastguard Worker         Data(dpy, pIn, inSize);
1087*8975f5c5SAndroid Build Coastguard Worker     }
1088*8975f5c5SAndroid Build Coastguard Worker 
1089*8975f5c5SAndroid Build Coastguard Worker     if (!_XReply (dpy, (xReply *) &rep, 0, False)) {
1090*8975f5c5SAndroid Build Coastguard Worker         UnlockDisplay(dpy);
1091*8975f5c5SAndroid Build Coastguard Worker         SyncHandle();
1092*8975f5c5SAndroid Build Coastguard Worker         return False;
1093*8975f5c5SAndroid Build Coastguard Worker     }
1094*8975f5c5SAndroid Build Coastguard Worker 
1095*8975f5c5SAndroid Build Coastguard Worker     length = rep.length;
1096*8975f5c5SAndroid Build Coastguard Worker     outSize = rep.num_bytes;
1097*8975f5c5SAndroid Build Coastguard Worker     slop = outSize & 3;
1098*8975f5c5SAndroid Build Coastguard Worker 
1099*8975f5c5SAndroid Build Coastguard Worker     if (outSize) *ppOut = (char *) Xmalloc(outSize);
1100*8975f5c5SAndroid Build Coastguard Worker 
1101*8975f5c5SAndroid Build Coastguard Worker     if (!*ppOut) {
1102*8975f5c5SAndroid Build Coastguard Worker         _XEatData(dpy, length);
1103*8975f5c5SAndroid Build Coastguard Worker     } else {
1104*8975f5c5SAndroid Build Coastguard Worker         _XRead(dpy, (char *) *ppOut, outSize);
1105*8975f5c5SAndroid Build Coastguard Worker         if (slop) _XEatData(dpy, 4-slop);
1106*8975f5c5SAndroid Build Coastguard Worker     }
1107*8975f5c5SAndroid Build Coastguard Worker 
1108*8975f5c5SAndroid Build Coastguard Worker     ret = rep.ret;
1109*8975f5c5SAndroid Build Coastguard Worker 
1110*8975f5c5SAndroid Build Coastguard Worker     UnlockDisplay(dpy);
1111*8975f5c5SAndroid Build Coastguard Worker     SyncHandle();
1112*8975f5c5SAndroid Build Coastguard Worker 
1113*8975f5c5SAndroid Build Coastguard Worker     return ret;
1114*8975f5c5SAndroid Build Coastguard Worker }
1115*8975f5c5SAndroid Build Coastguard Worker 
1116*8975f5c5SAndroid Build Coastguard Worker 
wire_to_event(Display * dpy,XEvent * host,xEvent * wire)1117*8975f5c5SAndroid Build Coastguard Worker static Bool wire_to_event (Display *dpy, XEvent *host, xEvent *wire)
1118*8975f5c5SAndroid Build Coastguard Worker {
1119*8975f5c5SAndroid Build Coastguard Worker     XExtDisplayInfo *info = find_display (dpy);
1120*8975f5c5SAndroid Build Coastguard Worker     XNVCtrlEvent *re;
1121*8975f5c5SAndroid Build Coastguard Worker     xnvctrlEvent *event;
1122*8975f5c5SAndroid Build Coastguard Worker     XNVCtrlEventTarget *reTarget;
1123*8975f5c5SAndroid Build Coastguard Worker     xnvctrlEventTarget *eventTarget;
1124*8975f5c5SAndroid Build Coastguard Worker     XNVCtrlEventTargetAvailability *reTargetAvailability;
1125*8975f5c5SAndroid Build Coastguard Worker     XNVCtrlStringEventTarget *reTargetString;
1126*8975f5c5SAndroid Build Coastguard Worker     XNVCtrlBinaryEventTarget *reTargetBinary;
1127*8975f5c5SAndroid Build Coastguard Worker 
1128*8975f5c5SAndroid Build Coastguard Worker     XNVCTRLCheckExtension (dpy, info, False);
1129*8975f5c5SAndroid Build Coastguard Worker 
1130*8975f5c5SAndroid Build Coastguard Worker     switch ((wire->u.u.type & 0x7F) - info->codes->first_event) {
1131*8975f5c5SAndroid Build Coastguard Worker     case ATTRIBUTE_CHANGED_EVENT:
1132*8975f5c5SAndroid Build Coastguard Worker         re = (XNVCtrlEvent *) host;
1133*8975f5c5SAndroid Build Coastguard Worker         event = (xnvctrlEvent *) wire;
1134*8975f5c5SAndroid Build Coastguard Worker         re->attribute_changed.type = event->u.u.type & 0x7F;
1135*8975f5c5SAndroid Build Coastguard Worker         re->attribute_changed.serial =
1136*8975f5c5SAndroid Build Coastguard Worker             _XSetLastRequestRead(dpy, (xGenericReply*) event);
1137*8975f5c5SAndroid Build Coastguard Worker         re->attribute_changed.send_event = ((event->u.u.type & 0x80) != 0);
1138*8975f5c5SAndroid Build Coastguard Worker         re->attribute_changed.display = dpy;
1139*8975f5c5SAndroid Build Coastguard Worker         re->attribute_changed.time = event->u.attribute_changed.time;
1140*8975f5c5SAndroid Build Coastguard Worker         re->attribute_changed.screen = event->u.attribute_changed.screen;
1141*8975f5c5SAndroid Build Coastguard Worker         re->attribute_changed.display_mask =
1142*8975f5c5SAndroid Build Coastguard Worker             event->u.attribute_changed.display_mask;
1143*8975f5c5SAndroid Build Coastguard Worker         re->attribute_changed.attribute = event->u.attribute_changed.attribute;
1144*8975f5c5SAndroid Build Coastguard Worker         re->attribute_changed.value = event->u.attribute_changed.value;
1145*8975f5c5SAndroid Build Coastguard Worker         break;
1146*8975f5c5SAndroid Build Coastguard Worker     case TARGET_ATTRIBUTE_CHANGED_EVENT:
1147*8975f5c5SAndroid Build Coastguard Worker         reTarget = (XNVCtrlEventTarget *) host;
1148*8975f5c5SAndroid Build Coastguard Worker         eventTarget = (xnvctrlEventTarget *) wire;
1149*8975f5c5SAndroid Build Coastguard Worker         reTarget->attribute_changed.type = eventTarget->u.u.type & 0x7F;
1150*8975f5c5SAndroid Build Coastguard Worker         reTarget->attribute_changed.serial =
1151*8975f5c5SAndroid Build Coastguard Worker             _XSetLastRequestRead(dpy, (xGenericReply*) eventTarget);
1152*8975f5c5SAndroid Build Coastguard Worker         reTarget->attribute_changed.send_event =
1153*8975f5c5SAndroid Build Coastguard Worker             ((eventTarget->u.u.type & 0x80) != 0);
1154*8975f5c5SAndroid Build Coastguard Worker         reTarget->attribute_changed.display = dpy;
1155*8975f5c5SAndroid Build Coastguard Worker         reTarget->attribute_changed.time =
1156*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.attribute_changed.time;
1157*8975f5c5SAndroid Build Coastguard Worker         reTarget->attribute_changed.target_type =
1158*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.attribute_changed.target_type;
1159*8975f5c5SAndroid Build Coastguard Worker         reTarget->attribute_changed.target_id =
1160*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.attribute_changed.target_id;
1161*8975f5c5SAndroid Build Coastguard Worker         reTarget->attribute_changed.display_mask =
1162*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.attribute_changed.display_mask;
1163*8975f5c5SAndroid Build Coastguard Worker         reTarget->attribute_changed.attribute =
1164*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.attribute_changed.attribute;
1165*8975f5c5SAndroid Build Coastguard Worker         reTarget->attribute_changed.value =
1166*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.attribute_changed.value;
1167*8975f5c5SAndroid Build Coastguard Worker         break;
1168*8975f5c5SAndroid Build Coastguard Worker     case TARGET_ATTRIBUTE_AVAILABILITY_CHANGED_EVENT:
1169*8975f5c5SAndroid Build Coastguard Worker         reTargetAvailability = (XNVCtrlEventTargetAvailability *) host;
1170*8975f5c5SAndroid Build Coastguard Worker         eventTarget = (xnvctrlEventTarget *) wire;
1171*8975f5c5SAndroid Build Coastguard Worker         reTargetAvailability->attribute_changed.type =
1172*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.u.type & 0x7F;
1173*8975f5c5SAndroid Build Coastguard Worker         reTargetAvailability->attribute_changed.serial =
1174*8975f5c5SAndroid Build Coastguard Worker             _XSetLastRequestRead(dpy, (xGenericReply*) eventTarget);
1175*8975f5c5SAndroid Build Coastguard Worker         reTargetAvailability->attribute_changed.send_event =
1176*8975f5c5SAndroid Build Coastguard Worker             ((eventTarget->u.u.type & 0x80) != 0);
1177*8975f5c5SAndroid Build Coastguard Worker         reTargetAvailability->attribute_changed.display = dpy;
1178*8975f5c5SAndroid Build Coastguard Worker         reTargetAvailability->attribute_changed.time =
1179*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.availability_changed.time;
1180*8975f5c5SAndroid Build Coastguard Worker         reTargetAvailability->attribute_changed.target_type =
1181*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.availability_changed.target_type;
1182*8975f5c5SAndroid Build Coastguard Worker         reTargetAvailability->attribute_changed.target_id =
1183*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.availability_changed.target_id;
1184*8975f5c5SAndroid Build Coastguard Worker         reTargetAvailability->attribute_changed.display_mask =
1185*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.availability_changed.display_mask;
1186*8975f5c5SAndroid Build Coastguard Worker         reTargetAvailability->attribute_changed.attribute =
1187*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.availability_changed.attribute;
1188*8975f5c5SAndroid Build Coastguard Worker         reTargetAvailability->attribute_changed.availability =
1189*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.availability_changed.availability;
1190*8975f5c5SAndroid Build Coastguard Worker         reTargetAvailability->attribute_changed.value =
1191*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.availability_changed.value;
1192*8975f5c5SAndroid Build Coastguard Worker         break;
1193*8975f5c5SAndroid Build Coastguard Worker     case TARGET_STRING_ATTRIBUTE_CHANGED_EVENT:
1194*8975f5c5SAndroid Build Coastguard Worker         reTargetString = (XNVCtrlStringEventTarget *) host;
1195*8975f5c5SAndroid Build Coastguard Worker         eventTarget = (xnvctrlEventTarget *) wire;
1196*8975f5c5SAndroid Build Coastguard Worker         reTargetString->attribute_changed.type = eventTarget->u.u.type & 0x7F;
1197*8975f5c5SAndroid Build Coastguard Worker         reTargetString->attribute_changed.serial =
1198*8975f5c5SAndroid Build Coastguard Worker             _XSetLastRequestRead(dpy, (xGenericReply*) eventTarget);
1199*8975f5c5SAndroid Build Coastguard Worker         reTargetString->attribute_changed.send_event =
1200*8975f5c5SAndroid Build Coastguard Worker             ((eventTarget->u.u.type & 0x80) != 0);
1201*8975f5c5SAndroid Build Coastguard Worker         reTargetString->attribute_changed.display = dpy;
1202*8975f5c5SAndroid Build Coastguard Worker         reTargetString->attribute_changed.time =
1203*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.attribute_changed.time;
1204*8975f5c5SAndroid Build Coastguard Worker         reTargetString->attribute_changed.target_type =
1205*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.attribute_changed.target_type;
1206*8975f5c5SAndroid Build Coastguard Worker         reTargetString->attribute_changed.target_id =
1207*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.attribute_changed.target_id;
1208*8975f5c5SAndroid Build Coastguard Worker         reTargetString->attribute_changed.display_mask =
1209*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.attribute_changed.display_mask;
1210*8975f5c5SAndroid Build Coastguard Worker         reTargetString->attribute_changed.attribute =
1211*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.attribute_changed.attribute;
1212*8975f5c5SAndroid Build Coastguard Worker         break;
1213*8975f5c5SAndroid Build Coastguard Worker     case TARGET_BINARY_ATTRIBUTE_CHANGED_EVENT:
1214*8975f5c5SAndroid Build Coastguard Worker         reTargetBinary = (XNVCtrlBinaryEventTarget *) host;
1215*8975f5c5SAndroid Build Coastguard Worker         eventTarget = (xnvctrlEventTarget *) wire;
1216*8975f5c5SAndroid Build Coastguard Worker         reTargetBinary->attribute_changed.type = eventTarget->u.u.type & 0x7F;
1217*8975f5c5SAndroid Build Coastguard Worker         reTargetBinary->attribute_changed.serial =
1218*8975f5c5SAndroid Build Coastguard Worker             _XSetLastRequestRead(dpy, (xGenericReply*) eventTarget);
1219*8975f5c5SAndroid Build Coastguard Worker         reTargetBinary->attribute_changed.send_event =
1220*8975f5c5SAndroid Build Coastguard Worker             ((eventTarget->u.u.type & 0x80) != 0);
1221*8975f5c5SAndroid Build Coastguard Worker         reTargetBinary->attribute_changed.display = dpy;
1222*8975f5c5SAndroid Build Coastguard Worker         reTargetBinary->attribute_changed.time =
1223*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.attribute_changed.time;
1224*8975f5c5SAndroid Build Coastguard Worker         reTargetBinary->attribute_changed.target_type =
1225*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.attribute_changed.target_type;
1226*8975f5c5SAndroid Build Coastguard Worker         reTargetBinary->attribute_changed.target_id =
1227*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.attribute_changed.target_id;
1228*8975f5c5SAndroid Build Coastguard Worker         reTargetBinary->attribute_changed.display_mask =
1229*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.attribute_changed.display_mask;
1230*8975f5c5SAndroid Build Coastguard Worker         reTargetBinary->attribute_changed.attribute =
1231*8975f5c5SAndroid Build Coastguard Worker             eventTarget->u.attribute_changed.attribute;
1232*8975f5c5SAndroid Build Coastguard Worker         break;
1233*8975f5c5SAndroid Build Coastguard Worker 
1234*8975f5c5SAndroid Build Coastguard Worker     default:
1235*8975f5c5SAndroid Build Coastguard Worker         return False;
1236*8975f5c5SAndroid Build Coastguard Worker     }
1237*8975f5c5SAndroid Build Coastguard Worker 
1238*8975f5c5SAndroid Build Coastguard Worker     return True;
1239*8975f5c5SAndroid Build Coastguard Worker }
1240*8975f5c5SAndroid Build Coastguard Worker 
1241