Skip to content

Commit

Permalink
Guard deprecated keysym test with verbositoty level
Browse files Browse the repository at this point in the history
  • Loading branch information
wismill committed Sep 22, 2023
1 parent 2f5931a commit bbc24aa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
2 changes: 2 additions & 0 deletions src/keysym.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ enum xkb_keysym_format {
XKB_KEYSYM_FORMAT_NUMERIC
};

#define XKB_MIN_VERBOSITY_DEPRECATED_KEYSYM 10

typedef uint8_t xkb_keysym_format_t;

xkb_keysym_t
Expand Down
30 changes: 17 additions & 13 deletions src/xkbcomp/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,15 +654,17 @@ ExprResolveKeySym(struct xkb_context *ctx, const ExprDef *expr,
xkb_keysym_format_t keysym_format;
*sym_rtrn = xkb_keysym_with_format_from_name(str, 0, &keysym_format);
if (*sym_rtrn != XKB_KEY_NoSymbol) {
const char *ref_name = NULL;
if (xkb_keysym_is_deprecated(*sym_rtrn, keysym_format, str, &ref_name)) {
if (ref_name == NULL) {
log_warn_with_code(ctx, XKB_WARNING_DEPRECATED_KEYSYM,
"deprecated keysym \"%s\"\n", str);
} else {
log_warn_with_code(ctx, XKB_WARNING_DEPRECATED_KEYSYM,
"deprecated keysym \"%s\"; please use \"%s\"\n",
str, ref_name);
if (unlikely(ctx->log_verbosity >= XKB_MIN_VERBOSITY_DEPRECATED_KEYSYM)) {
const char *ref_name = NULL;
if (xkb_keysym_is_deprecated(*sym_rtrn, keysym_format, str, &ref_name)) {
if (ref_name == NULL) {
log_warn_with_code(ctx, XKB_WARNING_DEPRECATED_KEYSYM,
"deprecated keysym \"%s\"\n", str);
} else {
log_warn_with_code(ctx, XKB_WARNING_DEPRECATED_KEYSYM,
"deprecated keysym \"%s\"; please use \"%s\"\n",
str, ref_name);
}
}
}
return true;
Expand All @@ -686,10 +688,12 @@ ExprResolveKeySym(struct xkb_context *ctx, const ExprDef *expr,
}

if (val <= XKB_KEYSYM_MAX) {
const char *ref_name = NULL;
if (xkb_keysym_is_deprecated(val, XKB_KEYSYM_FORMAT_NUMERIC, NULL, &ref_name)) {
log_warn_with_code(ctx, XKB_WARNING_DEPRECATED_KEYSYM,
"deprecated keysym \"0x%x\" (%d)\n", val, val);
if (unlikely(ctx->log_verbosity >= XKB_MIN_VERBOSITY_DEPRECATED_KEYSYM)) {
const char *ref_name = NULL;
if (xkb_keysym_is_deprecated(val, XKB_KEYSYM_FORMAT_NUMERIC, NULL, &ref_name)) {
log_warn_with_code(ctx, XKB_WARNING_DEPRECATED_KEYSYM,
"deprecated keysym \"0x%x\" (%d)\n", val, val);
}
}
log_warn_with_code(ctx, XKB_WARNING_NUMERIC_KEYSYM,
"numeric keysym \"0x%x\" (%d)",
Expand Down
24 changes: 15 additions & 9 deletions src/xkbcomp/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,17 @@ resolve_keysym(struct parser_param *param, const char *name, xkb_keysym_t *sym_r
sym = xkb_keysym_with_format_from_name(name, XKB_KEYSYM_NO_FLAGS, &keysym_format);
if (sym != XKB_KEY_NoSymbol) {
*sym_rtrn = sym;
const char *ref_name = NULL;
if (xkb_keysym_is_deprecated(sym, keysym_format, name, &ref_name)) {
if (ref_name == NULL) {
parser_warn(param, XKB_WARNING_DEPRECATED_KEYSYM,
"deprecated keysym \"%s\"", name);
} else {
parser_warn(param, XKB_WARNING_DEPRECATED_KEYSYM,
"deprecated keysym \"%s\"; please use \"%s\"",
name, ref_name);
if (unlikely(param->ctx->log_verbosity >= XKB_MIN_VERBOSITY_DEPRECATED_KEYSYM)) {
const char *ref_name = NULL;
if (xkb_keysym_is_deprecated(sym, keysym_format, name, &ref_name)) {
if (ref_name == NULL) {
parser_warn(param, XKB_WARNING_DEPRECATED_KEYSYM,
"deprecated keysym \"%s\"", name);
} else {
parser_warn(param, XKB_WARNING_DEPRECATED_KEYSYM,
"deprecated keysym \"%s\"; please use \"%s\"",
name, ref_name);
}
}
}
return true;
Expand Down Expand Up @@ -769,6 +771,9 @@ KeySym : IDENT
else {
if ($1 <= XKB_KEYSYM_MAX) {
$$ = (xkb_keysym_t) $1;

if (unlikely(param->ctx->log_verbosity >= XKB_MIN_VERBOSITY_DEPRECATED_KEYSYM)) {

// [FIXME] ref_name is never used: change API to allow NULL??
const char *ref_name = NULL;
if (xkb_keysym_is_deprecated($$, XKB_KEYSYM_FORMAT_NUMERIC, NULL, &ref_name)) {
Expand All @@ -782,6 +787,7 @@ KeySym : IDENT
$1, ref_name);
}
}
}
} else {
parser_warn(
param, XKB_WARNING_UNRECOGNIZED_KEYSYM,
Expand Down

0 comments on commit bbc24aa

Please sign in to comment.