summaryrefslogtreecommitdiffstats
path: root/chromium/ui/events/platform/x11/x11_event_source_libevent.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/events/platform/x11/x11_event_source_libevent.cc')
-rw-r--r--chromium/ui/events/platform/x11/x11_event_source_libevent.cc68
1 files changed, 68 insertions, 0 deletions
diff --git a/chromium/ui/events/platform/x11/x11_event_source_libevent.cc b/chromium/ui/events/platform/x11/x11_event_source_libevent.cc
new file mode 100644
index 00000000000..d92e12a5d82
--- /dev/null
+++ b/chromium/ui/events/platform/x11/x11_event_source_libevent.cc
@@ -0,0 +1,68 @@
+// Copyright 2014 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 "ui/events/platform/x11/x11_event_source.h"
+
+#include <X11/Xlib.h>
+
+#include "base/message_loop/message_loop.h"
+#include "base/message_loop/message_pump_libevent.h"
+
+namespace ui {
+
+namespace {
+
+class X11EventSourceLibevent : public X11EventSource,
+ public base::MessagePumpLibevent::Watcher {
+ public:
+ explicit X11EventSourceLibevent(XDisplay* display)
+ : X11EventSource(display),
+ initialized_(false) {
+ AddEventWatcher();
+ }
+
+ virtual ~X11EventSourceLibevent() {
+ }
+
+ private:
+ void AddEventWatcher() {
+ if (initialized_)
+ return;
+ if (!base::MessageLoop::current())
+ return;
+
+ int fd = ConnectionNumber(display());
+ base::MessageLoopForUI::current()->WatchFileDescriptor(fd, true,
+ base::MessagePumpLibevent::WATCH_READ, &watcher_controller_, this);
+ initialized_ = true;
+ }
+
+ // PlatformEventSource:
+ virtual void OnDispatcherListChanged() OVERRIDE {
+ AddEventWatcher();
+ }
+
+ // base::MessagePumpLibevent::Watcher:
+ virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE {
+ DispatchXEvents();
+ }
+
+ virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE {
+ NOTREACHED();
+ }
+
+ base::MessagePumpLibevent::FileDescriptorWatcher watcher_controller_;
+ bool initialized_;
+
+ DISALLOW_COPY_AND_ASSIGN(X11EventSourceLibevent);
+};
+
+} // namespace
+
+scoped_ptr<PlatformEventSource> PlatformEventSource::CreateDefault() {
+ return scoped_ptr<PlatformEventSource>(
+ new X11EventSourceLibevent(gfx::GetXDisplay()));
+}
+
+} // namespace ui