summaryrefslogtreecommitdiff
path: root/lib/X11
diff options
context:
space:
mode:
authordawes <dawes>2005-06-15 01:02:07 +0000
committerdawes <dawes>2005-06-15 01:02:07 +0000
commit23202557b77fd2edd167ae00103dcd81782401d5 (patch)
tree9337ebde1a5f2afc5db51f741e2f3a4c8b8e18ed /lib/X11
parent0f5ad039f23b951684fdc01c280649dadbedd444 (diff)
78. Several fixes for XKB:
- Off-by-one errors in XKBMAlloc.c. - Shrink tables instead of only growing them. - Fix various vmodmap vs modmap cut and paste bugs. - Improve synthesized core X events for reporting XKB changes to XKB-unaware clients. (Michal Maruska).
Diffstat (limited to 'lib/X11')
-rw-r--r--lib/X11/XKBGetMap.c78
-rw-r--r--lib/X11/XKBMAlloc.c127
-rw-r--r--lib/X11/XKBUse.c65
3 files changed, 249 insertions, 21 deletions
diff --git a/lib/X11/XKBGetMap.c b/lib/X11/XKBGetMap.c
index 71fc7f485..f4a0d8f77 100644
--- a/lib/X11/XKBGetMap.c
+++ b/lib/X11/XKBGetMap.c
@@ -1,4 +1,3 @@
-/* $Xorg: XKBGetMap.c,v 1.4 2000/08/17 19:45:02 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
@@ -25,7 +24,55 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
********************************************************/
-/* $XFree86: xc/lib/X11/XKBGetMap.c,v 1.9 2003/04/17 02:06:31 dawes Exp $ */
+/*
+ * Copyright (c) 2005 by The XFree86 Project, Inc.
+ * Copyright (c) 2005 by Michal Maruska.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions, and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution, and in the same place and form as other copyright,
+ * license and disclaimer information.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment: "This product
+ * includes software developed by The XFree86 Project, Inc
+ * (http://www.xfree86.org/) and its contributors", in the same
+ * place and form as other third-party acknowledgments. Alternately,
+ * this acknowledgment may appear in the software itself, in the
+ * same form and location as other such third-party acknowledgments.
+ *
+ * 4. Except as contained in this notice, the name of The XFree86
+ * Project, Inc shall not be used in advertising or otherwise to
+ * promote the sale, use or other dealings in this Software without
+ * prior written authorization from The XFree86 Project, Inc.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE XFREE86 PROJECT, INC OR ITS CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $XFree86: xc/lib/X11/XKBGetMap.c,v 1.10 2003/11/17 22:20:09 dawes Exp $ */
#define NEED_REPLIES
#define NEED_EVENTS
@@ -150,6 +197,7 @@ _XkbReadKeySyms(XkbReadBufferPtr buf,XkbDescPtr xkb,xkbGetMapReply *rep)
register int i;
XkbClientMapPtr map;
+ if (rep->totalSyms > 0) {
map= xkb->map;
if (map->key_sym_map==NULL) {
register int offset;
@@ -236,7 +284,8 @@ XkbClientMapPtr map;
oldMap->width = newMap->width;
}
}
- return Success;
+ }
+ return Success;
}
static Status
@@ -249,7 +298,9 @@ register int nKeyActs;
Status ret = Success;
if ( (nKeyActs=rep->nKeyActs)>0 ) {
+#if 0
XkbSymMapPtr symMap;
+#endif
if (nKeyActs < sizeof numDescBuf) numDesc = numDescBuf;
else numDesc = Xmalloc (nKeyActs * sizeof(CARD8));
@@ -263,8 +314,19 @@ Status ret = Success;
ret = BadLength;
goto done;
}
+#if 0
+ /*
+ * mmc: This probably should check that the number of actions &
+ * keysyms is the same for each keycode.
+ * But for now it doesn't, so I disable it.
+ */
symMap = &info->map->key_sym_map[rep->firstKeyAct];
- for (i=0;i<(int)rep->nKeyActs;i++,symMap++) {
+#endif
+ for (i=0;i<(int)rep->nKeyActs;i++
+#if 0
+ ,symMap++
+#endif
+ ) {
if (numDesc[i]==0) {
info->server->key_acts[i+rep->firstKeyAct]= 0;
}
@@ -478,7 +540,7 @@ unsigned mask;
}
extraData= (int)(rep->length*4);
extraData-= (SIZEOF(xkbGetMapReply)-SIZEOF(xGenericReply));
- if (rep->length) {
+ if (extraData) {
XkbReadBufferRec buf;
int left;
if (_XkbInitReadBuffer(dpy,&buf,extraData)) {
@@ -683,6 +745,8 @@ XkbGetVirtualMods(Display *dpy,unsigned which,XkbDescPtr xkb)
req = _XkbGetGetMapReq(dpy, xkb);
req->virtualMods = which;
+ /* mmc: We want this information, so the mask must be set! */
+ req->partial = XkbVirtualModsMask;
status= _XkbHandleGetMapReply(dpy, xkb);
UnlockDisplay(dpy);
@@ -740,6 +804,7 @@ XkbGetKeyModifierMap(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
req = _XkbGetGetMapReq(dpy, xkb);
req->firstModMapKey = first;
req->nModMapKeys = num;
+ req->partial = XkbModifierMapMask; /* mmc: Once again (see above). */
if ((xkb!=NULL) && (xkb->map!=NULL) && (xkb->map->modmap!=NULL)) {
if ((num>0)&&(first>=xkb->min_key_code)&&(first+num<=xkb->max_key_code))
bzero(&xkb->map->modmap[first],num);
@@ -767,9 +832,10 @@ XkbGetKeyVirtualModMap(Display *dpy,unsigned first,unsigned num,XkbDescPtr xkb)
LockDisplay(dpy);
req = _XkbGetGetMapReq(dpy, xkb);
+ req->partial = XkbVirtualModMapMask;
req->firstVModMapKey = first;
req->nVModMapKeys = num;
- if ((xkb!=NULL) && (xkb->map!=NULL) && (xkb->map->modmap!=NULL)) {
+ if ((xkb!=NULL) && (xkb->server!=NULL) && (xkb->server->vmodmap!=NULL)) {
if ((num>0)&&(first>=xkb->min_key_code)&&(first+num<=xkb->max_key_code))
bzero(&xkb->server->vmodmap[first],num*sizeof(unsigned short));
}
diff --git a/lib/X11/XKBMAlloc.c b/lib/X11/XKBMAlloc.c
index d1fd14f27..9c766d545 100644
--- a/lib/X11/XKBMAlloc.c
+++ b/lib/X11/XKBMAlloc.c
@@ -1,4 +1,3 @@
-/* $Xorg: XKBMAlloc.c,v 1.4 2000/08/17 19:45:02 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
@@ -24,7 +23,55 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.
********************************************************/
-/* $XFree86: xc/lib/X11/XKBMAlloc.c,v 3.11 2001/01/17 19:41:48 dawes Exp $ */
+/*
+ * Copyright (c) 2005 by The XFree86 Project, Inc.
+ * Copyright (c) 2005 by Michal Maruska.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions, and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution, and in the same place and form as other copyright,
+ * license and disclaimer information.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment: "This product
+ * includes software developed by The XFree86 Project, Inc
+ * (http://www.xfree86.org/) and its contributors", in the same
+ * place and form as other third-party acknowledgments. Alternately,
+ * this acknowledgment may appear in the software itself, in the
+ * same form and location as other such third-party acknowledgments.
+ *
+ * 4. Except as contained in this notice, the name of The XFree86
+ * Project, Inc shall not be used in advertising or otherwise to
+ * promote the sale, use or other dealings in this Software without
+ * prior written authorization from The XFree86 Project, Inc.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE XFREE86 PROJECT, INC OR ITS CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $XFree86: xc/lib/X11/XKBMAlloc.c,v 3.12 2003/11/17 22:20:09 dawes Exp $ */
#ifndef XKB_IN_SERVER
@@ -363,7 +410,7 @@ XkbClientMapPtr map;
Status
XkbResizeKeyType( XkbDescPtr xkb,
int type_ndx,
- int map_count,
+ int map_count, /* number of mappings: modifier-set -> level */
Bool want_preserve,
int new_num_lvls)
{
@@ -596,6 +643,7 @@ KeySym *newSyms;
int nCopy;
nCopy= nKeySyms= XkbKeyNumSyms(xkb,i);
+ /* i could invert these following 2 IFs: */
if ((nKeySyms==0)&&(i!=key))
continue;
if (i==key)
@@ -610,6 +658,25 @@ KeySym *newSyms;
_XkbFree(xkb->map->syms);
xkb->map->syms = newSyms;
xkb->map->num_syms = nSyms;
+
+
+ /*
+ * mmc: We grow the table when needed, and never shrink it.
+ * So i decided to test & shrink here:
+ */
+
+ if (xkb->map->size_syms > 2 * xkb->map->num_syms + 64) {
+#ifdef XKB_IN_SERVER
+#ifdef DEBUG
+ ErrorF("%s: reduction! %d ->%d\n", __FUNCTION__, xkb->map->size_syms, 2 * xkb->map->num_syms + 64);
+#endif
+#endif
+ xkb->map->size_syms = 2 * xkb->map->num_syms + 64;
+ /* xkb->map->num_syms remains! */
+ /* todo: if this fails....!! hopefully never, we just shrink. */
+ xkb->map->syms = _XkbTypedRealloc(xkb->map->syms, xkb->map->size_syms,
+ KeySym);
+ }
return &xkb->map->syms[xkb->map->key_sym_map[key].offset];
}
@@ -702,7 +769,7 @@ int tmp;
if (changes) {
changes->map.changed= _ExtendRange(changes->map.changed,
XkbVirtualModMapMask,minKC,
- &changes->map.first_modmap_key,
+ &changes->map.first_vmodmap_key,
&changes->map.num_vmodmap_keys);
}
}
@@ -732,7 +799,7 @@ int tmp;
_XkbFree(prev_key_sym_map);
return BadAlloc;
}
- bzero((char *)&xkb->map->key_sym_map[xkb->max_key_code],
+ bzero((char *)&xkb->map->key_sym_map[xkb->max_key_code+1],
tmp*sizeof(XkbSymMapRec));
if (changes) {
changes->map.changed= _ExtendRange(changes->map.changed,
@@ -750,7 +817,7 @@ int tmp;
_XkbFree(prev_modmap);
return BadAlloc;
}
- bzero((char *)&xkb->map->modmap[xkb->max_key_code],tmp);
+ bzero((char *)&xkb->map->modmap[xkb->max_key_code + 1],tmp);
if (changes) {
changes->map.changed= _ExtendRange(changes->map.changed,
XkbModifierMapMask,maxKC,
@@ -769,7 +836,7 @@ int tmp;
_XkbFree(prev_behaviors);
return BadAlloc;
}
- bzero((char *)&xkb->server->behaviors[xkb->max_key_code],
+ bzero((char *)&xkb->server->behaviors[xkb->max_key_code +1],
tmp*sizeof(XkbBehavior));
if (changes) {
changes->map.changed= _ExtendRange(changes->map.changed,
@@ -787,7 +854,7 @@ int tmp;
_XkbFree(prev_key_acts);
return BadAlloc;
}
- bzero((char *)&xkb->server->key_acts[xkb->max_key_code],
+ bzero((char *)&xkb->server->key_acts[xkb->max_key_code + 1],
tmp*sizeof(unsigned short));
if (changes) {
changes->map.changed= _ExtendRange(changes->map.changed,
@@ -805,15 +872,34 @@ int tmp;
_XkbFree(prev_vmodmap);
return BadAlloc;
}
- bzero((char *)&xkb->server->vmodmap[xkb->max_key_code],
+ bzero((char *)&xkb->server->vmodmap[xkb->max_key_code + 1],
tmp*sizeof(unsigned short));
if (changes) {
changes->map.changed= _ExtendRange(changes->map.changed,
XkbVirtualModMapMask,maxKC,
- &changes->map.first_modmap_key,
+ &changes->map.first_vmodmap_key,
&changes->map.num_vmodmap_keys);
}
}
+ /* mmc: We have to resize server->explicit too. */
+ if (xkb->server->explicit) {
+ unsigned char *prev_explicit = xkb->server->explicit;
+ xkb->server->explicit= _XkbTypedRealloc(xkb->server->explicit,
+ (maxKC+1),unsigned char);
+ if (!xkb->server->explicit) {
+ _XkbFree(prev_explicit);
+ return BadAlloc;
+ }
+ bzero((char *)&xkb->server->explicit[xkb->max_key_code + 1],
+ tmp*sizeof(unsigned char));
+ if (changes) {
+ changes->map.changed= _ExtendRange(changes->map.changed,
+ XkbExplicitComponentsMask,maxKC,
+ /* ???? */
+ &changes->map.first_key_explicit,
+ &changes->map.num_key_explicit);
+ }
+ }
}
if ((xkb->names)&&(xkb->names->keys)) {
XkbKeyNameRec *prev_keys = xkb->names->keys;
@@ -824,7 +910,7 @@ int tmp;
_XkbFree(prev_keys);
return BadAlloc;
}
- bzero((char *)&xkb->names->keys[xkb->max_key_code],
+ bzero((char *)&xkb->names->keys[xkb->max_key_code +1],
tmp*sizeof(XkbKeyNameRec));
if (changes) {
changes->names.changed= _ExtendRange(changes->names.changed,
@@ -885,6 +971,25 @@ XkbAction *newActs;
_XkbFree(xkb->server->acts);
xkb->server->acts = newActs;
xkb->server->num_acts= nActs;
+
+ /*
+ * mmc: Again (see above for keysyms), we grow the table when needed,
+ * and never shrink it. So i decided to test & shrink here:
+ */
+ if (xkb->server->size_acts > 2 * xkb->server->num_acts + 64) {
+#ifdef XKB_IN_SERVER
+#ifdef DEBUG
+ ErrorF("%s: reduction! %d ->%d\n", __FUNCTION__,
+ xkb->server->size_acts, 2 * xkb->server->num_acts + 64);
+#endif
+#endif
+ xkb->server->size_acts = 2 * xkb->server->num_acts + 64;
+
+ /* xkb->server->num_acts remains! */
+ /* fixme: if this fails....! */
+ xkb->server->acts = _XkbTypedRealloc(xkb->server->acts,
+ xkb->server->size_acts, XkbAction);
+ }
return &xkb->server->acts[xkb->server->key_acts[key]];
}
diff --git a/lib/X11/XKBUse.c b/lib/X11/XKBUse.c
index aea49cb65..defd50e04 100644
--- a/lib/X11/XKBUse.c
+++ b/lib/X11/XKBUse.c
@@ -1,4 +1,3 @@
-/* $Xorg: XKBUse.c,v 1.3 2000/08/17 19:45:03 cpqbld Exp $ */
/************************************************************
Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
@@ -24,7 +23,55 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
THE USE OR PERFORMANCE OF THIS SOFTWARE.
********************************************************/
-/* $XFree86: xc/lib/X11/XKBUse.c,v 3.7 2003/07/07 15:34:21 eich Exp $ */
+/*
+ * Copyright (c) 2005 by The XFree86 Project, Inc.
+ * Copyright (c) 2005 by Michal Maruska.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject
+ * to the following conditions:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions, and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution, and in the same place and form as other copyright,
+ * license and disclaimer information.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment: "This product
+ * includes software developed by The XFree86 Project, Inc
+ * (http://www.xfree86.org/) and its contributors", in the same
+ * place and form as other third-party acknowledgments. Alternately,
+ * this acknowledgment may appear in the software itself, in the
+ * same form and location as other such third-party acknowledgments.
+ *
+ * 4. Except as contained in this notice, the name of The XFree86
+ * Project, Inc shall not be used in advertising or otherwise to
+ * promote the sale, use or other dealings in this Software without
+ * prior written authorization from The XFree86 Project, Inc.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE XFREE86 PROJECT, INC OR ITS CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* $XFree86: xc/lib/X11/XKBUse.c,v 3.8 2003/11/17 22:20:10 dawes Exp $ */
#include <stdio.h>
#include <ctype.h>
@@ -204,6 +251,10 @@ _XkbNoteCoreMapChanges( XkbMapChangesPtr old,
return;
}
+/*
+ * mmc: Rewrite xbk event, possibly to a core X event.
+ * EVENT is on wire (xkb event). RE is where we transfer to (X event).
+ */
static Bool
wire_to_event(Display *dpy,XEvent *re,xEvent *event)
{
@@ -304,8 +355,14 @@ wire_to_event(Display *dpy,XEvent *re,xEvent *event)
ev->request = MappingKeyboard;
ev->count = mn->nKeySyms;
_XkbNoteCoreMapChanges(&xkbi->changes,ev,XKB_XLIB_MAP_MASK);
- if (xkbi->changes.changed)
- xkbi->flags|= XkbMapPending;
+ if (xkbi->changes.changed) {
+ /*
+ * If types change, we need to reload all, othewise,
+ * _maybe_ only ...
+ */
+ xkbi->flags|= XkbMapPending |
+ ((mn->nTypes != 0)?0:XkbXlibNewKeyboard);
+ }
return True;
}
}