Commit Graph

1124 Commits (61fed8dab9b8e27981f36ffc96666d7376546e30)

Author SHA1 Message Date
Ran Benita 61fed8dab9 Replace darray_mem with a new darray_steal
That's a more declarative interface.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-07-26 00:19:34 +03:00
Ran Benita fbd9286036 ast-build: use cast instead of ->common
Missed in 1b2bb204e0.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-07-26 00:13:54 +03:00
Ran Benita 5f5b960c71 types: refactor CopyKeyTypesToKeymap
So it's OOM-safe and doesn't clobber keymap on failure.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-07-25 23:45:04 +03:00
Ran Benita 320e5ffaf1 keycodes: split CopyKeyInfoToKeymap to several functions
It's a bit easier to read and self-documenting. Also handles OOM better.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-07-25 23:45:04 +03:00
Ran Benita cb4bae714e parser: don't shadow "str"
It's a name of a function in scanner-utils.h and also of some
parameters.

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

Reported-by: Bryce Harrington <b.harrington@samsung.com>
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-06-30 14:52:30 +03:00
Ran Benita 9c30d6da4e x11: don't iterate on empty batches
If count % SIZE == 0 we did a useless iteration where start==stop. It's
harmless but strange, so don't do that.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-06-15 15:30:51 +03:00
Ran Benita 67d884ec14 Remove unnecessary !!(expressions)
_Bool already does that.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-06-01 15:24:10 +03:00
Ran Benita d6f2d8ecd0 rules: fix leak on failure
matcher_match() builds up the kccgst's, and we steal the memory on
success. But on error we didn't free it.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-05-28 20:36:58 +03:00
Ran Benita e3f751be66 x11: fix out-of-bounds access in adopt_atoms() error handling
Two problems:

- `j` can be >= `SIZE`, and needs to be wrapped like in the rest of the
   code.

- `cookies[j % SIZE]` is not initialized if there's no atom in `from[j]`.

The is manifested when:

- We've already gone through one batch (>= 128 atoms) (in fact this
  cannot happen in call to `adopt_atoms` in the current code).

- An XCB request failed in the middle of a batch.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-05-14 12:02:13 +03:00
Ran Benita 86cfef63ca ast-build: don't leak on OOM in BoolVarCreate
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-05-11 09:47:56 +03:00
Ran Benita 2e561c3f25 parser: show the keysym in "unrecognized keysym" messages
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-30 08:57:16 +03:00
Ran Benita 67323f41a6 keycodes: fix uninitialized variable
Happened in one of the previous commits. For some reason, gcc doesn't
warn about this, but clang does...

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-25 01:14:31 +03:00
Ran Benita 07fb6a6c19 xkbcomp: don't align enum values
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-22 18:19:01 +03:00
Ran Benita 28a22ba226 xkbcomp: use straight assignment instead of CopyModSet
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-22 18:11:16 +03:00
Ran Benita 9014cf8cd8 keymap, keycodes, compat: don't use darray for LEDs
Use a static array of size XKB_MAX_LEDS instead, as in xkb_mod_set.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-22 14:58:42 +03:00
Ran Benita 787faf3665 keymap: don't use darray in xkb_mod_set
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>
2014-04-22 14:56:44 +03:00
Ran Benita 6b1cdee107 keymap: add and use xkb_mods_{foreach,enumerate}()
To iterate over an xkb_mod_set. Slightly nicer interface and makes
transitioning from darray easier.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-22 14:56:01 +03:00
Ran Benita 0f6bca2b37 keymap: rename xkb_foreach_key to xkb_keys_foreach
We'll use the format xkb_foos_foreach and xkb_foos_enumerate for the
various iterators.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-22 14:56:01 +03:00
Ran Benita 9b1a68eca9 keymap: protect xkb_foreach_key macro params
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-22 14:56:01 +03:00
Ran Benita decb291553 darray: remove unused darray_foreach_reverse()
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-22 14:56:01 +03:00
Ran Benita 00f084b6ec utils: detect overflow in memdup()
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-22 14:56:01 +03:00
Ran Benita 95aabeecb1 symbols: use xkb_mod_set instead of entire keymap
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>
2014-04-19 17:07:34 +03:00
Ran Benita f2cbeda9f0 types: use xkb_mod_set instead of entire keymap
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-19 16:23:48 +03:00
Ran Benita bf2878d227 compat: use xkb_mod_set instead of entire keymap
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-19 16:23:48 +03:00
Ran Benita b5655b3d67 vmod: take xkb_mod_set instead of the entire keymap
This is the only place where the modifier information is modified. We
will make it local to a given XKB file (after which it will be merged
into the keymap). Currently it changes the keymap directly, which
sidesteps the abstraction and leaves side-effects even if the XkbFile's
compilation fails.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-19 16:23:48 +03:00
Ran Benita 0b7c8d6198 action: take xkb_mod_set instead of the entire keymap
A couple of modiifer actions need this information, but not the entire
keymap.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-19 16:23:48 +03:00
Ran Benita 9fbcf6bb18 expr: take xkb_mod_set instead of the entire keymap
The modifier-resolving functions only need the modifier information.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-19 16:23:46 +03:00
Ran Benita edc0aef57d text: take xkb_mod_set instead of the entire keymap
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>
2014-04-19 16:23:04 +03:00
Ran Benita ca3170ad38 Add struct xkb_mod_set
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>
2014-04-19 16:20:09 +03:00
Ran Benita 3d7aff5fcd keymap: rename wrap_group_into_range -> XkbWrapGroupIntoRange
It better fits with the naming convention in keymap.h.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-19 16:15:05 +03:00
Ran Benita 51a1df2f21 keymap: move ModNameToIndex from text.c and use it in keymap.c
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-19 16:12:26 +03:00
Ran Benita 120c5c317e symbols: separate ctx
Same as was done for compat and types.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-17 22:16:34 +03:00
Ran Benita 659eacc9fc compat: separate ctx
Same as was done for types.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-17 22:16:34 +03:00
Ran Benita 36cbecc5b5 types: separate ctx
Separate the ctx object to its own field in CompatInfo, instead of doing
keymap->ctx.

