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.

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