Add a new warning for numeric keysyms
authorPierre Le Marre <dev@wismill.eu>
Mon, 18 Sep 2023 16:17:39 +0000 (18:17 +0200)
committerWismill <dev@wismill.eu>
Tue, 19 Sep 2023 06:49:52 +0000 (08:49 +0200)
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.

doc/message-registry.md
doc/message-registry.yaml
src/messages-codes.h
src/xkbcomp/expr.c
src/xkbcomp/parser.y
tools/messages.c

index 69027be..dac4175 100644 (file)
@@ -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.
 
@@ -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 |
@@ -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>
@@ -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
index fea4658..f7e0c2e 100644 (file)
   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
index 64a6177..1ba568c 100644 (file)
@@ -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 */
index f935ce6..558fef3 100644 (file)
@@ -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;
     }
index 1beb30b..e1226b1 100644 (file)
@@ -765,6 +765,11 @@ KeySym          :       IDENT
                                     );
                                     $$ = XKB_KEY_NoSymbol;
                                 }
+                                parser_warn(
+                                    param, XKB_WARNING_NUMERIC_KEYSYM,
+                                    "numeric keysym \"0x%"PRIx64"\" (%"PRId64")",
+                                    $1, $1
+                                );
                             }
                         }
                 ;
index 365792b..abda073 100644 (file)
@@ -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"},