Commit Graph

1145 Commits (2c259f178229ec8b71f8a62d4e23b7dbdac007c7)

Author SHA1 Message Date
Ran Benita e6e3bda393 expr: share code for modifier functions
We can make more use of the functions in text.c now and remove some
cruft.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:42:00 +02:00
Ran Benita 9ebd2f67f4 text: explicitly take mod_type in mod functions
This essentially "tags" each invocation of the functions with the
modifier type of the argument, which allows for easy grepping for them
(with the aim being, to remove anything but MOD_BOTH).

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:41:59 +02:00
Ran Benita 6d580127d8 text: share code for modifiers
Add static common functions which take enum mod_type, and change the
existing ones to use them.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:41:59 +02:00
Ran Benita 424de613af Keep real and virtual mods in the same table in the keymap
We change the keymap->vmods array into keymap->mods, and change it's
member type from struct xkb_vmod to struct xkb_mod. This table now
includes the real modifiers in the first 8 places. To distinguish
between them, we add an enum mod_type to struct xkb_mod.

Besides being a more reasonable approach, this enables us to share
some code later, remove XKB_NUM_CORE_MODS (though the 0xff mask still
appears in a few places), and prepares us to flat out remove the
distinction in the future. This commit just does the conversion.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:41:59 +02:00
Ran Benita 1005b320f1 Don't use shifted virtual modifier masks
Modifier masks can be confusing in some places. For example,
key->vmodmap only contains virtual modifiers, where the first is in
position 0, the second in 1 etc., while normally in a xkb_mod_mask_t the
virtual modifiers start from the 8th (XKB_NUM_CORE_MODS) position. This
happens in some other places as well.

Change all of the masks to be in the usual real+virtual format, and when
we need to access e.g. keymap->vmods we just adjust by
XKB_NUM_CORE_MODS. (This also goes for indexes, e.g.
interpret->virtual_modifier).

This makes this stuff easier to reason about.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:41:59 +02:00
Ran Benita 6974e1f9ac expr: don't expose LookupModIndex
The Lookup* functions should remain a private implementation detail of
the expr.c file.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:41:59 +02:00
Ran Benita aed3140e8d Remove VModInfo for now
VModInfo currently is only used to track which virtual modifiers were
declared in the file which owns the VModInfo. This, in turn, is only
used in ResolveVirtualModifier, which in turn is only used to resolve
the virtualModifier field in an interpret statement (compat.c). In other
words, it is used to ensure that interprets can only use a vmod which
was declared in the same map.

We remove this now, because it doesn't do much and distracts from other
changes; we will later re-add it properly. Specificly, we will make it
so that virtual modifiers are not the exception in that they modify the
keymap directly, instead of keeping the changes in some *Info struct and
commiting them to the keymap at the end of the compilation. (This is bad
because if a vmod is added to the keymap, and then the compilation of
this specific file fails, the change sticks around nonetheless).

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:41:59 +02:00
Ran Benita 9a2ce2a5ad vmod: don't allow to add a vmod with the name of a real mod
Otherwise strange thing might ensue.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:41:59 +02:00
Ran Benita b65980ccff state: don't needlessly fetch the xkb_key
It's a leftover.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:41:59 +02:00
Ran Benita 1f4009d4e9 vmod: remove merge argument from HandleVModDef
It's unused and unneeded.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:41:59 +02:00
Ran Benita a75989b96e Omit struct '_Name' from non-recursive struct typedefs
Just a pet peeve.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:41:58 +02:00
Ran Benita 1401b0fb5e expr: don't allow "none" in LookupModIndex
LookupModMask handles this before calling LookupModIndex, and the only
other user in symbols.c doesn't handle this return value at all.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:41:58 +02:00
Ran Benita 239a5be10e keysym-utf: make keysym->unicode table a bit smaller
Saves a few kbytes, and unlikely to change.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:41:58 +02:00
Ran Benita dd29b14e11 Remove the XKB_NUM_VIRTUAL_MODIFIERS limit
Turn the virtual modifiers arrays in the keymap to a single darray,
which doesn't use this limit. The number of virtual modifiers is still
limited by the size of xkb_mod_mask_t, so we make sure not to go over
that.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:41:58 +02:00
Ran Benita 8016c6f4f1 state: simplify xkb_state_mod_index_is_active
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:41:58 +02:00
Ran Benita e5b6055b34 state: don't ignore type argument in xkb_state_mod_*_are_active
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:41:58 +02:00
Ran Benita 1a6b1e0788 state: fix bad EFFECTIVE check in *_is_active()
This is a regression introduced in ed78fbcb30.
XKB_STATE_EFFECTIVE is just a OR of the other states, so using & here is
completely wrong. So test/state shows for example:
    dumping state for LCtrl down:
            group English (US) (0): effective depressed latched locked
            mod Control (2): depressed latched locked
    dumping state for LCtrl + RAlt down:
            group English (US) (0): effective depressed latched locked
            mod Control (2): depressed latched locked
            mod Mod1 (3): depressed latched locked
    dumping state for RAlt down:
            group English (US) (0): effective depressed latched locked
            mod Mod1 (3): depressed latched locked
    dumping state for Caps Lock:
            group English (US) (0): effective depressed latched locked
            mod Lock (1): depressed latched locked
            led Caps Lock (0): active
    dumping state for Alt-Shift-+
            group English (US) (0): effective depressed latched locked
            mod Shift (0): depressed latched locked
            mod Mod1 (3): depressed latched locked
which is bogus.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:41:58 +02:00
Ran Benita fe1faa143e Use our types instead of int/uint32_t in a few places
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:41:58 +02:00
Ran Benita 1c88088766 Don't scan and parse useless maps
One physical xkb file may (and usually does) contain multiple maps. For
example, the us symbols file contains a map for every variant.
Currently, when we need a map from a file (specific or default), we
parse the entire file into a list of XkbFile's, find the map we want and
discard the others. This happens for every include statement. This is a lot
of unnecessary work; this commit is a first step at making it better.

What we do now is make yyparse return one map at a time; if we find what
we want, we can stop looking and avoid processing the rest of the file.

This moves some logic from include.c to parser.y (i.e. finding the
correct map, named or default). It also necessarily removes the
CheckDefaultMap check, which warned about a file which contains multiple
default maps. We can live without it.

Some stats with test/rulecomp (under valgrind and the benchmark):

Before:
==2280==   total heap usage: 288,665 allocs, 288,665 frees, 13,121,349 bytes allocated
compiled 1000 keymaps in 10.849487353s

After:
==1070==   total heap usage: 100,197 allocs, 100,197 frees, 9,329,900 bytes allocated
compiled 1000 keymaps in 5.258960549s

Pretty good.

Note: we still do some unnecessary work, by parsing and discarding the
maps before the one we want. However dealing with this is more
complicated (maybe using bison's push-parser and sniffing the token
stream). Probably not worth it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-30 15:26:00 +02:00
Ran Benita 26e685daae scanner: don't strdup the file name
We don't modify it and there's no way to modify the original in the
scanner_extra life time.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-30 15:25:56 +02:00
Ran Benita ee4ab30ea2 scanner: share code in XkbParse{File,String}
Some refactoring to prepare for changes in the parse() function.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-30 15:25:25 +02:00
Ran Benita 471ebad623 scanner: remove uselss 'last symbol' error message
It never shows something useful. Besides, you already get the line
number, which is enough.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-30 14:29:49 +02:00
Ran Benita 22684cd1dd parser: remove XkbCompMapList rule
This rule allows you to put several xkb_keymaps in one file.
This doesn't make any sense: only the default/first can ever be used,
yet the others are fully parsed as well.
Different keymaps should just be put in different files.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-30 14:20:16 +02:00
Ran Benita 3b5ada233b parser: remove XkbConfig rule
This rule allows you to write file maps as:
    xkb_keycodes
    <BLA> = 5;
    [...]
instead of the usual format which is:
    xkb_keycodes {
        <BLA> = 5;
        [...]
    };

This is not documented, It is also not used in xkeyboard-config, and I
have never run into it otherwise. It also only allows one map per file.

It *might* be used in some obscure place, but probably nothing we should
care about; the simplified grammar is more useful for us now.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-30 14:20:16 +02:00
Ran Benita 26cc2f400a Don't use %z printf format
Some libc's don't support it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-30 14:20:16 +02:00
Ran Benita ed1203dfef rules: always initialize idx variable
gcc didn't catch this one.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-30 12:44:52 +02:00
Ran Benita 32c19f4b44 keymap-dump: make it look better with long key names
Not worth messing around with too much, just make it legible.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-27 21:31:33 +02:00
Ran Benita 41a7fed3f8 Fix type of keycode in parser and ast
For some reason keycodes were listed under mapFlags in the yylval union.
Fix it and some sanity checks.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-27 21:12:08 +02:00
Ran Benita 3b389b15bf Don't limit key names to 4 characters
Currently you can't give a key in xkb_keycodes a name of more than
XKB_KEY_NAME_LENGTH (= 4) chars. This is a pretty annoying and arbitrary
limitation; it leads to names such as <RTSH>, <COMP>, <PRSC>, <KPAD>
etc. which may be hard to decipher, and makes it impossible to give
more standard names (e.g. from linux/input.h) to keycodes.

The purpose of this, as far as I can tell, was to save memory and to
allow encoding a key name directly to a 32 bit value (unsigned long it
was).

We remove this limitation by just storing the names as atoms; this lifts
the limit, allows for easy comparison like the unsigned long thing, and
doesn't use more memory than previous solution. It also relieves us from
doing all of the annoying conversions to/from long.

