[cosmetic] cleanup copyright headers
[vuplus_xbmc] / xbmc / windowing / wayland / Keyboard.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2011-2013 Team XBMC
5  *      http://xbmc.org
6  *
7  *  This Program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2, or (at your option)
10  *  any later version.
11  *
12  *  This Program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with XBMC; see the file COPYING.  If not, see
19  *  <http://www.gnu.org/licenses/>.
20  *
21  */
22 #include <boost/scoped_ptr.hpp>
23 #include <boost/shared_ptr.hpp>
24 #include <boost/noncopyable.hpp>
25
26 #include <wayland-client.h>
27
28 #include "input/linux/Keymap.h"
29
30 class IDllWaylandClient;
31 class IDllXKBCommon;
32
33 struct xkb_context;
34
35 namespace xbmc
36 {
37 namespace wayland
38 {
39 class IKeyboardReceiver
40 {
41 public:
42
43   virtual ~IKeyboardReceiver() {}
44
45   virtual void UpdateKeymap(ILinuxKeymap *) = 0;
46   virtual void Enter(uint32_t serial,
47                      struct wl_surface *surface,
48                      struct wl_array *keys) = 0;
49   virtual void Leave(uint32_t serial,
50                      struct wl_surface *surface) = 0;
51   virtual void Key(uint32_t serial,
52                    uint32_t time,
53                    uint32_t key,
54                    enum wl_keyboard_key_state state) = 0;
55   virtual void Modifier(uint32_t serial,
56                         uint32_t depressed,
57                         uint32_t latched,
58                         uint32_t locked,
59                         uint32_t group) = 0;
60 };
61
62 /* Wrapper class for a keyboard object. Generally there is one keyboard
63  * per seat.
64  * 
65  * Keyboard events are translated into a more readable form and
66  * forwarded on to the injected IKeyboardReceiver for further 
67  * processing.
68  * 
69  * Many of these events require some shared agreement between the
70  * compositor and the client as to the keymap in use. A file descriptor
71  * for a shared memory region to a serialized keymap parsable
72  * with libxkbcommon is provided in HandleKeymap and to the
73  * registered IKeyboardReceiever through UpdateKeymap. The delegate for
74  * that interface should ascertain the intended keymap before processing
75  * any other events.
76  */
77 class Keyboard :
78   public boost::noncopyable
79 {
80 public:
81
82   Keyboard(IDllWaylandClient &,
83            IDllXKBCommon &,
84            struct wl_keyboard *,
85            IKeyboardReceiver &);
86   ~Keyboard();
87
88   struct wl_keyboard * GetWlKeyboard();
89
90   static void HandleKeymapCallback(void *,
91                                    struct wl_keyboard *,
92                                    uint32_t,
93                                    int,
94                                    uint32_t);
95   static void HandleEnterCallback(void *,
96                                   struct wl_keyboard *,
97                                   uint32_t,
98                                   struct wl_surface *,
99                                   struct wl_array *);
100   static void HandleLeaveCallback(void *,
101                                   struct wl_keyboard *,
102                                   uint32_t,
103                                   struct wl_surface *);
104   static void HandleKeyCallback(void *,
105                                 struct wl_keyboard *,
106                                 uint32_t,
107                                 uint32_t,
108                                 uint32_t,
109                                 uint32_t);
110   static void HandleModifiersCallback(void *,
111                                       struct wl_keyboard *,
112                                       uint32_t,
113                                       uint32_t,
114                                       uint32_t,
115                                       uint32_t,
116                                       uint32_t);
117
118 private:
119
120   void HandleKeymap(uint32_t format,
121                     int fd,
122                     uint32_t size);
123   void HandleEnter(uint32_t serial,
124                    struct wl_surface *surface,
125                    struct wl_array *keys);
126   void HandleLeave(uint32_t serial,
127                    struct wl_surface *surface);
128   void HandleKey(uint32_t serial,
129                  uint32_t time,
130                  uint32_t key,
131                  uint32_t state);
132   void HandleModifiers(uint32_t serial,
133                        uint32_t mods_depressed,
134                        uint32_t mods_latched,
135                        uint32_t mods_locked,
136                        uint32_t group);
137
138   static const struct wl_keyboard_listener m_listener;
139
140   IDllWaylandClient &m_clientLibrary;
141   IDllXKBCommon &m_xkbCommonLibrary;
142   
143   /* boost::scoped_ptr does not permit custom deleters
144    * and std::auto_ptr is deprecated, so we are using
145    * boost::shared_ptr instead */
146   boost::shared_ptr<struct xkb_context> m_xkbCommonContext;
147   struct wl_keyboard *m_keyboard;
148   IKeyboardReceiver &m_reciever;
149
150   /* Keyboard owns the keymap object, but it might inject observing
151    * references elsewhere in order to assist those objects in their
152    * processing */
153   boost::scoped_ptr<ILinuxKeymap> m_keymap;
154 };
155 }
156 }