BsLinuxDragAndDrop.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include <X11/X.h>
  6. #include <X11/Xlib.h>
  7. namespace bs
  8. {
  9. /** Handles X11 drag and drop functionality. */
  10. class LinuxDragAndDrop
  11. {
  12. /** Possible states of the DND manager. */
  13. enum class State
  14. {
  15. Inactive,
  16. Entered,
  17. Active
  18. };
  19. /** Type of drag and drop operation. */
  20. enum class DragAndDropOpType
  21. {
  22. Enter,
  23. DragOver,
  24. Drop,
  25. Leave
  26. };
  27. /** Structure describing a drag and drop operation. */
  28. struct DragAndDropOp
  29. {
  30. DragAndDropOp(DragAndDropOpType type, OSDropTarget* target)
  31. :type(type), target(target)
  32. { }
  33. DragAndDropOp(DragAndDropOpType type, OSDropTarget* target, const Vector2I& pos)
  34. :type(type), position(pos), target(target)
  35. { }
  36. DragAndDropOp(DragAndDropOpType type, OSDropTarget* target, const Vector2I& pos,
  37. const Vector<WString>& fileList)
  38. :type(type), position(pos), target(target), fileList(fileList)
  39. { }
  40. DragAndDropOpType type;
  41. OSDropTarget* target;
  42. Vector2I position;
  43. Vector<WString> fileList;
  44. };
  45. public:
  46. /**
  47. * Initializes the drag and drop system. Must be called before any other drag and drop methods are called.
  48. *
  49. * @note Core thread only.
  50. */
  51. static void startUp(::Display* xDisplay);
  52. /**
  53. * Shuts down the drag and drop system. Should be called after no more calls to the system are expected.
  54. *
  55. * @note Core thread only.
  56. */
  57. static void shutDown();
  58. /**
  59. * Triggers any drag and drop events.
  60. *
  61. * @note Sim thread only.
  62. */
  63. static void update();
  64. /**
  65. * Marks an X11 window as drag and drop aware (being able to accept and send drag and drop events).
  66. *
  67. * @note Core thread only.
  68. */
  69. static void makeDNDAware(::Window xWindow);
  70. /**
  71. * Creates a new drop target. Any further events processed will take this target into account, trigger its event
  72. * and populate its data if a drop occurs.
  73. *
  74. * @note Thread safe.
  75. */
  76. static OSDropTarget& createDropTarget(const RenderWindow* window, INT32 x, INT32 y, UINT32 width, UINT32 height);
  77. /**
  78. * Destroys a drop target.
  79. *
  80. * @note Thread safe.
  81. */
  82. static void destroyDropTarget(OSDropTarget& target);
  83. /**
  84. * Processes X11 ClientMessage event and handles any messages relating to drag and drop. Returns true if a message
  85. * was handled, or false if it needs to be handled by the caller.
  86. *
  87. * @note Core thread only.
  88. */
  89. static bool handleClientMessage(XClientMessageEvent& event);
  90. /**
  91. * Processes X11 SelectionNotify event and handles it if it relates to drag and drop. Returns true if the event was
  92. * handled, or false otherwise.
  93. *
  94. * @note Core thread only.
  95. */
  96. static bool handleSelectionNotify(XSelectionEvent& event);
  97. private:
  98. static ::Display* sXDisplay;
  99. static bool sDragActive;
  100. static Vector<OSDropTarget*> sTargets;
  101. static Mutex sMutex;
  102. static INT32 sDNDVersion;
  103. static Atom sDNDType;
  104. static ::Window sDNDSource;
  105. static Vector2I sDragPosition;
  106. static Vector<DragAndDropOp> sQueuedOperations;
  107. static Vector<OSDropTarget*> sTargetsToRegister;
  108. static Vector<OSDropTarget*> sTargetsToUnregister;
  109. // Awareness
  110. static Atom sXdndAware;
  111. // Selection handling
  112. static Atom sXdndSelection;
  113. // Client messages
  114. static Atom sXdndEnter;
  115. static Atom sXdndLeave;
  116. static Atom sXdndPosition;
  117. static Atom sXdndStatus;
  118. static Atom sXdndDrop;
  119. static Atom sXdndFinished;
  120. // Actions
  121. static Atom sXdndActionCopy;
  122. // Type list
  123. static Atom sXdndTypeList;
  124. // Other
  125. static Atom sPRIMARY;
  126. };
  127. }