Skip to content

Commit

Permalink
scx: show all flags when changing profile or scheduler (#30)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Pprighi authored Nov 28, 2024
1 parent 76a95e2 commit a147d57
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/schedext-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>::of(&QComboBox::currentIndexChanged),
this,
&SchedExtWindow::on_sched_profile_changed);

m_ui->current_sched_label->setText(QString::fromStdString(get_current_scheduler()));

Expand Down Expand Up @@ -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();

Expand All @@ -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 {
Expand All @@ -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(' ');
}
Expand Down
1 change: 1 addition & 0 deletions src/schedext-window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a147d57

Please sign in to comment.