tools: switch interactive-evdev to getopt_long Requiring long options for this tool means it's immediately obvious what an invocation does, compare e.g. xkbcli interactive-evdev -gcd to the equivalent: xkbcli interactive-evdev --consumed-mode=gtk --enalbe-compose --report-state-changes This drops the evdev offset argument - that offset should never be anything other than 8, having this as argument here is more likely to confuse or produce misleading debugging logs. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
diff --git a/meson.build b/meson.build
index 8de5928..fac5c6b 100644
--- a/meson.build
+++ b/meson.build
@@ -564,15 +564,15 @@ if build_tools
install_dir: dir_libexec)
man_pages += 'tools/xkbcli-how-to-type.1.ronn'
configh_data.set10('HAVE_XKBCLI_HOW_TO_TYPE', true)
- endif
- if cc.has_header('linux/input.h')
- executable('xkbcli-interactive-evdev',
- 'tools/interactive-evdev.c',
- dependencies: tools_dep,
- install: true,
- install_dir: dir_libexec)
- configh_data.set10('HAVE_XKBCLI_INTERACTIVE_EVDEV', true)
- man_pages += 'tools/xkbcli-interactive-evdev.1.ronn'
+ if cc.has_header('linux/input.h')
+ executable('xkbcli-interactive-evdev',
+ 'tools/interactive-evdev.c',
+ dependencies: tools_dep,
+ install: true,
+ install_dir: dir_libexec)
+ configh_data.set10('HAVE_XKBCLI_INTERACTIVE_EVDEV', true)
+ man_pages += 'tools/xkbcli-interactive-evdev.1.ronn'
+ endif
endif
if get_option('enable-x11')
x11_tools_dep = declare_dependency(
diff --git a/tools/interactive-evdev.c b/tools/interactive-evdev.c
index a49b932..0868b4f 100644
--- a/tools/interactive-evdev.c
+++ b/tools/interactive-evdev.c
@@ -28,6 +28,7 @@
#include <errno.h>
#include <fcntl.h>
#include <fnmatch.h>
+#include <getopt.h>
#include <limits.h>
#include <locale.h>
#include <signal.h>
@@ -368,11 +369,24 @@ sigintr_handler(int signum)
terminate = true;
}
+static void
+usage(FILE *fp, char *progname)
+{
+ fprintf(fp, "Usage: %s [--rules <rules>] [--model <model>] "
+ "[--layout <layout>] [--variant <variant>] [--options <options>]\n",
+ progname);
+ fprintf(fp, " or: %s --keymap <path to keymap file>\n",
+ progname);
+ fprintf(fp, "For both:\n"
+ " --report-state-changes (report changes to the state)\n"
+ " --enable-compose (enable compose)\n"
+ " --consumed-mode={gtk|xkb} (select the consumed mode)\n");
+}
+
int
main(int argc, char *argv[])
{
int ret = EXIT_FAILURE;
- int opt;
struct keyboard *kbds;
struct xkb_context *ctx = NULL;
struct xkb_keymap *keymap = NULL;
@@ -385,57 +399,82 @@ main(int argc, char *argv[])
const char *keymap_path = NULL;
const char *locale;
struct sigaction act;
+ enum options {
+ OPT_RULES,
+ OPT_MODEL,
+ OPT_LAYOUT,
+ OPT_VARIANT,
+ OPT_OPTION,
+ OPT_KEYMAP,
+ OPT_CONSUMED_MODE,
+ OPT_COMPOSE,
+ OPT_REPORT_STATE,
+ };
+ static struct option opts[] = {
+ {"help", no_argument, 0, 'h'},
+ {"rules", required_argument, 0, OPT_RULES},
+ {"model", required_argument, 0, OPT_MODEL},
+ {"layout", required_argument, 0, OPT_LAYOUT},
+ {"variant", required_argument, 0, OPT_VARIANT},
+ {"options", required_argument, 0, OPT_OPTION},
+ {"keymap", required_argument, 0, OPT_KEYMAP},
+ {"consumed-mode", required_argument, 0, OPT_CONSUMED_MODE},
+ {"enable-compose", no_argument, 0, OPT_COMPOSE},
+ {"report-state-changes", no_argument, 0, OPT_REPORT_STATE},
+ {0, 0, 0, 0},
+ };
setlocale(LC_ALL, "");
- while ((opt = getopt(argc, argv, "r:m:l:v:o:k:n:cdg")) != -1) {
+ while (1) {
+ int opt;
+ int option_index = 0;
+
+ opt = getopt_long(argc, argv, "h", opts, &option_index);
+ if (opt == -1)
+ break;
+
switch (opt) {
- case 'r':
+ case OPT_RULES:
rules = optarg;
break;
- case 'm':
+ case OPT_MODEL:
model = optarg;
break;
- case 'l':
+ case OPT_LAYOUT:
layout = optarg;
break;
- case 'v':
+ case OPT_VARIANT:
variant = optarg;
break;
- case 'o':
+ case OPT_OPTION:
options = optarg;
break;
- case 'k':
+ case OPT_KEYMAP:
keymap_path = optarg;
break;
- case 'n':
- errno = 0;
- evdev_offset = strtol(optarg, NULL, 10);
- if (errno) {
- fprintf(stderr, "error: -n option expects a number\n");
- exit(EXIT_INVALID_USAGE);
- }
- break;
- case 'c':
+ case OPT_REPORT_STATE:
report_state_changes = true;
break;
- case 'd':
+ case OPT_COMPOSE:
with_compose = true;
break;
- case 'g':
- consumed_mode = XKB_CONSUMED_MODE_GTK;
+ case OPT_CONSUMED_MODE:
+ if (strcmp(optarg, "gtk") == 0) {
+ consumed_mode = XKB_CONSUMED_MODE_GTK;
+ } else if (strcmp(optarg, "xkb") == 0) {
+ consumed_mode = XKB_CONSUMED_MODE_XKB;
+ } else {
+ usage(stderr, argv[0]);
+ return EXIT_INVALID_USAGE;
+ }
break;
+ case 'h':
+ usage(stdout, argv[0]);
+ return EXIT_SUCCESS;
case '?':
- fprintf(stderr, " Usage: %s [-r <rules>] [-m <model>] "
- "[-l <layout>] [-v <variant>] [-o <options>]\n",
- argv[0]);
- fprintf(stderr, " or: %s -k <path to keymap file>\n",
- argv[0]);
- fprintf(stderr, "For both: -n <evdev keycode offset>\n"
- " -c (to report changes to the state)\n"
- " -d (to enable compose)\n"
- " -g (to use GTK consumed mode)\n");
- exit(EXIT_INVALID_USAGE);
+ usage(stderr, argv[0]);
+ return EXIT_INVALID_USAGE;
}
}
diff --git a/tools/xkbcli-interactive-evdev.1.ronn b/tools/xkbcli-interactive-evdev.1.ronn
index b3d98f4..6b81837 100644
--- a/tools/xkbcli-interactive-evdev.1.ronn
+++ b/tools/xkbcli-interactive-evdev.1.ronn
@@ -17,36 +17,33 @@ stable.
* `--help`:
Print help and exit
- * `-r`:
- Specify the XKB ruleset
+ * `--rules <rules>`:
+ The XKB ruleset
- * `-m`:
- Specify the XKB model
+ * `--model <model>`:
+ The XKB model
- * `-l`:
- Specify the XKB layout
+ * `--layout <layout>`:
+ The XKB layout
- * `-v`:
- Specify the XKB variant
+ * `--variant <variant>`:
+ The XKB layout variant
- * `-o`:
- Specify the XKB options
+ * `--options <options>`:
+ The XKB options
- * `-k`:
+ * `--keymap`:
Specify a keymap path. This option is mutually exclusive with the rmlvo
options.
- * `-n`:
- Specify an evdev keycode offset.
-
- * `-c`:
+ * `--report-state-changes`:
Report changes to the keyboard state
- * `-d`:
+ * `--enable-compose`:
Enable compose functionality
- * `-g`:
- Use GTK consumed mode
+ * `--consumed-mode={gtk|xkb}`:
+ Set the consumed modifiers mode (default: xkb)
## SEE ALSO