| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/events/platform/x11/x11_event_source.h" | 5 #include "ui/events/platform/x11/x11_event_source_libevent.h" |
| 6 | 6 |
| 7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | |
| 10 #include "base/message_loop/message_loop.h" | |
| 11 #include "base/message_loop/message_pump_libevent.h" | |
| 12 | |
| 13 namespace ui { | 9 namespace ui { |
| 14 | 10 |
| 15 namespace { | 11 X11EventSourceLibevent::X11EventSourceLibevent(XDisplay* display) |
| 12 : X11EventSource(display), initialized_(false) { |
| 13 AddEventWatcher(); |
| 14 } |
| 16 | 15 |
| 17 class X11EventSourceLibevent : public X11EventSource, | 16 X11EventSourceLibevent::~X11EventSourceLibevent() {} |
| 18 public base::MessagePumpLibevent::Watcher { | |
| 19 public: | |
| 20 explicit X11EventSourceLibevent(XDisplay* display) | |
| 21 : X11EventSource(display), | |
| 22 initialized_(false) { | |
| 23 AddEventWatcher(); | |
| 24 } | |
| 25 | 17 |
| 26 ~X11EventSourceLibevent() override { | 18 void X11EventSourceLibevent::AddEventWatcher() { |
| 27 } | 19 if (initialized_) |
| 20 return; |
| 21 if (!base::MessageLoop::current()) |
| 22 return; |
| 28 | 23 |
| 29 private: | 24 int fd = ConnectionNumber(display()); |
| 30 void AddEventWatcher() { | 25 base::MessageLoopForUI::current()->WatchFileDescriptor( |
| 31 if (initialized_) | 26 fd, true, base::MessagePumpLibevent::WATCH_READ, &watcher_controller_, |
| 32 return; | 27 this); |
| 33 if (!base::MessageLoop::current()) | 28 initialized_ = true; |
| 34 return; | 29 } |
| 35 | 30 |
| 36 int fd = ConnectionNumber(display()); | 31 void X11EventSourceLibevent::OnDispatcherListChanged() { |
| 37 base::MessageLoopForUI::current()->WatchFileDescriptor(fd, true, | 32 AddEventWatcher(); |
| 38 base::MessagePumpLibevent::WATCH_READ, &watcher_controller_, this); | 33 } |
| 39 initialized_ = true; | |
| 40 } | |
| 41 | 34 |
| 42 // PlatformEventSource: | 35 void X11EventSourceLibevent::OnFileCanReadWithoutBlocking(int fd) { |
| 43 void OnDispatcherListChanged() override { | 36 DispatchXEvents(); |
| 44 AddEventWatcher(); | 37 } |
| 45 } | |
| 46 | 38 |
| 47 // base::MessagePumpLibevent::Watcher: | 39 void X11EventSourceLibevent::OnFileCanWriteWithoutBlocking(int fd) { |
| 48 void OnFileCanReadWithoutBlocking(int fd) override { | 40 NOTREACHED(); |
| 49 DispatchXEvents(); | 41 } |
| 50 } | |
| 51 | |
| 52 void OnFileCanWriteWithoutBlocking(int fd) override { | |
| 53 NOTREACHED(); | |
| 54 } | |
| 55 | |
| 56 base::MessagePumpLibevent::FileDescriptorWatcher watcher_controller_; | |
| 57 bool initialized_; | |
| 58 | |
| 59 DISALLOW_COPY_AND_ASSIGN(X11EventSourceLibevent); | |
| 60 }; | |
| 61 | |
| 62 } // namespace | |
| 63 | 42 |
| 64 scoped_ptr<PlatformEventSource> PlatformEventSource::CreateDefault() { | 43 scoped_ptr<PlatformEventSource> PlatformEventSource::CreateDefault() { |
| 65 return make_scoped_ptr(new X11EventSourceLibevent(gfx::GetXDisplay())); | 44 return make_scoped_ptr(new X11EventSourceLibevent(gfx::GetXDisplay())); |
| 66 } | 45 } |
| 67 | 46 |
| 68 } // namespace ui | 47 } // namespace ui |
| OLD | NEW |