add scx stuff
This commit is contained in:
parent
209e1cc421
commit
a281832711
@ -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/",
|
||||
);
|
||||
}
|
@ -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: >k::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: >k::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 |_| {
|
||||
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: >k::SizeGroup, group_size0: >k::SizeGroup, group_size1: >k::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: >k::SizeGroup,
|
||||
group_size0: >k::SizeGroup,
|
||||
group_size1: >k::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() {
|
||||
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()
|
||||
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,7 +321,7 @@ 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() {
|
||||
@ -334,7 +342,7 @@ fn bore_check() -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
Err(_) => false
|
||||
Err(_) => false,
|
||||
};
|
||||
is_bore
|
||||
}
|
||||
@ -348,8 +356,7 @@ fn create_kernel_badges(badge_box: >k::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: >k::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,
|
||||
));
|
||||
}
|
10
src/main.rs
10
src/main.rs
@ -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() {
|
||||
|
@ -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: >k::Stack) -> gtk::Box {
|
||||
let main_box = gtk::Box::builder()
|
||||
@ -32,22 +34,149 @@ pub fn sched_ext_page(content_stack: >k::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: >k::Box, running_kernel_info: &RunningKernelInfo, kernel_badges_size_group: >k::SizeGroup, kernel_badges_size_group0: >k::SizeGroup, kernel_badges_size_group1: >k::SizeGroup) {
|
||||
fn create_current_sched_badge(
|
||||
badge_box: >k::Box,
|
||||
running_kernel_info: &RunningKernelInfo,
|
||||
kernel_badges_size_group: >k::SizeGroup,
|
||||
kernel_badges_size_group0: >k::SizeGroup,
|
||||
kernel_badges_size_group1: >k::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
|
||||
}
|
Loading…
Reference in New Issue
Block a user