The compilation functions should not have direct access to the keymap;
instead they should process the files with their own independent state
(in the *Info structs) as much as possible, and only at the end should
they be copied (i.e. commited) to the keymap. If the compilation fails,
it leaves no by-products. It's also just good form.

This was seemingly the original author's intention, but I suppose he cut
a few corners (mostly with the handling of virtual modifiers, which are
threaded through types -> compat -> symbols).

This commit is the first step and may look artificial; however the
'keymap' field will be removed shortly.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-16 23:19:49 +03:00
Ran Benita 999f3792ac action: convert a few missed unsigned -> enum xkb_action_type
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-16 23:19:49 +03:00
Ran Benita 9c8fcee195 expr: fix handling of unknown integer binary operator
We can't reach the default branch but at least make it do something
sensible.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-04-16 21:25:40 +03:00
Ran Benita 5417440970 state: fix consumed modifier calculation
The current calculation is in short:
    entry ? (entry->mask & ~entry->preserve) : 0

This changes it be
    type->mask & ~(entry ? entry->preserve : 0)

This is what Xlib does. While less intuitive, it is actually more
correct, if you follow this deduction:

- The key group's type->mask defines which modifiers the key even cares
  about. The others are completely irrelevant (and in fact they are
  masked out from all sided in the level calculation). Example: NumLock
  for an alphabetic key.

- The type->mask, the mods which are not masked out, are *all* relevant
  (and in fact in the level calculation they must match *exactly* to the
  state). These mods affect which level is chosen for the key, whether
  they are active or not.

- Because the type->mask mods are all relevant, they must be considered
  as consumed by the calculation *even if they are not active*.

Therefore we use type->mask instead of entry->mask.

The second change is what happens when no entry is found: return 0 or
just take preserve to be 0? Let's consider an example, the basic type

    type "ALPHABETIC" {
        modifiers = Shift+Lock;
        map[Shift] = Level2;
        map[Lock] = Level2;
        level_name[Level1] = "Base";
        level_name[Level2] = "Caps";
    };

Suppose Shift+Lock is active - it doesn't match any entry, thus it gets
to level 0. The first interpretation would take them both to be
unconsumed, the second (new one) would take them both to be consumed.
This seems much better: Caps is active, and Shift disables it, they both
do something.

This change also fixes a pretty lousy bug (since 0.3.2), where Shift
appears to apparently *not* disable Caps. What actually happens is that
Caps is not consumed (see above) but active, thus the implicit
capitalization in get_one_sym() kicks in and capitalizes it anyway.

Reported-by: Davinder Pal Singh Bhamra
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-03-27 19:38:30 +02:00
Ran Benita 3cfa7fdac8 state: apply control transformation on utf8/utf32 keysym strings
This is required by the specification:
http://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Control_Modifier
and clients expect this to happen.

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

Reported-by: Gatis Paeglis <gatis.paeglis@digia.com>
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-03-22 20:07:30 +02: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 2bbaf7c7d1 Add utf8.{c,h} for common UTF-8 util functions
We need to validate some UTF-8, so this adds an is_valid_utf8()
function, which is probably pretty slow but should work correctly.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-03-22 02:10:28 +02:00
Ran Benita 3c14d23367 x11: relax XkbGetNames requirements
It is valid for a keymap to not have key aliases, group names and
various other things. But the current test requires all of them to be
present in the reply, which causes us the fail on such keymaps (as the
XQuartz one).

Instead, require only what we really need. The virtual-mods names may
not be strictly required, but it seems safer to leave it in for now.

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

Reported-by: Gatis Paeglis <gatis.paeglis@digia.com>
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-03-06 13:43:02 +02:00
Ran Benita caf8f3be98 symbols, keycodes: fix int return type when bool is intended
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-22 23:45:52 +02:00
Ran Benita 09bcf0ffc0 symbols: cleanup SetSymbolsField
Normalize the style and error message levels.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-22 23:45:52 +02:00
Ran Benita 35dea49b0a symbols: fix possible use of uninitialized value
Nothing bad can come out of it, but for some reason this error didn't
return early (inherited from xkbcomp).
Also promote the log message to an error, as it clearly is.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-22 23:45:31 +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 1fa7d6d3ab action: unify SetLatch and Lock handler functions
This is a little shorter and follows easier from the spec flag
description table.
Also a few were too permissive (like allowing LatchToLock in SetMods).

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-16 18:39:31 +02:00
Ran Benita af75353a88 action: add a common CheckBooleanFlag function
Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-16 11:05:34 +02:00
Ran Benita 18191702ae keymap: change action flag NO_ACCEL -> ACCEL
It's easier to deal with, but we need to set it as "factory default".

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-16 11:05:32 +02:00
Ran Benita af261cb605 action: fix SwitchScreen "same" field handling
This used to *unset* a flag called "SwitchApplication"; we changed the
flag to "same" but forgot to switch the cases.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-16 11:05:17 +02:00
Ran Benita 8d3db622b8 keymap-dump: add missing support for NoLock and NoUnlock flags
Based on a libxkbfile patch by Andreas Wettstein.

Signed-off-by: Ran Benita <ran234@gmail.com>
2014-02-15 23:50:21 +02:00