x_window_property.cc (1425B)
1 /* 2 * Copyright (c) 2019 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "modules/desktop_capture/linux/x11/x_window_property.h" 12 13 #include <X11/X.h> 14 #include <X11/Xlib.h> 15 16 namespace webrtc { 17 18 XWindowPropertyBase::XWindowPropertyBase(Display* display, 19 Window window, 20 Atom property, 21 int expected_size) { 22 const int kBitsPerByte = 8; 23 Atom actual_type; 24 int actual_format; 25 unsigned long bytes_after; // NOLINT: type required by XGetWindowProperty 26 int status = XGetWindowProperty(display, window, property, 0L, ~0L, False, 27 AnyPropertyType, &actual_type, &actual_format, 28 &size_, &bytes_after, &data_); 29 if (status != Success) { 30 data_ = nullptr; 31 return; 32 } 33 if ((expected_size * kBitsPerByte) != actual_format) { 34 size_ = 0; 35 return; 36 } 37 38 is_valid_ = true; 39 } 40 41 XWindowPropertyBase::~XWindowPropertyBase() { 42 if (data_) 43 XFree(data_); 44 } 45 46 } // namespace webrtc