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 2.7KB

10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Juce Plugin Window Helper
  3. * Copyright (C) 2013-2014 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 "juce_gui_basics.h"
  21. #ifdef HAVE_X11
  22. # include <X11/Xlib.h>
  23. #endif
  24. // -----------------------------------------------------------------------
  25. namespace juce {
  26. #ifdef HAVE_X11
  27. extern Display* display;
  28. #endif
  29. class JucePluginWindow : public DocumentWindow
  30. {
  31. public:
  32. JucePluginWindow()
  33. : DocumentWindow("JucePluginWindow", Colour(50, 50, 200), DocumentWindow::closeButton, false),
  34. fClosed(false),
  35. leakDetector_JucePluginWindow()
  36. {
  37. setVisible(false);
  38. //setAlwaysOnTop(true);
  39. setOpaque(true);
  40. setResizable(false, false);
  41. setUsingNativeTitleBar(true);
  42. }
  43. void show(Component* const comp, const bool useContentOwned = false)
  44. {
  45. fClosed = false;
  46. centreWithSize(comp->getWidth(), comp->getHeight());
  47. if (useContentOwned)
  48. setContentOwned(comp, false);
  49. else
  50. setContentNonOwned(comp, true);
  51. if (! isOnDesktop())
  52. addToDesktop();
  53. setVisible(true);
  54. }
  55. void hide()
  56. {
  57. setVisible(false);
  58. if (isOnDesktop())
  59. removeFromDesktop();
  60. clearContentComponent();
  61. }
  62. bool wasClosedByUser() const noexcept
  63. {
  64. return fClosed;
  65. }
  66. void setTransientWinId(const uintptr_t winId) const
  67. {
  68. CARLA_SAFE_ASSERT_RETURN(winId != 0,);
  69. #ifdef HAVE_X11
  70. CARLA_SAFE_ASSERT_RETURN(display != nullptr,);
  71. ::Window window = (::Window)getWindowHandle();
  72. CARLA_SAFE_ASSERT_RETURN(window != 0,);
  73. XSetTransientForHint(display, window, static_cast<Window>(winId));
  74. #endif
  75. }
  76. protected:
  77. void closeButtonPressed() override
  78. {
  79. fClosed = true;
  80. }
  81. private:
  82. volatile bool fClosed;
  83. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(JucePluginWindow)
  84. };
  85. } // namespace juce
  86. using juce::JucePluginWindow;
  87. // -----------------------------------------------------------------------
  88. #endif // JUCE_PLUGIN_WINDOW_HPP_INCLUDED