Skip to content

Commit

Permalink
[Fix] r21750 broke key handling in the bridged plugins themselves.
Browse files Browse the repository at this point in the history
git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@21751 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Sep 25, 2024
1 parent be2c8c3 commit 4e468b4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
5 changes: 4 additions & 1 deletion mptrack/AbstractVstEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ BOOL CAbstractVstEditor::PreTranslateMessage(MSG *msg)
}


bool CAbstractVstEditor::HandleKeyMessage(MSG &msg)
bool CAbstractVstEditor::HandleKeyMessage(MSG &msg, bool handleGlobal)
{
if(m_VstPlugin.m_passKeypressesToPlug)
return false;
Expand All @@ -467,6 +467,9 @@ bool CAbstractVstEditor::HandleKeyMessage(MSG &msg)
if(ih->KeyEvent(kCtxVSTGUI, event, this) != kcNull)
return true;

if(handleGlobal && HandleGlobalKeyMessage(msg))
return true;

// Don't forward key repeats if plug does not listen for keypresses
// (avoids system beeps on note hold)
if(event.keyEventType == kKeyEventRepeat)
Expand Down
2 changes: 1 addition & 1 deletion mptrack/AbstractVstEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class CAbstractVstEditor : public DialogBase

protected:
BOOL PreTranslateMessage(MSG *msg) override;
bool HandleKeyMessage(MSG &msg);
bool HandleKeyMessage(MSG &msg, bool handleGlobal = false);
void UpdatePresetMenu(bool force = false);
void GeneratePresetMenu(int32 offset, CMenu &parent);
void UpdateInputMenu();
Expand Down
20 changes: 15 additions & 5 deletions mptrack/DialogBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,33 @@
OPENMPT_NAMESPACE_BEGIN

BOOL DialogBase::PreTranslateMessage(MSG *pMsg)
{
if(pMsg && HandleGlobalKeyMessage(*pMsg))
return TRUE;

return CDialog::PreTranslateMessage(pMsg);
}


bool DialogBase::HandleGlobalKeyMessage(const MSG &msg) const
{
// We handle keypresses before Windows has a chance to handle them (for alt etc..)
if(pMsg->message == WM_KEYDOWN || pMsg->message == WM_KEYUP || pMsg->message == WM_SYSKEYUP || pMsg->message == WM_SYSKEYDOWN)
if(msg.message == WM_KEYDOWN || msg.message == WM_KEYUP || msg.message == WM_SYSKEYUP || msg.message == WM_SYSKEYDOWN)
{
if(CInputHandler *ih = CMainFrame::GetInputHandler())
{
const auto event = ih->Translate(*pMsg);
const auto event = ih->Translate(msg);
if(ih->KeyEvent(kCtxAllContexts, event) != kcNull)
{
// Special case: ESC is typically bound to stopping playback, but we also want to allow ESC to close dialogs
if(pMsg->message != WM_KEYDOWN || pMsg->wParam != VK_ESCAPE)
return TRUE; // Mapped to a command, no need to pass message on.
if(msg.message != WM_KEYDOWN || msg.wParam != VK_ESCAPE)
return true; // Mapped to a command, no need to pass message on.
}
}
}

return CDialog::PreTranslateMessage(pMsg);
return false;
}


OPENMPT_NAMESPACE_END
3 changes: 3 additions & 0 deletions mptrack/DialogBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class DialogBase : public CDialog
using CDialog::CDialog;

BOOL PreTranslateMessage(MSG *pMsg) override;

protected:
bool HandleGlobalKeyMessage(const MSG &msg) const;
};

OPENMPT_NAMESPACE_END
2 changes: 1 addition & 1 deletion mptrack/VSTEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class COwnerVstEditor : public CAbstractVstEditor
LRESULT HandlePreTranslateMessage(UINT message, WPARAM wParam, LPARAM lParam)
{
MSG msg = {m_plugWindow, message, wParam, lParam, 0, {}};
return PreTranslateMessage(&msg);
return HandleKeyMessage(msg, true);
}

DECLARE_MESSAGE_MAP()
Expand Down

0 comments on commit 4e468b4

Please sign in to comment.