This has a large diffstat only because KeyNameText, which is used a lot,
now needs to take the context in order to resolve the atom.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-27 21:12:08 +02:00
Ran Benita 53cfe8c362 xkbcomp/keymap: use default interpret in ApplyInterpsToKey
This makes the code easier to follow and does more explicitly what the
xkblib spec says:
     If no matching symbol interpretation is found, the server uses a
     default interpretation where:
        sym =	0
        flags =	XkbSI_AutoRepeat
        match =	XkbSI_AnyOfOrNone
        mods =	0
        virtual_mod =	XkbNoModifier
        act =	SA_NoAction

If a level doesn't have any keysyms, we don't apply anything to it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-27 21:12:08 +02:00
Ran Benita 11df063265 state: add missing const in get_one_sym
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-27 21:12:08 +02:00
Daniel Stone 5aaf65b74e Add xkb_state_key_get_one_sym
The trivial wrapper around xkb_state_key_get_syms that every user to
date has implemented.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-27 23:27:49 +10:00
Daniel Stone 29a8b1ceac Fix size_t vs. %d warning
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-26 10:28:52 +10:00
Ran Benita cfa6d25cb5 symbols: get rid of autoType
The autoType variable is supposed to tell us whether the type was
explicitly specified by the user or was detected automatically according
to the keysyms. It then allows us to know whether to prints the type
when we dump the keymap to a string or not.

Right now it is not always set when we find an automatic type, according
to some apparently legacy rules. We change it to simply this: type
computed automatically? -> don't print.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-25 11:49:23 +02:00
Ran Benita 76478418bc symbols: separate type-finding logic from CopySymbolsDef
It's easier to follow this in isolation. Besides, previously the error
reporting wasn't done very well.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-25 11:35:59 +02:00
Ran Benita 5d2659267a keymap: remove some more unneeded macros
It clearer to just access the needed data directly.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 14:57:30 +02:00
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 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 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 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 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
Ran Benita e670d084a6 include: improve file-not-found error reporting
Only report it once, and not only for rules.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-16 15:20:18 +03:00
Ran Benita 09a4f2ca89 keycodes: add KeyNameInfo
Instead of keeping the two files and names arrays.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-15 13:45:55 +03:00
Ran Benita b979a5e95e keycodes: rename computedMin/Max to min/max_key_code
min/max_key_code is more descriptive and matches the names of these
field in xkb_keymap.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-15 02:25:47 +03:00
Ran Benita 4b69d6f71d keycodes: ignore explicit minimum/maximum statements
These statements are pretty pointless for us; we don't restrict keycodes
like X does, and if someone writes e.g. maximum = 255 but only has 100
keys, we currently happily alloc all those empty keys. xkbcomp already
handles the case when these statements aren't given, and uses a computed
min/max instead. We should just always use that.
(Of course since keycodes/evdev currently uses almost all of the
keycodes in the range it declares, including 255, this doesn't save any
memory for the common user right now).

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-15 02:09:34 +03:00
Ran Benita c53122cb96 symbols: remove useless grow_alloc of keys array
This just does a big, mostly too big, allocation to save about a dozen
malloc calls. Remove it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-14 21:53:27 +03:00
Ran Benita 9a27ac7253 state: use filter->priv instead of modifying the action
in xkb_filter_group_set_new.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-14 21:09:49 +03:00
Ran Benita 8098daa08f state: move filter initialization to the dispatcher
This removes all of the boilerplate from the *_new functions, and leaves
them just as simple functions which perform the effect of the action on state.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-14 21:09:49 +03:00
Ran Benita 2c19c9388b state: call xkb_filter_new from the dispatcher
Pass the new filter as a parameter instead of getting a new one in each
action function, and introducing a failure condition there.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-14 21:09:49 +03:00
Ran Benita 04f1b3be07 state: dispatch actions from a table
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-14 21:09:49 +03:00
Ran Benita 18a0ead587 Rename ACTION_TYPE_LAST to _ACTION_TYPE_NUM_ENTRIES
It's not really "last" per-se, and we use this other format in some
other enums.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-14 21:09:49 +03:00
Ran Benita 16425ffad9 state: don't keep the xkb_state in the filters
Just pass it as a parameter: to make state.c a bit less stateful.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-14 21:09:49 +03:00
Ran Benita c2570d51d1 state, map: constify references to xkb_key
Makes it clear that we treat the keys as immutible values in these
files.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-14 21:09:49 +03:00
Ran Benita 841f32230a state, map: use keycodes only for the API functions
The policy is now consistent: every API functions which recieves a
keycode should resolve it to an xkb_key first thing, and all the
internal functions use that instead of the keycode.
To facilitate it a bit, we move the KeycodeInRange check to XkbKey
itself, which returns NULL if the keycode is illegal.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-14 21:09:49 +03:00
Ran Benita 4d3d2ef004 rules: fix mmap failure handling
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-14 21:09:49 +03:00
Ran Benita 96c21e1577 Clean up Init/Clear functions
- The Clear* functions should just free the memory associated with the
  object. If the object is used again, it is Init'd again.
- s/Free/Clear if the actual pointer is not free'd.
- Zeroise object in Init and only initialize non-zero fields.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-14 21:09:48 +03:00
Ran Benita 7b5a1dd556 symbols: refactor CoypSymbolsDef
To make it easier to follow.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-14 00:07:55 +03:00
Ran Benita 4c16b39f31 symbols: FindAutomaticType only needs the context
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-14 00:07:55 +03:00
Ran Benita dd6124ca07 symbols: store actions from symbols in the right offset
This regression was introduced in 93ce9c7d4f. This meant that actions
specified inside key {} statments were always going to the first group.
But actions are almost never specified in xkb_symbols so this wasn't
noticed.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-13 21:09:48 +03:00
Ran Benita 898d6fd416 symbols: remove CopyKeyInfo
The code is better without it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-13 21:09:48 +03:00
Ran Benita 3abfe83e11 symbols: fix real/alias key merge ordering bug
Background:

The CopySymbolsDef has a comment on a couple of lines which supposedly
fixed a bug:

    /*
     * kt_index[i] may have been set by a previous run (if we have two
     * layouts specified). Let's not overwrite it with the ONE_LEVEL
     * default group if we dont even have keys for this group anyway.
     *
     * FIXME: There should be a better fix for this.
     */
    if (!darray_empty(groupi->levels))
        key->kt_index[i] = types[i];

But neither the comment nor the fix make any sense, because the kt_index
is indexed per group, i.e. each group gets its own type.
The original xkbcomp commit which added this (36fecff58) points to this
bug: https://bugzilla.redhat.com/show_bug.cgi?id=436626
which complains about -layout "ru,us" -variant "phonetic," not working
properly. And indeed when we try:
    sudo ./test/interactive -l ru,us -v
the first group doesn't get any syms for the main keys.

The problem (Clearly the fix above is useless):

The ru(phonetic) map is specified using aliases, e.g. LatQ, LatW instead
of AD01, AD02, etc. When combined with another layout which uses the
real names (AD01, AD02), the symbols code should recognize they are the
same key and merge them into one KeyInfo. The current code does that,
but it doesn't catch the case where the alias was processes *before* the
real one; so we get two KeyInfo's and the later one wins. So e.g. the
ru(phonetic) symbols are ignored.

The fix:

Before adding a new KeyInfo to the keys array, always replace its name
by the real name, which avoids the entire issue. Luckily this is done
pretty late so most error messages should still show the alias name.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-13 21:09:46 +03:00
Ran Benita 1d6bffc904 symbols: add CopySymbolsToKeymap
Like in the other sections.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-13 15:57:10 +03:00
Ran Benita 376e45eb6d symbols: remove mention of keycodes in CopySymbolsDef
Since now we only use the keycode in this function for logging, it's
better not to mention the keycode at all because the XkbKeyGetKeycode
macro is implemented using a dirty hack 0_0
The key name is sufficient to determine uniquely where to look.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-13 15:57:10 +03:00
Ran Benita 77ab928e92 symbols: remove unneeded recursion form CopySymbolsDef
This function does some funky stuff, which, as far as I can tell, was
needed to support the functionality of giving different keycodes the
same name and thus make them duplicates (MERGE_ALT_FORM). This stuff was
removed as useless in 0765064b3, but this leftover wasn't noticed.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-13 15:57:10 +03:00
Ran Benita ce5dbeff60 symbols: add LevelInfo
Add a LevelInfo to hold a single array of level specific info inside
a GroupInfo, instead of keeping the acts, symsMapIndex and
symsMapNumEntries arrays and the numLevels field separate and in sync.
This simplifies the code, and goes a long way toward making  the
key-merging code somewhat understandable. Also uses less memory.

Note that the syms array is still in GroupInfo for now, with the levels
holding offsets into it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-13 15:57:10 +03:00
Ran Benita ca87031861 symbols: make xkb_key::syms a plain array
It's never resized.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-13 15:57:10 +03:00
Ran Benita ee3ade3924 symbols: shorten symsMapNumEntries to uint from size_t
size_t is too wide for this in 64-bit machines.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-13 15:57:10 +03:00
Ran Benita 3cfcbbab38 symbols: consolidate group merging in MergeGroups
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-13 15:57:10 +03:00
Ran Benita db45d664d3 symbols: add GroupInfo
GroupInfo keeps all of the info for a specific group in one struct.
This is the old array-of-structures vs. structure-of-arrays, but in this
case readability wins. It would also help with lifting the
XkbNumKbdGroups limit, because we only have to worry about one array
(instead of 6).

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-13 15:57:10 +03:00
Ran Benita a9fa37396f keymap-dump: don't write spaces between multiple-syms-per-level
This can get a bit unwieldy.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-13 15:57:10 +03:00
Ran Benita 2a5b0c9dc1 symbols: use darray for ModMapEntry instead of list
There's no need for a list here.
[This also happens to be the last place list.h is used.]

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-13 15:57:09 +03:00
Ran Benita 886b0ca502 state: remove unused next field from xkb_filter
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-13 15:57:09 +03:00
Daniel Stone b4b40d73ad Copyright updates
With Dan Nicholson's permission (via email), update his copyright and
license statements to the standard X.Org boilerplate MIT license, as
both myself and Ran have been using.

