IPC: add the settings dialog

This commit is contained in:
Gauvain 'GovanifY' Roussel-Tarbouriech 2021-03-03 23:59:18 +01:00 committed by refractionpcsx2
parent 0be35a3799
commit 52c1d027ee
10 changed files with 345 additions and 237 deletions

View File

@ -611,6 +611,7 @@ set(pcsx2GuiSources
gui/Dialogs/McdConfigDialog.cpp
gui/Dialogs/PickUserModeDialog.cpp
gui/Dialogs/SysConfigDialog.cpp
gui/Dialogs/IPCDialog.cpp
gui/Debugger/BreakpointWindow.cpp
gui/Debugger/CtrlDisassemblyView.cpp
gui/Debugger/CtrlRegisterList.cpp

View File

@ -82,20 +82,17 @@ SocketIPC::SocketIPC(SysCoreThread* vm, unsigned int slot)
#endif
// fallback in case macOS or other OSes don't implement the XDG base
// spec
char* tmp_socket;
if (runtime_dir == NULL)
m_socket_name = tmp_socket = (char*)"/tmp/" IPC_EMULATOR_NAME ".sock";
m_socket_name = (char*)"/tmp/" IPC_EMULATOR_NAME ".sock";
else
m_socket_name = tmp_socket = strcat(runtime_dir, "/" IPC_EMULATOR_NAME ".sock");
m_socket_name = strcat(runtime_dir, "/" IPC_EMULATOR_NAME ".sock");
if (slot != IPC_DEFAULT_SLOT)
{
// maximum size of .%u
char slot_ending[34];
sprintf(slot_ending, ".%u", slot);
m_socket_name = strcat(tmp_socket, slot_ending);
free(tmp_socket);
m_socket_name = strcat(m_socket_name, slot_ending);
}
struct sockaddr_un server;

View File

@ -51,6 +51,11 @@
bool g_CDVDReset = false;
namespace IPCSettings
{
unsigned int slot = IPC_DEFAULT_SLOT;
};
// --------------------------------------------------------------------------------------
// SysCoreThread *External Thread* Implementations
// (Called from outside the context of this thread)
@ -270,7 +275,7 @@ void SysCoreThread::GameStartingInThread()
if (EmuConfig.EnableIPC && m_IpcState == OFF)
{
m_IpcState = ON;
m_socketIpc = std::make_unique<SocketIPC>(this);
m_socketIpc = std::make_unique<SocketIPC>(this, IPCSettings::slot);
}
if (m_IpcState == ON && m_socketIpc->m_end)
m_socketIpc->Start();

View File

@ -267,3 +267,8 @@ protected:
extern SysCoreThread& GetCoreThread();
extern bool g_CDVDReset;
namespace IPCSettings
{
extern unsigned int slot;
};

View File

@ -122,7 +122,6 @@ enum MenuIdentifiers
MenuId_GameSettingsSubMenu,
MenuId_EnablePatches,
MenuId_EnableCheats,
MenuId_EnableIPC,
MenuId_EnableWideScreenPatches,
MenuId_EnableInputRecording,
MenuId_EnableLuaTools,
@ -210,6 +209,11 @@ enum MenuIdentifiers
MenuId_Recording_VirtualPad_Port1,
#endif
// IPC Subsection
MenuId_IPC,
MenuId_IPC_Enable,
MenuId_IPC_Settings,
};
namespace Exception
@ -229,7 +233,7 @@ namespace Exception
}
};
}
} // namespace Exception
// --------------------------------------------------------------------------------------
// AppImageIds - Config and Toolbar Images and Icons
@ -414,7 +418,8 @@ public:
bool HasPluginsOverride() const
{
for (int i = 0; i < PluginId_Count; ++i)
if( Filenames.Plugins[i].IsOk() ) return true;
if (Filenames.Plugins[i].IsOk())
return true;
return false;
}
@ -578,7 +583,10 @@ public:
DisassemblyDialog* GetDisassemblyPtr() const { return (DisassemblyDialog*)wxWindow::FindWindowById(m_id_Disassembler); }
#ifndef DISABLE_RECORDING
NewRecordingFrame* GetNewRecordingFramePtr() const { return (NewRecordingFrame*)wxWindow::FindWindowById(m_id_NewRecordingFrame); }
NewRecordingFrame* GetNewRecordingFramePtr() const
{
return (NewRecordingFrame*)wxWindow::FindWindowById(m_id_NewRecordingFrame);
}
#endif
void enterDebugMode();
@ -728,18 +736,22 @@ wxDECLARE_APP(Pcsx2App);
// conditionals or temp variable defines in the code.
//
#define sApp \
if( Pcsx2App* __app_ = (Pcsx2App*)wxApp::GetInstance() ) (*__app_)
if (Pcsx2App* __app_ = (Pcsx2App*)wxApp::GetInstance()) \
(*__app_)
#define sLogFrame \
if( ConsoleLogFrame* __conframe_ = wxGetApp().GetProgramLog() ) (*__conframe_)
if (ConsoleLogFrame* __conframe_ = wxGetApp().GetProgramLog()) \
(*__conframe_)
#define sMainFrame \
if( MainEmuFrame* __frame_ = GetMainFramePtr() ) (*__frame_)
if (MainEmuFrame* __frame_ = GetMainFramePtr()) \
(*__frame_)
// Use this within the scope of a wxWindow (wxDialog or wxFrame). If the window has a valid menu
// bar, the command will run, otherwise it will be silently ignored. :)
#define sMenuBar \
if( wxMenuBar* __menubar_ = GetMenuBar() ) (*__menubar_)
if (wxMenuBar* __menubar_ = GetMenuBar()) \
(*__menubar_)
// --------------------------------------------------------------------------------------
// AppOpenDialog
@ -751,7 +763,8 @@ wxWindow* AppOpenDialog( wxWindow* parent=NULL )
{
wxWindow* window = wxFindWindowByName(L"Dialog:" + DialogType::GetNameStatic());
if( !window ) window = new DialogType( parent );
if (!window)
window = new DialogType(parent);
window->Show();
window->SetFocus();
@ -772,7 +785,8 @@ int AppOpenModalDialog(wxString panel_name, wxWindow* parent = NULL)
if (wxDialog* dialog = wxDynamicCast(window, wxDialog))
{
// Switch to the requested panel.
if (panel_name != wxEmptyString) {
if (panel_name != wxEmptyString)
{
wxCommandEvent evt(pxEvt_SetSettingsPage);
evt.SetString(panel_name);
dialog->GetEventHandler()->ProcessEvent(evt);
@ -790,7 +804,8 @@ int AppOpenModalDialog(wxString panel_name, wxWindow* parent = NULL)
}
pxFailDev("Can only show wxDialog class windows as modal!");
return wxID_CANCEL;
} else
}
else
return DialogType(parent).ShowModal();
}

