Commit Graph

1124 Commits (61fed8dab9b8e27981f36ffc96666d7376546e30)

Author SHA1 Message Date
Ran Benita efe5b036ee rules: improve error logging macros
Improve safety with parenthesis, make the matcher macros use the scanner
ones, and make the 1 variant use %s instead of embedding the msg; this
way the compiler can reuse the string in the binary.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-10-10 22:02:30 +03:00
Ran Benita 5af688e694 rules: reduce variable scopes
There are some big functions there, and this might help reduce the
cognitive load a bit.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-10-10 22:02:30 +03:00
Ran Benita c35c388b79 scanner: remove unnecessary cast
'tok' is already an int now.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-10-10 22:02:21 +03:00
Siddharth Heroor 27f2743cf1 keysym-utf: Fix a warning about shadowing
Change variable names to avoid the name clash. The warning seen is

src/keysym-utf.c: In function 'bin_search':
src/keysym-utf.c:841: warning: declaration of 'min' shadows a global declaration
src/utils.h:109: warning: shadowed declaration is here
src/keysym-utf.c:842: warning: declaration of 'max' shadows a global declaration
src/utils.h:115: warning: shadowed declaration is here

Signed-off-by: Siddharth Heroor <heroor@ti.com>
2013-10-07 21:00:33 +03:00
Ran Benita 1e52bf7995 symbols: fix use of uninitialized variable
'tmp' is stack allocated so tmp->merge is used uninitialized by
AddModMapEntry(). The value doesn't matter much, but it used to
make some modmap merging decision (which doesn't have many
conflicts usually).

