juce_linux_X11.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. struct _XDisplay;
  20. namespace juce
  21. {
  22. typedef ::_XDisplay* XDisplay;
  23. typedef unsigned long AtomType;
  24. typedef unsigned long WindowType;
  25. //==============================================================================
  26. class XWindowSystem : public DeletedAtShutdown
  27. {
  28. public:
  29. XDisplay displayRef() noexcept;
  30. XDisplay displayUnref() noexcept;
  31. JUCE_DECLARE_SINGLETON (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. /** Creates and holds a reference to the X display.
  42. @tags{GUI}
  43. */
  44. struct ScopedXDisplay
  45. {
  46. ScopedXDisplay();
  47. ~ScopedXDisplay();
  48. const XDisplay display;
  49. };
  50. //==============================================================================
  51. /** A handy class that uses XLockDisplay and XUnlockDisplay to lock the X server
  52. using RAII (Only available in Linux!).
  53. @tags{GUI}
  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);
  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);
  74. enum ProtocolItems
  75. {
  76. TAKE_FOCUS = 0,
  77. DELETE_WINDOW = 1,
  78. PING = 2
  79. };
  80. AtomType 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 AtomType getIfExists (XDisplay, const char* name);
  90. static AtomType getCreating (XDisplay, const char* name);
  91. static String getName (XDisplay, AtomType);
  92. static bool isMimeTypeFile (XDisplay, AtomType);
  93. };
  94. //==============================================================================
  95. struct GetXProperty
  96. {
  97. GetXProperty (XDisplay, WindowType, AtomType,
  98. long offset, long length, bool shouldDelete,
  99. AtomType requestedType);
  100. ~GetXProperty();
  101. bool success;
  102. unsigned char* data = nullptr;
  103. unsigned long numItems, bytesLeft;
  104. AtomType actualType;
  105. int actualFormat;
  106. };
  107. //==============================================================================
  108. enum
  109. {
  110. maxXEmbedVersionToSupport = 0
  111. };
  112. enum
  113. {
  114. XEMBED_MAPPED = (1<<0)
  115. };
  116. enum
  117. {
  118. XEMBED_EMBEDDED_NOTIFY = 0,
  119. XEMBED_WINDOW_ACTIVATE = 1,
  120. XEMBED_WINDOW_DEACTIVATE = 2,
  121. XEMBED_REQUEST_FOCUS = 3,
  122. XEMBED_FOCUS_IN = 4,
  123. XEMBED_FOCUS_OUT = 5,
  124. XEMBED_FOCUS_NEXT = 6,
  125. XEMBED_FOCUS_PREV = 7,
  126. XEMBED_MODALITY_ON = 10,
  127. XEMBED_MODALITY_OFF = 11,
  128. XEMBED_REGISTER_ACCELERATOR = 12,
  129. XEMBED_UNREGISTER_ACCELERATOR = 13,
  130. XEMBED_ACTIVATE_ACCELERATOR = 14
  131. };
  132. enum
  133. {
  134. XEMBED_FOCUS_CURRENT = 0,
  135. XEMBED_FOCUS_FIRST = 1,
  136. XEMBED_FOCUS_LAST = 2
  137. };
  138. } // namespace juce