xkbout.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926
  1. /************************************************************
  2. Copyright (c) 1994 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 <ctype.h>
  28. #include <stdlib.h>
  29. #include <X11/Xfuncs.h>
  30. #include <X11/X.h>
  31. #include <X11/keysym.h>
  32. #include <X11/Xproto.h>
  33. #include <X11/extensions/XKMformat.h>
  34. #include "misc.h"
  35. #include "inputstr.h"
  36. #include "dix.h"
  37. #include "xkbstr.h"
  38. #define XKBSRV_NEED_FILE_FUNCS 1
  39. #include <xkbsrv.h>
  40. #include "xkbgeom.h"
  41. #include "xkbfile.h"
  42. #define VMOD_HIDE_VALUE 0
  43. #define VMOD_SHOW_VALUE 1
  44. #define VMOD_COMMENT_VALUE 2
  45. static Bool
  46. WriteXKBVModDecl(FILE * file, XkbDescPtr xkb, int showValue)
  47. {
  48. register int i, nMods;
  49. Atom *vmodNames;
  50. if (xkb == NULL)
  51. return FALSE;
  52. if (xkb->names != NULL)
  53. vmodNames = xkb->names->vmods;
  54. else
  55. vmodNames = NULL;
  56. for (i = nMods = 0; i < XkbNumVirtualMods; i++) {
  57. if ((vmodNames != NULL) && (vmodNames[i] != None)) {
  58. if (nMods == 0)
  59. fprintf(file, " virtual_modifiers ");
  60. else
  61. fprintf(file, ",");
  62. fprintf(file, "%s", XkbAtomText(vmodNames[i], XkbXKBFile));
  63. if ((showValue != VMOD_HIDE_VALUE) &&
  64. (xkb->server) && (xkb->server->vmods[i] != XkbNoModifierMask)) {
  65. if (showValue == VMOD_COMMENT_VALUE) {
  66. fprintf(file, "/* = %s */",
  67. XkbModMaskText(xkb->server->vmods[i], XkbXKBFile));
  68. }
  69. else {
  70. fprintf(file, "= %s",
  71. XkbModMaskText(xkb->server->vmods[i], XkbXKBFile));
  72. }
  73. }
  74. nMods++;
  75. }
  76. }
  77. if (nMods > 0)
  78. fprintf(file, ";\n\n");
  79. return TRUE;
  80. }
  81. /***====================================================================***/
  82. static Bool
  83. WriteXKBAction(FILE * file, XkbDescPtr xkb, XkbAnyAction * action)
  84. {
  85. fprintf(file, "%s", XkbActionText(xkb, (XkbAction *) action, XkbXKBFile));
  86. return TRUE;
  87. }
  88. /***====================================================================***/
  89. Bool
  90. XkbWriteXKBKeycodes(FILE * file,
  91. XkbDescPtr xkb,
  92. Bool topLevel,
  93. Bool showImplicit, XkbFileAddOnFunc addOn, void *priv)
  94. {
  95. Atom kcName;
  96. register unsigned i;
  97. const char *alternate;
  98. if ((!xkb) || (!xkb->names) || (!xkb->names->keys)) {
  99. _XkbLibError(_XkbErrMissingNames, "XkbWriteXKBKeycodes", 0);
  100. return FALSE;
  101. }
  102. kcName = xkb->names->keycodes;
  103. if (kcName != None)
  104. fprintf(file, "xkb_keycodes \"%s\" {\n",
  105. XkbAtomText(kcName, XkbXKBFile));
  106. else
  107. fprintf(file, "xkb_keycodes {\n");
  108. fprintf(file, " minimum = %d;\n", xkb->min_key_code);
  109. fprintf(file, " maximum = %d;\n", xkb->max_key_code);
  110. for (i = xkb->min_key_code; i <= xkb->max_key_code; i++) {
  111. if (xkb->names->keys[i].name[0] != '\0') {
  112. if (XkbFindKeycodeByName(xkb, xkb->names->keys[i].name, TRUE) != i)
  113. alternate = "alternate ";
  114. else
  115. alternate = "";
  116. fprintf(file, " %s%6s = %d;\n", alternate,
  117. XkbKeyNameText(xkb->names->keys[i].name, XkbXKBFile), i);
  118. }
  119. }
  120. if (xkb->indicators != NULL) {
  121. for (i = 0; i < XkbNumIndicators; i++) {
  122. const char *type;
  123. if (xkb->indicators->phys_indicators & (1 << i))
  124. type = " ";
  125. else
  126. type = " virtual ";
  127. if (xkb->names->indicators[i] != None) {
  128. fprintf(file, "%sindicator %d = \"%s\";\n", type, i + 1,
  129. XkbAtomText(xkb->names->indicators[i], XkbXKBFile));
  130. }
  131. }
  132. }
  133. if (xkb->names->key_aliases != NULL) {
  134. XkbKeyAliasPtr pAl;
  135. pAl = xkb->names->key_aliases;
  136. for (i = 0; i < xkb->names->num_key_aliases; i++, pAl++) {
  137. fprintf(file, " alias %6s = %6s;\n",
  138. XkbKeyNameText(pAl->alias, XkbXKBFile),
  139. XkbKeyNameText(pAl->real, XkbXKBFile));
  140. }
  141. }
  142. if (addOn)
  143. (*addOn) (file, xkb, topLevel, showImplicit, XkmKeyNamesIndex, priv);
  144. fprintf(file, "};\n\n");
  145. return TRUE;
  146. }
  147. Bool
  148. XkbWriteXKBKeyTypes(FILE * file,
  149. XkbDescPtr xkb,
  150. Bool topLevel,
  151. Bool showImplicit, XkbFileAddOnFunc addOn, void *priv)
  152. {
  153. register unsigned i, n;
  154. XkbKeyTypePtr type;
  155. XkbKTMapEntryPtr entry;
  156. if ((!xkb) || (!xkb->map) || (!xkb->map->types)) {
  157. _XkbLibError(_XkbErrMissingTypes, "XkbWriteXKBKeyTypes", 0);
  158. return FALSE;
  159. }
  160. if (xkb->map->num_types < XkbNumRequiredTypes) {
  161. _XkbLibError(_XkbErrMissingReqTypes, "XkbWriteXKBKeyTypes", 0);
  162. return 0;
  163. }
  164. if ((xkb->names == NULL) || (xkb->names->types == None))
  165. fprintf(file, "xkb_types {\n\n");
  166. else
  167. fprintf(file, "xkb_types \"%s\" {\n\n",
  168. XkbAtomText(xkb->names->types, XkbXKBFile));
  169. WriteXKBVModDecl(file, xkb,
  170. (showImplicit ? VMOD_COMMENT_VALUE : VMOD_HIDE_VALUE));
  171. type = xkb->map->types;
  172. for (i = 0; i < xkb->map->num_types; i++, type++) {
  173. fprintf(file, " type \"%s\" {\n",
  174. XkbAtomText(type->name, XkbXKBFile));
  175. fprintf(file, " modifiers= %s;\n",
  176. XkbVModMaskText(xkb, type->mods.real_mods, type->mods.vmods,
  177. XkbXKBFile));
  178. entry = type->map;
  179. for (n = 0; n < type->map_count; n++, entry++) {
  180. char *str;
  181. str = XkbVModMaskText(xkb, entry->mods.real_mods, entry->mods.vmods,
  182. XkbXKBFile);
  183. fprintf(file, " map[%s]= Level%d;\n", str, entry->level + 1);
  184. if ((type->preserve) && ((type->preserve[n].real_mods) ||
  185. (type->preserve[n].vmods))) {
  186. fprintf(file, " preserve[%s]= ", str);
  187. fprintf(file, "%s;\n", XkbVModMaskText(xkb,
  188. type->preserve[n].
  189. real_mods,
  190. type->preserve[n].vmods,
  191. XkbXKBFile));
  192. }
  193. }
  194. if (type->level_names != NULL) {
  195. Atom *name = type->level_names;
  196. for (n = 0; n < type->num_levels; n++, name++) {
  197. if ((*name) == None)
  198. continue;
  199. fprintf(file, " level_name[Level%d]= \"%s\";\n", n + 1,
  200. XkbAtomText(*name, XkbXKBFile));
  201. }
  202. }
  203. fprintf(file, " };\n");
  204. }
  205. if (addOn)
  206. (*addOn) (file, xkb, topLevel, showImplicit, XkmTypesIndex, priv);
  207. fprintf(file, "};\n\n");
  208. return TRUE;
  209. }
  210. static Bool
  211. WriteXKBIndicatorMap(FILE * file,
  212. XkbDescPtr xkb,
  213. Atom name,
  214. XkbIndicatorMapPtr led, XkbFileAddOnFunc addOn, void *priv)
  215. {
  216. fprintf(file, " indicator \"%s\" {\n", NameForAtom(name));
  217. if (led->flags & XkbIM_NoExplicit)
  218. fprintf(file, " !allowExplicit;\n");
  219. if (led->flags & XkbIM_LEDDrivesKB)
  220. fprintf(file, " indicatorDrivesKeyboard;\n");
  221. if (led->which_groups != 0) {
  222. if (led->which_groups != XkbIM_UseEffective) {
  223. fprintf(file, " whichGroupState= %s;\n",
  224. XkbIMWhichStateMaskText(led->which_groups, XkbXKBFile));
  225. }
  226. fprintf(file, " groups= 0x%02x;\n", led->groups);
  227. }
  228. if (led->which_mods != 0) {
  229. if (led->which_mods != XkbIM_UseEffective) {
  230. fprintf(file, " whichModState= %s;\n",
  231. XkbIMWhichStateMaskText(led->which_mods, XkbXKBFile));
  232. }
  233. fprintf(file, " modifiers= %s;\n",
  234. XkbVModMaskText(xkb,
  235. led->mods.real_mods, led->mods.vmods,
  236. XkbXKBFile));
  237. }
  238. if (led->ctrls != 0) {
  239. fprintf(file, " controls= %s;\n",
  240. XkbControlsMaskText(led->ctrls, XkbXKBFile));
  241. }
  242. if (addOn)
  243. (*addOn) (file, xkb, FALSE, TRUE, XkmIndicatorsIndex, priv);
  244. fprintf(file, " };\n");
  245. return TRUE;
  246. }
  247. Bool
  248. XkbWriteXKBCompatMap(FILE * file,
  249. XkbDescPtr xkb,
  250. Bool topLevel,
  251. Bool showImplicit, XkbFileAddOnFunc addOn, void *priv)
  252. {
  253. register unsigned i;
  254. XkbSymInterpretPtr interp;
  255. if ((!xkb) || (!xkb->compat) || (!xkb->compat->sym_interpret)) {
  256. _XkbLibError(_XkbErrMissingCompatMap, "XkbWriteXKBCompatMap", 0);
  257. return FALSE;
  258. }
  259. if ((xkb->names == NULL) || (xkb->names->compat == None))
  260. fprintf(file, "xkb_compatibility {\n\n");
  261. else
  262. fprintf(file, "xkb_compatibility \"%s\" {\n\n",
  263. XkbAtomText(xkb->names->compat, XkbXKBFile));
  264. WriteXKBVModDecl(file, xkb,
  265. (showImplicit ? VMOD_COMMENT_VALUE : VMOD_HIDE_VALUE));
  266. fprintf(file, " interpret.useModMapMods= AnyLevel;\n");
  267. fprintf(file, " interpret.repeat= FALSE;\n");
  268. fprintf(file, " interpret.locking= FALSE;\n");
  269. interp = xkb->compat->sym_interpret;
  270. for (i = 0; i < xkb->compat->num_si; i++, interp++) {
  271. fprintf(file, " interpret %s+%s(%s) {\n",
  272. ((interp->sym == NoSymbol) ? "Any" :
  273. XkbKeysymText(interp->sym, XkbXKBFile)),
  274. XkbSIMatchText(interp->match, XkbXKBFile),
  275. XkbModMaskText(interp->mods, XkbXKBFile));
  276. if (interp->virtual_mod != XkbNoModifier) {
  277. fprintf(file, " virtualModifier= %s;\n",
  278. XkbVModIndexText(xkb, interp->virtual_mod, XkbXKBFile));
  279. }
  280. if (interp->match & XkbSI_LevelOneOnly)
  281. fprintf(file, " useModMapMods=level1;\n");
  282. if (interp->flags & XkbSI_LockingKey)
  283. fprintf(file, " locking= TRUE;\n");
  284. if (interp->flags & XkbSI_AutoRepeat)
  285. fprintf(file, " repeat= TRUE;\n");
  286. fprintf(file, " action= ");
  287. WriteXKBAction(file, xkb, &interp->act);
  288. fprintf(file, ";\n");
  289. fprintf(file, " };\n");
  290. }
  291. for (i = 0; i < XkbNumKbdGroups; i++) {
  292. XkbModsPtr gc;
  293. gc = &xkb->compat->groups[i];
  294. if ((gc->real_mods == 0) && (gc->vmods == 0))
  295. continue;
  296. fprintf(file, " group %d = %s;\n", i + 1, XkbVModMaskText(xkb,
  297. gc->
  298. real_mods,
  299. gc->vmods,
  300. XkbXKBFile));
  301. }
  302. if (xkb->indicators) {
  303. for (i = 0; i < XkbNumIndicators; i++) {
  304. XkbIndicatorMapPtr map = &xkb->indicators->maps[i];
  305. if ((map->flags != 0) || (map->which_groups != 0) ||
  306. (map->groups != 0) || (map->which_mods != 0) ||
  307. (map->mods.real_mods != 0) || (map->mods.vmods != 0) ||
  308. (map->ctrls != 0)) {
  309. WriteXKBIndicatorMap(file, xkb, xkb->names->indicators[i], map,
  310. addOn, priv);
  311. }
  312. }
  313. }
  314. if (addOn)
  315. (*addOn) (file, xkb, topLevel, showImplicit, XkmCompatMapIndex, priv);
  316. fprintf(file, "};\n\n");
  317. return TRUE;
  318. }
  319. Bool
  320. XkbWriteXKBSymbols(FILE * file,
  321. XkbDescPtr xkb,
  322. Bool topLevel,
  323. Bool showImplicit, XkbFileAddOnFunc addOn, void *priv)
  324. {
  325. register unsigned i, tmp;
  326. XkbClientMapPtr map;
  327. XkbServerMapPtr srv;
  328. Bool showActions;
  329. if (!xkb) {
  330. _XkbLibError(_XkbErrMissingSymbols, "XkbWriteXKBSymbols", 0);
  331. return FALSE;
  332. }
  333. map = xkb->map;
  334. if ((!map) || (!map->syms) || (!map->key_sym_map)) {
  335. _XkbLibError(_XkbErrMissingSymbols, "XkbWriteXKBSymbols", 0);
  336. return FALSE;
  337. }
  338. if ((!xkb->names) || (!xkb->names->keys)) {
  339. _XkbLibError(_XkbErrMissingNames, "XkbWriteXKBSymbols", 0);
  340. return FALSE;
  341. }
  342. if ((xkb->names == NULL) || (xkb->names->symbols == None))
  343. fprintf(file, "xkb_symbols {\n\n");
  344. else
  345. fprintf(file, "xkb_symbols \"%s\" {\n\n",
  346. XkbAtomText(xkb->names->symbols, XkbXKBFile));
  347. for (tmp = i = 0; i < XkbNumKbdGroups; i++) {
  348. if (xkb->names->groups[i] != None) {
  349. fprintf(file, " name[group%d]=\"%s\";\n", i + 1,
  350. XkbAtomText(xkb->names->groups[i], XkbXKBFile));
  351. tmp++;
  352. }
  353. }
  354. if (tmp > 0)
  355. fprintf(file, "\n");
  356. srv = xkb->server;
  357. for (i = xkb->min_key_code; i <= xkb->max_key_code; i++) {
  358. Bool simple;
  359. if ((int) XkbKeyNumSyms(xkb, i) < 1)
  360. continue;
  361. if (XkbFindKeycodeByName(xkb, xkb->names->keys[i].name, TRUE) != i)
  362. continue;
  363. simple = TRUE;
  364. fprintf(file, " key %6s {",
  365. XkbKeyNameText(xkb->names->keys[i].name, XkbXKBFile));
  366. if (srv->explicit) {
  367. if (((srv->explicit[i] & XkbExplicitKeyTypesMask) != 0) ||
  368. (showImplicit)) {
  369. int typeNdx, g;
  370. Bool multi;
  371. const char *comment = " ";
  372. if ((srv->explicit[i] & XkbExplicitKeyTypesMask) == 0)
  373. comment = "//";
  374. multi = FALSE;
  375. typeNdx = XkbKeyKeyTypeIndex(xkb, i, 0);
  376. for (g = 1; (g < XkbKeyNumGroups(xkb, i)) && (!multi); g++) {
  377. if (XkbKeyKeyTypeIndex(xkb, i, g) != typeNdx)
  378. multi = TRUE;
  379. }
  380. if (multi) {
  381. for (g = 0; g < XkbKeyNumGroups(xkb, i); g++) {
  382. typeNdx = XkbKeyKeyTypeIndex(xkb, i, g);
  383. if (srv->explicit[i] & (1 << g)) {
  384. fprintf(file, "\n%s type[group%d]= \"%s\",",
  385. comment, g + 1,
  386. XkbAtomText(map->types[typeNdx].name,
  387. XkbXKBFile));
  388. }
  389. else if (showImplicit) {
  390. fprintf(file, "\n// type[group%d]= \"%s\",",
  391. g + 1, XkbAtomText(map->types[typeNdx].name,
  392. XkbXKBFile));
  393. }
  394. }
  395. }
  396. else {
  397. fprintf(file, "\n%s type= \"%s\",", comment,
  398. XkbAtomText(map->types[typeNdx].name, XkbXKBFile));
  399. }
  400. simple = FALSE;
  401. }
  402. if (((srv->explicit[i] & XkbExplicitAutoRepeatMask) != 0) &&
  403. (xkb->ctrls != NULL)) {
  404. if (xkb->ctrls->per_key_repeat[i / 8] & (1 << (i % 8)))
  405. fprintf(file, "\n repeat= Yes,");
  406. else
  407. fprintf(file, "\n repeat= No,");
  408. simple = FALSE;
  409. }
  410. if ((xkb->server != NULL) && (xkb->server->vmodmap != NULL) &&
  411. (xkb->server->vmodmap[i] != 0)) {
  412. if ((srv->explicit[i] & XkbExplicitVModMapMask) != 0) {
  413. fprintf(file, "\n virtualMods= %s,",
  414. XkbVModMaskText(xkb, 0,
  415. xkb->server->vmodmap[i],
  416. XkbXKBFile));
  417. }
  418. else if (showImplicit) {
  419. fprintf(file, "\n// virtualMods= %s,",
  420. XkbVModMaskText(xkb, 0,
  421. xkb->server->vmodmap[i],
  422. XkbXKBFile));
  423. }
  424. }
  425. }
  426. switch (XkbOutOfRangeGroupAction(XkbKeyGroupInfo(xkb, i))) {
  427. case XkbClampIntoRange:
  428. fprintf(file, "\n groupsClamp,");
  429. break;
  430. case XkbRedirectIntoRange:
  431. fprintf(file, "\n groupsRedirect= Group%d,",
  432. XkbOutOfRangeGroupNumber(XkbKeyGroupInfo(xkb, i)) + 1);
  433. break;
  434. }
  435. if (srv->behaviors != NULL) {
  436. unsigned type;
  437. type = srv->behaviors[i].type & XkbKB_OpMask;
  438. if (type != XkbKB_Default) {
  439. simple = FALSE;
  440. fprintf(file, "\n %s,",
  441. XkbBehaviorText(xkb, &srv->behaviors[i], XkbXKBFile));
  442. }
  443. }
  444. if ((srv->explicit == NULL) || showImplicit ||
  445. ((srv->explicit[i] & XkbExplicitInterpretMask) != 0))
  446. showActions = XkbKeyHasActions(xkb, i);
  447. else
  448. showActions = FALSE;
  449. if (((unsigned) XkbKeyNumGroups(xkb, i) > 1) || showActions)
  450. simple = FALSE;
  451. if (simple) {
  452. KeySym *syms;
  453. unsigned s;
  454. syms = XkbKeySymsPtr(xkb, i);
  455. fprintf(file, " [ ");
  456. for (s = 0; s < XkbKeyGroupWidth(xkb, i, XkbGroup1Index); s++) {
  457. if (s != 0)
  458. fprintf(file, ", ");
  459. fprintf(file, "%15s", XkbKeysymText(*syms++, XkbXKBFile));
  460. }
  461. fprintf(file, " ] };\n");
  462. }
  463. else {
  464. unsigned g, s;
  465. KeySym *syms;
  466. XkbAction *acts;
  467. syms = XkbKeySymsPtr(xkb, i);
  468. acts = XkbKeyActionsPtr(xkb, i);
  469. for (g = 0; g < XkbKeyNumGroups(xkb, i); g++) {
  470. if (g != 0)
  471. fprintf(file, ",");
  472. fprintf(file, "\n symbols[Group%d]= [ ", g + 1);
  473. for (s = 0; s < XkbKeyGroupWidth(xkb, i, g); s++) {
  474. if (s != 0)
  475. fprintf(file, ", ");
  476. fprintf(file, "%15s", XkbKeysymText(syms[s], XkbXKBFile));
  477. }
  478. fprintf(file, " ]");
  479. syms += XkbKeyGroupsWidth(xkb, i);
  480. if (showActions) {
  481. fprintf(file, ",\n actions[Group%d]= [ ", g + 1);
  482. for (s = 0; s < XkbKeyGroupWidth(xkb, i, g); s++) {
  483. if (s != 0)
  484. fprintf(file, ", ");
  485. WriteXKBAction(file, xkb, (XkbAnyAction *) &acts[s]);
  486. }
  487. fprintf(file, " ]");
  488. acts += XkbKeyGroupsWidth(xkb, i);
  489. }
  490. }
  491. fprintf(file, "\n };\n");
  492. }
  493. }
  494. if (map && map->modmap) {
  495. for (i = xkb->min_key_code; i <= xkb->max_key_code; i++) {
  496. if (map->modmap[i] != 0) {
  497. register int n, bit;
  498. for (bit = 1, n = 0; n < XkbNumModifiers; n++, bit <<= 1) {
  499. if (map->modmap[i] & bit) {
  500. char buf[5];
  501. memcpy(buf, xkb->names->keys[i].name, 4);
  502. buf[4] = '\0';
  503. fprintf(file, " modifier_map %s { <%s> };\n",
  504. XkbModIndexText(n, XkbXKBFile), buf);
  505. }
  506. }
  507. }
  508. }
  509. }
  510. if (addOn)
  511. (*addOn) (file, xkb, topLevel, showImplicit, XkmSymbolsIndex, priv);
  512. fprintf(file, "};\n\n");
  513. return TRUE;
  514. }
  515. static Bool
  516. WriteXKBOutline(FILE * file,
  517. XkbShapePtr shape,
  518. XkbOutlinePtr outline, int lastRadius, int first, int indent)
  519. {
  520. register int i;
  521. XkbPointPtr pt;
  522. char *iStr;
  523. fprintf(file, "%s", iStr = XkbIndentText(first));
  524. if (first != indent)
  525. iStr = XkbIndentText(indent);
  526. if (outline->corner_radius != lastRadius) {
  527. fprintf(file, "corner= %s,",
  528. XkbGeomFPText(outline->corner_radius, XkbMessage));
  529. if (shape != NULL) {
  530. fprintf(file, "\n%s", iStr);
  531. }
  532. }
  533. if (shape) {
  534. if (outline == shape->approx)
  535. fprintf(file, "approx= ");
  536. else if (outline == shape->primary)
  537. fprintf(file, "primary= ");
  538. }
  539. fprintf(file, "{");
  540. for (pt = outline->points, i = 0; i < outline->num_points; i++, pt++) {
  541. if (i == 0)
  542. fprintf(file, " ");
  543. else if ((i % 4) == 0)
  544. fprintf(file, ",\n%s ", iStr);
  545. else
  546. fprintf(file, ", ");
  547. fprintf(file, "[ %3s, %3s ]", XkbGeomFPText(pt->x, XkbXKBFile),
  548. XkbGeomFPText(pt->y, XkbXKBFile));
  549. }
  550. fprintf(file, " }");
  551. return TRUE;
  552. }
  553. static Bool
  554. WriteXKBDoodad(FILE * file,
  555. unsigned indent, XkbGeometryPtr geom, XkbDoodadPtr doodad)
  556. {
  557. register char *i_str;
  558. XkbShapePtr shape;
  559. XkbColorPtr color;
  560. i_str = XkbIndentText(indent);
  561. fprintf(file, "%s%s \"%s\" {\n", i_str,
  562. XkbDoodadTypeText(doodad->any.type, XkbMessage),
  563. XkbAtomText(doodad->any.name, XkbMessage));
  564. fprintf(file, "%s top= %s;\n", i_str,
  565. XkbGeomFPText(doodad->any.top, XkbXKBFile));
  566. fprintf(file, "%s left= %s;\n", i_str,
  567. XkbGeomFPText(doodad->any.left, XkbXKBFile));
  568. fprintf(file, "%s priority= %d;\n", i_str, doodad->any.priority);
  569. switch (doodad->any.type) {
  570. case XkbOutlineDoodad:
  571. case XkbSolidDoodad:
  572. if (doodad->shape.angle != 0) {
  573. fprintf(file, "%s angle= %s;\n", i_str,
  574. XkbGeomFPText(doodad->shape.angle, XkbXKBFile));
  575. }
  576. if (doodad->shape.color_ndx != 0) {
  577. fprintf(file, "%s color= \"%s\";\n", i_str,
  578. XkbShapeDoodadColor(geom, &doodad->shape)->spec);
  579. }
  580. shape = XkbShapeDoodadShape(geom, &doodad->shape);
  581. fprintf(file, "%s shape= \"%s\";\n", i_str,
  582. XkbAtomText(shape->name, XkbXKBFile));
  583. break;
  584. case XkbTextDoodad:
  585. if (doodad->text.angle != 0) {
  586. fprintf(file, "%s angle= %s;\n", i_str,
  587. XkbGeomFPText(doodad->text.angle, XkbXKBFile));
  588. }
  589. if (doodad->text.width != 0) {
  590. fprintf(file, "%s width= %s;\n", i_str,
  591. XkbGeomFPText(doodad->text.width, XkbXKBFile));
  592. }
  593. if (doodad->text.height != 0) {
  594. fprintf(file, "%s height= %s;\n", i_str,
  595. XkbGeomFPText(doodad->text.height, XkbXKBFile));
  596. }
  597. if (doodad->text.color_ndx != 0) {
  598. color = XkbTextDoodadColor(geom, &doodad->text);
  599. fprintf(file, "%s color= \"%s\";\n", i_str,
  600. XkbStringText(color->spec, XkbXKBFile));
  601. }
  602. fprintf(file, "%s XFont= \"%s\";\n", i_str,
  603. XkbStringText(doodad->text.font, XkbXKBFile));
  604. fprintf(file, "%s text= \"%s\";\n", i_str,
  605. XkbStringText(doodad->text.text, XkbXKBFile));
  606. break;
  607. case XkbIndicatorDoodad:
  608. shape = XkbIndicatorDoodadShape(geom, &doodad->indicator);
  609. color = XkbIndicatorDoodadOnColor(geom, &doodad->indicator);
  610. fprintf(file, "%s onColor= \"%s\";\n", i_str,
  611. XkbStringText(color->spec, XkbXKBFile));
  612. color = XkbIndicatorDoodadOffColor(geom, &doodad->indicator);
  613. fprintf(file, "%s offColor= \"%s\";\n", i_str,
  614. XkbStringText(color->spec, XkbXKBFile));
  615. fprintf(file, "%s shape= \"%s\";\n", i_str,
  616. XkbAtomText(shape->name, XkbXKBFile));
  617. break;
  618. case XkbLogoDoodad:
  619. fprintf(file, "%s logoName= \"%s\";\n", i_str,
  620. XkbStringText(doodad->logo.logo_name, XkbXKBFile));
  621. if (doodad->shape.angle != 0) {
  622. fprintf(file, "%s angle= %s;\n", i_str,
  623. XkbGeomFPText(doodad->logo.angle, XkbXKBFile));
  624. }
  625. if (doodad->shape.color_ndx != 0) {
  626. fprintf(file, "%s color= \"%s\";\n", i_str,
  627. XkbLogoDoodadColor(geom, &doodad->logo)->spec);
  628. }
  629. shape = XkbLogoDoodadShape(geom, &doodad->logo);
  630. fprintf(file, "%s shape= \"%s\";\n", i_str,
  631. XkbAtomText(shape->name, XkbXKBFile));
  632. break;
  633. }
  634. fprintf(file, "%s};\n", i_str);
  635. return TRUE;
  636. }
  637. /*ARGSUSED*/ static Bool
  638. WriteXKBOverlay(FILE * file,
  639. unsigned indent, XkbGeometryPtr geom, XkbOverlayPtr ol)
  640. {
  641. register char *i_str;
  642. int r, k, nOut;
  643. XkbOverlayRowPtr row;
  644. XkbOverlayKeyPtr key;
  645. i_str = XkbIndentText(indent);
  646. if (ol->name != None) {
  647. fprintf(file, "%soverlay \"%s\" {\n", i_str,
  648. XkbAtomText(ol->name, XkbMessage));
  649. }
  650. else
  651. fprintf(file, "%soverlay {\n", i_str);
  652. for (nOut = r = 0, row = ol->rows; r < ol->num_rows; r++, row++) {
  653. for (k = 0, key = row->keys; k < row->num_keys; k++, key++) {
  654. char *over, *under;
  655. over = XkbKeyNameText(key->over.name, XkbXKBFile);
  656. under = XkbKeyNameText(key->under.name, XkbXKBFile);
  657. if (nOut == 0)
  658. fprintf(file, "%s %6s=%6s", i_str, under, over);
  659. else if ((nOut % 4) == 0)
  660. fprintf(file, ",\n%s %6s=%6s", i_str, under, over);
  661. else
  662. fprintf(file, ", %6s=%6s", under, over);
  663. nOut++;
  664. }
  665. }
  666. fprintf(file, "\n%s};\n", i_str);
  667. return TRUE;
  668. }
  669. static Bool
  670. WriteXKBSection(FILE * file, XkbSectionPtr s, XkbGeometryPtr geom)
  671. {
  672. register int i;
  673. XkbRowPtr row;
  674. int dfltKeyColor = 0;
  675. fprintf(file, " section \"%s\" {\n", XkbAtomText(s->name, XkbXKBFile));
  676. if (s->rows && (s->rows->num_keys > 0)) {
  677. dfltKeyColor = s->rows->keys[0].color_ndx;
  678. fprintf(file, " key.color= \"%s\";\n",
  679. XkbStringText(geom->colors[dfltKeyColor].spec, XkbXKBFile));
  680. }
  681. fprintf(file, " priority= %d;\n", s->priority);
  682. fprintf(file, " top= %s;\n",
  683. XkbGeomFPText(s->top, XkbXKBFile));
  684. fprintf(file, " left= %s;\n",
  685. XkbGeomFPText(s->left, XkbXKBFile));
  686. fprintf(file, " width= %s;\n",
  687. XkbGeomFPText(s->width, XkbXKBFile));
  688. fprintf(file, " height= %s;\n",
  689. XkbGeomFPText(s->height, XkbXKBFile));
  690. if (s->angle != 0) {
  691. fprintf(file, " angle= %s;\n",
  692. XkbGeomFPText(s->angle, XkbXKBFile));
  693. }
  694. for (i = 0, row = s->rows; i < s->num_rows; i++, row++) {
  695. fprintf(file, " row {\n");
  696. fprintf(file, " top= %s;\n",
  697. XkbGeomFPText(row->top, XkbXKBFile));
  698. fprintf(file, " left= %s;\n",
  699. XkbGeomFPText(row->left, XkbXKBFile));
  700. if (row->vertical)
  701. fprintf(file, " vertical;\n");
  702. if (row->num_keys > 0) {
  703. register int k;
  704. register XkbKeyPtr key;
  705. int forceNL = 0;
  706. int nThisLine = 0;
  707. fprintf(file, " keys {\n");
  708. for (k = 0, key = row->keys; k < row->num_keys; k++, key++) {
  709. XkbShapePtr shape;
  710. if (key->color_ndx != dfltKeyColor)
  711. forceNL = 1;
  712. if (k == 0) {
  713. fprintf(file, " ");
  714. nThisLine = 0;
  715. }
  716. else if (((nThisLine % 2) == 1) || (forceNL)) {
  717. fprintf(file, ",\n ");
  718. forceNL = nThisLine = 0;
  719. }
  720. else {
  721. fprintf(file, ", ");
  722. nThisLine++;
  723. }
  724. shape = XkbKeyShape(geom, key);
  725. fprintf(file, "{ %6s, \"%s\", %3s",
  726. XkbKeyNameText(key->name.name, XkbXKBFile),
  727. XkbAtomText(shape->name, XkbXKBFile),
  728. XkbGeomFPText(key->gap, XkbXKBFile));
  729. if (key->color_ndx != dfltKeyColor) {
  730. fprintf(file, ", color=\"%s\"",
  731. XkbKeyColor(geom, key)->spec);
  732. forceNL = 1;
  733. }
  734. fprintf(file, " }");
  735. }
  736. fprintf(file, "\n };\n");
  737. }
  738. fprintf(file, " };\n");
  739. }
  740. if (s->doodads != NULL) {
  741. XkbDoodadPtr doodad;
  742. for (i = 0, doodad = s->doodads; i < s->num_doodads; i++, doodad++) {
  743. WriteXKBDoodad(file, 8, geom, doodad);
  744. }
  745. }
  746. if (s->overlays != NULL) {
  747. XkbOverlayPtr ol;
  748. for (i = 0, ol = s->overlays; i < s->num_overlays; i++, ol++) {
  749. WriteXKBOverlay(file, 8, geom, ol);
  750. }
  751. }
  752. fprintf(file, " }; // End of \"%s\" section\n\n",
  753. XkbAtomText(s->name, XkbXKBFile));
  754. return TRUE;
  755. }
  756. Bool
  757. XkbWriteXKBGeometry(FILE * file,
  758. XkbDescPtr xkb,
  759. Bool topLevel,
  760. Bool showImplicit, XkbFileAddOnFunc addOn, void *priv)
  761. {
  762. register unsigned i, n;
  763. XkbGeometryPtr geom;
  764. if ((!xkb) || (!xkb->geom)) {
  765. _XkbLibError(_XkbErrMissingGeometry, "XkbWriteXKBGeometry", 0);
  766. return FALSE;
  767. }
  768. geom = xkb->geom;
  769. if (geom->name == None)
  770. fprintf(file, "xkb_geometry {\n\n");
  771. else
  772. fprintf(file, "xkb_geometry \"%s\" {\n\n",
  773. XkbAtomText(geom->name, XkbXKBFile));
  774. fprintf(file, " width= %s;\n",
  775. XkbGeomFPText(geom->width_mm, XkbXKBFile));
  776. fprintf(file, " height= %s;\n\n",
  777. XkbGeomFPText(geom->height_mm, XkbXKBFile));
  778. if (geom->key_aliases != NULL) {
  779. XkbKeyAliasPtr pAl;
  780. pAl = geom->key_aliases;
  781. for (i = 0; i < geom->num_key_aliases; i++, pAl++) {
  782. fprintf(file, " alias %6s = %6s;\n",
  783. XkbKeyNameText(pAl->alias, XkbXKBFile),
  784. XkbKeyNameText(pAl->real, XkbXKBFile));
  785. }
  786. fprintf(file, "\n");
  787. }
  788. if (geom->base_color != NULL)
  789. fprintf(file, " baseColor= \"%s\";\n",
  790. XkbStringText(geom->base_color->spec, XkbXKBFile));
  791. if (geom->label_color != NULL)
  792. fprintf(file, " labelColor= \"%s\";\n",
  793. XkbStringText(geom->label_color->spec, XkbXKBFile));
  794. if (geom->label_font != NULL)
  795. fprintf(file, " xfont= \"%s\";\n",
  796. XkbStringText(geom->label_font, XkbXKBFile));
  797. if ((geom->num_colors > 0) && (showImplicit)) {
  798. XkbColorPtr color;
  799. for (color = geom->colors, i = 0; i < geom->num_colors; i++, color++) {
  800. fprintf(file, "// color[%d]= \"%s\"\n", i,
  801. XkbStringText(color->spec, XkbXKBFile));
  802. }
  803. fprintf(file, "\n");
  804. }
  805. if (geom->num_properties > 0) {
  806. XkbPropertyPtr prop;
  807. for (prop = geom->properties, i = 0; i < geom->num_properties;
  808. i++, prop++) {
  809. fprintf(file, " %s= \"%s\";\n", prop->name,
  810. XkbStringText(prop->value, XkbXKBFile));
  811. }
  812. fprintf(file, "\n");
  813. }
  814. if (geom->num_shapes > 0) {
  815. XkbShapePtr shape;
  816. XkbOutlinePtr outline;
  817. int lastR;
  818. for (shape = geom->shapes, i = 0; i < geom->num_shapes; i++, shape++) {
  819. lastR = 0;
  820. fprintf(file, " shape \"%s\" {",
  821. XkbAtomText(shape->name, XkbXKBFile));
  822. outline = shape->outlines;
  823. if (shape->num_outlines > 1) {
  824. for (n = 0; n < shape->num_outlines; n++, outline++) {
  825. if (n == 0)
  826. fprintf(file, "\n");
  827. else
  828. fprintf(file, ",\n");
  829. WriteXKBOutline(file, shape, outline, lastR, 8, 8);
  830. lastR = outline->corner_radius;
  831. }
  832. fprintf(file, "\n };\n");
  833. }
  834. else {
  835. WriteXKBOutline(file, NULL, outline, lastR, 1, 8);
  836. fprintf(file, " };\n");
  837. }
  838. }
  839. }
  840. if (geom->num_sections > 0) {
  841. XkbSectionPtr section;
  842. for (section = geom->sections, i = 0; i < geom->num_sections;
  843. i++, section++) {
  844. WriteXKBSection(file, section, geom);
  845. }
  846. }
  847. if (geom->num_doodads > 0) {
  848. XkbDoodadPtr doodad;
  849. for (i = 0, doodad = geom->doodads; i < geom->num_doodads;
  850. i++, doodad++) {
  851. WriteXKBDoodad(file, 4, geom, doodad);
  852. }
  853. }
  854. if (addOn)
  855. (*addOn) (file, xkb, topLevel, showImplicit, XkmGeometryIndex, priv);
  856. fprintf(file, "};\n\n");
  857. return TRUE;
  858. }