Bug inherited from xkbcomp.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-10-03 10:02:49 +03:00
Ran Benita 8e14bff0a1 parser: add some notes about byacc working
We now also work with byacc (version tested: 20130925) which some people
prefer, perhaps due to its license (public domain) or performance
(haven't compared).

When using byacc, currently the following warning comes up:
    src/xkbcomp/parser.c:954:14: warning: declaration shadows a variable in the global scope [-Wshadow]
        YYSTYPE  yylval;
                ^
    src/xkbcomp/parser.c:37:20: note: expanded from macro 'yylval'
    #define yylval     _xkbcommon_lval
                    ^
    ./src/xkbcomp/parser.h:96:16: note: previous declaration is here
    extern YYSTYPE _xkbcommon_lval;

This is due to a bug in byacc - it shouldn't output that extern line in
%pure-parser mode. So the warning stays.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-09-29 01:41:52 +03:00
Ran Benita 8dcb30e564 parser: add a workaround for byacc
Unlike bison, byacc outputs its own parser code *after* our own parser.y
code, which includes the #undef. So this fix is needed for the 'scanner'
-> 'param->scanner' translation to work in the parser.c code generated
by byacc.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-09-29 01:29:47 +03:00
Ran Benita 409f27d783 parser: don't use %locations
byacc doesn't support this feature.

We print the line/col of the last scanned token instead. This is slightly
less in case of *parser* errors (not syntax errors), but I couldn't make
it point to another line, and this are pretty cryptic anyways. So it's
good enough. Also might be a bit faster, but haven't checked.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-09-29 00:41:17 +03:00
Ran Benita 13da6da0e7 parser: drop %name-prefix, use -p yacc argument instead
Even though the %name-prefix is more sensible, byacc doesn't support it,
but both bison and byacc support the -p argument.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-09-29 00:24:50 +03:00
Ran Benita cfd7e7c160 parser: use %pure-parser instead of %define api.pure
Both bison and byacc support this syntax. Bison manpage says something
about this giving more or less options, but we don't care.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-09-29 00:22:20 +03:00
Ran Benita e4c00e90ab parser: don't use enum yytokentype
byacc doesn't support this, it just puts out #define's for the tokens.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-09-29 00:19:32 +03:00
Ran Benita 2a2a8d7da1 state: apply capitalization transformation on keysyms
The xkbproto spec says:
http://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Lock_Modifier

    If the Lock modifier is not consumed by the symbol lookup process,
    routines that determine the symbol and string that correspond to
    an event should capitalize the result.

This was not an issue until now, because most xkeyboard-config keymaps
do not utilize this "feature", and specify the keysyms for the Lock
modifier explicitly instead. However, some keymaps do depend on it, e.g.
ch(fr) for eacute and others.

The spec goes on to describe two options for doing this transformation:
locale-sensitive and locale-insensitive. We opt for the latter; it is
less desirable but we don't want *that* headache.

Also, only xkb_state_key_get_one_sym() is changed;
xkb_state_key_get_syms() is left as-is, and always reports the
untransformed keysyms. This is for the following reasons:

- The API doesn't allow it, since we return a const pointer directly to
  the keymap keysyms table and we can't transform that.

- The transformation doesn't make sense for multiple-keysyms.

- It can be useful for an application to get the "raw" keysyms if it
  wants to (e.g. maybe it wants to do the transformation itself).

Finally, note that xkb_state_mod_index_is_consumed() does *not*
report Lock as consumed even if it was used in the transformation. This
is what Xlib does.

This definitely doesn't fall under the "hard to misuse" API rule but
it's the best we can do.

https://bugs.freedesktop.org/show_bug.cgi?id=67167

Reported-By: Gatis Paeglis <gatis.paeglis@digia.com>
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-08-15 09:58:50 +03:00
Ran Benita 1499eedd82 keysym: add xkb_keysym_to_{lower,upper}
These functions are needed later; they are not API functions. The
capitalization is not locale sensitive.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-08-15 09:58:50 +03:00
Ran Benita 7caa1af25e scanner: don't fail over unknown escape sequence
This is too strict, and causes symbols/cz to fail parsing. Instead, just
emit a warning (not shown by default):
    xkbcommon: WARNING: cz:75:19: unknown escape sequence in string literal

https://bugs.freedesktop.org/show_bug.cgi?id=68056

Reported-By: Gatis Paeglis <gatis.paeglis@digia.com>
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-08-13 14:52:11 +03:00
Ran Benita 869c9b582d xkbcomp: improve a few log messages
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-08-13 10:01:22 +03:00
Ran Benita aa9c91943e scanner: fix compiler warning
src/xkbcomp/scanner.c:158:17: warning: comparison of constant -1 with expression of type 'enum yytokentype' is always true
      [-Wtautological-constant-out-of-range-compare]
        if (tok != -1) return tok;
            ~~~ ^  ~~

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-08-02 14:41:19 +03:00
Ran Benita e91d2653dd scanner: allow empty key name literals
Some keymaps actually have this, like the quartz.xkb which is tested. We
need to support these.

https://bugs.freedesktop.org/show_bug.cgi?id=67654

Reported-By: Gatis Paeglis <gatis.paeglis@digia.com>
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-08-02 11:40:27 +03:00
Ran Benita e731b2514b xkbcomp: handle empty keymaps
We should handle empty xkb_keycode and xkb_symbol sections, since
xkbcomp handles them, and apparently XQuartz uses it. There are also
files for it in xkeyboard-config (rules=base model=empty layout=empty,
which translate to keycodes/empty and symbols/empty).

https://bugs.freedesktop.org/show_bug.cgi?id=67654

Reported-By: Gatis Paeglis <gatis.paeglis@digia.com>
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-08-02 11:39:39 +03:00
Ran Benita d2383d3852 keymap-dump: use correct format specifiers
For keycodes, groups, levels, etc, which are unsigned. The really proper
inttypes.h ones seem a bit much though.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-08-01 21:49:48 +03:00
Ran Benita c0589be69b log: change the log prefixes to be more library-like
"Error: " is not very informative when intermingled with other logs. The
format that seems most suitable is:
    "xkbcommon: ERROR: %s"

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-07-31 10:58:25 +03:00
Ran Benita 990c09a3d0 keymap: update builtin fields directly in src/keymap.c
This fields are part of our API and every keymap should have them, not
just xkbcomp/ ones.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-07-31 10:58:25 +03:00
Ran Benita 5f787e5e91 keymap: be more careful in xkb_keymap_unref
To allow calling _unref on the keymap in whatever limbo state it happens
to be in.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-07-31 10:58:25 +03:00
Ran Benita be38862b2a keymap: remove struct xkb_key_redirect_action
The file src/xkbcomp/action.c already doesn't handle this action type
and fails if it encounters it. So lets not pretend to do something with
it, and ignore it rather than failing.

If we/someone wants this we can consider implementing it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-07-31 10:58:25 +03:00
Pino Toscano ec9a02a239 Get rid of the usage of PATH_MAX
PATH_MAX is optional in POSIX, so avoid its unconditional usage
allocating and freeing buffers as needed.
To avoid too many malloc/free in the for loop in FindFileInXkbPath,
a buffer is grown according to the size needed at each iteration.
2013-07-24 12:08:11 +03:00
Ran Benita 806d24b1a5 keymap: move RANGE_WRAP to be the first in the enum
This is the reasonable "zero-default" for this enum.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-07-23 11:36:01 +03:00
Ran Benita c00ea5ff8e atom: really work with non-NUL-terminated strings
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-07-22 11:02:20 +03:00
Ran Benita 9e801ff782 ctx: adapt to the len-aware atom functions
xkb_atom_intern now takes a len parameter. Turns out though that almost
all of our xkb_atom_intern calls are called on string literals, the
length of which we know statically. So we add a macro to micro-optimize
this case.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-07-21 17:07:41 +03:00
Ran Benita 7e0ae4b4d5 atom: allow interning non-NUL-terminated strings
We need this later. The strlen was calculated anyway, so no loss here.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-07-21 17:07:41 +03:00
Ran Benita 9cd29453ae atom: expand variable names
A bit easier to understand at a glance.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-07-21 17:07:41 +03:00
Ran Benita 9ffe9dae1d keymap: don't use darray for sym_interprets
We want xkb_keymap to be easy to handle everywhere.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-07-21 10:00:37 +03:00
Ran Benita 4b560287f8 xkbcomp: escape the section names before storing them in the keymap
This ensures the names are escaped before having any interaction with
the user.

This was caught by noticing dump(compile(dump())) != dump. Since that's
a nice test we add it to stringcomp.

https://bugs.freedesktop.org/show_bug.cgi?id=67032

Reported-By: Auke Booij
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-07-18 14:50:21 +03:00
Daniel Stone 6bb727b227 Resync keysym database
xproto 7.0.24 adds XF86AudioMicMute.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2013-07-17 22:47:32 +01:00
Matthias Clasen b06de3072b Add keycode min/max and iteration API
Add three new pieces of API:
  - xkb_keymap_min_keycode does what it says on the tin
  - xkb_keymap_max_keycode likewise
  - xkb_keymap_key_for_each calls the provided function once for every
    valid key in the keymap

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2013-05-09 15:31:21 +01:00
Daniel Stone 17a956d807 Widen keycode range to 8/255 if possible (bug #63390)
If the keycode range is smaller than 8 → 255, artifically widen it when
dumping the keymap as not to displease X.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2013-05-09 14:47:09 +01:00
Ran Benita a392d2682b Replace flex scanner with a hand-written one
The scanner is very similar in structure to the one in xkbcomp/rules.c.
It avoids copying and has nicer error reporting.

It uses gperf to generate a hashtable for the keywords, which gives a
nice speed boost (compared to the naive strcasecmp method at least). But
since there's hardly a reason to regenerate it every time and require
people to install gperf, the output (keywords.c) is added here as well.

Here are some stats from test/rulescomp:

Before:
compiled 1000 keymaps in 4.052939625s
==22063==   total heap usage: 101,101 allocs, 101,101 frees, 11,840,834 bytes allocated

After:
compiled 1000 keymaps in 3.519665434s
==26505==   total heap usage: 99,945 allocs, 99,945 frees, 7,033,608 bytes allocated

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-04-01 18:20:57 +01:00
Ran Benita e4bceec880 utils: add {un,}map_file to read an entire file
This wraps the current mmap call and adds a fallback implementation for
systems which do not have mmap (e.g. mingw).

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-04-01 18:20:56 +01:00
Ran Benita 99f6e6fc28 Add scanner-utils.h for common scanner functions
We want to share the same functions for another scanner.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-04-01 18:20:54 +01:00
David Herrmann 36f55c494e keymap: add xkb_keymap_new_from_buffer()
The current API doesn't allow the caller to create keymaps from mmap()'ed
files. The problem is, xkb_keymap_new_from_string() requires a terminating
0 byte. However, there is no way to guarantee that when using mmap() so a
user currently has to copy the whole file just to get the terminating zero
byte (assuming they cannot use xkb_keymap_new_from_file()).

This adds a new entry xkb_keymap_new_from_buffer() which takes a memory
location and the buffer size in bytes.

Internally, we depend on yy_scan_{string,byte}() helpers. According to
flex documentation these already copy the input string because they are
wrappers around yy_scan_buffer().
yy_scan_buffer() on the other hand has some insane requirements. The
buffer must be writeable and the last two bytes must be ASCII-NUL. But the
buffer may contain other 0 bytes just fine.

Because we don't want these constraints in our public API,
xkb_keymap_new_from_buffer() needs to create a copy of the input memory.
But it then calls yy_scan_buffer() directly. Hence, we have the same
number of buffer-copies as with *_from_string() but without the
terminating 0 requirement.
The explicit yy_scan_buffer() call is preferred over yy_scan_byte() so the
buffer-copy operation is not hidden somewhere in flex.

Maybe some day we no longer depend on flex and can have a zero-copy API. A
user could mmap() a file and it would get parsed right from this buffer.
But until then, we shouldn't expose this limitation in the API but instead
provide an API that some day can work with zero-copy.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>

[ran: rebased on top of my branch]
Conflicts:
	Makefile.am
	src/xkbcomp/xkbcomp.c
2013-04-01 18:04:06 +01:00
Ran Benita 094f1dc29a xkbcomp/keymap: silence a gcc warning
src/xkbcomp/keymap.c:127:12: error: 'found' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Not really, but why not.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-04-01 17:50:08 +01:00
Daniel Stone fbe5e6751e Add environment overrides for default RMLVO
You can now set default values in the environment, as well as a context
option to ignore the environment, e.g. for tests.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2013-03-19 10:53:37 +00:00
Ran Benita 0513686b5d rules: be more paranoid in scanner
This can't happen, but better safe than sorry. The optimizations were
noticeable but negligible.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:06 +00:00
Ran Benita 0e200bd507 rules: quiet a gcc warning
src/xkbcomp/rules.c:620:36: error: 'idx' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Can't happen but no harm done.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:06 +00:00
Ran Benita 9f75e0ab2e state: use stdbool in filters
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:06 +00:00
Ran Benita 57bfde3aff keymap: rename xkb_kt_map_entry to xkb_key_type_entry
That's a better name and fits more nicely.
Also change type->map to type->entries.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:06 +00:00
Ran Benita 6a39a0657d Fix pointer style nit
(I really dislike this one for some reason..)

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:05 +00:00
Ran Benita 56ba986613 Remove file_id entirely
It is not used anymore.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:05 +00:00
Ran Benita 64c002627d symbols: remove file_id
See previous commits.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:05 +00:00
Ran Benita 4921eb7416 compat: remove file_id
See previous commit.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:05 +00:00
Ran Benita 2b6e576f26 types: remove file_id
See previous commit.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:05 +00:00
Ran Benita 2ddb9e4f98 types: put all copy-to-keymap code in one function
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:05 +00:00
Ran Benita 4bd0610f13 keycodes: remove KeyNamesInfo::merge
Not used.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:05 +00:00
Ran Benita b06ef2b826 keycodes: unwrap KeyNameInfo
We don't need the struct any more, it only contains one field now.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:05 +00:00
Ran Benita a78c1f0a04 keycodes: remove file_id
The file_id thing is used to identify the XkbFile some statement
originally came from. This is needed to avoid spurious warnings; for
example, if you write the same alias twice in a file, that's redundant,
and you'd want a warning about it. However if intentionally override it
from another file, that's fine, and you shouldn't get a warning. So by
comparing the file_id's the needed log verbosity is changed.

However, the file_id mechanism is really not needed, because we already
have that info! Each KeyNamesInfo corresponds to one XkbFile, so if the
conflict occurred while handling that one file -> same_file = true, and
if it occurs while merging two Info's -> same_file = false.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:05 +00:00
Ran Benita f8d3ec9f6f keymap: don't use darray for key aliases
With a little tweak to the copy-to-keymap routine in keycodes.c we can
use a normal array.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:05 +00:00
Ran Benita ea3cf26db5 keycodes: don't do unnecessary copies while merging
If 'into' in empty we can just steal 'from'.

Also move the alias-merging into the big function, it's nicer this way.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:05 +00:00
Ran Benita cd6a71fc63 state: small style fix
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:04 +00:00
Ran Benita 71eb033eef Move a couple of general keymap functions from keycodes.c
To get a key by name and resolve an alias - this makes sense for
everyone.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:04 +00:00
Ran Benita 82c3e39360 keycodes: remove unneeded alias conflict check
This is already checked when adding a new alias and merging aliases, so
it can never happen when we get to copying to the keymap.

Also the log verbosity decision there is quite useless, we should just
warn always and be done with it. So we can remove the file_id from
AliasInfo, and collapse the alias functions together.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:04 +00:00
Ran Benita 614f60e3fa xkbcomp: handle XKB file include's better
The 'merge_mode' situation is quite messy, and we've introduced a
regression compared to original xkbcomp: when handling a composite
include statement, such as
    replace "foo(bar)+baz(bla)|doo:dee"
and merging the entire resulting *Info back into the including *Info,
we actually use the merge mode that is set by the last part (here it is
"augment" because of the '|'), when we should be using the one set for
the whole statement (here "replace").

We also take the opportunity to clean up a bit.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:04 +00:00
Ran Benita a7b1f80d34 Build cleanly with clang
clang doesn't like the use of typeof with out default flags, so just
don't use it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:04 +00:00
Ran Benita 14842d6dc9 keymap: abstract a bit over the keymap format
Make it a bit easier to experiment with other formats.

Add a struct xkb_keymap_format_operations, which currently contains the
keymap compilation and _get_as_string functions. Each format can
implement whatever it wants from these.

The current public entry points become wrappers which do some error
reporting, allocation etc., and calling to the specific format. The
wrappers are all moved to src/keymap.c, so there are no XKB_EXPORT's
under src/xkbcomp/ anymore.

The only format available now is normal text_v1.

This is all not very KISS, and adds some indirection, but it is helpful
and somewhat cleaner.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:04 +00:00
Ran Benita d1eae42ac5 text: some style changes
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:04 +00:00
Ran Benita 4e8dcca86d text: clean up and fix the *MaskText functions
The snprintf trick that LedStateText and ControlMaskText do cannot work,
because you can't use the buffer as an argument to write to itself!
(posix at least has 'restrict' there). So those two actually never
worked for more than one value (i.e. with a +).

Fix that, and do the same cleanup to ModMaskText. Now we have 3
functions which look exactly the same, oh well.

Also increase the context text buffer size, you never know.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:04 +00:00
Ran Benita 540feef3bb More spelling errors
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:04 +00:00
Ran Benita b36d5b23d2 parser: also skip 'section' ELEMENT
It's for geometry only.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:03 +00:00
Ran Benita 35657c660a ast-build: remove malloc_or_die
This should be fixed properly.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:03 +00:00
Ran Benita a7b9c73d28 keycodes: fix spelling in error message
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:03 +00:00
Ran Benita 958b27284f Remove list.h
We don't use it anymore and it's easy to add back if needed.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:03 +00:00
Ran Benita 98ccbf9aff keymap-dump: move writing 'key {}' in symbols to its own function
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:03 +00:00
Ran Benita 4a59c84e43 keymap-dump: remove some ugly empty lines
xkbcomp prints them too, but that's just annoying. Also xkb_keycodes
doesn't have it already.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:03 +00:00
Ran Benita e95dac76f2 keymap-dump: don't indent after xkb_keymap {
xkbcomp doesn't indent there, so it's easier to diff.
Also saves some horizontal space which is sorely needed when looking at
these files (especially the xkb_symbols).

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:03 +00:00
Ran Benita 9842b7a58a keymap-dump: style cleanups
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:03 +00:00
Ran Benita d1f7100bcf ast: add error handling to XkbFileFromComponents
And try to not repeat ourselves.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:03 +00:00
Ran Benita a46e4cc163 Fix dead assignments
"Value stored to 'stmt' is never read"
"Value stored to 'grp_to_use' is never read"

And change 'grp' to 'group' if we're here.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:02 +00:00
Ran Benita c7aef16649 keysym: print unicode keysyms uppercase and 0-padded
Use the same format as XKeysymToString.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:02 +00:00
Ran Benita dd81d5e0c0 Change some log functions to take ctx instead of keymap
They don't need the keymap, only the context.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:02 +00:00
Ran Benita a4904ee1b7 keycodes: some minor style
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:02 +00:00
Ran Benita 60bb639bbe action: s/hndlrType/handler_type
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:02 +00:00
Ran Benita fab28da39f compat: make it clear which 'dflt' is meant
Also s/dflt/default.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:02 +00:00
Ran Benita b5c1b1d221 symbols: make it clear which 'dflt' is meant
A bit easier at a glance. Also, vowels are cool, so just say 'default'.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:02 +00:00
Ran Benita fc56b5134f ast: constify argument
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:02 +00:00
Ran Benita 164cec6636 symbols: fix bad 'merge' assignment
Bug introduced in 2a5b0c9dc1, was causing
some keys to be merged incorrectly.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:02 +00:00
Ran Benita 8cee749000 Change 'indicator' to 'led' everywhere possible
The code currently uses the two names interchangeably.
Settle on 'led', because it is shorter, more recognizable, and what we
use in our API (though of course the parser still uses 'indicator').

In camel case we make it 'Led'.
We change 'xkb_indicator_map' to just 'xkb_led' and the variables of
this type are 'led'. This mimics 'xkb_key' and 'key'.
IndicatorNameInfo and LEDInfo are changed to 'LedNameInfo' and
'LedInfo', and the variables are 'ledi' (like 'keyi' etc.). This is
instead of 'ii' and 'im'.

This might make a few places a bit confusing, but less than before I
think. It's also shorter.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:02 +00:00
Ran Benita 089c3a1811 state: fix unbound virtual modifier bug
Recent xkeyboard-config introduced the following line in symbols/level3:
    vmods = LevelThree,
However, the XKM format which xkbcomp produces for the X server can't
handle explicit virtual modifiers such as this:
https://bugs.freedesktop.org/show_bug.cgi?id=4927

So by doing the following, for example:

setxkbmap -layout de (or another 3-level layouts)
xkbcomp $DISPLAY out.xkb
xkbcomp out.xkb $DISPLAY

The modifier is lost and can't be used for switching to Level3 (see the
included test).

We, however, are affected worse by this bug when we load the out.xkb
keymap. First, the FOUR_LEVEL_ALPHABETIC key type has these entries:
    map[None] = Level1;
    map[Shift] = Level2;
    map[Lock]  = Level2;
    map[LevelThree] = Level3;
    [...]
Now, because the LevelThree virtual modifier is not bound to anything,
the effective mask of the "map[LevelThree]" entry is just 0. So when
the modifier state is empty (initial state), this entry is chosen, and
we get Level3, instead of failing to match any entry and getting the
default Level1.

The difference in behavior from the xserver stems from this commit:
acdad6058d
Which removed the entry->active field. Without bugs, this would be
correct; however, it seems in this case we should just follow the
server's behavior.

The server sets the entry->active field like so in XKBMisc.c:
    /* entry is active if vmods are bound */
    entry->active = (mask != 0);
The xkblib spec explains this field, but does not specify how to
initialize it. This commit does the same as above but more directly.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:01 +00:00
Daniel Stone bb620df7aa Parser: Initialise geometry elements for VarDecl
We were using uninitialised memory whilst parsing geometry, leaving
random contents as the return for shape/overlay/etc sections.  Somehow
this actually worked everywhere but under Java.

https://bugs.freedesktop.org/show_bug.cgi?id=57913

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-12-06 15:04:15 +11:00
Ran Benita f159846943 state: rename state->cur to state->components
'cur' doesn't make sense anymore. 'components' is a bit long for this,
but not too bad, and nothing better comes to mind.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-11-11 16:14:30 +02:00
Ran Benita 7372c9f181 state: don't keep the previous state components in xkb_state
There is really no need to keep this in the struct, we can just allocate
it on the stack when we need to.
Don't know why I did it this way.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-11-11 16:09:05 +02:00
Ran Benita 60bd92021b keymap: wrap the layout parameter if it is out of range for the key
The functions num_levels_for_key() and get_syms_by_level() have a
'layout' parameter. Currently it is expected that this value is always
legal for the key, as determined by num_layouts_for_key(). However,
there are legitimate use cases for passing an out-of-range layout there,
most probably passing the effective layout, and expecting to get the
keysyms/levels for just this layout. So we wrap it just as we do in the
xkb_state_* functions.

This is also useful for stuff like this:
http://developer.gnome.org/gdk/stable/gdk-Keyboard-Handling.html#gdk-keymap-lookup-key

If this behavior is not desired, the user has the option to check
against num_layouts_for_key herself.

https://bugs.freedesktop.org/show_bug.cgi?id=56866

Reported-by: Gatis Paeglis <gatis.paeglis@digia.com>
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-11-11 00:32:16 +02:00
Ran Benita d9317d5f32 keysym-utf: mark keysymtab array as static
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-11-05 21:50:38 +02:00
Ran Benita 7891c9170b keysym-utf: also translate special keysyms like Tab and Return
The keysym2ucs.c file apparently leaves out some keysyms, which libX11
deals with separately (like in _XkbHandleSpecialSym()).
The problematic keysyms are the keypad ones (for which we already added
some support) and keysyms which use 0xff** instead of 0x00** < 0x20.
This code should fix them properly, as much as I could gather from
libX11 and http://www.cl.cam.ac.uk/~mgk25/ucs/keysym2ucs.c and other
sources (which are not aware of locale).

https://bugs.freedesktop.org/show_bug.cgi?id=56780

Reported-by: Gatis Paeglis <gatis.paeglis@digia.com>
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-11-05 21:34:59 +02:00
Ran Benita 998c957a3c action: don't allow private actions with a known type
Some obscure bug having to do with Private actions; see the comments.
This was prompted by:
https://bugs.freedesktop.org/show_bug.cgi?id=56491

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-30 18:25:08 +02:00
Ran Benita 7261f404d2 state, context: allow passing NULL to *_unref()
For error handling code, it's nice to be able to pass NULL to these
function without worrying about segfaults ensuing. free() sets the
precedent here.

Also document this fact.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-29 01:20:04 +02:00
Ran Benita a51ee70419 state: don't use xkb_keymap_num_layouts internally
Clearer and more greppable this way.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-26 16:34:39 +02:00
Ran Benita ee6f3f2809 state: don't use xkb_state_serialize_* internally
The code in these cases is clearer when done directly.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-26 16:12:28 +02:00
Ran Benita 6f093ad56b state: fix possible index-out-of-bounds in action dispatch table
The current code assumes that action->type always falls in the range of
the xkb_action_type enum. But keymaps can also have Private actions,
which are allowed to set their own type number.

So with a default xkeyboard-config keymap, keycode 86 at level 4, which
triggers such an action, causes us to crash.

Fix it by always checking the bounds.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-24 23:09:26 +02:00
Ran Benita f76859bc87 keymap: use plain array for keymap->group_names
Again it is not resized.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-23 17:22:13 +02:00
Ran Benita 867992cd21 state: fix typo in state component copying
Gladly no-one should have been fast enough to hit this.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-23 17:22:13 +02:00
Ran Benita 4b81c9f3e3 Report which components of the state have changed
We add a return value to the xkb_state_update_key and
xkb_state_update_mask, which reports to the caller which of the state
components have changed as a result.

This restores the XKB functionality of the XkbStateNotify and
XkbIndicatorsStateNotify events. See:
http://www.x.org/releases/current/doc/kbproto/xkbproto.html#Events
It is quite useful in some situations. For example, it allows an
application to avoid doing some work if nothing of relevance in the
state has changed. Say, a keyboard layout applet. Also useful for
debugging.

The deltas themselves are not provided, because I can't see a use case.
If needed, it should be possible to add some API for that.

In xkbcommon, keymaps are immutable, so all of the other *Notify events
from XKB are irrelevant.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-22 21:58:03 +02:00
Ran Benita 550cb24d3c state: add struct state_components
This holds all of the state component fields in the state in one struct.
We will later want to keep the previous state components after updates,
so this will allow us to do it without duplicating the fields.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-22 21:55:43 +02:00
Ran Benita 6a94b122a4 Split the mods, layout, leds parts of xkb_state_components
Note first:
This commits breaks the ABI somewhat. If an application is run against
this commit without recompiling against the updated header, these break:
    - xkb_state_layout_*_is_active always retuns false.
    - xkb_state_serialize_mods always returns 0.
So it might break layout switching in some applications. However,
xkbcommon-compat.h provides the necessary fixes, so recompiling should
work (though updating the application is even better).

Split the enum to its individual components, which enables us to refer
to them individually. We will use that later for reporting which
components of the state have changed after update.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-22 21:48:40 +02:00
Ran Benita 0779d9dcad Silence a couple of warnings
These appear to come and go randomly.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-21 17:13:25 +02:00
Ran Benita bb82759c90 Move _text() functions from keymap-dump to text.c
And make them use context_get_buffer() instead of using a static char
array.

This was the last non-thread-safe piece we had, as far as I can tell.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-18 23:12:24 +02:00
Ran Benita e6946ae2c5 Remove a couple more uses of static char buffers
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-18 22:55:17 +02:00
Ran Benita 714e95e144 Contextualize GetBuffer()
Instead storing the buffer in a non-thread-safe static array, we move it
to the context.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-18 22:51:10 +02:00
Ran Benita eb748ab643 Clean up xkb_sym_interpret a bit
First we split the LEVEL_ONE_ONLY bit off of the 'match' field, which
allows us to turn enum xkb_match_operation to a simple enum and remove
the need for MATCH_OP_MASK.

Next we rename 'act' to 'action', because we've settled on that
everywhere else.

Finally, SIMatchText is changed to not handle illegal values - it
shouldn't get any. This removes one usage of the GetBuffer hack.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-18 21:04:27 +02:00
Ran Benita 5d9a5cb003 Commit and distribute ks_tables.h
The ks_tables.h file is generated by makekeys.py from
xkbcommon-keysyms.h, which in turn is generated initially by 'make
update-keysyms'. The xkbcommon-keysyms.h file is commited to git and
distributed in the tarball. Since ks_tables.h should only ever change
when xkbcommon-keysyms.h changes, it is more sensible to update them
together and treat them the same, instead of generating ks_tables.h
every time for every builder with 'make', as we do now.

This means we don't need python as a build dependency (only the one
running update-keysyms, i.e. no one, needs this), and we can be
sure exactly the same file is used by everyone. We also don't need to
run makekeys.py on every build.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-17 20:09:09 +02:00
Ran Benita 179855116d utils: add and use ARRAY_SIZE macro
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-16 21:31:25 +02:00
David Herrmann 7b3bd11f92 Add xkb_keysym_from_name() flags argument for case-insensitive search
This adds a flags argument to xkb_keysym_from_name() so we can perform a
case-insensitive search. This should really be supported as many keysyms
have really weird capitalization-rules.

