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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/views/widget/desktop_aura/x11_capture_window.h"
6
7 #include <X11/Xlib.h>
8
9 #include "ui/events/platform/x11/x11_event_source.h"
10 #include "ui/gfx/x/x11_types.h"
11
12 namespace views {
13
14 X11CaptureWindow::X11CaptureWindow()
15 : captured_(false),
16 xwindow_(None) {
17 Display* display = gfx::GetXDisplay();
18 XSetWindowAttributes swa;
19 memset(&swa, 0, sizeof(swa));
20 swa.event_mask = ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
21 LeaveWindowMask | FocusChangeMask | StructureNotifyMask;
22 swa.override_redirect = True;
23 xwindow_ = XCreateWindow(display,
24 DefaultRootWindow(display),
25 -100, -100, 10, 10,
26 0,
27 CopyFromParent,
28 InputOnly,
29 CopyFromParent,
30 CWEventMask | CWOverrideRedirect,
31 &swa);
32 XMapRaised(display, xwindow_);
33 ui::X11EventSource::GetInstance()->BlockUntilWindowMapped(xwindow_);
34
35 unsigned int event_mask = PointerMotionMask | ButtonReleaseMask |
36 ButtonPressMask;
37 int status = XGrabPointer(display, xwindow_, True, event_mask, GrabModeAsync,
38 GrabModeAsync, None, None, CurrentTime);
39 captured_ = (status == GrabSuccess);
40
41 ui::PlatformEventSource::GetInstance()->
42 AddPlatformEventDispatcher(this);
43 }
44
45 X11CaptureWindow::~X11CaptureWindow() {
46 ui::PlatformEventSource::GetInstance()->
47 RemovePlatformEventDispatcher(this);
48
49 if (captured_)
50 XUngrabPointer(gfx::GetXDisplay(), CurrentTime);
51 XDestroyWindow(gfx::GetXDisplay(), xwindow_);
52 }
53
54 bool X11CaptureWindow::CanDispatchEvent(const ui::PlatformEvent& event) {
55 return event->xany.window == xwindow_;
56 }
57
58 uint32_t X11CaptureWindow::DispatchEvent(const ui::PlatformEvent& event) {
59 // Stop propagation of events which should not be handled by the
60 // DesktopWindowTreeHostX11 which has capture.
61 switch (event->type) {
62 case MotionNotify:
63 case ButtonPress:
64 case ButtonRelease:
65 case FocusOut:
66 case LeaveNotify:
67 return ui::POST_DISPATCH_PERFORM_DEFAULT;
68 default:
69 return ui::POST_DISPATCH_STOP_PROPAGATION;
70 }
71 }
72
73 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698