Mir
xkb_mapper.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2013-2016 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by:
17  * Robert Carr <robert.carr@canonical.com>
18  * Andreas Pokorny <andreas.pokorny@canonical.com>
19  */
20 
21 #ifndef MIR_INPUT_RECEIVER_XKB_MAPPER_H_
22 #define MIR_INPUT_RECEIVER_XKB_MAPPER_H_
23 
24 #include "mir_toolkit/event.h"
25 
26 #include <xkbcommon/xkbcommon.h>
27 
28 #include <memory>
29 #include <mutex>
30 
31 namespace mir
32 {
33 namespace input
34 {
35 
36 using XKBContextPtr = std::unique_ptr<xkb_context, void(*)(xkb_context*)>;
38 
39 using XKBKeymapPtr = std::unique_ptr<xkb_keymap, void (*)(xkb_keymap*)>;
40 XKBKeymapPtr make_unique_keymap(xkb_context* context, std::string const& model, std::string const& layout,
41  std::string const& variant, std::string const& options);
42 XKBKeymapPtr make_unique_keymap(xkb_context* context, char const* buffer, size_t size);
43 
44 using XKBStatePtr = std::unique_ptr<xkb_state, void(*)(xkb_state*)>;
45 XKBStatePtr make_unique_state(xkb_keymap* keymap);
46 
47 namespace receiver
48 {
49 
50 class XKBMapper
51 {
52 public:
53  XKBMapper();
54  virtual ~XKBMapper() = default;
55 
56  xkb_context* get_context() const;
57  void set_keymap(MirInputDeviceId device_id, XKBKeymapPtr names);
58 
60 
61 protected:
62  XKBMapper(XKBMapper const&) = delete;
63  XKBMapper& operator=(XKBMapper const&) = delete;
64 
65 private:
66  std::mutex guard;
67 
68  XKBContextPtr context;
69  XKBKeymapPtr keymap;
70  XKBStatePtr state;
71 };
72 
73 }
74 }
75 }
76 
77 #endif // MIR_INPUT_RECEIVER_XKB_MAPPER_H_
All things Mir.
Definition: atomic_callback.h:25
XKBContextPtr make_unique_context()
Definition: xkb_mapper.cpp:27
std::unique_ptr< xkb_context, void(*)(xkb_context *)> XKBContextPtr
Definition: xkb_mapper.h:36
XKBKeymapPtr make_unique_keymap(xkb_context *context, std::string const &model, std::string const &layout, std::string const &variant, std::string const &options)
Definition: xkb_mapper.cpp:32
std::unique_ptr< xkb_state, void(*)(xkb_state *)> XKBStatePtr
Definition: xkb_mapper.h:44
void update_state_and_map_event(MirEvent &ev)
Definition: xkb_mapper.h:50
int64_t MirInputDeviceId
Definition: input_event.h:35
std::unique_ptr< xkb_keymap, void(*)(xkb_keymap *)> XKBKeymapPtr
Definition: xkb_mapper.h:39
XKBStatePtr make_unique_state(xkb_keymap *keymap)
Definition: xkb_mapper.cpp:53
void set_keymap(MirInputDeviceId device_id, XKBKeymapPtr names)
Definition: event_private.h:181
XKBMapper & operator=(XKBMapper const &)=delete
xkb_context * get_context() const
int const size
Definition: make_socket_rpc_channel.cpp:51

Copyright © 2012-2015 Canonical Ltd.
Generated on Wed Mar 30 00:29:56 UTC 2016