From b9964b5e90ddb790b9ca50b1f2a637d1d67ab296 Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Tue, 8 Jul 2025 09:58:39 -0400 Subject: [PATCH] refactor: remove anon enum in IKeyState and replace with static s_numButtons --- src/lib/deskflow/IKeyState.h | 6 +----- src/lib/deskflow/KeyState.cpp | 4 ++-- src/lib/deskflow/KeyState.h | 8 ++++---- src/lib/platform/MSWindowsScreen.cpp | 8 ++++---- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/lib/deskflow/IKeyState.h b/src/lib/deskflow/IKeyState.h index 6c3f3795f..71720eab6 100644 --- a/src/lib/deskflow/IKeyState.h +++ b/src/lib/deskflow/IKeyState.h @@ -24,11 +24,7 @@ class IKeyState : public IInterface { public: explicit IKeyState(const IEventQueue *events); - - enum - { - kNumButtons = 0x200 - }; + inline static const auto s_numButtons = 0x200; //! Key event data class KeyInfo diff --git a/src/lib/deskflow/KeyState.cpp b/src/lib/deskflow/KeyState.cpp index 4f1c859e9..f510af01e 100644 --- a/src/lib/deskflow/KeyState.cpp +++ b/src/lib/deskflow/KeyState.cpp @@ -15,7 +15,7 @@ #include #include -static const KeyButton kButtonMask = (KeyButton)(IKeyState::kNumButtons - 1); +static const KeyButton kButtonMask = (KeyButton)(IKeyState::s_numButtons - 1); static const KeyID s_decomposeTable[] = { // spacing version of dead keys @@ -943,7 +943,7 @@ bool KeyState::fakeKeyUp(KeyButton serverID) void KeyState::fakeAllKeysUp() { Keystrokes keys; - for (KeyButton i = 0; i < IKeyState::kNumButtons; ++i) { + for (KeyButton i = 0; i < IKeyState::s_numButtons; ++i) { if (m_syntheticKeys[i] > 0) { keys.push_back(Keystroke(i, false, false, m_keyClientData[i])); m_keys[i] = 0; diff --git a/src/lib/deskflow/KeyState.h b/src/lib/deskflow/KeyState.h index 67f159c86..9aed6aca5 100644 --- a/src/lib/deskflow/KeyState.h +++ b/src/lib/deskflow/KeyState.h @@ -204,20 +204,20 @@ private: // current keyboard state (> 0 if pressed, 0 otherwise). this is // initialized to the keyboard state according to the system then // it tracks synthesized events. - int32_t m_keys[kNumButtons]; + int32_t m_keys[s_numButtons]; // synthetic keyboard state (> 0 if pressed, 0 otherwise). this // tracks the synthesized keyboard state. if m_keys[n] > 0 but // m_syntheticKeys[n] == 0 then the key was pressed locally and // not synthesized yet. - int32_t m_syntheticKeys[kNumButtons]; + int32_t m_syntheticKeys[s_numButtons]; // client data for each pressed key - uint32_t m_keyClientData[kNumButtons]; + uint32_t m_keyClientData[s_numButtons]; // server keyboard state. an entry is 0 if not the key isn't pressed // otherwise it's the local KeyButton synthesized for the server key. - KeyButton m_serverKeys[kNumButtons]; + KeyButton m_serverKeys[s_numButtons]; IEventQueue *m_events; diff --git a/src/lib/platform/MSWindowsScreen.cpp b/src/lib/platform/MSWindowsScreen.cpp index 047a3c515..3edd455d9 100644 --- a/src/lib/platform/MSWindowsScreen.cpp +++ b/src/lib/platform/MSWindowsScreen.cpp @@ -302,7 +302,7 @@ void MSWindowsScreen::leave() m_hook.setMode(kHOOK_RELAY_EVENTS); m_primaryKeyDownList.clear(); - for (KeyButton i = 0; i < IKeyState::kNumButtons; ++i) { + for (KeyButton i = 0; i < IKeyState::s_numButtons; ++i) { if (m_keyState->isKeyDown(i)) { m_primaryKeyDownList.push_back(i); LOG((CLOG_DEBUG1 "key button %d is down before leaving to another screen", i)); @@ -1549,10 +1549,10 @@ bool MSWindowsScreen::mapPressFromEvent(WPARAM msg, LPARAM) const void MSWindowsScreen::updateKeysCB(void *) { // record which keys we think are down - bool down[IKeyState::kNumButtons]; + bool down[IKeyState::s_numButtons]; bool sendFixes = (isPrimary() && !m_isOnScreen); if (sendFixes) { - for (KeyButton i = 0; i < IKeyState::kNumButtons; ++i) { + for (KeyButton i = 0; i < IKeyState::s_numButtons; ++i) { down[i] = m_keyState->isKeyDown(i); } } @@ -1569,7 +1569,7 @@ void MSWindowsScreen::updateKeysCB(void *) // send key releases for these keys to the active client. if (sendFixes) { KeyModifierMask mask = pollActiveModifiers(); - for (KeyButton i = 0; i < IKeyState::kNumButtons; ++i) { + for (KeyButton i = 0; i < IKeyState::s_numButtons; ++i) { if (down[i] && !m_keyState->isKeyDown(i)) { m_keyState->sendKeyEvent(getEventTarget(), false, false, kKeyNone, mask, 1, i); }