upload tizen2.0 source
[framework/uifw/xorg/lib/libxkbfile.git] / src / srvmisc.c
1 /************************************************************
2  Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
3
4  Permission to use, copy, modify, and distribute this
5  software and its documentation for any purpose and without
6  fee is hereby granted, provided that the above copyright
7  notice appear in all copies and that both that copyright
8  notice and this permission notice appear in supporting
9  documentation, and that the name of Silicon Graphics not be
10  used in advertising or publicity pertaining to distribution
11  of the software without specific prior written permission.
12  Silicon Graphics makes no representation about the suitability
13  of this software for any purpose. It is provided "as is"
14  without any express or implied warranty.
15
16  SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17  SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18  AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19  GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20  DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21  DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22  OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
23  THE USE OR PERFORMANCE OF THIS SOFTWARE.
24
25  ********************************************************/
26
27 #ifdef HAVE_CONFIG_H
28 #include <config.h>
29 #endif
30 #include <stdio.h>
31 #include <ctype.h>
32 #include <stdlib.h>
33 #include <X11/Xlib.h>
34 #include <X11/XKBlib.h>
35 #include <X11/extensions/XKBgeom.h>
36
37 #include "XKMformat.h"
38 #include "XKBfileInt.h"
39
40 Bool
41 XkbWriteToServer(XkbFileInfo *result)
42 {
43 XkbDescPtr              xkb;
44 Display *               dpy;
45
46     if ((result==NULL)||(result->xkb==NULL)||(result->xkb->dpy==NULL))
47         return False;
48     xkb= result->xkb;
49     dpy= xkb->dpy;
50     if (!XkbSetMap(dpy,XkbAllMapComponentsMask,xkb))
51         return False;
52     if (!XkbSetIndicatorMap(dpy,~0,xkb))
53         return False;
54 #ifdef NOTYET
55     if (!XkbSetControls(dpy,XkbAllControlsMask,xkb))
56         return False;
57 #endif
58     if (!XkbSetCompatMap(dpy,XkbAllCompatMask,xkb,True))
59         return False;
60     if (!XkbSetNames(dpy,XkbAllNamesMask,0,xkb->map->num_types,xkb))
61         return False;
62     if (xkb->geom) {
63         if (XkbSetGeometry(dpy,xkb->device_spec,xkb->geom)!=Success)
64             return False;
65     }
66     return True;
67 #ifdef NOTYET
68     switch (result->type) {
69         case XkmSemanticsFile:
70             func= WriteCHdrSemantics;
71             break;
72         case XkmLayoutFile:
73             func= WriteCHdrLayout;
74             break;
75         case XkmKeymapFile:
76             func= WriteCHdrKeymap;
77             break;
78         default:
79            _XkbLibError(_XkbErrIllegalContents,"XkbWriteToServer",result->type);
80            break;
81     }
82     return ok;
83 #endif
84 }
85
86 unsigned
87 XkbReadFromServer(Display *dpy,unsigned need,unsigned want,XkbFileInfo *result)
88 {
89 unsigned which= need|want;
90 unsigned tmp = 0;
91
92     if ((result==NULL)||(dpy==NULL))
93         return which;
94
95     if (which&XkmSymbolsMask)           tmp= XkbAllMapComponentsMask;
96     else if (which&XkmTypesMask)        tmp= XkbKeyTypesMask;
97     if (result->xkb==NULL) {
98         result->xkb= XkbGetMap(dpy,tmp,XkbUseCoreKbd);
99         if (!result->xkb)
100              return which;
101         else which&= ~(XkmSymbolsMask|XkmTypesMask|XkmVirtualModsMask);
102     }
103     else if ((tmp)&&(XkbGetUpdatedMap(dpy,tmp,result->xkb)==Success))
104         which&= ~(XkmSymbolsMask|XkmTypesMask|XkmVirtualModsMask);
105
106     if (which&XkmIndicatorsMask) {
107         if (XkbGetIndicatorMap(dpy,XkbAllIndicatorsMask,result->xkb)==Success)
108             which&= ~XkmIndicatorsMask;
109     }
110
111     if (which&XkmCompatMapMask) {
112         if (XkbGetCompatMap(dpy,XkbAllCompatMask,result->xkb)==Success)
113             which&= ~XkmCompatMapMask;
114     }
115     if (which&XkmGeometryMask) {
116         if (XkbGetGeometry(dpy,result->xkb)==Success)
117             which&= ~XkmGeometryMask;
118     }
119     XkbGetNames(dpy,XkbAllNamesMask,result->xkb);
120     return which;
121 }
122
123 Status
124 XkbChangeKbdDisplay(Display *newDpy,XkbFileInfo *result)
125 {
126 register int    i;
127 XkbDescPtr      xkb;
128 Display *       oldDpy;
129 Atom *          atm;
130
131     if ((result->xkb==NULL)||(result->xkb->dpy==newDpy))
132         return Success;
133     xkb= result->xkb;
134     oldDpy= xkb->dpy;
135     if (xkb->names) {
136         XkbNamesPtr     names= xkb->names;
137         names->keycodes= XkbChangeAtomDisplay(oldDpy,newDpy,names->keycodes);
138         names->geometry= XkbChangeAtomDisplay(oldDpy,newDpy,names->geometry);
139         names->symbols= XkbChangeAtomDisplay(oldDpy,newDpy,names->symbols);
140         names->types= XkbChangeAtomDisplay(oldDpy,newDpy,names->types);
141         names->compat= XkbChangeAtomDisplay(oldDpy,newDpy,names->compat);
142         names->phys_symbols= XkbChangeAtomDisplay(oldDpy,newDpy,
143                                                          names->phys_symbols);
144         for (i=0,atm=names->vmods;i<XkbNumVirtualMods;i++,atm++) {
145             *atm= XkbChangeAtomDisplay(oldDpy,newDpy,*atm);
146         }
147         for (i=0,atm=names->indicators;i<XkbNumIndicators;i++,atm++) {
148             *atm= XkbChangeAtomDisplay(oldDpy,newDpy,*atm);
149         }
150         for (i=0,atm=names->groups;i<XkbNumKbdGroups;i++,atm++) {
151             *atm= XkbChangeAtomDisplay(oldDpy,newDpy,*atm);
152         }
153         for (i=0,atm=names->radio_groups;i<names->num_rg;i++,atm++) {
154             *atm= XkbChangeAtomDisplay(oldDpy,newDpy,*atm);
155         }
156     }
157     if (xkb->map) {
158         register int    t;
159         XkbKeyTypePtr   type;
160         for (t=0,type=xkb->map->types;t<xkb->map->num_types;t++,type++) {
161             type->name= XkbChangeAtomDisplay(oldDpy,newDpy,type->name);
162             if (type->level_names!=NULL) {
163                 for (i=0,atm=type->level_names;i<type->num_levels;i++,atm++) {
164                     *atm= XkbChangeAtomDisplay(oldDpy,newDpy,*atm);
165                 }
166             }
167         }
168     }
169     if (xkb->geom) {
170         XkbGeometryPtr  geom= xkb->geom;
171         geom->name= XkbChangeAtomDisplay(oldDpy,newDpy,geom->name);
172         if (geom->shapes) {
173             register int s;
174             XkbShapePtr shape;
175             for (s=0,shape=geom->shapes;s<geom->num_shapes;s++,shape++) {
176                 shape->name= XkbChangeAtomDisplay(oldDpy,newDpy,shape->name);
177             }
178         }
179         if (geom->sections) {
180             register int s;
181             XkbSectionPtr       section;
182             for (s=0,section=geom->sections;s<geom->num_sections;s++,section++){
183                 section->name=XkbChangeAtomDisplay(oldDpy,newDpy,section->name);
184                 if (section->doodads) {
185                     register int d;
186                     XkbDoodadPtr doodad;
187                     for (d=0,doodad=section->doodads;d<section->num_doodads;
188                                                                 d++,doodad++) {
189                         doodad->any.name= XkbChangeAtomDisplay(oldDpy,newDpy,
190                                                          doodad->any.name);
191                     }
192                 }
193                 if (section->overlays) {
194                     register int o;
195                     register XkbOverlayPtr ol;
196                     for (o=0,ol=section->overlays;o<section->num_overlays;
197                                                                 o++,ol++) {
198                         ol->name= XkbChangeAtomDisplay(oldDpy,newDpy,ol->name);
199                     }
200                 }
201             }
202         }
203         if (geom->doodads) {
204             register int d;
205             XkbDoodadPtr doodad;
206             for (d=0,doodad=geom->doodads;d<geom->num_doodads;d++,doodad++) {
207                 doodad->any.name= XkbChangeAtomDisplay(oldDpy,newDpy,
208                                                          doodad->any.name);
209             }
210         }
211     }
212     xkb->dpy= newDpy;
213     return Success;
214 }