00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #if !defined(XTHREADS)
00031 #define XTHREADS
00032 #endif
00033
00034 #define NEED_EVENTS
00035 #define NEED_REPLIES
00036 #include <stdlib.h>
00037 #include <X11/Xlibint.h>
00038 #include <X11/Xutil.h>
00039 #include <X11/extensions/Xext.h>
00040 #include <X11/extensions/extutil.h>
00041 #include "NVCtrlLib.h"
00042 #include "nv_control.h"
00043
00044 #define NVCTRL_EXT_NEED_CHECK (XPointer)(~0)
00045 #define NVCTRL_EXT_NEED_NOTHING (XPointer)(0)
00046 #define NVCTRL_EXT_NEED_TARGET_SWAP (XPointer)(1)
00047
00048 static XExtensionInfo _nvctrl_ext_info_data;
00049 static XExtensionInfo *nvctrl_ext_info = &_nvctrl_ext_info_data;
00050 static char *nvctrl_extension_name = NV_CONTROL_NAME;
00051
00052 #define XNVCTRLCheckExtension(dpy,i,val) \
00053 XextCheckExtension (dpy, i, nvctrl_extension_name, val)
00054 #define XNVCTRLSimpleCheckExtension(dpy,i) \
00055 XextSimpleCheckExtension (dpy, i, nvctrl_extension_name)
00056
00057 static int close_display();
00058 static Bool wire_to_event();
00059 static XExtensionHooks nvctrl_extension_hooks = {
00060 NULL,
00061 NULL,
00062 NULL,
00063 NULL,
00064 NULL,
00065 NULL,
00066 close_display,
00067 wire_to_event,
00068 NULL,
00069 NULL,
00070 NULL,
00071 };
00072
00073 static XEXT_GENERATE_FIND_DISPLAY (find_display, nvctrl_ext_info,
00074 nvctrl_extension_name,
00075 &nvctrl_extension_hooks,
00076 NV_CONTROL_EVENTS, NVCTRL_EXT_NEED_CHECK)
00077
00078 static XEXT_GENERATE_CLOSE_DISPLAY (close_display, nvctrl_ext_info)
00079
00080
00081
00082
00083
00084
00085 static void XNVCTRLCheckTargetData(Display *dpy, XExtDisplayInfo *info,
00086 int *target_type, int *target_id)
00087 {
00088
00089
00090
00091 if (info->data == NVCTRL_EXT_NEED_CHECK) {
00092 int major, minor;
00093
00094 if (XNVCTRLQueryVersion(dpy, &major, &minor)) {
00095 if (major == 1 &&
00096 (minor == 8 || minor == 9)) {
00097 info->data = NVCTRL_EXT_NEED_TARGET_SWAP;
00098 } else {
00099 info->data = NVCTRL_EXT_NEED_NOTHING;
00100 }
00101 } else {
00102 info->data = NVCTRL_EXT_NEED_NOTHING;
00103 }
00104 }
00105
00106
00107 if (info->data == NVCTRL_EXT_NEED_TARGET_SWAP) {
00108 int tmp;
00109 tmp = *target_type;
00110 *target_type = *target_id;
00111 *target_id = tmp;
00112 }
00113 }
00114
00115
00116 Bool XNVCTRLQueryExtension (
00117 Display *dpy,
00118 int *event_basep,
00119 int *error_basep
00120 ){
00121 XExtDisplayInfo *info = find_display (dpy);
00122
00123 if (XextHasExtension(info)) {
00124 if (event_basep) *event_basep = info->codes->first_event;
00125 if (error_basep) *error_basep = info->codes->first_error;
00126 return True;
00127 } else {
00128 return False;
00129 }
00130 }
00131
00132
00133 Bool XNVCTRLQueryVersion (
00134 Display *dpy,
00135 int *major,
00136 int *minor
00137 ){
00138 XExtDisplayInfo *info = find_display (dpy);
00139 xnvCtrlQueryExtensionReply rep;
00140 xnvCtrlQueryExtensionReq *req;
00141
00142 if(!XextHasExtension(info))
00143 return False;
00144
00145 XNVCTRLCheckExtension (dpy, info, False);
00146
00147 LockDisplay (dpy);
00148 GetReq (nvCtrlQueryExtension, req);
00149 req->reqType = info->codes->major_opcode;
00150 req->nvReqType = X_nvCtrlQueryExtension;
00151 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
00152 UnlockDisplay (dpy);
00153 SyncHandle ();
00154 return False;
00155 }
00156 if (major) *major = rep.major;
00157 if (minor) *minor = rep.minor;
00158 UnlockDisplay (dpy);
00159 SyncHandle ();
00160 return True;
00161 }
00162
00163
00164 Bool XNVCTRLIsNvScreen (
00165 Display *dpy,
00166 int screen
00167 ){
00168 XExtDisplayInfo *info = find_display (dpy);
00169 xnvCtrlIsNvReply rep;
00170 xnvCtrlIsNvReq *req;
00171 Bool isnv;
00172
00173 if(!XextHasExtension(info))
00174 return False;
00175
00176 XNVCTRLCheckExtension (dpy, info, False);
00177
00178 LockDisplay (dpy);
00179 GetReq (nvCtrlIsNv, req);
00180 req->reqType = info->codes->major_opcode;
00181 req->nvReqType = X_nvCtrlIsNv;
00182 req->screen = screen;
00183 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
00184 UnlockDisplay (dpy);
00185 SyncHandle ();
00186 return False;
00187 }
00188 isnv = rep.isnv;
00189 UnlockDisplay (dpy);
00190 SyncHandle ();
00191 return isnv;
00192 }
00193
00194
00195 Bool XNVCTRLQueryTargetCount (
00196 Display *dpy,
00197 int target_type,
00198 int *value
00199 ){
00200 XExtDisplayInfo *info = find_display (dpy);
00201 xnvCtrlQueryTargetCountReply rep;
00202 xnvCtrlQueryTargetCountReq *req;
00203
00204 if(!XextHasExtension(info))
00205 return False;
00206
00207 XNVCTRLCheckExtension (dpy, info, False);
00208
00209 LockDisplay (dpy);
00210 GetReq (nvCtrlQueryTargetCount, req);
00211 req->reqType = info->codes->major_opcode;
00212 req->nvReqType = X_nvCtrlQueryTargetCount;
00213 req->target_type = target_type;
00214 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
00215 UnlockDisplay (dpy);
00216 SyncHandle ();
00217 return False;
00218 }
00219 if (value) *value = rep.count;
00220 UnlockDisplay (dpy);
00221 SyncHandle ();
00222 return True;
00223 }
00224
00225
00226 void XNVCTRLSetTargetAttribute (
00227 Display *dpy,
00228 int target_type,
00229 int target_id,
00230 unsigned int display_mask,
00231 unsigned int attribute,
00232 int value
00233 ){
00234 XExtDisplayInfo *info = find_display (dpy);
00235 xnvCtrlSetAttributeReq *req;
00236
00237 XNVCTRLSimpleCheckExtension (dpy, info);
00238 XNVCTRLCheckTargetData(dpy, info, &target_type, &target_id);
00239
00240 LockDisplay (dpy);
00241 GetReq (nvCtrlSetAttribute, req);
00242 req->reqType = info->codes->major_opcode;
00243 req->nvReqType = X_nvCtrlSetAttribute;
00244 req->target_type = target_type;
00245 req->target_id = target_id;
00246 req->display_mask = display_mask;
00247 req->attribute = attribute;
00248 req->value = value;
00249 UnlockDisplay (dpy);
00250 SyncHandle ();
00251 }
00252
00253 void XNVCTRLSetAttribute (
00254 Display *dpy,
00255 int screen,
00256 unsigned int display_mask,
00257 unsigned int attribute,
00258 int value
00259 ){
00260 XNVCTRLSetTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, screen,
00261 display_mask, attribute, value);
00262 }
00263
00264
00265 Bool XNVCTRLSetAttributeAndGetStatus (
00266 Display *dpy,
00267 int screen,
00268 unsigned int display_mask,
00269 unsigned int attribute,
00270 int value
00271 ){
00272 XExtDisplayInfo *info = find_display (dpy);
00273 xnvCtrlSetAttributeAndGetStatusReq *req;
00274 xnvCtrlSetAttributeAndGetStatusReply rep;
00275 Bool success;
00276
00277 if(!XextHasExtension(info))
00278 return False;
00279
00280 XNVCTRLCheckExtension (dpy, info, False);
00281
00282 LockDisplay (dpy);
00283 GetReq (nvCtrlSetAttributeAndGetStatus, req);
00284 req->reqType = info->codes->major_opcode;
00285 req->nvReqType = X_nvCtrlSetAttributeAndGetStatus;
00286 req->screen = screen;
00287 req->display_mask = display_mask;
00288 req->attribute = attribute;
00289 req->value = value;
00290 if (!_XReply (dpy, (xReply *) &rep, 0, False)) {
00291 UnlockDisplay (dpy);
00292 SyncHandle ();
00293 return False;
00294 }
00295 UnlockDisplay (dpy);
00296 SyncHandle ();
00297
00298 success = rep.flags;
00299 return success;
00300 }
00301
00302
00303
00304 Bool XNVCTRLQueryTargetAttribute (
00305 Display *dpy,
00306 int target_type,
00307 int target_id,
00308 unsigned int display_mask,
00309 unsigned int attribute,
00310 int *value
00311 ){
00312 XExtDisplayInfo *info = find_display (dpy);
00313 xnvCtrlQueryAttributeReply rep;
00314 xnvCtrlQueryAttributeReq *req;
00315 Bool exists;
00316
00317 if(!XextHasExtension(info))
00318 return False;
00319
00320 XNVCTRLCheckExtension (dpy, info, False);
00321 XNVCTRLCheckTargetData(dpy, info, &target_type, &target_id);
00322
00323 LockDisplay (dpy);
00324 GetReq (nvCtrlQueryAttribute, req);
00325 req->reqType = info->codes->major_opcode;
00326 req->nvReqType = X_nvCtrlQueryAttribute;
00327 req->target_type = target_type;
00328 req->target_id = target_id;
00329 req->display_mask = display_mask;
00330 req->attribute = attribute;
00331 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
00332 UnlockDisplay (dpy);
00333 SyncHandle ();
00334 return False;
00335 }
00336 if (value) *value = rep.value;
00337 exists = rep.flags;
00338 UnlockDisplay (dpy);
00339 SyncHandle ();
00340 return exists;
00341 }
00342
00343 Bool XNVCTRLQueryAttribute (
00344 Display *dpy,
00345 int screen,
00346 unsigned int display_mask,
00347 unsigned int attribute,
00348 int *value
00349 ){
00350 return XNVCTRLQueryTargetAttribute(dpy, NV_CTRL_TARGET_TYPE_X_SCREEN,
00351 screen, display_mask, attribute, value);
00352 }
00353
00354
00355 Bool XNVCTRLQueryTargetStringAttribute (
00356 Display *dpy,
00357 int target_type,
00358 int target_id,
00359 unsigned int display_mask,
00360 unsigned int attribute,
00361 char **ptr
00362 ){
00363 XExtDisplayInfo *info = find_display (dpy);
00364 xnvCtrlQueryStringAttributeReply rep;
00365 xnvCtrlQueryStringAttributeReq *req;
00366 Bool exists;
00367 int length, numbytes, slop;
00368
00369 if (!ptr) return False;
00370
00371 if(!XextHasExtension(info))
00372 return False;
00373
00374 XNVCTRLCheckExtension (dpy, info, False);
00375 XNVCTRLCheckTargetData(dpy, info, &target_type, &target_id);
00376
00377 LockDisplay (dpy);
00378 GetReq (nvCtrlQueryStringAttribute, req);
00379 req->reqType = info->codes->major_opcode;
00380 req->nvReqType = X_nvCtrlQueryStringAttribute;
00381 req->target_type = target_type;
00382 req->target_id = target_id;
00383 req->display_mask = display_mask;
00384 req->attribute = attribute;
00385 if (!_XReply (dpy, (xReply *) &rep, 0, False)) {
00386 UnlockDisplay (dpy);
00387 SyncHandle ();
00388 return False;
00389 }
00390 length = rep.length;
00391 numbytes = rep.n;
00392 slop = numbytes & 3;
00393 *ptr = (char *) Xmalloc(numbytes);
00394 if (! *ptr) {
00395 _XEatData(dpy, length);
00396 UnlockDisplay (dpy);
00397 SyncHandle ();
00398 return False;
00399 } else {
00400 _XRead(dpy, (char *) *ptr, numbytes);
00401 if (slop) _XEatData(dpy, 4-slop);
00402 }
00403 exists = rep.flags;
00404 UnlockDisplay (dpy);
00405 SyncHandle ();
00406 return exists;
00407 }
00408
00409 Bool XNVCTRLQueryStringAttribute (
00410 Display *dpy,
00411 int screen,
00412 unsigned int display_mask,
00413 unsigned int attribute,
00414 char **ptr
00415 ){
00416 return XNVCTRLQueryTargetStringAttribute(dpy, NV_CTRL_TARGET_TYPE_X_SCREEN,
00417 screen, display_mask,
00418 attribute, ptr);
00419 }
00420
00421
00422 Bool XNVCTRLSetStringAttribute (
00423 Display *dpy,
00424 int screen,
00425 unsigned int display_mask,
00426 unsigned int attribute,
00427 char *ptr
00428 ){
00429 XExtDisplayInfo *info = find_display (dpy);
00430 xnvCtrlSetStringAttributeReq *req;
00431 xnvCtrlSetStringAttributeReply rep;
00432 int size;
00433 Bool success;
00434
00435 if(!XextHasExtension(info))
00436 return False;
00437
00438 XNVCTRLCheckExtension (dpy, info, False);
00439
00440 size = strlen(ptr)+1;
00441
00442 LockDisplay (dpy);
00443 GetReq (nvCtrlSetStringAttribute, req);
00444 req->reqType = info->codes->major_opcode;
00445 req->nvReqType = X_nvCtrlSetStringAttribute;
00446 req->screen = screen;
00447 req->display_mask = display_mask;
00448 req->attribute = attribute;
00449 req->length += ((size + 3) & ~3) >> 2;
00450 req->num_bytes = size;
00451 Data(dpy, ptr, size);
00452
00453 if (!_XReply (dpy, (xReply *) &rep, 0, False)) {
00454 UnlockDisplay (dpy);
00455 SyncHandle ();
00456 return False;
00457 }
00458 UnlockDisplay (dpy);
00459 SyncHandle ();
00460
00461 success = rep.flags;
00462 return success;
00463 }
00464
00465
00466 Bool XNVCTRLQueryValidTargetAttributeValues (
00467 Display *dpy,
00468 int target_type,
00469 int target_id,
00470 unsigned int display_mask,
00471 unsigned int attribute,
00472 NVCTRLAttributeValidValuesRec *values
00473 ){
00474 XExtDisplayInfo *info = find_display (dpy);
00475 xnvCtrlQueryValidAttributeValuesReply rep;
00476 xnvCtrlQueryValidAttributeValuesReq *req;
00477 Bool exists;
00478
00479 if (!values) return False;
00480
00481 if(!XextHasExtension(info))
00482 return False;
00483
00484 XNVCTRLCheckExtension (dpy, info, False);
00485 XNVCTRLCheckTargetData(dpy, info, &target_type, &target_id);
00486
00487 LockDisplay (dpy);
00488 GetReq (nvCtrlQueryValidAttributeValues, req);
00489 req->reqType = info->codes->major_opcode;
00490 req->nvReqType = X_nvCtrlQueryValidAttributeValues;
00491 req->target_type = target_type;
00492 req->target_id = target_id;
00493 req->display_mask = display_mask;
00494 req->attribute = attribute;
00495 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
00496 UnlockDisplay (dpy);
00497 SyncHandle ();
00498 return False;
00499 }
00500 exists = rep.flags;
00501 values->type = rep.attr_type;
00502 if (rep.attr_type == ATTRIBUTE_TYPE_RANGE) {
00503 values->u.range.min = rep.min;
00504 values->u.range.max = rep.max;
00505 }
00506 if (rep.attr_type == ATTRIBUTE_TYPE_INT_BITS) {
00507 values->u.bits.ints = rep.bits;
00508 }
00509 values->permissions = rep.perms;
00510 UnlockDisplay (dpy);
00511 SyncHandle ();
00512 return exists;
00513 }
00514
00515 Bool XNVCTRLQueryValidAttributeValues (
00516 Display *dpy,
00517 int screen,
00518 unsigned int display_mask,
00519 unsigned int attribute,
00520 NVCTRLAttributeValidValuesRec *values
00521 ){
00522 return XNVCTRLQueryValidTargetAttributeValues(dpy,
00523 NV_CTRL_TARGET_TYPE_X_SCREEN,
00524 screen, display_mask,
00525 attribute, values);
00526 }
00527
00528
00529 void XNVCTRLSetGvoColorConversion (
00530 Display *dpy,
00531 int screen,
00532 float colorMatrix[3][3],
00533 float colorOffset[3],
00534 float colorScale[3]
00535 ){
00536 XExtDisplayInfo *info = find_display (dpy);
00537 xnvCtrlSetGvoColorConversionReq *req;
00538
00539 XNVCTRLSimpleCheckExtension (dpy, info);
00540
00541 LockDisplay (dpy);
00542 GetReq (nvCtrlSetGvoColorConversion, req);
00543 req->reqType = info->codes->major_opcode;
00544 req->nvReqType = X_nvCtrlSetGvoColorConversion;
00545 req->screen = screen;
00546
00547 req->cscMatrix_y_r = colorMatrix[0][0];
00548 req->cscMatrix_y_g = colorMatrix[0][1];
00549 req->cscMatrix_y_b = colorMatrix[0][2];
00550
00551 req->cscMatrix_cr_r = colorMatrix[1][0];
00552 req->cscMatrix_cr_g = colorMatrix[1][1];
00553 req->cscMatrix_cr_b = colorMatrix[1][2];
00554
00555 req->cscMatrix_cb_r = colorMatrix[2][0];
00556 req->cscMatrix_cb_g = colorMatrix[2][1];
00557 req->cscMatrix_cb_b = colorMatrix[2][2];
00558
00559 req->cscOffset_y = colorOffset[0];
00560 req->cscOffset_cr = colorOffset[1];
00561 req->cscOffset_cb = colorOffset[2];
00562
00563 req->cscScale_y = colorScale[0];
00564 req->cscScale_cr = colorScale[1];
00565 req->cscScale_cb = colorScale[2];
00566
00567 UnlockDisplay (dpy);
00568 SyncHandle ();
00569 }
00570
00571
00572 Bool XNVCTRLQueryGvoColorConversion (
00573 Display *dpy,
00574 int screen,
00575 float colorMatrix[3][3],
00576 float colorOffset[3],
00577 float colorScale[3]
00578 ){
00579 XExtDisplayInfo *info = find_display (dpy);
00580 xnvCtrlQueryGvoColorConversionReply rep;
00581 xnvCtrlQueryGvoColorConversionReq *req;
00582
00583 if(!XextHasExtension(info))
00584 return False;
00585
00586 XNVCTRLCheckExtension (dpy, info, False);
00587
00588 LockDisplay (dpy);
00589
00590 GetReq (nvCtrlQueryGvoColorConversion, req);
00591 req->reqType = info->codes->major_opcode;
00592 req->nvReqType = X_nvCtrlQueryGvoColorConversion;
00593 req->screen = screen;
00594
00595 if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
00596 UnlockDisplay (dpy);
00597 SyncHandle ();
00598 return False;
00599 }
00600
00601 _XRead(dpy, (char *)(colorMatrix), 36);
00602 _XRead(dpy, (char *)(colorOffset), 12);
00603 _XRead(dpy, (char *)(colorScale), 12);
00604
00605 UnlockDisplay (dpy);
00606 SyncHandle ();
00607
00608 return True;
00609 }
00610
00611
00612 Bool XNVCtrlSelectTargetNotify (
00613 Display *dpy,
00614 int target_type,
00615 int target_id,
00616 int notify_type,
00617 Bool onoff
00618 ){
00619 XExtDisplayInfo *info = find_display (dpy);
00620 xnvCtrlSelectTargetNotifyReq *req;
00621
00622 if(!XextHasExtension (info))
00623 return False;
00624
00625 XNVCTRLCheckExtension (dpy, info, False);
00626
00627 LockDisplay (dpy);
00628 GetReq (nvCtrlSelectTargetNotify, req);
00629 req->reqType = info->codes->major_opcode;
00630 req->nvReqType = X_nvCtrlSelectTargetNotify;
00631 req->target_type = target_type;
00632 req->target_id = target_id;
00633 req->notifyType = notify_type;
00634 req->onoff = onoff;
00635 UnlockDisplay (dpy);
00636 SyncHandle ();
00637
00638 return True;
00639 }
00640
00641
00642 Bool XNVCtrlSelectNotify (
00643 Display *dpy,
00644 int screen,
00645 int type,
00646 Bool onoff
00647 ){
00648 XExtDisplayInfo *info = find_display (dpy);
00649 xnvCtrlSelectNotifyReq *req;
00650
00651 if(!XextHasExtension (info))
00652 return False;
00653
00654 XNVCTRLCheckExtension (dpy, info, False);
00655
00656 LockDisplay (dpy);
00657 GetReq (nvCtrlSelectNotify, req);
00658 req->reqType = info->codes->major_opcode;
00659 req->nvReqType = X_nvCtrlSelectNotify;
00660 req->screen = screen;
00661 req->notifyType = type;
00662 req->onoff = onoff;
00663 UnlockDisplay (dpy);
00664 SyncHandle ();
00665
00666 return True;
00667 }
00668
00669 Bool XNVCTRLQueryTargetBinaryData (
00670 Display *dpy,
00671 int target_type,
00672 int target_id,
00673 unsigned int display_mask,
00674 unsigned int attribute,
00675 unsigned char **ptr,
00676 int *len
00677 ){
00678 XExtDisplayInfo *info = find_display (dpy);
00679 xnvCtrlQueryBinaryDataReply rep;
00680 xnvCtrlQueryBinaryDataReq *req;
00681 Bool exists;
00682 int length, numbytes, slop;
00683
00684 if (!ptr) return False;
00685
00686 if(!XextHasExtension(info))
00687 return False;
00688
00689 XNVCTRLCheckExtension (dpy, info, False);
00690 XNVCTRLCheckTargetData(dpy, info, &target_type, &target_id);
00691
00692 LockDisplay (dpy);
00693 GetReq (nvCtrlQueryBinaryData, req);
00694 req->reqType = info->codes->major_opcode;
00695 req->nvReqType = X_nvCtrlQueryBinaryData;
00696 req->target_type = target_type;
00697 req->target_id = target_id;
00698 req->display_mask = display_mask;
00699 req->attribute = attribute;
00700 if (!_XReply (dpy, (xReply *) &rep, 0, False)) {
00701 UnlockDisplay (dpy);
00702 SyncHandle ();
00703 return False;
00704 }
00705 length = rep.length;
00706 numbytes = rep.n;
00707 slop = numbytes & 3;
00708 *ptr = (char *) Xmalloc(numbytes);
00709 if (! *ptr) {
00710 _XEatData(dpy, length);
00711 UnlockDisplay (dpy);
00712 SyncHandle ();
00713 return False;
00714 } else {
00715 _XRead(dpy, (char *) *ptr, numbytes);
00716 if (slop) _XEatData(dpy, 4-slop);
00717 }
00718 exists = rep.flags;
00719 if (len) *len = numbytes;
00720 UnlockDisplay (dpy);
00721 SyncHandle ();
00722 return exists;
00723 }
00724
00725 Bool XNVCTRLQueryBinaryData (
00726 Display *dpy,
00727 int screen,
00728 unsigned int display_mask,
00729 unsigned int attribute,
00730 unsigned char **ptr,
00731 int *len
00732 ){
00733 return XNVCTRLQueryTargetBinaryData(dpy, NV_CTRL_TARGET_TYPE_X_SCREEN,
00734 screen, display_mask,
00735 attribute, ptr, len);
00736 }
00737
00738 Bool XNVCTRLStringOperation (
00739 Display *dpy,
00740 int target_type,
00741 int target_id,
00742 unsigned int display_mask,
00743 unsigned int attribute,
00744 char *pIn,
00745 char **ppOut
00746 ) {
00747 XExtDisplayInfo *info = find_display(dpy);
00748 xnvCtrlStringOperationReq *req;
00749 xnvCtrlStringOperationReply rep;
00750 Bool ret;
00751 int inSize, outSize, length, slop;
00752
00753 if (!XextHasExtension(info))
00754 return False;
00755
00756 if (!ppOut)
00757 return False;
00758
00759 *ppOut = NULL;
00760
00761 XNVCTRLCheckExtension(dpy, info, False);
00762 XNVCTRLCheckTargetData(dpy, info, &target_type, &target_id);
00763
00764 if (pIn) {
00765 inSize = strlen(pIn) + 1;
00766 } else {
00767 inSize = 0;
00768 }
00769
00770 LockDisplay(dpy);
00771 GetReq(nvCtrlStringOperation, req);
00772
00773 req->reqType = info->codes->major_opcode;
00774 req->nvReqType = X_nvCtrlStringOperation;
00775 req->target_type = target_type;
00776 req->target_id = target_id;
00777 req->display_mask = display_mask;
00778 req->attribute = attribute;
00779
00780 req->length += ((inSize + 3) & ~3) >> 2;
00781 req->num_bytes = inSize;
00782
00783 if (pIn) {
00784 Data(dpy, pIn, inSize);
00785 }
00786
00787 if (!_XReply (dpy, (xReply *) &rep, 0, False)) {
00788 UnlockDisplay(dpy);
00789 SyncHandle();
00790 return False;
00791 }
00792
00793 length = rep.length;
00794 outSize = rep.num_bytes;
00795 slop = outSize & 3;
00796
00797 if (outSize) *ppOut = (char *) Xmalloc(outSize);
00798
00799 if (!*ppOut) {
00800 _XEatData(dpy, length);
00801 } else {
00802 _XRead(dpy, (char *) *ppOut, outSize);
00803 if (slop) _XEatData(dpy, 4-slop);
00804 }
00805
00806 ret = rep.ret;
00807
00808 UnlockDisplay(dpy);
00809 SyncHandle();
00810
00811 return ret;
00812 }
00813
00814
00815 static Bool wire_to_event (Display *dpy, XEvent *host, xEvent *wire)
00816 {
00817 XExtDisplayInfo *info = find_display (dpy);
00818 XNVCtrlEvent *re;
00819 xnvctrlEvent *event;
00820 XNVCtrlEventTarget *reTarget;
00821 xnvctrlEventTarget *eventTarget;
00822 XNVCtrlEventTargetAvailability *reTargetAvailability;
00823 XNVCtrlStringEventTarget *reTargetString;
00824 XNVCtrlBinaryEventTarget *reTargetBinary;
00825
00826 XNVCTRLCheckExtension (dpy, info, False);
00827
00828 switch ((wire->u.u.type & 0x7F) - info->codes->first_event) {
00829 case ATTRIBUTE_CHANGED_EVENT:
00830 re = (XNVCtrlEvent *) host;
00831 event = (xnvctrlEvent *) wire;
00832 re->attribute_changed.type = event->u.u.type & 0x7F;
00833 re->attribute_changed.serial =
00834 _XSetLastRequestRead(dpy, (xGenericReply*) event);
00835 re->attribute_changed.send_event = ((event->u.u.type & 0x80) != 0);
00836 re->attribute_changed.display = dpy;
00837 re->attribute_changed.time = event->u.attribute_changed.time;
00838 re->attribute_changed.screen = event->u.attribute_changed.screen;
00839 re->attribute_changed.display_mask =
00840 event->u.attribute_changed.display_mask;
00841 re->attribute_changed.attribute = event->u.attribute_changed.attribute;
00842 re->attribute_changed.value = event->u.attribute_changed.value;
00843 break;
00844 case TARGET_ATTRIBUTE_CHANGED_EVENT:
00845 reTarget = (XNVCtrlEventTarget *) host;
00846 eventTarget = (xnvctrlEventTarget *) wire;
00847 reTarget->attribute_changed.type = eventTarget->u.u.type & 0x7F;
00848 reTarget->attribute_changed.serial =
00849 _XSetLastRequestRead(dpy, (xGenericReply*) eventTarget);
00850 reTarget->attribute_changed.send_event =
00851 ((eventTarget->u.u.type & 0x80) != 0);
00852 reTarget->attribute_changed.display = dpy;
00853 reTarget->attribute_changed.time =
00854 eventTarget->u.attribute_changed.time;
00855 reTarget->attribute_changed.target_type =
00856 eventTarget->u.attribute_changed.target_type;
00857 reTarget->attribute_changed.target_id =
00858 eventTarget->u.attribute_changed.target_id;
00859 reTarget->attribute_changed.display_mask =
00860 eventTarget->u.attribute_changed.display_mask;
00861 reTarget->attribute_changed.attribute =
00862 eventTarget->u.attribute_changed.attribute;
00863 reTarget->attribute_changed.value =
00864 eventTarget->u.attribute_changed.value;
00865 break;
00866 case TARGET_ATTRIBUTE_AVAILABILITY_CHANGED_EVENT:
00867 reTargetAvailability = (XNVCtrlEventTargetAvailability *) host;
00868 eventTarget = (xnvctrlEventTarget *) wire;
00869 reTargetAvailability->attribute_changed.type =
00870 eventTarget->u.u.type & 0x7F;
00871 reTargetAvailability->attribute_changed.serial =
00872 _XSetLastRequestRead(dpy, (xGenericReply*) eventTarget);
00873 reTargetAvailability->attribute_changed.send_event =
00874 ((eventTarget->u.u.type & 0x80) != 0);
00875 reTargetAvailability->attribute_changed.display = dpy;
00876 reTargetAvailability->attribute_changed.time =
00877 eventTarget->u.availability_changed.time;
00878 reTargetAvailability->attribute_changed.target_type =
00879 eventTarget->u.availability_changed.target_type;
00880 reTargetAvailability->attribute_changed.target_id =
00881 eventTarget->u.availability_changed.target_id;
00882 reTargetAvailability->attribute_changed.display_mask =
00883 eventTarget->u.availability_changed.display_mask;
00884 reTargetAvailability->attribute_changed.attribute =
00885 eventTarget->u.availability_changed.attribute;
00886 reTargetAvailability->attribute_changed.availability =
00887 eventTarget->u.availability_changed.availability;
00888 reTargetAvailability->attribute_changed.value =
00889 eventTarget->u.availability_changed.value;
00890 break;
00891 case TARGET_STRING_ATTRIBUTE_CHANGED_EVENT:
00892 reTargetString = (XNVCtrlStringEventTarget *) host;
00893 eventTarget = (xnvctrlEventTarget *) wire;
00894 reTargetString->attribute_changed.type = eventTarget->u.u.type & 0x7F;
00895 reTargetString->attribute_changed.serial =
00896 _XSetLastRequestRead(dpy, (xGenericReply*) eventTarget);
00897 reTargetString->attribute_changed.send_event =
00898 ((eventTarget->u.u.type & 0x80) != 0);
00899 reTargetString->attribute_changed.display = dpy;
00900 reTargetString->attribute_changed.time =
00901 eventTarget->u.attribute_changed.time;
00902 reTargetString->attribute_changed.target_type =
00903 eventTarget->u.attribute_changed.target_type;
00904 reTargetString->attribute_changed.target_id =
00905 eventTarget->u.attribute_changed.target_id;
00906 reTargetString->attribute_changed.display_mask =
00907 eventTarget->u.attribute_changed.display_mask;
00908 reTargetString->attribute_changed.attribute =
00909 eventTarget->u.attribute_changed.attribute;
00910 break;
00911 case TARGET_BINARY_ATTRIBUTE_CHANGED_EVENT:
00912 reTargetBinary = (XNVCtrlBinaryEventTarget *) host;
00913 eventTarget = (xnvctrlEventTarget *) wire;
00914 reTargetBinary->attribute_changed.type = eventTarget->u.u.type & 0x7F;
00915 reTargetBinary->attribute_changed.serial =
00916 _XSetLastRequestRead(dpy, (xGenericReply*) eventTarget);
00917 reTargetBinary->attribute_changed.send_event =
00918 ((eventTarget->u.u.type & 0x80) != 0);
00919 reTargetBinary->attribute_changed.display = dpy;
00920 reTargetBinary->attribute_changed.time =
00921 eventTarget->u.attribute_changed.time;
00922 reTargetBinary->attribute_changed.target_type =
00923 eventTarget->u.attribute_changed.target_type;
00924 reTargetBinary->attribute_changed.target_id =
00925 eventTarget->u.attribute_changed.target_id;
00926 reTargetBinary->attribute_changed.display_mask =
00927 eventTarget->u.attribute_changed.display_mask;
00928 reTargetBinary->attribute_changed.attribute =
00929 eventTarget->u.attribute_changed.attribute;
00930 break;
00931
00932 default:
00933 return False;
00934 }
00935
00936 return True;
00937 }
00938