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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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/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. {
  36. setVisible(false);
  37. //setAlwaysOnTop(true);
  38. setOpaque(true);
  39. setResizable(false, false);
  40. setUsingNativeTitleBar(true);
  41. }
  42. void show(Component* const comp, const bool useContentOwned = false)
  43. {
  44. fClosed = false;
  45. centreWithSize(comp->getWidth(), comp->getHeight());
  46. if (useContentOwned)
  47. setContentOwned(comp, false);
  48. else
  49. setContentNonOwned(comp, true);
  50. if (! isOnDesktop())
  51. addToDesktop();
  52. setVisible(true);
  53. }
  54. void hide()
  55. {
  56. setVisible(false);
  57. if (isOnDesktop())
  58. removeFromDesktop();
  59. clearContentComponent();
  60. }
  61. bool wasClosedByUser() const noexcept
  62. {
  63. return fClosed;
  64. }
  65. void setTransientWinId(const uintptr_t winId) const
  66. {
  67. CARLA_SAFE_ASSERT_RETURN(winId != 0,);
  68. #ifdef HAVE_X11
  69. CARLA_SAFE_ASSERT_RETURN(display != nullptr,);
  70. ::Window window = (::Window)getWindowHandle();
  71. CARLA_SAFE_ASSERT_RETURN(window != 0,);
  72. XSetTransientForHint(display, window, static_cast<Window>(winId));
  73. #endif
  74. }
  75. protected:
  76. void closeButtonPressed() override
  77. {
  78. fClosed = true;
  79. }
  80. private:
  81. volatile bool fClosed;
  82. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(JucePluginWindow)
  83. };
  84. } // namespace juce
  85. using juce::JucePluginWindow;
  86. // -----------------------------------------------------------------------
  87. #endif // JUCE_PLUGIN_WINDOW_HPP_INCLUDED