Skip to content

Commit 33aaa89

Browse files
author
Deren Vural
committed
Working concurrency
Updated Cargo.toml: - cleaned Updated main.rs: - Added gpu_page module Updated MainWindow class: - Switched to GtkStack instead of AdwLeaflet - Removed uneeded card_selected callback - Updated to use new GpuPage class - Updated to use dynamic GpuPage generation instead of template items (allows customisation in future) - Added function to create a GpuPage - Updated refresh_cards to reflect above changes - Updated to show split of memory stat into 2 separate stats (total+used) - Added psuedocode for json saving+loading of stat layout - Have to call setup functions from constructor, after obj creation, so that we can use constructor parameters Updated MainWindow ui: - Switched to GtkStack instead of AdwLeaflet - Updated to use dynamic GpuPage generation instead of template items (allows customisation in future) by removing static items - Moved menu description to end of file - Added refresh button linked to refresh_cards to the top bar Updated SettingsWindow class: - Removed unecessary ComboRow import Added GpuPage class + ui: - Extends a grid, adds the loaded stats to itself as boxes (hardcoded for now, loading and better properties needed) - Will eventually need to be stored in a GpuPages object that contains multiple pages (allowing sections) - Updates stats every `refresh_rate` seconds, loading this from stored settings Updated Provider class: - Split memory stat into 2 separate stats (total+used) - Added the nvidia-settings versions of gpu_data stats Updated Processor class: - Added missing type declarations Updated Property class: - Added missing type declarations - Added psuedocode new version of parse Signed-off-by: Deren Vural <[email protected]>
1 parent d71e367 commit 33aaa89

File tree

15 files changed

+1133
-303
lines changed

15 files changed

+1133
-303
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ adwaita = { version = "^0.1.1", package = "libadwaita" }
1111
gtk = { version = "^0.4.8", package = "gtk4" }
1212
gdk = { version = "^0.4.8", package = "gdk4" }
1313

14-
#shell = { version = "^0.4.4", package = "gtk-layer-shell" } #may not need
1514
#serde = { version = "1.0", features = ["derive"] }
1615
#serde_json = "1.0"
16+
17+
#shell = { version = "^0.4.4", package = "gtk-layer-shell" } #may not need
1718
#gobject = { version = "^0.15.10", package = "gobject-sys" }
1819
#libappindicator = { version = "^0.7.1", package = "libappindicator" }
1920

src/gpu_page/imp.rs