Clean up my copyright declarations (in some cases to correct ownership),
and add copyright/license statements from myself and/or Ran where
appropriate.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-12 16:58:54 +01:00
Daniel Stone 14cd8c79cd utils: Replace DEC copyright with Ran's
This is not something I do often, but I have good reason here ...

utils.h has been totally rewritten since import, and now contains no
original DEC content.  Everything in here has been added by Ran, and I
do not believe that any lingering content from previous iterations is
substantial enough as to be copyrightable.

Replace DEC's copyright (and license with hostile advertising clause)
with Ran's boilerplate copyright and license statement.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-11 17:00:38 +01:00
Daniel Stone 82de180ede Remove unused ExprResolveKeyName
The only user was removed in 314965b1.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-11 15:09:37 +01:00
Daniel Stone 14741800a8 Constify keysym <-> Unicode lookup table
Before:
  text     data     bss     dec     hex filename
234422    11288    2304  248014   3c8ce obj-amd64/.libs/libxkbcommon.so.0.0.0

After:
  text     data     bss     dec     hex filename
240694     5016    2304  248014   3c8ce obj-amd64/.libs/libxkbcommon.so.0.0.0

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-11 14:52:27 +01:00
Daniel Stone 28bd10cee7 kbproto unentanglement: drop dependency
\o\ \o/ /o/

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-11 14:10:41 +01:00
Daniel Stone fa1ea9a5bf kbproto unentanglement: XkbGeomPtsPerMM
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-11 14:09:20 +01:00
Daniel Stone e60e9523c6 kbproto unentanglement: XkbExplicit*Mask
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-11 14:05:42 +01:00
Daniel Stone 2eab7efc13 kbproto unentanglement: XkbSI_AutoRepeat
That was the only interp flag, so just turn it into a straight boolean.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-11 12:32:18 +01:00
Daniel Stone a8d462e366 kbproto unentanglement: XkbSI match flags
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-11 12:28:29 +01:00
Daniel Stone ed9fd5beb0 kbproto unentanglement: control actions
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-11 12:20:21 +01:00
Daniel Stone 6573aca0b2 kbproto unentanglement: XkbMaxShiftLevel
... by removing its only use.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-10 21:05:17 +01:00
Daniel Stone 32bf405376 kbproto unentanglement: Xkb{Wrap,Clamp,Redirect}IntoRange
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-10 21:02:49 +01:00
Daniel Stone 461f8a7697 actions: Remove PointerDefault affect field
This was always set to affect the default button, so no need for it.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-10 20:40:32 +01:00
Daniel Stone 70c775f69d kbproto unentanglement: action flags
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-10 20:38:46 +01:00
Daniel Stone b6e0457195 kbproto unentanglement: XkbLC_*
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-10 20:16:05 +01:00
Daniel Stone 830fe67132 kbproto unentanglement: XkbIM_*
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-10 20:07:54 +01:00
Daniel Stone 0b2506db12 kbproto unentanglement: action types
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-10 19:23:36 +01:00
Daniel Stone 314965b1f0 Remove deprecated actions
We didn't do anything with ISO_Lock, ActionMessage, RedirectKey, and the
device-specifying variants of the pointer actions, so remove those.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-10 19:23:35 +01:00
Daniel Stone b04d896ab2 kbproto unentanglement: XkbNumVirtualMods
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-10 19:23:35 +01:00
Daniel Stone 74ec4c1c3f kbproto unentanglement: XkbNumIndicators
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-10 19:23:35 +01:00
Daniel Stone 4b8ceae91f kbproto untanglement: XkbKbdNumGroups
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-10 19:23:35 +01:00
Daniel Stone f5dffd2b6e kbproto untanglement: XkbKeyNameLength
Define it ourselves as XKB_KEY_NAME_LENGTH and use that, instead of the
one from XKB.h.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-10 18:26:20 +01:00
Ran Benita 3b6b214c78 rules: use goto instead of state variable
There's no noticeable speed difference, but I think it's nicer and more
explicit than the previous code. Some people just don't like goto,
though..

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-05 16:37:43 +03:00
Ran Benita 0071227e7f rules: rewrite
Rewrite the rules file parser for clarity, performance and memory usage
reduction. The previous implementation was quite hard to navigate and
did a lot of unnecessary work and copying.
This implementation keeps along just the state necessary, and doesn't
perform any copying of the file's content (although the entire file is
mmap'ed as before). Hopefully it's also easier to understand, has better
documentation, and better error checking and reporting. We try to
reproduce the previous behavior in every case.

Note: the diff is pretty confusing; it's likely better to look at the
file directly.

Benchmarks:
    On an old 32-bit Intel processor.
    gcc -O2 -pg
    ./test/rulescomp bench
    grof test/rulescomp

    Before:
        compiled 1000 keymaps in 14.863564304s
        %   cumulative   self              self     total
        time   seconds   seconds    calls  ms/call  ms/call  name
        49.33      4.43     4.43 30610000     0.00     0.00  yylex
        17.93      6.04     1.61    31000     0.05     0.22  yyparse
        6.57      6.63     0.59     1000     0.59     0.59  load_rules
        3.23      6.92     0.29  3637000     0.00     0.00  AppendStmt
        2.45      7.14     0.22   472000     0.00     0.00  AddKeySymbols
        2.12      7.33     0.19  3591000     0.00     0.00  atom_intern
        2.12      7.52     0.19   518000     0.00     0.00  FindNamedKey
        2.00      7.70     0.18   230000     0.00     0.00  FreeStmt
        1.78      7.86     0.16     1000     0.16     0.17  UpdateModifiersFromCompat
        1.34      7.98     0.12   732000     0.00     0.00  AddKeyName
        1.34      8.10     0.12                             __x86.get_pc_thunk.bx

    After:
        compiled 1000 keymaps in 13.874666269s
        %   cumulative   self              self     total
        time   seconds   seconds    calls  ms/call  ms/call  name
        49.82      4.26     4.26 30610000     0.00     0.00  yylex
        22.22      6.16     1.90    31000     0.06     0.22  yyparse
        2.92      6.41     0.25  3591000     0.00     0.00  atom_intern
        2.57      6.63     0.22     1000     0.22     0.25  xkb_components_from_rules
        2.11      6.81     0.18  3637000     0.00     0.00  AppendStmt
        2.11      6.99     0.18   230000     0.00     0.00  FreeStmt
        1.99      7.16     0.17   518000     0.00     0.00  FindNamedKey
        1.99      7.33     0.17     1000     0.17     0.17  UpdateModifiersFromCompat
        1.99      7.50     0.17                             __x86.get_pc_thunk.bx
        1.52      7.63     0.13   150000     0.00     0.00  AddInterp
        1.40      7.75     0.12   472000     0.00     0.00  AddKeySymbols

    On a newer 64-bit Intel processor.
    gcc -O2
    ./test/rules-file bench

    Before:
        processed 20000 times in 15.940546625s

    After:
        processed 20000 times in 5.295026345s

Allocations:
    gcc -O2
    valgrind test/rulescomp

    Before:
    total heap usage: 257,519 allocs, 257,519 frees, 14,766,529 bytes allocated

    After:
    total heap usage: 240,756 allocs, 240,756 frees, 14,007,886 bytes allocated

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-05 16:37:02 +03:00
Ran Benita 54d1d5ed5a compat: make LEDInfo a wrapper around xkb_indicator_map
instead of duplicating the fields. The same is done in SymInterpInfo
which wraps xkb_sym_interpret.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-05 13:47:46 +03:00
Ran Benita 5f613988c8 Fold keymap->indicator_names into keymap->indicators
This makes sense, since giving a name to an indicator 'activates' the
indicator_map in that index.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-04 17:20:46 +03:00
Ran Benita af2a8b3a37 Unify some string tables from xkbcomp, text and keymap-dump
We move the LookupEntry struct from expr.h to text.h, along with most of
the lookup tables. This makes them available everywhere.
Looking up a value in the LookupEntry format is slower than direct index
mapping, but it allows multiple names per value (with the canonical one
being first) and "all"- and "none"-type masks. These functions are not
used anywhere efficiency matters.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:31:13 +03:00
Ran Benita 7ae0c6bac4 Convert rest of names in xkb_keymap back to atoms
These were kept as atoms, but since the keymap was exposed in the API,
we converted them to strings; no the keymap is no longer exposed, so we
can go back to atoms. They make the keymap smaller (at least on 64-bit
machines) and the comparisons faster.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:31:13 +03:00
Ran Benita 1a9968839e expr: make ResolveString return an atom
Almost all callers do xkb_atom_intern on the currently returned string,
while ResolveString converts the atom to the string to begin with...
uselss double work.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:31:13 +03:00
Ran Benita 7aa31097bf atom: add xkb_atom_lookup
This will only lookup the string and return the atom if found; it will
not intern it if not. This is useful when e.g. getting a string from the
user (which may be arbitrary) and comparing against atoms.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:31:13 +03:00
Ran Benita 651e1dab04 atom: separate lookup logic from atom_intern
This would allow us to add a non-interning xkb_atom_lookup function.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:31:13 +03:00
Ran Benita f205d0f9b6 atom: make type and name of the 'a' field clearer
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:31:13 +03:00
Ran Benita 7f04ffc4d3 rules: fix check for appending '|' character when applying
There are two ways to separate multiple files in XKB include statements:
'+' will cause the later file to override the first in case of conflict,
while '|' will cause it augment it (this is done by xkbcomp). '!' is
unrelated here.
Since '|' is practically never used, this wasn't noticed.

