From a147d576a6d0b0f838bce6511782e73f52844e62 Mon Sep 17 00:00:00 2001 From: Pprighi Date: Fri, 29 Nov 2024 00:17:45 +0100 Subject: [PATCH] scx: show all flags when changing profile or scheduler (#30) When a scheduler or profile is selected, its options are currently hidden and uneditable. With this change, users can always view and modify these options. Signed-off-by: Pietro Righi --- src/schedext-window.cpp | 33 ++++++++++++++++++++++----------- src/schedext-window.hpp | 1 + 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/schedext-window.cpp b/src/schedext-window.cpp index 8bb1cfa..e137760 100644 --- a/src/schedext-window.cpp +++ b/src/schedext-window.cpp @@ -175,6 +175,10 @@ SchedExtWindow::SchedExtWindow(QWidget* parent) << "Lowlatency" << "Powersave"; m_ui->schedext_profile_combo_box->addItems(sched_profiles); + connect(m_ui->schedext_profile_combo_box, + QOverload::of(&QComboBox::currentIndexChanged), + this, + &SchedExtWindow::on_sched_profile_changed); m_ui->current_sched_label->setText(QString::fromStdString(get_current_scheduler())); @@ -222,6 +226,23 @@ void SchedExtWindow::on_disable() noexcept { m_ui->apply_button->setEnabled(true); } +void SchedExtWindow::on_sched_profile_changed() noexcept { + const auto& current_selected = m_ui->schedext_combo_box->currentText().toStdString(); + const auto& current_profile = m_ui->schedext_profile_combo_box->currentText().toStdString(); + const auto& scx_mode = get_scx_mode_from_str(current_profile); + + auto sched_args = QStringList(); + if (auto scx_flags_for_mode = m_scx_config->scx_flags_for_mode(current_selected, scx_mode); scx_flags_for_mode) { + if (!scx_flags_for_mode->empty()) { + sched_args << std::move(*scx_flags_for_mode); + } + } else { + QMessageBox::critical(this, "CachyOS Kernel Manager", tr("Cannot get scx flags from scx_loader configuration!")); + } + + m_ui->schedext_flags_edit->setText(sched_args.join(' ')); +} + void SchedExtWindow::on_sched_changed() noexcept { const auto& scheduler = m_ui->schedext_combo_box->currentText(); @@ -236,6 +257,7 @@ void SchedExtWindow::on_sched_changed() noexcept { m_ui->scheduler_profile_select_label->setVisible(false); m_ui->schedext_profile_combo_box->setVisible(false); } + on_sched_profile_changed(); } void SchedExtWindow::on_apply() noexcept { @@ -250,20 +272,9 @@ void SchedExtWindow::on_apply() noexcept { const auto& current_selected = m_ui->schedext_combo_box->currentText().toStdString(); const auto& current_profile = m_ui->schedext_profile_combo_box->currentText().toStdString(); const auto& extra_flags = m_ui->schedext_flags_edit->text().trimmed().toStdString(); - const auto& scx_mode = get_scx_mode_from_str(current_profile); auto sched_args = QStringList(); - if (auto scx_flags_for_mode = m_scx_config->scx_flags_for_mode(current_selected, scx_mode); scx_flags_for_mode) { - if (!scx_flags_for_mode->empty()) { - sched_args << std::move(*scx_flags_for_mode); - } - } else { - QMessageBox::critical(this, "CachyOS Kernel Manager", tr("Cannot get scx flags from scx_loader configuration!")); - } - - // NOTE: maybe we should also take into consideration these custom flags, - // but then the question how it should be displayed/handled if (!extra_flags.empty()) { sched_args << QString::fromStdString(extra_flags).split(' '); } diff --git a/src/schedext-window.hpp b/src/schedext-window.hpp index 4200832..01c2ef2 100644 --- a/src/schedext-window.hpp +++ b/src/schedext-window.hpp @@ -69,6 +69,7 @@ class SchedExtWindow final : public QMainWindow { void on_apply() noexcept; void on_disable() noexcept; void on_sched_changed() noexcept; + void on_sched_profile_changed() noexcept; const std::string_view m_config_path{"/etc/scx_loader.toml"}; scx::loader::ConfigPtr m_scx_config;