Commit Graph

463 Commits (ed2dc978b12776d32e6213fcfe3b6d2d51afb88c)

Author SHA1 Message Date
Pierre Le Marre 1731c6b3ef compose: Ensure we mmap only regular files
Currently we do not check that the Compose files we try successively are
*regular* files. This may result in an error, while we should just really
just skip the corresponding path.

Fixed by adding the new utily function `open_file`.
2024-02-07 09:24:59 +01:00
Pierre Le Marre 382f6d2d5e Keysyms: Update using latest xorgproto
For the sake of compatibility, this reintroduce some deleted keysyms and
postpone the effective deprecation of others.

xorgproto commit: fe12c5102762afcbf852e50dcbbdea2ef625570c

Also added tests for some canonical names.
2024-02-06 17:45:02 +01:00
Yuichiro Hanada efdb05d193 parser: Do now allow the empty symbol declaration
An empty element is allowed in SymbolsBody definition, so the following
keymap is gramatically correct.

```
xkb_keymap {
  ...
  xkb_symbols "sym" {
    key <SPC> {, [Space] };
  };
};
```

However, the current parser crashes with the keymap due to null pointer
access.
This change fixes it by changing the parser not to allow it.
2024-02-05 09:42:02 +01:00
Pierre Le Marre 43c9752d44 compose: Fix iterator for empty tables
The current `xkb_compose_table_iterator_next` segfaults when used with an
empty table. Indeed, in this case we initialize cursors in
`xkb_compose_table_iterator_new` with the dummy node and the direction
`NODE_LEFT`, but the dummy node is a leaf!

Fixed by initializing with no cursors when the table is has no non-dummy
nodes.
2024-01-16 11:34:28 +01:00
Pierre Le Marre 8cca3a7bfb compose: Add XKB_COMPOSE_MAX_STRING_SIZE
Define the maximum size of a compose sequence result string explicit as
a constant and use it everywhere to improve the code readability.
2024-01-12 10:58:38 +01:00
Pierre Le Marre c88fe4b692 keysyms: Add tests with ICU
Added tests of the simple case mappings when the ICU library is
available. A warning is raised for missing mappings.

Note: `xkb_keysym_is_upper` is interpreted as matching the disjunction of the
Unicode character properties “Uppercase” or “Titlecase”.
2024-01-10 15:03:22 +01:00
Pierre Le Marre 82305adb51 keysyms: Test keypad 2024-01-10 14:43:29 +01:00
Pierre Le Marre b5a140832b keysyms: Fix xkb_keysym_is_modifier
Currently `xkb_keysym_is_modifier` does not detect the following keysyms:
- `XKB_KEY_ISO_Level5_Shift`
- `XKB_KEY_ISO_Level5_Latch`
- `XKB_KEY_ISO_Level5_Lock`

Indeed, there is a mistake in the keysym interval that the code checks.
The reason seems a confusing order of the keysyms in
`xkbcommon-keysyms.h`: the current code has a comment “libX11 only goes
up to XKB_KEY_ISO_Level5_Lock”, but in fact the modifiers keysyms are
listed in a _semantic_ order in `xkbcommon-keysyms.h`, not in the
increasing keysym _value_ order.

Fixed by using the same (correct) code as libX11 and added some tests.
2024-01-10 14:43:29 +01:00
Pierre Le Marre 0074baf451 keysyms: Add XKB_KEYSYM_NAME_MAX_SIZE for internal use
Currently there is no indication of the maximum length of keysym names.

This is statically known, so add the new *internal* following API:
`XKB_KEYSYM_NAME_MAX_SIZE`.
2024-01-10 14:18:43 +01:00
Pierre Le Marre f77c97bd45 keysyms: Test xkb_keysym_to_utf8 length 2024-01-10 14:18:43 +01:00
Pierre Le Marre 817179d866 keysyms: Add xkb_keysym_iterator
Add an efficient way to iterate over the assigned keysyms.

