summaryrefslogtreecommitdiff
path: root/src/keymap.h
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.
* API to query modifier set required to type a keysymJaroslaw Kubik2020-03-201-0/+11
| | | | | | | | | 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).
* keymap: fix NULL dereference when dumping the default fallback typeRan Benita2017-12-121-0/+1
| | | | | | | | | | | | | The default fallback type uses type->level_names = NULL but the keymap-dump code was not checking this case. Instead of adding more workarounds and possible bugs (e.g. previous commit), let's just keep the number of level names separately. This has the additional advantage retains extraneous level name if someone adds them for some reason. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: share LevelsSameSyms()Ran Benita2016-02-281-0/+3
| | | | | | The function is generic enough. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: fix outdated commentRan Benita2015-10-261-1/+1
| | | | | | See 725ae134d434bab6c999121d55dbc3582c4acb65. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: rename XkbKeyGroupWidth to XkbKeyNumLevelsRan Benita2014-09-251-1/+1
| | | | | | | | The "width" terminology comes from the group*width+level layout of the keysyms in a key, as used in the old implementations. We don't keep all the keysyms of a key in one array so change it to a more accurate name. Signed-off-by: Ran Benita <ran234@gmail.com>
* Make the effective mod mask calculation available to other filesRan Benita2014-08-181-0/+3
| | | | | | We will want to use that function in state.c as well. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: remove "flags" field of xkb_private_actionRan Benita2014-08-091-1/+0
| | | | | | Private actions have no flags - only serialized data. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap, keycodes, compat: don't use darray for LEDsRan Benita2014-04-221-1/+12
| | | | | | Use a static array of size XKB_MAX_LEDS instead, as in xkb_mod_set. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: don't use darray in xkb_mod_setRan Benita2014-04-221-3/+8
| | | | | | | | 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-0/+6
| | | | | | | To iterate over an xkb_mod_set. Slightly nicer interface and makes transitioning from darray easier. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: rename xkb_foreach_key to xkb_keys_foreachRan Benita2014-04-221-1/+1
| | | | | | | We'll use the format xkb_foos_foreach and xkb_foos_enumerate for the various iterators. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: protect xkb_foreach_key macro paramsRan Benita2014-04-221-3/+3
| | | | Signed-off-by: Ran Benita <ran234@gmail.com>
* symbols: use xkb_mod_set instead of entire keymapRan Benita2014-04-191-1/+1
| | | | | | | | The keymap is not removed entirely from the Info (just constified), since it is still needed in AddKeySymbols() for looking up aliases. This dependency will be removed in the future. Signed-off-by: Ran Benita <ran234@gmail.com>
* text: take xkb_mod_set instead of the entire keymapRan Benita2014-04-191-1/+1
| | | | | | | 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-1/+5
| | | | | | | | | | | 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: rename wrap_group_into_range -> XkbWrapGroupIntoRangeRan Benita2014-04-191-1/+1
| | | | | | It better fits with the naming convention in keymap.h. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: move ModNameToIndex from text.c and use it in keymap.cRan Benita2014-04-191-0/+4
| | | | Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: change action flag NO_ACCEL -> ACCELRan Benita2014-02-161-1/+1
| | | | | | It's easier to deal with, but we need to set it as "factory default". Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: reduce padding in struct xkb_sym_interpretRan Benita2014-02-091-1/+1
| | | | Signed-off-by: Ran Benita <ran234@gmail.com>
* action: change xkb_pointer_button_action::button to uint8_tRan Benita2014-02-081-1/+1
| | | | | | In XkbPtrBtnAction it is unsigned char, don't know how it became signed. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: split private functions to keymap-priv.cRan Benita2014-01-131-0/+5
| | | | | | | | This makes it easier to share the private functions in other DSOs without relying (too much) on dead code elimination, exported symbols, etc. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: move XkbEscapeMapName() to keymap.c.Ran Benita2014-01-131-0/+3
| | | | | | So we can use it outside src/xkbcomp; it is not really specific to it. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: remove struct xkb_key_redirect_actionRan Benita2013-07-311-12/+0
| | | | | | | | | | 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>
* keymap: move RANGE_WRAP to be the first in the enumRan Benita2013-07-231-1/+1
| | | | | | This is the reasonable "zero-default" for this enum. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: don't use darray for sym_interpretsRan Benita2013-07-211-1/+2
| | | | | | We want xkb_keymap to be easy to handle everywhere. Signed-off-by: Ran Benita <ran234@gmail.com>
* Replace flex scanner with a hand-written oneRan Benita2013-04-011-3/+1
| | | | | | | | | | | | | | | | | | | | | | The scanner is very similar in structure to the one in xkbcomp/rules.c. It avoids copying and has nicer error reporting. It uses gperf to generate a hashtable for the keywords, which gives a nice speed boost (compared to the naive strcasecmp method at least). But since there's hardly a reason to regenerate it every time and require people to install gperf, the output (keywords.c) is added here as well. Here are some stats from test/rulescomp: Before: compiled 1000 keymaps in 4.052939625s ==22063== total heap usage: 101,101 allocs, 101,101 frees, 11,840,834 bytes allocated After: compiled 1000 keymaps in 3.519665434s ==26505== total heap usage: 99,945 allocs, 99,945 frees, 7,033,608 bytes allocated Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: add xkb_keymap_new_from_buffer()David Herrmann2013-04-011-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The current API doesn't allow the caller to create keymaps from mmap()'ed files. The problem is, xkb_keymap_new_from_string() requires a terminating 0 byte. However, there is no way to guarantee that when using mmap() so a user currently has to copy the whole file just to get the terminating zero byte (assuming they cannot use xkb_keymap_new_from_file()). This adds a new entry xkb_keymap_new_from_buffer() which takes a memory location and the buffer size in bytes. Internally, we depend on yy_scan_{string,byte}() helpers. According to flex documentation these already copy the input string because they are wrappers around yy_scan_buffer(). yy_scan_buffer() on the other hand has some insane requirements. The buffer must be writeable and the last two bytes must be ASCII-NUL. But the buffer may contain other 0 bytes just fine. Because we don't want these constraints in our public API, xkb_keymap_new_from_buffer() needs to create a copy of the input memory. But it then calls yy_scan_buffer() directly. Hence, we have the same number of buffer-copies as with *_from_string() but without the terminating 0 requirement. The explicit yy_scan_buffer() call is preferred over yy_scan_byte() so the buffer-copy operation is not hidden somewhere in flex. Maybe some day we no longer depend on flex and can have a zero-copy API. A user could mmap() a file and it would get parsed right from this buffer. But until then, we shouldn't expose this limitation in the API but instead provide an API that some day can work with zero-copy. Signed-off-by: David Herrmann <dh.herrmann@gmail.com> [ran: rebased on top of my branch] Conflicts: Makefile.am src/xkbcomp/xkbcomp.c
* keymap: rename xkb_kt_map_entry to xkb_key_type_entryRan Benita2013-03-181-4/+4
| | | | | | | That's a better name and fits more nicely. Also change type->map to type->entries. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: don't use darray for key aliasesRan Benita2013-03-181-1/+2
| | | | | | | With a little tweak to the copy-to-keymap routine in keycodes.c we can use a normal array. Signed-off-by: Ran Benita <ran234@gmail.com>
* Move a couple of general keymap functions from keycodes.cRan Benita2013-03-181-5/+11
| | | | | | | To get a key by name and resolve an alias - this makes sense for everyone. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: abstract a bit over the keymap formatRan Benita2013-03-181-7/+13
| | | | | | | | | | | | | | | | | | | | Make it a bit easier to experiment with other formats. Add a struct xkb_keymap_format_operations, which currently contains the keymap compilation and _get_as_string functions. Each format can implement whatever it wants from these. The current public entry points become wrappers which do some error reporting, allocation etc., and calling to the specific format. The wrappers are all moved to src/keymap.c, so there are no XKB_EXPORT's under src/xkbcomp/ anymore. The only format available now is normal text_v1. This is all not very KISS, and adds some indirection, but it is helpful and somewhat cleaner. Signed-off-by: Ran Benita <ran234@gmail.com>
* Change 'indicator' to 'led' everywhere possibleRan Benita2013-03-181-2/+2
| | | | | | | | | | | | | | | | | | 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>
* keymap: wrap the layout parameter if it is out of range for the keyRan Benita2012-11-111-0/+6
| | | | | | | | | | | | | | | | | | | | | The functions num_levels_for_key() and get_syms_by_level() have a 'layout' parameter. Currently it is expected that this value is always legal for the key, as determined by num_layouts_for_key(). However, there are legitimate use cases for passing an out-of-range layout there, most probably passing the effective layout, and expecting to get the keysyms/levels for just this layout. So we wrap it just as we do in the xkb_state_* functions. This is also useful for stuff like this: http://developer.gnome.org/gdk/stable/gdk-Keyboard-Handling.html#gdk-keymap-lookup-key If this behavior is not desired, the user has the option to check against num_layouts_for_key herself. https://bugs.freedesktop.org/show_bug.cgi?id=56866 Reported-by: Gatis Paeglis <gatis.paeglis@digia.com> Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: use plain array for keymap->group_namesRan Benita2012-10-231-3/+3
| | | | | | Again it is not resized. Signed-off-by: Ran Benita <ran234@gmail.com>
* Clean up xkb_sym_interpret a bitRan Benita2012-10-181-11/+8
| | | | | | | | | | | | | | 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>
* keymap: rename keymap->sym_interpret -> sym_interpretsRan Benita2012-10-111-1/+1
| | | | | | This can be a bit confusing. Signed-off-by: Ran Benita <ran234@gmail.com>
* Remove the XKB_NUM_INDICATORS limitRan Benita2012-10-101-4/+4
| | | | | | | Use a darray instead of a static array of size 32. We still enforce XKB_MAX_LEDS because of the size of xkb_led_mask_t. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: don't use darray for keymap->keysRan Benita2012-10-101-4/+5
| | | | | | It's never resized. Signed-off-by: Ran Benita <ran234@gmail.com>
* Rename XKB_NUM_GROUPS to XKB_MAX_GROUPSRan Benita2012-10-101-1/+1
| | | | | | This is a more appropriate name now. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: use xkb_mod_mask_t for interpret->mods and modmapRan Benita2012-10-061-2/+2
| | | | | | | | These are both real modifier masks, but we keep this information only in the program logic now so when we change it we don't have to worry about the type. Signed-off-by: Ran Benita <ran234@gmail.com>
* Replace 0xff with MOD_REAL_MASK_ALLRan Benita2012-10-061-0/+2
| | | | | | | 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>
* Keep real and virtual mods in the same table in the keymapRan Benita2012-10-061-6/+11
| | | | | | | | | | | | | | 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>
* Remove the XKB_NUM_VIRTUAL_MODIFIERS limitRan Benita2012-10-061-4/+10
| | | | | | | | | 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>
* Use our types instead of int/uint32_t in a few placesRan Benita2012-10-061-1/+1
| | | | Signed-off-by: Ran Benita <ran234@gmail.com>
* Don't limit key names to 4 charactersRan Benita2012-09-271-5/+3
| | | | | | | | | | | | | | | | | | | | | | 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>
* keymap: remove some more unneeded macrosRan Benita2012-09-241-24/+0
| | | | | | It clearer to just access the needed data directly. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: store a pointer to the type in xkb_group instead of indexRan Benita2012-09-241-11/+4
| | | | | | | Gets rid of some more unneeded indirection, including the XkbKeyType macro. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap, symbols: improve xkb_key memory layoutRan Benita2012-09-241-18/+25
| | | | | | | | | | | | | | | | Add struct xkb_group and xkb_level for use in xkb_key, to mirror how it's done in KeyInfo, GroupInfo, LevelInfo in symbols.c. This corresponds more nicely to the logical data layout (i.e. a key has groups which have levels), and also removes a lot of copying and ugly code due to the index indirections and separate arrays which were used before. This uses more memory in some places (e.g. we alloc an action for every level even if the key doesn't have any) but less in other places (e.g. we no longer have to pad each group to ->width levels). The numbers say we use less overall. Signed-off-by: Ran Benita <ran234@gmail.com>
* keymap: use our type for keymap->enabled_ctrlsRan Benita2012-09-241-1/+1
| | | | Signed-off-by: Ran Benita <ran234@gmail.com>