Commit Graph

1417 Commits (5270a5532470564168affb04d5749de65efc3d05)

Author SHA1 Message Date
Uli Schlachter 1b3a1c277a Remove three more round trips
There are a number of XKB requests needed to request all the information from
the X11 server. So far, the code was sending one request and waiting for the
reply. This commit starts batching the request so that we get multiple replies
with one round trip.

This removes three round trips.

Only the simple requests are converted. get_map() and get_names() use some
bitmasks that are needed for both the request and the reply. These will be dealt
with separately.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2021-03-09 11:00:13 +02:00
Uli Schlachter b9707c1db0 Save three more round trips in xkb_x11_keymap_new_from_device()
Instead of asking for an atom name and waiting for the reply four times, this
now sends four GetAtomName requests and waits for all the replies at once. Thus,
this saves three round trips.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2021-03-09 11:00:13 +02:00
Uli Schlachter 40c00b4721 xkb_x11_keymap_new_from_device: Less X11 round-trips
On my system, calling xkb_x11_keymap_new_from_device() did 78 round trips to the
X11 server, which seems excessive. This commit brings this number down to about
9 to 10 round trips.

The existing functions adopt_atom() and adopt_atoms() guarantee that the atom
was adopted by the time they return. Thus, each call to these functions must do
a round-trip. However, none of the callers need this guarantee.

This commit makes "atom adopting" asynchronous: Only some time later is the atom
actually adopted. Until then, it is in some pending "limbo" state.

This actually fixes a TODO in the comments.

Fixes: https://github.com/xkbcommon/libxkbcommon/issues/216
Signed-off-by: Uli Schlachter <psychon@znc.in>
2021-03-09 11:00:13 +02:00
Pierre Le Marre 30ce6c04f9 Fix a few keysymtab entries to match their comment in xkbcommon-keysyms.h
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-02-27 22:06:42 +02:00
Peter Hutterer 0bfc71e7b5 Update keysym definitions to latest xorgproto
As of xorgproto commit e5d8af9711516385f8346c9e077692b29c914478

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-02-22 13:43:16 +02:00
Ran Benita fbf087ea94 keymap-dump: follow xkbcomp in printing affect=both in pointer actions
It is equivalent to nothing but good to match up.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-11-23 20:03:17 +02:00
Ran Benita ac6cd20c55 x11: fix type level names missing
When reading the keymap, the level names would get discarded.
Regressed in 26453b8473.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-11-23 18:49:49 +02:00
Ran Benita 4aed3c6811 x11/keymap: fix case with no actions
Possible regression in f41e609bbe (not
confirmed yet).

Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-11-23 18:24:52 +02:00
Ran Benita 1bd3b3c7cb x11: cache X11 atoms
On every keymap notify event, the keymap should be refreshed, which
fetches the required X11 atoms. A big keymap might have a few hundred of
atoms.

A profile by a user has shown this *might* be slow when some intensive
amount of keymap activity is occurring. It might also be slow on a
remote X server.

While I'm not really sure this is the actual bottleneck, caching the
atoms is easy enough and only needs a couple kb of memory, so do that.

On the added bench-x11:

Before: retrieved 2500 keymaps from X in 11.233237s
After : retrieved 2500 keymaps from X in 1.592339s

Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-11-20 13:04:21 +02:00
Ran Benita f41e609bbe x11: eliminate slow divisions
Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-11-20 12:50:50 +02:00
Peter Hutterer afdc9ceee7 xkbcomp: where a keysym cannot be resolved, set it to NoSymbol
Where resolve_keysym fails we warn but use the otherwise uninitialized variable
as our keysym. That later ends up in the keymap as random garbage hex value.

Simplest test case, set this in the 'us' keymap:
    key <TLDE>               {      [        xyz ] };

And without this patch we get random garbage:
./build/xkbcli-compile-keymap --layout us | grep TLDE:
    key <TLDE>               {      [      0x018a5cf0 ] };

With this patch, we now get NoSymbol:
./build/xkbcli-compile-keymap --layout us | grep TLDE:
    key <TLDE>               {      [        NoSymbol ] };
