Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(583)

Side by Side Diff: ui/events/platform/x11/x11_event_source_libevent.cc

Issue 1602173005: Add PlatformWindow/Event related code for Ozone X11. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix deps problem. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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/macros.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/message_loop/message_pump_libevent.h"
12
13 namespace ui {
14
15 namespace {
16
17 class X11EventSourceLibevent : public X11EventSource,
18 public base::MessagePumpLibevent::Watcher {
19 public:
20 explicit X11EventSourceLibevent(XDisplay* display)
21 : X11EventSource(display),
22 initialized_(false) {
23 AddEventWatcher();
24 }
25
26 ~X11EventSourceLibevent() override {
27 }
28
29 private:
30 void AddEventWatcher() {
31 if (initialized_)
32 return;
33 if (!base::MessageLoop::current())
34 return;
35
36 int fd = ConnectionNumber(display());
37 base::MessageLoopForUI::current()->WatchFileDescriptor(fd, true,
38 base::MessagePumpLibevent::WATCH_READ, &watcher_controller_, this);
39 initialized_ = true;
40 }
41
42 // PlatformEventSource:
43 void OnDispatcherListChanged() override {
44 AddEventWatcher();
45 }
46
47 // base::MessagePumpLibevent::Watcher:
48 void OnFileCanReadWithoutBlocking(int fd) override {
49 DispatchXEvents();
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
64 scoped_ptr<PlatformEventSource> PlatformEventSource::CreateDefault() {
65 return make_scoped_ptr(new X11EventSourceLibevent(gfx::GetXDisplay()));
66 }
67
68 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698