In the modified test, the '|some_compat' previously was just ignored.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:31:12 +03:00
Ran Benita 41472822b6 Use XKB_MOD_INVALID instead of XkbNoModifier
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:31:12 +03:00
Ran Benita 300f3fb1e0 Don't printf NULL strings
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:31:12 +03:00
Ran Benita bce90d5b2c xkbcomp: add debug messages of the RMLVO and KcCGST
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:31:12 +03:00
Ran Benita 8e6fce9b22 include: document ParseIncludeMap better
The format of the include statment is not explained anywhere, the code
is confusing and the comments misleading. Try to explain it better.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:31:12 +03:00
Ran Benita 799cc064d3 include: properly use the default map if none is found
For some reason this piece of code wasn't copied from xkbcomp, which
causes all of the warnings like these:
Warning:       No map in include statement, but "pc" contains several; Using first defined map, "pc105"

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:31:12 +03:00
Ran Benita 8d7d9792d1 log: replace "priority" by "level" everywhere
Now that we don't use syslog, "level" does sound more commonplace. We
should change it while there is still nobody using it.
Also leave some space between the integers of the xkb_log_level enum
values, if we ever need to shove more in between.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:31:12 +03:00
Ran Benita 95d4fb9e4b action: fix LookupEntry for "lockdevbtn"
xkbcomp has that bug as well, guess no one uses it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:31:12 +03:00
Ran Benita 7e0c49e084 action: remove redundant check
The NoAction handler always errors out with the same message.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:25:20 +03:00
Ran Benita 87bfd97333 action: keep array of default actions, instead of list of changes
The implementation of changing the default properties of actions, e.g. a
statements such as (from test/data/compat/basic):
    setMods.clearLocks= True;
    latchMods.clearLocks= True;
    latchMods.latchToLock= True;
works by keeping a list of ActionInfo's, each containing the neccesary
info from each statement, and then when some action comes up (e.g. in an
interpret statment) it goes through the list, and applies the relevent
ActionInfo's to the newly-constructed xkb_action.

Instead of doing this, we add a struct ActionsInfo, which contains an
array of xkb_actions, one for each type. When a default changing
statement appears, we change the action in the array; when a new action
comes up, we just copy from the array. This is simpler to figure out,
and pretty straightforward.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:25:20 +03:00
Ran Benita 4ca85c7b3b action: disallow setting an action_field default for all types
Currently where it is possible to write:
    setMods.clearLocks = True;
It's also possible to write:
    action.clearLocks = True;
This will set the default value for the clearLocks action field for
*all* action types, as opposed to just setMods in this case. If
subsequently an action is used for which this field does not make sense,
it will error out.
This doesn't make any sense, because any given field is only possible by at
most 3 or 4 action types... which you might as well write explicitly and
avoid the side effect mentioned above.
Needless to say this is one of xkbcomp's "hidden features" and is not
used anywhere; remove it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:25:20 +03:00
Ran Benita ba9f66bda3 action: clean up formatting of extern functions
Make it a bit easier to understand what they do.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:25:20 +03:00
Ran Benita 1736e7daad types: don't strdup a default name
None of the other files does that.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:25:20 +03:00
Ran Benita 149e1b2f0d types: use darray for KeyTypesInfo instead of list
Simpler, uses less memory and more efficient.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:25:19 +03:00
Ran Benita 8654d36e7a types: remove outdated comments
The code is pretty straightforward now...

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:25:19 +03:00
Ran Benita db639be6df keymap: optimize FindInterpsForKey a bit
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:25:19 +03:00
Ran Benita 872e15e52c keymap: refactor ApplyInterpsToKey
There's really not much to explain what the function used to do there...

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-03 10:13:42 +03:00
Ran Benita 8c1b1b0e9e Add xkbcomp/keymap.c and move some code there
Add CompileKeymap to do most of what compile_keymap_file does now, and
move UpdateKeymapFromModifiers along with it from (mostly unrelated)
compat.c.
Also rename UpdateKeymapFromModifiers to UpdateDerivedKeymapFields,
because it does more than update the modifiers.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita 591df1156d Move enum xkb_file_type to xkbcomp/ast.h
This is a more suitable place for this enum, since it's internal to
xkbcomp.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita efc2d74141 xkbcomp: clean up compile_keymap function
We make the xkb_file_type enum sequential instead of masks, and then
we don't have to repeat the file types several times in the function.
Makes the code cleaner.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita 82491d5fd1 map, state: check for KeycodeInRange only in API functions
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita 06d7803a6d state: fix mod_names_are_active
This function was always returning -1.
Adding a test, we see that test/state.c treat the is_active functions as
returning booleans, which would treat -1 as success, so we test for > 0
instead (most users would probably get this wrong as well...).
Also update the documentation for the are_active functions, and add a
ATTR_NULL_SENTINEL for gcc __attribute__((sentinel)).

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita 9f0c016063 state: fix type confusion within xkb_state_update_mask
idx should be xkb_mod_index_t, while mod is the mask.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita ae576e85b7 state: remove unneeded optimization
The code that follows does exactly that.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita a45b7d7559 state: light indicator when either condition is satisfied
For the indicator to be set, it is sufficient for at least one of the
group, modifier, or control state to match; this is in line with the
xkblib spec, section 8.2 and ComputeAutoState() in xserver/xkb/xkbLEDs.c
(though the xserver implementation differs from the spec on some
points...).

This also adds a tiny optimization to skip the entire check if the mask
is empty.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita d1b476a387 state: fix led_update_all group mask calculation
The one above uses which_mods, this one should use which_groups.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita 9ba5ac0ec0 keycodes: remove outdated comments
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita bebad402e4 keycodes: use darray for aliases instead of list
Uses slightly more memory, but worth it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita 518aff6d7b keycodes: use array for indicator names instead of list
Using a simple array here to mirror keymap->indicator_names makes much
more sense, and is simpler.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita be78b8264d keycodes: ignore "virtual" in indicators
The distinction between real/virtual indicators is useless for us, we
can just ignore it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita 4c56d4d9c0 symbols: call deinit functions Clear instead of Free
Everywhere else Free is reserved for when the argument is free'd as
well.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita 2eba51c0f6 symbols: remove comparison of unsigned >= 0
clang warning.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita 3d305bd0cb vmod: remove outdated comments
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita b3aced7e22 vmod: ClearVModInfo doesn't need the keymap
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita ab1566cd6b vmod: remove useless keymap initialization
keymap->vmods is not touched until UpdateModifiersFromCompat,
where it initialized and used.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita f410622b4b vmod: remove support for resolving integer to virtual modifier
This is only relevant to the virtualModifier= statement in interpret
statements in xkb_compat. The current code allows to write e.g.
    virtualModifier = 4
to get the virtual modifier whose index happens to be 4 (possibly
declared in other files or sections, i.e. xkb_types). Doing this is
undeterministic, will break without notice, and not used anywhere.
Don't allow it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita d3ddcf70e8 expr: move op_type/value_type_to_string functions to ast
Generally the enum-to-string function should appear where the enum is
defined.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita b9c87eb710 vmod: remove support for direct vmod -> real mod mapping
The current code supports statements such as:
    virtual_modifiers NumLock = Mod2;
This would set the mapping from the NumLock vmod to the Mod2 real mod
directly, without going through the virtualModifier field in an
interpret statement (in xkb_compat) or vmods field in a key statement
(in xkb_symbols).

This is undocumented, unused and complicates things, so remove it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita eaa50c450b xkbcomp: seperate keymap-copying code from Compile functions
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:09 +03:00
Ran Benita 6738d30036 compat: only compute 'bool report' once
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 19:17:08 +03:00
Ran Benita e5fdbcbb99 compat: disallow changing global defaults from within an interpret
It's currently possible to write something like this:
    interpret Num_Lock+Any {
        virtualModifier = NumLock;
        action = LockMods(modifiers=NumLock);
        !indicator.allowExplicit;
    };
The final statement has the same effect as writing it in the global file
scope, which changes the default indicator (which all subsequent
indicators start off as). This very strange and also unused; if someone
does it he probably expects it to affect only the local scope, and he
might then get unexpected behavior. So don't allow it.

Also, HandleInterpVar is clearly a misnomer (as it can also change
indicator defaults) so rename it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 18:53:01 +03:00
Ran Benita c9466b32df compat: use darray instead of list for interps
No need for a list here.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 18:53:01 +03:00
Ran Benita 8c6694fd58 compat: remove "flags" field from xkb_indicator_map
We don't set this field any more.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-02 18:52:46 +03:00
Ran Benita 6e676cb7d8 compat: ignore "allowExplicit" in indicator statements
Using !allowExplicit sets the XkbIM_NoExplicit flag of the indicator,
which means that an XKB client cannot change the state of the indicator
using e.g. XkbSetNamedIndicator().
We do not support changing the state of an indicator; furthermore doing
it is probably only useful in conjunction with led-drives-keyboard
behavior, which we also do not support. This is because setting an
indicator without led-drives-keyboard would make the indicator and the
modifier/group it's bound to to get out of sync.

