OLD | NEW |
---|---|
(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 "ui/ozone/platform/wayland/wayland_keyboard.h" | |
6 | |
7 #include <sys/mman.h> | |
8 #include <wayland-client.h> | |
9 | |
10 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" | |
11 #include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h" | |
12 #include "ui/ozone/platform/wayland/wayland_window.h" | |
13 | |
14 namespace ui { | |
15 | |
16 WaylandKeyboard::WaylandKeyboard(wl_keyboard* keyboard, | |
17 const EventDispatchCallback& callback) | |
18 : obj_(keyboard), | |
19 evdev_(&modifiers_, | |
20 KeyboardLayoutEngineManager::GetKeyboardLayoutEngine(), | |
21 callback) { | |
22 static const wl_keyboard_listener listener = { | |
23 &WaylandKeyboard::Keymap, &WaylandKeyboard::Enter, | |
24 &WaylandKeyboard::Leave, &WaylandKeyboard::Key, | |
25 &WaylandKeyboard::Modifiers, &WaylandKeyboard::RepeatInfo, | |
26 }; | |
27 | |
28 wl_keyboard_add_listener(obj_.get(), &listener, this); | |
29 evdev_.SetAutoRepeatEnabled(true); | |
30 } | |
31 | |
32 WaylandKeyboard::~WaylandKeyboard() {} | |
33 | |
34 void WaylandKeyboard::Keymap(void* data, | |
35 wl_keyboard* obj, | |
36 uint32_t format, | |
37 int32_t fd, | |
38 uint32_t size) { | |
39 if (!data) { | |
40 close(fd); | |
41 return; | |
42 } | |
43 | |
44 if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) { | |
45 close(fd); | |
46 return; | |
47 } | |
48 | |
49 char* map_str = | |
50 reinterpret_cast<char*>(mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0)); | |
51 if (map_str == MAP_FAILED) | |
52 return; | |
53 | |
54 WaylandKeyboard* keyboard = static_cast<WaylandKeyboard*>(data); | |
55 keyboard->evdev_.SetCurrentLayoutByName(map_str); | |
Michael Forney
2017/01/17 23:44:56
map_str might not be NULL terminated.
This is why
tonikitoo
2017/01/18 00:02:28
That is a good. I can certainly try that out. Not
Michael Forney
2017/01/18 00:16:05
I think we should change this CL to pass std::stri
| |
56 munmap(map_str, size); | |
57 close(fd); | |
58 } | |
59 | |
60 void WaylandKeyboard::Enter(void* data, | |
61 wl_keyboard* obj, | |
62 uint32_t serial, | |
63 wl_surface* surface, | |
64 wl_array* keys) { | |
65 WaylandWindow::FromSurface(surface)->set_keyboard_focus(true); | |
66 // TODO(forney): The KeyboardEvdev object should update its state using the | |
67 // passed key array. | |
68 } | |
69 | |
70 void WaylandKeyboard::Leave(void* data, | |
71 wl_keyboard* obj, | |
72 uint32_t serial, | |
73 wl_surface* surface) { | |
74 WaylandWindow::FromSurface(surface)->set_keyboard_focus(false); | |
75 } | |
76 | |
77 void WaylandKeyboard::Key(void* data, | |
78 wl_keyboard* obj, | |
79 uint32_t serial, | |
80 uint32_t time, | |
81 uint32_t key, | |
82 uint32_t state) { | |
83 WaylandKeyboard* keyboard = static_cast<WaylandKeyboard*>(data); | |
84 keyboard->evdev_.OnKeyChange( | |
85 key, state == WL_KEYBOARD_KEY_STATE_PRESSED false, | |
Michael Forney
2017/01/17 23:44:56
Missing comma?
tonikitoo
2017/01/18 00:02:28
Done.
'git cl format' did me this favor. I should
| |
86 base::TimeTicks() + base::TimeDelta::FromMilliseconds(time), | |
87 keyboard->obj_.id()); | |
88 } | |
89 | |
90 void WaylandKeyboard::Modifiers(void* data, | |
91 wl_keyboard* obj, | |
92 uint32_t serial, | |
93 uint32_t mods_depressed, | |
94 uint32_t mods_latched, | |
95 uint32_t mods_locked, | |
96 uint32_t group) { | |
97 // TODO(forney): Implement proper modifier handling. | |
98 NOTIMPLEMENTED(); | |
99 } | |
100 | |
101 void WaylandKeyboard::RepeatInfo(void* data, | |
102 wl_keyboard* obj, | |
103 int32_t rate, | |
104 int32_t delay) { | |
105 WaylandKeyboard* keyboard = static_cast<WaylandKeyboard*>(data); | |
106 keyboard->evdev_.SetAutoRepeatRate(base::TimeDelta::FromMilliseconds(delay), | |
107 base::TimeDelta::FromSeconds(1) / rate); | |
108 } | |
109 | |
110 } // namespace ui | |
OLD | NEW |