Currently only provided for testing, so we guard it by
`ENABLE_PRIVATE_APIS` in order to reduce the installed library.
2024-01-10 14:18:43 +01:00
Pierre Le Marre 4f52d6068e keysyms: Add xkb_keysym_is_assigned
Add internal API `xkb_keysym_is_assigned` for tests, guarded by
`ENABLE_PRIVATE_APIS` in order to avoid increasing the size of the installed library.
2024-01-10 14:18:43 +01:00
Pierre Le Marre 82f138c633 keysyms: Add min and max assigned keysyms internal API
Currently there is no direct way to know the minimum and maximum keysym
values that are assigned, i.e. that have an explicit name or are
Unicode keysyms.

Introduce the new following internal API:
- XKB_KEYSYM_MIN_ASSIGNED
- XKB_KEYSYM_MAX_ASSIGNED
- XKB_KEYSYM_MIN_EXPLICIT
- XKB_KEYSYM_MAX_EXPLICIT
- XKB_KEYSYM_COUNT_EXPLICIT

Also add a bunch of tests to ensure consistant keysyms bounds.
2024-01-10 14:18:43 +01:00
Pierre Le Marre 4a92f61b5c keysyms: Add Unicode constants
Add the following constants in order to improve the code readability:
- XKB_KEYSYM_UNICODE_OFFSET
- XKB_KEYSYM_UNICODE_MIN
- XKB_KEYSYM_UNICODE_MAX
2024-01-10 14:18:43 +01:00
Peter Hutterer 31ebe0037b test: add a test for multiple keysyms (and some minimal docs)
I couldn't find any reference to *how* the keymap format actually needs to look
like if you want multiple keysyms per level. So let's add a test for it and a
minimal documentation entry.
2023-12-27 12:23:46 +01:00
ppw0 0db1dc1c4a fix error with "-Wl,--gc-sections" 2023-12-02 19:13:39 +02:00
Pierre Le Marre 7caf57f013 registry: Parse “popularity” attribute
Previously the attribute “popularity” was completely ignored. It also
did not respect the modified DTD, because its default value depends if
we are currently parsing an “extras” rules file.

Fixed:
- Always parse the popularity attribute.
- Change the DTD to reflect that the default value is implied.
2023-11-21 08:10:22 +01:00
Pierre Le Marre 0a577a0998 xkbcli-compile-compose: Fix string result escaping
Currently the result string is not escaped and may produce invalid
results.

Fixed by introducing an ad-hoc escape function and relative tests.
2023-11-19 09:57:24 +01:00
Pierre Le Marre bc330c00e6 xkbcli: Promote compose to xkbcli-compile-compose
Previously this tool was only used for internal testing and thus
not installed. But it is useful for debugging, much like
xkbcli-compile-keymap.
2023-11-19 09:57:24 +01:00
Pierre Le Marre 00e3058e7b Prevent recursive includes of keymap components
- Add check for recursive includes of keymap components. It relies on
  limiting the include depth. The threshold is currently to 15, which
  seems reasonable with plenty of margin for keymaps in the wild.
- Add corresponding new log message `recursive-include`.
- Add tests for recursive includes.
2023-11-06 22:06:25 +01:00
Pierre Le Marre 3aaa4e2a53 rules: early detection of invalid encoding 2023-11-03 04:16:50 +01:00
Pierre Le Marre 82e9293e12 xkbcomp: early detection of invalid encoding 2023-11-03 04:16:50 +01:00
Pierre Le Marre a2da57aba1 Compose: early detection of invalid encoding
Also move “unrecognized token” error message before skiping the
line, in order to fix token position.
2023-11-03 04:16:50 +01:00
Pierre Le Marre 9e88718080 rules: skip heading UTF-8 encoded BOM (U+FEFF)
Leading BOM is legal and is used as a signature — an indication that
an otherwise unmarked text file is in UTF-8.
See: https://www.unicode.org/faq/utf_bom.html#bom5 for further details.
2023-10-30 07:15:13 +01:00
Pierre Le Marre f937c30820 xkbcomp: skip heading UTF-8 encoded BOM (U+FEFF)
Leading BOM is legal and is used as a signature — an indication that
an otherwise unmarked text file is in UTF-8.
See: https://www.unicode.org/faq/utf_bom.html#bom5 for further
details.
2023-10-30 07:15:13 +01:00
Pierre Le Marre 59886e4183 Compose: skip heading UTF-8 encoded BOM (U+FEFF)
Leading BOM is legal and is used as a signature — an indication that
an otherwise unmarked text file is in UTF-8.
See: https://www.unicode.org/faq/utf_bom.html#bom5 for further details.
2023-10-30 07:15:13 +01:00
Pierre Le Marre 87dcf30126 Fix trailing whitespaces in XKB files 2023-09-29 09:42:08 +02:00
Pierre Le Marre 1a4a89a749 Python: make ruff & black happy 2023-09-29 09:42:08 +02:00
Pierre Le Marre 0d4541151f Keysyms: Fix failing tests
- Update keymap to use reference keysym names.
- Fix x11comp test by handling old x11proto.

  We need xkbcomp to be compiled with at least x11proto-dev 2023.2.
  So we replace the unsupported keysyms with supported ones not
  already in the keymap. This is kind of ugly, but it works. If we
  ever want to restore the original keysyms with their supported names,
  the substitute keysyms will be easy to spot.
