Commit Graph

1231 Commits (1651e5af465f45f9b6fff7e65ab958425ccda00b)

Author SHA1 Message Date
Ran Benita c955f8e2f9 keymap: store a pointer to the type in xkb_group instead of index
Gets rid of some more unneeded indirection, including the XkbKeyType
macro.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 14:41:09 +02:00
Ran Benita 01b00d7540 keymap, symbols: improve xkb_key memory layout
Add struct xkb_group and xkb_level for use in xkb_key, to mirror how
it's done in KeyInfo, GroupInfo, LevelInfo in symbols.c. This
corresponds more nicely to the logical data layout (i.e. a key has
groups which have levels), and also removes a lot of copying and ugly
code due to the index indirections and separate arrays which were used
before.

This uses more memory in some places (e.g. we alloc an action for every
level even if the key doesn't have any) but less in other places (e.g.
we no longer have to pad each group to ->width levels). The numbers say
we use less overall.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 12:46:51 +02:00
Ran Benita e44cd2e93b symbols: move keysyms into LevelInfo
Instead of maintaining a syms array in the GroupInfo + sym_index's in
the levels. This simplifies the code somewhat.
In order not to alloc for every level instead of every group, we only do
it if the level has more than one keysym (with a union). Since for now
this is a special case, it actually works out better memory-wise.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 12:33:06 +02:00
Ran Benita eaf9515229 symbols: fix index-out-of-bounds in FindAutomaticType
If we enter this branch, we have 3 <= width <= 4, so if the width is 3
than syms[3] is out of bounds.

Happily inherited from xkbcomp.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 10:19:02 +02:00
Ran Benita 504853de3b symbols: remove unneeded optimization
The levels will be resized to the number of levels of the type anyway,
so removing useless levels from the end here is unneeded.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:14:35 +02:00
Ran Benita e0573c766d keymap: use our type for keymap->enabled_ctrls
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 08:24:29 +02:00
Daniel Stone a8b6b08afb Add missing declaration for _xkbcommon_parse (aka yyparse)
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-24 14:36:46 +10:00
Ran Benita 1d47cbfc4a keymap.h: add note on why XKB_NUM_GROUPS is still there
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:13:32 +10:00
Ran Benita d941bc0c03 keymap, symbols: use darray for num_groups
Instead of using a static array of size XKB_NUM_GROUPS, because we want
to get rid of this limit.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:13:32 +10:00
Ran Benita 79bbf6f758 symbols: avoid possible access-out-of-bound due to explicit_group
The code that handles group name statements currently does this:
    info->group_names[grp - 1 + info->explicit_group] = name;
Other than the fact that this addition makes no sense, it actually can
reach out of the bounds of the array (which is of size XKB_NUM_GROUPS)
in the (non-realistic) case where (grp - 1) is not 0 (i.e. the statement
is not name[Group1] = "foo").

We also change explicit_group to be XKB_LAYOUT_INVALID if not set
otherwise, instead of initializing it to 0; this is clearer and if
someone happens to write 'us:1' for some reason, it will discard the
other groups in the file as it should.

This entire explicit_group thing was clearly bolted on as an
afterthought.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:13:32 +10:00
Ran Benita 6d97d0ce5e symbols: rename SymbolsInfo groupNames to group_names
Just to match the matching field in the keymap.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:13:32 +10:00
Ran Benita 7a90f9e225 keymap: don't use XKB_NUM_GROUPS for key->kt_index
One unneeded XKB_NUM_GROUPS less.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:13:32 +10:00
Ran Benita 9a18b87251 Add format argument to xkb_keymap_get_as_string
This function really needs a format argument, for symmetry with the
keymap creation functions. If we add new formats, we will almost
certainly want to add support for serializing it into a string. It would
also allow to convert from one format to another, etc.

The in the common case, the user would just want to use the format she
used to create the keymap; for that we add a special
XKB_KEYMAP_USE_ORIGINAL_FORMAT value, which will do that (it is defined
to -1 outside of the enum because I have a feeling we might want to use
0 for something else). To support this we need to keep the format inside
the keymap. While we're at it we also initialize keymap flags properly.

This changes the API, but the old xkb_map_get_as_string name works as
expected so this is the best time to do this.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:13:32 +10:00
Ran Benita 5d31b9e3e7 Add return value the xkb_keysym_get_name
This is useful to see whether the function was successful and whether
truncation occurred.
It just changes void -> int so shouldn't break API or ABI.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:13:32 +10:00
Ran Benita 25b8384404 Improve API doxygen documentation
To make it look better and a bit more structured and informative.
Not all of the functions are converted to doxygen format, so this is not
finished.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:13:32 +10:00
Ran Benita 108fa1c793 Add support for building doxygen API documentation
Simple HTML docs generated from the doxygen comments.
After running 'make' or 'make doc', try firefox doc/html/index.html to
see it (if you have doxygen). It's also installed with 'make install'.
You can use --enable-docs or --disable-docs, or specifically
--with-doxygen or --without-doxygen (autodetected, default yes).