View File

@ -0,0 +1,61 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "PrecompiledHeader.h"
#include "App.h"
#include "AppCommon.h"
#include "MSWstuff.h"
#include "Dialogs/ModalPopups.h"
#include "System/SysThreads.h"
#include "PathDefs.h"
#include "AppConfig.h"
using namespace pxSizerFlags;
/* This dialog currently assumes the IPC server is started when launching a
* game, as such we can allow the IPC Settings window to change the slot in a
* volatile fashion so that it returns to the default but you can change it at
* each restart of the emulator to allow for multiple emulator sessions.
* If we change this behaviour we will need to change that accordingly.
*/
// --------------------------------------------------------------------------------------
// IPCDialog Implementation
// --------------------------------------------------------------------------------------
Dialogs::IPCDialog::IPCDialog(wxWindow* parent)
: wxDialogWithHelpers(parent, _("IPC Settings"), pxDialogFlags())
{
wxTextCtrl* ipc_slot = new wxTextCtrl(this, wxID_ANY, wxString::Format(wxT("%u"), IPCSettings::slot), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
ipc_slot->Bind(wxEVT_TEXT_ENTER, &Dialogs::IPCDialog::OnConfirm, this);
wxButton* confirm = new wxButton(this, wxID_OK);
confirm->SetDefault();
*this += new wxStaticText(this, wxID_ANY, _("IPC Slot"));
*this += ipc_slot;
*this += confirm;
}
void Dialogs::IPCDialog::OnConfirm(wxCommandEvent& evt)
{
wxTextCtrl* textbox = dynamic_cast<wxTextCtrl*>(evt.GetEventObject());
if (textbox)
{
IPCSettings::slot = (unsigned int)atoi(textbox->GetValue().ToUTF8().data());
}
}

View File

@ -101,6 +101,17 @@ namespace Dialogs
AssertionDialog( const wxString& text, const wxString& stacktrace );
virtual ~AssertionDialog() = default;
};
class IPCDialog : public wxDialogWithHelpers
{
public:
IPCDialog(wxWindow* parent = NULL);
virtual ~IPCDialog() = default;
void OnConfirm(wxCommandEvent& evt);
static wxString GetNameStatic() { return L"IPCSettings"; }
wxString GetDialogName() const { return GetNameStatic(); }
};
}
wxWindowID pxIssueConfirmation( wxDialogWithHelpers& confirmDlg, const MsgButtons& buttons );

View File

