summaryrefslogtreecommitdiffstats
path: root/xbmc/input/keyboard
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 18:07:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 18:07:22 +0000
commitc04dcc2e7d834218ef2d4194331e383402495ae1 (patch)
tree7333e38d10d75386e60f336b80c2443c1166031d /xbmc/input/keyboard
parentInitial commit. (diff)
downloadkodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz
kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/input/keyboard')
-rw-r--r--xbmc/input/keyboard/CMakeLists.txt14
-rw-r--r--xbmc/input/keyboard/KeyboardEasterEgg.cpp45
-rw-r--r--xbmc/input/keyboard/KeyboardEasterEgg.h38
-rw-r--r--xbmc/input/keyboard/KeyboardTypes.h40
-rw-r--r--xbmc/input/keyboard/KeymapActionMap.cpp26
-rw-r--r--xbmc/input/keyboard/KeymapActionMap.h28
-rw-r--r--xbmc/input/keyboard/generic/CMakeLists.txt5
-rw-r--r--xbmc/input/keyboard/generic/KeyboardInputHandling.cpp51
-rw-r--r--xbmc/input/keyboard/generic/KeyboardInputHandling.h46
-rw-r--r--xbmc/input/keyboard/interfaces/IActionMap.h36
-rw-r--r--xbmc/input/keyboard/interfaces/IKeyboardDriverHandler.h43
-rw-r--r--xbmc/input/keyboard/interfaces/IKeyboardInputHandler.h69
-rw-r--r--xbmc/input/keyboard/interfaces/IKeyboardInputProvider.h43
13 files changed, 484 insertions, 0 deletions
diff --git a/xbmc/input/keyboard/CMakeLists.txt b/xbmc/input/keyboard/CMakeLists.txt
new file mode 100644
index 0000000..14d48a8
--- /dev/null
+++ b/xbmc/input/keyboard/CMakeLists.txt
@@ -0,0 +1,14 @@
+set(SOURCES KeyboardEasterEgg.cpp
+ KeymapActionMap.cpp
+)
+
+set(HEADERS interfaces/IActionMap.h
+ interfaces/IKeyboardDriverHandler.h
+ interfaces/IKeyboardInputHandler.h
+ interfaces/IKeyboardInputProvider.h
+ KeyboardEasterEgg.h
+ KeyboardTypes.h
+ KeymapActionMap.h
+)
+
+core_add_library(input_keyboard)
diff --git a/xbmc/input/keyboard/KeyboardEasterEgg.cpp b/xbmc/input/keyboard/KeyboardEasterEgg.cpp
new file mode 100644
index 0000000..8b7049d
--- /dev/null
+++ b/xbmc/input/keyboard/KeyboardEasterEgg.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2017-2018 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#include "input/keyboard/KeyboardEasterEgg.h"
+
+#include "input/Key.h"
+#include "input/joysticks/JoystickEasterEgg.h"
+
+using namespace KODI;
+using namespace KEYBOARD;
+
+std::vector<XBMCVKey> CKeyboardEasterEgg::m_sequence = {
+ XBMCVK_UP, XBMCVK_UP, XBMCVK_DOWN, XBMCVK_DOWN, XBMCVK_LEFT,
+ XBMCVK_RIGHT, XBMCVK_LEFT, XBMCVK_RIGHT, XBMCVK_B, XBMCVK_A,
+};
+
+bool CKeyboardEasterEgg::OnKeyPress(const CKey& key)
+{
+ bool bHandled = false;
+
+ // Update state
+ if (key.GetVKey() == m_sequence[m_state])
+ m_state++;
+ else
+ m_state = 0;
+
+ // Capture input when finished with arrows (2 x up/down/left/right)
+ if (m_state > 8)
+ {
+ bHandled = true;
+
+ if (m_state >= m_sequence.size())
+ {
+ JOYSTICK::CJoystickEasterEgg::OnFinish();
+ m_state = 0;
+ }
+ }
+
+ return bHandled;
+}
diff --git a/xbmc/input/keyboard/KeyboardEasterEgg.h b/xbmc/input/keyboard/KeyboardEasterEgg.h
new file mode 100644
index 0000000..00c1791
--- /dev/null
+++ b/xbmc/input/keyboard/KeyboardEasterEgg.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2016-2018 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+#include "input/XBMC_vkeys.h"
+#include "input/keyboard/interfaces/IKeyboardDriverHandler.h"
+
+#include <vector>
+
+namespace KODI
+{
+namespace KEYBOARD
+{
+/*!
+ * \brief Hush!!!
+ */
+class CKeyboardEasterEgg : public IKeyboardDriverHandler
+{
+public:
+ ~CKeyboardEasterEgg() override = default;
+
+ // implementation of IKeyboardDriverHandler
+ bool OnKeyPress(const CKey& key) override;
+ void OnKeyRelease(const CKey& key) override {}
+
+private:
+ static std::vector<XBMCVKey> m_sequence;
+
+ unsigned int m_state = 0;
+};
+} // namespace KEYBOARD
+} // namespace KODI
diff --git a/xbmc/input/keyboard/KeyboardTypes.h b/xbmc/input/keyboard/KeyboardTypes.h
new file mode 100644
index 0000000..5a5d39b
--- /dev/null
+++ b/xbmc/input/keyboard/KeyboardTypes.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2017-2018 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+#include "input/Key.h"
+#include "input/XBMC_keysym.h"
+
+#include <string>
+
+namespace KODI
+{
+namespace KEYBOARD
+{
+/*!
+ * \brief Symbol of a hardware-independent key
+ */
+using KeySymbol = XBMCKey;
+
+/*!
+ * \brief Name of a hardware-indendent symbol representing a key
+ *
+ * Names are defined in the keyboard's controller profile.
+ */
+using KeyName = std::string;
+
+/*!
+ * \brief Modifier keys on a keyboard that can be held when
+ * sending a key press
+ *
+ * \todo Move CKey enum to this file
+ */
+using Modifier = CKey::Modifier;
+} // namespace KEYBOARD
+} // namespace KODI
diff --git a/xbmc/input/keyboard/KeymapActionMap.cpp b/xbmc/input/keyboard/KeymapActionMap.cpp
new file mode 100644
index 0000000..f6e6919
--- /dev/null
+++ b/xbmc/input/keyboard/KeymapActionMap.cpp
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2017-2018 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#include "KeymapActionMap.h"
+
+#include "ServiceBroker.h"
+#include "guilib/GUIComponent.h"
+#include "guilib/GUIWindowManager.h"
+#include "input/InputManager.h"
+#include "input/Key.h"
+#include "input/actions/Action.h"
+
+using namespace KODI;
+using namespace KEYBOARD;
+
+unsigned int CKeymapActionMap::GetActionID(const CKey& key)
+{
+ CAction action = CServiceBroker::GetInputManager().GetAction(
+ CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindowOrDialog(), key);
+ return action.GetID();
+}
diff --git a/xbmc/input/keyboard/KeymapActionMap.h b/xbmc/input/keyboard/KeymapActionMap.h
new file mode 100644
index 0000000..6ee9344
--- /dev/null
+++ b/xbmc/input/keyboard/KeymapActionMap.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2017-2018 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+#include "input/keyboard/interfaces/IActionMap.h"
+
+namespace KODI
+{
+namespace KEYBOARD
+{
+class CKeymapActionMap : public IActionMap
+{
+public:
+ CKeymapActionMap(void) = default;
+
+ ~CKeymapActionMap(void) override = default;
+
+ // implementation of IActionMap
+ unsigned int GetActionID(const CKey& key) override;
+};
+} // namespace KEYBOARD
+} // namespace KODI
diff --git a/xbmc/input/keyboard/generic/CMakeLists.txt b/xbmc/input/keyboard/generic/CMakeLists.txt
new file mode 100644
index 0000000..993a1f4
--- /dev/null
+++ b/xbmc/input/keyboard/generic/CMakeLists.txt
@@ -0,0 +1,5 @@
+set(SOURCES KeyboardInputHandling.cpp)
+
+set(HEADERS KeyboardInputHandling.h)
+
+core_add_library(input_keyboard_generic)
diff --git a/xbmc/input/keyboard/generic/KeyboardInputHandling.cpp b/xbmc/input/keyboard/generic/KeyboardInputHandling.cpp
new file mode 100644
index 0000000..5e84081
--- /dev/null
+++ b/xbmc/input/keyboard/generic/KeyboardInputHandling.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2017-2018 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#include "KeyboardInputHandling.h"
+
+#include "input/XBMC_keysym.h"
+#include "input/joysticks/DriverPrimitive.h"
+#include "input/joysticks/interfaces/IButtonMap.h"
+#include "input/keyboard/interfaces/IKeyboardInputHandler.h"
+
+using namespace KODI;
+using namespace KEYBOARD;
+
+CKeyboardInputHandling::CKeyboardInputHandling(IKeyboardInputHandler* handler,
+ JOYSTICK::IButtonMap* buttonMap)
+ : m_handler(handler), m_buttonMap(buttonMap)
+{
+}
+
+bool CKeyboardInputHandling::OnKeyPress(const CKey& key)
+{
+ bool bHandled = false;
+
+ JOYSTICK::CDriverPrimitive source(static_cast<XBMCKey>(key.GetKeycode()));
+
+ KeyName keyName;
+ if (m_buttonMap->GetFeature(source, keyName))
+ {
+ const Modifier mod = static_cast<Modifier>(key.GetModifiers() | key.GetLockingModifiers());
+ bHandled = m_handler->OnKeyPress(keyName, mod, key.GetUnicode());
+ }
+
+ return bHandled;
+}
+
+void CKeyboardInputHandling::OnKeyRelease(const CKey& key)
+{
+ JOYSTICK::CDriverPrimitive source(static_cast<XBMCKey>(key.GetKeycode()));
+
+ KeyName keyName;
+ if (m_buttonMap->GetFeature(source, keyName))
+ {
+ const Modifier mod = static_cast<Modifier>(key.GetModifiers() | key.GetLockingModifiers());
+ m_handler->OnKeyRelease(keyName, mod, key.GetUnicode());
+ }
+}
diff --git a/xbmc/input/keyboard/generic/KeyboardInputHandling.h b/xbmc/input/keyboard/generic/KeyboardInputHandling.h
new file mode 100644
index 0000000..4cd2d26
--- /dev/null
+++ b/xbmc/input/keyboard/generic/KeyboardInputHandling.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2017-2018 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+#include "input/keyboard/interfaces/IKeyboardDriverHandler.h"
+
+namespace KODI
+{
+namespace JOYSTICK
+{
+class IButtonMap;
+}
+
+namespace KEYBOARD
+{
+class IKeyboardInputHandler;
+
+/*!
+ * \ingroup keyboard
+ * \brief Class to translate input from Kodi keycodes to key names defined
+ * by the keyboard's controller profile
+ */
+class CKeyboardInputHandling : public IKeyboardDriverHandler
+{
+public:
+ CKeyboardInputHandling(IKeyboardInputHandler* handler, JOYSTICK::IButtonMap* buttonMap);
+
+ ~CKeyboardInputHandling(void) override = default;
+
+ // implementation of IKeyboardDriverHandler
+ bool OnKeyPress(const CKey& key) override;
+ void OnKeyRelease(const CKey& key) override;
+
+private:
+ // Construction parameters
+ IKeyboardInputHandler* const m_handler;
+ JOYSTICK::IButtonMap* const m_buttonMap;
+};
+} // namespace KEYBOARD
+} // namespace KODI
diff --git a/xbmc/input/keyboard/interfaces/IActionMap.h b/xbmc/input/keyboard/interfaces/IActionMap.h
new file mode 100644
index 0000000..e77643e
--- /dev/null
+++ b/xbmc/input/keyboard/interfaces/IActionMap.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2017-2018 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+class CKey;
+
+namespace KODI
+{
+namespace KEYBOARD
+{
+/*!
+ * \brief Interface for translating keys to action IDs
+ */
+class IActionMap
+{
+public:
+ virtual ~IActionMap() = default;
+
+ /*!
+ * \brief Get the action ID mapped to the specified key
+ *
+ * \param key The key to look up
+ *
+ * \return The action ID from ActionIDs.h, or ACTION_NONE if no action is
+ * mapped to the specified key
+ */
+ virtual unsigned int GetActionID(const CKey& key) = 0;
+};
+} // namespace KEYBOARD
+} // namespace KODI
diff --git a/xbmc/input/keyboard/interfaces/IKeyboardDriverHandler.h b/xbmc/input/keyboard/interfaces/IKeyboardDriverHandler.h
new file mode 100644
index 0000000..828f0a9
--- /dev/null
+++ b/xbmc/input/keyboard/interfaces/IKeyboardDriverHandler.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2015-2018 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+class CKey;
+
+namespace KODI
+{
+namespace KEYBOARD
+{
+/*!
+ * \ingroup keyboard
+ * \brief Interface for handling keyboard events
+ */
+class IKeyboardDriverHandler
+{
+public:
+ virtual ~IKeyboardDriverHandler() = default;
+
+ /*!
+ * \brief A key has been pressed
+ *
+ * \param key The pressed key
+ *
+ * \return True if the event was handled, false otherwise
+ */
+ virtual bool OnKeyPress(const CKey& key) = 0;
+
+ /*!
+ * \brief A key has been released
+ *
+ * \param key The released key
+ */
+ virtual void OnKeyRelease(const CKey& key) = 0;
+};
+} // namespace KEYBOARD
+} // namespace KODI
diff --git a/xbmc/input/keyboard/interfaces/IKeyboardInputHandler.h b/xbmc/input/keyboard/interfaces/IKeyboardInputHandler.h
new file mode 100644
index 0000000..f0df6a3
--- /dev/null
+++ b/xbmc/input/keyboard/interfaces/IKeyboardInputHandler.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2017-2018 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+#include "input/keyboard/KeyboardTypes.h"
+
+#include <stdint.h>
+#include <string>
+
+namespace KODI
+{
+namespace KEYBOARD
+{
+/*!
+ * \ingroup keyboard
+ * \brief Interface for handling input events for keyboards
+ *
+ * Input events are an abstraction over driver events. Keys are identified by
+ * the name defined in the keyboard's controller profile.
+ */
+class IKeyboardInputHandler
+{
+public:
+ virtual ~IKeyboardInputHandler() = default;
+
+ /*!
+ * \brief The add-on ID of the keyboard's controller profile
+ *
+ * \return The ID of the controller profile add-on
+ */
+ virtual std::string ControllerID() const = 0;
+
+ /*!
+ * \brief Return true if the input handler accepts the given key
+ *
+ * \param key A key belonging to the controller specified by ControllerID()
+ *
+ * \return True if the key is used for input, false otherwise
+ */
+ virtual bool HasKey(const KeyName& key) const = 0;
+
+ /*!
+ * \brief A key has been pressed
+ *
+ * \param key A key belonging to the controller specified by ControllerID()
+ * \param mod A combination of modifiers
+ * \param unicode The unicode value associated with the key, or 0 if unknown
+ *
+ * \return True if the event was handled, false otherwise
+ */
+ virtual bool OnKeyPress(const KeyName& key, Modifier mod, uint32_t unicode) = 0;
+
+ /*!
+ * \brief A key has been released
+ *
+ * \param key A key belonging to the controller specified by ControllerID()
+ * \param mod A combination of modifiers
+ * \param unicode The unicode value associated with the key, or 0 if unknown
+ */
+ virtual void OnKeyRelease(const KeyName& key, Modifier mod, uint32_t unicode) = 0;
+};
+} // namespace KEYBOARD
+} // namespace KODI
diff --git a/xbmc/input/keyboard/interfaces/IKeyboardInputProvider.h b/xbmc/input/keyboard/interfaces/IKeyboardInputProvider.h
new file mode 100644
index 0000000..5d964d5
--- /dev/null
+++ b/xbmc/input/keyboard/interfaces/IKeyboardInputProvider.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2017-2018 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+namespace KODI
+{
+namespace KEYBOARD
+{
+class IKeyboardInputHandler;
+
+/*!
+ * \ingroup mouse
+ * \brief Interface for classes that can provide keyboard input
+ */
+class IKeyboardInputProvider
+{
+public:
+ virtual ~IKeyboardInputProvider() = default;
+
+ /*!
+ * \brief Registers a handler to be called on keyboard input
+ *
+ * \param handler The handler to receive keyboard input provided by this class
+ * \param bPromiscuous True to observe all events without affecting the
+ * input's destination
+ */
+ virtual void RegisterKeyboardHandler(IKeyboardInputHandler* handler, bool bPromiscuous) = 0;
+
+ /*!
+ * \brief Unregisters handler from keyboard input
+ *
+ * \param handler The handler that was receiving keyboard input
+ */
+ virtual void UnregisterKeyboardHandler(IKeyboardInputHandler* handler) = 0;
+};
+} // namespace KEYBOARD
+} // namespace KODI