wip clocks gui

This commit is contained in:
Ilya Zlobintsev
2023-01-07 17:11:53 +02:00
parent d06fb359ea
commit d907cf4a2d
6 changed files with 123 additions and 53 deletions
+3 -1
View File
@@ -6,7 +6,8 @@ pub use lact_schema as schema;
use anyhow::{anyhow, Context};
use nix::unistd::getuid;
use schema::{
DeviceInfo, DeviceListEntry, DeviceStats, FanCurveMap, PerformanceLevel, Request, Response,
ClocksInfo, DeviceInfo, DeviceListEntry, DeviceStats, FanCurveMap, PerformanceLevel, Request,
Response,
};
use serde::Deserialize;
use std::{
@@ -87,6 +88,7 @@ impl DaemonClient {
request_with_id!(get_device_info, DeviceInfo, DeviceInfo);
request_with_id!(get_device_stats, DeviceStats, DeviceStats);
request_with_id!(get_device_clocks_info, DeviceClocksInfo, ClocksInfo);
pub fn set_performance_level(
&self,
+12
View File
@@ -237,6 +237,18 @@ impl App {
self.root_stack.oc_page.set_stats(&stats, true);
self.root_stack.thermals_page.set_stats(&stats, true);
let maybe_clocks_table = match self.daemon_client.get_device_clocks_info(gpu_id) {
Ok(clocks_buf) => {
let clocks_info = clocks_buf.inner().unwrap();
clocks_info.table
}
Err(err) => {
debug!("Could not fetch clocks info: {err}");
None
}
};
self.root_stack.oc_page.set_clocks_table(maybe_clocks_table);
self.apply_revealer.hide();
}
@@ -1,14 +1,68 @@
use gtk::Frame;
use anyhow::{anyhow, Context};
use gtk::prelude::*;
use gtk::*;
use lact_client::schema::{ClocksTable, ClocksTableGen};
use super::section_box;
#[derive(Clone)]
pub struct ClocksFrame {
pub container: Frame,
pub container: Box,
pub max_sclk_adjustment: Adjustment,
pub max_mclk_adjustment: Adjustment,
}
impl ClocksFrame {
pub fn new() -> Self {
let container = Frame::new(None);
let container = section_box("Maximum Clocks");
container.hide();
Self { container }
let max_sclk_adjustment = Adjustment::new(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
let max_mclk_adjustment = Adjustment::new(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
let max_sclk_scale = scale(&max_sclk_adjustment);
let max_mclk_scale = scale(&max_mclk_adjustment);
container.append(&max_sclk_scale);
container.append(&max_mclk_scale);
Self {
container,
max_sclk_adjustment,
max_mclk_adjustment,
}
}
pub fn set_table(&self, table: ClocksTableGen) -> anyhow::Result<()> {
let current_sclk_max = table.get_max_sclk().context("No max sclk clockspeed")?;
let current_mclk_max = table.get_max_mclk().context("No max mclk clockspeed")?;
let ranges = table.get_allowed_ranges();
let (sclk_min, sclk_max) = ranges
.sclk
.try_into()
.map_err(|_| anyhow!("No sclk range"))?;
let (mclk_min, mclk_max) = ranges
.mclk
.and_then(|range| range.try_into().ok())
.context("No mclk range")?;
self.max_sclk_adjustment.set_lower(sclk_min.into());
self.max_sclk_adjustment.set_upper(sclk_max.into());
self.max_sclk_adjustment.set_value(current_sclk_max.into());
self.max_mclk_adjustment.set_lower(mclk_min.into());
self.max_mclk_adjustment.set_upper(mclk_max.into());
self.max_mclk_adjustment.set_value(current_mclk_max.into());
Ok(())
}
}
fn scale(adjustment: &Adjustment) -> Scale {
Scale::builder()
.orientation(Orientation::Horizontal)
.adjustment(adjustment)
.draw_value(true)
.build()
}
+45 -22
View File
@@ -4,12 +4,14 @@ mod power_cap_frame;
mod stats_grid;
mod warning_frame;
use clocks_frame::ClocksFrame;
use gtk::prelude::*;
use gtk::*;
use lact_client::schema::{DeviceStats, PerformanceLevel, PowerStats};
use lact_client::schema::{ClocksTableGen, DeviceStats, PerformanceLevel};
use performance_level_frame::PerformanceLevelFrame;
use power_cap_frame::PowerCapFrame;
use stats_grid::StatsGrid;
use tracing::warn;
use warning_frame::WarningFrame;
#[derive(Clone)]
@@ -18,7 +20,7 @@ pub struct OcPage {
stats_grid: StatsGrid,
performance_level_frame: PerformanceLevelFrame,
power_cap_frame: PowerCapFrame,
// clocks_frame: ClocksFrame,
clocks_frame: ClocksFrame,
pub warning_frame: WarningFrame,
}
@@ -35,21 +37,18 @@ impl OcPage {
container.append(&stats_grid.container);
let power_cap_frame = PowerCapFrame::new();
let performance_level_frame = PerformanceLevelFrame::new();
let clocks_frame = ClocksFrame::new();
container.append(&power_cap_frame.container);
let power_profile_frame = PerformanceLevelFrame::new();
container.append(&power_profile_frame.container);
// let clocks_frame = ClocksFrame::new();
// container.append(&clocks_frame.container);
container.append(&performance_level_frame.container);
container.append(&clocks_frame.container);
Self {
container,
stats_grid,
performance_level_frame: power_profile_frame,
// clocks_frame,
performance_level_frame,
clocks_frame,
warning_frame,
power_cap_frame,
}
@@ -67,6 +66,23 @@ impl OcPage {
}
}
pub fn set_clocks_table(&self, table: Option<ClocksTableGen>) {
match table {
Some(table) => match self.clocks_frame.set_table(table) {
Ok(()) => {
self.clocks_frame.container.show();
}
Err(err) => {
warn!("Got invalid clocks table: {err}");
self.clocks_frame.container.hide();
}
},
None => {
self.clocks_frame.container.hide();
}
}
}
pub fn connect_clocks_reset<F: Fn() + 'static + Clone>(&self, f: F) {
/*self.clocks_frame.connect_clocks_reset(move || {
f();
@@ -106,17 +122,6 @@ impl OcPage {
}
}
pub fn set_power_stats(&self, power_stats: PowerStats) {
// TODO
/*match &info.clocks_table {
Some(clocks_table) => {
self.clocks_frame.show();
self.clocks_frame.set_clocks(clocks_table);
}
None => self.clocks_frame.hide(),
}*/
}
/*pub fn get_clocks(&self) -> Option<ClocksSettings> {
match self.clocks_frame.get_visibility() {
true => Some(self.clocks_frame.get_settings()),
@@ -128,3 +133,21 @@ impl OcPage {
self.power_cap_frame.get_cap()
}
}
fn section_box(title: &str) -> Box {
let container = Box::builder()
.orientation(Orientation::Vertical)
.spacing(5)
.margin_start(5)
.margin_end(5)
.build();
let label = Label::builder()
.use_markup(true)
.label(&format!("<span font_desc='11'><b>{title}</b></span>"))
.xalign(0.1)
.build();
container.append(&label);
container
}
@@ -2,6 +2,8 @@ use gtk::prelude::*;
use gtk::*;
use lact_client::schema::PerformanceLevel;
use super::section_box;
#[derive(Clone)]
pub struct PerformanceLevelFrame {
pub container: Box,
@@ -10,19 +12,7 @@ pub struct PerformanceLevelFrame {
impl PerformanceLevelFrame {
pub fn new() -> Self {
let container = Box::builder()
.orientation(Orientation::Vertical)
.spacing(5)
.margin_start(5)
.margin_end(5)
.build();
let label = Label::builder()
.use_markup(true)
.label("<span font_desc='11'><b>Performance Level</b></span>")
.xalign(0.1)
.build();
container.append(&label);
let container = section_box("Performance level");
let root_box = Box::new(Orientation::Horizontal, 5);
@@ -1,3 +1,4 @@
use super::section_box;
use glib::clone;
use gtk::prelude::*;
use gtk::*;
@@ -13,19 +14,7 @@ pub struct PowerCapFrame {
impl PowerCapFrame {
pub fn new() -> Self {
let container = Box::builder()
.orientation(Orientation::Vertical)
.spacing(5)
.margin_start(5)
.margin_end(5)
.build();
let label = Label::builder()
.use_markup(true)
.label("<span font_desc='11'><b>Power Usage Limit</b></span>")
.xalign(0.1)
.build();
container.append(&label);
let container = section_box("Power Usage Limit");
let root_box = Box::new(Orientation::Horizontal, 0);