Move ComputeEffectiveMap code and avoid some duplication The ComputeEffectiveMap function is only called from keytypes.c, with the last argument NULL, so we can move it there and remove some code. The function XkbcVirtualModsToRealMods, of which the above is the only user, is already implemented more simply in compat.c, so make this one non-static and use it. This leaves src/xkb.c empty, so remove it. Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
diff --git a/Makefile.am b/Makefile.am
index 3e41ba6..78e7621 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -84,7 +84,6 @@ libxkbcommon_la_SOURCES = \
src/text.h \
src/utils.c \
src/utils.h \
- src/xkb.c \
src/xkb-priv.h
BUILT_SOURCES = \
diff --git a/src/xkb-priv.h b/src/xkb-priv.h
index 41dc3c6..1d75043 100644
--- a/src/xkb-priv.h
+++ b/src/xkb-priv.h
@@ -457,10 +457,6 @@ xkb_map_new_from_kccgst(struct xkb_context *ctx,
extern int
xkb_context_take_file_id(struct xkb_context *ctx);
-extern bool
-XkbcComputeEffectiveMap(struct xkb_keymap *keymap, struct xkb_key_type *type,
- unsigned char *map_rtrn);
-
extern int
XkbcInitCanonicalKeyTypes(struct xkb_keymap *keymap, unsigned which,
int keypadVMod);
diff --git a/src/xkb.c b/src/xkb.c
deleted file mode 100644
index 9d9d0ba..0000000
--- a/src/xkb.c
+++ /dev/null
@@ -1,94 +0,0 @@
-/************************************************************
-Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
-
-Permission to use, copy, modify, and distribute this
-software and its documentation for any purpose and without
-fee is hereby granted, provided that the above copyright
-notice appear in all copies and that both that copyright
-notice and this permission notice appear in supporting
-documentation, and that the name of Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
-DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
-DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
-THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-********************************************************/
-
-#include "xkb-priv.h"
-
-static bool
-VirtualModsToReal(struct xkb_keymap *keymap, unsigned virtual_mask,
- unsigned *mask_rtrn)
-{
- int i, bit;
- unsigned mask;
-
- if (!keymap)
- return false;
- if (virtual_mask == 0) {
- *mask_rtrn = 0;
- return true;
- }
- if (!keymap->server)
- return false;
-
- for (i = mask = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
- if (virtual_mask & bit)
- mask |= keymap->server->vmods[i];
- }
-
- *mask_rtrn = mask;
- return true;
-}
-
-bool
-XkbcComputeEffectiveMap(struct xkb_keymap *keymap, struct xkb_key_type *type,
- unsigned char *map_rtrn)
-{
- unsigned tmp;
- struct xkb_kt_map_entry * entry = NULL;
-
- if (!keymap || !type || !keymap->server)
- return false;
-
- if (type->mods.vmods != 0) {
- if (!VirtualModsToReal(keymap, type->mods.vmods, &tmp))
- return false;
-
- type->mods.mask = tmp | type->mods.real_mods;
- darray_foreach(entry, type->map) {
- tmp = 0;
- if (entry->mods.vmods != 0) {
- if (!VirtualModsToReal(keymap, entry->mods.vmods, &tmp))
- return false;
- if (tmp == 0) {
- entry->active = false;
- continue;
- }
- }
- entry->active = true;
- entry->mods.mask = (entry->mods.real_mods | tmp) & type->mods.mask;
- }
- }
- else
- type->mods.mask = type->mods.real_mods;
-
- if (map_rtrn) {
- memset(map_rtrn, 0, type->mods.mask + 1);
- if (entry && entry->active)
- darray_foreach(entry, type->map)
- map_rtrn[entry->mods.mask] = entry->level;
- }
-
- return true;
-}
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index f9fed35..99ed570 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -838,7 +838,7 @@ err_info:
return false;
}
-static uint32_t
+uint32_t
VModsToReal(struct xkb_keymap *keymap, uint32_t vmodmask)
{
uint32_t ret = 0;
diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c
index 5b0cd82..8801e6f 100644
--- a/src/xkbcomp/keytypes.c
+++ b/src/xkbcomp/keytypes.c
@@ -988,6 +988,34 @@ HandleKeyTypesFile(XkbFile *file, struct xkb_keymap *keymap,
}
static bool
+ComputeEffectiveMap(struct xkb_keymap *keymap, struct xkb_key_type *type)
+{
+ uint32_t tmp;
+ struct xkb_kt_map_entry *entry = NULL;
+
+ if (type->mods.vmods != 0) {
+ tmp = VModsToReal(keymap, type->mods.vmods);
+ type->mods.mask = tmp | type->mods.real_mods;
+ darray_foreach(entry, type->map) {
+ tmp = 0;
+ if (entry->mods.vmods != 0) {
+ tmp = VModsToReal(keymap, entry->mods.vmods);
+ if (tmp == 0) {
+ entry->active = false;
+ continue;
+ }
+ }
+ entry->active = true;
+ entry->mods.mask = (entry->mods.real_mods | tmp) & type->mods.mask;
+ }
+ }
+ else
+ type->mods.mask = type->mods.real_mods;
+
+ return true;
+}
+
+static bool
CopyDefToKeyType(struct xkb_keymap *keymap, struct xkb_key_type *type,
KeyTypeInfo *def)
{
@@ -1055,7 +1083,7 @@ CopyDefToKeyType(struct xkb_keymap *keymap, struct xkb_key_type *type,
}
darray_init(def->entries);
- return XkbcComputeEffectiveMap(keymap, type, NULL);
+ return ComputeEffectiveMap(keymap, type);
}
bool
diff --git a/src/xkbcomp/xkbcomp-priv.h b/src/xkbcomp/xkbcomp-priv.h
index 9d10597..35d59d4 100644
--- a/src/xkbcomp/xkbcomp-priv.h
+++ b/src/xkbcomp/xkbcomp-priv.h
@@ -80,4 +80,7 @@ FindKeyNameForAlias(struct xkb_keymap *keymap, unsigned long lname,
extern bool
UpdateModifiersFromCompat(struct xkb_keymap *keymap);
+uint32_t
+VModsToReal(struct xkb_keymap *keymap, uint32_t vmodmask);
+
#endif /* XKBCOMP_PRIV_H */