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.

234 lines
9.6KB

  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,
  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. template<typename WindowHandle>
  76. class LinuxComponentPeer;
  77. class XWindowSystem : public DeletedAtShutdown
  78. {
  79. public:
  80. //==============================================================================
  81. ::Window createWindow (::Window parentWindow, LinuxComponentPeer<::Window>* peer) const;
  82. void destroyWindow (::Window windowH);
  83. void setTitle (::Window windowH, const String& title) const;
  84. void setIcon (::Window windowH, const Image& newIcon) const;
  85. void setVisible (::Window windowH, bool shouldBeVisible) const;
  86. void setBounds (::Window windowH, Rectangle<int> newBounds, bool fullScreen) const;
  87. BorderSize<int> getBorderSize (::Window windowH) const;
  88. Rectangle<int> getWindowBounds (::Window windowH, ::Window parentWindow);
  89. Point<int> getParentScreenPosition() const;
  90. bool contains (::Window windowH, Point<int> localPos) const;
  91. void setMinimised (::Window windowH, bool shouldBeMinimised) const;
  92. bool isMinimised (::Window windowH) const;
  93. void toFront (::Window windowH, bool makeActive) const;
  94. void toBehind (::Window windowH, ::Window otherWindow) const;
  95. bool isFocused (::Window windowH) const;
  96. bool grabFocus (::Window windowH) const;
  97. bool canUseSemiTransparentWindows() const;
  98. bool canUseARGBImages() const;
  99. int getNumPaintsPending (::Window windowH) const;
  100. Image createImage (int width, int height, bool argb) const;
  101. void blitToWindow (::Window windowH, Image image, Rectangle<int> destinationRect, Rectangle<int> totalRect) const;
  102. void setScreenSaverEnabled (bool enabled) const;
  103. Point<float> getCurrentMousePosition() const;
  104. void setMousePosition (Point<float> pos) const;
  105. void* createCustomMouseCursorInfo (const Image& image, Point<int> hotspot) const;
  106. void deleteMouseCursor (void* cursorHandle) const;
  107. void* createStandardMouseCursor (MouseCursor::StandardCursorType type) const;
  108. void showCursor (::Window windowH, void* cursorHandle) const;
  109. bool isKeyCurrentlyDown (int keyCode) const;
  110. ModifierKeys getNativeRealtimeModifiers() const;
  111. Array<Displays::Display> findDisplays (float masterScale) const;
  112. ::Window createKeyProxy (::Window windowH) const;
  113. void deleteKeyProxy (::Window keyProxy) const;
  114. bool externalDragFileInit (LinuxComponentPeer<::Window>* peer, const StringArray& files, bool canMove, std::function<void()>&& callback) const;
  115. bool externalDragTextInit (LinuxComponentPeer<::Window>* peer, const String& text, std::function<void()>&& callback) const;
  116. void copyTextToClipboard (const String& clipText);
  117. String getTextFromClipboard() const;
  118. String getLocalClipboardContent() const { return localClipboardContent; }
  119. ::Display* getDisplay() { return display; }
  120. XWindowSystemUtilities::Atoms& getAtoms() { return atoms; }
  121. //==============================================================================
  122. void handleWindowMessage (LinuxComponentPeer<::Window>* peer, XEvent& event) const;
  123. //==============================================================================
  124. JUCE_DECLARE_SINGLETON (XWindowSystem, false)
  125. private:
  126. XWindowSystem();
  127. ~XWindowSystem();
  128. //==============================================================================
  129. bool initialiseXDisplay();
  130. void destroyXDisplay();
  131. //==============================================================================
  132. ::Window getFocusWindow (::Window windowH) const;
  133. bool isParentWindowOf (::Window windowH, ::Window possibleChild) const;
  134. bool isFrontWindow (::Window windowH) const;
  135. //==============================================================================
  136. void xchangeProperty (::Window windowH, Atom property, Atom type, int format, const void* data, int numElements) const;
  137. void removeWindowDecorations (::Window windowH) const;
  138. void addWindowButtons (::Window windowH, int styleFlags) const;
  139. void setWindowType (::Window windowH, int styleFlags) const;
  140. void initialisePointerMap();
  141. void deleteIconPixmaps (::Window windowH) const;
  142. void updateModifierMappings() const;
  143. long getUserTime (::Window windowH) const;
  144. //==============================================================================
  145. void handleKeyPressEvent (LinuxComponentPeer<::Window>*, XKeyEvent&) const;
  146. void handleKeyReleaseEvent (LinuxComponentPeer<::Window>*, const XKeyEvent&) const;
  147. void handleWheelEvent (LinuxComponentPeer<::Window>*, const XButtonPressedEvent&, float) const;
  148. void handleButtonPressEvent (LinuxComponentPeer<::Window>*, const XButtonPressedEvent&, int) const;
  149. void handleButtonPressEvent (LinuxComponentPeer<::Window>*, const XButtonPressedEvent&) const;
  150. void handleButtonReleaseEvent (LinuxComponentPeer<::Window>*, const XButtonReleasedEvent&) const;
  151. void handleMotionNotifyEvent (LinuxComponentPeer<::Window>*, const XPointerMovedEvent&) const;
  152. void handleEnterNotifyEvent (LinuxComponentPeer<::Window>*, const XEnterWindowEvent&) const;
  153. void handleLeaveNotifyEvent (LinuxComponentPeer<::Window>*, const XLeaveWindowEvent&) const;
  154. void handleFocusInEvent (LinuxComponentPeer<::Window>*) const;
  155. void handleFocusOutEvent (LinuxComponentPeer<::Window>*) const;
  156. void handleExposeEvent (LinuxComponentPeer<::Window>*, XExposeEvent&) const;
  157. void handleConfigureNotifyEvent (LinuxComponentPeer<::Window>*, XConfigureEvent&) const;
  158. void handleGravityNotify (LinuxComponentPeer<::Window>*) const;
  159. void handleMappingNotify (XMappingEvent&) const;
  160. void handleClientMessageEvent (LinuxComponentPeer<::Window>*, XClientMessageEvent&, XEvent&) const;
  161. void handleXEmbedMessage (LinuxComponentPeer<::Window>*, XClientMessageEvent&) const;
  162. //==============================================================================
  163. bool xIsAvailable = false;
  164. XWindowSystemUtilities::Atoms atoms;
  165. ::Display* display = nullptr;
  166. Colormap colormap = {};
  167. Visual* visual = nullptr;
  168. int depth = 0, shmCompletionEvent = 0;
  169. int pointerMap[5] = {};
  170. String localClipboardContent;
  171. Point<int> parentScreenPosition;
  172. //==============================================================================
  173. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (XWindowSystem)
  174. };
  175. } // namespace juce