Basic multi-GPU GUI code

This commit is contained in:
Ilya Zlobintsev 2020-11-09 11:01:10 +02:00
parent ec6de604f9
commit 532aeb8aed
3 changed files with 65 additions and 16 deletions

View File

@ -11,4 +11,5 @@ daemon = { path = "../daemon" }
gtk = "0.9"
gio = "0.9"
glib = "0.10"
gdk = "0.13"
gdk = "0.13"
pango = "0.9"

View File

@ -4,20 +4,12 @@ extern crate gtk;
use daemon::{Daemon, daemon_connection::DaemonConnection, gpu_controller::GpuInfo};
use gio::prelude::*;
use gtk::{
prelude::*, Adjustment, Button, ButtonsType, DialogFlags, Frame, Label, LevelBar, MessageType,
Switch,
};
use gtk::{Adjustment, Button, ButtonsType, ComboBoxText, DialogFlags, Frame, Label, LevelBar, MessageType, Switch, prelude::*};
use gtk::{Builder, MessageDialog, TextBuffer, Window};
use pango::EllipsizeMode;
use std::{
collections::BTreeMap,
env::args,
sync::{Arc, RwLock},
thread,
time::Duration,
};
use std::{collections::BTreeMap, env::args, sync::{Arc, Mutex, RwLock}, thread, time::Duration};
fn build_ui(application: &gtk::Application) {
let glade_src = include_str!("main_window.glade");
@ -36,6 +28,8 @@ fn build_ui(application: &gtk::Application) {
.get_object("vram_usage_label")
.expect("Couldn't get label");
let gpu_select_comboboxtext: ComboBoxText = builder.get_object("gpu_select_comboboxtext").unwrap();
let gpu_clock_text_buffer: TextBuffer = builder.get_object("gpu_clock_text_buffer").unwrap();
let vram_clock_text_buffer: TextBuffer = builder.get_object("vram_clock_text_buffer").unwrap();
@ -81,11 +75,35 @@ fn build_ui(application: &gtk::Application) {
println!("Connected");
let gpus = d.get_gpus().unwrap();
let current_gpu_id = gpus.iter().next().unwrap().0.clone();
let gpu_info = d.get_gpu_info(current_gpu_id).unwrap();
for gpu in &gpus {
gpu_select_comboboxtext.append(Some(&gpu.0.to_string()), &gpu.1);
}
set_info(&builder, &gpu_info);
//limits the length of gpu names in combobox
for cell in gpu_select_comboboxtext.get_cells() {
cell.set_property("width-chars", &10).unwrap();
cell.set_property("ellipsize", &EllipsizeMode::End).unwrap();
}
let current_gpu_id = Arc::new(Mutex::new(0u32));
let cur_id = current_gpu_id.clone();
let build = builder.clone();
gpu_select_comboboxtext.connect_changed(move |combobox| {
let mut current_gpu_id = cur_id.lock().unwrap();
*current_gpu_id = combobox.get_active_id().unwrap().parse::<u32>().expect("invalid id");
let gpu_info = d.get_gpu_info(*current_gpu_id).unwrap();
set_info(&build, &gpu_info);
});
//gpu_select_comboboxtext.set_active_id(Some(&current_gpu_id.to_string()));
gpu_select_comboboxtext.set_active(Some(0));
let current_gpu_id = *current_gpu_id.clone().lock().unwrap();
if unpriviliged {
automatic_fan_control_switch.set_sensitive(false);
@ -120,7 +138,7 @@ fn build_ui(application: &gtk::Application) {
fan_speed_text_buffer.set_text(&format!(
"{}RPM({}%)",
gpu_stats.fan_speed,
(gpu_stats.fan_speed as f64 / gpu_info.max_fan_speed as f64 * 100 as f64) as i32
(gpu_stats.fan_speed as f64 / gpu_stats.max_fan_speed as f64 * 100 as f64) as i32
));
glib::Continue(true)

View File

@ -45,6 +45,20 @@
<object class="GtkTextBuffer" id="gpu_temp_text_buffer">
<property name="text" translatable="yes">100°C</property>
</object>
<object class="GtkListStore" id="gpus_list_store">
<columns>
<!-- column-name name -->
<column type="gchararray"/>
</columns>
<data>
<row>
<col id="0" translatable="yes">test</col>
</row>
<row>
<col id="0" translatable="yes">test1</col>
</row>
</data>
</object>
<object class="GtkTextBuffer" id="link_speed_text_buffer">
<property name="text" translatable="yes">1.0 GT/s PCIe x1</property>
</object>
@ -1128,6 +1142,22 @@
<property name="tab-fill">False</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child type="tab">
<placeholder/>
</child>
<child type="action-start">
<object class="GtkComboBoxText" id="gpu_select_comboboxtext">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="active">0</property>
</object>
<packing>
<property name="tab-fill">False</property>
</packing>
</child>
<child type="action-end">
<object class="GtkButton" id="apply_button">
<property name="label">gtk-apply</property>