int XvQueryAdaptors( Display *dpy, Window window, unsigned int *p_nAdaptors, XvAdaptorInfo **p_pAdaptors ){ XExtDisplayInfo *info = xv_find_display(dpy); xvQueryAdaptorsReq *req; xvQueryAdaptorsReply rep; int size,ii,jj; char *name; XvAdaptorInfo *pas, *pa; XvFormat *pfs, *pf; char *buffer; union { char *buffer; char *string; xvAdaptorInfo *pa; xvFormat *pf; } u; XvCheckExtension(dpy, info, XvBadExtension); LockDisplay(dpy); XvGetReq(QueryAdaptors, req); req->window = window; /* READ THE REPLY */ if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { UnlockDisplay(dpy); SyncHandle(); return(XvBadReply); } size = rep.length << 2; if ( (buffer = (char *)Xmalloc ((unsigned) size)) == NULL) { UnlockDisplay(dpy); SyncHandle(); return(XvBadAlloc); } _XRead (dpy, buffer, size); u.buffer = buffer; /* GET INPUT ADAPTORS */ if (rep.num_adaptors == 0) { pas = NULL; } else { size = rep.num_adaptors*sizeof(XvAdaptorInfo); if ((pas=(XvAdaptorInfo *)Xmalloc(size))==NULL) { Xfree(buffer); UnlockDisplay(dpy); SyncHandle(); return(XvBadAlloc); } } /* INIT ADAPTOR FIELDS */ pa = pas; for (ii=0; ii<rep.num_adaptors; ii++) { pa->num_adaptors = 0; pa->name = (char *)NULL; pa->formats = (XvFormat *)NULL; pa++; } pa = pas; for (ii=0; ii<rep.num_adaptors; ii++) { pa->type = u.pa->type; pa->base_id = u.pa->base_id; pa->num_ports = u.pa->num_ports; pa->num_formats = u.pa->num_formats; pa->num_adaptors = rep.num_adaptors - ii; /* GET ADAPTOR NAME */ size = u.pa->name_size; u.buffer += (sz_xvAdaptorInfo + 3) & ~3; if ( (name = (char *)Xmalloc(size+1)) == NULL) { XvFreeAdaptorInfo(pas); Xfree(buffer); UnlockDisplay(dpy); SyncHandle(); return(XvBadAlloc); } (void)strncpy(name, u.string, size); name[size] = '\0'; pa->name = name; u.buffer += (size + 3) & ~3; /* GET FORMATS */ size = pa->num_formats*sizeof(XvFormat); if ((pfs=(XvFormat *)Xmalloc(size))==NULL) { XvFreeAdaptorInfo(pas); Xfree(buffer); UnlockDisplay(dpy); SyncHandle(); return(XvBadAlloc); } pf = pfs; for (jj=0; jj<pa->num_formats; jj++) { pf->depth = u.pf->depth; pf->visual_id = u.pf->visual; pf++; u.buffer += (sz_xvFormat + 3) & ~3; } pa->formats = pfs; pa++; } *p_nAdaptors = rep.num_adaptors; *p_pAdaptors = pas; Xfree(buffer); UnlockDisplay(dpy); SyncHandle(); return (Success); }
/* * XFixesExtAddDisplay - add a display to this extension. (Replaces * XextAddDisplay) */ static XFixesExtDisplayInfo * XFixesExtAddDisplay (XFixesExtInfo *extinfo, Display *dpy, char *ext_name) { XFixesExtDisplayInfo *info; int ev; info = (XFixesExtDisplayInfo *) Xmalloc (sizeof (XFixesExtDisplayInfo)); if (!info) return NULL; info->display = dpy; info->codes = XInitExtension (dpy, ext_name); /* * if the server has the extension, then we can initialize the * appropriate function vectors */ if (info->codes) { xXFixesQueryVersionReply rep; xXFixesQueryVersionReq *req; XESetCloseDisplay (dpy, info->codes->extension, XFixesCloseDisplay); for (ev = info->codes->first_event; ev < info->codes->first_event + XFixesNumberEvents; ev++) { XESetWireToEvent (dpy, ev, XFixesWireToEvent); XESetEventToWire (dpy, ev, XFixesEventToWire); } /* * Get the version info */ LockDisplay (dpy); GetReq (XFixesQueryVersion, req); req->reqType = info->codes->major_opcode; req->xfixesReqType = X_XFixesQueryVersion; req->majorVersion = XFIXES_MAJOR; req->minorVersion = XFIXES_MINOR; if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { UnlockDisplay (dpy); SyncHandle (); Xfree(info); return NULL; } info->major_version = rep.majorVersion; info->minor_version = rep.minorVersion; UnlockDisplay (dpy); SyncHandle (); } else { /* The server doesn't have this extension. * Use a private Xlib-internal extension to hang the close_display * hook on so that the "cache" (extinfo->cur) is properly cleaned. * (XBUG 7955) */ XExtCodes *codes = XAddExtension(dpy); if (!codes) { XFree(info); return NULL; } XESetCloseDisplay (dpy, codes->extension, XFixesCloseDisplay); } /* * now, chain it onto the list */ _XLockMutex(_Xglobal_lock); info->next = extinfo->head; extinfo->head = info; extinfo->cur = info; extinfo->ndisplays++; _XUnlockMutex(_Xglobal_lock); return info; }
/* * NAME * XcmsAllocNamedColor - * * SYNOPSIS */ Status XcmsAllocNamedColor ( Display *dpy, Colormap cmap, _Xconst char *colorname, XcmsColor *pColor_scrn_return, XcmsColor *pColor_exact_return, XcmsColorFormat result_format) /* * DESCRIPTION * Finds the color specification associated with the color * name in the Device-Independent Color Name Database, then * converts that color specification to an RGB format. This * RGB value is then used in a call to XAllocColor to allocate * a read-only color cell. * * RETURNS * 0 if failed to parse string or find any entry in the database. * 1 if succeeded in converting color name to XcmsColor. * 2 if succeeded in converting color name to another color name. * */ { long nbytes; xAllocNamedColorReply rep; xAllocNamedColorReq *req; XColor hard_def; XColor exact_def; Status retval1 = 1; Status retval2 = XcmsSuccess; XcmsColor tmpColor; XColor XColor_in_out; XcmsCCC ccc; /* * 0. Check for invalid arguments. */ if (dpy == NULL || colorname[0] == '\0' || pColor_scrn_return == 0 || pColor_exact_return == NULL) { return(XcmsFailure); } if ((ccc = XcmsCCCOfColormap(dpy, cmap)) == (XcmsCCC)NULL) { return(XcmsFailure); } /* * 1. Convert string to a XcmsColor using Xcms and i18n mechanism */ if ((retval1 = _XcmsResolveColorString(ccc, &colorname, &tmpColor, result_format)) == XcmsFailure) { return(XcmsFailure); } if (retval1 == _XCMS_NEWNAME) { goto PassToServer; } memcpy((char *)pColor_exact_return, (char *)&tmpColor, sizeof(XcmsColor)); /* * 2. Convert tmpColor to RGB * Assume pColor_exact_return is now adjusted to Client White Point */ if ((retval2 = XcmsConvertColors(ccc, &tmpColor, 1, XcmsRGBFormat, (Bool *) NULL)) == XcmsFailure) { return(XcmsFailure); } /* * 3. Convert to XColor and call XAllocColor */ _XcmsRGB_to_XColor(&tmpColor, &XColor_in_out, 1); if (XAllocColor(ccc->dpy, cmap, &XColor_in_out) == 0) { return(XcmsFailure); } /* * 4. pColor_scrn_return * * Now convert to the target format. * We can ignore the return value because we're already in a * device-dependent format. */ _XColor_to_XcmsRGB(ccc, &XColor_in_out, pColor_scrn_return, 1); if (result_format != XcmsRGBFormat) { if (result_format == XcmsUndefinedFormat) { result_format = pColor_exact_return->format; } if (XcmsConvertColors(ccc, pColor_scrn_return, 1, result_format, (Bool *) NULL) == XcmsFailure) { return(XcmsFailure); } } return(retval1 > retval2 ? retval1 : retval2); PassToServer: /* * All previous methods failed, so lets pass it to the server * for parsing. */ dpy = ccc->dpy; LockDisplay(dpy); GetReq(AllocNamedColor, req); req->cmap = cmap; nbytes = req->nbytes = strlen(colorname); req->length += (nbytes + 3) >> 2; /* round up to mult of 4 */ _XSend(dpy, colorname, nbytes); /* _XSend is more efficient that Data, since _XReply follows */ if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { UnlockDisplay(dpy); SyncHandle(); return (0); } exact_def.red = rep.exactRed; exact_def.green = rep.exactGreen; exact_def.blue = rep.exactBlue; hard_def.red = rep.screenRed; hard_def.green = rep.screenGreen; hard_def.blue = rep.screenBlue; exact_def.pixel = hard_def.pixel = rep.pixel; UnlockDisplay(dpy); SyncHandle(); /* * Now convert to the target format. */ _XColor_to_XcmsRGB(ccc, &exact_def, pColor_exact_return, 1); _XColor_to_XcmsRGB(ccc, &hard_def, pColor_scrn_return, 1); if (result_format != XcmsRGBFormat && result_format != XcmsUndefinedFormat) { if (XcmsConvertColors(ccc, pColor_exact_return, 1, result_format, (Bool *) NULL) == XcmsFailure) { return(XcmsFailure); } if (XcmsConvertColors(ccc, pColor_scrn_return, 1, result_format, (Bool *) NULL) == XcmsFailure) { return(XcmsFailure); } } return(XcmsSuccess); }
int XDrawImageString( register Display *dpy, Drawable d, GC gc, int x, int y, _Xconst char *string, int length) { register xImageText8Req *req; char *CharacterOffset = (char *)string; int FirstTimeThrough = True; int lastX = 0; printf("XDrawImageString:%.*s\n", length, string); LockDisplay(dpy); FlushGC(dpy, gc); while (length > 0) { int Unit; if (length > 255) Unit = 255; else Unit = length; if (FirstTimeThrough) { FirstTimeThrough = False; } else { char buf[512]; char *ptr, *str; xQueryTextExtentsReq *qreq; xQueryTextExtentsReply rep; int i; GetReq(QueryTextExtents, qreq); qreq->fid = gc->gid; qreq->length += (510 + 3)>>2; qreq->oddLength = 1; str = CharacterOffset - 255; for (ptr = buf, i = 255; --i >= 0; ) { *ptr++ = 0; *ptr++ = *str++; } Data (dpy, buf, 510); if (!_XReply (dpy, (xReply *)&rep, 0, xTrue)) break; x = lastX + cvtINT32toInt (rep.overallWidth); } GetReq (ImageText8, req); req->length += (Unit + 3) >> 2; req->nChars = Unit; req->drawable = d; req->gc = gc->gid; req->y = y; lastX = req->x = x; Data (dpy, CharacterOffset, (long)Unit); CharacterOffset += Unit; length -= Unit; } UnlockDisplay(dpy); SyncHandle(); return 0; }
int __glXVForwardAllWithReply(__GLXclientState * cl, GLbyte * pc) { ClientPtr client = cl->client; xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *) pc; xGLXVendorPrivateReq *be_req; xGLXVendorPrivReply reply; xGLXVendorPrivReply be_reply; __GLXcontext *glxc; int buf_size; char *be_buf = NULL; int be_buf_size = 0; int from_screen = 0; int to_screen = 0; int s; DMXScreenInfo *dmxScreen; Display *dpy; glxc = __glXLookupContextByTag(cl, req->contextTag); if (!glxc) { return 0; } from_screen = to_screen = glxc->pScreen->myNum; #ifdef PANORAMIX if (!noPanoramiXExtension) { from_screen = 0; to_screen = screenInfo.numScreens - 1; } #endif pc += sz_xGLXVendorPrivateReq; buf_size = (req->length << 2) - sz_xGLXVendorPrivateReq; /* * send the request to the first back-end server(s) */ for (s = to_screen; s >= from_screen; s--) { dmxScreen = &dmxScreens[s]; dpy = GetBackEndDisplay(cl, s); LockDisplay(dpy); GetReqVendorPrivate(GLXVendorPrivate, be_req); be_req->reqType = dmxScreen->glxMajorOpcode; be_req->glxCode = req->glxCode; be_req->length = req->length; be_req->vendorCode = req->vendorCode; be_req->contextTag = GetCurrentBackEndTag(cl, req->contextTag, s); if (buf_size > 0) _XSend(dpy, (const char *) pc, buf_size); /* * get the reply from the back-end server */ _XReply(dpy, (xReply *) & be_reply, 0, False); be_buf_size = be_reply.length << 2; if (be_buf_size > 0) { be_buf = (char *) malloc(be_buf_size); if (be_buf) { _XRead(dpy, be_buf, be_buf_size); } else { /* Throw data on the floor */ _XEatData(dpy, be_buf_size); return BadAlloc; } } UnlockDisplay(dpy); SyncHandle(); if (s > from_screen && be_buf_size > 0) { free(be_buf); } } /* * send the reply to the client */ memcpy(&reply, &be_reply, sz_xGLXVendorPrivReply); reply.type = X_Reply; reply.sequenceNumber = client->sequence; if (client->swapped) { SendSwappedReply(client, &reply, be_buf, be_buf_size); } else { WriteToClient(client, sizeof(xGLXVendorPrivReply), (char *) &reply); if (be_buf_size > 0) WriteToClient(client, be_buf_size, (char *) be_buf); } if (be_buf_size > 0) free(be_buf); return Success; }
int XDrawImageString16( register Display *dpy, Drawable d, GC gc, int x, int y, _Xconst XChar2b *string, int length) { register xImageText16Req *req; XChar2b *CharacterOffset = (XChar2b *)string; int FirstTimeThrough = True; int lastX = 0; LockDisplay(dpy); FlushGC(dpy, gc); while (length > 0) { int Unit, Datalength; if (length > 255) Unit = 255; else Unit = length; if (FirstTimeThrough) { FirstTimeThrough = False; } else { char buf[512]; xQueryTextExtentsReq *qreq; xQueryTextExtentsReply rep; unsigned char *ptr; XChar2b *str; int i; GetReq(QueryTextExtents, qreq); qreq->fid = gc->gid; qreq->length += (510 + 3)>>2; qreq->oddLength = 1; str = CharacterOffset - 255; for (ptr = (unsigned char *)buf, i = 255; --i >= 0; str++) { *ptr++ = str->byte1; *ptr++ = str->byte2; } Data (dpy, buf, 510); if (!_XReply (dpy, (xReply *)&rep, 0, xTrue)) break; x = lastX + cvtINT32toInt (rep.overallWidth); } GetReq (ImageText16, req); req->length += ((Unit << 1) + 3) >> 2; req->nChars = Unit; req->drawable = d; req->gc = gc->gid; req->y = y; lastX = req->x = x; Datalength = Unit << 1; Data (dpy, (char *)CharacterOffset, (long)Datalength); CharacterOffset += Unit; length -= Unit; } UnlockDisplay(dpy); SyncHandle(); return 0; }
Bool NVCTRLQueryDDCCICapabilities ( Display *dpy, int screen, unsigned int display_mask, unsigned int **nvctrl_vcp_supported, unsigned int **possible_values_offset, unsigned int **possible_values_size, unsigned int **nvctrl_vcp_possible_values, unsigned int **nvctrl_string_vcp_supported ) { XExtDisplayInfo *info = find_display (dpy); xnvCtrlQueryDDCCICapabilitiesReply rep; xnvCtrlQueryDDCCICapabilitiesReq *req; Bool exists=1; int length, numbytes, slop; char *ptr, *p; int len1, len2, len3, len4, len5; *nvctrl_vcp_supported=*nvctrl_vcp_possible_values=*possible_values_offset=*possible_values_size=*nvctrl_string_vcp_supported=NULL; if(!XextHasExtension(info)) return False; XNVCTRLCheckExtension (dpy, info, False); LockDisplay (dpy); GetReq (nvCtrlQueryDDCCICapabilities, req); req->reqType = info->codes->major_opcode; req->nvReqType = X_nvCtrlQueryDDCCICapabilities; req->screen = screen; req->display_mask = display_mask; if (!_XReply (dpy, (xReply *) &rep, 0, False)) { UnlockDisplay (dpy); SyncHandle (); return False; } length = rep.length; numbytes = rep.num_bytes; slop = numbytes & 3; ptr = (char *) Xmalloc(numbytes); if (! ptr) { _XEatData(dpy, length); UnlockDisplay (dpy); SyncHandle (); return False; } else { _XRead(dpy, (char *) ptr, numbytes); if (slop) _XEatData(dpy, 4-slop); } exists = rep.flags; if(exists) { p = ptr; len1 = len2 = len3 = (NV_CTRL_DDCCI_LAST_VCP+1) << 2 ; len4 = rep.possible_val_len << 2; len5 = (NV_CTRL_STRING_LAST_ATTRIBUTE+1) << 2; *nvctrl_vcp_supported=(unsigned int *) Xmalloc(len1); *possible_values_offset=(unsigned int *) Xmalloc(len2); *possible_values_size=(unsigned int *) Xmalloc(len3); if(len4) *nvctrl_vcp_possible_values=(unsigned int *) Xmalloc(len4); *nvctrl_string_vcp_supported=(unsigned int *) Xmalloc(len5); memcpy((char*)*nvctrl_vcp_supported, p, len1); p += len1; memcpy((char*)*possible_values_offset, p, len2); p += len2; memcpy((char*)*possible_values_size, p, len3); p += len3; if(len4) { memcpy((char*)*nvctrl_vcp_possible_values, p, len4); p += len4; } memcpy((char*)*nvctrl_string_vcp_supported, p, len5); } free(ptr); UnlockDisplay (dpy); SyncHandle (); return exists; }
int XIChangeHierarchy(Display* dpy, XIAnyHierarchyChangeInfo* changes, int num_changes) { XIAnyHierarchyChangeInfo* any; xXIChangeHierarchyReq *req; XExtDisplayInfo *info = XInput_find_display(dpy); char *data = NULL, *dptr; int dlen = 0, i; LockDisplay(dpy); if (_XiCheckExtInit(dpy, XInput_2_0, info) == -1) return (NoSuchExtension); GetReq(XIChangeHierarchy, req); req->reqType = info->codes->major_opcode; req->ReqType = X_XIChangeHierarchy; req->num_changes = num_changes; /* alloc required memory */ for (i = 0, any = changes; i < num_changes; i++, any++) { switch(any->type) { case XIAddMaster: { int slen = (strlen(any->add.name)); dlen += sizeof(xXIAddMasterInfo) + slen + (4 - (slen % 4)); } break; case XIRemoveMaster: dlen += sizeof(xXIRemoveMasterInfo); break; case XIAttachSlave: dlen += sizeof(xXIAttachSlaveInfo); break; case XIDetachSlave: dlen += sizeof(xXIDetachSlaveInfo); break; default: return BadValue; } } req->length += dlen / 4; /* dlen is 4-byte aligned */ data = Xmalloc(dlen); if (!data) return BadAlloc; dptr = data; for (i = 0, any = changes; i < num_changes; i++, any++) { switch(any->type) { case XIAddMaster: { XIAddMasterInfo* C = &any->add; xXIAddMasterInfo* c = (xXIAddMasterInfo*)dptr; c->type = C->type; c->send_core = C->send_core; c->enable = C->enable; c->name_len = strlen(C->name); c->length = (sizeof(xXIAddMasterInfo) + c->name_len + 3)/4; strncpy((char*)&c[1], C->name, c->name_len); dptr += c->length; } break; case XIRemoveMaster: { XIRemoveMasterInfo* R = &any->remove; xXIRemoveMasterInfo* r = (xXIRemoveMasterInfo*)dptr; r->type = R->type; r->return_mode = R->return_mode; r->deviceid = R->deviceid; r->length = sizeof(xXIRemoveMasterInfo)/4; if (r->return_mode == XIAttachToMaster) { r->return_pointer = R->return_pointer; r->return_keyboard = R->return_keyboard; } dptr += sizeof(xXIRemoveMasterInfo); } break; case XIAttachSlave: { XIAttachSlaveInfo* C = &any->attach; xXIAttachSlaveInfo* c = (xXIAttachSlaveInfo*)dptr; c->type = C->type; c->deviceid = C->deviceid; c->length = sizeof(xXIAttachSlaveInfo)/4; c->new_master = C->new_master; dptr += sizeof(xXIAttachSlaveInfo); } break; case XIDetachSlave: { XIDetachSlaveInfo *D = &any->detach; xXIDetachSlaveInfo *d = (xXIDetachSlaveInfo*)dptr; d->type = D->type; d->deviceid = D->deviceid; d->length = sizeof(xXIDetachSlaveInfo)/4; dptr += sizeof(xXIDetachSlaveInfo); } } } Data(dpy, data, dlen); Xfree(data); UnlockDisplay(dpy); SyncHandle(); return Success; }
XIDeviceInfo* XIQueryDevice(Display *dpy, int deviceid, int *ndevices_return) { XIDeviceInfo *info = NULL; xXIQueryDeviceReq *req; xXIQueryDeviceReply reply; char *ptr; char *end; int i; char *buf; XExtDisplayInfo *extinfo = XInput_find_display(dpy); LockDisplay(dpy); if (_XiCheckExtInit(dpy, XInput_2_0, extinfo) == -1) goto error_unlocked; GetReq(XIQueryDevice, req); req->reqType = extinfo->codes->major_opcode; req->ReqType = X_XIQueryDevice; req->deviceid = deviceid; if (!_XReply(dpy, (xReply*) &reply, 0, xFalse)) goto error; if (reply.length < INT_MAX / 4) { *ndevices_return = reply.num_devices; info = Xmalloc((reply.num_devices + 1) * sizeof(XIDeviceInfo)); } else { *ndevices_return = 0; info = NULL; } if (!info) goto error; buf = Xmalloc(reply.length * 4); _XRead(dpy, buf, reply.length * 4); ptr = buf; end = buf + reply.length * 4; /* info is a null-terminated array */ info[reply.num_devices].name = NULL; for (i = 0; i < reply.num_devices; i++) { int nclasses; size_t sz; XIDeviceInfo *lib = &info[i]; xXIDeviceInfo *wire = (xXIDeviceInfo*)ptr; if (ptr + sizeof(xXIDeviceInfo) > end) goto error_loop; lib->deviceid = wire->deviceid; lib->use = wire->use; lib->attachment = wire->attachment; lib->enabled = wire->enabled; nclasses = wire->num_classes; ptr += sizeof(xXIDeviceInfo); if (ptr + wire->name_len > end) goto error_loop; lib->name = Xcalloc(wire->name_len + 1, 1); if (lib->name == NULL) goto error_loop; strncpy(lib->name, ptr, wire->name_len); lib->name[wire->name_len] = '\0'; ptr += ((wire->name_len + 3)/4) * 4; sz = size_classes((xXIAnyInfo*)ptr, nclasses); lib->classes = Xmalloc(sz); if (lib->classes == NULL) { Xfree(lib->name); goto error_loop; } ptr += copy_classes(lib, (xXIAnyInfo*)ptr, &nclasses); /* We skip over unused classes */ lib->num_classes = nclasses; } Xfree(buf); UnlockDisplay(dpy); SyncHandle(); return info; error_loop: while (--i >= 0) { Xfree(info[i].name); Xfree(info[i].classes); } error: UnlockDisplay(dpy); error_unlocked: SyncHandle(); *ndevices_return = -1; Xfree(buf); return NULL; }
XIDeviceInfo* XIQueryDevice(Display *dpy, int deviceid, int *ndevices_return) { XIDeviceInfo *info = NULL; xXIQueryDeviceReq *req; xXIQueryDeviceReply reply; char *ptr; int i; char *buf; XExtDisplayInfo *extinfo = XInput_find_display(dpy); LockDisplay(dpy); if (_XiCheckExtInit(dpy, XInput_2_0, extinfo) == -1) goto error; GetReq(XIQueryDevice, req); req->reqType = extinfo->codes->major_opcode; req->ReqType = X_XIQueryDevice; req->deviceid = deviceid; if (!_XReply(dpy, (xReply*) &reply, 0, xFalse)) goto error; *ndevices_return = reply.num_devices; info = Xmalloc((reply.num_devices + 1) * sizeof(XIDeviceInfo)); if (!info) goto error; buf = Xmalloc(reply.length * 4); _XRead(dpy, buf, reply.length * 4); ptr = buf; /* info is a null-terminated array */ info[reply.num_devices].name = NULL; for (i = 0; i < reply.num_devices; i++) { XIDeviceInfo *lib = &info[i]; xXIDeviceInfo *wire = (xXIDeviceInfo*)ptr; lib->deviceid = wire->deviceid; lib->use = wire->use; lib->attachment = wire->attachment; lib->enabled = wire->enabled; lib->num_classes = wire->num_classes; lib->classes = (XIAnyClassInfo**)&lib[1]; ptr += sizeof(xXIDeviceInfo); lib->name = Xcalloc(wire->name_len + 1, 1); strncpy(lib->name, ptr, wire->name_len); ptr += ((wire->name_len + 3)/4) * 4; lib->classes = Xmalloc(size_classes((xXIAnyInfo*)ptr, lib->num_classes)); ptr += copy_classes(lib, (xXIAnyInfo*)ptr, lib->num_classes); } Xfree(buf); UnlockDisplay(dpy); SyncHandle(); return info; error: UnlockDisplay(dpy); SyncHandle(); *ndevices_return = -1; return NULL; }
Bool XkbSelectEventDetails(Display *dpy, unsigned deviceSpec, unsigned eventType, unsigned long int affect, unsigned long int details) { register xkbSelectEventsReq *req; XkbInfoPtr xkbi; int size = 0; char *out; union { CARD8 *c8; CARD16 *c16; CARD32 *c32; } u; if ((dpy->flags & XlibDisplayNoXkb) || (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) return False; LockDisplay(dpy); xkbi = dpy->xkb_info; if (affect & details) xkbi->selected_events |= (1 << eventType); else xkbi->selected_events &= ~(1 << eventType); GetReq(kbSelectEvents, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbSelectEvents; req->deviceSpec = deviceSpec; req->clear = req->selectAll = 0; if (eventType == XkbMapNotify) { /* we need all of the client info, even if the application */ /* doesn't. Make sure that we always request the stuff */ /* that the implicit support needs, and just filter out anything */ /* the client doesn't want later */ req->affectMap = (CARD16) affect; req->map = (CARD16) details | (XkbAllClientInfoMask & affect); req->affectWhich = XkbMapNotifyMask; xkbi->selected_map_details &= ~affect; xkbi->selected_map_details |= (details & affect); } else { req->affectMap = req->map = 0; req->affectWhich = (1 << eventType); switch (eventType) { case XkbNewKeyboardNotify: xkbi->selected_nkn_details &= ~affect; xkbi->selected_nkn_details |= (details & affect); if (!(xkbi->xlib_ctrls & XkbLC_IgnoreNewKeyboards)) details = (affect & XkbAllNewKeyboardEventsMask); case XkbStateNotify: case XkbNamesNotify: case XkbAccessXNotify: case XkbExtensionDeviceNotify: size = 2; req->length += 1; break; case XkbControlsNotify: case XkbIndicatorStateNotify: case XkbIndicatorMapNotify: size = 4; req->length += 2; break; case XkbBellNotify: case XkbActionMessage: case XkbCompatMapNotify: size = 1; req->length += 1; break; } BufAlloc(char *, out, (((size * 2) + (unsigned) 3) / 4) * 4); u.c8 = (CARD8 *) out; if (size == 2) { u.c16[0] = (CARD16) affect; u.c16[1] = (CARD16) details; } else if (size == 4) { u.c32[0] = (CARD32) affect; u.c32[1] = (CARD32) details; } else { u.c8[0] = (CARD8) affect; u.c8[1] = (CARD8) details; } } UnlockDisplay(dpy); SyncHandle(); return True; }
XkbDescPtr XkbGetKeyboardByName( Display * dpy, unsigned deviceSpec, XkbComponentNamesPtr names, unsigned want, unsigned need, Bool load) { register xkbGetKbdByNameReq * req; xkbGetKbdByNameReply rep; int len,extraLen; char * str; XkbDescPtr xkb; int mapLen,codesLen,typesLen,compatLen; int symsLen,geomLen; XkbInfoPtr xkbi; if ( (dpy==NULL) || (dpy->flags & XlibDisplayNoXkb) || (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) ) return NULL; xkbi= dpy->xkb_info; xkb = (XkbDescRec *)_XkbCalloc(1,sizeof(XkbDescRec)); if (!xkb) return NULL; xkb->device_spec = deviceSpec; xkb->map = (XkbClientMapRec *)_XkbCalloc(1,sizeof(XkbClientMapRec)); xkb->dpy = dpy; LockDisplay(dpy); GetReq(kbGetKbdByName, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbGetKbdByName; req->deviceSpec = xkb->device_spec; req->want= want; req->need= need; req->load= load; mapLen= codesLen= typesLen= compatLen= symsLen= geomLen= 0; if (names) { if (names->keymap) mapLen= (int)strlen(names->keymap); if (names->keycodes) codesLen= (int)strlen(names->keycodes); if (names->types) typesLen= (int)strlen(names->types); if (names->compat) compatLen= (int)strlen(names->compat); if (names->symbols) symsLen= (int)strlen(names->symbols); if (names->geometry) geomLen= (int)strlen(names->geometry); if (mapLen>255) mapLen= 255; if (codesLen>255) codesLen= 255; if (typesLen>255) typesLen= 255; if (compatLen>255) compatLen= 255; if (symsLen>255) symsLen= 255; if (geomLen>255) geomLen= 255; } else mapLen= codesLen= typesLen= compatLen= symsLen= geomLen= 0; len= mapLen+codesLen+typesLen+compatLen+symsLen+geomLen+6; len= XkbPaddedSize(len); req->length+= len/4; BufAlloc(char *,str,len); *str++= mapLen; if (mapLen>0) { memcpy(str,names->keymap,mapLen); str+= mapLen; } *str++= codesLen; if (codesLen>0) { memcpy(str,names->keycodes,codesLen); str+= codesLen; } *str++= typesLen; if (typesLen>0) { memcpy(str,names->types,typesLen); str+= typesLen; } *str++= compatLen; if (compatLen>0) { memcpy(str,names->compat,compatLen); str+= compatLen; } *str++= symsLen; if (symsLen>0) { memcpy(str,names->symbols,symsLen); str+= symsLen; } *str++= geomLen; if (geomLen>0) { memcpy(str,names->geometry,geomLen); str+= geomLen; } if ((!_XReply(dpy, (xReply *)&rep, 0, xFalse))||(!rep.reported)) goto BAILOUT; extraLen= (int)rep.length*4; xkb->device_spec= rep.deviceID; xkb->min_key_code = rep.minKeyCode; xkb->max_key_code = rep.maxKeyCode; if (rep.reported&(XkbGBN_SymbolsMask|XkbGBN_TypesMask)) { xkbGetMapReply mrep; Status status; int nread= 0; _XRead(dpy, (char *)&mrep, SIZEOF(xkbGetMapReply)); extraLen-= SIZEOF(xkbGetMapReply); status= _XkbReadGetMapReply(dpy,&mrep,xkb,&nread); extraLen-= nread; if (status!=Success) goto BAILOUT; } if (rep.reported&XkbGBN_CompatMapMask) { xkbGetCompatMapReply crep; Status status; int nread= 0; _XRead(dpy, (char *)&crep, SIZEOF(xkbGetCompatMapReply)); extraLen-= SIZEOF(xkbGetCompatMapReply); status= _XkbReadGetCompatMapReply(dpy,&crep,xkb,&nread); extraLen-= nread; if (status!=Success) goto BAILOUT; } if (rep.reported&XkbGBN_IndicatorMapMask) { xkbGetIndicatorMapReply irep; Status status; int nread= 0; _XRead(dpy, (char *)&irep, SIZEOF(xkbGetIndicatorMapReply)); extraLen-= SIZEOF(xkbGetIndicatorMapReply); status= _XkbReadGetIndicatorMapReply(dpy,&irep,xkb,&nread); extraLen-= nread; if (status!=Success) goto BAILOUT; } if (rep.reported&(XkbGBN_KeyNamesMask|XkbGBN_OtherNamesMask)) { xkbGetNamesReply nrep; Status status; int nread= 0; _XRead(dpy, (char *)&nrep, SIZEOF(xkbGetNamesReply)); extraLen-= SIZEOF(xkbGetNamesReply); status= _XkbReadGetNamesReply(dpy,&nrep,xkb,&nread); extraLen-= nread; if (status!=Success) goto BAILOUT; } if (rep.reported&XkbGBN_GeometryMask) { xkbGetGeometryReply grep; Status status; int nread= 0; _XRead(dpy, (char *)&grep, SIZEOF(xkbGetGeometryReply)); extraLen-= SIZEOF(xkbGetGeometryReply); status= _XkbReadGetGeometryReply(dpy,&grep,xkb,&nread); extraLen-= nread; if (status!=Success) goto BAILOUT; } UnlockDisplay(dpy); SyncHandle(); return xkb; BAILOUT: if (xkb!=NULL) XkbFreeKeyboard(xkb,XkbAllComponentsMask,xTrue); UnlockDisplay(dpy); SyncHandle(); return NULL; }
XvImageFormatValues * XvListImageFormats ( Display *dpy, XvPortID port, int *num ){ XExtDisplayInfo *info = xv_find_display(dpy); xvListImageFormatsReq *req; xvListImageFormatsReply rep; XvImageFormatValues *ret = NULL; *num = 0; XvCheckExtension(dpy, info, NULL); LockDisplay(dpy); XvGetReq(ListImageFormats, req); req->port = port; /* READ THE REPLY */ if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { UnlockDisplay(dpy); SyncHandle(); return NULL; } if(rep.num_formats) { int size = (rep.num_formats * sizeof(XvImageFormatValues)); if((ret = Xmalloc(size))) { xvImageFormatInfo Info; int i; for(i = 0; i < rep.num_formats; i++) { _XRead(dpy, (char*)(&Info), sz_xvImageFormatInfo); ret[i].id = Info.id; ret[i].type = Info.type; ret[i].byte_order = Info.byte_order; memcpy(&(ret[i].guid[0]), &(Info.guid[0]), 16); ret[i].bits_per_pixel = Info.bpp; ret[i].format = Info.format; ret[i].num_planes = Info.num_planes; ret[i].depth = Info.depth; ret[i].red_mask = Info.red_mask; ret[i].green_mask = Info.green_mask; ret[i].blue_mask = Info.blue_mask; ret[i].y_sample_bits = Info.y_sample_bits; ret[i].u_sample_bits = Info.u_sample_bits; ret[i].v_sample_bits = Info.v_sample_bits; ret[i].horz_y_period = Info.horz_y_period; ret[i].horz_u_period = Info.horz_u_period; ret[i].horz_v_period = Info.horz_v_period; ret[i].vert_y_period = Info.vert_y_period; ret[i].vert_u_period = Info.vert_u_period; ret[i].vert_v_period = Info.vert_v_period; memcpy(&(ret[i].component_order[0]), &(Info.comp_order[0]), 32); ret[i].scanline_order = Info.scanline_order; (*num)++; } } else _XEatData(dpy, rep.length << 2); } UnlockDisplay(dpy); SyncHandle(); return ret; }
int XvQueryEncodings( Display *dpy, XvPortID port, unsigned int *p_nEncodings, XvEncodingInfo **p_pEncodings ){ XExtDisplayInfo *info = xv_find_display(dpy); xvQueryEncodingsReq *req; xvQueryEncodingsReply rep; int size, jj; char *name; XvEncodingInfo *pes, *pe; char *buffer; union { char *buffer; char *string; xvEncodingInfo *pe; } u; XvCheckExtension(dpy, info, XvBadExtension); LockDisplay(dpy); XvGetReq(QueryEncodings, req); req->port = port; /* READ THE REPLY */ if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) { UnlockDisplay(dpy); SyncHandle(); return(XvBadReply); } size = rep.length << 2; if ( (buffer = (char *)Xmalloc ((unsigned) size)) == NULL) { UnlockDisplay(dpy); SyncHandle(); return(XvBadAlloc); } _XRead (dpy, buffer, size); u.buffer = buffer; /* GET ENCODINGS */ size = rep.num_encodings*sizeof(XvEncodingInfo); if ( (pes = (XvEncodingInfo *)Xmalloc(size)) == NULL) { Xfree(buffer); UnlockDisplay(dpy); SyncHandle(); return(XvBadAlloc); } /* INITIALIZE THE ENCODING POINTER */ pe = pes; for (jj=0; jj<rep.num_encodings; jj++) { pe->name = (char *)NULL; pe->num_encodings = 0; pe++; } pe = pes; for (jj=0; jj<rep.num_encodings; jj++) { pe->encoding_id = u.pe->encoding; pe->width = u.pe->width; pe->height = u.pe->height; pe->rate.numerator = u.pe->rate.numerator; pe->rate.denominator = u.pe->rate.denominator; pe->num_encodings = rep.num_encodings - jj; size = u.pe->name_size; u.buffer += (sz_xvEncodingInfo + 3) & ~3; if ( (name = (char *)Xmalloc(size+1)) == NULL) { XvFreeEncodingInfo(pes); Xfree(buffer); UnlockDisplay(dpy); SyncHandle(); return(XvBadAlloc); } strncpy(name, u.string, size); name[size] = '\0'; pe->name = name; pe++; u.buffer += (size + 3) & ~3; } *p_nEncodings = rep.num_encodings; *p_pEncodings = pes; Xfree(buffer); UnlockDisplay(dpy); SyncHandle(); return (Success); }
void XRenderCompositeString32 (Display *dpy, int op, Picture src, Picture dst, _Xconst XRenderPictFormat *maskFormat, GlyphSet glyphset, int xSrc, int ySrc, int xDst, int yDst, _Xconst unsigned int *string, int nchar) { XExtDisplayInfo *info = XRenderFindDisplay (dpy); xRenderCompositeGlyphs8Req *req; long len; xGlyphElt *elt; int nbytes; if (!nchar) return; RenderSimpleCheckExtension (dpy, info); LockDisplay(dpy); GetReq(RenderCompositeGlyphs32, req); req->reqType = info->codes->major_opcode; req->renderReqType = X_RenderCompositeGlyphs32; req->op = op; req->src = src; req->dst = dst; req->maskFormat = maskFormat ? maskFormat->id : None; req->glyphset = glyphset; req->xSrc = xSrc; req->ySrc = ySrc; #define MAX_32 254 len = SIZEOF(xGlyphElt) * ((nchar + MAX_8-1) / MAX_8) + nchar * 4; req->length += (len + 3)>>2; /* convert to number of 32-bit words */ /* * If the entire request does not fit into the remaining space in the * buffer, flush the buffer first. */ if (dpy->bufptr + len > dpy->bufmax) _XFlush (dpy); while(nchar > MAX_32) { nbytes = MAX_32 * 4 + SIZEOF(xGlyphElt); BufAlloc (xGlyphElt *, elt, nbytes); elt->len = MAX_32; elt->deltax = xDst; elt->deltay = yDst; xDst = 0; yDst = 0; memcpy ((char *) (elt + 1), (char *) string, MAX_32 * 4); nchar = nchar - MAX_32; string += MAX_32; } if (nchar) { nbytes = nchar * 4 + SIZEOF(xGlyphElt); BufAlloc (xGlyphElt *, elt, nbytes); elt->len = nchar; elt->deltax = xDst; elt->deltay = yDst; memcpy ((char *) (elt + 1), (char *) string, nchar * 4); } UnlockDisplay(dpy); SyncHandle(); }
XIEventMask* XIGetSelectedEvents(Display* dpy, Window win, int *num_masks_return) { int i, len = 0; unsigned char *mask; XIEventMask *mask_out = NULL; xXIEventMask *mask_in = NULL, *mi; xXIGetSelectedEventsReq *req; xXIGetSelectedEventsReply reply; XExtDisplayInfo *info = XInput_find_display(dpy); *num_masks_return = -1; LockDisplay(dpy); if (_XiCheckExtInit(dpy, XInput_2_0, info) == -1) goto out; GetReq(XIGetSelectedEvents, req); req->reqType = info->codes->major_opcode; req->ReqType = X_XIGetSelectedEvents; req->win = win; if (!_XReply(dpy, (xReply *) &reply, 0, xFalse)) goto out; if (reply.num_masks == 0) { *num_masks_return = 0; goto out; } mask_in = Xmalloc(reply.length * 4); if (!mask_in) goto out; _XRead(dpy, (char*)mask_in, reply.length * 4); /* Memory layout of the XIEventMask for a 3 mask reply: * [struct a][struct b][struct c][masks a][masks b][masks c] */ len = reply.num_masks * sizeof(XIEventMask); for (i = 0, mi = mask_in; i < reply.num_masks; i++) { len += mi->mask_len * 4; mi = (xXIEventMask*)((char*)mi + mi->mask_len * 4); mi++; } mask_out = Xmalloc(len); if (!mask_out) goto out; mi = mask_in; mask = (unsigned char*)&mask_out[reply.num_masks]; for (i = 0; i < reply.num_masks; i++) { mask_out[i].deviceid = mi->deviceid; mask_out[i].mask_len = mi->mask_len * 4; mask_out[i].mask = mask; memcpy(mask_out[i].mask, &mi[1], mask_out[i].mask_len); mask += mask_out[i].mask_len; mi = (xXIEventMask*)((char*)mi + mi->mask_len * 4); mi++; } *num_masks_return = reply.num_masks; out: Xfree(mask_in); UnlockDisplay(dpy); SyncHandle(); return mask_out; }
void XRenderCompositeText32 (Display *dpy, int op, Picture src, Picture dst, _Xconst XRenderPictFormat *maskFormat, int xSrc, int ySrc, int xDst, int yDst, _Xconst XGlyphElt32 *elts, int nelt) { XExtDisplayInfo *info = XRenderFindDisplay (dpy); xRenderCompositeGlyphs32Req *req; long len; long elen; xGlyphElt *elt; int i; _Xconst unsigned int *chars; int nchars; if (!nelt) return; RenderSimpleCheckExtension (dpy, info); LockDisplay(dpy); GetReq(RenderCompositeGlyphs32, req); req->reqType = info->codes->major_opcode; req->renderReqType = X_RenderCompositeGlyphs32; req->op = op; req->src = src; req->dst = dst; req->maskFormat = maskFormat ? maskFormat->id : None; req->glyphset = elts[0].glyphset; req->xSrc = xSrc; req->ySrc = ySrc; /* * Compute the space necessary */ len = 0; for (i = 0; i < nelt; i++) { if (elts[i].glyphset != req->glyphset) len += (SIZEOF (xGlyphElt) + 4) >> 2; nchars = elts[i].nchars; elen = SIZEOF(xGlyphElt) * ((nchars + MAX_32) / MAX_32) + nchars *4; len += (elen + 3) >> 2; } req->length += len; /* * If the entire request does not fit into the remaining space in the * buffer, flush the buffer first. */ if (dpy->bufptr + (len << 2) > dpy->bufmax) _XFlush (dpy); for (i = 0; i < nelt; i++) { /* * Switch glyphsets */ if (elts[i].glyphset != req->glyphset) { BufAlloc (xGlyphElt *, elt, SIZEOF (xGlyphElt)); elt->len = 0xff; elt->deltax = 0; elt->deltay = 0; Data32(dpy, &elts[i].glyphset, 4); } nchars = elts[i].nchars; xDst = elts[i].xOff; yDst = elts[i].yOff; chars = elts[i].chars; while (nchars) { BufAlloc (xGlyphElt *, elt, SIZEOF(xGlyphElt)) elt->len = nchars > MAX_32 ? MAX_32 : nchars; elt->deltax = xDst; elt->deltay = yDst; xDst = 0; yDst = 0; Data32 (dpy, chars, elt->len * 4); nchars -= elt->len; chars += elt->len; } } UnlockDisplay(dpy); SyncHandle(); }
static Bool SendMakeCurrentRequest(Display * dpy, GLXContextID gc_id, GLXContextTag gc_tag, GLXDrawable draw, GLXDrawable read, GLXContextTag *out_tag) { xGLXMakeCurrentReply reply; Bool ret; int opcode = __glXSetupForCommand(dpy); LockDisplay(dpy); if (draw == read) { xGLXMakeCurrentReq *req; GetReq(GLXMakeCurrent, req); req->reqType = opcode; req->glxCode = X_GLXMakeCurrent; req->drawable = draw; req->context = gc_id; req->oldContextTag = gc_tag; } else { struct glx_display *priv = __glXInitialize(dpy); /* If the server can support the GLX 1.3 version, we should * perfer that. Not only that, some servers support GLX 1.3 but * not the SGI extension. */ if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) { xGLXMakeContextCurrentReq *req; GetReq(GLXMakeContextCurrent, req); req->reqType = opcode; req->glxCode = X_GLXMakeContextCurrent; req->drawable = draw; req->readdrawable = read; req->context = gc_id; req->oldContextTag = gc_tag; } else { xGLXVendorPrivateWithReplyReq *vpreq; xGLXMakeCurrentReadSGIReq *req; GetReqExtra(GLXVendorPrivateWithReply, sz_xGLXMakeCurrentReadSGIReq - sz_xGLXVendorPrivateWithReplyReq, vpreq); req = (xGLXMakeCurrentReadSGIReq *) vpreq; req->reqType = opcode; req->glxCode = X_GLXVendorPrivateWithReply; req->vendorCode = X_GLXvop_MakeCurrentReadSGI; req->drawable = draw; req->readable = read; req->context = gc_id; req->oldContextTag = gc_tag; } } ret = _XReply(dpy, (xReply *) &reply, 0, False); if (out_tag) *out_tag = reply.contextTag; UnlockDisplay(dpy); SyncHandle(); return ret; }
bool CClipboard::GetStringUTF8( //Copies the system clipboard string into sClip //Returns: true on success, false otherwise. // //Params: string& sClip) //(out) { if (!display && !Init()) { //Failed to load X, but at least we can have local clipboard sClip = sClipBuf; return true; } LockDisplay(); Window owner = Dyn::XGetSelectionOwner(display, xa.clipboard); UnlockDisplay(); Atom selection; if (owner == None || owner == window) { owner = DefaultRootWindow(display); selection = xa.clipboard; } else { //FIXME: Use TARGETS to check what formats are available, and handle XA_STRING SDL_Event event; owner = window; LockDisplay(); selection = Dyn::XInternAtom(display, "DeadlySelectionOfDeath3", False); Dyn::XConvertSelection(display, xa.clipboard, xa.utf8_string, selection, owner, CurrentTime); UnlockDisplay(); const Uint32 tick = SDL_GetTicks(); do while (SDL_PollEvent(&event)) if (event.type == SDL_SYSWMEVENT) { XEvent xevent = event.syswm.msg->event.xevent; if ((xevent.type == SelectionNotify) && (xevent.xselection.requestor == owner)) goto Selection_ready; } while (SDL_GetTicks() - tick < 1000); //Timeout fprintf(stderr, "Clipboard timeout\n"); return false; } Selection_ready: unsigned char *src; Atom seln_type; int seln_format; unsigned long nbytes, overflow; bool bSuccess = false; LockDisplay(); if (Dyn::XGetWindowProperty(display, owner, selection, 0, INT_MAX/4-1, False, xa.utf8_string, &seln_type, &seln_format, &nbytes, &overflow, &src) == Success) { if (seln_type == xa.utf8_string) { unsigned int ibytes = src[nbytes-1] ? nbytes : nbytes - 1; sClip.assign((const char*)src, ibytes); bSuccess = true; UnfixNewlines(sClip); } if (src) Dyn::XFree(src); } UnlockDisplay(); return bSuccess; }
int XDrawText16( register Display *dpy, Drawable d, GC gc, int x, int y, XTextItem16 *items, int nitems) { register int i; register XTextItem16 *item; int length = 0; register xPolyText16Req *req; LockDisplay(dpy); FlushGC(dpy, gc); GetReq (PolyText16, req); req->drawable = d; req->gc = gc->gid; req->x = x; req->y = y; item = items; for (i=0; i < nitems; i++) { if (item->font) length += 5; /* a 255 byte, plus size of Font id */ if (item->delta) { if (item->delta > 0) { length += SIZEOF(xTextElt) * ((item->delta + 126) / 127); } else { length += SIZEOF(xTextElt) * ((-item->delta + 127) / 128); } } if (item->nchars > 0) { length += SIZEOF(xTextElt) * ((item->nchars + 253) / 254 - 1); if (!item->delta) length += SIZEOF(xTextElt); length += item->nchars << 1; } item++; } req->length += (length + 3)>>2; /* convert to number of 32-bit words */ /* * If the entire request does not fit into the remaining space in the * buffer, flush the buffer first. If the request does fit into the * empty buffer, then we won't have to flush it at the end to keep * the buffer 32-bit aligned. */ if (dpy->bufptr + length > dpy->bufmax) _XFlush (dpy); item = items; for (i=0; i< nitems; i++) { if (item->font) { /* to mark a font shift, write a 255 byte followed by the 4 bytes of font ID, big-end first */ register unsigned char *f; BufAlloc (unsigned char *, f, 5); f[0] = 255; f[1] = (item->font & 0xff000000) >> 24; f[2] = (item->font & 0x00ff0000) >> 16; f[3] = (item->font & 0x0000ff00) >> 8; f[4] = item->font & 0x000000ff; /* update GC shadow */ gc->values.font = item->font; } { int nbytes = SIZEOF(xTextElt); int PartialNChars = item->nchars; int PartialDelta = item->delta; register xTextElt *elt = NULL; int FirstTimeThrough = True; XChar2b *CharacterOffset = item->chars; while((PartialDelta < -128) || (PartialDelta > 127)) { int nb = SIZEOF(xTextElt); BufAlloc (xTextElt *, elt, nb); elt->len = 0; if (PartialDelta > 0 ) { elt->delta = 127; PartialDelta = PartialDelta - 127; } else { elt->delta = -128; PartialDelta = PartialDelta + 128; } } if (PartialDelta) { BufAlloc (xTextElt *, elt, nbytes); elt->len = 0; elt->delta = PartialDelta; } while(PartialNChars > 254) { nbytes = 254 * 2; if (FirstTimeThrough) { FirstTimeThrough = False; if (!item->delta) { nbytes += SIZEOF(xTextElt); BufAlloc (xTextElt *, elt, nbytes); elt->delta = 0; } else { char *DummyChar; BufAlloc(char *, DummyChar, nbytes); #ifdef lint DummyChar = DummyChar; #endif } } else { nbytes += SIZEOF(xTextElt); BufAlloc (xTextElt *, elt, nbytes); elt->delta = 0; } elt->len = 254; #if defined(MUSTCOPY) || defined(MUSTCOPY2B) { register int i; register unsigned char *cp; for (i = 0, cp = ((unsigned char *)elt) + 2; i < 254; i++) { *cp++ = CharacterOffset[i].byte1; *cp++ = CharacterOffset[i].byte2; } } #else memcpy ((char *) (elt + 1), (char *)CharacterOffset, 254 * 2); #endif PartialNChars = PartialNChars - 254; CharacterOffset += 254; } if (PartialNChars) { nbytes = PartialNChars * 2; if (FirstTimeThrough) { FirstTimeThrough = False; if (!item->delta) { nbytes += SIZEOF(xTextElt); BufAlloc (xTextElt *, elt, nbytes); elt->delta = 0; } else { char *DummyChar; BufAlloc(char *, DummyChar, nbytes); #ifdef lint DummyChar = DummyChar; #endif } } else { nbytes += SIZEOF(xTextElt); BufAlloc (xTextElt *, elt, nbytes); elt->delta = 0; } elt->len = PartialNChars; #if defined(MUSTCOPY) || defined(MUSTCOPY2B) { register int i; register unsigned char *cp; for (i = 0, cp = ((unsigned char *)elt) + 2; i < PartialNChars; i++) { *cp++ = CharacterOffset[i].byte1; *cp++ = CharacterOffset[i].byte2; } } #else memcpy ((char *) (elt + 1), (char *)CharacterOffset, PartialNChars * 2); #endif } } item++; } /* Pad request out to a 32-bit boundary */ if (length &= 3) { char *pad; /* * BufAlloc is a macro that uses its last argument more than * once, otherwise I'd write "BufAlloc (char *, pad, 4-length)" */ length = 4 - length; BufAlloc (char *, pad, length); /* * if there are 3 bytes of padding, the first byte MUST be 0 * so the pad bytes aren't mistaken for a final xTextElt */ *pad = 0; } /* * If the buffer pointer is not now pointing to a 32-bit boundary, * we must flush the buffer so that it does point to a 32-bit boundary * at the end of this routine. */ if ((dpy->bufptr - dpy->buffer) & 3) _XFlush (dpy); UnlockDisplay(dpy); SyncHandle(); return 1; }
Bool XNVCTRLStringOperation ( Display *dpy, int target_type, int target_id, unsigned int display_mask, unsigned int attribute, char *pIn, char **ppOut ) { XExtDisplayInfo *info = find_display(dpy); xnvCtrlStringOperationReq *req; xnvCtrlStringOperationReply rep; Bool ret; int inSize, outSize, length, slop; if (!XextHasExtension(info)) return False; if (!ppOut) return False; *ppOut = NULL; XNVCTRLCheckExtension(dpy, info, False); XNVCTRLCheckTargetData(dpy, info, &target_type, &target_id); if (pIn) { inSize = strlen(pIn) + 1; } else { inSize = 0; } LockDisplay(dpy); GetReq(nvCtrlStringOperation, req); req->reqType = info->codes->major_opcode; req->nvReqType = X_nvCtrlStringOperation; req->target_type = target_type; req->target_id = target_id; req->display_mask = display_mask; req->attribute = attribute; req->length += ((inSize + 3) & ~3) >> 2; req->num_bytes = inSize; if (pIn) { Data(dpy, pIn, inSize); } if (!_XReply (dpy, (xReply *) &rep, 0, False)) { UnlockDisplay(dpy); SyncHandle(); return False; } length = rep.length; outSize = rep.num_bytes; slop = outSize & 3; if (outSize) *ppOut = (char *) Xmalloc(outSize); if (!*ppOut) { _XEatData(dpy, length); } else { _XRead(dpy, (char *) *ppOut, outSize); if (slop) _XEatData(dpy, 4-slop); } ret = rep.ret; UnlockDisplay(dpy); SyncHandle(); return ret; }
XDeviceTimeCoord * XGetDeviceMotionEvents( register Display *dpy, XDevice *dev, Time start, Time stop, int *nEvents, int *mode, int *axis_count) { xGetDeviceMotionEventsReq *req; xGetDeviceMotionEventsReply rep; XDeviceTimeCoord *tc; int *data, *bufp, *readp, *savp; long size, size2; int i, j; XExtDisplayInfo *info = XInput_find_display(dpy); LockDisplay(dpy); if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1) return ((XDeviceTimeCoord *) NoSuchExtension); GetReq(GetDeviceMotionEvents, req); req->reqType = info->codes->major_opcode; req->ReqType = X_GetDeviceMotionEvents; req->start = start; req->stop = stop; req->deviceid = dev->device_id; if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); *nEvents = 0; return (NULL); } *mode = rep.mode; *axis_count = rep.axes; *nEvents = rep.nEvents; if (!rep.nEvents) { UnlockDisplay(dpy); SyncHandle(); return (NULL); } size = rep.length << 2; size2 = rep.nEvents * (sizeof(XDeviceTimeCoord) + (rep.axes * sizeof(int))); savp = readp = (int *)Xmalloc(size); bufp = (int *)Xmalloc(size2); if (!bufp || !savp) { Xfree(bufp); Xfree(savp); *nEvents = 0; _XEatData(dpy, (unsigned long)size); UnlockDisplay(dpy); SyncHandle(); return (NULL); } _XRead(dpy, (char *)readp, size); tc = (XDeviceTimeCoord *) bufp; data = (int *)(tc + rep.nEvents); for (i = 0; i < *nEvents; i++, tc++) { tc->time = *readp++; tc->data = data; for (j = 0; j < *axis_count; j++) *data++ = *readp++; } XFree((char *)savp); UnlockDisplay(dpy); SyncHandle(); return ((XDeviceTimeCoord *) bufp); }
Status XLookupColor ( register Display *dpy, Colormap cmap, _Xconst char *spec, XColor *def, XColor *scr) { register int n; xLookupColorReply reply; register xLookupColorReq *req; XcmsCCC ccc; XcmsColor cmsColor_exact; /* * Let's Attempt to use Xcms and i18n approach to Parse Color */ if ((ccc = XcmsCCCOfColormap(dpy, cmap)) != (XcmsCCC)NULL) { const char *tmpName = spec; switch (_XcmsResolveColorString(ccc, &tmpName, &cmsColor_exact, XcmsRGBFormat)) { case XcmsSuccess: case XcmsSuccessWithCompression: _XcmsRGB_to_XColor(&cmsColor_exact, def, 1); memcpy((char *)scr, (char *)def, sizeof(XColor)); _XUnresolveColor(ccc, scr); return(1); case XcmsFailure: case _XCMS_NEWNAME: /* * if the result was _XCMS_NEWNAME tmpName points to * a string in cmsColNm.c:pairs table, for example, * gray70 would become tekhvc:0.0/70.0/0.0 */ break; } } /* * Xcms and i18n methods failed, so lets pass it to the server * for parsing. */ n = strlen (spec); LockDisplay(dpy); GetReq (LookupColor, req); req->cmap = cmap; req->nbytes = n; req->length += (n + 3) >> 2; Data (dpy, spec, (long)n); if (!_XReply (dpy, (xReply *) &reply, 0, xTrue)) { UnlockDisplay(dpy); SyncHandle(); return (0); } def->red = reply.exactRed; def->green = reply.exactGreen; def->blue = reply.exactBlue; scr->red = reply.screenRed; scr->green = reply.screenGreen; scr->blue = reply.screenBlue; UnlockDisplay(dpy); SyncHandle(); return (1); }
static BOOL DRI2Connect(Display *dpy, XID window, unsigned driver_type, char **device ) { XExtDisplayInfo *info = find_display(dpy); xDRI2ConnectReply rep; xDRI2ConnectReq *req; int dev_len, driv_len; char *driver; DRI2CheckExtension(dpy, info, False); LockDisplay(dpy); GetReq(DRI2Connect, req); req->reqType = info->codes->major_opcode; req->dri2ReqType = X_DRI2Connect; req->window = window; req->driverType = driver_type; if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); return False; } /* check string lengths */ dev_len = rep.deviceNameLength; driv_len = rep.driverNameLength; if (dev_len == 0 || driv_len == 0) { _XEatData(dpy, XALIGN(dev_len) + XALIGN(driv_len)); UnlockDisplay(dpy); SyncHandle(); return False; } /* read out driver */ driver = HeapAlloc(GetProcessHeap(), 0, driv_len + 1); if (!driver) { _XEatData(dpy, XALIGN(dev_len) + XALIGN(driv_len)); UnlockDisplay(dpy); SyncHandle(); return False; } _XReadPad(dpy, driver, driv_len); HeapFree(GetProcessHeap(), 0, driver); /* we don't need the driver */ /* read out device */ *device = HeapAlloc(GetProcessHeap(), 0, dev_len + 1); if (!*device) { _XEatData(dpy, XALIGN(dev_len)); UnlockDisplay(dpy); SyncHandle(); return False; } _XReadPad(dpy, *device, dev_len); (*device)[dev_len] = '\0'; UnlockDisplay(dpy); SyncHandle(); return True; }
XFixesCursorImage * XFixesGetCursorImage (Display *dpy) { XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy); xXFixesGetCursorImageAndNameReq *req; xXFixesGetCursorImageAndNameReply rep; int npixels; int nbytes_name; int nbytes, nread, rlength; XFixesCursorImage *image; char *name; XFixesCheckExtension (dpy, info, NULL); LockDisplay (dpy); GetReq (XFixesGetCursorImageAndName, req); req->reqType = info->codes->major_opcode; if (info->major_version >= 2) req->xfixesReqType = X_XFixesGetCursorImageAndName; else req->xfixesReqType = X_XFixesGetCursorImage; if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) { UnlockDisplay (dpy); SyncHandle (); return NULL; } if (info->major_version < 2) { rep.cursorName = None; rep.nbytes = 0; } npixels = rep.width * rep.height; nbytes_name = rep.nbytes; /* reply data length */ nbytes = (long) rep.length << 2; /* bytes of actual data in the reply */ nread = (npixels << 2) + nbytes_name; /* size of data returned to application */ rlength = (sizeof (XFixesCursorImage) + npixels * sizeof (unsigned long) + nbytes_name + 1); image = (XFixesCursorImage *) Xmalloc (rlength); if (!image) { _XEatData (dpy, nbytes); UnlockDisplay (dpy); SyncHandle (); return NULL; } image->x = rep.x; image->y = rep.y; image->width = rep.width; image->height = rep.height; image->xhot = rep.xhot; image->yhot = rep.yhot; image->cursor_serial = rep.cursorSerial; image->pixels = (unsigned long *) (image + 1); image->atom = rep.cursorName; name = (char *) (image->pixels + npixels); image->name = name; _XRead32 (dpy, (long *) image->pixels, npixels << 2); _XRead (dpy, name, nbytes_name); name[nbytes_name] = '\0'; /* null-terminate */ /* skip any padding */ if(nbytes > nread) { _XEatData (dpy, (unsigned long) (nbytes - nread)); } UnlockDisplay (dpy); SyncHandle (); return image; }
int XDrawString16( register Display *dpy, Drawable d, GC gc, int x, int y, _Xconst XChar2b *string, int length) { int Datalength = 0; register xPolyText16Req *req; if (length <= 0) return 0; LockDisplay(dpy); FlushGC(dpy, gc); GetReq (PolyText16, req); req->drawable = d; req->gc = gc->gid; req->x = x; req->y = y; Datalength += SIZEOF(xTextElt) * ((length + 253) / 254) + (length << 1); req->length += (Datalength + 3)>>2; /* convert to number of 32-bit words */ /* * If the entire request does not fit into the remaining space in the * buffer, flush the buffer first. If the request does fit into the * empty buffer, then we won't have to flush it at the end to keep * the buffer 32-bit aligned. */ if (dpy->bufptr + Datalength > dpy->bufmax) _XFlush (dpy); { int nbytes; int PartialNChars = length; register xTextElt *elt; XChar2b *CharacterOffset = (XChar2b *)string; while(PartialNChars > 254) { nbytes = 254 * 2 + SIZEOF(xTextElt); BufAlloc (xTextElt *, elt, nbytes); elt->delta = 0; elt->len = 254; #if defined(MUSTCOPY) || defined(MUSTCOPY2B) { register int i; register unsigned char *cp; for (i = 0, cp = ((unsigned char *)elt) + 2; i < 254; i++) { *cp++ = CharacterOffset[i].byte1; *cp++ = CharacterOffset[i].byte2; } } #else memcpy (((char *) elt) + 2, (char *)CharacterOffset, 254 * 2); #endif PartialNChars = PartialNChars - 254; CharacterOffset += 254; } if (PartialNChars) { nbytes = PartialNChars * 2 + SIZEOF(xTextElt); BufAlloc (xTextElt *, elt, nbytes); elt->delta = 0; elt->len = PartialNChars; #if defined(MUSTCOPY) || defined(MUSTCOPY2B) { register int i; register unsigned char *cp; for (i = 0, cp = ((unsigned char *)elt) + 2; i < PartialNChars; i++) { *cp++ = CharacterOffset[i].byte1; *cp++ = CharacterOffset[i].byte2; } } #else memcpy(((char *)elt) + 2, (char *)CharacterOffset, PartialNChars * 2); #endif } } /* Pad request out to a 32-bit boundary */ if (Datalength &= 3) { char *pad; /* * BufAlloc is a macro that uses its last argument more than * once, otherwise I'd write "BufAlloc (char *, pad, 4-length)" */ length = 4 - Datalength; BufAlloc (char *, pad, length); /* * if there are 3 bytes of padding, the first byte MUST be 0 * so the pad bytes aren't mistaken for a final xTextElt */ *pad = 0; } /* * If the buffer pointer is not now pointing to a 32-bit boundary, * we must flush the buffer so that it does point to a 32-bit boundary * at the end of this routine. */ if ((dpy->bufptr - dpy->buffer) & 3) _XFlush (dpy); UnlockDisplay(dpy); SyncHandle(); return 0; }
XkbComponentListPtr XkbListComponents( Display * dpy, unsigned deviceSpec, XkbComponentNamesPtr ptrns, int * max_inout) { register xkbListComponentsReq* req; xkbListComponentsReply rep; XkbInfoPtr xkbi; XkbComponentListPtr list; XkbReadBufferRec buf; int left; char * str; int extraLen,len,mapLen,codesLen,typesLen,compatLen,symsLen,geomLen; if ( (dpy==NULL) || (dpy->flags & XlibDisplayNoXkb) || (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL)) || (ptrns==NULL) || (max_inout==NULL)) return NULL; xkbi= dpy->xkb_info; LockDisplay(dpy); GetReq(kbListComponents, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbListComponents; req->deviceSpec = deviceSpec; req->maxNames = *max_inout; mapLen= codesLen= typesLen= compatLen= symsLen= geomLen= 0; if (ptrns->keymap) mapLen= (int)strlen(ptrns->keymap); if (ptrns->keycodes) codesLen= (int)strlen(ptrns->keycodes); if (ptrns->types) typesLen= (int)strlen(ptrns->types); if (ptrns->compat) compatLen= (int)strlen(ptrns->compat); if (ptrns->symbols) symsLen= (int)strlen(ptrns->symbols); if (ptrns->geometry) geomLen= (int)strlen(ptrns->geometry); if (mapLen>255) mapLen= 255; if (codesLen>255) codesLen= 255; if (typesLen>255) typesLen= 255; if (compatLen>255) compatLen= 255; if (symsLen>255) symsLen= 255; if (geomLen>255) geomLen= 255; len= mapLen+codesLen+typesLen+compatLen+symsLen+geomLen+6; len= XkbPaddedSize(len); req->length+= len/4; BufAlloc(char *,str,len); *str++= mapLen; if (mapLen>0) { memcpy(str,ptrns->keymap,mapLen); str+= mapLen; } *str++= codesLen; if (codesLen>0) { memcpy(str,ptrns->keycodes,codesLen); str+= codesLen; } *str++= typesLen; if (typesLen>0) { memcpy(str,ptrns->types,typesLen); str+= typesLen; } *str++= compatLen; if (compatLen>0) { memcpy(str,ptrns->compat,compatLen); str+= compatLen; } *str++= symsLen; if (symsLen>0) { memcpy(str,ptrns->symbols,symsLen); str+= symsLen; } *str++= geomLen; if (geomLen>0) { memcpy(str,ptrns->geometry,geomLen); str+= geomLen; } if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) goto BAILOUT; extraLen= (int)rep.length*4; *max_inout= rep.extra; if (extraLen==0) { /* no matches, but we don't want to report a failure */ list= _XkbTypedCalloc(1,XkbComponentListRec); UnlockDisplay(dpy); SyncHandle(); return list; } if (_XkbInitReadBuffer(dpy,&buf,extraLen)) { Status status; status= Success; list= _XkbTypedCalloc(1,XkbComponentListRec); if (!list) { _XkbFreeReadBuffer(&buf); goto BAILOUT; } list->num_keymaps= rep.nKeymaps; list->num_keycodes= rep.nKeycodes; list->num_types= rep.nTypes; list->num_compat= rep.nCompatMaps; list->num_symbols= rep.nSymbols; list->num_geometry= rep.nGeometries; if ((status==Success)&&(list->num_keymaps>0)) list->keymaps= _ReadListing(&buf,list->num_keymaps,&status); if ((status==Success)&&(list->num_keycodes>0)) list->keycodes= _ReadListing(&buf,list->num_keycodes,&status); if ((status==Success)&&(list->num_types>0)) list->types= _ReadListing(&buf,list->num_types,&status); if ((status==Success)&&(list->num_compat>0)) list->compat= _ReadListing(&buf,list->num_compat,&status); if ((status==Success)&&(list->num_symbols>0)) list->symbols= _ReadListing(&buf,list->num_symbols,&status); if ((status==Success)&&(list->num_geometry>0)) list->geometry= _ReadListing(&buf,list->num_geometry,&status); left= _XkbFreeReadBuffer(&buf); if ((status!=Success)||(buf.error)||(left>2)) { XkbFreeComponentList(list); goto BAILOUT; } UnlockDisplay(dpy); SyncHandle(); return list; } BAILOUT: UnlockDisplay(dpy); SyncHandle(); return NULL; }
Status XeviGetVisualInfo( register Display *dpy, VisualID *visual, int n_visual, ExtendedVisualInfo **evi_return, int *n_info_return) { XExtDisplayInfo *info = find_display (dpy); register xEVIGetVisualInfoReq *req; xEVIGetVisualInfoReply rep; int sz_info, sz_xInfo, sz_conflict, sz_xConflict; VisualID32 *temp_conflict, *temp_visual, *xConflictPtr; VisualID *conflict; xExtendedVisualInfo *temp_xInfo; XVisualInfo *vinfo; register ExtendedVisualInfo *infoPtr; register xExtendedVisualInfo *xInfoPtr; register int n_data, visualIndex, vinfoIndex; Bool isValid; XeviCheckExtension (dpy, info, 0); *n_info_return = 0; *evi_return = NULL; vinfo = XGetVisualInfo(dpy, 0, NULL, &sz_info); if (!vinfo || !evi_return) { return BadValue; } if (!n_visual || !visual) { /* copy the all visual */ temp_visual = (VisualID32 *)Xmalloc(sz_VisualID32 * sz_info); n_visual = 0; for (vinfoIndex = 0; vinfoIndex < sz_info; vinfoIndex++) if (notInList(temp_visual, n_visual, vinfo[vinfoIndex].visualid)) temp_visual[n_visual++] = vinfo[vinfoIndex].visualid; } else { /* check if the visual is valid */ for (visualIndex = 0; visualIndex < n_visual; visualIndex++) { isValid = False; for (vinfoIndex = 0; vinfoIndex < sz_info; vinfoIndex++) { if (visual[visualIndex] == vinfo[vinfoIndex].visualid) { isValid = True; break; } } if (!isValid) { XFree(vinfo); return BadValue; } } temp_visual = (VisualID32 *)Xmalloc(sz_VisualID32 * n_visual); for (visualIndex = 0; visualIndex < n_visual; visualIndex++) temp_visual[visualIndex] = visual[visualIndex]; } XFree(vinfo); LockDisplay(dpy); GetReq(EVIGetVisualInfo, req); req->reqType = info->codes->major_opcode; req->xeviReqType = X_EVIGetVisualInfo; req->n_visual = n_visual; SetReqLen(req, n_visual, 1); Data(dpy, (char *)temp_visual, n_visual * sz_VisualID32); if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); Xfree(temp_visual); return BadAccess; } Xfree(temp_visual); sz_info = rep.n_info * sizeof(ExtendedVisualInfo); sz_xInfo = rep.n_info * sz_xExtendedVisualInfo; sz_conflict = rep.n_conflicts * sizeof(VisualID); sz_xConflict = rep.n_conflicts * sz_VisualID32; infoPtr = *evi_return = (ExtendedVisualInfo *)Xmalloc(sz_info + sz_conflict); xInfoPtr = temp_xInfo = (xExtendedVisualInfo *)Xmalloc(sz_xInfo); xConflictPtr = temp_conflict = (VisualID32 *)Xmalloc(sz_xConflict); if (!*evi_return || !temp_xInfo || !temp_conflict) { _XEatData(dpy, (sz_xInfo + sz_xConflict + 3) & ~3); UnlockDisplay(dpy); SyncHandle(); if (evi_return) Xfree(evi_return); if (temp_xInfo) Xfree(temp_xInfo); if (temp_conflict) Xfree(temp_conflict); return BadAlloc; } _XRead(dpy, (char *)temp_xInfo, sz_xInfo); _XRead(dpy, (char *)temp_conflict, sz_xConflict); UnlockDisplay(dpy); SyncHandle(); n_data = rep.n_info; conflict = (VisualID *)(infoPtr + n_data); while (n_data-- > 0) { infoPtr->core_visual_id = xInfoPtr->core_visual_id; infoPtr->screen = xInfoPtr->screen; infoPtr->level = xInfoPtr->level; infoPtr->transparency_type = xInfoPtr->transparency_type; infoPtr->transparency_value = xInfoPtr->transparency_value; infoPtr->min_hw_colormaps = xInfoPtr->min_hw_colormaps; infoPtr->max_hw_colormaps = xInfoPtr->max_hw_colormaps; infoPtr->num_colormap_conflicts = xInfoPtr->num_colormap_conflicts; infoPtr->colormap_conflicts = conflict; conflict += infoPtr->num_colormap_conflicts; infoPtr++; xInfoPtr++; } n_data = rep.n_conflicts; conflict = (VisualID *)(infoPtr); while (n_data-- > 0) *conflict++ = *xConflictPtr++; Xfree(temp_xInfo); Xfree(temp_conflict); *n_info_return = rep.n_info; return Success; }
Status XcupGetReservedColormapEntries( Display* dpy, int screen, XColor** colors_out, int* ncolors) { XExtDisplayInfo *info = find_display (dpy); xXcupGetReservedColormapEntriesReply rep; xXcupGetReservedColormapEntriesReq *req; xColorItem rbuf[TYP_RESERVED_ENTRIES]; *ncolors = 0; XextCheckExtension (dpy, info, xcup_extension_name, False); LockDisplay(dpy); GetReq(XcupGetReservedColormapEntries, req); req->reqType = info->codes->major_opcode; req->xcupReqType = X_XcupGetReservedColormapEntries; req->screen = screen; if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) { long nbytes; xColorItem* rbufp; int nentries = rep.length / 3; nbytes = nentries * SIZEOF (xColorItem); if (nentries > TYP_RESERVED_ENTRIES) rbufp = (xColorItem*) Xmalloc (nbytes); else rbufp = rbuf; if (rbufp == NULL) { _XEatData (dpy, (unsigned long) nbytes); UnlockDisplay (dpy); SyncHandle (); return False; } _XRead (dpy, (char*) rbufp, nbytes); *colors_out = (XColor*) Xmalloc (nentries * sizeof (XColor)); if (*colors_out) { xColorItem* cs = (xColorItem *) rbufp; XColor* cd = *colors_out; int i; *ncolors = nentries; for (i = 0; i < *ncolors; i++, cd++) { cd->pixel = cs->pixel; cd->red = cs->red; cd->green = cs->green; cd->blue = cs->blue; cs = (xColorItem*) (((char*) cs) + SIZEOF(xColorItem)); } if (rbufp != rbuf) XFree ((char*) rbufp); UnlockDisplay(dpy); SyncHandle(); return True; } if (rbufp != rbuf) XFree ((char*) rbufp); } UnlockDisplay(dpy); SyncHandle(); return False; }
int XRefreshKeyboardMapping(register XMappingEvent *event) { XkbEvent *xkbevent = (XkbEvent *)event; Display *dpy = event->display; XkbMapChangesRec changes; XkbInfoPtr xkbi; /* always do this for input methods, which still use the old keymap */ (void) _XRefreshKeyboardMapping(event); if (_XkbUnavailable(dpy)) return 1; xkbi = dpy->xkb_info; if (((event->type&0x7f)-xkbi->codes->first_event)==XkbEventCode) return XkbRefreshKeyboardMapping(&xkbevent->map); if (xkbi->flags&XkbXlibNewKeyboard) { _XkbReloadDpy(dpy); return 1; } if ((xkbi->flags&XkbMapPending)||(event->request==MappingKeyboard)) { if (xkbi->flags&XkbMapPending) { changes= xkbi->changes; _XkbNoteCoreMapChanges(&changes,event,XKB_XLIB_MAP_MASK); } else { bzero(&changes,sizeof(changes)); changes.changed= XkbKeySymsMask; if (xkbi->desc->min_key_code<xkbi->desc->max_key_code) { changes.first_key_sym= xkbi->desc->min_key_code; changes.num_key_syms= xkbi->desc->max_key_code- xkbi->desc->min_key_code+1; } else { changes.first_key_sym= event->first_keycode; changes.num_key_syms= event->count; } } if (XkbGetMapChanges(dpy,xkbi->desc, &changes)!=Success) { #ifdef DEBUG fprintf(stderr,"Internal Error! XkbGetMapChanges failed:\n"); if (changes.changed&XkbKeyTypesMask) { int first= changes.first_type; int last= changes.first_type+changes.num_types-1; fprintf(stderr," types: %d..%d\n",first,last); } if (changes.changed&XkbKeySymsMask) { int first= changes.first_key_sym; int last= changes.first_key_sym+changes.num_key_syms-1; fprintf(stderr," symbols: %d..%d\n",first,last); } if (changes.changed&XkbKeyActionsMask) { int last,first= changes.first_key_act; last= changes.first_key_act+changes.num_key_acts-1; fprintf(stderr," acts: %d..%d\n",first,last); } if (changes.changed&XkbKeyBehaviorsMask) { int last,first= changes.first_key_behavior; last= first+changes.num_key_behaviors-1; fprintf(stderr," behaviors: %d..%d\n",first,last); } if (changes.changed&XkbVirtualModsMask) { fprintf(stderr,"virtual mods: 0x%04x\n", changes.vmods); } if (changes.changed&XkbExplicitComponentsMask) { int last,first= changes.first_key_explicit; last= first+changes.num_key_explicit-1; fprintf(stderr," explicit: %d..%d\n",first,last); } #endif } LockDisplay(dpy); if (xkbi->flags&XkbMapPending) { xkbi->flags&= ~XkbMapPending; bzero(&xkbi->changes,sizeof(XkbMapChangesRec)); } UnlockDisplay(dpy); } if (event->request==MappingModifier) { LockDisplay(dpy); if (xkbi->desc->map->modmap) { _XkbFree(xkbi->desc->map->modmap); xkbi->desc->map->modmap= NULL; } if (dpy->key_bindings) { register struct _XKeytrans *p; for (p = dpy->key_bindings; p; p = p->next) { register int i; p->state= 0; if (p->mlen>0) { for (i = 0; i < p->mlen; i++) { p->state|= XkbKeysymToModifiers(dpy,p->modifiers[i]); } if (p->state) p->state &= AllMods; else p->state = AnyModifier; } } } UnlockDisplay(dpy); } return 1; }