Index: remoting/host/linux/x_server_key_mapper.h |
diff --git a/remoting/host/linux/x_server_key_mapper.h b/remoting/host/linux/x_server_key_mapper.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..878da6f1443fd435e0973891fc2b99bbb0ce9717 |
--- /dev/null |
+++ b/remoting/host/linux/x_server_key_mapper.h |
@@ -0,0 +1,50 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef REMOTING_HOST_LINUX_X_SERVER_KEY_MAPPER_H_ |
+#define REMOTING_HOST_LINUX_X_SERVER_KEY_MAPPER_H_ |
+ |
+#include <stdint.h> |
+#include <X11/Xlib.h> |
+ |
+#include <queue> |
+#include <unordered_set> |
+ |
+#include "base/macros.h" |
+ |
+namespace remoting { |
+ |
+/** |
+ * This is a helper class for assigning unused keycodes to characters. When all |
+ * keycodes are used, newly added character will take the keycode of the oldest |
+ * character. |
+ * When the key mapper is destructed, all keycodes used by the mapper will be |
+ * reset to map NoSymbol. |
+ * The key mapper must be used on single thread thread. |
+ */ |
+class XServerKeyMapper { |
+ public: |
+ explicit XServerKeyMapper(Display* display); |
+ ~XServerKeyMapper(); |
+ |
+ // |code_point|: The Unicode code point for the character. |
+ // Returns the keycode for the new character. Returns -1 when failed to map |
+ // the character. |
+ int AddNewCharacter(uint32_t code_point); |
+ |
+ private: |
+ // X11 graphics context. |
+ Display* display_; |
+ |
+ // TODO(yuweih): Consider better data structure, e.g. LRU. |
Sergey Ulanov
2016/09/19 21:39:00
To implement the current solution you can just hav
Yuwei
2016/09/21 03:47:40
For LRU I think we should count use of KeySym rath
|
+ std::queue<uint32_t> available_keycodes_; |
+ |
+ std::unordered_set<uint32_t> used_keycodes_; |
Sergey Ulanov
2016/09/19 21:39:00
keycodes are always in range [8..255] so this can
Yuwei
2016/09/21 03:47:40
Obsolete. The |last_used| field of KeyInfo is enou
|
+ |
+ DISALLOW_COPY_AND_ASSIGN(XServerKeyMapper); |
+}; |
+ |
+} // namespace remoting |
+ |
+#endif // REMOTING_HOST_LINUX_X_SERVER_KEY_MAPPER_H_ |