srvmisc.c revision 70728a38
18c9fbc29Smrg/************************************************************
28c9fbc29Smrg Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
38c9fbc29Smrg
48c9fbc29Smrg Permission to use, copy, modify, and distribute this
58c9fbc29Smrg software and its documentation for any purpose and without
68c9fbc29Smrg fee is hereby granted, provided that the above copyright
78c9fbc29Smrg notice appear in all copies and that both that copyright
88c9fbc29Smrg notice and this permission notice appear in supporting
94cd6a3aeSmrg documentation, and that the name of Silicon Graphics not be
104cd6a3aeSmrg used in advertising or publicity pertaining to distribution
118c9fbc29Smrg of the software without specific prior written permission.
124cd6a3aeSmrg Silicon Graphics makes no representation about the suitability
138c9fbc29Smrg of this software for any purpose. It is provided "as is"
148c9fbc29Smrg without any express or implied warranty.
154cd6a3aeSmrg
164cd6a3aeSmrg SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
174cd6a3aeSmrg SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
188c9fbc29Smrg AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
194cd6a3aeSmrg GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
204cd6a3aeSmrg DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
214cd6a3aeSmrg DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
228c9fbc29Smrg OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
238c9fbc29Smrg THE USE OR PERFORMANCE OF THIS SOFTWARE.
248c9fbc29Smrg
258c9fbc29Smrg ********************************************************/
268c9fbc29Smrg
278c9fbc29Smrg#ifdef HAVE_CONFIG_H
288c9fbc29Smrg#include <config.h>
298c9fbc29Smrg#endif
308c9fbc29Smrg#include <stdio.h>
318c9fbc29Smrg#include <ctype.h>
328c9fbc29Smrg#include <stdlib.h>
338c9fbc29Smrg#include <X11/Xlib.h>
348c9fbc29Smrg#include <X11/XKBlib.h>
358c9fbc29Smrg#include <X11/extensions/XKBgeom.h>
368c9fbc29Smrg
378c9fbc29Smrg#include "XKMformat.h"
388c9fbc29Smrg#include "XKBfileInt.h"
398c9fbc29Smrg
408c9fbc29SmrgBool
418c9fbc29SmrgXkbWriteToServer(XkbFileInfo *result)
428c9fbc29Smrg{
4370728a38Smrg    XkbDescPtr xkb;
4470728a38Smrg    Display *dpy;
4570728a38Smrg
4670728a38Smrg    if ((result == NULL) || (result->xkb == NULL) || (result->xkb->dpy == NULL))
4770728a38Smrg        return False;
4870728a38Smrg    xkb = result->xkb;
4970728a38Smrg    dpy = xkb->dpy;
5070728a38Smrg    if (!XkbSetMap(dpy, XkbAllMapComponentsMask, xkb))
5170728a38Smrg        return False;
5270728a38Smrg    if (!XkbSetIndicatorMap(dpy, ~0, xkb))
5370728a38Smrg        return False;
548c9fbc29Smrg#ifdef NOTYET
5570728a38Smrg    if (!XkbSetControls(dpy, XkbAllControlsMask, xkb))
5670728a38Smrg        return False;
578c9fbc29Smrg#endif
5870728a38Smrg    if (!XkbSetCompatMap(dpy, XkbAllCompatMask, xkb, True))
5970728a38Smrg        return False;
6070728a38Smrg    if (!XkbSetNames(dpy, XkbAllNamesMask, 0, xkb->map->num_types, xkb))
6170728a38Smrg        return False;
628c9fbc29Smrg    if (xkb->geom) {
6370728a38Smrg        if (XkbSetGeometry(dpy, xkb->device_spec, xkb->geom) != Success)
6470728a38Smrg            return False;
658c9fbc29Smrg    }
668c9fbc29Smrg    return True;
678c9fbc29Smrg#ifdef NOTYET
688c9fbc29Smrg    switch (result->type) {
6970728a38Smrg    case XkmSemanticsFile:
7070728a38Smrg        func = WriteCHdrSemantics;
7170728a38Smrg        break;
7270728a38Smrg    case XkmLayoutFile:
7370728a38Smrg        func = WriteCHdrLayout;
7470728a38Smrg        break;
7570728a38Smrg    case XkmKeymapFile:
7670728a38Smrg        func = WriteCHdrKeymap;
7770728a38Smrg        break;
7870728a38Smrg    default:
7970728a38Smrg        _XkbLibError(_XkbErrIllegalContents, "XkbWriteToServer", result->type);
8070728a38Smrg        break;
818c9fbc29Smrg    }
828c9fbc29Smrg    return ok;
838c9fbc29Smrg#endif
848c9fbc29Smrg}
858c9fbc29Smrg
868c9fbc29Smrgunsigned
8770728a38SmrgXkbReadFromServer(Display *dpy, unsigned need, unsigned want,
8870728a38Smrg                  XkbFileInfo *result)
898c9fbc29Smrg{
9070728a38Smrg    unsigned which = need | want;
9170728a38Smrg    unsigned tmp = 0;
9270728a38Smrg
9370728a38Smrg    if ((result == NULL) || (dpy == NULL))
9470728a38Smrg        return which;
9570728a38Smrg
9670728a38Smrg    if (which & XkmSymbolsMask)
9770728a38Smrg        tmp = XkbAllMapComponentsMask;
9870728a38Smrg    else if (which & XkmTypesMask)
9970728a38Smrg        tmp = XkbKeyTypesMask;
10070728a38Smrg    if (result->xkb == NULL) {
10170728a38Smrg        result->xkb = XkbGetMap(dpy, tmp, XkbUseCoreKbd);
10270728a38Smrg        if (!result->xkb)
10370728a38Smrg            return which;
10470728a38Smrg        else
10570728a38Smrg            which &= ~(XkmSymbolsMask | XkmTypesMask | XkmVirtualModsMask);
1068c9fbc29Smrg    }
10770728a38Smrg    else if ((tmp) && (XkbGetUpdatedMap(dpy, tmp, result->xkb) == Success))
10870728a38Smrg        which &= ~(XkmSymbolsMask | XkmTypesMask | XkmVirtualModsMask);
1098c9fbc29Smrg
11070728a38Smrg    if (which & XkmIndicatorsMask) {
11170728a38Smrg        if (XkbGetIndicatorMap(dpy, XkbAllIndicatorsMask, result->xkb) ==
11270728a38Smrg            Success)
11370728a38Smrg            which &= ~XkmIndicatorsMask;
1148c9fbc29Smrg    }
1158c9fbc29Smrg
11670728a38Smrg    if (which & XkmCompatMapMask) {
11770728a38Smrg        if (XkbGetCompatMap(dpy, XkbAllCompatMask, result->xkb) == Success)
11870728a38Smrg            which &= ~XkmCompatMapMask;
1198c9fbc29Smrg    }
12070728a38Smrg    if (which & XkmGeometryMask) {
12170728a38Smrg        if (XkbGetGeometry(dpy, result->xkb) == Success)
12270728a38Smrg            which &= ~XkmGeometryMask;
1238c9fbc29Smrg    }
12470728a38Smrg    XkbGetNames(dpy, XkbAllNamesMask, result->xkb);
1258c9fbc29Smrg    return which;
1268c9fbc29Smrg}
1278c9fbc29Smrg
1288c9fbc29SmrgStatus
12970728a38SmrgXkbChangeKbdDisplay(Display *newDpy, XkbFileInfo *result)
1308c9fbc29Smrg{
13170728a38Smrg    register int i;
13270728a38Smrg    XkbDescPtr xkb;
13370728a38Smrg    Display *oldDpy;
13470728a38Smrg    Atom *atm;
13570728a38Smrg
13670728a38Smrg    if ((result->xkb == NULL) || (result->xkb->dpy == newDpy))
13770728a38Smrg        return Success;
13870728a38Smrg    xkb = result->xkb;
13970728a38Smrg    oldDpy = xkb->dpy;
1408c9fbc29Smrg    if (xkb->names) {
14170728a38Smrg        XkbNamesPtr names = xkb->names;
14270728a38Smrg
14370728a38Smrg        names->keycodes = XkbChangeAtomDisplay(oldDpy, newDpy, names->keycodes);
14470728a38Smrg        names->geometry = XkbChangeAtomDisplay(oldDpy, newDpy, names->geometry);
14570728a38Smrg        names->symbols = XkbChangeAtomDisplay(oldDpy, newDpy, names->symbols);
14670728a38Smrg        names->types = XkbChangeAtomDisplay(oldDpy, newDpy, names->types);
14770728a38Smrg        names->compat = XkbChangeAtomDisplay(oldDpy, newDpy, names->compat);
14870728a38Smrg        names->phys_symbols = XkbChangeAtomDisplay(oldDpy, newDpy,
14970728a38Smrg                                                   names->phys_symbols);
15070728a38Smrg        for (i = 0, atm = names->vmods; i < XkbNumVirtualMods; i++, atm++) {
15170728a38Smrg            *atm = XkbChangeAtomDisplay(oldDpy, newDpy, *atm);
15270728a38Smrg        }
15370728a38Smrg        for (i = 0, atm = names->indicators; i < XkbNumIndicators; i++, atm++) {
15470728a38Smrg            *atm = XkbChangeAtomDisplay(oldDpy, newDpy, *atm);
15570728a38Smrg        }
15670728a38Smrg        for (i = 0, atm = names->groups; i < XkbNumKbdGroups; i++, atm++) {
15770728a38Smrg            *atm = XkbChangeAtomDisplay(oldDpy, newDpy, *atm);
15870728a38Smrg        }
15970728a38Smrg        for (i = 0, atm = names->radio_groups; i < names->num_rg; i++, atm++) {
16070728a38Smrg            *atm = XkbChangeAtomDisplay(oldDpy, newDpy, *atm);
16170728a38Smrg        }
1628c9fbc29Smrg    }
1638c9fbc29Smrg    if (xkb->map) {
16470728a38Smrg        register int t;
16570728a38Smrg        XkbKeyTypePtr type;
16670728a38Smrg
16770728a38Smrg        for (t = 0, type = xkb->map->types; t < xkb->map->num_types;
16870728a38Smrg             t++, type++) {
16970728a38Smrg            type->name = XkbChangeAtomDisplay(oldDpy, newDpy, type->name);
17070728a38Smrg            if (type->level_names != NULL) {
17170728a38Smrg                for (i = 0, atm = type->level_names; i < type->num_levels;
17270728a38Smrg                     i++, atm++) {
17370728a38Smrg                    *atm = XkbChangeAtomDisplay(oldDpy, newDpy, *atm);
17470728a38Smrg                }
17570728a38Smrg            }
17670728a38Smrg        }
1778c9fbc29Smrg    }
1788c9fbc29Smrg    if (xkb->geom) {
17970728a38Smrg        XkbGeometryPtr geom = xkb->geom;
18070728a38Smrg
18170728a38Smrg        geom->name = XkbChangeAtomDisplay(oldDpy, newDpy, geom->name);
18270728a38Smrg        if (geom->shapes) {
18370728a38Smrg            register int s;
18470728a38Smrg            XkbShapePtr shape;
18570728a38Smrg
18670728a38Smrg            for (s = 0, shape = geom->shapes; s < geom->num_shapes;
18770728a38Smrg                 s++, shape++) {
18870728a38Smrg                shape->name = XkbChangeAtomDisplay(oldDpy, newDpy, shape->name);
18970728a38Smrg            }
19070728a38Smrg        }
19170728a38Smrg        if (geom->sections) {
19270728a38Smrg            register int s;
19370728a38Smrg            XkbSectionPtr section;
19470728a38Smrg
19570728a38Smrg            for (s = 0, section = geom->sections; s < geom->num_sections;
19670728a38Smrg                 s++, section++) {
19770728a38Smrg                section->name =
19870728a38Smrg                    XkbChangeAtomDisplay(oldDpy, newDpy, section->name);
19970728a38Smrg                if (section->doodads) {
20070728a38Smrg                    register int d;
20170728a38Smrg                    XkbDoodadPtr doodad;
20270728a38Smrg
20370728a38Smrg                    for (d = 0, doodad = section->doodads;
20470728a38Smrg                         d < section->num_doodads; d++, doodad++) {
20570728a38Smrg                        doodad->any.name =
20670728a38Smrg                            XkbChangeAtomDisplay(oldDpy, newDpy,
20770728a38Smrg                                                 doodad->any.name);
20870728a38Smrg                    }
20970728a38Smrg                }
21070728a38Smrg                if (section->overlays) {
21170728a38Smrg                    register int o;
21270728a38Smrg                    register XkbOverlayPtr ol;
21370728a38Smrg
21470728a38Smrg                    for (o = 0, ol = section->overlays;
21570728a38Smrg                         o < section->num_overlays; o++, ol++) {
21670728a38Smrg                        ol->name =
21770728a38Smrg                            XkbChangeAtomDisplay(oldDpy, newDpy, ol->name);
21870728a38Smrg                    }
21970728a38Smrg                }
22070728a38Smrg            }
22170728a38Smrg        }
22270728a38Smrg        if (geom->doodads) {
22370728a38Smrg            register int d;
22470728a38Smrg            XkbDoodadPtr doodad;
22570728a38Smrg
22670728a38Smrg            for (d = 0, doodad = geom->doodads; d < geom->num_doodads;
22770728a38Smrg                 d++, doodad++) {
22870728a38Smrg                doodad->any.name =
22970728a38Smrg                    XkbChangeAtomDisplay(oldDpy, newDpy, doodad->any.name);
23070728a38Smrg            }
23170728a38Smrg        }
2328c9fbc29Smrg    }
23370728a38Smrg    xkb->dpy = newDpy;
2348c9fbc29Smrg    return Success;
2358c9fbc29Smrg}
236