summaryrefslogtreecommitdiffstats
path: root/xbmc/windowing/wayland/SeatInputProcessing.cpp
blob: 6430aad20c997008b95d7c4abac1fa7a5bfde902 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 *  Copyright (C) 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 "SeatInputProcessing.h"

#include <cassert>

using namespace KODI::WINDOWING::WAYLAND;

CSeatInputProcessing::CSeatInputProcessing(wayland::surface_t const& inputSurface, IInputHandler& handler)
: m_inputSurface{inputSurface}, m_handler{handler}
{
}

void CSeatInputProcessing::AddSeat(CSeat* seat)
{
  assert(m_seats.find(seat->GetGlobalName()) == m_seats.end());
  auto& seatState = m_seats.emplace(seat->GetGlobalName(), seat).first->second;

  seatState.keyboardProcessor.reset(new CInputProcessorKeyboard(*this));
  seat->AddRawInputHandlerKeyboard(seatState.keyboardProcessor.get());
  seatState.pointerProcessor.reset(new CInputProcessorPointer(m_inputSurface, *this));
  seat->AddRawInputHandlerPointer(seatState.pointerProcessor.get());
  seatState.touchProcessor.reset(new CInputProcessorTouch(m_inputSurface));
  seat->AddRawInputHandlerTouch(seatState.touchProcessor.get());
}

void CSeatInputProcessing::RemoveSeat(CSeat* seat)
{
  auto seatStateI = m_seats.find(seat->GetGlobalName());
  if (seatStateI != m_seats.end())
  {
    seat->RemoveRawInputHandlerKeyboard(seatStateI->second.keyboardProcessor.get());
    seat->RemoveRawInputHandlerPointer(seatStateI->second.pointerProcessor.get());
    seat->RemoveRawInputHandlerTouch(seatStateI->second.touchProcessor.get());
    m_seats.erase(seatStateI);
  }
}

void CSeatInputProcessing::OnPointerEnter(std::uint32_t seatGlobalName, std::uint32_t serial)
{
  m_handler.OnSetCursor(seatGlobalName, serial);
  m_handler.OnEnter(InputType::POINTER);
}

void CSeatInputProcessing::OnPointerLeave()
{
  m_handler.OnLeave(InputType::POINTER);
}

void CSeatInputProcessing::OnPointerEvent(XBMC_Event& event)
{
  m_handler.OnEvent(InputType::POINTER, event);
}

void CSeatInputProcessing::OnKeyboardEnter()
{
  m_handler.OnEnter(InputType::KEYBOARD);
}

void CSeatInputProcessing::OnKeyboardLeave()
{
  m_handler.OnLeave(InputType::KEYBOARD);
}

void CSeatInputProcessing::OnKeyboardEvent(XBMC_Event& event)
{
  m_handler.OnEvent(InputType::KEYBOARD, event);
}

void CSeatInputProcessing::SetCoordinateScale(std::int32_t scale)
{
  for (auto& seatPair : m_seats)
  {
    seatPair.second.touchProcessor->SetCoordinateScale(scale);
    seatPair.second.pointerProcessor->SetCoordinateScale(scale);
  }
}