Commit Graph

59 Commits

Author SHA1 Message Date
Matthias Clasen
8931169e00 input: Accept short compose sequences
Some of the X keyboard layouts use compose
sequences of length one to make individual
keys generate multiple Unicode characters.

To support this use case, change the index
part of the table format to also include
an offset for length 1. Bump the table
version to indicate this change.

Fixes: #5172
2022-09-12 22:30:47 -04:00
Matthias Clasen
2b183a9f4e Reject compose tables that are too large
The fixed-size format we use currently can only handle up
to 32768 bytes of string data. If a compose file contains
more, reject it with a warning.

Fixes: #4873
2022-05-02 16:03:45 +08:00
Matthias Clasen
5df314fa8f composetable: Add a missing NULL check
gtk_compose_table_parse can return NULL. Handle it.
2022-05-02 15:39:03 +08:00
Naïm Favier
22f5236943
composetable: invalidate cache based on symlink mtime too
When the compose file is a symbolic link, take the link itself's
modification time into account (in addition to its target's) in
determining whether to invalidate the compose cache.

This is useful e.g. on NixOS systems where the compose file might point
to a store path with an irrelevant modification time, and we want the
cache to expire when the symlink itself changes.
2021-11-16 12:53:38 +01:00
Martin Kühl
a9d7282f00 gtkcomposetable: Accept long replacement strings
This change removes the assertions limiting replacement strings in the compose table to be less than 20 characters.
The limit seems arbitrary, is not required, will break some users' setups, and problems with it result in applications not launching.

Fixes #4273
2021-09-21 17:03:20 +02:00
Matthias Clasen
bbc36448fb imcontext: Treat keysyms as 32bit values
Our compose table format is still limited to 16bit
values for keysyms, but what we see in key events
can be 32bit values, and we treat them as such now.

Fixes: #4149
2021-08-02 19:16:18 -04:00
Matthias Clasen
e67b2cb54b composetable: Allow multiple dead keys
Remove the limitation on the number of dead keys
that we match, and allow the result be be multiple
characters.

Regenerate the builtin sequences, since this changes
what dead key sequences we can reproduce algorithmically.

Update tests to match.

Fixes: #10
2021-07-29 20:37:30 -04:00
Matthias Clasen
539391ce6c composetable: Change an API
Make gtk_check_algorithmically take a GString
for the result. This is in preparation for allowing
multi-character results here, in the future.

Update all callers.
2021-07-29 17:29:25 -04:00
Matthias Clasen
914edb1472 composetable: Add a prefix api
Add a function that computes the longest prefix
of a buffer for which a compose table has matches.
2021-07-29 08:23:40 -04:00
Matthias Clasen
dbf5033f94 composetable: Reduce the scope of a variable
'prefix' is not a good name for a file-scope variable,
move it into the sole function using it.
2021-07-29 08:22:52 -04:00
Matthias Clasen
87e2a02e0c composetable: Rewrite Compose files if necessary
Apply heuristics to avoid breaking users existing configurations
with the change to not always add the default sequences.

If we find a cache that was generated before 4.4, and the Compose
file does not have an include, and doesn't contain so many sequences
that it is probably a copy of the system one, we take steps to keep
things working, and thell the user about it.
2021-07-15 09:30:09 -04:00
Matthias Clasen
264d592012 composetable: Keep the number of sequences
And print it out in tests.

Update all tests for this.
2021-07-15 09:30:01 -04:00
Matthias Clasen
54dffa07f3 composetable: Drop GtkComposeTableCompact
All tables use the compact format now, and we generate
caches in that format too. Bump the cache version to 3
for this.

Replace the python script for generating the builtin table
by a small C program using the same code to generate the data
for the builtin table. This drops the restriction on only
generating a single character in the builtin sequences.
2021-07-13 22:03:23 -04:00
Matthias Clasen
1cff4bb27a composetable: Ignore length 1 sequences
It turns out that the X11 Compose file has some
length 1 sequences which are not interesting to us.
2021-07-13 22:02:33 -04:00
Matthias Clasen
485dc052ca composetable: Allow removing sequences
Interpret an empty string as value in the Compose
file to mean: Remove this sequence.

Tests included.
2021-07-13 22:02:33 -04:00
Matthias Clasen
45d39c2802 composetable: Switch to using a hash table
This lets us naturally replace matching sequences
while parsing. That means that the semantics are now
"last one wins" if the parser sees multiple entries
for the same sequence.

Add a testcase that checks the new replacement semantics.
2021-07-13 22:02:33 -04:00
Matthias Clasen
3b4b1c6878 composetable: Reinterpret %L
When we see include "%L" in a Compose file, use the
builtin sequences. We no longer filter out duplicates
wrt. to the builtin sequences.
2021-07-13 22:02:33 -04:00
Matthias Clasen
ff4f07d76f composetable: Handle substitutions in includes
Hande the %H, %L, %S substitutions that are described
in Compose(7).

Test included.
2021-07-13 22:02:33 -04:00
Matthias Clasen
fb6c8cd466 composetable: Handle includes
This adds the mechanics for parsing include lines in
Compose files. We do detect and prevent cycles.

Tests included.
2021-07-13 22:02:33 -04:00
Matthias Clasen
8464b0484f composetable: Move code into the parser
This is just code reshuffling.
2021-07-13 22:02:33 -04:00
Matthias Clasen
bee58fd09d composetable: Introduce a parser struct
This will be used in the following commits to
beef up Compose file parsing.
2021-07-13 22:02:33 -04:00
Matthias Clasen
d25557a5ef Clean up the GtkComposeTable api
Keep the list of composetables private to GtkIMContextSimple,
and just have an api that creates new GtkComposeTables, either
from a file or from data.

Update tests to use the new api.
2021-07-13 22:02:33 -04:00
Matthias Clasen
dbcd24adf4 composetable: Limit algorithmic checking
Only check for combinations of up to 2 dead keys with
a base character. We don't want to spend ages generating
all permutations of long sequences.
2021-03-26 20:27:55 -04:00
Matthias Clasen
915e3f0e28 composetable: Remove some redundant code
Pointed out by Peter Bloomfield.
2021-02-23 19:14:26 -05:00
Matthias Clasen
baec7079e0 imcontext: Take out the warnings
Don't warn about Compose file constructs we don't
support. We haven't supported these for a long time,
and nobody has every complained. No need to wake
up sleeping dogs.
2021-02-22 15:08:58 -05:00
Matthias Clasen
2f43b8dc49 imcontext: Improve compose table parsing
Avoid leaking value in error cases, and actually
emit a warning for a missing quote. Pointed out
by Peter Bloomfield.
2021-02-15 01:46:00 -05:00
Matthias Clasen
d2e074e36b imcontext: Be more lenient in parsing Compose
X11 allows keysyms to be specified in addition to strings.
We only support the strings. In the past, we ignored everything
after the string. Go back to doing that, but issue a warning
that we've ignored the keysym.
2021-02-14 12:56:00 -05:00
Matthias Clasen
f15aa2f3e5 imcontext: Fix a regression in Compose file parsing
We accidentally dropped the handing of # comments.
Bring it back. Test included.

Fixes: #3664
2021-02-14 11:56:24 -05:00
Matthias Clasen
e91e75173d composetable: Remove a redundant check
We already know seq_index is not NULL here.

Pointed out in https://www.viva64.com/en/b/0793/
2021-02-04 00:22:52 -05:00
Matthias Clasen
949c783187 composetable: Parse hex escapes too
This was a small omission from the Compose file
syntax that doesn't cost us much to support.

Add a test for this syntax too.

Fixes: #1004
2021-02-02 12:05:19 -05:00
Matthias Clasen
676f875bf6 composetable: Support string values in the cache
Change the cache format to include the character
data that we need to hold string values in the table.
2021-02-02 11:55:00 -05:00
Matthias Clasen
140c5c5333 composetable: Don't use GSlice for big blobs
This just doesn't make sense. This will use malloc
anyway, so just call malloc directly.
2021-02-02 11:55:00 -05:00
Matthias Clasen
cebf2b2009 composetable: Keep multi-char values
Keep string values in the table, and return them
from the check function. This commit temporarily
disables the table caching, since the cache format
does not handle string values yet.

Fixes: #186
2021-02-02 11:54:53 -05:00
Matthias Clasen
773ae0cd0f composetable: Parse multi-char values
Rewrite the value parsing function to accept strings
that hold more than a single Unicode character.
2021-02-02 09:03:53 -05:00
Matthias Clasen
564793d5b5 composetable: Another step towards multi-char values
Change the parser data structures to hold a string, rather
than a gunichar. We still only put a single Unicode character
into it, currently.
2021-02-02 09:02:46 -05:00
Matthias Clasen
9142aa0f51 composetable: Prepare for multi character values
Make it possible for gtk_compose_table_check to return
a string instead of just a single Unicode character.
Currently, we only ever return strings holding a single
character, still.
2021-02-02 09:02:00 -05:00
Matthias Clasen
ef053ebb4a composetable: Fix algorithmic matching
The code wasn't paying attention to (lack of) nul-termination
in one place, causing it to not match when it should.
2021-02-01 21:51:51 -05:00
Matthias Clasen
5d9509c51b imcontext: Move code around
Move all the checking code to gtkcomposetable.c, and
add api that we can use in tests.
2021-02-01 20:27:38 -05:00
Matthias Clasen
9ebf3fac73 composetable: Add api to check tables
This copies the check_table code from gtkimcontextsimple.c,
in order to have an api for tests.
2021-02-01 19:40:22 -05:00
Matthias Clasen
be35c46ce9 composetable: Drop table debug code
This is better off in the tests that we are going to add.
2021-02-01 19:02:21 -05:00
Matthias Clasen
dbbcb13721 composetable: Parser fixes
We were not handling octal escapes right.
2021-02-01 16:05:05 -05:00
Matthias Clasen
61f709811c composetable: Warn when ignoring things
We should at least give a hint that we've seen the line,
otherwise people will wonder why nothing happened.
2021-02-01 12:27:41 -05:00
Matthias Clasen
f7c4375509 composetable: parse long sequences
Allow compose sequences of up to 20 code points.

Fixes: #3521
2021-02-01 12:27:35 -05:00
Matthias Clasen
52fb900ced composetable: Fix an off-by-one
Fix an off-by-one in the code parsing octal escapes
in compose files.
2021-02-01 12:10:05 -05:00
Matthias Clasen
094a346539 imcontext: Allow sequences of length GTK_MAX_COMPOSE_LEN
There was an off-by-one error, making us reject sequences
of this length. But the rest of the code handles them
just fine.

Fixes: #2319
2021-02-01 00:55:25 -05:00
Matthias Clasen
162814f969 imcontext: Improve an error message
This error message was misleading, as pointed out
by Ralf Jung.
2021-02-01 00:44:41 -05:00
Matthias Clasen
929a56e53c Clean up lots of GTK+ -> GTK
Replace most remaining uses of GTK+ in the docs and
user-visible strings by GTK. Also remove some leftover
"Was added in 3.x" sentences from the docs.
2020-09-12 12:01:04 -04:00
Benjamin Otte
d375dce9f5 Replace "gchar" with "char" 2020-07-25 00:47:36 +02:00
Benjamin Otte
d7266b25ba Replace "gint" with "int" 2020-07-25 00:47:36 +02:00
Christoph Reiter
b66e4cd64c gtkcomposetable: use g_size_checked_mul() for overflow checking
The check was added in !741, this replaces it with g_size_checked_mul()
2019-04-12 22:41:58 +02:00