The docs are currently not distributed in the tarball, because I
couldn't make it work properly in all cases :/

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:13:32 +10:00
Ran Benita 0dd40125c5 API: add _context prefix to log-related functions
This is to follow the general scheme set by all of the other API
functions.
Since no one is using these functions yet, we don't (actually better
not) add the old names to xkbcommon-compat.h.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:54 +10:00
Ran Benita be3cbc993e keymap: remove XkbKeyGetKeycode
Because we keep the keycode inside the xkb_key now.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:54 +10:00
Ran Benita 428c6f313f symbols: convert KeyInfo->groups to darray
Before it was a static array of size XKB_NUM_GROUPS.

The previous cleanups made this transition a bit easier. This is a
first step for removing the XKB_NUM_GROUPS hardcoded limit; but for now
we still check that the groups are < XKB_NUM_GROUPS (e.g. in
ResolveGroup and GetGroupIndex) until the keymap, etc. is worked out as
well.

This also makes us alloc quite a bit less (this is just rulescomp):
Before:
==51999==   total heap usage: 291,474 allocs, 291,474 frees, 21,458,334 bytes allocated
After:
==31394==   total heap usage: 293,595 allocs, 293,595 frees, 18,150,110 bytes allocated
This is because most rmlvo's don't use the full 4 layouts that KeyInfo
had always alloced statically before.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:54 +10:00
Ran Benita f671ce07ff symbols: fix memleak from default KeyInfo
If the default KeyInfo gets any keysyms or actions, it needs to be
free'd.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:54 +10:00
Ran Benita a12b5f6224 symbols: disallow changing global defaults from within a key statement
Pretty much like e5fdbcbb99, again it isn't used.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:54 +10:00
Ran Benita b70abcaf36 symbols: fold PrepareKeyDef into CopySymbolsDef
The function is big enough already but it's nicer to read sequentially.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:54 +10:00
Ran Benita 419a497554 state: missing XKB_EXPORT on xkb_state_key_get_level
And some error handling.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:54 +10:00
Ran Benita 70a82afa73 configure.ac: use XORG_TESTSET_CFLAG for -fvisibility=hidden
Probably shouldn't use CFLAGS for that but o well.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:54 +10:00
Ran Benita 18a433223e configure.ac: add XORG_MEMORY_CHECK_FLAGS
Adds some memory checking (e.g. MALLOC_PERTURB_) to tests.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:54 +10:00
Ran Benita 414007ca67 configure.ac: remove XORG_CHECK_MALLOC_ZERO
We don't use its result.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:53 +10:00
Ran Benita 31c7427209 configure.ac: fix bug report url
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:53 +10:00
Ran Benita 67b03cea0b state: correctly wrap state->locked_group and ->group
These values weren't wrapped before, which caused group_index_is_active
to stop working after a few group switches.

Also, the current group-wrapping function didn't take into consideration
actions such as LockGroup=-1, which need to wrap around, etc.
xkb_layout_index_t is unsigned, but it was used to hold possibly
negative values (e.g. locked_group is 0 and gets a -1 action).

This group wrapping function should now act like the XkbAdjustGroup
function from xserver, and at least ./test/interactive doesn't bring up
any problems with group switching any more.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:53 +10:00
Ran Benita 7d1db12dbb state: separate group wrapping/clamping to a function
We'll need this function for wrapping our global effective group as
well.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:53 +10:00
Ran Benita ed78fbcb30 state: special case effective group in layout_is_active
Currently, xkb_state_layout_{index,name}_is_active may report multiple
groups as effective, because at looks at base,latched,locked separately.
But there can only be one effective group, which is computed from the
other three. So if XKB_STATE_EFFECTIVE is requested, just compare to the
effective group we have computed.

