| Index: chrome/common/x11_util.cc
|
| diff --git a/chrome/common/x11_util.cc b/chrome/common/x11_util.cc
|
| index 537157356ccdaa2571ead3152beaf6f5903b9b7e..6abcb4ea55d01ad4d5c447bce5729aab4f75a050 100644
|
| --- a/chrome/common/x11_util.cc
|
| +++ b/chrome/common/x11_util.cc
|
| @@ -6,6 +6,8 @@
|
| // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support
|
| // remains woefully incomplete.
|
|
|
| +#include "base/message_loop.h"
|
| +#include "base/message_pump_libevent.h"
|
| #include "base/thread.h"
|
| #include "chrome/common/x11_util.h"
|
| #include "chrome/common/x11_util_internal.h"
|
| @@ -228,12 +230,55 @@ void FreePixmap(Display* display, XID pixmap) {
|
| XFreePixmap(display, pixmap);
|
| }
|
|
|
| +// This class gets callbacks when the X file descriptor is ready for reading.
|
| +class XEventHandler : public base::MessagePumpLibevent::Watcher {
|
| + public:
|
| + XEventHandler(Display* display, int x_fd)
|
| + : display_(display),
|
| + x_fd_(x_fd) {
|
| + }
|
| +
|
| + void OnFileCanReadWithoutBlocking(int fd) {
|
| + DCHECK_EQ(fd, x_fd_);
|
| +
|
| + while (true) {
|
| + XEvent event;
|
| + if (!XCheckMaskEvent(
|
| + display_, 0x8fffffff /* all ones, but still positive in 32-bits */,
|
| + &event)) {
|
| + return;
|
| + }
|
| +
|
| + LOG(INFO) << "Got X event";
|
| + }
|
| + }
|
| +
|
| + void OnFileCanWriteWithoutBlocking(int fd) {
|
| + CHECK(false);
|
| + }
|
| +
|
| + private:
|
| + Display* const display_;
|
| + const int x_fd_;
|
| +};
|
| +
|
| // Called on BACKGROUND_X11 thread.
|
| Display* GetSecondaryDisplay() {
|
| static Display* display = NULL;
|
| + static base::MessagePumpLibevent::FileDescriptorWatcher* watcher = NULL;
|
| + static XEventHandler* x_event_handler = NULL;
|
| +
|
| if (!display) {
|
| display = XOpenDisplay(NULL);
|
| CHECK(display);
|
| +
|
| + watcher = new base::MessagePumpLibevent::FileDescriptorWatcher;
|
| + const int x_fd = XConnectionNumber(display);
|
| + x_event_handler = new XEventHandler(display, x_fd);
|
| +
|
| + MessageLoopForIO::current()->WatchFileDescriptor(
|
| + x_fd, true, MessageLoopForIO::WATCH_READ, watcher,
|
| + x_event_handler);
|
| }
|
|
|
| return display;
|
|
|