Commit Graph

437 Commits (357c00b3a1c28afeb352887397ab9549740f1c85)

Author SHA1 Message Date
Ran Benita f967d46b65 test/context: use a more portable directory-exists check
MSVC doesn't have opendir/closedir.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 15:47:49 +02:00
Ran Benita 670566f0d4 Only add GCC diagnostic pragmas when compiler is GCC compatible
Avoid "unknown pragma" warnings on other compilers.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 15:20:25 +02:00
Ran Benita 40aab05e77 build: include config.h manually
Previously we included it with an `-include` compiler directive. But
that's not portable. And it's better to be explicit anyway.

Every .c file should have `include "config.h"` first thing.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 13:09:11 +02:00
Peter Hutterer ca033a29d2 rules: add include statements to rules files
The majority use-case for extending XKB on a machine is to override one or a
few keys with custom keycodes, not to define whole layouts.

Previously, we relied on the rules file to be a single file, making it hard to
extend. libxkbcommon parses $XDG_CONFIG_HOME/xkb/ but that only works as long
as there is a rule that matches the user-specified RMLVO. This works for MLV
but not for options which don't have a wildcard defined. Users have to copy
the whole rules file and then work from there - not something easy to extend
and maintain.

This patch adds a new ! include directive to rules files that allows including
another file. The file path must be without quotes and may not start with the
literal "include". Two directives are supported, %H to $HOME and %S for the
system-installed rules directory (usually /usr/share/X11/xkb/rules).

A user would typically use a custom rules file like this:

! option                =       symbols
  custom:foo            =       +custom(foo)
  custom:bar            =       +custom(baz)

! include %S/evdev

Where the above defines the two options and then includes the system-installed
evdev rule. Since most current implementations default to loading the "evdev"
ruleset, it's best to name this $XDG_CONFIG_HOME/xkb/rules/evdev, but any
valid name is allowed.

The include functionally replaces the line with the content of the included
file which means the behavior of rules files is maintained. Specifically,
custom options must be defined before including another file because the first
match usually wins. In other words, the following ruleset will not assign
my_model as one would expect:

! include %S/evdev

! model                 =  symbols
  my_model              =  +custom(foo)

The default evdev ruleset has wildcards for model and those match before the
my_model is hit.

The actual resolved components need only be in one of the XKB lookup
directories, e.g. for the example above:

$ cat $XDG_CONFIG_HOME/xkb/symbols/custom
partial alphanumeric_keys
xkb_symbols "foo" {
    key <TLDE> {        [      VoidSymbol ]       };
};

partial alphanumeric_keys
xkb_symbols "baz" {
    key <AB01> {        [      k, K ]       };
};

This can then be loaded with the XKB option "custom:foo,custom:bar".

The use of "custom" is just as an example, there are no naming requirements
beyond avoiding already-used ones. Also note the bar/baz above - the option
names don't have to match the component names.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-24 09:50:03 +02:00
Peter Hutterer 1de2f174c2 test: let rmlvo-to-kccgst take long options like rmlvo-to-keymap
The short options were left for backwards compatibility.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-11-18 15:32:35 +02:00
Ran Benita c79c80335b atom: combine atom_intern() and atom_lookup()
Use an "add" bool parameter instead. This simplifies the code a bit.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-09 21:28:43 +02:00
Ran Benita 2a6155936c test/atom: increase iteration count and print random seed on failure
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-08 22:40:13 +02:00
Ran Benita 2af474e8d0 parser: get rid of "stealing" atoms
This requires (well, at least implemented by) casting away `const` which
is undefined behavior, and clang started to warn about it.

The micro optimization didn't save too many allocations, anyway.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-08 12:13:31 +02:00
Peter Hutterer 31e561fca9 test: remove a superfluous string-is-null check
A few lines above we check path_rel[0], so any null pointer will blow up
before we get here.