2023-09-28 07:48:37 +02:00
Pierre Le Marre 0038c86607 Prevent overflow of octal escape sequences
The octal parser accepts the range `\1..\777`. The result is cast to
`char` which will silently overflow.

This commit prevents overlow and will treat `\400..\777` as invalid
escape sequences.
2023-09-26 17:25:49 +02:00
Pierre Le Marre ca7aa69cc0 Disallow producing NULL character with escape sequences
NULL usually terminates the strings; allowing to produce it via escape
sequences may lead to undefined behaviour.

- Make NULL escape sequences (e.g. `\0` and `\x0`) invalid.
- Add corresponding test.
- Introduce the new message: XKB_WARNING_INVALID_ESCAPE_SEQUENCE.
2023-09-26 17:25:49 +02:00
Ran Benita a17701327e Compose: add iterator API
Allow users to iterate the entries in a compose table. This is useful
for other projects which want programmable access to the sequences,
without having to write their own parser.

- New API:
  - `xkb_compose_table_entry_sequence`;
  - `xkb_compose_table_entry_keysym`;
  - `xkb_compose_table_entry_utf8`;
  - `xkb_compose_table_iterator_new`;
  - `xkb_compose_table_iterator_free`;
  - `xkb_compose_table_iterator_next`.
- Add tests in `test/compose.c`.
- Add benchmark for compose traversal.
- `tools/compose.c`:
  - Print entries instead of just validating them.
  - Add `--file` option.
  - TODO: make this tool part of the xkbcli commands.

Co-authored-by: Pierre Le Marre <dev@wismill.eu>
Co-authored-by: Ran Benita <ran@unusedvar.com>
Signed-off-by: Ran Benita <ran@unusedvar.com>
2023-09-26 09:02:45 +02:00
Pierre Le Marre c0065c95a4 Messages: merge macros with and without message code
Previously we had two types of macros for logging: with and without
message code. They were intended to be merged afterwards.

The idea is to use a special code – `XKB_LOG_MESSAGE_NO_ID = 0` – that
should *not* be displayed. But we would like to avoid checking this
special code at run time. This is achieved using macro tricks; they
are detailed in the code (see: `PREPEND_MESSAGE_ID`).

Now it is also easier to spot the remaining undocumented log entries:
just search `XKB_LOG_MESSAGE_NO_ID`.
2023-09-24 09:09:24 +02:00
Pierre Le Marre a83d745b62 Messages: add new messages to registry
This commit is another step to identify and document the maximum number
of logging messages. Bulk changes:

- Rename `conflicting-key-type` to `conflicting-key-type-merging-groups`.
  Giving more context in the name allow us to introduce
  `conflicting-key-type-definitions` later.
- Add conflicting-key-type-definitions
- Add conflicting-key-type-map-entry
- Add undeclared-modifiers-in-key-type
  Also improve the log messages.
