Display can be cluttered when too many fields are displayed.
Add options to hide some default fields
static bool report_state_changes;
static bool with_compose;
static enum xkb_consumed_mode consumed_mode = XKB_CONSUMED_MODE_XKB;
+#define DEFAULT_PRINT_FIELDS PRINT_ALL_FIELDS
+print_state_fields_mask_t print_fields = DEFAULT_PRINT_FIELDS;
#define DEFAULT_INCLUDE_PATH_PLACEHOLDER "__defaults__"
#define NLONGS(n) (((n) + LONG_BIT - 1) / LONG_BIT)
xkb_compose_state_feed(kbd->compose_state, keysym);
}
- if (value != KEY_STATE_RELEASE)
- tools_print_keycode_state(kbd->state, kbd->compose_state, keycode,
- consumed_mode);
+ if (value != KEY_STATE_RELEASE) {
+ tools_print_keycode_state(
+ kbd->state, kbd->compose_state, keycode,
+ consumed_mode, print_fields
+ );
+ }
if (with_compose) {
status = xkb_compose_state_get_status(kbd->compose_state);
fprintf(fp, " or: %s --keymap <path to keymap file>\n",
progname);
fprintf(fp, "For both:\n"
+ " --short (do not print layout nor Unicode keysym translation)\n"
" --report-state-changes (report changes to the state)\n"
" --enable-compose (enable Compose)\n"
" --consumed-mode={xkb|gtk} (select the consumed modifiers mode, default: xkb)\n"
OPT_WITHOUT_X11_OFFSET,
OPT_CONSUMED_MODE,
OPT_COMPOSE,
+ OPT_SHORT,
OPT_REPORT_STATE,
};
static struct option opts[] = {
{"keymap", required_argument, 0, OPT_KEYMAP},
{"consumed-mode", required_argument, 0, OPT_CONSUMED_MODE},
{"enable-compose", no_argument, 0, OPT_COMPOSE},
+ {"short", no_argument, 0, OPT_SHORT},
{"report-state-changes", no_argument, 0, OPT_REPORT_STATE},
{"without-x11-offset", no_argument, 0, OPT_WITHOUT_X11_OFFSET},
{0, 0, 0, 0},
case OPT_COMPOSE:
with_compose = true;
break;
+ case OPT_SHORT:
+ print_fields &= ~PRINT_VERBOSE_FIELDS;
+ break;
case OPT_CONSUMED_MODE:
if (strcmp(optarg, "gtk") == 0) {
consumed_mode = XKB_CONSUMED_MODE_GTK;
printf("%s: ", seat->name_str);
tools_print_keycode_state(seat->state, NULL, key + EVDEV_OFFSET,
- XKB_CONSUMED_MODE_XKB);
+ XKB_CONSUMED_MODE_XKB,
+ PRINT_ALL_FIELDS);
/* Exit on ESC. */
if (xkb_state_key_get_one_sym(seat->state, key + EVDEV_OFFSET) == XKB_KEY_Escape)
xkb_keycode_t keycode = event->detail;
tools_print_keycode_state(kbd->state, NULL, keycode,
- XKB_CONSUMED_MODE_XKB);
+ XKB_CONSUMED_MODE_XKB,
+ PRINT_ALL_FIELDS);
/* Exit on ESC. */
if (xkb_state_key_get_one_sym(kbd->state, keycode) == XKB_KEY_Escape)
tools_print_keycode_state(struct xkb_state *state,
struct xkb_compose_state *compose_state,
xkb_keycode_t keycode,
- enum xkb_consumed_mode consumed_mode)
+ enum xkb_consumed_mode consumed_mode,
+ print_state_fields_mask_t fields)
{
struct xkb_keymap *keymap;
}
printf("] ");
- if (status == XKB_COMPOSE_COMPOSED)
- xkb_compose_state_get_utf8(compose_state, s, sizeof(s));
- else
- xkb_state_key_get_utf8(state, keycode, s, sizeof(s));
- /* HACK: escape single control characters from C0 set using the
- * Unicode codepoint convention. Ideally we would like to escape
- * any non-printable character in the string.
- */
- if (!*s) {
- printf("unicode [ ] ");
- } else if (strlen(s) == 1 && (*s <= 0x1F || *s == 0x7F)) {
- printf("unicode [ U+%04hX ] ", *s);
- } else {
- printf("unicode [ %s ] ", s);
+ if (fields & PRINT_UNICODE) {
+ if (status == XKB_COMPOSE_COMPOSED)
+ xkb_compose_state_get_utf8(compose_state, s, sizeof(s));
+ else
+ xkb_state_key_get_utf8(state, keycode, s, sizeof(s));
+ /* HACK: escape single control characters from C0 set using the
+ * Unicode codepoint convention. Ideally we would like to escape
+ * any non-printable character in the string.
+ */
+ if (!*s) {
+ printf("unicode [ ] ");
+ } else if (strlen(s) == 1 && (*s <= 0x1F || *s == 0x7F)) {
+ printf("unicode [ U+%04hX ] ", *s);
+ } else {
+ printf("unicode [ %s ] ", s);
+ }
}
layout = xkb_state_key_get_layout(state, keycode);
- printf("layout [ %s (%d) ] ",
- xkb_keymap_layout_get_name(keymap, layout), layout);
+ if (fields & PRINT_LAYOUT) {
+ printf("layout [ %s (%d) ] ",
+ xkb_keymap_layout_get_name(keymap, layout), layout);
+ }
printf("level [ %d ] ",
xkb_state_key_get_level(state, keycode, layout));
#define ARRAY_SIZE(arr) ((sizeof(arr) / sizeof(*(arr))))
+/* Fields that are printed in the interactive tools. */
+enum print_state_fields {
+ PRINT_LAYOUT = (1u << 2),
+ PRINT_UNICODE = (1u << 3),
+ PRINT_ALL_FIELDS = ((PRINT_UNICODE << 1) - 1),
+ /*
+ * Fields that can be hidden with the option --short.
+ * NOTE: If this value is modified, remember to update the documentation of
+ * the --short option in the corresponding tools.
+ */
+ PRINT_VERBOSE_FIELDS = (PRINT_LAYOUT | PRINT_UNICODE)
+};
+typedef uint32_t print_state_fields_mask_t;
+
void
tools_print_keycode_state(struct xkb_state *state,
struct xkb_compose_state *compose_state,
xkb_keycode_t keycode,
- enum xkb_consumed_mode consumed_mode);
+ enum xkb_consumed_mode consumed_mode,
+ print_state_fields_mask_t fields);
void
tools_print_state_changes(enum xkb_state_component changed);