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