From 3783fd37ba28434a800b8c9db2bd2367352ebd87 Mon Sep 17 00:00:00 2001 From: stsdc <6031763+stsdc@users.noreply.github.com> Date: Fri, 24 Nov 2023 14:56:28 +0100 Subject: [PATCH] ProcessInfoView ported --- src/Services/Appearance.vala | 24 +++++---- .../ProcessInfoView/Preventor.vala | 19 +++---- .../ProcessInfoView/ProcessInfoHeader.vala | 1 + .../ProcessInfoView/ProcessInfoIOStats.vala | 4 +- .../ProcessInfoView/ProcessInfoView.vala | 49 +++++++++---------- src/Views/ProcessView/ProcessView.vala | 5 +- src/Widgets/Headerbar/Search.vala | 2 +- src/meson.build | 2 +- 8 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/Services/Appearance.vala b/src/Services/Appearance.vala index b127f520..371df0ac 100644 --- a/src/Services/Appearance.vala +++ b/src/Services/Appearance.vala @@ -6,29 +6,27 @@ public class Monitor.Appearance : Object { bool is_dark = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK; gtk_settings.gtk_application_prefer_dark_theme = is_dark; - - var provider = new Gtk.CssProvider (); - - if (is_dark) { - provider.load_from_resource ("/com/github/stsdc/monitor/monitor-dark.css"); - } else { - provider.load_from_resource ("/com/github/stsdc/monitor/monitor-light.css"); - } - - // @TODO: Fix styles - // Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + load_style (is_dark); // We listen to changes in Granite.Settings and update our app if the user changes their preference granite_settings.notify["prefers-color-scheme"].connect (() => { is_dark = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK; gtk_settings.gtk_application_prefer_dark_theme = is_dark; + load_style (is_dark); + }); + } + + private static void load_style (bool is_dark) { + var provider = new Gtk.CssProvider (); if (is_dark) { provider.load_from_resource ("/com/github/stsdc/monitor/monitor-dark.css"); } else { provider.load_from_resource ("/com/github/stsdc/monitor/monitor-light.css"); } - }); + // @TODO: Fix styles + Gtk.StyleContext.add_provider_for_display (Gdk.Display.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + } public static void retrofit () { @@ -39,7 +37,7 @@ public class Monitor.Appearance : Object { var provider = new Gtk.CssProvider (); provider.load_from_resource ("/com/github/stsdc/monitor/monitor-retrofit.css"); // @TODO: Fix retrofitting styles - // Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + Gtk.StyleContext.add_provider_for_display (Gdk.Display.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); } } } diff --git a/src/Views/ProcessView/ProcessInfoView/Preventor.vala b/src/Views/ProcessView/ProcessInfoView/Preventor.vala index 8ebc8a34..19d58cde 100644 --- a/src/Views/ProcessView/ProcessInfoView/Preventor.vala +++ b/src/Views/ProcessView/ProcessInfoView/Preventor.vala @@ -1,4 +1,4 @@ -public class Monitor.Preventor : Gtk.Stack { +public class Monitor.Preventor : Gtk.Box { private Gtk.Box preventive_action_bar; private Gtk.Label confirmation_label; private Gtk.Button confirm_button; @@ -33,26 +33,27 @@ public class Monitor.Preventor : Gtk.Stack { public Preventor (Gtk.Widget _child, string name) { child_widget = _child; - add_named (child_widget, name); - add_named (preventive_action_bar, "preventive_action_bar"); + append (child_widget); + append (preventive_action_bar); deny_button.clicked.connect (() => { - set_transition_type (Gtk.StackTransitionType.SLIDE_UP); - set_visible_child (child_widget); + // set_transition_type (Gtk.StackTransitionType.SLIDE_UP); + // set_visible_child (child_widget); confirmed (false); }); confirm_button.clicked.connect (() => { - set_transition_type (Gtk.StackTransitionType.SLIDE_UP); - set_visible_child (child_widget); + // set_transition_type (Gtk.StackTransitionType.SLIDE_UP); + // set_visible_child (child_widget); confirmed (true); }); } public void set_prevention (string confirmation_text) { - set_transition_type (Gtk.StackTransitionType.SLIDE_DOWN); + // set_transition_type (Gtk.StackTransitionType.SLIDE_DOWN); confirmation_label.set_text (_(confirmation_text)); - set_visible_child (preventive_action_bar); + // set_visible_child (preventive_action_bar); + preventive_action_bar.visible = true; } } diff --git a/src/Views/ProcessView/ProcessInfoView/ProcessInfoHeader.vala b/src/Views/ProcessView/ProcessInfoView/ProcessInfoHeader.vala index b4840181..5cd6ebb2 100644 --- a/src/Views/ProcessView/ProcessInfoView/ProcessInfoHeader.vala +++ b/src/Views/ProcessView/ProcessInfoView/ProcessInfoHeader.vala @@ -15,6 +15,7 @@ public class Monitor.ProcessInfoHeader : Gtk.Grid { construct { column_spacing = 12; + width_request = 270; /* *INDENT-OFF* */ regex = /(?i:^.*\.(xpm|png)$)/; // vala-lint=space-before-paren, diff --git a/src/Views/ProcessView/ProcessInfoView/ProcessInfoIOStats.vala b/src/Views/ProcessView/ProcessInfoView/ProcessInfoIOStats.vala index 177eaf21..1a52a2fe 100644 --- a/src/Views/ProcessView/ProcessInfoView/ProcessInfoIOStats.vala +++ b/src/Views/ProcessView/ProcessInfoView/ProcessInfoIOStats.vala @@ -14,6 +14,8 @@ public class Monitor.ProcessInfoIOStats : Gtk.Grid { row_spacing = 6; column_homogeneous = true; row_homogeneous = false; + width_request = 270; + vexpand = true; var opened_files_label = create_label (_("Opened files")); opened_files_label.get_style_context ().add_class (Granite.STYLE_CLASS_H4_LABEL); @@ -52,7 +54,7 @@ public class Monitor.ProcessInfoIOStats : Gtk.Grid { var open_files_tree_view_scrolled = new Gtk.ScrolledWindow (); open_files_tree_view = new OpenFilesTreeView (model); open_files_tree_view_scrolled.set_child (open_files_tree_view); - attach (open_files_tree_view_scrolled, 0, 4, 3, 1); + // attach (open_files_tree_view_scrolled, 0, 4, 3, 1); } public void update (Process process) { diff --git a/src/Views/ProcessView/ProcessInfoView/ProcessInfoView.vala b/src/Views/ProcessView/ProcessInfoView/ProcessInfoView.vala index 45a01055..58c68700 100644 --- a/src/Views/ProcessView/ProcessInfoView/ProcessInfoView.vala +++ b/src/Views/ProcessView/ProcessInfoView/ProcessInfoView.vala @@ -1,5 +1,4 @@ public class Monitor.ProcessInfoView : Gtk.Box { - // private Preventor preventor; private ProcessInfoIOStats process_info_io_stats = new ProcessInfoIOStats (); private Process _process; @@ -20,7 +19,8 @@ public class Monitor.ProcessInfoView : Gtk.Box { if (_process.uid != Posix.getuid ()) { process_info_cpu_ram.hide (); process_info_io_stats.hide (); - // preventor.hide (); + end_process_button.hide (); + kill_process_button.hide (); } else { _process.fd_permission_error.connect (show_permission_error_infobar); @@ -32,7 +32,11 @@ 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.set_visible (true); + process_info_cpu_ram.set_visible (true); + process_info_io_stats.set_visible (true); + end_process_button.show (); + kill_process_button.show (); } } } @@ -56,7 +60,7 @@ public class Monitor.ProcessInfoView : Gtk.Box { permission_error_infobar.revealed = false; permission_error_label = new Gtk.Label (Utils.NO_DATA); permission_error_infobar.add_child (permission_error_label); - append (permission_error_infobar); + // append (permission_error_infobar); var grid = new Gtk.Grid () { margin_start = 12, @@ -82,52 +86,45 @@ public class Monitor.ProcessInfoView : Gtk.Box { grid.attach (separator, 0, 1, 1, 1); process_info_cpu_ram = new ProcessInfoCPURAM (); - process_info_cpu_ram.hide (); grid.attach (process_info_cpu_ram, 0, 2, 1, 1); grid.attach (process_info_io_stats, 0, 4, 1, 1); - var process_action_bar = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); - process_action_bar.margin_top = 12; - process_action_bar.valign = Gtk.Align.END; - process_action_bar.halign = Gtk.Align.END; + var process_action_bar = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) { + margin_top = 12, + margin_bottom = 12, + margin_end = 12, + valign = Gtk.Align.END, + halign = Gtk.Align.END + }; end_process_button = new Gtk.Button.with_label (_("End Process")); end_process_button.margin_end = 10; end_process_button.tooltip_markup = Granite.markup_accel_tooltip ({ "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 (Granite.STYLE_CLASS_SUGGESTED_ACTION); kill_process_button = new Gtk.Button.with_label (_("Kill Process")); kill_process_button.tooltip_markup = Granite.markup_accel_tooltip ({ "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 (Granite.STYLE_CLASS_DESTRUCTIVE_ACTION); process_action_bar.append (end_process_button); process_action_bar.append (kill_process_button); - // preventor = new Preventor (process_action_bar, "process_action_bar"); + append (grid); + append (process_action_bar); + kill_process_button.clicked.connect (() => { - // preventor.set_prevention (_("Confirm kill of the process?")); - // preventor.confirmed.connect ((is_confirmed) => { - // if (is_confirmed) process.kill (); // maybe add a toast that process killed - // }); + process.kill (); // maybe add a toast that process killed }); end_process_button.clicked.connect (() => { - // preventor.set_prevention (_("Confirm end of the process?")); - // preventor.confirmed.connect ((is_confirmed) => { - // if (is_confirmed) process.end (); // maybe add a toast that process ended - // }); + process.end (); // maybe add a toast that process ended }); - // grid.attach (preventor, 0, 5, 1, 1); - - process_info_cpu_ram.hide (); - process_info_io_stats.hide (); - // preventor.hide (); } private void show_permission_error_infobar (string error) { @@ -144,7 +141,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.set_visible (true); } } diff --git a/src/Views/ProcessView/ProcessView.vala b/src/Views/ProcessView/ProcessView.vala index 223c6078..637acd90 100644 --- a/src/Views/ProcessView/ProcessView.vala +++ b/src/Views/ProcessView/ProcessView.vala @@ -9,7 +9,7 @@ public class Monitor.ProcessView : Gtk.Box { // hide on startup // process_info_view.no_show_all = true; - treeview_model = TreeViewModel.get_default (); + treeview_model = TreeViewModel.get_default (); process_tree_view = new CPUProcessTreeView (treeview_model); process_tree_view.process_selected.connect ((process) => on_process_selected (process)); @@ -22,7 +22,8 @@ public class Monitor.ProcessView : Gtk.Box { paned.set_start_child (process_tree_view_scrolled); paned.set_end_child (process_info_view); paned.set_shrink_end_child (false); - paned.set_position (paned.max_position); + paned.set_resize_end_child (false); + paned.set_position (paned.max_position - 200); paned.set_hexpand (true); append (paned); diff --git a/src/Widgets/Headerbar/Search.vala b/src/Widgets/Headerbar/Search.vala index bef2767d..9ec42b62 100644 --- a/src/Widgets/Headerbar/Search.vala +++ b/src/Widgets/Headerbar/Search.vala @@ -15,7 +15,7 @@ public class Monitor.Search : Gtk.Box { // process_tree_view.set_model (filter_model); var sort_model = new Gtk.TreeModelSort.with_model (filter_model); - process_tree_view.set_model (sort_model); + // process_tree_view.set_model (sort_model); append (search_entry); } diff --git a/src/meson.build b/src/meson.build index 4c90de17..beb1a0f9 100644 --- a/src/meson.build +++ b/src/meson.build @@ -27,7 +27,7 @@ source_app_files = [ 'Views/ContainerView/ContainerInfoView/ContainerInfoCharts.vala', # Widgets related only to ProcessInfoView - # 'Views/ProcessView/ProcessInfoView/Preventor.vala', + 'Views/ProcessView/ProcessInfoView/Preventor.vala', 'Views/ProcessView/ProcessInfoView/ProcessInfoHeader.vala', 'Views/ProcessView/ProcessInfoView/ProcessInfoCPURAM.vala', 'Views/ProcessView/ProcessInfoView/ProcessInfoIOStats.vala',