| 1 |
/* |
| 2 |
* Copyright (C) 2018 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 "SeatInputProcessing.h" |
| 10 |
|
| 11 |
#include <cassert> |
| 12 |
#include <memory> |
| 13 |
|
| 14 |
using namespace KODI::WINDOWING::WAYLAND; |
| 15 |
|
| 16 |
CSeatInputProcessing::CSeatInputProcessing(wayland::surface_t const& inputSurface, IInputHandler& handler) |
| 17 |
: m_inputSurface{inputSurface}, m_handler{handler} |
| 18 |
{ |
| 19 |
} |
| 20 |
|
| 21 |
void CSeatInputProcessing::AddSeat(CSeat* seat) |
| 22 |
{ |
| 23 |
assert(m_seats.find(seat->GetGlobalName()) == m_seats.end()); |
| 24 |
auto& seatState = m_seats.emplace(seat->GetGlobalName(), seat).first->second; |
| 25 |
|
| 26 |
seatState.keyboardProcessor = std::make_unique<CInputProcessorKeyboard>(*this); |
| 27 |
seat->AddRawInputHandlerKeyboard(seatState.keyboardProcessor.get()); |
| 28 |
seatState.pointerProcessor = std::make_unique<CInputProcessorPointer>(m_inputSurface, *this); |
| 29 |
seat->AddRawInputHandlerPointer(seatState.pointerProcessor.get()); |
| 30 |
seatState.touchProcessor = std::make_unique<CInputProcessorTouch>(m_inputSurface); |
| 31 |
seat->AddRawInputHandlerTouch(seatState.touchProcessor.get()); |
| 32 |
} |
| 33 |
|
| 34 |
void CSeatInputProcessing::RemoveSeat(CSeat* seat) |
| 35 |
{ |
| 36 |
auto seatStateI = m_seats.find(seat->GetGlobalName()); |
| 37 |
if (seatStateI != m_seats.end()) |
| 38 |
{ |
| 39 |
seat->RemoveRawInputHandlerKeyboard(seatStateI->second.keyboardProcessor.get()); |
| 40 |
seat->RemoveRawInputHandlerPointer(seatStateI->second.pointerProcessor.get()); |
| 41 |
seat->RemoveRawInputHandlerTouch(seatStateI->second.touchProcessor.get()); |
| 42 |
m_seats.erase(seatStateI); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
void CSeatInputProcessing::OnPointerEnter(std::uint32_t seatGlobalName, std::uint32_t serial) |
| 47 |
{ |
| 48 |
m_handler.OnSetCursor(seatGlobalName, serial); |
| 49 |
m_handler.OnEnter(InputType::POINTER); |
| 50 |
} |
| 51 |
|
| 52 |
void CSeatInputProcessing::OnPointerLeave() |
| 53 |
{ |
| 54 |
m_handler.OnLeave(InputType::POINTER); |
| 55 |
} |
| 56 |
|
| 57 |
void CSeatInputProcessing::OnPointerEvent(XBMC_Event& event) |
| 58 |
{ |
| 59 |
m_handler.OnEvent(InputType::POINTER, event); |
| 60 |
} |
| 61 |
|
| 62 |
void CSeatInputProcessing::OnKeyboardEnter() |
| 63 |
{ |
| 64 |
m_handler.OnEnter(InputType::KEYBOARD); |
| 65 |
} |
| 66 |
|
| 67 |
void CSeatInputProcessing::OnKeyboardLeave() |
| 68 |
{ |
| 69 |
m_handler.OnLeave(InputType::KEYBOARD); |
| 70 |
} |
| 71 |
|
| 72 |
void CSeatInputProcessing::OnKeyboardEvent(XBMC_Event& event) |
| 73 |
{ |
| 74 |
m_handler.OnEvent(InputType::KEYBOARD, event); |
| 75 |
} |
| 76 |
|
| 77 |
void CSeatInputProcessing::SetCoordinateScale(std::int32_t scale) |
| 78 |
{ |
| 79 |
for (auto& seatPair : m_seats) |
| 80 |
{ |
| 81 |
seatPair.second.touchProcessor->SetCoordinateScale(scale); |
| 82 |
seatPair.second.pointerProcessor->SetCoordinateScale(scale); |
| 83 |
} |
| 84 |
} |