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) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. //==============================================================================
  22. namespace XWindowSystemUtilities
  23. {
  24. //==============================================================================
  25. /** A handy struct that uses XLockDisplay and XUnlockDisplay to lock the X server
  26. using RAII.
  27. @tags{GUI}
  28. */
  29. struct ScopedXLock
  30. {
  31. ScopedXLock();
  32. ~ScopedXLock();
  33. };
  34. //==============================================================================
  35. /** Gets a specified window property and stores its associated data, freeing it
  36. on deletion.
  37. @tags{GUI}
  38. */
  39. struct GetXProperty
  40. {
  41. GetXProperty (::Window windowH, Atom property, long offset,
  42. long length, bool shouldDelete, Atom requestedType);
  43. ~GetXProperty();
  44. bool success = false;
  45. unsigned char* data = nullptr;
  46. unsigned long numItems = 0, bytesLeft = 0;
  47. Atom actualType;
  48. int actualFormat = -1;
  49. };
  50. //==============================================================================
  51. /** Initialises and stores some atoms for the display.
  52. @tags{GUI}
  53. */
  54. struct Atoms
  55. {
  56. enum ProtocolItems
  57. {
  58. TAKE_FOCUS = 0,
  59. DELETE_WINDOW = 1,
  60. PING = 2
  61. };
  62. 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() { jassert (atoms.get() != nullptr); 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. void 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. std::unique_ptr<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