-
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathMainWindow.vala
More file actions
153 lines (111 loc) · 4.9 KB
/
MainWindow.vala
File metadata and controls
153 lines (111 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
public class Monitor.MainWindow : Hdy.ApplicationWindow {
// application reference
private Shortcuts shortcuts;
private Resources resources;
// Widgets
public Headerbar headerbar;
public ProcessView process_view;
public SystemView system_view;
private Gtk.Stack stack;
private Statusbar statusbar;
public DBusServer dbusserver;
// Constructs a main window
public MainWindow (MonitorApp app) {
Hdy.init ();
this.set_application (app);
setup_window_state ();
title = _("Monitor");
get_style_context ().add_class ("rounded");
resources = new Resources ();
process_view = new ProcessView ();
var sorting_state = MonitorApp.settings.get_string ("process-view-columns-sorting-state");
debug ("sorting state: " + sorting_state);
process_view.process_tree_view.set_sorting_state (sorting_state);
system_view = new SystemView (resources);
stack = new Gtk.Stack ();
stack.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT_RIGHT);
stack.add_titled (process_view, "process_view", _("Processes"));
stack.add_titled (system_view, "system_view", _("System"));
Gtk.StackSwitcher stack_switcher = new Gtk.StackSwitcher ();
stack_switcher.valign = Gtk.Align.CENTER;
stack_switcher.set_stack (stack);
headerbar = new Headerbar (this);
headerbar.set_custom_title (stack_switcher);
var sv = new PreferencesView ();
headerbar.preferences_grid.add (sv);
sv.show_all ();
statusbar = new Statusbar ();
var grid = new Gtk.Grid () {
orientation = Gtk.Orientation.VERTICAL
};
grid.add (headerbar);
grid.add (stack);
grid.add (statusbar);
add (grid);
show_all ();
dbusserver = DBusServer.get_default ();
stack.notify["visible-child-name"].connect (() => {
headerbar.search.sensitive = stack.visible_child_name == "process_view";
});
new Thread<void> ("upd", () => {
Timeout.add_seconds (2, () => {
process_view.update ();
Idle.add (() => {
system_view.update ();
dbusserver.indicator_state (MonitorApp.settings.get_boolean ("indicator-state"));
var res = resources.serialize ();
statusbar.update (res);
dbusserver.update (res);
return false;
});
return true;
});
});
dbusserver.quit.connect (() => app.quit ());
dbusserver.show.connect (() => {
this.deiconify ();
this.present ();
setup_window_state ();
this.show_all ();
});
shortcuts = new Shortcuts (this);
key_press_event.connect ((e) => shortcuts.handle (e));
this.delete_event.connect (() => {
int window_width, window_height, position_x, position_y;
get_size (out window_width, out window_height);
get_position (out position_x, out position_y);
MonitorApp.settings.set_int ("window-width", window_width);
MonitorApp.settings.set_int ("window-height", window_height);
MonitorApp.settings.set_int ("position-x", position_x);
MonitorApp.settings.set_int ("position-y", position_y);
MonitorApp.settings.set_boolean ("is-maximized", this.is_maximized);
MonitorApp.settings.set_string ("opened-view", stack.visible_child_name);
MonitorApp.settings.set_string ("process-view-columns-sorting-state", process_view.process_tree_view.get_sorting_state ());
if (MonitorApp.settings.get_boolean ("indicator-state")) {
this.hide_on_delete ();
} else {
dbusserver.indicator_state (false);
app.quit ();
}
return true;
});
dbusserver.indicator_state (MonitorApp.settings.get_boolean ("indicator-state"));
stack.visible_child_name = MonitorApp.settings.get_string ("opened-view");
}
private void setup_window_state () {
int window_width = MonitorApp.settings.get_int ("window-width");
int window_height = MonitorApp.settings.get_int ("window-height");
this.set_default_size (window_width, window_height);
if (MonitorApp.settings.get_boolean ("is-maximized")) {
this.maximize ();
}
int position_x = MonitorApp.settings.get_int ("position-x");
int position_y = MonitorApp.settings.get_int ("position-y");
if (position_x == -1 || position_y == -1) {
// -1 is default value of these keys, which means this is the first launch
this.window_position = Gtk.WindowPosition.CENTER;
} else {
move (position_x, position_y);
}
}
}