Commit Graph

227 Commits (27f2743cf19ec6e2d4e8fe8d172a7e2e7cf99a38)

Author SHA1 Message Date
Ran Benita 59fb79e75e test/state: fix missing xkb_state_unref
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-09-25 10:05:26 +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 9e92319db4 test/interactive: use xkb_state_key_get_one_sym() when there's only 1
Kind of odd, but get_one_sym() will be getting a different behavior.
Real life users *should* pick one or the other.

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 9cef902dab test: make sure keycode 0 works fine
It is a legal keycode but we never tried it actually.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-08-14 11:37:57 +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 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 7f1b7a1c36 test/keyseq: add de(neo) Level{6,7,8} tests
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-07-25 13:21:33 +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 0c8e9e0c9c test: sync test/data from xkeyboard-config 2.9
Needed for some tests. The tests need some adjustment, mostly because of
the resolution of xkeyboard-config bug
https://bugs.freedesktop.org/show_bug.cgi?id=50935

Also add the 'ch' symbols file for future tests.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-07-22 22:28: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 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
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
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
Daniel Stone 38654f5e74 Add key-sequence checking to rulescomp
Make sure we're actually getting the keymaps we're hoping to
compile.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2013-04-01 17:50:08 +01:00
Daniel Stone 4d7600bd0c test: Add va_list variant of test_key_seq
For use when chaining tests.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2013-03-19 10:59:38 +00:00
Daniel Stone 40c46ecd5b Allow NULL rmlvo for xkb_keymap_new_from_names
Previously we allowed you to pass a names struct with five NULL members,
but not just pass NULL for the struct itself.  This was pretty dumb. :(

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2013-03-19 10:54:23 +00:00
Daniel Stone 22ba1fa1a6 test: Add environment checking to rulescomp
To ensure that overriding RMLVO from the environment works.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2013-03-19 10:54:23 +00:00
Daniel Stone 964b2a4023 test: Suppress RMLVO environment inheritance by default
But add a flag to allow it for later usage.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2013-03-19 10:54:23 +00: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
Daniel Stone d4c22ecc8a test: Use test_get_context() in log.c
Since the only behavioural change is overriding default includes.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2013-03-19 10:34:28 +00:00
Daniel Stone 54f95f496f test: Add flags argument to test_get_context()
Allowing overriding of environment suppression, at first.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2013-03-19 10:28:23 +00:00
Daniel Stone a1f203c031 test: Move test_key_seq to common.c
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2013-03-19 10:25:52 +00:00
Ran Benita 559252a1a8 keyseq: add a couple of tests
Tests the filter refcounting.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:06 +00:00
Ran Benita 79329e1022 Don't try to build linux-specific tests on non-linux
Some tests use linux/input.h (and epoll), but we're building on some
other kernels (e.g. debian freebsd). We could just copy the file but
it's GPL. We could also skip the tests (exit code 77) but it doesn't
really matter.

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 a0fc9066ef test/rmlvo-to-kccgst: free memory before exit
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:04 +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 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 10c351f516 test/interactive: change variable name for 'xkb' to 'keymap'
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
Ran Benita 0ad8bf573f test/interactive: also print the level
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:01 +00:00
Ran Benita bc7b2ff2fb test/keyseq: re-add de(neo) level5 test
See:
https://bugs.freedesktop.org/show_bug.cgi?id=50935
This works now after syncing with recent xkeyboard-config.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:01 +00:00
Ran Benita 4058110676 Sync test data from xkeyboard-config
Sync the files again from xkeyboard-config 2.8, since there have been
some changes we should test against.

Also added a script test/data/sync.sh if we want to do it again in the
future.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:01 +00:00
Ran Benita d87035adac test/keysym: '\e' is non-standard
test/keysym.c:139:43: warning: non-ISO-standard escape sequence, '\e'
Didn't warn about it before..

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-11-07 18:59:41 +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 94155878ec test/keyseq: add test for setting depressed group
Tests the SetGroup action is working properly.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-29 20:20:51 +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 c1c1b720b0 test: add key processing benchmark
This runs a bunch of random keys against xkb_state_update_key() and
xkb_state_key_get_one_sym(), in a fairly unintelligent way.

It might be nice to check when modifying this code path, or changing it,
to see things haven't slowed down considerably. However, given the
numbers this benchmark gives, it is pretty clear that we are not going
to be the bottleneck for anything. So this can more-or-less be ignored.

Incidentally, this also turned out to be a poor man's fuzzer, because it
turned up the fix in the previous commit. Maybe we should consider
beefing it up with an actual 'break stuff' intention and running it as
part of 'make check'.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-24 23:27:40 +02:00
Ran Benita e24ed49c72 test/interactive: use num_layouts_for_key()
This is the more appropriate for a specific key (also considering the
num_layouts() is a bit of a made-up value).

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-23 17:22:13 +02:00
Ran Benita a807494e47 test/interactive: add option to show state changes
Pass -c to see.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-22 22:23:29 +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
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 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 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 a05fbc17c5 stringcomp: test compilation of a dump of a keymap created from rules
This would have caught the regression fixed in 2ac319c.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-10 19:44: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