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_scoped_capture.h" 6 7#include <X11/X.h> 8#include <X11/Xlib.h> 9 10#include "ui/gfx/x/x11_types.h" 11 12namespace views { 13 14X11ScopedCapture::X11ScopedCapture(XID window) 15 : captured_(false) { 16 // TODO(sad): Use XI2 API instead. 17 unsigned int event_mask = PointerMotionMask | ButtonReleaseMask | 18 ButtonPressMask; 19 int status = XGrabPointer(gfx::GetXDisplay(), window, True, event_mask, 20 GrabModeAsync, GrabModeAsync, None, None, 21 CurrentTime); 22 captured_ = status == GrabSuccess; 23} 24 25X11ScopedCapture::~X11ScopedCapture() { 26 if (captured_) { 27 XUngrabPointer(gfx::GetXDisplay(), CurrentTime); 28 } 29} 30 31} // namespace views 32