feat: gui for enabling overclocking

This commit is contained in:
Ilya Zlobintsev
2023-03-04 13:11:05 +02:00
parent d93d46d48e
commit 36466b2c7d
4 changed files with 79 additions and 8 deletions

View File

@@ -89,6 +89,7 @@ impl DaemonClient {
}
request_plain!(get_system_info, SystemInfo, SystemInfo);
request_plain!(enable_overdrive, EnableOverdrive, ());
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);

View File

@@ -14,6 +14,8 @@ use tokio::{
};
use tracing::{debug, error, instrument};
pub use system::MODULE_CONF_PATH;
pub struct Server {
pub handler: Handler,
listener: UnixListener,

View File

@@ -11,6 +11,7 @@ use header::Header;
use lact_client::schema::request::SetClocksCommand;
use lact_client::schema::DeviceStats;
use lact_client::DaemonClient;
use lact_daemon::MODULE_CONF_PATH;
use root_stack::RootStack;
use std::sync::{Arc, RwLock};
use std::thread;
@@ -127,6 +128,12 @@ impl App {
app.set_initial(&gpu_id)
}));
if let Some(ref button) = app.root_stack.oc_page.enable_overclocking_button {
button.connect_clicked(clone!(@strong app => move |_| {
app.enable_overclocking();
}));
}
app.start_stats_update_loop(current_gpu_id);
app.window.show();
@@ -339,6 +346,40 @@ impl App {
Ok(())
}
fn enable_overclocking(&self) {
let text = format!("This will enable the overdrive feature of the amdgpu driver by creating a file at <b>{MODULE_CONF_PATH}</b>. Are you sure you want to do this?");
let dialog = MessageDialog::builder()
.title("Enable Overclocking")
.use_markup(true)
.text(text)
.message_type(MessageType::Question)
.buttons(ButtonsType::OkCancel)
.transient_for(&self.window)
.build();
dialog.run_async(clone!(@strong self as app => move |diag, response| {
if response == ResponseType::Ok {
match app.daemon_client.enable_overdrive().and_then(|buffer| buffer.inner()) {
Ok(_) => {
let success_dialog = MessageDialog::builder()
.title("Success")
.text("Overclocking successfully enabled. A system reboot is required to apply the changes")
.message_type(MessageType::Info)
.buttons(ButtonsType::Ok)
.build();
success_dialog.run_async(move |diag, _| {
diag.hide();
});
}
Err(err) => {
show_error(&app.window, err);
}
}
}
diag.hide();
}));
}
}
enum GuiUpdateMsg {

View File

@@ -15,6 +15,9 @@ use power_cap_frame::PowerCapFrame;
use stats_frame::StatsFrame;
use tracing::warn;
const OVERCLOCKING_DISABLED_TEXT: &str = "Overclocking support is not enabled! \
You can still change basic settings, but the more advanced clocks and voltage control will not be available.";
#[derive(Clone)]
pub struct OcPage {
pub container: Box,
@@ -22,6 +25,7 @@ pub struct OcPage {
pub performance_frame: PerformanceFrame,
power_cap_frame: PowerCapFrame,
pub clocks_frame: ClocksFrame,
pub enable_overclocking_button: Option<Button>,
}
impl OcPage {
@@ -31,8 +35,11 @@ impl OcPage {
.spacing(15)
.build();
let mut enable_overclocking_button = None;
if system_info.amdgpu_overdrive_enabled == Some(false) {
let warning_frame = oc_warning_frame();
let (warning_frame, button) = oc_warning_frame();
enable_overclocking_button = Some(button);
container.append(&warning_frame);
}
@@ -53,6 +60,7 @@ impl OcPage {
performance_frame: performance_level_frame,
clocks_frame,
power_cap_frame,
enable_overclocking_button,
}
}
@@ -115,17 +123,36 @@ impl OcPage {
}
}
fn oc_warning_frame() -> Frame {
fn oc_warning_frame() -> (Frame, Button) {
let container = Frame::new(Some("Overclocking information"));
container.set_label_align(0.3);
let warning_label = Label::new(None);
let vbox = Box::builder()
.orientation(Orientation::Vertical)
.spacing(5)
.margin_top(10)
.margin_bottom(10)
.margin_start(10)
.margin_end(10)
.build();
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);
let warning_label = Label::builder()
.use_markup(true)
.label(OVERCLOCKING_DISABLED_TEXT)
.wrap(true)
.wrap_mode(pango::WrapMode::Word)
.build();
container.set_child(Some(&warning_label));
container
let enable_button = Button::builder()
.label("Enable Overclocking")
.halign(Align::End)
.build();
vbox.append(&warning_label);
vbox.append(&enable_button);
container.set_child(Some(&vbox));
(container, enable_button)
}