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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "remoting/host/linux/x_server_key_mapper.h"
6
7 #include "base/time/time.h"
8 #include "remoting/host/linux/keyboard_interface.h"
9
10 namespace {
11
12 // The minimum duration before a mapped keycode can be reused.
13 constexpr base::TimeDelta kMinReuseDuration =
14 base::TimeDelta::FromMilliseconds(200);
15
16 } // namespace
17
18 namespace remoting {
19
20 struct XServerKeyMapper::KeyInfo {
21 uint32_t keycode;
22 base::TimeTicks last_used_time;
23 };
24
25 XServerKeyMapper::XServerKeyMapper(KeyboardInterface* keyboard)
26 : keyboard_(keyboard) {
27 std::vector<uint32_t> keycodes = keyboard_->GetUnusedKeycodes();
28 for (uint32_t keycode : keycodes) {
29 available_keycodes_.push_back({keycode, base::TimeTicks()});
30 }
31 }
32
33 XServerKeyMapper::~XServerKeyMapper() {
34 // Clear all used key mappings.
35 for (const KeyInfo& info : available_keycodes_) {
36 if (!info.last_used_time.is_null()) {
37 keyboard_->ChangeKeyMapping(info.keycode, 0, 0);
38 }
39 }
40 keyboard_->Sync();
41 }
42
43 XServerKeyMapper::MapResult XServerKeyMapper::AddNewCharacter(
44 uint32_t code_point) {
45 KeyInfo& info = available_keycodes_[current_keycode_index_];
46
47 base::TimeDelta time_until_reusable =
48 info.last_used_time + kMinReuseDuration - base::TimeTicks::Now();
49 if (time_until_reusable > base::TimeDelta()) {
50 return {false, 0, time_until_reusable};
51 }
52
53 if (!keyboard_->ChangeKeyMapping(info.keycode, code_point, code_point)) {
54 return {false, 0, base::TimeDelta()};
55 }
56
57 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.
58 current_keycode_index_ =
59 (current_keycode_index_ + 1) % available_keycodes_.size();
60
61 keyboard_->Sync();
62 return {true, info.keycode, base::TimeDelta()};
63 }
64
65 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698