Commit Graph

1418 Commits (f39966344458d947a09a275d09a4a75ea2e54b50)

Author SHA1 Message Date
alois31 f3210cbf27
compose: drop the 65535 node limit (#343)
In commit 1638409b22, the number of
compose nodes was limited to 65535 to enable "future optimizations",
which apparently means slightly reduced memory usage due to fitting in
a uint16_t. At this time, it was mentioned that the author was not
aware of "any compose files which come close".

However, I'm one of the users that actually do require a larger number
of nodes for their compose file. Thus, use a uint32_t again and raise
the limit significantly.
2023-05-15 15:23:16 +03:00
Pierre Le Marre 183761ac24 Do not interpret nor emit invalid Unicode encoding forms
Surrogates are invalid in both UTF-32 and UTF-8.
See https://www.unicode.org/versions/Unicode15.0.0/ch03.pdf#G28875
and https://www.unicode.org/versions/Unicode15.0.0/ch03.pdf#G31703
2023-05-13 22:02:46 +03:00
Pierre Le Marre 5fbffaf035 Add warning when RMLVO with no layout but variant set
There is no feedback that they are both replaced with default values.
Fix it by adding a warning informing about missing layout and show the
defaults for both.
2023-05-13 21:59:37 +03:00
Ran Benita 5a5ab3e880 utils: fix printf format warnings on mingw
See:
https://github.com/mesonbuild/wrapdb/pull/819
c86ae6acf5/src/image_int.hpp (L15)
https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/

Signed-off-by: Ran Benita <ran@unusedvar.com>
2023-05-06 17:29:45 +03:00
Peter Hutterer b06aedb8ba scanner: allow for a zero terminated string as keymap
As the documentation for xkb_keymap_new_from_buffer() states, the "input string
does not have to be zero-terminated". The actual implementation however failed
with "unrecognized token/syntax error" when it encountered a null byte.

Fix this by allowing a null byte at the last position of the buffer. Anything
else is likely a client error anyway.

Fixes #307
2023-05-05 09:57:23 +10:00
Peter Hutterer 8b7c1850e1 registry: remove a few asprintf/free() calls with snprintf
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-05-04 18:46:16 +10:00
Peter Hutterer a50890b155 registry: simplify strdup() error handling
strdup() is the least likely call to fail here, let's move it to the bottom so
we don't need to worry about the allocated string.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-05-04 18:46:16 +10:00
Wismill 5b5b67f28c
Add support for modmap None (#291)
Unlike current xkbcommon, X11’s xkbcomp allows to remove entries in
the modifiers’ map using “modifier_map None { … }”.

“None” is translated to the special value “XkbNoModifier” defined in
“X11/extensions/XKB.h”. Then it relies on the fact that in "CopyModMapDef",
the following code:

    1U << entry->modifier

ends up being zero when “entry->modifier” is “XkbNoModifier” (i.e. 0xFF).
Indeed, it relies on the overflow behaviour of the left shift, which in
practice resolves to use only the 5 low bits of the shift amount, i.e.
0x1F here. Then the result of “1U << 0xFF” is cast to “char”, i.e. 0.

This is a good trick but too magical, so in libxkbcommon we will use
an explicit test against our new constant XKB_MOD_NONE.
2023-05-01 23:30:41 +03:00
Ran Benita 003fdee137 keysyms: add new keysyms XF86EmojiPicker, XF86Dictate
Ref: 914d8f5e0f
Ref: a839f0c7fc
Signed-off-by: Ran Benita <ran@unusedvar.com>
2023-04-12 10:29:42 +03:00
Ran Benita bd79a960f5 Possible fix for non-MSVC windows compilers
`_MSC_VER` is specific to MSVC, but there can be other compilers targeting
windows. Hopefully they do define `_WIN32`, so let's use that.

Refs: https://github.com/xkbcommon/libxkbcommon/issues/305
Signed-off-by: Ran Benita <ran@unusedvar.com>
2023-04-11 23:29:25 +03:00
Peter Hutterer 13d4b7f641 keysym: replace deprecated Serbian_DZE with Cyrillic_DZHE
Same numeric value for both and the Serbian one has been listed as deprecated
for decades.

See https://gitlab.freedesktop.org/xorg/proto/xorgproto/-/merge_requests/69#note_1843415

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-03-31 10:11:59 +10:00
Ronan Pigott b4e81ca172
context: add XKB_CONTEXT_NO_SECURE_GETENV flag (#312)
This flag is useful for clients that may have relatively benign capabilities
set, like CAP_SYS_NICE, that also want to use the xkb configuration from the
environment and user configs in XDG_CONFIG_HOME.

Fixes: https://github.com/xkbcommon/libxkbcommon/issues/308
Fixes: https://github.com/xkbcommon/libxkbcommon/issues/129
Signed-off-by: Ran Benita <ran@unusedvar.com>
2022-12-16 10:26:25 +02:00
Ran Benita 4d8293901b utils: move some MSVC compat stuff to common place
Signed-off-by: Ran Benita <ran@unusedvar.com>
2022-09-24 12:31:53 +03:00
Ran Benita 4000a1bdde keysym-utf: remove bogus currency sign entries
These ended up being mapping in the 0x100xxxx Unicode range, which are
handled automatically ; these special keysyms don't exist (except for
EuroSign).

    #define XKB_KEY_EcuSign                    0x10020a0  /* U+20A0 EURO-CURRENCY SIGN */
    #define XKB_KEY_ColonSign                  0x10020a1  /* U+20A1 COLON SIGN */
    #define XKB_KEY_CruzeiroSign               0x10020a2  /* U+20A2 CRUZEIRO SIGN */
    #define XKB_KEY_FFrancSign                 0x10020a3  /* U+20A3 FRENCH FRANC SIGN */
    #define XKB_KEY_LiraSign                   0x10020a4  /* U+20A4 LIRA SIGN */
    #define XKB_KEY_MillSign                   0x10020a5  /* U+20A5 MILL SIGN */
    #define XKB_KEY_NairaSign                  0x10020a6  /* U+20A6 NAIRA SIGN */
    #define XKB_KEY_PesetaSign                 0x10020a7  /* U+20A7 PESETA SIGN */
    #define XKB_KEY_RupeeSign                  0x10020a8  /* U+20A8 RUPEE SIGN */
    #define XKB_KEY_WonSign                    0x10020a9  /* U+20A9 WON SIGN */
    #define XKB_KEY_NewSheqelSign              0x10020aa  /* U+20AA NEW SHEQEL SIGN */
    #define XKB_KEY_DongSign                   0x10020ab  /* U+20AB DONG SIGN */
    #define XKB_KEY_EuroSign                      0x20ac  /* U+20AC EURO SIGN */

Signed-off-by: Ran Benita <ran@unusedvar.com>
2022-05-15 10:41:53 +03:00
Ran Benita 49e8a2d85b keysym-utf: remove bogus Korean Won sign entry
This entry maps a non existing special keysym 0x20a9.
The correct mapping for XKB_KEY_Korean_Won (0x0eff) already exists.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2022-05-15 10:35:30 +03:00
Sam Lantinga 2536713070 Remove bogus euro sign entry from keysymtab
Not sure what it's doing here, but converting "€" to a keysym
doesn't work with this entry. 0x13a4 doesn't appear in
xkbcommon-keysyms.h. 0x20ac is the keysym documented in the
header (and it's the last entry in the table).

It's been in the table since it was introduced in e0524296d2
("Add API for getting unicode representation of a keysym").

Co-authored-by: Simon Ser <contact@emersion.fr>
2022-05-15 10:26:44 +03:00
Weng Xuetian b064b60984 Do not clear sibling entries when override.
lokid and hikid actually stores the sibling to current node, which
should not be cleared when override. This would break the sequence with
a common prefix when override another.

Fix #286

Signed-off-by: Weng Xuetian <wengxt@gmail.com>
2022-05-15 10:07:57 +03:00
Ran Benita 0b3d90925c scanner: prefix functions with `scanner_` to avoid symbol conflicts
Particularly `eof()` in mingw-w64.

Fixes: https://github.com/xkbcommon/libxkbcommon/pull/285
Reported-by: Marko Lindqvist
Signed-off-by: Ran Benita <ran@unusedvar.com>
2022-03-14 16:45:19 +02:00
M Hickford efa9962432
Variants should inherit iso639, iso3166 and brief from parent layout if omitted (#266) 2022-01-24 11:16:08 +10:00
Peter Hutterer 9b05825e53 registry: skip over invalid ISO639 or ISO3166 entries
If the XML file is somehow off, don't load entries that are against the spec.
2022-01-24 10:44:31 +10:00
Peter Hutterer 0e3f72af65 registry: don't call xmlCleanupParser()
From the documentation:
> It does not clean up parser state, it cleans up memory allocated by the library
> itself. It is a cleanup function for the XML library. It tries to reclaim all
> related global memory allocated for the library processing. [...]
> One should call xmlCleanupParser() only when the process has finished using the library.

http://xmlsoft.org/html/libxml-parser.html#xmlCleanupParser

Since we're a library ourselves we cannot know if something else in the same
proces uses the parser, so we must not call this.

Reported-by: M Hickford
2022-01-18 15:03:24 +10:00
Ran Benita 4a576ab184 x11: try to fix crash in xkb_x11_keymap_new_from_device error handling
In 1b3a1c277a we changed the error
handling in this code to not bail out immediately but only after
everything has been processed, to simplify the code. But I suspect the
code isn't prepared for this and that's what causing the crash reported
in the issue.

Bring back the short-circuit error handling which would hopefully fix
such crashes.

Fixes: https://github.com/xkbcommon/libxkbcommon/issues/252
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-09-09 16:52:47 +03:00
Ran Benita 4e361712d2 x11: stylistic fixes
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-08-31 22:03:03 +03:00
Ran Benita 09ac27f744 ignore: remove no longer relevant gitignore files
These were relevant for the autoconf build but now we're meson only.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-05-22 19:51:02 +03:00
Ran Benita 1915632e06 compose: add mapped locale to Compose-file-not-found error log
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-05-08 21:08:37 +03:00
Ran Benita 16fe837d8d atom: rewrite as a hash table
While the previous 1987-style[0] scheme was fun (and I reasonably
optimized it for a fair comparison), this task is more suited to a hash
table. Even a simple implementation beats the old one.

[0] Seems to have first appeared in X11R1, released September 1987.
    See server/dix/atom.c here: https://www.x.org/releases/X11R1/X.V11R1.tar.gz

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-27 16:41:32 +03:00
Isaac Freund 68dddd4132 keysym: fix underflow in binary searches
This is hit when passing an empty string and XKB_KEYSYM_CASE_INSENSITIVE
to xkb_keysym_from_name currently if `(lo + hi) / 2` is 0 and `cmp < 0`,
causing mid to underflow and the the array access into name_to_keysym on
the next iteration of the loop to be out of bounds .

We *would* use ssize_t here as it is the appropriate type, but windows
unfortunately does not define it.
2021-04-25 12:25:58 +03:00
Ran Benita 29af25eaa8 x11: fix xkb_x11_keymap_new_from_device failing when a level name is empty
The numpad:mac option doesn't specify a name for the first level:

    // On Mac keypads, level 1 and 2 are swapped.
    partial xkb_types "mac" {
        type "KEYPAD" {
            modifiers = None;
            map[None] = Level2;
            level_name[Level2] = "Number";
        };
        include "extra(keypad)"
    };

This means the atom for level name is XCB_ATOM_NONE. We tried to get its
name, which fails. This regressed in 40c00b4721.

Instead, translate it to XKB_ATOM_NONE, same as the previous behavior.

Fixes: https://github.com/xkbcommon/libxkbcommon/issues/229
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-07 19:21:10 +03:00
Ran Benita 7e6d942a4f compose: fix max compose nodes check
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-02 15:15:33 +03:00
Ran Benita 45b1ca2205 keysym: speed up the perfect hash function
Make it use a bit operation instead of an expensive modulo.

perf diff:

    Baseline  Delta Abs  Shared Object      Symbol
    ........  .........  .................  ...................................

      28.15%     -6.57%  bench-compose      [.] xkb_keysym_from_name

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-01 22:52:59 +03:00
Ran Benita 8cd688c063 keysym: avoid strtoul in xkb_keysym_from_name
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-01 22:24:05 +03:00
Ran Benita 68e69b7deb keysym: use a perfect hash function for case sensitive xkb_keysym_from_name
In 7d84809fdc I added a fast path for the
case-sensitive case, but it is still slowing down Compose parsing.

Instead of the binary search, use a perfect hash function, computed with
a simple python module I found (vendored).

It is faster -- perf diff is:

   Baseline  Delta Abs  Shared Object      Symbol
   ........  .........  .................  ...................................

     22.35%    -14.04%  libc-2.33.so       [.] __strcmp_avx2
     16.75%    +10.28%  bench-compose      [.] xkb_keysym_from_name
     20.72%     +2.40%  bench-compose      [.] parse.constprop.0
      2.29%     -1.97%  bench-compose      [.] strcmp@plt
      2.56%     +1.81%  bench-compose      [.] resolve_name
      2.37%     +0.92%  libc-2.33.so       [.] __GI_____strtoull_l_internal
     26.19%     -0.63%  bench-compose      [.] lex
      1.45%     +0.56%  libc-2.33.so       [.] __memchr_avx2
      1.13%     -0.31%  libc-2.33.so       [.] __strcpy_avx2

Also reduces the binary size:

Before:

      text    data     bss     dec     hex filename
    341111    5064       8  346183   54847 build/libxkbcommon.so.0.0.0

After:

      text    data     bss     dec     hex filename
    330215    5064       8  335287   51db7 build/libxkbcommon.so.0.0.0

Note however that it's still larger than before 7d84809fdccbb5898d08388:

      text    data     bss     dec     hex filename
    320617    5168       8  325793   4f8a1 build/libxkbcommon.so.0.0.0

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-01 20:06:59 +03:00
Ran Benita 02b9cabf98 compose: use a ternary tree instead of a regular trie
Previously we used a simple trie with a linked list for each chain.
Unfortunately most compose files have very long chains which means the
constructions performs an almost quadratic number of comparisons.

Switch to using a ternary search tree instead. This is very similar to a
trie, only the linked list is essentially replaced with a binary tree.

On the en_US/Compose file, the perf diff is the following (the modified
function is `parse`):

  Event 'cycles:u'

  Baseline  Delta Abs  Shared Object     Symbol
  ........  .........  ................  .................................

    39.91%    -17.62%  bench-compose     [.] parse.constprop.0
    20.54%     +6.47%  bench-compose     [.] lex
    17.28%     +5.55%  libc-2.33.so      [.] __strcmp_avx2
    12.78%     +4.01%  bench-compose     [.] xkb_keysym_from_name
     2.30%     +0.83%  libc-2.33.so      [.] __GI_____strtoull_l_internal
     3.36%     +0.78%  bench-compose     [.] strcmp@plt

Thanks to some careful packing, the memory usage is pretty much the
same.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-31 12:10:52 +03:00
Ran Benita 3a6c3b2c48 ast: remove comment re. anonymous struct
C11 is not sufficient for this, needs `--ms-extensions` which we don't
want to enable.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-30 20:42:31 +03:00
Ran Benita 8b09e1772c compose: use anonymous union
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-30 20:42:31 +03:00
Ran Benita 1c0e28ad26 keysym: properly handle overflow in 0x keysym names
Relatedly, strtoul allows a lot of unwanted stuff (spaces, +/- sign,
thousand seperators), we really ought not use it. But that's for another
time.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-30 19:17:29 +03:00
Ran Benita 1638409b22 compose: add a limit of 65535 sequences
Fits in uint16_t, which enables some future optimizations. But also a
good idea to have some limit. Not aware of any compose files which come
close.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-30 17:52:36 +03:00
Peter Hutterer 127f8c976d utils: assert on streq for NULL pointers
We have streq_null for that purpose

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 01:37:55 +03:00
Peter Hutterer fa86433e7c xkbcomp: remove useless assignment
../../../src/xkbcomp/compat.c:693:16: warning: Although the value stored to
'merge' is used in the enclosing expression, the value is never actually read
from 'merge' [deadcode.DeadStores]
    si.merge = merge = (def->merge == MERGE_DEFAULT ? merge : def->merge);

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 01:37:55 +03:00
Peter Hutterer 20f7f80c23 xkbcomp: use memcpy over strncpy to avoid analyzer warnings
The target buffer is 7 bytes long, null-termination is optional (as the comment
already suggests). Coverity is unhappy about this though so let's use memset and
memcpy instead.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 01:34:33 +03:00
Ran Benita 7d84809fdc keysym: fast path for case sensitive xkb_keysym_from_name
xkb_keysym_from_name() is called a lot in Compose file parsing. The
lower case handling slows things down a lot (particularly given we can't
use the optimized strcasecmp() due to locale issues). So add separate
handling for the non-case-sensitive case which is used by Compose.

To do this we need to add another version of the ks_tables table. This
adds ~20kb to the shared library binary. We can probably do something
better here but I think it's fine.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-28 16:11:36 +03:00
Ran Benita 3b506497bf keysym: inline find_sym function
It's easier when everything is in one place.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-28 16:11:36 +03:00
Ran Benita 2d87ab08f3 keysym: use a more descriptive argument name
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-28 16:11:36 +03:00
Ran Benita a717549eb2 keysym: open-code bsearch
We want to optimize things here which requires messing with the binary
search some.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-28 16:11:36 +03:00
Ran Benita 62b5b4a170 x11: fix comparison of integer expressions of different signedness
src/x11/keymap.c:980:26: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
  980 |     for (size_t i = 0; i < length; i++) {
      |                          ^

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-28 13:02:27 +03:00
Peter Hutterer 95e2907978 xkbcomp: plug a potential memory leak
libxkbcommon-1.0.3/src/xkbcomp/ast-build.c:526: leaked_storage: Variable "file"
going out of scope leaks the storage it points to.

Where we exit the loop early, we don't release the various allocated memory.

Make this patch more obvious my moving the declaration for those into the loop
as well, this way we know that they aren't used outside the loop anywhere.

Found by coverity

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-19 23:44:30 +02:00
Peter Hutterer 01aa222257 registry: plug a potential memleak for invalid rules files
If the name is missing in a configItem, we'd fail and leak the memory for
description, brief and vendor.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-19 23:44:30 +02:00
Uli Schlachter 21c864ccbf Inline x11_atom_interner_adopt_atoms() into callers
Signed-off-by: Uli Schlachter <psychon@znc.in>
2021-03-09 11:00:13 +02:00
Uli Schlachter c033970163 Save another GetAtomName round trip
Both get_atom_name() and the new atom interner required a round trip. Move
get_atom_name() into the atom interner to save one more round trip. This brings
xkb_x11_keymap_new_from_device() down to two round trips, which is the minimum
possible number.

(Also, I think the new code in keymap.c is more readable than the mess I
previously created)

With this last commit in the series, this definitely:

Fixes: https://github.com/xkbcommon/libxkbcommon/pull/217
Signed-off-by: Uli Schlachter <psychon@znc.in>
2021-03-09 11:00:13 +02:00
Uli Schlachter c8efc3d67d Also batch the XKB GetNames request
This gets rid of another round trip.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2021-03-09 11:00:13 +02:00
Uli Schlachter 599064cf28 Also batch the XKB-GetMapMap request
This gets rid of one more round trip.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2021-03-09 11:00:13 +02:00
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