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