x_window_property.h 1.9 KB

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