Lines changed: 316 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,316 @@
1+
// SPDX-FileCopyrightText: 2022 Deren Vural
2+
// SPDX-License-Identifier: GPL-3.0-or-later
3+
4+
/*
5+
* Name:
6+
* imp.rs
7+
*
8+
* Description:
9+
* Implementation of our custom GObject class (GpuPage)
10+
*
11+
* Made:
12+
* 02/11/2022
13+
*
14+
* Made by:
15+
* Deren Vural
16+
*
17+
* Notes:
18+
*
19+
*/
20+
21+
// Imports
22+
use std::{cell::Ref, cell::Cell, cell::RefCell, rc::Rc};
23+
use gio::Settings;
24+
use glib::{once_cell::sync::OnceCell, once_cell::sync::Lazy, ParamSpec, ToValue, Value, subclass::InitializingObject};
25+
use gtk::{subclass::prelude::*, CompositeTemplate};
26+
use adwaita::{glib, gio, prelude::*};
27+
28+
// Modules
29+
use crate::{provider::Provider};
30+
31+
/// Object holding the State and any Template Children
32+
#[derive(CompositeTemplate, Default)]
33+
#[template(resource = "/gpu-page.ui")]
34+
pub struct GpuPage {
35+
pub settings: OnceCell<Settings>,
36+
uuid: Cell<String>,
37+
name: Cell<String>,
38+
provider: Rc<RefCell<Provider>>,
39+
}
40+
41+
/// The central trait for subclassing a GObject
42+
#[glib::object_subclass]
43+
impl ObjectSubclass for GpuPage {
44+
// `NAME` needs to match `class` attribute of template
45+
const NAME: &'static str = "NvidiaExtensionGpuPage";
46+
type Type = super::GpuPage;
47+
type ParentType = gtk::Grid;
48+
49+
fn class_init(klass: &mut Self::Class) {
50+
klass.bind_template();
51+
klass.bind_template_callbacks();
52+
}
53+
54+
fn instance_init(obj: &InitializingObject<Self>) {
55+
obj.init_template();
56+
}
57+
}
58+
59+
/**
60+
* Name:
61+
* GpuPage
62+
*
63+
* Description:
64+
* Trait shared by all GpuPage objects
65+
*
66+
* Made:
67+
* 02/11/2022
68+
*
69+
* Made by:
70+
* Deren Vural
71+
*
72+
* Notes:
73+
*
74+
*/
75+
#[gtk::template_callbacks]
76+
impl GpuPage {
77+
// #[template_callback]
78+
// fn get_gpu_data(&self, _label: &Label) {
79+
// //
80+
// println!("TEST callback");//TEST
81+
// }
82+
}
83+
84+
/**
85+
* Trait Name:
86+
* ObjectImpl
87+
*
88+
* Description:
89+
* Trait shared by all GObjects
90+
*
91+
* Made:
92+
* 02/11/2022
93+
*
94+
* Made by:
95+
* Deren Vural
96+
*
97+
* Notes:
98+
*
99+
*/
100+
impl ObjectImpl for GpuPage {
101+
/**
102+
* Name:
103+
* constructed
104+
*
105+
* Description:
106+
* Called during construction, allows calling setup functions
107+
*
108+
* Made:
109+
* 02/11/2022
110+
*
111+
* Made by:
112+
* Deren Vural
113+
*
114+
* Notes:
115+
*
116+
*/
117+
fn constructed(&self, obj: &Self::Type) {
118+
// println!("CONSTRUCTED");//TEST
119+
// Call "constructed" on parent
120+
self.parent_constructed(obj);
121+
122+
// Setup
123+
//obj.setup_settings();
124+
//obj.load_properties();//TODO
125+
//obj.setup_widgets();
126+
//obj.setup_callbacks();
127+
//obj.setup_actions();
128+
}
129+
130+
/**
131+
* Name:
132+
* properties
133+
*
134+
* Description:
135+
* Create list of custom properties for our GObject
136+
*
137+
* Made:
138+
* 02/11/2022
139+
*
140+
* Made by:
141+
* Deren Vural
142+
*
143+
* Notes:
144+
* beware that you need to use kebab-case (<https://en.wikipedia.org/wiki/Letter_case#Kebab_case>)
145+
*
146+
* ParamSpec Examples:
147+
* glib::ParamSpecString::builder("icon").build(),
148+
* glib::ParamSpecUInt::builder("gpu_count").build(),
149+
* glib::ParamSpecString::builder("call_extension").build(),
150+
* TODO: these are from property class
151+
* glib::ParamSpecBoxed::builder("processor").build(),
152+
* glib::ParamSpecObject::builder("formatter").build(),
153+
*/
154+
fn properties() -> &'static [ParamSpec] {
155+
//println!("PROPERTIES");//TEST
156+
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
157+
vec![
158+
glib::ParamSpecString::builder("uuid").build(),
159+
glib::ParamSpecString::builder("name").build(),
160+
glib::ParamSpecObject::builder("provider", glib::Type::OBJECT).build(),
161+
]
162+
});
163+
164+
//println!("PROPERTIES: {:?}", PROPERTIES);//TEST
165+
//println!("trying to add `base_call`: {:?}", glib::ParamSpecString::builder("base_call").build());//TEST
166+
167+
PROPERTIES.as_ref()
168+
}
169+
170+
/**
171+
* Name:
172+
* set_property
173+
*
174+
* Description:
175+
* Mutator for custom GObject properties
176+
*
177+
* Made:
178+
* 02/11/2022
179+
*
180+
* Made by:
181+
* Deren Vural
182+
*
183+
* Notes:
184+
*
185+
*/
186+
fn set_property(&self, _obj: &Self::Type, _id: usize, value: &Value, pspec: &ParamSpec) {
187+
//println!("setting: {:?}", pspec.name());//TEST
188+
189+
// println!("setting: {:?}", pspec.name());//TEST
190+
// let x: String = self.uuid.take();
191+
// self.uuid.set(x.clone());
192+
// println!("U: `{}`", x);
193+
// let x: String = self.name.take();
194+
// self.name.set(x.clone());
195+
// println!("N: `{}`", x);
196+
197+
match pspec.name() {
198+
"uuid" => {
199+
match value.get() {
200+
Ok(input_uuid) => {
201+
self.uuid.replace(input_uuid);
202+
},
203+
Err(_) => panic!("The value needs to be of type `String`."),
204+
}
205+
}
206+
"name" => {
207+
match value.get() {
208+
Ok(input_name) => {
209+
self.name.replace(input_name);
210+
},
211+
Err(_) => panic!("The value needs to be of type `String`."),
212+
}
213+
}
214+
"provider" => {
215+
match value.get() {
216+
Ok(input_provider_property) => {
217+
self.provider.replace(input_provider_property);
218+
},
219+
Err(_) => panic!("The value needs to be of type `Provider`."),
220+
}
221+
}
222+
_ => panic!("Property `{}` does not exist..", pspec.name())
223+
}
224+
225+
// let x: String = self.uuid.take();
226+
// self.uuid.set(x.clone());
227+
// println!("U: `{}`", x);
228+
// let x: String = self.name.take();
229+
// self.name.set(x.clone());
230+
// println!("N: `{}`", x);
231+
}
232+
233+
/**
234+
* Name:
235+
* property
236+
*
237+
* Description:
238+
* Accessor for custom GObject properties
239+
*
240+
* Made:
241+
* 02/11/2022
242+
*
243+
* Made by:
244+
* Deren Vural
245+
*
246+
* Notes:
247+
*
248+
*/
249+
fn property(&self, _obj: &Self::Type, _id: usize, pspec: &ParamSpec) -> Value {
250+
//println!("getting: {:?}", pspec.name());//TEST
251+
252+
match pspec.name() {
253+
"uuid" => {
254+
//TODO: this seems ridiculous..
255+
let value: String = self.uuid.take();
256+
257+
self.uuid.set(value.clone());
258+
259+
value.to_value()
260+
}
261+
"name" => {
262+
//TODO: this seems ridiculous..
263+
let value: String = self.name.take();
264+
265+
self.name.set(value.clone());
266+
267+
value.to_value()
268+
}
269+
"provider" => {
270+
let value: Ref<Provider> = self.provider.borrow();
271+
272+
//self.provider.set(value.clone());
273+
274+
value.to_value()
275+
}
276+
_ => panic!("Property `{}` does not exist..", pspec.name())
277+
}
278+
}
279+
}
280+
281+
/**
282+
* Trait Name:
283+
* WidgetImpl
284+
*
285+
* Description:
286+
* Trait shared by all widgets
287+
*
288+
* Made:
289+
* 09/10/2022
290+
*
291+
* Made by:
292+
* Deren Vural
293+
*
294+
* Notes:
295+
*
296+
*/
297+
impl WidgetImpl for GpuPage {}
298+
299+
/**
300+
* Trait Name:
301+
* GridImpl
302+
*
303+
* Description:
304+
* Trait shared by all grids
305+
*
306+
* Made:
307+
* 02/11/2022
308+
*
309+
* Made by:
310+
* Deren Vural
311+
*
312+
* Notes:
313+
*
314+
*/
315+
impl GridImpl for GpuPage {}
316+

0 commit comments

Comments
 (0)