Add include.
[chromium-blink-merge.git] / ui / events / platform / x11 / x11_event_source_libevent.cc
blob8ad7931b3f0df3d825eac818ddea7fc83ca221f5
1 // Copyright 2014 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.
5 #include "ui/events/platform/x11/x11_event_source.h"
7 #include <X11/Xlib.h>
9 #include "base/message_loop/message_loop.h"
10 #include "base/message_loop/message_pump_libevent.h"
12 namespace ui {
14 namespace {
16 class X11EventSourceLibevent : public X11EventSource,
17 public base::MessagePumpLibevent::Watcher {
18 public:
19 explicit X11EventSourceLibevent(XDisplay* display)
20 : X11EventSource(display),
21 initialized_(false) {
22 AddEventWatcher();
25 virtual ~X11EventSourceLibevent() {
28 private:
29 void AddEventWatcher() {
30 if (initialized_)
31 return;
32 if (!base::MessageLoop::current())
33 return;
35 int fd = ConnectionNumber(display());
36 base::MessageLoopForUI::current()->WatchFileDescriptor(fd, true,
37 base::MessagePumpLibevent::WATCH_READ, &watcher_controller_, this);
38 initialized_ = true;
41 // PlatformEventSource:
42 virtual void OnDispatcherListChanged() override {
43 AddEventWatcher();
46 // base::MessagePumpLibevent::Watcher:
47 virtual void OnFileCanReadWithoutBlocking(int fd) override {
48 DispatchXEvents();
51 virtual void OnFileCanWriteWithoutBlocking(int fd) override {
52 NOTREACHED();
55 base::MessagePumpLibevent::FileDescriptorWatcher watcher_controller_;
56 bool initialized_;
58 DISALLOW_COPY_AND_ASSIGN(X11EventSourceLibevent);
61 } // namespace
63 scoped_ptr<PlatformEventSource> PlatformEventSource::CreateDefault() {
64 return scoped_ptr<PlatformEventSource>(
65 new X11EventSourceLibevent(gfx::GetXDisplay()));
68 } // namespace ui