Line data Source code
1 : /*
2 : * Copyright (c) 2014 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 WEBRTC_MODULES_DESKTOP_CAPTURE_X11_SHARED_X_UTIL_H_
12 : #define WEBRTC_MODULES_DESKTOP_CAPTURE_X11_SHARED_X_UTIL_H_
13 :
14 : #include "webrtc/system_wrappers/include/atomic32.h"
15 : #include "webrtc/modules/desktop_capture/x11/shared_x_display.h"
16 : #include "webrtc/system_wrappers/include/logging.h"
17 : #include <unistd.h>
18 : #include <string.h>
19 :
20 : #include <map>
21 : #include <vector>
22 : #include <vector>
23 : #include <algorithm>
24 :
25 : #include <assert.h>
26 : #include <X11/Xlib.h>
27 :
28 : #include <X11/Xatom.h>
29 : #include <X11/extensions/Xcomposite.h>
30 : #include <X11/extensions/Xrender.h>
31 : #include <X11/Xutil.h>
32 : #include <string>
33 :
34 : namespace webrtc {
35 :
36 : //===============================================================================
37 : // Moved common code from window_capture_x11.cc to better reuse throughout module
38 :
39 : // Convenience wrapper for XGetWindowProperty() results.
40 : template <class PropertyType>
41 : class XWindowProperty {
42 : public:
43 0 : XWindowProperty(Display* display, Window window, Atom property) :
44 : is_valid_(false),
45 : size_(0),
46 0 : data_(NULL) {
47 0 : const int kBitsPerByte = 8;
48 : Atom actual_type;
49 : int actual_format;
50 : unsigned long bytes_after; // NOLINT: type required by XGetWindowProperty
51 0 : int status = XGetWindowProperty(display, window, property, 0L, ~0L, False,
52 : AnyPropertyType, &actual_type,
53 : &actual_format, &size_,
54 0 : &bytes_after, &data_);
55 0 : if (status != Success) {
56 0 : data_ = NULL;
57 0 : return;
58 : }
59 0 : if (sizeof(PropertyType) * kBitsPerByte != actual_format) {
60 0 : size_ = 0;
61 0 : return;
62 : }
63 :
64 0 : is_valid_ = true;
65 : }
66 :
67 0 : ~XWindowProperty() {
68 0 : if (data_) {
69 0 : XFree(data_);
70 : }
71 0 : }
72 :
73 : // True if we got properly value successfully.
74 0 : bool is_valid() const { return is_valid_; }
75 :
76 : // Size and value of the property.
77 0 : size_t size() const { return size_; }
78 : const PropertyType* data() const {
79 : return reinterpret_cast<PropertyType*>(data_);
80 : }
81 0 : PropertyType* data() {
82 0 : return reinterpret_cast<PropertyType*>(data_);
83 : }
84 :
85 : private:
86 : bool is_valid_;
87 : unsigned long size_; // NOLINT: type required by XGetWindowProperty
88 : unsigned char* data_;
89 :
90 : RTC_DISALLOW_COPY_AND_ASSIGN(XWindowProperty);
91 : };
92 :
93 : class WindowUtilX11 {
94 : public:
95 : WindowUtilX11(rtc::scoped_refptr<SharedXDisplay> x_display);
96 : ~WindowUtilX11();
97 : // Iterates through |window| hierarchy to find first visible window, i.e. one
98 : // that has WM_STATE property set to NormalState.
99 : // See http://tronche.com/gui/x/icccm/sec-4.html#s-4.1.3.1 .
100 : ::Window GetApplicationWindow(::Window window);
101 : // Returns true if the |window| is a desktop element.
102 : bool IsDesktopElement(::Window window);
103 : // Returns window title for the specified X |window|.
104 : bool GetWindowTitle(::Window window, std::string* title);
105 : bool BringWindowToFront(::Window window);
106 : int GetWindowProcessID(::Window window);
107 : int32_t GetWindowStatus(::Window window);
108 : bool GetWindowRect(::Window window, XRectangle &rcWindow,bool bWithFrame);
109 : bool GetWindowFrameExtents(::Window window, int32_t &left, int32_t &top, int32_t &right, int32_t &bottom);
110 :
111 : protected:
112 0 : Display* display() { return x_display_->display(); }
113 :
114 : rtc::scoped_refptr<SharedXDisplay> x_display_;
115 : Atom wm_state_atom_;
116 : Atom window_type_atom_;
117 : Atom normal_window_type_atom_;
118 : Atom process_atom_;
119 : Atom frame_extends_atom_;
120 : };
121 :
122 : } // namespace webrtc
123 :
124 : #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_X11_SHARED_X_UTIL_H_
|