2020-10-20 09:23:50 +10:00
hhb 69713ce3e9
parser: fix another format string for int64_t (#191) 2020-09-11 15:06:23 +03:00
Peter Hutterer d327475282 utils: include unistd.h where we have it
MacOS doesn't have eaccess/euidaccess but it does have unistd.h, so let's
include it to silence the R_OK redefinition compiler warnings.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-07 22:01:57 +03:00
Peter Hutterer a350222cc9 context: fix a compiler warning
../src/context.c:57:9: warning: variable 'err' is used uninitialized whenever
'if' condition is true [-Wsometimes-uninitialized]

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-07 22:01:57 +03:00
Peter Hutterer 3039d62a48 registry: mark the rxkb_log function as attribute printf
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-07 22:01:57 +03:00
Peter Hutterer d7b39f6ffb Add /etc/xkb as extra lookup path for system data files
This completes the usual triplet of configuration locations available for most
processes:
- vendor-provided data files in /usr/share/X11/xkb
- system-specific data files in /etc/xkb
- user-specific data files in $XDG_CONFIG_HOME/xkb

The default lookup order user, system, vendor, just like everything else that
uses these conventions.

For include directives in rules files, the '%E' resolves to that path.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-30 21:49:41 +03:00
Peter Hutterer 05d6efc417 xkbcomp: allow including kccgst files from other paths
Previously, a 'symbols/us' file in path A would shadow the same file in path B.
This is suboptimal, we rarely need to hide the system files - we care mostly
about *extending* them. By continuing to check other lookup paths, we make it
possible for a XDG_CONFIG_HOME/xkb/symbols/us file to have sections including
those from /usr/share/X11/xkb/symbols/us.

Note that this is not possible for rules files which need to be manually
controlled to get the right bits resolved.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-30 21:49:41 +03:00
Peter Hutterer bbc7005b2a xkbcomp: simplify the include path handling
Streamline the code a bit - instead of handling all the if (!file) conditions
handle the case of where we have a file and jump to the end.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-30 21:49:41 +03:00
Peter Hutterer 351b4b9c0b xkbcomp: move the logging of include paths into a helper function
No functional changes, prep work for some other refacturing.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-30 21:49:41 +03:00
Emmanuel Gil Peyrot ddd1188d97 Make path retrieval consistent in xkb_compose_table_new_from_locale() 2020-07-23 09:39:53 +03:00
Emmanuel Gil Peyrot 17ad0df14a compose: add xdg base directory support
Before reading ~/.XCompose, try to read $XDG_CONFIG_HOME/XCompose
(falling back to ~/.config/XCompose).

This helps unclutter the home directory of users who want that.
2020-07-23 09:39:53 +03:00
Peter Hutterer dcb6c7b8a4 xkbcomp: return NULL, not false in place of a FILE*
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-13 18:41:00 +10:00
Peter Hutterer d4b78a5fca xkbcomp: simplify buffer handling in the include handling
Don't do the realloc dance, just asprintf to the buffer and move on. The check
is likely pointless anyway, if we run out of asprintf size, log_error will
probably blow up as well.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-13 18:41:00 +10:00
Peter Hutterer 41a7c975f8 Add asprintf_safe helper function
We only ever care about whether we error out or not, so let's wrap this into
something more sane.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-13 18:41:00 +10:00
Peter Hutterer ce286601b0 context: log include paths for debugging
Now that we're relying on various different include paths, let's log that ones
we use and the ones we failed to use.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-08 15:21:19 +10:00
Peter Hutterer e55587f4cf meson.build: always set the default variants/options
Make this more balanced with the rules/layouts so we can rely on that #define to
exist.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-08 15:21:19 +10:00
Peter Hutterer afb26e7df9 Add libxkbregistry to query available RMLVO
This library is the replacement for clients parsing evdev.xml directly.
Instead, they should use the API here so that in the future we may even
be able to swap evdev.xml for a more suitable data format.

The library parses through evdev.xml (using libxml2) and - if requested -
through evdev.extras.xml as well. The merge approach is optimised for
the default case where we have a system-installed rules XML and another file in
$XDG_CONFIG_DIR that adds a few entries.  We load the system file first, then
append any custom ones to that. It's not possible to overwrite the MLVO list
provided by the system files - if you want to do that, get the change upstream.

XML validation is handled through the DTD itself which means we only need to
check for a nonempty name, everything else the DTD validation should complain
about.

The logging system is effectively identical to xkbcommon.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-06 15:15:20 +10:00
Peter Hutterer fe88613382 utils: add streq_null() for streq that allows NULL values
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-06 15:15:20 +10:00
Peter Hutterer 9b1b0c5743 Add a snprintf_safe() helper function
Returns true on success or false on error _or_ truncation. Since truncation is
almost always an error anyway, we might as well make this easier to check.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-06 15:15:20 +10:00
Peter Hutterer d075c3e697 Factor the access check for paths out
Easier to re-use without having to duplicate ifdefs.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-06 15:15:20 +10:00
Ran Benita 892cfef834 keysyms: add XKB_KEY_XF86FullScreen
Updated using ./scripts/update-keysyms using latest xorgproto.

Fixes: https://github.com/xkbcommon/libxkbcommon/issues/147
Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-05-20 20:42:02 +03:00
Ran Benita 860cfc039f keymap: don't forget about fallback mappings in xkb_keymap_key_get_mods_for_level()
If the active set of modifiers doesn't match any explicit entry of the
key type, the resulting level is 0 (i.e. Level 1). Some key types don't
explicitly map Level 1, taking advantage of this fallback.

Previously, xkb_keymap_key_get_mods_for_level didn't consider this, and
only reported masks for explicit mappings. But this causes some glaring
omissions, like matching "a" in the "us" keymap returning not results.

Since every mask which isn't explicitly mapped falls back to 0, we can't
return the all. Almost always the best choice for this is the empty
mask, so return that, when applicable.

Fixes https://github.com/xkbcommon/libxkbcommon/issues/140.
Reported-by: https://github.com/AliKet
Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-04-18 22:23:06 +03:00
Jaroslaw Kubik d92a248c48 API to query modifier set required to type a keysym
The new API is useful to implement features like auto-type and
desktop automation. Since the inputs for these features is usually
specified in terms of the symbols that need to be typed, the
implementation needs to be able to invert the keycode->keysym
transformation and produce a sequence of keycodes that can be used
to type the requested character(s).
2020-03-20 19:20:36 +02:00
Jaroslaw Kubik 0345aba082 Support translation Unicode codepoints to keysyms
In order to support features like auto-type and UI automation, the
relevant tools need to be able to invert the keycode->keysym->text
transformation. In order to facilitate that, a new API was added.
It allows querying the keysyms that correspond to particular Unicode
codepoints. For all practical purposes, it can be thought of as an
inverse of xkb_keysym_to_utf32().
2020-02-24 09:54:09 +02:00
Adrian Perez de Castro 5354dee2f7 MSVC: Use <io.h> as an alternative for <unistd.h>
Only the input/output functions from <unistd.h> options are used, so
using <io.h> when building with MSVC should be enough. The inclusion
of the header in context-priv.c does not seem to be needed (tested
on GNU/Linux) and so it is removed.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-28 16:12:15 +02:00
Ran Benita fadfb13c42 xkbcomp/rules: support \r\n line endings
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-28 14:19:22 +02:00
Ran Benita da4a90c13e Open files in binary mode
This turns off some misfeatures on Windows, and does nothing on POSIX.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-28 13:49:40 +02:00
Ran Benita 521bb498ed xkbcomp: remove cast which triggers warning on gcc
Will need some other way to take care of the warning on MSVC.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 22:09:34 +02:00
Ran Benita fbd0e643d8 xkbcomp: make a couple of casts explicit to mark them as checked
This acknowledges some "possible loss of data cast" warnings from MSVC.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 21:55:14 +02:00
Ran Benita 1849158afd xkbcomp/keywords: regenerate with newer gperf
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 15:20:25 +02:00
Ran Benita 823708b73e parser: fix format string for int64_t
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 15:20:25 +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 40bea8e9fa xkbcomp: fix wrong return type
Detected by MSVC:

xkbcomp\xkbcomp.c(111): warning C4047: 'return': 'bool' differs in levels of indirection from 'void *'

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 15:04:40 +02:00
Ran Benita 6ca1a0c9f6 parser: use int64_t for all numbers
Don't use int which can have different size on different machines.
Also avoid some warnings from MSVC:

xkbcomp/parser.y(760): warning C4244: '=': conversion from 'int64_t' to 'int', possible loss of data
xkbcomp/parser.y(761): warning C4244: '=': conversion from 'int64_t' to 'int', possible loss of data
xkbcomp/parser.y(767): warning C4244: '=': conversion from 'int64_t' to 'int', possible loss of data

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 14:17:55 +02:00
Ran Benita c3ac58a941 scanner-utils: avoid possible implicit truncating of line/column
This increases the size of the struct a bit but it's not very important.

Fixes these MSVC warnings:

src\scanner-utils.h(112): warning C4267: '+=': conversion from 'size_t' to 'unsigned int', possible loss of data
src\scanner-utils.h(147): warning C4267: '+=': conversion from 'size_t' to 'unsigned int', possible loss of data

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 14:06:47 +02:00
Ran Benita 0fdd29bb7b utils: move macro defines to before they're used
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 13:55:24 +02:00
Ran Benita 64137a4ab5 utils: fix typo in strndup fallback
Fixup 93a1305 - we will have CI for this soon.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 13:52:51 +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
Adrian Perez de Castro bdff8ebe3c Provide a fallback implementation of [v]asprintf()
Some environments (e.g. Windows + MSVC) do not provide asprintf() or
vasprintf(). This tries to detect their presence, and provides suitable
fallback implementations when not available.
2019-12-27 12:45:34 +02:00
Adrian Perez de Castro 93a13050d6 Provide a fallback implementation of strndup()
Some environments (e.g. Windows + MSVC) do not provide strndup(), this
tries to detect its presence and provide a fallback implementation when
not available.

[ran: some tweaks]
2019-12-27 12:45:14 +02:00
Adrian Perez de Castro a8acc2ff5c Use built-in istr[n]cmp() instead of strcase[n]cmp()
This avoids the problem that MSVC does not provide strcasecmp() nor
strncasecmp(), and at the same time avoids potential problems due to
locale configuration by using istrcmp() and istrncmp() which are
already in the source tree and written to cover only ASCII.
2019-12-27 12:36:39 +02:00
Ran Benita 34122f9f06 utils: use MIN/MAX instead of min/max
min/max symbols conflict on some systems (msvc), so just use the macros.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 12:34:49 +02:00
Ran Benita ade131307c xkbcomp: downgrade "Symbol added to modifier map for multiple modifiers" log to a warning
This condition happens in xkeyboard-config keymaps and seems hard to
fix. Currently it incessantly spams people's logs who have no idea what
to do about it. So downgrade to "warning" level, so it doesn't show up
by default.

When working on keymaps, set `XKB_LOG_LEVEL=debug XKB_LOG_VERBOSITY=10`
to see all possible messages.

Refs https://github.com/xkbcommon/libxkbcommon/issues/111
Fixes https://github.com/xkbcommon/libxkbcommon/issues/128
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-27 12:26:35 +02:00
Peter Hutterer 00f31e0d27 rules: eliminate an extra fopen/fclose cycle
FindXkbFileInPath() opens the file so we're guaranteed that the file not only
exists, but that we can read it. Changing that would alter behavior so instead
let's just pass that file handle along and do the same for include files.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-24 09:50:03 +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 67b538ddc0 context: add a helper function to return the default system include path
No functional changes but we'll need that same lookup in the rules file
include handling in a future patch.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-24 09:50:03 +02:00
Peter Hutterer 3c57b3289a rules: move the matcher result handling to the caller
This shouldn't be processed in the matcher itself, especially in the glorious
future when we can have nested matchers. Only handle this once in the caller
to the original parsed file.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-24 09:50:03 +02:00
Peter Hutterer 2ec07b62b5 rules: put the scanner on the stack
This allows nesting the scanner for the future !include directive.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-24 09:50:03 +02:00
Peter Hutterer bb7551a649 rules: simplify an error path
Initialize to NULL so we don't have to care about whether the cleanups can be
called or not.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-24 09:50:03 +02:00
Peter Hutterer d9b9885624 rules: rename a variable from 's' to 'str'
To avoid name conflicts with a future patch.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-24 09:50:03 +02:00
Peter Hutterer 2a578a60b3 rules: drop the matcher_err() macro and use scanner_err directly
No functional changes, this is what the macro expanded to anyway. Prep work
for putting the scanner on the stack and removing it from the matcher struct.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-24 09:50:03 +02:00
Peter Hutterer f57c13ea4f rules: factor out the function to parse a rules file
No functional changes, this just makes the part to parse a single rules file
re-usable.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-24 09:50:03 +02:00
Peter Hutterer 13b30f4f0d keysym: handle ssharp in XConvertCase()
lowercase: LATIN SMALL LETTER SHARP S (U+00DF)
uppercase: LATIN CAPITAL LETTER SHARP S (U+1E9E)

The uppercase sharp s (XK_ssharp) is a relatively recent addition to unicode
but was added to the relevant keyboard layouts in xkeyboard-config-2.25
(d1411e5e95c)
https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/issues/144

Alas, the CapsLock behavior was broken on the finnish layout (maybe others).
This was due XConvertCase() never returning the uppercase characters.

Let's make this function return the right lower/upper symbols for the sharp s
and hope that the world won't get any worse because of it.

Corresponding Xlib issue:
https://gitlab.freedesktop.org/xorg/lib/libx11/issues/110

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-12-22 10:12:53 +02:00
Ran Benita a237f4f699 parser: fix the remaining pointer chasing
Fix the TODO added in 7c42945.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-12-14 13:45:05 +02:00
Ran Benita 7c42945e04 parser: fix quadratic pointer chasing
In the AST, lists (e.g. the list of statements in a file) are kept in
singly-linked lists -- each AST node has a `next` pointer available for
this purpose.

Previously, a node was added to the list by starting from the head,
chasing to the last, and appending. So creating a list of length N would
take ~N^2/2 pointer dereferences.

Now, we always (temporarily) keep the last as well, so appending is O(1)
instead of O(N).

Given a keymap

    xkb_keymap {
    xkb_keycodes {
    minimum = 8;
    minimum = 8;
    minimum = 8;
    minimum = 8;
    minimum = 8;
    [... repeated N times ...]
    };
    xkb_types {};
    xkb_compat {};
    xkb_symbols {};
    };

The compilation times are

N       | Before   | After
--------|----------|-------
10,000  | 0.407s   | 0.006s
20,000  | 1.851s   | 0.015s
30,000  | 5.737s   | 0.021s
40,000  | 12.759s  | 0.023s
50,000  | 21.489s  | 0.035s
60,000  | 40.473s  | 0.041s
70,000  | 53.336s  | 0.039s
80,000  | 72.485s  | 0.044s
90,000  | 94.703s  | 0.048s
100,000 | 118.390s | 0.057s

Another option is to ditch the linked lists and use arrays instead. I
got it to work, but its more involved and allocation heavy so turns out
to be worse without further optimizations.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-14 22:10:09 +02:00
Ran Benita f9b95c06c1 parser: remove an unneeded check
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-14 22:10:09 +02:00
Ran Benita 3d43f4806d compat: reject interpret modifier predicate with more than one value
Given

    interpret ISO_Level3_Shift+AnyOf(all,extraneous) { ... };

Previously, extraneous (and further) was ignored. Now it's rejected.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-12 22:31:46 +02:00
Ran Benita 7d44c7a9f9 expr: fix log message on some unexpected expression types
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-12 22:09:19 +02:00
Ran Benita 406beecae5 Replace some tabs that sneaked in with spaces
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-12 22:06:02 +02:00
Ran Benita 322cd8563c parser: fix merge mode only applied to first vmod in a virtual_modifiers statement
Given

    augment virtual_modifiers NumLock,Alt,LevelThree

Previously it was expanded (directly in the parser) to

    augment virtual_modifiers NumLock;
    virtual_modifiers Alt;
    virtual_modifiers LevelThree;

Now it expands to

    augment virtual_modifiers NumLock;
    augment virtual_modifiers Alt;
    augment virtual_modifiers LevelThree;

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-12 20:37:09 +02:00
Ran Benita 400cc84911 ast: use a separate expr struct for action list
Currently it's under UnaryExpr, which just doesn't make sense.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-12 20:07:12 +02:00
Ran Benita 8c62d48c0c ast-build: get rid of unhelpful macro
Straightforward code is better here.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-12 19:16:08 +02:00
Ran Benita 4849bc1914 atom: a string is greater than its prefix
Bug accidentally introduced in 9a92b46.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-09 22:11:22 +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 adbd9c6f08 atom: correct iteration count in hash function
Fixup of ccab349 - unlike the commit message, hash a byte twice instead
of zero times, which is probably better. This is how it was before.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-09 13:50:59 +02:00
Ran Benita 9ebf97d706 atom: describe how this odd data structure works
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-09 13:13:30 +02:00
Ran Benita ccab349c99 atom: use a better hash function
FNV-1a instead of the djb2-like one from before.

Keep the unrolling since it seems quite beneficial, even though it loses
one byte if the length is odd...

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-09 13:01:43 +02:00
Ran Benita 9a92b4643b atom: style changes
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-09 12:26:19 +02:00
Ran Benita 1fe1b65385 atom: remove handling of garbage input
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-09 11:40:07 +02:00
Ran Benita a5f95c2b3c atom: use explicit size for fingerprint
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-09 11:33:45 +02:00
Ran Benita 8ea4a001d1 atom: replace an avoidable strlen
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-09 00:20:45 +02:00
Ran Benita 6f8bb5ee70 atom: remove redundant field
The field is redundant.

Due to alignment, this will only save memory on 32bit architectures.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-11-09 00:05:59 +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 e23f1061b2 Use XDG_CONFIG_HOME as first XKB search path
Use $XDG_CONFIG_HOME/xkb as the primary lookup path for XKB rules. Same
motivation as in 3a91788d92, however the XDG directories are more standard
and recommended these days than application-specific dotfiles.

The XDG spec says to fall back to $HOME/.config where XDG_CONFIG_HOME is not
set so we implement that behavior as well.

Fixes #112

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-10-31 19:29:30 +02:00
Jan Alexander Steffens (heftig) 4b3783987e context: Don't fail to create the context if HOME isn't available
E.g. when Mutter has CAP_SYS_NICE and thus secure_getenv returns NULL.

Fixes https://bugs.archlinux.org/task/64191

[ran: changed to ignore error]
Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-10-20 23:00:30 +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 3a91788d92 context: move ~/.xkb to before XKB_CONFIG_ROOT in the default include path
Previously, the default include path was XKB_CONFIG_ROOT:~/.xkb.

The ~/.xkb include path is intended to allow the local user to customize
their keymaps without having to modify system paths.

But usually, the user only wants to customize specific parts. When
XKB_CONFIG_ROOT is first, the user can only customize through the "entry
point" (the RMLVO). When ~/.xkb is first, the user can drop in a file
and it will override the system one.

The impetus for this change is the rules file. "evdev" is hard-coded
everywhere, so it not often not possible to change to something else.
And the rules files determines how the rest of the RMLVO is interpreted.
So, to enable customization, we have these options:

A: System includes user.
B: User includes system.
C: Library goes over both in one or the other order.

Option A is problematic due to backward compatibility and is also
unnatural.

Option B gives the user control and is backward compatible, so that's
what we choose. This is also how Compose files are handled, and that
seems to work fine in the wild.

Option C is actually less flexible than B, and more complicated.

(The rules file format doesn't have an include statement yet, but it's
planned).

Signed-off-by: Ran Benita <ran@unusedvar.com>
2019-10-03 17:27:00 +03:00
Michael Forney 9d58bbd4ff Use bitwise test instead of popcount to check if one bit is set
We don't need to determine the total number of bits set to determine if
exactly one is set.

Additionally, on x86_64 without any -march=* flag, __builtin_popcount
will get compiled to a function call to the compiler runtime (on gcc),
or a long sequence of bit operations (on clang).

Signed-off-by: Michael Forney <mforney@mforney.org>
2019-06-10 11:15:55 -07:00
Konstantin Kharlamov 75d1110c22 symbols: add a comment to suppress warning from code analyzers
Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
2019-03-23 23:31:29 +03:00
Hans de Goede 9b85d96d2a Sync Keysyms with recent xproto additions
xproto recently has been extended with 2 new keysyms:
XF86XK_MonBrightnessCycle
XF86XK_RotationLockToggle

This commit is the result of running "scripts/update-keysyms" on a system
with the updated xproto installed.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2019-01-22 08:31:43 +01:00
Alan Coopersmith 31f1f35570 Fix off-by-one error in index check in xkb_file_type_to_string
Found by Oracle's Parfait 2.2 static analyzer:
Error: Buffer overrun
   Read outside array bounds [read-outside-array-bounds] (CWE 125):
      In array dereference of xkb_file_type_strings[type] with index type
      Array size is 56 bytes, index <= 56
        at line 734 of src/xkbcomp/ast-build.c in function 'xkb_file_type_to_string'.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2018-09-30 16:04:29 -07:00
Ran Benita c9a499c9c9 darray: fix unprotected macro argument
Reported-by: @msmeissn
Signed-off-by: Ran Benita <ran234@gmail.com>
2018-08-24 09:19:29 +03:00
Ran Benita a9ace75f64 x11: fix undefined behavior when copying the coordinates of ptr movements actions
Left shift of a negative integer. For some reason the protocol
representation here got really botched (in the spec it is just a nice
and simple INT16).

Signed-off-by: Ran Benita <ran234@gmail.com>
2018-08-18 14:58:03 +03:00
Daniel Stone bb4909d2d8 Fail expression lookup on invalid atoms
If we fail atom lookup, then we should not claim that we successfully
looked up the expression.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2018-08-03 16:24:50 +01:00
Daniel Stone 5440aaa522 Fix signed vs. unsigned confusion in name sanitisation
Don't try to divide through a signed char when indexing an array, lest
ye try to index off the start of it.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2018-08-03 16:17:10 +01:00
Daniel Stone 4fcbc47059 darray: Don't call memcpy() on NULL
The only time we could ever hit this was with count == 0, which seems
unnecessarily pedantic. But OK.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2018-08-03 16:15:49 +01:00
Daniel Stone ae7856db48 text: NULL-terminate SI mask names
The list should have a NULL sentry. Add one.

testcase: 'interpret KP_Delete+AnyOfOrNaneo(ll)'

Signed-off-by: Daniel Stone <daniels@collabora.com>
2018-08-03 16:15:48 +01:00
Daniel Stone 38e1766bc6 xkbcomp: Don't falsely promise from ExprResolveLhs
Every user of ExprReturnLhs goes on to unconditionally dereference the
field return, which can be NULL if xkb_intern_atom fails. Return false
if this is the case, so we fail safely.

testcase: splice geometry data into interp

Signed-off-by: Daniel Stone <daniels@collabora.com>
2018-08-03 16:14:16 +01:00
Daniel Stone 4e2ee9c3f6 xkbcomp: Don't explode on invalid virtual modifiers
testcase: 'virtualModifiers=LevelThreC'

Signed-off-by: Daniel Stone <daniels@collabora.com>
2018-08-03 16:14:16 +01:00
Daniel Stone 96df3106d4 xkbcomp: Don't crash on no-op modmask expressions
If we have an expression of the form 'l1' in an interp section, we
unconditionally try to dereference its args, even if it has none.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2018-08-03 16:13:35 +01:00
Daniel Stone a8ea7a1d3d parser: Don't set more maps when we don't have any
If the scanner indicates that we might have something which looks like a
map, but the parser in fact fails to create that map, we will try to
access the map regardless. Stop doing that.

testcase: 'xkb_keymap {' -> '#kb_keymap'

Signed-off-by: Daniel Stone <daniels@collabora.com>
2018-08-03 16:13:35 +01:00
Peter Hutterer c81682975d action: make a note that we may not null-terminate private strings
Coverity complains that a 7-byte string may not be null-terminated when copied
into act->data (size 7). This is fine, make a note of it.

All the strings in xkeyboard-config only use 6 bytes + null terminator so this
won't be an issue. The server (the only user of these) uses an 8-byte array
and forcibly null-terminates the string, see XkbDDXPrivate().

Everything else treats it as byte-array size 7 anyway so whether it's
null-terminated doesn't matter.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-08-01 18:50:38 +10:00
Peter Hutterer c1e5ac16e7 xkbcomp: fix pointer value for FreeStmt
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-08-01 13:50:38 +10:00
Peter Hutterer badb428e63 keycodes: don't try to copy zero key aliases
Move the aliases copy to within the (num_key_aliases > 0) block.

Passing info->aliases into this fuction with invalid aliases will
cause log messages but num_key_aliases stays on 0. The key_aliases array
is never allocated and remains NULL. We then loop through the aliases, causing
a null-pointer dereference.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-08-01 13:50:38 +10:00
Peter Hutterer 9045b03598 text: init the target buffer to zero
There's a (theoretical?) path where we might end up strcpy() buf without ever
writing to it. This happens if the mask is nonzero but specifies a modifier
larger than the one in the xkb_mod_set.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-08-01 13:50:38 +10:00
Ran Benita 842e4351c2 compose: fix infinite loop in parser on some inputs
The parser would enter an infinite loop if an unterminated keysym
literal occurs at EOF.

Found with the afl fuzzer.

Signed-off-by: Ran Benita <ran234@gmail.com>
2018-07-30 10:35:10 +03:00
Ran Benita 917636b1d0 xkbcomp: fix crash when parsing an xkb_geometry section
xkb_geometry sections are ignored; previously the had done so by
returning NULL for the section's XkbFile, however some sections of the
code do not expect this. Instead, create an XkbFile for it, it will
never be processes and discarded later.

Caught with the afl fuzzer.

Signed-off-by: Ran Benita <ran234@gmail.com>
2018-07-30 10:35:10 +03:00
Ran Benita e3cacae7b1 xkbcomp: fix crashes in the parser when geometry tokens appear
In the XKB format, floats and various keywords can only be used in the
xkb_geometry section. xkbcommon removed support xkb_geometry, but still
parses it for backward compatibility. As part of ignoring it, the float
AST node and various keywords were removed, and instead NULL was
returned by their parsing actions. However, the rest of the code does
not handle NULLs, and so when they appear crashes usually ensue.

To fix this, restore the float AST node and the ignored keywords. None
of the evaluating code expects them, so nice error are displayed.

Caught with the afl fuzzer.

Signed-off-by: Ran Benita <ran234@gmail.com>
2018-07-30 10:35:10 +03:00
Ran Benita 1f9d1248c0 xkbcomp: fix stack overflow when evaluating boolean negation
The expression evaluator would go into an infinite recursion when
evaluating something like this as a boolean: `!True`. Instead of
recursing to just `True` and negating, it recursed to `!True` itself
again.

Bug inherited from xkbcomp.

Caught with the afl fuzzer.

Signed-off-by: Ran Benita <ran234@gmail.com>
2018-07-30 10:35:10 +03: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 b63196e91e keysym-utf: replace the Unicode characters for leftanglebracket and rightanglebracket
Looking at leftanglebracket

- The standard[1] does not specify any Unicode value for it.

- The keysym list keysymdef.h in x11proto[2] says U+27E9 MATHEMATICAL
  RIGHT ANGLE BRACKET in a comment.

- The keysym->unicode list in xkbcommon which comes from [3] has U+2329
  LEFT-POINTING ANGLE BRACKET.

- The keysym->unicode list in Xlib[4] has U+2039 SINGLE LEFT-POINTING
  ANGLE QUOTATION MARK.

[1] https://www.x.org/releases/X11R7.7/doc/xproto/x11protocol.html#Legacy_KEYSYMs
[2] https://cgit.freedesktop.org/xorg/proto/x11proto/tree/keysymdef.h
[3] https://www.cl.cam.ac.uk/%7Emgk25/ucs/keysym2ucs.c
[4] https://cgit.freedesktop.org/xorg/lib/libX11/tree/src/xlibi18n/imKStoUCS.c

The symbols we are using, {LEFT,RIGHT}-POINTING ANGLE BRACKET, are
deprecated according to Unicode[5]:

    These characters are deprecated and are strongly discouraged for
    mathematical use because of their canonical equivalence to CJK
    punctuation.

[5] https://www.unicode.org/charts/PDF/U2300.pdf

Hence, switch to the MATHEMATICAL codepoints which seem to be the best
fit.

Fixes: https://github.com/xkbcommon/libxkbcommon/issues/47
Reported-by: @bytensky
Signed-off-by: Ran Benita <ran234@gmail.com>
2018-02-27 20:24:57 +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 4fccdee383 x11: check and document the correct range of device IDs
The actual value is 127, not 255.

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

Reported-by: Gatis Paeglis <gatis.paeglis@qt.io>
Signed-off-by: Ran Benita <ran234@gmail.com>
2017-12-18 16:41:21 +02:00
Ran Benita 47f45194e4 compose/parser: be more careful when checking if sequence overrides or duplicates another
Signed-off-by: Ran Benita <ran234@gmail.com>
2017-12-12 15:45:37 +02:00
Ran Benita 2963e29f0e xkbcomp/ast-build: fix memory leak when appending multi-keysyms
`syms` was not freed.

Signed-off-by: Ran Benita <ran234@gmail.com>
2017-12-12 14:44:01 +02:00
Ran Benita 26453b8473 keymap: fix NULL dereference when dumping the default fallback type
The default fallback type uses
    type->level_names = NULL
but the keymap-dump code was not checking this case.

Instead of adding more workarounds and possible bugs (e.g. previous
commit), let's just keep the number of level names separately. This has
the additional advantage retains extraneous level name if someone adds
them for some reason.

Signed-off-by: Ran Benita <ran234@gmail.com>
2017-12-12 14:33:24 +02:00
Ran Benita 9f85d6b78c xkbcomp/types: fix types being assigned the wrong number of levels in some circumstances
The buggy code assigned the number of levels based on the number of
level names in the definition, instead of the actual number of levels!
This would completely break type definitions which do not give names to
levels.

This was not noticed for so long because xkeyboard-config always gives
names to all levels.

This regressed in 61fed8dab9.

Reported-by: Gatis Paeglis <gatis.paeglis@qt.io>
Signed-off-by: Ran Benita <ran234@gmail.com>
2017-12-12 14:08:01 +02:00
Ran Benita 18d6aebec0 keysym: add xkb_keysym_to_{lower,upper} to public API
These can be useful in some odd cases.

There is already an implementation (+ tests) for internal use, so all
that's needed is to export them.

If xkbcommon were to provide a way to convert a Unicode codepoint to a
keysym, this could have been implemented externally as follows:

    uint32_t codepoint = xkb_keysym_to_utf32(keysym);
    uint32_t upper_codepoint = my_unicode_library_to_upper(codepoint);
    xkb_keysym_t upper_keysym = theoretical_xkb_keysym_from_utf32(upper_codepoint);

However keysym -> codepoint is not injective so such a function is not
possible strictly speaking.

Signed-off-by: Ran Benita <ran234@gmail.com>
2017-12-11 23:01:18 +02:00
Matt Whitlock 0db1d3131a keysym-utf: Add missing codes for signifblank and permille keysyms 2017-09-28 21:31:28 -04:00
Ran Benita 41f1018897 expr: paper over a maybe-uninitialized warning
Signed-off-by: Ran Benita <ran234@gmail.com>
2017-09-08 12:16:13 +03:00
Ran Benita 993f4837ad build: fix out-of-tree build
The change in d44ba48 removed -I$(top_builddir)/src/xkbcomp, but this is
needed in order to find the generated parser.h file which is put in the
build dir.

I also added -I$(top_builddir)/src in order to match the meson behavior.

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

Signed-off-by: Ran Benita <ran234@gmail.com>
2017-07-31 18:20:58 +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
Hans de Goede 939d0909a4 Sync Keysyms with recent xproto additions
xproto recently has been extended with 4 new keysyms:
XF86XK_Keyboard
XF86XK_WWAN
XF86XK_RFKill
XF86XK_AudioPreset

This commit is the result of running "make update-keysyms" on a system
with the updated xproto installed.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2017-05-12 12:27:05 +02:00
Ran Benita 6b57344c32 state: cure boolean blindness in the filter functions' result
Makes it a little easier to understand the filters.

Signed-off-by: Ran Benita <ran234@gmail.com>
2017-04-27 20:06:21 +03:00
Ran Benita 927fd8f89a state: remove unneeded NULL check
xkb_filter_new() cannot return NULL.

Signed-off-by: Ran Benita <ran234@gmail.com>
2017-04-27 19:17:53 +03:00
Ran Benita d44c3ab28e state: reorder new() functions before the set() functions in the code
So that they may be read more naturally in chronological order.

Signed-off-by: Ran Benita <ran234@gmail.com>
2017-04-27 19:16:04 +03:00
Daniel Stone ce38f96e95 Add explicit fallthrough case statements
When we fall through to another label in a case, add an explicit comment
noting so, to quiet GCC 7's warnings.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2017-04-11 15:09:23 +01:00
Ran Benita 1ec14d0996 compose: remove the keysym_from_name cache
The hit rate is high, but either the cache is slow or the function is
not fast enough -- the cache no longer holds its weight, leading only to
very modest improvements. If it's the former, it can definitely be
improved, the code is very dumb (though it worked just as well as any
other I tried back then). But instead, let's just kill it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2016-12-03 00:22:05 +02: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 327364d277 utils: rename popcount to avoid conflict in NetBSD
Resolves https://github.com/xkbcommon/libxkbcommon/issues/41
Signed-off-by: Ran Benita <ran234@gmail.com>
2016-11-14 17:37:35 +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 9061171957 utils: add popcount function
Signed-off-by: Ran Benita <ran234@gmail.com>
2016-10-22 20:13:46 +03:00
Ran Benita 0dd610fbcb keymap-dump: use consistent order set/latch/lock (style)
Signed-off-by: Ran Benita <ran234@gmail.com>
2016-06-09 16:32:32 +03:00
Ran Benita c8e6996ff9 src/state: match_mod_masks can return bool instead of int
Signed-off-by: Ran Benita <ran234@gmail.com>
2016-06-09 15:30:21 +03:00
Ran Benita 763e2b7e53 src/utils: check if fileno() failed in map_file
fileno() can fail, if called on e.g. fmemopen() FILEs which are not
backed by a file descriptor. This functions uses mmap to map the entire
file to memory, so using such FILEs will not work.

(There is actually no change of behavior here, since the following fstat
would have already failed with EBADF. But lets make it clear.)

Another possibility is to fall back to the !HAVE_MMAP case; but it
sounds like a better idea to leave it to the programmer to use the
new_from_string/new_from_buffer functions instead, instead of doing
double allocation behind their back.

Signed-off-by: Ran Benita <ran234@gmail.com>
2016-03-13 20:24:44 +02:00
Ran Benita 39082082f6 keymap: share LevelsSameSyms()
The function is generic enough.

Signed-off-by: Ran Benita <ran234@gmail.com>
2016-02-28 00:33:19 +02:00
Ran Benita c8a2564588 state: factor out get_entry_for_mods()
Will be useful later.

Signed-off-by: Ran Benita <ran234@gmail.com>
2016-02-28 00:09:30 +02:00
Ran Benita 9f5139b5ea state: factor out entry_is_active() check
Makes the code slightly cleaner and I plan to use the function in
another place.

Signed-off-by: Ran Benita <ran234@gmail.com>
2016-02-28 00:09:19 +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
Ran Benita 2cca028906 src/utils: change map_file to not take const string argument
map_file() uses PROT_READ, so const seems fitting; however unmap_file
calls munmap/free, which do not take const, so an UNCONSTIFY is needed.
To avoid the UNCONSTIFY hack, which is likely undefined behavior or some
such, just remove the const.

Signed-off-by: Ran Benita <ran234@gmail.com>
2015-11-19 00:44:27 +02:00
Ran Benita c7e2e6d7b4 keymap: fix outdated comment
See 725ae134d4.

Signed-off-by: Ran Benita <ran234@gmail.com>
2015-10-26 22:16:54 +02:00
Ran Benita 13d232592e state: reduce scope of fake action
Also rename to "dummy" as I think it is a nicer name.

Signed-off-by: Ran Benita <ran234@gmail.com>
2015-09-07 14:45:09 +03:00
Michael Vogt 7ea129fbfb Add XKB_CONFIG_ROOT environment
The XKB_CONFIG_ROOT environment allows overrding the build time
DFLT_XKB_CONFIG_ROOT path.
2015-07-20 10:31:02 +02: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 9162017947 keycodes: use correct printf format
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-23 21:03:13 +03:00
Ran Benita c03834a1c6 Reduce variable scopes
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-23 21:00:20 +03:00
Ran Benita 5e3615b246 ast-build: remove log message about allocation failure
We don't do so anywhere else, so until we have something comprehensive,
let's not so here.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-18 20:04:57 +03:00
Ran Benita 4a660d7f86 xkbcomp: remove file->topName
It is useless.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-10-18 19:47:19 +03:00