Skip to content

Commit

Permalink
Add a new warning for numeric keysyms
Browse files Browse the repository at this point in the history
Usually it is better to use the corresponding human-friendly keysym
names. If there is none, then the keysym is most probably not
supported in the ecosystem. The only use case I see is similar to the
PUA in Unicode (see: https://en.wikipedia.org/wiki/Private_Use_Areas).
I am not aware of examples of this kind of use.
  • Loading branch information
wismill committed Sep 19, 2023
1 parent 417d074 commit eafd3ac
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 1 deletion.
51 changes: 50 additions & 1 deletion doc/message-registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ NOTE: This file has been generated automatically by “update-message-registry.p
-->

This page lists the warnings and errors generated by xkbcommon.
There are currently 20 entries.
There are currently 21 entries.

@todo The documentation of the log messages is a work in progress.

Expand All @@ -23,6 +23,7 @@ There are currently 20 entries.
| [XKB-305] | `non-base-group-name` | Warn if a group name was defined for group other than the first one | Warning |
| [XKB-312] | `unsupported-shift-level` | Warn when a shift level is not supported | Error |
| [XKB-461] | `conflicting-key-symbol` | Warn if there are conflicting keysyms while merging keys | Warning |
| [XKB-489] | `numeric-keysym` | Warn on numeric keysym (other than 0-9) | Warning |
| [XKB-516] | `extra-symbols-ignored` | <span class="todo">TODO:</span> add description | Warning |
| [XKB-578] | `wrong-field-type` | Warn when a field has not the expected type | Error |
| [XKB-645] | `unknown-char-escape-sequence` | Warn on unknown escape sequence in string literal | Warning |
Expand Down Expand Up @@ -165,6 +166,53 @@ as numbers and as identifiers `LevelN`, where `N` is in the range (1..8).
<dt>Summary</dt><dd>Warn if there are conflicting keysyms while merging keys</dd>
</dl>

### XKB-489 – Numeric keysym {#XKB-489}

<dl>
<dt>Since</dt><dd>1.6.0</dd>
<dt>Type</dt><dd>Warning</dd>
<dt>Summary</dt><dd>Warn on numeric keysym (other than 0-9)</dd>
</dl>

Numeric keysyms are not human-friendly. Use the corresponding named keysym
or Unicode keysym, if available.


#### Examples

<details>
<summary>Hexadecimal keysym `0x1001ed0`</summary>

**Error message:**

```
xkbcommon: WARNING: [XKB-489] numeric keysym "0x1001ed0"
```

**Fix:**
<div class="example-container">
<div class="example">
<div class="example-inner">
<div class="example-title">Before</div>
```c
key <AE01> { [ 0x1001ed0] };
```
</div>
</div>
<div class="example">
<div class="example-inner">
<div class="example-title">After</div>
```c
// Preferred form: human-friendly
key <AE01> { [ Ocircumflexacute ] };
// or
key <AE01> { [ U1ED0 ] };
```
</div>
</div>
</div>
</details>

### XKB-516 – Extra symbols ignored {#XKB-516}

<dl>
Expand Down Expand Up @@ -280,6 +328,7 @@ xkbcommon support the following escape sequences in string literals:
[XKB-305]: @ref XKB-305
[XKB-312]: @ref XKB-312
[XKB-461]: @ref XKB-461
[XKB-489]: @ref XKB-489
[XKB-516]: @ref XKB-516
[XKB-578]: @ref XKB-578
[XKB-645]: @ref XKB-645
Expand Down
27 changes: 27 additions & 0 deletions doc/message-registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,33 @@
added: ALWAYS
type: warning
description: "Warn if there are conflicting keysyms while merging keys"
- id: "numeric-keysym"
code: 489
added: 1.6.0
type: warning
description: "Warn on numeric keysym (other than 0-9)"
details: |
Numeric keysyms are not human-friendly. Use the corresponding named keysym
or Unicode keysym, if available.
examples:
- name: Hexadecimal keysym `0x1001ed0`
description: |
**Error message:**
```
xkbcommon: WARNING: [XKB-489] numeric keysym "0x1001ed0"
```
before: |
```c
key <AE01> { [ 0x1001ed0] };
```
after: |
```c
// Preferred form: human-friendly
key <AE01> { [ Ocircumflexacute ] };
// or
key <AE01> { [ U1ED0 ] };
```
- id: "extra-symbols-ignored"
code: 516
added: ALWAYS
Expand Down
2 changes: 2 additions & 0 deletions src/messages-codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ enum xkb_message_code {
XKB_ERROR_UNSUPPORTED_SHIFT_LEVEL = 312,
/** Warn if there are conflicting keysyms while merging keys */
XKB_WARNING_CONFLICTING_KEY_SYMBOL = 461,
/** Warn on numeric keysym (other than 0-9) */
XKB_WARNING_NUMERIC_KEYSYM = 489,
/** TODO: add description */
XKB_WARNING_EXTRA_SYMBOLS_IGNORED = 516,
/** Warn when a field has not the expected type */
Expand Down
3 changes: 3 additions & 0 deletions src/xkbcomp/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,9 @@ ExprResolveKeySym(struct xkb_context *ctx, const ExprDef *expr,
}

if (val <= XKB_KEYSYM_MAX) {
log_warn_with_code(ctx, XKB_WARNING_NUMERIC_KEYSYM,
"numeric keysym \"0x%x\" (%d)",
(unsigned int) val, val);
*sym_rtrn = (xkb_keysym_t) val;
return true;
}
Expand Down
5 changes: 5 additions & 0 deletions src/xkbcomp/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,11 @@ KeySym : IDENT
);
$$ = XKB_KEY_NoSymbol;
}
parser_warn(
param, XKB_WARNING_NUMERIC_KEYSYM,
"numeric keysym \"0x%"PRIx64"\" (%"PRId64")",
$1, $1
);
}
}
;
Expand Down
1 change: 1 addition & 0 deletions tools/messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static const struct xkb_message_entry xkb_messages[] = {
{XKB_WARNING_NON_BASE_GROUP_NAME, "Non base group name"},
{XKB_ERROR_UNSUPPORTED_SHIFT_LEVEL, "Unsupported shift level"},
{XKB_WARNING_CONFLICTING_KEY_SYMBOL, "Conflicting key symbol"},
{XKB_WARNING_NUMERIC_KEYSYM, "Numeric keysym"},
{XKB_WARNING_EXTRA_SYMBOLS_IGNORED, "Extra symbols ignored"},
{XKB_ERROR_WRONG_FIELD_TYPE, "Wrong field type"},
{XKB_WARNING_UNKNOWN_CHAR_ESCAPE_SEQUENCE, "Unknown char escape sequence"},
Expand Down

0 comments on commit eafd3ac

Please sign in to comment.