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.

147 lines
3.5KB

  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 JUCE_LINUX && defined(HAVE_X11)
  23. # include <X11/Xlib.h>
  24. #elif JUCE_MAC
  25. # import <Cocoa/Cocoa.h>
  26. #endif
  27. // -----------------------------------------------------------------------
  28. namespace juce {
  29. #if JUCE_LINUX && defined(HAVE_X11)
  30. extern Display* display;
  31. #endif
  32. class JucePluginWindow : public DialogWindow
  33. {
  34. public:
  35. JucePluginWindow(const uintptr_t parentId)
  36. : DialogWindow("JucePluginWindow", Colour(50, 50, 200), true, false),
  37. fClosed(false),
  38. fTransientId(parentId)
  39. {
  40. setVisible(false);
  41. //setAlwaysOnTop(true);
  42. setOpaque(true);
  43. setResizable(false, false);
  44. setUsingNativeTitleBar(true);
  45. }
  46. void show(Component* const comp)
  47. {
  48. fClosed = false;
  49. centreWithSize(comp->getWidth(), comp->getHeight());
  50. setContentNonOwned(comp, true);
  51. if (! isOnDesktop())
  52. addToDesktop();
  53. setVisible(true);
  54. setTransient();
  55. }
  56. void hide()
  57. {
  58. setVisible(false);
  59. if (isOnDesktop())
  60. removeFromDesktop();
  61. clearContentComponent();
  62. }
  63. bool wasClosedByUser() const noexcept
  64. {
  65. return fClosed;
  66. }
  67. protected:
  68. void closeButtonPressed() override
  69. {
  70. fClosed = true;
  71. }
  72. bool escapeKeyPressed() override
  73. {
  74. fClosed = true;
  75. return true;
  76. }
  77. private:
  78. volatile bool fClosed;
  79. const uintptr_t fTransientId;
  80. void setTransient()
  81. {
  82. if (fTransientId == 0)
  83. return;
  84. #if JUCE_LINUX && defined(HAVE_X11)
  85. CARLA_SAFE_ASSERT_RETURN(display != nullptr,);
  86. ::Window window = (::Window)getWindowHandle();
  87. CARLA_SAFE_ASSERT_RETURN(window != 0,);
  88. XSetTransientForHint(display, window, static_cast<::Window>(fTransientId));
  89. #endif
  90. #if JUCE_MAC
  91. NSView* const view = (NSView*)getWindowHandle();
  92. CARLA_SAFE_ASSERT_RETURN(view != nullptr,);
  93. NSWindow* const window = [view window];
  94. CARLA_SAFE_ASSERT_RETURN(window != nullptr,);
  95. NSWindow* const parentWindow = [NSApp windowWithWindowNumber:fTransientId];
  96. CARLA_SAFE_ASSERT_RETURN(parentWindow != nullptr,);
  97. [parentWindow addChildWindow:window
  98. ordered:NSWindowAbove];
  99. #endif
  100. #if JUCE_WINDOWS
  101. const HWND window = (HWND)getWindowHandle();
  102. CARLA_SAFE_ASSERT_RETURN(window != nullptr,);
  103. SetWindowLongPtr(window, GWLP_HWNDPARENT, static_cast<LONG_PTR>(fTransientId));
  104. #endif
  105. }
  106. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(JucePluginWindow)
  107. };
  108. } // namespace juce
  109. using juce::JucePluginWindow;
  110. // -----------------------------------------------------------------------
  111. #endif // JUCE_PLUGIN_WINDOW_HPP_INCLUDED