Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Unified Diff: remoting/host/linux/x_server_key_mapper.cc

Issue 2346643003: [Remoting Host] Handle text event characters that are not presented on the keyboard (Closed)
Patch Set: Create KeyboardInterface and XServerKeyboardInterface Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/host/linux/x_server_key_mapper.cc
diff --git a/remoting/host/linux/x_server_key_mapper.cc b/remoting/host/linux/x_server_key_mapper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8eca217013184757539271489323c703f3c3bf0e
--- /dev/null
+++ b/remoting/host/linux/x_server_key_mapper.cc
@@ -0,0 +1,65 @@
+// 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.
+
+#include "remoting/host/linux/x_server_key_mapper.h"
+
+#include "base/time/time.h"
+#include "remoting/host/linux/keyboard_interface.h"
+
+namespace {
+
+// The minimum duration before a mapped keycode can be reused.
+constexpr base::TimeDelta kMinReuseDuration =
+ base::TimeDelta::FromMilliseconds(200);
+
+} // namespace
+
+namespace remoting {
+
+struct XServerKeyMapper::KeyInfo {
+ uint32_t keycode;
+ base::TimeTicks last_used_time;
+};
+
+XServerKeyMapper::XServerKeyMapper(KeyboardInterface* keyboard)
+ : keyboard_(keyboard) {
+ std::vector<uint32_t> keycodes = keyboard_->GetUnusedKeycodes();
+ for (uint32_t keycode : keycodes) {
+ available_keycodes_.push_back({keycode, base::TimeTicks()});
+ }
+}
+
+XServerKeyMapper::~XServerKeyMapper() {
+ // Clear all used key mappings.
+ for (const KeyInfo& info : available_keycodes_) {
+ if (!info.last_used_time.is_null()) {
+ keyboard_->ChangeKeyMapping(info.keycode, 0, 0);
+ }
+ }
+ keyboard_->Sync();
+}
+
+XServerKeyMapper::MapResult XServerKeyMapper::AddNewCharacter(
+ uint32_t code_point) {
+ KeyInfo& info = available_keycodes_[current_keycode_index_];
+
+ base::TimeDelta time_until_reusable =
+ info.last_used_time + kMinReuseDuration - base::TimeTicks::Now();
+ if (time_until_reusable > base::TimeDelta()) {
+ return {false, 0, time_until_reusable};
+ }
+
+ if (!keyboard_->ChangeKeyMapping(info.keycode, code_point, code_point)) {
+ return {false, 0, base::TimeDelta()};
+ }
+
+ info.last_used_time = base::TimeTicks::Now();
Sergey Ulanov 2016/09/21 19:59:23 I think we also want to update last_used_time late
Yuwei 2016/09/21 20:35:32 Since the time here is just to prevent remapping b
Sergey Ulanov 2016/09/21 20:55:23 I think we want to track the time when the mapping
Yuwei 2016/09/21 21:14:18 Got it.
Yuwei 2016/09/22 00:32:58 Looks like STL doesn't provide useful heap utility
Sergey Ulanov 2016/09/22 18:32:46 I think just putting everything in a sorted vector
Yuwei 2016/09/23 01:40:37 Done.
+ current_keycode_index_ =
+ (current_keycode_index_ + 1) % available_keycodes_.size();
+
+ keyboard_->Sync();
+ return {true, info.keycode, base::TimeDelta()};
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698