Skip to content

Commit

Permalink
Add top_name_verbose option
Browse files Browse the repository at this point in the history
Since commit 749083a, the output of ${top name <num>} contains the full
command line of each process, including arguments. While this feature can
be very useful, it changes the default behavior of Conky.

The present commit adds a new top_name_verbose option that allows the user
to toggle between basenames with no arguments (the old behavior) and full
command lines with arguments. To remain consistent with past versions of
Conky, the default value of top_name_verbose is false.

Fixes #113 (#113).
  • Loading branch information
marcpayne committed Jul 20, 2015
1 parent 9ac60dc commit 06722e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 11 additions & 0 deletions doc/config_settings.xml
Expand Up @@ -959,6 +959,17 @@
of all processors' power combined.
<para /></listitem>
</varlistentry>
<varlistentry>
<term>
<command>
<option>top_name_verbose</option>
</command>
</term>
<listitem>If true, top name shows the full command line of each
process, including arguments (whenever possible). Otherwise,
only the basename is displayed. Default value is false.
<para /></listitem>
</varlistentry>
<varlistentry>
<term>
<command>
Expand Down
9 changes: 8 additions & 1 deletion src/top.cc
Expand Up @@ -32,6 +32,7 @@
#include "prioqueue.h"
#include "top.h"
#include "logging.h"
#include <string>

/* hash table size - always a power of 2 */
#define HTABSIZE 256
Expand Down Expand Up @@ -480,6 +481,7 @@ struct top_data {

static conky::range_config_setting<unsigned int> top_name_width("top_name_width", 0,
std::numeric_limits<unsigned int>::max(), 15, true);
static conky::simple_config_setting<bool> top_name_verbose("top_name_verbose", false, false);

static void print_top_name(struct text_object *obj, char *p, int p_max_size)
{
Expand All @@ -489,8 +491,13 @@ static void print_top_name(struct text_object *obj, char *p, int p_max_size)
if (!td || !td->list || !td->list[td->num])
return;

std::string top_name = td->list[td->num]->name;
if (!top_name_verbose.get(*state)) {
top_name = top_name.substr(0, top_name.find_first_of(' '));
}

width = MIN(p_max_size, (int)top_name_width.get(*state) + 1);
snprintf(p, width + 1, "%-*s", width, td->list[td->num]->name);
snprintf(p, width + 1, "%-*s", width, top_name.c_str());
}

static void print_top_mem(struct text_object *obj, char *p, int p_max_size)
Expand Down

0 comments on commit 06722e4

Please sign in to comment.