From d854ff03febb59d7f37b98ae05d0ffb50d2dca93 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Tue, 13 Jan 2026 13:55:22 +0100 Subject: [PATCH] Qt: allow to disable logging to the log frame while it is hidden --- rpcs3/Emu/Io/usb_microphone.cpp | 4 +-- rpcs3/rpcs3qt/gui_settings.h | 1 + rpcs3/rpcs3qt/log_frame.cpp | 57 +++++++++++++++++++++------------ rpcs3/rpcs3qt/log_frame.h | 1 + 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/rpcs3/Emu/Io/usb_microphone.cpp b/rpcs3/Emu/Io/usb_microphone.cpp index 743fadb66a..39bf45d91d 100644 --- a/rpcs3/Emu/Io/usb_microphone.cpp +++ b/rpcs3/Emu/Io/usb_microphone.cpp @@ -599,7 +599,7 @@ void usb_device_mic::control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, case GET_MIN: { ensure(buf_size >= 2); - constexpr s16 minVol = 0xff00; + constexpr s16 minVol = -256; buf[0] = (minVol ) & 0xff; buf[1] = (minVol >> 8) & 0xff; usb_mic_log.notice("Get Min Volume: 0x%04x (%d dB)", minVol, minVol / 256); @@ -608,7 +608,7 @@ void usb_device_mic::control_transfer(u8 bmRequestType, u8 bRequest, u16 wValue, case GET_MAX: { ensure(buf_size >= 2); - constexpr s16 maxVol = 0x0100; + constexpr s16 maxVol = 256; buf[0] = (maxVol ) & 0xff; buf[1] = (maxVol >> 8) & 0xff; usb_mic_log.notice("Get Max Volume: 0x%04x (%d dB)", maxVol, maxVol / 256); diff --git a/rpcs3/rpcs3qt/gui_settings.h b/rpcs3/rpcs3qt/gui_settings.h index fbf66dceed..a3b6fb4286 100644 --- a/rpcs3/rpcs3qt/gui_settings.h +++ b/rpcs3/rpcs3qt/gui_settings.h @@ -237,6 +237,7 @@ namespace gui const gui_save l_ansi_code = gui_save(logger, "ANSI_code", true); const gui_save l_limit = gui_save(logger, "limit", 1000); const gui_save l_limit_tty = gui_save(logger, "TTY_limit", 1000); + const gui_save l_log_hide = gui_save(logger, "Log hide", false); const gui_save d_splitterState = gui_save(debugger, "splitterState", QByteArray()); diff --git a/rpcs3/rpcs3qt/log_frame.cpp b/rpcs3/rpcs3qt/log_frame.cpp index 2080cdabcf..6d99791799 100644 --- a/rpcs3/rpcs3qt/log_frame.cpp +++ b/rpcs3/rpcs3qt/log_frame.cpp @@ -39,6 +39,7 @@ struct gui_listener : logs::listener lf_queue queue; atomic_t show_prefix{false}; + atomic_t logging_enabled{true}; gui_listener() : logs::listener() @@ -55,7 +56,7 @@ struct gui_listener : logs::listener { Q_UNUSED(stamp) - if (msg <= enabled) + if (msg <= enabled && (logging_enabled || msg <= logs::level::fatal)) { packet_t p,* _new = &p; _new->sev = msg; @@ -237,7 +238,7 @@ void log_frame::CreateAndConnectActions() }; m_clear_act = new QAction(tr("Clear"), this); - connect(m_clear_act, &QAction::triggered, [this]() + connect(m_clear_act, &QAction::triggered, this, [this]() { m_old_log_text.clear(); m_log->clear(); @@ -245,14 +246,14 @@ void log_frame::CreateAndConnectActions() }); m_clear_tty_act = new QAction(tr("Clear"), this); - connect(m_clear_tty_act, &QAction::triggered, [this]() + connect(m_clear_tty_act, &QAction::triggered, this, [this]() { m_old_tty_text.clear(); m_tty->clear(); }); m_perform_goto_on_debugger = new QAction(tr("Go-To on Debugger"), this); - connect(m_perform_goto_on_debugger, &QAction::triggered, [this]() + connect(m_perform_goto_on_debugger, &QAction::triggered, this, [this]() { QPlainTextEdit* pte = (m_tabWidget->currentIndex() == 1 ? m_tty : m_log); Q_EMIT PerformGoToOnDebugger(pte->textCursor().selectedText(), true); @@ -274,7 +275,7 @@ void log_frame::CreateAndConnectActions() }); m_perform_goto_thread_on_debugger = new QAction(tr("Show Thread on Debugger"), this); - connect(m_perform_goto_thread_on_debugger, &QAction::triggered, [this]() + connect(m_perform_goto_thread_on_debugger, &QAction::triggered, this, [this]() { QPlainTextEdit* pte = (m_tabWidget->currentIndex() == 1 ? m_tty : m_log); Q_EMIT PerformGoToOnDebugger(pte->textCursor().selectedText(), false); @@ -282,7 +283,7 @@ void log_frame::CreateAndConnectActions() m_stack_act_tty = new QAction(tr("Stack Mode (TTY)"), this); m_stack_act_tty->setCheckable(true); - connect(m_stack_act_tty, &QAction::toggled, [this](bool checked) + connect(m_stack_act_tty, &QAction::toggled, this, [this](bool checked) { m_gui_settings->SetValue(gui::l_stack_tty, checked); m_stack_tty = checked; @@ -290,7 +291,7 @@ void log_frame::CreateAndConnectActions() m_ansi_act_tty = new QAction(tr("ANSI Code (TTY)"), this); m_ansi_act_tty->setCheckable(true); - connect(m_ansi_act_tty, &QAction::toggled, [this](bool checked) + connect(m_ansi_act_tty, &QAction::toggled, this, [this](bool checked) { m_gui_settings->SetValue(gui::l_ansi_code, checked); m_ansi_tty = checked; @@ -311,7 +312,7 @@ void log_frame::CreateAndConnectActions() QAction* all_channels_act = new QAction(tr("All user channels"), m_tty_channel_acts); all_channels_act->setCheckable(true); all_channels_act->setChecked(m_tty_channel == -1); - connect(all_channels_act, &QAction::triggered, [this]() + connect(all_channels_act, &QAction::triggered, this, [this]() { m_tty_channel = -1; m_tty_input->setPlaceholderText(tr("All user channels")); @@ -322,7 +323,7 @@ void log_frame::CreateAndConnectActions() QAction* act = new QAction(tr("Channel %0").arg(i), m_tty_channel_acts); act->setCheckable(true); act->setChecked(i == m_tty_channel); - connect(act, &QAction::triggered, [this, i]() + connect(act, &QAction::triggered, this, [this, i]() { m_tty_channel = i; m_tty_input->setPlaceholderText(tr("Channel %0").arg(m_tty_channel)); @@ -343,7 +344,7 @@ void log_frame::CreateAndConnectActions() m_stack_act_log = new QAction(tr("Stack Mode (Log)"), this); m_stack_act_log->setCheckable(true); - connect(m_stack_act_log, &QAction::toggled, [this](bool checked) + connect(m_stack_act_log, &QAction::toggled, this, [this](bool checked) { m_gui_settings->SetValue(gui::l_stack, checked); m_stack_log = checked; @@ -351,7 +352,7 @@ void log_frame::CreateAndConnectActions() m_stack_act_err = new QAction(tr("Stack Cell Errors"), this); m_stack_act_err->setCheckable(true); - connect(m_stack_act_err, &QAction::toggled, [this](bool checked) + connect(m_stack_act_err, &QAction::toggled, this, [this](bool checked) { m_gui_settings->SetValue(gui::l_stack_err, checked); g_log_all_errors = !checked; @@ -359,15 +360,27 @@ void log_frame::CreateAndConnectActions() m_show_prefix_act = new QAction(tr("Show Thread Prefix"), this); m_show_prefix_act->setCheckable(true); - connect(m_show_prefix_act, &QAction::toggled, [this](bool checked) + connect(m_show_prefix_act, &QAction::toggled, this, [this](bool checked) { m_gui_settings->SetValue(gui::l_prefix, checked); s_gui_listener.show_prefix = checked; }); + m_log_while_hidden_act = new QAction(tr("Print Log/TTY while hidden"), this); + m_log_while_hidden_act->setCheckable(true); + connect(m_log_while_hidden_act, &QAction::toggled, this, [this](bool checked) + { + m_gui_settings->SetValue(gui::l_log_hide, checked); + s_gui_listener.logging_enabled = checked || isVisible(); + }); + connect(this, &log_frame::visibilityChanged, this, [this](bool visible) + { + s_gui_listener.logging_enabled = m_log_while_hidden_act->isChecked() || visible; + }); + m_tty_act = new QAction(tr("Enable TTY"), this); m_tty_act->setCheckable(true); - connect(m_tty_act, &QAction::triggered, [this](bool checked) + connect(m_tty_act, &QAction::triggered, this, [this](bool checked) { m_gui_settings->SetValue(gui::l_tty, checked); }); @@ -381,7 +394,7 @@ void log_frame::CreateAndConnectActions() l_initAct(m_notice_act, logs::level::notice); l_initAct(m_trace_act, logs::level::trace); - connect(m_log, &QWidget::customContextMenuRequested, [this](const QPoint& pos) + connect(m_log, &QWidget::customContextMenuRequested, this, [this](const QPoint& pos) { QMenu* menu = m_log->createStandardContextMenu(); menu->addAction(m_clear_act); @@ -403,13 +416,14 @@ void log_frame::CreateAndConnectActions() menu->addAction(m_stack_act_log); menu->addAction(m_stack_act_err); menu->addAction(m_show_prefix_act); + menu->addAction(m_log_while_hidden_act); menu->addSeparator(); menu->addActions(m_log_level_acts->actions()); menu->exec(m_log->viewport()->mapToGlobal(pos)); }); - connect(m_tty, &QWidget::customContextMenuRequested, [this](const QPoint& pos) + connect(m_tty, &QWidget::customContextMenuRequested, this, [this](const QPoint& pos) { QMenu* menu = m_tty->createStandardContextMenu(); menu->addAction(m_clear_tty_act); @@ -432,13 +446,13 @@ void log_frame::CreateAndConnectActions() menu->exec(m_tty->viewport()->mapToGlobal(pos)); }); - connect(m_tabWidget, &QTabWidget::currentChanged, [this](int/* index*/) + connect(m_tabWidget, &QTabWidget::currentChanged, this, [this](int/* index*/) { if (m_find_dialog) m_find_dialog->close(); }); - connect(m_tty_input, &QLineEdit::returnPressed, [this]() + connect(m_tty_input, &QLineEdit::returnPressed, this, [this]() { std::string text = m_tty_input->text().toStdString(); @@ -492,6 +506,9 @@ void log_frame::LoadSettings() m_ansi_act_tty->setChecked(m_ansi_tty); m_stack_act_err->setChecked(!g_log_all_errors); + m_log_while_hidden_act->setChecked(m_gui_settings->GetValue(gui::l_log_hide).toBool()); + s_gui_listener.logging_enabled = m_log_while_hidden_act->isChecked() || isVisible(); + s_gui_listener.show_prefix = m_gui_settings->GetValue(gui::l_prefix).toBool(); m_show_prefix_act->setChecked(s_gui_listener.show_prefix); @@ -599,9 +616,9 @@ void log_frame::UpdateUI() const std::chrono::time_point log_timeout = start + 7ms; // Check TTY logs - if (u64 size = std::max(0, m_tty_file ? (g_tty_size.load() - m_tty_file.pos()) : 0)) + if (const u64 size = std::max(0, m_tty_file ? (g_tty_size.load() - m_tty_file.pos()) : 0)) { - if (m_tty_act->isChecked()) + if (m_tty_act->isChecked() && s_gui_listener.logging_enabled) { m_tty_buf.resize(std::min(size, m_tty_limited_read ? m_tty_limited_read : usz{umax})); m_tty_buf.resize(m_tty_file.read(&m_tty_buf.front(), m_tty_buf.size())); @@ -781,7 +798,7 @@ void log_frame::UpdateUI() usz first_rep_counter = m_log_counter; // Batch output of multiple lines if possible (optimization) - auto flush = [&]() + const auto flush = [&]() { if (m_log_text.isEmpty() && !is_first_rep) { diff --git a/rpcs3/rpcs3qt/log_frame.h b/rpcs3/rpcs3qt/log_frame.h index 35bd3a7ab1..7bdd304c5f 100644 --- a/rpcs3/rpcs3qt/log_frame.h +++ b/rpcs3/rpcs3qt/log_frame.h @@ -95,6 +95,7 @@ private: QAction* m_stack_act_err = nullptr; QAction* m_show_prefix_act = nullptr; + QAction* m_log_while_hidden_act = nullptr; QAction* m_tty_act = nullptr;