From b0ddcbba56b8fc6f1576553c805b5dc7185773e4 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 22 Jul 2019 09:18:54 +0200 Subject: Simplify modifier translation code --- pugl/pugl_osx.m | 14 ++++++-------- pugl/pugl_win.c | 12 +++++------- pugl/pugl_x11.c | 12 +++++------- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/pugl/pugl_osx.m b/pugl/pugl_osx.m index 5febeb7..45d0fb1 100644 --- a/pugl/pugl_osx.m +++ b/pugl/pugl_osx.m @@ -213,14 +213,12 @@ struct PuglInternalsImpl { static uint32_t getModifiers(PuglView* view, NSEvent* ev) { - const unsigned modifierFlags = [ev modifierFlags]; - - uint32_t mods = 0; - mods |= (modifierFlags & NSShiftKeyMask) ? PUGL_MOD_SHIFT : 0; - mods |= (modifierFlags & NSControlKeyMask) ? PUGL_MOD_CTRL : 0; - mods |= (modifierFlags & NSAlternateKeyMask) ? PUGL_MOD_ALT : 0; - mods |= (modifierFlags & NSCommandKeyMask) ? PUGL_MOD_SUPER : 0; - return mods; + const NSEventModifierFlags modifierFlags = [ev modifierFlags]; + + return (((modifierFlags & NSShiftKeyMask) ? PUGL_MOD_SHIFT : 0) | + ((modifierFlags & NSControlKeyMask) ? PUGL_MOD_CTRL : 0) | + ((modifierFlags & NSAlternateKeyMask) ? PUGL_MOD_ALT : 0) | + ((modifierFlags & NSCommandKeyMask) ? PUGL_MOD_SUPER : 0)); } static PuglKey diff --git a/pugl/pugl_win.c b/pugl/pugl_win.c index b5afe90..af32210 100644 --- a/pugl/pugl_win.c +++ b/pugl/pugl_win.c @@ -434,13 +434,11 @@ keySymToSpecial(WPARAM sym) static uint32_t getModifiers(void) { - uint32_t mods = 0; - mods |= (GetKeyState(VK_SHIFT) < 0) ? PUGL_MOD_SHIFT : 0; - mods |= (GetKeyState(VK_CONTROL) < 0) ? PUGL_MOD_CTRL : 0; - mods |= (GetKeyState(VK_MENU) < 0) ? PUGL_MOD_ALT : 0; - mods |= (GetKeyState(VK_LWIN) < 0) ? PUGL_MOD_SUPER : 0; - mods |= (GetKeyState(VK_RWIN) < 0) ? PUGL_MOD_SUPER : 0; - return mods; + return (((GetKeyState(VK_SHIFT) < 0) ? PUGL_MOD_SHIFT : 0u) | + ((GetKeyState(VK_CONTROL) < 0) ? PUGL_MOD_CTRL : 0u) | + ((GetKeyState(VK_MENU) < 0) ? PUGL_MOD_ALT : 0u) | + ((GetKeyState(VK_LWIN) < 0) ? PUGL_MOD_SUPER : 0u) | + ((GetKeyState(VK_RWIN) < 0) ? PUGL_MOD_SUPER : 0u)); } static void diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c index 97c3351..bd9de42 100644 --- a/pugl/pugl_x11.c +++ b/pugl/pugl_x11.c @@ -285,14 +285,12 @@ translateKey(PuglView* view, XEvent* xevent, PuglEventKey* event) } static uint32_t -translateModifiers(unsigned xstate) +translateModifiers(const unsigned xstate) { - uint32_t state = 0; - state |= (xstate & ShiftMask) ? PUGL_MOD_SHIFT : 0; - state |= (xstate & ControlMask) ? PUGL_MOD_CTRL : 0; - state |= (xstate & Mod1Mask) ? PUGL_MOD_ALT : 0; - state |= (xstate & Mod4Mask) ? PUGL_MOD_SUPER : 0; - return state; + return (((xstate & ShiftMask) ? PUGL_MOD_SHIFT : 0) | + ((xstate & ControlMask) ? PUGL_MOD_CTRL : 0) | + ((xstate & Mod1Mask) ? PUGL_MOD_ALT : 0) | + ((xstate & Mod4Mask) ? PUGL_MOD_SUPER : 0)); } static PuglEvent -- cgit v1.2.1