- Add conflicting-key-type-preserve-entries
- Use XKB_ERROR_UNSUPPORTED_MODIFIER_MASK
- Add illegal-key-type-preserve-result
- Add conflicting-key-type-level-names
- Add duplicate-entry
- Add unsupported-symbols-field
- Add missing-symbols-group-name-index
- Use XKB_ERROR_WRONG_FIELD_TYPE
- Add conflicting-key-name
- Use XKB_WARNING_UNDEFINED_KEYCODE
- Add illegal-keycode-alias
- Add unsupported-geometry-section
- Add missing-default-section
- Add XKB_LOG_MESSAGE_NO_ID
- Rename log_vrb_with_code to log_vrb
- Use ERROR_WRONG_FIELD_TYPE & ERROR_INVALID_SYNTAX
- Add unknown-identifier
- Add invalid-expression-type
- Add invalid-operation + fixes
- Add unknown-operator
- Rename ERROR_UNKNOWN_IDENTIFIER to ERROR_INVALID_IDENTIFIER
- Add undeclared-virtual-modifier
- Add expected-array-entry
- Add invalid-include-statement
- Add included-file-not-found
- Add allocation-error
- Add invalid-included-file
- Process symbols.c
- Add invalid-value
- Add invalid-real-modifier
- Add unknown-field
- Add wrong-scope
- Add invalid-modmap-entry
- Add wrong-statement-type
- Add conflicting-key-symbols-entry
- Add invalid-set-default-statement
2023-09-24 09:09:24 +02:00
Pierre Le Marre 417d0747b6 Add xkb-check-messages tool
This tool checks whether messages codes are supported.

This is useful e.g. for CI, where one may want to grep for some XKB
error codes and ensure that these are still supported.
2023-09-19 08:49:52 +02:00
Pierre Le Marre 399aa888e0 Use warning code in xkeyboard-config test 2023-09-19 08:49:52 +02:00
Pierre Le Marre fe9cd66fca Test: Enable x11comp and use the xvfb wrapper
This test was previously disabled in 914e84e018.

Note that it requires a recent version of xkeyboard-config to succeed.
2023-09-18 16:07:09 +02:00
Pierre Le Marre 266427723a Test: Catch SIGUSR1 from Xvfb for X11 tests
Based on the work done by Peter Hutterer. Original commit message:

If SIGUSR1 is set to SIG_IGN, X servers (all of them, including Xvfb)
will send that signal to the parent process when they're ready to accept
connections. We can use that instead of a hardcoded sleep which brings
the wait down to ~37ms on my box.
2023-09-18 16:07:09 +02:00
Pierre Le Marre 26b1a07659 Test: Use a xvfb wrapper for x11 test
The x11 test is currently silently skipped in CI, because it requires a
running X server.

Create a xvfb wrapper to run the test. We do not use `xvfb-run`, because
it is a shell script and it causes valgrind to detect unrelated memory
issues in the shell (dash, bash).

Improve wrapper using a special ELF section

TODO: The wrapper is intended to be used with the x11comp test as well.
2023-09-18 16:07:09 +02:00
Pierre Le Marre a4c0852687 Improved tests related to keysyms
- Add a keymap test with decimal and hexadecimal keysyms.
- Reorganize code in `test/keysym.c` by parsing type: name, Unicode and
  hexadecimal.
- Add more tests for edge cases. In particular:
  - test decimal format (currently not supported);
  - test the Unicode and hexadecimal ranges more thoroughly;
  - test with wrong case without the XKB_KEYSYM_CASE_INSENSITIVE flag;
  - test surrounding spaces.
- Document the tests.
2023-07-14 09:22:24 +02:00
Pierre Le Marre 0d01a933bb Replace keycode numeric offset with EVDEV_OFFSET
Add a constant `EVDEV_OFFSET` to make the semantic of the offset clearer.
2023-07-04 10:59:19 +02:00
Pierre Le Marre fc25e0f0f7 Test(compose): fix assumption on environment variables
The test `test_from_locale` fails when there is a user-defined compose
file, e.g. ~/.XCompose.

Indeed, the function `xkb_compose_table_new_from_locale` use various
environment variables to determine the location of the compose file.

Ensure no environment variables but the required ones are set, in order
to have robust tests.
2023-06-28 07:52:04 +02: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
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
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 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
Ran Benita f9858bf5b9 test: move mkdir & mkdtemp calls to common place and fix them on MSVC
Signed-off-by: Ran Benita <ran@unusedvar.com>
2022-09-24 12:31:53 +03: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
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