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.

136 lines
3.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. // Hack to forward declare _XDisplay outside the
  19. // juce namespace
  20. }
  21. struct _XDisplay;
  22. #define ATOM_TYPE unsigned long
  23. #define WINDOW_TYPE unsigned long
  24. namespace juce {
  25. //==============================================================================
  26. class XWindowSystem
  27. {
  28. public:
  29. ::_XDisplay* displayRef() noexcept;
  30. ::_XDisplay* displayUnref() noexcept;
  31. juce_DeclareSingleton (XWindowSystem, false)
  32. private:
  33. ::_XDisplay* display;
  34. Atomic<int> displayCount;
  35. XWindowSystem() noexcept;
  36. ~XWindowSystem() noexcept;
  37. void initialiseXDisplay() noexcept;
  38. void destroyXDisplay() noexcept;
  39. };
  40. //==============================================================================
  41. class ScopedXDisplay
  42. {
  43. public:
  44. ScopedXDisplay();
  45. ~ScopedXDisplay();
  46. ::_XDisplay* get();
  47. private:
  48. ::_XDisplay* display;
  49. };
  50. /** A handy class that uses XLockDisplay and XUnlockDisplay to lock the X server
  51. using RAII (Only available in Linux!).
  52. */
  53. class ScopedXLock
  54. {
  55. public:
  56. /** Creating a ScopedXLock object locks the X display.
  57. This uses XLockDisplay() to grab the display that Juce is using.
  58. */
  59. ScopedXLock (::_XDisplay* _display);
  60. /** Deleting a ScopedXLock object unlocks the X display.
  61. This calls XUnlockDisplay() to release the lock.
  62. */
  63. ~ScopedXLock();
  64. private:
  65. // defined in juce_linux_X11.h
  66. ::_XDisplay* display;
  67. };
  68. //==============================================================================
  69. struct Atoms
  70. {
  71. Atoms(::_XDisplay* display);
  72. enum ProtocolItems
  73. {
  74. TAKE_FOCUS = 0,
  75. DELETE_WINDOW = 1,
  76. PING = 2
  77. };
  78. ATOM_TYPE protocols, protocolList[3], changeState, state, userTime,
  79. activeWin, pid, windowType, windowState,
  80. XdndAware, XdndEnter, XdndLeave, XdndPosition, XdndStatus,
  81. XdndDrop, XdndFinished, XdndSelection, XdndTypeList, XdndActionList,
  82. XdndActionDescription, XdndActionCopy, XdndActionPrivate,
  83. allowedActions[5],
  84. allowedMimeTypes[4];
  85. static const unsigned long DndVersion;
  86. static ATOM_TYPE getIfExists (::_XDisplay* display, const char* name);
  87. static ATOM_TYPE getCreating (::_XDisplay* display, const char* name);
  88. static String getName (::_XDisplay* display, const ATOM_TYPE atom);
  89. static bool isMimeTypeFile (::_XDisplay* display, const ATOM_TYPE atom);
  90. };
  91. //==============================================================================
  92. struct GetXProperty
  93. {
  94. GetXProperty (::_XDisplay* display, WINDOW_TYPE window, ATOM_TYPE atom,
  95. long offset, long length, bool shouldDelete,
  96. ATOM_TYPE requestedType);
  97. ~GetXProperty();
  98. bool success;
  99. unsigned char* data;
  100. unsigned long numItems, bytesLeft;
  101. ATOM_TYPE actualType;
  102. int actualFormat;
  103. };
  104. #undef ATOM_TYPE