@@ -30,7 +30,7 @@ mod custom_button;
30
30
mod settingswindow;
31
31
32
32
// Imports
33
- use adwaita:: { gio, prelude:: * , Application } ;
33
+ use adwaita:: { gio, glib , prelude:: * , Application } ;
34
34
use gdk:: Display ;
35
35
use gio:: resources_register_include;
36
36
use gtk:: { CssProvider , StyleContext } ;
@@ -54,7 +54,7 @@ const APP_ID: &str = "com.gtk_d.NvidiaMonitorRust";
54
54
* Notes:
55
55
*
56
56
*/
57
- fn main ( ) {
57
+ pub fn create_app ( ) -> Application {
58
58
// Resources
59
59
resources_register_include ! ( "nvidiamonitorrust.gresource" )
60
60
. expect ( "Failed to register resources." ) ;
@@ -66,12 +66,12 @@ fn main() {
66
66
let app: Application = Application :: builder ( ) . application_id ( APP_ID ) . build ( ) ;
67
67
68
68
// Connect to signals of `app`
69
- // app.connect_startup(setup_shortcuts);
69
+ app. connect_startup ( setup_shortcuts) ;
70
70
app. connect_startup ( |_| load_css ( ) ) ;
71
71
app. connect_activate ( build_ui) ;
72
72
73
- // Run the application
74
- println ! ( "{}" , app. run ( ) ) ;
73
+ // Return the application
74
+ app
75
75
}
76
76
77
77
/**
@@ -91,14 +91,18 @@ fn main() {
91
91
* <https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/todo/5/main.rs>
92
92
* <https://gtk-rs.org/gtk4-rs/stable/latest/book/todo_3.html>
93
93
*
94
+ * https://gtk-rs.org/gtk4-rs/git/book/actions.html
95
+ * https://gtk-rs.org/gtk4-rs/git/docs/gtk4/struct.Window.html#actions
94
96
*/
95
- /*
96
97
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"]);
98
+ //app.set_accels_for_action("win.filter('All')", &["<Ctrl>a"]);
99
+ //app.set_accels_for_action("win.filter('Open')", &["<Ctrl>o"]);
100
+ //app.set_accels_for_action("win.filter('Done')", &["<Ctrl>d"]);
101
+ //app.set_accels_for_action("win.filter('Close')", &["<Ctrl>q"])
102
+ app. set_accels_for_action ( "window.close" , & [ "<Ctrl>q" ] ) ;
103
+ app. set_accels_for_action ( "window.toggle-maximized" , & [ "<Ctrl>w" ] ) ;
104
+ app. set_accels_for_action ( "window.minimize" , & [ "<Ctrl>m" ] ) ;
100
105
}
101
- */
102
106
103
107
/**
104
108
* Name:
@@ -149,44 +153,26 @@ fn build_ui(app: &Application) {
149
153
// Create a new custom window and show it
150
154
let window: MainWindow = MainWindow :: new ( app) ;
151
155
156
+ // Create custom action to close window (for shortcuts)
157
+ // Was a "close" replica
158
+ /*
159
+ let action_close = SimpleAction::new("something", None);
160
+ action_close.connect_activate(clone!(@weak window => move |_, _| {
161
+ window.close();
162
+ }));
163
+ window.add_action(&action_close);
164
+ */
165
+
152
166
// Present window
153
167
window. show ( ) ;
154
168
155
169
/*
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
170
// App Indicator
169
171
//let mut indicator = AppIndicator::new("Nvidia App", "");
170
172
//indicator.set_status(AppIndicatorStatus::Active);
171
173
//let icon_path = Path::new(env!("CARGO_MANIFEST_DIR")).join("resources");
172
174
//indicator.set_icon_theme_path(icon_path.to_str().unwrap());
173
175
//indicator.set_icon_full("rust-logo", "icon");
174
176
//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
- */
177
+ */
192
178
}
0 commit comments