1 /*
2  *  Copyright (c) 2017 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_WINDOW_LIST_UTILS_H_
12 #define MODULES_DESKTOP_CAPTURE_LINUX_WINDOW_LIST_UTILS_H_
13 
14 #include <X11/X.h>
15 #include <X11/Xlib.h>
16 #include <stdint.h>
17 
18 #include "api/function_view.h"
19 #include "modules/desktop_capture/desktop_geometry.h"
20 #include "modules/desktop_capture/linux/x_atom_cache.h"
21 
22 namespace webrtc {
23 
24 // Synchronously iterates all on-screen windows in |cache|.display() in
25 // decreasing z-order and sends them one-by-one to |on_window| function before
26 // GetWindowList() returns. If |on_window| returns false, this function ignores
27 // other windows and returns immediately. GetWindowList() returns false if
28 // native APIs failed. If multiple screens are attached to the |display|, this
29 // function returns false only when native APIs failed on all screens. Menus,
30 // panels and minimized windows will be ignored.
31 bool GetWindowList(XAtomCache* cache,
32                    rtc::FunctionView<bool(::Window)> on_window);
33 
34 // Returns WM_STATE property of the |window|. This function returns
35 // WithdrawnState if the |window| is missing.
36 int32_t GetWindowState(XAtomCache* cache, ::Window window);
37 
38 // Returns the rectangle of the |window| in the coordinates of |display|. This
39 // function returns false if native APIs failed. If |attributes| is provided, it
40 // will be filled with the attributes of |window|. The |rect| is in system
41 // coordinate, i.e. the primary monitor always starts from (0, 0).
42 bool GetWindowRect(::Display* display,
43                    ::Window window,
44                    DesktopRect* rect,
45                    XWindowAttributes* attributes = nullptr);
46 
47 // Creates a DesktopRect from |attributes|.
48 template <typename T>
DesktopRectFromXAttributes(const T & attributes)49 DesktopRect DesktopRectFromXAttributes(const T& attributes) {
50   return DesktopRect::MakeXYWH(attributes.x, attributes.y, attributes.width,
51                                attributes.height);
52 }
53 
54 }  // namespace webrtc
55 
56 #endif  // MODULES_DESKTOP_CAPTURE_LINUX_WINDOW_LIST_UTILS_H_
57