summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorinfirit <[email protected]>2014-12-18 21:30:25 +0100
committerinfirit <[email protected]>2014-12-18 21:31:13 +0100
commit6034caada16eab3b07e090c0f2b29a1a3dd9d105 (patch)
tree8d7d47e968444258975bdd887821f7694241451d
parentad78931540508c4f3d52d938852c47086ce7b03f (diff)
downloadmate-system-monitor-6034caada16eab3b07e090c0f2b29a1a3dd9d105.tar.bz2
mate-system-monitor-6034caada16eab3b07e090c0f2b29a1a3dd9d105.tar.xz
Priority column to the process table to show user-friendly nice values
Taken from GSM commit: 6fcbf5aaa65d63dd751c812c3ac05a937b50450d From: Robert Roth <[email protected]> Gnome bug: https://bugzilla.gnome.org/show_bug.cgi?id=131802
-rw-r--r--src/org.mate.system-monitor.gschema.xml.in.in8
-rw-r--r--src/procdialogs.cpp24
-rw-r--r--src/proctable.cpp15
-rw-r--r--src/proctable.h1
-rw-r--r--src/util.cpp45
-rw-r--r--src/util.h8
6 files changed, 80 insertions, 21 deletions
diff --git a/src/org.mate.system-monitor.gschema.xml.in.in b/src/org.mate.system-monitor.gschema.xml.in.in
index 39f4f09..bc79cb5 100644
--- a/src/org.mate.system-monitor.gschema.xml.in.in
+++ b/src/org.mate.system-monitor.gschema.xml.in.in
@@ -295,6 +295,14 @@
<default>false</default>
<_summary>Show process 'Control Group' column on startup</_summary>
</key>
+ <key name="col-18-width" type="i">
+ <default>100</default>
+ <_summary>Width of process 'Priority' column</_summary>
+ </key>
+ <key name="col-18-visible" type="b">
+ <default>true</default>
+ <_summary>Show process 'Priority' column on startup</_summary>
+ </key>
</schema>
<schema gettext-domain="@GETTEXT_PACKAGE@" id="org.mate.system-monitor.disktreenew" path="/org/mate/system-monitor/disktreenew/">
<key name="sort-col" type="i">
diff --git a/src/procdialogs.cpp b/src/procdialogs.cpp
index d129bd9..c51a769 100644
--- a/src/procdialogs.cpp
+++ b/src/procdialogs.cpp
@@ -115,28 +115,15 @@ procdialog_create_kill_dialog (ProcData *procdata, int signal)
gtk_widget_show_all (kill_alert_dialog);
}
-static gchar *
-get_nice_level (gint nice)
-{
- if (nice < -7)
- return _("(Very High Priority)");
- else if (nice < -2)
- return _("(High Priority)");
- else if (nice < 3)
- return _("(Normal Priority)");
- else if (nice < 7)
- return _("(Low Priority)");
- else
- return _("(Very Low Priority)");
-}
-
static void
renice_scale_changed (GtkAdjustment *adj, gpointer data)
{
GtkWidget *label = GTK_WIDGET (data);
new_nice_value = int(gtk_adjustment_get_value (adj));
- gtk_label_set_text (GTK_LABEL (label), get_nice_level (new_nice_value));
+ gchar* text = g_strdup_printf(_("(%s Priority)"), procman::get_nice_level (new_nice_value));
+ gtk_label_set_text (GTK_LABEL (label), text);
+ g_free(text);
}
@@ -232,10 +219,11 @@ procdialog_create_renice_dialog (ProcData *procdata)
gtk_scale_set_digits (GTK_SCALE (hscale), 0);
gtk_table_attach (GTK_TABLE (table), hscale, 1, 2, 0, 1,
static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), GTK_FILL, 0, 0);
-
- priority_label = gtk_label_new (get_nice_level (info->nice));
+ text = g_strdup_printf(_("(%s Priority)"), procman::get_nice_level (info->nice));
+ priority_label = gtk_label_new (text);
gtk_table_attach (GTK_TABLE (table), priority_label, 1, 2, 1, 2,
GTK_FILL, GTK_FILL, 0, 0);
+ g_free(text);
text = g_strconcat("<small><i><b>", _("Note:"), "</b> ",
_("The priority of a process is given by its nice value. A lower nice value corresponds to a higher priority."),
diff --git a/src/proctable.cpp b/src/proctable.cpp
index f77f842..63cd572 100644
--- a/src/proctable.cpp
+++ b/src/proctable.cpp
@@ -68,7 +68,6 @@ ProcInfo* ProcInfo::find(pid_t pid)
-
static void
set_proctree_reorderable(ProcData *procdata)
{
@@ -260,6 +259,7 @@ proctable_new (ProcData * const procdata)
/* xgettext: combined noun, the function the process is waiting in, see wchan ps(1) */
N_("Waiting Channel"),
N_("Control Group"),
+ N_("Priority"),
NULL,
"POINTER"
};
@@ -290,6 +290,7 @@ proctable_new (ProcData * const procdata)
G_TYPE_ULONG, /* Memory */
G_TYPE_STRING, /* wchan */
G_TYPE_STRING, /* Cgroup */
+ G_TYPE_STRING, /* Priority */
GDK_TYPE_PIXBUF, /* Icon */
G_TYPE_POINTER, /* ProcInfo */
G_TYPE_STRING /* Sexy tooltip */
@@ -333,7 +334,7 @@ proctable_new (ProcData * const procdata)
gtk_tree_view_set_expander_column (GTK_TREE_VIEW (proctree), column);
- for (i = COL_USER; i <= COL_CGROUP; i++) {
+ for (i = COL_USER; i <= COL_PRIORITY; i++) {
GtkCellRenderer *cell;
GtkTreeViewColumn *col;
@@ -388,7 +389,15 @@ proctable_new (ProcData * const procdata)
GUINT_TO_POINTER(i),
NULL);
break;
-
+ case COL_PRIORITY:
+ gtk_tree_view_column_set_cell_data_func(col, cell,
+ &procman::priority_cell_data_func,
+ GUINT_TO_POINTER(COL_NICE),
+ NULL);
+ gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(model), i,
+ procman::priority_compare_func,
+ GUINT_TO_POINTER(COL_NICE), NULL);
+ break;
default:
gtk_tree_view_column_set_attributes(col, cell, "text", i, NULL);
break;
diff --git a/src/proctable.h b/src/proctable.h
index 0811c61..5a24803 100644
--- a/src/proctable.h
+++ b/src/proctable.h
@@ -44,6 +44,7 @@ enum
COL_MEM,
COL_WCHAN,
COL_CGROUP,
+ COL_PRIORITY,
COL_PIXBUF,
COL_POINTER,
COL_TOOLTIP,
diff --git a/src/util.cpp b/src/util.cpp
index 97119ec..ac4405f 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -210,6 +210,20 @@ procman::format_size(guint64 size, guint64 max_size, bool want_bits)
}
}
+gchar *
+procman::get_nice_level (gint nice)
+{
+ if (nice < -7)
+ return _("Very High");
+ else if (nice < -2)
+ return _("High");
+ else if (nice < 3)
+ return _("Normal");
+ else if (nice < 7)
+ return _("Low");
+ else
+ return _("Very Low");
+}
gboolean
@@ -471,6 +485,37 @@ namespace procman
g_object_set(renderer, "text", str, NULL);
}
+ void priority_cell_data_func(GtkTreeViewColumn *, GtkCellRenderer *renderer,
+ GtkTreeModel *model, GtkTreeIter *iter,
+ gpointer user_data)
+ {
+ const guint index = GPOINTER_TO_UINT(user_data);
+
+ GValue value = { 0 };
+
+ gtk_tree_model_get_value(model, iter, index, &value);
+
+ gint priority = g_value_get_int(&value);
+
+ g_value_unset(&value);
+
+ g_object_set(renderer, "text", procman::get_nice_level(priority), NULL);
+
+ }
+
+ gint priority_compare_func(GtkTreeModel* model, GtkTreeIter* first,
+ GtkTreeIter* second, gpointer user_data)
+ {
+ const guint index = GPOINTER_TO_UINT(user_data);
+ GValue value1 = { 0 };
+ GValue value2 = { 0 };
+ gtk_tree_model_get_value(model, first, index, &value1);
+ gtk_tree_model_get_value(model, second, index, &value2);
+ gint result = g_value_get_int(&value1) - g_value_get_int(&value2);
+ g_value_unset(&value1);
+ g_value_unset(&value2);
+ return result;
+ }
template<>
void tree_store_update<const char>(GtkTreeModel* model, GtkTreeIter* iter, int column, const char* new_value)
diff --git a/src/util.h b/src/util.h
index 6e989a9..8d044ce 100644
--- a/src/util.h
+++ b/src/util.h
@@ -99,6 +99,12 @@ namespace procman
void status_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
GtkTreeModel *model, GtkTreeIter *iter,
gpointer user_data);
+ void priority_cell_data_func(GtkTreeViewColumn *col, GtkCellRenderer *renderer,
+ GtkTreeModel *model, GtkTreeIter *iter,
+ gpointer user_data);
+ gint priority_compare_func(GtkTreeModel* model, GtkTreeIter* first,
+ GtkTreeIter* second, gpointer user_data);
+
template<typename T>
void poison(T &t, char c)
@@ -141,6 +147,8 @@ namespace procman
gchar* format_size(guint64 size, guint64 max = 0, bool want_bits = false);
+ gchar* get_nice_level (gint nice);
+
std::string format_rate(guint64 rate, guint64 max_rate = 0, bool want_bits = false);
std::string format_network(guint64 rate, guint64 max_rate = 0);