Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
stsdc committed Oct 29, 2023
1 parent c5456f1 commit a396210
Show file tree
Hide file tree
Showing 24 changed files with 280 additions and 195 deletions.
4 changes: 2 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ app_dependencies = [
dependency('gio-2.0'),
dependency('gobject-2.0'),
dependency('libgtop-2.0'),
dependency('libwnck-3.0', version: '>=40.1'),
#dependency('libwnck-3.0', version: '>=40.1'),
dependency('libadwaita-1', version: '>=1.0.0'),
dependency('gtk4-x11'),
dependency('x11'),
# dependency('x11'),
dependency('udisks2'),
dependency('json-glib-1.0'),
dependency('flatpak'),
Expand Down
58 changes: 32 additions & 26 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public class Monitor.MainWindow : Hdy.ApplicationWindow {
public class Monitor.MainWindow : Adw.ApplicationWindow {
// application reference
private Shortcuts shortcuts;

Expand All @@ -19,7 +19,7 @@ public class Monitor.MainWindow : Hdy.ApplicationWindow {

// Constructs a main window
public MainWindow (MonitorApp app) {
Hdy.init ();
Adw.init ();
this.set_application (app);

setup_window_state ();
Expand Down Expand Up @@ -49,24 +49,23 @@ public class Monitor.MainWindow : Hdy.ApplicationWindow {
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 ();
headerbar.set_title_widget (stack_switcher);
headerbar.preferences_grid.attach (new PreferencesView (), 0, 0, 1, 1);
// sv.show_all ();

statusbar = new Statusbar ();

var grid = new Gtk.Grid () {
orientation = Gtk.Orientation.VERTICAL
};

grid.add (headerbar);
grid.add (stack);
grid.add (statusbar);
grid.attach (headerbar, 0, 0, 1, 1);
grid.attach (stack, 0, 1, 1, 1);
grid.attach (statusbar, 0, 2, 1, 1);

add (grid);
set_content (grid);

show_all ();
present ();

dbusserver = DBusServer.get_default ();

Expand Down Expand Up @@ -98,35 +97,38 @@ public class Monitor.MainWindow : Hdy.ApplicationWindow {

dbusserver.quit.connect (() => app.quit ());
dbusserver.show.connect (() => {
this.deiconify ();
// this.deiconify ();
this.present ();
setup_window_state ();
this.show_all ();
this.present ();
});

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);
app.window_removed.connect (() => {
int position_x, position_y;
int window_width = get_size (Gtk.Orientation.HORIZONTAL);
int window_height = get_size (Gtk.Orientation.VERTICAL);
// 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_boolean ("is-maximized", this.is_maximized);

MonitorApp.settings.set_string ("opened-view", stack.visible_child_name);

if (MonitorApp.settings.get_boolean ("indicator-state")) {
this.hide_on_delete ();
// Read: https://discourse.gnome.org/t/how-to-hide-widget-instead-removing-them-in-gtk-4/8176
// this.hide_on_delete ();

} else {
dbusserver.indicator_state (false);
app.quit ();
}

return true;
// return true;
});

dbusserver.indicator_state (MonitorApp.settings.get_boolean ("indicator-state"));
Expand All @@ -144,12 +146,16 @@ public class Monitor.MainWindow : Hdy.ApplicationWindow {

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);
}

// Can't move window to a specific position in GTK4
// Read: https://discourse.gnome.org/t/how-to-center-gtkwindows-in-gtk4/3112

// 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);
// }
}

}
8 changes: 4 additions & 4 deletions src/Managers/Process.vala
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,10 @@ public class Monitor.Process : GLib.Object {
mem_usage = (proc_mem.resident - proc_mem.share) / 1024; // in KiB

// also if it is using X Window Server
if (Gdk.Display.get_default () is Gdk.X11.Display) {
Wnck.ResourceUsage resu = Wnck.ResourceUsage.pid_read (Gdk.Display.get_default (), stat.pid);
mem_usage += (resu.total_bytes_estimate / 1024);
}
// if (Gdk.Display.get_default () is Gdk.X11.Display) {
// Wnck.ResourceUsage resu = Wnck.ResourceUsage.pid_read (Gdk.Display.get_default (), stat.pid);
// mem_usage += (resu.total_bytes_estimate / 1024);
// }

var total_installed_memory = (double) mem.total / 1024;
mem_percentage = (mem_usage / total_installed_memory) * 100;
Expand Down
5 changes: 2 additions & 3 deletions src/Monitor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ namespace Monitor {
public override void activate () {
// only have one window
if (get_windows () != null) {
window.show_all ();
window.present ();
return;
}
Expand Down Expand Up @@ -60,10 +59,10 @@ namespace Monitor {
window.hide ();
MonitorApp.settings.set_boolean ("background-state", true);
} else {
window.show_all ();
window.present ();
}

window.process_view.process_tree_view.focus_on_first_row ();
// window.process_view.process_tree_view.focus_on_first_row ();

var quit_action = new SimpleAction ("quit", null);
add_action (quit_action);
Expand Down
6 changes: 4 additions & 2 deletions src/Services/Appearance.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class Monitor.Appearance : Object {
provider.load_from_resource ("/com/github/stsdc/monitor/monitor-light.css");
}

Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
// @TODO: Fix styles
// Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

// We listen to changes in Granite.Settings and update our app if the user changes their preference
granite_settings.notify["prefers-color-scheme"].connect (() => {
Expand All @@ -37,7 +38,8 @@ public class Monitor.Appearance : Object {
debug ("Retrofitting styles to make Monitor usable with a current theme.");
var provider = new Gtk.CssProvider ();
provider.load_from_resource ("/com/github/stsdc/monitor/monitor-retrofit.css");
Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
// @TODO: Fix retrofitting styles
// Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
}
}
}
12 changes: 6 additions & 6 deletions src/Services/Shortcuts.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ public class Monitor.Shortcuts : Object {
this.window = window;
}

public bool handle (Gdk.EventKey e) {
public bool handle (Gdk.KeyEvent e) {
handled = false;
char typed = e.str[0];
// char typed = e.str[0];

if (typed.isalnum () && !window.headerbar.search.is_focus) {
window.headerbar.search.activate_entry (e.str);
handled = true;
}
// if (typed.isalnum () && !window.headerbar.search.is_focus) {
// window.headerbar.search.activate_entry (e.str);
// handled = true;
// }

// if ((e.state & Gdk.ModifierType.CONTROL_MASK) != 0) {
// switch (e.keyval) {
Expand Down
8 changes: 4 additions & 4 deletions src/Views/ProcessView/ProcessInfoView/Preventor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public class Monitor.Preventor : Gtk.Stack {

confirm_button = new Gtk.Button.with_label (_("Yes"));
confirm_button.margin_end = 10;
confirm_button.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
// confirm_button.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);

deny_button = new Gtk.Button.with_label (_("No"));

preventive_action_bar.add (confirmation_label);
preventive_action_bar.add (confirm_button);
preventive_action_bar.add (deny_button);
preventive_action_bar.append (confirmation_label);
preventive_action_bar.append (confirm_button);
preventive_action_bar.append (deny_button);
}

public Preventor (Gtk.Widget _child, string name) {
Expand Down
4 changes: 2 additions & 2 deletions src/Views/ProcessView/ProcessInfoView/ProcessInfoCPURAM.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public class Monitor.ProcessInfoCPURAM : Gtk.Grid {
ram_chart.height_request = 60;

var cpu_graph_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
cpu_graph_box.add (cpu_chart);
cpu_graph_box.append (cpu_chart);

var mem_graph_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
mem_graph_box.add (ram_chart);
mem_graph_box.append (ram_chart);

cpu_label = new Gtk.Label ("CPU: " + Utils.NO_DATA);
cpu_label.get_style_context ().add_class (Granite.STYLE_CLASS_H4_LABEL);
Expand Down
14 changes: 7 additions & 7 deletions src/Views/ProcessView/ProcessInfoView/ProcessInfoHeader.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Monitor.ProcessInfoHeader : Gtk.Grid {
regex = /(?i:^.*\.(xpm|png)$)/; // vala-lint=space-before-paren,
/* *INDENT-ON* */

icon = new Gtk.Image.from_icon_name ("application-x-executable", Gtk.IconSize.DIALOG);
icon = new Gtk.Image.from_icon_name ("application-x-executable");
icon.set_pixel_size (64);
icon.valign = Gtk.Align.END;

Expand Down Expand Up @@ -50,11 +50,11 @@ public class Monitor.ProcessInfoHeader : Gtk.Grid {
username = new LabelRoundy ("");

var wrapper = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
wrapper.add (pid);
wrapper.add (priority);
wrapper.add (nice);
wrapper.add (num_threads);
wrapper.add (username);
wrapper.append (pid);
wrapper.append (priority);
wrapper.append (nice);
wrapper.append (num_threads);
wrapper.append (username);

attach (icon_container, 0, 0, 1, 2);
attach (application_name, 1, 0, 3, 1);
Expand Down Expand Up @@ -96,7 +96,7 @@ public class Monitor.ProcessInfoHeader : Gtk.Grid {
var icon_name = process.icon.to_string ();

if (!regex.match (icon_name)) {
icon.set_from_icon_name (icon_name, Gtk.IconSize.DIALOG);
icon.set_from_icon_name (icon_name);
} else {
try {
var pixbuf = new Gdk.Pixbuf.from_file_at_size (icon_name, 48, -1);
Expand Down
4 changes: 2 additions & 2 deletions src/Views/ProcessView/ProcessInfoView/ProcessInfoIOStats.vala
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public class Monitor.ProcessInfoIOStats : Gtk.Grid {
// attach (opened_files_label, 0, 3, 3, 1);

var model = new OpenFilesTreeViewModel ();
var open_files_tree_view_scrolled = new Gtk.ScrolledWindow (null, null);
var open_files_tree_view_scrolled = new Gtk.ScrolledWindow ();
open_files_tree_view = new OpenFilesTreeView (model);
open_files_tree_view_scrolled.add (open_files_tree_view);
open_files_tree_view_scrolled.set_child (open_files_tree_view);
attach (open_files_tree_view_scrolled, 0, 4, 3, 1);
}

Expand Down
31 changes: 18 additions & 13 deletions src/Views/ProcessView/ProcessInfoView/ProcessInfoView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Monitor.ProcessInfoView : Gtk.Box {

process_info_header.update (_process);

this.show_all ();
// this.show_all ();
if (_process.uid != Posix.getuid ()) {
process_info_cpu_ram.hide ();
process_info_io_stats.hide ();
Expand All @@ -32,7 +32,7 @@ public class Monitor.ProcessInfoView : Gtk.Box {
permission_error_infobar.revealed = false;

process_info_io_stats.open_files_tree_view.model.process = _process;
process_info_io_stats.open_files_tree_view.show_all ();
// process_info_io_stats.open_files_tree_view.show_all ();
}
}
}
Expand All @@ -55,22 +55,28 @@ public class Monitor.ProcessInfoView : Gtk.Box {
permission_error_infobar.message_type = Gtk.MessageType.ERROR;
permission_error_infobar.revealed = false;
permission_error_label = new Gtk.Label (Utils.NO_DATA);
permission_error_infobar.get_content_area ().add (permission_error_label);
add (permission_error_infobar);
permission_error_infobar.add_child (permission_error_label);
append (permission_error_infobar);

var grid = new Gtk.Grid () {
margin = 12,
margin_start = 12,
margin_end = 12,
margin_top = 12,
margin_bottom = 12,
hexpand = true,
column_spacing = 12
};
add (grid);
append (grid);


process_info_header = new ProcessInfoHeader ();
grid.attach (process_info_header, 0, 0, 1, 1);

var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL) {
margin = 12,
margin_start = 12,
margin_end = 12,
margin_top = 12,
margin_bottom = 12,
hexpand = true
};
grid.attach (separator, 0, 1, 1, 1);
Expand All @@ -91,15 +97,15 @@ public class Monitor.ProcessInfoView : Gtk.Box {
end_process_button.margin_end = 10;
end_process_button.tooltip_markup = Granite.markup_accel_tooltip ({ "<Ctrl>E" }, _("End selected process"));
var end_process_button_context = end_process_button.get_style_context ();
end_process_button_context.add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
// end_process_button_context.add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);

kill_process_button = new Gtk.Button.with_label (_("Kill Process"));
kill_process_button.tooltip_markup = Granite.markup_accel_tooltip ({ "<Ctrl>K" }, _("Kill selected process"));
var kill_process_button_context = kill_process_button.get_style_context ();
kill_process_button_context.add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
// kill_process_button_context.add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);

process_action_bar.add (end_process_button);
process_action_bar.add (kill_process_button);
process_action_bar.append (end_process_button);
process_action_bar.append (kill_process_button);

preventor = new Preventor (process_action_bar, "process_action_bar");

Expand All @@ -119,7 +125,6 @@ public class Monitor.ProcessInfoView : Gtk.Box {

grid.attach (preventor, 0, 5, 1, 1);

show_all ();
process_info_cpu_ram.hide ();
process_info_io_stats.hide ();
preventor.hide ();
Expand All @@ -139,7 +144,7 @@ public class Monitor.ProcessInfoView : Gtk.Box {
process_info_io_stats.update (process);

process_info_io_stats.open_files_tree_view.model.process = _process;
process_info_io_stats.open_files_tree_view.show_all ();
// process_info_io_stats.open_files_tree_view.show_all ();
}
}

Expand Down
Loading

0 comments on commit a396210

Please sign in to comment.