summaryrefslogtreecommitdiff
path: root/src/text.c
Commit message (Collapse)AuthorAgeFilesLines
* Add support for modmap None (#291)Wismill2023-05-011-0/+3
| | | | | | | | | | | | | | | | | | | 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.
* build: include config.h manuallyRan Benita2019-12-271-0/+2
| | | | | | | | | 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>
* 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>
* text: init the target buffer to zeroPeter Hutterer2018-08-011-1/+1
| | | | | | | | 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>
* keymap: don't use darray in xkb_mod_setRan Benita2014-04-221-2/+2
| | | | | | | | Instead just statically allocate the mods array (of size MAX_MOD_SIZE = 32). The limit is not going anywhere, and static allocations are nicer (nicer code, no OOM, etc.). It's also small and dense enough. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: add and use xkb_mods_{foreach,enumerate}()Ran Benita2014-04-221-1/+1
| | | | | | | To iterate over an xkb_mod_set. Slightly nicer interface and makes transitioning from darray easier. Signed-off-by: Ran Benita <ran234@gmail.com>
* text: take xkb_mod_set instead of the entire keymapRan Benita2014-04-191-8/+9
| | | | | | | The modifier printing functions only need the modifier information, they don't care about keys or leds, etc. Signed-off-by: Ran Benita <ran234@gmail.com>
* Add struct xkb_mod_setRan Benita2014-04-191-3/+4
| | | | | | | | | | | The only thing that the compilation phase needs the keymap for currently is for access to the modifier information (it also modifies it in place!). We want to only pass along the neccessary information, to make it more tractable and testable, so instead of passing the entire keymap we add a new 'mod_set' object and pass a (const) reference to that. The new object is just the old array of 'struct xkb_mod'. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: move ModNameToIndex from text.c and use it in keymap.cRan Benita2014-04-191-14/+0
| | | | Signed-off-by: Ran Benita <ran234@gmail.com>
* Use (1u << idx) instead of (1 << idx) where appropriateRan Benita2014-02-081-7/+7
| | | | | | | | It doesn't matter (I think), since the implicit conversion doesn't have any effect (e.g. sign-extension). But it's better to be aware of the type. Signed-off-by: Ran Benita <ran234@gmail.com>
* scanner: allow empty key name literalsRan Benita2013-08-021-2/+2
| | | | | | | | | | Some keymaps actually have this, like the quartz.xkb which is tested. We need to support these. https://bugs.freedesktop.org/show_bug.cgi?id=67654 Reported-By: Gatis Paeglis <gatis.paeglis@digia.com> Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: remove struct xkb_key_redirect_actionRan Benita2013-07-311-2/+2
| | | | | | | | | | The file src/xkbcomp/action.c already doesn't handle this action type and fails if it encounters it. So lets not pretend to do something with it, and ignore it rather than failing. If we/someone wants this we can consider implementing it. Signed-off-by: Ran Benita <ran234@gmail.com>
* text: some style changesRan Benita2013-03-181-57/+53
| | | | Signed-off-by: Ran Benita <ran234@gmail.com>
* text: clean up and fix the *MaskText functionsRan Benita2013-03-181-73/+53
| | | | | | | | | | | | | | The snprintf trick that LedStateText and ControlMaskText do cannot work, because you can't use the buffer as an argument to write to itself! (posix at least has 'restrict' there). So those two actually never worked for more than one value (i.e. with a +). Fix that, and do the same cleanup to ModMaskText. Now we have 3 functions which look exactly the same, oh well. Also increase the context text buffer size, you never know. Signed-off-by: Ran Benita <ran234@gmail.com>
* Change 'indicator' to 'led' everywhere possibleRan Benita2013-03-181-1/+1
| | | | | | | | | | | | | | | | | | The code currently uses the two names interchangeably. Settle on 'led', because it is shorter, more recognizable, and what we use in our API (though of course the parser still uses 'indicator'). In camel case we make it 'Led'. We change 'xkb_indicator_map' to just 'xkb_led' and the variables of this type are 'led'. This mimics 'xkb_key' and 'key'. IndicatorNameInfo and LEDInfo are changed to 'LedNameInfo' and 'LedInfo', and the variables are 'ledi' (like 'keyi' etc.). This is instead of 'ii' and 'im'. This might make a few places a bit confusing, but less than before I think. It's also shorter. Signed-off-by: Ran Benita <ran234@gmail.com>
* action: don't allow private actions with a known typeRan Benita2012-10-301-1/+1
| | | | | | | | Some obscure bug having to do with Private actions; see the comments. This was prompted by: https://bugs.freedesktop.org/show_bug.cgi?id=56491 Signed-off-by: Ran Benita <ran234@gmail.com>
* Split the mods, layout, leds parts of xkb_state_componentsRan Benita2012-10-221-11/+11
| | | | | | | | | | | | | | | | | Note first: This commits breaks the ABI somewhat. If an application is run against this commit without recompiling against the updated header, these break: - xkb_state_layout_*_is_active always retuns false. - xkb_state_serialize_mods always returns 0. So it might break layout switching in some applications. However, xkbcommon-compat.h provides the necessary fixes, so recompiling should work (though updating the application is even better). Split the enum to its individual components, which enables us to refer to them individually. We will use that later for reporting which components of the state have changed after update. Signed-off-by: Ran Benita <ran234@gmail.com>
* Move _text() functions from keymap-dump to text.cRan Benita2012-10-181-0/+71
| | | | | | | | | And make them use context_get_buffer() instead of using a static char array. This was the last non-thread-safe piece we had, as far as I can tell. Signed-off-by: Ran Benita <ran234@gmail.com>
* Remove a couple more uses of static char buffersRan Benita2012-10-181-4/+2
| | | | Signed-off-by: Ran Benita <ran234@gmail.com>
* Contextualize GetBuffer()Ran Benita2012-10-181-28/+7
| | | | | | | Instead storing the buffer in a non-thread-safe static array, we move it to the context. Signed-off-by: Ran Benita <ran234@gmail.com>
* Clean up xkb_sym_interpret a bitRan Benita2012-10-181-12/+1
| | | | | | | | | | | | | | First we split the LEVEL_ONE_ONLY bit off of the 'match' field, which allows us to turn enum xkb_match_operation to a simple enum and remove the need for MATCH_OP_MASK. Next we rename 'act' to 'action', because we've settled on that everywhere else. Finally, SIMatchText is changed to not handle illegal values - it shouldn't get any. This removes one usage of the GetBuffer hack. Signed-off-by: Ran Benita <ran234@gmail.com>
* Replace 0xff with MOD_REAL_MASK_ALLRan Benita2012-10-061-1/+1
| | | | | | | To make it easier to see where it's used. The name is just to match MOD_REAL. Signed-off-by: Ran Benita <ran234@gmail.com>
* Remove now-unneeded mod type annotationsRan Benita2012-10-061-13/+6
| | | | | | | | | | | Most of the mod type annotations can now be changed to MOD_BOTH, because if you pass a mask which can only contain real mods in the first place to e.g. ModMaskText, then MOD_REAL and MOD_BOTH will give the same result. In the cases where MOD_BOTH is only ever the argument, we just remove it. What's left is where it really "matters". Signed-off-by: Ran Benita <ran234@gmail.com>
* text: explicitly take mod_type in mod functionsRan Benita2012-10-061-58/+15
| | | | | | | | This essentially "tags" each invocation of the functions with the modifier type of the argument, which allows for easy grepping for them (with the aim being, to remove anything but MOD_BOTH). Signed-off-by: Ran Benita <ran234@gmail.com>
* text: share code for modifiersRan Benita2012-10-061-64/+51
| | | | | | | Add static common functions which take enum mod_type, and change the existing ones to use them. Signed-off-by: Ran Benita <ran234@gmail.com>
* Keep real and virtual mods in the same table in the keymapRan Benita2012-10-061-54/+40
| | | | | | | | | | | | | | We change the keymap->vmods array into keymap->mods, and change it's member type from struct xkb_vmod to struct xkb_mod. This table now includes the real modifiers in the first 8 places. To distinguish between them, we add an enum mod_type to struct xkb_mod. Besides being a more reasonable approach, this enables us to share some code later, remove XKB_NUM_CORE_MODS (though the 0xff mask still appears in a few places), and prepares us to flat out remove the distinction in the future. This commit just does the conversion. Signed-off-by: Ran Benita <ran234@gmail.com>
* Don't use shifted virtual modifier masksRan Benita2012-10-061-24/+14
| | | | | | | | | | | | | | | | | Modifier masks can be confusing in some places. For example, key->vmodmap only contains virtual modifiers, where the first is in position 0, the second in 1 etc., while normally in a xkb_mod_mask_t the virtual modifiers start from the 8th (XKB_NUM_CORE_MODS) position. This happens in some other places as well. Change all of the masks to be in the usual real+virtual format, and when we need to access e.g. keymap->vmods we just adjust by XKB_NUM_CORE_MODS. (This also goes for indexes, e.g. interpret->virtual_modifier). This makes this stuff easier to reason about. Signed-off-by: Ran Benita <ran234@gmail.com>
* Remove the XKB_NUM_VIRTUAL_MODIFIERS limitRan Benita2012-10-061-31/+7
| | | | | | | | | Turn the virtual modifiers arrays in the keymap to a single darray, which doesn't use this limit. The number of virtual modifiers is still limited by the size of xkb_mod_mask_t, so we make sure not to go over that. Signed-off-by: Ran Benita <ran234@gmail.com>
* Don't limit key names to 4 charactersRan Benita2012-09-271-12/+5
| | | | | | | | | | | | | | | | | | | | | | Currently you can't give a key in xkb_keycodes a name of more than XKB_KEY_NAME_LENGTH (= 4) chars. This is a pretty annoying and arbitrary limitation; it leads to names such as <RTSH>, <COMP>, <PRSC>, <KPAD> etc. which may be hard to decipher, and makes it impossible to give more standard names (e.g. from linux/input.h) to keycodes. The purpose of this, as far as I can tell, was to save memory and to allow encoding a key name directly to a 32 bit value (unsigned long it was). We remove this limitation by just storing the names as atoms; this lifts the limit, allows for easy comparison like the unsigned long thing, and doesn't use more memory than previous solution. It also relieves us from doing all of the annoying conversions to/from long. This has a large diffstat only because KeyNameText, which is used a lot, now needs to take the context in order to resolve the atom. Signed-off-by: Ran Benita <ran234@gmail.com>
* Rename map.{c,h} to keymap.{c,h}Ran Benita2012-09-241-1/+1
| | | | | | Seeing as we don't like "map" anymore. Signed-off-by: Ran Benita <ran234@gmail.com>
* Organize src/ and test/ headersRan Benita2012-09-161-0/+1
| | | | | | | | | | | | - Add context.h and move context-related functions from xkb-priv.h to it. - Move xkb_context definition back to context.c. - Add keysym.h and move keysym upper/lower/keypad from xkb-priv.h to it. - Rename xkb-priv.h to map.h since it only contains keymap-related definitions and declarations now. - Remove unnecessary includes and some and some other small cleanups. Signed-off-by: Ran Benita <ran234@gmail.com>
* kbproto unentanglement: XkbSI match flagsDaniel Stone2012-09-111-8/+8
| | | | Signed-off-by: Daniel Stone <daniel@fooishbar.org>
* kbproto unentanglement: control actionsDaniel Stone2012-09-111-14/+14
| | | | Signed-off-by: Daniel Stone <daniel@fooishbar.org>
* kbproto unentanglement: XkbIM_*Daniel Stone2012-09-101-11/+11
| | | | Signed-off-by: Daniel Stone <daniel@fooishbar.org>
* kbproto unentanglement: action typesDaniel Stone2012-09-101-41/+41
| | | | Signed-off-by: Daniel Stone <daniel@fooishbar.org>
* Remove deprecated actionsDaniel Stone2012-09-101-16/+17
| | | | | | | We didn't do anything with ISO_Lock, ActionMessage, RedirectKey, and the device-specifying variants of the pointer actions, so remove those. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
* kbproto unentanglement: XkbNumVirtualModsDaniel Stone2012-09-101-8/+8
| | | | Signed-off-by: Daniel Stone <daniel@fooishbar.org>
* kbproto untanglement: XkbKeyNameLengthDaniel Stone2012-09-101-1/+1
| | | | | | | Define it ourselves as XKB_KEY_NAME_LENGTH and use that, instead of the one from XKB.h. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
* Unify some string tables from xkbcomp, text and keymap-dumpRan Benita2012-09-031-51/+194
| | | | | | | | | | | We move the LookupEntry struct from expr.h to text.h, along with most of the lookup tables. This makes them available everywhere. Looking up a value in the LookupEntry format is slower than direct index mapping, but it allows multiple names per value (with the canonical one being first) and "all"- and "none"-type masks. These functions are not used anywhere efficiency matters. Signed-off-by: Ran Benita <ran234@gmail.com>
* Convert rest of names in xkb_keymap back to atomsRan Benita2012-09-031-1/+1
| | | | | | | | | These were kept as atoms, but since the keymap was exposed in the API, we converted them to strings; no the keymap is no longer exposed, so we can go back to atoms. They make the keymap smaller (at least on 64-bit machines) and the comparisons faster. Signed-off-by: Ran Benita <ran234@gmail.com>
* Use XKB_MOD_INVALID instead of XkbNoModifierRan Benita2012-09-031-1/+1
| | | | Signed-off-by: Ran Benita <ran234@gmail.com>
* Move enum xkb_file_type to xkbcomp/ast.hRan Benita2012-09-021-17/+0
| | | | | | | This is a more suitable place for this enum, since it's internal to xkbcomp. Signed-off-by: Ran Benita <ran234@gmail.com>
* xkbcomp: clean up compile_keymap functionRan Benita2012-09-021-15/+11
| | | | | | | | We make the xkb_file_type enum sequential instead of masks, and then we don't have to repeat the file types several times in the function. Makes the code cleaner. Signed-off-by: Ran Benita <ran234@gmail.com>
* Modernize struct xkb_modsRan Benita2012-08-101-14/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently xkb_mods has the following members: - uint8_t real_mods - 8 X11 core mods - xkb_mod_mask_t vmods - 16 virtual mods, zero-based index - xkb_mod_mask_t mask - the computed effective *real* modifier mask, basically a cache for the first two which is: real_mods | real mods computed from vmods Our API acts on masks which combine the real_mods and vmods into a single value, which is: 8 first bits real mods | 16 next bits virtual mods (XkbNumModifiers = 8, XkbNumVirtualMods = 16). This is also the format which ResolveVModMask uses (which is where all the modifier masks really "come from", e.g. "Shift+Lock+Level5" -> xkb_mod_mask_t). What the code does now after getting the mask from ResolveVModMask, is to break it into real part and virtual part and store them seperately, and then join them back together when the effective mask is calculated. This is all pretty useless work. We change xkb_mods to the following: - xkb_mod_mask_t mods - usually what ResolveVModMask returns - xkb_mod_mask_t mask - the computed mask cache And try to consistently use the word "mods" for the original, non-effective mods and mask for the effective mods (which can only contain real mods for now, because things break otherwise). The separation is also made clearer. The effective masks are computed by UpdateModifiersFromCompat after all the sections have been compiled; before this the mask field is never touched; after this (i.e. map.c and state.c) the original mods field is never touched. This single execption to this rule is keymap-dump.c: it needs to print out only the original modifiers, not computed ones. This is also the reason why we actually keep two fields instead keeping one and modifying it in place. The next logical step is probably to turn the real mods into vmods themselves, and get rid of the distinction entirely (in a compatible way). Signed-off-by: Ran Benita <ran234@gmail.com>
* Remove xproto build dependencyRan Benita2012-08-071-8/+15
| | | | | | Very little left to do for this. Signed-off-by: Ran Benita <ran234@gmail.com>
* Handle key names consistentlyRan Benita2012-08-071-1/+1
| | | | | | | | | We treat the key names as fixed length, non NUL terminated strings of length XkbKeyNameLength, and use the appropriate *Text functions to print them. We also use strncpy everywhere instead of memcpy to copy the names, because it does some NUL padding and we might as well. Signed-off-by: Ran Benita <ran234@gmail.com>
* filecomp: fix path and error messageRan Benita2012-08-071-6/+6
| | | | Signed-off-by: Ran Benita <ran234@gmail.com>
* Use only one set of core mod name-to-index functionsRan Benita2012-08-071-11/+34
| | | | | | | | | | | | These were repeated 5 times. Note that this changes the ABI slightly: XKB_MOD_NAME_CAPS is changed from "Caps Lock" to "Lock", which is the ordinary legacy mod name for it. Since its hidden behind a #define, it's best to stay compatible with the old names (as I think was intended, given that "Mod1", etc. are the same). Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap-dump: use ActionTypeTextRan Benita2012-08-071-21/+21
| | | | Signed-off-by: Ran Benita <ran234@gmail.com>
* Drop Xkbc prefix of text functionsRan Benita2012-07-271-25/+25
| | | | | | Not really needed and inconsistent. Signed-off-by: Ran Benita <ran234@gmail.com>