doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NVCtrl.c
Go to the documentation of this file.
1 #define NEED_EVENTS
2 #define NEED_REPLIES
3 #include <X11/Xlibint.h>
4 #include <X11/Xutil.h>
5 #include <X11/extensions/Xext.h>
6 #include "extutil.h"
7 #include "NVCtrlLib.h"
8 #include "nv_control.h"
9 
10 #if !defined(XTRHEADS)
11 #warning XTRHEADS not defined -- this libXNVCtrl.a will not be thread safe!
12 #endif
13 
14 static XExtensionInfo _nvctrl_ext_info_data;
15 static XExtensionInfo *nvctrl_ext_info = &_nvctrl_ext_info_data;
16 static /* const */ char *nvctrl_extension_name = NV_CONTROL_NAME;
17 
18 #define XNVCTRLCheckExtension(dpy,i,val) \
19  XextCheckExtension (dpy, i, nvctrl_extension_name, val)
20 #define XNVCTRLSimpleCheckExtension(dpy,i) \
21  XextSimpleCheckExtension (dpy, i, nvctrl_extension_name)
22 
23 static int close_display();
24 static Bool wire_to_event();
25 static /* const */ XExtensionHooks nvctrl_extension_hooks = {
26  NULL, /* create_gc */
27  NULL, /* copy_gc */
28  NULL, /* flush_gc */
29  NULL, /* free_gc */
30  NULL, /* create_font */
31  NULL, /* free_font */
32  close_display, /* close_display */
33  wire_to_event, /* wire_to_event */
34  NULL, /* event_to_wire */
35  NULL, /* error */
36  NULL, /* error_string */
37 };
38 
39 static XEXT_GENERATE_FIND_DISPLAY (find_display, nvctrl_ext_info,
40  nvctrl_extension_name,
41  &nvctrl_extension_hooks,
43 
44 static XEXT_GENERATE_CLOSE_DISPLAY (close_display, nvctrl_ext_info)
45 
47  Display *dpy,
48  int *event_basep,
49  int *error_basep
50 ){
51  XExtDisplayInfo *info = find_display (dpy);
52 
53  if (XextHasExtension(info)) {
54  if (event_basep) *event_basep = info->codes->first_event;
55  if (error_basep) *error_basep = info->codes->first_error;
56  return True;
57  } else {
58  return False;
59  }
60 }
61 
62 
64  Display *dpy,
65  int *major,
66  int *minor
67 ){
68  XExtDisplayInfo *info = find_display (dpy);
71 
72  if(!XextHasExtension(info))
73  return False;
74 
75  XNVCTRLCheckExtension (dpy, info, False);
76 
77  LockDisplay (dpy);
78  GetReq (nvCtrlQueryExtension, req);
79  req->reqType = info->codes->major_opcode;
81  if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
82  UnlockDisplay (dpy);
83  SyncHandle ();
84  return False;
85  }
86  if (major) *major = rep.major;
87  if (minor) *minor = rep.minor;
88  UnlockDisplay (dpy);
89  SyncHandle ();
90  return True;
91 }
92 
93 
95  Display *dpy,
96  int screen
97 ){
98  XExtDisplayInfo *info = find_display (dpy);
99  xnvCtrlIsNvReply rep;
100  xnvCtrlIsNvReq *req;
101  Bool isnv;
102 
103  if(!XextHasExtension(info))
104  return False;
105 
106  XNVCTRLCheckExtension (dpy, info, False);
107 
108  LockDisplay (dpy);
109  GetReq (nvCtrlIsNv, req);
110  req->reqType = info->codes->major_opcode;
111  req->nvReqType = X_nvCtrlIsNv;
112  req->screen = screen;
113  if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
114  UnlockDisplay (dpy);
115  SyncHandle ();
116  return False;
117  }
118  isnv = rep.isnv;
119  UnlockDisplay (dpy);
120  SyncHandle ();
121  return isnv;
122 }
123 
124 
126  Display *dpy,
127  int screen,
128  unsigned int display_mask,
129  unsigned int attribute,
130  int value
131 ){
132  XExtDisplayInfo *info = find_display (dpy);
134 
135  XNVCTRLSimpleCheckExtension (dpy, info);
136 
137  LockDisplay (dpy);
138  GetReq (nvCtrlSetAttribute, req);
139  req->reqType = info->codes->major_opcode;
141  req->screen = screen;
142  req->display_mask = display_mask;
143  req->attribute = attribute;
144  req->value = value;
145  UnlockDisplay (dpy);
146  SyncHandle ();
147 }
148 
149 
151  Display *dpy,
152  int screen,
153  unsigned int display_mask,
154  unsigned int attribute,
155  int *value
156 ){
157  XExtDisplayInfo *info = find_display (dpy);
160  Bool exists;
161 
162  if(!XextHasExtension(info))
163  return False;
164 
165  XNVCTRLCheckExtension (dpy, info, False);
166 
167  LockDisplay (dpy);
168  GetReq (nvCtrlQueryAttribute, req);
169  req->reqType = info->codes->major_opcode;
171  req->screen = screen;
172  req->display_mask = display_mask;
173  req->attribute = attribute;
174  if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
175  UnlockDisplay (dpy);
176  SyncHandle ();
177  return False;
178  }
179  if (value) *value = rep.value;
180  exists = rep.flags;
181  UnlockDisplay (dpy);
182  SyncHandle ();
183  return exists;
184 }
185 
186 
188  Display *dpy,
189  int screen,
190  unsigned int display_mask,
191  unsigned int attribute,
192  char **ptr
193 ){
194  XExtDisplayInfo *info = find_display (dpy);
197  Bool exists;
198  int length, numbytes, slop;
199 
200  if (!ptr) return False;
201 
202  if(!XextHasExtension(info))
203  return False;
204 
205  XNVCTRLCheckExtension (dpy, info, False);
206 
207  LockDisplay (dpy);
208  GetReq (nvCtrlQueryStringAttribute, req);
209  req->reqType = info->codes->major_opcode;
211  req->screen = screen;
212  req->display_mask = display_mask;
213  req->attribute = attribute;
214  if (!_XReply (dpy, (xReply *) &rep, 0, False)) {
215  UnlockDisplay (dpy);
216  SyncHandle ();
217  return False;
218  }
219  length = rep.length;
220  numbytes = rep.n;
221  slop = numbytes & 3;
222  *ptr = (char *) Xmalloc(numbytes);
223  if (! *ptr) {
224  _XEatData(dpy, length);
225  UnlockDisplay (dpy);
226  SyncHandle ();
227  return False;
228  } else {
229  _XRead(dpy, (char *) *ptr, numbytes);
230  if (slop) _XEatData(dpy, 4-slop);
231  }
232  exists = rep.flags;
233  UnlockDisplay (dpy);
234  SyncHandle ();
235  return exists;
236 }
237 
239  Display *dpy,
240  int screen,
241  unsigned int display_mask,
242  unsigned int attribute,
244 ){
245  XExtDisplayInfo *info = find_display (dpy);
248  Bool exists;
249 
250  if (!values) return False;
251 
252  if(!XextHasExtension(info))
253  return False;
254 
255  XNVCTRLCheckExtension (dpy, info, False);
256 
257  LockDisplay (dpy);
258  GetReq (nvCtrlQueryValidAttributeValues, req);
259  req->reqType = info->codes->major_opcode;
261  req->screen = screen;
262  req->display_mask = display_mask;
263  req->attribute = attribute;
264  if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
265  UnlockDisplay (dpy);
266  SyncHandle ();
267  return False;
268  }
269  exists = rep.flags;
270  values->type = rep.attr_type;
271  if (rep.attr_type == ATTRIBUTE_TYPE_RANGE) {
272  values->u.range.min = rep.min;
273  values->u.range.max = rep.max;
274  }
275  if (rep.attr_type == ATTRIBUTE_TYPE_INT_BITS) {
276  values->u.bits.ints = rep.bits;
277  }
278  values->permissions = rep.perms;
279  UnlockDisplay (dpy);
280  SyncHandle ();
281  return exists;
282 }
283 
285  Display *dpy,
286  int screen,
287  int type,
288  Bool onoff
289 ){
290  XExtDisplayInfo *info = find_display (dpy);
292 
293  if(!XextHasExtension (info))
294  return False;
295 
296  XNVCTRLCheckExtension (dpy, info, False);
297 
298  LockDisplay (dpy);
299  GetReq (nvCtrlSelectNotify, req);
300  req->reqType = info->codes->major_opcode;
302  req->screen = screen;
303  req->notifyType = type;
304  req->onoff = onoff;
305  UnlockDisplay (dpy);
306  SyncHandle ();
307 
308  return True;
309 }
310 
311 static Bool wire_to_event (Display *dpy, XEvent *host, xEvent *wire)
312 {
313  XExtDisplayInfo *info = find_display (dpy);
314  XNVCtrlEvent *re = (XNVCtrlEvent *) host;
315  xnvctrlEvent *event = (xnvctrlEvent *) wire;
316 
317  XNVCTRLCheckExtension (dpy, info, False);
318 
319  switch ((event->u.u.type & 0x7F) - info->codes->first_event) {
321  re->attribute_changed.type = event->u.u.type & 0x7F;
323  _XSetLastRequestRead(dpy, (xGenericReply*) event);
324  re->attribute_changed.send_event = ((event->u.u.type & 0x80) != 0);
326  re->attribute_changed.time = event->u.attribute_changed.time;
327  re->attribute_changed.screen = event->u.attribute_changed.screen;
329  event->u.attribute_changed.display_mask;
330  re->attribute_changed.attribute = event->u.attribute_changed.attribute;
331  re->attribute_changed.value = event->u.attribute_changed.value;
332  break;
333  default:
334  return False;
335  }
336 
337  return True;
338 }
339 
XNVCtrlAttributeChangedEvent attribute_changed
Definition: NVCtrlLib.h:172
GLboolean GLenum GLenum GLvoid * values
Definition: glext.h:2868
GLsizei const GLfloat * value
Definition: glext.h:3614
#define X_nvCtrlQueryStringAttribute
Definition: nv_control.h:15
#define ATTRIBUTE_TYPE_RANGE
Definition: NVCtrl.h:760
unsigned int permissions
Definition: NVCtrl.h:778
#define X_nvCtrlIsNv
Definition: nv_control.h:12
XExtCodes * codes
Definition: extutil.h:49
Bool XNVCTRLQueryStringAttribute(Display *dpy, int screen, unsigned int display_mask, unsigned int attribute, char **ptr)
Definition: NVCtrl.c:187
GLuint GLuint GLsizei GLenum type
Definition: glext.h:2845
#define X_nvCtrlQueryAttribute
Definition: nv_control.h:13
static nvctrl_ext_info Bool XNVCTRLQueryExtension(Display *dpy, int *event_basep, int *error_basep)
Definition: NVCtrl.c:46
#define NV_CONTROL_NAME
Definition: nv_control.h:6
#define X_nvCtrlQueryValidAttributeValues
Definition: nv_control.h:16
Bool XNVCTRLQueryValidAttributeValues(Display *dpy, int screen, unsigned int display_mask, unsigned int attribute, NVCTRLAttributeValidValuesRec *values)
Definition: NVCtrl.c:238
#define X_nvCtrlSelectNotify
Definition: nv_control.h:17
struct _NVCTRLAttributeValidValues::@100::@101 range
#define NV_CONTROL_EVENTS
Definition: nv_control.h:5
#define XEXT_GENERATE_FIND_DISPLAY(proc, extinfo, extname, hooks, nev, data)
Definition: extutil.h:187
#define NULL
Definition: Lib.h:88
#define ATTRIBUTE_CHANGED_EVENT
Definition: NVCtrl.h:783
#define ATTRIBUTE_TYPE_INT_BITS
Definition: NVCtrl.h:761
#define XNVCTRLSimpleCheckExtension(dpy, i)
Definition: NVCtrl.c:20
#define X_nvCtrlQueryExtension
Definition: nv_control.h:11
#define X_nvCtrlSetAttribute
Definition: nv_control.h:14
union _NVCTRLAttributeValidValues::@100 u
struct _NVCTRLAttributeValidValues::@100::@102 bits
void XNVCTRLSetAttribute(Display *dpy, int screen, unsigned int display_mask, unsigned int attribute, int value)
Definition: NVCtrl.c:125
Bool XNVCTRLQueryVersion(Display *dpy, int *major, int *minor)
Definition: NVCtrl.c:63
#define XextHasExtension(i)
Definition: extutil.h:174
Bool XNVCTRLQueryAttribute(Display *dpy, int screen, unsigned int display_mask, unsigned int attribute, int *value)
Definition: NVCtrl.c:150
GLsizei const GLcharARB const GLint * length
Definition: glext.h:3599
Display * dpy
Definition: glimp.cpp:43
#define XEXT_GENERATE_CLOSE_DISPLAY(proc, extinfo)
Definition: extutil.h:200
CARD8 nvReqType
Definition: nv_control.h:44
Bool XNVCTRLIsNvScreen(Display *dpy, int screen)
Definition: NVCtrl.c:94
Bool XNVCtrlSelectNotify(Display *dpy, int screen, int type, Bool onoff)
Definition: NVCtrl.c:284
#define XNVCTRLCheckExtension(dpy, i, val)
Definition: NVCtrl.c:18