feat: clocks control gui!

This commit is contained in:
Ilya Zlobintsev
2023-02-22 09:06:04 +02:00
parent 51f105286d
commit 0e8b7d3563
7 changed files with 99 additions and 39 deletions

View File

@@ -8,6 +8,7 @@ use apply_revealer::ApplyRevealer;
use glib::clone;
use gtk::{gio::ApplicationFlags, prelude::*, *};
use header::Header;
use lact_client::schema::request::SetClocksCommand;
use lact_client::schema::DeviceStats;
use lact_client::DaemonClient;
use root_stack::RootStack;
@@ -98,25 +99,20 @@ impl App {
app.header.set_devices(&devices);
{
let app = app.clone();
let current_gpu_id = current_gpu_id.clone();
app.root_stack.oc_page.clocks_frame.connect_clocks_reset(clone!(@strong app, @strong current_gpu_id => move || {
debug!("Resetting clocks");
// TODO
/*app.root_stack.oc_page.connect_clocks_reset(move || {
info!("Resetting clocks, but not applying");
let gpu_id = current_gpu_id.read().unwrap();
let gpu_id = current_gpu_id.load(Ordering::SeqCst);
app.daemon_client
.reset_gpu_power_states(gpu_id)
.expect("Failed to reset clocks");
app.set_info(gpu_id);
app.apply_revealer.show();
})*/
}
match app.daemon_client.set_clocks_value(&gpu_id, SetClocksCommand::Reset) {
Ok(()) => {
app.set_initial(&gpu_id);
}
Err(err) => {
show_error(&app.window, err);
}
}
}));
app.apply_revealer.connect_apply_button_clicked(
clone!(@strong app, @strong current_gpu_id => move || {
@@ -327,6 +323,26 @@ impl App {
.context("Could not set fan control")?;
}
let clocks_settings = self.root_stack.oc_page.clocks_frame.get_settings();
if let Some(clock) = clocks_settings.max_core_clock {
self.daemon_client
.set_clocks_value(&gpu_id, SetClocksCommand::MaxCoreClock(clock))
.context("Could not set the maximum core clock")?;
}
if let Some(clock) = clocks_settings.max_memory_clock {
self.daemon_client
.set_clocks_value(&gpu_id, SetClocksCommand::MaxMemoryClock(clock))
.context("Could not set the maximum memory clock")?;
}
if let Some(voltage) = clocks_settings.max_voltage {
self.daemon_client
.set_clocks_value(&gpu_id, SetClocksCommand::MaxVoltage(voltage))
.context("Could not set the maximum voltage")?;
}
self.set_initial(&gpu_id);
Ok(())

View File

@@ -157,7 +157,7 @@ impl InformationPage {
.subsystem_pci_info
.model
.as_deref()
.or_else(|| pci_info.device_pci_info.model.as_deref())
.or(pci_info.device_pci_info.model.as_deref())
})
.unwrap_or_default();
self.gpu_name_label
@@ -171,7 +171,7 @@ impl InformationPage {
.subsystem_pci_info
.vendor
.as_deref()
.or_else(|| pci_info.device_pci_info.model.as_deref())
.or(pci_info.device_pci_info.model.as_deref())
})
.unwrap_or_default();
self.gpu_manufacturer_label

View File

@@ -1,4 +1,5 @@
use super::section_box;
use glib::clone;
use gtk::prelude::*;
use gtk::*;
use lact_client::schema::{ClocksTable, ClocksTableGen};
@@ -10,6 +11,7 @@ pub struct ClocksFrame {
max_sclk_adjustment: Adjustment,
max_mclk_adjustment: Adjustment,
max_voltage_adjustment: Adjustment,
reset_button: Button,
clocks_data_unavailable_label: Label,
}
@@ -22,6 +24,12 @@ impl ClocksFrame {
let max_voltage_adjustment = oc_adjustment("GPU voltage (mV)", &tweaking_grid, 1);
let max_mclk_adjustment = oc_adjustment("VRAM Clock (MHz)", &tweaking_grid, 2);
let reset_button = Button::builder()
.label("Defaults")
.halign(Align::End)
.build();
tweaking_grid.attach(&reset_button, 4, 3, 1, 1);
let clocks_data_unavailable_label = Label::new(Some("No clocks data available"));
container.append(&tweaking_grid);
@@ -33,6 +41,7 @@ impl ClocksFrame {
max_sclk_adjustment,
max_mclk_adjustment,
max_voltage_adjustment,
reset_button,
clocks_data_unavailable_label,
}
}
@@ -81,6 +90,33 @@ impl ClocksFrame {
self.tweaking_grid.hide();
self.clocks_data_unavailable_label.show();
}
pub fn connect_clocks_changed<F: Fn() + 'static + Clone>(&self, f: F) {
let f = clone!(@strong f => move |_: &Adjustment| f());
self.max_sclk_adjustment.connect_value_changed(f.clone());
self.max_mclk_adjustment.connect_value_changed(f.clone());
self.max_voltage_adjustment.connect_value_changed(f);
}
pub fn connect_clocks_reset<F: Fn() + 'static + Clone>(&self, f: F) {
self.reset_button.connect_clicked(move |_| f());
}
pub fn get_settings(&self) -> ClocksSettings {
if self.tweaking_grid.is_visible() {
let max_core_clock = zero_to_option(self.max_sclk_adjustment.value());
let max_memory_clock = zero_to_option(self.max_mclk_adjustment.value());
let max_voltage = zero_to_option(self.max_voltage_adjustment.value());
ClocksSettings {
max_core_clock,
max_memory_clock,
max_voltage,
}
} else {
ClocksSettings::default()
}
}
}
fn extract_value_and_range(
@@ -112,3 +148,18 @@ fn oc_adjustment(title: &'static str, grid: &Grid, row: i32) -> Adjustment {
adjustment
}
#[derive(Debug, Default)]
pub struct ClocksSettings {
pub max_core_clock: Option<u32>,
pub max_memory_clock: Option<u32>,
pub max_voltage: Option<u32>,
}
fn zero_to_option(value: f64) -> Option<u32> {
if value == 0.0 {
None
} else {
Some(value as u32)
}
}

View File

@@ -18,7 +18,7 @@ pub struct OcPage {
stats_grid: StatsGrid,
performance_level_frame: PerformanceLevelFrame,
power_cap_frame: PowerCapFrame,
clocks_frame: ClocksFrame,
pub clocks_frame: ClocksFrame,
}
impl OcPage {
@@ -85,22 +85,11 @@ impl OcPage {
}
}
pub fn connect_clocks_reset<F: Fn() + 'static + Clone>(&self, f: F) {
/*self.clocks_frame.connect_clocks_reset(move || {
f();
});*/
todo!()
}
pub fn connect_settings_changed<F: Fn() + 'static + Clone>(&self, f: F) {
self.performance_level_frame
.connect_power_profile_changed(f.clone());
self.power_cap_frame.connect_cap_changed(f);
/*let f = f.clone();
self.clocks_frame.connect_clocks_changed(move || {
f();
})*/
self.power_cap_frame.connect_cap_changed(f.clone());
self.clocks_frame.connect_clocks_changed(f);
}
pub fn set_performance_level(&self, profile: Option<PerformanceLevel>) {
@@ -146,7 +135,7 @@ fn section_box(title: &str, spacing: i32, margin: i32) -> Box {
let label = Label::builder()
.use_markup(true)
.label(&format!("<span font_desc='11'><b>{title}</b></span>"))
.label(format!("<span font_desc='11'><b>{title}</b></span>"))
.xalign(0.1)
.build();

View File

@@ -29,7 +29,6 @@ impl PerformanceLevelFrame {
root_box.append(&description_label);
{
let description_label = description_label.clone();
combo_box.connect_changed(move |combobox| match combobox.active().unwrap() {
0 => description_label
.set_text("Automatically adjust GPU and VRAM clocks. (Default)"),

View File

@@ -31,7 +31,7 @@ pub fn software_page(system_info: SystemInfo, embedded: bool) -> Grid {
}
let version_label = Label::builder()
.use_markup(true)
.label(&format!("<b>{daemon_version}</b>"))
.label(format!("<b>{daemon_version}</b>"))
.hexpand(true)
.halign(Align::Start)
.build();
@@ -51,7 +51,7 @@ pub fn software_page(system_info: SystemInfo, embedded: bool) -> Grid {
);
let kernel_version_label = Label::builder()
.use_markup(true)
.label(&format!("<b>{}</b>", system_info.kernel_version))
.label(format!("<b>{}</b>", system_info.kernel_version))
.hexpand(true)
.halign(Align::Start)
.build();