From ea1cbf9444a57992df9091ff585cc79eeaf60e5a Mon Sep 17 00:00:00 2001 From: infirit Date: Thu, 18 Dec 2014 21:41:05 +0100 Subject: Added priority selection submenu with preset priority items Taken from GSM commit: 70ba9c1af2dbd8b74943b1a283f718d8646f087b From: Robert Roth Gnome bug: https://bugzilla.gnome.org/show_bug.cgi?id=131803 --- src/callbacks.cpp | 41 +++++++++++++++++++++++++++++++++++++---- src/callbacks.h | 2 +- src/interface.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++---- src/procman.h | 9 +++++++++ 4 files changed, 90 insertions(+), 9 deletions(-) diff --git a/src/callbacks.cpp b/src/callbacks.cpp index 8916c2e..ffded13 100644 --- a/src/callbacks.cpp +++ b/src/callbacks.cpp @@ -30,6 +30,7 @@ #include "proctable.h" #include "util.h" #include "procactions.h" +#include "procman.h" #include "procdialogs.h" #include "memmaps.h" #include "openfiles.h" @@ -82,11 +83,26 @@ cb_edit_preferences (GtkAction *action, gpointer data) void -cb_renice (GtkAction *action, gpointer data) +cb_renice (GtkAction *action, GtkRadioAction *current, gpointer data) { ProcData * const procdata = static_cast(data); - procdialog_create_renice_dialog (procdata); + gint selected = gtk_radio_action_get_current_value(current); + + if (selected == CUSTOM_PRIORITY) + { + procdialog_create_renice_dialog (procdata); + } else { + gint new_nice_value = 0; + switch (selected) { + case VERY_HIGH_PRIORITY: new_nice_value = -20; break; + case HIGH_PRIORITY: new_nice_value = -5; break; + case NORMAL_PRIORITY: new_nice_value = 0; break; + case LOW_PRIORITY: new_nice_value = 5; break; + case VERY_LOW_PRIORITY: new_nice_value = 19; break; + } + renice(procdata, new_nice_value); + } } @@ -300,8 +316,25 @@ cb_row_selected (GtkTreeSelection *selection, gpointer data) */ gtk_tree_selection_selected_foreach (procdata->selection, get_last_selected, &procdata->selected_process); - - update_sensitivity(procdata); + if (procdata->selected_process) { + gint value; + gint nice = procdata->selected_process->nice; + if (nice < -7) + value = VERY_HIGH_PRIORITY; + else if (nice < -2) + value = HIGH_PRIORITY; + else if (nice < 3) + value = NORMAL_PRIORITY; + else if (nice < 7) + value = LOW_PRIORITY; + else + value = VERY_LOW_PRIORITY; + + GtkRadioAction* normal = GTK_RADIO_ACTION(gtk_action_group_get_action(procdata->action_group, "Normal")); + + gtk_radio_action_set_current_value(normal, value); + } + update_sensitivity(procdata); } diff --git a/src/callbacks.h b/src/callbacks.h index 35e8016..5dfc134 100644 --- a/src/callbacks.h +++ b/src/callbacks.h @@ -29,7 +29,7 @@ void cb_show_memory_maps (GtkAction *action, gpointer data); void cb_show_open_files (GtkAction *action, gpointer data); void cb_show_lsof(GtkAction *action, gpointer data); -void cb_renice (GtkAction *action, gpointer data); +void cb_renice (GtkAction *action, GtkRadioAction *current, gpointer data); void cb_end_process (GtkAction *action, gpointer data); void cb_kill_process (GtkAction *action, gpointer data); void cb_edit_preferences (GtkAction *action, gpointer data); diff --git a/src/interface.cpp b/src/interface.cpp index 3561ea2..302be6b 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -68,8 +68,8 @@ static const GtkActionEntry menu_entries[] = N_("Force process to finish normally"), G_CALLBACK (cb_end_process) }, { "KillProcess", NULL, N_("_Kill Process"), "K", N_("Force process to finish immediately"), G_CALLBACK (cb_kill_process) }, - { "ChangePriority", NULL, N_("_Change Priority…"), "N", - N_("Change the order of priority of process"), G_CALLBACK (cb_renice) }, + { "ChangePriority", NULL, N_("_Change Priority"), NULL, + N_("Change the order of priority of process"), NULL }, { "Preferences", GTK_STOCK_PREFERENCES, NULL, NULL, N_("Configure the application"), G_CALLBACK (cb_edit_preferences) }, @@ -106,6 +106,22 @@ static const GtkRadioActionEntry radio_menu_entries[] = N_("Show only user-owned processes"), MY_PROCESSES } }; +static const GtkRadioActionEntry priority_menu_entries[] = +{ + { "VeryHigh", NULL, N_("Very High"), NULL, + N_("Set process priority to very high"), VERY_HIGH_PRIORITY }, + { "High", NULL, N_("High"), NULL, + N_("Set process priority to high"), HIGH_PRIORITY }, + { "Normal", NULL, N_("Normal"), NULL, + N_("Set process priority to normal"), NORMAL_PRIORITY }, + { "Low", NULL, N_("Low"), NULL, + N_("Set process priority to low"), LOW_PRIORITY }, + { "VeryLow", NULL, N_("Very Low"), NULL, + N_("Set process priority to very low"), VERY_LOW_PRIORITY }, + { "Custom", NULL, N_("Custom"), NULL, + N_("Set process priority manually"), CUSTOM_PRIORITY } +}; + static const char ui_info[] = " " @@ -120,7 +136,15 @@ static const char ui_info[] = " " " " " " -" " +" " +" " +" " +" " +" " +" " +" " +" " +" " " " " " " " @@ -148,7 +172,15 @@ static const char ui_info[] = " " " " " " -" " +" " +" " +" " +" " +" " +" " +" " +" " +" " " " " " " " @@ -710,6 +742,13 @@ create_main_window (ProcData *procdata) G_CALLBACK(cb_radio_processes), procdata); + gtk_action_group_add_radio_actions (procdata->action_group, + priority_menu_entries, + G_N_ELEMENTS (priority_menu_entries), + NORMAL_PRIORITY, + G_CALLBACK(cb_renice), + procdata); + gtk_ui_manager_insert_action_group (procdata->uimanager, procdata->action_group, 0); diff --git a/src/procman.h b/src/procman.h index 2adfb7d..5bfb7b8 100644 --- a/src/procman.h +++ b/src/procman.h @@ -49,6 +49,15 @@ enum ACTIVE_PROCESSES }; +enum +{ + VERY_HIGH_PRIORITY, + HIGH_PRIORITY, + NORMAL_PRIORITY, + LOW_PRIORITY, + VERY_LOW_PRIORITY, + CUSTOM_PRIORITY +}; static const unsigned MIN_UPDATE_INTERVAL = 1 * 1000; static const unsigned MAX_UPDATE_INTERVAL = 100 * 1000; -- cgit v1.2.1