| Index: ui/views/widget/desktop_aura/x11_capture_window.cc
|
| diff --git a/ui/views/widget/desktop_aura/x11_capture_window.cc b/ui/views/widget/desktop_aura/x11_capture_window.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..fe76e92eadb4aee9a621affe799a8fe5fa220fc3
|
| --- /dev/null
|
| +++ b/ui/views/widget/desktop_aura/x11_capture_window.cc
|
| @@ -0,0 +1,73 @@
|
| +// Copyright 2013 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/views/widget/desktop_aura/x11_capture_window.h"
|
| +
|
| +#include <X11/Xlib.h>
|
| +
|
| +#include "ui/events/platform/x11/x11_event_source.h"
|
| +#include "ui/gfx/x/x11_types.h"
|
| +
|
| +namespace views {
|
| +
|
| +X11CaptureWindow::X11CaptureWindow()
|
| + : captured_(false),
|
| + xwindow_(None) {
|
| + Display* display = gfx::GetXDisplay();
|
| + XSetWindowAttributes swa;
|
| + memset(&swa, 0, sizeof(swa));
|
| + swa.event_mask = ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
|
| + LeaveWindowMask | FocusChangeMask | StructureNotifyMask;
|
| + swa.override_redirect = True;
|
| + xwindow_ = XCreateWindow(display,
|
| + DefaultRootWindow(display),
|
| + -100, -100, 10, 10,
|
| + 0,
|
| + CopyFromParent,
|
| + InputOnly,
|
| + CopyFromParent,
|
| + CWEventMask | CWOverrideRedirect,
|
| + &swa);
|
| + XMapRaised(display, xwindow_);
|
| + ui::X11EventSource::GetInstance()->BlockUntilWindowMapped(xwindow_);
|
| +
|
| + unsigned int event_mask = PointerMotionMask | ButtonReleaseMask |
|
| + ButtonPressMask;
|
| + int status = XGrabPointer(display, xwindow_, True, event_mask, GrabModeAsync,
|
| + GrabModeAsync, None, None, CurrentTime);
|
| + captured_ = (status == GrabSuccess);
|
| +
|
| + ui::PlatformEventSource::GetInstance()->
|
| + AddPlatformEventDispatcher(this);
|
| +}
|
| +
|
| +X11CaptureWindow::~X11CaptureWindow() {
|
| + ui::PlatformEventSource::GetInstance()->
|
| + RemovePlatformEventDispatcher(this);
|
| +
|
| + if (captured_)
|
| + XUngrabPointer(gfx::GetXDisplay(), CurrentTime);
|
| + XDestroyWindow(gfx::GetXDisplay(), xwindow_);
|
| +}
|
| +
|
| +bool X11CaptureWindow::CanDispatchEvent(const ui::PlatformEvent& event) {
|
| + return event->xany.window == xwindow_;
|
| +}
|
| +
|
| +uint32_t X11CaptureWindow::DispatchEvent(const ui::PlatformEvent& event) {
|
| + // Stop propagation of events which should not be handled by the
|
| + // DesktopWindowTreeHostX11 which has capture.
|
| + switch (event->type) {
|
| + case MotionNotify:
|
| + case ButtonPress:
|
| + case ButtonRelease:
|
| + case FocusOut:
|
| + case LeaveNotify:
|
| + return ui::POST_DISPATCH_PERFORM_DEFAULT;
|
| + default:
|
| + return ui::POST_DISPATCH_STOP_PROPAGATION;
|
| + }
|
| +}
|
| +
|
| +} // namespace views
|
|
|