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"
9 #include "base/message_loop/message_loop.h"
10 #include "base/message_loop/message_pump_libevent.h"
16 class X11EventSourceLibevent
: public X11EventSource
,
17 public base::MessagePumpLibevent::Watcher
{
19 explicit X11EventSourceLibevent(XDisplay
* display
)
20 : X11EventSource(display
),
25 ~X11EventSourceLibevent() override
{
29 void AddEventWatcher() {
32 if (!base::MessageLoop::current())
35 int fd
= ConnectionNumber(display());
36 base::MessageLoopForUI::current()->WatchFileDescriptor(fd
, true,
37 base::MessagePumpLibevent::WATCH_READ
, &watcher_controller_
, this);
41 // PlatformEventSource:
42 void OnDispatcherListChanged() override
{
46 // base::MessagePumpLibevent::Watcher:
47 void OnFileCanReadWithoutBlocking(int fd
) override
{
51 void OnFileCanWriteWithoutBlocking(int fd
) override
{
55 base::MessagePumpLibevent::FileDescriptorWatcher watcher_controller_
;
58 DISALLOW_COPY_AND_ASSIGN(X11EventSourceLibevent
);
63 scoped_ptr
<PlatformEventSource
> PlatformEventSource::CreateDefault() {
64 return make_scoped_ptr(new X11EventSourceLibevent(gfx::GetXDisplay()));