Skip to content

Commit

Permalink
Improve xkb_keysym_is_deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
wismill committed Sep 22, 2023
1 parent bbc24aa commit d90814d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
29 changes: 11 additions & 18 deletions src/keysym.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,13 @@ xkb_keysym_from_name(const char *name, enum xkb_keysym_flags flags)

/*
* Check whether a keysym with code "keysym" and name "name" is deprecated.
* If so, and if there is a non-deprecated name for the given keysym, then write
* it in "reference_name", else write NULL.
* If "name" is NULL, then just check if there is some non-deprecated name for
* "keysym".
* • If the keysym is not deprecated itself and has no deprecated names,
* then return false and write NULL in "reference_name".
* • If there is a non-deprecated name for the given keysym, then write this
* name in "reference_name", else write NULL and return true.
* • If "name" is NULL, then returns false: the keysym itself is not deprecated.
* • If "name" is not NULL, then returns whether "name" and "reference_name"
* are different.
*
* WARNING: this function is unsafe because it does not test if "name" is
* actually a correct name for "keysym". It is intended to be used just after
Expand Down Expand Up @@ -292,20 +295,10 @@ xkb_keysym_is_deprecated(xkb_keysym_t keysym,
return true;
} else {
/* There is a reference name that is not deprecated */
if (keysym_format != XKB_KEYSYM_FORMAT_NAME || name == NULL) {
/* No name given: just indicate not deprecated */
*reference_name = NULL;
return false;
} else {
/* Check if the given name is the reference one */
*reference_name = get_name(&deprecated_keysyms[mid]);
if (strcmp(name, *reference_name) == 0) {
*reference_name = NULL;
return false;
} else {
return true;
}
}
*reference_name = get_name(&deprecated_keysyms[mid]);
/* If there is no name given: just indicate not deprecated;
* else check if the given name is the reference one */
return (name != NULL && strcmp(name, *reference_name) != 0);
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/xkbcomp/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -774,14 +774,12 @@ KeySym : IDENT

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)) {
if (ref_name == NULL) {
parser_warn(param, XKB_WARNING_DEPRECATED_KEYSYM,
"deprecated keysym \"0x%"PRIx64"\"", $1);
} else {
// [FIXME] currently dead code
parser_warn(param, XKB_WARNING_DEPRECATED_KEYSYM,
"deprecated keysym \"0x%"PRIx64"\"; please use \"%s\"",
$1, ref_name);
Expand Down

0 comments on commit d90814d

Please sign in to comment.