The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

268 lines
10KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. namespace XWindowSystemUtilities
  22. {
  23. //==============================================================================
  24. /** A handy struct that uses XLockDisplay and XUnlockDisplay to lock the X server
  25. using RAII.
  26. @tags{GUI}
  27. */
  28. struct ScopedXLock
  29. {
  30. ScopedXLock();
  31. ~ScopedXLock();
  32. };
  33. //==============================================================================
  34. /** Gets a specified window property and stores its associated data, freeing it
  35. on deletion.
  36. @tags{GUI}
  37. */
  38. struct GetXProperty
  39. {
  40. GetXProperty (::Window windowH, Atom property, long offset,
  41. long length, bool shouldDelete, Atom requestedType);
  42. ~GetXProperty();
  43. bool success = false;
  44. unsigned char* data = nullptr;
  45. unsigned long numItems = 0, bytesLeft = 0;
  46. Atom actualType;
  47. int actualFormat = -1;
  48. };
  49. //==============================================================================
  50. /** Initialises and stores some atoms for the display.
  51. @tags{GUI}
  52. */
  53. struct Atoms
  54. {
  55. enum ProtocolItems
  56. {
  57. TAKE_FOCUS = 0,
  58. DELETE_WINDOW = 1,
  59. PING = 2
  60. };
  61. Atoms() = default;
  62. explicit Atoms (::Display*);
  63. static Atom getIfExists (::Display*, const char* name);
  64. static Atom getCreating (::Display*, const char* name);
  65. static String getName (::Display*, Atom);
  66. static bool isMimeTypeFile (::Display*, Atom);
  67. static constexpr unsigned long DndVersion = 3;
  68. Atom protocols, protocolList[3], changeState, state, userTime, activeWin, pid, windowType, windowState, windowStateHidden,
  69. XdndAware, XdndEnter, XdndLeave, XdndPosition, XdndStatus, XdndDrop, XdndFinished, XdndSelection,
  70. XdndTypeList, XdndActionList, XdndActionDescription, XdndActionCopy, XdndActionPrivate,
  71. XembedMsgType, XembedInfo, allowedActions[5], allowedMimeTypes[4], utf8String, clipboard, targets;
  72. };
  73. }
  74. //==============================================================================
  75. class LinuxComponentPeer;
  76. class XWindowSystem : public DeletedAtShutdown
  77. {
  78. public:
  79. //==============================================================================
  80. ::Window createWindow (::Window parentWindow, LinuxComponentPeer*) const;
  81. void destroyWindow (::Window);
  82. void setTitle (::Window, const String&) const;
  83. void setIcon (::Window , const Image&) const;
  84. void setVisible (::Window, bool shouldBeVisible) const;
  85. void setBounds (::Window, Rectangle<int>, bool fullScreen) const;
  86. BorderSize<int> getBorderSize (::Window) const;
  87. Rectangle<int> getWindowBounds (::Window, ::Window parentWindow);
  88. Point<int> getPhysicalParentScreenPosition() const;
  89. bool contains (::Window, Point<int> localPos) const;
  90. void setMinimised (::Window, bool shouldBeMinimised) const;
  91. bool isMinimised (::Window) const;
  92. void setMaximised (::Window, bool shouldBeMinimised) const;
  93. void toFront (::Window, bool makeActive) const;
  94. void toBehind (::Window, ::Window otherWindow) const;
  95. bool isFocused (::Window) const;
  96. bool grabFocus (::Window) const;
  97. bool canUseSemiTransparentWindows() const;
  98. bool canUseARGBImages() const;
  99. int getNumPaintsPendingForWindow (::Window);
  100. void processPendingPaintsForWindow (::Window);
  101. void addPendingPaintForWindow (::Window);
  102. void removePendingPaintForWindow (::Window);
  103. Image createImage (bool isSemiTransparentWindow, int width, int height, bool argb) const;
  104. void blitToWindow (::Window, Image, Rectangle<int> destinationRect, Rectangle<int> totalRect) const;
  105. void setScreenSaverEnabled (bool enabled) const;
  106. Point<float> getCurrentMousePosition() const;
  107. void setMousePosition (Point<float> pos) const;
  108. void* createCustomMouseCursorInfo (const Image&, Point<int> hotspot) const;
  109. void deleteMouseCursor (void* cursorHandle) const;
  110. void* createStandardMouseCursor (MouseCursor::StandardCursorType) const;
  111. void showCursor (::Window, void* cursorHandle) const;
  112. bool isKeyCurrentlyDown (int keyCode) const;
  113. ModifierKeys getNativeRealtimeModifiers() const;
  114. Array<Displays::Display> findDisplays (float masterScale) const;
  115. ::Window createKeyProxy (::Window) const;
  116. void deleteKeyProxy (::Window) const;
  117. bool externalDragFileInit (LinuxComponentPeer*, const StringArray& files, bool canMove, std::function<void()>&& callback) const;
  118. bool externalDragTextInit (LinuxComponentPeer*, const String& text, std::function<void()>&& callback) const;
  119. void copyTextToClipboard (const String&);
  120. String getTextFromClipboard() const;
  121. String getLocalClipboardContent() const noexcept { return localClipboardContent; }
  122. ::Display* getDisplay() noexcept { return display; }
  123. const XWindowSystemUtilities::Atoms& getAtoms() const noexcept { return atoms; }
  124. bool isX11Available() const noexcept { return xIsAvailable; }
  125. //==============================================================================
  126. void handleWindowMessage (LinuxComponentPeer*, XEvent&) const;
  127. bool isParentWindowOf (::Window, ::Window possibleChild) const;
  128. //==============================================================================
  129. JUCE_DECLARE_SINGLETON (XWindowSystem, false)
  130. private:
  131. XWindowSystem();
  132. ~XWindowSystem();
  133. //==============================================================================
  134. struct VisualAndDepth
  135. {
  136. Visual* visual;
  137. int depth;
  138. };
  139. struct DisplayVisuals
  140. {
  141. explicit DisplayVisuals (::Display*);
  142. VisualAndDepth getBestVisualForWindow (bool) const;
  143. bool isValid() const noexcept;
  144. Visual* visual16Bit = nullptr;
  145. Visual* visual24Bit = nullptr;
  146. Visual* visual32Bit = nullptr;
  147. };
  148. bool initialiseXDisplay();
  149. void destroyXDisplay();
  150. //==============================================================================
  151. ::Window getFocusWindow (::Window) const;
  152. bool isFrontWindow (::Window) const;
  153. //==============================================================================
  154. void xchangeProperty (::Window, Atom, Atom, int, const void*, int) const;
  155. void removeWindowDecorations (::Window) const;
  156. void addWindowButtons (::Window, int) const;
  157. void setWindowType (::Window, int) const;
  158. void initialisePointerMap();
  159. void deleteIconPixmaps (::Window) const;
  160. void updateModifierMappings() const;
  161. long getUserTime (::Window) const;
  162. //==============================================================================
  163. void handleKeyPressEvent (LinuxComponentPeer*, XKeyEvent&) const;
  164. void handleKeyReleaseEvent (LinuxComponentPeer*, const XKeyEvent&) const;
  165. void handleWheelEvent (LinuxComponentPeer*, const XButtonPressedEvent&, float) const;
  166. void handleButtonPressEvent (LinuxComponentPeer*, const XButtonPressedEvent&, int) const;
  167. void handleButtonPressEvent (LinuxComponentPeer*, const XButtonPressedEvent&) const;
  168. void handleButtonReleaseEvent (LinuxComponentPeer*, const XButtonReleasedEvent&) const;
  169. void handleMotionNotifyEvent (LinuxComponentPeer*, const XPointerMovedEvent&) const;
  170. void handleEnterNotifyEvent (LinuxComponentPeer*, const XEnterWindowEvent&) const;
  171. void handleLeaveNotifyEvent (LinuxComponentPeer*, const XLeaveWindowEvent&) const;
  172. void handleFocusInEvent (LinuxComponentPeer*) const;
  173. void handleFocusOutEvent (LinuxComponentPeer*) const;
  174. void handleExposeEvent (LinuxComponentPeer*, XExposeEvent&) const;
  175. void handleConfigureNotifyEvent (LinuxComponentPeer*, XConfigureEvent&) const;
  176. void handleGravityNotify (LinuxComponentPeer*) const;
  177. void propertyNotifyEvent (LinuxComponentPeer*, const XPropertyEvent&) const;
  178. void handleMappingNotify (XMappingEvent&) const;
  179. void handleClientMessageEvent (LinuxComponentPeer*, XClientMessageEvent&, XEvent&) const;
  180. void handleXEmbedMessage (LinuxComponentPeer*, XClientMessageEvent&) const;
  181. void dismissBlockingModals (LinuxComponentPeer*) const;
  182. void dismissBlockingModals (LinuxComponentPeer*, const XConfigureEvent&) const;
  183. ::Window findTopLevelWindowOf (::Window) const;
  184. static void windowMessageReceive (XEvent&);
  185. //==============================================================================
  186. bool xIsAvailable = false;
  187. XWindowSystemUtilities::Atoms atoms;
  188. ::Display* display = nullptr;
  189. std::unique_ptr<DisplayVisuals> displayVisuals;
  190. #if JUCE_USE_XSHM
  191. std::map<::Window, int> shmPaintsPendingMap;
  192. #endif
  193. int shmCompletionEvent = 0;
  194. int pointerMap[5] = {};
  195. String localClipboardContent;
  196. Point<int> parentScreenPosition;
  197. //==============================================================================
  198. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (XWindowSystem)
  199. };
  200. } // namespace juce