| 1 | /* Procman - main window |
| 2 | * Copyright (C) 2001 Kevin Vandersloot |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version 2 |
| 7 | * of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Library General Public |
| 15 | * License along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | |
| 20 | #include <config.h> |
| 21 | |
| 22 | #include <glib/gi18n.h> |
| 23 | #include <gtk/gtk.h> |
| 24 | #include <adwaita.h> |
| 25 | #include <sys/types.h> |
| 26 | #include <sys/stat.h> |
| 27 | #include <unistd.h> |
| 28 | #include <string.h> |
| 29 | #include <signal.h> |
| 30 | #include <gdk/gdkkeysyms.h> |
| 31 | #include <math.h> |
| 32 | |
| 33 | #include "interface.h" |
| 34 | #include "application.h" |
| 35 | #include "procinfo.h" |
| 36 | #include "proctable.h" |
| 37 | #include "procactions.h" |
| 38 | #include "procdialogs.h" |
| 39 | #include "setaffinity.h" |
| 40 | #include "memmaps.h" |
| 41 | #include "openfiles.h" |
| 42 | #include "procproperties.h" |
| 43 | #include "load-graph.h" |
| 44 | #include "util.h" |
| 45 | #include "disks.h" |
| 46 | #include "settings-keys.h" |
| 47 | #include "legacy/gsm_color_button.h" |
| 48 | |
| 49 | static void |
| 50 | search_text_changed (GtkEditable*, |
| 51 | gpointer data) |
| 52 | { |
| 53 | GsmApplication * const app = static_cast<GsmApplication *>(data); |
| 54 | |
| 55 | gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (gtk_tree_model_sort_get_model ( |
| 56 | GTK_TREE_MODEL_SORT (gtk_tree_view_get_model ( |
| 57 | GTK_TREE_VIEW (app->tree)))))); |
| 58 | proctable_refresh_summary_headers(app); |
| 59 | } |
| 60 | |
| 61 | /* |
| 62 | static void |
| 63 | set_affinity_visiblity (GtkWidget *widget, |
| 64 | gpointer user_data) |
| 65 | { |
| 66 | #ifndef __linux__ |
| 67 | GtkMenuItem *item = GTK_MENU_ITEM (widget); |
| 68 | const gchar *name = gtk_menu_item_get_label (item); |
| 69 | |
| 70 | if (strcmp (name, "Set _Affinity") == 0) |
| 71 | gtk_widget_set_visible (widget, false); |
| 72 | #endif |
| 73 | }*/ |
| 74 | |
| 75 | static void |
| 76 | create_proc_view (GsmApplication *app, |
| 77 | GtkBuilder *builder) |
| 78 | { |
| 79 | GsmTreeView *proctree; |
| 80 | GtkWidget *scrolled; |
| 81 | |
| 82 | proctree = proctable_new (app); |
| 83 | scrolled = GTK_WIDGET (gtk_builder_get_object (builder, "processes_scrolled")); |
| 84 | |
| 85 | gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolled), GTK_WIDGET (proctree)); |
| 86 | |
| 87 | app->proc_actionbar_revealer = GTK_REVEALER (gtk_builder_get_object (builder, "proc_actionbar_revealer")); |
| 88 | |
| 89 | /* create popover_menu for the processes tab */ |
| 90 | GMenuModel *menu_model = G_MENU_MODEL (gtk_builder_get_object (builder, "process-popup-menu")); |
| 91 | |
| 92 | app->proc_popover_menu = GTK_POPOVER (gtk_popover_menu_new_from_model (menu_model)); |
| 93 | gtk_popover_set_has_arrow (app->proc_popover_menu, FALSE); |
| 94 | gtk_popover_set_default_widget (app->proc_popover_menu, GTK_WIDGET (scrolled)); |
| 95 | gtk_widget_set_parent (GTK_WIDGET (app->proc_popover_menu), GTK_WIDGET (scrolled)); |
| 96 | |
| 97 | app->end_process_button = GTK_BUTTON (gtk_builder_get_object (builder, "end_process_button")); |
| 98 | app->search_button = GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "search_button")); |
| 99 | app->search_bar = GTK_SEARCH_BAR (gtk_builder_get_object (builder, "proc_searchbar")); |
| 100 | app->search_entry = GTK_SEARCH_ENTRY (gtk_builder_get_object (builder, "proc_searchentry")); |
| 101 | |
| 102 | gtk_search_bar_set_key_capture_widget (app->search_bar, GTK_WIDGET (app->main_window)); |
| 103 | |
| 104 | g_signal_connect (app->search_entry, |
| 105 | "changed", |
| 106 | G_CALLBACK (search_text_changed), |
| 107 | app); |
| 108 | } |
| 109 | |
| 110 | static void |
| 111 | cb_cpu_color_changed (GsmColorButton *cp, |
| 112 | gpointer data) |
| 113 | { |
| 114 | guint cpu_i = GPOINTER_TO_UINT (data); |
| 115 | auto settings = Gio::Settings::create (GSM_GSETTINGS_SCHEMA); |
| 116 | |
| 117 | /* Get current values */ |
| 118 | GVariant *cpu_colors_var = g_settings_get_value (settings->gobj (), GSM_SETTING_CPU_COLORS); |
| 119 | gsize children_n = g_variant_n_children (cpu_colors_var); |
| 120 | |
| 121 | /* Create builder to construct new setting with updated value for cpu i */ |
| 122 | GVariantBuilder builder; |
| 123 | |
| 124 | g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); |
| 125 | |
| 126 | for (guint i = 0; i < children_n; i++) |
| 127 | { |
| 128 | if (cpu_i == i) |
| 129 | { |
| 130 | gchar *color; |
| 131 | GdkRGBA button_color; |
| 132 | gsm_color_button_get_color (cp, &button_color); |
| 133 | color = gdk_rgba_to_string (&button_color); |
| 134 | g_variant_builder_add (&builder, "(us)", i, color); |
| 135 | g_free (color); |
| 136 | } |
| 137 | else |
| 138 | { |
| 139 | g_variant_builder_add_value (&builder, |
| 140 | g_variant_get_child_value (cpu_colors_var, i)); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | /* Just set the value and let the changed::cpu-colors signal callback do the rest. */ |
| 145 | settings->set_value (GSM_SETTING_CPU_COLORS, Glib::wrap (g_variant_builder_end (&builder))); |
| 146 | } |
| 147 | |
| 148 | static void |
| 149 | change_settings_color (Gio::Settings& settings, |
| 150 | const char *key, |
| 151 | GsmColorButton *cp) |
| 152 | { |
| 153 | GdkRGBA c; |
| 154 | char *color; |
| 155 | |
| 156 | gsm_color_button_get_color (cp, &c); |
| 157 | color = gdk_rgba_to_string (&c); |
| 158 | settings.set_string (key, color); |
| 159 | g_free (color); |
| 160 | } |
| 161 | |
| 162 | static void |
| 163 | cb_mem_color_changed (GsmColorButton *cp, |
| 164 | gpointer data) |
| 165 | { |
| 166 | GsmApplication *app = (GsmApplication *) data; |
| 167 | |
| 168 | change_settings_color (*app->settings.operator-> (), GSM_SETTING_MEM_COLOR, cp); |
| 169 | } |
| 170 | |
| 171 | |
| 172 | static void |
| 173 | cb_swap_color_changed (GsmColorButton *cp, |
| 174 | gpointer data) |
| 175 | { |
| 176 | GsmApplication *app = (GsmApplication *) data; |
| 177 | |
| 178 | change_settings_color (*app->settings.operator-> (), GSM_SETTING_SWAP_COLOR, cp); |
| 179 | } |
| 180 | |
| 181 | static void |
| 182 | cb_net_in_color_changed (GsmColorButton *cp, |
| 183 | gpointer data) |
| 184 | { |
| 185 | GsmApplication *app = (GsmApplication *) data; |
| 186 | |
| 187 | change_settings_color (*app->settings.operator-> (), GSM_SETTING_NET_IN_COLOR, cp); |
| 188 | } |
| 189 | |
| 190 | static void |
| 191 | cb_net_out_color_changed (GsmColorButton *cp, |
| 192 | gpointer data) |
| 193 | { |
| 194 | GsmApplication *app = (GsmApplication *) data; |
| 195 | |
| 196 | change_settings_color (*app->settings.operator-> (), GSM_SETTING_NET_OUT_COLOR, cp); |
| 197 | } |
| 198 | |
| 199 | static void |
| 200 | cb_disk_read_color_changed (GsmColorButton *cp, |
| 201 | gpointer data) |
| 202 | { |
| 203 | GsmApplication *app = (GsmApplication *) data; |
| 204 | |
| 205 | change_settings_color (*app->settings.operator-> (), GSM_SETTING_DISK_READ_COLOR, cp); |
| 206 | } |
| 207 | |
| 208 | static void |
| 209 | cb_disk_write_color_changed (GsmColorButton *cp, |
| 210 | gpointer data) |
| 211 | { |
| 212 | GsmApplication *app = (GsmApplication *) data; |
| 213 | |
| 214 | change_settings_color (*app->settings.operator-> (), GSM_SETTING_DISK_WRITE_COLOR, cp); |
| 215 | } |
| 216 | |
| 217 | static void |
| 218 | create_sys_view (GsmApplication *app, |
| 219 | GtkBuilder *builder) |
| 220 | { |
| 221 | GtkBox *cpu_graph_box, *mem_graph_box, *net_graph_box, *disk_graph_box; |
| 222 | GtkExpander *cpu_expander, *mem_expander, *net_expander, *disk_expander; |
| 223 | GtkLabel *label, *cpu_label; |
| 224 | GtkGrid *table; |
| 225 | GsmColorButton *color_picker; |
| 226 | |
| 227 | LoadGraph *cpu_graph, *mem_graph, *net_graph, *disk_graph; |
| 228 | |
| 229 | gint i; |
| 230 | gchar *title_text; |
| 231 | gchar *label_text; |
| 232 | gchar *title_template; |
| 233 | |
| 234 | // Translators: color picker title, %s is CPU, Memory, Swap, Receiving, Sending |
| 235 | title_template = g_strdup (_("Pick a Color for “%s”")); |
| 236 | |
| 237 | /* The CPU BOX */ |
| 238 | |
| 239 | cpu_graph_box = GTK_BOX (gtk_builder_get_object (builder, "cpu_graph_box")); |
| 240 | cpu_expander = GTK_EXPANDER (gtk_builder_get_object (builder, "cpu_expander")); |
| 241 | g_object_bind_property (cpu_expander, "expanded", cpu_expander, "vexpand", G_BINDING_DEFAULT); |
| 242 | g_settings_bind (app->settings->gobj (), GSM_SETTING_RESOURCES_CPU_EXPANDED, G_OBJECT (cpu_expander), "expanded", G_SETTINGS_BIND_DEFAULT); |
| 243 | |
| 244 | cpu_graph = new LoadGraph (LOAD_GRAPH_CPU); |
| 245 | gtk_widget_set_size_request (GTK_WIDGET (load_graph_get_widget (cpu_graph)), -1, 70); |
| 246 | gtk_box_prepend (cpu_graph_box, |
| 247 | GTK_WIDGET (load_graph_get_widget (cpu_graph))); |
| 248 | |
| 249 | GtkGrid*cpu_table = GTK_GRID (gtk_builder_get_object (builder, "cpu_table")); |
| 250 | gint cols = 4 + app->config.num_cpus / 32; |
| 251 | gint rows = (app->config.num_cpus + cols - 1) / cols; |
| 252 | |
| 253 | for (i = 0; i < app->config.num_cpus; i++) |
| 254 | { |
| 255 | GtkBox *temp_hbox; |
| 256 | |
| 257 | temp_hbox = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0)); |
| 258 | gtk_box_set_spacing (temp_hbox, 4); |
| 259 | if (i < cols) |
| 260 | gtk_grid_insert_column (cpu_table, i % cols); |
| 261 | if ((i + 1) % cols == cols) |
| 262 | gtk_grid_insert_row (cpu_table, (i + 1) / cols); |
| 263 | gtk_grid_attach (cpu_table, GTK_WIDGET (temp_hbox), i / rows, i % rows, 1, 1); |
| 264 | |
| 265 | color_picker = gsm_color_button_new (&cpu_graph->colors.at (i), GSMCP_TYPE_CPU); |
| 266 | g_signal_connect (G_OBJECT (color_picker), "color-set", |
| 267 | G_CALLBACK (cb_cpu_color_changed), GINT_TO_POINTER (i)); |
| 268 | gtk_box_append (temp_hbox, GTK_WIDGET (color_picker)); |
| 269 | gtk_widget_set_size_request (GTK_WIDGET (color_picker), 32, -1); |
| 270 | |
| 271 | if (app->config.num_cpus == 1) |
| 272 | label_text = g_strdup (_("CPU")); |
| 273 | else |
| 274 | label_text = g_strdup_printf (_("CPU%d"), i + 1); |
| 275 | title_text = g_strdup_printf (title_template, label_text); |
| 276 | label = GTK_LABEL (gtk_label_new (label_text)); |
| 277 | if (app->config.num_cpus >= 10) |
| 278 | gtk_label_set_width_chars (label, log10 (app->config.num_cpus) + 1 + 4); |
| 279 | gsm_color_button_set_title (color_picker, title_text); |
| 280 | g_free (title_text); |
| 281 | gtk_box_append (temp_hbox, GTK_WIDGET (label)); |
| 282 | g_free (label_text); |
| 283 | |
| 284 | cpu_label = make_tnum_label (); |
| 285 | |
| 286 | /* Reserve some space to avoid the layout changing with the values. */ |
| 287 | gtk_label_set_width_chars (cpu_label, 6); |
| 288 | gtk_box_append (temp_hbox, GTK_WIDGET (cpu_label)); |
| 289 | load_graph_get_labels (cpu_graph)->cpu[i] = cpu_label; |
| 290 | } |
| 291 | |
| 292 | app->cpu_graph = cpu_graph; |
| 293 | |
| 294 | /** The memory box */ |
| 295 | |
| 296 | mem_graph_box = GTK_BOX (gtk_builder_get_object (builder, "mem_graph_box")); |
| 297 | mem_expander = GTK_EXPANDER (gtk_builder_get_object (builder, "mem_expander")); |
| 298 | g_object_bind_property (mem_expander, "expanded", mem_expander, "vexpand", G_BINDING_DEFAULT); |
| 299 | g_settings_bind (app->settings->gobj (), GSM_SETTING_RESOURCES_MEM_EXPANDED, G_OBJECT (mem_expander), "expanded", G_SETTINGS_BIND_DEFAULT); |
| 300 | |
| 301 | mem_graph = new LoadGraph (LOAD_GRAPH_MEM); |
| 302 | gtk_widget_set_size_request (GTK_WIDGET (load_graph_get_widget (mem_graph)), -1, 70); |
| 303 | gtk_box_prepend (mem_graph_box, |
| 304 | GTK_WIDGET (load_graph_get_widget (mem_graph))); |
| 305 | |
| 306 | table = GTK_GRID (gtk_builder_get_object (builder, "mem_table")); |
| 307 | |
| 308 | color_picker = load_graph_get_mem_color_picker (mem_graph); |
| 309 | g_signal_connect (G_OBJECT (color_picker), "color-set", |
| 310 | G_CALLBACK (cb_mem_color_changed), app); |
| 311 | title_text = g_strdup_printf (title_template, _("Memory")); |
| 312 | gsm_color_button_set_title (color_picker, title_text); |
| 313 | g_free (title_text); |
| 314 | |
| 315 | label = GTK_LABEL (gtk_builder_get_object (builder, "memory_label")); |
| 316 | |
| 317 | gtk_grid_attach_next_to (table, GTK_WIDGET (color_picker), GTK_WIDGET (label), GTK_POS_LEFT, 1, 3); |
| 318 | gtk_grid_attach_next_to (table, GTK_WIDGET (load_graph_get_labels (mem_graph)->memory), GTK_WIDGET (label), GTK_POS_BOTTOM, 1, 2); |
| 319 | |
| 320 | color_picker = load_graph_get_swap_color_picker (mem_graph); |
| 321 | g_signal_connect (G_OBJECT (color_picker), "color-set", |
| 322 | G_CALLBACK (cb_swap_color_changed), app); |
| 323 | title_text = g_strdup_printf (title_template, _("Swap")); |
| 324 | gsm_color_button_set_title (GSM_COLOR_BUTTON (color_picker), title_text); |
| 325 | g_free (title_text); |
| 326 | |
| 327 | label = GTK_LABEL (gtk_builder_get_object (builder, "swap_label")); |
| 328 | |
| 329 | gtk_grid_attach_next_to (table, GTK_WIDGET (color_picker), GTK_WIDGET (label), GTK_POS_LEFT, 1, 3); |
| 330 | gtk_grid_attach_next_to (table, GTK_WIDGET (load_graph_get_labels (mem_graph)->swap), GTK_WIDGET (label), GTK_POS_BOTTOM, 1, 2); |
| 331 | |
| 332 | app->mem_graph = mem_graph; |
| 333 | |
| 334 | /* The net box */ |
| 335 | |
| 336 | net_graph_box = GTK_BOX (gtk_builder_get_object (builder, "net_graph_box")); |
| 337 | net_expander = GTK_EXPANDER (gtk_builder_get_object (builder, "net_expander")); |
| 338 | g_object_bind_property (net_expander, "expanded", net_expander, "vexpand", G_BINDING_DEFAULT); |
| 339 | g_settings_bind (app->settings->gobj (), GSM_SETTING_RESOURCES_NET_EXPANDED, G_OBJECT (net_expander), "expanded", G_SETTINGS_BIND_DEFAULT); |
| 340 | |
| 341 | net_graph = new LoadGraph (LOAD_GRAPH_NET); |
| 342 | gtk_widget_set_size_request (GTK_WIDGET (load_graph_get_widget (net_graph)), -1, 70); |
| 343 | gtk_box_prepend (net_graph_box, |
| 344 | GTK_WIDGET (load_graph_get_widget (net_graph))); |
| 345 | |
| 346 | table = GTK_GRID (gtk_builder_get_object (builder, "net_table")); |
| 347 | |
| 348 | color_picker = gsm_color_button_new ( |
| 349 | &net_graph->colors.at (0), GSMCP_TYPE_NETWORK_IN); |
| 350 | gtk_widget_set_valign (GTK_WIDGET (color_picker), GTK_ALIGN_CENTER); |
| 351 | g_signal_connect (G_OBJECT (color_picker), "color-set", |
| 352 | G_CALLBACK (cb_net_in_color_changed), app); |
| 353 | title_text = g_strdup_printf (title_template, _("Receiving")); |
| 354 | gsm_color_button_set_title (color_picker, title_text); |
| 355 | g_free (title_text); |
| 356 | |
| 357 | label = GTK_LABEL (gtk_builder_get_object (builder, "receiving_label")); |
| 358 | gtk_grid_attach_next_to (table, GTK_WIDGET (color_picker), GTK_WIDGET (label), GTK_POS_LEFT, 1, 2); |
| 359 | gtk_grid_attach_next_to (table, GTK_WIDGET (load_graph_get_labels (net_graph)->net_in), GTK_WIDGET (label), GTK_POS_RIGHT, 1, 1); |
| 360 | label = GTK_LABEL (gtk_builder_get_object (builder, "total_received_label")); |
| 361 | gtk_grid_attach_next_to (table, GTK_WIDGET (load_graph_get_labels (net_graph)->net_in_total), GTK_WIDGET (label), GTK_POS_RIGHT, 1, 1); |
| 362 | |
| 363 | color_picker = gsm_color_button_new ( |
| 364 | &net_graph->colors.at (1), GSMCP_TYPE_NETWORK_OUT); |
| 365 | gtk_widget_set_valign (GTK_WIDGET (color_picker), GTK_ALIGN_CENTER); |
| 366 | gtk_widget_set_hexpand (GTK_WIDGET (color_picker), true); |
| 367 | gtk_widget_set_halign (GTK_WIDGET (color_picker), GTK_ALIGN_END); |
| 368 | |
| 369 | g_signal_connect (G_OBJECT (color_picker), "color-set", |
| 370 | G_CALLBACK (cb_net_out_color_changed), app); |
| 371 | title_text = g_strdup_printf (title_template, _("Sending")); |
| 372 | gsm_color_button_set_title (color_picker, title_text); |
| 373 | g_free (title_text); |
| 374 | |
| 375 | label = GTK_LABEL (gtk_builder_get_object (builder, "sending_label")); |
| 376 | gtk_grid_attach_next_to (table, GTK_WIDGET (color_picker), GTK_WIDGET (label), GTK_POS_LEFT, 1, 2); |
| 377 | gtk_grid_attach_next_to (table, GTK_WIDGET (load_graph_get_labels (net_graph)->net_out), GTK_WIDGET (label), GTK_POS_RIGHT, 1, 1); |
| 378 | label = GTK_LABEL (gtk_builder_get_object (builder, "total_sent_label")); |
| 379 | gtk_grid_attach_next_to (table, GTK_WIDGET (load_graph_get_labels (net_graph)->net_out_total), GTK_WIDGET (label), GTK_POS_RIGHT, 1, 1); |
| 380 | gtk_widget_set_hexpand (GTK_WIDGET (load_graph_get_labels (net_graph)->net_out_total), true); |
| 381 | gtk_widget_set_halign (GTK_WIDGET (load_graph_get_labels (net_graph)->net_out_total), GTK_ALIGN_START); |
| 382 | |
| 383 | gtk_widget_set_hexpand (GTK_WIDGET (load_graph_get_labels (net_graph)->net_out), true); |
| 384 | gtk_widget_set_halign (GTK_WIDGET (load_graph_get_labels (net_graph)->net_out), GTK_ALIGN_START); |
| 385 | |
| 386 | app->net_graph = net_graph; |
| 387 | |
| 388 | /* The disk box */ |
| 389 | |
| 390 | disk_graph_box = GTK_BOX (gtk_builder_get_object (builder, "disk_graph_box")); |
| 391 | disk_expander = GTK_EXPANDER (gtk_builder_get_object (builder, "disk_expander")); |
| 392 | g_object_bind_property (disk_expander, "expanded", disk_expander, "vexpand", G_BINDING_DEFAULT); |
| 393 | g_settings_bind (app->settings->gobj (), GSM_SETTING_RESOURCES_DISK_EXPANDED, G_OBJECT (disk_expander), "expanded", G_SETTINGS_BIND_DEFAULT); |
| 394 | |
| 395 | disk_graph = new LoadGraph (LOAD_GRAPH_DISK); |
| 396 | gtk_widget_set_size_request (GTK_WIDGET (load_graph_get_widget (disk_graph)), -1, 70); |
| 397 | gtk_box_prepend (disk_graph_box, |
| 398 | GTK_WIDGET (load_graph_get_widget (disk_graph))); |
| 399 | |
| 400 | table = GTK_GRID (gtk_builder_get_object (builder, "disk_table")); |
| 401 | |
| 402 | color_picker = gsm_color_button_new ( |
| 403 | &disk_graph->colors.at (0), GSMCP_TYPE_DISK_READ); |
| 404 | gtk_widget_set_valign (GTK_WIDGET (color_picker), GTK_ALIGN_CENTER); |
| 405 | g_signal_connect (G_OBJECT (color_picker), "color-set", |
| 406 | G_CALLBACK (cb_disk_read_color_changed), app); |
| 407 | title_text = g_strdup_printf (title_template, _("Reading")); |
| 408 | gsm_color_button_set_title (color_picker, title_text); |
| 409 | g_free (title_text); |
| 410 | |
| 411 | label = GTK_LABEL (gtk_builder_get_object (builder, "reading_label")); |
| 412 | gtk_grid_attach_next_to (table, GTK_WIDGET (color_picker), GTK_WIDGET (label), GTK_POS_LEFT, 1, 2); |
| 413 | gtk_grid_attach_next_to (table, GTK_WIDGET (load_graph_get_labels (disk_graph)->disk_read), GTK_WIDGET (label), GTK_POS_RIGHT, 1, 1); |
| 414 | label = GTK_LABEL (gtk_builder_get_object (builder, "total_read_label")); |
| 415 | gtk_grid_attach_next_to (table, GTK_WIDGET (load_graph_get_labels (disk_graph)->disk_read_total), GTK_WIDGET (label), GTK_POS_RIGHT, 1, 1); |
| 416 | |
| 417 | color_picker = gsm_color_button_new ( |
| 418 | &disk_graph->colors.at (1), GSMCP_TYPE_DISK_WRITE); |
| 419 | gtk_widget_set_valign (GTK_WIDGET (color_picker), GTK_ALIGN_CENTER); |
| 420 | gtk_widget_set_hexpand (GTK_WIDGET (color_picker), true); |
| 421 | gtk_widget_set_halign (GTK_WIDGET (color_picker), GTK_ALIGN_END); |
| 422 | |
| 423 | g_signal_connect (G_OBJECT (color_picker), "color-set", |
| 424 | G_CALLBACK (cb_disk_write_color_changed), app); |
| 425 | title_text = g_strdup_printf (title_template, _("Writing")); |
| 426 | gsm_color_button_set_title (color_picker, title_text); |
| 427 | g_free (title_text); |
| 428 | |
| 429 | label = GTK_LABEL (gtk_builder_get_object (builder, "writing_label")); |
| 430 | gtk_grid_attach_next_to (table, GTK_WIDGET (color_picker), GTK_WIDGET (label), GTK_POS_LEFT, 1, 2); |
| 431 | gtk_grid_attach_next_to (table, GTK_WIDGET (load_graph_get_labels (disk_graph)->disk_write), GTK_WIDGET (label), GTK_POS_RIGHT, 1, 1); |
| 432 | label = GTK_LABEL (gtk_builder_get_object (builder, "total_written_label")); |
| 433 | gtk_grid_attach_next_to (table, GTK_WIDGET (load_graph_get_labels (disk_graph)->disk_write_total), GTK_WIDGET (label), GTK_POS_RIGHT, 1, 1); |
| 434 | gtk_widget_set_hexpand (GTK_WIDGET (load_graph_get_labels (disk_graph)->disk_write_total), true); |
| 435 | gtk_widget_set_halign (GTK_WIDGET (load_graph_get_labels (disk_graph)->disk_write_total), GTK_ALIGN_START); |
| 436 | |
| 437 | gtk_widget_set_hexpand (GTK_WIDGET (load_graph_get_labels (disk_graph)->disk_write), true); |
| 438 | gtk_widget_set_halign (GTK_WIDGET (load_graph_get_labels (disk_graph)->disk_write), GTK_ALIGN_START); |
| 439 | |
| 440 | app->disk_graph = disk_graph; |
| 441 | g_free (title_template); |
| 442 | } |
| 443 | |
| 444 | static void |
| 445 | on_activate_about (GSimpleAction *, |
| 446 | GVariant *, |
| 447 | gpointer data) |
| 448 | { |
| 449 | GsmApplication *app = (GsmApplication *) data; |
| 450 | AdwDialog *about_dialog; |
| 451 | |
| 452 | const gchar *authors[] = { |
| 453 | "Kevin Vandersloot", |
| 454 | "Erik Johnsson", |
| 455 | "Jorgen Scheibengruber", |
| 456 | "Benoît Dejean", |
| 457 | "Paolo Borelli", |
| 458 | "Karl Lattimer", |
| 459 | "Chris Kühl", |
| 460 | "Robert Roth", |
| 461 | "Stefano Facchini", |
| 462 | "Jacob Barkdull", |
| 463 | "Ondřej Míchal", |
| 464 | NULL |
| 465 | }; |
| 466 | |
| 467 | const gchar *documenters[] = { |
| 468 | "Bill Day", |
| 469 | "Sun Microsystems", |
| 470 | NULL |
| 471 | }; |
| 472 | |
| 473 | const gchar *artists[] = { |
| 474 | "Baptiste Mille-Mathias", |
| 475 | NULL |
| 476 | }; |
| 477 | |
| 478 | about_dialog = adw_about_dialog_new_from_appdata ("/org/gnome/gnome-system-monitor/metainfo.xml", |
| 479 | VERSION); |
| 480 | |
| 481 | adw_about_dialog_set_copyright (ADW_ABOUT_DIALOG (about_dialog), |
| 482 | "Copyright \xc2\xa9 2001-2004 Kevin Vandersloot\n" |
| 483 | "Copyright \xc2\xa9 2005-2007 Benoît Dejean\n" |
| 484 | "Copyright \xc2\xa9 2011 Chris Kühl"); |
| 485 | adw_about_dialog_set_developers (ADW_ABOUT_DIALOG (about_dialog), authors); |
| 486 | adw_about_dialog_set_artists (ADW_ABOUT_DIALOG (about_dialog), artists); |
| 487 | adw_about_dialog_set_documenters (ADW_ABOUT_DIALOG (about_dialog), documenters); |
| 488 | adw_about_dialog_set_translator_credits (ADW_ABOUT_DIALOG (about_dialog), _("translator-credits")); |
| 489 | |
| 490 | adw_dialog_present (about_dialog, GTK_WIDGET (app->main_window)); |
| 491 | } |
| 492 | |
| 493 | static void |
| 494 | on_activate_keyboard_shortcuts (GSimpleAction *, |
| 495 | GVariant *, |
| 496 | gpointer data) |
| 497 | { |
| 498 | GsmApplication *app = (GsmApplication *) data; |
| 499 | GtkBuilder *builder = gtk_builder_new (); |
| 500 | GError *err = NULL; |
| 501 | AdwDialog *shortcuts_dialog; |
| 502 | |
| 503 | gtk_builder_add_from_resource (builder, "/org/gnome/gnome-system-monitor/shortcuts-dialog.ui", &err); |
| 504 | if (err != NULL) |
| 505 | g_error ("%s", err->message); |
| 506 | |
| 507 | shortcuts_dialog = ADW_DIALOG (gtk_builder_get_object (builder, "shortcuts_dialog")); |
| 508 | |
| 509 | adw_dialog_present (shortcuts_dialog, GTK_WIDGET (app->main_window)); |
| 510 | } |
| 511 | |
| 512 | static void |
| 513 | on_activate_refresh (GSimpleAction *, |
| 514 | GVariant *, |
| 515 | gpointer data) |
| 516 | { |
| 517 | GsmApplication *app = (GsmApplication *) data; |
| 518 | |
| 519 | proctable_update (app); |
| 520 | } |
| 521 | |
| 522 | static void |
| 523 | on_activate_set_affinity (GSimpleAction *, |
| 524 | GVariant *, |
| 525 | gpointer data) |
| 526 | { |
| 527 | GsmApplication *app = (GsmApplication *) data; |
| 528 | |
| 529 | create_set_affinity_dialog (app); |
| 530 | } |
| 531 | |
| 532 | static void |
| 533 | create_single_memmaps_dialog (GtkTreeModel *model, |
| 534 | GtkTreePath*, |
| 535 | GtkTreeIter *iter, |
| 536 | gpointer) |
| 537 | { |
| 538 | ProcInfo *info; |
| 539 | GsmMemMapsView *memmaps_view; |
| 540 | |
| 541 | gtk_tree_model_get (model, iter, COL_POINTER, &info, -1); |
| 542 | |
| 543 | memmaps_view = gsm_memmaps_view_new (info); |
| 544 | |
| 545 | gtk_window_present (GTK_WINDOW (memmaps_view)); |
| 546 | } |
| 547 | |
| 548 | static void |
| 549 | on_activate_memory_maps (GSimpleAction *, |
| 550 | GVariant *, |
| 551 | gpointer data) |
| 552 | { |
| 553 | GsmApplication *app = (GsmApplication *) data; |
| 554 | |
| 555 | /* TODO: do we really want to open multiple dialogs ? */ |
| 556 | gtk_tree_selection_selected_foreach (app->selection, create_single_memmaps_dialog, |
| 557 | NULL); |
| 558 | } |
| 559 | |
| 560 | |
| 561 | static void |
| 562 | create_single_openfiles_dialog (GtkTreeModel *model, |
| 563 | GtkTreePath *, |
| 564 | GtkTreeIter *iter, |
| 565 | gpointer) |
| 566 | { |
| 567 | ProcInfo *info; |
| 568 | GsmOpenFiles *open_files; |
| 569 | |
| 570 | gtk_tree_model_get (model, iter, COL_POINTER, &info, -1); |
| 571 | |
| 572 | open_files = gsm_open_files_new (GsmApplication::get().gobj(), info); |
| 573 | |
| 574 | gtk_window_present (GTK_WINDOW (open_files)); |
| 575 | } |
| 576 | |
| 577 | |
| 578 | static void |
| 579 | on_activate_open_files (GSimpleAction *, |
| 580 | GVariant *, |
| 581 | gpointer data) |
| 582 | { |
| 583 | GsmApplication *app = (GsmApplication *) data; |
| 584 | |
| 585 | gtk_tree_selection_selected_foreach (app->selection, create_single_openfiles_dialog, |
| 586 | app); |
| 587 | } |
| 588 | |
| 589 | static void |
| 590 | on_activate_process_properties (GSimpleAction *, |
| 591 | GVariant *, |
| 592 | gpointer data) |
| 593 | { |
| 594 | GsmApplication *app = (GsmApplication *) data; |
| 595 | |
| 596 | create_procproperties_dialog (app); |
| 597 | } |
| 598 | |
| 599 | static void |
| 600 | on_activate_radio (GSimpleAction *action, |
| 601 | GVariant *parameter, |
| 602 | gpointer) |
| 603 | { |
| 604 | g_action_change_state (G_ACTION (action), parameter); |
| 605 | } |
| 606 | |
| 607 | static void |
| 608 | on_activate_toggle (GSimpleAction *action, |
| 609 | GVariant*, |
| 610 | gpointer) |
| 611 | { |
| 612 | GVariant *state = g_action_get_state (G_ACTION (action)); |
| 613 | |
| 614 | g_action_change_state (G_ACTION (action), g_variant_new_boolean (!g_variant_get_boolean (state))); |
| 615 | g_variant_unref (state); |
| 616 | } |
| 617 | |
| 618 | static void |
| 619 | on_activate_search (GSimpleAction*, |
| 620 | GVariant*, |
| 621 | gpointer data) |
| 622 | { |
| 623 | GsmApplication *app = (GsmApplication *) data; |
| 624 | |
| 625 | gtk_search_bar_set_search_mode (app->search_bar, !gtk_search_bar_get_search_mode (app->search_bar)); |
| 626 | } |
| 627 | |
| 628 | static void |
| 629 | change_show_page_state (GSimpleAction *action, |
| 630 | GVariant *state, |
| 631 | gpointer data) |
| 632 | { |
| 633 | GsmApplication *app = (GsmApplication *) data; |
| 634 | |
| 635 | g_simple_action_set_state (action, state); |
| 636 | auto tab = g_variant_get_string (state, NULL); |
| 637 | app->settings->set_string (GSM_SETTING_CURRENT_TAB, tab); |
| 638 | app->config.current_tab = tab; |
| 639 | adw_view_stack_set_visible_child_name (app->stack, tab); |
| 640 | } |
| 641 | |
| 642 | static void |
| 643 | change_show_processes_state (GSimpleAction *action, |
| 644 | GVariant *state, |
| 645 | gpointer data) |
| 646 | { |
| 647 | GsmApplication *app = (GsmApplication *) data; |
| 648 | |
| 649 | auto state_var = Glib::wrap (state, true); |
| 650 | |
| 651 | g_simple_action_set_state (action, state); |
| 652 | app->settings->set_value (GSM_SETTING_SHOW_WHOSE_PROCESSES, state_var); |
| 653 | } |
| 654 | |
| 655 | static void |
| 656 | change_show_dependencies_state (GSimpleAction *action, |
| 657 | GVariant *state, |
| 658 | gpointer data) |
| 659 | { |
| 660 | GsmApplication *app = (GsmApplication *) data; |
| 661 | |
| 662 | auto state_var = Glib::wrap (state, true); |
| 663 | |
| 664 | g_simple_action_set_state (action, state); |
| 665 | app->settings->set_value (GSM_SETTING_SHOW_DEPENDENCIES, state_var); |
| 666 | } |
| 667 | |
| 668 | static void |
| 669 | on_activate_priority (GSimpleAction *action, |
| 670 | GVariant *parameter, |
| 671 | gpointer data) |
| 672 | { |
| 673 | GsmApplication *app = (GsmApplication *) data; |
| 674 | |
| 675 | g_action_change_state (G_ACTION (action), parameter); |
| 676 | |
| 677 | const gint32 priority = g_variant_get_int32 (parameter); |
| 678 | |
| 679 | switch (priority) |
| 680 | { |
| 681 | case 32: |
| 682 | procdialog_create_renice_dialog (app); |
| 683 | break; |
| 684 | |
| 685 | default: |
| 686 | renice (app, priority); |
| 687 | break; |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | static void |
| 692 | change_priority_state (GSimpleAction *action, |
| 693 | GVariant *state, |
| 694 | gpointer) |
| 695 | { |
| 696 | g_simple_action_set_state (action, state); |
| 697 | } |
| 698 | |
| 699 | static void |
| 700 | update_page_activities (GsmApplication *app) |
| 701 | { |
| 702 | const gchar *current_page = adw_view_stack_get_visible_child_name (app->stack); |
| 703 | |
| 704 | if (app->config.current_tab != current_page) |
| 705 | { |
| 706 | app->settings->set_string (GSM_SETTING_CURRENT_TAB, current_page); |
| 707 | app->config.current_tab = current_page; |
| 708 | } |
| 709 | |
| 710 | if (strcmp (current_page, "processes") == 0) |
| 711 | { |
| 712 | proctable_update (app); |
| 713 | proctable_thaw (app); |
| 714 | |
| 715 | gtk_widget_set_visible (GTK_WIDGET (app->end_process_button), TRUE); |
| 716 | gtk_widget_set_visible (GTK_WIDGET (app->search_button), TRUE); |
| 717 | |
| 718 | gtk_menu_button_set_menu_model (app->app_menu_button, app->process_window_menu_model); |
| 719 | gtk_search_bar_set_key_capture_widget (app->search_bar, GTK_WIDGET (app->main_window)); |
| 720 | |
| 721 | update_sensitivity (app); |
| 722 | |
| 723 | if (gtk_search_bar_get_search_mode (app->search_bar)) |
| 724 | gtk_widget_grab_focus (GTK_WIDGET (app->search_entry)); |
| 725 | else |
| 726 | gtk_widget_grab_focus (GTK_WIDGET (app->tree)); |
| 727 | } |
| 728 | else |
| 729 | { |
| 730 | proctable_freeze (app); |
| 731 | |
| 732 | gtk_widget_set_visible (GTK_WIDGET (app->end_process_button), FALSE); |
| 733 | gtk_widget_set_visible (GTK_WIDGET (app->search_button), FALSE); |
| 734 | |
| 735 | gtk_menu_button_set_menu_model (app->app_menu_button, app->generic_window_menu_model); |
| 736 | gtk_search_bar_set_key_capture_widget (app->search_bar, NULL); |
| 737 | |
| 738 | update_sensitivity (app); |
| 739 | } |
| 740 | |
| 741 | if (strcmp (current_page, "resources") == 0) |
| 742 | { |
| 743 | load_graph_start (app->cpu_graph); |
| 744 | load_graph_start (app->mem_graph); |
| 745 | load_graph_start (app->net_graph); |
| 746 | load_graph_start (app->disk_graph); |
| 747 | } |
| 748 | else |
| 749 | { |
| 750 | load_graph_stop (app->cpu_graph); |
| 751 | load_graph_stop (app->mem_graph); |
| 752 | load_graph_stop (app->net_graph); |
| 753 | load_graph_stop (app->disk_graph); |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | |
| 758 | static void |
| 759 | cb_change_current_page (AdwViewStack *view_stack, |
| 760 | GParamSpec*, |
| 761 | gpointer data) |
| 762 | { |
| 763 | GsmApplication *app = (GsmApplication *) data; |
| 764 | |
| 765 | if (g_strcmp0 (adw_view_stack_get_visible_child_name (view_stack), "processes") != 0) |
| 766 | gtk_toggle_button_set_active (app->search_button, FALSE); |
| 767 | |
| 768 | update_page_activities ((GsmApplication *)data); |
| 769 | } |
| 770 | |
| 771 | static gboolean |
| 772 | cb_main_window_delete (GtkWindow*, |
| 773 | gpointer data) |
| 774 | { |
| 775 | GsmApplication *app = (GsmApplication *) data; |
| 776 | |
| 777 | app->shutdown (); |
| 778 | |
| 779 | return TRUE; |
| 780 | } |
| 781 | |
| 782 | static gboolean |
| 783 | cb_main_window_close (GtkWindow*, |
| 784 | gpointer data) |
| 785 | { |
| 786 | GsmApplication *app = (GsmApplication *) data; |
| 787 | gint default_width, default_height; |
| 788 | gboolean maximized; |
| 789 | |
| 790 | g_object_get (G_OBJECT (app->main_window), "default-width", &default_width, NULL); |
| 791 | g_object_get (G_OBJECT (app->main_window), "default-height", &default_height, NULL); |
| 792 | g_object_get (G_OBJECT (app->main_window), "maximized", &maximized, NULL); |
| 793 | |
| 794 | g_settings_set_int (app->settings->gobj (), GSM_SETTING_WINDOW_WIDTH, default_width); |
| 795 | g_settings_set_int (app->settings->gobj (), GSM_SETTING_WINDOW_HEIGHT, default_height); |
| 796 | g_settings_set_boolean (app->settings->gobj (), GSM_SETTING_MAXIMIZED, maximized); |
| 797 | |
| 798 | return FALSE; |
| 799 | } |
| 800 | |
| 801 | static void |
| 802 | cb_main_window_suspended (GtkWindow *window, |
| 803 | GParamSpec *, |
| 804 | GsmApplication *app) |
| 805 | { |
| 806 | auto current_page = app->config.current_tab; |
| 807 | |
| 808 | if (gtk_window_is_suspended (window)) |
| 809 | { |
| 810 | if (current_page == "processes") |
| 811 | { |
| 812 | proctable_freeze (app); |
| 813 | } |
| 814 | else if (current_page == "resources") |
| 815 | { |
| 816 | load_graph_stop (app->cpu_graph); |
| 817 | load_graph_stop (app->mem_graph); |
| 818 | load_graph_stop (app->net_graph); |
| 819 | load_graph_stop (app->disk_graph); |
| 820 | } |
| 821 | } |
| 822 | else |
| 823 | { |
| 824 | if (current_page == "processes") |
| 825 | { |
| 826 | proctable_update (app); |
| 827 | proctable_thaw (app); |
| 828 | } |
| 829 | else if (current_page == "resources") |
| 830 | { |
| 831 | load_graph_start (app->cpu_graph); |
| 832 | load_graph_start (app->mem_graph); |
| 833 | load_graph_start (app->net_graph); |
| 834 | load_graph_start (app->disk_graph); |
| 835 | } |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | |
| 840 | void |
| 841 | create_main_window (GsmApplication *app) |
| 842 | { |
| 843 | GtkBuilder *builder = gtk_builder_new (); |
| 844 | GError *err = NULL; |
| 845 | |
| 846 | gtk_builder_add_from_resource (builder, "/org/gnome/gnome-system-monitor/data/interface.ui", &err); |
| 847 | if (err != NULL) |
| 848 | g_error ("%s", err->message); |
| 849 | gtk_builder_add_from_resource (builder, "/org/gnome/gnome-system-monitor/data/menus.ui", &err); |
| 850 | if (err != NULL) |
| 851 | g_error ("%s", err->message); |
| 852 | |
| 853 | app->main_window = ADW_APPLICATION_WINDOW (gtk_builder_get_object (builder, "main_window")); |
| 854 | gtk_window_set_application (GTK_WINDOW (app->main_window), app->gobj ()); |
| 855 | gtk_widget_set_name (GTK_WIDGET (app->main_window), "gnome-system-monitor"); |
| 856 | |
| 857 | /* create the main stack */ |
| 858 | app->stack = ADW_VIEW_STACK (gtk_builder_get_object (builder, "stack")); |
| 859 | create_proc_view (app, builder); |
| 860 | create_sys_view (app, builder); |
| 861 | app->disk_list = GSM_DISKS_VIEW (gtk_builder_get_object (builder, "disks_view")); |
| 862 | |
| 863 | app->app_menu_button = GTK_MENU_BUTTON (gtk_builder_get_object (builder, "app_menu_button")); |
| 864 | app->generic_window_menu_model = G_MENU_MODEL (gtk_builder_get_object (builder, "generic-window-menu")); |
| 865 | app->process_window_menu_model = G_MENU_MODEL (gtk_builder_get_object (builder, "process-window-menu")); |
| 866 | |
| 867 | // GtkMenuButton owns its models and thus an additional reference needs to be held |
| 868 | g_object_ref (G_OBJECT (app->generic_window_menu_model)); |
| 869 | g_object_ref (G_OBJECT (app->process_window_menu_model)); |
| 870 | |
| 871 | gtk_menu_button_set_menu_model (app->app_menu_button, app->generic_window_menu_model); |
| 872 | |
| 873 | GActionEntry win_action_entries[] = { |
| 874 | { "about", on_activate_about, NULL, NULL, NULL, { 0, 0, 0 } }, |
| 875 | { "shortcuts", on_activate_keyboard_shortcuts, NULL, NULL, NULL, { 0, 0, 0 } }, |
| 876 | { "search", on_activate_search, NULL, NULL, NULL, { 0, 0, 0 } }, |
| 877 | { "send-signal-stop", on_activate_send_signal, NULL, NULL, NULL, { 0, 0, 0 } }, |
| 878 | { "send-signal-cont", on_activate_send_signal, NULL, NULL, NULL, { 0, 0, 0 } }, |
| 879 | { "send-signal-term", on_activate_send_signal, NULL, NULL, NULL, { 0, 0, 0 } }, |
| 880 | { "send-signal-kill", on_activate_send_signal, NULL, NULL, NULL, { 0, 0, 0 } }, |
| 881 | { "priority", on_activate_priority, "i", "@i 0", change_priority_state, { 0, 0, 0 } }, |
| 882 | { "set-affinity", on_activate_set_affinity, NULL, NULL, NULL, { 0, 0, 0 } }, |
| 883 | { "memory-maps", on_activate_memory_maps, NULL, NULL, NULL, { 0, 0, 0 } }, |
| 884 | { "open-files", on_activate_open_files, NULL, NULL, NULL, { 0, 0, 0 } }, |
| 885 | { "process-properties", on_activate_process_properties, NULL, NULL, NULL, { 0, 0, 0 } }, |
| 886 | { "refresh", on_activate_refresh, NULL, NULL, NULL, { 0, 0, 0 } }, |
| 887 | { "show-page", on_activate_radio, "s", "'resources'", change_show_page_state, { 0, 0, 0 } }, |
| 888 | { "show-whose-processes", on_activate_radio, "s", "'all'", change_show_processes_state, { 0, 0, 0 } }, |
| 889 | { "show-dependencies", on_activate_toggle, NULL, "false", change_show_dependencies_state, { 0, 0, 0 } } |
| 890 | }; |
| 891 | g_action_map_add_action_entries (G_ACTION_MAP (app->main_window), |
| 892 | win_action_entries, |
| 893 | G_N_ELEMENTS (win_action_entries), |
| 894 | app); |
| 895 | |
| 896 | adw_view_stack_set_visible_child_name (ADW_VIEW_STACK (app->stack), app->config.current_tab.c_str ()); |
| 897 | |
| 898 | g_signal_connect (G_OBJECT (app->stack), |
| 899 | "notify::visible-child", |
| 900 | G_CALLBACK (cb_change_current_page), |
| 901 | app); |
| 902 | g_signal_connect (G_OBJECT (app->main_window), |
| 903 | "notify::suspended", |
| 904 | G_CALLBACK (cb_main_window_suspended), |
| 905 | app); |
| 906 | g_signal_connect (G_OBJECT (app->main_window), |
| 907 | "destroy", |
| 908 | G_CALLBACK (cb_main_window_delete), |
| 909 | app); |
| 910 | g_signal_connect (G_OBJECT (app->main_window), |
| 911 | "close-request", |
| 912 | G_CALLBACK (cb_main_window_close), |
| 913 | app); |
| 914 | |
| 915 | GAction *action; |
| 916 | |
| 917 | action = g_action_map_lookup_action (G_ACTION_MAP (app->main_window), |
| 918 | "show-dependencies"); |
| 919 | g_action_change_state (action, |
| 920 | g_settings_get_value (app->settings->gobj (), GSM_SETTING_SHOW_DEPENDENCIES)); |
| 921 | |
| 922 | |
| 923 | action = g_action_map_lookup_action (G_ACTION_MAP (app->main_window), |
| 924 | "show-whose-processes"); |
| 925 | g_action_change_state (action, |
| 926 | g_settings_get_value (app->settings->gobj (), GSM_SETTING_SHOW_WHOSE_PROCESSES)); |
| 927 | |
| 928 | // Surface is available only after a widget has been shown |
| 929 | gtk_window_present (GTK_WINDOW (app->main_window)); |
| 930 | |
| 931 | g_object_set (GTK_WINDOW (app->main_window), |
| 932 | "default-width", |
| 933 | g_settings_get_int (app->settings->gobj (), GSM_SETTING_WINDOW_WIDTH), |
| 934 | NULL); |
| 935 | |
| 936 | g_object_set (GTK_WINDOW (app->main_window), |
| 937 | "default-height", |
| 938 | g_settings_get_int (app->settings->gobj (), GSM_SETTING_WINDOW_HEIGHT), |
| 939 | NULL); |
| 940 | |
| 941 | g_object_set (GTK_WINDOW (app->main_window), |
| 942 | "maximized", |
| 943 | g_settings_get_boolean (app->settings->gobj (), GSM_SETTING_MAXIMIZED), |
| 944 | NULL); |
| 945 | |
| 946 | update_page_activities (app); |
| 947 | |
| 948 | g_object_unref (G_OBJECT (builder)); |
| 949 | } |
| 950 | |
| 951 | static gboolean |
| 952 | scroll_to_selection (gpointer data) |
| 953 | { |
| 954 | GsmApplication *app = (GsmApplication *) data; |
| 955 | GList*paths = gtk_tree_selection_get_selected_rows (app->selection, NULL); |
| 956 | guint length = g_list_length (paths); |
| 957 | |
| 958 | if (length > 0) |
| 959 | { |
| 960 | GtkTreePath*last_path = (GtkTreePath*) g_list_nth_data (paths, length - 1); |
| 961 | gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (app->tree), last_path, NULL, FALSE, 0.0, 0.0); |
| 962 | } |
| 963 | |
| 964 | g_list_free_full (paths, (GDestroyNotify) gtk_tree_path_free); |
| 965 | return FALSE; |
| 966 | } |
| 967 | |
| 968 | void |
| 969 | update_sensitivity (GsmApplication *app) |
| 970 | { |
| 971 | const char * const selected_actions[] = { "send-signal-stop", |
| 972 | "send-signal-cont", |
| 973 | "send-signal-term", |
| 974 | "send-signal-kill", |
| 975 | "priority", |
| 976 | "set-affinity", |
| 977 | "memory-maps", |
| 978 | "open-files", |
| 979 | "process-properties" }; |
| 980 | |
| 981 | const char * const processes_actions[] = { "refresh", |
| 982 | "search", |
| 983 | "show-whose-processes", |
| 984 | "show-dependencies" }; |
| 985 | |
| 986 | size_t i; |
| 987 | gboolean processes_sensitivity, selected_sensitivity; |
| 988 | GAction *action; |
| 989 | |
| 990 | processes_sensitivity = (strcmp (adw_view_stack_get_visible_child_name (app->stack), "processes") == 0); |
| 991 | selected_sensitivity = gtk_tree_selection_count_selected_rows (app->selection) > 0; |
| 992 | |
| 993 | for (i = 0; i != G_N_ELEMENTS (processes_actions); ++i) |
| 994 | { |
| 995 | action = g_action_map_lookup_action (G_ACTION_MAP (app->main_window), |
| 996 | processes_actions[i]); |
| 997 | g_simple_action_set_enabled (G_SIMPLE_ACTION (action), |
| 998 | processes_sensitivity); |
| 999 | } |
| 1000 | |
| 1001 | for (i = 0; i != G_N_ELEMENTS (selected_actions); ++i) |
| 1002 | { |
| 1003 | action = g_action_map_lookup_action (G_ACTION_MAP (app->main_window), |
| 1004 | selected_actions[i]); |
| 1005 | g_simple_action_set_enabled (G_SIMPLE_ACTION (action), |
| 1006 | processes_sensitivity & selected_sensitivity); |
| 1007 | } |
| 1008 | |
| 1009 | gtk_revealer_set_reveal_child (GTK_REVEALER (app->proc_actionbar_revealer), |
| 1010 | selected_sensitivity); |
| 1011 | |
| 1012 | // Scrolls the table to selected row. Useful when the last row is obstructed by the revealer |
| 1013 | guint duration_ms = gtk_revealer_get_transition_duration (GTK_REVEALER (app->proc_actionbar_revealer)); |
| 1014 | |
| 1015 | g_timeout_add (duration_ms, scroll_to_selection, app); |
| 1016 | } |