mirror of
https://github.com/ilya-zlobintsev/LACT.git
synced 2025-02-25 18:55:26 -06:00
feat: make power states not clickable when they are not available
This commit is contained in:
parent
9e2be03757
commit
a371c99d3d
@ -1,6 +1,9 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use gtk::glib::{self, subclass::types::ObjectSubclassIsExt, Object};
|
||||
use gtk::{
|
||||
glib::{self, subclass::types::ObjectSubclassIsExt, Object},
|
||||
prelude::WidgetExt,
|
||||
};
|
||||
use lact_client::schema::{amdgpu_sysfs::gpu_handle::PowerLevelKind, DeviceStats, PowerStates};
|
||||
|
||||
glib::wrapper! {
|
||||
@ -16,6 +19,12 @@ impl PowerStatesFrame {
|
||||
|
||||
pub fn set_power_states(&self, states: PowerStates) {
|
||||
let imp = self.imp();
|
||||
|
||||
imp.expander.set_sensitive(!states.is_empty());
|
||||
if states.is_empty() {
|
||||
imp.expander.set_expanded(false);
|
||||
}
|
||||
|
||||
imp.core_states_list.set_power_states(states.core, "MHz");
|
||||
imp.vram_states_list.set_power_states(states.vram, "MHz");
|
||||
}
|
||||
@ -64,7 +73,7 @@ mod imp {
|
||||
prelude::*,
|
||||
widget::{CompositeTemplateClass, WidgetImpl},
|
||||
},
|
||||
CompositeTemplate,
|
||||
CompositeTemplate, Expander,
|
||||
};
|
||||
use std::sync::atomic::AtomicBool;
|
||||
|
||||
@ -72,6 +81,8 @@ mod imp {
|
||||
#[properties(wrapper_type = super::PowerStatesFrame)]
|
||||
#[template(file = "ui/oc_page/power_states_frame.blp")]
|
||||
pub struct PowerStatesFrame {
|
||||
#[template_child]
|
||||
pub expander: TemplateChild<Expander>,
|
||||
#[template_child]
|
||||
pub core_states_list: TemplateChild<PowerStatesList>,
|
||||
#[template_child]
|
||||
|
@ -1,7 +1,7 @@
|
||||
using Gtk 4.0;
|
||||
|
||||
template $PowerStatesFrame: Box {
|
||||
Expander {
|
||||
Expander expander {
|
||||
label: "Power states";
|
||||
|
||||
Box {
|
||||
|
@ -231,6 +231,12 @@ pub struct PowerStates {
|
||||
pub vram: Vec<PowerState<u64>>,
|
||||
}
|
||||
|
||||
impl PowerStates {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.core.is_empty() && self.vram.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
|
||||
pub struct PowerState<T> {
|
||||
pub enabled: bool,
|
||||
|
Loading…
Reference in New Issue
Block a user