17
17
* Notes:
18
18
*
19
19
*/
20
+
20
21
// Modules
21
22
mod formatter;
22
23
mod gpu_page;
@@ -30,7 +31,7 @@ mod custom_button;
30
31
mod settingswindow;
31
32
32
33
// Imports
33
- use adwaita:: { gio, prelude:: * , Application } ;
34
+ use adwaita:: { gio, glib , prelude:: * , Application } ;
34
35
use gdk:: Display ;
35
36
use gio:: resources_register_include;
36
37
use gtk:: { CssProvider , StyleContext } ;
@@ -54,7 +55,7 @@ const APP_ID: &str = "com.gtk_d.NvidiaMonitorRust";
54
55
* Notes:
55
56
*
56
57
*/
57
- fn main ( ) {
58
+ pub fn create_app ( ) -> Application {
58
59
// Resources
59
60
resources_register_include ! ( "nvidiamonitorrust.gresource" )
60
61
. expect ( "Failed to register resources." ) ;
@@ -66,12 +67,12 @@ fn main() {
66
67
let app: Application = Application :: builder ( ) . application_id ( APP_ID ) . build ( ) ;
67
68
68
69
// Connect to signals of `app`
69
- // app.connect_startup(setup_shortcuts);
70
+ app. connect_startup ( setup_shortcuts) ;
70
71
app. connect_startup ( |_| load_css ( ) ) ;
71
72
app. connect_activate ( build_ui) ;
72
73
73
- // Run the application
74
- println ! ( "{}" , app. run ( ) ) ;
74
+ // Return the application
75
+ app
75
76
}
76
77
77
78
/**
@@ -91,14 +92,18 @@ fn main() {
91
92
* <https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/todo/5/main.rs>
92
93
* <https://gtk-rs.org/gtk4-rs/stable/latest/book/todo_3.html>
93
94
*
95
+ * https://gtk-rs.org/gtk4-rs/git/book/actions.html
96
+ * https://gtk-rs.org/gtk4-rs/git/docs/gtk4/struct.Window.html#actions
94
97
*/
95
- /*
96
98
fn setup_shortcuts ( app : & Application ) {
97
- app.set_accels_for_action("win.filter('All')", &["<Ctrl>a"]);
98
- app.set_accels_for_action("win.filter('Open')", &["<Ctrl>o"]);
99
- app.set_accels_for_action("win.filter('Done')", &["<Ctrl>d"]);
99
+ //app.set_accels_for_action("win.filter('All')", &["<Ctrl>a"]);
100
+ //app.set_accels_for_action("win.filter('Open')", &["<Ctrl>o"]);
101
+ //app.set_accels_for_action("win.filter('Done')", &["<Ctrl>d"]);
102
+ //app.set_accels_for_action("win.filter('Close')", &["<Ctrl>q"])
103
+ app. set_accels_for_action ( "window.close" , & [ "<Ctrl>q" ] ) ;
104
+ app. set_accels_for_action ( "window.toggle-maximized" , & [ "<Ctrl>w" ] ) ;
105
+ app. set_accels_for_action ( "window.minimize" , & [ "<Ctrl>m" ] ) ;
100
106
}
101
- */
102
107
103
108
/**
104
109
* Name:
@@ -149,44 +154,26 @@ fn build_ui(app: &Application) {
149
154
// Create a new custom window and show it
150
155
let window: MainWindow = MainWindow :: new ( app) ;
151
156
157
+ // Create custom action to close window (for shortcuts)
158
+ // Was a "close" replica
159
+ /*
160
+ let action_close = SimpleAction::new("something", None);
161
+ action_close.connect_activate(clone!(@weak window => move |_, _| {
162
+ window.close();
163
+ }));
164
+ window.add_action(&action_close);
165
+ */
166
+
152
167
// Present window
153
168
window. show ( ) ;
154
169
155
170
/*
156
- // Menu Child
157
- let menu: Menu = Menu::new();
158
- let item: Menu = Menu::new();
159
- item.append(Some("Utilisation"), Some("app.util"));
160
- item.append(Some("Temperature"), Some("app.temp"));
161
- item.append(Some("Memory Usage"), Some("app.memo"));
162
- item.append(Some("Fan Speed"), Some("app.fans"));
163
- menu.append_submenu(Some("Item 1"), &item);
164
- menu.append(Some("SMI"), Some("app.smi"));
165
- menu.append(Some("Settings"), Some("app.settings"));
166
- app.set_menubar(Some(&menu));
167
-
168
171
// App Indicator
169
172
//let mut indicator = AppIndicator::new("Nvidia App", "");
170
173
//indicator.set_status(AppIndicatorStatus::Active);
171
174
//let icon_path = Path::new(env!("CARGO_MANIFEST_DIR")).join("resources");
172
175
//indicator.set_icon_theme_path(icon_path.to_str().unwrap());
173
176
//indicator.set_icon_full("rust-logo", "icon");
174
177
//indicator.set_menu(&mut menu);
175
-
176
- // Create Parent window
177
- let window: ApplicationWindow = ApplicationWindow::new(app);
178
- window.set_title(Some("Nvidia App"));
179
- window.set_default_size(400, 400);
180
- window.set_show_menubar(true);
181
-
182
- // Add children to window
183
- //window.set_child(Some(&button1));
184
- //window.set_child(Some(&button2));
185
- //window.set_child(Some(&button3));
186
- //window.set_child(Some(&button4));
187
- //window.set_child(Some(&button5));
188
-
189
- // Present window
190
- window.show();
191
178
*/
192
179
}
0 commit comments