We also modify mod_{index,name}_is_active similarly, just for symmetry
(there the effective mask is just an OR of the other three so the
current test is correct).

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:53 +10:00
Ran Benita a8b932a032 symbols: remove useless identical groups optimization
What this code does is, in case someone compile a keymap like -layout
'us,us,us' then only one group would be created. If there is anything
which differentiates between any of the groups (e.g. a variant, another
layout), then this is not done.
This is pretty obscure, only saves a few kbytes in the final keymap, and
if the user asked for it, why not let her?

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:53 +10:00
Ran Benita 95b2344849 symbols: avoid reverse iteration in PrepareKeyDef
No need for that.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:53 +10:00
Ran Benita c174173209 Don't choke on RMLVO layout string with holes
This old rules parser gives the same kccgst here, so in the interest of
staying compatible we shouldn't fix it there. Similarly we shouldn't
touch ParseIncludeMap, so this is the best place to handle this.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:53 +10:00
Ran Benita bbaa11c6e3 Rename map.{c,h} to keymap.{c,h}
Seeing as we don't like "map" anymore.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:53 +10:00
Ran Benita 7dca986e3f state, map: check XkbKey != NULL where missing
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:53 +10:00
Ran Benita debd62b59b Move xkb_state functions from map.c to state.c
Seems more appropriate.
Only change is to turn some xkb_state_get_map functions to direct
state->keymap.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:53 +10:00
Ran Benita d206ecd9e3 Rename private xkb_map_new to xkb_keymap_new
To be consistent with the API rename.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:53 +10:00
Ran Benita fcd202909b Don't use xkbcommon-compat names in internal code
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:53 +10:00
Daniel Stone bf19408078 Promote keymap enumeration API to public
Rename the functions to get keysyms by key/layout/level to fit with the
recent public API renames, and expose them.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-24 09:08:53 +10:00
Daniel Stone 33a66515d6 API change: Rename xkb_map_* and group -> layout
Move xkb_map_* functions to xkb_keymap_*, xkb_key_* functions under
either xkb_keymap or xkb_state, and rename groups to layout in all
user-visible API.

Backwards-compatible hooks are provided, such that old source will
build, but silently mangled to the new names, and old binaries will
also continue to work.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-20 23:30:23 +10:00
Daniel Stone 005dee2bb6 Add _xkbcommon_ prefix to parser and lexer symbols
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-20 23:30:17 +10:00
Daniel Stone 80e156814d Add xkbcommon-compat.h and compat.c
So we can start renaming stuff while retaining backwards source and
binary compatibility.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-20 23:29:45 +10:00
Ran Benita 2c96828f75 test: add print-compiled-keymap tool
This just prints the compiled keymap string for to the given command
line arguments. This often useful when developing.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-19 16:56:26 +03:00
Ran Benita 6b66afc4e7 state: handle ACTION_LOCK_NO_{UN,}LOCK for mods
xkblib spec says:
    XkbSA_LockNoLock    If set, and the action type is XkbSA_LockMods,
                        the server only unlocks the action modifiers.
    XkbSA_LockNoUnlock  If set, and the action is XkbSA_LockMods,
                        the server only locks the action modifiers.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-19 15:56:07 +03:00
Ran Benita 9c2a5c6c61 xkbcomp/keymap: correct ACTION_MODS_LOOKUP_MODS handling
The xkblib spec says:
    If XkbSA_UseModMapMods is not set in the flags field, the mask,
    real_mods, vmods1, and vmods2 fields are used to determine the
    action modifiers. Otherwise they are ignored and the modifiers
    bound to the key (client map->modmap[keycode]) are used instead.

So we should just assign the modmap without considering what's there.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-19 15:23:35 +03:00
Ran Benita 9aee332e9f Fix a couple of mistakes from previous commits
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-18 17:31:55 +03:00
Rob Bradford de4098a024 keysym-utf8: Optimise the keysym to utf8 lookup
This change adds range checks based on the lowest keysym and highest keysym in
the table. This allows a quick check to be applied to identify if the keysym
is inside the table.

To really give value to this optimisation the table is split to have a
separate table for the keypad keysyms.

The test suite passes with this change.

Signed-off-by: Rob Bradford <rob@linux.intel.com>
2012-09-18 09:03:40 +10:00
Ran Benita ac872bdfc2 symbols: fix buffer overflow with illegal explicit group
Trying ''./test/interactive -l us:5' causes us to crash.

The <layout>:<N> syntax says to put this layout at the N'th level.
However the code (inherited from xkbcomp) doesn't check that the group
is valid, and then happily indexes keyi->groups with it, which has a
static size of XKB_NUM_GROUPS (the SetExplicitGroup function assumes the
index is valid). So any value a user might put there > 4 makes nice
things happen.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-17 14:30:16 +03:00
Ran Benita dbd7a95359 keyseq: add test for repeat-shift-repeat-unshift-repeat
e.g. hhhhhHHHHHHHhhhhhh with shift down and up in the middle.
Unfortunately trying a quick test with test/interactive is not possible
because the evdev soft-repeat stops the repeat when another key is
pressed. So you need real soft-repeat for that.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-16 15:59:31 +03:00
Ran Benita b21107056e Organize src/ and test/ headers
- Add context.h and move context-related functions from xkb-priv.h to
  it.
- Move xkb_context definition back to context.c.
- Add keysym.h and move keysym upper/lower/keypad from xkb-priv.h to it.
- Rename xkb-priv.h to map.h since it only contains keymap-related
  definitions and declarations now.
- Remove unnecessary includes and some and some other small cleanups.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-16 15:20:18 +03:00