BsLinuxWindow.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "Prerequisites/BsPrerequisitesUtil.h"
  5. #include "Math/BsVector2I.h"
  6. #include <X11/X.h>
  7. #include <X11/Xutil.h>
  8. namespace bs
  9. {
  10. /** @addtogroup Internal-Utility
  11. * @{
  12. */
  13. /** @addtogroup Platform-Utility-Internal
  14. * @{
  15. */
  16. /** Descriptor used for creating a platform specific native window. */
  17. struct WINDOW_DESC
  18. {
  19. INT32 x, y;
  20. UINT32 width, height;
  21. UINT32 screen;
  22. String title;
  23. bool showDecorations;
  24. bool allowResize;
  25. bool modal;
  26. bool showOnTaskBar;
  27. ::Window parent;
  28. XVisualInfo visualInfo;
  29. SPtr<PixelData> background;
  30. };
  31. /**
  32. * Represents a X11 window. Note that all accesses (including creation and destruction) to objects of this class must
  33. * be locked by the main X11 lock accessible through LinuxPlatform.
  34. */
  35. class BS_UTILITY_EXPORT LinuxWindow
  36. {
  37. public:
  38. LinuxWindow(const WINDOW_DESC& desc);
  39. ~LinuxWindow();
  40. /** Returns position of the left-most border of the window, relative to the screen. */
  41. INT32 getLeft() const;
  42. /** Returns position of the top-most border of the window, relative to the screen. */
  43. INT32 getTop() const;
  44. /** Returns width of the window in pixels. */
  45. UINT32 getWidth() const;
  46. /** Returns height of the window in pixels. */
  47. UINT32 getHeight() const;
  48. /** Hides the window. */
  49. void hide();
  50. /** Shows (unhides) the window. */
  51. void show();
  52. /** Minimizes the window. */
  53. void minimize();
  54. /** Maximizes the window over the entire current screen. */
  55. void maximize();
  56. /** Restores the window to original position and size if it is minimized or maximized. */
  57. void restore();
  58. /** Closes the window. Window becomes unusable past this call. */
  59. void close();
  60. /** Change the size of the window. */
  61. void resize(UINT32 width, UINT32 height);
  62. /** Reposition the window. */
  63. void move(INT32 left, INT32 top);
  64. /** Sets the icon to display for the window. */
  65. void setIcon(const PixelData& icon);
  66. /** Converts screen position into window local position. */
  67. Vector2I screenToWindowPos(const Vector2I& screenPos) const;
  68. /** Converts window local position to screen position. */
  69. Vector2I windowToScreenPos(const Vector2I& windowPos) const;
  70. /**
  71. * @name Internal
  72. * @{
  73. */
  74. /** Unregisters the window from the manager. Should be called before the window is destroyed. */
  75. void _cleanUp();
  76. /**
  77. * Sets a portion of the window in which the user can click and drag in order to move the window. This is needed
  78. * when window has no title bar, yet you still want to allow the user to drag it by clicking on some specific area
  79. * (e.g. a title bar you manually render).
  80. *
  81. * @param[in] rect Area of the window (relative to the window origin in top-left corner) in which the drag
  82. * operation in allowed.
  83. */
  84. void _setDragZone(const Rect2I& rect);
  85. /**
  86. * Notifies the window that user has started dragging the window using the custom drag zone. Provided coordinates
  87. * specify the location of the drag start. They are relative to the window top left origin.
  88. */
  89. bool _dragStart(int32_t x, int32_t y);
  90. /**
  91. * Notifies the window that the user has moved the cursor while dragging the window. The provided coordinates are
  92. * relative to the window top left origin.
  93. */
  94. void _dragUpdate(int32_t x, int32_t y);
  95. /** Notifies the window the user has stopped the window drag operation. */
  96. void _dragEnd();
  97. /** Returns the internal X11 window handle. */
  98. ::Window _getXWindow() const;
  99. /** Toggles between fullscreen and windowed mode. */
  100. void _setFullscreen(bool fullscreen);
  101. /** Attaches non-specific user data that can later be retrieved through _getUserData(). */
  102. void _setUserData(void* data);
  103. /** Returns user data attached to the object when _setUserData was called. */
  104. void* _getUserData() const;
  105. /** @} */
  106. private:
  107. /** Checks if the window is currently maximized. */
  108. bool isMaximized() const;
  109. /** Checks if the window is currently minimized (iconified). */
  110. bool isMinimized();
  111. /**
  112. * Maximizes a window if @p enable is true. If false restores the window to size/position before maximization
  113. * occurred.
  114. */
  115. void maximize(bool enable);
  116. /**
  117. * Minimizes a window if @p enable is true. If false restores the window to size/position before minimization
  118. * occurred.
  119. */
  120. void minimize(bool enable);
  121. /** Shows or hides the window icon from the taskbar. */
  122. void showOnTaskbar(bool enable);
  123. /**
  124. * Shows or hides window decorations. Decorations include window title bar, border and similar. Essentially anything
  125. * not part of the main rendering area.
  126. */
  127. void setShowDecorations(bool show);
  128. /**
  129. * Switches the window between modal and normal mode. Modal window prevents input to their parent window until
  130. * it is dismissed.
  131. */
  132. void setIsModal(bool modal);
  133. struct Pimpl;
  134. Pimpl* m;
  135. };
  136. /** @} */
  137. /** @} */
  138. }