We can re-add this if we need this info.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-01 10:59:47 +03:00
Ran Benita d573600da0 compat: ignore "ledDrivesKbd" in indicator statements
We don't support it, as mentioned in the README, so we should stop
processing it and print a message about it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-01 10:59:47 +03:00
Ran Benita 9de067aad4 compat: ignore "group" (compatibility) statements
Group compatibility statements are like the following:
    group 3 = AltGr;
This currently results in:
    keymap->groups[2].mask = <real mod mapped from AltGr vmod>
And we don't do any thing with this value later. The reason it exists in
XKB is to support non-XKB clients (i.e. XKB support disabled entirely in
the server), which do not know the concept of "group", and use some
modifier to distinguish between the first and second keyboard layouts
(usually with the AltGr key). We don't care about all of that, so we can
forget about it.

One artifact of this removal is that xkb_map_num_groups no longer
works, because it counted through keymap->groups (this wasn't entirely
correct BTW). Instead we add a new num_groups member to the keymap,
which just hold the maximum among the xkb_key's num_groups. This also
means we don't have to compute anything just to get the number of
groups.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-01 10:59:47 +03:00
Ran Benita 7f75502f18 compat: get rid of BindIndicators
Now that 1fba6189e67 removed support for binding indicator maps by index
instead of name, we can remove some more magic which happens now: if an
indicator map specifies an indicator name which was not previously
declared in a 'indicator 5 = "Caps Lock"'-like statement in
xkb_keycodes, we can just look at the next free index and assign it.

This also allows us to use a darray for the LEDInfo's instead of a list.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-01 10:59:47 +03:00
Ran Benita 02de2a3e74 compat: ignore "index" field in indicator statements
The current code allows to set the "index" field in an indicator
statment's body. This would bind the indicator to the specified index,
instead of by name (which was declared previously in xkb_keycodes).
Doing this is a bad idea, for the same reasons as in 3cd9704, and is
also happily not used anywhere.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-01 10:59:46 +03:00
Ran Benita 65c4a71731 compat: remove dead NoAutomatic code
The xkblib spec, table 7.1 (indicators), says:
XkbIM_NoAutomatic: Xkb does not automatically change the value of the
                   indicator based upon a change in the keyboard state,
                   regardless of the values for the other fields of the
                   indicator map.

xkbcomp (the real one) never actually implemented a way for an indicator
statement to set this flag, so it's just dead unused code. We definitely
don't want to implement it ourselves, so remove any mention of it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-01 10:59:46 +03:00
Ran Benita 16f2de8bf0 compat: ignore "locking" field in sym interprets
This field is used in conjunction with key behaviors, which we don't
support since c1ea23da5. This is also unused in xkeyboard-config.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-01 10:59:46 +03:00
Ran Benita e9aa84f311 compat: small changes
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-01 10:59:46 +03:00
Ran Benita 4fec91cbbc compat: add general overview
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-01 10:59:46 +03:00
Ran Benita 79a2cc09cc action: convert action field type to enum
We can also hide the ActionInfo definition inside action.c.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-01 10:59:46 +03:00
Ran Benita 8f1ee62904 types: add "Effects on keymap" to overview
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-01 10:59:46 +03:00
Ran Benita cdc228eaf6 Organize xkbcomp/ header files
Various non-functional changes:
- Re-add keycodes.h and move some stuff there.
- Add parser-priv.h for internal bison/flex stuff.
- Don't include headers from other headers, such that file dependencies
  are immediate in each file.
- Rename xkbcomp.h -> ast.h, parseutils.{c,h} -> ast-build.{c,h}
- Rename path.{c,h} -> include.{c,h}
- Rename keytypes.c -> types.c
- Make the naming of XkbFile-related functions more consistent.
- Move xkb_map_{new,ref,unref} to map.c.
- Remove most extern keyword from function declarations, it's just
  noise (XKB_EXPORT is what's important here).
- Append XKBCOMP_ to include guards.
- Shuffle some code around to make all of this work.

Splitting this would be a headache..

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-01 10:58:10 +03:00
Ran Benita 3634b1565e Allocate xkb_component_names on stack
Instead of malloc'ing it as well. Also improve the error handling.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-01 10:58:10 +03:00
Ran Benita e535352828 Move ISEMPTY to utils.h
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-01 10:58:10 +03:00
Daniel Stone f491285a5f Move 'no symbols defined for ...' message to a warning
Shut up shut up shut up shut up shut up shut up.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-08-11 18:17:00 +02:00
Ran Benita ec2172f31b Combine a couple of macros
Easier to see what it does without the trivial macros.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-10 22:49:46 +03:00
Ran Benita 4c34bda15a action: get rid of xkb_any_action
And use union xkb_action instead. We add xkb_private_action, which is
the same as xkb_any_action, but only used where the intention is clear.
This should take care of whatever sizing changes the action struct might
have.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-10 22:42:17 +03:00
Ran Benita 600caac33a Remove XkbKeyTypeIndex and widen index type
We don't need the macro, and using char for the kt_index is imaginably
too small.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-10 22:06:12 +03:00
Ran Benita 87dff888ab Store actions inside struct xkb_key
Cuts out a lot of useless redirection and space.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-10 21:54:33 +03:00
Ran Benita 7bcc5fabbd keycodes: save context in Info, not keymap
We don't need the keymap in this case, just makes things more verbose.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-10 13:49:20 +03:00
Ran Benita 0cc5ae33b5 Remove xkbcomp/misc.c
The KeyName functions are more appropriate in keycodes.c.
The ProcessIncludeFile can go to path.c along with the other functions
dealing with includes.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-10 13:49:20 +03:00
Ran Benita f7c9d749d3 Remove left over keycodes.h
For some reason we still track this file in git even though we don't use
it any more.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-10 13:49:20 +03:00
Ran Benita 34e690ceeb Remove AutoKeyNames feature
If this keymap flag is set, whenever a key name appears in one of the
sections which does not exist (i.e. has not been declared in keycodes),
it finds the first unused keycode and attaches it that name.

This might have been useful when you could compile the symbols section
or geometry section without a keycodes section, but we don't support
this anymore. It's also pretty useless for any real work, because the
user has no way of knowing the keycode and so it will never be used.
Finally the only obscure way left to set this flag is by including a
keycodes file called "computed".

Just remove it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-10 13:49:20 +03:00
Ran Benita ef518a10af map: share some code
Make more extensive use of get_entry_for_key_state, and add
key_get_consumed to use in the other consume functions.

There's also a slight change in the consumed mods calculations, where
we use entry->mods.mask instead of type->mods.mask. The original was
copied from what libX11 does but what we do now is more logically
correct. The result is exactly the same though because:
type->mods.mask ⊇ entry->mods.mask ⊇ entry->preserve.mask

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-10 13:49:19 +03:00
Ran Benita 75853ed66b Use XKB_{GROUP,LEVEL}_INVALID instead of -1 for errors
The group/level types are unsigned, so it's odd to return -1 for them.
Instead use their invalid values (which happen to be == -1).

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-10 13:45:58 +03:00
Ran Benita 6d61e39d20 state: use global static const for fake action
Requires constifying some arguments.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-10 13:45:58 +03:00
Ran Benita 07b18bde17 Modernize struct xkb_mods
Currently xkb_mods has the following members:
- uint8_t real_mods - 8 X11 core mods
- xkb_mod_mask_t vmods - 16 virtual mods, zero-based index
- xkb_mod_mask_t mask - the computed effective *real* modifier mask,
  basically a cache for the first two which is:
  real_mods | real mods computed from vmods

Our API acts on masks which combine the real_mods and vmods into a
single value, which is:
8 first bits real mods | 16 next bits virtual mods
(XkbNumModifiers = 8, XkbNumVirtualMods = 16). This is also the format
which ResolveVModMask uses (which is where all the modifier masks really
"come from", e.g. "Shift+Lock+Level5" -> xkb_mod_mask_t).

What the code does now after getting the mask from ResolveVModMask, is
to break it into real part and virtual part and store them seperately,
and then join them back together when the effective mask is calculated.

This is all pretty useless work. We change xkb_mods to the following:
- xkb_mod_mask_t mods - usually what ResolveVModMask returns
- xkb_mod_mask_t mask - the computed mask cache
And try to consistently use the word "mods" for the original,
non-effective mods and mask for the effective mods (which can only
contain real mods for now, because things break otherwise).

The separation is also made clearer. The effective masks are computed by
UpdateModifiersFromCompat after all the sections have been compiled;
before this the mask field is never touched; after this (i.e. map.c and
state.c) the original mods field is never touched. This single execption
to this rule is keymap-dump.c: it needs to print out only the original
modifiers, not computed ones. This is also the reason why we actually
keep two fields instead keeping one and modifying it in place.

The next logical step is probably to turn the real mods into vmods
themselves, and get rid of the distinction entirely (in a compatible
way).

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-10 13:45:58 +03:00
Ran Benita 45cd92b4d3 Fix xkb_keymap::vmods type
It maps a vmod to a mask, of course.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-09 02:33:51 +03:00
Ran Benita 41478b4309 types: don't compute effective masks here as well
After compiling all of the sections, UpdateModifiersFromCompat does all
of the vmod -> real mods translations, including types/kt_entries.

keytypes.c also has code that does that, but it's unneeded:
- Later sections don't look at their effective masks, so doing it later
  is fine.
- When this code is executed, the vmods -> real mods mapping is empty
  (that is set up later), so VModsToReal has no effect here.
So we can just remove it.

However UpdateModifiersFromCompat didn't update the preserve mask, so do
that.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-09 01:57:17 +03:00
Ran Benita fafc1132d2 types: get rid of PreserveInfo
We don't need the indirection. We store the preserve mask directly in
the entry, and create a new one if it doesn't exists (which is exactly
what the current code does in a roundabout way).

