From 98246e21ebf86db15cc848644bcd3e2827c5a2ca Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 21 Jan 2025 09:28:03 -0500 Subject: Add PUGL_KEY_NONE This isn't a strict enumeration anyway, so a sentinel value does no harm, and using it avoids warnings about testing an enum with no zero value. --- include/pugl/pugl.h | 1 + src/.clang-tidy | 1 - src/mac.m | 4 ++-- src/win.c | 6 +++--- src/x11.c | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/pugl/pugl.h b/include/pugl/pugl.h index ac5f51c..79d3969 100644 --- a/include/pugl/pugl.h +++ b/include/pugl/pugl.h @@ -341,6 +341,7 @@ typedef struct { mapping used here is arbitrary and specific to Pugl. */ typedef enum { + PUGL_KEY_NONE = 0U, ///< Sentinel value for no key PUGL_KEY_BACKSPACE = 0x00000008U, ///< Backspace PUGL_KEY_TAB = 0x00000009U, ///< Tab PUGL_KEY_ENTER = 0x0000000DU, ///< Enter diff --git a/src/.clang-tidy b/src/.clang-tidy index 6d51f06..cfc824d 100644 --- a/src/.clang-tidy +++ b/src/.clang-tidy @@ -4,7 +4,6 @@ Checks: > -bugprone-easily-swappable-parameters, -bugprone-multi-level-implicit-pointer-conversion, - -clang-analyzer-optin.core.EnumCastOutOfRange, -hicpp-multiway-paths-covered, -hicpp-signed-bitwise, -llvm-header-guard, diff --git a/src/mac.m b/src/mac.m index 727f142..dd1d1e8 100644 --- a/src/mac.m +++ b/src/mac.m @@ -463,7 +463,7 @@ keySymToSpecial(const NSEvent* const ev) return PUGL_KEY_PAD_9; } - return (PuglKey)0; + return PUGL_KEY_NONE; } - (void)updateTrackingAreas @@ -856,7 +856,7 @@ flagDiffers(const uint32_t lhs, const uint32_t rhs, const uint32_t mask) - (void)flagsChanged:(NSEvent*)event { const uint32_t mods = getModifiers(event); - PuglKey special = (PuglKey)0; + PuglKey special = PUGL_KEY_NONE; const uint16_t keyCode = [event keyCode]; if (flagDiffers(mods, puglview->impl->mods, PUGL_MOD_SHIFT)) { diff --git a/src/win.c b/src/win.c index cae1a20..54981f7 100644 --- a/src/win.c +++ b/src/win.c @@ -424,13 +424,13 @@ keyInRange(const WPARAM winSym, { return (winSym >= winMin && winSym <= winMax) ? (PuglKey)((WPARAM)puglMin + (winSym - winMin)) - : (PuglKey)0; + : PUGL_KEY_NONE; } static PuglKey keySymToSpecial(const WPARAM sym, const bool ext) { - PuglKey key = (PuglKey)0; + PuglKey key = PUGL_KEY_NONE; if ((key = keyInRange(sym, VK_F1, VK_F12, PUGL_KEY_F1)) || (key = keyInRange(sym, VK_PRIOR, @@ -479,7 +479,7 @@ keySymToSpecial(const WPARAM sym, const bool ext) // clang-format on } - return (PuglKey)0; + return PUGL_KEY_NONE; } static bool diff --git a/src/x11.c b/src/x11.c index f09e8e5..1d3b7f0 100644 --- a/src/x11.c +++ b/src/x11.c @@ -814,13 +814,13 @@ keyInRange(const KeySym xSym, const PuglKey puglMin) { return (xSym >= xMin && xSym <= xMax) ? (PuglKey)(puglMin + (xSym - xMin)) - : (PuglKey)0; + : PUGL_KEY_NONE; } static PuglKey keySymToSpecial(const KeySym sym) { - PuglKey key = (PuglKey)0; + PuglKey key = PUGL_KEY_NONE; if ((key = keyInRange(sym, XK_F1, XK_F12, PUGL_KEY_F1)) || (key = keyInRange(sym, XK_Page_Up, XK_End, PUGL_KEY_PAGE_UP)) || (key = keyInRange(sym, XK_Home, XK_Down, PUGL_KEY_HOME)) || @@ -853,7 +853,7 @@ keySymToSpecial(const KeySym sym) } // clang-format on - return (PuglKey)0; + return PUGL_KEY_NONE; } static int -- cgit v1.2.1