@ -233,7 +233,8 @@ void MainEmuFrame::ConnectMenus()
Bind(wxEVT_MENU, &MainEmuFrame::Menu_EnablePatches_Click, this, MenuId_EnablePatches);
Bind(wxEVT_MENU, &MainEmuFrame::Menu_EnableCheats_Click, this, MenuId_EnableCheats);
Bind(wxEVT_MENU, &MainEmuFrame::Menu_EnableIPC_Click, this, MenuId_EnableIPC);
Bind(wxEVT_MENU, &MainEmuFrame::Menu_IPC_Enable_Click, this, MenuId_IPC_Enable);
Bind(wxEVT_MENU, &MainEmuFrame::Menu_IPC_Settings_Click, this, MenuId_IPC_Settings);
Bind(wxEVT_MENU, &MainEmuFrame::Menu_EnableWideScreenPatches_Click, this, MenuId_EnableWideScreenPatches);
#ifndef DISABLE_RECORDING
Bind(wxEVT_MENU, &MainEmuFrame::Menu_EnableRecordingTools_Click, this, MenuId_EnableInputRecording);
@ -393,9 +394,13 @@ void MainEmuFrame::CreatePcsx2Menu()
m_GameSettingsSubmenu.Append(MenuId_EnableCheats, _("Enable &Cheats"),
_("Use cheats otherwise known as pnachs from the cheats folder."), wxITEM_CHECK);
m_GameSettingsSubmenu.Append(MenuId_EnableIPC, _("Enable &IPC"),
m_GameSettingsSubmenu.Append(MenuId_IPC_Enable, _("Configure &IPC"), &m_submenuIPC);
m_submenuIPC.Append(MenuId_IPC, _("&Enable IPC"),
wxEmptyString, wxITEM_CHECK);
m_submenuIPC.Append(MenuId_IPC_Settings, _("IPC &Settings"));
m_GameSettingsSubmenu.Append(MenuId_EnableWideScreenPatches, _("Enable &Widescreen Patches"),
_("Enabling Widescreen Patches may occasionally cause issues."), wxITEM_CHECK);
@ -551,6 +556,7 @@ MainEmuFrame::MainEmuFrame(wxWindow* parent, const wxString& title)
, m_menuWindow(*new wxMenu())
, m_menuCapture(*new wxMenu())
, m_submenuVideoCapture(*new wxMenu())
, m_submenuIPC(*new wxMenu())
, m_submenuScreenshot(*new wxMenu())
#ifndef DISABLE_RECORDING
, m_menuRecording(*new wxMenu())
@ -800,7 +806,7 @@ void MainEmuFrame::ApplyConfigToGui(AppConfig& configToApply, int flags)
{ //these should not be affected by presets
menubar.Check(MenuId_EnableBackupStates, configToApply.EmuOptions.BackupSavestate);
menubar.Check(MenuId_EnableCheats, configToApply.EmuOptions.EnableCheats);
menubar.Check(MenuId_EnableIPC, configToApply.EmuOptions.EnableIPC);
menubar.Check(MenuId_IPC_Enable, configToApply.EmuOptions.EnableIPC);
menubar.Check(MenuId_EnableWideScreenPatches, configToApply.EmuOptions.EnableWideScreenPatches);
#ifndef DISABLE_RECORDING
menubar.Check(MenuId_EnableInputRecording, configToApply.EmuOptions.EnableRecordingTools);

View File

@ -117,6 +117,7 @@ protected:
wxMenu& m_menuCapture;
wxMenu& m_submenuVideoCapture;
wxMenu& m_submenuIPC;
wxMenu& m_submenuScreenshot;
#ifndef DISABLE_RECORDING
@ -208,7 +209,8 @@ protected:
void Menu_EnableBackupStates_Click(wxCommandEvent& event);
void Menu_EnablePatches_Click(wxCommandEvent& event);
void Menu_EnableCheats_Click(wxCommandEvent& event);
void Menu_EnableIPC_Click(wxCommandEvent& event);
void Menu_IPC_Enable_Click(wxCommandEvent& event);
void Menu_IPC_Settings_Click(wxCommandEvent& event);
void Menu_EnableWideScreenPatches_Click(wxCommandEvent& event);
#ifndef DISABLE_RECORDING
void Menu_EnableRecordingTools_Click(wxCommandEvent& event);

View File

@ -53,6 +53,11 @@ void MainEmuFrame::Menu_SysSettings_Click(wxCommandEvent& event)
AppOpenDialog<SysConfigDialog>(this);
}
void MainEmuFrame::Menu_IPC_Settings_Click(wxCommandEvent& event)
{
AppOpenDialog<IPCDialog>(this);
}
void MainEmuFrame::Menu_AudioSettings_Click(wxCommandEvent& event)
{
SPU2configure();
@ -564,9 +569,9 @@ void MainEmuFrame::Menu_EnableCheats_Click(wxCommandEvent&)
AppSaveSettings();
}
void MainEmuFrame::Menu_EnableIPC_Click(wxCommandEvent&)
void MainEmuFrame::Menu_IPC_Enable_Click(wxCommandEvent&)
{
g_Conf->EmuOptions.EnableIPC = GetMenuBar()->IsChecked(MenuId_EnableIPC);
g_Conf->EmuOptions.EnableIPC = GetMenuBar()->IsChecked(MenuId_IPC_Enable);
AppApplySettings();
AppSaveSettings();
}