Incidentally this fixes a bug where the effective modifier mask of the
entries' preserve[] wasn't calculated, so the virtual modifiers had no
effect there.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-09 01:57:11 +03:00
Ran Benita 0f1ca360f1 keymap-dump: use VModMaskText
The difference between the two are irrelevant here.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-09 01:55:59 +03:00
Ran Benita 5a51ce8b36 Fix warning
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-09 01:55:30 +03:00
Daniel Stone 2f1f1bca5b Add xkb_map_mod_mask_remove_consumed
A fairly simple helper which, given an xkb_mod_mask_t, removes all
modifiers which are consumed during processing of a particular key.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-08-08 16:23:31 +02:00
Daniel Stone 5e276adb92 Add xkb_log_level enum rather than using syslog
Instead of relying on people including syslog.h, add our own
XKB_LOG_LEVEL_* defines.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-08-08 16:23:31 +02:00
Daniel Stone d5f725f69a Rules: mmap() rules file instead of using getc()
Good for a small performance win on my system.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-08-08 16:23:31 +02:00
Daniel Stone 5968c5e6a8 Always have at least one level in types
The ONE_LEVEL definition from xkeyboard-config doesn't specify any
actual levels, but there's an implicit (anything unmatched) -> Level1
rule.  Given this, each type actually has at least one level, whether or
not it specifies anything.

Fixes stringcomp.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-08-08 16:23:30 +02:00
Daniel Stone 28733c54f9 IncludeStmt: Remove useless 'path' member
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-08-08 16:23:30 +02:00
Daniel Stone 4bb8b6b1cf Remove unused vmodmask calculation
This was basically an open-coded VModsToReal, which we were using in the
line immediately below.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-08-08 16:23:30 +02:00
Daniel Stone 42b2c93433 Print failed include paths on failure to find rules
Thus giving a hint as to which directory we're trying to find.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-08-08 16:23:30 +02:00
Daniel Stone 226cb22c80 Move xkb_context struct to xkb-priv.h
So we can print more intelligent debugging messages without needing
helper functions for the failed_includes array.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-08-08 16:23:30 +02:00
Daniel Stone 3e8370b028 context: Maintain list of failed include paths
Keep around a list of paths we tried to add but couldn't.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-08-08 16:23:30 +02:00
Daniel Stone 53e2db6ba9 More useful error message on failing RMLVO -> KcCGST
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-08-08 16:23:30 +02:00
Daniel Stone 41d97df951 Move more of xkb_map_new_from_rmlvo into compilation
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-08-08 16:23:30 +02:00
Daniel Stone 5cf4f51044 Staticise xkb_map_new_from_kccgst
We didn't expose this to the outside world, and its only trivial user
was xkb_map_new_from_rules.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-08-08 16:23:30 +02:00
Daniel Stone 04253fb2eb Add support for default rules/model/layout
Right now it just comes from build-time, but eventually this should be
sourced from configuration files at runtime too.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-08-08 13:30:24 +02:00
Daniel Stone 26c01d3bb4 Warning fixes
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-08-08 13:30:24 +02:00
Ran Benita 1a930bf256 Add API to query whether a modifier is consumed
Currently the user has no way of knowing which of the active modifiers
have been used in the translation of a keycode to its keysyms. The use
case is described in the GTK docs: say there's a menu accelerator
activated by "<Alt>+". Some layouts have "+" shifted, and some have it
on the first level. So in keymaps where "+" is shifted, the Shift
modifier is consumed and must be ignored when the user is testing
for "<Alt>+". Otherwise, we may get "<Alt><Shift>+" and the accelerator
should not actually fire.

For this we also use the preserve[] information in the key types, which
can forces us to report modifiers as unconsumed even if they were used
in the translation. Until now we didn't do anything with this
information.

The API tries to match its surronding. It's not very efficient but this
can be fixed.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-08 10:03:38 +03:00
Ran Benita 262bf97f9b types: remove default type
The default type is copied over for each new key type to build on.
Further, it can be modified from within the xkb_types section itself,
with statements such as "type.modifiers = Lock" which affect all
subsequent type definitions.

The default type is (well, by default) just the simplest one level type
possible, with name "default". When no types are defined at all, it is
copied over to the keymap as the single type.

