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.

120 lines
4.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  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 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. #ifndef DOXYGEN
  21. #if JUCE_MAC
  22. //==============================================================================
  23. // Helper class to workaround windows not getting mouse-moves...
  24. class FakeMouseMoveGenerator : private Timer
  25. {
  26. public:
  27. FakeMouseMoveGenerator()
  28. {
  29. startTimer (1000 / 30);
  30. }
  31. static bool componentContainsAudioProcessorEditor (Component* comp) noexcept
  32. {
  33. if (dynamic_cast<AudioProcessorEditor*> (comp) != nullptr)
  34. return true;
  35. for (auto* child : comp->getChildren())
  36. if (componentContainsAudioProcessorEditor (child))
  37. return true;
  38. return false;
  39. }
  40. void timerCallback() override
  41. {
  42. // Workaround for windows not getting mouse-moves...
  43. auto screenPos = Desktop::getInstance().getMainMouseSource().getScreenPosition();
  44. if (screenPos != lastScreenPos)
  45. {
  46. lastScreenPos = screenPos;
  47. auto mods = ModifierKeys::currentModifiers;
  48. if (! mods.isAnyMouseButtonDown())
  49. {
  50. if (auto* comp = Desktop::getInstance().findComponentAt (screenPos.roundToInt()))
  51. {
  52. if (componentContainsAudioProcessorEditor (comp->getTopLevelComponent()))
  53. {
  54. safeOldComponent = comp;
  55. if (auto* peer = comp->getPeer())
  56. {
  57. if (! peer->isFocused())
  58. {
  59. peer->handleMouseEvent (MouseInputSource::InputSourceType::mouse,
  60. peer->globalToLocal (Desktop::getInstance().getMainMouseSource().getRawScreenPosition()),
  61. mods,
  62. MouseInputSource::invalidPressure,
  63. MouseInputSource::invalidOrientation,
  64. Time::currentTimeMillis());
  65. }
  66. }
  67. return;
  68. }
  69. }
  70. if (safeOldComponent != nullptr)
  71. {
  72. if (auto* peer = safeOldComponent->getPeer())
  73. {
  74. peer->handleMouseEvent (MouseInputSource::InputSourceType::mouse,
  75. MouseInputSource::offscreenMousePos,
  76. mods,
  77. MouseInputSource::invalidPressure,
  78. MouseInputSource::invalidOrientation,
  79. Time::currentTimeMillis());
  80. }
  81. }
  82. safeOldComponent = nullptr;
  83. }
  84. }
  85. }
  86. private:
  87. Point<float> lastScreenPos;
  88. WeakReference<Component> safeOldComponent;
  89. };
  90. #else
  91. struct FakeMouseMoveGenerator {};
  92. #endif
  93. #endif
  94. } // namespace juce