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

Side by Side Diff: ui/ozone/platform/wayland/wayland_connection.cc

Issue 2639053002: [ozone/wayland] Implement basic keyboard handling support (Closed)
Patch Set: Addressed spang's feedback Created 3 years, 11 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/ozone/platform/wayland/wayland_connection.h" 5 #include "ui/ozone/platform/wayland/wayland_connection.h"
6 6
7 #include <xdg-shell-unstable-v5-client-protocol.h> 7 #include <xdg-shell-unstable-v5-client-protocol.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
15 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
15 #include "ui/ozone/platform/wayland/wayland_object.h" 16 #include "ui/ozone/platform/wayland/wayland_object.h"
16 #include "ui/ozone/platform/wayland/wayland_window.h" 17 #include "ui/ozone/platform/wayland/wayland_window.h"
17 18
19 #if BUILDFLAG(USE_XKBCOMMON)
20 #include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h"
21 #else
22 #include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h"
23 #endif
24
18 static_assert(XDG_SHELL_VERSION_CURRENT == 5, "Unsupported xdg-shell version"); 25 static_assert(XDG_SHELL_VERSION_CURRENT == 5, "Unsupported xdg-shell version");
19 26
20 namespace ui { 27 namespace ui {
21 namespace { 28 namespace {
22 const uint32_t kMaxCompositorVersion = 4; 29 const uint32_t kMaxCompositorVersion = 4;
23 const uint32_t kMaxSeatVersion = 4; 30 const uint32_t kMaxSeatVersion = 4;
24 const uint32_t kMaxShmVersion = 1; 31 const uint32_t kMaxShmVersion = 1;
25 const uint32_t kMaxXdgShellVersion = 1; 32 const uint32_t kMaxXdgShellVersion = 1;
26 } // namespace 33 } // namespace
27 34
28 WaylandConnection::WaylandConnection() {} 35 WaylandConnection::WaylandConnection() {
36 #if BUILDFLAG(USE_XKBCOMMON)
37 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(
38 base::MakeUnique<XkbKeyboardLayoutEngine>(codes_));
39 #else
40 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(
41 base::MakeUnique<StubKeyboardLayoutEngine>());
42 #endif
43 }
29 44
30 WaylandConnection::~WaylandConnection() {} 45 WaylandConnection::~WaylandConnection() {}
31 46
32 bool WaylandConnection::Initialize() { 47 bool WaylandConnection::Initialize() {
33 static const wl_registry_listener registry_listener = { 48 static const wl_registry_listener registry_listener = {
34 &WaylandConnection::Global, &WaylandConnection::GlobalRemove, 49 &WaylandConnection::Global, &WaylandConnection::GlobalRemove,
35 }; 50 };
36 51
37 display_.reset(wl_display_connect(nullptr)); 52 display_.reset(wl_display_connect(nullptr));
38 if (!display_) { 53 if (!display_) {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 LOG(ERROR) << "Failed to get wl_pointer from seat"; 235 LOG(ERROR) << "Failed to get wl_pointer from seat";
221 return; 236 return;
222 } 237 }
223 connection->pointer_ = base::MakeUnique<WaylandPointer>( 238 connection->pointer_ = base::MakeUnique<WaylandPointer>(
224 pointer, base::Bind(&WaylandConnection::DispatchUiEvent, 239 pointer, base::Bind(&WaylandConnection::DispatchUiEvent,
225 base::Unretained(connection))); 240 base::Unretained(connection)));
226 } 241 }
227 } else if (connection->pointer_) { 242 } else if (connection->pointer_) {
228 connection->pointer_.reset(); 243 connection->pointer_.reset();
229 } 244 }
245 if (capabilities & WL_SEAT_CAPABILITY_KEYBOARD) {
246 if (!connection->keyboard_) {
247 wl_keyboard* keyboard = wl_seat_get_keyboard(connection->seat_.get());
248 if (!keyboard) {
249 LOG(ERROR) << "Failed to get wl_keyboard from seat";
250 return;
251 }
252 connection->keyboard_ = base::MakeUnique<WaylandKeyboard>(
253 keyboard, base::Bind(&WaylandConnection::DispatchUiEvent,
254 base::Unretained(connection)));
255 }
256 } else if (connection->keyboard_) {
257 connection->keyboard_.reset();
258 }
230 connection->ScheduleFlush(); 259 connection->ScheduleFlush();
231 } 260 }
232 261
233 // static 262 // static
234 void WaylandConnection::Name(void* data, wl_seat* seat, const char* name) {} 263 void WaylandConnection::Name(void* data, wl_seat* seat, const char* name) {}
235 264
236 // static 265 // static
237 void WaylandConnection::Ping(void* data, xdg_shell* shell, uint32_t serial) { 266 void WaylandConnection::Ping(void* data, xdg_shell* shell, uint32_t serial) {
238 WaylandConnection* connection = static_cast<WaylandConnection*>(data); 267 WaylandConnection* connection = static_cast<WaylandConnection*>(data);
239 xdg_shell_pong(shell, serial); 268 xdg_shell_pong(shell, serial);
240 connection->ScheduleFlush(); 269 connection->ScheduleFlush();
241 } 270 }
242 271
243 } // namespace ui 272 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698