xkb.c 219 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862
  1. /************************************************************
  2. Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
  3. Permission to use, copy, modify, and distribute this
  4. software and its documentation for any purpose and without
  5. fee is hereby granted, provided that the above copyright
  6. notice appear in all copies and that both that copyright
  7. notice and this permission notice appear in supporting
  8. documentation, and that the name of Silicon Graphics not be
  9. used in advertising or publicity pertaining to distribution
  10. of the software without specific prior written permission.
  11. Silicon Graphics makes no representation about the suitability
  12. of this software for any purpose. It is provided "as is"
  13. without any express or implied warranty.
  14. SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  15. SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  16. AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  17. GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  18. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  19. DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  20. OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
  21. THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22. ********************************************************/
  23. #ifdef HAVE_DIX_CONFIG_H
  24. #include <dix-config.h>
  25. #endif
  26. #include <stdio.h>
  27. #include <X11/X.h>
  28. #include <X11/Xproto.h>
  29. #include "misc.h"
  30. #include "inputstr.h"
  31. #define XKBSRV_NEED_FILE_FUNCS
  32. #include <xkbsrv.h>
  33. #include "extnsionst.h"
  34. #include "extinit.h"
  35. #include "xace.h"
  36. #include "xkb.h"
  37. #include "protocol-versions.h"
  38. #include <X11/extensions/XI.h>
  39. #include <X11/extensions/XKMformat.h>
  40. int XkbEventBase;
  41. static int XkbErrorBase;
  42. int XkbReqCode;
  43. int XkbKeyboardErrorCode;
  44. CARD32 xkbDebugFlags = 0;
  45. static CARD32 xkbDebugCtrls = 0;
  46. static RESTYPE RT_XKBCLIENT;
  47. /***====================================================================***/
  48. #define CHK_DEVICE(dev, id, client, access_mode, lf) {\
  49. int why;\
  50. int tmprc = lf(&(dev), id, client, access_mode, &why);\
  51. if (tmprc != Success) {\
  52. client->errorValue = _XkbErrCode2(why, id);\
  53. return tmprc;\
  54. }\
  55. }
  56. #define CHK_KBD_DEVICE(dev, id, client, mode) \
  57. CHK_DEVICE(dev, id, client, mode, _XkbLookupKeyboard)
  58. #define CHK_LED_DEVICE(dev, id, client, mode) \
  59. CHK_DEVICE(dev, id, client, mode, _XkbLookupLedDevice)
  60. #define CHK_BELL_DEVICE(dev, id, client, mode) \
  61. CHK_DEVICE(dev, id, client, mode, _XkbLookupBellDevice)
  62. #define CHK_ANY_DEVICE(dev, id, client, mode) \
  63. CHK_DEVICE(dev, id, client, mode, _XkbLookupAnyDevice)
  64. #define CHK_ATOM_ONLY2(a,ev,er) {\
  65. if (((a)==None)||(!ValidAtom((a)))) {\
  66. (ev)= (XID)(a);\
  67. return er;\
  68. }\
  69. }
  70. #define CHK_ATOM_ONLY(a) \
  71. CHK_ATOM_ONLY2(a,client->errorValue,BadAtom)
  72. #define CHK_ATOM_OR_NONE3(a,ev,er,ret) {\
  73. if (((a)!=None)&&(!ValidAtom((a)))) {\
  74. (ev)= (XID)(a);\
  75. (er)= BadAtom;\
  76. return ret;\
  77. }\
  78. }
  79. #define CHK_ATOM_OR_NONE2(a,ev,er) {\
  80. if (((a)!=None)&&(!ValidAtom((a)))) {\
  81. (ev)= (XID)(a);\
  82. return er;\
  83. }\
  84. }
  85. #define CHK_ATOM_OR_NONE(a) \
  86. CHK_ATOM_OR_NONE2(a,client->errorValue,BadAtom)
  87. #define CHK_MASK_LEGAL3(err,mask,legal,ev,er,ret) {\
  88. if ((mask)&(~(legal))) { \
  89. (ev)= _XkbErrCode2((err),((mask)&(~(legal))));\
  90. (er)= BadValue;\
  91. return ret;\
  92. }\
  93. }
  94. #define CHK_MASK_LEGAL2(err,mask,legal,ev,er) {\
  95. if ((mask)&(~(legal))) { \
  96. (ev)= _XkbErrCode2((err),((mask)&(~(legal))));\
  97. return er;\
  98. }\
  99. }
  100. #define CHK_MASK_LEGAL(err,mask,legal) \
  101. CHK_MASK_LEGAL2(err,mask,legal,client->errorValue,BadValue)
  102. #define CHK_MASK_MATCH(err,affect,value) {\
  103. if ((value)&(~(affect))) { \
  104. client->errorValue= _XkbErrCode2((err),((value)&(~(affect))));\
  105. return BadMatch;\
  106. }\
  107. }
  108. #define CHK_MASK_OVERLAP(err,m1,m2) {\
  109. if ((m1)&(m2)) { \
  110. client->errorValue= _XkbErrCode2((err),((m1)&(m2)));\
  111. return BadMatch;\
  112. }\
  113. }
  114. #define CHK_KEY_RANGE2(err,first,num,x,ev,er) {\
  115. if (((unsigned)(first)+(num)-1)>(x)->max_key_code) {\
  116. (ev)=_XkbErrCode4(err,(first),(num),(x)->max_key_code);\
  117. return er;\
  118. }\
  119. else if ( (first)<(x)->min_key_code ) {\
  120. (ev)=_XkbErrCode3(err+1,(first),xkb->min_key_code);\
  121. return er;\
  122. }\
  123. }
  124. #define CHK_KEY_RANGE(err,first,num,x) \
  125. CHK_KEY_RANGE2(err,first,num,x,client->errorValue,BadValue)
  126. #define CHK_REQ_KEY_RANGE2(err,first,num,r,ev,er) {\
  127. if (((unsigned)(first)+(num)-1)>(r)->maxKeyCode) {\
  128. (ev)=_XkbErrCode4(err,(first),(num),(r)->maxKeyCode);\
  129. return er;\
  130. }\
  131. else if ( (first)<(r)->minKeyCode ) {\
  132. (ev)=_XkbErrCode3(err+1,(first),(r)->minKeyCode);\
  133. return er;\
  134. }\
  135. }
  136. #define CHK_REQ_KEY_RANGE(err,first,num,r) \
  137. CHK_REQ_KEY_RANGE2(err,first,num,r,client->errorValue,BadValue)
  138. /***====================================================================***/
  139. int
  140. ProcXkbUseExtension(ClientPtr client)
  141. {
  142. REQUEST(xkbUseExtensionReq);
  143. xkbUseExtensionReply rep;
  144. int supported;
  145. REQUEST_SIZE_MATCH(xkbUseExtensionReq);
  146. if (stuff->wantedMajor != SERVER_XKB_MAJOR_VERSION) {
  147. /* pre-release version 0.65 is compatible with 1.00 */
  148. supported = ((SERVER_XKB_MAJOR_VERSION == 1) &&
  149. (stuff->wantedMajor == 0) && (stuff->wantedMinor == 65));
  150. }
  151. else
  152. supported = 1;
  153. if ((supported) && (!(client->xkbClientFlags & _XkbClientInitialized))) {
  154. client->xkbClientFlags = _XkbClientInitialized;
  155. client->vMajor = stuff->wantedMajor;
  156. client->vMinor = stuff->wantedMinor;
  157. }
  158. else if (xkbDebugFlags & 0x1) {
  159. ErrorF
  160. ("[xkb] Rejecting client %d (0x%lx) (wants %d.%02d, have %d.%02d)\n",
  161. client->index, (long) client->clientAsMask, stuff->wantedMajor,
  162. stuff->wantedMinor, SERVER_XKB_MAJOR_VERSION,
  163. SERVER_XKB_MINOR_VERSION);
  164. }
  165. rep = (xkbUseExtensionReply) {
  166. .type = X_Reply,
  167. .supported = supported,
  168. .sequenceNumber = client->sequence,
  169. .length = 0,
  170. .serverMajor = SERVER_XKB_MAJOR_VERSION,
  171. .serverMinor = SERVER_XKB_MINOR_VERSION
  172. };
  173. if (client->swapped) {
  174. swaps(&rep.sequenceNumber);
  175. swaps(&rep.serverMajor);
  176. swaps(&rep.serverMinor);
  177. }
  178. WriteToClient(client, SIZEOF(xkbUseExtensionReply), &rep);
  179. return Success;
  180. }
  181. /***====================================================================***/
  182. int
  183. ProcXkbSelectEvents(ClientPtr client)
  184. {
  185. unsigned legal;
  186. DeviceIntPtr dev;
  187. XkbInterestPtr masks;
  188. REQUEST(xkbSelectEventsReq);
  189. REQUEST_AT_LEAST_SIZE(xkbSelectEventsReq);
  190. if (!(client->xkbClientFlags & _XkbClientInitialized))
  191. return BadAccess;
  192. CHK_ANY_DEVICE(dev, stuff->deviceSpec, client, DixUseAccess);
  193. if (((stuff->affectWhich & XkbMapNotifyMask) != 0) && (stuff->affectMap)) {
  194. client->mapNotifyMask &= ~stuff->affectMap;
  195. client->mapNotifyMask |= (stuff->affectMap & stuff->map);
  196. }
  197. if ((stuff->affectWhich & (~XkbMapNotifyMask)) == 0)
  198. return Success;
  199. masks = XkbFindClientResource((DevicePtr) dev, client);
  200. if (!masks) {
  201. XID id = FakeClientID(client->index);
  202. if (!AddResource(id, RT_XKBCLIENT, dev))
  203. return BadAlloc;
  204. masks = XkbAddClientResource((DevicePtr) dev, client, id);
  205. }
  206. if (masks) {
  207. union {
  208. CARD8 *c8;
  209. CARD16 *c16;
  210. CARD32 *c32;
  211. } from, to;
  212. register unsigned bit, ndx, maskLeft, dataLeft, size;
  213. from.c8 = (CARD8 *) &stuff[1];
  214. dataLeft = (stuff->length * 4) - SIZEOF(xkbSelectEventsReq);
  215. maskLeft = (stuff->affectWhich & (~XkbMapNotifyMask));
  216. for (ndx = 0, bit = 1; (maskLeft != 0); ndx++, bit <<= 1) {
  217. if ((bit & maskLeft) == 0)
  218. continue;
  219. maskLeft &= ~bit;
  220. switch (ndx) {
  221. case XkbNewKeyboardNotify:
  222. to.c16 = &client->newKeyboardNotifyMask;
  223. legal = XkbAllNewKeyboardEventsMask;
  224. size = 2;
  225. break;
  226. case XkbStateNotify:
  227. to.c16 = &masks->stateNotifyMask;
  228. legal = XkbAllStateEventsMask;
  229. size = 2;
  230. break;
  231. case XkbControlsNotify:
  232. to.c32 = &masks->ctrlsNotifyMask;
  233. legal = XkbAllControlEventsMask;
  234. size = 4;
  235. break;
  236. case XkbIndicatorStateNotify:
  237. to.c32 = &masks->iStateNotifyMask;
  238. legal = XkbAllIndicatorEventsMask;
  239. size = 4;
  240. break;
  241. case XkbIndicatorMapNotify:
  242. to.c32 = &masks->iMapNotifyMask;
  243. legal = XkbAllIndicatorEventsMask;
  244. size = 4;
  245. break;
  246. case XkbNamesNotify:
  247. to.c16 = &masks->namesNotifyMask;
  248. legal = XkbAllNameEventsMask;
  249. size = 2;
  250. break;
  251. case XkbCompatMapNotify:
  252. to.c8 = &masks->compatNotifyMask;
  253. legal = XkbAllCompatMapEventsMask;
  254. size = 1;
  255. break;
  256. case XkbBellNotify:
  257. to.c8 = &masks->bellNotifyMask;
  258. legal = XkbAllBellEventsMask;
  259. size = 1;
  260. break;
  261. case XkbActionMessage:
  262. to.c8 = &masks->actionMessageMask;
  263. legal = XkbAllActionMessagesMask;
  264. size = 1;
  265. break;
  266. case XkbAccessXNotify:
  267. to.c16 = &masks->accessXNotifyMask;
  268. legal = XkbAllAccessXEventsMask;
  269. size = 2;
  270. break;
  271. case XkbExtensionDeviceNotify:
  272. to.c16 = &masks->extDevNotifyMask;
  273. legal = XkbAllExtensionDeviceEventsMask;
  274. size = 2;
  275. break;
  276. default:
  277. client->errorValue = _XkbErrCode2(33, bit);
  278. return BadValue;
  279. }
  280. if (stuff->clear & bit) {
  281. if (size == 2)
  282. to.c16[0] = 0;
  283. else if (size == 4)
  284. to.c32[0] = 0;
  285. else
  286. to.c8[0] = 0;
  287. }
  288. else if (stuff->selectAll & bit) {
  289. if (size == 2)
  290. to.c16[0] = ~0;
  291. else if (size == 4)
  292. to.c32[0] = ~0;
  293. else
  294. to.c8[0] = ~0;
  295. }
  296. else {
  297. if (dataLeft < (size * 2))
  298. return BadLength;
  299. if (size == 2) {
  300. CHK_MASK_MATCH(ndx, from.c16[0], from.c16[1]);
  301. CHK_MASK_LEGAL(ndx, from.c16[0], legal);
  302. to.c16[0] &= ~from.c16[0];
  303. to.c16[0] |= (from.c16[0] & from.c16[1]);
  304. }
  305. else if (size == 4) {
  306. CHK_MASK_MATCH(ndx, from.c32[0], from.c32[1]);
  307. CHK_MASK_LEGAL(ndx, from.c32[0], legal);
  308. to.c32[0] &= ~from.c32[0];
  309. to.c32[0] |= (from.c32[0] & from.c32[1]);
  310. }
  311. else {
  312. CHK_MASK_MATCH(ndx, from.c8[0], from.c8[1]);
  313. CHK_MASK_LEGAL(ndx, from.c8[0], legal);
  314. to.c8[0] &= ~from.c8[0];
  315. to.c8[0] |= (from.c8[0] & from.c8[1]);
  316. size = 2;
  317. }
  318. from.c8 += (size * 2);
  319. dataLeft -= (size * 2);
  320. }
  321. }
  322. if (dataLeft > 2) {
  323. ErrorF("[xkb] Extra data (%d bytes) after SelectEvents\n",
  324. dataLeft);
  325. return BadLength;
  326. }
  327. return Success;
  328. }
  329. return BadAlloc;
  330. }
  331. /***====================================================================***/
  332. /**
  333. * Ring a bell on the given device for the given client.
  334. */
  335. static int
  336. _XkbBell(ClientPtr client, DeviceIntPtr dev, WindowPtr pWin,
  337. int bellClass, int bellID, int pitch, int duration,
  338. int percent, int forceSound, int eventOnly, Atom name)
  339. {
  340. int base;
  341. void *ctrl;
  342. int oldPitch, oldDuration;
  343. int newPercent;
  344. if (bellClass == KbdFeedbackClass) {
  345. KbdFeedbackPtr k;
  346. if (bellID == XkbDfltXIId)
  347. k = dev->kbdfeed;
  348. else {
  349. for (k = dev->kbdfeed; k; k = k->next) {
  350. if (k->ctrl.id == bellID)
  351. break;
  352. }
  353. }
  354. if (!k) {
  355. client->errorValue = _XkbErrCode2(0x5, bellID);
  356. return BadValue;
  357. }
  358. base = k->ctrl.bell;
  359. ctrl = (void *) &(k->ctrl);
  360. oldPitch = k->ctrl.bell_pitch;
  361. oldDuration = k->ctrl.bell_duration;
  362. if (pitch != 0) {
  363. if (pitch == -1)
  364. k->ctrl.bell_pitch = defaultKeyboardControl.bell_pitch;
  365. else
  366. k->ctrl.bell_pitch = pitch;
  367. }
  368. if (duration != 0) {
  369. if (duration == -1)
  370. k->ctrl.bell_duration = defaultKeyboardControl.bell_duration;
  371. else
  372. k->ctrl.bell_duration = duration;
  373. }
  374. }
  375. else if (bellClass == BellFeedbackClass) {
  376. BellFeedbackPtr b;
  377. if (bellID == XkbDfltXIId)
  378. b = dev->bell;
  379. else {
  380. for (b = dev->bell; b; b = b->next) {
  381. if (b->ctrl.id == bellID)
  382. break;
  383. }
  384. }
  385. if (!b) {
  386. client->errorValue = _XkbErrCode2(0x6, bellID);
  387. return BadValue;
  388. }
  389. base = b->ctrl.percent;
  390. ctrl = (void *) &(b->ctrl);
  391. oldPitch = b->ctrl.pitch;
  392. oldDuration = b->ctrl.duration;
  393. if (pitch != 0) {
  394. if (pitch == -1)
  395. b->ctrl.pitch = defaultKeyboardControl.bell_pitch;
  396. else
  397. b->ctrl.pitch = pitch;
  398. }
  399. if (duration != 0) {
  400. if (duration == -1)
  401. b->ctrl.duration = defaultKeyboardControl.bell_duration;
  402. else
  403. b->ctrl.duration = duration;
  404. }
  405. }
  406. else {
  407. client->errorValue = _XkbErrCode2(0x7, bellClass);
  408. return BadValue;
  409. }
  410. newPercent = (base * percent) / 100;
  411. if (percent < 0)
  412. newPercent = base + newPercent;
  413. else
  414. newPercent = base - newPercent + percent;
  415. XkbHandleBell(forceSound, eventOnly,
  416. dev, newPercent, ctrl, bellClass, name, pWin, client);
  417. if ((pitch != 0) || (duration != 0)) {
  418. if (bellClass == KbdFeedbackClass) {
  419. KbdFeedbackPtr k;
  420. k = (KbdFeedbackPtr) ctrl;
  421. if (pitch != 0)
  422. k->ctrl.bell_pitch = oldPitch;
  423. if (duration != 0)
  424. k->ctrl.bell_duration = oldDuration;
  425. }
  426. else {
  427. BellFeedbackPtr b;
  428. b = (BellFeedbackPtr) ctrl;
  429. if (pitch != 0)
  430. b->ctrl.pitch = oldPitch;
  431. if (duration != 0)
  432. b->ctrl.duration = oldDuration;
  433. }
  434. }
  435. return Success;
  436. }
  437. int
  438. ProcXkbBell(ClientPtr client)
  439. {
  440. REQUEST(xkbBellReq);
  441. DeviceIntPtr dev;
  442. WindowPtr pWin;
  443. int rc;
  444. REQUEST_SIZE_MATCH(xkbBellReq);
  445. if (!(client->xkbClientFlags & _XkbClientInitialized))
  446. return BadAccess;
  447. CHK_BELL_DEVICE(dev, stuff->deviceSpec, client, DixBellAccess);
  448. CHK_ATOM_OR_NONE(stuff->name);
  449. /* device-independent checks request for sane values */
  450. if ((stuff->forceSound) && (stuff->eventOnly)) {
  451. client->errorValue =
  452. _XkbErrCode3(0x1, stuff->forceSound, stuff->eventOnly);
  453. return BadMatch;
  454. }
  455. if (stuff->percent < -100 || stuff->percent > 100) {
  456. client->errorValue = _XkbErrCode2(0x2, stuff->percent);
  457. return BadValue;
  458. }
  459. if (stuff->duration < -1) {
  460. client->errorValue = _XkbErrCode2(0x3, stuff->duration);
  461. return BadValue;
  462. }
  463. if (stuff->pitch < -1) {
  464. client->errorValue = _XkbErrCode2(0x4, stuff->pitch);
  465. return BadValue;
  466. }
  467. if (stuff->bellClass == XkbDfltXIClass) {
  468. if (dev->kbdfeed != NULL)
  469. stuff->bellClass = KbdFeedbackClass;
  470. else
  471. stuff->bellClass = BellFeedbackClass;
  472. }
  473. if (stuff->window != None) {
  474. rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
  475. if (rc != Success) {
  476. client->errorValue = stuff->window;
  477. return rc;
  478. }
  479. }
  480. else
  481. pWin = NULL;
  482. /* Client wants to ring a bell on the core keyboard?
  483. Ring the bell on the core keyboard (which does nothing, but if that
  484. fails the client is screwed anyway), and then on all extension devices.
  485. Fail if the core keyboard fails but not the extension devices. this
  486. may cause some keyboards to ding and others to stay silent. Fix
  487. your client to use explicit keyboards to avoid this.
  488. dev is the device the client requested.
  489. */
  490. rc = _XkbBell(client, dev, pWin, stuff->bellClass, stuff->bellID,
  491. stuff->pitch, stuff->duration, stuff->percent,
  492. stuff->forceSound, stuff->eventOnly, stuff->name);
  493. if ((rc == Success) && ((stuff->deviceSpec == XkbUseCoreKbd) ||
  494. (stuff->deviceSpec == XkbUseCorePtr))) {
  495. DeviceIntPtr other;
  496. for (other = inputInfo.devices; other; other = other->next) {
  497. if ((other != dev) && other->key && !IsMaster(other) &&
  498. GetMaster(other, MASTER_KEYBOARD) == dev) {
  499. rc = XaceHook(XACE_DEVICE_ACCESS, client, other, DixBellAccess);
  500. if (rc == Success)
  501. _XkbBell(client, other, pWin, stuff->bellClass,
  502. stuff->bellID, stuff->pitch, stuff->duration,
  503. stuff->percent, stuff->forceSound,
  504. stuff->eventOnly, stuff->name);
  505. }
  506. }
  507. rc = Success; /* reset to success, that's what we got for the VCK */
  508. }
  509. return rc;
  510. }
  511. /***====================================================================***/
  512. int
  513. ProcXkbGetState(ClientPtr client)
  514. {
  515. REQUEST(xkbGetStateReq);
  516. DeviceIntPtr dev;
  517. xkbGetStateReply rep;
  518. XkbStateRec *xkb;
  519. REQUEST_SIZE_MATCH(xkbGetStateReq);
  520. if (!(client->xkbClientFlags & _XkbClientInitialized))
  521. return BadAccess;
  522. CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixGetAttrAccess);
  523. xkb = &dev->key->xkbInfo->state;
  524. rep = (xkbGetStateReply) {
  525. .type = X_Reply,
  526. .deviceID = dev->id,
  527. .sequenceNumber = client->sequence,
  528. .length = 0,
  529. .mods = XkbStateFieldFromRec(xkb) & 0xff,
  530. .baseMods = xkb->base_mods,
  531. .latchedMods = xkb->latched_mods,
  532. .lockedMods = xkb->locked_mods,
  533. .group = xkb->group,
  534. .lockedGroup = xkb->locked_group,
  535. .baseGroup = xkb->base_group,
  536. .latchedGroup = xkb->latched_group,
  537. .compatState = xkb->compat_state,
  538. .ptrBtnState = xkb->ptr_buttons
  539. };
  540. if (client->swapped) {
  541. swaps(&rep.sequenceNumber);
  542. swaps(&rep.ptrBtnState);
  543. }
  544. WriteToClient(client, SIZEOF(xkbGetStateReply), &rep);
  545. return Success;
  546. }
  547. /***====================================================================***/
  548. int
  549. ProcXkbLatchLockState(ClientPtr client)
  550. {
  551. int status;
  552. DeviceIntPtr dev, tmpd;
  553. XkbStateRec oldState, *newState;
  554. CARD16 changed;
  555. xkbStateNotify sn;
  556. XkbEventCauseRec cause;
  557. REQUEST(xkbLatchLockStateReq);
  558. REQUEST_SIZE_MATCH(xkbLatchLockStateReq);
  559. if (!(client->xkbClientFlags & _XkbClientInitialized))
  560. return BadAccess;
  561. CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixSetAttrAccess);
  562. CHK_MASK_MATCH(0x01, stuff->affectModLocks, stuff->modLocks);
  563. CHK_MASK_MATCH(0x01, stuff->affectModLatches, stuff->modLatches);
  564. status = Success;
  565. for (tmpd = inputInfo.devices; tmpd; tmpd = tmpd->next) {
  566. if ((tmpd == dev) ||
  567. (!IsMaster(tmpd) && GetMaster(tmpd, MASTER_KEYBOARD) == dev)) {
  568. if (!tmpd->key || !tmpd->key->xkbInfo)
  569. continue;
  570. oldState = tmpd->key->xkbInfo->state;
  571. newState = &tmpd->key->xkbInfo->state;
  572. if (stuff->affectModLocks) {
  573. newState->locked_mods &= ~stuff->affectModLocks;
  574. newState->locked_mods |=
  575. (stuff->affectModLocks & stuff->modLocks);
  576. }
  577. if (status == Success && stuff->lockGroup)
  578. newState->locked_group = stuff->groupLock;
  579. if (status == Success && stuff->affectModLatches)
  580. status = XkbLatchModifiers(tmpd, stuff->affectModLatches,
  581. stuff->modLatches);
  582. if (status == Success && stuff->latchGroup)
  583. status = XkbLatchGroup(tmpd, stuff->groupLatch);
  584. if (status != Success)
  585. return status;
  586. XkbComputeDerivedState(tmpd->key->xkbInfo);
  587. changed = XkbStateChangedFlags(&oldState, newState);
  588. if (changed) {
  589. sn.keycode = 0;
  590. sn.eventType = 0;
  591. sn.requestMajor = XkbReqCode;
  592. sn.requestMinor = X_kbLatchLockState;
  593. sn.changed = changed;
  594. XkbSendStateNotify(tmpd, &sn);
  595. changed = XkbIndicatorsToUpdate(tmpd, changed, FALSE);
  596. if (changed) {
  597. XkbSetCauseXkbReq(&cause, X_kbLatchLockState, client);
  598. XkbUpdateIndicators(tmpd, changed, TRUE, NULL, &cause);
  599. }
  600. }
  601. }
  602. }
  603. return Success;
  604. }
  605. /***====================================================================***/
  606. int
  607. ProcXkbGetControls(ClientPtr client)
  608. {
  609. xkbGetControlsReply rep;
  610. XkbControlsPtr xkb;
  611. DeviceIntPtr dev;
  612. REQUEST(xkbGetControlsReq);
  613. REQUEST_SIZE_MATCH(xkbGetControlsReq);
  614. if (!(client->xkbClientFlags & _XkbClientInitialized))
  615. return BadAccess;
  616. CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixGetAttrAccess);
  617. xkb = dev->key->xkbInfo->desc->ctrls;
  618. rep = (xkbGetControlsReply) {
  619. .type = X_Reply,
  620. .deviceID = ((DeviceIntPtr) dev)->id,
  621. .sequenceNumber = client->sequence,
  622. .length = bytes_to_int32(SIZEOF(xkbGetControlsReply) -
  623. SIZEOF(xGenericReply)),
  624. .mkDfltBtn = xkb->mk_dflt_btn,
  625. .numGroups = xkb->num_groups,
  626. .groupsWrap = xkb->groups_wrap,
  627. .internalMods = xkb->internal.mask,
  628. .ignoreLockMods = xkb->ignore_lock.mask,
  629. .internalRealMods = xkb->internal.real_mods,
  630. .ignoreLockRealMods = xkb->ignore_lock.real_mods,
  631. .internalVMods = xkb->internal.vmods,
  632. .ignoreLockVMods = xkb->ignore_lock.vmods,
  633. .repeatDelay = xkb->repeat_delay,
  634. .repeatInterval = xkb->repeat_interval,
  635. .slowKeysDelay = xkb->slow_keys_delay,
  636. .debounceDelay = xkb->debounce_delay,
  637. .mkDelay = xkb->mk_delay,
  638. .mkInterval = xkb->mk_interval,
  639. .mkTimeToMax = xkb->mk_time_to_max,
  640. .mkMaxSpeed = xkb->mk_max_speed,
  641. .mkCurve = xkb->mk_curve,
  642. .axOptions = xkb->ax_options,
  643. .axTimeout = xkb->ax_timeout,
  644. .axtOptsMask = xkb->axt_opts_mask,
  645. .axtOptsValues = xkb->axt_opts_values,
  646. .axtCtrlsMask = xkb->axt_ctrls_mask,
  647. .axtCtrlsValues = xkb->axt_ctrls_values,
  648. .enabledCtrls = xkb->enabled_ctrls,
  649. };
  650. memcpy(rep.perKeyRepeat, xkb->per_key_repeat, XkbPerKeyBitArraySize);
  651. if (client->swapped) {
  652. swaps(&rep.sequenceNumber);
  653. swapl(&rep.length);
  654. swaps(&rep.internalVMods);
  655. swaps(&rep.ignoreLockVMods);
  656. swapl(&rep.enabledCtrls);
  657. swaps(&rep.repeatDelay);
  658. swaps(&rep.repeatInterval);
  659. swaps(&rep.slowKeysDelay);
  660. swaps(&rep.debounceDelay);
  661. swaps(&rep.mkDelay);
  662. swaps(&rep.mkInterval);
  663. swaps(&rep.mkTimeToMax);
  664. swaps(&rep.mkMaxSpeed);
  665. swaps(&rep.mkCurve);
  666. swaps(&rep.axTimeout);
  667. swapl(&rep.axtCtrlsMask);
  668. swapl(&rep.axtCtrlsValues);
  669. swaps(&rep.axtOptsMask);
  670. swaps(&rep.axtOptsValues);
  671. swaps(&rep.axOptions);
  672. }
  673. WriteToClient(client, SIZEOF(xkbGetControlsReply), &rep);
  674. return Success;
  675. }
  676. int
  677. ProcXkbSetControls(ClientPtr client)
  678. {
  679. DeviceIntPtr dev, tmpd;
  680. XkbSrvInfoPtr xkbi;
  681. XkbControlsPtr ctrl;
  682. XkbControlsRec new, old;
  683. xkbControlsNotify cn;
  684. XkbEventCauseRec cause;
  685. XkbSrvLedInfoPtr sli;
  686. REQUEST(xkbSetControlsReq);
  687. REQUEST_SIZE_MATCH(xkbSetControlsReq);
  688. if (!(client->xkbClientFlags & _XkbClientInitialized))
  689. return BadAccess;
  690. CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixManageAccess);
  691. CHK_MASK_LEGAL(0x01, stuff->changeCtrls, XkbAllControlsMask);
  692. for (tmpd = inputInfo.devices; tmpd; tmpd = tmpd->next) {
  693. if (!tmpd->key || !tmpd->key->xkbInfo)
  694. continue;
  695. if ((tmpd == dev) ||
  696. (!IsMaster(tmpd) && GetMaster(tmpd, MASTER_KEYBOARD) == dev)) {
  697. xkbi = tmpd->key->xkbInfo;
  698. ctrl = xkbi->desc->ctrls;
  699. new = *ctrl;
  700. XkbSetCauseXkbReq(&cause, X_kbSetControls, client);
  701. if (stuff->changeCtrls & XkbInternalModsMask) {
  702. CHK_MASK_MATCH(0x02, stuff->affectInternalMods,
  703. stuff->internalMods);
  704. CHK_MASK_MATCH(0x03, stuff->affectInternalVMods,
  705. stuff->internalVMods);
  706. new.internal.real_mods &= ~(stuff->affectInternalMods);
  707. new.internal.real_mods |= (stuff->affectInternalMods &
  708. stuff->internalMods);
  709. new.internal.vmods &= ~(stuff->affectInternalVMods);
  710. new.internal.vmods |= (stuff->affectInternalVMods &
  711. stuff->internalVMods);
  712. new.internal.mask = new.internal.real_mods |
  713. XkbMaskForVMask(xkbi->desc, new.internal.vmods);
  714. }
  715. if (stuff->changeCtrls & XkbIgnoreLockModsMask) {
  716. CHK_MASK_MATCH(0x4, stuff->affectIgnoreLockMods,
  717. stuff->ignoreLockMods);
  718. CHK_MASK_MATCH(0x5, stuff->affectIgnoreLockVMods,
  719. stuff->ignoreLockVMods);
  720. new.ignore_lock.real_mods &= ~(stuff->affectIgnoreLockMods);
  721. new.ignore_lock.real_mods |= (stuff->affectIgnoreLockMods &
  722. stuff->ignoreLockMods);
  723. new.ignore_lock.vmods &= ~(stuff->affectIgnoreLockVMods);
  724. new.ignore_lock.vmods |= (stuff->affectIgnoreLockVMods &
  725. stuff->ignoreLockVMods);
  726. new.ignore_lock.mask = new.ignore_lock.real_mods |
  727. XkbMaskForVMask(xkbi->desc, new.ignore_lock.vmods);
  728. }
  729. CHK_MASK_MATCH(0x06, stuff->affectEnabledCtrls,
  730. stuff->enabledCtrls);
  731. if (stuff->affectEnabledCtrls) {
  732. CHK_MASK_LEGAL(0x07, stuff->affectEnabledCtrls,
  733. XkbAllBooleanCtrlsMask);
  734. new.enabled_ctrls &= ~(stuff->affectEnabledCtrls);
  735. new.enabled_ctrls |= (stuff->affectEnabledCtrls &
  736. stuff->enabledCtrls);
  737. }
  738. if (stuff->changeCtrls & XkbRepeatKeysMask) {
  739. if (stuff->repeatDelay < 1 || stuff->repeatInterval < 1) {
  740. client->errorValue = _XkbErrCode3(0x08, stuff->repeatDelay,
  741. stuff->repeatInterval);
  742. return BadValue;
  743. }
  744. new.repeat_delay = stuff->repeatDelay;
  745. new.repeat_interval = stuff->repeatInterval;
  746. }
  747. if (stuff->changeCtrls & XkbSlowKeysMask) {
  748. if (stuff->slowKeysDelay < 1) {
  749. client->errorValue = _XkbErrCode2(0x09,
  750. stuff->slowKeysDelay);
  751. return BadValue;
  752. }
  753. new.slow_keys_delay = stuff->slowKeysDelay;
  754. }
  755. if (stuff->changeCtrls & XkbBounceKeysMask) {
  756. if (stuff->debounceDelay < 1) {
  757. client->errorValue = _XkbErrCode2(0x0A,
  758. stuff->debounceDelay);
  759. return BadValue;
  760. }
  761. new.debounce_delay = stuff->debounceDelay;
  762. }
  763. if (stuff->changeCtrls & XkbMouseKeysMask) {
  764. if (stuff->mkDfltBtn > XkbMaxMouseKeysBtn) {
  765. client->errorValue = _XkbErrCode2(0x0B, stuff->mkDfltBtn);
  766. return BadValue;
  767. }
  768. new.mk_dflt_btn = stuff->mkDfltBtn;
  769. }
  770. if (stuff->changeCtrls & XkbMouseKeysAccelMask) {
  771. if (stuff->mkDelay < 1 || stuff->mkInterval < 1 ||
  772. stuff->mkTimeToMax < 1 || stuff->mkMaxSpeed < 1 ||
  773. stuff->mkCurve < -1000) {
  774. client->errorValue = _XkbErrCode2(0x0C, 0);
  775. return BadValue;
  776. }
  777. new.mk_delay = stuff->mkDelay;
  778. new.mk_interval = stuff->mkInterval;
  779. new.mk_time_to_max = stuff->mkTimeToMax;
  780. new.mk_max_speed = stuff->mkMaxSpeed;
  781. new.mk_curve = stuff->mkCurve;
  782. AccessXComputeCurveFactor(xkbi, &new);
  783. }
  784. if (stuff->changeCtrls & XkbGroupsWrapMask) {
  785. unsigned act, num;
  786. act = XkbOutOfRangeGroupAction(stuff->groupsWrap);
  787. switch (act) {
  788. case XkbRedirectIntoRange:
  789. num = XkbOutOfRangeGroupNumber(stuff->groupsWrap);
  790. if (num >= new.num_groups) {
  791. client->errorValue = _XkbErrCode3(0x0D, new.num_groups,
  792. num);
  793. return BadValue;
  794. }
  795. case XkbWrapIntoRange:
  796. case XkbClampIntoRange:
  797. break;
  798. default:
  799. client->errorValue = _XkbErrCode2(0x0E, act);
  800. return BadValue;
  801. }
  802. new.groups_wrap = stuff->groupsWrap;
  803. }
  804. CHK_MASK_LEGAL(0x0F, stuff->axOptions, XkbAX_AllOptionsMask);
  805. if (stuff->changeCtrls & XkbAccessXKeysMask) {
  806. new.ax_options = stuff->axOptions & XkbAX_AllOptionsMask;
  807. }
  808. else {
  809. if (stuff->changeCtrls & XkbStickyKeysMask) {
  810. new.ax_options &= ~(XkbAX_SKOptionsMask);
  811. new.ax_options |= (stuff->axOptions & XkbAX_SKOptionsMask);
  812. }
  813. if (stuff->changeCtrls & XkbAccessXFeedbackMask) {
  814. new.ax_options &= ~(XkbAX_FBOptionsMask);
  815. new.ax_options |= (stuff->axOptions & XkbAX_FBOptionsMask);
  816. }
  817. }
  818. if (stuff->changeCtrls & XkbAccessXTimeoutMask) {
  819. if (stuff->axTimeout < 1) {
  820. client->errorValue = _XkbErrCode2(0x10, stuff->axTimeout);
  821. return BadValue;
  822. }
  823. CHK_MASK_MATCH(0x11, stuff->axtCtrlsMask,
  824. stuff->axtCtrlsValues);
  825. CHK_MASK_LEGAL(0x12, stuff->axtCtrlsMask,
  826. XkbAllBooleanCtrlsMask);
  827. CHK_MASK_MATCH(0x13, stuff->axtOptsMask, stuff->axtOptsValues);
  828. CHK_MASK_LEGAL(0x14, stuff->axtOptsMask, XkbAX_AllOptionsMask);
  829. new.ax_timeout = stuff->axTimeout;
  830. new.axt_ctrls_mask = stuff->axtCtrlsMask;
  831. new.axt_ctrls_values = (stuff->axtCtrlsValues &
  832. stuff->axtCtrlsMask);
  833. new.axt_opts_mask = stuff->axtOptsMask;
  834. new.axt_opts_values = (stuff->axtOptsValues &
  835. stuff->axtOptsMask);
  836. }
  837. if (stuff->changeCtrls & XkbPerKeyRepeatMask) {
  838. memcpy(new.per_key_repeat, stuff->perKeyRepeat,
  839. XkbPerKeyBitArraySize);
  840. if (xkbi->repeatKey &&
  841. !BitIsOn(new.per_key_repeat, xkbi->repeatKey)) {
  842. AccessXCancelRepeatKey(xkbi, xkbi->repeatKey);
  843. }
  844. }
  845. old = *ctrl;
  846. *ctrl = new;
  847. XkbDDXChangeControls(tmpd, &old, ctrl);
  848. if (XkbComputeControlsNotify(tmpd, &old, ctrl, &cn, FALSE)) {
  849. cn.keycode = 0;
  850. cn.eventType = 0;
  851. cn.requestMajor = XkbReqCode;
  852. cn.requestMinor = X_kbSetControls;
  853. XkbSendControlsNotify(tmpd, &cn);
  854. }
  855. sli = XkbFindSrvLedInfo(tmpd, XkbDfltXIClass, XkbDfltXIId, 0);
  856. if (sli)
  857. XkbUpdateIndicators(tmpd, sli->usesControls, TRUE, NULL,
  858. &cause);
  859. /* If sticky keys were disabled, clear all locks and latches */
  860. if ((old.enabled_ctrls & XkbStickyKeysMask) &&
  861. !(ctrl->enabled_ctrls & XkbStickyKeysMask))
  862. XkbClearAllLatchesAndLocks(tmpd, xkbi, TRUE, &cause);
  863. }
  864. }
  865. return Success;
  866. }
  867. /***====================================================================***/
  868. static int
  869. XkbSizeKeyTypes(XkbDescPtr xkb, xkbGetMapReply * rep)
  870. {
  871. XkbKeyTypeRec *type;
  872. unsigned i, len;
  873. len = 0;
  874. if (((rep->present & XkbKeyTypesMask) == 0) || (rep->nTypes < 1) ||
  875. (!xkb) || (!xkb->map) || (!xkb->map->types)) {
  876. rep->present &= ~XkbKeyTypesMask;
  877. rep->firstType = rep->nTypes = 0;
  878. return 0;
  879. }
  880. type = &xkb->map->types[rep->firstType];
  881. for (i = 0; i < rep->nTypes; i++, type++) {
  882. len += SIZEOF(xkbKeyTypeWireDesc);
  883. if (type->map_count > 0) {
  884. len += (type->map_count * SIZEOF(xkbKTMapEntryWireDesc));
  885. if (type->preserve)
  886. len += (type->map_count * SIZEOF(xkbModsWireDesc));
  887. }
  888. }
  889. return len;
  890. }
  891. static char *
  892. XkbWriteKeyTypes(XkbDescPtr xkb,
  893. xkbGetMapReply * rep, char *buf, ClientPtr client)
  894. {
  895. XkbKeyTypePtr type;
  896. unsigned i;
  897. xkbKeyTypeWireDesc *wire;
  898. type = &xkb->map->types[rep->firstType];
  899. for (i = 0; i < rep->nTypes; i++, type++) {
  900. register unsigned n;
  901. wire = (xkbKeyTypeWireDesc *) buf;
  902. wire->mask = type->mods.mask;
  903. wire->realMods = type->mods.real_mods;
  904. wire->virtualMods = type->mods.vmods;
  905. wire->numLevels = type->num_levels;
  906. wire->nMapEntries = type->map_count;
  907. wire->preserve = (type->preserve != NULL);
  908. if (client->swapped) {
  909. swaps(&wire->virtualMods);
  910. }
  911. buf = (char *) &wire[1];
  912. if (wire->nMapEntries > 0) {
  913. xkbKTMapEntryWireDesc *ewire;
  914. XkbKTMapEntryPtr entry;
  915. ewire = (xkbKTMapEntryWireDesc *) buf;
  916. entry = type->map;
  917. for (n = 0; n < type->map_count; n++, ewire++, entry++) {
  918. ewire->active = entry->active;
  919. ewire->mask = entry->mods.mask;
  920. ewire->level = entry->level;
  921. ewire->realMods = entry->mods.real_mods;
  922. ewire->virtualMods = entry->mods.vmods;
  923. if (client->swapped) {
  924. swaps(&ewire->virtualMods);
  925. }
  926. }
  927. buf = (char *) ewire;
  928. if (type->preserve != NULL) {
  929. xkbModsWireDesc *pwire;
  930. XkbModsPtr preserve;
  931. pwire = (xkbModsWireDesc *) buf;
  932. preserve = type->preserve;
  933. for (n = 0; n < type->map_count; n++, pwire++, preserve++) {
  934. pwire->mask = preserve->mask;
  935. pwire->realMods = preserve->real_mods;
  936. pwire->virtualMods = preserve->vmods;
  937. if (client->swapped) {
  938. swaps(&pwire->virtualMods);
  939. }
  940. }
  941. buf = (char *) pwire;
  942. }
  943. }
  944. }
  945. return buf;
  946. }
  947. static int
  948. XkbSizeKeySyms(XkbDescPtr xkb, xkbGetMapReply * rep)
  949. {
  950. XkbSymMapPtr symMap;
  951. unsigned i, len;
  952. unsigned nSyms, nSymsThisKey;
  953. if (((rep->present & XkbKeySymsMask) == 0) || (rep->nKeySyms < 1) ||
  954. (!xkb) || (!xkb->map) || (!xkb->map->key_sym_map)) {
  955. rep->present &= ~XkbKeySymsMask;
  956. rep->firstKeySym = rep->nKeySyms = 0;
  957. rep->totalSyms = 0;
  958. return 0;
  959. }
  960. len = rep->nKeySyms * SIZEOF(xkbSymMapWireDesc);
  961. symMap = &xkb->map->key_sym_map[rep->firstKeySym];
  962. for (i = nSyms = 0; i < rep->nKeySyms; i++, symMap++) {
  963. if (symMap->offset != 0) {
  964. nSymsThisKey = XkbNumGroups(symMap->group_info) * symMap->width;
  965. nSyms += nSymsThisKey;
  966. }
  967. }
  968. len += nSyms * 4;
  969. rep->totalSyms = nSyms;
  970. return len;
  971. }
  972. static int
  973. XkbSizeVirtualMods(XkbDescPtr xkb, xkbGetMapReply * rep)
  974. {
  975. register unsigned i, nMods, bit;
  976. if (((rep->present & XkbVirtualModsMask) == 0) || (rep->virtualMods == 0) ||
  977. (!xkb) || (!xkb->server)) {
  978. rep->present &= ~XkbVirtualModsMask;
  979. rep->virtualMods = 0;
  980. return 0;
  981. }
  982. for (i = nMods = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
  983. if (rep->virtualMods & bit)
  984. nMods++;
  985. }
  986. return XkbPaddedSize(nMods);
  987. }
  988. static char *
  989. XkbWriteKeySyms(XkbDescPtr xkb, xkbGetMapReply * rep, char *buf,
  990. ClientPtr client)
  991. {
  992. register KeySym *pSym;
  993. XkbSymMapPtr symMap;
  994. xkbSymMapWireDesc *outMap;
  995. register unsigned i;
  996. symMap = &xkb->map->key_sym_map[rep->firstKeySym];
  997. for (i = 0; i < rep->nKeySyms; i++, symMap++) {
  998. outMap = (xkbSymMapWireDesc *) buf;
  999. outMap->ktIndex[0] = symMap->kt_index[0];
  1000. outMap->ktIndex[1] = symMap->kt_index[1];
  1001. outMap->ktIndex[2] = symMap->kt_index[2];
  1002. outMap->ktIndex[3] = symMap->kt_index[3];
  1003. outMap->groupInfo = symMap->group_info;
  1004. outMap->width = symMap->width;
  1005. outMap->nSyms = symMap->width * XkbNumGroups(symMap->group_info);
  1006. buf = (char *) &outMap[1];
  1007. if (outMap->nSyms == 0)
  1008. continue;
  1009. pSym = &xkb->map->syms[symMap->offset];
  1010. memcpy((char *) buf, (char *) pSym, outMap->nSyms * 4);
  1011. if (client->swapped) {
  1012. register int nSyms = outMap->nSyms;
  1013. swaps(&outMap->nSyms);
  1014. while (nSyms-- > 0) {
  1015. swapl((int *) buf);
  1016. buf += 4;
  1017. }
  1018. }
  1019. else
  1020. buf += outMap->nSyms * 4;
  1021. }
  1022. return buf;
  1023. }
  1024. static int
  1025. XkbSizeKeyActions(XkbDescPtr xkb, xkbGetMapReply * rep)
  1026. {
  1027. unsigned i, len, nActs;
  1028. register KeyCode firstKey;
  1029. if (((rep->present & XkbKeyActionsMask) == 0) || (rep->nKeyActs < 1) ||
  1030. (!xkb) || (!xkb->server) || (!xkb->server->key_acts)) {
  1031. rep->present &= ~XkbKeyActionsMask;
  1032. rep->firstKeyAct = rep->nKeyActs = 0;
  1033. rep->totalActs = 0;
  1034. return 0;
  1035. }
  1036. firstKey = rep->firstKeyAct;
  1037. for (nActs = i = 0; i < rep->nKeyActs; i++) {
  1038. if (xkb->server->key_acts[i + firstKey] != 0)
  1039. nActs += XkbKeyNumActions(xkb, i + firstKey);
  1040. }
  1041. len = XkbPaddedSize(rep->nKeyActs) + (nActs * SIZEOF(xkbActionWireDesc));
  1042. rep->totalActs = nActs;
  1043. return len;
  1044. }
  1045. static char *
  1046. XkbWriteKeyActions(XkbDescPtr xkb, xkbGetMapReply * rep, char *buf,
  1047. ClientPtr client)
  1048. {
  1049. unsigned i;
  1050. CARD8 *numDesc;
  1051. XkbAnyAction *actDesc;
  1052. numDesc = (CARD8 *) buf;
  1053. for (i = 0; i < rep->nKeyActs; i++) {
  1054. if (xkb->server->key_acts[i + rep->firstKeyAct] == 0)
  1055. numDesc[i] = 0;
  1056. else
  1057. numDesc[i] = XkbKeyNumActions(xkb, (i + rep->firstKeyAct));
  1058. }
  1059. buf += XkbPaddedSize(rep->nKeyActs);
  1060. actDesc = (XkbAnyAction *) buf;
  1061. for (i = 0; i < rep->nKeyActs; i++) {
  1062. if (xkb->server->key_acts[i + rep->firstKeyAct] != 0) {
  1063. unsigned int num;
  1064. num = XkbKeyNumActions(xkb, (i + rep->firstKeyAct));
  1065. memcpy((char *) actDesc,
  1066. (char *) XkbKeyActionsPtr(xkb, (i + rep->firstKeyAct)),
  1067. num * SIZEOF(xkbActionWireDesc));
  1068. actDesc += num;
  1069. }
  1070. }
  1071. buf = (char *) actDesc;
  1072. return buf;
  1073. }
  1074. static int
  1075. XkbSizeKeyBehaviors(XkbDescPtr xkb, xkbGetMapReply * rep)
  1076. {
  1077. unsigned i, len, nBhvr;
  1078. XkbBehavior *bhv;
  1079. if (((rep->present & XkbKeyBehaviorsMask) == 0) || (rep->nKeyBehaviors < 1)
  1080. || (!xkb) || (!xkb->server) || (!xkb->server->behaviors)) {
  1081. rep->present &= ~XkbKeyBehaviorsMask;
  1082. rep->firstKeyBehavior = rep->nKeyBehaviors = 0;
  1083. rep->totalKeyBehaviors = 0;
  1084. return 0;
  1085. }
  1086. bhv = &xkb->server->behaviors[rep->firstKeyBehavior];
  1087. for (nBhvr = i = 0; i < rep->nKeyBehaviors; i++, bhv++) {
  1088. if (bhv->type != XkbKB_Default)
  1089. nBhvr++;
  1090. }
  1091. len = nBhvr * SIZEOF(xkbBehaviorWireDesc);
  1092. rep->totalKeyBehaviors = nBhvr;
  1093. return len;
  1094. }
  1095. static char *
  1096. XkbWriteKeyBehaviors(XkbDescPtr xkb, xkbGetMapReply * rep, char *buf,
  1097. ClientPtr client)
  1098. {
  1099. unsigned i;
  1100. xkbBehaviorWireDesc *wire;
  1101. XkbBehavior *pBhvr;
  1102. wire = (xkbBehaviorWireDesc *) buf;
  1103. pBhvr = &xkb->server->behaviors[rep->firstKeyBehavior];
  1104. for (i = 0; i < rep->nKeyBehaviors; i++, pBhvr++) {
  1105. if (pBhvr->type != XkbKB_Default) {
  1106. wire->key = i + rep->firstKeyBehavior;
  1107. wire->type = pBhvr->type;
  1108. wire->data = pBhvr->data;
  1109. wire++;
  1110. }
  1111. }
  1112. buf = (char *) wire;
  1113. return buf;
  1114. }
  1115. static int
  1116. XkbSizeExplicit(XkbDescPtr xkb, xkbGetMapReply * rep)
  1117. {
  1118. unsigned i, len, nRtrn;
  1119. if (((rep->present & XkbExplicitComponentsMask) == 0) ||
  1120. (rep->nKeyExplicit < 1) || (!xkb) || (!xkb->server) ||
  1121. (!xkb->server->explicit)) {
  1122. rep->present &= ~XkbExplicitComponentsMask;
  1123. rep->firstKeyExplicit = rep->nKeyExplicit = 0;
  1124. rep->totalKeyExplicit = 0;
  1125. return 0;
  1126. }
  1127. for (nRtrn = i = 0; i < rep->nKeyExplicit; i++) {
  1128. if (xkb->server->explicit[i + rep->firstKeyExplicit] != 0)
  1129. nRtrn++;
  1130. }
  1131. rep->totalKeyExplicit = nRtrn;
  1132. len = XkbPaddedSize(nRtrn * 2); /* two bytes per non-zero explicit component */
  1133. return len;
  1134. }
  1135. static char *
  1136. XkbWriteExplicit(XkbDescPtr xkb, xkbGetMapReply * rep, char *buf,
  1137. ClientPtr client)
  1138. {
  1139. unsigned i;
  1140. char *start;
  1141. unsigned char *pExp;
  1142. start = buf;
  1143. pExp = &xkb->server->explicit[rep->firstKeyExplicit];
  1144. for (i = 0; i < rep->nKeyExplicit; i++, pExp++) {
  1145. if (*pExp != 0) {
  1146. *buf++ = i + rep->firstKeyExplicit;
  1147. *buf++ = *pExp;
  1148. }
  1149. }
  1150. i = XkbPaddedSize(buf - start) - (buf - start); /* pad to word boundary */
  1151. return buf + i;
  1152. }
  1153. static int
  1154. XkbSizeModifierMap(XkbDescPtr xkb, xkbGetMapReply * rep)
  1155. {
  1156. unsigned i, len, nRtrn;
  1157. if (((rep->present & XkbModifierMapMask) == 0) || (rep->nModMapKeys < 1) ||
  1158. (!xkb) || (!xkb->map) || (!xkb->map->modmap)) {
  1159. rep->present &= ~XkbModifierMapMask;
  1160. rep->firstModMapKey = rep->nModMapKeys = 0;
  1161. rep->totalModMapKeys = 0;
  1162. return 0;
  1163. }
  1164. for (nRtrn = i = 0; i < rep->nModMapKeys; i++) {
  1165. if (xkb->map->modmap[i + rep->firstModMapKey] != 0)
  1166. nRtrn++;
  1167. }
  1168. rep->totalModMapKeys = nRtrn;
  1169. len = XkbPaddedSize(nRtrn * 2); /* two bytes per non-zero modmap component */
  1170. return len;
  1171. }
  1172. static char *
  1173. XkbWriteModifierMap(XkbDescPtr xkb, xkbGetMapReply * rep, char *buf,
  1174. ClientPtr client)
  1175. {
  1176. unsigned i;
  1177. char *start;
  1178. unsigned char *pMap;
  1179. start = buf;
  1180. pMap = &xkb->map->modmap[rep->firstModMapKey];
  1181. for (i = 0; i < rep->nModMapKeys; i++, pMap++) {
  1182. if (*pMap != 0) {
  1183. *buf++ = i + rep->firstModMapKey;
  1184. *buf++ = *pMap;
  1185. }
  1186. }
  1187. i = XkbPaddedSize(buf - start) - (buf - start); /* pad to word boundary */
  1188. return buf + i;
  1189. }
  1190. static int
  1191. XkbSizeVirtualModMap(XkbDescPtr xkb, xkbGetMapReply * rep)
  1192. {
  1193. unsigned i, len, nRtrn;
  1194. if (((rep->present & XkbVirtualModMapMask) == 0) || (rep->nVModMapKeys < 1)
  1195. || (!xkb) || (!xkb->server) || (!xkb->server->vmodmap)) {
  1196. rep->present &= ~XkbVirtualModMapMask;
  1197. rep->firstVModMapKey = rep->nVModMapKeys = 0;
  1198. rep->totalVModMapKeys = 0;
  1199. return 0;
  1200. }
  1201. for (nRtrn = i = 0; i < rep->nVModMapKeys; i++) {
  1202. if (xkb->server->vmodmap[i + rep->firstVModMapKey] != 0)
  1203. nRtrn++;
  1204. }
  1205. rep->totalVModMapKeys = nRtrn;
  1206. len = nRtrn * SIZEOF(xkbVModMapWireDesc);
  1207. return len;
  1208. }
  1209. static char *
  1210. XkbWriteVirtualModMap(XkbDescPtr xkb, xkbGetMapReply * rep, char *buf,
  1211. ClientPtr client)
  1212. {
  1213. unsigned i;
  1214. xkbVModMapWireDesc *wire;
  1215. unsigned short *pMap;
  1216. wire = (xkbVModMapWireDesc *) buf;
  1217. pMap = &xkb->server->vmodmap[rep->firstVModMapKey];
  1218. for (i = 0; i < rep->nVModMapKeys; i++, pMap++) {
  1219. if (*pMap != 0) {
  1220. wire->key = i + rep->firstVModMapKey;
  1221. wire->vmods = *pMap;
  1222. wire++;
  1223. }
  1224. }
  1225. return (char *) wire;
  1226. }
  1227. static Status
  1228. XkbComputeGetMapReplySize(XkbDescPtr xkb, xkbGetMapReply * rep)
  1229. {
  1230. int len;
  1231. rep->minKeyCode = xkb->min_key_code;
  1232. rep->maxKeyCode = xkb->max_key_code;
  1233. len = XkbSizeKeyTypes(xkb, rep);
  1234. len += XkbSizeKeySyms(xkb, rep);
  1235. len += XkbSizeKeyActions(xkb, rep);
  1236. len += XkbSizeKeyBehaviors(xkb, rep);
  1237. len += XkbSizeVirtualMods(xkb, rep);
  1238. len += XkbSizeExplicit(xkb, rep);
  1239. len += XkbSizeModifierMap(xkb, rep);
  1240. len += XkbSizeVirtualModMap(xkb, rep);
  1241. rep->length += (len / 4);
  1242. return Success;
  1243. }
  1244. static int
  1245. XkbSendMap(ClientPtr client, XkbDescPtr xkb, xkbGetMapReply * rep)
  1246. {
  1247. unsigned i, len;
  1248. char *desc, *start;
  1249. len = (rep->length * 4) - (SIZEOF(xkbGetMapReply) - SIZEOF(xGenericReply));
  1250. start = desc = calloc(1, len);
  1251. if (!start)
  1252. return BadAlloc;
  1253. if (rep->nTypes > 0)
  1254. desc = XkbWriteKeyTypes(xkb, rep, desc, client);
  1255. if (rep->nKeySyms > 0)
  1256. desc = XkbWriteKeySyms(xkb, rep, desc, client);
  1257. if (rep->nKeyActs > 0)
  1258. desc = XkbWriteKeyActions(xkb, rep, desc, client);
  1259. if (rep->totalKeyBehaviors > 0)
  1260. desc = XkbWriteKeyBehaviors(xkb, rep, desc, client);
  1261. if (rep->virtualMods) {
  1262. register int sz, bit;
  1263. for (i = sz = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
  1264. if (rep->virtualMods & bit) {
  1265. desc[sz++] = xkb->server->vmods[i];
  1266. }
  1267. }
  1268. desc += XkbPaddedSize(sz);
  1269. }
  1270. if (rep->totalKeyExplicit > 0)
  1271. desc = XkbWriteExplicit(xkb, rep, desc, client);
  1272. if (rep->totalModMapKeys > 0)
  1273. desc = XkbWriteModifierMap(xkb, rep, desc, client);
  1274. if (rep->totalVModMapKeys > 0)
  1275. desc = XkbWriteVirtualModMap(xkb, rep, desc, client);
  1276. if ((desc - start) != (len)) {
  1277. ErrorF
  1278. ("[xkb] BOGUS LENGTH in write keyboard desc, expected %d, got %ld\n",
  1279. len, (unsigned long) (desc - start));
  1280. }
  1281. if (client->swapped) {
  1282. swaps(&rep->sequenceNumber);
  1283. swapl(&rep->length);
  1284. swaps(&rep->present);
  1285. swaps(&rep->totalSyms);
  1286. swaps(&rep->totalActs);
  1287. }
  1288. WriteToClient(client, (i = SIZEOF(xkbGetMapReply)), rep);
  1289. WriteToClient(client, len, start);
  1290. free((char *) start);
  1291. return Success;
  1292. }
  1293. int
  1294. ProcXkbGetMap(ClientPtr client)
  1295. {
  1296. DeviceIntPtr dev;
  1297. xkbGetMapReply rep;
  1298. XkbDescRec *xkb;
  1299. int n, status;
  1300. REQUEST(xkbGetMapReq);
  1301. REQUEST_SIZE_MATCH(xkbGetMapReq);
  1302. if (!(client->xkbClientFlags & _XkbClientInitialized))
  1303. return BadAccess;
  1304. CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixGetAttrAccess);
  1305. CHK_MASK_OVERLAP(0x01, stuff->full, stuff->partial);
  1306. CHK_MASK_LEGAL(0x02, stuff->full, XkbAllMapComponentsMask);
  1307. CHK_MASK_LEGAL(0x03, stuff->partial, XkbAllMapComponentsMask);
  1308. xkb = dev->key->xkbInfo->desc;
  1309. rep = (xkbGetMapReply) {
  1310. .type = X_Reply,
  1311. .deviceID = dev->id,
  1312. .sequenceNumber = client->sequence,
  1313. .length = (SIZEOF(xkbGetMapReply) - SIZEOF(xGenericReply)) >> 2,
  1314. .present = stuff->partial | stuff->full,
  1315. .minKeyCode = xkb->min_key_code,
  1316. .maxKeyCode = xkb->max_key_code
  1317. };
  1318. if (stuff->full & XkbKeyTypesMask) {
  1319. rep.firstType = 0;
  1320. rep.nTypes = xkb->map->num_types;
  1321. }
  1322. else if (stuff->partial & XkbKeyTypesMask) {
  1323. if (((unsigned) stuff->firstType + stuff->nTypes) > xkb->map->num_types) {
  1324. client->errorValue = _XkbErrCode4(0x04, xkb->map->num_types,
  1325. stuff->firstType, stuff->nTypes);
  1326. return BadValue;
  1327. }
  1328. rep.firstType = stuff->firstType;
  1329. rep.nTypes = stuff->nTypes;
  1330. }
  1331. else
  1332. rep.nTypes = 0;
  1333. rep.totalTypes = xkb->map->num_types;
  1334. n = XkbNumKeys(xkb);
  1335. if (stuff->full & XkbKeySymsMask) {
  1336. rep.firstKeySym = xkb->min_key_code;
  1337. rep.nKeySyms = n;
  1338. }
  1339. else if (stuff->partial & XkbKeySymsMask) {
  1340. CHK_KEY_RANGE(0x05, stuff->firstKeySym, stuff->nKeySyms, xkb);
  1341. rep.firstKeySym = stuff->firstKeySym;
  1342. rep.nKeySyms = stuff->nKeySyms;
  1343. }
  1344. else
  1345. rep.nKeySyms = 0;
  1346. rep.totalSyms = 0;
  1347. if (stuff->full & XkbKeyActionsMask) {
  1348. rep.firstKeyAct = xkb->min_key_code;
  1349. rep.nKeyActs = n;
  1350. }
  1351. else if (stuff->partial & XkbKeyActionsMask) {
  1352. CHK_KEY_RANGE(0x07, stuff->firstKeyAct, stuff->nKeyActs, xkb);
  1353. rep.firstKeyAct = stuff->firstKeyAct;
  1354. rep.nKeyActs = stuff->nKeyActs;
  1355. }
  1356. else
  1357. rep.nKeyActs = 0;
  1358. rep.totalActs = 0;
  1359. if (stuff->full & XkbKeyBehaviorsMask) {
  1360. rep.firstKeyBehavior = xkb->min_key_code;
  1361. rep.nKeyBehaviors = n;
  1362. }
  1363. else if (stuff->partial & XkbKeyBehaviorsMask) {
  1364. CHK_KEY_RANGE(0x09, stuff->firstKeyBehavior, stuff->nKeyBehaviors, xkb);
  1365. rep.firstKeyBehavior = stuff->firstKeyBehavior;
  1366. rep.nKeyBehaviors = stuff->nKeyBehaviors;
  1367. }
  1368. else
  1369. rep.nKeyBehaviors = 0;
  1370. rep.totalKeyBehaviors = 0;
  1371. if (stuff->full & XkbVirtualModsMask)
  1372. rep.virtualMods = ~0;
  1373. else if (stuff->partial & XkbVirtualModsMask)
  1374. rep.virtualMods = stuff->virtualMods;
  1375. if (stuff->full & XkbExplicitComponentsMask) {
  1376. rep.firstKeyExplicit = xkb->min_key_code;
  1377. rep.nKeyExplicit = n;
  1378. }
  1379. else if (stuff->partial & XkbExplicitComponentsMask) {
  1380. CHK_KEY_RANGE(0x0B, stuff->firstKeyExplicit, stuff->nKeyExplicit, xkb);
  1381. rep.firstKeyExplicit = stuff->firstKeyExplicit;
  1382. rep.nKeyExplicit = stuff->nKeyExplicit;
  1383. }
  1384. else
  1385. rep.nKeyExplicit = 0;
  1386. rep.totalKeyExplicit = 0;
  1387. if (stuff->full & XkbModifierMapMask) {
  1388. rep.firstModMapKey = xkb->min_key_code;
  1389. rep.nModMapKeys = n;
  1390. }
  1391. else if (stuff->partial & XkbModifierMapMask) {
  1392. CHK_KEY_RANGE(0x0D, stuff->firstModMapKey, stuff->nModMapKeys, xkb);
  1393. rep.firstModMapKey = stuff->firstModMapKey;
  1394. rep.nModMapKeys = stuff->nModMapKeys;
  1395. }
  1396. else
  1397. rep.nModMapKeys = 0;
  1398. rep.totalModMapKeys = 0;
  1399. if (stuff->full & XkbVirtualModMapMask) {
  1400. rep.firstVModMapKey = xkb->min_key_code;
  1401. rep.nVModMapKeys = n;
  1402. }
  1403. else if (stuff->partial & XkbVirtualModMapMask) {
  1404. CHK_KEY_RANGE(0x0F, stuff->firstVModMapKey, stuff->nVModMapKeys, xkb);
  1405. rep.firstVModMapKey = stuff->firstVModMapKey;
  1406. rep.nVModMapKeys = stuff->nVModMapKeys;
  1407. }
  1408. else
  1409. rep.nVModMapKeys = 0;
  1410. rep.totalVModMapKeys = 0;
  1411. if ((status = XkbComputeGetMapReplySize(xkb, &rep)) != Success)
  1412. return status;
  1413. return XkbSendMap(client, xkb, &rep);
  1414. }
  1415. /***====================================================================***/
  1416. static int
  1417. CheckKeyTypes(ClientPtr client,
  1418. XkbDescPtr xkb,
  1419. xkbSetMapReq * req,
  1420. xkbKeyTypeWireDesc ** wireRtrn,
  1421. int *nMapsRtrn, CARD8 *mapWidthRtrn)
  1422. {
  1423. unsigned nMaps;
  1424. register unsigned i, n;
  1425. register CARD8 *map;
  1426. register xkbKeyTypeWireDesc *wire = *wireRtrn;
  1427. if (req->firstType > ((unsigned) xkb->map->num_types)) {
  1428. *nMapsRtrn = _XkbErrCode3(0x01, req->firstType, xkb->map->num_types);
  1429. return 0;
  1430. }
  1431. if (req->flags & XkbSetMapResizeTypes) {
  1432. nMaps = req->firstType + req->nTypes;
  1433. if (nMaps < XkbNumRequiredTypes) { /* canonical types must be there */
  1434. *nMapsRtrn = _XkbErrCode4(0x02, req->firstType, req->nTypes, 4);
  1435. return 0;
  1436. }
  1437. }
  1438. else if (req->present & XkbKeyTypesMask) {
  1439. nMaps = xkb->map->num_types;
  1440. if ((req->firstType + req->nTypes) > nMaps) {
  1441. *nMapsRtrn = req->firstType + req->nTypes;
  1442. return 0;
  1443. }
  1444. }
  1445. else {
  1446. *nMapsRtrn = xkb->map->num_types;
  1447. for (i = 0; i < xkb->map->num_types; i++) {
  1448. mapWidthRtrn[i] = xkb->map->types[i].num_levels;
  1449. }
  1450. return 1;
  1451. }
  1452. for (i = 0; i < req->firstType; i++) {
  1453. mapWidthRtrn[i] = xkb->map->types[i].num_levels;
  1454. }
  1455. for (i = 0; i < req->nTypes; i++) {
  1456. unsigned width;
  1457. if (client->swapped) {
  1458. swaps(&wire->virtualMods);
  1459. }
  1460. n = i + req->firstType;
  1461. width = wire->numLevels;
  1462. if (width < 1) {
  1463. *nMapsRtrn = _XkbErrCode3(0x04, n, width);
  1464. return 0;
  1465. }
  1466. else if ((n == XkbOneLevelIndex) && (width != 1)) { /* must be width 1 */
  1467. *nMapsRtrn = _XkbErrCode3(0x05, n, width);
  1468. return 0;
  1469. }
  1470. else if ((width != 2) &&
  1471. ((n == XkbTwoLevelIndex) || (n == XkbKeypadIndex) ||
  1472. (n == XkbAlphabeticIndex))) {
  1473. /* TWO_LEVEL, ALPHABETIC and KEYPAD must be width 2 */
  1474. *nMapsRtrn = _XkbErrCode3(0x05, n, width);
  1475. return 0;
  1476. }
  1477. if (wire->nMapEntries > 0) {
  1478. xkbKTSetMapEntryWireDesc *mapWire;
  1479. xkbModsWireDesc *preWire;
  1480. mapWire = (xkbKTSetMapEntryWireDesc *) &wire[1];
  1481. preWire = (xkbModsWireDesc *) &mapWire[wire->nMapEntries];
  1482. for (n = 0; n < wire->nMapEntries; n++) {
  1483. if (client->swapped) {
  1484. swaps(&mapWire[n].virtualMods);
  1485. }
  1486. if (mapWire[n].realMods & (~wire->realMods)) {
  1487. *nMapsRtrn = _XkbErrCode4(0x06, n, mapWire[n].realMods,
  1488. wire->realMods);
  1489. return 0;
  1490. }
  1491. if (mapWire[n].virtualMods & (~wire->virtualMods)) {
  1492. *nMapsRtrn = _XkbErrCode3(0x07, n, mapWire[n].virtualMods);
  1493. return 0;
  1494. }
  1495. if (mapWire[n].level >= wire->numLevels) {
  1496. *nMapsRtrn = _XkbErrCode4(0x08, n, wire->numLevels,
  1497. mapWire[n].level);
  1498. return 0;
  1499. }
  1500. if (wire->preserve) {
  1501. if (client->swapped) {
  1502. swaps(&preWire[n].virtualMods);
  1503. }
  1504. if (preWire[n].realMods & (~mapWire[n].realMods)) {
  1505. *nMapsRtrn = _XkbErrCode4(0x09, n, preWire[n].realMods,
  1506. mapWire[n].realMods);
  1507. return 0;
  1508. }
  1509. if (preWire[n].virtualMods & (~mapWire[n].virtualMods)) {
  1510. *nMapsRtrn =
  1511. _XkbErrCode3(0x0a, n, preWire[n].virtualMods);
  1512. return 0;
  1513. }
  1514. }
  1515. }
  1516. if (wire->preserve)
  1517. map = (CARD8 *) &preWire[wire->nMapEntries];
  1518. else
  1519. map = (CARD8 *) &mapWire[wire->nMapEntries];
  1520. }
  1521. else
  1522. map = (CARD8 *) &wire[1];
  1523. mapWidthRtrn[i + req->firstType] = wire->numLevels;
  1524. wire = (xkbKeyTypeWireDesc *) map;
  1525. }
  1526. for (i = req->firstType + req->nTypes; i < nMaps; i++) {
  1527. mapWidthRtrn[i] = xkb->map->types[i].num_levels;
  1528. }
  1529. *nMapsRtrn = nMaps;
  1530. *wireRtrn = wire;
  1531. return 1;
  1532. }
  1533. static int
  1534. CheckKeySyms(ClientPtr client,
  1535. XkbDescPtr xkb,
  1536. xkbSetMapReq * req,
  1537. int nTypes,
  1538. CARD8 *mapWidths,
  1539. CARD16 *symsPerKey, xkbSymMapWireDesc ** wireRtrn, int *errorRtrn)
  1540. {
  1541. register unsigned i;
  1542. XkbSymMapPtr map;
  1543. xkbSymMapWireDesc *wire = *wireRtrn;
  1544. if (!(XkbKeySymsMask & req->present))
  1545. return 1;
  1546. CHK_REQ_KEY_RANGE2(0x11, req->firstKeySym, req->nKeySyms, req, (*errorRtrn),
  1547. 0);
  1548. for (i = 0; i < req->nKeySyms; i++) {
  1549. KeySym *pSyms;
  1550. register unsigned nG;
  1551. if (client->swapped) {
  1552. swaps(&wire->nSyms);
  1553. }
  1554. nG = XkbNumGroups(wire->groupInfo);
  1555. if (nG > XkbNumKbdGroups) {
  1556. *errorRtrn = _XkbErrCode3(0x14, i + req->firstKeySym, nG);
  1557. return 0;
  1558. }
  1559. if (nG > 0) {
  1560. register int g, w;
  1561. for (g = w = 0; g < nG; g++) {
  1562. if (wire->ktIndex[g] >= (unsigned) nTypes) {
  1563. *errorRtrn = _XkbErrCode4(0x15, i + req->firstKeySym, g,
  1564. wire->ktIndex[g]);
  1565. return 0;
  1566. }
  1567. if (mapWidths[wire->ktIndex[g]] > w)
  1568. w = mapWidths[wire->ktIndex[g]];
  1569. }
  1570. if (wire->width != w) {
  1571. *errorRtrn =
  1572. _XkbErrCode3(0x16, i + req->firstKeySym, wire->width);
  1573. return 0;
  1574. }
  1575. w *= nG;
  1576. symsPerKey[i + req->firstKeySym] = w;
  1577. if (w != wire->nSyms) {
  1578. *errorRtrn =
  1579. _XkbErrCode4(0x16, i + req->firstKeySym, wire->nSyms, w);
  1580. return 0;
  1581. }
  1582. }
  1583. else if (wire->nSyms != 0) {
  1584. *errorRtrn = _XkbErrCode3(0x17, i + req->firstKeySym, wire->nSyms);
  1585. return 0;
  1586. }
  1587. pSyms = (KeySym *) &wire[1];
  1588. wire = (xkbSymMapWireDesc *) &pSyms[wire->nSyms];
  1589. }
  1590. map = &xkb->map->key_sym_map[i];
  1591. for (; i <= (unsigned) xkb->max_key_code; i++, map++) {
  1592. register int g, nG, w;
  1593. nG = XkbKeyNumGroups(xkb, i);
  1594. for (w = g = 0; g < nG; g++) {
  1595. if (map->kt_index[g] >= (unsigned) nTypes) {
  1596. *errorRtrn = _XkbErrCode4(0x18, i, g, map->kt_index[g]);
  1597. return 0;
  1598. }
  1599. if (mapWidths[map->kt_index[g]] > w)
  1600. w = mapWidths[map->kt_index[g]];
  1601. }
  1602. symsPerKey[i] = w * nG;
  1603. }
  1604. *wireRtrn = wire;
  1605. return 1;
  1606. }
  1607. static int
  1608. CheckKeyActions(XkbDescPtr xkb,
  1609. xkbSetMapReq * req,
  1610. int nTypes,
  1611. CARD8 *mapWidths,
  1612. CARD16 *symsPerKey, CARD8 **wireRtrn, int *nActsRtrn)
  1613. {
  1614. int nActs;
  1615. CARD8 *wire = *wireRtrn;
  1616. register unsigned i;
  1617. if (!(XkbKeyActionsMask & req->present))
  1618. return 1;
  1619. CHK_REQ_KEY_RANGE2(0x21, req->firstKeyAct, req->nKeyActs, req, (*nActsRtrn),
  1620. 0);
  1621. for (nActs = i = 0; i < req->nKeyActs; i++) {
  1622. if (wire[0] != 0) {
  1623. if (wire[0] == symsPerKey[i + req->firstKeyAct])
  1624. nActs += wire[0];
  1625. else {
  1626. *nActsRtrn = _XkbErrCode3(0x23, i + req->firstKeyAct, wire[0]);
  1627. return 0;
  1628. }
  1629. }
  1630. wire++;
  1631. }
  1632. if (req->nKeyActs % 4)
  1633. wire += 4 - (req->nKeyActs % 4);
  1634. *wireRtrn = (CARD8 *) (((XkbAnyAction *) wire) + nActs);
  1635. *nActsRtrn = nActs;
  1636. return 1;
  1637. }
  1638. static int
  1639. CheckKeyBehaviors(XkbDescPtr xkb,
  1640. xkbSetMapReq * req,
  1641. xkbBehaviorWireDesc ** wireRtrn, int *errorRtrn)
  1642. {
  1643. register xkbBehaviorWireDesc *wire = *wireRtrn;
  1644. register XkbServerMapPtr server = xkb->server;
  1645. register unsigned i;
  1646. unsigned first, last;
  1647. if (((req->present & XkbKeyBehaviorsMask) == 0) || (req->nKeyBehaviors < 1)) {
  1648. req->present &= ~XkbKeyBehaviorsMask;
  1649. req->nKeyBehaviors = 0;
  1650. return 1;
  1651. }
  1652. first = req->firstKeyBehavior;
  1653. last = req->firstKeyBehavior + req->nKeyBehaviors - 1;
  1654. if (first < req->minKeyCode) {
  1655. *errorRtrn = _XkbErrCode3(0x31, first, req->minKeyCode);
  1656. return 0;
  1657. }
  1658. if (last > req->maxKeyCode) {
  1659. *errorRtrn = _XkbErrCode3(0x32, last, req->maxKeyCode);
  1660. return 0;
  1661. }
  1662. for (i = 0; i < req->totalKeyBehaviors; i++, wire++) {
  1663. if ((wire->key < first) || (wire->key > last)) {
  1664. *errorRtrn = _XkbErrCode4(0x33, first, last, wire->key);
  1665. return 0;
  1666. }
  1667. if ((wire->type & XkbKB_Permanent) &&
  1668. ((server->behaviors[wire->key].type != wire->type) ||
  1669. (server->behaviors[wire->key].data != wire->data))) {
  1670. *errorRtrn = _XkbErrCode3(0x33, wire->key, wire->type);
  1671. return 0;
  1672. }
  1673. if ((wire->type == XkbKB_RadioGroup) &&
  1674. ((wire->data & (~XkbKB_RGAllowNone)) > XkbMaxRadioGroups)) {
  1675. *errorRtrn = _XkbErrCode4(0x34, wire->key, wire->data,
  1676. XkbMaxRadioGroups);
  1677. return 0;
  1678. }
  1679. if ((wire->type == XkbKB_Overlay1) || (wire->type == XkbKB_Overlay2)) {
  1680. CHK_KEY_RANGE2(0x35, wire->key, 1, xkb, *errorRtrn, 0);
  1681. }
  1682. }
  1683. *wireRtrn = wire;
  1684. return 1;
  1685. }
  1686. static int
  1687. CheckVirtualMods(XkbDescRec * xkb,
  1688. xkbSetMapReq * req, CARD8 **wireRtrn, int *errorRtrn)
  1689. {
  1690. register CARD8 *wire = *wireRtrn;
  1691. register unsigned i, nMods, bit;
  1692. if (((req->present & XkbVirtualModsMask) == 0) || (req->virtualMods == 0))
  1693. return 1;
  1694. for (i = nMods = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
  1695. if (req->virtualMods & bit)
  1696. nMods++;
  1697. }
  1698. *wireRtrn = (wire + XkbPaddedSize(nMods));
  1699. return 1;
  1700. }
  1701. static int
  1702. CheckKeyExplicit(XkbDescPtr xkb,
  1703. xkbSetMapReq * req, CARD8 **wireRtrn, int *errorRtrn)
  1704. {
  1705. register CARD8 *wire = *wireRtrn;
  1706. CARD8 *start;
  1707. register unsigned i;
  1708. int first, last;
  1709. if (((req->present & XkbExplicitComponentsMask) == 0) ||
  1710. (req->nKeyExplicit < 1)) {
  1711. req->present &= ~XkbExplicitComponentsMask;
  1712. req->nKeyExplicit = 0;
  1713. return 1;
  1714. }
  1715. first = req->firstKeyExplicit;
  1716. last = first + req->nKeyExplicit - 1;
  1717. if (first < req->minKeyCode) {
  1718. *errorRtrn = _XkbErrCode3(0x51, first, req->minKeyCode);
  1719. return 0;
  1720. }
  1721. if (last > req->maxKeyCode) {
  1722. *errorRtrn = _XkbErrCode3(0x52, last, req->maxKeyCode);
  1723. return 0;
  1724. }
  1725. start = wire;
  1726. for (i = 0; i < req->totalKeyExplicit; i++, wire += 2) {
  1727. if ((wire[0] < first) || (wire[0] > last)) {
  1728. *errorRtrn = _XkbErrCode4(0x53, first, last, wire[0]);
  1729. return 0;
  1730. }
  1731. if (wire[1] & (~XkbAllExplicitMask)) {
  1732. *errorRtrn = _XkbErrCode3(0x52, ~XkbAllExplicitMask, wire[1]);
  1733. return 0;
  1734. }
  1735. }
  1736. wire += XkbPaddedSize(wire - start) - (wire - start);
  1737. *wireRtrn = wire;
  1738. return 1;
  1739. }
  1740. static int
  1741. CheckModifierMap(XkbDescPtr xkb, xkbSetMapReq * req, CARD8 **wireRtrn,
  1742. int *errRtrn)
  1743. {
  1744. register CARD8 *wire = *wireRtrn;
  1745. CARD8 *start;
  1746. register unsigned i;
  1747. int first, last;
  1748. if (((req->present & XkbModifierMapMask) == 0) || (req->nModMapKeys < 1)) {
  1749. req->present &= ~XkbModifierMapMask;
  1750. req->nModMapKeys = 0;
  1751. return 1;
  1752. }
  1753. first = req->firstModMapKey;
  1754. last = first + req->nModMapKeys - 1;
  1755. if (first < req->minKeyCode) {
  1756. *errRtrn = _XkbErrCode3(0x61, first, req->minKeyCode);
  1757. return 0;
  1758. }
  1759. if (last > req->maxKeyCode) {
  1760. *errRtrn = _XkbErrCode3(0x62, last, req->maxKeyCode);
  1761. return 0;
  1762. }
  1763. start = wire;
  1764. for (i = 0; i < req->totalModMapKeys; i++, wire += 2) {
  1765. if ((wire[0] < first) || (wire[0] > last)) {
  1766. *errRtrn = _XkbErrCode4(0x63, first, last, wire[0]);
  1767. return 0;
  1768. }
  1769. }
  1770. wire += XkbPaddedSize(wire - start) - (wire - start);
  1771. *wireRtrn = wire;
  1772. return 1;
  1773. }
  1774. static int
  1775. CheckVirtualModMap(XkbDescPtr xkb,
  1776. xkbSetMapReq * req,
  1777. xkbVModMapWireDesc ** wireRtrn, int *errRtrn)
  1778. {
  1779. register xkbVModMapWireDesc *wire = *wireRtrn;
  1780. register unsigned i;
  1781. int first, last;
  1782. if (((req->present & XkbVirtualModMapMask) == 0) || (req->nVModMapKeys < 1)) {
  1783. req->present &= ~XkbVirtualModMapMask;
  1784. req->nVModMapKeys = 0;
  1785. return 1;
  1786. }
  1787. first = req->firstVModMapKey;
  1788. last = first + req->nVModMapKeys - 1;
  1789. if (first < req->minKeyCode) {
  1790. *errRtrn = _XkbErrCode3(0x71, first, req->minKeyCode);
  1791. return 0;
  1792. }
  1793. if (last > req->maxKeyCode) {
  1794. *errRtrn = _XkbErrCode3(0x72, last, req->maxKeyCode);
  1795. return 0;
  1796. }
  1797. for (i = 0; i < req->totalVModMapKeys; i++, wire++) {
  1798. if ((wire->key < first) || (wire->key > last)) {
  1799. *errRtrn = _XkbErrCode4(0x73, first, last, wire->key);
  1800. return 0;
  1801. }
  1802. }
  1803. *wireRtrn = wire;
  1804. return 1;
  1805. }
  1806. static char *
  1807. SetKeyTypes(XkbDescPtr xkb,
  1808. xkbSetMapReq * req,
  1809. xkbKeyTypeWireDesc * wire, XkbChangesPtr changes)
  1810. {
  1811. register unsigned i;
  1812. unsigned first, last;
  1813. CARD8 *map;
  1814. if ((unsigned) (req->firstType + req->nTypes) > xkb->map->size_types) {
  1815. i = req->firstType + req->nTypes;
  1816. if (XkbAllocClientMap(xkb, XkbKeyTypesMask, i) != Success) {
  1817. return NULL;
  1818. }
  1819. }
  1820. if ((unsigned) (req->firstType + req->nTypes) > xkb->map->num_types)
  1821. xkb->map->num_types = req->firstType + req->nTypes;
  1822. for (i = 0; i < req->nTypes; i++) {
  1823. XkbKeyTypePtr pOld;
  1824. register unsigned n;
  1825. if (XkbResizeKeyType(xkb, i + req->firstType, wire->nMapEntries,
  1826. wire->preserve, wire->numLevels) != Success) {
  1827. return NULL;
  1828. }
  1829. pOld = &xkb->map->types[i + req->firstType];
  1830. map = (CARD8 *) &wire[1];
  1831. pOld->mods.real_mods = wire->realMods;
  1832. pOld->mods.vmods = wire->virtualMods;
  1833. pOld->num_levels = wire->numLevels;
  1834. pOld->map_count = wire->nMapEntries;
  1835. pOld->mods.mask = pOld->mods.real_mods |
  1836. XkbMaskForVMask(xkb, pOld->mods.vmods);
  1837. if (wire->nMapEntries) {
  1838. xkbKTSetMapEntryWireDesc *mapWire;
  1839. xkbModsWireDesc *preWire;
  1840. unsigned tmp;
  1841. mapWire = (xkbKTSetMapEntryWireDesc *) map;
  1842. preWire = (xkbModsWireDesc *) &mapWire[wire->nMapEntries];
  1843. for (n = 0; n < wire->nMapEntries; n++) {
  1844. pOld->map[n].active = 1;
  1845. pOld->map[n].mods.mask = mapWire[n].realMods;
  1846. pOld->map[n].mods.real_mods = mapWire[n].realMods;
  1847. pOld->map[n].mods.vmods = mapWire[n].virtualMods;
  1848. pOld->map[n].level = mapWire[n].level;
  1849. if (mapWire[n].virtualMods != 0) {
  1850. tmp = XkbMaskForVMask(xkb, mapWire[n].virtualMods);
  1851. pOld->map[n].active = (tmp != 0);
  1852. pOld->map[n].mods.mask |= tmp;
  1853. }
  1854. if (wire->preserve) {
  1855. pOld->preserve[n].real_mods = preWire[n].realMods;
  1856. pOld->preserve[n].vmods = preWire[n].virtualMods;
  1857. tmp = XkbMaskForVMask(xkb, preWire[n].virtualMods);
  1858. pOld->preserve[n].mask = preWire[n].realMods | tmp;
  1859. }
  1860. }
  1861. if (wire->preserve)
  1862. map = (CARD8 *) &preWire[wire->nMapEntries];
  1863. else
  1864. map = (CARD8 *) &mapWire[wire->nMapEntries];
  1865. }
  1866. else
  1867. map = (CARD8 *) &wire[1];
  1868. wire = (xkbKeyTypeWireDesc *) map;
  1869. }
  1870. first = req->firstType;
  1871. last = first + req->nTypes - 1; /* last changed type */
  1872. if (changes->map.changed & XkbKeyTypesMask) {
  1873. int oldLast;
  1874. oldLast = changes->map.first_type + changes->map.num_types - 1;
  1875. if (changes->map.first_type < first)
  1876. first = changes->map.first_type;
  1877. if (oldLast > last)
  1878. last = oldLast;
  1879. }
  1880. changes->map.changed |= XkbKeyTypesMask;
  1881. changes->map.first_type = first;
  1882. changes->map.num_types = (last - first) + 1;
  1883. return (char *) wire;
  1884. }
  1885. static char *
  1886. SetKeySyms(ClientPtr client,
  1887. XkbDescPtr xkb,
  1888. xkbSetMapReq * req,
  1889. xkbSymMapWireDesc * wire, XkbChangesPtr changes, DeviceIntPtr dev)
  1890. {
  1891. register unsigned i, s;
  1892. XkbSymMapPtr oldMap;
  1893. KeySym *newSyms;
  1894. KeySym *pSyms;
  1895. unsigned first, last;
  1896. oldMap = &xkb->map->key_sym_map[req->firstKeySym];
  1897. for (i = 0; i < req->nKeySyms; i++, oldMap++) {
  1898. pSyms = (KeySym *) &wire[1];
  1899. if (wire->nSyms > 0) {
  1900. newSyms = XkbResizeKeySyms(xkb, i + req->firstKeySym, wire->nSyms);
  1901. for (s = 0; s < wire->nSyms; s++) {
  1902. newSyms[s] = pSyms[s];
  1903. }
  1904. if (client->swapped) {
  1905. for (s = 0; s < wire->nSyms; s++) {
  1906. swapl(&newSyms[s]);
  1907. }
  1908. }
  1909. }
  1910. oldMap->kt_index[0] = wire->ktIndex[0];
  1911. oldMap->kt_index[1] = wire->ktIndex[1];
  1912. oldMap->kt_index[2] = wire->ktIndex[2];
  1913. oldMap->kt_index[3] = wire->ktIndex[3];
  1914. oldMap->group_info = wire->groupInfo;
  1915. oldMap->width = wire->width;
  1916. wire = (xkbSymMapWireDesc *) &pSyms[wire->nSyms];
  1917. }
  1918. first = req->firstKeySym;
  1919. last = first + req->nKeySyms - 1;
  1920. if (changes->map.changed & XkbKeySymsMask) {
  1921. int oldLast =
  1922. (changes->map.first_key_sym + changes->map.num_key_syms - 1);
  1923. if (changes->map.first_key_sym < first)
  1924. first = changes->map.first_key_sym;
  1925. if (oldLast > last)
  1926. last = oldLast;
  1927. }
  1928. changes->map.changed |= XkbKeySymsMask;
  1929. changes->map.first_key_sym = first;
  1930. changes->map.num_key_syms = (last - first + 1);
  1931. s = 0;
  1932. for (i = xkb->min_key_code; i <= xkb->max_key_code; i++) {
  1933. if (XkbKeyNumGroups(xkb, i) > s)
  1934. s = XkbKeyNumGroups(xkb, i);
  1935. }
  1936. if (s != xkb->ctrls->num_groups) {
  1937. xkbControlsNotify cn;
  1938. XkbControlsRec old;
  1939. cn.keycode = 0;
  1940. cn.eventType = 0;
  1941. cn.requestMajor = XkbReqCode;
  1942. cn.requestMinor = X_kbSetMap;
  1943. old = *xkb->ctrls;
  1944. xkb->ctrls->num_groups = s;
  1945. if (XkbComputeControlsNotify(dev, &old, xkb->ctrls, &cn, FALSE))
  1946. XkbSendControlsNotify(dev, &cn);
  1947. }
  1948. return (char *) wire;
  1949. }
  1950. static char *
  1951. SetKeyActions(XkbDescPtr xkb,
  1952. xkbSetMapReq * req, CARD8 *wire, XkbChangesPtr changes)
  1953. {
  1954. register unsigned i, first, last;
  1955. CARD8 *nActs = wire;
  1956. XkbAction *newActs;
  1957. wire += XkbPaddedSize(req->nKeyActs);
  1958. for (i = 0; i < req->nKeyActs; i++) {
  1959. if (nActs[i] == 0)
  1960. xkb->server->key_acts[i + req->firstKeyAct] = 0;
  1961. else {
  1962. newActs = XkbResizeKeyActions(xkb, i + req->firstKeyAct, nActs[i]);
  1963. memcpy((char *) newActs, (char *) wire,
  1964. nActs[i] * SIZEOF(xkbActionWireDesc));
  1965. wire += nActs[i] * SIZEOF(xkbActionWireDesc);
  1966. }
  1967. }
  1968. first = req->firstKeyAct;
  1969. last = (first + req->nKeyActs - 1);
  1970. if (changes->map.changed & XkbKeyActionsMask) {
  1971. int oldLast;
  1972. oldLast = changes->map.first_key_act + changes->map.num_key_acts - 1;
  1973. if (changes->map.first_key_act < first)
  1974. first = changes->map.first_key_act;
  1975. if (oldLast > last)
  1976. last = oldLast;
  1977. }
  1978. changes->map.changed |= XkbKeyActionsMask;
  1979. changes->map.first_key_act = first;
  1980. changes->map.num_key_acts = (last - first + 1);
  1981. return (char *) wire;
  1982. }
  1983. static char *
  1984. SetKeyBehaviors(XkbSrvInfoPtr xkbi,
  1985. xkbSetMapReq * req,
  1986. xkbBehaviorWireDesc * wire, XkbChangesPtr changes)
  1987. {
  1988. register unsigned i;
  1989. int maxRG = -1;
  1990. XkbDescPtr xkb = xkbi->desc;
  1991. XkbServerMapPtr server = xkb->server;
  1992. unsigned first, last;
  1993. first = req->firstKeyBehavior;
  1994. last = req->firstKeyBehavior + req->nKeyBehaviors - 1;
  1995. memset(&server->behaviors[first], 0,
  1996. req->nKeyBehaviors * sizeof(XkbBehavior));
  1997. for (i = 0; i < req->totalKeyBehaviors; i++) {
  1998. if ((server->behaviors[wire->key].type & XkbKB_Permanent) == 0) {
  1999. server->behaviors[wire->key].type = wire->type;
  2000. server->behaviors[wire->key].data = wire->data;
  2001. if ((wire->type == XkbKB_RadioGroup) &&
  2002. (((int) wire->data) > maxRG))
  2003. maxRG = wire->data + 1;
  2004. }
  2005. wire++;
  2006. }
  2007. if (maxRG > (int) xkbi->nRadioGroups) {
  2008. int sz = maxRG * sizeof(XkbRadioGroupRec);
  2009. if (xkbi->radioGroups)
  2010. xkbi->radioGroups = realloc(xkbi->radioGroups, sz);
  2011. else
  2012. xkbi->radioGroups = calloc(1, sz);
  2013. if (xkbi->radioGroups) {
  2014. if (xkbi->nRadioGroups)
  2015. memset(&xkbi->radioGroups[xkbi->nRadioGroups], 0,
  2016. (maxRG - xkbi->nRadioGroups) * sizeof(XkbRadioGroupRec));
  2017. xkbi->nRadioGroups = maxRG;
  2018. }
  2019. else
  2020. xkbi->nRadioGroups = 0;
  2021. /* should compute members here */
  2022. }
  2023. if (changes->map.changed & XkbKeyBehaviorsMask) {
  2024. unsigned oldLast;
  2025. oldLast = changes->map.first_key_behavior +
  2026. changes->map.num_key_behaviors - 1;
  2027. if (changes->map.first_key_behavior < req->firstKeyBehavior)
  2028. first = changes->map.first_key_behavior;
  2029. if (oldLast > last)
  2030. last = oldLast;
  2031. }
  2032. changes->map.changed |= XkbKeyBehaviorsMask;
  2033. changes->map.first_key_behavior = first;
  2034. changes->map.num_key_behaviors = (last - first + 1);
  2035. return (char *) wire;
  2036. }
  2037. static char *
  2038. SetVirtualMods(XkbSrvInfoPtr xkbi, xkbSetMapReq * req, CARD8 *wire,
  2039. XkbChangesPtr changes)
  2040. {
  2041. register int i, bit, nMods;
  2042. XkbServerMapPtr srv = xkbi->desc->server;
  2043. if (((req->present & XkbVirtualModsMask) == 0) || (req->virtualMods == 0))
  2044. return (char *) wire;
  2045. for (i = nMods = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
  2046. if (req->virtualMods & bit) {
  2047. if (srv->vmods[i] != wire[nMods]) {
  2048. changes->map.changed |= XkbVirtualModsMask;
  2049. changes->map.vmods |= bit;
  2050. srv->vmods[i] = wire[nMods];
  2051. }
  2052. nMods++;
  2053. }
  2054. }
  2055. return (char *) (wire + XkbPaddedSize(nMods));
  2056. }
  2057. static char *
  2058. SetKeyExplicit(XkbSrvInfoPtr xkbi, xkbSetMapReq * req, CARD8 *wire,
  2059. XkbChangesPtr changes)
  2060. {
  2061. register unsigned i, first, last;
  2062. XkbServerMapPtr xkb = xkbi->desc->server;
  2063. CARD8 *start;
  2064. start = wire;
  2065. first = req->firstKeyExplicit;
  2066. last = req->firstKeyExplicit + req->nKeyExplicit - 1;
  2067. memset(&xkb->explicit[first], 0, req->nKeyExplicit);
  2068. for (i = 0; i < req->totalKeyExplicit; i++, wire += 2) {
  2069. xkb->explicit[wire[0]] = wire[1];
  2070. }
  2071. if (first > 0) {
  2072. if (changes->map.changed & XkbExplicitComponentsMask) {
  2073. int oldLast;
  2074. oldLast = changes->map.first_key_explicit +
  2075. changes->map.num_key_explicit - 1;
  2076. if (changes->map.first_key_explicit < first)
  2077. first = changes->map.first_key_explicit;
  2078. if (oldLast > last)
  2079. last = oldLast;
  2080. }
  2081. changes->map.first_key_explicit = first;
  2082. changes->map.num_key_explicit = (last - first) + 1;
  2083. }
  2084. wire += XkbPaddedSize(wire - start) - (wire - start);
  2085. return (char *) wire;
  2086. }
  2087. static char *
  2088. SetModifierMap(XkbSrvInfoPtr xkbi,
  2089. xkbSetMapReq * req, CARD8 *wire, XkbChangesPtr changes)
  2090. {
  2091. register unsigned i, first, last;
  2092. XkbClientMapPtr xkb = xkbi->desc->map;
  2093. CARD8 *start;
  2094. start = wire;
  2095. first = req->firstModMapKey;
  2096. last = req->firstModMapKey + req->nModMapKeys - 1;
  2097. memset(&xkb->modmap[first], 0, req->nModMapKeys);
  2098. for (i = 0; i < req->totalModMapKeys; i++, wire += 2) {
  2099. xkb->modmap[wire[0]] = wire[1];
  2100. }
  2101. if (first > 0) {
  2102. if (changes->map.changed & XkbModifierMapMask) {
  2103. int oldLast;
  2104. oldLast = changes->map.first_modmap_key +
  2105. changes->map.num_modmap_keys - 1;
  2106. if (changes->map.first_modmap_key < first)
  2107. first = changes->map.first_modmap_key;
  2108. if (oldLast > last)
  2109. last = oldLast;
  2110. }
  2111. changes->map.first_modmap_key = first;
  2112. changes->map.num_modmap_keys = (last - first) + 1;
  2113. }
  2114. wire += XkbPaddedSize(wire - start) - (wire - start);
  2115. return (char *) wire;
  2116. }
  2117. static char *
  2118. SetVirtualModMap(XkbSrvInfoPtr xkbi,
  2119. xkbSetMapReq * req,
  2120. xkbVModMapWireDesc * wire, XkbChangesPtr changes)
  2121. {
  2122. register unsigned i, first, last;
  2123. XkbServerMapPtr srv = xkbi->desc->server;
  2124. first = req->firstVModMapKey;
  2125. last = req->firstVModMapKey + req->nVModMapKeys - 1;
  2126. memset(&srv->vmodmap[first], 0, req->nVModMapKeys * sizeof(unsigned short));
  2127. for (i = 0; i < req->totalVModMapKeys; i++, wire++) {
  2128. srv->vmodmap[wire->key] = wire->vmods;
  2129. }
  2130. if (first > 0) {
  2131. if (changes->map.changed & XkbVirtualModMapMask) {
  2132. int oldLast;
  2133. oldLast = changes->map.first_vmodmap_key +
  2134. changes->map.num_vmodmap_keys - 1;
  2135. if (changes->map.first_vmodmap_key < first)
  2136. first = changes->map.first_vmodmap_key;
  2137. if (oldLast > last)
  2138. last = oldLast;
  2139. }
  2140. changes->map.first_vmodmap_key = first;
  2141. changes->map.num_vmodmap_keys = (last - first) + 1;
  2142. }
  2143. return (char *) wire;
  2144. }
  2145. /**
  2146. * Check if the given request can be applied to the given device but don't
  2147. * actually do anything..
  2148. */
  2149. static int
  2150. _XkbSetMapChecks(ClientPtr client, DeviceIntPtr dev, xkbSetMapReq * req,
  2151. char *values)
  2152. {
  2153. XkbSrvInfoPtr xkbi;
  2154. XkbDescPtr xkb;
  2155. int error;
  2156. int nTypes = 0, nActions;
  2157. CARD8 mapWidths[XkbMaxLegalKeyCode + 1] = { 0 };
  2158. CARD16 symsPerKey[XkbMaxLegalKeyCode + 1] = { 0 };
  2159. XkbSymMapPtr map;
  2160. int i;
  2161. xkbi = dev->key->xkbInfo;
  2162. xkb = xkbi->desc;
  2163. if ((xkb->min_key_code != req->minKeyCode) ||
  2164. (xkb->max_key_code != req->maxKeyCode)) {
  2165. if (client->vMajor != 1) { /* pre 1.0 versions of Xlib have a bug */
  2166. req->minKeyCode = xkb->min_key_code;
  2167. req->maxKeyCode = xkb->max_key_code;
  2168. }
  2169. else {
  2170. if (!XkbIsLegalKeycode(req->minKeyCode)) {
  2171. client->errorValue =
  2172. _XkbErrCode3(2, req->minKeyCode, req->maxKeyCode);
  2173. return BadValue;
  2174. }
  2175. if (req->minKeyCode > req->maxKeyCode) {
  2176. client->errorValue =
  2177. _XkbErrCode3(3, req->minKeyCode, req->maxKeyCode);
  2178. return BadMatch;
  2179. }
  2180. }
  2181. }
  2182. if ((req->present & XkbKeyTypesMask) &&
  2183. (!CheckKeyTypes(client, xkb, req, (xkbKeyTypeWireDesc **) &values,
  2184. &nTypes, mapWidths))) {
  2185. client->errorValue = nTypes;
  2186. return BadValue;
  2187. }
  2188. /* symsPerKey/mapWidths must be filled regardless of client-side flags */
  2189. map = &xkb->map->key_sym_map[xkb->min_key_code];
  2190. for (i = xkb->min_key_code; i < xkb->max_key_code; i++, map++) {
  2191. register int g, ng, w;
  2192. ng = XkbNumGroups(map->group_info);
  2193. for (w = g = 0; g < ng; g++) {
  2194. if (map->kt_index[g] >= (unsigned) nTypes) {
  2195. client->errorValue = _XkbErrCode4(0x13, i, g, map->kt_index[g]);
  2196. return 0;
  2197. }
  2198. if (mapWidths[map->kt_index[g]] > w)
  2199. w = mapWidths[map->kt_index[g]];
  2200. }
  2201. symsPerKey[i] = w * ng;
  2202. }
  2203. if ((req->present & XkbKeySymsMask) &&
  2204. (!CheckKeySyms(client, xkb, req, nTypes, mapWidths, symsPerKey,
  2205. (xkbSymMapWireDesc **) &values, &error))) {
  2206. client->errorValue = error;
  2207. return BadValue;
  2208. }
  2209. if ((req->present & XkbKeyActionsMask) &&
  2210. (!CheckKeyActions(xkb, req, nTypes, mapWidths, symsPerKey,
  2211. (CARD8 **) &values, &nActions))) {
  2212. client->errorValue = nActions;
  2213. return BadValue;
  2214. }
  2215. if ((req->present & XkbKeyBehaviorsMask) &&
  2216. (!CheckKeyBehaviors
  2217. (xkb, req, (xkbBehaviorWireDesc **) &values, &error))) {
  2218. client->errorValue = error;
  2219. return BadValue;
  2220. }
  2221. if ((req->present & XkbVirtualModsMask) &&
  2222. (!CheckVirtualMods(xkb, req, (CARD8 **) &values, &error))) {
  2223. client->errorValue = error;
  2224. return BadValue;
  2225. }
  2226. if ((req->present & XkbExplicitComponentsMask) &&
  2227. (!CheckKeyExplicit(xkb, req, (CARD8 **) &values, &error))) {
  2228. client->errorValue = error;
  2229. return BadValue;
  2230. }
  2231. if ((req->present & XkbModifierMapMask) &&
  2232. (!CheckModifierMap(xkb, req, (CARD8 **) &values, &error))) {
  2233. client->errorValue = error;
  2234. return BadValue;
  2235. }
  2236. if ((req->present & XkbVirtualModMapMask) &&
  2237. (!CheckVirtualModMap
  2238. (xkb, req, (xkbVModMapWireDesc **) &values, &error))) {
  2239. client->errorValue = error;
  2240. return BadValue;
  2241. }
  2242. if (((values - ((char *) req)) / 4) != req->length) {
  2243. ErrorF("[xkb] Internal error! Bad length in XkbSetMap (after check)\n");
  2244. client->errorValue = values - ((char *) &req[1]);
  2245. return BadLength;
  2246. }
  2247. return Success;
  2248. }
  2249. /**
  2250. * Apply the given request on the given device.
  2251. */
  2252. static int
  2253. _XkbSetMap(ClientPtr client, DeviceIntPtr dev, xkbSetMapReq * req, char *values)
  2254. {
  2255. XkbEventCauseRec cause;
  2256. XkbChangesRec change;
  2257. Bool sentNKN;
  2258. XkbSrvInfoPtr xkbi;
  2259. XkbDescPtr xkb;
  2260. xkbi = dev->key->xkbInfo;
  2261. xkb = xkbi->desc;
  2262. XkbSetCauseXkbReq(&cause, X_kbSetMap, client);
  2263. memset(&change, 0, sizeof(change));
  2264. sentNKN = FALSE;
  2265. if ((xkb->min_key_code != req->minKeyCode) ||
  2266. (xkb->max_key_code != req->maxKeyCode)) {
  2267. Status status;
  2268. xkbNewKeyboardNotify nkn;
  2269. nkn.deviceID = nkn.oldDeviceID = dev->id;
  2270. nkn.oldMinKeyCode = xkb->min_key_code;
  2271. nkn.oldMaxKeyCode = xkb->max_key_code;
  2272. status = XkbChangeKeycodeRange(xkb, req->minKeyCode,
  2273. req->maxKeyCode, &change);
  2274. if (status != Success)
  2275. return status; /* oh-oh. what about the other keyboards? */
  2276. nkn.minKeyCode = xkb->min_key_code;
  2277. nkn.maxKeyCode = xkb->max_key_code;
  2278. nkn.requestMajor = XkbReqCode;
  2279. nkn.requestMinor = X_kbSetMap;
  2280. nkn.changed = XkbNKN_KeycodesMask;
  2281. XkbSendNewKeyboardNotify(dev, &nkn);
  2282. sentNKN = TRUE;
  2283. }
  2284. if (req->present & XkbKeyTypesMask) {
  2285. values = SetKeyTypes(xkb, req, (xkbKeyTypeWireDesc *) values, &change);
  2286. if (!values)
  2287. goto allocFailure;
  2288. }
  2289. if (req->present & XkbKeySymsMask) {
  2290. values =
  2291. SetKeySyms(client, xkb, req, (xkbSymMapWireDesc *) values, &change,
  2292. dev);
  2293. if (!values)
  2294. goto allocFailure;
  2295. }
  2296. if (req->present & XkbKeyActionsMask) {
  2297. values = SetKeyActions(xkb, req, (CARD8 *) values, &change);
  2298. if (!values)
  2299. goto allocFailure;
  2300. }
  2301. if (req->present & XkbKeyBehaviorsMask) {
  2302. values =
  2303. SetKeyBehaviors(xkbi, req, (xkbBehaviorWireDesc *) values, &change);
  2304. if (!values)
  2305. goto allocFailure;
  2306. }
  2307. if (req->present & XkbVirtualModsMask)
  2308. values = SetVirtualMods(xkbi, req, (CARD8 *) values, &change);
  2309. if (req->present & XkbExplicitComponentsMask)
  2310. values = SetKeyExplicit(xkbi, req, (CARD8 *) values, &change);
  2311. if (req->present & XkbModifierMapMask)
  2312. values = SetModifierMap(xkbi, req, (CARD8 *) values, &change);
  2313. if (req->present & XkbVirtualModMapMask)
  2314. values =
  2315. SetVirtualModMap(xkbi, req, (xkbVModMapWireDesc *) values, &change);
  2316. if (((values - ((char *) req)) / 4) != req->length) {
  2317. ErrorF("[xkb] Internal error! Bad length in XkbSetMap (after set)\n");
  2318. client->errorValue = values - ((char *) &req[1]);
  2319. return BadLength;
  2320. }
  2321. if (req->flags & XkbSetMapRecomputeActions) {
  2322. KeyCode first, last, firstMM, lastMM;
  2323. if (change.map.num_key_syms > 0) {
  2324. first = change.map.first_key_sym;
  2325. last = first + change.map.num_key_syms - 1;
  2326. }
  2327. else
  2328. first = last = 0;
  2329. if (change.map.num_modmap_keys > 0) {
  2330. firstMM = change.map.first_modmap_key;
  2331. lastMM = first + change.map.num_modmap_keys - 1;
  2332. }
  2333. else
  2334. firstMM = lastMM = 0;
  2335. if ((last > 0) && (lastMM > 0)) {
  2336. if (firstMM < first)
  2337. first = firstMM;
  2338. if (lastMM > last)
  2339. last = lastMM;
  2340. }
  2341. else if (lastMM > 0) {
  2342. first = firstMM;
  2343. last = lastMM;
  2344. }
  2345. if (last > 0) {
  2346. unsigned check = 0;
  2347. XkbUpdateActions(dev, first, (last - first + 1), &change, &check,
  2348. &cause);
  2349. if (check)
  2350. XkbCheckSecondaryEffects(xkbi, check, &change, &cause);
  2351. }
  2352. }
  2353. if (!sentNKN)
  2354. XkbSendNotification(dev, &change, &cause);
  2355. return Success;
  2356. allocFailure:
  2357. return BadAlloc;
  2358. }
  2359. int
  2360. ProcXkbSetMap(ClientPtr client)
  2361. {
  2362. DeviceIntPtr dev;
  2363. char *tmp;
  2364. int rc;
  2365. REQUEST(xkbSetMapReq);
  2366. REQUEST_AT_LEAST_SIZE(xkbSetMapReq);
  2367. if (!(client->xkbClientFlags & _XkbClientInitialized))
  2368. return BadAccess;
  2369. CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixManageAccess);
  2370. CHK_MASK_LEGAL(0x01, stuff->present, XkbAllMapComponentsMask);
  2371. tmp = (char *) &stuff[1];
  2372. /* Check if we can to the SetMap on the requested device. If this
  2373. succeeds, do the same thing for all extension devices (if needed).
  2374. If any of them fails, fail. */
  2375. rc = _XkbSetMapChecks(client, dev, stuff, tmp);
  2376. if (rc != Success)
  2377. return rc;
  2378. if (stuff->deviceSpec == XkbUseCoreKbd) {
  2379. DeviceIntPtr other;
  2380. for (other = inputInfo.devices; other; other = other->next) {
  2381. if ((other != dev) && other->key && !IsMaster(other) &&
  2382. GetMaster(other, MASTER_KEYBOARD) == dev) {
  2383. rc = XaceHook(XACE_DEVICE_ACCESS, client, other,
  2384. DixManageAccess);
  2385. if (rc == Success) {
  2386. rc = _XkbSetMapChecks(client, other, stuff, tmp);
  2387. if (rc != Success)
  2388. return rc;
  2389. }
  2390. }
  2391. }
  2392. }
  2393. /* We know now that we will succed with the SetMap. In theory anyway. */
  2394. rc = _XkbSetMap(client, dev, stuff, tmp);
  2395. if (rc != Success)
  2396. return rc;
  2397. if (stuff->deviceSpec == XkbUseCoreKbd) {
  2398. DeviceIntPtr other;
  2399. for (other = inputInfo.devices; other; other = other->next) {
  2400. if ((other != dev) && other->key && !IsMaster(other) &&
  2401. GetMaster(other, MASTER_KEYBOARD) == dev) {
  2402. rc = XaceHook(XACE_DEVICE_ACCESS, client, other,
  2403. DixManageAccess);
  2404. if (rc == Success)
  2405. _XkbSetMap(client, other, stuff, tmp);
  2406. /* ignore rc. if the SetMap failed although the check above
  2407. reported true there isn't much we can do. we still need to
  2408. set all other devices, hoping that at least they stay in
  2409. sync. */
  2410. }
  2411. }
  2412. }
  2413. return Success;
  2414. }
  2415. /***====================================================================***/
  2416. static Status
  2417. XkbComputeGetCompatMapReplySize(XkbCompatMapPtr compat,
  2418. xkbGetCompatMapReply * rep)
  2419. {
  2420. unsigned size, nGroups;
  2421. nGroups = 0;
  2422. if (rep->groups != 0) {
  2423. register int i, bit;
  2424. for (i = 0, bit = 1; i < XkbNumKbdGroups; i++, bit <<= 1) {
  2425. if (rep->groups & bit)
  2426. nGroups++;
  2427. }
  2428. }
  2429. size = nGroups * SIZEOF(xkbModsWireDesc);
  2430. size += (rep->nSI * SIZEOF(xkbSymInterpretWireDesc));
  2431. rep->length = size / 4;
  2432. return Success;
  2433. }
  2434. static int
  2435. XkbSendCompatMap(ClientPtr client,
  2436. XkbCompatMapPtr compat, xkbGetCompatMapReply * rep)
  2437. {
  2438. char *data;
  2439. int size;
  2440. size = rep->length * 4;
  2441. if (size > 0) {
  2442. data = malloc(size);
  2443. if (data) {
  2444. register unsigned i, bit;
  2445. xkbModsWireDesc *grp;
  2446. XkbSymInterpretPtr sym = &compat->sym_interpret[rep->firstSI];
  2447. xkbSymInterpretWireDesc *wire = (xkbSymInterpretWireDesc *) data;
  2448. for (i = 0; i < rep->nSI; i++, sym++, wire++) {
  2449. wire->sym = sym->sym;
  2450. wire->mods = sym->mods;
  2451. wire->match = sym->match;
  2452. wire->virtualMod = sym->virtual_mod;
  2453. wire->flags = sym->flags;
  2454. memcpy((char *) &wire->act, (char *) &sym->act,
  2455. sz_xkbActionWireDesc);
  2456. if (client->swapped) {
  2457. swapl(&wire->sym);
  2458. }
  2459. }
  2460. if (rep->groups) {
  2461. grp = (xkbModsWireDesc *) wire;
  2462. for (i = 0, bit = 1; i < XkbNumKbdGroups; i++, bit <<= 1) {
  2463. if (rep->groups & bit) {
  2464. grp->mask = compat->groups[i].mask;
  2465. grp->realMods = compat->groups[i].real_mods;
  2466. grp->virtualMods = compat->groups[i].vmods;
  2467. if (client->swapped) {
  2468. swaps(&grp->virtualMods);
  2469. }
  2470. grp++;
  2471. }
  2472. }
  2473. wire = (xkbSymInterpretWireDesc *) grp;
  2474. }
  2475. }
  2476. else
  2477. return BadAlloc;
  2478. }
  2479. else
  2480. data = NULL;
  2481. if (client->swapped) {
  2482. swaps(&rep->sequenceNumber);
  2483. swapl(&rep->length);
  2484. swaps(&rep->firstSI);
  2485. swaps(&rep->nSI);
  2486. swaps(&rep->nTotalSI);
  2487. }
  2488. WriteToClient(client, SIZEOF(xkbGetCompatMapReply), rep);
  2489. if (data) {
  2490. WriteToClient(client, size, data);
  2491. free((char *) data);
  2492. }
  2493. return Success;
  2494. }
  2495. int
  2496. ProcXkbGetCompatMap(ClientPtr client)
  2497. {
  2498. xkbGetCompatMapReply rep;
  2499. DeviceIntPtr dev;
  2500. XkbDescPtr xkb;
  2501. XkbCompatMapPtr compat;
  2502. REQUEST(xkbGetCompatMapReq);
  2503. REQUEST_SIZE_MATCH(xkbGetCompatMapReq);
  2504. if (!(client->xkbClientFlags & _XkbClientInitialized))
  2505. return BadAccess;
  2506. CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixGetAttrAccess);
  2507. xkb = dev->key->xkbInfo->desc;
  2508. compat = xkb->compat;
  2509. rep = (xkbGetCompatMapReply) {
  2510. .type = X_Reply,
  2511. .sequenceNumber = client->sequence,
  2512. .length = 0,
  2513. .deviceID = dev->id,
  2514. .firstSI = stuff->firstSI,
  2515. .nSI = stuff->nSI
  2516. };
  2517. if (stuff->getAllSI) {
  2518. rep.firstSI = 0;
  2519. rep.nSI = compat->num_si;
  2520. }
  2521. else if ((((unsigned) stuff->nSI) > 0) &&
  2522. ((unsigned) (stuff->firstSI + stuff->nSI - 1) >= compat->num_si)) {
  2523. client->errorValue = _XkbErrCode2(0x05, compat->num_si);
  2524. return BadValue;
  2525. }
  2526. rep.nTotalSI = compat->num_si;
  2527. rep.groups = stuff->groups;
  2528. XkbComputeGetCompatMapReplySize(compat, &rep);
  2529. return XkbSendCompatMap(client, compat, &rep);
  2530. }
  2531. /**
  2532. * Apply the given request on the given device.
  2533. * If dryRun is TRUE, then value checks are performed, but the device isn't
  2534. * modified.
  2535. */
  2536. static int
  2537. _XkbSetCompatMap(ClientPtr client, DeviceIntPtr dev,
  2538. xkbSetCompatMapReq * req, char *data, BOOL dryRun)
  2539. {
  2540. XkbSrvInfoPtr xkbi;
  2541. XkbDescPtr xkb;
  2542. XkbCompatMapPtr compat;
  2543. int nGroups;
  2544. unsigned i, bit;
  2545. xkbi = dev->key->xkbInfo;
  2546. xkb = xkbi->desc;
  2547. compat = xkb->compat;
  2548. if ((req->nSI > 0) || (req->truncateSI)) {
  2549. xkbSymInterpretWireDesc *wire;
  2550. if (req->firstSI > compat->num_si) {
  2551. client->errorValue = _XkbErrCode2(0x02, compat->num_si);
  2552. return BadValue;
  2553. }
  2554. wire = (xkbSymInterpretWireDesc *) data;
  2555. wire += req->nSI;
  2556. data = (char *) wire;
  2557. }
  2558. nGroups = 0;
  2559. if (req->groups != 0) {
  2560. for (i = 0, bit = 1; i < XkbNumKbdGroups; i++, bit <<= 1) {
  2561. if (req->groups & bit)
  2562. nGroups++;
  2563. }
  2564. }
  2565. data += nGroups * SIZEOF(xkbModsWireDesc);
  2566. if (((data - ((char *) req)) / 4) != req->length) {
  2567. return BadLength;
  2568. }
  2569. /* Done all the checks we can do */
  2570. if (dryRun)
  2571. return Success;
  2572. data = (char *) &req[1];
  2573. if (req->nSI > 0) {
  2574. xkbSymInterpretWireDesc *wire = (xkbSymInterpretWireDesc *) data;
  2575. XkbSymInterpretPtr sym;
  2576. unsigned int skipped = 0;
  2577. if ((unsigned) (req->firstSI + req->nSI) > compat->num_si) {
  2578. compat->num_si = req->firstSI + req->nSI;
  2579. compat->sym_interpret = realloc(compat->sym_interpret,
  2580. compat->num_si *
  2581. sizeof(XkbSymInterpretRec));
  2582. if (!compat->sym_interpret) {
  2583. compat->num_si = 0;
  2584. return BadAlloc;
  2585. }
  2586. }
  2587. else if (req->truncateSI) {
  2588. compat->num_si = req->firstSI + req->nSI;
  2589. }
  2590. sym = &compat->sym_interpret[req->firstSI];
  2591. for (i = 0; i < req->nSI; i++, wire++) {
  2592. if (client->swapped) {
  2593. swapl(&wire->sym);
  2594. }
  2595. if (wire->sym == NoSymbol && wire->match == XkbSI_AnyOfOrNone &&
  2596. (wire->mods & 0xff) == 0xff &&
  2597. wire->act.type == XkbSA_XFree86Private) {
  2598. ErrorF("XKB: Skipping broken Any+AnyOfOrNone(All) -> Private "
  2599. "action from client\n");
  2600. skipped++;
  2601. continue;
  2602. }
  2603. sym->sym = wire->sym;
  2604. sym->mods = wire->mods;
  2605. sym->match = wire->match;
  2606. sym->flags = wire->flags;
  2607. sym->virtual_mod = wire->virtualMod;
  2608. memcpy((char *) &sym->act, (char *) &wire->act,
  2609. SIZEOF(xkbActionWireDesc));
  2610. sym++;
  2611. }
  2612. if (skipped) {
  2613. if (req->firstSI + req->nSI < compat->num_si)
  2614. memmove(sym, sym + skipped,
  2615. (compat->num_si - req->firstSI - req->nSI) *
  2616. sizeof(*sym));
  2617. compat->num_si -= skipped;
  2618. }
  2619. data = (char *) wire;
  2620. }
  2621. else if (req->truncateSI) {
  2622. compat->num_si = req->firstSI;
  2623. }
  2624. if (req->groups != 0) {
  2625. xkbModsWireDesc *wire = (xkbModsWireDesc *) data;
  2626. for (i = 0, bit = 1; i < XkbNumKbdGroups; i++, bit <<= 1) {
  2627. if (req->groups & bit) {
  2628. if (client->swapped) {
  2629. swaps(&wire->virtualMods);
  2630. }
  2631. compat->groups[i].mask = wire->realMods;
  2632. compat->groups[i].real_mods = wire->realMods;
  2633. compat->groups[i].vmods = wire->virtualMods;
  2634. if (wire->virtualMods != 0) {
  2635. unsigned tmp;
  2636. tmp = XkbMaskForVMask(xkb, wire->virtualMods);
  2637. compat->groups[i].mask |= tmp;
  2638. }
  2639. data += SIZEOF(xkbModsWireDesc);
  2640. wire = (xkbModsWireDesc *) data;
  2641. }
  2642. }
  2643. }
  2644. i = XkbPaddedSize((data - ((char *) req)));
  2645. if ((i / 4) != req->length) {
  2646. ErrorF("[xkb] Internal length error on read in _XkbSetCompatMap\n");
  2647. return BadLength;
  2648. }
  2649. if (dev->xkb_interest) {
  2650. xkbCompatMapNotify ev;
  2651. ev.deviceID = dev->id;
  2652. ev.changedGroups = req->groups;
  2653. ev.firstSI = req->firstSI;
  2654. ev.nSI = req->nSI;
  2655. ev.nTotalSI = compat->num_si;
  2656. XkbSendCompatMapNotify(dev, &ev);
  2657. }
  2658. if (req->recomputeActions) {
  2659. XkbChangesRec change;
  2660. unsigned check;
  2661. XkbEventCauseRec cause;
  2662. XkbSetCauseXkbReq(&cause, X_kbSetCompatMap, client);
  2663. memset(&change, 0, sizeof(XkbChangesRec));
  2664. XkbUpdateActions(dev, xkb->min_key_code, XkbNumKeys(xkb), &change,
  2665. &check, &cause);
  2666. if (check)
  2667. XkbCheckSecondaryEffects(xkbi, check, &change, &cause);
  2668. XkbSendNotification(dev, &change, &cause);
  2669. }
  2670. return Success;
  2671. }
  2672. int
  2673. ProcXkbSetCompatMap(ClientPtr client)
  2674. {
  2675. DeviceIntPtr dev;
  2676. char *data;
  2677. int rc;
  2678. REQUEST(xkbSetCompatMapReq);
  2679. REQUEST_AT_LEAST_SIZE(xkbSetCompatMapReq);
  2680. if (!(client->xkbClientFlags & _XkbClientInitialized))
  2681. return BadAccess;
  2682. CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixManageAccess);
  2683. data = (char *) &stuff[1];
  2684. /* check first using a dry-run */
  2685. rc = _XkbSetCompatMap(client, dev, stuff, data, TRUE);
  2686. if (rc != Success)
  2687. return rc;
  2688. if (stuff->deviceSpec == XkbUseCoreKbd) {
  2689. DeviceIntPtr other;
  2690. for (other = inputInfo.devices; other; other = other->next) {
  2691. if ((other != dev) && other->key && !IsMaster(other) &&
  2692. GetMaster(other, MASTER_KEYBOARD) == dev) {
  2693. rc = XaceHook(XACE_DEVICE_ACCESS, client, other,
  2694. DixManageAccess);
  2695. if (rc == Success) {
  2696. /* dry-run */
  2697. rc = _XkbSetCompatMap(client, other, stuff, data, TRUE);
  2698. if (rc != Success)
  2699. return rc;
  2700. }
  2701. }
  2702. }
  2703. }
  2704. /* Yay, the dry-runs succeed. Let's apply */
  2705. rc = _XkbSetCompatMap(client, dev, stuff, data, FALSE);
  2706. if (rc != Success)
  2707. return rc;
  2708. if (stuff->deviceSpec == XkbUseCoreKbd) {
  2709. DeviceIntPtr other;
  2710. for (other = inputInfo.devices; other; other = other->next) {
  2711. if ((other != dev) && other->key && !IsMaster(other) &&
  2712. GetMaster(other, MASTER_KEYBOARD) == dev) {
  2713. rc = XaceHook(XACE_DEVICE_ACCESS, client, other,
  2714. DixManageAccess);
  2715. if (rc == Success) {
  2716. rc = _XkbSetCompatMap(client, other, stuff, data, FALSE);
  2717. if (rc != Success)
  2718. return rc;
  2719. }
  2720. }
  2721. }
  2722. }
  2723. return Success;
  2724. }
  2725. /***====================================================================***/
  2726. int
  2727. ProcXkbGetIndicatorState(ClientPtr client)
  2728. {
  2729. xkbGetIndicatorStateReply rep;
  2730. XkbSrvLedInfoPtr sli;
  2731. DeviceIntPtr dev;
  2732. REQUEST(xkbGetIndicatorStateReq);
  2733. REQUEST_SIZE_MATCH(xkbGetIndicatorStateReq);
  2734. if (!(client->xkbClientFlags & _XkbClientInitialized))
  2735. return BadAccess;
  2736. CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixReadAccess);
  2737. sli = XkbFindSrvLedInfo(dev, XkbDfltXIClass, XkbDfltXIId,
  2738. XkbXI_IndicatorStateMask);
  2739. if (!sli)
  2740. return BadAlloc;
  2741. rep = (xkbGetIndicatorStateReply) {
  2742. .type = X_Reply,
  2743. .deviceID = dev->id,
  2744. .sequenceNumber = client->sequence,
  2745. .length = 0,
  2746. .state = sli->effectiveState
  2747. };
  2748. if (client->swapped) {
  2749. swaps(&rep.sequenceNumber);
  2750. swapl(&rep.state);
  2751. }
  2752. WriteToClient(client, SIZEOF(xkbGetIndicatorStateReply), &rep);
  2753. return Success;
  2754. }
  2755. /***====================================================================***/
  2756. static Status
  2757. XkbComputeGetIndicatorMapReplySize(XkbIndicatorPtr indicators,
  2758. xkbGetIndicatorMapReply * rep)
  2759. {
  2760. register int i, bit;
  2761. int nIndicators;
  2762. rep->realIndicators = indicators->phys_indicators;
  2763. for (i = nIndicators = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) {
  2764. if (rep->which & bit)
  2765. nIndicators++;
  2766. }
  2767. rep->length = (nIndicators * SIZEOF(xkbIndicatorMapWireDesc)) / 4;
  2768. rep->nIndicators = nIndicators;
  2769. return Success;
  2770. }
  2771. static int
  2772. XkbSendIndicatorMap(ClientPtr client,
  2773. XkbIndicatorPtr indicators, xkbGetIndicatorMapReply * rep)
  2774. {
  2775. int length;
  2776. CARD8 *map;
  2777. register int i;
  2778. register unsigned bit;
  2779. length = rep->length * 4;
  2780. if (length > 0) {
  2781. CARD8 *to;
  2782. to = map = malloc(length);
  2783. if (map) {
  2784. xkbIndicatorMapWireDesc *wire = (xkbIndicatorMapWireDesc *) to;
  2785. for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) {
  2786. if (rep->which & bit) {
  2787. wire->flags = indicators->maps[i].flags;
  2788. wire->whichGroups = indicators->maps[i].which_groups;
  2789. wire->groups = indicators->maps[i].groups;
  2790. wire->whichMods = indicators->maps[i].which_mods;
  2791. wire->mods = indicators->maps[i].mods.mask;
  2792. wire->realMods = indicators->maps[i].mods.real_mods;
  2793. wire->virtualMods = indicators->maps[i].mods.vmods;
  2794. wire->ctrls = indicators->maps[i].ctrls;
  2795. if (client->swapped) {
  2796. swaps(&wire->virtualMods);
  2797. swapl(&wire->ctrls);
  2798. }
  2799. wire++;
  2800. }
  2801. }
  2802. to = (CARD8 *) wire;
  2803. if ((to - map) != length) {
  2804. client->errorValue = _XkbErrCode2(0xff, length);
  2805. free(map);
  2806. return BadLength;
  2807. }
  2808. }
  2809. else
  2810. return BadAlloc;
  2811. }
  2812. else
  2813. map = NULL;
  2814. if (client->swapped) {
  2815. swaps(&rep->sequenceNumber);
  2816. swapl(&rep->length);
  2817. swapl(&rep->which);
  2818. swapl(&rep->realIndicators);
  2819. }
  2820. WriteToClient(client, SIZEOF(xkbGetIndicatorMapReply), rep);
  2821. if (map) {
  2822. WriteToClient(client, length, map);
  2823. free((char *) map);
  2824. }
  2825. return Success;
  2826. }
  2827. int
  2828. ProcXkbGetIndicatorMap(ClientPtr client)
  2829. {
  2830. xkbGetIndicatorMapReply rep;
  2831. DeviceIntPtr dev;
  2832. XkbDescPtr xkb;
  2833. XkbIndicatorPtr leds;
  2834. REQUEST(xkbGetIndicatorMapReq);
  2835. REQUEST_SIZE_MATCH(xkbGetIndicatorMapReq);
  2836. if (!(client->xkbClientFlags & _XkbClientInitialized))
  2837. return BadAccess;
  2838. CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixGetAttrAccess);
  2839. xkb = dev->key->xkbInfo->desc;
  2840. leds = xkb->indicators;
  2841. rep = (xkbGetIndicatorMapReply) {
  2842. .type = X_Reply,
  2843. .deviceID = dev->id,
  2844. .sequenceNumber = client->sequence,
  2845. .length = 0,
  2846. .which = stuff->which
  2847. };
  2848. XkbComputeGetIndicatorMapReplySize(leds, &rep);
  2849. return XkbSendIndicatorMap(client, leds, &rep);
  2850. }
  2851. /**
  2852. * Apply the given map to the given device. Which specifies which components
  2853. * to apply.
  2854. */
  2855. static int
  2856. _XkbSetIndicatorMap(ClientPtr client, DeviceIntPtr dev,
  2857. int which, xkbIndicatorMapWireDesc * desc)
  2858. {
  2859. XkbSrvInfoPtr xkbi;
  2860. XkbSrvLedInfoPtr sli;
  2861. XkbEventCauseRec cause;
  2862. int i, bit;
  2863. xkbi = dev->key->xkbInfo;
  2864. sli = XkbFindSrvLedInfo(dev, XkbDfltXIClass, XkbDfltXIId,
  2865. XkbXI_IndicatorMapsMask);
  2866. if (!sli)
  2867. return BadAlloc;
  2868. for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) {
  2869. if (which & bit) {
  2870. sli->maps[i].flags = desc->flags;
  2871. sli->maps[i].which_groups = desc->whichGroups;
  2872. sli->maps[i].groups = desc->groups;
  2873. sli->maps[i].which_mods = desc->whichMods;
  2874. sli->maps[i].mods.mask = desc->mods;
  2875. sli->maps[i].mods.real_mods = desc->mods;
  2876. sli->maps[i].mods.vmods = desc->virtualMods;
  2877. sli->maps[i].ctrls = desc->ctrls;
  2878. if (desc->virtualMods != 0) {
  2879. unsigned tmp;
  2880. tmp = XkbMaskForVMask(xkbi->desc, desc->virtualMods);
  2881. sli->maps[i].mods.mask = desc->mods | tmp;
  2882. }
  2883. desc++;
  2884. }
  2885. }
  2886. XkbSetCauseXkbReq(&cause, X_kbSetIndicatorMap, client);
  2887. XkbApplyLedMapChanges(dev, sli, which, NULL, NULL, &cause);
  2888. return Success;
  2889. }
  2890. int
  2891. ProcXkbSetIndicatorMap(ClientPtr client)
  2892. {
  2893. int i, bit;
  2894. int nIndicators;
  2895. DeviceIntPtr dev;
  2896. xkbIndicatorMapWireDesc *from;
  2897. int rc;
  2898. REQUEST(xkbSetIndicatorMapReq);
  2899. REQUEST_AT_LEAST_SIZE(xkbSetIndicatorMapReq);
  2900. if (!(client->xkbClientFlags & _XkbClientInitialized))
  2901. return BadAccess;
  2902. CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixSetAttrAccess);
  2903. if (stuff->which == 0)
  2904. return Success;
  2905. for (nIndicators = i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) {
  2906. if (stuff->which & bit)
  2907. nIndicators++;
  2908. }
  2909. if (stuff->length != ((SIZEOF(xkbSetIndicatorMapReq) +
  2910. (nIndicators * SIZEOF(xkbIndicatorMapWireDesc))) /
  2911. 4)) {
  2912. return BadLength;
  2913. }
  2914. from = (xkbIndicatorMapWireDesc *) &stuff[1];
  2915. for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) {
  2916. if (stuff->which & bit) {
  2917. if (client->swapped) {
  2918. swaps(&from->virtualMods);
  2919. swapl(&from->ctrls);
  2920. }
  2921. CHK_MASK_LEGAL(i, from->whichGroups, XkbIM_UseAnyGroup);
  2922. CHK_MASK_LEGAL(i, from->whichMods, XkbIM_UseAnyMods);
  2923. from++;
  2924. }
  2925. }
  2926. from = (xkbIndicatorMapWireDesc *) &stuff[1];
  2927. rc = _XkbSetIndicatorMap(client, dev, stuff->which, from);
  2928. if (rc != Success)
  2929. return rc;
  2930. if (stuff->deviceSpec == XkbUseCoreKbd) {
  2931. DeviceIntPtr other;
  2932. for (other = inputInfo.devices; other; other = other->next) {
  2933. if ((other != dev) && other->key && !IsMaster(other) &&
  2934. GetMaster(other, MASTER_KEYBOARD) == dev) {
  2935. rc = XaceHook(XACE_DEVICE_ACCESS, client, other,
  2936. DixSetAttrAccess);
  2937. if (rc == Success)
  2938. _XkbSetIndicatorMap(client, other, stuff->which, from);
  2939. }
  2940. }
  2941. }
  2942. return Success;
  2943. }
  2944. /***====================================================================***/
  2945. int
  2946. ProcXkbGetNamedIndicator(ClientPtr client)
  2947. {
  2948. DeviceIntPtr dev;
  2949. xkbGetNamedIndicatorReply rep;
  2950. register int i = 0;
  2951. XkbSrvLedInfoPtr sli;
  2952. XkbIndicatorMapPtr map = NULL;
  2953. REQUEST(xkbGetNamedIndicatorReq);
  2954. REQUEST_SIZE_MATCH(xkbGetNamedIndicatorReq);
  2955. if (!(client->xkbClientFlags & _XkbClientInitialized))
  2956. return BadAccess;
  2957. CHK_LED_DEVICE(dev, stuff->deviceSpec, client, DixReadAccess);
  2958. CHK_ATOM_ONLY(stuff->indicator);
  2959. sli = XkbFindSrvLedInfo(dev, stuff->ledClass, stuff->ledID, 0);
  2960. if (!sli)
  2961. return BadAlloc;
  2962. i = 0;
  2963. map = NULL;
  2964. if ((sli->names) && (sli->maps)) {
  2965. for (i = 0; i < XkbNumIndicators; i++) {
  2966. if (stuff->indicator == sli->names[i]) {
  2967. map = &sli->maps[i];
  2968. break;
  2969. }
  2970. }
  2971. }
  2972. rep = (xkbGetNamedIndicatorReply) {
  2973. .type = X_Reply,
  2974. .sequenceNumber = client->sequence,
  2975. .length = 0,
  2976. .deviceID = dev->id,
  2977. .indicator = stuff->indicator
  2978. };
  2979. if (map != NULL) {
  2980. rep.found = TRUE;
  2981. rep.on = ((sli->effectiveState & (1 << i)) != 0);
  2982. rep.realIndicator = ((sli->physIndicators & (1 << i)) != 0);
  2983. rep.ndx = i;
  2984. rep.flags = map->flags;
  2985. rep.whichGroups = map->which_groups;
  2986. rep.groups = map->groups;
  2987. rep.whichMods = map->which_mods;
  2988. rep.mods = map->mods.mask;
  2989. rep.realMods = map->mods.real_mods;
  2990. rep.virtualMods = map->mods.vmods;
  2991. rep.ctrls = map->ctrls;
  2992. rep.supported = TRUE;
  2993. }
  2994. else {
  2995. rep.found = FALSE;
  2996. rep.on = FALSE;
  2997. rep.realIndicator = FALSE;
  2998. rep.ndx = XkbNoIndicator;
  2999. rep.flags = 0;
  3000. rep.whichGroups = 0;
  3001. rep.groups = 0;
  3002. rep.whichMods = 0;
  3003. rep.mods = 0;
  3004. rep.realMods = 0;
  3005. rep.virtualMods = 0;
  3006. rep.ctrls = 0;
  3007. rep.supported = TRUE;
  3008. }
  3009. if (client->swapped) {
  3010. swapl(&rep.length);
  3011. swaps(&rep.sequenceNumber);
  3012. swapl(&rep.indicator);
  3013. swaps(&rep.virtualMods);
  3014. swapl(&rep.ctrls);
  3015. }
  3016. WriteToClient(client, SIZEOF(xkbGetNamedIndicatorReply), &rep);
  3017. return Success;
  3018. }
  3019. /**
  3020. * Find the IM on the device.
  3021. * Returns the map, or NULL if the map doesn't exist.
  3022. * If the return value is NULL, led_return is undefined. Otherwise, led_return
  3023. * is set to the led index of the map.
  3024. */
  3025. static XkbIndicatorMapPtr
  3026. _XkbFindNamedIndicatorMap(XkbSrvLedInfoPtr sli, Atom indicator, int *led_return)
  3027. {
  3028. XkbIndicatorMapPtr map;
  3029. /* search for the right indicator */
  3030. map = NULL;
  3031. if (sli->names && sli->maps) {
  3032. int led;
  3033. for (led = 0; (led < XkbNumIndicators) && (map == NULL); led++) {
  3034. if (sli->names[led] == indicator) {
  3035. map = &sli->maps[led];
  3036. *led_return = led;
  3037. break;
  3038. }
  3039. }
  3040. }
  3041. return map;
  3042. }
  3043. /**
  3044. * Creates an indicator map on the device. If dryRun is TRUE, it only checks
  3045. * if creation is possible, but doesn't actually create it.
  3046. */
  3047. static int
  3048. _XkbCreateIndicatorMap(DeviceIntPtr dev, Atom indicator,
  3049. int ledClass, int ledID,
  3050. XkbIndicatorMapPtr * map_return, int *led_return,
  3051. Bool dryRun)
  3052. {
  3053. XkbSrvLedInfoPtr sli;
  3054. XkbIndicatorMapPtr map;
  3055. int led;
  3056. sli = XkbFindSrvLedInfo(dev, ledClass, ledID, XkbXI_IndicatorsMask);
  3057. if (!sli)
  3058. return BadAlloc;
  3059. map = _XkbFindNamedIndicatorMap(sli, indicator, &led);
  3060. if (!map) {
  3061. /* find first unused indicator maps and assign the name to it */
  3062. for (led = 0, map = NULL; (led < XkbNumIndicators) && (map == NULL);
  3063. led++) {
  3064. if ((sli->names) && (sli->maps) && (sli->names[led] == None) &&
  3065. (!XkbIM_InUse(&sli->maps[led]))) {
  3066. map = &sli->maps[led];
  3067. if (!dryRun)
  3068. sli->names[led] = indicator;
  3069. break;
  3070. }
  3071. }
  3072. }
  3073. if (!map)
  3074. return BadAlloc;
  3075. *led_return = led;
  3076. *map_return = map;
  3077. return Success;
  3078. }
  3079. static int
  3080. _XkbSetNamedIndicator(ClientPtr client, DeviceIntPtr dev,
  3081. xkbSetNamedIndicatorReq * stuff)
  3082. {
  3083. unsigned int extDevReason;
  3084. unsigned int statec, namec, mapc;
  3085. XkbSrvLedInfoPtr sli;
  3086. int led = 0;
  3087. XkbIndicatorMapPtr map;
  3088. DeviceIntPtr kbd;
  3089. XkbEventCauseRec cause;
  3090. xkbExtensionDeviceNotify ed;
  3091. XkbChangesRec changes;
  3092. int rc;
  3093. rc = _XkbCreateIndicatorMap(dev, stuff->indicator, stuff->ledClass,
  3094. stuff->ledID, &map, &led, FALSE);
  3095. if (rc != Success || !map) /* oh-oh */
  3096. return rc;
  3097. sli = XkbFindSrvLedInfo(dev, stuff->ledClass, stuff->ledID,
  3098. XkbXI_IndicatorsMask);
  3099. if (!sli)
  3100. return BadAlloc;
  3101. namec = mapc = statec = 0;
  3102. extDevReason = 0;
  3103. namec |= (1 << led);
  3104. sli->namesPresent |= ((stuff->indicator != None) ? (1 << led) : 0);
  3105. extDevReason |= XkbXI_IndicatorNamesMask;
  3106. if (stuff->setMap) {
  3107. map->flags = stuff->flags;
  3108. map->which_groups = stuff->whichGroups;
  3109. map->groups = stuff->groups;
  3110. map->which_mods = stuff->whichMods;
  3111. map->mods.mask = stuff->realMods;
  3112. map->mods.real_mods = stuff->realMods;
  3113. map->mods.vmods = stuff->virtualMods;
  3114. map->ctrls = stuff->ctrls;
  3115. mapc |= (1 << led);
  3116. }
  3117. if ((stuff->setState) && ((map->flags & XkbIM_NoExplicit) == 0)) {
  3118. if (stuff->on)
  3119. sli->explicitState |= (1 << led);
  3120. else
  3121. sli->explicitState &= ~(1 << led);
  3122. statec |= ((sli->effectiveState ^ sli->explicitState) & (1 << led));
  3123. }
  3124. memset((char *) &ed, 0, sizeof(xkbExtensionDeviceNotify));
  3125. memset((char *) &changes, 0, sizeof(XkbChangesRec));
  3126. XkbSetCauseXkbReq(&cause, X_kbSetNamedIndicator, client);
  3127. if (namec)
  3128. XkbApplyLedNameChanges(dev, sli, namec, &ed, &changes, &cause);
  3129. if (mapc)
  3130. XkbApplyLedMapChanges(dev, sli, mapc, &ed, &changes, &cause);
  3131. if (statec)
  3132. XkbApplyLedStateChanges(dev, sli, statec, &ed, &changes, &cause);
  3133. kbd = dev;
  3134. if ((sli->flags & XkbSLI_HasOwnState) == 0)
  3135. kbd = inputInfo.keyboard;
  3136. XkbFlushLedEvents(dev, kbd, sli, &ed, &changes, &cause);
  3137. return Success;
  3138. }
  3139. int
  3140. ProcXkbSetNamedIndicator(ClientPtr client)
  3141. {
  3142. int rc;
  3143. DeviceIntPtr dev;
  3144. int led = 0;
  3145. XkbIndicatorMapPtr map;
  3146. REQUEST(xkbSetNamedIndicatorReq);
  3147. REQUEST_SIZE_MATCH(xkbSetNamedIndicatorReq);
  3148. if (!(client->xkbClientFlags & _XkbClientInitialized))
  3149. return BadAccess;
  3150. CHK_LED_DEVICE(dev, stuff->deviceSpec, client, DixSetAttrAccess);
  3151. CHK_ATOM_ONLY(stuff->indicator);
  3152. CHK_MASK_LEGAL(0x10, stuff->whichGroups, XkbIM_UseAnyGroup);
  3153. CHK_MASK_LEGAL(0x11, stuff->whichMods, XkbIM_UseAnyMods);
  3154. /* Dry-run for checks */
  3155. rc = _XkbCreateIndicatorMap(dev, stuff->indicator,
  3156. stuff->ledClass, stuff->ledID,
  3157. &map, &led, TRUE);
  3158. if (rc != Success || !map) /* couldn't be created or didn't exist */
  3159. return rc;
  3160. if (stuff->deviceSpec == XkbUseCoreKbd ||
  3161. stuff->deviceSpec == XkbUseCorePtr) {
  3162. DeviceIntPtr other;
  3163. for (other = inputInfo.devices; other; other = other->next) {
  3164. if ((other != dev) && !IsMaster(other) &&
  3165. GetMaster(other, MASTER_KEYBOARD) == dev && (other->kbdfeed ||
  3166. other->leds) &&
  3167. (XaceHook(XACE_DEVICE_ACCESS, client, other, DixSetAttrAccess)
  3168. == Success)) {
  3169. rc = _XkbCreateIndicatorMap(other, stuff->indicator,
  3170. stuff->ledClass, stuff->ledID, &map,
  3171. &led, TRUE);
  3172. if (rc != Success || !map)
  3173. return rc;
  3174. }
  3175. }
  3176. }
  3177. /* All checks passed, let's do it */
  3178. rc = _XkbSetNamedIndicator(client, dev, stuff);
  3179. if (rc != Success)
  3180. return rc;
  3181. if (stuff->deviceSpec == XkbUseCoreKbd ||
  3182. stuff->deviceSpec == XkbUseCorePtr) {
  3183. DeviceIntPtr other;
  3184. for (other = inputInfo.devices; other; other = other->next) {
  3185. if ((other != dev) && !IsMaster(other) &&
  3186. GetMaster(other, MASTER_KEYBOARD) == dev && (other->kbdfeed ||
  3187. other->leds) &&
  3188. (XaceHook(XACE_DEVICE_ACCESS, client, other, DixSetAttrAccess)
  3189. == Success)) {
  3190. _XkbSetNamedIndicator(client, other, stuff);
  3191. }
  3192. }
  3193. }
  3194. return Success;
  3195. }
  3196. /***====================================================================***/
  3197. static CARD32
  3198. _XkbCountAtoms(Atom *atoms, int maxAtoms, int *count)
  3199. {
  3200. register unsigned int i, bit, nAtoms;
  3201. register CARD32 atomsPresent;
  3202. for (i = nAtoms = atomsPresent = 0, bit = 1; i < maxAtoms; i++, bit <<= 1) {
  3203. if (atoms[i] != None) {
  3204. atomsPresent |= bit;
  3205. nAtoms++;
  3206. }
  3207. }
  3208. if (count)
  3209. *count = nAtoms;
  3210. return atomsPresent;
  3211. }
  3212. static char *
  3213. _XkbWriteAtoms(char *wire, Atom *atoms, int maxAtoms, int swap)
  3214. {
  3215. register unsigned int i;
  3216. Atom *atm;
  3217. atm = (Atom *) wire;
  3218. for (i = 0; i < maxAtoms; i++) {
  3219. if (atoms[i] != None) {
  3220. *atm = atoms[i];
  3221. if (swap) {
  3222. swapl(atm);
  3223. }
  3224. atm++;
  3225. }
  3226. }
  3227. return (char *) atm;
  3228. }
  3229. static Status
  3230. XkbComputeGetNamesReplySize(XkbDescPtr xkb, xkbGetNamesReply * rep)
  3231. {
  3232. register unsigned which, length;
  3233. register int i;
  3234. rep->minKeyCode = xkb->min_key_code;
  3235. rep->maxKeyCode = xkb->max_key_code;
  3236. which = rep->which;
  3237. length = 0;
  3238. if (xkb->names != NULL) {
  3239. if (which & XkbKeycodesNameMask)
  3240. length++;
  3241. if (which & XkbGeometryNameMask)
  3242. length++;
  3243. if (which & XkbSymbolsNameMask)
  3244. length++;
  3245. if (which & XkbPhysSymbolsNameMask)
  3246. length++;
  3247. if (which & XkbTypesNameMask)
  3248. length++;
  3249. if (which & XkbCompatNameMask)
  3250. length++;
  3251. }
  3252. else
  3253. which &= ~XkbComponentNamesMask;
  3254. if (xkb->map != NULL) {
  3255. if (which & XkbKeyTypeNamesMask)
  3256. length += xkb->map->num_types;
  3257. rep->nTypes = xkb->map->num_types;
  3258. if (which & XkbKTLevelNamesMask) {
  3259. XkbKeyTypePtr pType = xkb->map->types;
  3260. int nKTLevels = 0;
  3261. length += XkbPaddedSize(xkb->map->num_types) / 4;
  3262. for (i = 0; i < xkb->map->num_types; i++, pType++) {
  3263. if (pType->level_names != NULL)
  3264. nKTLevels += pType->num_levels;
  3265. }
  3266. rep->nKTLevels = nKTLevels;
  3267. length += nKTLevels;
  3268. }
  3269. }
  3270. else {
  3271. rep->nTypes = 0;
  3272. rep->nKTLevels = 0;
  3273. which &= ~(XkbKeyTypeNamesMask | XkbKTLevelNamesMask);
  3274. }
  3275. rep->minKeyCode = xkb->min_key_code;
  3276. rep->maxKeyCode = xkb->max_key_code;
  3277. rep->indicators = 0;
  3278. rep->virtualMods = 0;
  3279. rep->groupNames = 0;
  3280. if (xkb->names != NULL) {
  3281. if (which & XkbIndicatorNamesMask) {
  3282. int nLeds;
  3283. rep->indicators =
  3284. _XkbCountAtoms(xkb->names->indicators, XkbNumIndicators,
  3285. &nLeds);
  3286. length += nLeds;
  3287. if (nLeds == 0)
  3288. which &= ~XkbIndicatorNamesMask;
  3289. }
  3290. if (which & XkbVirtualModNamesMask) {
  3291. int nVMods;
  3292. rep->virtualMods =
  3293. _XkbCountAtoms(xkb->names->vmods, XkbNumVirtualMods, &nVMods);
  3294. length += nVMods;
  3295. if (nVMods == 0)
  3296. which &= ~XkbVirtualModNamesMask;
  3297. }
  3298. if (which & XkbGroupNamesMask) {
  3299. int nGroups;
  3300. rep->groupNames =
  3301. _XkbCountAtoms(xkb->names->groups, XkbNumKbdGroups, &nGroups);
  3302. length += nGroups;
  3303. if (nGroups == 0)
  3304. which &= ~XkbGroupNamesMask;
  3305. }
  3306. if ((which & XkbKeyNamesMask) && (xkb->names->keys))
  3307. length += rep->nKeys;
  3308. else
  3309. which &= ~XkbKeyNamesMask;
  3310. if ((which & XkbKeyAliasesMask) &&
  3311. (xkb->names->key_aliases) && (xkb->names->num_key_aliases > 0)) {
  3312. rep->nKeyAliases = xkb->names->num_key_aliases;
  3313. length += rep->nKeyAliases * 2;
  3314. }
  3315. else {
  3316. which &= ~XkbKeyAliasesMask;
  3317. rep->nKeyAliases = 0;
  3318. }
  3319. if ((which & XkbRGNamesMask) && (xkb->names->num_rg > 0))
  3320. length += xkb->names->num_rg;
  3321. else
  3322. which &= ~XkbRGNamesMask;
  3323. }
  3324. else {
  3325. which &= ~(XkbIndicatorNamesMask | XkbVirtualModNamesMask);
  3326. which &= ~(XkbGroupNamesMask | XkbKeyNamesMask | XkbKeyAliasesMask);
  3327. which &= ~XkbRGNamesMask;
  3328. }
  3329. rep->length = length;
  3330. rep->which = which;
  3331. return Success;
  3332. }
  3333. static int
  3334. XkbSendNames(ClientPtr client, XkbDescPtr xkb, xkbGetNamesReply * rep)
  3335. {
  3336. register unsigned i, length, which;
  3337. char *start;
  3338. char *desc;
  3339. length = rep->length * 4;
  3340. which = rep->which;
  3341. if (client->swapped) {
  3342. swaps(&rep->sequenceNumber);
  3343. swapl(&rep->length);
  3344. swapl(&rep->which);
  3345. swaps(&rep->virtualMods);
  3346. swapl(&rep->indicators);
  3347. }
  3348. start = desc = calloc(1, length);
  3349. if (!start)
  3350. return BadAlloc;
  3351. if (xkb->names) {
  3352. if (which & XkbKeycodesNameMask) {
  3353. *((CARD32 *) desc) = xkb->names->keycodes;
  3354. if (client->swapped) {
  3355. swapl((int *) desc);
  3356. }
  3357. desc += 4;
  3358. }
  3359. if (which & XkbGeometryNameMask) {
  3360. *((CARD32 *) desc) = xkb->names->geometry;
  3361. if (client->swapped) {
  3362. swapl((int *) desc);
  3363. }
  3364. desc += 4;
  3365. }
  3366. if (which & XkbSymbolsNameMask) {
  3367. *((CARD32 *) desc) = xkb->names->symbols;
  3368. if (client->swapped) {
  3369. swapl((int *) desc);
  3370. }
  3371. desc += 4;
  3372. }
  3373. if (which & XkbPhysSymbolsNameMask) {
  3374. register CARD32 *atm = (CARD32 *) desc;
  3375. atm[0] = (CARD32) xkb->names->phys_symbols;
  3376. if (client->swapped) {
  3377. swapl(&atm[0]);
  3378. }
  3379. desc += 4;
  3380. }
  3381. if (which & XkbTypesNameMask) {
  3382. *((CARD32 *) desc) = (CARD32) xkb->names->types;
  3383. if (client->swapped) {
  3384. swapl((int *) desc);
  3385. }
  3386. desc += 4;
  3387. }
  3388. if (which & XkbCompatNameMask) {
  3389. *((CARD32 *) desc) = (CARD32) xkb->names->compat;
  3390. if (client->swapped) {
  3391. swapl((int *) desc);
  3392. }
  3393. desc += 4;
  3394. }
  3395. if (which & XkbKeyTypeNamesMask) {
  3396. register CARD32 *atm = (CARD32 *) desc;
  3397. register XkbKeyTypePtr type = xkb->map->types;
  3398. for (i = 0; i < xkb->map->num_types; i++, atm++, type++) {
  3399. *atm = (CARD32) type->name;
  3400. if (client->swapped) {
  3401. swapl(atm);
  3402. }
  3403. }
  3404. desc = (char *) atm;
  3405. }
  3406. if (which & XkbKTLevelNamesMask && xkb->map) {
  3407. XkbKeyTypePtr type = xkb->map->types;
  3408. register CARD32 *atm;
  3409. for (i = 0; i < rep->nTypes; i++, type++) {
  3410. *desc++ = type->num_levels;
  3411. }
  3412. desc += XkbPaddedSize(rep->nTypes) - rep->nTypes;
  3413. atm = (CARD32 *) desc;
  3414. type = xkb->map->types;
  3415. for (i = 0; i < xkb->map->num_types; i++, type++) {
  3416. register unsigned l;
  3417. if (type->level_names) {
  3418. for (l = 0; l < type->num_levels; l++, atm++) {
  3419. *atm = type->level_names[l];
  3420. if (client->swapped) {
  3421. swapl(atm);
  3422. }
  3423. }
  3424. desc += type->num_levels * 4;
  3425. }
  3426. }
  3427. }
  3428. if (which & XkbIndicatorNamesMask) {
  3429. desc =
  3430. _XkbWriteAtoms(desc, xkb->names->indicators, XkbNumIndicators,
  3431. client->swapped);
  3432. }
  3433. if (which & XkbVirtualModNamesMask) {
  3434. desc = _XkbWriteAtoms(desc, xkb->names->vmods, XkbNumVirtualMods,
  3435. client->swapped);
  3436. }
  3437. if (which & XkbGroupNamesMask) {
  3438. desc = _XkbWriteAtoms(desc, xkb->names->groups, XkbNumKbdGroups,
  3439. client->swapped);
  3440. }
  3441. if (which & XkbKeyNamesMask) {
  3442. for (i = 0; i < rep->nKeys; i++, desc += sizeof(XkbKeyNameRec)) {
  3443. *((XkbKeyNamePtr) desc) = xkb->names->keys[i + rep->firstKey];
  3444. }
  3445. }
  3446. if (which & XkbKeyAliasesMask) {
  3447. XkbKeyAliasPtr pAl;
  3448. pAl = xkb->names->key_aliases;
  3449. for (i = 0; i < rep->nKeyAliases;
  3450. i++, pAl++, desc += 2 * XkbKeyNameLength) {
  3451. *((XkbKeyAliasPtr) desc) = *pAl;
  3452. }
  3453. }
  3454. if ((which & XkbRGNamesMask) && (rep->nRadioGroups > 0)) {
  3455. register CARD32 *atm = (CARD32 *) desc;
  3456. for (i = 0; i < rep->nRadioGroups; i++, atm++) {
  3457. *atm = (CARD32) xkb->names->radio_groups[i];
  3458. if (client->swapped) {
  3459. swapl(atm);
  3460. }
  3461. }
  3462. desc += rep->nRadioGroups * 4;
  3463. }
  3464. }
  3465. if ((desc - start) != (length)) {
  3466. ErrorF("[xkb] BOGUS LENGTH in write names, expected %d, got %ld\n",
  3467. length, (unsigned long) (desc - start));
  3468. }
  3469. WriteToClient(client, SIZEOF(xkbGetNamesReply), rep);
  3470. WriteToClient(client, length, start);
  3471. free((char *) start);
  3472. return Success;
  3473. }
  3474. int
  3475. ProcXkbGetNames(ClientPtr client)
  3476. {
  3477. DeviceIntPtr dev;
  3478. XkbDescPtr xkb;
  3479. xkbGetNamesReply rep;
  3480. REQUEST(xkbGetNamesReq);
  3481. REQUEST_SIZE_MATCH(xkbGetNamesReq);
  3482. if (!(client->xkbClientFlags & _XkbClientInitialized))
  3483. return BadAccess;
  3484. CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixGetAttrAccess);
  3485. CHK_MASK_LEGAL(0x01, stuff->which, XkbAllNamesMask);
  3486. xkb = dev->key->xkbInfo->desc;
  3487. rep = (xkbGetNamesReply) {
  3488. .type = X_Reply,
  3489. .deviceID = dev->id,
  3490. .sequenceNumber = client->sequence,
  3491. .length = 0,
  3492. .which = stuff->which,
  3493. .nTypes = xkb->map->num_types,
  3494. .firstKey = xkb->min_key_code,
  3495. .nKeys = XkbNumKeys(xkb),
  3496. .nKeyAliases = xkb->names ? xkb->names->num_key_aliases : 0,
  3497. .nRadioGroups = xkb->names ? xkb->names->num_rg : 0
  3498. };
  3499. XkbComputeGetNamesReplySize(xkb, &rep);
  3500. return XkbSendNames(client, xkb, &rep);
  3501. }
  3502. /***====================================================================***/
  3503. static CARD32 *
  3504. _XkbCheckAtoms(CARD32 *wire, int nAtoms, int swapped, Atom *pError)
  3505. {
  3506. register int i;
  3507. for (i = 0; i < nAtoms; i++, wire++) {
  3508. if (swapped) {
  3509. swapl(wire);
  3510. }
  3511. if ((((Atom) *wire) != None) && (!ValidAtom((Atom) *wire))) {
  3512. *pError = ((Atom) *wire);
  3513. return NULL;
  3514. }
  3515. }
  3516. return wire;
  3517. }
  3518. static CARD32 *
  3519. _XkbCheckMaskedAtoms(CARD32 *wire, int nAtoms, CARD32 present, int swapped,
  3520. Atom *pError)
  3521. {
  3522. register unsigned i, bit;
  3523. for (i = 0, bit = 1; (i < nAtoms) && (present); i++, bit <<= 1) {
  3524. if ((present & bit) == 0)
  3525. continue;
  3526. if (swapped) {
  3527. swapl(wire);
  3528. }
  3529. if ((((Atom) *wire) != None) && (!ValidAtom(((Atom) *wire)))) {
  3530. *pError = (Atom) *wire;
  3531. return NULL;
  3532. }
  3533. wire++;
  3534. }
  3535. return wire;
  3536. }
  3537. static Atom *
  3538. _XkbCopyMaskedAtoms(Atom *wire, Atom *dest, int nAtoms, CARD32 present)
  3539. {
  3540. register int i, bit;
  3541. for (i = 0, bit = 1; (i < nAtoms) && (present); i++, bit <<= 1) {
  3542. if ((present & bit) == 0)
  3543. continue;
  3544. dest[i] = *wire++;
  3545. }
  3546. return wire;
  3547. }
  3548. static Bool
  3549. _XkbCheckTypeName(Atom name, int typeNdx)
  3550. {
  3551. const char *str;
  3552. str = NameForAtom(name);
  3553. if ((strcmp(str, "ONE_LEVEL") == 0) || (strcmp(str, "TWO_LEVEL") == 0) ||
  3554. (strcmp(str, "ALPHABETIC") == 0) || (strcmp(str, "KEYPAD") == 0))
  3555. return FALSE;
  3556. return TRUE;
  3557. }
  3558. /**
  3559. * Check the device-dependent data in the request against the device. Returns
  3560. * Success, or the appropriate error code.
  3561. */
  3562. static int
  3563. _XkbSetNamesCheck(ClientPtr client, DeviceIntPtr dev,
  3564. xkbSetNamesReq * stuff, CARD32 *data)
  3565. {
  3566. XkbDescRec *xkb;
  3567. CARD32 *tmp;
  3568. Atom bad;
  3569. tmp = data;
  3570. xkb = dev->key->xkbInfo->desc;
  3571. if (stuff->which & XkbKeyTypeNamesMask) {
  3572. int i;
  3573. CARD32 *old;
  3574. if (stuff->nTypes < 1) {
  3575. client->errorValue = _XkbErrCode2(0x02, stuff->nTypes);
  3576. return BadValue;
  3577. }
  3578. if ((unsigned) (stuff->firstType + stuff->nTypes - 1) >=
  3579. xkb->map->num_types) {
  3580. client->errorValue =
  3581. _XkbErrCode4(0x03, stuff->firstType, stuff->nTypes,
  3582. xkb->map->num_types);
  3583. return BadValue;
  3584. }
  3585. if (((unsigned) stuff->firstType) <= XkbLastRequiredType) {
  3586. client->errorValue = _XkbErrCode2(0x04, stuff->firstType);
  3587. return BadAccess;
  3588. }
  3589. old = tmp;
  3590. tmp = _XkbCheckAtoms(tmp, stuff->nTypes, client->swapped, &bad);
  3591. if (!tmp) {
  3592. client->errorValue = bad;
  3593. return BadAtom;
  3594. }
  3595. for (i = 0; i < stuff->nTypes; i++, old++) {
  3596. if (!_XkbCheckTypeName((Atom) *old, stuff->firstType + i))
  3597. client->errorValue = _XkbErrCode2(0x05, i);
  3598. }
  3599. }
  3600. if (stuff->which & XkbKTLevelNamesMask) {
  3601. unsigned i;
  3602. XkbKeyTypePtr type;
  3603. CARD8 *width;
  3604. if (stuff->nKTLevels < 1) {
  3605. client->errorValue = _XkbErrCode2(0x05, stuff->nKTLevels);
  3606. return BadValue;
  3607. }
  3608. if ((unsigned) (stuff->firstKTLevel + stuff->nKTLevels - 1) >=
  3609. xkb->map->num_types) {
  3610. client->errorValue = _XkbErrCode4(0x06, stuff->firstKTLevel,
  3611. stuff->nKTLevels,
  3612. xkb->map->num_types);
  3613. return BadValue;
  3614. }
  3615. width = (CARD8 *) tmp;
  3616. tmp = (CARD32 *) (((char *) tmp) + XkbPaddedSize(stuff->nKTLevels));
  3617. type = &xkb->map->types[stuff->firstKTLevel];
  3618. for (i = 0; i < stuff->nKTLevels; i++, type++) {
  3619. if (width[i] == 0)
  3620. continue;
  3621. else if (width[i] != type->num_levels) {
  3622. client->errorValue = _XkbErrCode4(0x07, i + stuff->firstKTLevel,
  3623. type->num_levels, width[i]);
  3624. return BadMatch;
  3625. }
  3626. tmp = _XkbCheckAtoms(tmp, width[i], client->swapped, &bad);
  3627. if (!tmp) {
  3628. client->errorValue = bad;
  3629. return BadAtom;
  3630. }
  3631. }
  3632. }
  3633. if (stuff->which & XkbIndicatorNamesMask) {
  3634. if (stuff->indicators == 0) {
  3635. client->errorValue = 0x08;
  3636. return BadMatch;
  3637. }
  3638. tmp = _XkbCheckMaskedAtoms(tmp, XkbNumIndicators, stuff->indicators,
  3639. client->swapped, &bad);
  3640. if (!tmp) {
  3641. client->errorValue = bad;
  3642. return BadAtom;
  3643. }
  3644. }
  3645. if (stuff->which & XkbVirtualModNamesMask) {
  3646. if (stuff->virtualMods == 0) {
  3647. client->errorValue = 0x09;
  3648. return BadMatch;
  3649. }
  3650. tmp = _XkbCheckMaskedAtoms(tmp, XkbNumVirtualMods,
  3651. (CARD32) stuff->virtualMods,
  3652. client->swapped, &bad);
  3653. if (!tmp) {
  3654. client->errorValue = bad;
  3655. return BadAtom;
  3656. }
  3657. }
  3658. if (stuff->which & XkbGroupNamesMask) {
  3659. if (stuff->groupNames == 0) {
  3660. client->errorValue = 0x0a;
  3661. return BadMatch;
  3662. }
  3663. tmp = _XkbCheckMaskedAtoms(tmp, XkbNumKbdGroups,
  3664. (CARD32) stuff->groupNames,
  3665. client->swapped, &bad);
  3666. if (!tmp) {
  3667. client->errorValue = bad;
  3668. return BadAtom;
  3669. }
  3670. }
  3671. if (stuff->which & XkbKeyNamesMask) {
  3672. if (stuff->firstKey < (unsigned) xkb->min_key_code) {
  3673. client->errorValue = _XkbErrCode3(0x0b, xkb->min_key_code,
  3674. stuff->firstKey);
  3675. return BadValue;
  3676. }
  3677. if (((unsigned) (stuff->firstKey + stuff->nKeys - 1) >
  3678. xkb->max_key_code) || (stuff->nKeys < 1)) {
  3679. client->errorValue =
  3680. _XkbErrCode4(0x0c, xkb->max_key_code, stuff->firstKey,
  3681. stuff->nKeys);
  3682. return BadValue;
  3683. }
  3684. tmp += stuff->nKeys;
  3685. }
  3686. if ((stuff->which & XkbKeyAliasesMask) && (stuff->nKeyAliases > 0)) {
  3687. tmp += stuff->nKeyAliases * 2;
  3688. }
  3689. if (stuff->which & XkbRGNamesMask) {
  3690. if (stuff->nRadioGroups < 1) {
  3691. client->errorValue = _XkbErrCode2(0x0d, stuff->nRadioGroups);
  3692. return BadValue;
  3693. }
  3694. tmp = _XkbCheckAtoms(tmp, stuff->nRadioGroups, client->swapped, &bad);
  3695. if (!tmp) {
  3696. client->errorValue = bad;
  3697. return BadAtom;
  3698. }
  3699. }
  3700. if ((tmp - ((CARD32 *) stuff)) != stuff->length) {
  3701. client->errorValue = stuff->length;
  3702. return BadLength;
  3703. }
  3704. return Success;
  3705. }
  3706. static int
  3707. _XkbSetNames(ClientPtr client, DeviceIntPtr dev, xkbSetNamesReq * stuff)
  3708. {
  3709. XkbDescRec *xkb;
  3710. XkbNamesRec *names;
  3711. CARD32 *tmp;
  3712. xkbNamesNotify nn;
  3713. tmp = (CARD32 *) &stuff[1];
  3714. xkb = dev->key->xkbInfo->desc;
  3715. names = xkb->names;
  3716. if (XkbAllocNames(xkb, stuff->which, stuff->nRadioGroups,
  3717. stuff->nKeyAliases) != Success) {
  3718. return BadAlloc;
  3719. }
  3720. memset(&nn, 0, sizeof(xkbNamesNotify));
  3721. nn.changed = stuff->which;
  3722. tmp = (CARD32 *) &stuff[1];
  3723. if (stuff->which & XkbKeycodesNameMask)
  3724. names->keycodes = *tmp++;
  3725. if (stuff->which & XkbGeometryNameMask)
  3726. names->geometry = *tmp++;
  3727. if (stuff->which & XkbSymbolsNameMask)
  3728. names->symbols = *tmp++;
  3729. if (stuff->which & XkbPhysSymbolsNameMask)
  3730. names->phys_symbols = *tmp++;
  3731. if (stuff->which & XkbTypesNameMask)
  3732. names->types = *tmp++;
  3733. if (stuff->which & XkbCompatNameMask)
  3734. names->compat = *tmp++;
  3735. if ((stuff->which & XkbKeyTypeNamesMask) && (stuff->nTypes > 0)) {
  3736. register unsigned i;
  3737. register XkbKeyTypePtr type;
  3738. type = &xkb->map->types[stuff->firstType];
  3739. for (i = 0; i < stuff->nTypes; i++, type++) {
  3740. type->name = *tmp++;
  3741. }
  3742. nn.firstType = stuff->firstType;
  3743. nn.nTypes = stuff->nTypes;
  3744. }
  3745. if (stuff->which & XkbKTLevelNamesMask) {
  3746. register XkbKeyTypePtr type;
  3747. register unsigned i;
  3748. CARD8 *width;
  3749. width = (CARD8 *) tmp;
  3750. tmp = (CARD32 *) (((char *) tmp) + XkbPaddedSize(stuff->nKTLevels));
  3751. type = &xkb->map->types[stuff->firstKTLevel];
  3752. for (i = 0; i < stuff->nKTLevels; i++, type++) {
  3753. if (width[i] > 0) {
  3754. if (type->level_names) {
  3755. register unsigned n;
  3756. for (n = 0; n < width[i]; n++) {
  3757. type->level_names[n] = tmp[n];
  3758. }
  3759. }
  3760. tmp += width[i];
  3761. }
  3762. }
  3763. nn.firstLevelName = 0;
  3764. nn.nLevelNames = stuff->nTypes;
  3765. }
  3766. if (stuff->which & XkbIndicatorNamesMask) {
  3767. tmp = _XkbCopyMaskedAtoms(tmp, names->indicators, XkbNumIndicators,
  3768. stuff->indicators);
  3769. nn.changedIndicators = stuff->indicators;
  3770. }
  3771. if (stuff->which & XkbVirtualModNamesMask) {
  3772. tmp = _XkbCopyMaskedAtoms(tmp, names->vmods, XkbNumVirtualMods,
  3773. stuff->virtualMods);
  3774. nn.changedVirtualMods = stuff->virtualMods;
  3775. }
  3776. if (stuff->which & XkbGroupNamesMask) {
  3777. tmp = _XkbCopyMaskedAtoms(tmp, names->groups, XkbNumKbdGroups,
  3778. stuff->groupNames);
  3779. nn.changedVirtualMods = stuff->groupNames;
  3780. }
  3781. if (stuff->which & XkbKeyNamesMask) {
  3782. memcpy((char *) &names->keys[stuff->firstKey], (char *) tmp,
  3783. stuff->nKeys * XkbKeyNameLength);
  3784. tmp += stuff->nKeys;
  3785. nn.firstKey = stuff->firstKey;
  3786. nn.nKeys = stuff->nKeys;
  3787. }
  3788. if (stuff->which & XkbKeyAliasesMask) {
  3789. if (stuff->nKeyAliases > 0) {
  3790. register int na = stuff->nKeyAliases;
  3791. if (XkbAllocNames(xkb, XkbKeyAliasesMask, 0, na) != Success)
  3792. return BadAlloc;
  3793. memcpy((char *) names->key_aliases, (char *) tmp,
  3794. stuff->nKeyAliases * sizeof(XkbKeyAliasRec));
  3795. tmp += stuff->nKeyAliases * 2;
  3796. }
  3797. else if (names->key_aliases != NULL) {
  3798. free(names->key_aliases);
  3799. names->key_aliases = NULL;
  3800. names->num_key_aliases = 0;
  3801. }
  3802. nn.nAliases = names->num_key_aliases;
  3803. }
  3804. if (stuff->which & XkbRGNamesMask) {
  3805. if (stuff->nRadioGroups > 0) {
  3806. register unsigned i, nrg;
  3807. nrg = stuff->nRadioGroups;
  3808. if (XkbAllocNames(xkb, XkbRGNamesMask, nrg, 0) != Success)
  3809. return BadAlloc;
  3810. for (i = 0; i < stuff->nRadioGroups; i++) {
  3811. names->radio_groups[i] = tmp[i];
  3812. }
  3813. tmp += stuff->nRadioGroups;
  3814. }
  3815. else if (names->radio_groups) {
  3816. free(names->radio_groups);
  3817. names->radio_groups = NULL;
  3818. names->num_rg = 0;
  3819. }
  3820. nn.nRadioGroups = names->num_rg;
  3821. }
  3822. if (nn.changed) {
  3823. Bool needExtEvent;
  3824. needExtEvent = (nn.changed & XkbIndicatorNamesMask) != 0;
  3825. XkbSendNamesNotify(dev, &nn);
  3826. if (needExtEvent) {
  3827. XkbSrvLedInfoPtr sli;
  3828. xkbExtensionDeviceNotify edev;
  3829. register int i;
  3830. register unsigned bit;
  3831. sli = XkbFindSrvLedInfo(dev, XkbDfltXIClass, XkbDfltXIId,
  3832. XkbXI_IndicatorsMask);
  3833. sli->namesPresent = 0;
  3834. for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) {
  3835. if (names->indicators[i] != None)
  3836. sli->namesPresent |= bit;
  3837. }
  3838. memset(&edev, 0, sizeof(xkbExtensionDeviceNotify));
  3839. edev.reason = XkbXI_IndicatorNamesMask;
  3840. edev.ledClass = KbdFeedbackClass;
  3841. edev.ledID = dev->kbdfeed->ctrl.id;
  3842. edev.ledsDefined = sli->namesPresent | sli->mapsPresent;
  3843. edev.ledState = sli->effectiveState;
  3844. edev.firstBtn = 0;
  3845. edev.nBtns = 0;
  3846. edev.supported = XkbXI_AllFeaturesMask;
  3847. edev.unsupported = 0;
  3848. XkbSendExtensionDeviceNotify(dev, client, &edev);
  3849. }
  3850. }
  3851. return Success;
  3852. }
  3853. int
  3854. ProcXkbSetNames(ClientPtr client)
  3855. {
  3856. DeviceIntPtr dev;
  3857. CARD32 *tmp;
  3858. Atom bad;
  3859. int rc;
  3860. REQUEST(xkbSetNamesReq);
  3861. REQUEST_AT_LEAST_SIZE(xkbSetNamesReq);
  3862. if (!(client->xkbClientFlags & _XkbClientInitialized))
  3863. return BadAccess;
  3864. CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixManageAccess);
  3865. CHK_MASK_LEGAL(0x01, stuff->which, XkbAllNamesMask);
  3866. /* check device-independent stuff */
  3867. tmp = (CARD32 *) &stuff[1];
  3868. if (stuff->which & XkbKeycodesNameMask) {
  3869. tmp = _XkbCheckAtoms(tmp, 1, client->swapped, &bad);
  3870. if (!tmp) {
  3871. client->errorValue = bad;
  3872. return BadAtom;
  3873. }
  3874. }
  3875. if (stuff->which & XkbGeometryNameMask) {
  3876. tmp = _XkbCheckAtoms(tmp, 1, client->swapped, &bad);
  3877. if (!tmp) {
  3878. client->errorValue = bad;
  3879. return BadAtom;
  3880. }
  3881. }
  3882. if (stuff->which & XkbSymbolsNameMask) {
  3883. tmp = _XkbCheckAtoms(tmp, 1, client->swapped, &bad);
  3884. if (!tmp) {
  3885. client->errorValue = bad;
  3886. return BadAtom;
  3887. }
  3888. }
  3889. if (stuff->which & XkbPhysSymbolsNameMask) {
  3890. tmp = _XkbCheckAtoms(tmp, 1, client->swapped, &bad);
  3891. if (!tmp) {
  3892. client->errorValue = bad;
  3893. return BadAtom;
  3894. }
  3895. }
  3896. if (stuff->which & XkbTypesNameMask) {
  3897. tmp = _XkbCheckAtoms(tmp, 1, client->swapped, &bad);
  3898. if (!tmp) {
  3899. client->errorValue = bad;
  3900. return BadAtom;
  3901. }
  3902. }
  3903. if (stuff->which & XkbCompatNameMask) {
  3904. tmp = _XkbCheckAtoms(tmp, 1, client->swapped, &bad);
  3905. if (!tmp) {
  3906. client->errorValue = bad;
  3907. return BadAtom;
  3908. }
  3909. }
  3910. /* start of device-dependent tests */
  3911. rc = _XkbSetNamesCheck(client, dev, stuff, tmp);
  3912. if (rc != Success)
  3913. return rc;
  3914. if (stuff->deviceSpec == XkbUseCoreKbd) {
  3915. DeviceIntPtr other;
  3916. for (other = inputInfo.devices; other; other = other->next) {
  3917. if ((other != dev) && other->key && !IsMaster(other) &&
  3918. GetMaster(other, MASTER_KEYBOARD) == dev) {
  3919. rc = XaceHook(XACE_DEVICE_ACCESS, client, other,
  3920. DixManageAccess);
  3921. if (rc == Success) {
  3922. rc = _XkbSetNamesCheck(client, other, stuff, tmp);
  3923. if (rc != Success)
  3924. return rc;
  3925. }
  3926. }
  3927. }
  3928. }
  3929. /* everything is okay -- update names */
  3930. rc = _XkbSetNames(client, dev, stuff);
  3931. if (rc != Success)
  3932. return rc;
  3933. if (stuff->deviceSpec == XkbUseCoreKbd) {
  3934. DeviceIntPtr other;
  3935. for (other = inputInfo.devices; other; other = other->next) {
  3936. if ((other != dev) && other->key && !IsMaster(other) &&
  3937. GetMaster(other, MASTER_KEYBOARD) == dev) {
  3938. rc = XaceHook(XACE_DEVICE_ACCESS, client, other,
  3939. DixManageAccess);
  3940. if (rc == Success)
  3941. _XkbSetNames(client, other, stuff);
  3942. }
  3943. }
  3944. }
  3945. /* everything is okay -- update names */
  3946. return Success;
  3947. }
  3948. /***====================================================================***/
  3949. #include "xkbgeom.h"
  3950. #define XkbSizeCountedString(s) ((s)?((((2+strlen(s))+3)/4)*4):4)
  3951. /**
  3952. * Write the zero-terminated string str into wire as a pascal string with a
  3953. * 16-bit length field prefixed before the actual string.
  3954. *
  3955. * @param wire The destination array, usually the wire struct
  3956. * @param str The source string as zero-terminated C string
  3957. * @param swap If TRUE, the length field is swapped.
  3958. *
  3959. * @return The input string in the format <string length><string> with a
  3960. * (swapped) 16 bit string length, non-zero terminated.
  3961. */
  3962. static char *
  3963. XkbWriteCountedString(char *wire, const char *str, Bool swap)
  3964. {
  3965. CARD16 len, *pLen, paddedLen;
  3966. if (!str)
  3967. return wire;
  3968. len = strlen(str);
  3969. pLen = (CARD16 *) wire;
  3970. *pLen = len;
  3971. if (swap) {
  3972. swaps(pLen);
  3973. }
  3974. paddedLen = pad_to_int32(sizeof(len) + len) - sizeof(len);
  3975. strncpy(&wire[sizeof(len)], str, paddedLen);
  3976. wire += sizeof(len) + paddedLen;
  3977. return wire;
  3978. }
  3979. static int
  3980. XkbSizeGeomProperties(XkbGeometryPtr geom)
  3981. {
  3982. register int i, size;
  3983. XkbPropertyPtr prop;
  3984. for (size = i = 0, prop = geom->properties; i < geom->num_properties;
  3985. i++, prop++) {
  3986. size += XkbSizeCountedString(prop->name);
  3987. size += XkbSizeCountedString(prop->value);
  3988. }
  3989. return size;
  3990. }
  3991. static char *
  3992. XkbWriteGeomProperties(char *wire, XkbGeometryPtr geom, Bool swap)
  3993. {
  3994. register int i;
  3995. register XkbPropertyPtr prop;
  3996. for (i = 0, prop = geom->properties; i < geom->num_properties; i++, prop++) {
  3997. wire = XkbWriteCountedString(wire, prop->name, swap);
  3998. wire = XkbWriteCountedString(wire, prop->value, swap);
  3999. }
  4000. return wire;
  4001. }
  4002. static int
  4003. XkbSizeGeomKeyAliases(XkbGeometryPtr geom)
  4004. {
  4005. return geom->num_key_aliases * (2 * XkbKeyNameLength);
  4006. }
  4007. static char *
  4008. XkbWriteGeomKeyAliases(char *wire, XkbGeometryPtr geom, Bool swap)
  4009. {
  4010. register int sz;
  4011. sz = geom->num_key_aliases * (XkbKeyNameLength * 2);
  4012. if (sz > 0) {
  4013. memcpy(wire, (char *) geom->key_aliases, sz);
  4014. wire += sz;
  4015. }
  4016. return wire;
  4017. }
  4018. static int
  4019. XkbSizeGeomColors(XkbGeometryPtr geom)
  4020. {
  4021. register int i, size;
  4022. register XkbColorPtr color;
  4023. for (i = size = 0, color = geom->colors; i < geom->num_colors; i++, color++) {
  4024. size += XkbSizeCountedString(color->spec);
  4025. }
  4026. return size;
  4027. }
  4028. static char *
  4029. XkbWriteGeomColors(char *wire, XkbGeometryPtr geom, Bool swap)
  4030. {
  4031. register int i;
  4032. register XkbColorPtr color;
  4033. for (i = 0, color = geom->colors; i < geom->num_colors; i++, color++) {
  4034. wire = XkbWriteCountedString(wire, color->spec, swap);
  4035. }
  4036. return wire;
  4037. }
  4038. static int
  4039. XkbSizeGeomShapes(XkbGeometryPtr geom)
  4040. {
  4041. register int i, size;
  4042. register XkbShapePtr shape;
  4043. for (i = size = 0, shape = geom->shapes; i < geom->num_shapes; i++, shape++) {
  4044. register int n;
  4045. register XkbOutlinePtr ol;
  4046. size += SIZEOF(xkbShapeWireDesc);
  4047. for (n = 0, ol = shape->outlines; n < shape->num_outlines; n++, ol++) {
  4048. size += SIZEOF(xkbOutlineWireDesc);
  4049. size += ol->num_points * SIZEOF(xkbPointWireDesc);
  4050. }
  4051. }
  4052. return size;
  4053. }
  4054. static char *
  4055. XkbWriteGeomShapes(char *wire, XkbGeometryPtr geom, Bool swap)
  4056. {
  4057. int i;
  4058. XkbShapePtr shape;
  4059. xkbShapeWireDesc *shapeWire;
  4060. for (i = 0, shape = geom->shapes; i < geom->num_shapes; i++, shape++) {
  4061. register int o;
  4062. XkbOutlinePtr ol;
  4063. xkbOutlineWireDesc *olWire;
  4064. shapeWire = (xkbShapeWireDesc *) wire;
  4065. shapeWire->name = shape->name;
  4066. shapeWire->nOutlines = shape->num_outlines;
  4067. if (shape->primary != NULL)
  4068. shapeWire->primaryNdx = XkbOutlineIndex(shape, shape->primary);
  4069. else
  4070. shapeWire->primaryNdx = XkbNoShape;
  4071. if (shape->approx != NULL)
  4072. shapeWire->approxNdx = XkbOutlineIndex(shape, shape->approx);
  4073. else
  4074. shapeWire->approxNdx = XkbNoShape;
  4075. shapeWire->pad = 0;
  4076. if (swap) {
  4077. swapl(&shapeWire->name);
  4078. }
  4079. wire = (char *) &shapeWire[1];
  4080. for (o = 0, ol = shape->outlines; o < shape->num_outlines; o++, ol++) {
  4081. register int p;
  4082. XkbPointPtr pt;
  4083. xkbPointWireDesc *ptWire;
  4084. olWire = (xkbOutlineWireDesc *) wire;
  4085. olWire->nPoints = ol->num_points;
  4086. olWire->cornerRadius = ol->corner_radius;
  4087. olWire->pad = 0;
  4088. wire = (char *) &olWire[1];
  4089. ptWire = (xkbPointWireDesc *) wire;
  4090. for (p = 0, pt = ol->points; p < ol->num_points; p++, pt++) {
  4091. ptWire[p].x = pt->x;
  4092. ptWire[p].y = pt->y;
  4093. if (swap) {
  4094. swaps(&ptWire[p].x);
  4095. swaps(&ptWire[p].y);
  4096. }
  4097. }
  4098. wire = (char *) &ptWire[ol->num_points];
  4099. }
  4100. }
  4101. return wire;
  4102. }
  4103. static int
  4104. XkbSizeGeomDoodads(int num_doodads, XkbDoodadPtr doodad)
  4105. {
  4106. register int i, size;
  4107. for (i = size = 0; i < num_doodads; i++, doodad++) {
  4108. size += SIZEOF(xkbAnyDoodadWireDesc);
  4109. if (doodad->any.type == XkbTextDoodad) {
  4110. size += XkbSizeCountedString(doodad->text.text);
  4111. size += XkbSizeCountedString(doodad->text.font);
  4112. }
  4113. else if (doodad->any.type == XkbLogoDoodad) {
  4114. size += XkbSizeCountedString(doodad->logo.logo_name);
  4115. }
  4116. }
  4117. return size;
  4118. }
  4119. static char *
  4120. XkbWriteGeomDoodads(char *wire, int num_doodads, XkbDoodadPtr doodad, Bool swap)
  4121. {
  4122. register int i;
  4123. xkbDoodadWireDesc *doodadWire;
  4124. for (i = 0; i < num_doodads; i++, doodad++) {
  4125. doodadWire = (xkbDoodadWireDesc *) wire;
  4126. wire = (char *) &doodadWire[1];
  4127. memset(doodadWire, 0, SIZEOF(xkbDoodadWireDesc));
  4128. doodadWire->any.name = doodad->any.name;
  4129. doodadWire->any.type = doodad->any.type;
  4130. doodadWire->any.priority = doodad->any.priority;
  4131. doodadWire->any.top = doodad->any.top;
  4132. doodadWire->any.left = doodad->any.left;
  4133. if (swap) {
  4134. swapl(&doodadWire->any.name);
  4135. swaps(&doodadWire->any.top);
  4136. swaps(&doodadWire->any.left);
  4137. }
  4138. switch (doodad->any.type) {
  4139. case XkbOutlineDoodad:
  4140. case XkbSolidDoodad:
  4141. doodadWire->shape.angle = doodad->shape.angle;
  4142. doodadWire->shape.colorNdx = doodad->shape.color_ndx;
  4143. doodadWire->shape.shapeNdx = doodad->shape.shape_ndx;
  4144. if (swap) {
  4145. swaps(&doodadWire->shape.angle);
  4146. }
  4147. break;
  4148. case XkbTextDoodad:
  4149. doodadWire->text.angle = doodad->text.angle;
  4150. doodadWire->text.width = doodad->text.width;
  4151. doodadWire->text.height = doodad->text.height;
  4152. doodadWire->text.colorNdx = doodad->text.color_ndx;
  4153. if (swap) {
  4154. swaps(&doodadWire->text.angle);
  4155. swaps(&doodadWire->text.width);
  4156. swaps(&doodadWire->text.height);
  4157. }
  4158. wire = XkbWriteCountedString(wire, doodad->text.text, swap);
  4159. wire = XkbWriteCountedString(wire, doodad->text.font, swap);
  4160. break;
  4161. case XkbIndicatorDoodad:
  4162. doodadWire->indicator.shapeNdx = doodad->indicator.shape_ndx;
  4163. doodadWire->indicator.onColorNdx = doodad->indicator.on_color_ndx;
  4164. doodadWire->indicator.offColorNdx = doodad->indicator.off_color_ndx;
  4165. break;
  4166. case XkbLogoDoodad:
  4167. doodadWire->logo.angle = doodad->logo.angle;
  4168. doodadWire->logo.colorNdx = doodad->logo.color_ndx;
  4169. doodadWire->logo.shapeNdx = doodad->logo.shape_ndx;
  4170. wire = XkbWriteCountedString(wire, doodad->logo.logo_name, swap);
  4171. break;
  4172. default:
  4173. ErrorF("[xkb] Unknown doodad type %d in XkbWriteGeomDoodads\n",
  4174. doodad->any.type);
  4175. ErrorF("[xkb] Ignored\n");
  4176. break;
  4177. }
  4178. }
  4179. return wire;
  4180. }
  4181. static char *
  4182. XkbWriteGeomOverlay(char *wire, XkbOverlayPtr ol, Bool swap)
  4183. {
  4184. register int r;
  4185. XkbOverlayRowPtr row;
  4186. xkbOverlayWireDesc *olWire;
  4187. olWire = (xkbOverlayWireDesc *) wire;
  4188. olWire->name = ol->name;
  4189. olWire->nRows = ol->num_rows;
  4190. olWire->pad1 = 0;
  4191. olWire->pad2 = 0;
  4192. if (swap) {
  4193. swapl(&olWire->name);
  4194. }
  4195. wire = (char *) &olWire[1];
  4196. for (r = 0, row = ol->rows; r < ol->num_rows; r++, row++) {
  4197. unsigned int k;
  4198. XkbOverlayKeyPtr key;
  4199. xkbOverlayRowWireDesc *rowWire;
  4200. rowWire = (xkbOverlayRowWireDesc *) wire;
  4201. rowWire->rowUnder = row->row_under;
  4202. rowWire->nKeys = row->num_keys;
  4203. rowWire->pad1 = 0;
  4204. wire = (char *) &rowWire[1];
  4205. for (k = 0, key = row->keys; k < row->num_keys; k++, key++) {
  4206. xkbOverlayKeyWireDesc *keyWire;
  4207. keyWire = (xkbOverlayKeyWireDesc *) wire;
  4208. memcpy(keyWire->over, key->over.name, XkbKeyNameLength);
  4209. memcpy(keyWire->under, key->under.name, XkbKeyNameLength);
  4210. wire = (char *) &keyWire[1];
  4211. }
  4212. }
  4213. return wire;
  4214. }
  4215. static int
  4216. XkbSizeGeomSections(XkbGeometryPtr geom)
  4217. {
  4218. register int i, size;
  4219. XkbSectionPtr section;
  4220. for (i = size = 0, section = geom->sections; i < geom->num_sections;
  4221. i++, section++) {
  4222. size += SIZEOF(xkbSectionWireDesc);
  4223. if (section->rows) {
  4224. int r;
  4225. XkbRowPtr row;
  4226. for (r = 0, row = section->rows; r < section->num_rows; row++, r++) {
  4227. size += SIZEOF(xkbRowWireDesc);
  4228. size += row->num_keys * SIZEOF(xkbKeyWireDesc);
  4229. }
  4230. }
  4231. if (section->doodads)
  4232. size += XkbSizeGeomDoodads(section->num_doodads, section->doodads);
  4233. if (section->overlays) {
  4234. int o;
  4235. XkbOverlayPtr ol;
  4236. for (o = 0, ol = section->overlays; o < section->num_overlays;
  4237. o++, ol++) {
  4238. int r;
  4239. XkbOverlayRowPtr row;
  4240. size += SIZEOF(xkbOverlayWireDesc);
  4241. for (r = 0, row = ol->rows; r < ol->num_rows; r++, row++) {
  4242. size += SIZEOF(xkbOverlayRowWireDesc);
  4243. size += row->num_keys * SIZEOF(xkbOverlayKeyWireDesc);
  4244. }
  4245. }
  4246. }
  4247. }
  4248. return size;
  4249. }
  4250. static char *
  4251. XkbWriteGeomSections(char *wire, XkbGeometryPtr geom, Bool swap)
  4252. {
  4253. register int i;
  4254. XkbSectionPtr section;
  4255. xkbSectionWireDesc *sectionWire;
  4256. for (i = 0, section = geom->sections; i < geom->num_sections;
  4257. i++, section++) {
  4258. sectionWire = (xkbSectionWireDesc *) wire;
  4259. sectionWire->name = section->name;
  4260. sectionWire->top = section->top;
  4261. sectionWire->left = section->left;
  4262. sectionWire->width = section->width;
  4263. sectionWire->height = section->height;
  4264. sectionWire->angle = section->angle;
  4265. sectionWire->priority = section->priority;
  4266. sectionWire->nRows = section->num_rows;
  4267. sectionWire->nDoodads = section->num_doodads;
  4268. sectionWire->nOverlays = section->num_overlays;
  4269. sectionWire->pad = 0;
  4270. if (swap) {
  4271. swapl(&sectionWire->name);
  4272. swaps(&sectionWire->top);
  4273. swaps(&sectionWire->left);
  4274. swaps(&sectionWire->width);
  4275. swaps(&sectionWire->height);
  4276. swaps(&sectionWire->angle);
  4277. }
  4278. wire = (char *) &sectionWire[1];
  4279. if (section->rows) {
  4280. int r;
  4281. XkbRowPtr row;
  4282. xkbRowWireDesc *rowWire;
  4283. for (r = 0, row = section->rows; r < section->num_rows; r++, row++) {
  4284. rowWire = (xkbRowWireDesc *) wire;
  4285. rowWire->top = row->top;
  4286. rowWire->left = row->left;
  4287. rowWire->nKeys = row->num_keys;
  4288. rowWire->vertical = row->vertical;
  4289. rowWire->pad = 0;
  4290. if (swap) {
  4291. swaps(&rowWire->top);
  4292. swaps(&rowWire->left);
  4293. }
  4294. wire = (char *) &rowWire[1];
  4295. if (row->keys) {
  4296. int k;
  4297. XkbKeyPtr key;
  4298. xkbKeyWireDesc *keyWire;
  4299. keyWire = (xkbKeyWireDesc *) wire;
  4300. for (k = 0, key = row->keys; k < row->num_keys; k++, key++) {
  4301. memcpy(keyWire[k].name, key->name.name,
  4302. XkbKeyNameLength);
  4303. keyWire[k].gap = key->gap;
  4304. keyWire[k].shapeNdx = key->shape_ndx;
  4305. keyWire[k].colorNdx = key->color_ndx;
  4306. if (swap) {
  4307. swaps(&keyWire[k].gap);
  4308. }
  4309. }
  4310. wire = (char *) &keyWire[row->num_keys];
  4311. }
  4312. }
  4313. }
  4314. if (section->doodads) {
  4315. wire = XkbWriteGeomDoodads(wire,
  4316. section->num_doodads, section->doodads,
  4317. swap);
  4318. }
  4319. if (section->overlays) {
  4320. register int o;
  4321. for (o = 0; o < section->num_overlays; o++) {
  4322. wire = XkbWriteGeomOverlay(wire, &section->overlays[o], swap);
  4323. }
  4324. }
  4325. }
  4326. return wire;
  4327. }
  4328. static Status
  4329. XkbComputeGetGeometryReplySize(XkbGeometryPtr geom,
  4330. xkbGetGeometryReply * rep, Atom name)
  4331. {
  4332. int len;
  4333. if (geom != NULL) {
  4334. len = XkbSizeCountedString(geom->label_font);
  4335. len += XkbSizeGeomProperties(geom);
  4336. len += XkbSizeGeomColors(geom);
  4337. len += XkbSizeGeomShapes(geom);
  4338. len += XkbSizeGeomSections(geom);
  4339. len += XkbSizeGeomDoodads(geom->num_doodads, geom->doodads);
  4340. len += XkbSizeGeomKeyAliases(geom);
  4341. rep->length = len / 4;
  4342. rep->found = TRUE;
  4343. rep->name = geom->name;
  4344. rep->widthMM = geom->width_mm;
  4345. rep->heightMM = geom->height_mm;
  4346. rep->nProperties = geom->num_properties;
  4347. rep->nColors = geom->num_colors;
  4348. rep->nShapes = geom->num_shapes;
  4349. rep->nSections = geom->num_sections;
  4350. rep->nDoodads = geom->num_doodads;
  4351. rep->nKeyAliases = geom->num_key_aliases;
  4352. rep->baseColorNdx = XkbGeomColorIndex(geom, geom->base_color);
  4353. rep->labelColorNdx = XkbGeomColorIndex(geom, geom->label_color);
  4354. }
  4355. else {
  4356. rep->length = 0;
  4357. rep->found = FALSE;
  4358. rep->name = name;
  4359. rep->widthMM = rep->heightMM = 0;
  4360. rep->nProperties = rep->nColors = rep->nShapes = 0;
  4361. rep->nSections = rep->nDoodads = 0;
  4362. rep->nKeyAliases = 0;
  4363. rep->labelColorNdx = rep->baseColorNdx = 0;
  4364. }
  4365. return Success;
  4366. }
  4367. static int
  4368. XkbSendGeometry(ClientPtr client,
  4369. XkbGeometryPtr geom, xkbGetGeometryReply * rep, Bool freeGeom)
  4370. {
  4371. char *desc, *start;
  4372. int len;
  4373. if (geom != NULL) {
  4374. len = rep->length * 4;
  4375. start = desc = malloc(len);
  4376. if (!start)
  4377. return BadAlloc;
  4378. desc = XkbWriteCountedString(desc, geom->label_font, client->swapped);
  4379. if (rep->nProperties > 0)
  4380. desc = XkbWriteGeomProperties(desc, geom, client->swapped);
  4381. if (rep->nColors > 0)
  4382. desc = XkbWriteGeomColors(desc, geom, client->swapped);
  4383. if (rep->nShapes > 0)
  4384. desc = XkbWriteGeomShapes(desc, geom, client->swapped);
  4385. if (rep->nSections > 0)
  4386. desc = XkbWriteGeomSections(desc, geom, client->swapped);
  4387. if (rep->nDoodads > 0)
  4388. desc = XkbWriteGeomDoodads(desc, geom->num_doodads, geom->doodads,
  4389. client->swapped);
  4390. if (rep->nKeyAliases > 0)
  4391. desc = XkbWriteGeomKeyAliases(desc, geom, client->swapped);
  4392. if ((desc - start) != (len)) {
  4393. ErrorF
  4394. ("[xkb] BOGUS LENGTH in XkbSendGeometry, expected %d, got %ld\n",
  4395. len, (unsigned long) (desc - start));
  4396. }
  4397. }
  4398. else {
  4399. len = 0;
  4400. start = NULL;
  4401. }
  4402. if (client->swapped) {
  4403. swaps(&rep->sequenceNumber);
  4404. swapl(&rep->length);
  4405. swapl(&rep->name);
  4406. swaps(&rep->widthMM);
  4407. swaps(&rep->heightMM);
  4408. swaps(&rep->nProperties);
  4409. swaps(&rep->nColors);
  4410. swaps(&rep->nShapes);
  4411. swaps(&rep->nSections);
  4412. swaps(&rep->nDoodads);
  4413. swaps(&rep->nKeyAliases);
  4414. }
  4415. WriteToClient(client, SIZEOF(xkbGetGeometryReply), rep);
  4416. if (len > 0)
  4417. WriteToClient(client, len, start);
  4418. if (start != NULL)
  4419. free((char *) start);
  4420. if (freeGeom)
  4421. XkbFreeGeometry(geom, XkbGeomAllMask, TRUE);
  4422. return Success;
  4423. }
  4424. int
  4425. ProcXkbGetGeometry(ClientPtr client)
  4426. {
  4427. DeviceIntPtr dev;
  4428. xkbGetGeometryReply rep;
  4429. XkbGeometryPtr geom;
  4430. Bool shouldFree;
  4431. Status status;
  4432. REQUEST(xkbGetGeometryReq);
  4433. REQUEST_SIZE_MATCH(xkbGetGeometryReq);
  4434. if (!(client->xkbClientFlags & _XkbClientInitialized))
  4435. return BadAccess;
  4436. CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixGetAttrAccess);
  4437. CHK_ATOM_OR_NONE(stuff->name);
  4438. geom = XkbLookupNamedGeometry(dev, stuff->name, &shouldFree);
  4439. rep = (xkbGetGeometryReply) {
  4440. .type = X_Reply,
  4441. .deviceID = dev->id,
  4442. .sequenceNumber = client->sequence,
  4443. .length = 0
  4444. };
  4445. status = XkbComputeGetGeometryReplySize(geom, &rep, stuff->name);
  4446. if (status != Success)
  4447. return status;
  4448. else
  4449. return XkbSendGeometry(client, geom, &rep, shouldFree);
  4450. }
  4451. /***====================================================================***/
  4452. static Status
  4453. _GetCountedString(char **wire_inout, ClientPtr client, char **str)
  4454. {
  4455. char *wire, *next;
  4456. CARD16 len;
  4457. wire = *wire_inout;
  4458. len = *(CARD16 *) wire;
  4459. if (client->swapped) {
  4460. swaps(&len);
  4461. }
  4462. next = wire + XkbPaddedSize(len + 2);
  4463. /* Check we're still within the size of the request */
  4464. if (client->req_len <
  4465. bytes_to_int32(next - (char *) client->requestBuffer))
  4466. return BadValue;
  4467. *str = malloc(len + 1);
  4468. if (!*str)
  4469. return BadAlloc;
  4470. memcpy(*str, &wire[2], len);
  4471. *(*str + len) = '\0';
  4472. *wire_inout = next;
  4473. return Success;
  4474. }
  4475. static Status
  4476. _CheckSetDoodad(char **wire_inout,
  4477. XkbGeometryPtr geom, XkbSectionPtr section, ClientPtr client)
  4478. {
  4479. char *wire;
  4480. xkbDoodadWireDesc *dWire;
  4481. xkbAnyDoodadWireDesc any;
  4482. xkbTextDoodadWireDesc text;
  4483. XkbDoodadPtr doodad;
  4484. Status status;
  4485. dWire = (xkbDoodadWireDesc *) (*wire_inout);
  4486. any = dWire->any;
  4487. wire = (char *) &dWire[1];
  4488. if (client->swapped) {
  4489. swapl(&any.name);
  4490. swaps(&any.top);
  4491. swaps(&any.left);
  4492. swaps(&any.angle);
  4493. }
  4494. CHK_ATOM_ONLY(dWire->any.name);
  4495. doodad = XkbAddGeomDoodad(geom, section, any.name);
  4496. if (!doodad)
  4497. return BadAlloc;
  4498. doodad->any.type = dWire->any.type;
  4499. doodad->any.priority = dWire->any.priority;
  4500. doodad->any.top = any.top;
  4501. doodad->any.left = any.left;
  4502. doodad->any.angle = any.angle;
  4503. switch (doodad->any.type) {
  4504. case XkbOutlineDoodad:
  4505. case XkbSolidDoodad:
  4506. if (dWire->shape.colorNdx >= geom->num_colors) {
  4507. client->errorValue = _XkbErrCode3(0x40, geom->num_colors,
  4508. dWire->shape.colorNdx);
  4509. return BadMatch;
  4510. }
  4511. if (dWire->shape.shapeNdx >= geom->num_shapes) {
  4512. client->errorValue = _XkbErrCode3(0x41, geom->num_shapes,
  4513. dWire->shape.shapeNdx);
  4514. return BadMatch;
  4515. }
  4516. doodad->shape.color_ndx = dWire->shape.colorNdx;
  4517. doodad->shape.shape_ndx = dWire->shape.shapeNdx;
  4518. break;
  4519. case XkbTextDoodad:
  4520. if (dWire->text.colorNdx >= geom->num_colors) {
  4521. client->errorValue = _XkbErrCode3(0x42, geom->num_colors,
  4522. dWire->text.colorNdx);
  4523. return BadMatch;
  4524. }
  4525. text = dWire->text;
  4526. if (client->swapped) {
  4527. swaps(&text.width);
  4528. swaps(&text.height);
  4529. }
  4530. doodad->text.width = text.width;
  4531. doodad->text.height = text.height;
  4532. doodad->text.color_ndx = dWire->text.colorNdx;
  4533. status = _GetCountedString(&wire, client, &doodad->text.text);
  4534. if (status != Success)
  4535. return status;
  4536. status = _GetCountedString(&wire, client, &doodad->text.font);
  4537. if (status != Success) {
  4538. free (doodad->text.text);
  4539. return status;
  4540. }
  4541. break;
  4542. case XkbIndicatorDoodad:
  4543. if (dWire->indicator.onColorNdx >= geom->num_colors) {
  4544. client->errorValue = _XkbErrCode3(0x43, geom->num_colors,
  4545. dWire->indicator.onColorNdx);
  4546. return BadMatch;
  4547. }
  4548. if (dWire->indicator.offColorNdx >= geom->num_colors) {
  4549. client->errorValue = _XkbErrCode3(0x44, geom->num_colors,
  4550. dWire->indicator.offColorNdx);
  4551. return BadMatch;
  4552. }
  4553. if (dWire->indicator.shapeNdx >= geom->num_shapes) {
  4554. client->errorValue = _XkbErrCode3(0x45, geom->num_shapes,
  4555. dWire->indicator.shapeNdx);
  4556. return BadMatch;
  4557. }
  4558. doodad->indicator.shape_ndx = dWire->indicator.shapeNdx;
  4559. doodad->indicator.on_color_ndx = dWire->indicator.onColorNdx;
  4560. doodad->indicator.off_color_ndx = dWire->indicator.offColorNdx;
  4561. break;
  4562. case XkbLogoDoodad:
  4563. if (dWire->logo.colorNdx >= geom->num_colors) {
  4564. client->errorValue = _XkbErrCode3(0x46, geom->num_colors,
  4565. dWire->logo.colorNdx);
  4566. return BadMatch;
  4567. }
  4568. if (dWire->logo.shapeNdx >= geom->num_shapes) {
  4569. client->errorValue = _XkbErrCode3(0x47, geom->num_shapes,
  4570. dWire->logo.shapeNdx);
  4571. return BadMatch;
  4572. }
  4573. doodad->logo.color_ndx = dWire->logo.colorNdx;
  4574. doodad->logo.shape_ndx = dWire->logo.shapeNdx;
  4575. status = _GetCountedString(&wire, client, &doodad->logo.logo_name);
  4576. if (status != Success)
  4577. return status;
  4578. break;
  4579. default:
  4580. client->errorValue = _XkbErrCode2(0x4F, dWire->any.type);
  4581. return BadValue;
  4582. }
  4583. *wire_inout = wire;
  4584. return Success;
  4585. }
  4586. static Status
  4587. _CheckSetOverlay(char **wire_inout,
  4588. XkbGeometryPtr geom, XkbSectionPtr section, ClientPtr client)
  4589. {
  4590. register int r;
  4591. char *wire;
  4592. XkbOverlayPtr ol;
  4593. xkbOverlayWireDesc *olWire;
  4594. xkbOverlayRowWireDesc *rWire;
  4595. wire = *wire_inout;
  4596. olWire = (xkbOverlayWireDesc *) wire;
  4597. if (client->swapped) {
  4598. swapl(&olWire->name);
  4599. }
  4600. CHK_ATOM_ONLY(olWire->name);
  4601. ol = XkbAddGeomOverlay(section, olWire->name, olWire->nRows);
  4602. rWire = (xkbOverlayRowWireDesc *) &olWire[1];
  4603. for (r = 0; r < olWire->nRows; r++) {
  4604. register int k;
  4605. xkbOverlayKeyWireDesc *kWire;
  4606. XkbOverlayRowPtr row;
  4607. if (rWire->rowUnder > section->num_rows) {
  4608. client->errorValue = _XkbErrCode4(0x20, r, section->num_rows,
  4609. rWire->rowUnder);
  4610. return BadMatch;
  4611. }
  4612. row = XkbAddGeomOverlayRow(ol, rWire->rowUnder, rWire->nKeys);
  4613. kWire = (xkbOverlayKeyWireDesc *) &rWire[1];
  4614. for (k = 0; k < rWire->nKeys; k++, kWire++) {
  4615. if (XkbAddGeomOverlayKey(ol, row,
  4616. (char *) kWire->over,
  4617. (char *) kWire->under) == NULL) {
  4618. client->errorValue = _XkbErrCode3(0x21, r, k);
  4619. return BadMatch;
  4620. }
  4621. }
  4622. rWire = (xkbOverlayRowWireDesc *) kWire;
  4623. }
  4624. olWire = (xkbOverlayWireDesc *) rWire;
  4625. wire = (char *) olWire;
  4626. *wire_inout = wire;
  4627. return Success;
  4628. }
  4629. static Status
  4630. _CheckSetSections(XkbGeometryPtr geom,
  4631. xkbSetGeometryReq * req, char **wire_inout, ClientPtr client)
  4632. {
  4633. Status status;
  4634. register int s;
  4635. char *wire;
  4636. xkbSectionWireDesc *sWire;
  4637. XkbSectionPtr section;
  4638. wire = *wire_inout;
  4639. if (req->nSections < 1)
  4640. return Success;
  4641. sWire = (xkbSectionWireDesc *) wire;
  4642. for (s = 0; s < req->nSections; s++) {
  4643. register int r;
  4644. xkbRowWireDesc *rWire;
  4645. if (client->swapped) {
  4646. swapl(&sWire->name);
  4647. swaps(&sWire->top);
  4648. swaps(&sWire->left);
  4649. swaps(&sWire->width);
  4650. swaps(&sWire->height);
  4651. swaps(&sWire->angle);
  4652. }
  4653. CHK_ATOM_ONLY(sWire->name);
  4654. section = XkbAddGeomSection(geom, sWire->name, sWire->nRows,
  4655. sWire->nDoodads, sWire->nOverlays);
  4656. if (!section)
  4657. return BadAlloc;
  4658. section->priority = sWire->priority;
  4659. section->top = sWire->top;
  4660. section->left = sWire->left;
  4661. section->width = sWire->width;
  4662. section->height = sWire->height;
  4663. section->angle = sWire->angle;
  4664. rWire = (xkbRowWireDesc *) &sWire[1];
  4665. for (r = 0; r < sWire->nRows; r++) {
  4666. register int k;
  4667. XkbRowPtr row;
  4668. xkbKeyWireDesc *kWire;
  4669. if (client->swapped) {
  4670. swaps(&rWire->top);
  4671. swaps(&rWire->left);
  4672. }
  4673. row = XkbAddGeomRow(section, rWire->nKeys);
  4674. if (!row)
  4675. return BadAlloc;
  4676. row->top = rWire->top;
  4677. row->left = rWire->left;
  4678. row->vertical = rWire->vertical;
  4679. kWire = (xkbKeyWireDesc *) &rWire[1];
  4680. for (k = 0; k < rWire->nKeys; k++) {
  4681. XkbKeyPtr key;
  4682. key = XkbAddGeomKey(row);
  4683. if (!key)
  4684. return BadAlloc;
  4685. memcpy(key->name.name, kWire[k].name, XkbKeyNameLength);
  4686. key->gap = kWire[k].gap;
  4687. key->shape_ndx = kWire[k].shapeNdx;
  4688. key->color_ndx = kWire[k].colorNdx;
  4689. if (key->shape_ndx >= geom->num_shapes) {
  4690. client->errorValue = _XkbErrCode3(0x10, key->shape_ndx,
  4691. geom->num_shapes);
  4692. return BadMatch;
  4693. }
  4694. if (key->color_ndx >= geom->num_colors) {
  4695. client->errorValue = _XkbErrCode3(0x11, key->color_ndx,
  4696. geom->num_colors);
  4697. return BadMatch;
  4698. }
  4699. }
  4700. rWire = (xkbRowWireDesc *) &kWire[rWire->nKeys];
  4701. }
  4702. wire = (char *) rWire;
  4703. if (sWire->nDoodads > 0) {
  4704. register int d;
  4705. for (d = 0; d < sWire->nDoodads; d++) {
  4706. status = _CheckSetDoodad(&wire, geom, section, client);
  4707. if (status != Success)
  4708. return status;
  4709. }
  4710. }
  4711. if (sWire->nOverlays > 0) {
  4712. register int o;
  4713. for (o = 0; o < sWire->nOverlays; o++) {
  4714. status = _CheckSetOverlay(&wire, geom, section, client);
  4715. if (status != Success)
  4716. return status;
  4717. }
  4718. }
  4719. sWire = (xkbSectionWireDesc *) wire;
  4720. }
  4721. wire = (char *) sWire;
  4722. *wire_inout = wire;
  4723. return Success;
  4724. }
  4725. static Status
  4726. _CheckSetShapes(XkbGeometryPtr geom,
  4727. xkbSetGeometryReq * req, char **wire_inout, ClientPtr client)
  4728. {
  4729. register int i;
  4730. char *wire;
  4731. wire = *wire_inout;
  4732. if (req->nShapes < 1) {
  4733. client->errorValue = _XkbErrCode2(0x06, req->nShapes);
  4734. return BadValue;
  4735. }
  4736. else {
  4737. xkbShapeWireDesc *shapeWire;
  4738. XkbShapePtr shape;
  4739. register int o;
  4740. shapeWire = (xkbShapeWireDesc *) wire;
  4741. for (i = 0; i < req->nShapes; i++) {
  4742. xkbOutlineWireDesc *olWire;
  4743. XkbOutlinePtr ol;
  4744. shape =
  4745. XkbAddGeomShape(geom, shapeWire->name, shapeWire->nOutlines);
  4746. if (!shape)
  4747. return BadAlloc;
  4748. olWire = (xkbOutlineWireDesc *) (&shapeWire[1]);
  4749. for (o = 0; o < shapeWire->nOutlines; o++) {
  4750. register int p;
  4751. XkbPointPtr pt;
  4752. xkbPointWireDesc *ptWire;
  4753. ol = XkbAddGeomOutline(shape, olWire->nPoints);
  4754. if (!ol)
  4755. return BadAlloc;
  4756. ol->corner_radius = olWire->cornerRadius;
  4757. ptWire = (xkbPointWireDesc *) &olWire[1];
  4758. for (p = 0, pt = ol->points; p < olWire->nPoints; p++, pt++) {
  4759. pt->x = ptWire[p].x;
  4760. pt->y = ptWire[p].y;
  4761. if (client->swapped) {
  4762. swaps(&pt->x);
  4763. swaps(&pt->y);
  4764. }
  4765. }
  4766. ol->num_points = olWire->nPoints;
  4767. olWire = (xkbOutlineWireDesc *) (&ptWire[olWire->nPoints]);
  4768. }
  4769. if (shapeWire->primaryNdx != XkbNoShape)
  4770. shape->primary = &shape->outlines[shapeWire->primaryNdx];
  4771. if (shapeWire->approxNdx != XkbNoShape)
  4772. shape->approx = &shape->outlines[shapeWire->approxNdx];
  4773. shapeWire = (xkbShapeWireDesc *) olWire;
  4774. }
  4775. wire = (char *) shapeWire;
  4776. }
  4777. if (geom->num_shapes != req->nShapes) {
  4778. client->errorValue = _XkbErrCode3(0x07, geom->num_shapes, req->nShapes);
  4779. return BadMatch;
  4780. }
  4781. *wire_inout = wire;
  4782. return Success;
  4783. }
  4784. static Status
  4785. _CheckSetGeom(XkbGeometryPtr geom, xkbSetGeometryReq * req, ClientPtr client)
  4786. {
  4787. register int i;
  4788. Status status;
  4789. char *wire;
  4790. wire = (char *) &req[1];
  4791. status = _GetCountedString(&wire, client, &geom->label_font);
  4792. if (status != Success)
  4793. return status;
  4794. for (i = 0; i < req->nProperties; i++) {
  4795. char *name, *val;
  4796. status = _GetCountedString(&wire, client, &name);
  4797. if (status != Success)
  4798. return status;
  4799. status = _GetCountedString(&wire, client, &val);
  4800. if (status != Success) {
  4801. free(name);
  4802. return status;
  4803. }
  4804. if (XkbAddGeomProperty(geom, name, val) == NULL) {
  4805. free(name);
  4806. free(val);
  4807. return BadAlloc;
  4808. }
  4809. free(name);
  4810. free(val);
  4811. }
  4812. if (req->nColors < 2) {
  4813. client->errorValue = _XkbErrCode3(0x01, 2, req->nColors);
  4814. return BadValue;
  4815. }
  4816. if (req->baseColorNdx > req->nColors) {
  4817. client->errorValue =
  4818. _XkbErrCode3(0x03, req->nColors, req->baseColorNdx);
  4819. return BadMatch;
  4820. }
  4821. if (req->labelColorNdx > req->nColors) {
  4822. client->errorValue =
  4823. _XkbErrCode3(0x03, req->nColors, req->labelColorNdx);
  4824. return BadMatch;
  4825. }
  4826. if (req->labelColorNdx == req->baseColorNdx) {
  4827. client->errorValue = _XkbErrCode3(0x04, req->baseColorNdx,
  4828. req->labelColorNdx);
  4829. return BadMatch;
  4830. }
  4831. for (i = 0; i < req->nColors; i++) {
  4832. char *name;
  4833. status = _GetCountedString(&wire, client, &name);
  4834. if (status != Success)
  4835. return status;
  4836. if (!XkbAddGeomColor(geom, name, geom->num_colors)) {
  4837. free(name);
  4838. return BadAlloc;
  4839. }
  4840. free(name);
  4841. }
  4842. if (req->nColors != geom->num_colors) {
  4843. client->errorValue = _XkbErrCode3(0x05, req->nColors, geom->num_colors);
  4844. return BadMatch;
  4845. }
  4846. geom->label_color = &geom->colors[req->labelColorNdx];
  4847. geom->base_color = &geom->colors[req->baseColorNdx];
  4848. if ((status = _CheckSetShapes(geom, req, &wire, client)) != Success)
  4849. return status;
  4850. if ((status = _CheckSetSections(geom, req, &wire, client)) != Success)
  4851. return status;
  4852. for (i = 0; i < req->nDoodads; i++) {
  4853. status = _CheckSetDoodad(&wire, geom, NULL, client);
  4854. if (status != Success)
  4855. return status;
  4856. }
  4857. for (i = 0; i < req->nKeyAliases; i++) {
  4858. if (XkbAddGeomKeyAlias(geom, &wire[XkbKeyNameLength], wire) == NULL)
  4859. return BadAlloc;
  4860. wire += 2 * XkbKeyNameLength;
  4861. }
  4862. return Success;
  4863. }
  4864. static int
  4865. _XkbSetGeometry(ClientPtr client, DeviceIntPtr dev, xkbSetGeometryReq * stuff)
  4866. {
  4867. XkbDescPtr xkb;
  4868. Bool new_name;
  4869. xkbNewKeyboardNotify nkn;
  4870. XkbGeometryPtr geom, old;
  4871. XkbGeometrySizesRec sizes;
  4872. Status status;
  4873. xkb = dev->key->xkbInfo->desc;
  4874. old = xkb->geom;
  4875. xkb->geom = NULL;
  4876. sizes.which = XkbGeomAllMask;
  4877. sizes.num_properties = stuff->nProperties;
  4878. sizes.num_colors = stuff->nColors;
  4879. sizes.num_shapes = stuff->nShapes;
  4880. sizes.num_sections = stuff->nSections;
  4881. sizes.num_doodads = stuff->nDoodads;
  4882. sizes.num_key_aliases = stuff->nKeyAliases;
  4883. if ((status = XkbAllocGeometry(xkb, &sizes)) != Success) {
  4884. xkb->geom = old;
  4885. return status;
  4886. }
  4887. geom = xkb->geom;
  4888. geom->name = stuff->name;
  4889. geom->width_mm = stuff->widthMM;
  4890. geom->height_mm = stuff->heightMM;
  4891. if ((status = _CheckSetGeom(geom, stuff, client)) != Success) {
  4892. XkbFreeGeometry(geom, XkbGeomAllMask, TRUE);
  4893. xkb->geom = old;
  4894. return status;
  4895. }
  4896. new_name = (xkb->names->geometry != geom->name);
  4897. xkb->names->geometry = geom->name;
  4898. if (old)
  4899. XkbFreeGeometry(old, XkbGeomAllMask, TRUE);
  4900. if (new_name) {
  4901. xkbNamesNotify nn;
  4902. memset(&nn, 0, sizeof(xkbNamesNotify));
  4903. nn.changed = XkbGeometryNameMask;
  4904. XkbSendNamesNotify(dev, &nn);
  4905. }
  4906. nkn.deviceID = nkn.oldDeviceID = dev->id;
  4907. nkn.minKeyCode = nkn.oldMinKeyCode = xkb->min_key_code;
  4908. nkn.maxKeyCode = nkn.oldMaxKeyCode = xkb->max_key_code;
  4909. nkn.requestMajor = XkbReqCode;
  4910. nkn.requestMinor = X_kbSetGeometry;
  4911. nkn.changed = XkbNKN_GeometryMask;
  4912. XkbSendNewKeyboardNotify(dev, &nkn);
  4913. return Success;
  4914. }
  4915. int
  4916. ProcXkbSetGeometry(ClientPtr client)
  4917. {
  4918. DeviceIntPtr dev;
  4919. int rc;
  4920. REQUEST(xkbSetGeometryReq);
  4921. REQUEST_AT_LEAST_SIZE(xkbSetGeometryReq);
  4922. if (!(client->xkbClientFlags & _XkbClientInitialized))
  4923. return BadAccess;
  4924. CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixManageAccess);
  4925. CHK_ATOM_OR_NONE(stuff->name);
  4926. rc = _XkbSetGeometry(client, dev, stuff);
  4927. if (rc != Success)
  4928. return rc;
  4929. if (stuff->deviceSpec == XkbUseCoreKbd) {
  4930. DeviceIntPtr other;
  4931. for (other = inputInfo.devices; other; other = other->next) {
  4932. if ((other != dev) && other->key && !IsMaster(other) &&
  4933. GetMaster(other, MASTER_KEYBOARD) == dev) {
  4934. rc = XaceHook(XACE_DEVICE_ACCESS, client, other,
  4935. DixManageAccess);
  4936. if (rc == Success)
  4937. _XkbSetGeometry(client, other, stuff);
  4938. }
  4939. }
  4940. }
  4941. return Success;
  4942. }
  4943. /***====================================================================***/
  4944. int
  4945. ProcXkbPerClientFlags(ClientPtr client)
  4946. {
  4947. DeviceIntPtr dev;
  4948. xkbPerClientFlagsReply rep;
  4949. XkbInterestPtr interest;
  4950. Mask access_mode = DixGetAttrAccess | DixSetAttrAccess;
  4951. REQUEST(xkbPerClientFlagsReq);
  4952. REQUEST_SIZE_MATCH(xkbPerClientFlagsReq);
  4953. if (!(client->xkbClientFlags & _XkbClientInitialized))
  4954. return BadAccess;
  4955. CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, access_mode);
  4956. CHK_MASK_LEGAL(0x01, stuff->change, XkbPCF_AllFlagsMask);
  4957. CHK_MASK_MATCH(0x02, stuff->change, stuff->value);
  4958. interest = XkbFindClientResource((DevicePtr) dev, client);
  4959. if (stuff->change) {
  4960. client->xkbClientFlags &= ~stuff->change;
  4961. client->xkbClientFlags |= stuff->value;
  4962. }
  4963. if (stuff->change & XkbPCF_AutoResetControlsMask) {
  4964. Bool want;
  4965. want = stuff->value & XkbPCF_AutoResetControlsMask;
  4966. if (interest && !want) {
  4967. interest->autoCtrls = interest->autoCtrlValues = 0;
  4968. }
  4969. else if (want && (!interest)) {
  4970. XID id = FakeClientID(client->index);
  4971. if (!AddResource(id, RT_XKBCLIENT, dev))
  4972. return BadAlloc;
  4973. interest = XkbAddClientResource((DevicePtr) dev, client, id);
  4974. if (!interest)
  4975. return BadAlloc;
  4976. }
  4977. if (interest && want) {
  4978. register unsigned affect;
  4979. affect = stuff->ctrlsToChange;
  4980. CHK_MASK_LEGAL(0x03, affect, XkbAllBooleanCtrlsMask);
  4981. CHK_MASK_MATCH(0x04, affect, stuff->autoCtrls);
  4982. CHK_MASK_MATCH(0x05, stuff->autoCtrls, stuff->autoCtrlValues);
  4983. interest->autoCtrls &= ~affect;
  4984. interest->autoCtrlValues &= ~affect;
  4985. interest->autoCtrls |= stuff->autoCtrls & affect;
  4986. interest->autoCtrlValues |= stuff->autoCtrlValues & affect;
  4987. }
  4988. }
  4989. rep = (xkbPerClientFlagsReply) {
  4990. .type = X_Reply,
  4991. .sequenceNumber = client->sequence,
  4992. .length = 0,
  4993. .supported = XkbPCF_AllFlagsMask,
  4994. .value = client->xkbClientFlags & XkbPCF_AllFlagsMask,
  4995. .autoCtrls = interest ? interest->autoCtrls : 0,
  4996. .autoCtrlValues = interest ? interest->autoCtrlValues : 0,
  4997. };
  4998. if (client->swapped) {
  4999. swaps(&rep.sequenceNumber);
  5000. swapl(&rep.supported);
  5001. swapl(&rep.value);
  5002. swapl(&rep.autoCtrls);
  5003. swapl(&rep.autoCtrlValues);
  5004. }
  5005. WriteToClient(client, SIZEOF(xkbPerClientFlagsReply), &rep);
  5006. return Success;
  5007. }
  5008. /***====================================================================***/
  5009. /* all latin-1 alphanumerics, plus parens, minus, underscore, slash */
  5010. /* and wildcards */
  5011. static unsigned char componentSpecLegal[] = {
  5012. 0x00, 0x00, 0x00, 0x00, 0x00, 0xa7, 0xff, 0x87,
  5013. 0xfe, 0xff, 0xff, 0x87, 0xfe, 0xff, 0xff, 0x07,
  5014. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  5015. 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0x7f, 0xff
  5016. };
  5017. /* same as above but accepts percent, plus and bar too */
  5018. static unsigned char componentExprLegal[] = {
  5019. 0x00, 0x00, 0x00, 0x00, 0x20, 0xaf, 0xff, 0x87,
  5020. 0xfe, 0xff, 0xff, 0x87, 0xfe, 0xff, 0xff, 0x17,
  5021. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  5022. 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0x7f, 0xff
  5023. };
  5024. static char *
  5025. GetComponentSpec(unsigned char **pWire, Bool allowExpr, int *errRtrn)
  5026. {
  5027. int len;
  5028. register int i;
  5029. unsigned char *wire, *str, *tmp, *legal;
  5030. if (allowExpr)
  5031. legal = &componentExprLegal[0];
  5032. else
  5033. legal = &componentSpecLegal[0];
  5034. wire = *pWire;
  5035. len = (*(unsigned char *) wire++);
  5036. if (len > 0) {
  5037. str = calloc(1, len + 1);
  5038. if (str) {
  5039. tmp = str;
  5040. for (i = 0; i < len; i++) {
  5041. if (legal[(*wire) / 8] & (1 << ((*wire) % 8)))
  5042. *tmp++ = *wire++;
  5043. else
  5044. wire++;
  5045. }
  5046. if (tmp != str)
  5047. *tmp++ = '\0';
  5048. else {
  5049. free(str);
  5050. str = NULL;
  5051. }
  5052. }
  5053. else {
  5054. *errRtrn = BadAlloc;
  5055. }
  5056. }
  5057. else {
  5058. str = NULL;
  5059. }
  5060. *pWire = wire;
  5061. return (char *) str;
  5062. }
  5063. /***====================================================================***/
  5064. int
  5065. ProcXkbListComponents(ClientPtr client)
  5066. {
  5067. DeviceIntPtr dev;
  5068. xkbListComponentsReply rep;
  5069. unsigned len;
  5070. unsigned char *str;
  5071. uint8_t size;
  5072. int i;
  5073. REQUEST(xkbListComponentsReq);
  5074. REQUEST_AT_LEAST_SIZE(xkbListComponentsReq);
  5075. if (!(client->xkbClientFlags & _XkbClientInitialized))
  5076. return BadAccess;
  5077. CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixGetAttrAccess);
  5078. /* The request is followed by six Pascal strings (i.e. size in characters
  5079. * followed by a string pattern) describing what the client wants us to
  5080. * list. We don't care, but might as well check they haven't got the
  5081. * length wrong. */
  5082. str = (unsigned char *) &stuff[1];
  5083. for (i = 0; i < 6; i++) {
  5084. size = *((uint8_t *)str);
  5085. len = (str + size + 1) - ((unsigned char *) stuff);
  5086. if ((XkbPaddedSize(len) / 4) > stuff->length)
  5087. return BadLength;
  5088. str += (size + 1);
  5089. }
  5090. if ((XkbPaddedSize(len) / 4) != stuff->length)
  5091. return BadLength;
  5092. rep = (xkbListComponentsReply) {
  5093. .type = X_Reply,
  5094. .deviceID = dev->id,
  5095. .sequenceNumber = client->sequence,
  5096. .length = 0,
  5097. .nKeymaps = 0,
  5098. .nKeycodes = 0,
  5099. .nTypes = 0,
  5100. .nCompatMaps = 0,
  5101. .nSymbols = 0,
  5102. .nGeometries = 0,
  5103. .extra = 0
  5104. };
  5105. if (client->swapped) {
  5106. swaps(&rep.sequenceNumber);
  5107. swapl(&rep.length);
  5108. swaps(&rep.nKeymaps);
  5109. swaps(&rep.nKeycodes);
  5110. swaps(&rep.nTypes);
  5111. swaps(&rep.nCompatMaps);
  5112. swaps(&rep.nSymbols);
  5113. swaps(&rep.nGeometries);
  5114. swaps(&rep.extra);
  5115. }
  5116. WriteToClient(client, SIZEOF(xkbListComponentsReply), &rep);
  5117. return Success;
  5118. }
  5119. /***====================================================================***/
  5120. int
  5121. ProcXkbGetKbdByName(ClientPtr client)
  5122. {
  5123. DeviceIntPtr dev;
  5124. DeviceIntPtr tmpd;
  5125. DeviceIntPtr master;
  5126. xkbGetKbdByNameReply rep = { 0 };
  5127. xkbGetMapReply mrep = { 0 };
  5128. xkbGetCompatMapReply crep = { 0 };
  5129. xkbGetIndicatorMapReply irep = { 0 };
  5130. xkbGetNamesReply nrep = { 0 };
  5131. xkbGetGeometryReply grep = { 0 };
  5132. XkbComponentNamesRec names = { 0 };
  5133. XkbDescPtr xkb, new;
  5134. unsigned char *str;
  5135. char mapFile[PATH_MAX];
  5136. unsigned len;
  5137. unsigned fwant, fneed, reported;
  5138. int status;
  5139. Bool geom_changed;
  5140. XkbSrvLedInfoPtr old_sli;
  5141. XkbSrvLedInfoPtr sli;
  5142. Mask access_mode = DixGetAttrAccess | DixManageAccess;
  5143. REQUEST(xkbGetKbdByNameReq);
  5144. REQUEST_AT_LEAST_SIZE(xkbGetKbdByNameReq);
  5145. if (!(client->xkbClientFlags & _XkbClientInitialized))
  5146. return BadAccess;
  5147. CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, access_mode);
  5148. master = GetMaster(dev, MASTER_KEYBOARD);
  5149. xkb = dev->key->xkbInfo->desc;
  5150. status = Success;
  5151. str = (unsigned char *) &stuff[1];
  5152. if (GetComponentSpec(&str, TRUE, &status)) /* keymap, unsupported */
  5153. return BadMatch;
  5154. names.keycodes = GetComponentSpec(&str, TRUE, &status);
  5155. names.types = GetComponentSpec(&str, TRUE, &status);
  5156. names.compat = GetComponentSpec(&str, TRUE, &status);
  5157. names.symbols = GetComponentSpec(&str, TRUE, &status);
  5158. names.geometry = GetComponentSpec(&str, TRUE, &status);
  5159. if (status != Success)
  5160. return status;
  5161. len = str - ((unsigned char *) stuff);
  5162. if ((XkbPaddedSize(len) / 4) != stuff->length)
  5163. return BadLength;
  5164. CHK_MASK_LEGAL(0x01, stuff->want, XkbGBN_AllComponentsMask);
  5165. CHK_MASK_LEGAL(0x02, stuff->need, XkbGBN_AllComponentsMask);
  5166. if (stuff->load)
  5167. fwant = XkbGBN_AllComponentsMask;
  5168. else
  5169. fwant = stuff->want | stuff->need;
  5170. if ((!names.compat) &&
  5171. (fwant & (XkbGBN_CompatMapMask | XkbGBN_IndicatorMapMask))) {
  5172. names.compat = Xstrdup("%");
  5173. }
  5174. if ((!names.types) && (fwant & (XkbGBN_TypesMask))) {
  5175. names.types = Xstrdup("%");
  5176. }
  5177. if ((!names.symbols) && (fwant & XkbGBN_SymbolsMask)) {
  5178. names.symbols = Xstrdup("%");
  5179. }
  5180. geom_changed = ((names.geometry != NULL) &&
  5181. (strcmp(names.geometry, "%") != 0));
  5182. if ((!names.geometry) && (fwant & XkbGBN_GeometryMask)) {
  5183. names.geometry = Xstrdup("%");
  5184. geom_changed = FALSE;
  5185. }
  5186. memset(mapFile, 0, PATH_MAX);
  5187. rep.type = X_Reply;
  5188. rep.deviceID = dev->id;
  5189. rep.sequenceNumber = client->sequence;
  5190. rep.length = 0;
  5191. rep.minKeyCode = xkb->min_key_code;
  5192. rep.maxKeyCode = xkb->max_key_code;
  5193. rep.loaded = FALSE;
  5194. fwant =
  5195. XkbConvertGetByNameComponents(TRUE, stuff->want) | XkmVirtualModsMask;
  5196. fneed = XkbConvertGetByNameComponents(TRUE, stuff->need);
  5197. rep.reported = XkbConvertGetByNameComponents(FALSE, fwant | fneed);
  5198. if (stuff->load) {
  5199. fneed |= XkmKeymapRequired;
  5200. fwant |= XkmKeymapLegal;
  5201. }
  5202. if ((fwant | fneed) & XkmSymbolsMask) {
  5203. fneed |= XkmKeyNamesIndex | XkmTypesIndex;
  5204. fwant |= XkmIndicatorsIndex;
  5205. }
  5206. /* We pass dev in here so we can get the old names out if needed. */
  5207. rep.found = XkbDDXLoadKeymapByNames(dev, &names, fwant, fneed, &new,
  5208. mapFile, PATH_MAX);
  5209. rep.newKeyboard = FALSE;
  5210. rep.pad1 = rep.pad2 = rep.pad3 = rep.pad4 = 0;
  5211. stuff->want |= stuff->need;
  5212. if (new == NULL)
  5213. rep.reported = 0;
  5214. else {
  5215. if (stuff->load)
  5216. rep.loaded = TRUE;
  5217. if (stuff->load ||
  5218. ((rep.reported & XkbGBN_SymbolsMask) && (new->compat))) {
  5219. XkbChangesRec changes;
  5220. memset(&changes, 0, sizeof(changes));
  5221. XkbUpdateDescActions(new,
  5222. new->min_key_code, XkbNumKeys(new), &changes);
  5223. }
  5224. if (new->map == NULL)
  5225. rep.reported &= ~(XkbGBN_SymbolsMask | XkbGBN_TypesMask);
  5226. else if (rep.reported & (XkbGBN_SymbolsMask | XkbGBN_TypesMask)) {
  5227. mrep.type = X_Reply;
  5228. mrep.deviceID = dev->id;
  5229. mrep.sequenceNumber = client->sequence;
  5230. mrep.length =
  5231. ((SIZEOF(xkbGetMapReply) - SIZEOF(xGenericReply)) >> 2);
  5232. mrep.minKeyCode = new->min_key_code;
  5233. mrep.maxKeyCode = new->max_key_code;
  5234. mrep.present = 0;
  5235. mrep.totalSyms = mrep.totalActs =
  5236. mrep.totalKeyBehaviors = mrep.totalKeyExplicit =
  5237. mrep.totalModMapKeys = mrep.totalVModMapKeys = 0;
  5238. if (rep.reported & (XkbGBN_TypesMask | XkbGBN_ClientSymbolsMask)) {
  5239. mrep.present |= XkbKeyTypesMask;
  5240. mrep.firstType = 0;
  5241. mrep.nTypes = mrep.totalTypes = new->map->num_types;
  5242. }
  5243. else {
  5244. mrep.firstType = mrep.nTypes = 0;
  5245. mrep.totalTypes = 0;
  5246. }
  5247. if (rep.reported & XkbGBN_ClientSymbolsMask) {
  5248. mrep.present |= (XkbKeySymsMask | XkbModifierMapMask);
  5249. mrep.firstKeySym = mrep.firstModMapKey = new->min_key_code;
  5250. mrep.nKeySyms = mrep.nModMapKeys = XkbNumKeys(new);
  5251. }
  5252. else {
  5253. mrep.firstKeySym = mrep.firstModMapKey = 0;
  5254. mrep.nKeySyms = mrep.nModMapKeys = 0;
  5255. }
  5256. if (rep.reported & XkbGBN_ServerSymbolsMask) {
  5257. mrep.present |= XkbAllServerInfoMask;
  5258. mrep.virtualMods = ~0;
  5259. mrep.firstKeyAct = mrep.firstKeyBehavior =
  5260. mrep.firstKeyExplicit = new->min_key_code;
  5261. mrep.nKeyActs = mrep.nKeyBehaviors =
  5262. mrep.nKeyExplicit = XkbNumKeys(new);
  5263. mrep.firstVModMapKey = new->min_key_code;
  5264. mrep.nVModMapKeys = XkbNumKeys(new);
  5265. }
  5266. else {
  5267. mrep.virtualMods = 0;
  5268. mrep.firstKeyAct = mrep.firstKeyBehavior =
  5269. mrep.firstKeyExplicit = 0;
  5270. mrep.nKeyActs = mrep.nKeyBehaviors = mrep.nKeyExplicit = 0;
  5271. }
  5272. XkbComputeGetMapReplySize(new, &mrep);
  5273. rep.length += SIZEOF(xGenericReply) / 4 + mrep.length;
  5274. }
  5275. if (new->compat == NULL)
  5276. rep.reported &= ~XkbGBN_CompatMapMask;
  5277. else if (rep.reported & XkbGBN_CompatMapMask) {
  5278. crep.type = X_Reply;
  5279. crep.deviceID = dev->id;
  5280. crep.sequenceNumber = client->sequence;
  5281. crep.length = 0;
  5282. crep.groups = XkbAllGroupsMask;
  5283. crep.firstSI = 0;
  5284. crep.nSI = crep.nTotalSI = new->compat->num_si;
  5285. XkbComputeGetCompatMapReplySize(new->compat, &crep);
  5286. rep.length += SIZEOF(xGenericReply) / 4 + crep.length;
  5287. }
  5288. if (new->indicators == NULL)
  5289. rep.reported &= ~XkbGBN_IndicatorMapMask;
  5290. else if (rep.reported & XkbGBN_IndicatorMapMask) {
  5291. irep.type = X_Reply;
  5292. irep.deviceID = dev->id;
  5293. irep.sequenceNumber = client->sequence;
  5294. irep.length = 0;
  5295. irep.which = XkbAllIndicatorsMask;
  5296. XkbComputeGetIndicatorMapReplySize(new->indicators, &irep);
  5297. rep.length += SIZEOF(xGenericReply) / 4 + irep.length;
  5298. }
  5299. if (new->names == NULL)
  5300. rep.reported &= ~(XkbGBN_OtherNamesMask | XkbGBN_KeyNamesMask);
  5301. else if (rep.reported & (XkbGBN_OtherNamesMask | XkbGBN_KeyNamesMask)) {
  5302. nrep.type = X_Reply;
  5303. nrep.deviceID = dev->id;
  5304. nrep.sequenceNumber = client->sequence;
  5305. nrep.length = 0;
  5306. nrep.minKeyCode = new->min_key_code;
  5307. nrep.maxKeyCode = new->max_key_code;
  5308. if (rep.reported & XkbGBN_OtherNamesMask) {
  5309. nrep.which = XkbAllNamesMask;
  5310. if (new->map != NULL)
  5311. nrep.nTypes = new->map->num_types;
  5312. else
  5313. nrep.nTypes = 0;
  5314. nrep.nKTLevels = 0;
  5315. nrep.groupNames = XkbAllGroupsMask;
  5316. nrep.virtualMods = XkbAllVirtualModsMask;
  5317. nrep.indicators = XkbAllIndicatorsMask;
  5318. nrep.nRadioGroups = new->names->num_rg;
  5319. }
  5320. else {
  5321. nrep.which = 0;
  5322. nrep.nTypes = 0;
  5323. nrep.nKTLevels = 0;
  5324. nrep.groupNames = 0;
  5325. nrep.virtualMods = 0;
  5326. nrep.indicators = 0;
  5327. nrep.nRadioGroups = 0;
  5328. }
  5329. if (rep.reported & XkbGBN_KeyNamesMask) {
  5330. nrep.which |= XkbKeyNamesMask;
  5331. nrep.firstKey = new->min_key_code;
  5332. nrep.nKeys = XkbNumKeys(new);
  5333. nrep.nKeyAliases = new->names->num_key_aliases;
  5334. if (nrep.nKeyAliases)
  5335. nrep.which |= XkbKeyAliasesMask;
  5336. }
  5337. else {
  5338. nrep.which &= ~(XkbKeyNamesMask | XkbKeyAliasesMask);
  5339. nrep.firstKey = nrep.nKeys = 0;
  5340. nrep.nKeyAliases = 0;
  5341. }
  5342. XkbComputeGetNamesReplySize(new, &nrep);
  5343. rep.length += SIZEOF(xGenericReply) / 4 + nrep.length;
  5344. }
  5345. if (new->geom == NULL)
  5346. rep.reported &= ~XkbGBN_GeometryMask;
  5347. else if (rep.reported & XkbGBN_GeometryMask) {
  5348. grep.type = X_Reply;
  5349. grep.deviceID = dev->id;
  5350. grep.sequenceNumber = client->sequence;
  5351. grep.length = 0;
  5352. grep.found = TRUE;
  5353. grep.pad = 0;
  5354. grep.widthMM = grep.heightMM = 0;
  5355. grep.nProperties = grep.nColors = grep.nShapes = 0;
  5356. grep.nSections = grep.nDoodads = 0;
  5357. grep.baseColorNdx = grep.labelColorNdx = 0;
  5358. XkbComputeGetGeometryReplySize(new->geom, &grep, None);
  5359. rep.length += SIZEOF(xGenericReply) / 4 + grep.length;
  5360. }
  5361. }
  5362. reported = rep.reported;
  5363. if (client->swapped) {
  5364. swaps(&rep.sequenceNumber);
  5365. swapl(&rep.length);
  5366. swaps(&rep.found);
  5367. swaps(&rep.reported);
  5368. }
  5369. WriteToClient(client, SIZEOF(xkbGetKbdByNameReply), &rep);
  5370. if (reported & (XkbGBN_SymbolsMask | XkbGBN_TypesMask))
  5371. XkbSendMap(client, new, &mrep);
  5372. if (reported & XkbGBN_CompatMapMask)
  5373. XkbSendCompatMap(client, new->compat, &crep);
  5374. if (reported & XkbGBN_IndicatorMapMask)
  5375. XkbSendIndicatorMap(client, new->indicators, &irep);
  5376. if (reported & (XkbGBN_KeyNamesMask | XkbGBN_OtherNamesMask))
  5377. XkbSendNames(client, new, &nrep);
  5378. if (reported & XkbGBN_GeometryMask)
  5379. XkbSendGeometry(client, new->geom, &grep, FALSE);
  5380. if (rep.loaded) {
  5381. XkbDescPtr old_xkb;
  5382. xkbNewKeyboardNotify nkn;
  5383. old_xkb = xkb;
  5384. xkb = new;
  5385. dev->key->xkbInfo->desc = xkb;
  5386. new = old_xkb; /* so it'll get freed automatically */
  5387. XkbCopyControls(xkb, old_xkb);
  5388. nkn.deviceID = nkn.oldDeviceID = dev->id;
  5389. nkn.minKeyCode = new->min_key_code;
  5390. nkn.maxKeyCode = new->max_key_code;
  5391. nkn.oldMinKeyCode = xkb->min_key_code;
  5392. nkn.oldMaxKeyCode = xkb->max_key_code;
  5393. nkn.requestMajor = XkbReqCode;
  5394. nkn.requestMinor = X_kbGetKbdByName;
  5395. nkn.changed = XkbNKN_KeycodesMask;
  5396. if (geom_changed)
  5397. nkn.changed |= XkbNKN_GeometryMask;
  5398. XkbSendNewKeyboardNotify(dev, &nkn);
  5399. /* Update the map and LED info on the device itself, as well as
  5400. * any slaves if it's an MD, or its MD if it's an SD and was the
  5401. * last device used on that MD. */
  5402. for (tmpd = inputInfo.devices; tmpd; tmpd = tmpd->next) {
  5403. if (tmpd != dev && GetMaster(tmpd, MASTER_KEYBOARD) != dev &&
  5404. (tmpd != master || dev != master->lastSlave))
  5405. continue;
  5406. if (tmpd != dev)
  5407. XkbDeviceApplyKeymap(tmpd, xkb);
  5408. if (tmpd->kbdfeed && tmpd->kbdfeed->xkb_sli) {
  5409. old_sli = tmpd->kbdfeed->xkb_sli;
  5410. tmpd->kbdfeed->xkb_sli = NULL;
  5411. sli = XkbAllocSrvLedInfo(tmpd, tmpd->kbdfeed, NULL, 0);
  5412. if (sli) {
  5413. sli->explicitState = old_sli->explicitState;
  5414. sli->effectiveState = old_sli->effectiveState;
  5415. }
  5416. tmpd->kbdfeed->xkb_sli = sli;
  5417. XkbFreeSrvLedInfo(old_sli);
  5418. }
  5419. }
  5420. }
  5421. if ((new != NULL) && (new != xkb)) {
  5422. XkbFreeKeyboard(new, XkbAllComponentsMask, TRUE);
  5423. new = NULL;
  5424. }
  5425. XkbFreeComponentNames(&names, FALSE);
  5426. return Success;
  5427. }
  5428. /***====================================================================***/
  5429. static int
  5430. ComputeDeviceLedInfoSize(DeviceIntPtr dev,
  5431. unsigned int what, XkbSrvLedInfoPtr sli)
  5432. {
  5433. int nNames, nMaps;
  5434. register unsigned n, bit;
  5435. if (sli == NULL)
  5436. return 0;
  5437. nNames = nMaps = 0;
  5438. if ((what & XkbXI_IndicatorNamesMask) == 0)
  5439. sli->namesPresent = 0;
  5440. if ((what & XkbXI_IndicatorMapsMask) == 0)
  5441. sli->mapsPresent = 0;
  5442. for (n = 0, bit = 1; n < XkbNumIndicators; n++, bit <<= 1) {
  5443. if (sli->names && sli->names[n] != None) {
  5444. sli->namesPresent |= bit;
  5445. nNames++;
  5446. }
  5447. if (sli->maps && XkbIM_InUse(&sli->maps[n])) {
  5448. sli->mapsPresent |= bit;
  5449. nMaps++;
  5450. }
  5451. }
  5452. return (nNames * 4) + (nMaps * SIZEOF(xkbIndicatorMapWireDesc));
  5453. }
  5454. static int
  5455. CheckDeviceLedFBs(DeviceIntPtr dev,
  5456. int class,
  5457. int id, xkbGetDeviceInfoReply * rep, ClientPtr client)
  5458. {
  5459. int nFBs = 0;
  5460. int length = 0;
  5461. Bool classOk;
  5462. if (class == XkbDfltXIClass) {
  5463. if (dev->kbdfeed)
  5464. class = KbdFeedbackClass;
  5465. else if (dev->leds)
  5466. class = LedFeedbackClass;
  5467. else {
  5468. client->errorValue = _XkbErrCode2(XkbErr_BadClass, class);
  5469. return XkbKeyboardErrorCode;
  5470. }
  5471. }
  5472. classOk = FALSE;
  5473. if ((dev->kbdfeed) &&
  5474. ((class == KbdFeedbackClass) || (class == XkbAllXIClasses))) {
  5475. KbdFeedbackPtr kf;
  5476. classOk = TRUE;
  5477. for (kf = dev->kbdfeed; (kf); kf = kf->next) {
  5478. if ((id != XkbAllXIIds) && (id != XkbDfltXIId) &&
  5479. (id != kf->ctrl.id))
  5480. continue;
  5481. nFBs++;
  5482. length += SIZEOF(xkbDeviceLedsWireDesc);
  5483. if (!kf->xkb_sli)
  5484. kf->xkb_sli = XkbAllocSrvLedInfo(dev, kf, NULL, 0);
  5485. length += ComputeDeviceLedInfoSize(dev, rep->present, kf->xkb_sli);
  5486. if (id != XkbAllXIIds)
  5487. break;
  5488. }
  5489. }
  5490. if ((dev->leds) &&
  5491. ((class == LedFeedbackClass) || (class == XkbAllXIClasses))) {
  5492. LedFeedbackPtr lf;
  5493. classOk = TRUE;
  5494. for (lf = dev->leds; (lf); lf = lf->next) {
  5495. if ((id != XkbAllXIIds) && (id != XkbDfltXIId) &&
  5496. (id != lf->ctrl.id))
  5497. continue;
  5498. nFBs++;
  5499. length += SIZEOF(xkbDeviceLedsWireDesc);
  5500. if (!lf->xkb_sli)
  5501. lf->xkb_sli = XkbAllocSrvLedInfo(dev, NULL, lf, 0);
  5502. length += ComputeDeviceLedInfoSize(dev, rep->present, lf->xkb_sli);
  5503. if (id != XkbAllXIIds)
  5504. break;
  5505. }
  5506. }
  5507. if (nFBs > 0) {
  5508. rep->nDeviceLedFBs = nFBs;
  5509. rep->length += (length / 4);
  5510. return Success;
  5511. }
  5512. if (classOk)
  5513. client->errorValue = _XkbErrCode2(XkbErr_BadId, id);
  5514. else
  5515. client->errorValue = _XkbErrCode2(XkbErr_BadClass, class);
  5516. return XkbKeyboardErrorCode;
  5517. }
  5518. static int
  5519. SendDeviceLedInfo(XkbSrvLedInfoPtr sli, ClientPtr client)
  5520. {
  5521. xkbDeviceLedsWireDesc wire;
  5522. int length;
  5523. length = 0;
  5524. wire.ledClass = sli->class;
  5525. wire.ledID = sli->id;
  5526. wire.namesPresent = sli->namesPresent;
  5527. wire.mapsPresent = sli->mapsPresent;
  5528. wire.physIndicators = sli->physIndicators;
  5529. wire.state = sli->effectiveState;
  5530. if (client->swapped) {
  5531. swaps(&wire.ledClass);
  5532. swaps(&wire.ledID);
  5533. swapl(&wire.namesPresent);
  5534. swapl(&wire.mapsPresent);
  5535. swapl(&wire.physIndicators);
  5536. swapl(&wire.state);
  5537. }
  5538. WriteToClient(client, SIZEOF(xkbDeviceLedsWireDesc), &wire);
  5539. length += SIZEOF(xkbDeviceLedsWireDesc);
  5540. if (sli->namesPresent | sli->mapsPresent) {
  5541. register unsigned i, bit;
  5542. if (sli->namesPresent) {
  5543. CARD32 awire;
  5544. for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) {
  5545. if (sli->namesPresent & bit) {
  5546. awire = (CARD32) sli->names[i];
  5547. if (client->swapped) {
  5548. swapl(&awire);
  5549. }
  5550. WriteToClient(client, 4, &awire);
  5551. length += 4;
  5552. }
  5553. }
  5554. }
  5555. if (sli->mapsPresent) {
  5556. for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) {
  5557. xkbIndicatorMapWireDesc iwire;
  5558. if (sli->mapsPresent & bit) {
  5559. iwire.flags = sli->maps[i].flags;
  5560. iwire.whichGroups = sli->maps[i].which_groups;
  5561. iwire.groups = sli->maps[i].groups;
  5562. iwire.whichMods = sli->maps[i].which_mods;
  5563. iwire.mods = sli->maps[i].mods.mask;
  5564. iwire.realMods = sli->maps[i].mods.real_mods;
  5565. iwire.virtualMods = sli->maps[i].mods.vmods;
  5566. iwire.ctrls = sli->maps[i].ctrls;
  5567. if (client->swapped) {
  5568. swaps(&iwire.virtualMods);
  5569. swapl(&iwire.ctrls);
  5570. }
  5571. WriteToClient(client, SIZEOF(xkbIndicatorMapWireDesc),
  5572. &iwire);
  5573. length += SIZEOF(xkbIndicatorMapWireDesc);
  5574. }
  5575. }
  5576. }
  5577. }
  5578. return length;
  5579. }
  5580. static int
  5581. SendDeviceLedFBs(DeviceIntPtr dev,
  5582. int class, int id, unsigned wantLength, ClientPtr client)
  5583. {
  5584. int length = 0;
  5585. if (class == XkbDfltXIClass) {
  5586. if (dev->kbdfeed)
  5587. class = KbdFeedbackClass;
  5588. else if (dev->leds)
  5589. class = LedFeedbackClass;
  5590. }
  5591. if ((dev->kbdfeed) &&
  5592. ((class == KbdFeedbackClass) || (class == XkbAllXIClasses))) {
  5593. KbdFeedbackPtr kf;
  5594. for (kf = dev->kbdfeed; (kf); kf = kf->next) {
  5595. if ((id == XkbAllXIIds) || (id == XkbDfltXIId) ||
  5596. (id == kf->ctrl.id)) {
  5597. length += SendDeviceLedInfo(kf->xkb_sli, client);
  5598. if (id != XkbAllXIIds)
  5599. break;
  5600. }
  5601. }
  5602. }
  5603. if ((dev->leds) &&
  5604. ((class == LedFeedbackClass) || (class == XkbAllXIClasses))) {
  5605. LedFeedbackPtr lf;
  5606. for (lf = dev->leds; (lf); lf = lf->next) {
  5607. if ((id == XkbAllXIIds) || (id == XkbDfltXIId) ||
  5608. (id == lf->ctrl.id)) {
  5609. length += SendDeviceLedInfo(lf->xkb_sli, client);
  5610. if (id != XkbAllXIIds)
  5611. break;
  5612. }
  5613. }
  5614. }
  5615. if (length == wantLength)
  5616. return Success;
  5617. else
  5618. return BadLength;
  5619. }
  5620. int
  5621. ProcXkbGetDeviceInfo(ClientPtr client)
  5622. {
  5623. DeviceIntPtr dev;
  5624. xkbGetDeviceInfoReply rep;
  5625. int status, nDeviceLedFBs;
  5626. unsigned length, nameLen;
  5627. CARD16 ledClass, ledID;
  5628. unsigned wanted;
  5629. char *str;
  5630. REQUEST(xkbGetDeviceInfoReq);
  5631. REQUEST_SIZE_MATCH(xkbGetDeviceInfoReq);
  5632. if (!(client->xkbClientFlags & _XkbClientInitialized))
  5633. return BadAccess;
  5634. wanted = stuff->wanted;
  5635. CHK_ANY_DEVICE(dev, stuff->deviceSpec, client, DixGetAttrAccess);
  5636. CHK_MASK_LEGAL(0x01, wanted, XkbXI_AllDeviceFeaturesMask);
  5637. if ((!dev->button) || ((stuff->nBtns < 1) && (!stuff->allBtns)))
  5638. wanted &= ~XkbXI_ButtonActionsMask;
  5639. if ((!dev->kbdfeed) && (!dev->leds))
  5640. wanted &= ~XkbXI_IndicatorsMask;
  5641. nameLen = XkbSizeCountedString(dev->name);
  5642. rep = (xkbGetDeviceInfoReply) {
  5643. .type = X_Reply,
  5644. .deviceID = dev->id,
  5645. .sequenceNumber = client->sequence,
  5646. .length = nameLen / 4,
  5647. .present = wanted,
  5648. .supported = XkbXI_AllDeviceFeaturesMask,
  5649. .unsupported = 0,
  5650. .nDeviceLedFBs = 0,
  5651. .firstBtnWanted = 0,
  5652. .nBtnsWanted = 0,
  5653. .firstBtnRtrn = 0,
  5654. .nBtnsRtrn = 0,
  5655. .totalBtns = dev->button ? dev->button->numButtons : 0,
  5656. .hasOwnState = (dev->key && dev->key->xkbInfo),
  5657. .dfltKbdFB = dev->kbdfeed ? dev->kbdfeed->ctrl.id : XkbXINone,
  5658. .dfltLedFB = dev->leds ? dev->leds->ctrl.id : XkbXINone,
  5659. .devType = dev->xinput_type
  5660. };
  5661. ledClass = stuff->ledClass;
  5662. ledID = stuff->ledID;
  5663. if (wanted & XkbXI_ButtonActionsMask) {
  5664. if (stuff->allBtns) {
  5665. stuff->firstBtn = 0;
  5666. stuff->nBtns = dev->button->numButtons;
  5667. }
  5668. if ((stuff->firstBtn + stuff->nBtns) > dev->button->numButtons) {
  5669. client->errorValue = _XkbErrCode4(0x02, dev->button->numButtons,
  5670. stuff->firstBtn, stuff->nBtns);
  5671. return BadValue;
  5672. }
  5673. else {
  5674. rep.firstBtnWanted = stuff->firstBtn;
  5675. rep.nBtnsWanted = stuff->nBtns;
  5676. if (dev->button->xkb_acts != NULL) {
  5677. XkbAction *act;
  5678. register int i;
  5679. rep.firstBtnRtrn = stuff->firstBtn;
  5680. rep.nBtnsRtrn = stuff->nBtns;
  5681. act = &dev->button->xkb_acts[rep.firstBtnWanted];
  5682. for (i = 0; i < rep.nBtnsRtrn; i++, act++) {
  5683. if (act->type != XkbSA_NoAction)
  5684. break;
  5685. }
  5686. rep.firstBtnRtrn += i;
  5687. rep.nBtnsRtrn -= i;
  5688. act =
  5689. &dev->button->xkb_acts[rep.firstBtnRtrn + rep.nBtnsRtrn -
  5690. 1];
  5691. for (i = 0; i < rep.nBtnsRtrn; i++, act--) {
  5692. if (act->type != XkbSA_NoAction)
  5693. break;
  5694. }
  5695. rep.nBtnsRtrn -= i;
  5696. }
  5697. rep.length += (rep.nBtnsRtrn * SIZEOF(xkbActionWireDesc)) / 4;
  5698. }
  5699. }
  5700. if (wanted & XkbXI_IndicatorsMask) {
  5701. status = CheckDeviceLedFBs(dev, ledClass, ledID, &rep, client);
  5702. if (status != Success)
  5703. return status;
  5704. }
  5705. length = rep.length * 4;
  5706. nDeviceLedFBs = rep.nDeviceLedFBs;
  5707. if (client->swapped) {
  5708. swaps(&rep.sequenceNumber);
  5709. swapl(&rep.length);
  5710. swaps(&rep.present);
  5711. swaps(&rep.supported);
  5712. swaps(&rep.unsupported);
  5713. swaps(&rep.nDeviceLedFBs);
  5714. swaps(&rep.dfltKbdFB);
  5715. swaps(&rep.dfltLedFB);
  5716. swapl(&rep.devType);
  5717. }
  5718. WriteToClient(client, SIZEOF(xkbGetDeviceInfoReply), &rep);
  5719. str = malloc(nameLen);
  5720. if (!str)
  5721. return BadAlloc;
  5722. XkbWriteCountedString(str, dev->name, client->swapped);
  5723. WriteToClient(client, nameLen, str);
  5724. free(str);
  5725. length -= nameLen;
  5726. if (rep.nBtnsRtrn > 0) {
  5727. int sz;
  5728. xkbActionWireDesc *awire;
  5729. sz = rep.nBtnsRtrn * SIZEOF(xkbActionWireDesc);
  5730. awire = (xkbActionWireDesc *) &dev->button->xkb_acts[rep.firstBtnRtrn];
  5731. WriteToClient(client, sz, awire);
  5732. length -= sz;
  5733. }
  5734. if (nDeviceLedFBs > 0) {
  5735. status = SendDeviceLedFBs(dev, ledClass, ledID, length, client);
  5736. if (status != Success)
  5737. return status;
  5738. }
  5739. else if (length != 0) {
  5740. ErrorF("[xkb] Internal Error! BadLength in ProcXkbGetDeviceInfo\n");
  5741. ErrorF("[xkb] Wrote %d fewer bytes than expected\n",
  5742. length);
  5743. return BadLength;
  5744. }
  5745. return Success;
  5746. }
  5747. static char *
  5748. CheckSetDeviceIndicators(char *wire,
  5749. DeviceIntPtr dev,
  5750. int num, int *status_rtrn, ClientPtr client)
  5751. {
  5752. xkbDeviceLedsWireDesc *ledWire;
  5753. int i;
  5754. XkbSrvLedInfoPtr sli;
  5755. ledWire = (xkbDeviceLedsWireDesc *) wire;
  5756. for (i = 0; i < num; i++) {
  5757. if (client->swapped) {
  5758. swaps(&ledWire->ledClass);
  5759. swaps(&ledWire->ledID);
  5760. swapl(&ledWire->namesPresent);
  5761. swapl(&ledWire->mapsPresent);
  5762. swapl(&ledWire->physIndicators);
  5763. }
  5764. sli = XkbFindSrvLedInfo(dev, ledWire->ledClass, ledWire->ledID,
  5765. XkbXI_IndicatorsMask);
  5766. if (sli != NULL) {
  5767. register int n;
  5768. register unsigned bit;
  5769. int nMaps, nNames;
  5770. CARD32 *atomWire;
  5771. xkbIndicatorMapWireDesc *mapWire;
  5772. nMaps = nNames = 0;
  5773. for (n = 0, bit = 1; n < XkbNumIndicators; n++, bit <<= 1) {
  5774. if (ledWire->namesPresent & bit)
  5775. nNames++;
  5776. if (ledWire->mapsPresent & bit)
  5777. nMaps++;
  5778. }
  5779. atomWire = (CARD32 *) &ledWire[1];
  5780. if (nNames > 0) {
  5781. for (n = 0; n < nNames; n++) {
  5782. if (client->swapped) {
  5783. swapl(atomWire);
  5784. }
  5785. CHK_ATOM_OR_NONE3(((Atom) (*atomWire)), client->errorValue,
  5786. *status_rtrn, NULL);
  5787. atomWire++;
  5788. }
  5789. }
  5790. mapWire = (xkbIndicatorMapWireDesc *) atomWire;
  5791. if (nMaps > 0) {
  5792. for (n = 0; n < nMaps; n++) {
  5793. if (client->swapped) {
  5794. swaps(&mapWire->virtualMods);
  5795. swapl(&mapWire->ctrls);
  5796. }
  5797. CHK_MASK_LEGAL3(0x21, mapWire->whichGroups,
  5798. XkbIM_UseAnyGroup,
  5799. client->errorValue, *status_rtrn, NULL);
  5800. CHK_MASK_LEGAL3(0x22, mapWire->whichMods, XkbIM_UseAnyMods,
  5801. client->errorValue, *status_rtrn, NULL);
  5802. mapWire++;
  5803. }
  5804. }
  5805. ledWire = (xkbDeviceLedsWireDesc *) mapWire;
  5806. }
  5807. else {
  5808. /* SHOULD NEVER HAPPEN */
  5809. return (char *) ledWire;
  5810. }
  5811. }
  5812. return (char *) ledWire;
  5813. }
  5814. static char *
  5815. SetDeviceIndicators(char *wire,
  5816. DeviceIntPtr dev,
  5817. unsigned changed,
  5818. int num,
  5819. int *status_rtrn,
  5820. ClientPtr client, xkbExtensionDeviceNotify * ev)
  5821. {
  5822. xkbDeviceLedsWireDesc *ledWire;
  5823. int i;
  5824. XkbEventCauseRec cause;
  5825. unsigned namec, mapc, statec;
  5826. xkbExtensionDeviceNotify ed;
  5827. XkbChangesRec changes;
  5828. DeviceIntPtr kbd;
  5829. memset((char *) &ed, 0, sizeof(xkbExtensionDeviceNotify));
  5830. memset((char *) &changes, 0, sizeof(XkbChangesRec));
  5831. XkbSetCauseXkbReq(&cause, X_kbSetDeviceInfo, client);
  5832. ledWire = (xkbDeviceLedsWireDesc *) wire;
  5833. for (i = 0; i < num; i++) {
  5834. register int n;
  5835. register unsigned bit;
  5836. CARD32 *atomWire;
  5837. xkbIndicatorMapWireDesc *mapWire;
  5838. XkbSrvLedInfoPtr sli;
  5839. namec = mapc = statec = 0;
  5840. sli = XkbFindSrvLedInfo(dev, ledWire->ledClass, ledWire->ledID,
  5841. XkbXI_IndicatorMapsMask);
  5842. if (!sli) {
  5843. /* SHOULD NEVER HAPPEN!! */
  5844. return (char *) ledWire;
  5845. }
  5846. atomWire = (CARD32 *) &ledWire[1];
  5847. if (changed & XkbXI_IndicatorNamesMask) {
  5848. namec = sli->namesPresent | ledWire->namesPresent;
  5849. memset((char *) sli->names, 0, XkbNumIndicators * sizeof(Atom));
  5850. }
  5851. if (ledWire->namesPresent) {
  5852. sli->namesPresent = ledWire->namesPresent;
  5853. memset((char *) sli->names, 0, XkbNumIndicators * sizeof(Atom));
  5854. for (n = 0, bit = 1; n < XkbNumIndicators; n++, bit <<= 1) {
  5855. if (ledWire->namesPresent & bit) {
  5856. sli->names[n] = (Atom) *atomWire;
  5857. if (sli->names[n] == None)
  5858. ledWire->namesPresent &= ~bit;
  5859. atomWire++;
  5860. }
  5861. }
  5862. }
  5863. mapWire = (xkbIndicatorMapWireDesc *) atomWire;
  5864. if (changed & XkbXI_IndicatorMapsMask) {
  5865. mapc = sli->mapsPresent | ledWire->mapsPresent;
  5866. sli->mapsPresent = ledWire->mapsPresent;
  5867. memset((char *) sli->maps, 0,
  5868. XkbNumIndicators * sizeof(XkbIndicatorMapRec));
  5869. }
  5870. if (ledWire->mapsPresent) {
  5871. for (n = 0, bit = 1; n < XkbNumIndicators; n++, bit <<= 1) {
  5872. if (ledWire->mapsPresent & bit) {
  5873. sli->maps[n].flags = mapWire->flags;
  5874. sli->maps[n].which_groups = mapWire->whichGroups;
  5875. sli->maps[n].groups = mapWire->groups;
  5876. sli->maps[n].which_mods = mapWire->whichMods;
  5877. sli->maps[n].mods.mask = mapWire->mods;
  5878. sli->maps[n].mods.real_mods = mapWire->realMods;
  5879. sli->maps[n].mods.vmods = mapWire->virtualMods;
  5880. sli->maps[n].ctrls = mapWire->ctrls;
  5881. mapWire++;
  5882. }
  5883. }
  5884. }
  5885. if (changed & XkbXI_IndicatorStateMask) {
  5886. statec = sli->effectiveState ^ ledWire->state;
  5887. sli->explicitState &= ~statec;
  5888. sli->explicitState |= (ledWire->state & statec);
  5889. }
  5890. if (namec)
  5891. XkbApplyLedNameChanges(dev, sli, namec, &ed, &changes, &cause);
  5892. if (mapc)
  5893. XkbApplyLedMapChanges(dev, sli, mapc, &ed, &changes, &cause);
  5894. if (statec)
  5895. XkbApplyLedStateChanges(dev, sli, statec, &ed, &changes, &cause);
  5896. kbd = dev;
  5897. if ((sli->flags & XkbSLI_HasOwnState) == 0)
  5898. kbd = inputInfo.keyboard;
  5899. XkbFlushLedEvents(dev, kbd, sli, &ed, &changes, &cause);
  5900. ledWire = (xkbDeviceLedsWireDesc *) mapWire;
  5901. }
  5902. return (char *) ledWire;
  5903. }
  5904. static int
  5905. _XkbSetDeviceInfo(ClientPtr client, DeviceIntPtr dev,
  5906. xkbSetDeviceInfoReq * stuff)
  5907. {
  5908. char *wire;
  5909. wire = (char *) &stuff[1];
  5910. if (stuff->change & XkbXI_ButtonActionsMask) {
  5911. if (!dev->button) {
  5912. client->errorValue = _XkbErrCode2(XkbErr_BadClass, ButtonClass);
  5913. return XkbKeyboardErrorCode;
  5914. }
  5915. if ((stuff->firstBtn + stuff->nBtns) > dev->button->numButtons) {
  5916. client->errorValue =
  5917. _XkbErrCode4(0x02, stuff->firstBtn, stuff->nBtns,
  5918. dev->button->numButtons);
  5919. return BadMatch;
  5920. }
  5921. wire += (stuff->nBtns * SIZEOF(xkbActionWireDesc));
  5922. }
  5923. if (stuff->change & XkbXI_IndicatorsMask) {
  5924. int status = Success;
  5925. wire = CheckSetDeviceIndicators(wire, dev, stuff->nDeviceLedFBs,
  5926. &status, client);
  5927. if (status != Success)
  5928. return status;
  5929. }
  5930. if (((wire - ((char *) stuff)) / 4) != stuff->length)
  5931. return BadLength;
  5932. return Success;
  5933. }
  5934. static int
  5935. _XkbSetDeviceInfoCheck(ClientPtr client, DeviceIntPtr dev,
  5936. xkbSetDeviceInfoReq * stuff)
  5937. {
  5938. char *wire;
  5939. xkbExtensionDeviceNotify ed;
  5940. memset((char *) &ed, 0, SIZEOF(xkbExtensionDeviceNotify));
  5941. ed.deviceID = dev->id;
  5942. wire = (char *) &stuff[1];
  5943. if (stuff->change & XkbXI_ButtonActionsMask) {
  5944. int nBtns, sz, i;
  5945. XkbAction *acts;
  5946. DeviceIntPtr kbd;
  5947. nBtns = dev->button->numButtons;
  5948. acts = dev->button->xkb_acts;
  5949. if (acts == NULL) {
  5950. acts = calloc(nBtns, sizeof(XkbAction));
  5951. if (!acts)
  5952. return BadAlloc;
  5953. dev->button->xkb_acts = acts;
  5954. }
  5955. sz = stuff->nBtns * SIZEOF(xkbActionWireDesc);
  5956. memcpy((char *) &acts[stuff->firstBtn], (char *) wire, sz);
  5957. wire += sz;
  5958. ed.reason |= XkbXI_ButtonActionsMask;
  5959. ed.firstBtn = stuff->firstBtn;
  5960. ed.nBtns = stuff->nBtns;
  5961. if (dev->key)
  5962. kbd = dev;
  5963. else
  5964. kbd = inputInfo.keyboard;
  5965. acts = &dev->button->xkb_acts[stuff->firstBtn];
  5966. for (i = 0; i < stuff->nBtns; i++, acts++) {
  5967. if (acts->type != XkbSA_NoAction)
  5968. XkbSetActionKeyMods(kbd->key->xkbInfo->desc, acts, 0);
  5969. }
  5970. }
  5971. if (stuff->change & XkbXI_IndicatorsMask) {
  5972. int status = Success;
  5973. wire = SetDeviceIndicators(wire, dev, stuff->change,
  5974. stuff->nDeviceLedFBs, &status, client, &ed);
  5975. if (status != Success)
  5976. return status;
  5977. }
  5978. if ((stuff->change) && (ed.reason))
  5979. XkbSendExtensionDeviceNotify(dev, client, &ed);
  5980. return Success;
  5981. }
  5982. int
  5983. ProcXkbSetDeviceInfo(ClientPtr client)
  5984. {
  5985. DeviceIntPtr dev;
  5986. int rc;
  5987. REQUEST(xkbSetDeviceInfoReq);
  5988. REQUEST_AT_LEAST_SIZE(xkbSetDeviceInfoReq);
  5989. if (!(client->xkbClientFlags & _XkbClientInitialized))
  5990. return BadAccess;
  5991. CHK_ANY_DEVICE(dev, stuff->deviceSpec, client, DixManageAccess);
  5992. CHK_MASK_LEGAL(0x01, stuff->change, XkbXI_AllFeaturesMask);
  5993. rc = _XkbSetDeviceInfoCheck(client, dev, stuff);
  5994. if (rc != Success)
  5995. return rc;
  5996. if (stuff->deviceSpec == XkbUseCoreKbd ||
  5997. stuff->deviceSpec == XkbUseCorePtr) {
  5998. DeviceIntPtr other;
  5999. for (other = inputInfo.devices; other; other = other->next) {
  6000. if (((other != dev) && !IsMaster(other) &&
  6001. GetMaster(other, MASTER_KEYBOARD) == dev) &&
  6002. ((stuff->deviceSpec == XkbUseCoreKbd && other->key) ||
  6003. (stuff->deviceSpec == XkbUseCorePtr && other->button))) {
  6004. rc = XaceHook(XACE_DEVICE_ACCESS, client, other,
  6005. DixManageAccess);
  6006. if (rc == Success) {
  6007. rc = _XkbSetDeviceInfoCheck(client, other, stuff);
  6008. if (rc != Success)
  6009. return rc;
  6010. }
  6011. }
  6012. }
  6013. }
  6014. /* checks done, apply */
  6015. rc = _XkbSetDeviceInfo(client, dev, stuff);
  6016. if (rc != Success)
  6017. return rc;
  6018. if (stuff->deviceSpec == XkbUseCoreKbd ||
  6019. stuff->deviceSpec == XkbUseCorePtr) {
  6020. DeviceIntPtr other;
  6021. for (other = inputInfo.devices; other; other = other->next) {
  6022. if (((other != dev) && !IsMaster(other) &&
  6023. GetMaster(other, MASTER_KEYBOARD) == dev) &&
  6024. ((stuff->deviceSpec == XkbUseCoreKbd && other->key) ||
  6025. (stuff->deviceSpec == XkbUseCorePtr && other->button))) {
  6026. rc = XaceHook(XACE_DEVICE_ACCESS, client, other,
  6027. DixManageAccess);
  6028. if (rc == Success) {
  6029. rc = _XkbSetDeviceInfo(client, other, stuff);
  6030. if (rc != Success)
  6031. return rc;
  6032. }
  6033. }
  6034. }
  6035. }
  6036. return Success;
  6037. }
  6038. /***====================================================================***/
  6039. int
  6040. ProcXkbSetDebuggingFlags(ClientPtr client)
  6041. {
  6042. CARD32 newFlags, newCtrls, extraLength;
  6043. xkbSetDebuggingFlagsReply rep;
  6044. int rc;
  6045. REQUEST(xkbSetDebuggingFlagsReq);
  6046. REQUEST_AT_LEAST_SIZE(xkbSetDebuggingFlagsReq);
  6047. rc = XaceHook(XACE_SERVER_ACCESS, client, DixDebugAccess);
  6048. if (rc != Success)
  6049. return rc;
  6050. newFlags = xkbDebugFlags & (~stuff->affectFlags);
  6051. newFlags |= (stuff->flags & stuff->affectFlags);
  6052. newCtrls = xkbDebugCtrls & (~stuff->affectCtrls);
  6053. newCtrls |= (stuff->ctrls & stuff->affectCtrls);
  6054. if (xkbDebugFlags || newFlags || stuff->msgLength) {
  6055. ErrorF("[xkb] XkbDebug: Setting debug flags to 0x%lx\n",
  6056. (long) newFlags);
  6057. if (newCtrls != xkbDebugCtrls)
  6058. ErrorF("[xkb] XkbDebug: Setting debug controls to 0x%lx\n",
  6059. (long) newCtrls);
  6060. }
  6061. extraLength = (stuff->length << 2) - sz_xkbSetDebuggingFlagsReq;
  6062. if (stuff->msgLength > 0) {
  6063. char *msg;
  6064. if (extraLength < XkbPaddedSize(stuff->msgLength)) {
  6065. ErrorF
  6066. ("[xkb] XkbDebug: msgLength= %d, length= %ld (should be %d)\n",
  6067. stuff->msgLength, (long) extraLength,
  6068. XkbPaddedSize(stuff->msgLength));
  6069. return BadLength;
  6070. }
  6071. msg = (char *) &stuff[1];
  6072. if (msg[stuff->msgLength - 1] != '\0') {
  6073. ErrorF("[xkb] XkbDebug: message not null-terminated\n");
  6074. return BadValue;
  6075. }
  6076. ErrorF("[xkb] XkbDebug: %s\n", msg);
  6077. }
  6078. xkbDebugFlags = newFlags;
  6079. xkbDebugCtrls = newCtrls;
  6080. rep = (xkbSetDebuggingFlagsReply) {
  6081. .type = X_Reply,
  6082. .sequenceNumber = client->sequence,
  6083. .length = 0,
  6084. .currentFlags = newFlags,
  6085. .currentCtrls = newCtrls,
  6086. .supportedFlags = ~0,
  6087. .supportedCtrls = ~0
  6088. };
  6089. if (client->swapped) {
  6090. swaps(&rep.sequenceNumber);
  6091. swapl(&rep.currentFlags);
  6092. swapl(&rep.currentCtrls);
  6093. swapl(&rep.supportedFlags);
  6094. swapl(&rep.supportedCtrls);
  6095. }
  6096. WriteToClient(client, SIZEOF(xkbSetDebuggingFlagsReply), &rep);
  6097. return Success;
  6098. }
  6099. /***====================================================================***/
  6100. static int
  6101. ProcXkbDispatch(ClientPtr client)
  6102. {
  6103. REQUEST(xReq);
  6104. switch (stuff->data) {
  6105. case X_kbUseExtension:
  6106. return ProcXkbUseExtension(client);
  6107. case X_kbSelectEvents:
  6108. return ProcXkbSelectEvents(client);
  6109. case X_kbBell:
  6110. return ProcXkbBell(client);
  6111. case X_kbGetState:
  6112. return ProcXkbGetState(client);
  6113. case X_kbLatchLockState:
  6114. return ProcXkbLatchLockState(client);
  6115. case X_kbGetControls:
  6116. return ProcXkbGetControls(client);
  6117. case X_kbSetControls:
  6118. return ProcXkbSetControls(client);
  6119. case X_kbGetMap:
  6120. return ProcXkbGetMap(client);
  6121. case X_kbSetMap:
  6122. return ProcXkbSetMap(client);
  6123. case X_kbGetCompatMap:
  6124. return ProcXkbGetCompatMap(client);
  6125. case X_kbSetCompatMap:
  6126. return ProcXkbSetCompatMap(client);
  6127. case X_kbGetIndicatorState:
  6128. return ProcXkbGetIndicatorState(client);
  6129. case X_kbGetIndicatorMap:
  6130. return ProcXkbGetIndicatorMap(client);
  6131. case X_kbSetIndicatorMap:
  6132. return ProcXkbSetIndicatorMap(client);
  6133. case X_kbGetNamedIndicator:
  6134. return ProcXkbGetNamedIndicator(client);
  6135. case X_kbSetNamedIndicator:
  6136. return ProcXkbSetNamedIndicator(client);
  6137. case X_kbGetNames:
  6138. return ProcXkbGetNames(client);
  6139. case X_kbSetNames:
  6140. return ProcXkbSetNames(client);
  6141. case X_kbGetGeometry:
  6142. return ProcXkbGetGeometry(client);
  6143. case X_kbSetGeometry:
  6144. return ProcXkbSetGeometry(client);
  6145. case X_kbPerClientFlags:
  6146. return ProcXkbPerClientFlags(client);
  6147. case X_kbListComponents:
  6148. return ProcXkbListComponents(client);
  6149. case X_kbGetKbdByName:
  6150. return ProcXkbGetKbdByName(client);
  6151. case X_kbGetDeviceInfo:
  6152. return ProcXkbGetDeviceInfo(client);
  6153. case X_kbSetDeviceInfo:
  6154. return ProcXkbSetDeviceInfo(client);
  6155. case X_kbSetDebuggingFlags:
  6156. return ProcXkbSetDebuggingFlags(client);
  6157. default:
  6158. return BadRequest;
  6159. }
  6160. }
  6161. static int
  6162. XkbClientGone(void *data, XID id)
  6163. {
  6164. DevicePtr pXDev = (DevicePtr) data;
  6165. if (!XkbRemoveResourceClient(pXDev, id)) {
  6166. ErrorF
  6167. ("[xkb] Internal Error! bad RemoveResourceClient in XkbClientGone\n");
  6168. }
  6169. return 1;
  6170. }
  6171. void
  6172. XkbExtensionInit(void)
  6173. {
  6174. ExtensionEntry *extEntry;
  6175. RT_XKBCLIENT = CreateNewResourceType(XkbClientGone, "XkbClient");
  6176. if (!RT_XKBCLIENT)
  6177. return;
  6178. if (!XkbInitPrivates())
  6179. return;
  6180. if ((extEntry = AddExtension(XkbName, XkbNumberEvents, XkbNumberErrors,
  6181. ProcXkbDispatch, SProcXkbDispatch,
  6182. NULL, StandardMinorOpcode))) {
  6183. XkbReqCode = (unsigned char) extEntry->base;
  6184. XkbEventBase = (unsigned char) extEntry->eventBase;
  6185. XkbErrorBase = (unsigned char) extEntry->errorBase;
  6186. XkbKeyboardErrorCode = XkbErrorBase + XkbKeyboard;
  6187. }
  6188. return;
  6189. }