BsLinuxWindow.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. /** Unregisters the window from the manager. Should be called before the window is destroyed. */
  74. void _cleanUp();
  75. /**
  76. * Sets a portion of the window in which the user can click and drag in order to move the window. This is needed
  77. * when window has no title bar, yet you still want to allow the user to drag it by clicking on some specific area
  78. * (e.g. a title bar you manually render).
  79. *
  80. * @param[in] rects Areas of the window (relative to the window origin in top-left corner) in which the drag
  81. * operation in allowed.
  82. */
  83. void _setDragZones(const Vector<Rect2I>& rects);
  84. /**
  85. * Notifies the window that user has started dragging the window using a custom drag zone. Provided parameter is the
  86. * event that started the drag.
  87. */
  88. void _dragStart(const XButtonEvent& event);
  89. /** Notifies the window the user has stopped the window drag operation. */
  90. void _dragEnd();
  91. /** Returns the internal X11 window handle. */
  92. ::Window _getXWindow() const;
  93. /** Toggles between fullscreen and windowed mode. */
  94. void _setFullscreen(bool fullscreen);
  95. /** Attaches non-specific user data that can later be retrieved through _getUserData(). */
  96. void _setUserData(void* data);
  97. /** Returns user data attached to the object when _setUserData was called. */
  98. void* _getUserData() const;
  99. /** @} */
  100. private:
  101. /** Checks if the window is currently maximized. */
  102. bool isMaximized() const;
  103. /** Checks if the window is currently minimized (iconified). */
  104. bool isMinimized();
  105. /**
  106. * Maximizes a window if @p enable is true. If false restores the window to size/position before maximization
  107. * occurred.
  108. */
  109. void maximize(bool enable);
  110. /**
  111. * Minimizes a window if @p enable is true. If false restores the window to size/position before minimization
  112. * occurred.
  113. */
  114. void minimize(bool enable);
  115. /** Shows or hides the window icon from the taskbar. */
  116. void showOnTaskbar(bool enable);
  117. /**
  118. * Shows or hides window decorations. Decorations include window title bar, border and similar. Essentially anything
  119. * not part of the main rendering area.
  120. */
  121. void setShowDecorations(bool show);
  122. /**
  123. * Switches the window between modal and normal mode. Modal window prevents input to their parent window until
  124. * it is dismissed.
  125. */
  126. void setIsModal(bool modal);
  127. struct Pimpl;
  128. Pimpl* m;
  129. };
  130. /** @} */
  131. /** @} */
  132. }