kodi
InputProcessorKeyboard.h
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 "Seat.h"
12 #include "XkbcommonKeymap.h"
13 #include "input/keyboard/XBMC_keysym.h"
14 #include "threads/Timer.h"
15 #include "windowing/XBMC_events.h"
16 
17 #include <atomic>
18 #include <cstdint>
19 #include <memory>
20 
21 namespace KODI
22 {
23 namespace WINDOWING
24 {
25 namespace WAYLAND
26 {
27 
29 {
30 public:
31  virtual void OnKeyboardEnter() {}
32  virtual void OnKeyboardLeave() {}
33  virtual void OnKeyboardEvent(XBMC_Event& event) = 0;
34  virtual ~IInputHandlerKeyboard() = default;
35 };
36 
38 {
39 public:
41 
42  void OnKeyboardKeymap(CSeat* seat, wayland::keyboard_keymap_format format, std::string const& keymap) override;
43  void OnKeyboardEnter(CSeat* seat,
44  std::uint32_t serial,
45  const wayland::surface_t& surface,
46  const wayland::array_t& keys) override;
47  void OnKeyboardLeave(CSeat* seat,
48  std::uint32_t serial,
49  const wayland::surface_t& surface) override;
50  void OnKeyboardKey(CSeat* seat, std::uint32_t serial, std::uint32_t time, std::uint32_t key, wayland::keyboard_key_state state) override;
51  void OnKeyboardModifiers(CSeat* seat, std::uint32_t serial, std::uint32_t modsDepressed, std::uint32_t modsLatched, std::uint32_t modsLocked, std::uint32_t group) override;
52  void OnKeyboardRepeatInfo(CSeat* seat, std::int32_t rate, std::int32_t delay) override;
53 
54 private:
55  CInputProcessorKeyboard(CInputProcessorKeyboard const& other) = delete;
56  CInputProcessorKeyboard& operator=(CInputProcessorKeyboard const& other) = delete;
57 
58  void ConvertAndSendKey(std::uint32_t scancode, bool pressed);
59  XBMC_Event SendKey(unsigned char scancode, XBMCKey key, std::uint16_t unicodeCodepoint, bool pressed);
66  void NotifyKeyComposingEvent(uint8_t eventType, std::uint16_t unicodeCodepoint);
67  void KeyRepeatTimeout();
68 
69  IInputHandlerKeyboard& m_handler;
70 
71  std::unique_ptr<CXkbcommonContext> m_xkbContext;
72  std::unique_ptr<CXkbcommonKeymap> m_keymap;
73  // Default values are used if compositor does not send any
74  std::atomic<int> m_keyRepeatDelay{1000};
75  std::atomic<int> m_keyRepeatInterval{50};
76  // Save complete XBMC_Event so no keymap lookups which might not be thread-safe
77  // are needed in the repeat callback
78  XBMC_Event m_keyToRepeat;
79 
80  CTimer m_keyRepeatTimer;
81 };
82 
83 }
84 }
85 }
Definition: Timer.h:25
Definition: InputProcessorKeyboard.h:37
Definition: InputProcessorKeyboard.h:28
Definition: AudioDecoder.h:18
Handler for raw wl_keyboard events.
Definition: Seat.h:33
Definition: SmartPlayList.cpp:137
Handle all events and requests related to one seat (including input and selection) ...
Definition: Seat.h:114
Definition: XBMC_events.h:117