summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* Provide a fallback implementation of strndup()Adrian Perez de Castro2019-12-271-0/+15
| | | | | | | | 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]
* Use built-in istr[n]cmp() instead of strcase[n]cmp()Adrian Perez de Castro2019-12-271-1/+1
| | | | | | | 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.
* utils: use MIN/MAX instead of min/maxRan Benita2019-12-273-17/+3
| | | | | | min/max symbols conflict on some systems (msvc), so just use the macros. Signed-off-by: Ran Benita <ran@unusedvar.com>
* xkbcomp: downgrade "Symbol added to modifier map for multiple modifiers" log ↵Ran Benita2019-12-271-12/+12
| | | | | | | | | | | | | | | | 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>
* rules: eliminate an extra fopen/fclose cyclePeter Hutterer2019-12-241-15/+15
| | | | | | | | 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>
* rules: add include statements to rules filesPeter Hutterer2019-12-241-2/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* context: add a helper function to return the default system include pathPeter Hutterer2019-12-242-5/+12
| | | | | | | 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>
* rules: move the matcher result handling to the callerPeter Hutterer2019-12-241-38/+37
| | | | | | | | 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>
* rules: put the scanner on the stackPeter Hutterer2019-12-241-58/+65
| | | | | | This allows nesting the scanner for the future !include directive. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* rules: simplify an error pathPeter Hutterer2019-12-241-3/+3
| | | | | | | 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>
* rules: rename a variable from 's' to 'str'Peter Hutterer2019-12-241-11/+11
| | | | | | To avoid name conflicts with a future patch. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* rules: drop the matcher_err() macro and use scanner_err directlyPeter Hutterer2019-12-241-17/+14
| | | | | | | 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>
* rules: factor out the function to parse a rules filePeter Hutterer2019-12-241-13/+36
| | | | | | | 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>
* keysym: handle ssharp in XConvertCase()Peter Hutterer2019-12-221-0/+4
| | | | | | | | | | | | | | | | | | | | | 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>
* parser: fix the remaining pointer chasingRan Benita2019-12-141-22/+21
| | | | | | Fix the TODO added in 7c42945. Signed-off-by: Ran Benita <ran@unusedvar.com>
* parser: fix quadratic pointer chasingRan Benita2019-11-143-61/+73
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* parser: remove an unneeded checkRan Benita2019-11-141-7/+2
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* compat: reject interpret modifier predicate with more than one valueRan Benita2019-11-121-1/+1
| | | | | | | | | | 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>
* expr: fix log message on some unexpected expression typesRan Benita2019-11-121-0/+6
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* Replace some tabs that sneaked in with spacesRan Benita2019-11-122-6/+6
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* parser: fix merge mode only applied to first vmod in a virtual_modifiers ↵Ran Benita2019-11-121-1/+2
| | | | | | | | | | | | | | | | | | | | | | 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>
* ast: use a separate expr struct for action listRan Benita2019-11-125-4/+28
| | | | | | Currently it's under UnaryExpr, which just doesn't make sense. Signed-off-by: Ran Benita <ran@unusedvar.com>
* ast-build: get rid of unhelpful macroRan Benita2019-11-121-17/+36
| | | | | | Straightforward code is better here. Signed-off-by: Ran Benita <ran@unusedvar.com>
* atom: a string is greater than its prefixRan Benita2019-11-091-8/+8
| | | | | | Bug accidentally introduced in 9a92b46. Signed-off-by: Ran Benita <ran@unusedvar.com>
* atom: combine atom_intern() and atom_lookup()Ran Benita2019-11-093-34/+7
| | | | | | Use an "add" bool parameter instead. This simplifies the code a bit. Signed-off-by: Ran Benita <ran@unusedvar.com>
* atom: correct iteration count in hash functionRan Benita2019-11-091-1/+1
| | | | | | | 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>
* atom: describe how this odd data structure worksRan Benita2019-11-091-0/+17
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* atom: use a better hash functionRan Benita2019-11-091-5/+15
| | | | | | | | | 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>
* atom: style changesRan Benita2019-11-091-21/+11
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* atom: remove handling of garbage inputRan Benita2019-11-091-11/+2
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* atom: use explicit size for fingerprintRan Benita2019-11-091-4/+4
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* atom: replace an avoidable strlenRan Benita2019-11-091-1/+1
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* atom: remove redundant fieldRan Benita2019-11-091-4/+3
| | | | | | | | The field is redundant. Due to alignment, this will only save memory on 32bit architectures. Signed-off-by: Ran Benita <ran@unusedvar.com>
* parser: get rid of "stealing" atomsRan Benita2019-11-085-35/+8
| | | | | | | | | 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>
* Use XDG_CONFIG_HOME as first XKB search pathPeter Hutterer2019-10-311-1/+18
| | | | | | | | | | | | | Use $XDG_CONFIG_HOME/xkb as the primary lookup path for XKB rules. Same motivation as in 3a91788d9254b, 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>
* context: Don't fail to create the context if HOME isn't availableJan Alexander Steffens (heftig)2019-10-201-7/+7
| | | | | | | | | 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>
* keymap-dump: use consistent capitalization for "Group<N>"Ran Benita2019-10-161-2/+2
| | | | | | It's used capitalized everywhere except a couple places. Signed-off-by: Ran Benita <ran@unusedvar.com>
* keymap-dump: fix invalid names used for levels above 8Ran Benita2019-10-161-2/+2
| | | | | | | | | | | | 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
* context: move ~/.xkb to before XKB_CONFIG_ROOT in the default include pathRan Benita2019-10-031-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Use bitwise test instead of popcount to check if one bit is setMichael Forney2019-06-102-11/+3
| | | | | | | | | | | 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>
* symbols: add a comment to suppress warning from code analyzersKonstantin Kharlamov2019-03-231-0/+3
| | | | Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
* Sync Keysyms with recent xproto additionsHans de Goede2019-01-221-241/+247
| | | | | | | | | | | 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>
* Fix off-by-one error in index check in xkb_file_type_to_stringAlan Coopersmith2018-09-301-1/+1
| | | | | | | | | | | 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>
* darray: fix unprotected macro argumentRan Benita2018-08-241-1/+1
| | | | | Reported-by: @msmeissn Signed-off-by: Ran Benita <ran234@gmail.com>
* x11: fix undefined behavior when copying the coordinates of ptr movements ↵Ran Benita2018-08-181-2/+2
| | | | | | | | | | 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>
* Fail expression lookup on invalid atomsDaniel Stone2018-08-031-1/+5
| | | | | | | 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>
* Fix signed vs. unsigned confusion in name sanitisationDaniel Stone2018-08-031-1/+2
| | | | | | | 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>
* darray: Don't call memcpy() on NULLDaniel Stone2018-08-031-1/+2
| | | | | | | 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>
* text: NULL-terminate SI mask namesDaniel Stone2018-08-031-0/+1
| | | | | | | | The list should have a NULL sentry. Add one. testcase: 'interpret KP_Delete+AnyOfOrNaneo(ll)' Signed-off-by: Daniel Stone <daniels@collabora.com>
* xkbcomp: Don't falsely promise from ExprResolveLhsDaniel Stone2018-08-031-1/+1
| | | | | | | | | | 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>