Found by coverity

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-11-07 11:10:00 +02:00
Peter Hutterer 96ef14ac94 test: fix a potential memory leak
Found by coverity

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-11-07 11:10:00 +02:00
Ran Benita 3515ba19a6 test: xkeyboard-config: bring back the progress bar
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-01 10:45:43 +02:00
Peter Hutterer 8f93e22a37 test: xkeyboard-config: invoke the python3 command (#120)
python3 is always python3, but python could be python2 in some cases. Or just
missing (e.g. RHEL8).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-11-01 10:41:16 +02:00
Peter Hutterer 0609073ce0 test: xkeyboard-config: add missing variant tests
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-11-01 10:24:03 +02:00
Peter Hutterer f4a0f73882 test: xkeyboard-config: use universal_newlines instead of decode
This way stdin/stdout of the process are opened in text mode and we don't need
manually decode.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-11-01 10:24:03 +02:00
Peter Hutterer 7832cc727c test: xkeyboard-config: flake8 fixes
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-11-01 10:24:03 +02:00
Peter Hutterer cd5a24aa38 test: xkeyboard-config: handle keyboard interrupts correctly
In python multiprocessing, each process needs to handle (and ignore) the
KeyboardInterrupt to avoid exception logging. This is a separate patch for
easier reviewing, the first hunks merely re-indent all of the
xkbcommontool/xkbcomp functions into a try/except KeyboardInterrupt block.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-11-01 10:24:03 +02:00
Peter Hutterer 9fc0cb8777 test: xkeyboard-config: print to stderr on failure, stdout otherwise
This is a change in behavior and requires any automated callers to adjust
accordingly. Still, much easier to get the errors that way rather than it
being mixed into a thousands-of-lines output file.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-11-01 10:24:03 +02:00
Peter Hutterer f53838477d test: xkeyboard-config: add a multiprocessing.Pool() to speed up the test
Collect all options into a dictionary, then process that as async actions
through a process pool. This of course requires collecting the various print
statements to avoid mangled output.

This dropped the time to completion from around 14 min to 8 min on my local
machine (unscientific single run only for the original timing).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-11-01 10:24:03 +02:00
Peter Hutterer 1e13190685 test: xkeyboard-config: use argparse for the path and the tool selection
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-11-01 10:24:03 +02:00
Peter Hutterer 255200faa7 test: add test for the various default include paths
All tests create a temporary directory, set up the environment for that
directory and then check the include paths for the presence of that directory,
ideally in the right position of the list.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-10-31 19:29:30 +02:00
Ran Benita 45496c33f1 test: fix printf("%s", NULL) in error path
../test/common.c: In function ‘test_get_path’:
    ../test/common.c:171:9: warning: ‘%s’ directive argument is null [-Wformat-overflow=]
      171 |         fprintf(stderr, "Failed to allocate path (%d chars) for %s\n",
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      172 |                 (int) path_len, path);
          |                 ~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-10-19 00:38:43 +03:00
Ran Benita 076047b21a keymap-dump: use consistent capitalization for "Group<N>"
It's used capitalized everywhere except a couple places.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-10-16 10:36:41 +03:00
Ran Benita a6ed0304f7 keymap-dump: fix invalid names used for levels above 8
xkbcomp only accepts the "Level" prefix for a level name for levels 1 to
8, but the keymap dumping code added it always, e.g. "Level15".

The plain integer, e.g. "8", "15" is always accepted, so just use that.

Fixes https://github.com/xkbcommon/libxkbcommon/issues/113

Signed-off-by: Ran Benita <ran@unusedvar.com>
Reported-by: progandy
2019-10-16 10:36:37 +03:00
Ran Benita ab4b4b7f12 travis: improve configuration and add macOS
Signed-off-by: Ran Benita <ran234@gmail.com>
2019-07-25 14:34:17 +03:00
Ran Benita 7407d311bf test/symbols-leak-test: fix sed regex on macOS
Signed-off-by: Ran Benita <ran234@gmail.com>
2019-07-25 14:18:42 +03:00
Ran Benita 97f41fe4ac test/symbols-leak-test: make it work with macOS diff
The <() stuff fails with an error:
    diff: extra operand `/dev/fd/61'

Signed-off-by: Ran Benita <ran234@gmail.com>
2019-07-25 13:24:00 +03:00
Ran Benita 6728ebca4a test/rmlvo-to-keymap: drop basename usage
It wants some libgen.h include which is POSIX only, let's just remove
it as it's hardly important.

Signed-off-by: Ran Benita <ran234@gmail.com>
2019-07-25 12:00:27 +03:00
worldofpeace 32d178b50f test/rmlvo-to-keymap.c: fix compilation on Darwin (#101)
program_invocation_short_name isn't portable.
2019-07-19 09:56:41 +03:00
Daniel Stone 909cc04d2c interactive-wayland: Port to stable xdg-shell (#100)
xdg_shell v6 was pretty close to the finalised stable version of
xdg-shell. We can now just use the stable version, which is supported
everywhere (Enlightenment, KWin, Mutter, Weston, wlroots).

This requires bumping the wayland-protocols dependency.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2019-07-02 15:48:32 +03:00
Peter Hutterer 878bc08559 test: allow for absolute paths to be resolved
This makes it possible to check a keymap sitting elsewhere than in the test
directory.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-08-21 11:31:10 +10:00
Peter Hutterer 16c84cdd81 test: drop the rmlvo ability from print-compiled-keymap
This is now handled by the rmlvo-to-keymap tool

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-08-21 11:31:07 +10:00
Peter Hutterer d1cb8ad409 test: add a tool to test-compile all LVO combinations from xkeyboard-config
This test contains of two parts:
- a simple program to convert RMLVO commandline arguments into a keymap (and
  print that keymap if requested).
- a python script that runs through rules/evdev.xml, and tries to compile a
  keymap for sort-of every layout/variant/option combination. Sort-of, because
  we can have multiple options and it really only does one per layout(variant)
  combination.

Same thing can be done using xkbcomp, but right now it doesn't take that as
argument, it's hard-coded.

This takes quite a while, installing python-tqdm is recommended to see fancy
progress bars instead of just miles of dumps.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-08-21 11:30:45 +10:00
Ran Benita 5cee660f69 keysym-utf: reject out-of-range Unicode codepoints in xkb_keysym_to_utf{8,32}
It used to be UTF-8 was defined for inputs > 0x10FFFF, but nowadays
that's the maximum and a codepoint is encoded up to 4 bytes, not 6.

Fixes: https://github.com/xkbcommon/libxkbcommon/issues/58
Fixes: https://github.com/xkbcommon/libxkbcommon/issues/59
Reported-by: @andrecbarros
Signed-off-by: Ran Benita <ran234@gmail.com>
2018-06-23 22:53:42 +03:00
Ran Benita afea3dd0cd test/interactive-wayland: replace tabs with spaces
Match the style of all other files.

Signed-off-by: Ran Benita <ran234@gmail.com>
2018-01-27 20:42:44 +02:00
Ran Benita 767fa86d42 Convert http:// -> https:// where possible
Signed-off-by: Ran Benita <ran234@gmail.com>
2017-12-21 14:18:07 +02:00
Ran Benita 29998c258c test/x11: properly clean up also when skipping test
To make valgrind happy.

Signed-off-by: Ran Benita <ran234@gmail.com>
2017-12-12 15:58:32 +02:00
Ran Benita 6456835f1c test/data: sync with xkeyboard-config 2.22
Some tweaks to the de(neo) keyseq tests were required. It seems to have
improved.

Signed-off-by: Ran Benita <ran234@gmail.com>
2017-12-03 13:07:21 +02:00
Ran Benita 14686cd1a8 test/interactive-wayland: avoid unused function warning due to configuration
test/interactive-wayland.c:95:1: warning: ‘set_cloexec_or_close’ defined but not used [-Wunused-function]

Signed-off-by: Ran Benita <ran234@gmail.com>
2017-08-16 20:24:27 +03:00
Ran Benita fbd86e44ad test/symbols-leak-test.bash: make it easier to read
Signed-off-by: Ran Benita <ran234@gmail.com>
2017-08-03 13:38:14 +03:00
Ran Benita 4309735de3 build: use top_srcdir consistently
Signed-off-by: Ran Benita <ran234@gmail.com>
2017-07-31 15:55:48 +03:00
Ran Benita d44ba481d7 build: remove unneeded preprocessor include flags
Better to avoid these unexpected include paths.

Signed-off-by: Ran Benita <ran234@gmail.com>
2017-07-31 15:55:48 +03:00
Ran Benita daebdb5e08 x11/keymap,test/interactive-evdev: fix a couple of clang-analyzer warnings
From my analysis these values cannot be null, but the analyzer cannot
see this. So assert it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2017-07-31 15:55:48 +03:00
Ran Benita 2d9640651a test/x11comp: fix compiler warnings
Signed-off-by: Ran Benita <ran234@gmail.com>
2017-07-31 15:55:48 +03:00
Naman Dixit 4f17fc6005 Fixed a minor bug in error detection in Wayland test 2017-05-27 09:15:26 +00:00
Ran Benita c9832d4374 test/interactive-x11: handle NULL from xcb_wait_for_event
Can happen in cases like:
- There was an error between the error check and the call.
- The internal poll() fails.

Signed-off-by: Ran Benita <ran234@gmail.com>
2017-04-28 09:33:25 +03:00
Ran Benita 5d821aed9b test/x11comp: be a bit more careful with kill()
We did it correctly but better be safe and appease clang.

Signed-off-by: Ran Benita <ran234@gmail.com>
2017-04-11 21:01:41 +03:00
Ran Benita 9d94145808 test/interactive-wayland: mark a local function static
Signed-off-by: Ran Benita <ran234@gmail.com>
2017-04-11 21:01:41 +03:00
Ran Benita 03f4a03e71 test/interactive-wayland: handle unrecognized SHM format
The enum seems large, and we don't handle all of the values in it.
Previously if we got an unrecognized SHM format we would use an
uninitialized `stride`.

Signed-off-by: Ran Benita <ran234@gmail.com>
2017-04-11 21:01:41 +03:00
Ran Benita 0f43cfa225 test/interactive-wayland: fix uninitialized `ret` in error path
Signed-off-by: Ran Benita <ran234@gmail.com>
2017-04-11 21:01:41 +03:00
Daniel Stone 90bd9fdb01 interactive-wayland: Port to xdg-shell v6
Mutter only implements v6 now, and Weston also implements that. Port
interactive-wayland to this so people can keep on using it.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2017-04-11 15:09:50 +01:00
Ran Benita b5586a6c42 keysym: fix locale dependence in xkb_keysym_from_name()
We currently use strcasecmp, which is locale-dependent. In particular,
one well-known surprise even if restricted just ASCII input is found in
the tr_TR (Turkish) locale, see e.g.
https://msdn.microsoft.com/en-us/library/ms973919.aspx#stringsinnet20_topic5

We have known to avoid locale-dependent functions before, but in this
case, we forgot.

Fix it by implementing our own simple ASCII-only strcasecmp/strncasecmp.
Might have been possible to use strcasecmp_l() with the C locale, but
went the easy route.

Side advantage is that even this non-optimized version is faster than
the optimized libc one (__strcasecmp_l_sse42) since it doesn't need to
do the locale stuff. xkb_keysym_from_name(), which uses strcasecmp
heavily, becomes faster, and so for example Compose file parsing, which
uses xkb_keysym_from_name() heavily, becomes ~20% faster.

Resolves https://github.com/xkbcommon/libxkbcommon/issues/42
Signed-off-by: Ran Benita <ran234@gmail.com>
2016-12-02 23:46:56 +02:00
Ran Benita babc9e0c30 state: add GTK consumed modifiers mode
This is more or less what is implemented here:
https://git.gnome.org/browse/gtk+/tree/gdk/x11/gdkkeys-x11.c?h=3.19.10#n1131

The implementation here is more technically correct but should provide
the same results.

Try it out with ./test/interactive-evdev -g (modifiers prefixed with "-"
are consumed).

https://bugzilla.gnome.org/show_bug.cgi?id=754110
https://github.com/xkbcommon/libxkbcommon/issues/17

Signed-off-by: Ran Benita <ran234@gmail.com>
2016-10-31 12:52:28 +02:00
Ran Benita a0a41332cc state: allow different modes for calculating consumed modifiers
The current functions dealing with consumed modifiers use the
traditional XKB definition of consumed modifiers (see description in the
added documentation). However, for several users of the library (e.g.
GTK) this definition is unsuitable or too eager. This is exacerbated by
some less-than-ideal xkeyboard-config type definitions (CTRL+ALT seems
to cause most grief...).

So, because we
- want to enable alternative interpretations, but
- don't want to expose too much internal details, and
- want to keep things simple for all library users,
we add a high-level "mode" parameter which selects the desired
interpretation. New ones can be added as long as they make some sense.

All of the old consumed-modifiers functions keep using the traditional
("XKB") mode. I mark xkb_state_mod_mask_remove_consumed() and as
deprecated without adding a *2 variant because I don't it is very useful
(or used) in practice.

Alternative modes are added in subsequent commits (this commit only adds
a mode for the existing behavior).

https://github.com/xkbcommon/libxkbcommon/issues/17

Signed-off-by: Ran Benita <ran234@gmail.com>
2016-10-31 12:52:26 +02:00
Ran Benita 914c060a1d test/state: move wrongly-placed assert
Signed-off-by: Ran Benita <ran234@gmail.com>
2016-10-22 20:13:11 +03:00
Ran Benita 8978ec39ed test/interactive-wayland: fix control reaches end of non-void function
AFAICS there is nothing that can fail directly in this function, so
change it to void.

Signed-off-by: Ran Benita <ran234@gmail.com>
2016-06-09 17:23:55 +03:00
Ran Benita 81ee012af0 test/symbols-leak-test: use more portable shebang
Some BSDs don't want to give bash the honor of /bin and put it
elsewhere. So look it up in PATH instead.

Signed-off-by: Ran Benita <ran234@gmail.com>
2016-06-09 15:00:43 +03:00
Ran Benita 316c7e2479 test/interactive-wayland: don't ignore asprintf return value
Fixes warn_unused_result warning.

Signed-off-by: Ran Benita <ran234@gmail.com>
2016-05-05 15:43:59 +03:00
Ran Benita fc41d3d605 test: use termios instead of system() for disabling terminal echo
Takes care of GCC's annoyingly persistent warn_unused_result warnings.
But it's better to avoid system() I suppose.

Signed-off-by: Ran Benita <ran234@gmail.com>
2016-05-05 15:41:13 +03:00
Daniel Stone 48d5b44fd0 interactive-wayland: Valgrind-proofing
More meticulously free everything we create, including hooking up the
buffer-release callback so we actually free those when required. Make
sure seats are actually in the display's seat list.

The xkbcommon object-unref functions don't actually require
NULL-checking, so we can elide those.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2016-04-12 13:19:25 +01:00
Daniel Stone 7e123a10b6 test: Add interactive-wayland
interactive-wayland is very similar to x11/xev, and dumps out as much
state as possible.

It provides no titlebar and a completely random cursor, but such is
life.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2016-04-12 12:15:04 +01:00
Ran Benita 4c24f7faa8 test: assert/ignore some warn_unused_result's
Signed-off-by: Ran Benita <ran234@gmail.com>
2016-03-15 20:45:05 +02:00
Ran Benita 37ee8e652b test/x11comp: fix memory leak
Signed-off-by: Ran Benita <ran234@gmail.com>
2016-03-13 23:17:23 +02:00
Ran Benita fa1b454328 test: add a test that all symbol version file is updated
It is easy to forget to update these files when adding new symbols.

Stolen with slight changes from libinput (commit by Marek Chalupa):
https://cgit.freedesktop.org/wayland/libinput/commit/?id=a9f216ab47ea2f643f20ed741b741a2b5766eba3

Signed-off-by: Ran Benita <ran234@gmail.com>
2016-03-13 23:17:23 +02:00
Mike Blumenkrantz 0ce17ef3ea keymap: add xkb_keymap_key_by_name(), xkb_keymap_key_get_name(), tests
xkb_keymap_key_by_name() allows finding a keycode from a given keyname and
is useful for generating keyboard events to use in regression tests
during CI

xkb_keymap_key_get_name() is the inverse of xkb_keymap_key_by_name()

Signed-off-by: Mike Blumenkrantz <zmike@osg.samsung.com>
[ran: some stylistic tweaks + another test case]
Signed-off-by: Ran Benita <ran234@gmail.com>
2016-01-20 23:17:10 +02:00
Kazunobu Kuriyama 91a19905b3 test/x11comp: Fix contention between X11 and Xvfb on Mac OS X
- Abandon use of -displayfd.
 - Have x11comp itself look for an unused X11 display number instead.
2015-08-28 19:37:09 +09:00
Ran Benita 74f85d0540 test/x11comp: remove duplicate FOUR_LEVEL_KEYPAD from test keymap
The `test/data/keymaps/host.xkb` file contains a duplicate definition of
this type. On my computer (linux, xkbcomp 1.3.0, xserver 1.17.2), the
test passes as is, but if I remove the duplicate definition, the
roundtrip brings it back and the test fails. I can also reproduce it
without relation to the test, by loading `test/data/keymaps/host.xkb`
(without the duplicate) using

    xkbcomp -I $(pwd)/test/data/keymaps/host.xkb $DISPLAY

and downloading it again using

    xkbcomp $DISPLAY out.xkb

the duplicate is added. On Mac OS X however, the duplicate is removed
(correctly), so the test fails there.

xkbcommon itself, which was forked from xkbcomp, doesn't have this bug;
in fact, doing

    ./test/print-compiled-keymap -k keymaps/host.xkb

removes the duplicate if it is present.

This is (probably) a regression in xkbcomp or xserver compared to the
versions used in Mac OS X. Since getting a patch for any of these two is
hopeless from my experience, I did not try to investigate further.

I am not sure why, but if I also add a `PC_SUPER_LEVEL2` type, the
duplicate of `FOUR_LEVEL_KEYPAD` doesn't show up. Hopefully the test
will work on all platforms now.

https://github.com/xkbcommon/libxkbcommon/issues/26

Reported-by: @nuko8
Signed-off-by: Ran Benita <ran234@gmail.com>
2015-08-23 23:16:37 +03:00
Ran Benita bdf6880364 test/x11comp: small simplifications
xkbcomp doesn't need the search-path argument, since we pass an absolute
path. Keep the plain -I which clears the search path just to be sure.

Signed-off-by: Ran Benita <ran234@gmail.com>
2015-08-23 23:16:23 +03:00
Ran Benita 8e1fed6c68 compose: correctly parse modifier syntax
As described in:
http://cgit.freedesktop.org/xorg/lib/libX11/commit/?id=ddf3b09bb262d01b56fbaade421ac85b0e60a69f

Signed-off-by: Ran Benita <ran234@gmail.com>
2015-03-24 16:49:47 +02:00
Ran Benita 74482de623 test/common: print keycode in decimal not hex
Keycodes are usually written in decimal, so hex is hard to compare.

Signed-off-by: Ran Benita <ran234@gmail.com>
2015-02-03 21:47:08 +02:00
Ran Benita a0d2b02976 test/keyseq: test 'map[None] = Level2;' scenario
See previous commit for an explanation.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-17 01:19:22 +03:00
Ran Benita 312182ce7d test/data: add files for model=applealu_ansi layout=us
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-17 01:19:03 +03:00
Ran Benita c6ee6371b5 test/data: sync to xkeyboard-config 2.13
(Run ./test/data/sync.sh).

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-17 01:19:03 +03:00
Ran Benita c42b864654 test/compose: test include statement
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-14 11:47:25 +03:00
Ran Benita 3f489730d3 test/compose: test modifier syntax
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-14 11:36:00 +03:00
Ran Benita 5cefa5c5d0 test/interactive-evdev: add compose support
To try, do e.g.:
sudo ./test/interactive-evdev -l us -v intl -o compose:ralt -d

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-05 12:56:46 +03:00
Ran Benita 10a7a2bd69 test/compose: add new test
Some results from the benchmark (compilation of en_US.UTF-8/Compose):

$ grep 'model name' /proc/cpuinfo
model name  : Intel(R) Core(TM)2 Duo CPU     E8400  @ 3.00GHz
model name  : Intel(R) Core(TM)2 Duo CPU     E8400  @ 3.00GHz

$ uname -a
Linux ran 3.16.1-1-ARCH #1 SMP PREEMPT Thu Aug 14 07:40:19 CEST 2014 x86_64 GNU/Linux

$ ./test/compose bench
compiled 1000 compose tables in 7.776488331s

So according to the above benchmark and valgrind --tool=massif, an
xkb_compose_table adds an overhead of about ~8ms time and ~130KB
resident memory.
For contrast, a plain US keymap adds an overhead of ~3ms time and 90KB
resident memory.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-05 12:56:46 +03:00
Ran Benita bc3b4c084a Move benchmarks from tests to their own files in bench/
The tests only contain tests, and the benchmarks are more visible.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-02 22:03:28 +03:00
Ran Benita 68962aa1f9 keymap-dump: combine modifier_map's with the same modifier
A bit less efficient, but makes for shorter, nicer output.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-09-22 00:05:38 +03:00
Ran Benita 24846080db test/keyseq: add test
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-09-11 14:08:12 +03:00
Ran Benita a931740cc7 keycodes: fix keymap compilation with no aliases and malloc(0)==NULL
If the keymap doesn't have any key-aliases (which is certainly
possible), the calloc(num_key_aliases, ...) is allowed to return NULL
according to the C standard, but this is not an error.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-09-10 13:44:33 +03:00
Ran Benita ba98562909 test: make most tests portable by copying linux/input.h locally
There is really no reason to deny these tests from different platforms
only for a few #defines.

The only linux-only test (or test program, it is not run by make check)
is interactive-evdev, which actually uses evdev.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-09-06 11:29:15 +03:00
Pino Toscano e95fb475eb Remove <linux/input.h> include from test/x11comp.c
libxkbcommon 0.4.3 introduces a new test, x11comp, which does not build
on non-Linux OSes because of the unconditional <linux/input.h> include.

This seems not needed even on Linux, so attached there is a simple patch
to remove it.

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

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-09-06 11:11:13 +03:00
Ran Benita fc95057c5f test/x11comp: don't hang if Xvfb is not available
If Xvfb is not present, posix_spawn still forks, but the child fails.
In that case, since we left the write fd of the pipe open in the parent,
we just kept waiting on the read() without noticing that the other side
is dead.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-09-01 17:20:40 +03:00
Ran Benita f3597f1b62 test/state: add test_update_mask() test
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-08-18 21:51:57 +03:00
Ran Benita a95c4e83e4 test/x11comp: server writes \n to displayfd
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-08-18 19:47:10 +03:00
Ran Benita 4df720b464 test/x11-keyseq: new test
It is like test/stringcomp, only instead of using
xkb_keymap_new_from_string(), it uses xkbcomp to upload the keymap to a
dummy Xvfb X server and then xkb_x11_keymap_new_from_device().

If any of these components are not present or fails, the test is shown
as skipped.

The test is messy, fragile, limited and depends on external tools, but I
will improve on that later -- it's better to have a test.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-08-09 22:57:24 +03:00
Ran Benita 5058620c88 interactive-evdev: don't use sysexits.h
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-07-27 16:36:11 +03:00
Ran Benita 40f109af56 ast-build: make sure InterpDef is freeable
With the following two rules:

    InterpretDecl   :       INTERPRET InterpretMatch OBRACE
                                VarDeclList
                            CBRACE SEMI
                            { $2->def = $4; $$ = $2; }
                    ;

    InterpretMatch  :       KeySym PLUS Expr
                            { $$ = InterpCreate($1, $3); }
                    |       KeySym
                            { $$ = InterpCreate($1, NULL); }
                    ;

And the fact that InterpCreate doesn't initialize ->def, if the
VarDeclList fails, the %destructor tries to recursively free the
uninitialized ->def VarDef. So always initialize it.

That was the only problematic code in the parser for %destructor (I'm
pretty sure).

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-07-27 14:32:18 +03:00
Ran Benita f5182bbd74 test: add file with a syntax error
We didn't really have any. It also a exposes a memory leak, since the
parser doesn't clean up the AST nodes of the discarded symbols.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-07-26 22:29:22 +03:00
Ran Benita 67d884ec14 Remove unnecessary !!(expressions)
_Bool already does that.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-06-01 15:24:10 +03:00
Ran Benita 5417440970 state: fix consumed modifier calculation
The current calculation is in short:
    entry ? (entry->mask & ~entry->preserve) : 0

This changes it be
    type->mask & ~(entry ? entry->preserve : 0)

This is what Xlib does. While less intuitive, it is actually more
correct, if you follow this deduction:

- The key group's type->mask defines which modifiers the key even cares
  about. The others are completely irrelevant (and in fact they are
  masked out from all sided in the level calculation). Example: NumLock
  for an alphabetic key.

- The type->mask, the mods which are not masked out, are *all* relevant
  (and in fact in the level calculation they must match *exactly* to the
  state). These mods affect which level is chosen for the key, whether
  they are active or not.

- Because the type->mask mods are all relevant, they must be considered
  as consumed by the calculation *even if they are not active*.

Therefore we use type->mask instead of entry->mask.

The second change is what happens when no entry is found: return 0 or
just take preserve to be 0? Let's consider an example, the basic type

    type "ALPHABETIC" {
        modifiers = Shift+Lock;
        map[Shift] = Level2;
        map[Lock] = Level2;
        level_name[Level1] = "Base";
        level_name[Level2] = "Caps";
    };

Suppose Shift+Lock is active - it doesn't match any entry, thus it gets
to level 0. The first interpretation would take them both to be
unconsumed, the second (new one) would take them both to be consumed.
This seems much better: Caps is active, and Shift disables it, they both
do something.

This change also fixes a pretty lousy bug (since 0.3.2), where Shift
appears to apparently *not* disable Caps. What actually happens is that
Caps is not consumed (see above) but active, thus the implicit
capitalization in get_one_sym() kicks in and capitalizes it anyway.

Reported-by: Davinder Pal Singh Bhamra
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-03-27 19:38:30 +02:00
Ran Benita 3cfa7fdac8 state: apply control transformation on utf8/utf32 keysym strings
This is required by the specification:
http://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Control_Modifier
and clients expect this to happen.

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

Reported-by: Gatis Paeglis <gatis.paeglis@digia.com>
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-03-22 20:07:30 +02:00
Ran Benita b973d71e82 state: add xkb_state_key_get_{utf8,utf32}() API functions
These functions generally have the same effect as
xkb_state_key_get_syms() + xkb_keysym_to_utf{8,32}().

So why add them?

- They provide a slightly nicer interface, especially if the string is
  the only interest.

- It makes the handling of multiple-keysyms-to-utf8 transparent. For the
  designated use-case of multiple-keysyms (unicode combining
  characters), this is a must. We also validate the UTF-8, which the
  user might not otherwise do.

- We will need to apply some transformation on the resulting string
  which depend on the xkb_state. This is not possible with the
  xkb_keysym_* functions.

With these functions, the existing xkb_keysym_to_utf{8,32}() are not
expected to be used by a typical user; they are "raw" functions.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-03-22 17:17:16 +02:00
Ran Benita 2bbaf7c7d1 Add utf8.{c,h} for common UTF-8 util functions
We need to validate some UTF-8, so this adds an is_valid_utf8()
function, which is probably pretty slow but should work correctly.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-03-22 02:10:28 +02:00
Ran Benita 6adf17bd5a interactive-x11: beef up select_events a bit
- Specify in detail which parts of the events we care about. In theory
  the X server should not bother us with things we didn't ask for. In
  practice it still does, but oh well.

- Use the _aux version of select_events. This is the correct one to use,
  the non-aux version is useless.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-28 15:30:49 +02:00
Jasper St. Pierre 4fb7b06b0f state: Add xkb_state_key_get_consumed_mods
This retrieves the mask of consumed modifiers for a given key and state,
which is helpful for toolkits without having them to do it one modifier
at a time, or pass in 0xFFFFFFFF to xkb_state_remove_consumed_mods to
"reverse-engineer" the consumed mods.
2014-02-22 02:23:37 +02:00
Ran Benita 11a9f76bf2 keymap-dump: don't print "affect=lock" in PtrLock
It's the same as no flags, so might as well not print it.
(In fact it is slightly harmful, because it actively *clears* the affect
flags, which might have been set in some other manner. But in practice
this cannot happen).

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-15 23:31:54 +02:00
Ran Benita 067c8c25c4 test/rmlvo-to-kccgst: use default RMLVO values in translation
The tool's supposed to display exactly the same results as the library
code.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-10 13:15:58 +02:00
Ran Benita 973b8fd47e api: deprecate XKB_MAP_COMPILE_PLACEHOLDER, and use KEYMAP instead of MAP
The PLACEHOLDER was not meant to be used, but c++ doesn't like passing 0
to enums, so it was used. For this reason we add all the NO_FLAGS items,
so the PLACEHOLDER shouldn't be used anymore.

Second, XKB_MAP is the prefix we used ages ago, KEYMAP is the expected
prefix here. So deprecate that as well.

The old names may still be used through the xkbcommon-compat.h header,
which is included by default (no need to include directly).

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-08 16:40:20 +02:00
Ran Benita 94e0be0dc7 test/state: fix tautological test
test/state.c:376:5: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-08 00:54:53 +02:00
Ran Benita 623b10f8c5 Fix sign-compare warnings
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-08 00:54:53 +02:00
Ran Benita 623602cb78 test: don't print control characters in interactive tests
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-07 01:35:56 +02:00
Ran Benita 2f93c78894 x11: add a couple of tests
Add two tests:

    ./test/interactive-x11
which is like test/interactive-evdev, but should behave exactly like your
X keyboard and react to state and keymap changes - in other words, just
like typing in xterm. Press ESC to exit.

    ./test/x11
which currently should only print out the same keymap as
    xkbcomp $DISPLAY out.xkb
(modulo some whitespace and some constructs we do not support.)

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-02 11:16:40 +02:00
Ran Benita d63e0ab838 test: rename test/interactive to interactive-evdev
And share the key-printing functions. In preparation for adding more
interactive-* variants.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-01-13 17:21:56 +02:00
Ran Benita 4841ea0c29 test/state: fix some *_{is,are}_active() tests
These functions also return -1 on invalid input. The original tests
didn't check that, but used !tests instead. Since then we've changed
them, but some were missed, and for some we forgot to remove the ! (or
you can say they were extra clever).

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-01-11 17:01:39 +02:00
Ran Benita 31430670df Fix some cppcheck warnings
Someone was nice enough to run this for us:

ftp://ftp.sunet.se/pub/Linux/distributions/Debian/debian/pool/main/libx/libxkbcommon/libxkbcommon_0.3.1.orig.tar.gz
[libxkbcommon-0.3.1/src/keymap.c:86]: (style) The scope of the variable 'j' can be reduced.
[libxkbcommon-0.3.1/src/keymap.c:87]: (style) The scope of the variable 'key' can be reduced.
[libxkbcommon-0.3.1/src/keysym-utf.c:843]: (style) The scope of the variable 'mid' can be reduced.
[libxkbcommon-0.3.1/src/state.c:992]: (style) The scope of the variable 'str' can be reduced.
[libxkbcommon-0.3.1/src/xkbcomp/action.c:467]: (style) The scope of the variable 'absolute' can be reduced.
[libxkbcommon-0.3.1/src/xkbcomp/rules.c:468]: (style) The scope of the variable 'consumed' can be reduced.
[libxkbcommon-0.3.1/src/xkbcomp/rules.c:862]: (style) The scope of the variable 'mlvo' can be reduced.
[libxkbcommon-0.3.1/src/xkbcomp/rules.c:863]: (style) The scope of the variable 'kccgst' can be reduced.
[libxkbcommon-0.3.1/src/xkbcomp/rules.c:865]: (style) The scope of the variable 'match_type' can be reduced.
[libxkbcommon-0.3.1/src/xkbcomp/symbols.c:753]: (style) The scope of the variable 'toAct' can be reduced.
[libxkbcommon-0.3.1/src/xkbcomp/symbols.c:1573]: (style) The scope of the variable 'key' can be reduced.
[libxkbcommon-0.3.1/test/common.c:80]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.
[libxkbcommon-0.3.1/test/interactive.c:358]: (style) The scope of the variable 'nevs' can be reduced.
[libxkbcommon-0.3.1/test/interactive.c:236]: (style) Checking if unsigned variable 'nsyms' is less than zero.
[libxkbcommon-0.3.1/test/interactive.c:226]: (style) Unused variable: unicode

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-01-11 17:01:39 +02:00
Ran Benita b246edc688 test/atom: add test for atom table
Mostly a random test.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-12-02 15:13:59 +02:00
Ran Benita ba7530fa90 scanner: restore lost DIVIDE token
I don't know how this could have happened. Luckily this token is
completely useless.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-11-27 13:45:15 +02:00
Ran Benita 65f9980b24 rules: fix scanning of line-continuation without leading space
We were failing to scan something like\
this correctly.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-10-14 19:05:24 +03:00
Ran Benita f813bdbfdc rulescomp: increase BENCHMARK_ITERATIONS from 1000 to 2500
1000 is a bit too low for statistical significance on this 6 years old
CPU. Since the benchmark is run manually this shouldn't be a problem.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-10-10 22:02:30 +03:00
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