add scx stuff

This commit is contained in:
Ward from fusion-voyager-3 2024-06-18 06:09:40 +03:00
parent 209e1cc421
commit a281832711
5 changed files with 245 additions and 75 deletions

View File

@ -4,4 +4,4 @@ fn main() {
"data/resources.gresource.xml",
"data.gresource",
);
}
}

View File

@ -1,8 +1,8 @@
use gtk::*;
use gtk::prelude::*;
use adw::*;
use crate::{content, sched_ext, PRETTY_NAME};
use adw::prelude::*;
use crate::{content, PRETTY_NAME, sched_ext};
use adw::*;
use gtk::prelude::*;
use gtk::*;
pub fn build_ui(app: &adw::Application) {
let window = adw::ApplicationWindow::new(app);
@ -24,12 +24,13 @@ pub fn build_ui(app: &adw::Application) {
.transition_type(StackTransitionType::Crossfade)
.build();
let window_toolbar = adw::ToolbarView::builder()
.content(&content_stack)
.build();
let window_toolbar = adw::ToolbarView::builder().content(&content_stack).build();
content_stack.add_named(&content::content(&content_stack), Some("content_page"));
content_stack.add_named(&sched_ext::sched_ext_page(&content_stack), Some("sched_ext_page"));
content_stack.add_named(
&sched_ext::sched_ext_page(&content_stack),
Some("sched_ext_page"),
);
window_toolbar.add_top_bar(&window_headerbar);
@ -48,5 +49,7 @@ fn load_icon_theme(window: &adw::ApplicationWindow) {
let icon_theme = gtk::IconTheme::for_display(&WidgetExt::display(window));
icon_theme.add_resource_path("/com/github/cosmicfusion/fedora-kernel-manager/icons/");
icon_theme.add_resource_path("/com/github/cosmicfusion/fedora-kernel-manager/icons/scalable/actions/");
}
icon_theme.add_resource_path(
"/com/github/cosmicfusion/fedora-kernel-manager/icons/scalable/actions/",
);
}

View File

@ -1,18 +1,17 @@
use glib::*;
use adw::prelude::*;
use gtk::*;
use gtk::prelude::*;
use std::process::{Command, Stdio};
use crate::{KernelBranch, RunningKernelInfo};
use Vec;
use std::fs;
use std::path::Path;
use adw::prelude::*;
use adw::ExpanderRow;
use duct::cmd;
use glib::*;
use gtk::prelude::*;
use gtk::*;
use std::fs;
use std::path::Path;
use std::process::{Command, Stdio};
use version_compare::Version;
use Vec;
pub fn content(content_stack: &gtk::Stack) -> gtk::Box {
let running_kernel_info = get_running_kernel_info();
let content_box = gtk::Box::builder()
@ -142,9 +141,7 @@ pub fn content(content_stack: &gtk::Stack) -> gtk::Box {
}
fn kernel_branch_expandable(expander_row: &adw::ExpanderRow) -> gtk::ListBox {
let searchbar = gtk::SearchEntry::builder()
.search_delay(500)
.build();
let searchbar = gtk::SearchEntry::builder().search_delay(500).build();
searchbar.add_css_class("round-border-only-top");
let boxedlist = gtk::ListBox::builder()
@ -174,11 +171,13 @@ fn kernel_branch_expandable(expander_row: &adw::ExpanderRow) -> gtk::ListBox {
branch_row.add_prefix(&branch_checkbutton);
branch_checkbutton.set_group(Some(&null_checkbutton));
branch_container.append(&branch_row);
branch_checkbutton.connect_toggled(clone!(@weak branch_checkbutton, @weak expander_row => move |_| {
if branch_checkbutton.is_active() == true {
expander_row.set_title(&branch_row.title());
}
}));
branch_checkbutton.connect_toggled(
clone!(@weak branch_checkbutton, @weak expander_row => move |_| {
if branch_checkbutton.is_active() == true {
expander_row.set_title(&branch_row.title());
}
}),
);
//if current_keyboard.contains(&(keyboard_layout_clone)) {
// keyboard_layout_checkbutton.set_active(true);
//}
@ -217,9 +216,15 @@ fn kernel_branch_expandable(expander_row: &adw::ExpanderRow) -> gtk::ListBox {
boxedlist
}
pub fn create_kernel_badge(label0_text: &str, label1_text: &str, css_style: &str, group_size: &gtk::SizeGroup, group_size0: &gtk::SizeGroup, group_size1: &gtk::SizeGroup) -> gtk::ListBox {
let badge_box = gtk::Box::builder()
.build();
pub fn create_kernel_badge(
label0_text: &str,
label1_text: &str,
css_style: &str,
group_size: &gtk::SizeGroup,
group_size0: &gtk::SizeGroup,
group_size1: &gtk::SizeGroup,
) -> gtk::ListBox {
let badge_box = gtk::Box::builder().build();
let label0 = gtk::Label::builder()
.label(label0_text)
@ -232,8 +237,7 @@ pub fn create_kernel_badge(label0_text: &str, label1_text: &str, css_style: &str
.build();
group_size0.add_widget(&label0);
let label_seprator = gtk::Separator::builder()
.build();
let label_seprator = gtk::Separator::builder().build();
let label1 = gtk::Label::builder()
.label(label1_text)
@ -282,9 +286,13 @@ fn get_kernel_branches() -> Vec<KernelBranch> {
vec![test_branch, test_branch2]
}
pub fn get_running_kernel_info() -> RunningKernelInfo {
let kernel = match Command::new("uname").arg("-r").stdout(Stdio::piped()).output() {
Ok(t) => String::from_utf8(t.stdout).unwrap().trim().to_owned(),
Err(_) => "Unknown".to_string()
let kernel = match Command::new("uname")
.arg("-r")
.stdout(Stdio::piped())
.output()
{
Ok(t) => String::from_utf8(t.stdout).unwrap().trim().to_owned(),
Err(_) => "Unknown".to_string(),
};
let version = match linux_version::linux_kernel_version() {
@ -295,14 +303,14 @@ pub fn get_running_kernel_info() -> RunningKernelInfo {
format!("{}.{}.{}", t.major, t.minor, t.patch)
}
}
Err(_) => "Unknown".to_string()
Err(_) => "Unknown".to_string(),
};
let info = RunningKernelInfo {
kernel: kernel,
version: version.clone(),
// didn't find a way to accurately get this, outside of sched-ext (https://github.com/CachyOS/kernel-manager/blob/develop/src/schedext-window.cpp)
sched: get_current_scheduler(version)
sched: get_current_scheduler(version),
};
info
@ -313,12 +321,12 @@ pub fn get_current_scheduler(version: String) -> String {
println!("sched_ext is detected, getting scx scheduler");
let scx_sched = match fs::read_to_string("/sys/kernel/sched_ext/root/ops") {
Ok(t) => t,
Err(_) => "unknown!".to_string()
Err(_) => "unknown!".to_string(),
};
"sched_ext: ".to_owned() + &scx_sched
} else if bore_check() {
"BORE".to_string()
} else if Version::from(&version) >= Version::from("6.6") {
} else if Version::from(&version) >= Version::from("6.6") {
"EEVDF?".to_string()
} else {
"CFS?".to_string()
@ -326,16 +334,16 @@ pub fn get_current_scheduler(version: String) -> String {
}
fn bore_check() -> bool {
let is_bore= match cmd!("sysctl", "-n", "kernel.sched_bore").read() {
Ok(t) => {
if t == "1" {
true
} else {
false
}
}
Err(_) => false
};
let is_bore = match cmd!("sysctl", "-n", "kernel.sched_bore").read() {
Ok(t) => {
if t == "1" {
true
} else {
false
}
}
Err(_) => false,
};
is_bore
}
@ -348,8 +356,7 @@ fn create_kernel_badges(badge_box: &gtk::Box, running_kernel_info: &RunningKerne
let version_css_style = if &running_kernel_info.version.as_str() == &kernel_version {
"background-green-bg"
}
else {
} else {
"background-red-bg"
};
@ -357,9 +364,44 @@ fn create_kernel_badges(badge_box: &gtk::Box, running_kernel_info: &RunningKerne
badge_box.remove(&widget);
}
badge_box.append(&create_kernel_badge("Kernel Branch", "cachy", "background-accent-bg", &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1));
badge_box.append(&create_kernel_badge("Latest Version", "6.9", "background-accent-bg", &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1));
badge_box.append(&create_kernel_badge("Running Version", &running_kernel_info.version, &version_css_style, &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1));
badge_box.append(&create_kernel_badge("Running Kernel", &running_kernel_info.kernel, &version_css_style, &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1));
badge_box.append(&create_kernel_badge("Running Sched", &running_kernel_info.sched, "background-accent-bg", &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1));
}
badge_box.append(&create_kernel_badge(
"Kernel Branch",
"cachy",
"background-accent-bg",
&kernel_badges_size_group,
&kernel_badges_size_group0,
&kernel_badges_size_group1,
));
badge_box.append(&create_kernel_badge(
"Latest Version",
"6.9",
"background-accent-bg",
&kernel_badges_size_group,
&kernel_badges_size_group0,
&kernel_badges_size_group1,
));
badge_box.append(&create_kernel_badge(
"Running Version",
&running_kernel_info.version,
&version_css_style,
&kernel_badges_size_group,
&kernel_badges_size_group0,
&kernel_badges_size_group1,
));
badge_box.append(&create_kernel_badge(
"Running Kernel",
&running_kernel_info.kernel,
&version_css_style,
&kernel_badges_size_group,
&kernel_badges_size_group0,
&kernel_badges_size_group1,
));
badge_box.append(&create_kernel_badge(
"Running Sched",
&running_kernel_info.sched,
"background-accent-bg",
&kernel_badges_size_group,
&kernel_badges_size_group0,
&kernel_badges_size_group1,
));
}

View File

@ -2,8 +2,8 @@ mod build_ui;
mod content;
mod sched_ext;
use gtk::*;
use adw::prelude::*;
use gtk::*;
use crate::gdk::Display;
@ -22,10 +22,7 @@ struct KernelBranch {
}
fn main() -> glib::ExitCode {
let app = adw::Application::builder()
.application_id(APP_ID)
.build();
let app = adw::Application::builder().application_id(APP_ID).build();
app.connect_startup(|app| {
load_gresource();
@ -38,8 +35,7 @@ fn main() -> glib::ExitCode {
}
fn load_gresource() {
gio::resources_register_include!("data.gresource")
.expect("Failed to register resources.");
gio::resources_register_include!("data.gresource").expect("Failed to register resources.");
}
fn load_css() {
@ -53,4 +49,4 @@ fn load_css() {
&provider,
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
);
}
}

View File

@ -1,9 +1,11 @@
use glib::*;
use adw::prelude::*;
use gtk::*;
use gtk::prelude::*;
use crate::content::get_running_kernel_info;
use crate::RunningKernelInfo;
use adw::prelude::*;
use glib::*;
use gtk::prelude::*;
use gtk::*;
use std::fs;
use std::fs::*;
pub fn sched_ext_page(content_stack: &gtk::Stack) -> gtk::Box {
let main_box = gtk::Box::builder()
@ -32,22 +34,149 @@ pub fn sched_ext_page(content_stack: &gtk::Stack) -> gtk::Box {
let badge_box = gtk::Box::builder()
.hexpand(true)
.vexpand(true)
.valign(Align::Start)
.orientation(Orientation::Vertical)
.build();
create_current_sched_badge(&badge_box, &get_running_kernel_info(), &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1);
create_current_sched_badge(
&badge_box,
&get_running_kernel_info(),
&kernel_badges_size_group,
&kernel_badges_size_group0,
&kernel_badges_size_group1,
);
let scx_sched_expander_row = adw::ExpanderRow::builder()
.subtitle("Select Sched-EXT Scheduler")
.build();
scx_sched_expander_row.add_row(&scx_sched_expandable(&scx_sched_expander_row));
let scx_sched_expander_row_boxedlist = gtk::ListBox::builder()
.selection_mode(SelectionMode::None)
.hexpand(true)
.vexpand(true)
.valign(Align::Start)
.halign(Align::Center)
.margin_start(10)
.margin_end(10)
.margin_bottom(20)
.margin_top(20)
.build();
scx_sched_expander_row_boxedlist.add_css_class("boxed-list");
scx_sched_expander_row_boxedlist.append(&scx_sched_expander_row);
main_box.append(&badge_box);
main_box.append(&scx_sched_expander_row_boxedlist);
main_box.append(&main_icon);
main_box
}
fn create_current_sched_badge(badge_box: &gtk::Box, running_kernel_info: &RunningKernelInfo, kernel_badges_size_group: &gtk::SizeGroup, kernel_badges_size_group0: &gtk::SizeGroup, kernel_badges_size_group1: &gtk::SizeGroup) {
fn create_current_sched_badge(
badge_box: &gtk::Box,
running_kernel_info: &RunningKernelInfo,
kernel_badges_size_group: &gtk::SizeGroup,
kernel_badges_size_group0: &gtk::SizeGroup,
kernel_badges_size_group1: &gtk::SizeGroup,
) {
while let Some(widget) = badge_box.last_child() {
badge_box.remove(&widget);
}
badge_box.append(&crate::content::create_kernel_badge("Running Sched", &running_kernel_info.sched, "background-accent-bg", &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1));
}
badge_box.append(&crate::content::create_kernel_badge(
"Running Sched",
&running_kernel_info.sched,
"background-accent-bg",
&kernel_badges_size_group,
&kernel_badges_size_group0,
&kernel_badges_size_group1,
));
}
fn scx_sched_expandable(expander_row: &adw::ExpanderRow) -> gtk::ListBox {
let searchbar = gtk::SearchEntry::builder().search_delay(500).build();
searchbar.add_css_class("round-border-only-top");
let boxedlist = gtk::ListBox::builder()
.selection_mode(SelectionMode::None)
.build();
boxedlist.append(&searchbar);
let sched_container = gtk::ListBox::builder()
.selection_mode(SelectionMode::None)
.build();
sched_container.add_css_class("boxed-list");
let null_checkbutton = gtk::CheckButton::builder()
.label("No branch selected")
.build();
let mut scx_sched_array: Vec<String> = Vec::new();
let data = fs::read_to_string(
"/home/ward/RustroverProjects/fedora-kernel-manager/data/scx_scheds.json",
)
.expect("Unable to read file");
let res: serde_json::Value = serde_json::from_str(&data).expect("Unable to parse");
if let serde_json::Value::Array(scheds) = &res["scx_schedulers"] {
for sched in scheds {
let sched = sched["name"].as_str().to_owned().unwrap().to_string();
let sched_checkbutton = gtk::CheckButton::builder()
.valign(Align::Center)
.can_focus(false)
.build();
let branch_row = adw::ActionRow::builder()
.activatable_widget(&sched_checkbutton)
.title(sched)
.build();
branch_row.add_prefix(&sched_checkbutton);
sched_checkbutton.set_group(Some(&null_checkbutton));
sched_container.append(&branch_row);
sched_checkbutton.connect_toggled(
clone!(@weak sched_checkbutton, @weak expander_row => move |_| {
if sched_checkbutton.is_active() == true {
expander_row.set_title(&branch_row.title());
}
}),
);
//if current_keyboard.contains(&(keyboard_layout_clone)) {
// keyboard_layout_checkbutton.set_active(true);
//}
}
};
let branch_container_viewport = gtk::ScrolledWindow::builder()
.child(&sched_container)
.hscrollbar_policy(PolicyType::Never)
.height_request(250)
.build();
sched_container.add_css_class("round-border-only-bottom");
boxedlist.append(&branch_container_viewport);
searchbar.connect_search_changed(clone!(@weak searchbar, @weak sched_container => move |_| {
let mut counter = sched_container.first_child();
while let Some(row) = counter {
if row.widget_name() == "AdwActionRow" {
if !searchbar.text().is_empty() {
if row.property::<String>("subtitle").to_lowercase().contains(&searchbar.text().to_string().to_lowercase()) || row.property::<String>("title").to_lowercase().contains(&searchbar.text().to_string().to_lowercase()) {
//row.grab_focus();
//row.add_css_class("highlight-widget");
row.set_property("visible", true);
searchbar.grab_focus();
} else {
row.set_property("visible", false);
}
} else {
row.set_property("visible", true);
}
}
counter = row.next_sibling();
}
}));
boxedlist
}