Bool XkbForceDeviceBell( Display * dpy, int deviceID, int bellClass, int bellID, int percent) { register xkbBellReq *req; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbBell,req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbBell; req->deviceSpec = deviceID; req->window = (CARD32)None; req->bellClass = (CARD16)bellClass; req->bellID = (CARD16)bellID; req->percent = percent; req->forceSound = True; req->eventOnly = False; req->pitch = 0; req->duration = 0; req->name = None; req->pad1= 0; req->pad2= 0; UnlockDisplay(dpy); SyncHandle(); return True; }
Status XkbGetNamedGeometry(Display *dpy, XkbDescPtr xkb, Atom name) { xkbGetGeometryReq *req; xkbGetGeometryReply rep; Status status; if ((name == None) || (dpy->flags & XlibDisplayNoXkb) || (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) return BadAccess; LockDisplay(dpy); GetReq(kbGetGeometry, req); req->reqType = dpy->xkb_info->codes->major_opcode; req->xkbReqType = X_kbGetGeometry; req->deviceSpec = xkb->device_spec; req->name = (CARD32) name; if ((!_XReply(dpy, (xReply *) &rep, 0, xFalse)) || (!rep.found)) status = BadImplementation; else if (!rep.found) status = BadName; else status = _XkbReadGetGeometryReply(dpy, &rep, xkb, NULL); UnlockDisplay(dpy); SyncHandle(); return status; }
Bool XkbSetDebuggingFlags( Display * dpy, unsigned int mask, unsigned int flags, char * msg, unsigned int ctrls_mask, unsigned int ctrls, unsigned int * rtrn_flags, unsigned int * rtrn_ctrls) { register xkbSetDebuggingFlagsReq *req; xkbSetDebuggingFlagsReply rep; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbSetDebuggingFlags, req); req->reqType= xkbi->codes->major_opcode; req->xkbReqType= X_kbSetDebuggingFlags; req->affectFlags= mask; req->flags= flags; req->affectCtrls= ctrls_mask; req->ctrls= ctrls; if (msg) { char *out; req->msgLength= (unsigned short)strlen(msg)+1; req->length+= (req->msgLength+(unsigned)3)>>2; BufAlloc(char *,out,((req->msgLength+(unsigned)3)/4)*4); memcpy(out,msg,req->msgLength); } else req->msgLength= 0;
Status XkbSetGeometry(Display *dpy,unsigned deviceSpec,XkbGeometryPtr geom) { xkbSetGeometryReq *req; Status ret; if ( (!geom) || (dpy->flags & XlibDisplayNoXkb) || (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) return BadAccess; GetReq(kbSetGeometry, req); req->reqType = dpy->xkb_info->codes->major_opcode; req->xkbReqType = X_kbSetGeometry; req->deviceSpec = deviceSpec; req->nShapes= geom->num_shapes; req->nSections= geom->num_sections; req->name= geom->name; req->widthMM= geom->width_mm; req->heightMM= geom->height_mm; req->nProperties= geom->num_properties; req->nColors= geom->num_colors; req->nDoodads= geom->num_doodads; req->nKeyAliases= geom->num_key_aliases; req->baseColorNdx= (geom->base_color-geom->colors); req->labelColorNdx= (geom->label_color-geom->colors); ret = _SendSetGeometry(dpy,geom,req); UnlockDisplay(dpy); SyncHandle(); return ret; }
Bool XkbLatchGroup(Display *dpy, unsigned int deviceSpec, unsigned int group) { register xkbLatchLockStateReq *req; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbLatchLockState, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbLatchLockState; req->deviceSpec = deviceSpec; req->affectModLatches = 0; req->modLatches = 0; req->latchGroup = True; req->groupLatch = group; req->affectModLocks = req->modLocks = 0; req->lockGroup = False; req->groupLock = 0; UnlockDisplay(dpy); SyncHandle(); return True; }
unsigned XkbGetXlibControls(Display *dpy) { if (!dpy->xkb_info) XkbUseExtension(dpy, NULL, NULL); if (!dpy->xkb_info) return 0; return dpy->xkb_info->xlib_ctrls; }
Bool XkbForceBell(Display *dpy,int percent) { if ((dpy->flags & XlibDisplayNoXkb) || (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) { XBell(dpy,percent); return False; } return XkbForceDeviceBell(dpy,XkbUseCoreKbd,XkbDfltXIClass,XkbDfltXIId, percent); }
Bool XkbBell(Display *dpy,Window window,int percent,Atom name) { if ((dpy->flags & XlibDisplayNoXkb) || (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) { XBell(dpy,percent); return False; } return XkbDeviceBell(dpy,window,XkbUseCoreKbd,XkbDfltXIClass,XkbDfltXIId, percent,name); }
unsigned XkbSetXlibControls(Display *dpy, unsigned affect, unsigned values) { if (!dpy->xkb_info) XkbUseExtension(dpy, NULL, NULL); if (!dpy->xkb_info) return 0; affect &= XkbLC_AllControls; dpy->xkb_info->xlib_ctrls &= ~affect; dpy->xkb_info->xlib_ctrls |= (affect & values); return dpy->xkb_info->xlib_ctrls; }
Bool XkbBellEvent(Display *dpy,Window window,int percent,Atom name) { if ((dpy->flags & XlibDisplayNoXkb) || (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) { return False; } /* class 0 = KbdFeedbackClass (X Input Extension) */ return XkbDeviceBellEvent(dpy,window,XkbUseCoreKbd, XkbDfltXIClass,XkbDfltXIId, percent,name); }
Bool XkbSelectEvents(Display *dpy, unsigned int deviceSpec, unsigned int affect, unsigned int selectAll) { register xkbSelectEventsReq *req; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || (!dpy->xkb_info && !XkbUseExtension(dpy, NULL, NULL))) return False; LockDisplay(dpy); xkbi = dpy->xkb_info; xkbi->selected_events &= ~affect; xkbi->selected_events |= (affect & selectAll); GetReq(kbSelectEvents, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbSelectEvents; req->deviceSpec = deviceSpec; req->affectWhich = (CARD16) affect; req->clear = affect & (~selectAll); req->selectAll = affect & selectAll; if (affect & XkbMapNotifyMask) { req->affectMap = XkbAllMapComponentsMask; /* the implicit support needs the client info */ /* even if the client itself doesn't want it */ if (selectAll & XkbMapNotifyMask) req->map = XkbAllMapEventsMask; else req->map = XkbAllClientInfoMask; if (selectAll & XkbMapNotifyMask) xkbi->selected_map_details = XkbAllMapEventsMask; else xkbi->selected_map_details = 0; } if (affect & XkbNewKeyboardNotifyMask) { if (selectAll & XkbNewKeyboardNotifyMask) xkbi->selected_nkn_details = XkbAllNewKeyboardEventsMask; else xkbi->selected_nkn_details = 0; if (!(xkbi->xlib_ctrls & XkbLC_IgnoreNewKeyboards)) { /* we want it, even if the client doesn't. Don't mess */ /* around with details -- ask for all of them and throw */ /* away the ones we don't need */ req->selectAll |= XkbNewKeyboardNotifyMask; } } UnlockDisplay(dpy); SyncHandle(); return True; }
bool RazorKbIndicatorEventFilter::initXkbExtension() { int code; int major = XkbMajorVersion; int minor = XkbMinorVersion; int XkbErrorBase; if (!XkbLibraryVersion(&major, &minor)) return false; if (!XkbQueryExtension(display, &code, &XkbEventBase, &XkbErrorBase, &major, &minor)) return false; if (!XkbUseExtension(display, &major, &minor)) return false; return true; }
static gboolean CheckXKB (void) { gboolean have_xkb = FALSE; Display *dpy; int opcode, errorBase, major, minor, xkbEventBase; gdk_error_trap_push (); dpy = GDK_DISPLAY (); have_xkb = XkbQueryExtension (dpy, &opcode, &xkbEventBase, &errorBase, &major, &minor) && XkbUseExtension (dpy, &major, &minor); XSync (dpy, FALSE); gdk_error_trap_pop (); return have_xkb; }
Bool XkbSetIndicatorMap(Display *dpy,unsigned long which,XkbDescPtr xkb) { register xkbSetIndicatorMapReq *req; register int i,bit; int nMaps; xkbIndicatorMapWireDesc *wire; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) return False; if ((!xkb)||(!which)||(!xkb->indicators)) return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbSetIndicatorMap, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbSetIndicatorMap; req->deviceSpec = xkb->device_spec; req->which = (CARD32)which; for (i=nMaps=0,bit=1;i<32;i++,bit<<=1) { if (which&bit) nMaps++; } req->length+= (nMaps*sizeof(XkbIndicatorMapRec))/4; BufAlloc(xkbIndicatorMapWireDesc *,wire, (nMaps*SIZEOF(xkbIndicatorMapWireDesc))); for (i=0,bit=1;i<32;i++,bit<<=1) { if (which&bit) { wire->flags= xkb->indicators->maps[i].flags; wire->whichGroups= xkb->indicators->maps[i].which_groups; wire->groups= xkb->indicators->maps[i].groups; wire->whichMods= xkb->indicators->maps[i].which_mods; wire->mods= xkb->indicators->maps[i].mods.real_mods; wire->virtualMods= xkb->indicators->maps[i].mods.vmods; wire->ctrls= xkb->indicators->maps[i].ctrls; wire++; } } UnlockDisplay(dpy); SyncHandle(); return True; }
static gboolean have_xkb (Display *dpy) { static int have_xkb = -1; if (have_xkb == -1) { int opcode, error_base, major, minor, xkb_event_base; have_xkb = XkbQueryExtension (dpy, &opcode, &xkb_event_base, &error_base, &major, &minor) && XkbUseExtension (dpy, &major, &minor); } return have_xkb; }
Status XkbGetCompatMap(Display *dpy,unsigned which,XkbDescPtr xkb) { register xkbGetCompatMapReq *req; xkbGetCompatMapReply rep; Status status; XkbInfoPtr xkbi; if ( (!dpy) || (!xkb) || (dpy->flags & XlibDisplayNoXkb) || ((xkb->dpy!=NULL)&&(xkb->dpy!=dpy)) || (!dpy->xkb_info && (!XkbUseExtension(dpy,NULL,NULL)))) return BadAccess; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbGetCompatMap, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbGetCompatMap; req->deviceSpec = xkb->device_spec; if (which&XkbSymInterpMask) req->getAllSI= True; else req->getAllSI= False; req->firstSI= req->nSI= 0; if (which&XkbGroupCompatMask) req->groups= XkbAllGroupsMask; else req->groups= 0; if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); return BadLength; } if (xkb->dpy==NULL) xkb->dpy= dpy; if (xkb->device_spec==XkbUseCoreKbd) xkb->device_spec= rep.deviceID; status = _XkbReadGetCompatMapReply(dpy,&rep,xkb,NULL); UnlockDisplay(dpy); SyncHandle(); return status; }
Status XkbGetGeometry(Display *dpy,XkbDescPtr xkb) { xkbGetGeometryReq *req; xkbGetGeometryReply rep; if ( (!xkb) || (dpy->flags & XlibDisplayNoXkb) || (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) return BadAccess; GetReq(kbGetGeometry, req); req->reqType = dpy->xkb_info->codes->major_opcode; req->xkbReqType = X_kbGetGeometry; req->deviceSpec = xkb->device_spec; req->name= None; if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) return BadImplementation; if (!rep.found) return BadName; return _XkbReadGetGeometryReply(dpy,&rep,xkb,NULL); }
LxQtKbIndicator::LxQtKbIndicator(const ILxQtPanelPluginStartupInfo &startupInfo): QObject(), ILxQtPanelPlugin(startupInfo), mContent(new QLabel()) { connect(this, SIGNAL(indicatorsChanged(uint,uint)), this, SLOT(setIndicators(uint,uint))); mContent->setAlignment(Qt::AlignCenter); int code; int major = XkbMajorVersion; int minor = XkbMinorVersion; int XkbErrorBase; mDisplay = QX11Info::display(); if (XkbLibraryVersion(&major, &minor)) if (XkbQueryExtension(mDisplay, &code, &mXkbEventBase, &XkbErrorBase, &major, &minor)) if (XkbUseExtension(mDisplay, &major, &minor)) XkbSelectEvents(mDisplay, XkbUseCoreKbd, XkbIndicatorStateNotifyMask, XkbIndicatorStateNotifyMask); QTimer::singleShot(0, this, SLOT(delayedInit())); }
Bool XkbGetIndicatorMap(Display *dpy,unsigned long which,XkbDescPtr xkb) { register xkbGetIndicatorMapReq * req; xkbGetIndicatorMapReply rep; XkbInfoPtr xkbi; Status status; if ((dpy->flags & XlibDisplayNoXkb) || (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) return BadAccess; if ((!which)||(!xkb)) return BadValue; LockDisplay(dpy); xkbi = dpy->xkb_info; if (!xkb->indicators) { xkb->indicators = _XkbTypedCalloc(1,XkbIndicatorRec); if (!xkb->indicators) { UnlockDisplay(dpy); SyncHandle(); return BadAlloc; } } GetReq(kbGetIndicatorMap, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbGetIndicatorMap; req->deviceSpec = xkb->device_spec; req->which = (CARD32)which; if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); return BadValue; } status= _XkbReadGetIndicatorMapReply(dpy,&rep,xkb,NULL); UnlockDisplay(dpy); SyncHandle(); return status; }
Bool XkbQueryExtension(Display *dpy, int *opcodeReturn, int *eventBaseReturn, int *errorBaseReturn, int *majorReturn, int *minorReturn) { if (!XkbUseExtension(dpy, majorReturn, minorReturn)) return False; if (opcodeReturn) *opcodeReturn = dpy->xkb_info->codes->major_opcode; if (eventBaseReturn) *eventBaseReturn = dpy->xkb_info->codes->first_event; if (errorBaseReturn) *errorBaseReturn = dpy->xkb_info->codes->first_error; if (majorReturn) *majorReturn = dpy->xkb_info->srv_major; if (minorReturn) *minorReturn = dpy->xkb_info->srv_minor; return True; }
Bool XkbSetCompatMap(Display *dpy,unsigned which,XkbDescPtr xkb,Bool updateActions) { register xkbSetCompatMapReq *req; Status ok; XkbInfoPtr xkbi; if ((dpy->flags & XlibDisplayNoXkb) || (dpy!=xkb->dpy) || (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) return False; if ((!xkb->compat) || ((which&XkbSymInterpMask)&&(!xkb->compat->sym_interpret))) return False; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbSetCompatMap, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbSetCompatMap; req->deviceSpec = xkb->device_spec; req->recomputeActions = updateActions; if (which&XkbSymInterpMask) { req->truncateSI = True; req->firstSI= 0; req->nSI= xkb->compat->num_si; } else { req->truncateSI = False; req->firstSI= 0; req->nSI= 0; } if (which&XkbGroupCompatMask) req->groups= XkbAllGroupsMask; else req->groups= 0; ok= _XkbWriteSetCompatMap(dpy,req,xkb); UnlockDisplay(dpy); SyncHandle(); return ok; }
static gboolean have_xkb (Display *dpy) { static int have_xkb = -1; if (have_xkb == -1) { #ifdef HAVE_X11_EXTENSIONS_XKB_H int opcode, error_base, major, minor, xkb_event_base; have_xkb = XkbQueryExtension (dpy, &opcode, &xkb_event_base, &error_base, &major, &minor) && XkbUseExtension (dpy, &major, &minor); #else have_xkb = 0; #endif } return have_xkb; }
static int _XkbLoadDpy(Display *dpy) { XkbInfoPtr xkbi; unsigned query,oldEvents; XkbDescRec *desc; if (!XkbUseExtension(dpy,NULL,NULL)) return 0; xkbi = dpy->xkb_info; query = XkbAllClientInfoMask; desc = XkbGetMap(dpy,query,XkbUseCoreKbd); if (!desc) { #ifdef DEBUG fprintf(stderr,"Warning! XkbGetMap failed!\n"); #endif return 0; } LockDisplay(dpy); xkbi->desc = desc; UnlockDisplay(dpy); oldEvents= xkbi->selected_events; if (!(xkbi->xlib_ctrls&XkbLC_IgnoreNewKeyboards)) { XkbSelectEventDetails(dpy,xkbi->desc->device_spec,XkbNewKeyboardNotify, XkbNKN_KeycodesMask|XkbNKN_DeviceIDMask, XkbNKN_KeycodesMask|XkbNKN_DeviceIDMask); } XkbSelectEventDetails(dpy,xkbi->desc->device_spec,XkbMapNotify, XkbAllClientInfoMask,XkbAllClientInfoMask); LockDisplay(dpy); xkbi->selected_events= oldEvents; UnlockDisplay(dpy); return 1; }
Status XkbGetIndicatorState(Display *dpy,unsigned deviceSpec,unsigned *pStateRtrn) { register xkbGetIndicatorStateReq *req; xkbGetIndicatorStateReply rep; XkbInfoPtr xkbi; Bool ok; if ((dpy->flags & XlibDisplayNoXkb) || (!dpy->xkb_info && !XkbUseExtension(dpy,NULL,NULL))) return BadAccess; LockDisplay(dpy); xkbi = dpy->xkb_info; GetReq(kbGetIndicatorState, req); req->reqType = xkbi->codes->major_opcode; req->xkbReqType = X_kbGetIndicatorState; req->deviceSpec = deviceSpec; ok=_XReply(dpy, (xReply *)&rep, 0, xFalse); if (ok && (pStateRtrn!=NULL)) *pStateRtrn= rep.state; UnlockDisplay(dpy); SyncHandle(); return (ok?Success:BadImplementation); }
Boolean InitXkb(Display *theDisplay) { int i,opcode,errorBase,major,minor; XkbDescPtr xkb; unsigned int bit; unsigned int real,virtual,named,explicit,automatic; char *name; if (!XkbQueryExtension(theDisplay, &opcode, &xkbEventBase, &errorBase, &major, &minor)) return False; if (!XkbUseExtension(theDisplay,&major,&minor)) return False; XkbSelectEvents(theDisplay, XkbUseCoreKbd, XkbIndicatorStateNotifyMask|XkbIndicatorMapNotifyMask, XkbIndicatorStateNotifyMask|XkbIndicatorMapNotifyMask); XtSetEventDispatcher(theDisplay, xkbEventBase+XkbEventCode, XkbEventHandler); xkb=XkbGetMap(theDisplay,0,XkbUseCoreKbd); real=virtual=named=explicit=automatic=0; if (!xkb) { fprintf(stderr,"Couldn't get keymap\n"); return False; } if (XkbGetIndicatorMap(theDisplay,XkbAllIndicatorsMask,xkb)!=Success) { fprintf(stderr,"Couldn't read indicator map\n"); XkbFreeKeyboard(xkb,XkbAllComponentsMask,True); return False; } real=virtual=named=explicit=automatic=0; if (XkbGetNames(theDisplay,XkbIndicatorNamesMask,xkb)!=Success) { fprintf(stderr,"Couldn't read indicator names\n"); XkbFreeKeyboard(xkb,XkbAllComponentsMask,True); return False; } real=virtual=named=explicit=automatic=0; for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) { XkbIndicatorMapPtr map= &xkb->indicators->maps[i]; name = NULL; if (xkb->names->indicators[i]!=None) { named|= bit; name = XGetAtomName(theDisplay,xkb->names->indicators[i]); } if (name != NULL) { ledAtoms[i] = xkb->names->indicators[i]; ledNames[i] = XmStringCreate(name,XmSTRING_DEFAULT_CHARSET); } else { char temp[12]; sprintf(temp,"led%d\0",i+1); ledAtoms[i] = None; ledNames[i] = XmStringCreate(temp,XmSTRING_DEFAULT_CHARSET); } if (xkb->indicators->phys_indicators&bit) real|= bit; if ((((map->which_groups!=0)&&(map->groups!=0))|| ((map->which_mods!=0)&& ((map->mods.real_mods!=0)||(map->mods.vmods!=0)))|| (map->ctrls!=0))&& ((map->flags&XkbIM_NoAutomatic)==0)) { automatic|= bit; } else explicit|= bit; } virtual = ~real; if (options.useUnion) { if ((options.wantReal==NO) || (options.wantReal==DONT_CARE)) real = 0; if ((options.wantVirtual==NO) || (options.wantVirtual==DONT_CARE)) virtual = 0; if ((options.wantNamed==NO) || (options.wantNamed==DONT_CARE)) named = 0; if ((options.wantAutomatic==NO) || (options.wantAutomatic==DONT_CARE)) automatic = 0; if ((options.wantExplicit==NO) || (options.wantExplicit==DONT_CARE)) explicit = 0; options.wanted |= real|virtual|named|automatic|explicit; } else { if (options.wanted == DONT_CARE)
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; }
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; }
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; }