diff --git a/data/scripts/change_scx.sh b/data/scripts/change_scx.sh new file mode 100755 index 0000000..fa5f351 --- /dev/null +++ b/data/scripts/change_scx.sh @@ -0,0 +1,10 @@ +#! /bin/bash + +if [[ "$1" == "scx_disabled" ]]; then + systemctl stop scx & systemctl disable scx +else + set -e + sed -i 's/SCX_SCHEDULER=.*/SCX_SCHEDULER="$1"/' /etc/default/scx + systemctl enable --now scx + systemctl restart scx +fi \ No newline at end of file diff --git a/data/scripts/core b/data/scripts/core index 7db5efa..d599a76 100644 Binary files a/data/scripts/core and b/data/scripts/core differ diff --git a/data/scripts/get_version.sh b/data/scripts/get_version.sh old mode 100644 new mode 100755 diff --git a/data/scripts/kernel-cachyos-init.sh b/data/scripts/kernel-cachyos-init.sh old mode 100644 new mode 100755 diff --git a/data/scripts/modify_package.sh b/data/scripts/modify_package.sh old mode 100644 new mode 100755 diff --git a/src/build_ui/mod.rs b/src/build_ui/mod.rs index a31782b..2571811 100644 --- a/src/build_ui/mod.rs +++ b/src/build_ui/mod.rs @@ -86,7 +86,7 @@ pub fn build_ui(app: &adw::Application) { Some("content_page"), ); content_stack.add_named( - &sched_ext::sched_ext_page(&content_stack), + &sched_ext::sched_ext_page(&content_stack, &window), Some("sched_ext_page"), ); diff --git a/src/kernel_pkg/mod.rs b/src/kernel_pkg/mod.rs index 588c5b7..f547457 100644 --- a/src/kernel_pkg/mod.rs +++ b/src/kernel_pkg/mod.rs @@ -463,7 +463,7 @@ fn get_cpu_feature_level() -> String { .trim_end_matches("(supported, searched)") .trim() .to_string(), - _ => "x86_64-v1".to_string(), + _ => "x86-64-v1".to_string(), }; result } diff --git a/src/sched_ext/mod.rs b/src/sched_ext/mod.rs index 10b7b81..c4ff683 100644 --- a/src/sched_ext/mod.rs +++ b/src/sched_ext/mod.rs @@ -4,10 +4,13 @@ use adw::prelude::*; use glib::*; use gtk::prelude::*; use gtk::*; -use std::fs; +use std::{fs, io}; use std::fs::*; +use std::process::Stdio; +use duct::cmd; +use gtk::AccessibleRole::Command; -pub fn sched_ext_page(content_stack: >k::Stack) -> gtk::Box { +pub fn sched_ext_page(content_stack: >k::Stack, window: &adw::ApplicationWindow,) -> gtk::Box { let main_box = gtk::Box::builder() .hexpand(true) .vexpand(true) @@ -60,7 +63,12 @@ pub fn sched_ext_page(content_stack: >k::Stack) -> gtk::Box { .subtitle("Select Sched-EXT Scheduler") .build(); - scx_sched_expander_row.add_row(&scx_sched_expandable(&scx_sched_expander_row)); + scx_sched_expander_row.add_row(&scx_sched_expandable(&scx_sched_expander_row, + &window, + &badge_box, + &kernel_badges_size_group, + &kernel_badges_size_group0, + &kernel_badges_size_group1,)); let scx_sched_expander_row_boxedlist = gtk::ListBox::builder() .selection_mode(SelectionMode::None) @@ -147,7 +155,13 @@ fn create_current_sched_badge( )); } -fn scx_sched_expandable(expander_row: &adw::ExpanderRow) -> gtk::ListBox { +fn scx_sched_expandable(expander_row: &adw::ExpanderRow, + window: &adw::ApplicationWindow, + badge_box: >k::Box, + kernel_badges_size_group: >k::SizeGroup, + kernel_badges_size_group0: >k::SizeGroup, + kernel_badges_size_group1: >k::SizeGroup, +) -> gtk::ListBox { let searchbar = gtk::SearchEntry::builder().search_delay(500).build(); searchbar.add_css_class("round-border-only-top"); @@ -181,15 +195,38 @@ fn scx_sched_expandable(expander_row: &adw::ExpanderRow) -> gtk::ListBox { .build(); let branch_row = adw::ActionRow::builder() .activatable_widget(&sched_checkbutton) - .title(sched) + .title(&sched) .build(); branch_row.add_prefix(&sched_checkbutton); sched_checkbutton.set_group(Some(&null_checkbutton)); sched_container.append(&branch_row); + let cmd_status_dialog = adw::MessageDialog::builder() + .transient_for(window) + .hide_on_close(true) + .build(); + cmd_status_dialog.add_response( + "cmd_status_dialog_ok", + "Ok", + ); sched_checkbutton.connect_toggled( - clone!(@weak sched_checkbutton, @weak expander_row => move |_| { + clone!(@weak sched_checkbutton, @weak expander_row, @weak badge_box, @strong get_running_kernel_info, @weak kernel_badges_size_group, @weak kernel_badges_size_group0, @weak kernel_badges_size_group1 => move |_| { if sched_checkbutton.is_active() == true { expander_row.set_title(&branch_row.title()); + match change_scx_scheduler(&sched, &badge_box, + &kernel_badges_size_group, + &kernel_badges_size_group0, + &kernel_badges_size_group1,) { + Ok(_) => { + cmd_status_dialog.set_heading(Some("Success!")); + cmd_status_dialog.set_body(format!("SCX has been set to: {}", &sched).as_str()); + cmd_status_dialog.present() + } + Err(_) => { + cmd_status_dialog.set_heading(Some("Failed!")); + cmd_status_dialog.set_body(format!("SCX couldn't be has been set to: {}", &sched).as_str()); + cmd_status_dialog.present() + } + }; } }), ); @@ -241,3 +278,19 @@ fn get_current_scx_scheduler() -> String { scx_sched } + +fn change_scx_scheduler(scx_sched: &str, + badge_box: >k::Box, + kernel_badges_size_group: >k::SizeGroup, + kernel_badges_size_group0: >k::SizeGroup, + kernel_badges_size_group1: >k::SizeGroup,) -> Result<(), io::Error> { + cmd!("pkexec", "bash", "-c", format!("/home/ward/RustroverProjects/fedora-kernel-manager/data/scripts/change_scx.sh {}", scx_sched)).run()?; + create_current_sched_badge( + &badge_box, + &get_running_kernel_info(), + &kernel_badges_size_group, + &kernel_badges_size_group0, + &kernel_badges_size_group1, + ); + Ok(()) +}