OLD | NEW |
(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 |
| 11 namespace views { |
| 12 |
| 13 X11CaptureWindow::X11CaptureWindow() |
| 14 : captured_(false), |
| 15 xwindow_(None) { |
| 16 Display* display = gfx::GetXDisplay(); |
| 17 XSetWindowAttributes swa; |
| 18 memset(&swa, 0, sizeof(swa)); |
| 19 swa.event_mask = ButtonPressMask | ButtonReleaseMask | PointerMotionMask | |
| 20 LeaveWindowMask | FocusChangeMask | StructureNotifyMask; |
| 21 swa.override_redirect = True; |
| 22 xwindow_ = XCreateWindow(display, |
| 23 DefaultRootWindow(display), |
| 24 -100, -100, 10, 10, |
| 25 0, |
| 26 CopyFromParent, |
| 27 InputOnly, |
| 28 CopyFromParent, |
| 29 CWEventMask | CWOverrideRedirect, |
| 30 &swa); |
| 31 XMapRaised(display, xwindow_); |
| 32 ui::X11EventSource::GetInstance()->BlockUntilWindowMapped(xwindow_); |
| 33 |
| 34 unsigned int event_mask = PointerMotionMask | ButtonReleaseMask | |
| 35 ButtonPressMask; |
| 36 int status = XGrabPointer(display, xwindow_, True, event_mask, GrabModeAsync, |
| 37 GrabModeAsync, None, None, CurrentTime); |
| 38 captured_ = (status == GrabSuccess); |
| 39 } |
| 40 |
| 41 X11CaptureWindow::~X11CaptureWindow() { |
| 42 if (captured_) |
| 43 XUngrabPointer(gfx::GetXDisplay(), CurrentTime); |
| 44 XDestroyWindow(gfx::GetXDisplay(), xwindow_); |
| 45 } |
| 46 |
| 47 bool X11CaptureWindow::CanDispatchEventToOwner(const ui::PlatformEvent& event) { |
| 48 if (event->xany.window != xwindow_) |
| 49 return false; |
| 50 switch (event->type) { |
| 51 case MotionNotify: |
| 52 case ButtonPress: |
| 53 case ButtonRelease: |
| 54 case FocusOut: |
| 55 case LeaveNotify: |
| 56 return true; |
| 57 default: |
| 58 return false; |
| 59 } |
| 60 return false; |
| 61 } |
| 62 |
| 63 } // namespace views |
OLD | NEW |