tools/how-to-type: add --keysym for how to type a keysym Previously, could only check how to type a Unicode codepoint, but searching for a keysym directly is also occasionally useful. Signed-off-by: Ran Benita <ran@unusedvar.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
diff --git a/tools/how-to-type.c b/tools/how-to-type.c
index 0a6f79e..91ebd00 100644
--- a/tools/how-to-type.c
+++ b/tools/how-to-type.c
@@ -24,6 +24,7 @@
#include "config.h"
#include <getopt.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
@@ -35,9 +36,9 @@
static void
usage(const char *argv0, FILE *fp)
{
- fprintf(fp, "Usage: %s [--rules <rules>] [--model <model>] "
+ fprintf(fp, "Usage: %s [--keysym] [--rules <rules>] [--model <model>] "
"[--layout <layout>] [--variant <variant>] [--options <options>]"
- " <unicode codepoint>\n", argv0);
+ " <unicode codepoint/keysym>\n", argv0);
}
int
@@ -48,6 +49,7 @@ main(int argc, char *argv[])
const char *layout_ = NULL;
const char *variant = NULL;
const char *options = NULL;
+ bool keysym_mode = false;
int err = EXIT_FAILURE;
struct xkb_context *ctx = NULL;
char *endp;
@@ -60,6 +62,7 @@ main(int argc, char *argv[])
xkb_keycode_t min_keycode, max_keycode;
xkb_mod_index_t num_mods;
enum options {
+ OPT_KEYSYM,
OPT_RULES,
OPT_MODEL,
OPT_LAYOUT,
@@ -68,6 +71,7 @@ main(int argc, char *argv[])
};
static struct option opts[] = {
{"help", no_argument, 0, 'h'},
+ {"keysym", no_argument, 0, OPT_KEYSYM},
{"rules", required_argument, 0, OPT_RULES},
{"model", required_argument, 0, OPT_MODEL},
{"layout", required_argument, 0, OPT_LAYOUT},
@@ -85,6 +89,9 @@ main(int argc, char *argv[])
break;
switch (opt) {
+ case OPT_KEYSYM:
+ keysym_mode = true;
+ break;
case OPT_RULES:
rules = optarg;
break;
@@ -113,18 +120,26 @@ main(int argc, char *argv[])
exit(EXIT_INVALID_USAGE);
}
- errno = 0;
- val = strtol(argv[optind], &endp, 0);
- if (errno != 0 || endp == argv[optind] || val < 0 || val > 0x10FFFF) {
- usage(argv[0], stderr);
- exit(EXIT_INVALID_USAGE);
- }
- codepoint = (uint32_t) val;
+ if (keysym_mode) {
+ keysym = xkb_keysym_from_name(argv[optind], XKB_KEYSYM_NO_FLAGS);
+ if (keysym == XKB_KEY_NoSymbol) {
+ fprintf(stderr, "Failed to convert argument to keysym\n");
+ goto err;
+ }
+ } else {
+ errno = 0;
+ val = strtol(argv[optind], &endp, 0);
+ if (errno != 0 || endp == argv[optind] || val < 0 || val > 0x10FFFF) {
+ usage(argv[0], stderr);
+ exit(EXIT_INVALID_USAGE);
+ }
+ codepoint = (uint32_t) val;
- keysym = xkb_utf32_to_keysym(codepoint);
- if (keysym == XKB_KEY_NoSymbol) {
- fprintf(stderr, "Failed to convert codepoint to keysym\n");
- goto err;
+ keysym = xkb_utf32_to_keysym(codepoint);
+ if (keysym == XKB_KEY_NoSymbol) {
+ fprintf(stderr, "Failed to convert codepoint to keysym\n");
+ goto err;
+ }
}
ret = xkb_keysym_get_name(keysym, name, sizeof(name));
diff --git a/tools/xkbcli-how-to-type.1 b/tools/xkbcli-how-to-type.1
index 5211d0f..d5002ae 100644
--- a/tools/xkbcli-how-to-type.1
+++ b/tools/xkbcli-how-to-type.1
@@ -9,7 +9,7 @@
.Sh SYNOPSIS
.Nm
.Op options
-.Ar codepoint
+.Ar codepoint/keysym
.
.Sh DESCRIPTION
.Nm
@@ -17,6 +17,9 @@ prints the key combinations (keycode + modifiers) in the keymap's layouts which
would produce the given Unicode codepoint.
.
.Bl -tag -width Ds
+.It Fl \-keysym
+Treat the argument as a keysym, not a Unicode codepoint
+.
.It Fl \-rules Ar rules
The XKB ruleset
.