prepare for scx

This commit is contained in:
Ward from fusion-voyager-3 2024-06-18 05:23:22 +03:00
parent aed674e412
commit 209e1cc421
4 changed files with 107 additions and 7 deletions

43
data/scx_scheds.json Normal file
View File

@ -0,0 +1,43 @@
{
"scx_schedulers": [
{
"name": "scx_disabled"
},
{
"name": "scx_central"
},
{
"name": "scx_flatcg"
},
{
"name": "scx_lavd"
},
{
"name": "scx_layered"
},
{
"name": "scx_nest"
},
{
"name": "scx_pair"
},
{
"name": "scx_qmap"
},
{
"name": "scx_rlfifo"
},
{
"name": "scx_rustland"
},
{
"name": "scx_rusty"
},
{
"name": "scx_simple"
},
{
"name": "scx_userland"
}
]
}

View File

@ -2,7 +2,7 @@ use gtk::*;
use gtk::prelude::*;
use adw::*;
use adw::prelude::*;
use crate::{content, PRETTY_NAME};
use crate::{content, PRETTY_NAME, sched_ext};
pub fn build_ui(app: &adw::Application) {
let window = adw::ApplicationWindow::new(app);
@ -28,7 +28,8 @@ pub fn build_ui(app: &adw::Application) {
.content(&content_stack)
.build();
content_stack.add_named(&content::content(), Some("content_page"));
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"));
window_toolbar.add_top_bar(&window_headerbar);

View File

@ -11,7 +11,7 @@ use adw::ExpanderRow;
use duct::cmd;
use version_compare::Version;
pub fn content() -> gtk::Box {
pub fn content(content_stack: &gtk::Stack) -> gtk::Box {
let running_kernel_info = get_running_kernel_info();
@ -92,6 +92,10 @@ pub fn content() -> gtk::Box {
.build();
config_kernel_button.add_css_class("circular");
config_kernel_button.connect_clicked(clone!(@weak content_stack => move |_| {
content_stack.set_visible_child_name("sched_ext_page")
}));
button_box.append(&browse_kernels_button);
button_box.append(&config_kernel_button);
@ -213,7 +217,7 @@ fn kernel_branch_expandable(expander_row: &adw::ExpanderRow) -> gtk::ListBox {
boxedlist
}
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 {
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();
@ -277,7 +281,7 @@ fn get_kernel_branches() -> Vec<KernelBranch> {
vec![test_branch, test_branch2]
}
fn get_running_kernel_info() -> RunningKernelInfo {
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()
@ -304,7 +308,7 @@ fn get_running_kernel_info() -> RunningKernelInfo {
info
}
fn get_current_scheduler(version: String) -> String {
pub fn get_current_scheduler(version: String) -> String {
if Path::new("/sys/kernel/sched_ext/root/ops").exists() {
println!("sched_ext is detected, getting scx scheduler");
let scx_sched = match fs::read_to_string("/sys/kernel/sched_ext/root/ops") {

View File

@ -1 +1,53 @@
//fn sched_ext_page()
use glib::*;
use adw::prelude::*;
use gtk::*;
use gtk::prelude::*;
use crate::content::get_running_kernel_info;
use crate::RunningKernelInfo;
pub fn sched_ext_page(content_stack: &gtk::Stack) -> gtk::Box {
let main_box = gtk::Box::builder()
.hexpand(true)
.vexpand(true)
.orientation(Orientation::Vertical)
.build();
let kernel_badges_size_group = gtk::SizeGroup::new(SizeGroupMode::Both);
let kernel_badges_size_group0 = gtk::SizeGroup::new(SizeGroupMode::Both);
let kernel_badges_size_group1 = gtk::SizeGroup::new(SizeGroupMode::Both);
let main_icon = gtk::Image::builder()
.pixel_size(128)
.halign(Align::Center)
.hexpand(true)
.margin_start(10)
.margin_end(10)
.margin_bottom(20)
.margin_top(20)
.build();
main_icon.set_icon_name(Some("tux-symbolic"));
main_icon.add_css_class("symbolic-accent-bg");
let badge_box = gtk::Box::builder()
.hexpand(true)
.vexpand(true)
.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);
main_box.append(&badge_box);
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) {
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));
}