| 1 |
/* |
| 2 |
* Copyright (C) 2024 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "DefaultKeyboardHandling.h" |
| 10 |
|
| 11 |
#include "KeyboardInputHandling.h" |
| 12 |
#include "games/controllers/input/DefaultButtonMap.h" |
| 13 |
#include "input/keyboard/interfaces/IKeyboardInputHandler.h" |
| 14 |
|
| 15 |
#include <memory> |
| 16 |
|
| 17 |
using namespace KODI; |
| 18 |
using namespace KEYBOARD; |
| 19 |
|
| 20 |
CDefaultKeyboardHandling::CDefaultKeyboardHandling(PERIPHERALS::CPeripheral* peripheral, |
| 21 |
IKeyboardInputHandler* handler) |
| 22 |
: m_peripheral(peripheral), m_inputHandler(handler) |
| 23 |
{ |
| 24 |
} |
| 25 |
|
| 26 |
CDefaultKeyboardHandling::~CDefaultKeyboardHandling(void) |
| 27 |
{ |
| 28 |
m_driverHandler.reset(); |
| 29 |
m_buttonMap.reset(); |
| 30 |
} |
| 31 |
|
| 32 |
bool CDefaultKeyboardHandling::Load() |
| 33 |
{ |
| 34 |
std::string controllerId; |
| 35 |
if (m_inputHandler != nullptr) |
| 36 |
controllerId = m_inputHandler->ControllerID(); |
| 37 |
|
| 38 |
if (!controllerId.empty()) |
| 39 |
m_buttonMap = std::make_unique<GAME::CDefaultButtonMap>(m_peripheral, std::move(controllerId)); |
| 40 |
|
| 41 |
if (m_buttonMap && m_buttonMap->Load()) |
| 42 |
{ |
| 43 |
m_driverHandler = std::make_unique<CKeyboardInputHandling>(m_inputHandler, m_buttonMap.get()); |
| 44 |
return true; |
| 45 |
} |
| 46 |
|
| 47 |
return false; |
| 48 |
} |
| 49 |
|
| 50 |
bool CDefaultKeyboardHandling::OnKeyPress(const CKey& key) |
| 51 |
{ |
| 52 |
if (m_driverHandler) |
| 53 |
return m_driverHandler->OnKeyPress(key); |
| 54 |
|
| 55 |
return false; |
| 56 |
} |
| 57 |
|
| 58 |
void CDefaultKeyboardHandling::OnKeyRelease(const CKey& key) |
| 59 |
{ |
| 60 |
if (m_driverHandler) |
| 61 |
m_driverHandler->OnKeyRelease(key); |
| 62 |
} |