tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

x_window_property.h (2044B)


      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 #ifndef MODULES_DESKTOP_CAPTURE_LINUX_X11_X_WINDOW_PROPERTY_H_
     12 #define MODULES_DESKTOP_CAPTURE_LINUX_X11_X_WINDOW_PROPERTY_H_
     13 
     14 #include <X11/X.h>
     15 #include <X11/Xlib.h>
     16 
     17 #include <cstddef>
     18 
     19 namespace webrtc {
     20 
     21 class XWindowPropertyBase {
     22 public:
     23  XWindowPropertyBase(Display* display,
     24                      Window window,
     25                      Atom property,
     26                      int expected_size);
     27  virtual ~XWindowPropertyBase();
     28 
     29  XWindowPropertyBase(const XWindowPropertyBase&) = delete;
     30  XWindowPropertyBase& operator=(const XWindowPropertyBase&) = delete;
     31 
     32  // True if we got properly value successfully.
     33  bool is_valid() const { return is_valid_; }
     34 
     35  // Size and value of the property.
     36  size_t size() const { return size_; }
     37 
     38 protected:
     39  unsigned char* data_ = nullptr;
     40 
     41 private:
     42  bool is_valid_ = false;
     43  unsigned long size_ = 0;  // NOLINT: type required by XGetWindowProperty
     44 };
     45 
     46 // Convenience wrapper for XGetWindowProperty() results.
     47 template <class PropertyType>
     48 class XWindowProperty : public XWindowPropertyBase {
     49 public:
     50  XWindowProperty(Display* display, const Window window, const Atom property)
     51      : XWindowPropertyBase(display, window, property, sizeof(PropertyType)) {}
     52  ~XWindowProperty() override = default;
     53 
     54  XWindowProperty(const XWindowProperty&) = delete;
     55  XWindowProperty& operator=(const XWindowProperty&) = delete;
     56 
     57  const PropertyType* data() const {
     58    return reinterpret_cast<PropertyType*>(data_);
     59  }
     60  PropertyType* data() { return reinterpret_cast<PropertyType*>(data_); }
     61 };
     62 
     63 }  // namespace webrtc
     64 
     65 #endif  // MODULES_DESKTOP_CAPTURE_LINUX_X11_X_WINDOW_PROPERTY_H_