BsLinuxWindow.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. bool hidden;
  28. ::Window parent;
  29. XVisualInfo visualInfo;
  30. SPtr<PixelData> background;
  31. };
  32. /**
  33. * Represents a X11 window. Note that all accesses (including creation and destruction) to objects of this class must
  34. * be locked by the main X11 lock accessible through LinuxPlatform.
  35. */
  36. class BS_UTILITY_EXPORT LinuxWindow
  37. {
  38. public:
  39. LinuxWindow(const WINDOW_DESC& desc);
  40. ~LinuxWindow();
  41. /** Returns position of the left-most border of the window, relative to the screen. */
  42. INT32 getLeft() const;
  43. /** Returns position of the top-most border of the window, relative to the screen. */
  44. INT32 getTop() const;
  45. /** Returns width of the window in pixels. */
  46. UINT32 getWidth() const;
  47. /** Returns height of the window in pixels. */
  48. UINT32 getHeight() const;
  49. /** Hides the window. */
  50. void hide();
  51. /** Shows (unhides) the window. */
  52. void show();
  53. /** Minimizes the window. */
  54. void minimize();
  55. /** Maximizes the window over the entire current screen. */
  56. void maximize();
  57. /** Restores the window to original position and size if it is minimized or maximized. */
  58. void restore();
  59. /** Change the size of the window. */
  60. void resize(UINT32 width, UINT32 height);
  61. /** Reposition the window. */
  62. void move(INT32 left, INT32 top);
  63. /** Sets the icon to display for the window. */
  64. void setIcon(const PixelData& icon);
  65. /** Converts screen position into window local position. */
  66. Vector2I screenToWindowPos(const Vector2I& screenPos) const;
  67. /** Converts window local position to screen position. */
  68. Vector2I windowToScreenPos(const Vector2I& windowPos) const;
  69. /**
  70. * @name Internal
  71. * @{
  72. */
  73. /**
  74. * Destroys the window, cleaning up any resources and removing it from the display. No further methods should be
  75. * called on this object after it has been destroyed.
  76. */
  77. void _destroy();
  78. /**
  79. * Sets a portion of the window in which the user can click and drag in order to move the window. This is needed
  80. * when window has no title bar, yet you still want to allow the user to drag it by clicking on some specific area
  81. * (e.g. a title bar you manually render).
  82. *
  83. * @param[in] rects Areas of the window (relative to the window origin in top-left corner) in which the drag
  84. * operation in allowed.
  85. */
  86. void _setDragZones(const Vector<Rect2I>& rects);
  87. /**
  88. * Notifies the window that user has started dragging the window using a custom drag zone. Provided parameter is the
  89. * event that started the drag.
  90. */
  91. void _dragStart(const XButtonEvent& event);
  92. /** Notifies the window the user has stopped the window drag operation. */
  93. void _dragEnd();
  94. /** Returns the internal X11 window handle. */
  95. ::Window _getXWindow() const;
  96. /** Toggles between fullscreen and windowed mode. */
  97. void _setFullscreen(bool fullscreen);
  98. /** Attaches non-specific user data that can later be retrieved through _getUserData(). */
  99. void _setUserData(void* data);
  100. /** Returns user data attached to the object when _setUserData was called. */
  101. void* _getUserData() const;
  102. /** @} */
  103. private:
  104. /** Checks if the window is currently maximized. */
  105. bool isMaximized() const;
  106. /** Checks if the window is currently minimized (iconified). */
  107. bool isMinimized();
  108. /**
  109. * Maximizes a window if @p enable is true. If false restores the window to size/position before maximization
  110. * occurred.
  111. */
  112. void maximize(bool enable);
  113. /**
  114. * Minimizes a window if @p enable is true. If false restores the window to size/position before minimization
  115. * occurred.
  116. */
  117. void minimize(bool enable);
  118. /** Shows or hides the window icon from the taskbar. */
  119. void showOnTaskbar(bool enable);
  120. /**
  121. * Shows or hides window decorations. Decorations include window title bar, border and similar. Essentially anything
  122. * not part of the main rendering area.
  123. */
  124. void setShowDecorations(bool show);
  125. /**
  126. * Switches the window between modal and normal mode. Modal window prevents input to their parent window until
  127. * it is dismissed.
  128. */
  129. void setIsModal(bool modal);
  130. struct Pimpl;
  131. Pimpl* m;
  132. };
  133. /** @} */
  134. /** @} */
  135. }