x11_event_source_libevent.cc revision 0529e5d033099cbfc42635f6f6183833b09dff6e
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. 4 5#include "ui/events/platform/x11/x11_event_source.h" 6 7#include <X11/Xlib.h> 8 9#include "base/message_loop/message_loop.h" 10#include "base/message_loop/message_pump_libevent.h" 11 12namespace ui { 13 14namespace { 15 16class X11EventSourceLibevent : public X11EventSource, 17 public base::MessagePumpLibevent::Watcher { 18 public: 19 explicit X11EventSourceLibevent(XDisplay* display) 20 : X11EventSource(display) { 21 int fd = ConnectionNumber(display); 22 base::MessageLoopForUI::current()->WatchFileDescriptor(fd, true, 23 base::MessagePumpLibevent::WATCH_READ, &watcher_controller_, this); 24 } 25 26 virtual ~X11EventSourceLibevent() { 27 } 28 29 private: 30 // base::MessagePumpLibevent::Watcher: 31 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE { 32 DispatchXEvents(); 33 } 34 35 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE { 36 NOTREACHED(); 37 } 38 39 base::MessagePumpLibevent::FileDescriptorWatcher watcher_controller_; 40 41 DISALLOW_COPY_AND_ASSIGN(X11EventSourceLibevent); 42}; 43 44} // namespace 45 46scoped_ptr<PlatformEventSource> PlatformEventSource::CreateDefault() { 47 return scoped_ptr<PlatformEventSource>( 48 new X11EventSourceLibevent(gfx::GetXDisplay())); 49} 50 51} // namespace ui 52