blob: e5b5d5088212b969641474f9e332237860fc6856 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
2 * Copyright 2004 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_BASE_WINDOW_H_
12#define WEBRTC_BASE_WINDOW_H_
13
pbos7fd1a752017-01-02 06:58:46 -080014#include <stdint.h>
15
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000016#include "webrtc/base/stringencode.h"
17
18// Define platform specific window types.
19#if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID)
20typedef unsigned long Window; // Avoid include <X11/Xlib.h>.
21#elif defined(WEBRTC_WIN)
22// We commonly include win32.h in webrtc/base so just include it here.
23#include "webrtc/base/win32.h" // Include HWND, HMONITOR.
24#elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
25typedef unsigned int CGWindowID;
26typedef unsigned int CGDirectDisplayID;
27#endif
28
29namespace rtc {
30
31class WindowId {
32 public:
33 // Define WindowT for each platform.
34#if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID)
35 typedef Window WindowT;
36#elif defined(WEBRTC_WIN)
37 typedef HWND WindowT;
38#elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
39 typedef CGWindowID WindowT;
40#else
41 typedef unsigned int WindowT;
42#endif
43
Peter Boström0c4e06b2015-10-07 12:23:21 +020044 static WindowId Cast(uint64_t id) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000045#if defined(WEBRTC_WIN)
46 return WindowId(reinterpret_cast<WindowId::WindowT>(id));
47#else
48 return WindowId(static_cast<WindowId::WindowT>(id));
49#endif
50 }
51
Peter Boström0c4e06b2015-10-07 12:23:21 +020052 static uint64_t Format(const WindowT& id) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000053#if defined(WEBRTC_WIN)
Peter Boström0c4e06b2015-10-07 12:23:21 +020054 return static_cast<uint64_t>(reinterpret_cast<uintptr_t>(id));
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000055#else
Peter Boström0c4e06b2015-10-07 12:23:21 +020056 return static_cast<uint64_t>(id);
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000057#endif
58 }
59
60 WindowId() : id_(0) {}
61 WindowId(const WindowT& id) : id_(id) {} // NOLINT
62 const WindowT& id() const { return id_; }
63 bool IsValid() const { return id_ != 0; }
64 bool Equals(const WindowId& other) const {
65 return id_ == other.id();
66 }
67
68 private:
69 WindowT id_;
70};
71
72class DesktopId {
73 public:
74 // Define DesktopT for each platform.
75#if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID)
76 typedef Window DesktopT;
77#elif defined(WEBRTC_WIN)
78 typedef HMONITOR DesktopT;
79#elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
80 typedef CGDirectDisplayID DesktopT;
81#else
82 typedef unsigned int DesktopT;
83#endif
84
85 static DesktopId Cast(int id, int index) {
86#if defined(WEBRTC_WIN)
87 return DesktopId(reinterpret_cast<DesktopId::DesktopT>(id), index);
88#else
89 return DesktopId(static_cast<DesktopId::DesktopT>(id), index);
90#endif
91 }
92
93 DesktopId() : id_(0), index_(-1) {}
94 DesktopId(const DesktopT& id, int index) // NOLINT
95 : id_(id), index_(index) {
96 }
97 const DesktopT& id() const { return id_; }
98 int index() const { return index_; }
99 bool IsValid() const { return index_ != -1; }
100 bool Equals(const DesktopId& other) const {
101 return id_ == other.id() && index_ == other.index();
102 }
103
104 private:
105 // Id is the platform specific desktop identifier.
106 DesktopT id_;
107 // Index is the desktop index as enumerated by each platform.
108 // Desktop capturer typically takes the index instead of id.
109 int index_;
110};
111
112// Window event types.
113enum WindowEvent {
114 WE_RESIZE = 0,
115 WE_CLOSE = 1,
116 WE_MINIMIZE = 2,
117 WE_RESTORE = 3,
118};
119
120inline std::string ToString(const WindowId& window) {
121 return ToString(window.id());
122}
123
124} // namespace rtc
125
126#endif // WEBRTC_BASE_WINDOW_H_