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

Unified Diff: ui/ozone/platform/wayland/wayland_display.cc

Issue 1712103002: ozone/platform/wayland: Implement pointer handling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add second window for WaylandPointerTest.Leave, check for NULL surface in WaylandPointer::{Enter,Le… Created 4 years, 10 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: ui/ozone/platform/wayland/wayland_display.cc
diff --git a/ui/ozone/platform/wayland/wayland_display.cc b/ui/ozone/platform/wayland/wayland_display.cc
index 1c0f07e25154aada7420abe0f4f3b7100554f6df..50f1175ce2cc8224c11bdae46034d164f6847a7d 100644
--- a/ui/ozone/platform/wayland/wayland_display.cc
+++ b/ui/ozone/platform/wayland/wayland_display.cc
@@ -6,6 +6,7 @@
#include <xdg-shell-unstable-v5-client-protocol.h>
+#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "ui/ozone/platform/wayland/wayland_object.h"
@@ -16,6 +17,7 @@ static_assert(XDG_SHELL_VERSION_CURRENT == 5, "Unsupported xdg-shell version");
namespace ui {
namespace {
const uint32_t kMaxCompositorVersion = 4;
+const uint32_t kMaxSeatVersion = 4;
const uint32_t kMaxShmVersion = 1;
const uint32_t kMaxXdgShellVersion = 1;
} // namespace
@@ -52,6 +54,10 @@ bool WaylandDisplay::Initialize() {
LOG(ERROR) << "No wl_shm object";
return false;
}
+ if (!seat_) {
+ LOG(ERROR) << "No wl_seat object";
+ return false;
+ }
if (!shell_) {
LOG(ERROR) << "No xdg_shell object";
return false;
@@ -79,17 +85,20 @@ void WaylandDisplay::RemoveWindow(WaylandWindow* window) {
}
void WaylandDisplay::OnDispatcherListChanged() {
- if (watching_)
+ if (watching_ || !base::MessageLoopForUI::IsCurrent())
return;
DCHECK(display_);
- DCHECK(base::MessageLoopForUI::IsCurrent());
spang 2016/02/26 01:41:11 I hope this cannot get called off the UI thread..
Michael Forney 2016/02/26 01:47:34 I changed it to a conditional because this gets ca
spang 2016/02/26 03:51:45 Sure, create a UI message loop from the test befor
Michael Forney 2016/02/27 00:01:37 Cool. Looks like just creating a MessageLoopForUI
base::MessageLoopForUI::current()->WatchFileDescriptor(
wl_display_get_fd(display_.get()), true,
base::MessagePumpLibevent::WATCH_READ, &controller_, this);
watching_ = true;
}
+void WaylandDisplay::DispatchUiEvent(Event* event) {
+ PlatformEventSource::DispatchEvent(event);
+}
+
void WaylandDisplay::OnFileCanReadWithoutBlocking(int fd) {
wl_display_dispatch(display_.get());
for (const auto& window : window_map_)
@@ -104,6 +113,9 @@ void WaylandDisplay::Global(void* data,
uint32_t name,
const char* interface,
uint32_t version) {
+ static const wl_seat_listener seat_listener = {
+ &WaylandDisplay::Capabilities, &WaylandDisplay::Name,
+ };
static const xdg_shell_listener shell_listener = {
&WaylandDisplay::Ping,
};
@@ -119,6 +131,14 @@ void WaylandDisplay::Global(void* data,
wl::Bind<wl_shm>(registry, name, std::min(version, kMaxShmVersion));
if (!display->shm_)
LOG(ERROR) << "Failed to bind to wl_shm global";
+ } else if (!display->seat_ && strcmp(interface, "wl_seat") == 0) {
+ display->seat_ =
+ wl::Bind<wl_seat>(registry, name, std::min(version, kMaxSeatVersion));
+ if (!display->seat_) {
+ LOG(ERROR) << "Failed to bind to wl_seat global";
+ return;
+ }
+ wl_seat_add_listener(display->seat_.get(), &seat_listener, display);
} else if (!display->shell_ && strcmp(interface, "xdg_shell") == 0) {
display->shell_ = wl::Bind<xdg_shell>(
registry, name, std::min(version, kMaxXdgShellVersion));
@@ -140,6 +160,30 @@ void WaylandDisplay::GlobalRemove(void* data,
}
// static
+void WaylandDisplay::Capabilities(void* data,
+ wl_seat* seat,
+ uint32_t capabilities) {
+ WaylandDisplay* display = static_cast<WaylandDisplay*>(data);
+ if (capabilities & WL_SEAT_CAPABILITY_POINTER) {
+ if (!display->pointer_) {
+ wl_pointer* pointer = wl_seat_get_pointer(display->seat_.get());
+ if (!pointer) {
+ LOG(ERROR) << "Failed to get wl_pointer from seat";
+ return;
+ }
+ display->pointer_ = make_scoped_ptr(new WaylandPointer(
+ pointer, base::Bind(&WaylandDisplay::DispatchUiEvent,
+ base::Unretained(display))));
+ }
+ } else if (display->pointer_) {
+ display->pointer_.reset();
spang 2016/02/26 01:41:11 How could the capability get revoked?
Michael Forney 2016/02/26 01:47:34 The user unplugs their mouse, and seat no longer h
+ }
+}
+
+// static
+void WaylandDisplay::Name(void* data, wl_seat* seat, const char* name) {}
+
+// static
void WaylandDisplay::Ping(void* data, xdg_shell* shell, uint32_t serial) {
xdg_shell_pong(shell, serial);
}

Powered by Google App Engine
This is Rietveld 408576698