Commit Graph

65 Commits (99af72fd098b4aeae1121644c7412824583eaaf0)

Author SHA1 Message Date
Ran Benita b973d71e82 state: add xkb_state_key_get_{utf8,utf32}() API functions
These functions generally have the same effect as
xkb_state_key_get_syms() + xkb_keysym_to_utf{8,32}().

So why add them?

- They provide a slightly nicer interface, especially if the string is
  the only interest.

- It makes the handling of multiple-keysyms-to-utf8 transparent. For the
  designated use-case of multiple-keysyms (unicode combining
  characters), this is a must. We also validate the UTF-8, which the
  user might not otherwise do.

- We will need to apply some transformation on the resulting string
  which depend on the xkb_state. This is not possible with the
  xkb_keysym_* functions.

With these functions, the existing xkb_keysym_to_utf{8,32}() are not
expected to be used by a typical user; they are "raw" functions.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-03-22 17:17:16 +02:00
Ran Benita fdb4de1f85 doc: extend xkb_rule_names default-value description
Especially a mention of the XKB_DEFAULT_* envvars was missing.

Reported-by: Paeglis Gatis <Gatis.Paeglis@digia.com> (thanks!)
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-03-04 19:30:09 +02:00
Ran Benita e086ba9416 doc: remove possibly confusing comment
There are valid reasons to use the other keymap-creation functions, if
one needs them. On the other hand, if one is supposed to use RMLVO, it
is more or less the only choice, so the comment is not needed in this
case as well.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-03-04 18:24:11 +02:00
Ran Benita d7c91a15f8 doc: add comments about update_key() and get_syms() order
I remember we had a comment about this, but I can't find it. So add it
again.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-28 14:50:48 +02:00
Jasper St. Pierre 4fb7b06b0f state: Add xkb_state_key_get_consumed_mods
This retrieves the mask of consumed modifiers for a given key and state,
which is helpful for toolkits without having them to do it one modifier
at a time, or pass in 0xFFFFFFFF to xkb_state_remove_consumed_mods to
"reverse-engineer" the consumed mods.
2014-02-22 02:23:37 +02:00
Ran Benita 973b8fd47e api: deprecate XKB_MAP_COMPILE_PLACEHOLDER, and use KEYMAP instead of MAP
The PLACEHOLDER was not meant to be used, but c++ doesn't like passing 0
to enums, so it was used. For this reason we add all the NO_FLAGS items,
so the PLACEHOLDER shouldn't be used anymore.

Second, XKB_MAP is the prefix we used ages ago, KEYMAP is the expected
prefix here. So deprecate that as well.

The old names may still be used through the xkbcommon-compat.h header,
which is included by default (no need to include directly).

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-08 16:40:20 +02:00
Ran Benita 779eec3b8b x11: add missing #ifdef __cplusplus to header
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-04 22:18:12 +02:00
Ran Benita eb34825560 x11: add XKB protocol keymap and state creation support
These are function to create an xkb_keymap directly from XKB requests
to the X server. This opens up the possibility for X clients to use
xcb + xcb-xkb + xkbcommon as a proper replacement for Xlib + xkbfile for
keyboard support.

The X11 support must be enabled with --enable-x11 for now.
The functions are in xkbcommon/xkbcommon-x11.h. It depends on a recent
libxcb with xkb enabled. The functions are in a new libxkbcommon-x11.so,
with a new pkg-config file, etc. so that the packages may be split, and
libxkbcommon.so itself remains dependency-free.

