srvmisc.c revision 70728a38
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
40Bool
41XkbWriteToServer(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
86unsigned
87XkbReadFromServer(Display *dpy, unsigned need, unsigned want,
88                  XkbFileInfo *result)
89{
90    unsigned which = need | want;
91    unsigned tmp = 0;
92
93    if ((result == NULL) || (dpy == NULL))
94        return which;
95
96    if (which & XkmSymbolsMask)
97        tmp = XkbAllMapComponentsMask;
98    else if (which & XkmTypesMask)
99        tmp = XkbKeyTypesMask;
100    if (result->xkb == NULL) {
101        result->xkb = XkbGetMap(dpy, tmp, XkbUseCoreKbd);
102        if (!result->xkb)
103            return which;
104        else
105            which &= ~(XkmSymbolsMask | XkmTypesMask | XkmVirtualModsMask);
106    }
107    else if ((tmp) && (XkbGetUpdatedMap(dpy, tmp, result->xkb) == Success))
108        which &= ~(XkmSymbolsMask | XkmTypesMask | XkmVirtualModsMask);
109
110    if (which & XkmIndicatorsMask) {
111        if (XkbGetIndicatorMap(dpy, XkbAllIndicatorsMask, result->xkb) ==
112            Success)
113            which &= ~XkmIndicatorsMask;
114    }
115
116    if (which & XkmCompatMapMask) {
117        if (XkbGetCompatMap(dpy, XkbAllCompatMask, result->xkb) == Success)
118            which &= ~XkmCompatMapMask;
119    }
120    if (which & XkmGeometryMask) {
121        if (XkbGetGeometry(dpy, result->xkb) == Success)
122            which &= ~XkmGeometryMask;
123    }
124    XkbGetNames(dpy, XkbAllNamesMask, result->xkb);
125    return which;
126}
127
128Status
129XkbChangeKbdDisplay(Display *newDpy, XkbFileInfo *result)
130{
131    register int i;
132    XkbDescPtr xkb;
133    Display *oldDpy;
134    Atom *atm;
135
136    if ((result->xkb == NULL) || (result->xkb->dpy == newDpy))
137        return Success;
138    xkb = result->xkb;
139    oldDpy = xkb->dpy;
140    if (xkb->names) {
141        XkbNamesPtr names = xkb->names;
142
143        names->keycodes = XkbChangeAtomDisplay(oldDpy, newDpy, names->keycodes);
144        names->geometry = XkbChangeAtomDisplay(oldDpy, newDpy, names->geometry);
145        names->symbols = XkbChangeAtomDisplay(oldDpy, newDpy, names->symbols);
146        names->types = XkbChangeAtomDisplay(oldDpy, newDpy, names->types);
147        names->compat = XkbChangeAtomDisplay(oldDpy, newDpy, names->compat);
148        names->phys_symbols = XkbChangeAtomDisplay(oldDpy, newDpy,
149                                                   names->phys_symbols);
150        for (i = 0, atm = names->vmods; i < XkbNumVirtualMods; i++, atm++) {
151            *atm = XkbChangeAtomDisplay(oldDpy, newDpy, *atm);
152        }
153        for (i = 0, atm = names->indicators; i < XkbNumIndicators; i++, atm++) {
154            *atm = XkbChangeAtomDisplay(oldDpy, newDpy, *atm);
155        }
156        for (i = 0, atm = names->groups; i < XkbNumKbdGroups; i++, atm++) {
157            *atm = XkbChangeAtomDisplay(oldDpy, newDpy, *atm);
158        }
159        for (i = 0, atm = names->radio_groups; i < names->num_rg; i++, atm++) {
160            *atm = XkbChangeAtomDisplay(oldDpy, newDpy, *atm);
161        }
162    }
163    if (xkb->map) {
164        register int t;
165        XkbKeyTypePtr type;
166
167        for (t = 0, type = xkb->map->types; t < xkb->map->num_types;
168             t++, type++) {
169            type->name = XkbChangeAtomDisplay(oldDpy, newDpy, type->name);
170            if (type->level_names != NULL) {
171                for (i = 0, atm = type->level_names; i < type->num_levels;
172                     i++, atm++) {
173                    *atm = XkbChangeAtomDisplay(oldDpy, newDpy, *atm);
174                }
175            }
176        }
177    }
178    if (xkb->geom) {
179        XkbGeometryPtr geom = xkb->geom;
180
181        geom->name = XkbChangeAtomDisplay(oldDpy, newDpy, geom->name);
182        if (geom->shapes) {
183            register int s;
184            XkbShapePtr shape;
185
186            for (s = 0, shape = geom->shapes; s < geom->num_shapes;
187                 s++, shape++) {
188                shape->name = XkbChangeAtomDisplay(oldDpy, newDpy, shape->name);
189            }
190        }
191        if (geom->sections) {
192            register int s;
193            XkbSectionPtr section;
194
195            for (s = 0, section = geom->sections; s < geom->num_sections;
196                 s++, section++) {
197                section->name =
198                    XkbChangeAtomDisplay(oldDpy, newDpy, section->name);
199                if (section->doodads) {
200                    register int d;
201                    XkbDoodadPtr doodad;
202
203                    for (d = 0, doodad = section->doodads;
204                         d < section->num_doodads; d++, doodad++) {
205                        doodad->any.name =
206                            XkbChangeAtomDisplay(oldDpy, newDpy,
207                                                 doodad->any.name);
208                    }
209                }
210                if (section->overlays) {
211                    register int o;
212                    register XkbOverlayPtr ol;
213
214                    for (o = 0, ol = section->overlays;
215                         o < section->num_overlays; o++, ol++) {
216                        ol->name =
217                            XkbChangeAtomDisplay(oldDpy, newDpy, ol->name);
218                    }
219                }
220            }
221        }
222        if (geom->doodads) {
223            register int d;
224            XkbDoodadPtr doodad;
225
226            for (d = 0, doodad = geom->doodads; d < geom->num_doodads;
227                 d++, doodad++) {
228                doodad->any.name =
229                    XkbChangeAtomDisplay(oldDpy, newDpy, doodad->any.name);
230            }
231        }
232    }
233    xkb->dpy = newDpy;
234    return Success;
235}
236