From: <sv...@op...> - 2024-08-06 17:38:53
|
Author: sagamusix Date: Tue Aug 6 19:38:41 2024 New Revision: 21339 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=21339 Log: Merged revision(s) 21338 from trunk/OpenMPT: [Imp] When looking for an OpenMPT process to send an IPC command to, always try sending it to the OpenMPT window that was touched last, rather than simply the last match in the list. ........ Modified: branches/OpenMPT-1.31/ (props changed) branches/OpenMPT-1.31/mptrack/IPCWindow.cpp branches/OpenMPT-1.31/mptrack/IPCWindow.h branches/OpenMPT-1.31/mptrack/MainFrm.cpp Modified: branches/OpenMPT-1.31/mptrack/IPCWindow.cpp ============================================================================== --- branches/OpenMPT-1.31/mptrack/IPCWindow.cpp Tue Aug 6 19:36:59 2024 (r21338) +++ branches/OpenMPT-1.31/mptrack/IPCWindow.cpp Tue Aug 6 19:38:41 2024 (r21339) @@ -120,6 +120,12 @@ ipcWindow = nullptr; } + void UpdateLastUsed() + { + if(ipcWindow) + SetWindowLongPtr(ipcWindow, GWLP_USERDATA, mpt::saturate_cast<LONG_PTR>(GetTickCount64() / 100)); + } + LRESULT SendIPC(HWND ipcWnd, Function function, mpt::const_byte_span data) { if(!ipcWnd) @@ -144,13 +150,14 @@ struct EnumWindowState { - FlagSet<InstanceRequirements> require; + uint64 lastActive = 0; HWND result = nullptr; + FlagSet<InstanceRequirements> require; }; static BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) { - EnumWindowState &state = *reinterpret_cast<EnumWindowState*>(lParam); + EnumWindowState &state = *reinterpret_cast<EnumWindowState *>(lParam); if(hwnd) { TCHAR className[256]; @@ -187,9 +194,13 @@ return TRUE; // continue } } - state.result = hwnd; + uint64 lastActive = GetWindowLongPtr(hwnd, GWLP_USERDATA); + if(!state.result || lastActive >= state.lastActive) + { + state.result = hwnd; + state.lastActive = lastActive; + } return TRUE; // continue - //return FALSE; // done } } } Modified: branches/OpenMPT-1.31/mptrack/IPCWindow.h ============================================================================== --- branches/OpenMPT-1.31/mptrack/IPCWindow.h Tue Aug 6 19:36:59 2024 (r21338) +++ branches/OpenMPT-1.31/mptrack/IPCWindow.h Tue Aug 6 19:38:41 2024 (r21339) @@ -30,6 +30,8 @@ void Close(); + void UpdateLastUsed(); + LRESULT SendIPC(HWND ipcWnd, Function function, mpt::const_byte_span data = mpt::const_byte_span()); template <typename Tdata> LRESULT SendIPC(HWND ipcWnd, Function function, mpt::span<const Tdata> data) { return SendIPC(ipcWnd, function, mpt::const_byte_span(reinterpret_cast<const std::byte*>(data.data()), data.size() * sizeof(Tdata))); } Modified: branches/OpenMPT-1.31/mptrack/MainFrm.cpp ============================================================================== --- branches/OpenMPT-1.31/mptrack/MainFrm.cpp Tue Aug 6 19:36:59 2024 (r21338) +++ branches/OpenMPT-1.31/mptrack/MainFrm.cpp Tue Aug 6 19:38:41 2024 (r21339) @@ -50,6 +50,7 @@ #include "Vstplug.h" #include "FileDialog.h" #include "ProgressDialog.h" +#include "IPCWindow.h" #include <HtmlHelp.h> #include <Dbt.h> // device change messages #include "mpt/audio/span.hpp" @@ -465,11 +466,13 @@ } -void CMainFrame::OnActivateApp(BOOL active, DWORD /*threadID*/) +void CMainFrame::OnActivateApp(BOOL active, DWORD threadID) { - // Ensure modifiers are reset when we leave the window (e.g. Alt-Tab) - if(!active) - m_InputHandler->SetModifierMask(ModNone); + if(active) + IPCWindow::UpdateLastUsed(); + else + m_InputHandler->SetModifierMask(ModNone); // Ensure modifiers are reset when we leave the window (e.g. Alt-Tab) + CMDIFrameWnd::OnActivateApp(active, threadID); } @@ -2443,7 +2446,7 @@ { case kcViewTree: OnBarCheck(IDD_TREEVIEW); break; case kcViewOptions: OnViewOptions(); break; - case kcViewMain: OnBarCheck(59392 /* MAINVIEW */); break; + case kcViewMain: OnBarCheck(ID_VIEW_TOOLBAR); break; case kcFileImportMidiLib: OnImportMidiLib(); break; case kcFileAddSoundBank: OnAddDlsBank(); break; case kcPauseSong: OnPlayerPause(); break; |