Why not just use the RMLVO that the server puts in the _XKB_RULES_NAMES
property? This does not account for custom keymaps, on-the-fly keymap
modifications, remote clients, etc., so is not a proper solution in
practice. Also, some servers don't even set it. Now, the client just
needs to recreate the keymap in response to a change in the server's
keymap (as Xlib clients do with XRefreshKeyboardMapping() and friends).

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-02 11:16:40 +02:00
Hardening e77712bd27 Add a constant for NumLock
This trivial patch adds the name of the Numlock modifier
2014-01-11 17:29:02 +02:00
Ran Benita 53e7a135c2 keysyms: add German T3 layout keysyms from xproto
Reference:
http://cgit.freedesktop.org/xorg/proto/xproto/commit/?id=6d4acb0e3a6568a8faaa651d4e3d32f917b9067b

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-01-01 10:40:09 +02:00
Wander Lairson Costa ac59e735eb Make C++ happy.
For most functions taking an enum flags parameter, we use 0 value to
indicate that no flags should be applied.

C++ has a stronger type system than C and will not implicitly convert
int's to enum's. Thus, we create valid 0 enum values for enum types
where it makes sense.

Signed-off-by: Wander Lairson Costa <wander.lairson@gmail.com>
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-09-26 15:54:53 +03:00
Ran Benita dbf07de14d doc: use 'indices' instead of 'indexes' consistently
We use 'indices' in some function names so use that.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-08-29 19:49:40 +03:00
Ran Benita b4cc33941d doc: try to explain leds and shift levels
Remove the @todo's.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-08-29 19:48:35 +03:00
Ran Benita 2a2a8d7da1 state: apply capitalization transformation on keysyms
The xkbproto spec says:
http://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Lock_Modifier

    If the Lock modifier is not consumed by the symbol lookup process,
    routines that determine the symbol and string that correspond to
    an event should capitalize the result.

This was not an issue until now, because most xkeyboard-config keymaps
do not utilize this "feature", and specify the keysyms for the Lock
modifier explicitly instead. However, some keymaps do depend on it, e.g.
ch(fr) for eacute and others.

The spec goes on to describe two options for doing this transformation:
locale-sensitive and locale-insensitive. We opt for the latter; it is
less desirable but we don't want *that* headache.

Also, only xkb_state_key_get_one_sym() is changed;
xkb_state_key_get_syms() is left as-is, and always reports the
untransformed keysyms. This is for the following reasons:

- The API doesn't allow it, since we return a const pointer directly to
  the keymap keysyms table and we can't transform that.

- The transformation doesn't make sense for multiple-keysyms.

- It can be useful for an application to get the "raw" keysyms if it
  wants to (e.g. maybe it wants to do the transformation itself).

Finally, note that xkb_state_mod_index_is_consumed() does *not*
report Lock as consumed even if it was used in the transformation. This
is what Xlib does.

This definitely doesn't fall under the "hard to misuse" API rule but
it's the best we can do.

https://bugs.freedesktop.org/show_bug.cgi?id=67167

Reported-By: Gatis Paeglis <gatis.paeglis@digia.com>
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-08-15 09:58:50 +03:00
Ran Benita 9c697f804a doc: tweak the wording on xkb_state/xkb_keymap relationship
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-08-14 11:37:58 +03:00
Ran Benita d83fe702d2 doc: un-clarify one subtle point
Including the X server is a bit of a borderline case; we should mostly
encourage people to use update_mask() only when xkbcommon itself
serializes the state on the other side. But it's not entirely wrong
either.. So rephrase a bit.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-08-13 15:17:59 +03:00
Ran Benita 3a0adc0f5c doc: try to clarify some subtle points
Which to choose: xkb_state_update_key() / xkb_state_update_mask(). If you
use update_mask(), you don't (and shouldn't) use update_key().
If you use update_key(), be careful not to have unmatched UP/DOWN
calls; this can bring about stuck modifiers etc.