However, as this may produce conflicts, users must be warned to only use
this for fallback paths or error-recovery. This is also the reason why the
internal XKB parsers still use the case-sensitive search.

This also adds some test-cases so the expected results are really
produced. The binary-size does _not_ change with this patch. However,
case-sensitive search may be slightly slower with this patch. But this is
barely measurable.

[ran: use bool instead of int for icase, add a recommendation to the
doc, and test a couple "thorny" cases.]

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-10-16 21:29:09 +02:00
Ran Benita 5fff637e07 makekeys: replace helper with python script and binary search
This removes the complicated and undocumented hash-table creation-helper
and replaces it with an autogenerated sorted array. The search uses simple
bsearch() now.

We also tried using gperf but it turned out to generate way to big
hashtables and when reducing the size it isn't really faster than
bsearch() anymore.

There are no users complaining about the speed of keysym lookups and we
have no benchmarks that tell that we are horribly slow. Hence, we can
safely use the simpler approach and drop all that old code.

Signed-off-by: Ran Benita <ran234@gmail.com>
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-10-16 21:10:04 +02:00
Ran Benita 3477d9e448 Finish first round of API documentation
There are a few @todo's, but nothing serious.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-13 14:03:29 +02:00
Ran Benita f43b33c02f state: make mod_index_is_consumed() return -1 on invalid input
Like all the other functions.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-13 13:13:55 +02:00
Ran Benita 523e46f41a Change log env vars to XKB_LOG_LEVEL/VERBOSITY
A bit more consistent and descriptive.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-12 10:17:57 +02:00
Ran Benita 89523789ca ast: simplify AppendStmt
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-11 21:51:08 +02:00
Ran Benita bbf388ec1f Make xkb_keymap_num_leds return the index range instead of active count
Currently xkb_keymap_num_leds() returns a count of valid (settable)
leds. Because the indexes might be non-consecutive, and some leds
might not be settable, it is incorrect to use this function for
iterating over the leds in the keymap. But this is the main use case of
this function, so instead of the current behavior we adapt the function
to the use case by making it return the needed range of iteration.
The caller needs to handle invalid intermittent indexes, though.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-11 16:54:17 +02:00
Ran Benita b6ddd10568 keymap: rename keymap->sym_interpret -> sym_interprets
This can be a bit confusing.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-11 14:05:49 +02:00
Ran Benita e43f53a698 compat: add documentation for interpret's
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-11 14:03:03 +02:00
Ran Benita 90b1984cba compat: don't forget to copy XKB_MATCH_NONE interpret's
Commit a8d462e366 accidentally removed the
OR with XKB_MATCH_NONE. It is in fact unused though.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-11 12:10:26 +02:00
Ran Benita 9197eb0fb3 Remove the XKB_NUM_INDICATORS limit
Use a darray instead of a static array of size 32.
We still enforce XKB_MAX_LEDS because of the size of xkb_led_mask_t.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-10 19:44:23 +02:00
Ran Benita f3732d8349 keymap: don't use darray for keymap->keys
It's never resized.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-10 17:51:06 +02:00
Ran Benita bdea377c93 Rename XKB_NUM_GROUPS to XKB_MAX_GROUPS
This is a more appropriate name now.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-10 17:30:15 +02:00
Ran Benita 1dbb2c4a9a keycodes: refactor AddIndicatorName
Make it shorter and fix the XXX.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-10 12:25:23 +02:00
Ran Benita 2f4db8a95b keymap, state: don't assume led index < xkb_keymap_num_leds
xkb_keymap_num_leds() returns the number of leds that have any
possibility of being set. Even if a led is defined but can not be set in
any way, it is not counted.

