diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2008-08-04 15:19:45 +0930 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2008-08-04 15:42:39 +0930 |
commit | 6c1bb64c6f2efd81856ca00591df37916713b142 (patch) | |
tree | 8e380896bff395142e01ddde44db7bcdaf9c052e /xkb | |
parent | 3c6a9c531f673b7a0cb9ca01860b4dbe79686363 (diff) |
xkb: break up XkbCopyKeymap into bite-sized chunks.
Diffstat (limited to 'xkb')
-rw-r--r-- | xkb/xkbUtils.c | 243 |
1 files changed, 167 insertions, 76 deletions
diff --git a/xkb/xkbUtils.c b/xkb/xkbUtils.c index 8409eced7..486446ac7 100644 --- a/xkb/xkbUtils.c +++ b/xkb/xkbUtils.c @@ -23,6 +23,30 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ********************************************************/ +/* + +Copyright © 2008 Red Hat Inc. + +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: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + +*/ #ifdef HAVE_DIX_CONFIG_H #include <dix-config.h> @@ -909,44 +933,12 @@ XkbConvertCase(register KeySym sym, KeySym *lower, KeySym *upper) } } - -/** - * Copy an XKB map from src to dst, reallocating when necessary: if some - * map components are present in one, but not in the other, the destination - * components will be allocated or freed as necessary. - * - * Basic map consistency is assumed on both sides, so maps with random - * uninitialised data (e.g. names->radio_grous == NULL, names->num_rg == 19) - * _will_ cause failures. You've been warned. - * - * Returns TRUE on success, or FALSE on failure. If this function fails, - * dst may be in an inconsistent state: all its pointers are guaranteed - * to remain valid, but part of the map may be from src and part from dst. - * - * FIXME: This function wants to be broken up into multiple functions. - */ -Bool -XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool sendNotifies) +static Bool +_XkbCopyClientMap(XkbDescPtr src, XkbDescPtr dst) { - int i = 0, j = 0, k = 0; void *tmp = NULL; - XkbColorPtr scolor = NULL, dcolor = NULL; - XkbDoodadPtr sdoodad = NULL, ddoodad = NULL; + int i; XkbKeyTypePtr stype = NULL, dtype = NULL; - XkbOutlinePtr soutline = NULL, doutline = NULL; - XkbPropertyPtr sprop = NULL, dprop = NULL; - XkbRowPtr srow = NULL, drow = NULL; - XkbSectionPtr ssection = NULL, dsection = NULL; - XkbShapePtr sshape = NULL, dshape = NULL; - DeviceIntPtr pDev = NULL, tmpDev = NULL; - xkbMapNotify mn; - xkbNewKeyboardNotify nkn; - - if (src == dst) - return TRUE; - - if (!src || !dst) - return FALSE; /* client map */ if (src->map) { @@ -1195,6 +1187,14 @@ XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool sendNotifies) XkbFreeClientMap(dst, XkbAllClientInfoMask, True); } + return TRUE; +} + +static Bool +_XkbCopyServerMap(XkbDescPtr src, XkbDescPtr dst) +{ + void *tmp = NULL; + /* server map */ if (src->server) { if (!dst->server) { @@ -1323,37 +1323,13 @@ XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool sendNotifies) XkbFreeServerMap(dst, XkbAllServerInfoMask, True); } - /* indicators */ - if (src->indicators) { - if (!dst->indicators) { - dst->indicators = xalloc(sizeof(XkbIndicatorRec)); - if (!dst->indicators) - return FALSE; - } - memcpy(dst->indicators, src->indicators, sizeof(XkbIndicatorRec)); - } - else { - if (dst->indicators) { - xfree(dst->indicators); - dst->indicators = NULL; - } - } + return TRUE; +} - /* controls */ - if (src->ctrls) { - if (!dst->ctrls) { - dst->ctrls = xalloc(sizeof(XkbControlsRec)); - if (!dst->ctrls) - return FALSE; - } - memcpy(dst->ctrls, src->ctrls, sizeof(XkbControlsRec)); - } - else { - if (dst->ctrls) { - xfree(dst->ctrls); - dst->ctrls = NULL; - } - } +static Bool +_XkbCopyNames(XkbDescPtr src, XkbDescPtr dst) +{ + void *tmp = NULL; /* names */ if (src->names) { @@ -1448,6 +1424,14 @@ XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool sendNotifies) XkbFreeNames(dst, XkbAllNamesMask, True); } + return TRUE; +} + +static Bool +_XkbCopyCompat(XkbDescPtr src, XkbDescPtr dst) +{ + void *tmp = NULL; + /* compat */ if (src->compat) { if (!dst->compat) { @@ -1492,6 +1476,22 @@ XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool sendNotifies) XkbFreeCompatMap(dst, XkbAllCompatMask, True); } + return TRUE; +} + +static Bool +_XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst) +{ + void *tmp = NULL; + int i = 0, j = 0, k = 0; + XkbColorPtr scolor = NULL, dcolor = NULL; + XkbDoodadPtr sdoodad = NULL, ddoodad = NULL; + XkbOutlinePtr soutline = NULL, doutline = NULL; + XkbPropertyPtr sprop = NULL, dprop = NULL; + XkbRowPtr srow = NULL, drow = NULL; + XkbSectionPtr ssection = NULL, dsection = NULL; + XkbShapePtr sshape = NULL, dshape = NULL; + /* geometry */ if (src->geom) { if (!dst->geom) { @@ -2014,20 +2014,111 @@ XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool sendNotifies) } } - for (tmpDev = inputInfo.devices; tmpDev && !pDev; - tmpDev = tmpDev->next) { - if (tmpDev->key && tmpDev->key->xkbInfo && - tmpDev->key->xkbInfo->desc == dst) { - pDev = tmpDev; - break; + return TRUE; +} + +static Bool +_XkbCopyIndicators(XkbDescPtr src, XkbDescPtr dst) +{ + /* indicators */ + if (src->indicators) { + if (!dst->indicators) { + dst->indicators = xalloc(sizeof(XkbIndicatorRec)); + if (!dst->indicators) + return FALSE; + } + memcpy(dst->indicators, src->indicators, sizeof(XkbIndicatorRec)); + } + else { + if (dst->indicators) { + xfree(dst->indicators); + dst->indicators = NULL; + } + } + return TRUE; +} + +static Bool +_XkbCopyControls(XkbDescPtr src, XkbDescPtr dst) +{ + /* controls */ + if (src->ctrls) { + if (!dst->ctrls) { + dst->ctrls = xalloc(sizeof(XkbControlsRec)); + if (!dst->ctrls) + return FALSE; + } + memcpy(dst->ctrls, src->ctrls, sizeof(XkbControlsRec)); + } + else { + if (dst->ctrls) { + xfree(dst->ctrls); + dst->ctrls = NULL; } } - for (tmpDev = inputInfo.off_devices; tmpDev && !pDev; - tmpDev = tmpDev->next) { - if (tmpDev->key && tmpDev->key->xkbInfo && + return TRUE; +} + +/** + * Copy an XKB map from src to dst, reallocating when necessary: if some + * map components are present in one, but not in the other, the destination + * components will be allocated or freed as necessary. + * + * Basic map consistency is assumed on both sides, so maps with random + * uninitialised data (e.g. names->radio_grous == NULL, names->num_rg == 19) + * _will_ cause failures. You've been warned. + * + * Returns TRUE on success, or FALSE on failure. If this function fails, + * dst may be in an inconsistent state: all its pointers are guaranteed + * to remain valid, but part of the map may be from src and part from dst. + * + */ + +Bool +XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool sendNotifies) +{ + DeviceIntPtr pDev = NULL, tmpDev = NULL; + xkbMapNotify mn; + xkbNewKeyboardNotify nkn; + + if (!src || !dst || src == dst) + return FALSE; + + if (!_XkbCopyClientMap(src, dst)) + return FALSE; + if (!_XkbCopyServerMap(src, dst)) + return FALSE; + if (!_XkbCopyIndicators(src, dst)) + return FALSE; + if (!_XkbCopyControls(src, dst)) + return FALSE; + if (!_XkbCopyNames(src, dst)) + return FALSE; + if (!_XkbCopyCompat(src, dst)) + return FALSE; + if (!_XkbCopyGeom(src, dst)) + return FALSE; + + if (inputInfo.keyboard->key->xkbInfo && + inputInfo.keyboard->key->xkbInfo->desc == dst) { + pDev = inputInfo.keyboard; + } + else { + for (tmpDev = inputInfo.devices; tmpDev && !pDev; + tmpDev = tmpDev->next) { + if (tmpDev->key && tmpDev->key->xkbInfo && tmpDev->key->xkbInfo->desc == dst) { - pDev = tmpDev; - break; + pDev = tmpDev; + break; + } + } + for (tmpDev = inputInfo.off_devices; tmpDev && !pDev; + tmpDev = tmpDev->next) { + if (tmpDev->key && tmpDev->key->xkbInfo && + tmpDev->key->xkbInfo->desc == dst) { + pDev = tmpDev; + break; + } } } |