xkeyboard-config never changes the default type. There is also no sane
use case for doing so; changing any thing there doesn't make sense. So
instead of doing all the hard work of maintaining and copying this type,
which is practically never used, just remove it and initialize new types
appropriately.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-08 10:03:37 +03:00
Ran Benita d327d3e27b types: store atoms instead of strings for level and type names
We don't use these strings much, so storing them in the manner they
were compiled saves some copying and space.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 13:20:37 +03:00
Ran Benita b2fba7305c types: use regular array for map entries
This array is only initialized once.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 13:20:37 +03:00
Ran Benita 8ccfee82ec types: use regular array for types
The current code doesn't resize it any more.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 13:20:37 +03:00
Ran Benita a681c6240d types: remove DeleteLevel1MapEntries
If there is no map entry for some modifier combination, the default is
to use level 1. The removed code is an optimization to save some space
by removing these entries. But it doesn't actually save any space, and
did not in fact remove all level 1 entries (it walks the array while
modifying it so there's an off-by-one error).

We can instead keep them in the types but just not print them in
keymap-dump.c, to get about the same behavior.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 13:20:37 +03:00
Ran Benita 233d85c427 types: move preserve directly into xkb_kt_map_entry
Currently each xkb_key_type has a preserve array, which is only allocated
if a preserve[] statement is specified in the type. In this case each map
entry has an element in the array.

The space savings are negligible; put this field where it logically
belongs.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 13:20:37 +03:00
Ran Benita 6b75dd2dcb Fix virtual modifiers mask extraction
The calculations were performed incorrectly in several places,
specifically shifting by 16 instead of 8 (= XkbNumModifiers) and masking
with 0xff instead of 0xffff.

More stuff that probably never worked as intended. This also makes these
more grep-able when we remove the vmods/real_mods separation.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 13:20:37 +03:00
Ran Benita 796dccabe8 types: small changes
Just make things easier to follow, no functional changes.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 13:20:37 +03:00
Ran Benita 4c00278c82 Remove xproto build dependency
Very little left to do for this.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 13:20:37 +03:00
Ran Benita b0b11c4e2e types: don't use canonical/required types
Xkb required every keymap to have at least the four following canonical
types: ONE_LEVEL, TWO_LEVEL, ALPHABETIC, KEYPAD. This is specified in
e.g. the kbproto spec and XkbKeyTypesForCoreSymbols(3) man page.

If these types are not specified in the keymap, the code specifically
checks for them and adds them to the 4 first places in the types array,
such that they exist in every keymap. These are also the types (along
with some non-required 4-level ones) that are automatically assigned to
keys which do not explicitly declare a type (see FindAutomaticType in
symbols.c, this commit doesn't touch these heuristics, whcih are also not
very nice but necessary).

The xkeyboard-config does not rely on the builtin xkbcomp definitions of
these types and does specify them explicitly, in types/basic and
types/numpad, which are virtually always included.

This commit removes the special behavior:
- The code is ugly and makes keytypes.c harder to read.
- The code practically never gets run - everyone who uses
  xkeyboard-config or a keymap based upon it (i.e. everyone) doesn't need
  it. So it doesn't get tested.
- It mixes policy with implementation for not very good reasons, it
  seems mostly for default compatibility with X11 core.
- And of course we don't need to remain compatible with Xkb ABI neither.

Instead, if we read a keymap with no types specified at all, we simply
assign all keys a default one-level type (like ONE_LEVEL), and issue
plenty of warnings to make it clear (with verbosity >= 3). Note that
this default can actually be changed from within the keymap, by writing
something like
    type.modifier = Shift
    type.whatever_field = value
in the top level of the xkb_types section. (This functionality is
completely unused as well today, BTW, but makes some sense).

This change means that if someone writes a keymap from scratch and
doesn't add say ALPHABETIC, then something like <AE11> = { [ q Q ]; }; will
ignore the second level. But as stated above this should never happen.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 13:20:37 +03:00
Ran Benita be82f08221 types: add a general overview
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 13:20:37 +03:00
Ran Benita c1ea23da5c symbols: remove support for key behaviors
The possible key behaviors are:
KB_RadioGroup, KB_Overlay1, KB_Overlay2: already removed support for
these.
KB_Lock (with or without KB_Permanent): used to ignore key presses or
releases to simulate and deal with some legacy keyboard behaviors
(like keys that physically lock). Not used at all.

We already ignore them while processing key events in state.c, so make
it official.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 11:09:42 +03:00
Ran Benita 7c89f34e63 keycodes: small changes
to make it a bit nicer.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 11:09:42 +03:00
Ran Benita b2c4331ac3 Handle key names consistently
We treat the key names as fixed length, non NUL terminated strings of
length XkbKeyNameLength, and use the appropriate *Text functions to
print them. We also use strncpy everywhere instead of memcpy to copy
the names, because it does some NUL padding and we might as well.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 11:09:42 +03:00
Ran Benita c548c81529 keycodes: add a general overview
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 11:09:42 +03:00
Ran Benita 15541766b0 expr: make ResolveLevel return zero-based level
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 11:09:42 +03:00
Ran Benita 59d947c9c1 Add and use xkb_level_index_t
Several types are used over the code for shift levels; better to use
just one.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 11:09:42 +03:00
Ran Benita b804aec292 action: drop global actionInitialized
The action.c needs to use two constant Expr values, constTrue and
constFalse. To do this is keeps to static globals Expr's of type boolean
and the values "true" and "false" which need to be interned (and thus
context specific). The interning means they can't be made static const,
so there's a global flag and initializer function.

Instead of using this unsafe global state, we can simply use an integer
boolean expression (1 and 0) instead of a string one ("true" and
"false") and make them const.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 11:09:42 +03:00
Ran Benita 6f08a2cfa0 expr: constify function arguments
We need this for later.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 11:09:42 +03:00
Ran Benita f2ecd6650a log: allow to resore default log function
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 11:09:42 +03:00
Ran Benita 18048cb7bf darray: fix formatting
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 11:09:42 +03:00
Ran Benita 9617b092e2 filecomp: fix path and error message
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 11:09:42 +03:00
Ran Benita cead852713 Replace more defines with enums
Mostly the ones used to track the fields of types/keys/leds which were
already defined.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 11:09:42 +03:00
Ran Benita 3bea189bd5 Make top level Handle*File functions nicer
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 11:09:42 +03:00
Ran Benita 82ee45b374 Use xkb_led_index_t throughout
And use XKB_LED_INVALID instead of _LED_Unbound, which served the same
purpose here.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 11:09:42 +03:00
Ran Benita 09dac54b97 vmod: remove unused fields
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 11:09:42 +03:00
Ran Benita 7c7e434151 Use only one set of core mod name-to-index functions
These were repeated 5 times.

Note that this changes the ABI slightly: XKB_MOD_NAME_CAPS is changed
from "Caps Lock" to "Lock", which is the ordinary legacy mod name for
it. Since its hidden behind a #define, it's best to stay compatible with
the old names (as I think was intended, given that "Mod1", etc. are the
same).

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 11:09:42 +03:00
Ran Benita c6dee4640a map: fix incorrect return value
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 11:09:39 +03:00
Ran Benita ae968f855a map: fix virtual mod index calculation
The current code made us miss vmod index 0. Also look at the code in
vmod.c:LookupVModMask.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 10:50:15 +03:00
Ran Benita 80ab9f12b4 keymap-dump: use ActionTypeText
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 10:47:43 +03:00
Ran Benita d53fcf53f8 keymap-dump: use SITextMatch
text.c has the exact same function.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 10:47:43 +03:00
Ran Benita 20bef734d8 keymap-dump: clean up write_buf function
It would have been nice to use open_memstream here if it was portable
enough (maybe someday it will?).

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-07 10:47:41 +03:00
Ran Benita 41d9afc556 Remove ExprResult
Convert the IdentLookup typedef away from ExprResult, which drags along
everything else. This should also make all of the conversions explicit.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 15:31:03 +03:00
Ran Benita 6917901f81 expr: remove support for evaluating string as integer
As the comment nicely puts it, this is a bit weird. When you try to
evaluate an expression of type string into an integer, what it does is:
    "" -> 0
    "c" -> (ascii value, i.e. like a char literal)
    more than one char -> error
The first one is obviously not very useful; why not just write 0?
The second one might be useful (though I don't see where in a keymap
it would be), but I don't think anyone would consider trying "X" for
that anyway.

A look through xkeyboard-config shows "" only used once as a string, and
"X" also only used as strings (and mostly in geometry which we don't
evaluate anyway). And I seriously doubt it's used (purposely) anywhere
else. So remove it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 14:15:39 +03:00
Daniel Stone dd0f3c6dc2 Don't create contexts with no include paths
Clean up the return code handling from
xkb_context_add_include_paths_default, and thus fail context creation if
we can't add any of the default include paths, but were asked to.  If
this happens, dump the DFLT_XKB_CONFIG_ROOT out in the log message, so
at least we know what we aren't looking at.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-07-27 11:59:55 +02:00
Ran Benita bd927abf3d expr: drop ExprResult from ResolveEnum
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 01:57:14 +03:00
Ran Benita 38614c886c expr: drop ExprResult from ResolveMask
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 01:57:14 +03:00
Ran Benita 2e4933cda7 expr: drop ExprResult from ResolveInteger
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 01:57:13 +03:00
Ran Benita d568228988 expr: drop ExprResult from ResolveButton
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 01:57:13 +03:00
Ran Benita 6ec135700d expr: drop ExprResult from ResolveLevel
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 01:57:13 +03:00
Ran Benita 000528dd59 expr: drop ExprResult from ResolveKeyCode
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 01:57:13 +03:00
Ran Benita e258f9ee07 expr: drop ExprResult from ResolveGroup
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 01:57:13 +03:00
Ran Benita 7026229210 expr: drop ExprResult from ResolveKeysym
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 01:57:13 +03:00
Ran Benita 0d262fa105 expr: drop ExprResult from ResolveBoolean
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 01:57:13 +03:00
Ran Benita 27f9492969 expr: drop ExprResult from ResolveString
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 01:57:13 +03:00
Ran Benita 025ca57905 expr: drop ExprResult from ResolveLhs
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 01:57:13 +03:00
Ran Benita 761b675cc3 expr: drop ExprResult from ResolveKeyName
Explicit is better than implicit, and this union makes it hard to follow
what's what, particularly the confusion with ival/uval.
The other Resolve functions will follow.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 01:56:11 +03:00
Ran Benita 01c81fa61e parser: untabify
Run vim's :%retab and some resulting indention fixes.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 01:49:09 +03:00
Ran Benita 724f62c8e3 Convert defines to enums in xkbcomp.h
For statement / expression types.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 01:49:06 +03:00
Ran Benita 35fb8b94cb Fix incorrect comparison
ExprFieldRef goes into the ExprDef op field, not the type field.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 01:47:32 +03:00
Ran Benita 89723b7cb7 utils: add/replace string equality macros
It's more tidy and less error prone, since we use strcasecmp == 0 a lot.
We replace strcmp == 0 by streq, strcasecmp == 0 by istreq,
uStrCasePrefix by istreq_prefix and uDupString by strdup_safe.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 00:27:24 +03:00
Ran Benita 4f843c817b Drop Xkbc prefix of text functions
Not really needed and inconsistent.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 00:11:42 +03:00
Ran Benita 6cb9820000 Use xkb_mod_mask_t and xkb_mask_index_t throughout
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 00:04:45 +03:00
Ran Benita 74be17627e Remove alloc.{c,h}
These functions are more appropriate elsewhere now.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 00:02:59 +03:00
Ran Benita 13eb9c357d scanner: don't strdup key names
The key name is always XkbKeyNameLength (= 4) bytes, so we can maintain
it directly in YYSTYPE union and copy when needed, instead of treating
it like a full blown string and then copy. This means the scanner
checks the length itself.

rulescomp under valgrind, before:
==1038==   total heap usage: 168,403 allocs, 168,403 frees, 9,732,648 bytes allocated
after:
==9377==   total heap usage: 155,643 allocs, 155,643 frees, 9,672,788 bytes allocated

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 00:01:57 +03:00
Ran Benita 112cccb18a Some atom related optimizations
We often get a strdup'd string, just to pass it over the atom_intern and
then immediately free it. But atom_intern then strdup's it again (if
it's not interned already); so instead we can have the interning "steal"
the memory instead of allocing a new one and freeing the old one. This
is done by a new xkb_atom_steal function.

It also turns out, that every time we strdup an atom, we don't actually
modify it afterwards. Since we are guaranteed that the atom table will
live as long as the context, we can just use xkb_atom_text instead. This
removes a some more dynamic allocations.

For this change we had to remove the ability to append two strings, e.g.
    "foo" + "bar" -> "foobar"
which is only possible with string literals. This is unused and quite
useless for our purposes.

xkb_atom_strdup is left unused, as it may still be useful.

Running rulescomp in valgrind, Before:
==7907== total heap usage: 173,698 allocs, 173,698 frees, 9,775,973 bytes allocated
After:
==6348== total heap usage: 168,403 allocs, 168,403 frees, 9,732,648 bytes allocated

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-27 00:01:41 +03:00
Ran Benita c6279b8bae expr: don't divide by zero
Calculator parser 101.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-26 23:15:54 +03:00
Ran Benita 7662397fd4 types: fix canonical types copying
Without the re-initialization, the copying fails. This wasn't noticed
because this code practically never gets executed with ordinary keymaps.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-26 22:55:41 +03:00
Ran Benita 3c58072172 keycodes: fix valgrind warnings
==7071== Conditional jump or move depends on uninitialised value(s)
==7071==    at 0x40B6CB: AddIndicatorName (keycodes.c:148)
==7071==    by 0x40C34F: MergeIncludedKeycodes (keycodes.c:420)
==7071==    by 0x40C613: HandleIncludeKeycodes (keycodes.c:480)
==7071==    by 0x40D022: HandleKeycodesFile (keycodes.c:733)
==7071==    by 0x40D79F: CompileKeycodes (keycodes.c:881)
==7071==    by 0x401E22: compile_keymap (xkbcomp.c:157)
==7071==    by 0x402091: xkb_map_new_from_kccgst (xkbcomp.c:229)
==7071==    by 0x40216A: xkb_map_new_from_names (xkbcomp.c:254)
==7071==    by 0x4046F5: test_compile_rules (common.c:164)
==7071==    by 0x4015C1: test_rmlvo (rulescomp.c:44)
==7071==    by 0x40180D: main (rulescomp.c:98)

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-26 22:55:34 +03:00
Ran Benita d4eee86160 parse: remove unused #define
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-26 22:55:28 +03:00
Ran Benita 2e245a9a41 expr: Remove ExprResolveFloat
Remnant from geometry.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-26 22:55:17 +03:00
Ran Benita 2c30fa7a60 Remove old logging leftovers
Everything has been converted.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:35 +03:00
Ran Benita 70e3e7e5c3 xkbcomp: use new log functions
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:35 +03:00
Ran Benita f48ee2d2af parse: use new log functions
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:35 +03:00
Ran Benita 8e3958032c path: use new log functions
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:35 +03:00
Ran Benita 885f6c8cb6 misc: use new log functions
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:35 +03:00
Ran Benita 544a83e6d7 vmod: use new log functions
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:35 +03:00
Ran Benita 3bb3e9c3a9 rules: use new log functions
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:35 +03:00
Ran Benita d659f2b46b expr: use new log functions
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:35 +03:00
Ran Benita e037f51862 action: use new log functions
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:35 +03:00
Ran Benita 87444fb969 types: use new log functions
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:35 +03:00
Ran Benita 36df40c3cd types: add keymap to KeyTypesInfo
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:34 +03:00
Ran Benita 8e62b368a7 compat: use new log functions
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:34 +03:00
Ran Benita 270ff8ad83 compat: add keymap to CompatInfo
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:34 +03:00
Ran Benita 7dc51ea84a symbols: use new log functions
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:34 +03:00
Ran Benita 7ef648134d symbols: add keymap to SymbolsInfo
and use it. Also make sure info is the first argument to the functions
in this file.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:34 +03:00
Ran Benita 0ae1199a5a keycodes: use new log functions
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:34 +03:00
Ran Benita 37579ce9a5 keycodes: add keymap to KeyNamesInfo
and let the info always be the first argument to the various functions,
just for consistency (and it acting as the contex for this file).

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:34 +03:00
Ran Benita 70f35cfbc0 Add logging API
Add new public API to provide the library users with some options to
control and customize the logging output from the library. It is based
upon the skeleton from the libabc demo libray:
https://git.kernel.org/?p=linux/kernel/git/kay/libabc.git
which is public domain and works pretty well.

This requires passing in the context object in every logging call, and
thus the conversion is done file by file. We also remove the global
warningLevel variable in favor of a verbosity level in the context,
which can be set by the user and is silent by default.

One issue is the ACTION calls, which, while nice, do not play very well
with line- and priority-based logging, and would require some
line continuation handling or keeping state or some other compromise. So
instead remove these and just inline them with their respective
warning/error. So instead of:
    ERROR("Memory allocation failed\n")
    ACTION("Removing all files on hardisk\n")
its something like that:
    log_err("Memory allocation failed; Removing all files on harddisk\n")

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:34 +03:00
Ran Benita 71c2f2e0e2 utils: replace FATAL by malloc_or_die
"Out of memory" is enough in this case. If we want to be OOM-safe this
makes it clear where to begin.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:34 +03:00
Ran Benita 58f8d2c151 utils: remove Xfuncproto.h and use our own macros
Add XKB_EXPORT to replace _X_EXPORT, and copy the definitions of
_X_ATTRIBUTE_FOO as ATTR_FOO.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:34 +03:00
Ran Benita 8b0e9f929c utils: remove uTypedAlloc/Calloc
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-23 00:45:34 +03:00
Ran Benita 2fc0ad5001 Fix bison 2.6 and clang warnings
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-20 12:48:13 +03:00
Ran Benita db98696d0b Remove CommonInfo
Not used by anything anymore.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 21:06:07 +03:00
Ran Benita 250c925ce4 types: use list instead of CommonInfo for KeyTypeInfo
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 21:06:07 +03:00
Ran Benita 85826c3c13 Simplify HandleInclude functions
Instead of special casing the first include, process it inside the loop
as well. It works perfectly fine.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 21:06:07 +03:00
Ran Benita 861e6a1751 Remove haveSelf include feature
When including a file from another file, its possible to do something
like this:
    include "+some(other)+files"
with the "+" or "|" in the beginning. What will happen then is that
instead of processing the include files separately and then merging into
the existing info, we instead start with the existing info and merge
into it as we go, as if it was written explicitly before the first "+".

It's not particulary clear what this may be useful for. Since it's not
used by xkeyboard-config, not documented anywhere (and google doesn't
bring up anything), completely untested and kind of ugly, remove this
"feature". It most likely never been used.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 20:40:33 +03:00
Ran Benita 730c2bc34f types: use list instead of CommonInfo in PreserveInfo
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 15:25:41 +03:00
Ran Benita 85abd36bf4 types: move global static tok_ atoms into KeyTypesInfo
The atoms are context-dependent.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 15:25:41 +03:00
Ran Benita 119c952b82 compat: use list instead of CommonInfo in LEDInfo
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 15:25:41 +03:00
Ran Benita 50b25a1210 Use xkb_group_index_t for group variables throughout
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 15:25:37 +03:00
Ran Benita 8237e9c77a Remove _X_EXPORT from xkb_key_get_group/level
We should add them to xkbcommon.h if they need to.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 14:07:02 +03:00
Ran Benita e21fc886ca compat: use list instead of CommonInfo in SymInterpInfo
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 14:07:02 +03:00
Ran Benita ba4320f7b3 Move indicators.c code into compat.c
It is only used there. Allows some refactoring.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 14:07:02 +03:00
Ran Benita dfa0929c6d Convert macros to inline functions
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 14:07:02 +03:00
Ran Benita 3fbf4ce315 keycodes: use list instead of CommonInfo in IndicatorNameInfo
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 14:07:02 +03:00
Ran Benita 4bf987e5f7 keycodes: use list instead of CommonInfo in AliasInfo
Always pass around the KeyNamesInfo which contains the list head.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 14:07:02 +03:00
Ran Benita cc8b06826b Move alias.c functions into keycodes.c
They are only used in this file.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 14:07:02 +03:00
Ran Benita cf4f170bdd symbols: don't use CommonInfo in KeyInfo
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 14:07:02 +03:00
Ran Benita ebb4d59c58 symbols: use list for ModMapEntry's
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 14:07:02 +03:00
Ran Benita b6e2a56dc0 Add common linked list implementation
Taken from xserver/include/list.h. The changes made are:
* Drop the xorg_ prefix and some typedef from the end.
* Rename _for_each_entry macros to just _foreach (like darray).
* Rename list_is_empty to list_empty (like darray).
* Add a list_replace function which we use later.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 12:56:13 +03:00
Ran Benita 0a6f9ccde2 symbols: remove alias info
It's never used - all of the aliases are added in the keycodes section.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 12:56:05 +03:00
Ran Benita d0097f4e60 Pass around xkb_key's instead of keycodes
This way we don't need to look up the key every time. We now only deal
with keycodes in the public API and in keycodes.c.

Also adds an xkb_foreach_key macro, which is used a lot.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 12:47:29 +03:00
Ran Benita 35a93b8e64 map: verifiy that the keycode is legal
In case someone passes in a bad keycode.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 12:46:29 +03:00
Ran Benita 091a0542ac Remove redundant keymap->keys resizes
The size (i.e. max_keycode) is determined in the keycodes section, which
gets compiled first.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 12:46:29 +03:00
Ran Benita ad8875c526 Remove GroupsWidth macro
Use key->width directly instead.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 12:46:29 +03:00
Ran Benita c705a82d60 Remove unused 'groupInfo' in KeyTypeInfo
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 12:46:29 +03:00
Ran Benita 4ccb0ef5cc Get rid of group_info
This is 8 bits which hold how many groups the key has, what to do the
key group is out of bound and the group to redirect to if want to. This
may save a few bytes, but is really annoying. So instead, just lay out
the fields separately. We can optimize later in a sane way, with pahole,
bitfields, etc. if we want.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 12:46:29 +03:00
Ran Benita 4066fcc9b5 Get rid of struct xkb_sym_map
Past its usefulness; put the stuff directly in xkb_key.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 12:46:28 +03:00
Ran Benita 7d9f031341 Get rid of struct xkb_key_name
Just embed it directly.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 12:45:28 +03:00
Ran Benita e8a6a5f09a Add common xkb_key struct
Instead of having a million arrays from the keycode to various
key-specific info in the keymap, add a single struct xkb_key to hold all
of the data for the key in one object. This way we can pass it around,
do some refactoring and make the code simpler. It's also nice to see
everything in one place.

The keys array is still indexed by keycode, which is suboptimal because
there may be a lot of holes (i.e. unused keycodes between min_key_code
and max_key_code). By the end of this series it would be abstracted
enough to replace it by a hash table or similar if there's ever a need.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 12:45:22 +03:00
Ran Benita e668d00956 Replace KeyInfo 'key' variable name by 'keyi'
We want to reserve the name 'key' for something else.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 12:39:37 +03:00
Ran Benita 81d029f563 Replace xkb_keycode_t 'key' variable name by 'kc'
We want to reserve the name 'key' for something else.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 12:35:48 +03:00
Ran Benita a52fb7e21c Convert indecipherable macros to inline functions
This was fun.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 12:25:29 +03:00
Ran Benita c064b95c7c symbols: split initialization code from CompileSymbols
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 12:25:29 +03:00
Ran Benita caca60f391 Move per_key_repeats and enabled_ctrls to keymap
All of the per-key data and global flags are now visible directly in the
keymap.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 12:25:29 +03:00
Ran Benita 1313af8fb5 Get rid of xkb_key_names
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 12:25:28 +03:00
Ran Benita 50fef8eb8a Get rid of xkb_indicator
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 12:22:20 +03:00
Ran Benita ed08261768 Get rid of xkb_compat_map
Same as xkb_{client,server}_map which were already removed.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-07-18 12:22:20 +03:00