| 1 |
/* |
| 2 |
* Copyright (C) 2017-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 "SeatSelection.h" |
| 12 |
|
| 13 |
#include <cstdint> |
| 14 |
#include <set> |
| 15 |
|
| 16 |
#include <wayland-client-protocol.hpp> |
| 17 |
|
| 18 |
namespace KODI |
| 19 |
{ |
| 20 |
namespace WINDOWING |
| 21 |
{ |
| 22 |
namespace WAYLAND |
| 23 |
{ |
| 24 |
|
| 25 |
class CSeat; |
| 26 |
|
| 27 |
/** |
| 28 |
* Handler for raw wl_keyboard events |
| 29 |
* |
| 30 |
* All functions are identical to wl_keyboard, except for the keymap which is |
| 31 |
* retrieved from its fd and put into a string |
| 32 |
*/ |
| 33 |
class IRawInputHandlerKeyboard |
| 34 |
{ |
| 35 |
public: |
| 36 |
virtual void OnKeyboardKeymap(CSeat* seat, wayland::keyboard_keymap_format format, std::string const& keymap) {} |
| 37 |
virtual void OnKeyboardEnter(CSeat* seat, |
| 38 |
std::uint32_t serial, |
| 39 |
const wayland::surface_t& surface, |
| 40 |
const wayland::array_t& keys) |
| 41 |
{ |
| 42 |
} |
| 43 |
virtual void OnKeyboardLeave(CSeat* seat, std::uint32_t serial, const wayland::surface_t& surface) |
| 44 |
{ |
| 45 |
} |
| 46 |
virtual void OnKeyboardKey(CSeat* seat, std::uint32_t serial, std::uint32_t time, std::uint32_t key, wayland::keyboard_key_state state) {} |
| 47 |
virtual void OnKeyboardModifiers(CSeat* seat, std::uint32_t serial, std::uint32_t modsDepressed, std::uint32_t modsLatched, std::uint32_t modsLocked, std::uint32_t group) {} |
| 48 |
virtual void OnKeyboardRepeatInfo(CSeat* seat, std::int32_t rate, std::int32_t delay) {} |
| 49 |
protected: |
| 50 |
~IRawInputHandlerKeyboard() = default; |
| 51 |
}; |
| 52 |
|
| 53 |
/** |
| 54 |
* Handler for raw wl_pointer events |
| 55 |
* |
| 56 |
* All functions are identical to wl_pointer |
| 57 |
*/ |
| 58 |
class IRawInputHandlerPointer |
| 59 |
{ |
| 60 |
public: |
| 61 |
virtual void OnPointerEnter(CSeat* seat, |
| 62 |
std::uint32_t serial, |
| 63 |
const wayland::surface_t& surface, |
| 64 |
double surfaceX, |
| 65 |
double surfaceY) |
| 66 |
{ |
| 67 |
} |
| 68 |
virtual void OnPointerLeave(CSeat* seat, std::uint32_t serial, const wayland::surface_t& surface) |
| 69 |
{ |
| 70 |
} |
| 71 |
virtual void OnPointerMotion(CSeat* seat, std::uint32_t time, double surfaceX, double surfaceY) {} |
| 72 |
virtual void OnPointerButton(CSeat* seat, std::uint32_t serial, std::uint32_t time, std::uint32_t button, wayland::pointer_button_state state) {} |
| 73 |
virtual void OnPointerAxis(CSeat* seat, std::uint32_t time, wayland::pointer_axis axis, double value) {} |
| 74 |
protected: |
| 75 |
~IRawInputHandlerPointer() = default; |
| 76 |
}; |
| 77 |
|
| 78 |
/** |
| 79 |
* Handler for raw wl_touch events |
| 80 |
* |
| 81 |
* All functions are identical to wl_touch |
| 82 |
*/ |
| 83 |
class IRawInputHandlerTouch |
| 84 |
{ |
| 85 |
public: |
| 86 |
virtual void OnTouchDown(CSeat* seat, |
| 87 |
std::uint32_t serial, |
| 88 |
std::uint32_t time, |
| 89 |
const wayland::surface_t& surface, |
| 90 |
std::int32_t id, |
| 91 |
double x, |
| 92 |
double y) |
| 93 |
{ |
| 94 |
} |
| 95 |
virtual void OnTouchUp(CSeat* seat, std::uint32_t serial, std::uint32_t time, std::int32_t id) {} |
| 96 |
virtual void OnTouchMotion(CSeat* seat, std::uint32_t time, std::int32_t id, double x, double y) {} |
| 97 |
virtual void OnTouchCancel(CSeat* seat) {} |
| 98 |
virtual void OnTouchShape(CSeat* seat, std::int32_t id, double major, double minor) {} |
| 99 |
protected: |
| 100 |
~IRawInputHandlerTouch() = default; |
| 101 |
}; |
| 102 |
|
| 103 |
/** |
| 104 |
* Handle all events and requests related to one seat (including input and selection) |
| 105 |
* |
| 106 |
* The primary purpose of this class is to act as entry point of Wayland events into |
| 107 |
* the Kodi world and distribute them further as necessary. |
| 108 |
* Input events are forwarded to (potentially multiple) handlers. As the Wayland |
| 109 |
* protocol is not very specific on having multiple wl_seat/wl_pointer instances |
| 110 |
* and how they interact, having one central instance and then handling everything |
| 111 |
* in Kodi with multiple handlers is better than each handler having its own |
| 112 |
* protocol object instance. |
| 113 |
*/ |
| 114 |
class CSeat |
| 115 |
{ |
| 116 |
public: |
| 117 |
/** |
| 118 |
* Construct seat handler |
| 119 |
* \param globalName Wayland numeric global name of the seat |
| 120 |
* \param seat bound seat_t instance |
| 121 |
* \param connection connection for retrieving additional globals |
| 122 |
*/ |
| 123 |
CSeat(std::uint32_t globalName, wayland::seat_t const& seat, CConnection& connection); |
| 124 |
~CSeat() noexcept; |
| 125 |
|
| 126 |
void AddRawInputHandlerKeyboard(IRawInputHandlerKeyboard* rawKeyboardHandler); |
| 127 |
void RemoveRawInputHandlerKeyboard(IRawInputHandlerKeyboard* rawKeyboardHandler); |
| 128 |
void AddRawInputHandlerPointer(IRawInputHandlerPointer* rawPointerHandler); |
| 129 |
void RemoveRawInputHandlerPointer(IRawInputHandlerPointer* rawPointerHandler); |
| 130 |
void AddRawInputHandlerTouch(IRawInputHandlerTouch* rawTouchHandler); |
| 131 |
void RemoveRawInputHandlerTouch(IRawInputHandlerTouch* rawTouchHandler); |
| 132 |
|
| 133 |
std::uint32_t GetGlobalName() const |
| 134 |
{ |
| 135 |
return m_globalName; |
| 136 |
} |
| 137 |
std::string const& GetName() const |
| 138 |
{ |
| 139 |
return m_name; |
| 140 |
} |
| 141 |
bool HasPointerCapability() const |
| 142 |
{ |
| 143 |
return !!m_pointer; |
| 144 |
} |
| 145 |
bool HasKeyboardCapability() const |
| 146 |
{ |
| 147 |
return !!m_keyboard; |
| 148 |
} |
| 149 |
bool HasTouchCapability() const |
| 150 |
{ |
| 151 |
return !!m_touch; |
| 152 |
} |
| 153 |
std::string GetSelectionText() const |
| 154 |
{ |
| 155 |
return m_selection.GetSelectionText(); |
| 156 |
} |
| 157 |
/** |
| 158 |
* Get the wl_seat underlying this seat |
| 159 |
* |
| 160 |
* The wl_seat should only be used when strictly necessary, e.g. when |
| 161 |
* starting a move operation with shell interfaces. |
| 162 |
* It may not be used to derive further wl_pointer etc. instances. |
| 163 |
*/ |
| 164 |
wayland::seat_t const& GetWlSeat() |
| 165 |
{ |
| 166 |
return m_seat; |
| 167 |
} |
| 168 |
|
| 169 |
/** |
| 170 |
* Set the cursor of the pointer of this seat |
| 171 |
* |
| 172 |
* Parameters are identical wo wl_pointer.set_cursor(). |
| 173 |
* If the seat does not currently have the pointer capability, this is a no-op. |
| 174 |
*/ |
| 175 |
void SetCursor(std::uint32_t serial, wayland::surface_t const& surface, std::int32_t hotspotX, std::int32_t hotspotY); |
| 176 |
|
| 177 |
private: |
| 178 |
CSeat(CSeat const& other) = delete; |
| 179 |
CSeat& operator=(CSeat const& other) = delete; |
| 180 |
|
| 181 |
void HandleOnCapabilities(const wayland::seat_capability& caps); |
| 182 |
void HandlePointerCapability(); |
| 183 |
void HandleKeyboardCapability(); |
| 184 |
void HandleTouchCapability(); |
| 185 |
|
| 186 |
std::uint32_t m_globalName; |
| 187 |
std::string m_name{"<unknown>"}; |
| 188 |
|
| 189 |
wayland::seat_t m_seat; |
| 190 |
wayland::pointer_t m_pointer; |
| 191 |
wayland::keyboard_t m_keyboard; |
| 192 |
wayland::touch_t m_touch; |
| 193 |
|
| 194 |
std::set<IRawInputHandlerKeyboard*> m_rawKeyboardHandlers; |
| 195 |
std::set<IRawInputHandlerPointer*> m_rawPointerHandlers; |
| 196 |
std::set<IRawInputHandlerTouch*> m_rawTouchHandlers; |
| 197 |
|
| 198 |
CSeatSelection m_selection; |
| 199 |
}; |
| 200 |
|
| 201 |
} |
| 202 |
} |
| 203 |
} |