Audio plugin host https://kx.studio/carla
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.

JucePluginWindow.hpp 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Juce Plugin Window Helper
  3. * Copyright (C) 2013-2019 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifndef JUCE_PLUGIN_WINDOW_HPP_INCLUDED
  18. #define JUCE_PLUGIN_WINDOW_HPP_INCLUDED
  19. #include "CarlaJuceUtils.hpp"
  20. #include "AppConfig.h"
  21. #include "juce_gui_basics/juce_gui_basics.h"
  22. #if defined(CARLA_OS_LINUX) && defined(HAVE_X11)
  23. # include <X11/Xlib.h>
  24. #elif defined(CARLA_OS_MAC)
  25. # import <Cocoa/Cocoa.h>
  26. #endif
  27. // -----------------------------------------------------------------------
  28. namespace juce {
  29. class JucePluginWindow : public DialogWindow
  30. {
  31. public:
  32. JucePluginWindow(const uintptr_t parentId)
  33. : DialogWindow("JucePluginWindow", Colour(50, 50, 200), true, false),
  34. fClosed(false),
  35. fTransientId(parentId)
  36. {
  37. setVisible(false);
  38. //setAlwaysOnTop(true);
  39. setOpaque(true);
  40. setResizable(false, false);
  41. setUsingNativeTitleBar(true);
  42. }
  43. void show(Component* const comp)
  44. {
  45. fClosed = false;
  46. centreWithSize(comp->getWidth(), comp->getHeight());
  47. setContentNonOwned(comp, true);
  48. if (! isOnDesktop())
  49. addToDesktop();
  50. setVisible(true);
  51. setTransient();
  52. }
  53. void hide()
  54. {
  55. setVisible(false);
  56. if (isOnDesktop())
  57. removeFromDesktop();
  58. clearContentComponent();
  59. }
  60. bool wasClosedByUser() const noexcept
  61. {
  62. return fClosed;
  63. }
  64. protected:
  65. void closeButtonPressed() override
  66. {
  67. fClosed = true;
  68. }
  69. bool escapeKeyPressed() override
  70. {
  71. fClosed = true;
  72. return true;
  73. }
  74. private:
  75. volatile bool fClosed;
  76. const uintptr_t fTransientId;
  77. void setTransient()
  78. {
  79. if (fTransientId == 0)
  80. return;
  81. #if defined(CARLA_OS_LINUX) && defined(HAVE_X11)
  82. Display* const display = XWindowSystem::getInstance()->getDisplay();
  83. CARLA_SAFE_ASSERT_RETURN(display != nullptr,);
  84. ::Window window = (::Window)getWindowHandle();
  85. CARLA_SAFE_ASSERT_RETURN(window != 0,);
  86. XSetTransientForHint(display, window, static_cast<::Window>(fTransientId));
  87. #endif
  88. #ifdef CARLA_OS_MAC
  89. NSView* const view = (NSView*)getWindowHandle();
  90. CARLA_SAFE_ASSERT_RETURN(view != nullptr,);
  91. NSWindow* const window = [view window];
  92. CARLA_SAFE_ASSERT_RETURN(window != nullptr,);
  93. NSWindow* const parentWindow = [NSApp windowWithWindowNumber:fTransientId];
  94. CARLA_SAFE_ASSERT_RETURN(parentWindow != nullptr,);
  95. [parentWindow addChildWindow:window
  96. ordered:NSWindowAbove];
  97. #endif
  98. #ifdef CARLA_OS_WIN
  99. const HWND window = (HWND)getWindowHandle();
  100. CARLA_SAFE_ASSERT_RETURN(window != nullptr,);
  101. SetWindowLongPtr(window, GWLP_HWNDPARENT, static_cast<LONG_PTR>(fTransientId));
  102. #endif
  103. }
  104. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(JucePluginWindow)
  105. };
  106. } // namespace juce
  107. using juce::JucePluginWindow;
  108. // -----------------------------------------------------------------------
  109. #endif // JUCE_PLUGIN_WINDOW_HPP_INCLUDED