You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
3.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2004--2005, Google Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  22. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  23. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  24. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef TALK_BASE_WINDOW_H_
  28. #define TALK_BASE_WINDOW_H_
  29. #include "talk/base/stringencode.h"
  30. // Define platform specific window types.
  31. #if defined(LINUX)
  32. typedef unsigned long Window; // Avoid include <X11/Xlib.h>.
  33. #elif defined(WIN32)
  34. // We commonly include win32.h in talk/base so just include it here.
  35. #include "talk/base/win32.h" // Include HWND, HMONITOR.
  36. #elif defined(OSX)
  37. typedef unsigned int CGWindowID;
  38. typedef unsigned int CGDirectDisplayID;
  39. #endif
  40. namespace talk_base {
  41. class WindowId {
  42. public:
  43. // Define WindowT for each platform.
  44. #if defined(LINUX)
  45. typedef Window WindowT;
  46. #elif defined(WIN32)
  47. typedef HWND WindowT;
  48. #elif defined(OSX)
  49. typedef CGWindowID WindowT;
  50. #else
  51. typedef unsigned int WindowT;
  52. #endif
  53. static WindowId Cast(int id) {
  54. #if defined(WIN32)
  55. return WindowId(reinterpret_cast<WindowId::WindowT>(id));
  56. #else
  57. return WindowId(static_cast<WindowId::WindowT>(id));
  58. #endif
  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. private:
  68. WindowT id_;
  69. };
  70. class DesktopId {
  71. public:
  72. // Define DesktopT for each platform.
  73. #if defined(LINUX)
  74. typedef Window DesktopT;
  75. #elif defined(WIN32)
  76. typedef HMONITOR DesktopT;
  77. #elif defined(OSX)
  78. typedef CGDirectDisplayID DesktopT;
  79. #else
  80. typedef unsigned int DesktopT;
  81. #endif
  82. static DesktopId Cast(int id, int index) {
  83. #if defined(WIN32)
  84. return DesktopId(reinterpret_cast<DesktopId::DesktopT>(id), index);
  85. #else
  86. return DesktopId(static_cast<DesktopId::DesktopT>(id), index);
  87. #endif
  88. }
  89. DesktopId() : id_(0), index_(-1) {}
  90. DesktopId(const DesktopT& id, int index) // NOLINT
  91. : id_(id), index_(index) {
  92. }
  93. const DesktopT& id() const { return id_; }
  94. int index() const { return index_; }
  95. bool IsValid() const { return index_ != -1; }
  96. bool Equals(const DesktopId& other) const {
  97. return id_ == other.id() && index_ == other.index();
  98. }
  99. private:
  100. // Id is the platform specific desktop identifier.
  101. DesktopT id_;
  102. // Index is the desktop index as enumerated by each platform.
  103. // Desktop capturer typically takes the index instead of id.
  104. int index_;
  105. };
  106. // Window event types.
  107. enum WindowEvent {
  108. WE_RESIZE = 0,
  109. WE_CLOSE = 1,
  110. WE_MINIMIZE = 2,
  111. WE_RESTORE = 3,
  112. };
  113. inline std::string ToString(const WindowId& window) {
  114. return ToString(window.id());
  115. }
  116. } // namespace talk_base
  117. #endif // TALK_BASE_WINDOW_H_