Debian Codegraph @

xbmc/windowing/wayland/SeatInputProcessing.h

raw
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 #pragma once
10
11 #include "InputProcessorKeyboard.h"
12 #include "InputProcessorPointer.h"
13 #include "InputProcessorTouch.h"
14 #include "Seat.h"
15
16 #include <cstdint>
17 #include <map>
18 #include <memory>
19
20 #include <wayland-client-protocol.hpp>
21
22 namespace KODI
23 {
24 namespace WINDOWING
25 {
26 namespace WAYLAND
27 {
28
29 enum class InputType
30 {
31 POINTER,
32 KEYBOARD,
33 TOUCH
34 };
35
36 /**
37 * Handler interface for input events from \ref CSeatInputProcessor
38 */
39 class IInputHandler
40 {
41 public:
42 /**
43 * Handle input event
44 * \param type input device type that caused the event
45 * \param event XBMC event data
46 */
47 virtual void OnEvent(InputType type, XBMC_Event& event) {}
48 /**
49 * Handle focus enter
50 * \param type input device type for which the surface has gained the focus
51 */
52 virtual void OnEnter(InputType type) {}
53 /**
54 * Handle focus leave
55 * \param type input device type for which the surface has lost the focus
56 */
57 virtual void OnLeave(InputType type) {}
58 /**
59 * Handle request for setting the cursor
60 *
61 * When the client gains pointer focus for a surface, a cursor image must be
62 * attached to the pointer. Otherwise the previous pointer image would
63 * be used.
64 *
65 * This request is sent in addition to \ref OnEnter for \ref InputType::POINTER.
66 *
67 * \param seatGlobalName numeric Wayland global name of the seat the event occurred on
68 * \param pointer pointer instance that needs its cursor set
69 * \param serial Wayland protocol message serial that must be sent back in set_cursor
70 */
71 virtual void OnSetCursor(std::uint32_t seatGlobalName, std::uint32_t serial) {}
72
73 virtual ~IInputHandler() = default;
74 };
75
76 /**
77 * Receive events from all registered wl_seats and process them into Kodi events
78 *
79 * Multi-seat support is not currently implemented completely, but each seat has
80 * separate state.
81 */
82 class CSeatInputProcessing final : public IInputHandlerPointer, public IInputHandlerKeyboard
83 {
84 public:
85 /**
86 * Construct a seat input processor
87 *
88 * \param inputSurface Surface that events should be processed on (all other surfaces are ignored)
89 * \param handler Mandatory handler for processed input events
90 */
91 CSeatInputProcessing(wayland::surface_t const& inputSurface, IInputHandler& handler);
92 void AddSeat(CSeat* seat);
93 void RemoveSeat(CSeat* seat);
94
95 /**
96 * Set the scale the coordinates should be interpreted at
97 *
98 * Wayland input events are always in surface coordinates, but Kodi only uses
99 * buffer coordinates internally. Use this function to set the scaling
100 * factor between the two and multiply the surface coordinates accordingly
101 * for Kodi events.
102 *
103 * \param scale new buffer-to-surface pixel ratio
104 */
105 void SetCoordinateScale(std::int32_t scale);
106
107 private:
108 wayland::surface_t m_inputSurface;
109 IInputHandler& m_handler;
110
111 void OnPointerEnter(std::uint32_t seatGlobalName, std::uint32_t serial) override;
112 void OnPointerLeave() override;
113 void OnPointerEvent(XBMC_Event& event) override;
114
115 void OnKeyboardEnter() override;
116 void OnKeyboardLeave() override;
117 void OnKeyboardEvent(XBMC_Event& event) override;
118
119 struct SeatState
120 {
121 CSeat* seat;
122 std::unique_ptr<CInputProcessorKeyboard> keyboardProcessor;
123 std::unique_ptr<CInputProcessorPointer> pointerProcessor;
124 std::unique_ptr<CInputProcessorTouch> touchProcessor;
125
126 SeatState(CSeat* seat)
127 : seat{seat}
128 {}
129 };
130 std::map<std::uint32_t, SeatState> m_seats;
131 };
132
133 }
134 }
135 }