| Index: ui/base/x/x11_window_cache_event_source.cc
|
| diff --git a/ui/base/x/x11_window_cache_event_source.cc b/ui/base/x/x11_window_cache_event_source.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2a5ce752d544d7b442ce67ae445011b405b01f45
|
| --- /dev/null
|
| +++ b/ui/base/x/x11_window_cache_event_source.cc
|
| @@ -0,0 +1,68 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "ui/base/x/x11_window_cache_event_source.h"
|
| +
|
| +#include <glib.h>
|
| +
|
| +#include "base/logging.h"
|
| +#include "ui/base/x/x11_window_cache.h"
|
| +
|
| +namespace ui {
|
| +
|
| +namespace {
|
| +
|
| +struct GLibXcbSource : public GSource {
|
| + GPollFD* poll_fd;
|
| +};
|
| +
|
| +gboolean callback(gpointer data) {
|
| + XWindowCache* cache = reinterpret_cast<XWindowCache*>(data);
|
| + cache->OnConnectionReadable();
|
| + return !cache->ConnectionHasError();
|
| +}
|
| +
|
| +gboolean prepare(GSource* source, gint* timeout) {
|
| + *timeout = -1;
|
| + return FALSE;
|
| +}
|
| +
|
| +gboolean check(GSource* source) {
|
| + return static_cast<GLibXcbSource*>(source)->poll_fd->revents & G_IO_IN;
|
| +}
|
| +
|
| +gboolean dispatch(GSource* source, GSourceFunc callback, gpointer data) {
|
| + return callback(data);
|
| +}
|
| +
|
| +GSourceFuncs source_funcs {prepare, check, dispatch, nullptr};
|
| +
|
| +} // anonymous namespace
|
| +
|
| +XWindowCacheEventSource::XWindowCacheEventSource(XWindowCache* cache) {
|
| + DCHECK(!cache->ConnectionHasError());
|
| + int fd = cache->ConnectionFd();
|
| +
|
| + GPollFD* poll = new GPollFD();
|
| + g_poll_.reset(poll);
|
| + poll->fd = fd;
|
| + poll->events = G_IO_IN;
|
| + poll->revents = 0;
|
| +
|
| + GLibXcbSource* g_source = static_cast<GLibXcbSource*>(
|
| + g_source_new(&source_funcs, sizeof(GLibXcbSource)));
|
| + g_source_ = g_source;
|
| + g_source->poll_fd = poll;
|
| + g_source_add_poll(g_source, poll);
|
| + g_source_set_can_recurse(g_source, TRUE);
|
| + g_source_set_callback(g_source, callback, cache, nullptr);
|
| + g_source_attach(g_source, g_main_context_default());
|
| +}
|
| +
|
| +XWindowCacheEventSource::~XWindowCacheEventSource() {
|
| + g_source_destroy(g_source_);
|
| + g_source_unref(g_source_);
|
| +}
|
| +
|
| +} // namespace ui
|
|
|