In a few places currently we assume that led indexes are smaller than
this number, which is wrong both for the above reason and for the fact
that the xkb format actually allows explicitly setting the indicator
index, which means that the indexes might be non-consecutive.

We don't really have good API to iterate on leds, now, because
xkb_keymap_num_leds is pretty useless. To work around that we use
sizeof(xkb_led_mask_t) * 8.

This makes the "Group 2" led work (try switching to a layout other than
the first in test/interactive).

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-10 10:10:45 +02:00
Ran Benita 9179fed76b keysym: fix xkb_keysym_is_upper/lower() to work properly
Our current code (taken from the xserver) doesn't handle unicode keysyms
at all, and there seem to be some other changes compared to libX11,
which is what xkbcomp uses. So we just copy the code that does that from
libX11.
It would be much better to not have to hardcode unicode tables like
that, but it's probably better than dealing with glibc locale stuff for
now. It also doesn't affect our binary size much.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-09 21:39:16 +02:00
Ran Benita 2ac319c54a compat: fix bad interpret predicate mods "all" calculation
Commit 9984d1d03c changed the type of
interpret->mods to xkb_mod_mask_t, but this bit of code assumes that the
type is uint8_t.
This code is not usually run (for example by our tests), but when it
does keymap-dump would print out all of the modifiers (including the
virtual ones) which causes recompilation of the output to fail
miserably.

