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

Unified Diff: ui/views/widget/desktop_aura/x11_capture_window.cc

Issue 380943003: Do not release capture when transferring capture between Chrome windows on Linux (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698