Event System: improve handling of unknown keys

When converting ghost keys to Blender's event system:

- All keys that aren't part of the GHOST_TKey enum map to EVENT_NONE
  (ignored), note that it's an internal error if the value of key isn't
  a known value.

- Modify the switch statement so any missing members of GHOST_TKey
  warn at compile time (GCC & Clang only).

- GHOST_kKeyUnknown maps to EVT_UNKNOWNKEY.
  We could ignore this key, changing can be evaluated separately.
This commit is contained in:
Campbell Barton 2022-03-23 21:30:36 +11:00
parent 8f63dccaa9
commit f634010c6e
1 changed files with 20 additions and 1 deletions

View File

@ -4565,9 +4565,28 @@ static int convert_key(GHOST_TKey key)
case GHOST_kKeyMediaLast:
return EVT_MEDIALAST;
default:
case GHOST_kKeyUnknown:
return EVT_UNKNOWNKEY;
#if defined(__GNUC__) || defined(__clang__)
/* Ensure all members of this enum are handled, otherwise generate a compiler warning.
* Note that these members have been handled, these ranges are to satisfy the compiler. */
case GHOST_kKeyF1 ... GHOST_kKeyF24:
case GHOST_kKeyA ... GHOST_kKeyZ:
case GHOST_kKeyNumpad0 ... GHOST_kKeyNumpad9:
case GHOST_kKey0 ... GHOST_kKey9: {
BLI_assert_unreachable();
break;
}
#else
default: {
break;
}
#endif
}
CLOG_WARN(WM_LOG_EVENTS, "unknown event type %d from ghost", (int)key);
return EVENT_NONE;
}
static void wm_eventemulation(wmEvent *event, bool test_only)