srvmisc.c revision 4cd6a3ae
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{
438c9fbc29SmrgXkbDescPtr		xkb;
448c9fbc29SmrgDisplay *		dpy;
458c9fbc29Smrg
468c9fbc29Smrg    if ((result==NULL)||(result->xkb==NULL)||(result->xkb->dpy==NULL))
478c9fbc29Smrg	return False;
488c9fbc29Smrg    xkb= result->xkb;
498c9fbc29Smrg    dpy= xkb->dpy;
508c9fbc29Smrg    if (!XkbSetMap(dpy,XkbAllMapComponentsMask,xkb))
518c9fbc29Smrg	return False;
528c9fbc29Smrg    if (!XkbSetIndicatorMap(dpy,~0,xkb))
538c9fbc29Smrg	return False;
548c9fbc29Smrg#ifdef NOTYET
558c9fbc29Smrg    if (!XkbSetControls(dpy,XkbAllControlsMask,xkb))
568c9fbc29Smrg	return False;
578c9fbc29Smrg#endif
588c9fbc29Smrg    if (!XkbSetCompatMap(dpy,XkbAllCompatMask,xkb,True))
598c9fbc29Smrg	return False;
608c9fbc29Smrg    if (!XkbSetNames(dpy,XkbAllNamesMask,0,xkb->map->num_types,xkb))
618c9fbc29Smrg	return False;
628c9fbc29Smrg    if (xkb->geom) {
638c9fbc29Smrg	if (XkbSetGeometry(dpy,xkb->device_spec,xkb->geom)!=Success)
648c9fbc29Smrg	    return False;
658c9fbc29Smrg    }
668c9fbc29Smrg    return True;
678c9fbc29Smrg#ifdef NOTYET
688c9fbc29Smrg    switch (result->type) {
698c9fbc29Smrg	case XkmSemanticsFile:
708c9fbc29Smrg	    func= WriteCHdrSemantics;
718c9fbc29Smrg	    break;
728c9fbc29Smrg	case XkmLayoutFile:
738c9fbc29Smrg	    func= WriteCHdrLayout;
748c9fbc29Smrg	    break;
758c9fbc29Smrg	case XkmKeymapFile:
768c9fbc29Smrg	    func= WriteCHdrKeymap;
778c9fbc29Smrg	    break;
788c9fbc29Smrg	default:
798c9fbc29Smrg	   _XkbLibError(_XkbErrIllegalContents,"XkbWriteToServer",result->type);
808c9fbc29Smrg	   break;
818c9fbc29Smrg    }
828c9fbc29Smrg    return ok;
838c9fbc29Smrg#endif
848c9fbc29Smrg}
858c9fbc29Smrg
868c9fbc29Smrgunsigned
878c9fbc29SmrgXkbReadFromServer(Display *dpy,unsigned need,unsigned want,XkbFileInfo *result)
888c9fbc29Smrg{
898c9fbc29Smrgunsigned which= need|want;
908c9fbc29Smrgunsigned tmp = 0;
918c9fbc29Smrg
928c9fbc29Smrg    if ((result==NULL)||(dpy==NULL))
938c9fbc29Smrg	return which;
948c9fbc29Smrg
958c9fbc29Smrg    if (which&XkmSymbolsMask)		tmp= XkbAllMapComponentsMask;
968c9fbc29Smrg    else if (which&XkmTypesMask)	tmp= XkbKeyTypesMask;
978c9fbc29Smrg    if (result->xkb==NULL) {
988c9fbc29Smrg	result->xkb= XkbGetMap(dpy,tmp,XkbUseCoreKbd);
998c9fbc29Smrg	if (!result->xkb)
1008c9fbc29Smrg	     return which;
1018c9fbc29Smrg	else which&= ~(XkmSymbolsMask|XkmTypesMask|XkmVirtualModsMask);
1028c9fbc29Smrg    }
1038c9fbc29Smrg    else if ((tmp)&&(XkbGetUpdatedMap(dpy,tmp,result->xkb)==Success))
1048c9fbc29Smrg	which&= ~(XkmSymbolsMask|XkmTypesMask|XkmVirtualModsMask);
1058c9fbc29Smrg
1068c9fbc29Smrg    if (which&XkmIndicatorsMask) {
1078c9fbc29Smrg	if (XkbGetIndicatorMap(dpy,XkbAllIndicatorsMask,result->xkb)==Success)
1088c9fbc29Smrg	    which&= ~XkmIndicatorsMask;
1098c9fbc29Smrg    }
1108c9fbc29Smrg
1118c9fbc29Smrg    if (which&XkmCompatMapMask) {
1128c9fbc29Smrg	if (XkbGetCompatMap(dpy,XkbAllCompatMask,result->xkb)==Success)
1138c9fbc29Smrg	    which&= ~XkmCompatMapMask;
1148c9fbc29Smrg    }
1158c9fbc29Smrg    if (which&XkmGeometryMask) {
1168c9fbc29Smrg	if (XkbGetGeometry(dpy,result->xkb)==Success)
1178c9fbc29Smrg	    which&= ~XkmGeometryMask;
1188c9fbc29Smrg    }
1198c9fbc29Smrg    XkbGetNames(dpy,XkbAllNamesMask,result->xkb);
1208c9fbc29Smrg    return which;
1218c9fbc29Smrg}
1228c9fbc29Smrg
1238c9fbc29SmrgStatus
1248c9fbc29SmrgXkbChangeKbdDisplay(Display *newDpy,XkbFileInfo *result)
1258c9fbc29Smrg{
1268c9fbc29Smrgregister int	i;
1278c9fbc29SmrgXkbDescPtr	xkb;
1288c9fbc29SmrgDisplay *	oldDpy;
1298c9fbc29SmrgAtom *		atm;
1308c9fbc29Smrg
1318c9fbc29Smrg    if ((result->xkb==NULL)||(result->xkb->dpy==newDpy))
1328c9fbc29Smrg	return Success;
1338c9fbc29Smrg    xkb= result->xkb;
1348c9fbc29Smrg    oldDpy= xkb->dpy;
1358c9fbc29Smrg    if (xkb->names) {
1368c9fbc29Smrg	XkbNamesPtr	names= xkb->names;
1378c9fbc29Smrg	names->keycodes= XkbChangeAtomDisplay(oldDpy,newDpy,names->keycodes);
1388c9fbc29Smrg	names->geometry= XkbChangeAtomDisplay(oldDpy,newDpy,names->geometry);
1398c9fbc29Smrg	names->symbols= XkbChangeAtomDisplay(oldDpy,newDpy,names->symbols);
1408c9fbc29Smrg	names->types= XkbChangeAtomDisplay(oldDpy,newDpy,names->types);
1418c9fbc29Smrg	names->compat= XkbChangeAtomDisplay(oldDpy,newDpy,names->compat);
1428c9fbc29Smrg	names->phys_symbols= XkbChangeAtomDisplay(oldDpy,newDpy,
1438c9fbc29Smrg							 names->phys_symbols);
1448c9fbc29Smrg	for (i=0,atm=names->vmods;i<XkbNumVirtualMods;i++,atm++) {
1458c9fbc29Smrg	    *atm= XkbChangeAtomDisplay(oldDpy,newDpy,*atm);
1468c9fbc29Smrg	}
1478c9fbc29Smrg	for (i=0,atm=names->indicators;i<XkbNumIndicators;i++,atm++) {
1488c9fbc29Smrg	    *atm= XkbChangeAtomDisplay(oldDpy,newDpy,*atm);
1498c9fbc29Smrg	}
1508c9fbc29Smrg	for (i=0,atm=names->groups;i<XkbNumKbdGroups;i++,atm++) {
1518c9fbc29Smrg	    *atm= XkbChangeAtomDisplay(oldDpy,newDpy,*atm);
1528c9fbc29Smrg	}
1538c9fbc29Smrg	for (i=0,atm=names->radio_groups;i<names->num_rg;i++,atm++) {
1548c9fbc29Smrg	    *atm= XkbChangeAtomDisplay(oldDpy,newDpy,*atm);
1558c9fbc29Smrg	}
1568c9fbc29Smrg    }
1578c9fbc29Smrg    if (xkb->map) {
1588c9fbc29Smrg	register int	t;
1598c9fbc29Smrg	XkbKeyTypePtr	type;
1608c9fbc29Smrg	for (t=0,type=xkb->map->types;t<xkb->map->num_types;t++,type++) {
1618c9fbc29Smrg	    type->name= XkbChangeAtomDisplay(oldDpy,newDpy,type->name);
1628c9fbc29Smrg	    if (type->level_names!=NULL) {
1638c9fbc29Smrg		for (i=0,atm=type->level_names;i<type->num_levels;i++,atm++) {
1648c9fbc29Smrg		    *atm= XkbChangeAtomDisplay(oldDpy,newDpy,*atm);
1658c9fbc29Smrg		}
1668c9fbc29Smrg	    }
1678c9fbc29Smrg	}
1688c9fbc29Smrg    }
1698c9fbc29Smrg    if (xkb->geom) {
1708c9fbc29Smrg	XkbGeometryPtr	geom= xkb->geom;
1718c9fbc29Smrg	geom->name= XkbChangeAtomDisplay(oldDpy,newDpy,geom->name);
1728c9fbc29Smrg	if (geom->shapes) {
1738c9fbc29Smrg	    register int s;
1748c9fbc29Smrg	    XkbShapePtr	shape;
1758c9fbc29Smrg	    for (s=0,shape=geom->shapes;s<geom->num_shapes;s++,shape++) {
1768c9fbc29Smrg		shape->name= XkbChangeAtomDisplay(oldDpy,newDpy,shape->name);
1778c9fbc29Smrg	    }
1788c9fbc29Smrg	}
1798c9fbc29Smrg	if (geom->sections) {
1808c9fbc29Smrg	    register int s;
1818c9fbc29Smrg	    XkbSectionPtr	section;
1828c9fbc29Smrg	    for (s=0,section=geom->sections;s<geom->num_sections;s++,section++){
1838c9fbc29Smrg		section->name=XkbChangeAtomDisplay(oldDpy,newDpy,section->name);
1848c9fbc29Smrg		if (section->doodads) {
1858c9fbc29Smrg		    register int d;
1868c9fbc29Smrg		    XkbDoodadPtr doodad;
1878c9fbc29Smrg		    for (d=0,doodad=section->doodads;d<section->num_doodads;
1888c9fbc29Smrg								d++,doodad++) {
1898c9fbc29Smrg			doodad->any.name= XkbChangeAtomDisplay(oldDpy,newDpy,
1908c9fbc29Smrg							 doodad->any.name);
1918c9fbc29Smrg		    }
1928c9fbc29Smrg		}
1938c9fbc29Smrg		if (section->overlays) {
1948c9fbc29Smrg		    register int o;
1958c9fbc29Smrg		    register XkbOverlayPtr ol;
1968c9fbc29Smrg		    for (o=0,ol=section->overlays;o<section->num_overlays;
1978c9fbc29Smrg								o++,ol++) {
1988c9fbc29Smrg			ol->name= XkbChangeAtomDisplay(oldDpy,newDpy,ol->name);
1998c9fbc29Smrg		    }
2008c9fbc29Smrg		}
2018c9fbc29Smrg	    }
2028c9fbc29Smrg	}
2038c9fbc29Smrg	if (geom->doodads) {
2048c9fbc29Smrg	    register int d;
2058c9fbc29Smrg	    XkbDoodadPtr doodad;
2068c9fbc29Smrg	    for (d=0,doodad=geom->doodads;d<geom->num_doodads;d++,doodad++) {
2078c9fbc29Smrg		doodad->any.name= XkbChangeAtomDisplay(oldDpy,newDpy,
2088c9fbc29Smrg							 doodad->any.name);
2098c9fbc29Smrg	    }
2108c9fbc29Smrg	}
2118c9fbc29Smrg    }
2128c9fbc29Smrg    xkb->dpy= newDpy;
2138c9fbc29Smrg    return Success;
2148c9fbc29Smrg}
215