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.

145 lines
3.8KB

  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. #pragma once
  20. // Hack to forward declare _XDisplay outside the
  21. // juce namespace
  22. }
  23. struct _XDisplay;
  24. namespace juce
  25. {
  26. typedef ::_XDisplay* XDisplay;
  27. typedef unsigned long ATOM_TYPE;
  28. typedef unsigned long WINDOW_TYPE;
  29. //==============================================================================
  30. class XWindowSystem
  31. {
  32. public:
  33. XDisplay displayRef() noexcept;
  34. XDisplay displayUnref() noexcept;
  35. juce_DeclareSingleton (XWindowSystem, false)
  36. private:
  37. XDisplay display;
  38. Atomic<int> displayCount;
  39. XWindowSystem() noexcept;
  40. ~XWindowSystem() noexcept;
  41. void initialiseXDisplay() noexcept;
  42. void destroyXDisplay() noexcept;
  43. };
  44. //==============================================================================
  45. class ScopedXDisplay
  46. {
  47. public:
  48. ScopedXDisplay();
  49. ~ScopedXDisplay();
  50. const XDisplay display;
  51. };
  52. //==============================================================================
  53. /** A handy class that uses XLockDisplay and XUnlockDisplay to lock the X server
  54. using RAII (Only available in Linux!).
  55. */
  56. class ScopedXLock
  57. {
  58. public:
  59. /** Creating a ScopedXLock object locks the X display.
  60. This uses XLockDisplay() to grab the display that Juce is using.
  61. */
  62. ScopedXLock (XDisplay);
  63. /** Deleting a ScopedXLock object unlocks the X display.
  64. This calls XUnlockDisplay() to release the lock.
  65. */
  66. ~ScopedXLock();
  67. private:
  68. // defined in juce_linux_X11.h
  69. XDisplay display;
  70. };
  71. //==============================================================================
  72. struct Atoms
  73. {
  74. Atoms (XDisplay);
  75. enum ProtocolItems
  76. {
  77. TAKE_FOCUS = 0,
  78. DELETE_WINDOW = 1,
  79. PING = 2
  80. };
  81. ATOM_TYPE protocols, protocolList[3], changeState, state, userTime,
  82. activeWin, pid, windowType, windowState,
  83. XdndAware, XdndEnter, XdndLeave, XdndPosition, XdndStatus,
  84. XdndDrop, XdndFinished, XdndSelection, XdndTypeList, XdndActionList,
  85. XdndActionDescription, XdndActionCopy, XdndActionPrivate,
  86. XembedMsgType, XembedInfo,
  87. allowedActions[5],
  88. allowedMimeTypes[4];
  89. static const unsigned long DndVersion;
  90. static ATOM_TYPE getIfExists (XDisplay, const char* name);
  91. static ATOM_TYPE getCreating (XDisplay, const char* name);
  92. static String getName (XDisplay, ATOM_TYPE atom);
  93. static bool isMimeTypeFile (XDisplay, ATOM_TYPE atom);
  94. };
  95. //==============================================================================
  96. struct GetXProperty
  97. {
  98. GetXProperty (XDisplay, WINDOW_TYPE window, ATOM_TYPE atom,
  99. long offset, long length, bool shouldDelete,
  100. ATOM_TYPE requestedType);
  101. ~GetXProperty();
  102. bool success;
  103. unsigned char* data;
  104. unsigned long numItems, bytesLeft;
  105. ATOM_TYPE actualType;
  106. int actualFormat;
  107. };
  108. #undef ATOM_TYPE