Skip to content

Commit fcc883f

Browse files
DomClarkPhysSong
authored andcommitted
Preserve VST GUI positions and keep them on top
1 parent ee18011 commit fcc883f

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

plugins/vst_base/RemoteVstPlugin.cpp

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ class RemoteVstPlugin : public RemotePluginClient
134134

135135
void init( const std::string & _plugin_file );
136136
void initEditor();
137+
void showEditor();
138+
void hideEditor();
137139
void destroyEditor();
138140

139141
virtual void process( const sampleFrame * _in, sampleFrame * _out );
@@ -507,27 +509,28 @@ bool RemoteVstPlugin::processMessage( const message & _m )
507509
switch( _m.id )
508510
{
509511
case IdShowUI:
510-
initEditor();
512+
showEditor();
511513
return true;
512514

513515
case IdHideUI:
514-
destroyEditor();
516+
hideEditor();
515517
return true;
516518

517519
case IdToggleUI:
518-
if( m_window )
520+
if( m_window && IsWindowVisible( m_window ) )
519521
{
520-
destroyEditor();
522+
hideEditor();
521523
}
522524
else
523525
{
524-
initEditor();
526+
showEditor();
525527
}
526528
return true;
527529

528530
case IdIsUIVisible:
531+
bool visible = m_window && IsWindowVisible( m_window );
529532
sendMessage( message( IdIsUIVisible )
530-
.addInt( m_window ? 1 : 0 ) );
533+
.addInt( visible ? 1 : 0 ) );
531534
return true;
532535
}
533536
}
@@ -709,7 +712,7 @@ void RemoteVstPlugin::initEditor()
709712
dwStyle = WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX;
710713
}
711714

712-
m_window = CreateWindowEx( 0, "LVSL", pluginName(),
715+
m_window = CreateWindowEx( WS_EX_APPWINDOW, "LVSL", pluginName(),
713716
dwStyle,
714717
0, 0, 10, 10, NULL, NULL, hInst, NULL );
715718
if( m_window == NULL )
@@ -733,7 +736,7 @@ void RemoteVstPlugin::initEditor()
733736
pluginDispatch( effEditTop );
734737

735738
if (! EMBED) {
736-
ShowWindow( m_window, SW_SHOWNORMAL );
739+
showEditor();
737740
}
738741

739742
#ifdef LMMS_BUILD_LINUX
@@ -747,6 +750,26 @@ void RemoteVstPlugin::initEditor()
747750

748751

749752

753+
void RemoteVstPlugin::showEditor() {
754+
if( !EMBED && !HEADLESS && m_window )
755+
{
756+
ShowWindow( m_window, SW_SHOWNORMAL );
757+
}
758+
}
759+
760+
761+
762+
763+
void RemoteVstPlugin::hideEditor() {
764+
if( !EMBED && !HEADLESS && m_window )
765+
{
766+
ShowWindow( m_window, SW_HIDE );
767+
}
768+
}
769+
770+
771+
772+
750773
void RemoteVstPlugin::destroyEditor()
751774
{
752775
if( m_window == NULL )
@@ -1947,7 +1970,7 @@ LRESULT CALLBACK RemoteVstPlugin::wndProc( HWND hwnd, UINT uMsg,
19471970
}
19481971
else if( uMsg == WM_SYSCOMMAND && wParam == SC_CLOSE )
19491972
{
1950-
__plugin->destroyEditor();
1973+
__plugin->hideEditor();
19511974
return 0;
19521975
}
19531976

plugins/vst_base/VstPlugin.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
#include <QMdiSubWindow>
3535

3636
#ifdef LMMS_BUILD_LINUX
37+
# include <QX11Info>
3738
# if QT_VERSION < 0x050000
3839
# include <QX11EmbedContainer>
39-
# include <QX11Info>
4040
# else
4141
# include "X11EmbedContainer.h"
4242
# include <QWindow>
@@ -62,6 +62,10 @@
6262
#include "templates.h"
6363
#include "FileDialog.h"
6464

65+
#ifdef LMMS_BUILD_LINUX
66+
# include <X11/Xlib.h>
67+
#endif
68+
6569

6670
VstPlugin::VstPlugin( const QString & _plugin ) :
6771
m_plugin( _plugin ),
@@ -324,6 +328,22 @@ bool VstPlugin::processMessage( const message & _m )
324328

325329
case IdVstPluginWindowID:
326330
m_pluginWindowID = _m.getInt();
331+
if( m_embedMethod == "none" )
332+
{
333+
#ifdef LMMS_BUILD_WIN32
334+
// We're changing the owner, not the parent,
335+
// so this is legal despite MSDN's warning
336+
SetWindowLongPtr( (HWND)(intptr_t) m_pluginWindowID,
337+
GWLP_HWNDPARENT,
338+
(LONG_PTR) gui->mainWindow()->winId() );
339+
#endif
340+
341+
#ifdef LMMS_BUILD_LINUX
342+
XSetTransientForHint( QX11Info::display(),
343+
m_pluginWindowID,
344+
gui->mainWindow()->winId() );
345+
#endif
346+
}
327347
break;
328348

329349
case IdVstPluginEditorGeometry:

0 commit comments

Comments
 (0)