Skip to content
Permalink
Browse files

Add Emu.HasGui() to properly hide Qt dialogs in no-gui mode

  • Loading branch information
Megamouse committed Dec 3, 2019
1 parent 84f9911 commit 46ca39ec4dfb3c04eabb943d3c69385bd39ecbf0
@@ -1,4 +1,4 @@
#include "stdafx.h"
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h"
@@ -250,6 +250,7 @@ class Emulator final
u32 m_usrid{1};

bool m_force_boot = false;
bool m_has_gui = true;

public:
Emulator() = default;
@@ -372,6 +373,9 @@ class Emulator final
bool IsStopped() const { return m_state == system_state::stopped; }
bool IsReady() const { return m_state == system_state::ready; }
auto GetStatus() const { return m_state.load(); }

bool HasGui() const { return m_has_gui; }
void SetHasGui(bool has_gui) { m_has_gui = has_gui; }
};

extern Emulator Emu;
@@ -14,7 +14,7 @@ headless_application::headless_application(int& argc, char** argv) : QCoreApplic
void headless_application::Init()
{
// Force init the emulator
InitializeEmulator("1", true); // TODO: get user from cli args if possible
InitializeEmulator("1", true, false); // TODO: get user from cli args if possible

// Create callbacks from the emulator, which reference the handlers.
InitializeCallbacks();
@@ -44,8 +44,10 @@
#endif

/** Emu.Init() wrapper for user manager */
bool main_application::InitializeEmulator(const std::string& user, bool force_init)
bool main_application::InitializeEmulator(const std::string& user, bool force_init, bool show_gui)
{
Emu.SetHasGui(show_gui);

// try to set a new user
const bool user_was_set = Emu.SetUsr(user);

@@ -9,7 +9,7 @@ class main_application
public:
virtual void Init() = 0;

static bool InitializeEmulator(const std::string& user, bool force_init);
static bool InitializeEmulator(const std::string& user, bool force_init, bool show_gui);

protected:
virtual QThread* get_thread() = 0;
@@ -37,7 +37,7 @@ void gui_application::Init()
m_gui_settings.reset(new gui_settings());

// Force init the emulator
InitializeEmulator(m_gui_settings->GetCurrentUser().toStdString(), true);
InitializeEmulator(m_gui_settings->GetCurrentUser().toStdString(), true, m_show_gui);

// Create the main window
if (m_show_gui)
@@ -182,8 +182,8 @@ void gui_application::InitializeCallbacks()
callbacks.get_gs_frame = [this]() -> std::unique_ptr<GSFrameBase> { return get_gs_frame(); };
callbacks.get_msg_dialog = [this]() -> std::shared_ptr<MsgDialogBase> { return m_show_gui ? std::make_shared<msg_dialog_frame>() : nullptr; };
callbacks.get_osk_dialog = [this]() -> std::shared_ptr<OskDialogBase> { return m_show_gui ? std::make_shared<osk_dialog_frame>() : nullptr; };
callbacks.get_save_dialog = [this]() -> std::unique_ptr<SaveDialogBase> { return m_show_gui ? std::make_unique<save_data_dialog>() : nullptr; };
callbacks.get_trophy_notification_dialog = [this]() -> std::unique_ptr<TrophyNotificationBase> { return m_show_gui ? std::make_unique<trophy_notification_helper>(m_game_window) : nullptr; };
callbacks.get_save_dialog = []() -> std::unique_ptr<SaveDialogBase> { return std::make_unique<save_data_dialog>(); };
callbacks.get_trophy_notification_dialog = [this]() -> std::unique_ptr<TrophyNotificationBase> { return std::make_unique<trophy_notification_helper>(m_game_window); };

callbacks.on_run = [=]() { OnEmulatorRun(); };
callbacks.on_pause = [=]() { OnEmulatorPause(); };
@@ -14,6 +14,11 @@ s32 save_data_dialog::ShowSaveDataList(std::vector<SaveDataEntry>& save_entries,
return result;
}

if (!Emu.HasGui())
{
return -2;
}

// Fall back to front-end GUI
atomic_t<bool> dlg_result(false);
atomic_t<s32> selection;
@@ -1,4 +1,4 @@
#include "trophy_notification_helper.h"
#include "trophy_notification_helper.h"

#include "trophy_notification_frame.h"

@@ -12,6 +12,11 @@ s32 trophy_notification_helper::ShowTrophyNotification(const SceNpTrophyDetails&
return manager->create<rsx::overlays::trophy_notification>()->show(trophy, trophy_icon_buffer);
}

if (!Emu.HasGui())
{
return 0;
}

Emu.CallAfter([=]
{
trophy_notification_frame* trophy_notification = new trophy_notification_frame(trophy_icon_buffer, trophy, m_game_window->frameGeometry().height() / 10);
@@ -1,4 +1,4 @@
#pragma once
#pragma once

#include "stdafx.h"
#include "Emu/Memory/vm.h"
@@ -368,7 +368,7 @@ void user_manager_dialog::OnUserLogin()
const u32 key = GetUserKey();
const std::string new_user = m_user_list[key].GetUserId();

if (!main_application::InitializeEmulator(new_user, false))
if (!main_application::InitializeEmulator(new_user, false, Emu.HasGui()))
{
LOG_FATAL(GENERAL, "Failed to login user! username=%s key=%d", new_user, key);
return;

0 comments on commit 46ca39e

Please sign in to comment.
You can’t perform that action at this time.