mirror of
https://github.com/ilya-zlobintsev/LACT.git
synced 2025-02-25 18:55:26 -06:00
Make separate revealer for the apply button and show/hide it on demand
This commit is contained in:
@@ -272,7 +272,7 @@ impl GpuController {
|
||||
let vendor_data =
|
||||
match VendorData::from_ids(&vendor_id, &model_id, &card_vendor_id, &card_model_id) {
|
||||
Ok(data) => data,
|
||||
Err(e) => VendorData::default(),
|
||||
Err(_) => VendorData::default(),
|
||||
};
|
||||
|
||||
log::info!("Vendor data: {:?}", vendor_data);
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#![feature(str_split_once)]
|
||||
|
||||
pub mod config;
|
||||
pub mod daemon_connection;
|
||||
pub mod gpu_controller;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
mod apply_revealer;
|
||||
mod header;
|
||||
mod root_stack;
|
||||
|
||||
@@ -8,20 +9,21 @@ use std::sync::Arc;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use daemon::{
|
||||
daemon_connection::DaemonConnection,
|
||||
gpu_controller::{FanControlInfo, GpuStats},
|
||||
DaemonError,
|
||||
};
|
||||
use apply_revealer::ApplyRevealer;
|
||||
use daemon::daemon_connection::DaemonConnection;
|
||||
use daemon::gpu_controller::GpuStats;
|
||||
use daemon::DaemonError;
|
||||
use gtk::*;
|
||||
|
||||
use header::Header;
|
||||
use root_stack::RootStack;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct App {
|
||||
pub window: Window,
|
||||
pub header: Header,
|
||||
root_stack: RootStack,
|
||||
apply_revealer: ApplyRevealer,
|
||||
daemon_connection: DaemonConnection,
|
||||
}
|
||||
|
||||
@@ -45,12 +47,21 @@ impl App {
|
||||
|
||||
header.set_switcher_stack(&root_stack.container);
|
||||
|
||||
window.add(&root_stack.container);
|
||||
let root_box = Box::new(Orientation::Vertical, 5);
|
||||
|
||||
root_box.add(&root_stack.container);
|
||||
|
||||
let apply_revealer = ApplyRevealer::new();
|
||||
|
||||
root_box.add(&apply_revealer.container);
|
||||
|
||||
window.add(&root_box);
|
||||
|
||||
App {
|
||||
window,
|
||||
header,
|
||||
root_stack,
|
||||
apply_revealer,
|
||||
daemon_connection,
|
||||
}
|
||||
}
|
||||
@@ -58,31 +69,59 @@ impl App {
|
||||
pub fn run(&self) -> Result<(), DaemonError> {
|
||||
let current_gpu_id = Arc::new(AtomicU32::new(0));
|
||||
|
||||
let root_stack = self.root_stack.clone();
|
||||
|
||||
{
|
||||
let current_gpu_id = current_gpu_id.clone();
|
||||
let daemon_connection = self.daemon_connection.clone();
|
||||
let app = self.clone();
|
||||
|
||||
self.header.connect_gpu_selection_changed(move |gpu_id| {
|
||||
let gpu_info = daemon_connection.get_gpu_info(gpu_id).unwrap();
|
||||
root_stack.info_page.set_info(gpu_info);
|
||||
|
||||
app.set_info(gpu_id);
|
||||
current_gpu_id.store(gpu_id, Ordering::SeqCst);
|
||||
});
|
||||
}
|
||||
|
||||
self.start_stats_update_loop(current_gpu_id.clone());
|
||||
|
||||
let gpus = self.daemon_connection.get_gpus()?;
|
||||
|
||||
self.header.set_gpus(gpus);
|
||||
|
||||
// Show apply button on setting changes
|
||||
{
|
||||
let apply_revealer = self.apply_revealer.clone();
|
||||
self.root_stack
|
||||
.thermals_page
|
||||
.connect_settings_changed(move || {
|
||||
apply_revealer.show();
|
||||
});
|
||||
}
|
||||
|
||||
// Apply settings
|
||||
{
|
||||
let current_gpu_id = current_gpu_id.clone();
|
||||
let app = self.clone();
|
||||
|
||||
self.apply_revealer.connect_apply_button_clicked(move || {
|
||||
let gpu_id = current_gpu_id.load(Ordering::SeqCst);
|
||||
app.set_info(gpu_id);
|
||||
});
|
||||
}
|
||||
|
||||
self.start_stats_update_loop(current_gpu_id.clone());
|
||||
|
||||
self.window.show_all();
|
||||
|
||||
Ok(gtk::main())
|
||||
}
|
||||
|
||||
fn set_info(&self, gpu_id: u32) {
|
||||
let gpu_info = self.daemon_connection.get_gpu_info(gpu_id).unwrap();
|
||||
self.root_stack.info_page.set_info(gpu_info);
|
||||
|
||||
let ventilation_info = self.daemon_connection.get_fan_control(gpu_id).unwrap();
|
||||
self.root_stack
|
||||
.thermals_page
|
||||
.set_ventilation_info(ventilation_info);
|
||||
|
||||
}
|
||||
|
||||
fn start_stats_update_loop(&self, current_gpu_id: Arc<AtomicU32>) {
|
||||
let (sender, receiver) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
||||
{
|
||||
@@ -95,12 +134,6 @@ impl App {
|
||||
sender.send(GuiUpdateMsg::GpuStats(stats)).unwrap();
|
||||
}
|
||||
|
||||
if let Ok(fan_control) = daemon_connection.get_fan_control(gpu_id) {
|
||||
sender
|
||||
.send(GuiUpdateMsg::FanControlInfo(fan_control))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
thread::sleep(Duration::from_millis(500));
|
||||
});
|
||||
}
|
||||
@@ -114,10 +147,9 @@ impl App {
|
||||
GuiUpdateMsg::GpuStats(stats) => {
|
||||
thermals_page.set_thermals_info(&stats);
|
||||
oc_page.set_stats(&stats);
|
||||
}
|
||||
GuiUpdateMsg::FanControlInfo(fan_control_info) => {
|
||||
thermals_page.set_ventilation_info(fan_control_info)
|
||||
}
|
||||
} /*GuiUpdateMsg::FanControlInfo(fan_control_info) => {
|
||||
thermals_page.set_ventilation_info(fan_control_info)
|
||||
}*/
|
||||
}
|
||||
|
||||
glib::Continue(true)
|
||||
@@ -127,6 +159,6 @@ impl App {
|
||||
}
|
||||
|
||||
enum GuiUpdateMsg {
|
||||
FanControlInfo(FanControlInfo),
|
||||
// FanControlInfo(FanControlInfo),
|
||||
GpuStats(GpuStats),
|
||||
}
|
||||
|
||||
39
gui/src/app/apply_revealer.rs
Normal file
39
gui/src/app/apply_revealer.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
use gtk::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ApplyRevealer {
|
||||
pub container: Revealer,
|
||||
apply_button: Button,
|
||||
}
|
||||
|
||||
impl ApplyRevealer {
|
||||
pub fn new() -> Self {
|
||||
let container = Revealer::new();
|
||||
|
||||
container.set_transition_duration(150);
|
||||
|
||||
let apply_button = Button::new();
|
||||
|
||||
apply_button.set_label("Apply");
|
||||
|
||||
container.add(&apply_button);
|
||||
|
||||
Self {
|
||||
container,
|
||||
apply_button,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn show(&self) {
|
||||
self.container.set_reveal_child(true);
|
||||
}
|
||||
|
||||
pub fn connect_apply_button_clicked<F: Fn() + 'static>(&self, f: F) {
|
||||
let apply_revealer = self.container.clone();
|
||||
|
||||
self.apply_button.connect_clicked(move |_| {
|
||||
f();
|
||||
apply_revealer.set_reveal_child(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,11 @@ use gtk::prelude::{ComboBoxExtManual, ObjectExt};
|
||||
use gtk::*;
|
||||
use pango::EllipsizeMode;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Header {
|
||||
pub container: HeaderBar,
|
||||
gpu_selector: ComboBoxText,
|
||||
switcher: StackSwitcher,
|
||||
apply_button: Button,
|
||||
}
|
||||
|
||||
impl Header {
|
||||
@@ -27,17 +27,10 @@ impl Header {
|
||||
let switcher = StackSwitcher::new();
|
||||
container.pack_start(&switcher);
|
||||
|
||||
let apply_button = Button::new();
|
||||
apply_button.set_label("Apply");
|
||||
apply_button.set_sensitive(false);
|
||||
|
||||
container.pack_start(&apply_button);
|
||||
|
||||
Header {
|
||||
container,
|
||||
gpu_selector,
|
||||
switcher,
|
||||
apply_button,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,14 +59,4 @@ impl Header {
|
||||
f(selected_id.parse().unwrap());
|
||||
});
|
||||
}
|
||||
|
||||
pub fn connect_apply_button_clicked<F: Fn() + 'static>(&self, f: F) {
|
||||
self.apply_button.connect_clicked(move |_| {
|
||||
f();
|
||||
});
|
||||
}
|
||||
|
||||
pub fn set_apply_button_sensitive(&self) {
|
||||
self.apply_button.set_sensitive(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ mod fan_curve_frame;
|
||||
|
||||
use daemon::gpu_controller::{FanControlInfo, GpuStats};
|
||||
use gtk::*;
|
||||
use gtk::prelude::*;
|
||||
|
||||
use fan_curve_frame::FanCurveFrame;
|
||||
|
||||
@@ -120,4 +121,10 @@ impl ThermalsPage {
|
||||
self.fan_curve_frame.container.set_visible(false);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn connect_settings_changed<F: Fn() + 'static>(&self, f: F) {
|
||||
self.fan_control_enabled_switch.connect_changed_active(move |_| {
|
||||
f();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user