feat: properly show/hide overdrive info frame

This commit is contained in:
Ilya Zlobintsev
2023-01-22 18:24:48 +02:00
parent 50e32509f4
commit ad0562be1f
4 changed files with 28 additions and 70 deletions

View File

@@ -202,32 +202,6 @@ impl App {
Err(_) => self.root_stack.thermals_page.hide_fan_controls(),
}*/
{
// It's overkill to both show and hide the frame, but it needs to be done in set_info because show_all overrides the default hidden state of the frame.
match fs::read_to_string("/sys/module/amdgpu/parameters/ppfeaturemask") {
Ok(ppfeaturemask) => {
const PP_OVERDRIVE_MASK: i32 = 0x4000;
let ppfeaturemask = ppfeaturemask.trim().strip_prefix("0x").unwrap();
trace!("ppfeaturemask {}", ppfeaturemask);
let ppfeaturemask: u64 =
u64::from_str_radix(ppfeaturemask, 16).expect("Invalid ppfeaturemask");
/*if (ppfeaturemask & PP_OVERDRIVE_MASK as u64) > 0 {
self.root_stack.oc_page.warning_frame.hide();
} else {
self.root_stack.oc_page.warning_frame.show();
}*/
}
Err(_) => {
info!("Failed to read feature mask! This is expected if your system doesn't have an AMD GPU.");
// self.root_stack.oc_page.warning_frame.hide();
}
}
}
self.set_initial(gpu_id);
}

View File

@@ -27,7 +27,7 @@ impl RootStack {
container.add_titled(&info_page.container, Some("info_page"), "Information");
let oc_page = OcPage::new();
let oc_page = OcPage::new(&system_info);
container.add_titled(&oc_page.container, Some("oc_page"), "OC");

View File

@@ -2,17 +2,15 @@ mod clocks_frame;
mod performance_level_frame;
mod power_cap_frame;
mod stats_grid;
mod warning_frame;
use clocks_frame::ClocksFrame;
use gtk::prelude::*;
use gtk::*;
use lact_client::schema::{ClocksTableGen, DeviceStats, PerformanceLevel};
use lact_client::schema::{ClocksTableGen, DeviceStats, PerformanceLevel, SystemInfo};
use performance_level_frame::PerformanceLevelFrame;
use power_cap_frame::PowerCapFrame;
use stats_grid::StatsGrid;
use tracing::warn;
use warning_frame::WarningFrame;
#[derive(Clone)]
pub struct OcPage {
@@ -21,16 +19,21 @@ pub struct OcPage {
performance_level_frame: PerformanceLevelFrame,
power_cap_frame: PowerCapFrame,
clocks_frame: ClocksFrame,
pub warning_frame: WarningFrame,
}
impl OcPage {
pub fn new() -> Self {
let container = Box::new(Orientation::Vertical, 5);
pub fn new(system_info: &SystemInfo) -> Self {
let container = Box::builder()
.orientation(Orientation::Vertical)
.spacing(5)
.margin_top(5)
.margin_bottom(5)
.build();
let warning_frame = WarningFrame::new();
container.append(&warning_frame.container);
if system_info.amdgpu_overdrive_enabled == Some(false) {
let warning_frame = oc_warning_frame();
container.append(&warning_frame);
}
let stats_grid = StatsGrid::new();
@@ -49,7 +52,6 @@ impl OcPage {
stats_grid,
performance_level_frame,
clocks_frame,
warning_frame,
power_cap_frame,
}
}
@@ -151,3 +153,18 @@ fn section_box(title: &str, spacing: i32, margin: i32) -> Box {
container.append(&label);
container
}
fn oc_warning_frame() -> Frame {
let container = Frame::new(Some("Overclocking information"));
container.set_label_align(0.3);
let warning_label = Label::new(None);
warning_label.set_wrap(true);
warning_label.set_markup("Overclocking support is not enabled! To enable overclocking support, you need to add <b>amdgpu.ppfeaturemask=0xffffffff</b> to your kernel boot options. Look for the documentation of your distro.");
warning_label.set_selectable(true);
container.set_child(Some(&warning_label));
container
}

View File

@@ -1,33 +0,0 @@
use gtk::prelude::*;
use gtk::*;
#[derive(Clone)]
pub struct WarningFrame {
pub container: Frame,
}
impl WarningFrame {
pub fn new() -> Self {
let container = Frame::new(Some("Overclocking information"));
container.set_label_align(0.3);
let warning_label = Label::new(None);
warning_label.set_wrap(true);
warning_label.set_markup("Overclocking support is not enabled! To enable overclocking support, you need to add <b>amdgpu.ppfeaturemask=0xffffffff</b> to your kernel boot options. Look for the documentation of your distro.");
warning_label.set_selectable(true);
container.set_child(Some(&warning_label));
Self { container }
}
pub fn show(&self) {
self.container.set_visible(true);
}
pub fn hide(&self) {
self.container.set_visible(false);
}
}