Commit Graph

73 Commits (b5586a6c4294b46eb23d1fc527ff63dcd27e23ac)

Author SHA1 Message Date
Ran Benita babc9e0c30 state: add GTK consumed modifiers mode
This is more or less what is implemented here:
https://git.gnome.org/browse/gtk+/tree/gdk/x11/gdkkeys-x11.c?h=3.19.10#n1131

The implementation here is more technically correct but should provide
the same results.

Try it out with ./test/interactive-evdev -g (modifiers prefixed with "-"
are consumed).

https://bugzilla.gnome.org/show_bug.cgi?id=754110
https://github.com/xkbcommon/libxkbcommon/issues/17

Signed-off-by: Ran Benita <ran234@gmail.com>
2016-10-31 12:52:28 +02:00
Ran Benita a0a41332cc state: allow different modes for calculating consumed modifiers
The current functions dealing with consumed modifiers use the
traditional XKB definition of consumed modifiers (see description in the
added documentation). However, for several users of the library (e.g.
GTK) this definition is unsuitable or too eager. This is exacerbated by
some less-than-ideal xkeyboard-config type definitions (CTRL+ALT seems
to cause most grief...).

So, because we
- want to enable alternative interpretations, but
- don't want to expose too much internal details, and
- want to keep things simple for all library users,
we add a high-level "mode" parameter which selects the desired
interpretation. New ones can be added as long as they make some sense.

All of the old consumed-modifiers functions keep using the traditional
("XKB") mode. I mark xkb_state_mod_mask_remove_consumed() and as
deprecated without adding a *2 variant because I don't it is very useful
(or used) in practice.

Alternative modes are added in subsequent commits (this commit only adds
a mode for the existing behavior).

https://github.com/xkbcommon/libxkbcommon/issues/17

Signed-off-by: Ran Benita <ran234@gmail.com>
2016-10-31 12:52:26 +02:00
Ran Benita b91584a8f3 doc: update reference to compat symbol to its new name
Signed-off-by: Ran Benita <ran234@gmail.com>
2016-03-26 01:56:03 +03:00
Ran Benita e8f04f222a doc: add environment variables index
Signed-off-by: Ran Benita <ran234@gmail.com>
2016-01-20 23:17:42 +02:00
Ran Benita 4aa50c9d88 doc: some notes about key names and aliases
Signed-off-by: Ran Benita <ran234@gmail.com>
2016-01-20 23:17:42 +02:00
Mike Blumenkrantz 0ce17ef3ea keymap: add xkb_keymap_key_by_name(), xkb_keymap_key_get_name(), tests
xkb_keymap_key_by_name() allows finding a keycode from a given keyname and
is useful for generating keyboard events to use in regression tests
during CI

xkb_keymap_key_get_name() is the inverse of xkb_keymap_key_by_name()

Signed-off-by: Mike Blumenkrantz <zmike@osg.samsung.com>
[ran: some stylistic tweaks + another test case]
Signed-off-by: Ran Benita <ran234@gmail.com>
2016-01-20 23:17:10 +02:00
Ran Benita 0b448548a8 doc: linkify some references
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-09-22 15:24:15 +03:00
Ran Benita 1ba7d9ecda doc: reorder "Keymap Components" functions
Put the general keymap stuff before key-specific functions.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-09-19 12:52:45 +03:00
Ran Benita 494e318946 doc: move consumed modifier description to its own section
With small edits.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-09-19 00:59:01 +03:00
Ran Benita 527bf96f9b keymap: fix typo
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-08-24 10:16:41 +03:00
David Herrmann c62cde57f5 keymap: fix description of xkb_keymap_key_get_syms_by_level()
The @level argument is restricted by xkb_keymap_num_levels_for_key(). Fix
the description to no longer mention xkb_keymap_num_layouts_for_key().

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
2014-08-24 10:14:07 +03:00
Ran Benita 9db1432326 docs: move keysym-transformations page to a better position
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-07-28 18:04:34 +03:00
Ran Benita b629576266 docs: fix self-reference
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-07-28 10:03:48 +03:00
Ran Benita 89fbf979f1 doc: explain keysym/string transformation
The documentation should be clear about what is happening, even if it's
rather unlikely anyone will really dig into the details.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-12 00:22:47 +03:00
Ran Benita da83e678ab doc: add @since annotations for API added since 0.3.0
And also add release dates to the NEWS.

We're adding API freely, so this can make life easier for anyone who
wants to stay compatible with an older version.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-11 19:09:48 +03:00
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
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
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