RAM2118 commited on
Commit
dca94cb
·
verified ·
1 Parent(s): 689e62a

Fix: Plugin GUI X button now closes window — custom DocumentWindow with closeButtonPressed override

Browse files
Files changed (1) hide show
  1. Source/Helper/HelperPluginHost.cpp +24 -7
Source/Helper/HelperPluginHost.cpp CHANGED
@@ -4,6 +4,21 @@
4
  #include <pthread.h>
5
  #include <sched.h>
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  HelperPluginHost::HelperPluginHost()
8
  {
9
  #if JUCE_PLUGINHOST_VST3
@@ -119,7 +134,6 @@ void HelperPluginHost::stopProcessing()
119
 
120
  void HelperPluginHost::audioProcessingLoop()
121
  {
122
- // Set realtime thread priority using native macOS/POSIX API
123
  struct sched_param param;
124
  param.sched_priority = sched_get_priority_max(SCHED_FIFO);
125
  pthread_setschedparam(pthread_self(), SCHED_FIFO, &param);
@@ -227,20 +241,23 @@ bool HelperPluginHost::setParams(const std::map<int, float>& values)
227
  void HelperPluginHost::showGui()
228
  {
229
  if (!plugin || !plugin->hasEditor()) return;
230
- if (guiWindow) return;
231
 
232
  juce::MessageManager::callAsync([this]()
233
  {
234
  if (!plugin) return;
235
 
 
 
 
 
 
 
 
 
236
  auto* editor = plugin->createEditor();
237
  if (!editor) return;
238
 
239
- guiWindow = std::make_unique<juce::DocumentWindow>(
240
- plugin->getName(),
241
- juce::Colour(0xff1a1a2e),
242
- juce::DocumentWindow::closeButton | juce::DocumentWindow::minimiseButton);
243
-
244
  guiWindow->setContentOwned(editor, true);
245
  guiWindow->setResizable(true, true);
246
  guiWindow->centreWithSize(editor->getWidth(), editor->getHeight());
 
4
  #include <pthread.h>
5
  #include <sched.h>
6
 
7
+ // Custom window that actually closes when you click X
8
+ class PluginGuiWindow : public juce::DocumentWindow
9
+ {
10
+ public:
11
+ PluginGuiWindow(const juce::String& name)
12
+ : DocumentWindow(name, juce::Colour(0xff1a1a2e),
13
+ DocumentWindow::closeButton | DocumentWindow::minimiseButton)
14
+ {}
15
+
16
+ void closeButtonPressed() override
17
+ {
18
+ setVisible(false);
19
+ }
20
+ };
21
+
22
  HelperPluginHost::HelperPluginHost()
23
  {
24
  #if JUCE_PLUGINHOST_VST3
 
134
 
135
  void HelperPluginHost::audioProcessingLoop()
136
  {
 
137
  struct sched_param param;
138
  param.sched_priority = sched_get_priority_max(SCHED_FIFO);
139
  pthread_setschedparam(pthread_self(), SCHED_FIFO, &param);
 
241
  void HelperPluginHost::showGui()
242
  {
243
  if (!plugin || !plugin->hasEditor()) return;
 
244
 
245
  juce::MessageManager::callAsync([this]()
246
  {
247
  if (!plugin) return;
248
 
249
+ // If window exists but hidden, just show it again
250
+ if (guiWindow)
251
+ {
252
+ guiWindow->setVisible(true);
253
+ guiWindow->toFront(true);
254
+ return;
255
+ }
256
+
257
  auto* editor = plugin->createEditor();
258
  if (!editor) return;
259
 
260
+ guiWindow = std::make_unique<PluginGuiWindow>(plugin->getName());
 
 
 
 
261
  guiWindow->setContentOwned(editor, true);
262
  guiWindow->setResizable(true, true);
263
  guiWindow->centreWithSize(editor->getWidth(), editor->getHeight());