Probably want to use XKB_STATE_{MODS,LAYOUT}_EFFECTIVE. The others are
only useful in very special cases.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-07-31 10:55:20 +03:00
Daniel Stone 6bb727b227 Resync keysym database
xproto 7.0.24 adds XF86AudioMicMute.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2013-07-17 22:47:32 +01:00
Matthias Clasen b06de3072b Add keycode min/max and iteration API
Add three new pieces of API:
  - xkb_keymap_min_keycode does what it says on the tin
  - xkb_keymap_max_keycode likewise
  - xkb_keymap_key_for_each calls the provided function once for every
    valid key in the keymap

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2013-05-09 15:31:21 +01:00
David Herrmann 36f55c494e keymap: add xkb_keymap_new_from_buffer()
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
2013-04-01 18:04:06 +01:00
Daniel Stone 40c46ecd5b Allow NULL rmlvo for xkb_keymap_new_from_names
Previously we allowed you to pass a names struct with five NULL members,
but not just pass NULL for the struct itself.  This was pretty dumb. :(

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2013-03-19 10:54:23 +00:00
Daniel Stone fbe5e6751e Add environment overrides for default RMLVO
You can now set default values in the environment, as well as a context
option to ignore the environment, e.g. for tests.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2013-03-19 10:53:37 +00:00
Ran Benita e33dd591bb doc: some improvements
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:06 +00:00
Ran Benita 540feef3bb More spelling errors
Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:04 +00:00
Ran Benita c7aef16649 keysym: print unicode keysyms uppercase and 0-padded
Use the same format as XKeysymToString.

Signed-off-by: Ran Benita <ran234@gmail.com>
2013-03-18 22:20:02 +00:00
Ran Benita 60bd92021b keymap: wrap the layout parameter if it is out of range for the key
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>
2012-11-11 00:32:16 +02:00
Ran Benita 577612258a Don't use trailing enum comma in public headers
Pretty annoying, but C89 doesn't support that (officially), and it might
cause warning with -pedantic, etc. (though you need -Wsystem-headers to
see them usually). Removing them is not a big deal.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-11-07 18:59:41 +02:00
Ran Benita eea0eaebfa doc: clarify that keysym_to_utf8 returns size including '\0'
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-11-06 23:01:44 +02:00
Ran Benita fb201645b2 Add some explanations on consumed modifiers
This should hopefully clarify this somewhat subtle point to the
uninitiated users.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-11-04 16:14:47 +02:00
Ran Benita 7261f404d2 state, context: allow passing NULL to *_unref()
For error handling code, it's nice to be able to pass NULL to these
function without worrying about segfaults ensuing. free() sets the
precedent here.

Also document this fact.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-29 01:20:04 +02:00
Ran Benita b935d3610f doc: fix wrong comment
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-26 16:16:18 +02:00
Ran Benita 3eac759989 doc: various fixes
Just moving around / fixing syntax / grammar.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-23 17:22:13 +02:00
Ran Benita 33bba36821 doc: move include_path functions to a separate group
These are 'special intrest' function, like the logging functions, so
it's nice to have them in their own logical group.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-23 17:22:13 +02:00
Ran Benita 0c98237f02 Change update_mask arguments to read 'depressed' instead of 'base'
Just to be consistent, as we use 'depressed' everywhere else in the API.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-22 22:23:29 +02:00
Ran Benita 4b81c9f3e3 Report which components of the state have changed
We add a return value to the xkb_state_update_key and
xkb_state_update_mask, which reports to the caller which of the state
components have changed as a result.

This restores the XKB functionality of the XkbStateNotify and
XkbIndicatorsStateNotify events. See:
http://www.x.org/releases/current/doc/kbproto/xkbproto.html#Events
It is quite useful in some situations. For example, it allows an
application to avoid doing some work if nothing of relevance in the
state has changed. Say, a keyboard layout applet. Also useful for
debugging.

The deltas themselves are not provided, because I can't see a use case.
If needed, it should be possible to add some API for that.

In xkbcommon, keymaps are immutable, so all of the other *Notify events
from XKB are irrelevant.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-22 21:58:03 +02:00
Ran Benita 6a94b122a4 Split the mods, layout, leds parts of xkb_state_components
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>
2012-10-22 21:48:40 +02:00
Ran Benita 3a5f87b8e9 doc: add note about X11 vs. extended keycodes
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-22 17:53:44 +02:00
David Herrmann 7b3bd11f92 Add xkb_keysym_from_name() flags argument for case-insensitive search
This adds a flags argument to xkb_keysym_from_name() so we can perform a
case-insensitive search. This should really be supported as many keysyms
have really weird capitalization-rules.

However, as this may produce conflicts, users must be warned to only use
this for fallback paths or error-recovery. This is also the reason why the
internal XKB parsers still use the case-sensitive search.

This also adds some test-cases so the expected results are really
produced. The binary-size does _not_ change with this patch. However,
case-sensitive search may be slightly slower with this patch. But this is
barely measurable.

[ran: use bool instead of int for icase, add a recommendation to the
doc, and test a couple "thorny" cases.]

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-10-16 21:29:09 +02:00
Ran Benita 3477d9e448 Finish first round of API documentation
There are a few @todo's, but nothing serious.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-13 14:03:29 +02:00
Ran Benita f43b33c02f state: make mod_index_is_consumed() return -1 on invalid input
Like all the other functions.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-13 13:13:55 +02:00
Ran Benita 523e46f41a Change log env vars to XKB_LOG_LEVEL/VERBOSITY
A bit more consistent and descriptive.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-12 10:17:57 +02:00
Ran Benita bde066b920 doc: use JAVADOC_AUTOBRIEF
Don't have to type @brief all the time.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-11 21:51:08 +02:00
Ran Benita bbf388ec1f Make xkb_keymap_num_leds return the index range instead of active count
Currently xkb_keymap_num_leds() returns a count of valid (settable)
leds. Because the indexes might be non-consecutive, and some leds
might not be settable, it is incorrect to use this function for
iterating over the leds in the keymap. But this is the main use case of
this function, so instead of the current behavior we adapt the function
to the use case by making it return the needed range of iteration.
The caller needs to handle invalid intermittent indexes, though.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-10-11 16:54:17 +02:00
Daniel Stone 5aaf65b74e Add xkb_state_key_get_one_sym
The trivial wrapper around xkb_state_key_get_syms that every user to
date has implemented.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-27 23:27:49 +10:00
Ran Benita 9a18b87251 Add format argument to xkb_keymap_get_as_string
This function really needs a format argument, for symmetry with the
keymap creation functions. If we add new formats, we will almost
certainly want to add support for serializing it into a string. It would
also allow to convert from one format to another, etc.

The in the common case, the user would just want to use the format she
used to create the keymap; for that we add a special
XKB_KEYMAP_USE_ORIGINAL_FORMAT value, which will do that (it is defined
to -1 outside of the enum because I have a feeling we might want to use
0 for something else). To support this we need to keep the format inside
the keymap. While we're at it we also initialize keymap flags properly.

This changes the API, but the old xkb_map_get_as_string name works as
expected so this is the best time to do this.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:13:32 +10:00
Ran Benita 5d31b9e3e7 Add return value the xkb_keysym_get_name
This is useful to see whether the function was successful and whether
truncation occurred.
It just changes void -> int so shouldn't break API or ABI.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:13:32 +10:00
Ran Benita 25b8384404 Improve API doxygen documentation
To make it look better and a bit more structured and informative.
Not all of the functions are converted to doxygen format, so this is not
finished.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:13:32 +10:00
Ran Benita 0dd40125c5 API: add _context prefix to log-related functions
This is to follow the general scheme set by all of the other API
functions.
Since no one is using these functions yet, we don't (actually better
not) add the old names to xkbcommon-compat.h.

Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-24 09:08:54 +10:00
Daniel Stone bf19408078 Promote keymap enumeration API to public
Rename the functions to get keysyms by key/layout/level to fit with the
recent public API renames, and expose them.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-24 09:08:53 +10:00
Daniel Stone 33a66515d6 API change: Rename xkb_map_* and group -> layout
Move xkb_map_* functions to xkb_keymap_*, xkb_key_* functions under
either xkb_keymap or xkb_state, and rename groups to layout in all
user-visible API.

Backwards-compatible hooks are provided, such that old source will
build, but silently mangled to the new names, and old binaries will
also continue to work.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-09-20 23:30:23 +10:00