https://bugs.freedesktop.org/show_bug.cgi?id=55769

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-09 10:36:48 +11:00
Ran Benita 9984d1d03c keymap: use xkb_mod_mask_t for interpret->mods and modmap
These are both real modifier masks, but we keep this information only in
the program logic now so when we change it we don't have to worry about
the type.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:42:42 +02:00
Ran Benita fcceeeafa8 symbols: refactor AddModMapEntry
It really asks for it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:42:00 +02:00
Ran Benita 6d74e66e3f Replace 0xff with MOD_REAL_MASK_ALL
To make it easier to see where it's used. The name is just to match
MOD_REAL.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:42:00 +02:00
Ran Benita a1124b5991 expr: unify the real and virtual modifier functions
This again pushes the mod type annotation to the original call site, to
make it easier to grep to see where the real/virtual distinction
matters.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:42:00 +02:00
Ran Benita 39232e6dae Remove now-unneeded mod type annotations
Most of the mod type annotations can now be changed to MOD_BOTH, because
if you pass a mask which can only contain real mods in the first place to
e.g. ModMaskText, then MOD_REAL and MOD_BOTH will give the same result.

In the cases where MOD_BOTH is only ever the argument, we just remove
it. What's left is where it really "matters".

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-06 21:42:00 +02:00
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