Apply .clang-format file
This commit is contained in:
@@ -28,7 +28,7 @@ struct _XtmAppManager
|
||||
{
|
||||
GObject parent;
|
||||
/*<private>*/
|
||||
GArray * apps;
|
||||
GArray *apps;
|
||||
};
|
||||
G_DEFINE_TYPE (XtmAppManager, xtm_app_manager, G_TYPE_OBJECT)
|
||||
|
||||
@@ -39,8 +39,8 @@ static gint app_pid_compare_fn (gconstpointer a, gconstpointer b);
|
||||
|
||||
static void apps_add_application (GArray *apps, WnckApplication *application, GPid pid);
|
||||
static void apps_remove_application (GArray *apps, WnckApplication *application);
|
||||
static App * apps_lookup_pid (GArray *apps, GPid pid);
|
||||
static App * apps_lookup_app (GArray *apps, WnckApplication *application);
|
||||
static App *apps_lookup_pid (GArray *apps, GPid pid);
|
||||
static App *apps_lookup_app (GArray *apps, WnckApplication *application);
|
||||
static void application_opened (WnckScreen *screen, WnckApplication *application, XtmAppManager *manager);
|
||||
static void application_closed (WnckScreen *screen, WnckApplication *application, XtmAppManager *manager);
|
||||
static void scale_factor_changed (GdkMonitor *monitor);
|
||||
@@ -103,7 +103,7 @@ xtm_app_manager_finalize (GObject *object)
|
||||
}
|
||||
|
||||
static GPid
|
||||
app_get_pid(WnckApplication *application)
|
||||
app_get_pid (WnckApplication *application)
|
||||
{
|
||||
GPid pid;
|
||||
GList *windows;
|
||||
@@ -120,9 +120,9 @@ app_get_pid(WnckApplication *application)
|
||||
}
|
||||
|
||||
static gint
|
||||
app_pid_compare_fn(gconstpointer a, gconstpointer b)
|
||||
app_pid_compare_fn (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
return (((const App*)a)->pid - ((const App*)b)->pid);
|
||||
return ((const App *)a)->pid - ((const App *)b)->pid;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -138,7 +138,7 @@ apps_add_application (GArray *apps, WnckApplication *application, GPid pid)
|
||||
|
||||
app.application = application;
|
||||
app.pid = pid;
|
||||
g_snprintf (app.name, sizeof(app.name), "%s", wnck_application_get_name (application));
|
||||
g_snprintf (app.name, sizeof (app.name), "%s", wnck_application_get_name (application));
|
||||
|
||||
monitor = gdk_display_get_monitor (gdk_display_get_default (), 0);
|
||||
if (monitor != NULL)
|
||||
@@ -153,14 +153,14 @@ apps_add_application (GArray *apps, WnckApplication *application, GPid pid)
|
||||
static void
|
||||
apps_remove_application (GArray *apps, WnckApplication *application)
|
||||
{
|
||||
App *app = apps_lookup_pid(apps, app_get_pid (application));
|
||||
App *app = apps_lookup_pid (apps, app_get_pid (application));
|
||||
|
||||
if (app == NULL)
|
||||
app = apps_lookup_app(apps, application);
|
||||
app = apps_lookup_app (apps, application);
|
||||
if (app == NULL)
|
||||
return;
|
||||
cairo_surface_destroy (app->surface);
|
||||
g_array_remove_index (apps, (guint)(((size_t)app - (size_t)apps->data) / sizeof(App)));
|
||||
g_array_remove_index (apps, (guint)(((size_t)app - (size_t)apps->data) / sizeof (App)));
|
||||
}
|
||||
|
||||
static App *
|
||||
@@ -173,7 +173,7 @@ apps_lookup_pid (GArray *apps, GPid pid)
|
||||
|
||||
tapp.pid = pid;
|
||||
|
||||
return (bsearch(&tapp, apps->data, apps->len, sizeof(App), app_pid_compare_fn));
|
||||
return bsearch (&tapp, apps->data, apps->len, sizeof (App), app_pid_compare_fn);
|
||||
}
|
||||
|
||||
static App *
|
||||
@@ -182,7 +182,8 @@ apps_lookup_app (GArray *apps, WnckApplication *application)
|
||||
App *tapp;
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < apps->len; i++) {
|
||||
for (i = 0; i < apps->len; i++)
|
||||
{
|
||||
tapp = &g_array_index (apps, App, i);
|
||||
if (tapp->application == application)
|
||||
return (tapp);
|
||||
@@ -195,14 +196,14 @@ static void
|
||||
application_opened (WnckScreen *screen __unused, WnckApplication *application, XtmAppManager *manager)
|
||||
{
|
||||
GPid pid = app_get_pid (application);
|
||||
G_DEBUG_FMT ("Application opened %p %d", (void*)application, pid);
|
||||
G_DEBUG_FMT ("Application opened %p %d", (void *)application, pid);
|
||||
apps_add_application (manager->apps, application, pid);
|
||||
}
|
||||
|
||||
static void
|
||||
application_closed (WnckScreen *screen __unused, WnckApplication *application, XtmAppManager *manager)
|
||||
{
|
||||
G_DEBUG_FMT ("Application closed %p", (void*)application);
|
||||
G_DEBUG_FMT ("Application closed %p", (void *)application);
|
||||
apps_remove_application (manager->apps, application);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
typedef struct _App App;
|
||||
struct _App
|
||||
{
|
||||
WnckApplication * application;
|
||||
WnckApplication *application;
|
||||
GPid pid;
|
||||
gchar name[1024];
|
||||
cairo_surface_t * surface;
|
||||
cairo_surface_t *surface;
|
||||
};
|
||||
|
||||
#define XTM_TYPE_APP_MANAGER (xtm_app_manager_get_type ())
|
||||
@@ -33,7 +33,7 @@ struct _App
|
||||
typedef struct _XtmAppManager XtmAppManager;
|
||||
|
||||
GType xtm_app_manager_get_type (void);
|
||||
XtmAppManager * xtm_app_manager_new (void);
|
||||
App * xtm_app_manager_get_app_from_pid (XtmAppManager *manager, GPid pid);
|
||||
XtmAppManager *xtm_app_manager_new (void);
|
||||
App *xtm_app_manager_get_app_from_pid (XtmAppManager *manager, GPid pid);
|
||||
|
||||
#endif /* !APP_MANAGER_H */
|
||||
|
||||
54
src/main.c
54
src/main.c
@@ -62,9 +62,9 @@ status_icon_popup_menu (GtkStatusIcon *_status_icon, guint button, guint activat
|
||||
gtk_widget_show_all (menu);
|
||||
}
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, gtk_status_icon_position_menu, _status_icon, button, activate_time);
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -72,9 +72,9 @@ create_status_icon (void)
|
||||
{
|
||||
if (!status_icon_or_null)
|
||||
{
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
GtkStatusIcon *status_icon = gtk_status_icon_new_from_icon_name ("org.xfce.taskmanager");
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
g_signal_connect (status_icon, "activate", G_CALLBACK (status_icon_activated), NULL);
|
||||
g_signal_connect (status_icon, "popup-menu", G_CALLBACK (status_icon_popup_menu), NULL);
|
||||
status_icon_or_null = status_icon;
|
||||
@@ -84,9 +84,9 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
static gboolean
|
||||
status_icon_get_visible (void)
|
||||
{
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
return status_icon_or_null && gtk_status_icon_get_visible (status_icon_or_null);
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -97,22 +97,23 @@ show_hide_status_icon (void)
|
||||
if (show_status_icon)
|
||||
{
|
||||
create_status_icon ();
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
gtk_status_icon_set_visible (status_icon_or_null, TRUE);
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
}
|
||||
else if (status_icon_get_visible ())
|
||||
{
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
gtk_status_icon_set_visible (status_icon_or_null, FALSE);
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
destroy_window (void)
|
||||
{
|
||||
if (gtk_main_level () > 0) {
|
||||
if (gtk_main_level () > 0)
|
||||
{
|
||||
if (timer_id > 0)
|
||||
g_source_remove (timer_id);
|
||||
gtk_main_quit ();
|
||||
@@ -146,17 +147,17 @@ collect_data (void)
|
||||
memory_percent = (memory_total != 0) ? ((memory_used * 100.0f) / (float)memory_total) : 0.0f;
|
||||
swap_percent = (swap_total != 0) ? ((swap_used * 100.0f) / (float)swap_total) : 0.0f;
|
||||
|
||||
used = g_format_size_full(memory_used, G_FORMAT_SIZE_IEC_UNITS);
|
||||
total = g_format_size_full(memory_total, G_FORMAT_SIZE_IEC_UNITS);
|
||||
g_snprintf (memory_info, sizeof(memory_info), "%.0f%% (%s / %s)", memory_percent, used, total);
|
||||
g_free(used);
|
||||
g_free(total);
|
||||
used = g_format_size_full (memory_used, G_FORMAT_SIZE_IEC_UNITS);
|
||||
total = g_format_size_full (memory_total, G_FORMAT_SIZE_IEC_UNITS);
|
||||
g_snprintf (memory_info, sizeof (memory_info), "%.0f%% (%s / %s)", memory_percent, used, total);
|
||||
g_free (used);
|
||||
g_free (total);
|
||||
|
||||
used = g_format_size_full(swap_used, G_FORMAT_SIZE_IEC_UNITS);
|
||||
total = g_format_size_full(swap_total, G_FORMAT_SIZE_IEC_UNITS);
|
||||
g_snprintf (swap_info, sizeof(swap_info), "%.0f%% (%s / %s)", swap_percent, used, total);
|
||||
g_free(used);
|
||||
g_free(total);
|
||||
used = g_format_size_full (swap_used, G_FORMAT_SIZE_IEC_UNITS);
|
||||
total = g_format_size_full (swap_total, G_FORMAT_SIZE_IEC_UNITS);
|
||||
g_snprintf (swap_info, sizeof (swap_info), "%.0f%% (%s / %s)", swap_percent, used, total);
|
||||
g_free (used);
|
||||
g_free (total);
|
||||
|
||||
xtm_process_window_set_system_info (XTM_PROCESS_WINDOW (window), num_processes, cpu, memory_percent, memory_info, swap_percent, swap_info);
|
||||
|
||||
@@ -165,15 +166,15 @@ collect_data (void)
|
||||
|
||||
if (status_icon_get_visible ())
|
||||
{
|
||||
g_snprintf (tooltip, sizeof(tooltip),
|
||||
g_snprintf (tooltip, sizeof (tooltip),
|
||||
_("<b>Processes:</b> %u\n"
|
||||
"<b>CPU:</b> %.0f%%\n"
|
||||
"<b>Memory:</b> %s\n"
|
||||
"<b>Swap:</b> %s"),
|
||||
num_processes, cpu, memory_info, swap_info);
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
gtk_status_icon_set_tooltip_markup (GTK_STATUS_ICON (status_icon_or_null), tooltip);
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
}
|
||||
|
||||
xtm_task_manager_update_model (task_manager);
|
||||
@@ -207,7 +208,8 @@ refresh_rate_changed (void)
|
||||
init_timeout ();
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
XfconfChannel *channel;
|
||||
GApplication *app;
|
||||
@@ -293,7 +295,7 @@ int main (int argc, char *argv[])
|
||||
g_object_unref (settings);
|
||||
if (status_icon_or_null != NULL)
|
||||
g_object_unref (status_icon_or_null);
|
||||
xfconf_shutdown();
|
||||
xfconf_shutdown ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ struct _XtmProcessMonitor
|
||||
/*<private>*/
|
||||
gfloat step_size;
|
||||
gint type;
|
||||
GArray * history;
|
||||
GArray * history_swap;
|
||||
GArray *history;
|
||||
GArray *history_swap;
|
||||
gboolean dark_mode;
|
||||
};
|
||||
G_DEFINE_TYPE (XtmProcessMonitor, xtm_process_monitor, GTK_TYPE_DRAWING_AREA)
|
||||
@@ -60,7 +60,7 @@ xtm_process_monitor_class_init (XtmProcessMonitorClass *klass)
|
||||
widget_class->draw = xtm_process_monitor_draw;
|
||||
|
||||
g_object_class_install_property (class, PROP_STEP_SIZE,
|
||||
g_param_spec_float ("step-size", "StepSize", "Step size", 0.1f, G_MAXFLOAT, 1, G_PARAM_CONSTRUCT|G_PARAM_READWRITE));
|
||||
g_param_spec_float ("step-size", "StepSize", "Step size", 0.1f, G_MAXFLOAT, 1, G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
|
||||
g_object_class_install_property (class, PROP_TYPE,
|
||||
g_param_spec_int ("type", "Type", "Type of graph to render", 0, G_MAXINT, 0, G_PARAM_READWRITE));
|
||||
}
|
||||
@@ -141,7 +141,7 @@ xtm_process_monitor_draw (GtkWidget *widget, cairo_t *cr)
|
||||
XtmProcessMonitor *monitor = XTM_PROCESS_MONITOR (widget);
|
||||
guint minimum_history_length;
|
||||
|
||||
minimum_history_length = (guint)(gtk_widget_get_allocated_width(widget) / monitor->step_size);
|
||||
minimum_history_length = (guint)(gtk_widget_get_allocated_width (widget) / monitor->step_size);
|
||||
if (monitor->history->len < minimum_history_length)
|
||||
{
|
||||
g_array_set_size (monitor->history, minimum_history_length + 1);
|
||||
@@ -255,10 +255,10 @@ xtm_process_monitor_paint (XtmProcessMonitor *monitor, cairo_t *cr)
|
||||
{
|
||||
cairo_surface_t *graph_surface;
|
||||
gint width, height;
|
||||
static const double dashed[] = {1.5};
|
||||
static const double dashed[] = { 1.5 };
|
||||
gint i;
|
||||
width = gtk_widget_get_allocated_width(GTK_WIDGET(monitor));
|
||||
height = gtk_widget_get_allocated_height(GTK_WIDGET(monitor));
|
||||
width = gtk_widget_get_allocated_width (GTK_WIDGET (monitor));
|
||||
height = gtk_widget_get_allocated_height (GTK_WIDGET (monitor));
|
||||
|
||||
/* Don't draw anything if the graph is too small */
|
||||
if (height < 3)
|
||||
@@ -275,7 +275,7 @@ xtm_process_monitor_paint (XtmProcessMonitor *monitor, cairo_t *cr)
|
||||
/* Paint dashed lines at 25%, 50% and 75% */
|
||||
xtm_process_monitor_cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.3, monitor->dark_mode);
|
||||
cairo_set_line_width (cr, 1.0);
|
||||
cairo_set_dash(cr, dashed, 1.0, 0);
|
||||
cairo_set_dash (cr, dashed, 1.0, 0);
|
||||
for (i = 25; i <= 75; i += 25)
|
||||
{
|
||||
cairo_move_to (cr, 1.5, i * height / 100 + 0.5);
|
||||
@@ -316,8 +316,8 @@ xtm_process_monitor_add_peak (XtmProcessMonitor *monitor, gfloat peak, gfloat pe
|
||||
g_array_remove_index (monitor->history_swap, monitor->history_swap->len - 1);
|
||||
}
|
||||
|
||||
if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET(monitor))))
|
||||
gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET(monitor)), NULL, FALSE);
|
||||
if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET (monitor))))
|
||||
gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (monitor)), NULL, FALSE);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -325,8 +325,8 @@ xtm_process_monitor_set_step_size (XtmProcessMonitor *monitor, gfloat step_size)
|
||||
{
|
||||
g_return_if_fail (XTM_IS_PROCESS_MONITOR (monitor));
|
||||
g_object_set (monitor, "step_size", step_size, NULL);
|
||||
if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET(monitor))))
|
||||
gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET(monitor)), NULL, FALSE);
|
||||
if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET (monitor))))
|
||||
gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (monitor)), NULL, FALSE);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -342,6 +342,6 @@ xtm_process_monitor_clear (XtmProcessMonitor *monitor)
|
||||
g_return_if_fail (XTM_IS_PROCESS_MONITOR (monitor));
|
||||
g_array_set_size (monitor->history, 0);
|
||||
g_array_set_size (monitor->history_swap, 0);
|
||||
if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET(monitor))))
|
||||
gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET(monitor)), NULL, FALSE);
|
||||
if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET (monitor))))
|
||||
gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (monitor)), NULL, FALSE);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
typedef struct _XtmProcessMonitor XtmProcessMonitor;
|
||||
|
||||
GType xtm_process_monitor_get_type (void);
|
||||
GtkWidget * xtm_process_monitor_new (void);
|
||||
GtkWidget *xtm_process_monitor_new (void);
|
||||
void xtm_process_monitor_add_peak (XtmProcessMonitor *monitor, gfloat peak, gfloat peak_swap);
|
||||
void xtm_process_monitor_set_step_size (XtmProcessMonitor *monitor, gfloat step_size);
|
||||
void xtm_process_monitor_set_type (XtmProcessMonitor *monitor, gint type);
|
||||
|
||||
@@ -36,12 +36,12 @@ struct _XtmProcessStatusbar
|
||||
{
|
||||
GtkHBox parent;
|
||||
/*<private>*/
|
||||
XtmSettings * settings;
|
||||
XtmSettings *settings;
|
||||
|
||||
GtkWidget * label_num_processes;
|
||||
GtkWidget * label_cpu;
|
||||
GtkWidget * label_memory;
|
||||
GtkWidget * label_swap;
|
||||
GtkWidget *label_num_processes;
|
||||
GtkWidget *label_cpu;
|
||||
GtkWidget *label_memory;
|
||||
GtkWidget *label_swap;
|
||||
|
||||
gfloat cpu;
|
||||
gchar memory[64];
|
||||
@@ -65,15 +65,15 @@ xtm_process_statusbar_class_init (XtmProcessStatusbarClass *klass)
|
||||
class->finalize = xtm_process_statusbar_finalize;
|
||||
class->set_property = xtm_process_statusbar_set_property;
|
||||
g_object_class_install_property (class, PROP_CPU,
|
||||
g_param_spec_float ("cpu", "CPU", "CPU usage", 0, 100, 0, G_PARAM_CONSTRUCT|G_PARAM_WRITABLE));
|
||||
g_param_spec_float ("cpu", "CPU", "CPU usage", 0, 100, 0, G_PARAM_CONSTRUCT | G_PARAM_WRITABLE));
|
||||
g_object_class_install_property (class, PROP_MEMORY,
|
||||
g_param_spec_string ("memory", "Memory", "Memory usage", "", G_PARAM_CONSTRUCT|G_PARAM_WRITABLE));
|
||||
g_param_spec_string ("memory", "Memory", "Memory usage", "", G_PARAM_CONSTRUCT | G_PARAM_WRITABLE));
|
||||
g_object_class_install_property (class, PROP_SWAP,
|
||||
g_param_spec_string ("swap", "Swap", "Swap usage", "", G_PARAM_CONSTRUCT|G_PARAM_WRITABLE));
|
||||
g_param_spec_string ("swap", "Swap", "Swap usage", "", G_PARAM_CONSTRUCT | G_PARAM_WRITABLE));
|
||||
g_object_class_install_property (class, PROP_SHOW_SWAP,
|
||||
g_param_spec_boolean ("show-swap", "ShowSwap", "Show or hide swap usage", TRUE, G_PARAM_WRITABLE));
|
||||
g_object_class_install_property (class, PROP_NUM_PROCESSES,
|
||||
g_param_spec_uint ("num-processes", "NumProcesses", "Number of processes", 0, G_MAXUINT, 0, G_PARAM_CONSTRUCT|G_PARAM_WRITABLE));
|
||||
g_param_spec_uint ("num-processes", "NumProcesses", "Number of processes", 0, G_MAXUINT, 0, G_PARAM_CONSTRUCT | G_PARAM_WRITABLE));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -195,7 +195,7 @@ xtm_process_statusbar_set_property (GObject *object, guint property_id, const GV
|
||||
break;
|
||||
|
||||
case PROP_MEMORY:
|
||||
g_strlcpy(statusbar->memory, g_value_get_string (value), sizeof(statusbar->memory));
|
||||
g_strlcpy (statusbar->memory, g_value_get_string (value), sizeof (statusbar->memory));
|
||||
text = g_strdup_printf (_("Memory: %s"), statusbar->memory);
|
||||
gtk_label_set_text (GTK_LABEL (statusbar->label_memory), text);
|
||||
gtk_widget_set_tooltip_text (statusbar->label_memory, text);
|
||||
@@ -203,7 +203,7 @@ xtm_process_statusbar_set_property (GObject *object, guint property_id, const GV
|
||||
break;
|
||||
|
||||
case PROP_SWAP:
|
||||
g_strlcpy(statusbar->swap, g_value_get_string (value), sizeof(statusbar->swap));
|
||||
g_strlcpy (statusbar->swap, g_value_get_string (value), sizeof (statusbar->swap));
|
||||
text = g_strdup_printf (_("Swap: %s"), statusbar->swap);
|
||||
gtk_label_set_text (GTK_LABEL (statusbar->label_swap), text);
|
||||
gtk_widget_set_tooltip_text (statusbar->label_swap, text);
|
||||
|
||||
@@ -23,6 +23,6 @@
|
||||
typedef struct _XtmProcessStatusbar XtmProcessStatusbar;
|
||||
|
||||
GType xtm_process_statusbar_get_type (void);
|
||||
GtkWidget * xtm_process_statusbar_new (void);
|
||||
GtkWidget *xtm_process_statusbar_new (void);
|
||||
|
||||
#endif /* !PROCESS_STATUSBAR_H */
|
||||
|
||||
@@ -20,16 +20,18 @@
|
||||
|
||||
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_MODEL
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
GtkTreePath * path;
|
||||
GSequenceIter * list;
|
||||
GNode * tree;
|
||||
GtkTreePath *path;
|
||||
GSequenceIter *list;
|
||||
GNode *tree;
|
||||
} XtmCrossLink;
|
||||
|
||||
typedef struct _XtmProcessTreeModelClass XtmProcessTreeModelClass;
|
||||
@@ -41,9 +43,9 @@ struct _XtmProcessTreeModel
|
||||
{
|
||||
GObject parent;
|
||||
/*<private>*/
|
||||
GtkTreeModel * model;
|
||||
GNode * tree;
|
||||
GSequence * list;
|
||||
GtkTreeModel *model;
|
||||
GNode *tree;
|
||||
GSequence *list;
|
||||
gint c_column;
|
||||
gint p_column;
|
||||
gint stamp;
|
||||
@@ -62,7 +64,7 @@ static GtkTreeModelFlags xtm_process_tree_model_get_flags (GtkTreeModel *model);
|
||||
static gint xtm_process_tree_model_get_n_columns (GtkTreeModel *model);
|
||||
static GType xtm_process_tree_model_get_column_type (GtkTreeModel *model, gint idx);
|
||||
static gboolean xtm_process_tree_model_get_iter (GtkTreeModel *model, GtkTreeIter *iter, GtkTreePath *path);
|
||||
static GtkTreePath * xtm_process_tree_model_get_path (GtkTreeModel *model, GtkTreeIter *iter);
|
||||
static GtkTreePath *xtm_process_tree_model_get_path (GtkTreeModel *model, GtkTreeIter *iter);
|
||||
static void xtm_process_tree_model_get_value (GtkTreeModel *model, GtkTreeIter *iter, gint column, GValue *value);
|
||||
static gboolean xtm_process_tree_model_iter_next (GtkTreeModel *model, GtkTreeIter *iter);
|
||||
static gboolean xtm_process_tree_model_iter_children (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *parent);
|
||||
@@ -73,7 +75,6 @@ static gboolean xtm_process_tree_model_iter_parent (GtkTreeModel *model, GtkTr
|
||||
|
||||
static void xtm_process_tree_model_row_changed (XtmProcessTreeModel *treemodel, GtkTreePath *path, GtkTreeIter *iter, GtkTreeModel *model);
|
||||
static void xtm_process_tree_model_row_inserted (XtmProcessTreeModel *treemodel, GtkTreePath *path, GtkTreeIter *iter, GtkTreeModel *model);
|
||||
//static void xtm_process_tree_model_row_has_child_toggled (XtmProcessTreeModel *treemodel, GtkTreePath *path, GtkTreeIter *iter, GtkTreeModel *model);
|
||||
static void xtm_process_tree_model_row_deleted (XtmProcessTreeModel *treemodel, GtkTreePath *path, GtkTreeModel *model);
|
||||
static void xtm_process_tree_model_rows_reordered (XtmProcessTreeModel *treemodel, GtkTreePath *path, GtkTreeIter *iter, gint *new_order, GtkTreeModel *model);
|
||||
|
||||
@@ -112,7 +113,7 @@ xtm_process_tree_model_class_init (XtmProcessTreeModelClass *klass)
|
||||
class->get_property = xtm_process_tree_model_get_property;
|
||||
|
||||
g_object_class_install_property (class, PROP_MODEL,
|
||||
g_param_spec_object ("model", NULL, NULL, GTK_TYPE_TREE_MODEL, G_PARAM_READABLE|G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
|
||||
g_param_spec_object ("model", NULL, NULL, GTK_TYPE_TREE_MODEL, G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -370,8 +371,8 @@ xtm_process_tree_model_iter_parent (GtkTreeModel *model, GtkTreeIter *iter, GtkT
|
||||
struct find_node_struct
|
||||
{
|
||||
GValue p_value;
|
||||
XtmProcessTreeModel * treemodel;
|
||||
GNode * parent;
|
||||
XtmProcessTreeModel *treemodel;
|
||||
GNode *parent;
|
||||
};
|
||||
|
||||
static gboolean
|
||||
@@ -380,7 +381,7 @@ find_node (GNode *node, gpointer data)
|
||||
XtmCrossLink *lnk = node->data;
|
||||
struct find_node_struct *found = data;
|
||||
gboolean same = FALSE;
|
||||
GValue c_value = {0};
|
||||
GValue c_value = { 0 };
|
||||
if (lnk == NULL)
|
||||
return FALSE;
|
||||
/* Use path for non-persistent models */
|
||||
@@ -458,8 +459,8 @@ xtm_process_tree_model_row_changed (XtmProcessTreeModel *treemodel, GtkTreePath
|
||||
XtmCrossLink *lnk, *c_link;
|
||||
GNode *node, *next_node, *old_parent;
|
||||
struct find_node_struct found;
|
||||
GValue c_value = {0};
|
||||
GValue p_value = {0};
|
||||
GValue c_value = { 0 };
|
||||
GValue p_value = { 0 };
|
||||
gboolean same = TRUE;
|
||||
gboolean signal_parent;
|
||||
|
||||
@@ -476,7 +477,7 @@ xtm_process_tree_model_row_changed (XtmProcessTreeModel *treemodel, GtkTreePath
|
||||
s_iter.user_data3 = NULL;
|
||||
|
||||
/* Use the root entry as fall-back if no parent could be found */
|
||||
memset(&found, 0, sizeof(found));
|
||||
memset (&found, 0, sizeof (found));
|
||||
found.parent = treemodel->tree;
|
||||
found.treemodel = treemodel;
|
||||
gtk_tree_model_get_value (model, iter, treemodel->p_column, &found.p_value);
|
||||
@@ -608,7 +609,7 @@ static void
|
||||
do_path (gpointer data, gpointer user_data)
|
||||
{
|
||||
XtmCrossLink *lnk = data;
|
||||
void (*func) (GtkTreePath*) = (void (*) (GtkTreePath*))user_data;
|
||||
void (*func) (GtkTreePath *) = (void (*) (GtkTreePath *))user_data;
|
||||
/* Use path for non-persistent models */
|
||||
g_return_if_fail (lnk->path);
|
||||
func (lnk->path);
|
||||
@@ -622,8 +623,8 @@ xtm_process_tree_model_row_inserted (XtmProcessTreeModel *treemodel, GtkTreePath
|
||||
XtmCrossLink *lnk, *c_link;
|
||||
GNode *node, *next_node;
|
||||
struct find_node_struct found;
|
||||
GValue c_value = {0};
|
||||
GValue p_value = {0};
|
||||
GValue c_value = { 0 };
|
||||
GValue p_value = { 0 };
|
||||
gboolean same;
|
||||
gboolean not_persist = TRUE;
|
||||
gboolean signal_parent;
|
||||
@@ -631,9 +632,9 @@ xtm_process_tree_model_row_inserted (XtmProcessTreeModel *treemodel, GtkTreePath
|
||||
g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
|
||||
|
||||
/* Take a reference on this node, to want to stay informed about any changes in this row */
|
||||
gtk_tree_model_ref_node(model, iter);
|
||||
gtk_tree_model_ref_node (model, iter);
|
||||
|
||||
not_persist = ! (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_ITERS_PERSIST);
|
||||
not_persist = !(gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_ITERS_PERSIST);
|
||||
|
||||
s_iter.stamp = treemodel->stamp;
|
||||
s_iter.user_data2 = NULL;
|
||||
@@ -654,7 +655,7 @@ xtm_process_tree_model_row_inserted (XtmProcessTreeModel *treemodel, GtkTreePath
|
||||
g_sequence_foreach_range (g_sequence_iter_next (lnk->list), g_sequence_get_end_iter (treemodel->list),
|
||||
do_path, (gpointer)gtk_tree_path_next);
|
||||
|
||||
memset(&found, 0, sizeof(found));
|
||||
memset (&found, 0, sizeof (found));
|
||||
found.parent = treemodel->tree;
|
||||
found.treemodel = treemodel;
|
||||
gtk_tree_model_get_value (model, iter, treemodel->p_column, &found.p_value);
|
||||
@@ -750,7 +751,7 @@ xtm_process_tree_model_row_deleted (XtmProcessTreeModel *treemodel, GtkTreePath
|
||||
|
||||
g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
|
||||
|
||||
not_persist = ! (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_ITERS_PERSIST);
|
||||
not_persist = !(gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_ITERS_PERSIST);
|
||||
|
||||
s_iter.stamp = treemodel->stamp;
|
||||
s_iter.user_data2 = NULL;
|
||||
@@ -852,7 +853,7 @@ reorder_children (GNode *parent, gpointer data)
|
||||
if (c_pos > 0)
|
||||
{
|
||||
/* move the items in between to keep order list in sync with the current tree */
|
||||
memmove ((new_order + i + 1), (new_order + i), ((guint)c_pos * sizeof(gint)));
|
||||
memmove (new_order + i + 1, new_order + i, (guint)c_pos * sizeof (gint));
|
||||
moved = TRUE;
|
||||
}
|
||||
/* Store the old position at the new location */
|
||||
@@ -891,7 +892,7 @@ xtm_process_tree_model_rows_reordered (XtmProcessTreeModel *treemodel, GtkTreePa
|
||||
if (G_UNLIKELY (size == 0))
|
||||
return;
|
||||
|
||||
not_persist = ! (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_ITERS_PERSIST);
|
||||
not_persist = !(gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_ITERS_PERSIST);
|
||||
|
||||
/* New list to hold the new order */
|
||||
s_list = g_sequence_new (xtm_cross_link_free);
|
||||
@@ -933,7 +934,6 @@ xtm_process_tree_model_set_model (XtmProcessTreeModel *treemodel, GtkTreeModel *
|
||||
|
||||
g_signal_connect_object (model, "row-changed", G_CALLBACK (xtm_process_tree_model_row_changed), treemodel, G_CONNECT_SWAPPED);
|
||||
g_signal_connect_object (model, "row-inserted", G_CALLBACK (xtm_process_tree_model_row_inserted), treemodel, G_CONNECT_SWAPPED);
|
||||
//g_signal_connect_object (model, "row-has-child-toggled", G_CALLBACK (xtm_process_tree_model_row_has_child_toggled), treemodel, G_CONNECT_SWAPPED);
|
||||
g_signal_connect_object (model, "row-deleted", G_CALLBACK (xtm_process_tree_model_row_deleted), treemodel, G_CONNECT_SWAPPED);
|
||||
g_signal_connect_object (model, "rows-reordered", G_CALLBACK (xtm_process_tree_model_rows_reordered), treemodel, G_CONNECT_SWAPPED);
|
||||
}
|
||||
@@ -941,7 +941,7 @@ xtm_process_tree_model_set_model (XtmProcessTreeModel *treemodel, GtkTreeModel *
|
||||
|
||||
|
||||
GtkTreeModel *
|
||||
xtm_process_tree_model_new (GtkTreeModel * model)
|
||||
xtm_process_tree_model_new (GtkTreeModel *model)
|
||||
{
|
||||
/* Only support flat models to build a tree */
|
||||
g_return_val_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY, NULL);
|
||||
|
||||
@@ -23,6 +23,6 @@
|
||||
typedef struct _XtmProcessTreeModel XtmProcessTreeModel;
|
||||
|
||||
GType xtm_process_tree_model_get_type (void);
|
||||
GtkTreeModel * xtm_process_tree_model_new (GtkTreeModel * model);
|
||||
GtkTreeModel *xtm_process_tree_model_new (GtkTreeModel *model);
|
||||
|
||||
#endif /* !PROCESS_TREE_MODEL_H */
|
||||
|
||||
@@ -50,13 +50,13 @@ struct _XtmProcessTreeView
|
||||
{
|
||||
GtkTreeView parent;
|
||||
/*<private>*/
|
||||
GtkListStore * model;
|
||||
GtkTreeModel * model_filter;
|
||||
gchar * cmd_filter;
|
||||
GtkTreeModel * model_tree;
|
||||
GtkTreeViewColumn * sort_column;
|
||||
GtkListStore *model;
|
||||
GtkTreeModel *model_filter;
|
||||
gchar *cmd_filter;
|
||||
GtkTreeModel *model_tree;
|
||||
GtkTreeViewColumn *sort_column;
|
||||
gushort columns_positions[N_COLUMNS];
|
||||
XtmSettings * settings;
|
||||
XtmSettings *settings;
|
||||
guint owner_uid;
|
||||
gboolean show_all_processes_cached;
|
||||
};
|
||||
@@ -143,7 +143,7 @@ xtm_process_tree_view_init (XtmProcessTreeView *treeview)
|
||||
treeview->cmd_filter = NULL;
|
||||
|
||||
/* Create cell renderer for tree view columns */
|
||||
cell_text = gtk_cell_renderer_text_new();
|
||||
cell_text = gtk_cell_renderer_text_new ();
|
||||
|
||||
cell_right_aligned = gtk_cell_renderer_text_new ();
|
||||
g_object_set (cell_right_aligned, "xalign", 1.0, NULL);
|
||||
@@ -417,7 +417,7 @@ save_columns_positions (XtmProcessTreeView *treeview)
|
||||
gchar columns_positions[COLUMNS_POSITIONS_STRLEN] = { 0 };
|
||||
|
||||
for (i = 0; i < N_COLUMNS; i++)
|
||||
offset += (gulong)g_snprintf (&columns_positions[offset], (sizeof(columns_positions) - offset), "%d;", treeview->columns_positions[i]);
|
||||
offset += (gulong)g_snprintf (&columns_positions[offset], (sizeof (columns_positions) - offset), "%d;", treeview->columns_positions[i]);
|
||||
|
||||
g_object_set (treeview->settings, "columns-positions", columns_positions, NULL);
|
||||
}
|
||||
@@ -457,7 +457,8 @@ cb_send_signal (GtkMenuItem *mi, gpointer user_data)
|
||||
_("Error sending signal"));
|
||||
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
||||
_("An error was encountered by sending a signal to the PID %d. "
|
||||
"It is likely you don't have the required privileges."), pid);
|
||||
"It is likely you don't have the required privileges."),
|
||||
pid);
|
||||
gtk_window_set_title (GTK_WINDOW (dialog), _("Task Manager"));
|
||||
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
|
||||
gtk_dialog_run (GTK_DIALOG (dialog));
|
||||
@@ -486,8 +487,10 @@ cb_set_priority (GtkMenuItem *mi, gpointer user_data)
|
||||
{
|
||||
GtkWidget *dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
|
||||
_("Error setting priority"));
|
||||
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("An error was encountered by setting a priority to the PID %d. "
|
||||
"It is likely you don't have the required privileges."), pid);
|
||||
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
||||
_("An error was encountered by setting a priority to the PID %d. "
|
||||
"It is likely you don't have the required privileges."),
|
||||
pid);
|
||||
gtk_window_set_title (GTK_WINDOW (dialog), _("Task Manager"));
|
||||
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
|
||||
gtk_dialog_run (GTK_DIALOG (dialog));
|
||||
@@ -610,7 +613,7 @@ build_context_menu (XtmProcessTreeView *treeview, GPid pid)
|
||||
g_signal_connect (mi, "activate", G_CALLBACK (cb_copy_command_line), treeview);
|
||||
/* Refer to treeview_key_pressed to see how the Ctrl-c press is handled */
|
||||
accel_label = gtk_bin_get_child (GTK_BIN (mi));
|
||||
gtk_accel_label_set_accel(GTK_ACCEL_LABEL (accel_label), GDK_KEY_c, GDK_CONTROL_MASK);
|
||||
gtk_accel_label_set_accel (GTK_ACCEL_LABEL (accel_label), GDK_KEY_c, GDK_CONTROL_MASK);
|
||||
|
||||
gtk_widget_show_all (menu);
|
||||
|
||||
@@ -740,17 +743,17 @@ column_clicked (GtkTreeViewColumn *column, XtmProcessTreeView *treeview)
|
||||
|
||||
treeview->sort_column = column;
|
||||
|
||||
g_object_set(treeview->settings,
|
||||
"sort-column-id", GPOINTER_TO_INT(g_object_get_data(G_OBJECT(treeview->sort_column), "column-id")),
|
||||
g_object_set (treeview->settings,
|
||||
"sort-column-id", GPOINTER_TO_INT (g_object_get_data (G_OBJECT (treeview->sort_column), "column-id")),
|
||||
"sort-type", sort_type,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void
|
||||
xtm_process_tree_view_set_filter(XtmProcessTreeView *treeview, const gchar *cmd_filter)
|
||||
xtm_process_tree_view_set_filter (XtmProcessTreeView *treeview, const gchar *cmd_filter)
|
||||
{
|
||||
g_free(treeview->cmd_filter);
|
||||
treeview->cmd_filter = g_strdup(cmd_filter);
|
||||
g_free (treeview->cmd_filter);
|
||||
treeview->cmd_filter = g_strdup (cmd_filter);
|
||||
|
||||
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (treeview->model_filter));
|
||||
}
|
||||
@@ -762,9 +765,11 @@ visible_func (GtkTreeModel *model, GtkTreeIter *iter, XtmProcessTreeView *treevi
|
||||
gboolean mach_filter = TRUE, match_uid = TRUE;
|
||||
guint uid;
|
||||
|
||||
if(treeview->cmd_filter) {
|
||||
if (treeview->cmd_filter)
|
||||
{
|
||||
gtk_tree_model_get (GTK_TREE_MODEL (model), iter, XTM_PTV_COLUMN_COMMAND, &cmdline, -1);
|
||||
if(cmdline) {
|
||||
if (cmdline)
|
||||
{
|
||||
cmdline_lower = g_ascii_strdown (cmdline, -1);
|
||||
key_lower = g_ascii_strdown (treeview->cmd_filter, -1);
|
||||
|
||||
@@ -775,10 +780,11 @@ visible_func (GtkTreeModel *model, GtkTreeIter *iter, XtmProcessTreeView *treevi
|
||||
g_free (cmdline);
|
||||
}
|
||||
|
||||
if(!p)
|
||||
if (!p)
|
||||
mach_filter = FALSE;
|
||||
}
|
||||
if (!treeview->show_all_processes_cached) {
|
||||
if (!treeview->show_all_processes_cached)
|
||||
{
|
||||
gtk_tree_model_get (GTK_TREE_MODEL (treeview->model), iter, XTM_PTV_COLUMN_UID, &uid, -1);
|
||||
if (treeview->owner_uid != uid)
|
||||
match_uid = FALSE;
|
||||
@@ -891,7 +897,8 @@ xtm_process_tree_view_get_model (XtmProcessTreeView *treeview)
|
||||
}
|
||||
|
||||
void
|
||||
xtm_process_tree_view_highlight_pid (XtmProcessTreeView *treeview, GPid pid) {
|
||||
xtm_process_tree_view_highlight_pid (XtmProcessTreeView *treeview, GPid pid)
|
||||
{
|
||||
GtkTreeModel *model;
|
||||
GtkTreePath *path;
|
||||
GtkTreeIter iter;
|
||||
@@ -936,8 +943,9 @@ xtm_process_tree_view_highlight_pid (XtmProcessTreeView *treeview, GPid pid) {
|
||||
valid = gtk_tree_model_iter_next (model, &iter);
|
||||
if (tree && !valid)
|
||||
{
|
||||
//finding my way up again
|
||||
do {
|
||||
// finding my way up again
|
||||
do
|
||||
{
|
||||
validParent = gtk_tree_model_iter_parent (model, &iter, &child_iter);
|
||||
child_iter = iter;
|
||||
valid = gtk_tree_model_iter_next (model, &iter);
|
||||
|
||||
@@ -56,9 +56,9 @@ enum
|
||||
typedef struct _XtmProcessTreeView XtmProcessTreeView;
|
||||
|
||||
GType xtm_process_tree_view_get_type (void);
|
||||
GtkWidget * xtm_process_tree_view_new (void);
|
||||
GtkWidget *xtm_process_tree_view_new (void);
|
||||
void xtm_process_tree_view_set_filter (XtmProcessTreeView *treeview, const gchar *cmd_filter);
|
||||
GtkTreeModel * xtm_process_tree_view_get_model (XtmProcessTreeView *treeview);
|
||||
GtkTreeModel *xtm_process_tree_view_get_model (XtmProcessTreeView *treeview);
|
||||
void xtm_process_tree_view_highlight_pid (XtmProcessTreeView *treeview, GPid pid);
|
||||
|
||||
#endif /* !PROCESS_TREE_VIEW_H */
|
||||
|
||||
@@ -46,18 +46,18 @@ struct _XtmProcessWindow
|
||||
{
|
||||
GtkWidget parent;
|
||||
/*<private>*/
|
||||
GtkBuilder * builder;
|
||||
GtkWidget * window;
|
||||
GtkWidget * filter_entry;
|
||||
GtkWidget * filter_searchbar;
|
||||
GtkWidget * cpu_monitor;
|
||||
GtkWidget * mem_monitor;
|
||||
GtkWidget * vpaned;
|
||||
GtkWidget * treeview;
|
||||
GtkWidget * statusbar;
|
||||
GtkWidget * settings_button;
|
||||
XtmSettings * settings;
|
||||
XfconfChannel * channel;
|
||||
GtkBuilder *builder;
|
||||
GtkWidget *window;
|
||||
GtkWidget *filter_entry;
|
||||
GtkWidget *filter_searchbar;
|
||||
GtkWidget *cpu_monitor;
|
||||
GtkWidget *mem_monitor;
|
||||
GtkWidget *vpaned;
|
||||
GtkWidget *treeview;
|
||||
GtkWidget *statusbar;
|
||||
GtkWidget *settings_button;
|
||||
XtmSettings *settings;
|
||||
XfconfChannel *channel;
|
||||
gint width;
|
||||
gint height;
|
||||
gulong handler;
|
||||
@@ -74,14 +74,12 @@ static void monitor_update_step_size (XtmProcessWindow *window);
|
||||
|
||||
|
||||
static void
|
||||
filter_entry_icon_pressed_cb (GtkEntry *entry,
|
||||
gint position,
|
||||
GdkEventButton *event __unused,
|
||||
gpointer data __unused)
|
||||
filter_entry_icon_pressed_cb (GtkEntry *entry, gint position, GdkEventButton *event __unused, gpointer data __unused)
|
||||
{
|
||||
if (position == GTK_ENTRY_ICON_SECONDARY) {
|
||||
if (position == GTK_ENTRY_ICON_SECONDARY)
|
||||
{
|
||||
gtk_entry_set_text (entry, "");
|
||||
gtk_widget_grab_focus (GTK_WIDGET(entry));
|
||||
gtk_widget_grab_focus (GTK_WIDGET (entry));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,31 +90,36 @@ Select_Window (Display *dpy, int screen)
|
||||
int status;
|
||||
Cursor cursor;
|
||||
XEvent event;
|
||||
Window target_win = None, root = RootWindow(dpy,screen);
|
||||
Window target_win = None, root = RootWindow (dpy, screen);
|
||||
int buttons = 0;
|
||||
|
||||
/* Make the target cursor */
|
||||
cursor = XCreateFontCursor(dpy, XC_crosshair);
|
||||
cursor = XCreateFontCursor (dpy, XC_crosshair);
|
||||
|
||||
/* Grab the pointer using target cursor, letting it roam all over */
|
||||
status = XGrabPointer(dpy, root, False,
|
||||
ButtonPressMask|ButtonReleaseMask, GrabModeSync,
|
||||
status = XGrabPointer (dpy, root, False,
|
||||
ButtonPressMask | ButtonReleaseMask, GrabModeSync,
|
||||
GrabModeAsync, root, cursor, CurrentTime);
|
||||
if (status != GrabSuccess) {
|
||||
if (status != GrabSuccess)
|
||||
{
|
||||
fprintf (stderr, "Can't grab the mouse.\n");
|
||||
return None;
|
||||
}
|
||||
|
||||
/* Let the user select a window... */
|
||||
while ((target_win == None) || (buttons != 0)) {
|
||||
while ((target_win == None) || (buttons != 0))
|
||||
{
|
||||
/* allow one more event */
|
||||
XAllowEvents(dpy, SyncPointer, CurrentTime);
|
||||
XWindowEvent(dpy, root, ButtonPressMask|ButtonReleaseMask, &event);
|
||||
switch (event.type) {
|
||||
XAllowEvents (dpy, SyncPointer, CurrentTime);
|
||||
XWindowEvent (dpy, root, ButtonPressMask | ButtonReleaseMask, &event);
|
||||
switch (event.type)
|
||||
{
|
||||
case ButtonPress:
|
||||
if (target_win == None) {
|
||||
if (target_win == None)
|
||||
{
|
||||
target_win = event.xbutton.subwindow; /* window selected */
|
||||
if (target_win == None) target_win = root;
|
||||
if (target_win == None)
|
||||
target_win = root;
|
||||
}
|
||||
buttons++;
|
||||
break;
|
||||
@@ -127,14 +130,15 @@ Select_Window (Display *dpy, int screen)
|
||||
}
|
||||
}
|
||||
|
||||
XUngrabPointer(dpy, CurrentTime); /* Done with pointer */
|
||||
XUngrabPointer (dpy, CurrentTime); /* Done with pointer */
|
||||
|
||||
return target_win;
|
||||
}
|
||||
|
||||
static void
|
||||
xwininfo_clicked_cb (GtkButton *button __unused, gpointer user_data) {
|
||||
XtmProcessWindow *window = (XtmProcessWindow *) user_data;
|
||||
xwininfo_clicked_cb (GtkButton *button __unused, gpointer user_data)
|
||||
{
|
||||
XtmProcessWindow *window = (XtmProcessWindow *)user_data;
|
||||
Window selected_window;
|
||||
Display *dpy;
|
||||
Atom atom_NET_WM_PID;
|
||||
@@ -148,51 +152,56 @@ xwininfo_clicked_cb (GtkButton *button __unused, gpointer user_data) {
|
||||
|
||||
dpy = XOpenDisplay (NULL);
|
||||
selected_window = Select_Window (dpy, 0);
|
||||
if (selected_window) {
|
||||
if (selected_window)
|
||||
{
|
||||
selected_window = XmuClientWindow (dpy, selected_window);
|
||||
}
|
||||
|
||||
atom_NET_WM_PID = XInternAtom(dpy, "_NET_WM_PID", False);
|
||||
atom_NET_WM_PID = XInternAtom (dpy, "_NET_WM_PID", False);
|
||||
|
||||
status = XGetWindowProperty(dpy, selected_window, atom_NET_WM_PID, 0, (~0L),
|
||||
status = XGetWindowProperty (dpy, selected_window, atom_NET_WM_PID, 0, ~0L,
|
||||
False, AnyPropertyType, &actual_type,
|
||||
&actual_format, &_nitems, &bytes_after,
|
||||
&prop);
|
||||
if (status == BadWindow) {
|
||||
XTM_SHOW_MESSAGE(GTK_MESSAGE_INFO,
|
||||
if (status == BadWindow)
|
||||
{
|
||||
XTM_SHOW_MESSAGE (GTK_MESSAGE_INFO,
|
||||
_("Bad Window"), _("Window id 0x%lx does not exist!"), selected_window);
|
||||
} if (status != Success) {
|
||||
XTM_SHOW_MESSAGE(GTK_MESSAGE_ERROR,
|
||||
}
|
||||
if (status != Success)
|
||||
{
|
||||
XTM_SHOW_MESSAGE (GTK_MESSAGE_ERROR,
|
||||
_("XGetWindowProperty failed"), _("XGetWindowProperty failed!"));
|
||||
} else {
|
||||
if (_nitems > 0) {
|
||||
memcpy(&pid, prop, sizeof(pid));
|
||||
xtm_process_tree_view_highlight_pid(XTM_PROCESS_TREE_VIEW (window->treeview), pid);
|
||||
} else {
|
||||
XTM_SHOW_MESSAGE(GTK_MESSAGE_INFO,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_nitems > 0)
|
||||
{
|
||||
memcpy (&pid, prop, sizeof (pid));
|
||||
xtm_process_tree_view_highlight_pid (XTM_PROCESS_TREE_VIEW (window->treeview), pid);
|
||||
}
|
||||
else
|
||||
{
|
||||
XTM_SHOW_MESSAGE (GTK_MESSAGE_INFO,
|
||||
_("No PID found"), _("No PID found for window 0x%lx."), selected_window);
|
||||
}
|
||||
g_free(prop);
|
||||
g_free (prop);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
filter_entry_keyrelease_handler(GtkEntry *entry,
|
||||
XtmProcessTreeView *treeview)
|
||||
filter_entry_keyrelease_handler (GtkEntry *entry, XtmProcessTreeView *treeview)
|
||||
{
|
||||
gchar *text;
|
||||
gboolean has_text;
|
||||
|
||||
text = gtk_editable_get_chars (GTK_EDITABLE(entry), 0, -1);
|
||||
xtm_process_tree_view_set_filter(treeview, text);
|
||||
text = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1);
|
||||
xtm_process_tree_view_set_filter (treeview, text);
|
||||
g_free (text);
|
||||
|
||||
has_text = gtk_entry_get_text_length (GTK_ENTRY(entry)) > 0;
|
||||
gtk_entry_set_icon_sensitive (GTK_ENTRY(entry),
|
||||
GTK_ENTRY_ICON_SECONDARY,
|
||||
has_text);
|
||||
has_text = gtk_entry_get_text_length (GTK_ENTRY (entry)) > 0;
|
||||
gtk_entry_set_icon_sensitive (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY, has_text);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -212,7 +221,7 @@ xtm_process_window_class_init (XtmProcessWindowClass *klass)
|
||||
static void
|
||||
xtm_process_window_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer user_data)
|
||||
{
|
||||
XtmProcessWindow *window = (XtmProcessWindow *) user_data;
|
||||
XtmProcessWindow *window = (XtmProcessWindow *)user_data;
|
||||
|
||||
g_return_if_fail (gtk_widget_is_toplevel (widget));
|
||||
|
||||
@@ -222,7 +231,7 @@ xtm_process_window_size_allocate (GtkWidget *widget, GtkAllocation *allocation,
|
||||
static void
|
||||
show_settings_dialog (GtkButton *button, gpointer user_data)
|
||||
{
|
||||
XtmProcessWindow *window = (XtmProcessWindow *) user_data;
|
||||
XtmProcessWindow *window = (XtmProcessWindow *)user_data;
|
||||
|
||||
g_signal_handler_block (G_OBJECT (window->window), window->handler);
|
||||
xtm_settings_dialog_run (window->window);
|
||||
@@ -244,13 +253,12 @@ xtm_process_window_unstick_view_event (GtkWidget *widget, GdkEvent *event, XtmPr
|
||||
GdkScrollDirection dir;
|
||||
gdouble y;
|
||||
|
||||
if (! window->view_stuck)
|
||||
if (!window->view_stuck)
|
||||
return FALSE;
|
||||
|
||||
if (event->type == GDK_SCROLL && (
|
||||
(gdk_event_get_scroll_direction (event, &dir) && dir == GDK_SCROLL_UP)
|
||||
|| (gdk_event_get_scroll_deltas (event, NULL, &y) && y <= 0)
|
||||
))
|
||||
if (event->type == GDK_SCROLL &&
|
||||
((gdk_event_get_scroll_direction (event, &dir) && dir == GDK_SCROLL_UP) ||
|
||||
(gdk_event_get_scroll_deltas (event, NULL, &y) && y <= 0)))
|
||||
return FALSE;
|
||||
|
||||
window->view_stuck = FALSE;
|
||||
@@ -263,10 +271,11 @@ xtm_process_window_unstick_view_cursor (GtkTreeView *tree_view, XtmProcessWindow
|
||||
{
|
||||
GtkTreePath *cursor, *end;
|
||||
|
||||
if (! window->view_stuck)
|
||||
if (!window->view_stuck)
|
||||
return;
|
||||
|
||||
if (gtk_tree_view_get_visible_range (tree_view, NULL, &end)) {
|
||||
if (gtk_tree_view_get_visible_range (tree_view, NULL, &end))
|
||||
{
|
||||
gtk_tree_view_get_cursor (tree_view, &cursor, NULL);
|
||||
if (cursor != NULL && gtk_tree_path_compare (cursor, end) >= 0)
|
||||
window->view_stuck = FALSE;
|
||||
@@ -298,17 +307,15 @@ xtm_process_window_init (XtmProcessWindow *window)
|
||||
|
||||
g_signal_connect_swapped (window->window, "destroy", G_CALLBACK (emit_destroy_signal), window);
|
||||
window->handler = g_signal_connect (window->window, "size-allocate", G_CALLBACK (xtm_process_window_size_allocate), window);
|
||||
g_signal_connect_swapped (window->window, "key-press-event", G_CALLBACK(xtm_process_window_key_pressed), window);
|
||||
g_signal_connect_swapped (window->window, "key-press-event", G_CALLBACK (xtm_process_window_key_pressed), window);
|
||||
|
||||
button = GTK_WIDGET (gtk_builder_get_object (window->builder, "button-settings"));
|
||||
g_signal_connect (G_OBJECT (button), "clicked",
|
||||
G_CALLBACK (show_settings_dialog), window);
|
||||
g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (show_settings_dialog), window);
|
||||
|
||||
button = GTK_WIDGET (gtk_builder_get_object (window->builder, "button-identify"));
|
||||
#ifdef HAVE_LIBX11
|
||||
if (GDK_IS_X11_DISPLAY (gdk_display_get_default ()))
|
||||
g_signal_connect (G_OBJECT (button), "clicked",
|
||||
G_CALLBACK (xwininfo_clicked_cb), window);
|
||||
g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (xwininfo_clicked_cb), window);
|
||||
else
|
||||
#endif
|
||||
gtk_widget_hide (button);
|
||||
@@ -369,9 +376,9 @@ xtm_process_window_init (XtmProcessWindow *window)
|
||||
g_signal_connect (window->treeview, "cursor-changed", G_CALLBACK (xtm_process_window_unstick_view_cursor), window);
|
||||
}
|
||||
|
||||
window->filter_entry = GTK_WIDGET(gtk_builder_get_object (window->builder, "filter-entry"));
|
||||
g_signal_connect (G_OBJECT(window->filter_entry), "icon-press", G_CALLBACK(filter_entry_icon_pressed_cb), NULL);
|
||||
g_signal_connect (G_OBJECT(window->filter_entry), "changed", G_CALLBACK(filter_entry_keyrelease_handler), window->treeview);
|
||||
window->filter_entry = GTK_WIDGET (gtk_builder_get_object (window->builder, "filter-entry"));
|
||||
g_signal_connect (G_OBJECT (window->filter_entry), "icon-press", G_CALLBACK (filter_entry_icon_pressed_cb), NULL);
|
||||
g_signal_connect (G_OBJECT (window->filter_entry), "changed", G_CALLBACK (filter_entry_keyrelease_handler), window->treeview);
|
||||
gtk_widget_set_tooltip_text (window->filter_entry, _("Filter on process name"));
|
||||
gtk_widget_grab_focus (window->filter_entry);
|
||||
|
||||
@@ -452,10 +459,10 @@ xtm_process_window_key_pressed (XtmProcessWindow *window, GdkEventKey *event)
|
||||
gboolean ret = FALSE;
|
||||
|
||||
if (event->keyval == GDK_KEY_Escape &&
|
||||
gtk_widget_is_focus(GTK_WIDGET (window->filter_entry)))
|
||||
gtk_widget_is_focus (GTK_WIDGET (window->filter_entry)))
|
||||
{
|
||||
if (xfconf_channel_get_bool (window->channel, SETTING_SHOW_FILTER, FALSE))
|
||||
gtk_entry_set_text (GTK_ENTRY(window->filter_entry), "");
|
||||
gtk_entry_set_text (GTK_ENTRY (window->filter_entry), "");
|
||||
else
|
||||
g_signal_emit_by_name (window, "delete-event", event, &ret, G_TYPE_BOOLEAN);
|
||||
}
|
||||
@@ -467,7 +474,7 @@ xtm_process_window_key_pressed (XtmProcessWindow *window, GdkEventKey *event)
|
||||
}
|
||||
else if (event->keyval == GDK_KEY_f && (event->state & GDK_CONTROL_MASK))
|
||||
{
|
||||
gtk_widget_grab_focus (GTK_WIDGET(window->filter_entry));
|
||||
gtk_widget_grab_focus (GTK_WIDGET (window->filter_entry));
|
||||
xfconf_channel_set_bool (window->channel, SETTING_SHOW_FILTER, TRUE);
|
||||
ret = TRUE;
|
||||
}
|
||||
@@ -501,7 +508,7 @@ xtm_process_window_show (GtkWidget *widget)
|
||||
g_return_if_fail (GTK_IS_WIDGET (XTM_PROCESS_WINDOW (widget)->window));
|
||||
gtk_widget_show (XTM_PROCESS_WINDOW (widget)->window);
|
||||
gtk_window_present (GTK_WINDOW (XTM_PROCESS_WINDOW (widget)->window));
|
||||
GTK_WIDGET_CLASS (xtm_process_window_parent_class)->show(widget);
|
||||
GTK_WIDGET_CLASS (xtm_process_window_parent_class)->show (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -514,7 +521,7 @@ xtm_process_window_hide (GtkWidget *widget)
|
||||
gtk_window_get_position (GTK_WINDOW (XTM_PROCESS_WINDOW (widget)->window), &winx, &winy);
|
||||
gtk_widget_hide (XTM_PROCESS_WINDOW (widget)->window);
|
||||
gtk_window_move (GTK_WINDOW (XTM_PROCESS_WINDOW (widget)->window), winx, winy);
|
||||
GTK_WIDGET_CLASS (xtm_process_window_parent_class)->hide(widget);
|
||||
GTK_WIDGET_CLASS (xtm_process_window_parent_class)->hide (widget);
|
||||
}
|
||||
|
||||
GtkTreeModel *
|
||||
@@ -526,7 +533,7 @@ xtm_process_window_get_model (XtmProcessWindow *window)
|
||||
}
|
||||
|
||||
void
|
||||
xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processes, gfloat cpu, gfloat memory, gchar* memory_str, gfloat swap, gchar* swap_str)
|
||||
xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processes, gfloat cpu, gfloat memory, gchar *memory_str, gfloat swap, gchar *swap_str)
|
||||
{
|
||||
gchar text[100];
|
||||
gchar value[4];
|
||||
@@ -537,12 +544,12 @@ xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processe
|
||||
g_object_set (window->statusbar, "num-processes", num_processes, "cpu", cpu, "memory", memory_str, "swap", swap_str, NULL);
|
||||
|
||||
xtm_process_monitor_add_peak (XTM_PROCESS_MONITOR (window->cpu_monitor), cpu / 100.0f, -1.0);
|
||||
g_snprintf (value, sizeof(value), "%.0f", cpu);
|
||||
g_snprintf (text, sizeof(text), _("CPU: %s%%"), value);
|
||||
g_snprintf (value, sizeof (value), "%.0f", cpu);
|
||||
g_snprintf (text, sizeof (text), _("CPU: %s%%"), value);
|
||||
gtk_widget_set_tooltip_text (window->cpu_monitor, text);
|
||||
|
||||
xtm_process_monitor_add_peak (XTM_PROCESS_MONITOR (window->mem_monitor), memory / 100.0f, swap / 100.0f);
|
||||
g_snprintf (text, sizeof(text), _("Memory: %s"), memory_str);
|
||||
g_snprintf (text, sizeof (text), _("Memory: %s"), memory_str);
|
||||
gtk_widget_set_tooltip_text (window->mem_monitor, text);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,23 +20,24 @@
|
||||
#define XTM_IS_PROCESS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XTM_TYPE_PROCESS_WINDOW))
|
||||
#define XTM_IS_PROCESS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XTM_TYPE_PROCESS_WINDOW))
|
||||
#define XTM_PROCESS_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_PROCESS_WINDOW, XtmProcessWindowClass))
|
||||
#define XTM_SHOW_MESSAGE(type, title, message, ...) { \
|
||||
#define XTM_SHOW_MESSAGE(type, title, message, ...) \
|
||||
{ \
|
||||
GtkWidget *dialog = gtk_message_dialog_new (NULL, 0, type, GTK_BUTTONS_OK, title); \
|
||||
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), message , ## __VA_ARGS__ ); \
|
||||
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), message, ##__VA_ARGS__); \
|
||||
gtk_window_set_title (GTK_WINDOW (dialog), _("Task Manager")); \
|
||||
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); \
|
||||
gtk_dialog_run (GTK_DIALOG (dialog)); \
|
||||
gtk_widget_destroy (dialog); \
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct _XtmProcessWindow XtmProcessWindow;
|
||||
|
||||
GType xtm_process_window_get_type (void);
|
||||
GtkWidget * xtm_process_window_new (void);
|
||||
GtkWidget *xtm_process_window_new (void);
|
||||
void xtm_process_window_settings_init (XtmProcessWindow *window, XfconfChannel *channel);
|
||||
void xtm_process_window_show (GtkWidget *widget);
|
||||
GtkTreeModel * xtm_process_window_get_model (XtmProcessWindow *window);
|
||||
void xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processes, gfloat cpu, gfloat memory, gchar* memory_str, gfloat swap, gchar* swap_str);
|
||||
GtkTreeModel *xtm_process_window_get_model (XtmProcessWindow *window);
|
||||
void xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processes, gfloat cpu, gfloat memory, gchar *memory_str, gfloat swap, gchar *swap_str);
|
||||
void xtm_process_window_show_swap_usage (XtmProcessWindow *window, gboolean show_swap_usage);
|
||||
|
||||
#endif /* !PROCESS_WINDOW_H */
|
||||
|
||||
@@ -58,7 +58,7 @@ combobox_changed (GtkComboBox *combobox, XtmSettings *settings)
|
||||
{
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter;
|
||||
GValue prop = { 0, };
|
||||
GValue prop = G_VALUE_INIT;
|
||||
gint rate;
|
||||
|
||||
gtk_combo_box_get_active_iter (combobox, &iter);
|
||||
@@ -69,17 +69,14 @@ combobox_changed (GtkComboBox *combobox, XtmSettings *settings)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
combobox_foreach (GtkTreeModel *model,
|
||||
GtkTreePath *path,
|
||||
GtkTreeIter *iter,
|
||||
gpointer user_data)
|
||||
combobox_foreach (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data)
|
||||
{
|
||||
XtmRefreshRate *refresh_rate = user_data;
|
||||
GValue prop = { 0, };
|
||||
GValue prop = G_VALUE_INIT;
|
||||
|
||||
gtk_tree_model_get_value (model, iter, 0, &prop);
|
||||
|
||||
if ((guint) g_value_get_int (&prop) == refresh_rate->rate)
|
||||
if ((guint)g_value_get_int (&prop) == refresh_rate->rate)
|
||||
{
|
||||
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (refresh_rate->combobox), iter);
|
||||
return TRUE;
|
||||
@@ -134,7 +131,8 @@ show_about_dialog (GtkWidget *widget, gpointer user_data)
|
||||
"OpenSolaris",
|
||||
" \342\200\242 Mike Massonnet",
|
||||
" \342\200\242 Peter Tribble",
|
||||
NULL };
|
||||
NULL
|
||||
};
|
||||
const gchar *license =
|
||||
"This program is free software; you can redistribute it and/or modify\n"
|
||||
"it under the terms of the GNU General Public License as published by\n"
|
||||
|
||||
@@ -129,7 +129,6 @@ xtm_settings_class_init (XtmSettingsClass *klass)
|
||||
static void
|
||||
xtm_settings_init (XtmSettings *settings)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -64,7 +64,7 @@ typedef struct _XtmSettings XtmSettings;
|
||||
|
||||
void xtm_settings_bind_xfconf (XtmSettings *settings, XfconfChannel *channel);
|
||||
GType xtm_settings_get_type (void);
|
||||
XtmSettings * xtm_settings_get_default (void);
|
||||
XtmSettings *xtm_settings_get_default (void);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -47,7 +47,8 @@ char *state_abbrev[] = {
|
||||
"", "start", "run", "sleep", "stop", "zomb", "dead", "onproc"
|
||||
};
|
||||
|
||||
gboolean get_task_list (GArray *task_list)
|
||||
gboolean
|
||||
get_task_list (GArray *task_list)
|
||||
{
|
||||
int mib[6];
|
||||
size_t size;
|
||||
@@ -58,7 +59,7 @@ gboolean get_task_list (GArray *task_list)
|
||||
#endif
|
||||
Task t;
|
||||
char **args;
|
||||
gchar* buf;
|
||||
gchar *buf;
|
||||
int nproc, i;
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
@@ -70,85 +71,88 @@ gboolean get_task_list (GArray *task_list)
|
||||
mib[2] = KERN_PROC_ALL;
|
||||
mib[3] = 0;
|
||||
#ifdef __OpenBSD__
|
||||
mib[4] = sizeof(struct kinfo_proc);
|
||||
mib[4] = sizeof (struct kinfo_proc);
|
||||
#else
|
||||
mib[4] = sizeof(struct kinfo_proc2);
|
||||
mib[4] = sizeof (struct kinfo_proc2);
|
||||
#endif
|
||||
mib[5] = 0;
|
||||
if (sysctl(mib, 6, NULL, &size, NULL, 0) < 0)
|
||||
if (sysctl (mib, 6, NULL, &size, NULL, 0) < 0)
|
||||
#ifdef __OpenBSD__
|
||||
errx(1, "could not get kern.proc size");
|
||||
errx (1, "could not get kern.proc size");
|
||||
#else
|
||||
errx(1, "could not get kern.proc2 size");
|
||||
errx (1, "could not get kern.proc2 size");
|
||||
#endif
|
||||
size = 5 * size / 4; /* extra slop */
|
||||
if ((kp = malloc(size)) == NULL)
|
||||
errx(1,"failed to allocate memory for proc structures");
|
||||
if ((kp = malloc (size)) == NULL)
|
||||
errx (1, "failed to allocate memory for proc structures");
|
||||
#ifdef __OpenBSD__
|
||||
mib[5] = (int)(size / sizeof(struct kinfo_proc));
|
||||
mib[5] = (int)(size / sizeof (struct kinfo_proc));
|
||||
#else
|
||||
mib[5] = (int)(size / sizeof(struct kinfo_proc2));
|
||||
mib[5] = (int)(size / sizeof (struct kinfo_proc2));
|
||||
#endif
|
||||
if (sysctl(mib, 6, kp, &size, NULL, 0) < 0)
|
||||
if (sysctl (mib, 6, kp, &size, NULL, 0) < 0)
|
||||
#ifdef __OpenBSD__
|
||||
errx(1, "could not read kern.proc");
|
||||
nproc = (int)(size / sizeof(struct kinfo_proc));
|
||||
errx (1, "could not read kern.proc");
|
||||
nproc = (int)(size / sizeof (struct kinfo_proc));
|
||||
#else
|
||||
errx(1, "could not read kern.proc2");
|
||||
nproc = (int)(size / sizeof(struct kinfo_proc2));
|
||||
errx (1, "could not read kern.proc2");
|
||||
nproc = (int)(size / sizeof (struct kinfo_proc2));
|
||||
#endif
|
||||
for (i=0 ; i < nproc ; i++)
|
||||
for (i = 0; i < nproc; i++)
|
||||
{
|
||||
#ifdef __OpenBSD__
|
||||
struct kinfo_proc p = kp[i];
|
||||
#else
|
||||
struct kinfo_proc2 p = kp[i];
|
||||
#endif
|
||||
memset(&t, 0, sizeof(t));
|
||||
memset (&t, 0, sizeof (t));
|
||||
t.pid = p.p_pid;
|
||||
t.ppid = p.p_ppid;
|
||||
t.uid = p.p_uid;
|
||||
t.prio = p.p_priority - PZERO;
|
||||
t.vsz = p.p_vm_dsize + p.p_vm_ssize + p.p_vm_tsize;
|
||||
t.vsz *= getpagesize();
|
||||
t.rss = p.p_vm_rssize * getpagesize();
|
||||
g_snprintf(t.state, sizeof t.state, "%s", state_abbrev[p.p_stat]);
|
||||
g_strlcpy(t.name, p.p_comm, strlen(p.p_comm) + 1);
|
||||
t.vsz *= getpagesize ();
|
||||
t.rss = p.p_vm_rssize * getpagesize ();
|
||||
g_snprintf (t.state, sizeof t.state, "%s", state_abbrev[p.p_stat]);
|
||||
g_strlcpy (t.name, p.p_comm, strlen (p.p_comm) + 1);
|
||||
/* shamelessly stolen from top/machine.c */
|
||||
if (!P_ZOMBIE(&p)) {
|
||||
if (!P_ZOMBIE (&p))
|
||||
{
|
||||
size = 1024;
|
||||
if ((args = malloc(size)) == NULL)
|
||||
errx(1,"failed to allocate memory for argv structures at %zu", size);
|
||||
memset(args, 0, size);
|
||||
for (;; size *= 2) {
|
||||
if ((args = realloc(args, size)) == NULL)
|
||||
errx(1,"failed to allocate memory (size=%zu) for argv structures of pid %d", size, t.pid);
|
||||
memset(args, 0, size);
|
||||
if ((args = malloc (size)) == NULL)
|
||||
errx (1, "failed to allocate memory for argv structures at %zu", size);
|
||||
memset (args, 0, size);
|
||||
for (;; size *= 2)
|
||||
{
|
||||
if ((args = realloc (args, size)) == NULL)
|
||||
errx (1, "failed to allocate memory (size=%zu) for argv structures of pid %d", size, t.pid);
|
||||
memset (args, 0, size);
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_PROC_ARGS;
|
||||
mib[2] = t.pid;
|
||||
mib[3] = KERN_PROC_ARGV;
|
||||
if (sysctl(mib, 4, args, &size, NULL, 0) == 0)
|
||||
if (sysctl (mib, 4, args, &size, NULL, 0) == 0)
|
||||
break;
|
||||
if (errno != ENOMEM) { /* ESRCH: process disappeared */
|
||||
if (errno != ENOMEM)
|
||||
{ /* ESRCH: process disappeared */
|
||||
/* printf ("process with pid %d disappeared, errno=%d\n", t.pid, errno); */
|
||||
args[0] ='\0';
|
||||
args[0] = '\0';
|
||||
args[1] = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
buf = g_strjoinv(" ", args);
|
||||
g_assert(g_utf8_validate(buf, -1, NULL));
|
||||
g_strlcpy(t.cmdline, buf, sizeof t.cmdline);
|
||||
g_free(buf);
|
||||
free(args);
|
||||
buf = g_strjoinv (" ", args);
|
||||
g_assert (g_utf8_validate (buf, -1, NULL));
|
||||
g_strlcpy (t.cmdline, buf, sizeof t.cmdline);
|
||||
g_free (buf);
|
||||
free (args);
|
||||
}
|
||||
|
||||
t.cpu_user = (100.0f * ((gfloat)p.p_pctcpu / FSCALE));
|
||||
t.cpu_system = 0.0f; /* TODO ? */
|
||||
g_array_append_val(task_list, t);
|
||||
g_array_append_val (task_list, t);
|
||||
}
|
||||
free(kp);
|
||||
free (kp);
|
||||
|
||||
g_array_sort (task_list, task_pid_compare_fn);
|
||||
|
||||
@@ -161,10 +165,10 @@ pid_is_sleeping (GPid pid)
|
||||
int mib[6];
|
||||
#ifdef __OpenBSD__
|
||||
struct kinfo_proc kp;
|
||||
size_t size = sizeof(struct kinfo_proc);
|
||||
size_t size = sizeof (struct kinfo_proc);
|
||||
#else
|
||||
struct kinfo_proc2 kp;
|
||||
size_t size = sizeof(struct kinfo_proc2);
|
||||
size_t size = sizeof (struct kinfo_proc2);
|
||||
#endif
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
@@ -176,30 +180,31 @@ pid_is_sleeping (GPid pid)
|
||||
mib[2] = KERN_PROC_PID;
|
||||
mib[3] = pid;
|
||||
#ifdef __OpenBSD__
|
||||
mib[4] = sizeof(struct kinfo_proc);
|
||||
mib[4] = sizeof (struct kinfo_proc);
|
||||
#else
|
||||
mib[4] = sizeof(struct kinfo_proc2);
|
||||
mib[4] = sizeof (struct kinfo_proc2);
|
||||
#endif
|
||||
mib[5] = 1;
|
||||
if (sysctl(mib, 6, &kp, &size, NULL, 0) < 0)
|
||||
if (sysctl (mib, 6, &kp, &size, NULL, 0) < 0)
|
||||
#ifdef __OpenBSD__
|
||||
errx(1, "could not read kern.proc for pid %d", pid);
|
||||
errx (1, "could not read kern.proc for pid %d", pid);
|
||||
#else
|
||||
errx(1, "could not read kern.proc2 for pid %d", pid);
|
||||
errx (1, "could not read kern.proc2 for pid %d", pid);
|
||||
#endif
|
||||
return (kp.p_stat == SSTOP ? TRUE : FALSE);
|
||||
}
|
||||
|
||||
gboolean get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
|
||||
gboolean
|
||||
get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
|
||||
{
|
||||
static gulong cur_user = 0, cur_system = 0, cur_total = 0;
|
||||
static gulong old_user = 0, old_system = 0, old_total = 0;
|
||||
|
||||
int mib[] = {CTL_KERN, KERN_CPTIME};
|
||||
int mib[] = { CTL_KERN, KERN_CPTIME };
|
||||
glong cp_time[CPUSTATES];
|
||||
gsize size = sizeof( cp_time );
|
||||
if (sysctl(mib, 2, &cp_time, &size, NULL, 0) < 0)
|
||||
errx(1,"failed to get kern.cptime");
|
||||
gsize size = sizeof (cp_time);
|
||||
if (sysctl (mib, 2, &cp_time, &size, NULL, 0) < 0)
|
||||
errx (1, "failed to get kern.cptime");
|
||||
|
||||
old_user = cur_user;
|
||||
old_system = cur_system;
|
||||
@@ -213,73 +218,76 @@ gboolean get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system
|
||||
*cpu_system = (old_total > 0) ? (((cur_system - old_system) * 100.0f) / (float)(cur_total - old_total)) : 0.0f;
|
||||
|
||||
/* get #cpu */
|
||||
size = sizeof(&cpu_count);
|
||||
size = sizeof (&cpu_count);
|
||||
mib[0] = CTL_HW;
|
||||
mib[1] = HW_NCPU;
|
||||
if (sysctl(mib, 2, cpu_count, &size, NULL, 0) == -1)
|
||||
errx(1,"failed to get cpu count");
|
||||
if (sysctl (mib, 2, cpu_count, &size, NULL, 0) == -1)
|
||||
errx (1, "failed to get cpu count");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* vmtotal values in #pg */
|
||||
#define pagetok(nb) ((nb) * (getpagesize()))
|
||||
#define pagetok(nb) ((nb) * (getpagesize ()))
|
||||
|
||||
gboolean
|
||||
get_memory_usage (guint64 *memory_total, guint64 *memory_available, guint64 *memory_free, guint64 *memory_cache, guint64 *memory_buffers, guint64 *swap_total, guint64 *swap_free)
|
||||
{
|
||||
#ifdef __OpenBSD__
|
||||
int mib[] = {CTL_VM, VM_UVMEXP};
|
||||
int mib[] = { CTL_VM, VM_UVMEXP };
|
||||
struct uvmexp uvmexp;
|
||||
#else
|
||||
int mib[] = {CTL_VM, VM_METER};
|
||||
int mib[] = { CTL_VM, VM_METER };
|
||||
struct vmtotal vmtotal;
|
||||
#endif
|
||||
struct swapent *swdev;
|
||||
int nswap, i;
|
||||
size_t size;
|
||||
#ifdef __OpenBSD__
|
||||
size = sizeof(uvmexp);
|
||||
if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0)
|
||||
errx(1,"failed to get vm.uvmexp");
|
||||
size = sizeof (uvmexp);
|
||||
if (sysctl (mib, 2, &uvmexp, &size, NULL, 0) < 0)
|
||||
errx (1, "failed to get vm.uvmexp");
|
||||
/* cheat : rm = tot used, add free to get total */
|
||||
*memory_free = pagetok((guint64)uvmexp.free);
|
||||
*memory_total = pagetok((guint64)uvmexp.npages);
|
||||
*memory_free = pagetok ((guint64)uvmexp.free);
|
||||
*memory_total = pagetok ((guint64)uvmexp.npages);
|
||||
*memory_cache = 0;
|
||||
*memory_buffers = 0; /*pagetok(uvmexp.npages - uvmexp.free - uvmexp.active);*/
|
||||
#else
|
||||
size = sizeof(vmtotal);
|
||||
if (sysctl(mib, 2, &vmtotal, &size, NULL, 0) < 0)
|
||||
errx(1,"failed to get vm.meter");
|
||||
size = sizeof (vmtotal);
|
||||
if (sysctl (mib, 2, &vmtotal, &size, NULL, 0) < 0)
|
||||
errx (1, "failed to get vm.meter");
|
||||
/* cheat : rm = tot used, add free to get total */
|
||||
*memory_total = pagetok(vmtotal.t_rm + vmtotal.t_free);
|
||||
*memory_free = pagetok(vmtotal.t_free);
|
||||
*memory_total = pagetok (vmtotal.t_rm + vmtotal.t_free);
|
||||
*memory_free = pagetok (vmtotal.t_free);
|
||||
*memory_cache = 0;
|
||||
*memory_buffers = pagetok(vmtotal.t_rm - vmtotal.t_arm);
|
||||
*memory_buffers = pagetok (vmtotal.t_rm - vmtotal.t_arm);
|
||||
#endif
|
||||
*memory_available = *memory_free + *memory_cache + *memory_buffers;
|
||||
|
||||
/* get swap stats */
|
||||
*swap_total = *swap_free = 0;
|
||||
if ((nswap = swapctl(SWAP_NSWAP, 0, 0)) == 0)
|
||||
if ((nswap = swapctl (SWAP_NSWAP, 0, 0)) == 0)
|
||||
return TRUE;
|
||||
|
||||
if ((swdev = calloc(nswap, sizeof(*swdev))) == NULL)
|
||||
errx(1,"failed to allocate memory for swdev structures");
|
||||
if ((swdev = calloc (nswap, sizeof (*swdev))) == NULL)
|
||||
errx (1, "failed to allocate memory for swdev structures");
|
||||
|
||||
if (swapctl(SWAP_STATS, swdev, nswap) == -1) {
|
||||
free(swdev);
|
||||
errx(1,"failed to get swap stats");
|
||||
if (swapctl (SWAP_STATS, swdev, nswap) == -1)
|
||||
{
|
||||
free (swdev);
|
||||
errx (1, "failed to get swap stats");
|
||||
}
|
||||
|
||||
/* Total things up */
|
||||
for (i = 0; i < nswap; i++) {
|
||||
if (swdev[i].se_flags & SWF_ENABLE) {
|
||||
for (i = 0; i < nswap; i++)
|
||||
{
|
||||
if (swdev[i].se_flags & SWF_ENABLE)
|
||||
{
|
||||
*swap_free += (swdev[i].se_nblks - swdev[i].se_inuse);
|
||||
*swap_total += swdev[i].se_nblks;
|
||||
}
|
||||
}
|
||||
*swap_total *= DEV_BSIZE;
|
||||
*swap_free *= DEV_BSIZE;
|
||||
free(swdev);
|
||||
free (swdev);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ get_memory_usage (guint64 *memory_total, guint64 *memory_available, guint64 *mem
|
||||
{
|
||||
/* Get memory usage */
|
||||
{
|
||||
*memory_total = get_mem_by_bytes ("hw.physmem");;
|
||||
*memory_total = get_mem_by_bytes ("hw.physmem");
|
||||
*memory_free = get_mem_by_pages ("vm.stats.vm.v_free_count");
|
||||
*memory_cache = get_mem_by_pages ("vm.stats.vm.v_inactive_count");
|
||||
*memory_buffers = get_mem_by_bytes ("vfs.bufspace");
|
||||
@@ -139,7 +139,7 @@ get_task_details (struct kinfo_proc *kp, Task *task)
|
||||
size_t bufsz;
|
||||
int i, oid[4];
|
||||
|
||||
memset(task, 0, sizeof(Task));
|
||||
memset (task, 0, sizeof (Task));
|
||||
task->pid = kp->ki_pid;
|
||||
task->ppid = kp->ki_ppid;
|
||||
task->cpu_user = 100.0f * ((float)kp->ki_pctcpu / FSCALE);
|
||||
@@ -148,39 +148,45 @@ get_task_details (struct kinfo_proc *kp, Task *task)
|
||||
task->rss = ((guint64)kp->ki_rssize * (guint64)getpagesize ());
|
||||
task->uid = kp->ki_uid;
|
||||
task->prio = kp->ki_nice;
|
||||
g_strlcpy (task->name, kp->ki_comm, sizeof(task->name));
|
||||
g_strlcpy (task->name, kp->ki_comm, sizeof (task->name));
|
||||
|
||||
oid[0] = CTL_KERN;
|
||||
oid[1] = KERN_PROC;
|
||||
oid[2] = KERN_PROC_ARGS;
|
||||
oid[3] = kp->ki_pid;
|
||||
bufsz = sizeof(buf);
|
||||
memset(buf, 0, sizeof(buf));
|
||||
if (sysctl(oid, 4, buf, &bufsz, 0, 0) == -1) {
|
||||
bufsz = sizeof (buf);
|
||||
memset (buf, 0, sizeof (buf));
|
||||
if (sysctl (oid, 4, buf, &bufsz, 0, 0) == -1)
|
||||
{
|
||||
/*
|
||||
* If the supplied buf is too short to hold the requested
|
||||
* value the sysctl returns with ENOMEM. The buf is filled
|
||||
* with the truncated value and the returned bufsz is equal
|
||||
* to the requested len.
|
||||
*/
|
||||
if (errno != ENOMEM || bufsz != sizeof(buf)) {
|
||||
if (errno != ENOMEM || bufsz != sizeof (buf))
|
||||
{
|
||||
bufsz = 0;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
buf[(bufsz - 1)] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 != bufsz) {
|
||||
if (0 != bufsz)
|
||||
{
|
||||
p = buf;
|
||||
do {
|
||||
g_strlcat (task->cmdline, p, sizeof(task->cmdline));
|
||||
g_strlcat (task->cmdline, " ", sizeof(task->cmdline));
|
||||
p += (strlen(p) + 1);
|
||||
do
|
||||
{
|
||||
g_strlcat (task->cmdline, p, sizeof (task->cmdline));
|
||||
g_strlcat (task->cmdline, " ", sizeof (task->cmdline));
|
||||
p += (strlen (p) + 1);
|
||||
} while (p < buf + bufsz);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_strlcpy (task->cmdline, kp->ki_comm, sizeof(task->cmdline));
|
||||
g_strlcpy (task->cmdline, kp->ki_comm, sizeof (task->cmdline));
|
||||
}
|
||||
|
||||
i = 0;
|
||||
|
||||
@@ -22,19 +22,13 @@ get_memory_usage (guint64 *memory_total, guint64 *memory_available, guint64 *mem
|
||||
{
|
||||
FILE *file;
|
||||
gchar *filename = "/proc/meminfo";
|
||||
guint64 mem_total = 0,
|
||||
mem_free = 0,
|
||||
mem_avail = 0,
|
||||
mem_cached = 0,
|
||||
mem_buffers = 0,
|
||||
swp_total = 0,
|
||||
swp_free = 0;
|
||||
guint64 mem_total = 0, mem_free = 0, mem_avail = 0, mem_cached = 0, mem_buffers = 0, swp_total = 0, swp_free = 0;
|
||||
|
||||
if ((file = fopen (filename, "r")) != NULL)
|
||||
{
|
||||
gint found = 0;
|
||||
gchar buffer[256];
|
||||
while (found < 7 && fgets (buffer, sizeof(buffer), file) != NULL)
|
||||
while (found < 7 && fgets (buffer, sizeof (buffer), file) != NULL)
|
||||
{
|
||||
found += !mem_total ? sscanf (buffer, "MemTotal:\t%lu kB", &mem_total) : 0;
|
||||
found += !mem_free ? sscanf (buffer, "MemFree:\t%lu kB", &mem_free) : 0;
|
||||
@@ -75,7 +69,7 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
|
||||
|
||||
if ((file = fopen (filename, "r")) == NULL)
|
||||
return FALSE;
|
||||
if (fgets (buffer, sizeof(buffer), file) == NULL)
|
||||
if (fgets (buffer, sizeof (buffer), file) == NULL)
|
||||
{
|
||||
fclose (file);
|
||||
return FALSE;
|
||||
@@ -85,7 +79,7 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
|
||||
|
||||
if (_cpu_count == 0)
|
||||
{
|
||||
while (fgets (buffer, sizeof(buffer), file) != NULL)
|
||||
while (fgets (buffer, sizeof (buffer), file) != NULL)
|
||||
{
|
||||
if (buffer[0] != 'c' && buffer[1] != 'p' && buffer[2] != 'u')
|
||||
break;
|
||||
@@ -117,7 +111,8 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static inline int get_pagesize (void)
|
||||
static inline int
|
||||
get_pagesize (void)
|
||||
{
|
||||
static int pagesize = 0;
|
||||
if (pagesize == 0)
|
||||
@@ -137,7 +132,7 @@ get_task_cmdline (Task *task)
|
||||
gint i;
|
||||
gint c;
|
||||
|
||||
snprintf (filename, sizeof(filename), "/proc/%i/cmdline", task->pid);
|
||||
snprintf (filename, sizeof (filename), "/proc/%i/cmdline", task->pid);
|
||||
if ((file = fopen (filename, "r")) == NULL)
|
||||
return FALSE;
|
||||
|
||||
@@ -145,8 +140,8 @@ get_task_cmdline (Task *task)
|
||||
for (i = 0; (c = fgetc (file)) != EOF && i < (gint)sizeof (task->cmdline) - 1; i++)
|
||||
task->cmdline[i] = (c == '\0') ? ' ' : (gchar)c;
|
||||
task->cmdline[i] = '\0';
|
||||
if (i > 0 && task->cmdline[i-1] == ' ')
|
||||
task->cmdline[i-1] = '\0';
|
||||
if (i > 0 && task->cmdline[i - 1] == ' ')
|
||||
task->cmdline[i - 1] = '\0';
|
||||
fclose (file);
|
||||
|
||||
/* Kernel processes don't have a cmdline nor an exec path */
|
||||
@@ -155,8 +150,8 @@ get_task_cmdline (Task *task)
|
||||
size_t len = strlen (task->name);
|
||||
g_strlcpy (&task->cmdline[1], task->name, len + 1);
|
||||
task->cmdline[0] = '[';
|
||||
task->cmdline[len+1] = ']';
|
||||
task->cmdline[len+2] = '\0';
|
||||
task->cmdline[len + 1] = ']';
|
||||
task->cmdline[len + 2] = '\0';
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@@ -201,17 +196,17 @@ get_task_details (GPid pid, Task *task)
|
||||
gchar filename[96];
|
||||
gchar buffer[1024];
|
||||
|
||||
snprintf (filename, sizeof(filename), "/proc/%d/stat", pid);
|
||||
snprintf (filename, sizeof (filename), "/proc/%d/stat", pid);
|
||||
if ((file = fopen (filename, "r")) == NULL)
|
||||
return FALSE;
|
||||
if (fgets (buffer, sizeof(buffer), file) == NULL)
|
||||
if (fgets (buffer, sizeof (buffer), file) == NULL)
|
||||
{
|
||||
fclose (file);
|
||||
return FALSE;
|
||||
}
|
||||
fclose (file);
|
||||
|
||||
memset(task, 0, sizeof(Task));
|
||||
memset (task, 0, sizeof (Task));
|
||||
|
||||
/* Scanning the short process name is unreliable with scanf when it contains
|
||||
* spaces, retrieve it manually and fill the buffer */
|
||||
@@ -238,7 +233,7 @@ get_task_details (GPid pid, Task *task)
|
||||
gint idummy;
|
||||
gulong jiffies_user = 0, jiffies_system = 0;
|
||||
|
||||
sscanf(buffer, "%i %255s %1s %i %i %i %i %i %255s %255s %255s %255s %255s %lu %lu %i %i %i %d %i %i %i %llu %llu %255s %255s %255s %i %255s %255s %255s %255s %255s %255s %255s %255s %255s %255s %i %255s %255s",
|
||||
sscanf (buffer, "%i %255s %1s %i %i %i %i %i %255s %255s %255s %255s %255s %lu %lu %i %i %i %d %i %i %i %llu %llu %255s %255s %255s %i %255s %255s %255s %255s %255s %255s %255s %255s %255s %255s %i %255s %255s",
|
||||
&task->pid, // processid
|
||||
dummy, // processname
|
||||
task->state, // processstate
|
||||
@@ -255,7 +250,7 @@ get_task_details (GPid pid, Task *task)
|
||||
dummy, // majflt
|
||||
dummy, // cmajflt
|
||||
&jiffies_user, // utime the number of jiffies that this process has scheduled in user mode
|
||||
&jiffies_system,// stime " system mode
|
||||
&jiffies_system, // stime " system mode
|
||||
|
||||
&idummy, // cutime " waited for children in user mode
|
||||
&idummy, // cstime " system mode
|
||||
@@ -265,8 +260,8 @@ get_task_details (GPid pid, Task *task)
|
||||
|
||||
&idummy, // itrealvalue time in jiffies to next SIGALRM send to this process
|
||||
&idummy, // starttime jiffies the process startet after system boot
|
||||
(unsigned long long*)&task->vsz, // vsize in bytes
|
||||
(unsigned long long*)&task->rss, // rss (number of pages in real memory)
|
||||
(unsigned long long *)&task->vsz, // vsize in bytes
|
||||
(unsigned long long *)&task->rss, // rss (number of pages in real memory)
|
||||
dummy, // rlim limit in bytes for rss
|
||||
|
||||
dummy, // startcode
|
||||
@@ -287,8 +282,7 @@ get_task_details (GPid pid, Task *task)
|
||||
&idummy, // CPU number last executed on
|
||||
dummy,
|
||||
|
||||
dummy
|
||||
);
|
||||
dummy);
|
||||
|
||||
task->rss *= get_pagesize ();
|
||||
get_cpu_percent (task->pid, jiffies_user, &task->cpu_user, jiffies_system, &task->cpu_system);
|
||||
@@ -298,11 +292,11 @@ get_task_details (GPid pid, Task *task)
|
||||
{
|
||||
guint dummy;
|
||||
|
||||
snprintf(filename, sizeof (filename), "/proc/%d/status", pid);
|
||||
snprintf (filename, sizeof (filename), "/proc/%d/status", pid);
|
||||
if ((file = fopen (filename, "r")) == NULL)
|
||||
return FALSE;
|
||||
|
||||
while (fgets (buffer, sizeof(buffer), file) != NULL)
|
||||
while (fgets (buffer, sizeof (buffer), file) != NULL)
|
||||
{
|
||||
if (sscanf (buffer, "Uid:\t%u\t%u\t%u\t%u", &dummy, &task->uid, &dummy, &dummy) == 1) // UIDs in order: real, effective, saved set, and filesystem
|
||||
break;
|
||||
@@ -328,7 +322,7 @@ get_task_list (GArray *task_list)
|
||||
if ((dir = g_dir_open ("/proc", 0, NULL)) == NULL)
|
||||
return FALSE;
|
||||
|
||||
while ((name = g_dir_read_name(dir)) != NULL)
|
||||
while ((name = g_dir_read_name (dir)) != NULL)
|
||||
{
|
||||
if ((pid = (GPid)g_ascii_strtoull (name, NULL, 0)) > 0)
|
||||
{
|
||||
@@ -354,11 +348,11 @@ pid_is_sleeping (GPid pid)
|
||||
gchar buffer[1024];
|
||||
gchar state[2];
|
||||
|
||||
snprintf (filename, sizeof(filename), "/proc/%i/status", pid);
|
||||
snprintf (filename, sizeof (filename), "/proc/%i/status", pid);
|
||||
if ((file = fopen (filename, "r")) == NULL)
|
||||
return FALSE;
|
||||
|
||||
while (fgets (buffer, sizeof(buffer), file) != NULL)
|
||||
while (fgets (buffer, sizeof (buffer), file) != NULL)
|
||||
{
|
||||
if (sscanf (buffer, "State:\t%1s", state) > 0)
|
||||
break;
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
/* Add includes for system functions needed */
|
||||
/* Example:
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
@@ -52,9 +52,9 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
|
||||
static gboolean
|
||||
get_task_details (GPid pid, Task *task)
|
||||
{
|
||||
memset(task, 0, sizeof(Task));
|
||||
g_snprintf (task->name, sizeof(task->name), "foo");
|
||||
g_snprintf (task->cmdline, sizeof(task->cmdline), "foo -bar");
|
||||
memset (task, 0, sizeof (Task));
|
||||
g_snprintf (task->name, sizeof (task->name), "foo");
|
||||
g_snprintf (task->cmdline, sizeof (task->cmdline), "foo -bar");
|
||||
task->uid = 1000;
|
||||
|
||||
return TRUE;
|
||||
@@ -66,16 +66,10 @@ get_task_list (GArray *task_list)
|
||||
GPid pid = 0;
|
||||
Task task;
|
||||
|
||||
//while (/* read all PIDs */)
|
||||
{
|
||||
// if (/* pid is valid */)
|
||||
{
|
||||
if (get_task_details (pid, &task))
|
||||
{
|
||||
g_array_append_val (task_list, task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_array_sort (task_list, task_pid_compare_fn);
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ get_memory_usage (guint64 *memory_total, guint64 *memory_available, guint64 *mem
|
||||
gint n;
|
||||
|
||||
if (!kc)
|
||||
init_stats();
|
||||
init_stats ();
|
||||
|
||||
if (!(ksp = kstat_lookup (kc, "unix", 0, "system_pages")))
|
||||
return FALSE;
|
||||
@@ -177,7 +177,7 @@ get_task_details (GPid pid, Task *task)
|
||||
gchar filename[96];
|
||||
psinfo_t process;
|
||||
|
||||
snprintf (filename, sizeof(filename), "/proc/%d/psinfo", pid);
|
||||
snprintf (filename, sizeof (filename), "/proc/%d/psinfo", pid);
|
||||
if ((file = fopen (filename, "r")) == NULL)
|
||||
return FALSE;
|
||||
|
||||
@@ -187,12 +187,12 @@ get_task_details (GPid pid, Task *task)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
memset(task, 0, sizeof(Task));
|
||||
memset (task, 0, sizeof (Task));
|
||||
task->pid = process.pr_pid;
|
||||
task->ppid = process.pr_ppid;
|
||||
g_strlcpy (task->name, process.pr_fname, sizeof(task->name));
|
||||
snprintf (task->cmdline, sizeof(task->cmdline), "%s", process.pr_psargs);
|
||||
snprintf (task->state, sizeof(task->state), "%c", process.pr_lwp.pr_sname);
|
||||
g_strlcpy (task->name, process.pr_fname, sizeof (task->name));
|
||||
snprintf (task->cmdline, sizeof (task->cmdline), "%s", process.pr_psargs);
|
||||
snprintf (task->state, sizeof (task->state), "%c", process.pr_lwp.pr_sname);
|
||||
task->vsz = (guint64)process.pr_size * 1024;
|
||||
task->rss = (guint64)process.pr_rssize * 1024;
|
||||
task->prio = process.pr_lwp.pr_pri;
|
||||
@@ -215,12 +215,12 @@ get_task_list (GArray *task_list)
|
||||
if ((dir = g_dir_open ("/proc", 0, NULL)) == NULL)
|
||||
return FALSE;
|
||||
|
||||
while ((name = g_dir_read_name(dir)) != NULL)
|
||||
while ((name = g_dir_read_name (dir)) != NULL)
|
||||
{
|
||||
if ((pid = (GPid)g_ascii_strtoull (name, NULL, 0)) > 0)
|
||||
{
|
||||
if (get_task_details (pid, &task))
|
||||
g_array_append_val(task_list, task);
|
||||
g_array_append_val (task_list, task);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ pid_is_sleeping (GPid pid)
|
||||
gchar state[2];
|
||||
psinfo_t process;
|
||||
|
||||
snprintf (filename, sizeof(filename), "/proc/%d/psinfo", pid);
|
||||
snprintf (filename, sizeof (filename), "/proc/%d/psinfo", pid);
|
||||
if ((file = fopen (filename, "r")) == NULL)
|
||||
return FALSE;
|
||||
|
||||
@@ -249,7 +249,7 @@ pid_is_sleeping (GPid pid)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
snprintf (state, sizeof(state), "%c", process.pr_lwp.pr_sname);
|
||||
snprintf (state, sizeof (state), "%c", process.pr_lwp.pr_sname);
|
||||
fclose (file);
|
||||
|
||||
return (state[0] == 'T') ? TRUE : FALSE;
|
||||
|
||||
@@ -46,10 +46,10 @@ struct _XtmTaskManager
|
||||
GObject parent;
|
||||
/*<private>*/
|
||||
#ifdef HAVE_WNCK
|
||||
XtmAppManager * app_manager;
|
||||
XtmAppManager *app_manager;
|
||||
#endif
|
||||
GtkTreeModel * model;
|
||||
GArray * tasks;
|
||||
GtkTreeModel *model;
|
||||
GArray *tasks;
|
||||
gushort cpu_count;
|
||||
gfloat cpu_user;
|
||||
gfloat cpu_system;
|
||||
@@ -87,7 +87,8 @@ static void
|
||||
xtm_task_manager_init (XtmTaskManager *manager)
|
||||
{
|
||||
#ifdef HAVE_WNCK
|
||||
if (GDK_IS_X11_DISPLAY (gdk_display_get_default ())) {
|
||||
if (GDK_IS_X11_DISPLAY (gdk_display_get_default ()))
|
||||
{
|
||||
manager->app_manager = xtm_app_manager_new ();
|
||||
}
|
||||
#endif
|
||||
@@ -107,7 +108,8 @@ xtm_task_manager_finalize (GObject *object)
|
||||
XtmTaskManager *manager = XTM_TASK_MANAGER (object);
|
||||
g_array_free (manager->tasks, TRUE);
|
||||
#ifdef HAVE_WNCK
|
||||
if (manager->app_manager != NULL) {
|
||||
if (manager->app_manager != NULL)
|
||||
{
|
||||
g_object_unref (manager->app_manager);
|
||||
}
|
||||
#endif
|
||||
@@ -132,38 +134,43 @@ pretty_cmdline (gchar *cmdline, gchar *comm)
|
||||
gsize csize, text_size = (gsize)strlen (text);
|
||||
|
||||
/* UTF-8 normalize. */
|
||||
do {
|
||||
do
|
||||
{
|
||||
for (ch = text, text_max = (text + text_size);
|
||||
text_max > ch;
|
||||
text_max = (text + text_size), ch = g_utf8_next_char(ch)) {
|
||||
c = g_utf8_get_char_validated(ch, -1); /* If use (text_max - ch) - result is worse. */
|
||||
if ((gunichar)-2 == c) {
|
||||
text_max = (text + text_size), ch = g_utf8_next_char (ch))
|
||||
{
|
||||
c = g_utf8_get_char_validated (ch, -1); /* If use (text_max - ch) - result is worse. */
|
||||
if ((gunichar)-2 == c)
|
||||
{
|
||||
text_size = (gsize)(ch - text);
|
||||
(*ch) = 0;
|
||||
break;
|
||||
}
|
||||
if ((gunichar)-1 == c) {
|
||||
if ((gunichar)-1 == c)
|
||||
{
|
||||
(*ch) = ' ';
|
||||
continue;
|
||||
}
|
||||
csize = (gsize)g_unichar_to_utf8(c, NULL);
|
||||
csize = (gsize)g_unichar_to_utf8 (c, NULL);
|
||||
|
||||
if (!g_unichar_isdefined(c) ||
|
||||
!g_unichar_isprint(c) ||
|
||||
(g_unichar_isspace(c) && (1 != csize || (' ' != (*ch) && ' ' != (*ch)))) ||
|
||||
g_unichar_ismark(c) ||
|
||||
g_unichar_istitle(c) ||
|
||||
g_unichar_iswide(c) ||
|
||||
g_unichar_iszerowidth(c) ||
|
||||
g_unichar_iscntrl(c)) {
|
||||
if (!g_unichar_isdefined (c) ||
|
||||
!g_unichar_isprint (c) ||
|
||||
(g_unichar_isspace (c) && (1 != csize || (' ' != (*ch) && ' ' != (*ch)))) ||
|
||||
g_unichar_ismark (c) ||
|
||||
g_unichar_istitle (c) ||
|
||||
g_unichar_iswide (c) ||
|
||||
g_unichar_iszerowidth (c) ||
|
||||
g_unichar_iscntrl (c))
|
||||
{
|
||||
if (text_max < (ch + csize))
|
||||
break;
|
||||
memmove(ch, (ch + csize), (gsize)(text_max - (ch + csize)));
|
||||
memmove (ch, (ch + csize), (gsize)(text_max - (ch + csize)));
|
||||
text_size -= csize;
|
||||
}
|
||||
}
|
||||
text[text_size] = 0;
|
||||
} while (!g_utf8_validate(text, (gssize)text_size, NULL));
|
||||
} while (!g_utf8_validate (text, (gssize)text_size, NULL));
|
||||
|
||||
if (!full_cmdline && text_size > 3)
|
||||
{
|
||||
@@ -203,7 +210,7 @@ model_add_task (XtmTaskManager *manager, Task *task, glong timestamp)
|
||||
XTM_PTV_COLUMN_UID_STR, uid_name,
|
||||
XTM_PTV_COLUMN_TIMESTAMP, timestamp,
|
||||
-1);
|
||||
g_free(uid_name);
|
||||
g_free (uid_name);
|
||||
model_update_tree_iter (manager, &iter, timestamp, TRUE, task);
|
||||
}
|
||||
|
||||
@@ -246,11 +253,11 @@ model_update_tree_iter (XtmTaskManager *manager, GtkTreeIter *iter, glong timest
|
||||
group_vsz = g_format_size_full (task->group_vsz, G_FORMAT_SIZE_IEC_UNITS);
|
||||
group_rss = g_format_size_full (task->group_rss, G_FORMAT_SIZE_IEC_UNITS);
|
||||
|
||||
g_snprintf (value, sizeof(value), (more_precision) ? "%.2f" : "%.0f", (task->cpu_user + task->cpu_system));
|
||||
g_snprintf (cpu, sizeof(cpu), _("%s%%"), value);
|
||||
g_snprintf (value, sizeof (value), (more_precision) ? "%.2f" : "%.0f", (task->cpu_user + task->cpu_system));
|
||||
g_snprintf (cpu, sizeof (cpu), _("%s%%"), value);
|
||||
|
||||
g_snprintf (value, sizeof(value), (more_precision) ? "%.2f" : "%.0f", (task->group_cpu_user + task->group_cpu_system));
|
||||
g_snprintf (group_cpu, sizeof(group_cpu), _("%s%%"), value);
|
||||
g_snprintf (value, sizeof (value), (more_precision) ? "%.2f" : "%.0f", (task->group_cpu_user + task->group_cpu_system));
|
||||
g_snprintf (group_cpu, sizeof (group_cpu), _("%s%%"), value);
|
||||
|
||||
/* Retrieve values for tweaking background/foreground color and updating content as needed */
|
||||
gtk_tree_model_get (model, iter,
|
||||
@@ -346,9 +353,10 @@ task_list_find_for_pid (GArray *task_list, GPid pid, Task **task, guint *idx)
|
||||
{
|
||||
Task *task_tmp = NULL, tkey;
|
||||
|
||||
if (task_list->data != NULL) {
|
||||
if (task_list->data != NULL)
|
||||
{
|
||||
tkey.pid = pid;
|
||||
task_tmp = bsearch(&tkey, task_list->data, task_list->len, sizeof(Task), task_pid_compare_fn);
|
||||
task_tmp = bsearch (&tkey, task_list->data, task_list->len, sizeof (Task), task_pid_compare_fn);
|
||||
}
|
||||
|
||||
if (NULL != task)
|
||||
@@ -359,7 +367,7 @@ task_list_find_for_pid (GArray *task_list, GPid pid, Task **task, guint *idx)
|
||||
{
|
||||
if (NULL != task_tmp)
|
||||
{
|
||||
(*idx) = (guint)(((size_t)task_tmp - (size_t)task_list->data) / sizeof(Task));
|
||||
(*idx) = (guint)(((size_t)task_tmp - (size_t)task_list->data) / sizeof (Task));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -438,11 +446,11 @@ xtm_task_manager_task_aggregate_children (Task *task, GArray *task_list)
|
||||
|
||||
for (guint i = 0; i < task_list->len; ++i)
|
||||
{
|
||||
Task *child_task = &g_array_index(task_list, Task, i);
|
||||
Task *child_task = &g_array_index (task_list, Task, i);
|
||||
if (child_task->ppid != task->pid)
|
||||
continue;
|
||||
|
||||
xtm_task_manager_task_aggregate_children(child_task, task_list);
|
||||
xtm_task_manager_task_aggregate_children (child_task, task_list);
|
||||
|
||||
task->group_cpu_system += child_task->group_cpu_system;
|
||||
task->group_cpu_user += child_task->group_cpu_user;
|
||||
@@ -456,7 +464,7 @@ xtm_task_manager_aggregate_children (GArray *task_list)
|
||||
{
|
||||
for (guint i = 0; i < task_list->len; ++i)
|
||||
{
|
||||
Task *task = &g_array_index(task_list, Task, i);
|
||||
Task *task = &g_array_index (task_list, Task, i);
|
||||
task->group_cpu_system = -1;
|
||||
task->group_cpu_user = -1;
|
||||
task->group_vsz = -1;
|
||||
@@ -465,7 +473,7 @@ xtm_task_manager_aggregate_children (GArray *task_list)
|
||||
|
||||
for (guint i = 0; i < task_list->len; ++i)
|
||||
{
|
||||
Task *task = &g_array_index(task_list, Task, i);
|
||||
Task *task = &g_array_index (task_list, Task, i);
|
||||
xtm_task_manager_task_aggregate_children (task, task_list);
|
||||
}
|
||||
}
|
||||
@@ -506,7 +514,8 @@ xtm_task_manager_update_model (XtmTaskManager *manager)
|
||||
g_free (cpu_str);
|
||||
if (found)
|
||||
{
|
||||
if ((timestamp - old_timestamp) > TIMESTAMP_DELTA) {
|
||||
if ((timestamp - old_timestamp) > TIMESTAMP_DELTA)
|
||||
{
|
||||
G_DEBUG_FMT ("Remove old task %d", pid);
|
||||
model_remove_tree_iter (manager->model, &cur_iter);
|
||||
}
|
||||
@@ -534,12 +543,12 @@ xtm_task_manager_update_model (XtmTaskManager *manager)
|
||||
update_cmd_line = FALSE;
|
||||
|
||||
/* Update the model (with the rest) only if needed, this keeps the CPU cool */
|
||||
if (model_update_forced || 0 != memcmp(task, task_new, sizeof(Task)))
|
||||
if (model_update_forced || 0 != memcmp (task, task_new, sizeof (Task)))
|
||||
{
|
||||
need_update = TRUE;
|
||||
/* Update command name if needed (can happen) */
|
||||
update_cmd_line = (model_update_forced || g_strcmp0 (task->cmdline, task_new->cmdline));
|
||||
memcpy(task, task_new, sizeof(Task));
|
||||
memcpy (task, task_new, sizeof (Task));
|
||||
}
|
||||
else /* Update color if needed */
|
||||
{
|
||||
@@ -588,8 +597,8 @@ get_uid_name (guint uid)
|
||||
struct passwd *pw = NULL, pwd_buf;
|
||||
char buf[4096];
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
error = getpwuid_r(uid, &pwd_buf, buf, sizeof(buf), &pw);
|
||||
memset (buf, 0, sizeof (buf));
|
||||
error = getpwuid_r (uid, &pwd_buf, buf, sizeof (buf), &pw);
|
||||
|
||||
return (g_strdup ((0 == error && pw != NULL) ? pw->pw_name : "nobody"));
|
||||
}
|
||||
@@ -650,9 +659,9 @@ set_priority_to_pid (GPid pid, gint priority)
|
||||
}
|
||||
|
||||
gint
|
||||
task_pid_compare_fn(gconstpointer a, gconstpointer b)
|
||||
task_pid_compare_fn (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
return (((const Task*)a)->pid - ((const Task*)b)->pid);
|
||||
return ((const Task *)a)->pid - ((const Task *)b)->pid;
|
||||
}
|
||||
|
||||
/* About the constants used below, see for example: https://stackoverflow.com/a/596243 */
|
||||
|
||||
@@ -72,12 +72,12 @@ gboolean pid_is_sleeping (GPid pid);
|
||||
typedef struct _XtmTaskManager XtmTaskManager;
|
||||
|
||||
GType xtm_task_manager_get_type (void);
|
||||
XtmTaskManager * xtm_task_manager_new (GtkTreeModel *model);
|
||||
XtmTaskManager *xtm_task_manager_new (GtkTreeModel *model);
|
||||
void xtm_task_manager_get_system_info (XtmTaskManager *manager, guint *num_processes, gfloat *cpu,
|
||||
guint64 *memory_used, guint64 *memory_total,
|
||||
guint64 *swap_used, guint64 *swap_total);
|
||||
void xtm_task_manager_get_swap_usage (XtmTaskManager *manager, guint64 *swap_free, guint64 *swap_total);
|
||||
const GArray * xtm_task_manager_get_task_list (XtmTaskManager *manager);
|
||||
const GArray *xtm_task_manager_get_task_list (XtmTaskManager *manager);
|
||||
void xtm_task_manager_update_model (XtmTaskManager *manager);
|
||||
|
||||
/**
|
||||
@@ -101,20 +101,20 @@ enum
|
||||
XTM_PRIORITY_VERY_HIGH,
|
||||
};
|
||||
|
||||
gchar * get_uid_name (guint uid);
|
||||
gchar *get_uid_name (guint uid);
|
||||
gboolean send_signal_to_pid (GPid pid, gint xtm_signal);
|
||||
gint task_pid_compare_fn (gconstpointer a, gconstpointer b);
|
||||
gboolean set_priority_to_pid (GPid pid, gint priority);
|
||||
|
||||
|
||||
#ifndef __unused
|
||||
# define __unused __attribute__((__unused__))
|
||||
#define __unused __attribute__ ((__unused__))
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
# define G_DEBUG_FMT(fmt, args...) g_debug((fmt), ##args)
|
||||
#define G_DEBUG_FMT(fmt, args...) g_debug ((fmt), ##args)
|
||||
#else
|
||||
# define G_DEBUG_FMT(fmt, args...)
|
||||
#define G_DEBUG_FMT(fmt, args...)
|
||||
#endif
|
||||
|
||||
gboolean xtm_gtk_widget_is_dark_mode (GtkWidget *widget);
|
||||
|
||||
Reference in New Issue
Block a user