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

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

Issue 1602173005: Add PlatformWindow/Event related code for Ozone X11. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final fixes for comments + tests. 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
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 "base/macros.h" 5 #include "ui/events/platform/x11/x11_event_source_glib.h"
6 #include "ui/events/platform/x11/x11_event_source.h"
7 6
8 #include <glib.h> 7 #include <glib.h>
9 #include <X11/Xlib.h> 8 #include <X11/Xlib.h>
10 9
11 namespace ui { 10 namespace ui {
12 11
13 namespace { 12 namespace {
14 13
15 struct GLibX11Source : public GSource { 14 struct GLibX11Source : public GSource {
16 // Note: The GLibX11Source is created and destroyed by GLib. So its 15 // Note: The GLibX11Source is created and destroyed by GLib. So its
(...skipping 24 matching lines...) Expand all
41 return TRUE; 40 return TRUE;
42 } 41 }
43 42
44 GSourceFuncs XSourceFuncs = { 43 GSourceFuncs XSourceFuncs = {
45 XSourcePrepare, 44 XSourcePrepare,
46 XSourceCheck, 45 XSourceCheck,
47 XSourceDispatch, 46 XSourceDispatch,
48 NULL 47 NULL
49 }; 48 };
50 49
51 class X11EventSourceGlib : public X11EventSource {
52 public:
53 explicit X11EventSourceGlib(XDisplay* display)
54 : X11EventSource(display),
55 x_source_(NULL) {
56 InitXSource(ConnectionNumber(display));
57 }
58
59 ~X11EventSourceGlib() override {
60 g_source_destroy(x_source_);
61 g_source_unref(x_source_);
62 }
63
64 private:
65 void InitXSource(int fd) {
66 CHECK(!x_source_);
67 CHECK(display()) << "Unable to get connection to X server";
68
69 x_poll_.reset(new GPollFD());
70 x_poll_->fd = fd;
71 x_poll_->events = G_IO_IN;
72 x_poll_->revents = 0;
73
74 GLibX11Source* glib_x_source = static_cast<GLibX11Source*>
75 (g_source_new(&XSourceFuncs, sizeof(GLibX11Source)));
76 glib_x_source->display = display();
77 glib_x_source->poll_fd = x_poll_.get();
78
79 x_source_ = glib_x_source;
80 g_source_add_poll(x_source_, x_poll_.get());
81 g_source_set_can_recurse(x_source_, TRUE);
82 g_source_set_callback(x_source_, NULL, this, NULL);
83 g_source_attach(x_source_, g_main_context_default());
84 }
85
86 // The GLib event source for X events.
87 GSource* x_source_;
88
89 // The poll attached to |x_source_|.
90 scoped_ptr<GPollFD> x_poll_;
91
92 DISALLOW_COPY_AND_ASSIGN(X11EventSourceGlib);
93 };
94
95 } // namespace 50 } // namespace
96 51
52 X11EventSourceGlib::X11EventSourceGlib(XDisplay* display)
53 : event_source_(this, display) {
54 InitXSource(ConnectionNumber(display));
55 }
56
57 X11EventSourceGlib::~X11EventSourceGlib() {
58 g_source_destroy(x_source_);
59 g_source_unref(x_source_);
60 }
61
62 void X11EventSourceGlib::ProcessXEvent(XEvent* xevent) {
63 DispatchEvent(xevent);
64 }
65
66 void X11EventSourceGlib::StopCurrentEventStream() {
67 event_source_.StopCurrentEventStream();
68 }
69
70 void X11EventSourceGlib::OnDispatcherListChanged() {
71 event_source_.OnDispatcherListChanged();
72 }
73
74 void X11EventSourceGlib::InitXSource(int fd) {
75 DCHECK(!x_source_);
76 DCHECK(event_source_.display()) << "Unable to get connection to X server";
77
78 x_poll_.reset(new GPollFD());
79 x_poll_->fd = fd;
80 x_poll_->events = G_IO_IN;
81 x_poll_->revents = 0;
82
83 GLibX11Source* glib_x_source = static_cast<GLibX11Source*>(
84 g_source_new(&XSourceFuncs, sizeof(GLibX11Source)));
85 glib_x_source->display = event_source_.display();
86 glib_x_source->poll_fd = x_poll_.get();
87
88 x_source_ = glib_x_source;
89 g_source_add_poll(x_source_, x_poll_.get());
90 g_source_set_can_recurse(x_source_, TRUE);
91 g_source_set_callback(x_source_, NULL, &event_source_, NULL);
92 g_source_attach(x_source_, g_main_context_default());
93 }
94
95 // static
97 scoped_ptr<PlatformEventSource> PlatformEventSource::CreateDefault() { 96 scoped_ptr<PlatformEventSource> PlatformEventSource::CreateDefault() {
98 return make_scoped_ptr(new X11EventSourceGlib(gfx::GetXDisplay())); 97 return make_scoped_ptr(new X11EventSourceGlib(gfx::GetXDisplay()));
99 } 98 }
100 99
101 } // namespace ui 100 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/platform/x11/x11_event_source_glib.h ('k') | ui/events/platform/x11/x11_event_source_libevent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698