Apply .clang-format file
This commit is contained in:
@@ -22,28 +22,28 @@
|
|||||||
typedef struct _XtmAppManagerClass XtmAppManagerClass;
|
typedef struct _XtmAppManagerClass XtmAppManagerClass;
|
||||||
struct _XtmAppManagerClass
|
struct _XtmAppManagerClass
|
||||||
{
|
{
|
||||||
GObjectClass parent_class;
|
GObjectClass parent_class;
|
||||||
};
|
};
|
||||||
struct _XtmAppManager
|
struct _XtmAppManager
|
||||||
{
|
{
|
||||||
GObject parent;
|
GObject parent;
|
||||||
/*<private>*/
|
/*<private>*/
|
||||||
GArray * apps;
|
GArray *apps;
|
||||||
};
|
};
|
||||||
G_DEFINE_TYPE (XtmAppManager, xtm_app_manager, G_TYPE_OBJECT)
|
G_DEFINE_TYPE (XtmAppManager, xtm_app_manager, G_TYPE_OBJECT)
|
||||||
|
|
||||||
static void xtm_app_manager_finalize (GObject *object);
|
static void xtm_app_manager_finalize (GObject *object);
|
||||||
|
|
||||||
static GPid app_get_pid (WnckApplication *application);
|
static GPid app_get_pid (WnckApplication *application);
|
||||||
static gint app_pid_compare_fn (gconstpointer a, gconstpointer b);
|
static gint app_pid_compare_fn (gconstpointer a, gconstpointer b);
|
||||||
|
|
||||||
static void apps_add_application (GArray *apps, WnckApplication *application, GPid pid);
|
static void apps_add_application (GArray *apps, WnckApplication *application, GPid pid);
|
||||||
static void apps_remove_application (GArray *apps, WnckApplication *application);
|
static void apps_remove_application (GArray *apps, WnckApplication *application);
|
||||||
static App * apps_lookup_pid (GArray *apps, GPid pid);
|
static App *apps_lookup_pid (GArray *apps, GPid pid);
|
||||||
static App * apps_lookup_app (GArray *apps, WnckApplication *application);
|
static App *apps_lookup_app (GArray *apps, WnckApplication *application);
|
||||||
static void application_opened (WnckScreen *screen, WnckApplication *application, XtmAppManager *manager);
|
static void application_opened (WnckScreen *screen, WnckApplication *application, XtmAppManager *manager);
|
||||||
static void application_closed (WnckScreen *screen, WnckApplication *application, XtmAppManager *manager);
|
static void application_closed (WnckScreen *screen, WnckApplication *application, XtmAppManager *manager);
|
||||||
static void scale_factor_changed (GdkMonitor *monitor);
|
static void scale_factor_changed (GdkMonitor *monitor);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ xtm_app_manager_finalize (GObject *object)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static GPid
|
static GPid
|
||||||
app_get_pid(WnckApplication *application)
|
app_get_pid (WnckApplication *application)
|
||||||
{
|
{
|
||||||
GPid pid;
|
GPid pid;
|
||||||
GList *windows;
|
GList *windows;
|
||||||
@@ -120,9 +120,9 @@ app_get_pid(WnckApplication *application)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
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
|
static void
|
||||||
@@ -138,7 +138,7 @@ apps_add_application (GArray *apps, WnckApplication *application, GPid pid)
|
|||||||
|
|
||||||
app.application = application;
|
app.application = application;
|
||||||
app.pid = pid;
|
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);
|
monitor = gdk_display_get_monitor (gdk_display_get_default (), 0);
|
||||||
if (monitor != NULL)
|
if (monitor != NULL)
|
||||||
@@ -153,14 +153,14 @@ apps_add_application (GArray *apps, WnckApplication *application, GPid pid)
|
|||||||
static void
|
static void
|
||||||
apps_remove_application (GArray *apps, WnckApplication *application)
|
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)
|
if (app == NULL)
|
||||||
app = apps_lookup_app(apps, application);
|
app = apps_lookup_app (apps, application);
|
||||||
if (app == NULL)
|
if (app == NULL)
|
||||||
return;
|
return;
|
||||||
cairo_surface_destroy (app->surface);
|
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 *
|
static App *
|
||||||
@@ -173,7 +173,7 @@ apps_lookup_pid (GArray *apps, GPid pid)
|
|||||||
|
|
||||||
tapp.pid = 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 *
|
static App *
|
||||||
@@ -182,7 +182,8 @@ apps_lookup_app (GArray *apps, WnckApplication *application)
|
|||||||
App *tapp;
|
App *tapp;
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
for (i = 0; i < apps->len; i++) {
|
for (i = 0; i < apps->len; i++)
|
||||||
|
{
|
||||||
tapp = &g_array_index (apps, App, i);
|
tapp = &g_array_index (apps, App, i);
|
||||||
if (tapp->application == application)
|
if (tapp->application == application)
|
||||||
return (tapp);
|
return (tapp);
|
||||||
@@ -195,14 +196,14 @@ static void
|
|||||||
application_opened (WnckScreen *screen __unused, WnckApplication *application, XtmAppManager *manager)
|
application_opened (WnckScreen *screen __unused, WnckApplication *application, XtmAppManager *manager)
|
||||||
{
|
{
|
||||||
GPid pid = app_get_pid (application);
|
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);
|
apps_add_application (manager->apps, application, pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
application_closed (WnckScreen *screen __unused, WnckApplication *application, XtmAppManager *manager)
|
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);
|
apps_remove_application (manager->apps, application);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,23 +17,23 @@
|
|||||||
typedef struct _App App;
|
typedef struct _App App;
|
||||||
struct _App
|
struct _App
|
||||||
{
|
{
|
||||||
WnckApplication * application;
|
WnckApplication *application;
|
||||||
GPid pid;
|
GPid pid;
|
||||||
gchar name[1024];
|
gchar name[1024];
|
||||||
cairo_surface_t * surface;
|
cairo_surface_t *surface;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define XTM_TYPE_APP_MANAGER (xtm_app_manager_get_type ())
|
#define XTM_TYPE_APP_MANAGER (xtm_app_manager_get_type ())
|
||||||
#define XTM_APP_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XTM_TYPE_APP_MANAGER, XtmAppManager))
|
#define XTM_APP_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XTM_TYPE_APP_MANAGER, XtmAppManager))
|
||||||
#define XTM_APP_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XTM_TYPE_APP_MANAGER, XtmAppManagerClass))
|
#define XTM_APP_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XTM_TYPE_APP_MANAGER, XtmAppManagerClass))
|
||||||
#define XTM_IS_APP_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XTM_TYPE_APP_MANAGER))
|
#define XTM_IS_APP_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XTM_TYPE_APP_MANAGER))
|
||||||
#define XTM_IS_APP_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XTM_TYPE_APP_MANAGER))
|
#define XTM_IS_APP_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XTM_TYPE_APP_MANAGER))
|
||||||
#define XTM_APP_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_APP_MANAGER, XtmAppManagerClass))
|
#define XTM_APP_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_APP_MANAGER, XtmAppManagerClass))
|
||||||
|
|
||||||
typedef struct _XtmAppManager XtmAppManager;
|
typedef struct _XtmAppManager XtmAppManager;
|
||||||
|
|
||||||
GType xtm_app_manager_get_type (void);
|
GType xtm_app_manager_get_type (void);
|
||||||
XtmAppManager * xtm_app_manager_new (void);
|
XtmAppManager *xtm_app_manager_new (void);
|
||||||
App * xtm_app_manager_get_app_from_pid (XtmAppManager *manager, GPid pid);
|
App *xtm_app_manager_get_app_from_pid (XtmAppManager *manager, GPid pid);
|
||||||
|
|
||||||
#endif /* !APP_MANAGER_H */
|
#endif /* !APP_MANAGER_H */
|
||||||
|
|||||||
60
src/main.c
60
src/main.c
@@ -35,7 +35,7 @@ static GOptionEntry main_entries[] = {
|
|||||||
{ NULL, 0, 0, 0, NULL, NULL, NULL }
|
{ NULL, 0, 0, 0, NULL, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void destroy_window (void);
|
static void destroy_window (void);
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -62,9 +62,9 @@ status_icon_popup_menu (GtkStatusIcon *_status_icon, guint button, guint activat
|
|||||||
gtk_widget_show_all (menu);
|
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);
|
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
|
static void
|
||||||
@@ -72,9 +72,9 @@ create_status_icon (void)
|
|||||||
{
|
{
|
||||||
if (!status_icon_or_null)
|
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");
|
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, "activate", G_CALLBACK (status_icon_activated), NULL);
|
||||||
g_signal_connect (status_icon, "popup-menu", G_CALLBACK (status_icon_popup_menu), NULL);
|
g_signal_connect (status_icon, "popup-menu", G_CALLBACK (status_icon_popup_menu), NULL);
|
||||||
status_icon_or_null = status_icon;
|
status_icon_or_null = status_icon;
|
||||||
@@ -84,9 +84,9 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
|||||||
static gboolean
|
static gboolean
|
||||||
status_icon_get_visible (void)
|
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);
|
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
|
static void
|
||||||
@@ -97,22 +97,23 @@ show_hide_status_icon (void)
|
|||||||
if (show_status_icon)
|
if (show_status_icon)
|
||||||
{
|
{
|
||||||
create_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);
|
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 ())
|
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);
|
gtk_status_icon_set_visible (status_icon_or_null, FALSE);
|
||||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
destroy_window (void)
|
destroy_window (void)
|
||||||
{
|
{
|
||||||
if (gtk_main_level () > 0) {
|
if (gtk_main_level () > 0)
|
||||||
|
{
|
||||||
if (timer_id > 0)
|
if (timer_id > 0)
|
||||||
g_source_remove (timer_id);
|
g_source_remove (timer_id);
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
@@ -146,17 +147,17 @@ collect_data (void)
|
|||||||
memory_percent = (memory_total != 0) ? ((memory_used * 100.0f) / (float)memory_total) : 0.0f;
|
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;
|
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);
|
used = g_format_size_full (memory_used, G_FORMAT_SIZE_IEC_UNITS);
|
||||||
total = g_format_size_full(memory_total, 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_snprintf (memory_info, sizeof (memory_info), "%.0f%% (%s / %s)", memory_percent, used, total);
|
||||||
g_free(used);
|
g_free (used);
|
||||||
g_free(total);
|
g_free (total);
|
||||||
|
|
||||||
used = g_format_size_full(swap_used, G_FORMAT_SIZE_IEC_UNITS);
|
used = g_format_size_full (swap_used, G_FORMAT_SIZE_IEC_UNITS);
|
||||||
total = g_format_size_full(swap_total, 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_snprintf (swap_info, sizeof (swap_info), "%.0f%% (%s / %s)", swap_percent, used, total);
|
||||||
g_free(used);
|
g_free (used);
|
||||||
g_free(total);
|
g_free (total);
|
||||||
|
|
||||||
xtm_process_window_set_system_info (XTM_PROCESS_WINDOW (window), num_processes, cpu, memory_percent, memory_info, swap_percent, swap_info);
|
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 ())
|
if (status_icon_get_visible ())
|
||||||
{
|
{
|
||||||
g_snprintf (tooltip, sizeof(tooltip),
|
g_snprintf (tooltip, sizeof (tooltip),
|
||||||
_("<b>Processes:</b> %u\n"
|
_("<b>Processes:</b> %u\n"
|
||||||
"<b>CPU:</b> %.0f%%\n"
|
"<b>CPU:</b> %.0f%%\n"
|
||||||
"<b>Memory:</b> %s\n"
|
"<b>Memory:</b> %s\n"
|
||||||
"<b>Swap:</b> %s"),
|
"<b>Swap:</b> %s"),
|
||||||
num_processes, cpu, memory_info, swap_info);
|
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);
|
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);
|
xtm_task_manager_update_model (task_manager);
|
||||||
@@ -207,7 +208,8 @@ refresh_rate_changed (void)
|
|||||||
init_timeout ();
|
init_timeout ();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main (int argc, char *argv[])
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
XfconfChannel *channel;
|
XfconfChannel *channel;
|
||||||
GApplication *app;
|
GApplication *app;
|
||||||
@@ -293,7 +295,7 @@ int main (int argc, char *argv[])
|
|||||||
g_object_unref (settings);
|
g_object_unref (settings);
|
||||||
if (status_icon_or_null != NULL)
|
if (status_icon_or_null != NULL)
|
||||||
g_object_unref (status_icon_or_null);
|
g_object_unref (status_icon_or_null);
|
||||||
xfconf_shutdown();
|
xfconf_shutdown ();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,25 +26,25 @@ enum
|
|||||||
typedef struct _XtmProcessMonitorClass XtmProcessMonitorClass;
|
typedef struct _XtmProcessMonitorClass XtmProcessMonitorClass;
|
||||||
struct _XtmProcessMonitorClass
|
struct _XtmProcessMonitorClass
|
||||||
{
|
{
|
||||||
GtkDrawingAreaClass parent_class;
|
GtkDrawingAreaClass parent_class;
|
||||||
};
|
};
|
||||||
struct _XtmProcessMonitor
|
struct _XtmProcessMonitor
|
||||||
{
|
{
|
||||||
GtkDrawingArea parent;
|
GtkDrawingArea parent;
|
||||||
/*<private>*/
|
/*<private>*/
|
||||||
gfloat step_size;
|
gfloat step_size;
|
||||||
gint type;
|
gint type;
|
||||||
GArray * history;
|
GArray *history;
|
||||||
GArray * history_swap;
|
GArray *history_swap;
|
||||||
gboolean dark_mode;
|
gboolean dark_mode;
|
||||||
};
|
};
|
||||||
G_DEFINE_TYPE (XtmProcessMonitor, xtm_process_monitor, GTK_TYPE_DRAWING_AREA)
|
G_DEFINE_TYPE (XtmProcessMonitor, xtm_process_monitor, GTK_TYPE_DRAWING_AREA)
|
||||||
|
|
||||||
static void xtm_process_monitor_finalize (GObject *object);
|
static void xtm_process_monitor_finalize (GObject *object);
|
||||||
static void xtm_process_monitor_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
|
static void xtm_process_monitor_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
|
||||||
static void xtm_process_monitor_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
|
static void xtm_process_monitor_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
|
||||||
static gboolean xtm_process_monitor_draw (GtkWidget *widget, cairo_t *cr);
|
static gboolean xtm_process_monitor_draw (GtkWidget *widget, cairo_t *cr);
|
||||||
static void xtm_process_monitor_paint (XtmProcessMonitor *monitor, cairo_t *cr);
|
static void xtm_process_monitor_paint (XtmProcessMonitor *monitor, cairo_t *cr);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ xtm_process_monitor_class_init (XtmProcessMonitorClass *klass)
|
|||||||
widget_class->draw = xtm_process_monitor_draw;
|
widget_class->draw = xtm_process_monitor_draw;
|
||||||
|
|
||||||
g_object_class_install_property (class, PROP_STEP_SIZE,
|
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_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));
|
g_param_spec_int ("type", "Type", "Type of graph to render", 0, G_MAXINT, 0, G_PARAM_READWRITE));
|
||||||
}
|
}
|
||||||
@@ -102,16 +102,16 @@ xtm_process_monitor_get_property (GObject *object, guint property_id, GValue *va
|
|||||||
switch (property_id)
|
switch (property_id)
|
||||||
{
|
{
|
||||||
case PROP_STEP_SIZE:
|
case PROP_STEP_SIZE:
|
||||||
g_value_set_float (value, monitor->step_size);
|
g_value_set_float (value, monitor->step_size);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_TYPE:
|
case PROP_TYPE:
|
||||||
g_value_set_int (value, monitor->type);
|
g_value_set_int (value, monitor->type);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,16 +122,16 @@ xtm_process_monitor_set_property (GObject *object, guint property_id, const GVal
|
|||||||
switch (property_id)
|
switch (property_id)
|
||||||
{
|
{
|
||||||
case PROP_STEP_SIZE:
|
case PROP_STEP_SIZE:
|
||||||
monitor->step_size = g_value_get_float (value);
|
monitor->step_size = g_value_get_float (value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_TYPE:
|
case PROP_TYPE:
|
||||||
monitor->type = g_value_get_int (value);
|
monitor->type = g_value_get_int (value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ xtm_process_monitor_draw (GtkWidget *widget, cairo_t *cr)
|
|||||||
XtmProcessMonitor *monitor = XTM_PROCESS_MONITOR (widget);
|
XtmProcessMonitor *monitor = XTM_PROCESS_MONITOR (widget);
|
||||||
guint minimum_history_length;
|
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)
|
if (monitor->history->len < minimum_history_length)
|
||||||
{
|
{
|
||||||
g_array_set_size (monitor->history, minimum_history_length + 1);
|
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;
|
cairo_surface_t *graph_surface;
|
||||||
gint width, height;
|
gint width, height;
|
||||||
static const double dashed[] = {1.5};
|
static const double dashed[] = { 1.5 };
|
||||||
gint i;
|
gint i;
|
||||||
width = gtk_widget_get_allocated_width(GTK_WIDGET(monitor));
|
width = gtk_widget_get_allocated_width (GTK_WIDGET (monitor));
|
||||||
height = gtk_widget_get_allocated_height(GTK_WIDGET(monitor));
|
height = gtk_widget_get_allocated_height (GTK_WIDGET (monitor));
|
||||||
|
|
||||||
/* Don't draw anything if the graph is too small */
|
/* Don't draw anything if the graph is too small */
|
||||||
if (height < 3)
|
if (height < 3)
|
||||||
@@ -275,7 +275,7 @@ xtm_process_monitor_paint (XtmProcessMonitor *monitor, cairo_t *cr)
|
|||||||
/* Paint dashed lines at 25%, 50% and 75% */
|
/* 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);
|
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_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)
|
for (i = 25; i <= 75; i += 25)
|
||||||
{
|
{
|
||||||
cairo_move_to (cr, 1.5, i * height / 100 + 0.5);
|
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);
|
g_array_remove_index (monitor->history_swap, monitor->history_swap->len - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET(monitor))))
|
if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET (monitor))))
|
||||||
gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET(monitor)), NULL, FALSE);
|
gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (monitor)), NULL, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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_return_if_fail (XTM_IS_PROCESS_MONITOR (monitor));
|
||||||
g_object_set (monitor, "step_size", step_size, NULL);
|
g_object_set (monitor, "step_size", step_size, NULL);
|
||||||
if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET(monitor))))
|
if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET (monitor))))
|
||||||
gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET(monitor)), NULL, FALSE);
|
gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (monitor)), NULL, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -342,6 +342,6 @@ xtm_process_monitor_clear (XtmProcessMonitor *monitor)
|
|||||||
g_return_if_fail (XTM_IS_PROCESS_MONITOR (monitor));
|
g_return_if_fail (XTM_IS_PROCESS_MONITOR (monitor));
|
||||||
g_array_set_size (monitor->history, 0);
|
g_array_set_size (monitor->history, 0);
|
||||||
g_array_set_size (monitor->history_swap, 0);
|
g_array_set_size (monitor->history_swap, 0);
|
||||||
if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET(monitor))))
|
if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET (monitor))))
|
||||||
gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET(monitor)), NULL, FALSE);
|
gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (monitor)), NULL, FALSE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,20 +13,20 @@
|
|||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
#define XTM_TYPE_PROCESS_MONITOR (xtm_process_monitor_get_type ())
|
#define XTM_TYPE_PROCESS_MONITOR (xtm_process_monitor_get_type ())
|
||||||
#define XTM_PROCESS_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XTM_TYPE_PROCESS_MONITOR, XtmProcessMonitor))
|
#define XTM_PROCESS_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XTM_TYPE_PROCESS_MONITOR, XtmProcessMonitor))
|
||||||
#define XTM_PROCESS_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XTM_TYPE_PROCESS_MONITOR, XtmProcessMonitorClass))
|
#define XTM_PROCESS_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XTM_TYPE_PROCESS_MONITOR, XtmProcessMonitorClass))
|
||||||
#define XTM_IS_PROCESS_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XTM_TYPE_PROCESS_MONITOR))
|
#define XTM_IS_PROCESS_MONITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XTM_TYPE_PROCESS_MONITOR))
|
||||||
#define XTM_IS_PROCESS_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XTM_TYPE_PROCESS_MONITOR))
|
#define XTM_IS_PROCESS_MONITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XTM_TYPE_PROCESS_MONITOR))
|
||||||
#define XTM_PROCESS_MONITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_PROCESS_MONITOR, XtmProcessMonitorClass))
|
#define XTM_PROCESS_MONITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_PROCESS_MONITOR, XtmProcessMonitorClass))
|
||||||
|
|
||||||
typedef struct _XtmProcessMonitor XtmProcessMonitor;
|
typedef struct _XtmProcessMonitor XtmProcessMonitor;
|
||||||
|
|
||||||
GType xtm_process_monitor_get_type (void);
|
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_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_step_size (XtmProcessMonitor *monitor, gfloat step_size);
|
||||||
void xtm_process_monitor_set_type (XtmProcessMonitor *monitor, gint type);
|
void xtm_process_monitor_set_type (XtmProcessMonitor *monitor, gint type);
|
||||||
void xtm_process_monitor_clear (XtmProcessMonitor *monitor);
|
void xtm_process_monitor_clear (XtmProcessMonitor *monitor);
|
||||||
|
|
||||||
#endif /* !PROCESS_MONITOR_H */
|
#endif /* !PROCESS_MONITOR_H */
|
||||||
|
|||||||
@@ -30,30 +30,30 @@ enum
|
|||||||
typedef struct _XtmProcessStatusbarClass XtmProcessStatusbarClass;
|
typedef struct _XtmProcessStatusbarClass XtmProcessStatusbarClass;
|
||||||
struct _XtmProcessStatusbarClass
|
struct _XtmProcessStatusbarClass
|
||||||
{
|
{
|
||||||
GtkStatusbarClass parent_class;
|
GtkStatusbarClass parent_class;
|
||||||
};
|
};
|
||||||
struct _XtmProcessStatusbar
|
struct _XtmProcessStatusbar
|
||||||
{
|
{
|
||||||
GtkHBox parent;
|
GtkHBox parent;
|
||||||
/*<private>*/
|
/*<private>*/
|
||||||
XtmSettings * settings;
|
XtmSettings *settings;
|
||||||
|
|
||||||
GtkWidget * label_num_processes;
|
GtkWidget *label_num_processes;
|
||||||
GtkWidget * label_cpu;
|
GtkWidget *label_cpu;
|
||||||
GtkWidget * label_memory;
|
GtkWidget *label_memory;
|
||||||
GtkWidget * label_swap;
|
GtkWidget *label_swap;
|
||||||
|
|
||||||
gfloat cpu;
|
gfloat cpu;
|
||||||
gchar memory[64];
|
gchar memory[64];
|
||||||
gchar swap[64];
|
gchar swap[64];
|
||||||
guint num_processes;
|
guint num_processes;
|
||||||
|
|
||||||
gboolean dark_mode;
|
gboolean dark_mode;
|
||||||
};
|
};
|
||||||
G_DEFINE_TYPE (XtmProcessStatusbar, xtm_process_statusbar, GTK_TYPE_BOX)
|
G_DEFINE_TYPE (XtmProcessStatusbar, xtm_process_statusbar, GTK_TYPE_BOX)
|
||||||
|
|
||||||
static void xtm_process_statusbar_finalize (GObject *object);
|
static void xtm_process_statusbar_finalize (GObject *object);
|
||||||
static void xtm_process_statusbar_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
|
static void xtm_process_statusbar_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -65,15 +65,15 @@ xtm_process_statusbar_class_init (XtmProcessStatusbarClass *klass)
|
|||||||
class->finalize = xtm_process_statusbar_finalize;
|
class->finalize = xtm_process_statusbar_finalize;
|
||||||
class->set_property = xtm_process_statusbar_set_property;
|
class->set_property = xtm_process_statusbar_set_property;
|
||||||
g_object_class_install_property (class, PROP_CPU,
|
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_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_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_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_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_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
|
static void
|
||||||
@@ -120,7 +120,7 @@ xtm_process_statusbar_init (XtmProcessStatusbar *statusbar)
|
|||||||
|
|
||||||
statusbar->label_cpu = gtk_label_new (NULL);
|
statusbar->label_cpu = gtk_label_new (NULL);
|
||||||
gtk_box_pack_start (GTK_BOX (hbox_cpu), statusbar->label_cpu, TRUE, FALSE, 0);
|
gtk_box_pack_start (GTK_BOX (hbox_cpu), statusbar->label_cpu, TRUE, FALSE, 0);
|
||||||
context = gtk_widget_get_style_context (statusbar->label_cpu);
|
context = gtk_widget_get_style_context (statusbar->label_cpu);
|
||||||
provider = gtk_css_provider_new ();
|
provider = gtk_css_provider_new ();
|
||||||
gtk_css_provider_load_from_data (provider, "* { color: #ff6e00; } .dark { color: #0091ff; }", -1, NULL);
|
gtk_css_provider_load_from_data (provider, "* { color: #ff6e00; } .dark { color: #0091ff; }", -1, NULL);
|
||||||
gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||||
@@ -132,7 +132,7 @@ xtm_process_statusbar_init (XtmProcessStatusbar *statusbar)
|
|||||||
statusbar->label_memory = gtk_label_new (NULL);
|
statusbar->label_memory = gtk_label_new (NULL);
|
||||||
gtk_label_set_ellipsize (GTK_LABEL (statusbar->label_memory), PANGO_ELLIPSIZE_END);
|
gtk_label_set_ellipsize (GTK_LABEL (statusbar->label_memory), PANGO_ELLIPSIZE_END);
|
||||||
gtk_box_pack_start (GTK_BOX (hbox_mem), statusbar->label_memory, TRUE, FALSE, 0);
|
gtk_box_pack_start (GTK_BOX (hbox_mem), statusbar->label_memory, TRUE, FALSE, 0);
|
||||||
context = gtk_widget_get_style_context (statusbar->label_memory);
|
context = gtk_widget_get_style_context (statusbar->label_memory);
|
||||||
provider = gtk_css_provider_new ();
|
provider = gtk_css_provider_new ();
|
||||||
gtk_css_provider_load_from_data (provider, "* { color: #cb386c; } .dark { color: #34c793; }", -1, NULL);
|
gtk_css_provider_load_from_data (provider, "* { color: #cb386c; } .dark { color: #34c793; }", -1, NULL);
|
||||||
gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||||
@@ -141,7 +141,7 @@ xtm_process_statusbar_init (XtmProcessStatusbar *statusbar)
|
|||||||
statusbar->label_swap = gtk_label_new (NULL);
|
statusbar->label_swap = gtk_label_new (NULL);
|
||||||
gtk_label_set_ellipsize (GTK_LABEL (statusbar->label_swap), PANGO_ELLIPSIZE_END);
|
gtk_label_set_ellipsize (GTK_LABEL (statusbar->label_swap), PANGO_ELLIPSIZE_END);
|
||||||
gtk_box_pack_start (GTK_BOX (hbox_mem), statusbar->label_swap, TRUE, FALSE, 0);
|
gtk_box_pack_start (GTK_BOX (hbox_mem), statusbar->label_swap, TRUE, FALSE, 0);
|
||||||
context = gtk_widget_get_style_context (statusbar->label_swap);
|
context = gtk_widget_get_style_context (statusbar->label_swap);
|
||||||
provider = gtk_css_provider_new ();
|
provider = gtk_css_provider_new ();
|
||||||
gtk_css_provider_load_from_data (provider, "* { color: #75324d; } .dark { color: #8acdb2; }", -1, NULL);
|
gtk_css_provider_load_from_data (provider, "* { color: #75324d; } .dark { color: #8acdb2; }", -1, NULL);
|
||||||
gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||||
@@ -186,47 +186,47 @@ xtm_process_statusbar_set_property (GObject *object, guint property_id, const GV
|
|||||||
switch (property_id)
|
switch (property_id)
|
||||||
{
|
{
|
||||||
case PROP_CPU:
|
case PROP_CPU:
|
||||||
statusbar->cpu = g_value_get_float (value);
|
statusbar->cpu = g_value_get_float (value);
|
||||||
float_value = rounded_float_value (statusbar->cpu, statusbar->settings);
|
float_value = rounded_float_value (statusbar->cpu, statusbar->settings);
|
||||||
text = g_strdup_printf (_("CPU: %s%%"), float_value);
|
text = g_strdup_printf (_("CPU: %s%%"), float_value);
|
||||||
gtk_label_set_text (GTK_LABEL (statusbar->label_cpu), text);
|
gtk_label_set_text (GTK_LABEL (statusbar->label_cpu), text);
|
||||||
g_free (float_value);
|
g_free (float_value);
|
||||||
g_free (text);
|
g_free (text);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_MEMORY:
|
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);
|
text = g_strdup_printf (_("Memory: %s"), statusbar->memory);
|
||||||
gtk_label_set_text (GTK_LABEL (statusbar->label_memory), text);
|
gtk_label_set_text (GTK_LABEL (statusbar->label_memory), text);
|
||||||
gtk_widget_set_tooltip_text (statusbar->label_memory, text);
|
gtk_widget_set_tooltip_text (statusbar->label_memory, text);
|
||||||
g_free (text);
|
g_free (text);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_SWAP:
|
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);
|
text = g_strdup_printf (_("Swap: %s"), statusbar->swap);
|
||||||
gtk_label_set_text (GTK_LABEL (statusbar->label_swap), text);
|
gtk_label_set_text (GTK_LABEL (statusbar->label_swap), text);
|
||||||
gtk_widget_set_tooltip_text (statusbar->label_swap, text);
|
gtk_widget_set_tooltip_text (statusbar->label_swap, text);
|
||||||
g_free (text);
|
g_free (text);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_SHOW_SWAP:
|
case PROP_SHOW_SWAP:
|
||||||
if (g_value_get_boolean (value))
|
if (g_value_get_boolean (value))
|
||||||
gtk_widget_show (statusbar->label_swap);
|
gtk_widget_show (statusbar->label_swap);
|
||||||
else
|
else
|
||||||
gtk_widget_hide (statusbar->label_swap);
|
gtk_widget_hide (statusbar->label_swap);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_NUM_PROCESSES:
|
case PROP_NUM_PROCESSES:
|
||||||
statusbar->num_processes = g_value_get_uint (value);
|
statusbar->num_processes = g_value_get_uint (value);
|
||||||
text = g_strdup_printf (_("Processes: %d"), statusbar->num_processes);
|
text = g_strdup_printf (_("Processes: %d"), statusbar->num_processes);
|
||||||
gtk_label_set_text (GTK_LABEL (statusbar->label_num_processes), text);
|
gtk_label_set_text (GTK_LABEL (statusbar->label_num_processes), text);
|
||||||
g_free (text);
|
g_free (text);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,16 +13,16 @@
|
|||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
#define XTM_TYPE_PROCESS_STATUSBAR (xtm_process_statusbar_get_type ())
|
#define XTM_TYPE_PROCESS_STATUSBAR (xtm_process_statusbar_get_type ())
|
||||||
#define XTM_PROCESS_STATUSBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XTM_TYPE_PROCESS_STATUSBAR, XtmProcessStatusbar))
|
#define XTM_PROCESS_STATUSBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XTM_TYPE_PROCESS_STATUSBAR, XtmProcessStatusbar))
|
||||||
#define XTM_PROCESS_STATUSBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XTM_TYPE_PROCESS_STATUSBAR, XtmProcessStatusbarClass))
|
#define XTM_PROCESS_STATUSBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XTM_TYPE_PROCESS_STATUSBAR, XtmProcessStatusbarClass))
|
||||||
#define XTM_IS_PROCESS_STATUSBAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XTM_TYPE_PROCESS_STATUSBAR))
|
#define XTM_IS_PROCESS_STATUSBAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XTM_TYPE_PROCESS_STATUSBAR))
|
||||||
#define XTM_IS_PROCESS_STATUSBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XTM_TYPE_PROCESS_STATUSBAR))
|
#define XTM_IS_PROCESS_STATUSBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XTM_TYPE_PROCESS_STATUSBAR))
|
||||||
#define XTM_PROCESS_STATUSBAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_PROCESS_STATUSBAR, XtmProcessStatusbarClass))
|
#define XTM_PROCESS_STATUSBAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_PROCESS_STATUSBAR, XtmProcessStatusbarClass))
|
||||||
|
|
||||||
typedef struct _XtmProcessStatusbar XtmProcessStatusbar;
|
typedef struct _XtmProcessStatusbar XtmProcessStatusbar;
|
||||||
|
|
||||||
GType xtm_process_statusbar_get_type (void);
|
GType xtm_process_statusbar_get_type (void);
|
||||||
GtkWidget * xtm_process_statusbar_new (void);
|
GtkWidget *xtm_process_statusbar_new (void);
|
||||||
|
|
||||||
#endif /* !PROCESS_STATUSBAR_H */
|
#endif /* !PROCESS_STATUSBAR_H */
|
||||||
|
|||||||
@@ -20,64 +20,65 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_MODEL
|
PROP_MODEL
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct
|
||||||
GtkTreeIter iter;
|
{
|
||||||
GtkTreePath * path;
|
GtkTreeIter iter;
|
||||||
GSequenceIter * list;
|
GtkTreePath *path;
|
||||||
GNode * tree;
|
GSequenceIter *list;
|
||||||
|
GNode *tree;
|
||||||
} XtmCrossLink;
|
} XtmCrossLink;
|
||||||
|
|
||||||
typedef struct _XtmProcessTreeModelClass XtmProcessTreeModelClass;
|
typedef struct _XtmProcessTreeModelClass XtmProcessTreeModelClass;
|
||||||
struct _XtmProcessTreeModelClass
|
struct _XtmProcessTreeModelClass
|
||||||
{
|
{
|
||||||
GObjectClass parent_class;
|
GObjectClass parent_class;
|
||||||
};
|
};
|
||||||
struct _XtmProcessTreeModel
|
struct _XtmProcessTreeModel
|
||||||
{
|
{
|
||||||
GObject parent;
|
GObject parent;
|
||||||
/*<private>*/
|
/*<private>*/
|
||||||
GtkTreeModel * model;
|
GtkTreeModel *model;
|
||||||
GNode * tree;
|
GNode *tree;
|
||||||
GSequence * list;
|
GSequence *list;
|
||||||
gint c_column;
|
gint c_column;
|
||||||
gint p_column;
|
gint p_column;
|
||||||
gint stamp;
|
gint stamp;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void xtm_process_tree_model_iface_init (GtkTreeModelIface *iface);
|
static void xtm_process_tree_model_iface_init (GtkTreeModelIface *iface);
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_CODE (XtmProcessTreeModel, xtm_process_tree_model, G_TYPE_OBJECT,
|
G_DEFINE_TYPE_WITH_CODE (XtmProcessTreeModel, xtm_process_tree_model, G_TYPE_OBJECT,
|
||||||
G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL, xtm_process_tree_model_iface_init))
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL, xtm_process_tree_model_iface_init))
|
||||||
|
|
||||||
static void xtm_process_tree_model_finalize (GObject *object);
|
static void xtm_process_tree_model_finalize (GObject *object);
|
||||||
static void xtm_process_tree_model_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
|
static void xtm_process_tree_model_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
|
||||||
static void xtm_process_tree_model_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
|
static void xtm_process_tree_model_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
|
||||||
|
|
||||||
static GtkTreeModelFlags xtm_process_tree_model_get_flags (GtkTreeModel *model);
|
static GtkTreeModelFlags xtm_process_tree_model_get_flags (GtkTreeModel *model);
|
||||||
static gint xtm_process_tree_model_get_n_columns (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 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 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 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_next (GtkTreeModel *model, GtkTreeIter *iter);
|
||||||
static gboolean xtm_process_tree_model_iter_children (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *parent);
|
static gboolean xtm_process_tree_model_iter_children (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *parent);
|
||||||
static gboolean xtm_process_tree_model_iter_has_child (GtkTreeModel *model, GtkTreeIter *iter);
|
static gboolean xtm_process_tree_model_iter_has_child (GtkTreeModel *model, GtkTreeIter *iter);
|
||||||
static gint xtm_process_tree_model_iter_n_children (GtkTreeModel *model, GtkTreeIter *iter);
|
static gint xtm_process_tree_model_iter_n_children (GtkTreeModel *model, GtkTreeIter *iter);
|
||||||
static gboolean xtm_process_tree_model_iter_nth_child (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *parent, gint n);
|
static gboolean xtm_process_tree_model_iter_nth_child (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *parent, gint n);
|
||||||
static gboolean xtm_process_tree_model_iter_parent (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *child);
|
static gboolean xtm_process_tree_model_iter_parent (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *child);
|
||||||
|
|
||||||
static void xtm_process_tree_model_row_changed (XtmProcessTreeModel *treemodel, GtkTreePath *path, GtkTreeIter *iter, GtkTreeModel *model);
|
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_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_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);
|
||||||
static void xtm_process_tree_model_rows_reordered (XtmProcessTreeModel *treemodel, GtkTreePath *path, GtkTreeIter *iter, gint *new_order, GtkTreeModel *model);
|
|
||||||
|
|
||||||
static void xtm_process_tree_model_set_model (XtmProcessTreeModel *treemodel, GtkTreeModel *model);
|
static void xtm_process_tree_model_set_model (XtmProcessTreeModel *treemodel, GtkTreeModel *model);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -112,7 +113,7 @@ xtm_process_tree_model_class_init (XtmProcessTreeModelClass *klass)
|
|||||||
class->get_property = xtm_process_tree_model_get_property;
|
class->get_property = xtm_process_tree_model_get_property;
|
||||||
|
|
||||||
g_object_class_install_property (class, PROP_MODEL,
|
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
|
static void
|
||||||
@@ -369,9 +370,9 @@ xtm_process_tree_model_iter_parent (GtkTreeModel *model, GtkTreeIter *iter, GtkT
|
|||||||
|
|
||||||
struct find_node_struct
|
struct find_node_struct
|
||||||
{
|
{
|
||||||
GValue p_value;
|
GValue p_value;
|
||||||
XtmProcessTreeModel * treemodel;
|
XtmProcessTreeModel *treemodel;
|
||||||
GNode * parent;
|
GNode *parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@@ -380,7 +381,7 @@ find_node (GNode *node, gpointer data)
|
|||||||
XtmCrossLink *lnk = node->data;
|
XtmCrossLink *lnk = node->data;
|
||||||
struct find_node_struct *found = data;
|
struct find_node_struct *found = data;
|
||||||
gboolean same = FALSE;
|
gboolean same = FALSE;
|
||||||
GValue c_value = {0};
|
GValue c_value = { 0 };
|
||||||
if (lnk == NULL)
|
if (lnk == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
/* Use path for non-persistent models */
|
/* Use path for non-persistent models */
|
||||||
@@ -438,7 +439,7 @@ find_sibling (GNode *parent, GSequenceIter *child)
|
|||||||
GSequenceIter *prev;
|
GSequenceIter *prev;
|
||||||
/* Go backward in the list until a node is found with the same parent */
|
/* Go backward in the list until a node is found with the same parent */
|
||||||
for (prev = g_sequence_iter_prev (child); prev != child; prev = g_sequence_iter_prev (child))
|
for (prev = g_sequence_iter_prev (child); prev != child; prev = g_sequence_iter_prev (child))
|
||||||
{
|
{
|
||||||
XtmCrossLink *lnk;
|
XtmCrossLink *lnk;
|
||||||
child = prev;
|
child = prev;
|
||||||
lnk = g_sequence_get (child);
|
lnk = g_sequence_get (child);
|
||||||
@@ -446,7 +447,7 @@ find_sibling (GNode *parent, GSequenceIter *child)
|
|||||||
{
|
{
|
||||||
return lnk->tree;
|
return lnk->tree;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -458,8 +459,8 @@ xtm_process_tree_model_row_changed (XtmProcessTreeModel *treemodel, GtkTreePath
|
|||||||
XtmCrossLink *lnk, *c_link;
|
XtmCrossLink *lnk, *c_link;
|
||||||
GNode *node, *next_node, *old_parent;
|
GNode *node, *next_node, *old_parent;
|
||||||
struct find_node_struct found;
|
struct find_node_struct found;
|
||||||
GValue c_value = {0};
|
GValue c_value = { 0 };
|
||||||
GValue p_value = {0};
|
GValue p_value = { 0 };
|
||||||
gboolean same = TRUE;
|
gboolean same = TRUE;
|
||||||
gboolean signal_parent;
|
gboolean signal_parent;
|
||||||
|
|
||||||
@@ -476,7 +477,7 @@ xtm_process_tree_model_row_changed (XtmProcessTreeModel *treemodel, GtkTreePath
|
|||||||
s_iter.user_data3 = NULL;
|
s_iter.user_data3 = NULL;
|
||||||
|
|
||||||
/* Use the root entry as fall-back if no parent could be found */
|
/* 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.parent = treemodel->tree;
|
||||||
found.treemodel = treemodel;
|
found.treemodel = treemodel;
|
||||||
gtk_tree_model_get_value (model, iter, treemodel->p_column, &found.p_value);
|
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)
|
do_path (gpointer data, gpointer user_data)
|
||||||
{
|
{
|
||||||
XtmCrossLink *lnk = data;
|
XtmCrossLink *lnk = data;
|
||||||
void (*func) (GtkTreePath*) = (void (*) (GtkTreePath*))user_data;
|
void (*func) (GtkTreePath *) = (void (*) (GtkTreePath *))user_data;
|
||||||
/* Use path for non-persistent models */
|
/* Use path for non-persistent models */
|
||||||
g_return_if_fail (lnk->path);
|
g_return_if_fail (lnk->path);
|
||||||
func (lnk->path);
|
func (lnk->path);
|
||||||
@@ -622,8 +623,8 @@ xtm_process_tree_model_row_inserted (XtmProcessTreeModel *treemodel, GtkTreePath
|
|||||||
XtmCrossLink *lnk, *c_link;
|
XtmCrossLink *lnk, *c_link;
|
||||||
GNode *node, *next_node;
|
GNode *node, *next_node;
|
||||||
struct find_node_struct found;
|
struct find_node_struct found;
|
||||||
GValue c_value = {0};
|
GValue c_value = { 0 };
|
||||||
GValue p_value = {0};
|
GValue p_value = { 0 };
|
||||||
gboolean same;
|
gboolean same;
|
||||||
gboolean not_persist = TRUE;
|
gboolean not_persist = TRUE;
|
||||||
gboolean signal_parent;
|
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);
|
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 */
|
/* 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.stamp = treemodel->stamp;
|
||||||
s_iter.user_data2 = NULL;
|
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),
|
g_sequence_foreach_range (g_sequence_iter_next (lnk->list), g_sequence_get_end_iter (treemodel->list),
|
||||||
do_path, (gpointer)gtk_tree_path_next);
|
do_path, (gpointer)gtk_tree_path_next);
|
||||||
|
|
||||||
memset(&found, 0, sizeof(found));
|
memset (&found, 0, sizeof (found));
|
||||||
found.parent = treemodel->tree;
|
found.parent = treemodel->tree;
|
||||||
found.treemodel = treemodel;
|
found.treemodel = treemodel;
|
||||||
gtk_tree_model_get_value (model, iter, treemodel->p_column, &found.p_value);
|
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);
|
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.stamp = treemodel->stamp;
|
||||||
s_iter.user_data2 = NULL;
|
s_iter.user_data2 = NULL;
|
||||||
@@ -852,7 +853,7 @@ reorder_children (GNode *parent, gpointer data)
|
|||||||
if (c_pos > 0)
|
if (c_pos > 0)
|
||||||
{
|
{
|
||||||
/* move the items in between to keep order list in sync with the current tree */
|
/* 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;
|
moved = TRUE;
|
||||||
}
|
}
|
||||||
/* Store the old position at the new location */
|
/* 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))
|
if (G_UNLIKELY (size == 0))
|
||||||
return;
|
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 */
|
/* New list to hold the new order */
|
||||||
s_list = g_sequence_new (xtm_cross_link_free);
|
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-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-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, "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);
|
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 *
|
GtkTreeModel *
|
||||||
xtm_process_tree_model_new (GtkTreeModel * model)
|
xtm_process_tree_model_new (GtkTreeModel *model)
|
||||||
{
|
{
|
||||||
/* Only support flat models to build a tree */
|
/* 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);
|
g_return_val_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY, NULL);
|
||||||
|
|||||||
@@ -13,16 +13,16 @@
|
|||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
#define XTM_TYPE_PROCESS_TREE_MODEL (xtm_process_tree_model_get_type ())
|
#define XTM_TYPE_PROCESS_TREE_MODEL (xtm_process_tree_model_get_type ())
|
||||||
#define XTM_PROCESS_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XTM_TYPE_PROCESS_TREE_MODEL, XtmProcessTreeModel))
|
#define XTM_PROCESS_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XTM_TYPE_PROCESS_TREE_MODEL, XtmProcessTreeModel))
|
||||||
#define XTM_PROCESS_TREE_MODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XTM_TYPE_PROCESS_TREE_MODEL, XtmProcessTreeModelClass))
|
#define XTM_PROCESS_TREE_MODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XTM_TYPE_PROCESS_TREE_MODEL, XtmProcessTreeModelClass))
|
||||||
#define XTM_IS_PROCESS_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XTM_TYPE_PROCESS_TREE_MODEL))
|
#define XTM_IS_PROCESS_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XTM_TYPE_PROCESS_TREE_MODEL))
|
||||||
#define XTM_IS_PROCESS_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XTM_TYPE_PROCESS_TREE_MODEL))
|
#define XTM_IS_PROCESS_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XTM_TYPE_PROCESS_TREE_MODEL))
|
||||||
#define XTM_PROCESS_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_PROCESS_TREE_MODEL, XtmProcessTreeModelClass))
|
#define XTM_PROCESS_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_PROCESS_TREE_MODEL, XtmProcessTreeModelClass))
|
||||||
|
|
||||||
typedef struct _XtmProcessTreeModel XtmProcessTreeModel;
|
typedef struct _XtmProcessTreeModel XtmProcessTreeModel;
|
||||||
|
|
||||||
GType xtm_process_tree_model_get_type (void);
|
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 */
|
#endif /* !PROCESS_TREE_MODEL_H */
|
||||||
|
|||||||
@@ -44,38 +44,38 @@ enum
|
|||||||
typedef struct _XtmProcessTreeViewClass XtmProcessTreeViewClass;
|
typedef struct _XtmProcessTreeViewClass XtmProcessTreeViewClass;
|
||||||
struct _XtmProcessTreeViewClass
|
struct _XtmProcessTreeViewClass
|
||||||
{
|
{
|
||||||
GtkTreeViewClass parent_class;
|
GtkTreeViewClass parent_class;
|
||||||
};
|
};
|
||||||
struct _XtmProcessTreeView
|
struct _XtmProcessTreeView
|
||||||
{
|
{
|
||||||
GtkTreeView parent;
|
GtkTreeView parent;
|
||||||
/*<private>*/
|
/*<private>*/
|
||||||
GtkListStore * model;
|
GtkListStore *model;
|
||||||
GtkTreeModel * model_filter;
|
GtkTreeModel *model_filter;
|
||||||
gchar * cmd_filter;
|
gchar *cmd_filter;
|
||||||
GtkTreeModel * model_tree;
|
GtkTreeModel *model_tree;
|
||||||
GtkTreeViewColumn * sort_column;
|
GtkTreeViewColumn *sort_column;
|
||||||
gushort columns_positions[N_COLUMNS];
|
gushort columns_positions[N_COLUMNS];
|
||||||
XtmSettings * settings;
|
XtmSettings *settings;
|
||||||
guint owner_uid;
|
guint owner_uid;
|
||||||
gboolean show_all_processes_cached;
|
gboolean show_all_processes_cached;
|
||||||
};
|
};
|
||||||
G_DEFINE_TYPE (XtmProcessTreeView, xtm_process_tree_view, GTK_TYPE_TREE_VIEW)
|
G_DEFINE_TYPE (XtmProcessTreeView, xtm_process_tree_view, GTK_TYPE_TREE_VIEW)
|
||||||
|
|
||||||
static void xtm_process_tree_view_finalize (GObject *object);
|
static void xtm_process_tree_view_finalize (GObject *object);
|
||||||
|
|
||||||
static gboolean treeview_clicked (XtmProcessTreeView *treeview, GdkEventButton *event);
|
static gboolean treeview_clicked (XtmProcessTreeView *treeview, GdkEventButton *event);
|
||||||
static gboolean treeview_key_pressed (XtmProcessTreeView *treeview, GdkEventKey *event);
|
static gboolean treeview_key_pressed (XtmProcessTreeView *treeview, GdkEventKey *event);
|
||||||
static void column_task_pack_cells (XtmProcessTreeView *treeview, GtkTreeViewColumn *column);
|
static void column_task_pack_cells (XtmProcessTreeView *treeview, GtkTreeViewColumn *column);
|
||||||
static void columns_changed (XtmProcessTreeView *treeview);
|
static void columns_changed (XtmProcessTreeView *treeview);
|
||||||
static void read_columns_positions (XtmProcessTreeView *treeview);
|
static void read_columns_positions (XtmProcessTreeView *treeview);
|
||||||
static void save_columns_positions (XtmProcessTreeView *treeview);
|
static void save_columns_positions (XtmProcessTreeView *treeview);
|
||||||
static void column_clicked (GtkTreeViewColumn *column, XtmProcessTreeView *treeview);
|
static void column_clicked (GtkTreeViewColumn *column, XtmProcessTreeView *treeview);
|
||||||
static gboolean visible_func (GtkTreeModel *model, GtkTreeIter *iter, XtmProcessTreeView *treeview);
|
static gboolean visible_func (GtkTreeModel *model, GtkTreeIter *iter, XtmProcessTreeView *treeview);
|
||||||
static gboolean search_func (GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer user_data);
|
static gboolean search_func (GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer user_data);
|
||||||
static void settings_changed (GObject *object, GParamSpec *pspec, XtmProcessTreeView *treeview);
|
static void settings_changed (GObject *object, GParamSpec *pspec, XtmProcessTreeView *treeview);
|
||||||
static void expand_row (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, XtmProcessTreeView *treeview);
|
static void expand_row (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, XtmProcessTreeView *treeview);
|
||||||
static gboolean treeview_query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_tip, GtkTooltip *tooltip, gpointer data);
|
static gboolean treeview_query_tooltip (GtkWidget *widget, gint x, gint y, gboolean keyboard_tip, GtkTooltip *tooltip, gpointer data);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xtm_process_tree_view_class_init (XtmProcessTreeViewClass *klass)
|
xtm_process_tree_view_class_init (XtmProcessTreeViewClass *klass)
|
||||||
@@ -126,7 +126,7 @@ xtm_process_tree_view_init (XtmProcessTreeView *treeview)
|
|||||||
G_TYPE_STRING, /* XTM_PTV_COLUMN_BACKGROUND */
|
G_TYPE_STRING, /* XTM_PTV_COLUMN_BACKGROUND */
|
||||||
G_TYPE_STRING, /* XTM_PTV_COLUMN_FOREGROUND */
|
G_TYPE_STRING, /* XTM_PTV_COLUMN_FOREGROUND */
|
||||||
G_TYPE_LONG /* XTM_PTV_COLUMN_TIMESTAMP */
|
G_TYPE_LONG /* XTM_PTV_COLUMN_TIMESTAMP */
|
||||||
);
|
);
|
||||||
|
|
||||||
treeview->model_filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (treeview->model), NULL);
|
treeview->model_filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (treeview->model), NULL);
|
||||||
gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (treeview->model_filter), (GtkTreeModelFilterVisibleFunc)visible_func, treeview, NULL);
|
gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (treeview->model_filter), (GtkTreeModelFilterVisibleFunc)visible_func, treeview, NULL);
|
||||||
@@ -143,7 +143,7 @@ xtm_process_tree_view_init (XtmProcessTreeView *treeview)
|
|||||||
treeview->cmd_filter = NULL;
|
treeview->cmd_filter = NULL;
|
||||||
|
|
||||||
/* Create cell renderer for tree view columns */
|
/* 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 ();
|
cell_right_aligned = gtk_cell_renderer_text_new ();
|
||||||
g_object_set (cell_right_aligned, "xalign", 1.0, NULL);
|
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 };
|
gchar columns_positions[COLUMNS_POSITIONS_STRLEN] = { 0 };
|
||||||
|
|
||||||
for (i = 0; i < N_COLUMNS; i++)
|
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);
|
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"));
|
_("Error sending signal"));
|
||||||
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
||||||
_("An error was encountered by sending a signal to the PID %d. "
|
_("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_title (GTK_WINDOW (dialog), _("Task Manager"));
|
||||||
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
|
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
|
||||||
gtk_dialog_run (GTK_DIALOG (dialog));
|
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,
|
GtkWidget *dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
|
||||||
_("Error setting priority"));
|
_("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. "
|
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
||||||
"It is likely you don't have the required privileges."), pid);
|
_("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_title (GTK_WINDOW (dialog), _("Task Manager"));
|
||||||
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
|
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
|
||||||
gtk_dialog_run (GTK_DIALOG (dialog));
|
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);
|
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 */
|
/* Refer to treeview_key_pressed to see how the Ctrl-c press is handled */
|
||||||
accel_label = gtk_bin_get_child (GTK_BIN (mi));
|
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);
|
gtk_widget_show_all (menu);
|
||||||
|
|
||||||
@@ -685,7 +688,7 @@ treeview_key_pressed (XtmProcessTreeView *treeview, GdkEventKey *event)
|
|||||||
GdkWindow *window = gtk_tree_view_get_bin_window (GTK_TREE_VIEW (treeview));
|
GdkWindow *window = gtk_tree_view_get_bin_window (GTK_TREE_VIEW (treeview));
|
||||||
|
|
||||||
gtk_menu_popup_at_rect (GTK_MENU (create_popup_menu (treeview, pid, event->time)),
|
gtk_menu_popup_at_rect (GTK_MENU (create_popup_menu (treeview, pid, event->time)),
|
||||||
window, &rect, GDK_GRAVITY_NORTH_WEST, GDK_GRAVITY_NORTH_WEST, NULL);
|
window, &rect, GDK_GRAVITY_NORTH_WEST, GDK_GRAVITY_NORTH_WEST, NULL);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else if (event->keyval == GDK_KEY_Delete)
|
else if (event->keyval == GDK_KEY_Delete)
|
||||||
@@ -740,17 +743,17 @@ column_clicked (GtkTreeViewColumn *column, XtmProcessTreeView *treeview)
|
|||||||
|
|
||||||
treeview->sort_column = column;
|
treeview->sort_column = column;
|
||||||
|
|
||||||
g_object_set(treeview->settings,
|
g_object_set (treeview->settings,
|
||||||
"sort-column-id", GPOINTER_TO_INT(g_object_get_data(G_OBJECT(treeview->sort_column), "column-id")),
|
"sort-column-id", GPOINTER_TO_INT (g_object_get_data (G_OBJECT (treeview->sort_column), "column-id")),
|
||||||
"sort-type", sort_type,
|
"sort-type", sort_type,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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);
|
g_free (treeview->cmd_filter);
|
||||||
treeview->cmd_filter = g_strdup(cmd_filter);
|
treeview->cmd_filter = g_strdup (cmd_filter);
|
||||||
|
|
||||||
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (treeview->model_filter));
|
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (treeview->model_filter));
|
||||||
}
|
}
|
||||||
@@ -759,12 +762,14 @@ static gboolean
|
|||||||
visible_func (GtkTreeModel *model, GtkTreeIter *iter, XtmProcessTreeView *treeview)
|
visible_func (GtkTreeModel *model, GtkTreeIter *iter, XtmProcessTreeView *treeview)
|
||||||
{
|
{
|
||||||
gchar *cmdline, *cmdline_lower, *key_lower, *p = NULL;
|
gchar *cmdline, *cmdline_lower, *key_lower, *p = NULL;
|
||||||
gboolean mach_filter = TRUE, match_uid = TRUE;
|
gboolean mach_filter = TRUE, match_uid = TRUE;
|
||||||
guint uid;
|
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);
|
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);
|
cmdline_lower = g_ascii_strdown (cmdline, -1);
|
||||||
key_lower = g_ascii_strdown (treeview->cmd_filter, -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);
|
g_free (cmdline);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!p)
|
if (!p)
|
||||||
mach_filter = FALSE;
|
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);
|
gtk_tree_model_get (GTK_TREE_MODEL (treeview->model), iter, XTM_PTV_COLUMN_UID, &uid, -1);
|
||||||
if (treeview->owner_uid != uid)
|
if (treeview->owner_uid != uid)
|
||||||
match_uid = FALSE;
|
match_uid = FALSE;
|
||||||
@@ -891,14 +897,15 @@ xtm_process_tree_view_get_model (XtmProcessTreeView *treeview)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
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;
|
GtkTreeModel *model;
|
||||||
GtkTreeIter iter;
|
GtkTreePath *path;
|
||||||
gboolean valid;
|
GtkTreeIter iter;
|
||||||
gboolean tree;
|
gboolean valid;
|
||||||
GPid pid_iter;
|
gboolean tree;
|
||||||
GtkTreeIter child_iter;
|
GPid pid_iter;
|
||||||
|
GtkTreeIter child_iter;
|
||||||
gboolean validParent;
|
gboolean validParent;
|
||||||
|
|
||||||
g_object_get (treeview->settings, "process-tree", &tree, NULL);
|
g_object_get (treeview->settings, "process-tree", &tree, NULL);
|
||||||
@@ -926,7 +933,7 @@ xtm_process_tree_view_highlight_pid (XtmProcessTreeView *treeview, GPid pid) {
|
|||||||
|
|
||||||
if (gtk_tree_model_iter_has_child (model, &iter))
|
if (gtk_tree_model_iter_has_child (model, &iter))
|
||||||
{
|
{
|
||||||
GtkTreeIter parent_iter = iter;
|
GtkTreeIter parent_iter = iter;
|
||||||
|
|
||||||
valid = gtk_tree_model_iter_children (model, &iter, &parent_iter);
|
valid = gtk_tree_model_iter_children (model, &iter, &parent_iter);
|
||||||
}
|
}
|
||||||
@@ -936,8 +943,9 @@ xtm_process_tree_view_highlight_pid (XtmProcessTreeView *treeview, GPid pid) {
|
|||||||
valid = gtk_tree_model_iter_next (model, &iter);
|
valid = gtk_tree_model_iter_next (model, &iter);
|
||||||
if (tree && !valid)
|
if (tree && !valid)
|
||||||
{
|
{
|
||||||
//finding my way up again
|
// finding my way up again
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
validParent = gtk_tree_model_iter_parent (model, &iter, &child_iter);
|
validParent = gtk_tree_model_iter_parent (model, &iter, &child_iter);
|
||||||
child_iter = iter;
|
child_iter = iter;
|
||||||
valid = gtk_tree_model_iter_next (model, &iter);
|
valid = gtk_tree_model_iter_next (model, &iter);
|
||||||
|
|||||||
@@ -46,19 +46,19 @@ enum
|
|||||||
XTM_PTV_N_COLUMNS,
|
XTM_PTV_N_COLUMNS,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define XTM_TYPE_PROCESS_TREE_VIEW (xtm_process_tree_view_get_type ())
|
#define XTM_TYPE_PROCESS_TREE_VIEW (xtm_process_tree_view_get_type ())
|
||||||
#define XTM_PROCESS_TREE_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XTM_TYPE_PROCESS_TREE_VIEW, XtmProcessTreeView))
|
#define XTM_PROCESS_TREE_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XTM_TYPE_PROCESS_TREE_VIEW, XtmProcessTreeView))
|
||||||
#define XTM_PROCESS_TREE_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XTM_TYPE_PROCESS_TREE_VIEW, XtmProcessTreeViewClass))
|
#define XTM_PROCESS_TREE_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XTM_TYPE_PROCESS_TREE_VIEW, XtmProcessTreeViewClass))
|
||||||
#define XTM_IS_PROCESS_TREE_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XTM_TYPE_PROCESS_TREE_VIEW))
|
#define XTM_IS_PROCESS_TREE_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XTM_TYPE_PROCESS_TREE_VIEW))
|
||||||
#define XTM_IS_PROCESS_TREE_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XTM_TYPE_PROCESS_TREE_VIEW))
|
#define XTM_IS_PROCESS_TREE_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XTM_TYPE_PROCESS_TREE_VIEW))
|
||||||
#define XTM_PROCESS_TREE_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_PROCESS_TREE_VIEW, XtmProcessTreeViewClass))
|
#define XTM_PROCESS_TREE_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_PROCESS_TREE_VIEW, XtmProcessTreeViewClass))
|
||||||
|
|
||||||
typedef struct _XtmProcessTreeView XtmProcessTreeView;
|
typedef struct _XtmProcessTreeView XtmProcessTreeView;
|
||||||
|
|
||||||
GType xtm_process_tree_view_get_type (void);
|
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);
|
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);
|
void xtm_process_tree_view_highlight_pid (XtmProcessTreeView *treeview, GPid pid);
|
||||||
|
|
||||||
#endif /* !PROCESS_TREE_VIEW_H */
|
#endif /* !PROCESS_TREE_VIEW_H */
|
||||||
|
|||||||
@@ -39,49 +39,47 @@
|
|||||||
typedef struct _XtmProcessWindowClass XtmProcessWindowClass;
|
typedef struct _XtmProcessWindowClass XtmProcessWindowClass;
|
||||||
struct _XtmProcessWindowClass
|
struct _XtmProcessWindowClass
|
||||||
{
|
{
|
||||||
GtkWidgetClass parent_class;
|
GtkWidgetClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _XtmProcessWindow
|
struct _XtmProcessWindow
|
||||||
{
|
{
|
||||||
GtkWidget parent;
|
GtkWidget parent;
|
||||||
/*<private>*/
|
/*<private>*/
|
||||||
GtkBuilder * builder;
|
GtkBuilder *builder;
|
||||||
GtkWidget * window;
|
GtkWidget *window;
|
||||||
GtkWidget * filter_entry;
|
GtkWidget *filter_entry;
|
||||||
GtkWidget * filter_searchbar;
|
GtkWidget *filter_searchbar;
|
||||||
GtkWidget * cpu_monitor;
|
GtkWidget *cpu_monitor;
|
||||||
GtkWidget * mem_monitor;
|
GtkWidget *mem_monitor;
|
||||||
GtkWidget * vpaned;
|
GtkWidget *vpaned;
|
||||||
GtkWidget * treeview;
|
GtkWidget *treeview;
|
||||||
GtkWidget * statusbar;
|
GtkWidget *statusbar;
|
||||||
GtkWidget * settings_button;
|
GtkWidget *settings_button;
|
||||||
XtmSettings * settings;
|
XtmSettings *settings;
|
||||||
XfconfChannel * channel;
|
XfconfChannel *channel;
|
||||||
gint width;
|
gint width;
|
||||||
gint height;
|
gint height;
|
||||||
gulong handler;
|
gulong handler;
|
||||||
gboolean view_stuck;
|
gboolean view_stuck;
|
||||||
};
|
};
|
||||||
G_DEFINE_TYPE (XtmProcessWindow, xtm_process_window, GTK_TYPE_WIDGET)
|
G_DEFINE_TYPE (XtmProcessWindow, xtm_process_window, GTK_TYPE_WIDGET)
|
||||||
|
|
||||||
static void xtm_process_window_finalize (GObject *object);
|
static void xtm_process_window_finalize (GObject *object);
|
||||||
static void xtm_process_window_hide (GtkWidget *widget);
|
static void xtm_process_window_hide (GtkWidget *widget);
|
||||||
|
|
||||||
static void emit_destroy_signal (XtmProcessWindow *window);
|
static void emit_destroy_signal (XtmProcessWindow *window);
|
||||||
static gboolean xtm_process_window_key_pressed (XtmProcessWindow *window, GdkEventKey *event);
|
static gboolean xtm_process_window_key_pressed (XtmProcessWindow *window, GdkEventKey *event);
|
||||||
static void monitor_update_step_size (XtmProcessWindow *window);
|
static void monitor_update_step_size (XtmProcessWindow *window);
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
filter_entry_icon_pressed_cb (GtkEntry *entry,
|
filter_entry_icon_pressed_cb (GtkEntry *entry, gint position, GdkEventButton *event __unused, gpointer data __unused)
|
||||||
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_entry_set_text (entry, "");
|
||||||
gtk_widget_grab_focus (GTK_WIDGET(entry));
|
gtk_widget_grab_focus (GTK_WIDGET (entry));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,49 +90,55 @@ Select_Window (Display *dpy, int screen)
|
|||||||
int status;
|
int status;
|
||||||
Cursor cursor;
|
Cursor cursor;
|
||||||
XEvent event;
|
XEvent event;
|
||||||
Window target_win = None, root = RootWindow(dpy,screen);
|
Window target_win = None, root = RootWindow (dpy, screen);
|
||||||
int buttons = 0;
|
int buttons = 0;
|
||||||
|
|
||||||
/* Make the target cursor */
|
/* 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 */
|
/* Grab the pointer using target cursor, letting it roam all over */
|
||||||
status = XGrabPointer(dpy, root, False,
|
status = XGrabPointer (dpy, root, False,
|
||||||
ButtonPressMask|ButtonReleaseMask, GrabModeSync,
|
ButtonPressMask | ButtonReleaseMask, GrabModeSync,
|
||||||
GrabModeAsync, root, cursor, CurrentTime);
|
GrabModeAsync, root, cursor, CurrentTime);
|
||||||
if (status != GrabSuccess) {
|
if (status != GrabSuccess)
|
||||||
fprintf (stderr, "Can't grab the mouse.\n");
|
{
|
||||||
return None;
|
fprintf (stderr, "Can't grab the mouse.\n");
|
||||||
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Let the user select a window... */
|
/* 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);
|
/* allow one more event */
|
||||||
XWindowEvent(dpy, root, ButtonPressMask|ButtonReleaseMask, &event);
|
XAllowEvents (dpy, SyncPointer, CurrentTime);
|
||||||
switch (event.type) {
|
XWindowEvent (dpy, root, ButtonPressMask | ButtonReleaseMask, &event);
|
||||||
case ButtonPress:
|
switch (event.type)
|
||||||
if (target_win == None) {
|
{
|
||||||
target_win = event.xbutton.subwindow; /* window selected */
|
case ButtonPress:
|
||||||
if (target_win == None) target_win = root;
|
if (target_win == None)
|
||||||
}
|
{
|
||||||
buttons++;
|
target_win = event.xbutton.subwindow; /* window selected */
|
||||||
break;
|
if (target_win == None)
|
||||||
case ButtonRelease:
|
target_win = root;
|
||||||
if (buttons > 0) /* there may have been some down before we started */
|
}
|
||||||
buttons--;
|
buttons++;
|
||||||
break;
|
break;
|
||||||
}
|
case ButtonRelease:
|
||||||
|
if (buttons > 0) /* there may have been some down before we started */
|
||||||
|
buttons--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XUngrabPointer(dpy, CurrentTime); /* Done with pointer */
|
XUngrabPointer (dpy, CurrentTime); /* Done with pointer */
|
||||||
|
|
||||||
return target_win;
|
return target_win;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xwininfo_clicked_cb (GtkButton *button __unused, gpointer user_data) {
|
xwininfo_clicked_cb (GtkButton *button __unused, gpointer user_data)
|
||||||
XtmProcessWindow *window = (XtmProcessWindow *) user_data;
|
{
|
||||||
|
XtmProcessWindow *window = (XtmProcessWindow *)user_data;
|
||||||
Window selected_window;
|
Window selected_window;
|
||||||
Display *dpy;
|
Display *dpy;
|
||||||
Atom atom_NET_WM_PID;
|
Atom atom_NET_WM_PID;
|
||||||
@@ -148,51 +152,56 @@ xwininfo_clicked_cb (GtkButton *button __unused, gpointer user_data) {
|
|||||||
|
|
||||||
dpy = XOpenDisplay (NULL);
|
dpy = XOpenDisplay (NULL);
|
||||||
selected_window = Select_Window (dpy, 0);
|
selected_window = Select_Window (dpy, 0);
|
||||||
if (selected_window) {
|
if (selected_window)
|
||||||
|
{
|
||||||
selected_window = XmuClientWindow (dpy, 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,
|
False, AnyPropertyType, &actual_type,
|
||||||
&actual_format, &_nitems, &bytes_after,
|
&actual_format, &_nitems, &bytes_after,
|
||||||
&prop);
|
&prop);
|
||||||
if (status == BadWindow) {
|
if (status == BadWindow)
|
||||||
XTM_SHOW_MESSAGE(GTK_MESSAGE_INFO,
|
{
|
||||||
_("Bad Window"), _("Window id 0x%lx does not exist!"), selected_window);
|
XTM_SHOW_MESSAGE (GTK_MESSAGE_INFO,
|
||||||
} if (status != Success) {
|
_("Bad Window"), _("Window id 0x%lx does not exist!"), selected_window);
|
||||||
XTM_SHOW_MESSAGE(GTK_MESSAGE_ERROR,
|
}
|
||||||
_("XGetWindowProperty failed"), _("XGetWindowProperty failed!"));
|
if (status != Success)
|
||||||
} else {
|
{
|
||||||
if (_nitems > 0) {
|
XTM_SHOW_MESSAGE (GTK_MESSAGE_ERROR,
|
||||||
memcpy(&pid, prop, sizeof(pid));
|
_("XGetWindowProperty failed"), _("XGetWindowProperty failed!"));
|
||||||
xtm_process_tree_view_highlight_pid(XTM_PROCESS_TREE_VIEW (window->treeview), pid);
|
}
|
||||||
} else {
|
else
|
||||||
XTM_SHOW_MESSAGE(GTK_MESSAGE_INFO,
|
{
|
||||||
_("No PID found"), _("No PID found for window 0x%lx."), selected_window);
|
if (_nitems > 0)
|
||||||
}
|
{
|
||||||
g_free(prop);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
filter_entry_keyrelease_handler(GtkEntry *entry,
|
filter_entry_keyrelease_handler (GtkEntry *entry, XtmProcessTreeView *treeview)
|
||||||
XtmProcessTreeView *treeview)
|
|
||||||
{
|
{
|
||||||
gchar *text;
|
gchar *text;
|
||||||
gboolean has_text;
|
gboolean has_text;
|
||||||
|
|
||||||
text = gtk_editable_get_chars (GTK_EDITABLE(entry), 0, -1);
|
text = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1);
|
||||||
xtm_process_tree_view_set_filter(treeview, text);
|
xtm_process_tree_view_set_filter (treeview, text);
|
||||||
g_free (text);
|
g_free (text);
|
||||||
|
|
||||||
has_text = gtk_entry_get_text_length (GTK_ENTRY(entry)) > 0;
|
has_text = gtk_entry_get_text_length (GTK_ENTRY (entry)) > 0;
|
||||||
gtk_entry_set_icon_sensitive (GTK_ENTRY(entry),
|
gtk_entry_set_icon_sensitive (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY, has_text);
|
||||||
GTK_ENTRY_ICON_SECONDARY,
|
|
||||||
has_text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -212,7 +221,7 @@ xtm_process_window_class_init (XtmProcessWindowClass *klass)
|
|||||||
static void
|
static void
|
||||||
xtm_process_window_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer user_data)
|
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));
|
g_return_if_fail (gtk_widget_is_toplevel (widget));
|
||||||
|
|
||||||
@@ -222,7 +231,7 @@ xtm_process_window_size_allocate (GtkWidget *widget, GtkAllocation *allocation,
|
|||||||
static void
|
static void
|
||||||
show_settings_dialog (GtkButton *button, gpointer user_data)
|
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);
|
g_signal_handler_block (G_OBJECT (window->window), window->handler);
|
||||||
xtm_settings_dialog_run (window->window);
|
xtm_settings_dialog_run (window->window);
|
||||||
@@ -244,13 +253,12 @@ xtm_process_window_unstick_view_event (GtkWidget *widget, GdkEvent *event, XtmPr
|
|||||||
GdkScrollDirection dir;
|
GdkScrollDirection dir;
|
||||||
gdouble y;
|
gdouble y;
|
||||||
|
|
||||||
if (! window->view_stuck)
|
if (!window->view_stuck)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (event->type == GDK_SCROLL && (
|
if (event->type == GDK_SCROLL &&
|
||||||
(gdk_event_get_scroll_direction (event, &dir) && dir == GDK_SCROLL_UP)
|
((gdk_event_get_scroll_direction (event, &dir) && dir == GDK_SCROLL_UP) ||
|
||||||
|| (gdk_event_get_scroll_deltas (event, NULL, &y) && y <= 0)
|
(gdk_event_get_scroll_deltas (event, NULL, &y) && y <= 0)))
|
||||||
))
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
window->view_stuck = FALSE;
|
window->view_stuck = FALSE;
|
||||||
@@ -263,10 +271,11 @@ xtm_process_window_unstick_view_cursor (GtkTreeView *tree_view, XtmProcessWindow
|
|||||||
{
|
{
|
||||||
GtkTreePath *cursor, *end;
|
GtkTreePath *cursor, *end;
|
||||||
|
|
||||||
if (! window->view_stuck)
|
if (!window->view_stuck)
|
||||||
return;
|
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);
|
gtk_tree_view_get_cursor (tree_view, &cursor, NULL);
|
||||||
if (cursor != NULL && gtk_tree_path_compare (cursor, end) >= 0)
|
if (cursor != NULL && gtk_tree_path_compare (cursor, end) >= 0)
|
||||||
window->view_stuck = FALSE;
|
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);
|
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);
|
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"));
|
button = GTK_WIDGET (gtk_builder_get_object (window->builder, "button-settings"));
|
||||||
g_signal_connect (G_OBJECT (button), "clicked",
|
g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (show_settings_dialog), window);
|
||||||
G_CALLBACK (show_settings_dialog), window);
|
|
||||||
|
|
||||||
button = GTK_WIDGET (gtk_builder_get_object (window->builder, "button-identify"));
|
button = GTK_WIDGET (gtk_builder_get_object (window->builder, "button-identify"));
|
||||||
#ifdef HAVE_LIBX11
|
#ifdef HAVE_LIBX11
|
||||||
if (GDK_IS_X11_DISPLAY (gdk_display_get_default ()))
|
if (GDK_IS_X11_DISPLAY (gdk_display_get_default ()))
|
||||||
g_signal_connect (G_OBJECT (button), "clicked",
|
g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (xwininfo_clicked_cb), window);
|
||||||
G_CALLBACK (xwininfo_clicked_cb), window);
|
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
gtk_widget_hide (button);
|
gtk_widget_hide (button);
|
||||||
@@ -319,8 +326,8 @@ xtm_process_window_init (XtmProcessWindow *window)
|
|||||||
guint refresh_rate;
|
guint refresh_rate;
|
||||||
|
|
||||||
g_object_get (window->settings,
|
g_object_get (window->settings,
|
||||||
"refresh-rate", &refresh_rate,
|
"refresh-rate", &refresh_rate,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
window->vpaned = GTK_WIDGET (gtk_builder_get_object (window->builder, "mainview-vpaned"));
|
window->vpaned = GTK_WIDGET (gtk_builder_get_object (window->builder, "mainview-vpaned"));
|
||||||
xfconf_g_property_bind (window->channel, SETTING_HANDLE_POSITION, G_TYPE_INT,
|
xfconf_g_property_bind (window->channel, SETTING_HANDLE_POSITION, G_TYPE_INT,
|
||||||
@@ -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);
|
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"));
|
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), "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);
|
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_set_tooltip_text (window->filter_entry, _("Filter on process name"));
|
||||||
gtk_widget_grab_focus (window->filter_entry);
|
gtk_widget_grab_focus (window->filter_entry);
|
||||||
|
|
||||||
@@ -452,22 +459,22 @@ xtm_process_window_key_pressed (XtmProcessWindow *window, GdkEventKey *event)
|
|||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
if (event->keyval == GDK_KEY_Escape &&
|
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))
|
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
|
else
|
||||||
g_signal_emit_by_name (window, "delete-event", event, &ret, G_TYPE_BOOLEAN);
|
g_signal_emit_by_name (window, "delete-event", event, &ret, G_TYPE_BOOLEAN);
|
||||||
}
|
}
|
||||||
else if (event->keyval == GDK_KEY_Escape ||
|
else if (event->keyval == GDK_KEY_Escape ||
|
||||||
(event->keyval == GDK_KEY_q && (event->state & GDK_CONTROL_MASK)))
|
(event->keyval == GDK_KEY_q && (event->state & GDK_CONTROL_MASK)))
|
||||||
{
|
{
|
||||||
g_signal_emit_by_name (window, "delete-event", event, &ret, G_TYPE_BOOLEAN);
|
g_signal_emit_by_name (window, "delete-event", event, &ret, G_TYPE_BOOLEAN);
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
}
|
}
|
||||||
else if (event->keyval == GDK_KEY_f && (event->state & GDK_CONTROL_MASK))
|
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);
|
xfconf_channel_set_bool (window->channel, SETTING_SHOW_FILTER, TRUE);
|
||||||
ret = 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));
|
g_return_if_fail (GTK_IS_WIDGET (XTM_PROCESS_WINDOW (widget)->window));
|
||||||
gtk_widget_show (XTM_PROCESS_WINDOW (widget)->window);
|
gtk_widget_show (XTM_PROCESS_WINDOW (widget)->window);
|
||||||
gtk_window_present (GTK_WINDOW (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
|
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_window_get_position (GTK_WINDOW (XTM_PROCESS_WINDOW (widget)->window), &winx, &winy);
|
||||||
gtk_widget_hide (XTM_PROCESS_WINDOW (widget)->window);
|
gtk_widget_hide (XTM_PROCESS_WINDOW (widget)->window);
|
||||||
gtk_window_move (GTK_WINDOW (XTM_PROCESS_WINDOW (widget)->window), winx, winy);
|
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 *
|
GtkTreeModel *
|
||||||
@@ -526,7 +533,7 @@ xtm_process_window_get_model (XtmProcessWindow *window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
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 text[100];
|
||||||
gchar value[4];
|
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);
|
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);
|
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 (value, sizeof (value), "%.0f", cpu);
|
||||||
g_snprintf (text, sizeof(text), _("CPU: %s%%"), value);
|
g_snprintf (text, sizeof (text), _("CPU: %s%%"), value);
|
||||||
gtk_widget_set_tooltip_text (window->cpu_monitor, text);
|
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);
|
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);
|
gtk_widget_set_tooltip_text (window->mem_monitor, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,29 +14,30 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <xfconf/xfconf.h>
|
#include <xfconf/xfconf.h>
|
||||||
|
|
||||||
#define XTM_TYPE_PROCESS_WINDOW (xtm_process_window_get_type ())
|
#define XTM_TYPE_PROCESS_WINDOW (xtm_process_window_get_type ())
|
||||||
#define XTM_PROCESS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XTM_TYPE_PROCESS_WINDOW, XtmProcessWindow))
|
#define XTM_PROCESS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XTM_TYPE_PROCESS_WINDOW, XtmProcessWindow))
|
||||||
#define XTM_PROCESS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XTM_TYPE_PROCESS_WINDOW, XtmProcessWindowClass))
|
#define XTM_PROCESS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XTM_TYPE_PROCESS_WINDOW, XtmProcessWindowClass))
|
||||||
#define XTM_IS_PROCESS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XTM_TYPE_PROCESS_WINDOW))
|
#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_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_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__ ); \
|
GtkWidget *dialog = gtk_message_dialog_new (NULL, 0, type, GTK_BUTTONS_OK, title); \
|
||||||
gtk_window_set_title (GTK_WINDOW (dialog), _("Task Manager")); \
|
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), message, ##__VA_ARGS__); \
|
||||||
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); \
|
gtk_window_set_title (GTK_WINDOW (dialog), _("Task Manager")); \
|
||||||
gtk_dialog_run (GTK_DIALOG (dialog)); \
|
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); \
|
||||||
gtk_widget_destroy (dialog); \
|
gtk_dialog_run (GTK_DIALOG (dialog)); \
|
||||||
}
|
gtk_widget_destroy (dialog); \
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct _XtmProcessWindow XtmProcessWindow;
|
typedef struct _XtmProcessWindow XtmProcessWindow;
|
||||||
|
|
||||||
GType xtm_process_window_get_type (void);
|
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_settings_init (XtmProcessWindow *window, XfconfChannel *channel);
|
||||||
void xtm_process_window_show (GtkWidget *widget);
|
void xtm_process_window_show (GtkWidget *widget);
|
||||||
GtkTreeModel * xtm_process_window_get_model (XtmProcessWindow *window);
|
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_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);
|
void xtm_process_window_show_swap_usage (XtmProcessWindow *window, gboolean show_swap_usage);
|
||||||
|
|
||||||
#endif /* !PROCESS_WINDOW_H */
|
#endif /* !PROCESS_WINDOW_H */
|
||||||
|
|||||||
@@ -21,14 +21,14 @@
|
|||||||
|
|
||||||
#include <libxfce4ui/libxfce4ui.h>
|
#include <libxfce4ui/libxfce4ui.h>
|
||||||
|
|
||||||
static void show_about_dialog (GtkWidget *widget, gpointer user_data);
|
static void show_about_dialog (GtkWidget *widget, gpointer user_data);
|
||||||
static GtkWidget *xtm_settings_dialog_new (GtkBuilder *builder, GtkWidget *parent_window);
|
static GtkWidget *xtm_settings_dialog_new (GtkBuilder *builder, GtkWidget *parent_window);
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
GtkWidget *combobox;
|
GtkWidget *combobox;
|
||||||
guint rate;
|
guint rate;
|
||||||
} XtmRefreshRate;
|
} XtmRefreshRate;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -58,7 +58,7 @@ combobox_changed (GtkComboBox *combobox, XtmSettings *settings)
|
|||||||
{
|
{
|
||||||
GtkTreeModel *model;
|
GtkTreeModel *model;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
GValue prop = { 0, };
|
GValue prop = G_VALUE_INIT;
|
||||||
gint rate;
|
gint rate;
|
||||||
|
|
||||||
gtk_combo_box_get_active_iter (combobox, &iter);
|
gtk_combo_box_get_active_iter (combobox, &iter);
|
||||||
@@ -69,17 +69,14 @@ combobox_changed (GtkComboBox *combobox, XtmSettings *settings)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
combobox_foreach (GtkTreeModel *model,
|
combobox_foreach (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data)
|
||||||
GtkTreePath *path,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
XtmRefreshRate *refresh_rate = user_data;
|
XtmRefreshRate *refresh_rate = user_data;
|
||||||
GValue prop = { 0, };
|
GValue prop = G_VALUE_INIT;
|
||||||
|
|
||||||
gtk_tree_model_get_value (model, iter, 0, &prop);
|
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);
|
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (refresh_rate->combobox), iter);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -134,7 +131,8 @@ show_about_dialog (GtkWidget *widget, gpointer user_data)
|
|||||||
"OpenSolaris",
|
"OpenSolaris",
|
||||||
" \342\200\242 Mike Massonnet",
|
" \342\200\242 Mike Massonnet",
|
||||||
" \342\200\242 Peter Tribble",
|
" \342\200\242 Peter Tribble",
|
||||||
NULL };
|
NULL
|
||||||
|
};
|
||||||
const gchar *license =
|
const gchar *license =
|
||||||
"This program is free software; you can redistribute it and/or modify\n"
|
"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"
|
"it under the terms of the GNU General Public License as published by\n"
|
||||||
|
|||||||
@@ -13,6 +13,6 @@
|
|||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
void xtm_settings_dialog_run (GtkWidget *parent_window);
|
void xtm_settings_dialog_run (GtkWidget *parent_window);
|
||||||
|
|
||||||
#endif /* !SETTINGS_DIALOG_H */
|
#endif /* !SETTINGS_DIALOG_H */
|
||||||
|
|||||||
@@ -56,19 +56,19 @@ enum
|
|||||||
typedef struct _XtmSettingsClass XtmSettingsClass;
|
typedef struct _XtmSettingsClass XtmSettingsClass;
|
||||||
struct _XtmSettingsClass
|
struct _XtmSettingsClass
|
||||||
{
|
{
|
||||||
GObjectClass parent_class;
|
GObjectClass parent_class;
|
||||||
};
|
};
|
||||||
struct _XtmSettings
|
struct _XtmSettings
|
||||||
{
|
{
|
||||||
GObject parent;
|
GObject parent;
|
||||||
/*<private>*/
|
/*<private>*/
|
||||||
GValue values[N_PROPS];
|
GValue values[N_PROPS];
|
||||||
};
|
};
|
||||||
G_DEFINE_TYPE (XtmSettings, xtm_settings, G_TYPE_OBJECT)
|
G_DEFINE_TYPE (XtmSettings, xtm_settings, G_TYPE_OBJECT)
|
||||||
|
|
||||||
static void xtm_settings_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
|
static void xtm_settings_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
|
||||||
static void xtm_settings_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
|
static void xtm_settings_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
|
||||||
static void xtm_settings_finalize (GObject *object);
|
static void xtm_settings_finalize (GObject *object);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xtm_settings_class_init (XtmSettingsClass *klass)
|
xtm_settings_class_init (XtmSettingsClass *klass)
|
||||||
@@ -129,7 +129,6 @@ xtm_settings_class_init (XtmSettingsClass *klass)
|
|||||||
static void
|
static void
|
||||||
xtm_settings_init (XtmSettings *settings)
|
xtm_settings_init (XtmSettings *settings)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
@@ -13,58 +13,58 @@
|
|||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
#include <xfconf/xfconf.h>
|
#include <xfconf/xfconf.h>
|
||||||
|
|
||||||
#define DEFAULT_WINDOW_HEIGHT 600
|
#define DEFAULT_WINDOW_HEIGHT 600
|
||||||
#define DEFAULT_WINDOW_WIDTH 400
|
#define DEFAULT_WINDOW_WIDTH 400
|
||||||
|
|
||||||
#define CHANNEL "xfce4-taskmanager"
|
#define CHANNEL "xfce4-taskmanager"
|
||||||
|
|
||||||
/* general settings */
|
/* general settings */
|
||||||
#define SETTING_SHOW_STATUS_ICON "/show-status-icon"
|
#define SETTING_SHOW_STATUS_ICON "/show-status-icon"
|
||||||
#define SETTING_PROMPT_TERMINATE_TASK "/prompt-terminate-task"
|
#define SETTING_PROMPT_TERMINATE_TASK "/prompt-terminate-task"
|
||||||
#define SETTING_WINDOW_MAXIMIZED "/window-maximized"
|
#define SETTING_WINDOW_MAXIMIZED "/window-maximized"
|
||||||
#define SETTING_WINDOW_WIDTH "/window-width"
|
#define SETTING_WINDOW_WIDTH "/window-width"
|
||||||
#define SETTING_WINDOW_HEIGHT "/window-height"
|
#define SETTING_WINDOW_HEIGHT "/window-height"
|
||||||
|
|
||||||
/* interface settings */
|
/* interface settings */
|
||||||
#define SETTING_SHOW_FILTER "/interface/show-filter"
|
#define SETTING_SHOW_FILTER "/interface/show-filter"
|
||||||
#define SETTING_HANDLE_POSITION "/interface/handle-position"
|
#define SETTING_HANDLE_POSITION "/interface/handle-position"
|
||||||
#define SETTING_SHOW_LEGEND "/interface/show-legend"
|
#define SETTING_SHOW_LEGEND "/interface/show-legend"
|
||||||
|
|
||||||
#define SETTING_SHOW_ALL_PROCESSES "/interface/show-all-processes"
|
#define SETTING_SHOW_ALL_PROCESSES "/interface/show-all-processes"
|
||||||
#define SETTING_SHOW_APPLICATION_ICONS "/interface/show-application-icons"
|
#define SETTING_SHOW_APPLICATION_ICONS "/interface/show-application-icons"
|
||||||
#define SETTING_FULL_COMMAND_LINE "/interface/full-command-line"
|
#define SETTING_FULL_COMMAND_LINE "/interface/full-command-line"
|
||||||
#define SETTING_MORE_PRECISION "/interface/more-precision"
|
#define SETTING_MORE_PRECISION "/interface/more-precision"
|
||||||
#define SETTING_PROCESS_TREE "/interface/process-tree"
|
#define SETTING_PROCESS_TREE "/interface/process-tree"
|
||||||
#define SETTING_REFRESH_RATE "/interface/refresh-rate"
|
#define SETTING_REFRESH_RATE "/interface/refresh-rate"
|
||||||
|
|
||||||
/* column visibility */
|
/* column visibility */
|
||||||
#define SETTING_COLUMN_PID "/columns/column-pid"
|
#define SETTING_COLUMN_PID "/columns/column-pid"
|
||||||
#define SETTING_COLUMN_PPID "/columns/column-ppid"
|
#define SETTING_COLUMN_PPID "/columns/column-ppid"
|
||||||
#define SETTING_COLUMN_STATE "/columns/column-state"
|
#define SETTING_COLUMN_STATE "/columns/column-state"
|
||||||
#define SETTING_COLUMN_VSZ "/columns/column-vsz"
|
#define SETTING_COLUMN_VSZ "/columns/column-vsz"
|
||||||
#define SETTING_COLUMN_GROUP_VSZ "/columns/column-group-vsz"
|
#define SETTING_COLUMN_GROUP_VSZ "/columns/column-group-vsz"
|
||||||
#define SETTING_COLUMN_RSS "/columns/column-rss"
|
#define SETTING_COLUMN_RSS "/columns/column-rss"
|
||||||
#define SETTING_COLUMN_GROUP_RSS "/columns/column-group-rss"
|
#define SETTING_COLUMN_GROUP_RSS "/columns/column-group-rss"
|
||||||
#define SETTING_COLUMN_UID "/columns/column-uid"
|
#define SETTING_COLUMN_UID "/columns/column-uid"
|
||||||
#define SETTING_COLUMN_CPU "/columns/column-cpu"
|
#define SETTING_COLUMN_CPU "/columns/column-cpu"
|
||||||
#define SETTING_COLUMN_GROUP_CPU "/columns/column-group-cpu"
|
#define SETTING_COLUMN_GROUP_CPU "/columns/column-group-cpu"
|
||||||
#define SETTING_COLUMN_PRIORITY "/columns/column-priority"
|
#define SETTING_COLUMN_PRIORITY "/columns/column-priority"
|
||||||
#define SETTING_COLUMN_SORT_ID "/columns/sort-id"
|
#define SETTING_COLUMN_SORT_ID "/columns/sort-id"
|
||||||
#define SETTING_COLUMN_SORT_TYPE "/columns/sort-type"
|
#define SETTING_COLUMN_SORT_TYPE "/columns/sort-type"
|
||||||
#define SETTING_COLUMN_POSITIONS "/columns/positions"
|
#define SETTING_COLUMN_POSITIONS "/columns/positions"
|
||||||
|
|
||||||
#define XTM_TYPE_SETTINGS (xtm_settings_get_type ())
|
#define XTM_TYPE_SETTINGS (xtm_settings_get_type ())
|
||||||
#define XTM_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XTM_TYPE_SETTINGS, XtmSettings))
|
#define XTM_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XTM_TYPE_SETTINGS, XtmSettings))
|
||||||
#define XTM_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XTM_TYPE_SETTINGS, XtmSettingsClass))
|
#define XTM_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XTM_TYPE_SETTINGS, XtmSettingsClass))
|
||||||
#define XTM_IS_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XTM_TYPE_SETTINGS))
|
#define XTM_IS_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XTM_TYPE_SETTINGS))
|
||||||
#define XTM_IS_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XTM_TYPE_SETTINGS))
|
#define XTM_IS_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XTM_TYPE_SETTINGS))
|
||||||
#define XTM_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_SETTINGS, XtmSettingsClass))
|
#define XTM_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_SETTINGS, XtmSettingsClass))
|
||||||
|
|
||||||
typedef struct _XtmSettings XtmSettings;
|
typedef struct _XtmSettings XtmSettings;
|
||||||
|
|
||||||
void xtm_settings_bind_xfconf (XtmSettings *settings, XfconfChannel *channel);
|
void xtm_settings_bind_xfconf (XtmSettings *settings, XfconfChannel *channel);
|
||||||
GType xtm_settings_get_type (void);
|
GType xtm_settings_get_type (void);
|
||||||
XtmSettings * xtm_settings_get_default (void);
|
XtmSettings *xtm_settings_get_default (void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -43,11 +43,12 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
extern int errno;
|
extern int errno;
|
||||||
|
|
||||||
char *state_abbrev[] = {
|
char *state_abbrev[] = {
|
||||||
"", "start", "run", "sleep", "stop", "zomb", "dead", "onproc"
|
"", "start", "run", "sleep", "stop", "zomb", "dead", "onproc"
|
||||||
};
|
};
|
||||||
|
|
||||||
gboolean get_task_list (GArray *task_list)
|
gboolean
|
||||||
|
get_task_list (GArray *task_list)
|
||||||
{
|
{
|
||||||
int mib[6];
|
int mib[6];
|
||||||
size_t size;
|
size_t size;
|
||||||
@@ -58,7 +59,7 @@ gboolean get_task_list (GArray *task_list)
|
|||||||
#endif
|
#endif
|
||||||
Task t;
|
Task t;
|
||||||
char **args;
|
char **args;
|
||||||
gchar* buf;
|
gchar *buf;
|
||||||
int nproc, i;
|
int nproc, i;
|
||||||
|
|
||||||
mib[0] = CTL_KERN;
|
mib[0] = CTL_KERN;
|
||||||
@@ -70,85 +71,88 @@ gboolean get_task_list (GArray *task_list)
|
|||||||
mib[2] = KERN_PROC_ALL;
|
mib[2] = KERN_PROC_ALL;
|
||||||
mib[3] = 0;
|
mib[3] = 0;
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
mib[4] = sizeof(struct kinfo_proc);
|
mib[4] = sizeof (struct kinfo_proc);
|
||||||
#else
|
#else
|
||||||
mib[4] = sizeof(struct kinfo_proc2);
|
mib[4] = sizeof (struct kinfo_proc2);
|
||||||
#endif
|
#endif
|
||||||
mib[5] = 0;
|
mib[5] = 0;
|
||||||
if (sysctl(mib, 6, NULL, &size, NULL, 0) < 0)
|
if (sysctl (mib, 6, NULL, &size, NULL, 0) < 0)
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
errx(1, "could not get kern.proc size");
|
errx (1, "could not get kern.proc size");
|
||||||
#else
|
#else
|
||||||
errx(1, "could not get kern.proc2 size");
|
errx (1, "could not get kern.proc2 size");
|
||||||
#endif
|
#endif
|
||||||
size = 5 * size / 4; /* extra slop */
|
size = 5 * size / 4; /* extra slop */
|
||||||
if ((kp = malloc(size)) == NULL)
|
if ((kp = malloc (size)) == NULL)
|
||||||
errx(1,"failed to allocate memory for proc structures");
|
errx (1, "failed to allocate memory for proc structures");
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
mib[5] = (int)(size / sizeof(struct kinfo_proc));
|
mib[5] = (int)(size / sizeof (struct kinfo_proc));
|
||||||
#else
|
#else
|
||||||
mib[5] = (int)(size / sizeof(struct kinfo_proc2));
|
mib[5] = (int)(size / sizeof (struct kinfo_proc2));
|
||||||
#endif
|
#endif
|
||||||
if (sysctl(mib, 6, kp, &size, NULL, 0) < 0)
|
if (sysctl (mib, 6, kp, &size, NULL, 0) < 0)
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
errx(1, "could not read kern.proc");
|
errx (1, "could not read kern.proc");
|
||||||
nproc = (int)(size / sizeof(struct kinfo_proc));
|
nproc = (int)(size / sizeof (struct kinfo_proc));
|
||||||
#else
|
#else
|
||||||
errx(1, "could not read kern.proc2");
|
errx (1, "could not read kern.proc2");
|
||||||
nproc = (int)(size / sizeof(struct kinfo_proc2));
|
nproc = (int)(size / sizeof (struct kinfo_proc2));
|
||||||
#endif
|
#endif
|
||||||
for (i=0 ; i < nproc ; i++)
|
for (i = 0; i < nproc; i++)
|
||||||
{
|
{
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
struct kinfo_proc p = kp[i];
|
struct kinfo_proc p = kp[i];
|
||||||
#else
|
#else
|
||||||
struct kinfo_proc2 p = kp[i];
|
struct kinfo_proc2 p = kp[i];
|
||||||
#endif
|
#endif
|
||||||
memset(&t, 0, sizeof(t));
|
memset (&t, 0, sizeof (t));
|
||||||
t.pid = p.p_pid;
|
t.pid = p.p_pid;
|
||||||
t.ppid = p.p_ppid;
|
t.ppid = p.p_ppid;
|
||||||
t.uid = p.p_uid;
|
t.uid = p.p_uid;
|
||||||
t.prio = p.p_priority - PZERO;
|
t.prio = p.p_priority - PZERO;
|
||||||
t.vsz = p.p_vm_dsize + p.p_vm_ssize + p.p_vm_tsize;
|
t.vsz = p.p_vm_dsize + p.p_vm_ssize + p.p_vm_tsize;
|
||||||
t.vsz *= getpagesize();
|
t.vsz *= getpagesize ();
|
||||||
t.rss = p.p_vm_rssize * getpagesize();
|
t.rss = p.p_vm_rssize * getpagesize ();
|
||||||
g_snprintf(t.state, sizeof t.state, "%s", state_abbrev[p.p_stat]);
|
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);
|
g_strlcpy (t.name, p.p_comm, strlen (p.p_comm) + 1);
|
||||||
/* shamelessly stolen from top/machine.c */
|
/* shamelessly stolen from top/machine.c */
|
||||||
if (!P_ZOMBIE(&p)) {
|
if (!P_ZOMBIE (&p))
|
||||||
|
{
|
||||||
size = 1024;
|
size = 1024;
|
||||||
if ((args = malloc(size)) == NULL)
|
if ((args = malloc (size)) == NULL)
|
||||||
errx(1,"failed to allocate memory for argv structures at %zu", size);
|
errx (1, "failed to allocate memory for argv structures at %zu", size);
|
||||||
memset(args, 0, size);
|
memset (args, 0, size);
|
||||||
for (;; size *= 2) {
|
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);
|
if ((args = realloc (args, size)) == NULL)
|
||||||
memset(args, 0, size);
|
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[0] = CTL_KERN;
|
||||||
mib[1] = KERN_PROC_ARGS;
|
mib[1] = KERN_PROC_ARGS;
|
||||||
mib[2] = t.pid;
|
mib[2] = t.pid;
|
||||||
mib[3] = KERN_PROC_ARGV;
|
mib[3] = KERN_PROC_ARGV;
|
||||||
if (sysctl(mib, 4, args, &size, NULL, 0) == 0)
|
if (sysctl (mib, 4, args, &size, NULL, 0) == 0)
|
||||||
break;
|
break;
|
||||||
if (errno != ENOMEM) { /* ESRCH: process disappeared */
|
if (errno != ENOMEM)
|
||||||
/* printf ("process with pid %d disappeared, errno=%d\n", t.pid, errno); */
|
{ /* ESRCH: process disappeared */
|
||||||
args[0] ='\0';
|
/* printf ("process with pid %d disappeared, errno=%d\n", t.pid, errno); */
|
||||||
|
args[0] = '\0';
|
||||||
args[1] = NULL;
|
args[1] = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf = g_strjoinv(" ", args);
|
buf = g_strjoinv (" ", args);
|
||||||
g_assert(g_utf8_validate(buf, -1, NULL));
|
g_assert (g_utf8_validate (buf, -1, NULL));
|
||||||
g_strlcpy(t.cmdline, buf, sizeof t.cmdline);
|
g_strlcpy (t.cmdline, buf, sizeof t.cmdline);
|
||||||
g_free(buf);
|
g_free (buf);
|
||||||
free(args);
|
free (args);
|
||||||
}
|
}
|
||||||
|
|
||||||
t.cpu_user = (100.0f * ((gfloat)p.p_pctcpu / FSCALE));
|
t.cpu_user = (100.0f * ((gfloat)p.p_pctcpu / FSCALE));
|
||||||
t.cpu_system = 0.0f; /* TODO ? */
|
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);
|
g_array_sort (task_list, task_pid_compare_fn);
|
||||||
|
|
||||||
@@ -161,10 +165,10 @@ pid_is_sleeping (GPid pid)
|
|||||||
int mib[6];
|
int mib[6];
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
struct kinfo_proc kp;
|
struct kinfo_proc kp;
|
||||||
size_t size = sizeof(struct kinfo_proc);
|
size_t size = sizeof (struct kinfo_proc);
|
||||||
#else
|
#else
|
||||||
struct kinfo_proc2 kp;
|
struct kinfo_proc2 kp;
|
||||||
size_t size = sizeof(struct kinfo_proc2);
|
size_t size = sizeof (struct kinfo_proc2);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mib[0] = CTL_KERN;
|
mib[0] = CTL_KERN;
|
||||||
@@ -176,30 +180,31 @@ pid_is_sleeping (GPid pid)
|
|||||||
mib[2] = KERN_PROC_PID;
|
mib[2] = KERN_PROC_PID;
|
||||||
mib[3] = pid;
|
mib[3] = pid;
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
mib[4] = sizeof(struct kinfo_proc);
|
mib[4] = sizeof (struct kinfo_proc);
|
||||||
#else
|
#else
|
||||||
mib[4] = sizeof(struct kinfo_proc2);
|
mib[4] = sizeof (struct kinfo_proc2);
|
||||||
#endif
|
#endif
|
||||||
mib[5] = 1;
|
mib[5] = 1;
|
||||||
if (sysctl(mib, 6, &kp, &size, NULL, 0) < 0)
|
if (sysctl (mib, 6, &kp, &size, NULL, 0) < 0)
|
||||||
#ifdef __OpenBSD__
|
#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
|
#else
|
||||||
errx(1, "could not read kern.proc2 for pid %d", pid);
|
errx (1, "could not read kern.proc2 for pid %d", pid);
|
||||||
#endif
|
#endif
|
||||||
return (kp.p_stat == SSTOP ? TRUE : FALSE);
|
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 cur_user = 0, cur_system = 0, cur_total = 0;
|
||||||
static gulong old_user = 0, old_system = 0, old_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];
|
glong cp_time[CPUSTATES];
|
||||||
gsize size = sizeof( cp_time );
|
gsize size = sizeof (cp_time);
|
||||||
if (sysctl(mib, 2, &cp_time, &size, NULL, 0) < 0)
|
if (sysctl (mib, 2, &cp_time, &size, NULL, 0) < 0)
|
||||||
errx(1,"failed to get kern.cptime");
|
errx (1, "failed to get kern.cptime");
|
||||||
|
|
||||||
old_user = cur_user;
|
old_user = cur_user;
|
||||||
old_system = cur_system;
|
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;
|
*cpu_system = (old_total > 0) ? (((cur_system - old_system) * 100.0f) / (float)(cur_total - old_total)) : 0.0f;
|
||||||
|
|
||||||
/* get #cpu */
|
/* get #cpu */
|
||||||
size = sizeof(&cpu_count);
|
size = sizeof (&cpu_count);
|
||||||
mib[0] = CTL_HW;
|
mib[0] = CTL_HW;
|
||||||
mib[1] = HW_NCPU;
|
mib[1] = HW_NCPU;
|
||||||
if (sysctl(mib, 2, cpu_count, &size, NULL, 0) == -1)
|
if (sysctl (mib, 2, cpu_count, &size, NULL, 0) == -1)
|
||||||
errx(1,"failed to get cpu count");
|
errx (1, "failed to get cpu count");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vmtotal values in #pg */
|
/* vmtotal values in #pg */
|
||||||
#define pagetok(nb) ((nb) * (getpagesize()))
|
#define pagetok(nb) ((nb) * (getpagesize ()))
|
||||||
|
|
||||||
gboolean
|
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)
|
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__
|
#ifdef __OpenBSD__
|
||||||
int mib[] = {CTL_VM, VM_UVMEXP};
|
int mib[] = { CTL_VM, VM_UVMEXP };
|
||||||
struct uvmexp uvmexp;
|
struct uvmexp uvmexp;
|
||||||
#else
|
#else
|
||||||
int mib[] = {CTL_VM, VM_METER};
|
int mib[] = { CTL_VM, VM_METER };
|
||||||
struct vmtotal vmtotal;
|
struct vmtotal vmtotal;
|
||||||
#endif
|
#endif
|
||||||
struct swapent *swdev;
|
struct swapent *swdev;
|
||||||
int nswap, i;
|
int nswap, i;
|
||||||
size_t size;
|
size_t size;
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
size = sizeof(uvmexp);
|
size = sizeof (uvmexp);
|
||||||
if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0)
|
if (sysctl (mib, 2, &uvmexp, &size, NULL, 0) < 0)
|
||||||
errx(1,"failed to get vm.uvmexp");
|
errx (1, "failed to get vm.uvmexp");
|
||||||
/* cheat : rm = tot used, add free to get total */
|
/* cheat : rm = tot used, add free to get total */
|
||||||
*memory_free = pagetok((guint64)uvmexp.free);
|
*memory_free = pagetok ((guint64)uvmexp.free);
|
||||||
*memory_total = pagetok((guint64)uvmexp.npages);
|
*memory_total = pagetok ((guint64)uvmexp.npages);
|
||||||
*memory_cache = 0;
|
*memory_cache = 0;
|
||||||
*memory_buffers = 0; /*pagetok(uvmexp.npages - uvmexp.free - uvmexp.active);*/
|
*memory_buffers = 0; /*pagetok(uvmexp.npages - uvmexp.free - uvmexp.active);*/
|
||||||
#else
|
#else
|
||||||
size = sizeof(vmtotal);
|
size = sizeof (vmtotal);
|
||||||
if (sysctl(mib, 2, &vmtotal, &size, NULL, 0) < 0)
|
if (sysctl (mib, 2, &vmtotal, &size, NULL, 0) < 0)
|
||||||
errx(1,"failed to get vm.meter");
|
errx (1, "failed to get vm.meter");
|
||||||
/* cheat : rm = tot used, add free to get total */
|
/* cheat : rm = tot used, add free to get total */
|
||||||
*memory_total = pagetok(vmtotal.t_rm + vmtotal.t_free);
|
*memory_total = pagetok (vmtotal.t_rm + vmtotal.t_free);
|
||||||
*memory_free = pagetok(vmtotal.t_free);
|
*memory_free = pagetok (vmtotal.t_free);
|
||||||
*memory_cache = 0;
|
*memory_cache = 0;
|
||||||
*memory_buffers = pagetok(vmtotal.t_rm - vmtotal.t_arm);
|
*memory_buffers = pagetok (vmtotal.t_rm - vmtotal.t_arm);
|
||||||
#endif
|
#endif
|
||||||
*memory_available = *memory_free + *memory_cache + *memory_buffers;
|
*memory_available = *memory_free + *memory_cache + *memory_buffers;
|
||||||
|
|
||||||
/* get swap stats */
|
/* get swap stats */
|
||||||
*swap_total = *swap_free = 0;
|
*swap_total = *swap_free = 0;
|
||||||
if ((nswap = swapctl(SWAP_NSWAP, 0, 0)) == 0)
|
if ((nswap = swapctl (SWAP_NSWAP, 0, 0)) == 0)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
if ((swdev = calloc(nswap, sizeof(*swdev))) == NULL)
|
if ((swdev = calloc (nswap, sizeof (*swdev))) == NULL)
|
||||||
errx(1,"failed to allocate memory for swdev structures");
|
errx (1, "failed to allocate memory for swdev structures");
|
||||||
|
|
||||||
if (swapctl(SWAP_STATS, swdev, nswap) == -1) {
|
if (swapctl (SWAP_STATS, swdev, nswap) == -1)
|
||||||
free(swdev);
|
{
|
||||||
errx(1,"failed to get swap stats");
|
free (swdev);
|
||||||
|
errx (1, "failed to get swap stats");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Total things up */
|
/* Total things up */
|
||||||
for (i = 0; i < nswap; i++) {
|
for (i = 0; i < nswap; i++)
|
||||||
if (swdev[i].se_flags & SWF_ENABLE) {
|
{
|
||||||
|
if (swdev[i].se_flags & SWF_ENABLE)
|
||||||
|
{
|
||||||
*swap_free += (swdev[i].se_nblks - swdev[i].se_inuse);
|
*swap_free += (swdev[i].se_nblks - swdev[i].se_inuse);
|
||||||
*swap_total += swdev[i].se_nblks;
|
*swap_total += swdev[i].se_nblks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*swap_total *= DEV_BSIZE;
|
*swap_total *= DEV_BSIZE;
|
||||||
*swap_free *= DEV_BSIZE;
|
*swap_free *= DEV_BSIZE;
|
||||||
free(swdev);
|
free (swdev);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ get_memory_usage (guint64 *memory_total, guint64 *memory_available, guint64 *mem
|
|||||||
{
|
{
|
||||||
/* Get memory usage */
|
/* 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_free = get_mem_by_pages ("vm.stats.vm.v_free_count");
|
||||||
*memory_cache = get_mem_by_pages ("vm.stats.vm.v_inactive_count");
|
*memory_cache = get_mem_by_pages ("vm.stats.vm.v_inactive_count");
|
||||||
*memory_buffers = get_mem_by_bytes ("vfs.bufspace");
|
*memory_buffers = get_mem_by_bytes ("vfs.bufspace");
|
||||||
@@ -139,7 +139,7 @@ get_task_details (struct kinfo_proc *kp, Task *task)
|
|||||||
size_t bufsz;
|
size_t bufsz;
|
||||||
int i, oid[4];
|
int i, oid[4];
|
||||||
|
|
||||||
memset(task, 0, sizeof(Task));
|
memset (task, 0, sizeof (Task));
|
||||||
task->pid = kp->ki_pid;
|
task->pid = kp->ki_pid;
|
||||||
task->ppid = kp->ki_ppid;
|
task->ppid = kp->ki_ppid;
|
||||||
task->cpu_user = 100.0f * ((float)kp->ki_pctcpu / FSCALE);
|
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->rss = ((guint64)kp->ki_rssize * (guint64)getpagesize ());
|
||||||
task->uid = kp->ki_uid;
|
task->uid = kp->ki_uid;
|
||||||
task->prio = kp->ki_nice;
|
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[0] = CTL_KERN;
|
||||||
oid[1] = KERN_PROC;
|
oid[1] = KERN_PROC;
|
||||||
oid[2] = KERN_PROC_ARGS;
|
oid[2] = KERN_PROC_ARGS;
|
||||||
oid[3] = kp->ki_pid;
|
oid[3] = kp->ki_pid;
|
||||||
bufsz = sizeof(buf);
|
bufsz = sizeof (buf);
|
||||||
memset(buf, 0, sizeof(buf));
|
memset (buf, 0, sizeof (buf));
|
||||||
if (sysctl(oid, 4, buf, &bufsz, 0, 0) == -1) {
|
if (sysctl (oid, 4, buf, &bufsz, 0, 0) == -1)
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* If the supplied buf is too short to hold the requested
|
* If the supplied buf is too short to hold the requested
|
||||||
* value the sysctl returns with ENOMEM. The buf is filled
|
* value the sysctl returns with ENOMEM. The buf is filled
|
||||||
* with the truncated value and the returned bufsz is equal
|
* with the truncated value and the returned bufsz is equal
|
||||||
* to the requested len.
|
* to the requested len.
|
||||||
*/
|
*/
|
||||||
if (errno != ENOMEM || bufsz != sizeof(buf)) {
|
if (errno != ENOMEM || bufsz != sizeof (buf))
|
||||||
|
{
|
||||||
bufsz = 0;
|
bufsz = 0;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
buf[(bufsz - 1)] = 0;
|
buf[(bufsz - 1)] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 != bufsz) {
|
if (0 != bufsz)
|
||||||
|
{
|
||||||
p = buf;
|
p = buf;
|
||||||
do {
|
do
|
||||||
g_strlcat (task->cmdline, p, sizeof(task->cmdline));
|
{
|
||||||
g_strlcat (task->cmdline, " ", sizeof(task->cmdline));
|
g_strlcat (task->cmdline, p, sizeof (task->cmdline));
|
||||||
p += (strlen(p) + 1);
|
g_strlcat (task->cmdline, " ", sizeof (task->cmdline));
|
||||||
|
p += (strlen (p) + 1);
|
||||||
} while (p < buf + bufsz);
|
} while (p < buf + bufsz);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_strlcpy (task->cmdline, kp->ki_comm, sizeof(task->cmdline));
|
g_strlcpy (task->cmdline, kp->ki_comm, sizeof (task->cmdline));
|
||||||
}
|
}
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|||||||
@@ -22,19 +22,13 @@ get_memory_usage (guint64 *memory_total, guint64 *memory_available, guint64 *mem
|
|||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
gchar *filename = "/proc/meminfo";
|
gchar *filename = "/proc/meminfo";
|
||||||
guint64 mem_total = 0,
|
guint64 mem_total = 0, mem_free = 0, mem_avail = 0, mem_cached = 0, mem_buffers = 0, swp_total = 0, swp_free = 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)
|
if ((file = fopen (filename, "r")) != NULL)
|
||||||
{
|
{
|
||||||
gint found = 0;
|
gint found = 0;
|
||||||
gchar buffer[256];
|
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_total ? sscanf (buffer, "MemTotal:\t%lu kB", &mem_total) : 0;
|
||||||
found += !mem_free ? sscanf (buffer, "MemFree:\t%lu kB", &mem_free) : 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)
|
if ((file = fopen (filename, "r")) == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (fgets (buffer, sizeof(buffer), file) == NULL)
|
if (fgets (buffer, sizeof (buffer), file) == NULL)
|
||||||
{
|
{
|
||||||
fclose (file);
|
fclose (file);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -85,7 +79,7 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
|
|||||||
|
|
||||||
if (_cpu_count == 0)
|
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')
|
if (buffer[0] != 'c' && buffer[1] != 'p' && buffer[2] != 'u')
|
||||||
break;
|
break;
|
||||||
@@ -117,7 +111,8 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int get_pagesize (void)
|
static inline int
|
||||||
|
get_pagesize (void)
|
||||||
{
|
{
|
||||||
static int pagesize = 0;
|
static int pagesize = 0;
|
||||||
if (pagesize == 0)
|
if (pagesize == 0)
|
||||||
@@ -137,7 +132,7 @@ get_task_cmdline (Task *task)
|
|||||||
gint i;
|
gint i;
|
||||||
gint c;
|
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)
|
if ((file = fopen (filename, "r")) == NULL)
|
||||||
return FALSE;
|
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++)
|
for (i = 0; (c = fgetc (file)) != EOF && i < (gint)sizeof (task->cmdline) - 1; i++)
|
||||||
task->cmdline[i] = (c == '\0') ? ' ' : (gchar)c;
|
task->cmdline[i] = (c == '\0') ? ' ' : (gchar)c;
|
||||||
task->cmdline[i] = '\0';
|
task->cmdline[i] = '\0';
|
||||||
if (i > 0 && task->cmdline[i-1] == ' ')
|
if (i > 0 && task->cmdline[i - 1] == ' ')
|
||||||
task->cmdline[i-1] = '\0';
|
task->cmdline[i - 1] = '\0';
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
|
||||||
/* Kernel processes don't have a cmdline nor an exec path */
|
/* 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);
|
size_t len = strlen (task->name);
|
||||||
g_strlcpy (&task->cmdline[1], task->name, len + 1);
|
g_strlcpy (&task->cmdline[1], task->name, len + 1);
|
||||||
task->cmdline[0] = '[';
|
task->cmdline[0] = '[';
|
||||||
task->cmdline[len+1] = ']';
|
task->cmdline[len + 1] = ']';
|
||||||
task->cmdline[len+2] = '\0';
|
task->cmdline[len + 2] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -201,17 +196,17 @@ get_task_details (GPid pid, Task *task)
|
|||||||
gchar filename[96];
|
gchar filename[96];
|
||||||
gchar buffer[1024];
|
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)
|
if ((file = fopen (filename, "r")) == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (fgets (buffer, sizeof(buffer), file) == NULL)
|
if (fgets (buffer, sizeof (buffer), file) == NULL)
|
||||||
{
|
{
|
||||||
fclose (file);
|
fclose (file);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
|
||||||
memset(task, 0, sizeof(Task));
|
memset (task, 0, sizeof (Task));
|
||||||
|
|
||||||
/* Scanning the short process name is unreliable with scanf when it contains
|
/* Scanning the short process name is unreliable with scanf when it contains
|
||||||
* spaces, retrieve it manually and fill the buffer */
|
* spaces, retrieve it manually and fill the buffer */
|
||||||
@@ -238,57 +233,56 @@ get_task_details (GPid pid, Task *task)
|
|||||||
gint idummy;
|
gint idummy;
|
||||||
gulong jiffies_user = 0, jiffies_system = 0;
|
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
|
&task->pid, // processid
|
||||||
dummy, // processname
|
dummy, // processname
|
||||||
task->state, // processstate
|
task->state, // processstate
|
||||||
&task->ppid, // parentid
|
&task->ppid, // parentid
|
||||||
&idummy, // processs groupid
|
&idummy, // processs groupid
|
||||||
|
|
||||||
&idummy, // session id
|
&idummy, // session id
|
||||||
&idummy, // tty id
|
&idummy, // tty id
|
||||||
&idummy, // tpgid the process group ID of the process running on tty of the process
|
&idummy, // tpgid the process group ID of the process running on tty of the process
|
||||||
dummy, // flags
|
dummy, // flags
|
||||||
dummy, // minflt minor faults the process has maid
|
dummy, // minflt minor faults the process has maid
|
||||||
|
|
||||||
dummy, // cminflt
|
dummy, // cminflt
|
||||||
dummy, // majflt
|
dummy, // majflt
|
||||||
dummy, // cmajflt
|
dummy, // cmajflt
|
||||||
&jiffies_user, // utime the number of jiffies that this process has scheduled in user mode
|
&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, // cutime " waited for children in user mode
|
||||||
&idummy, // cstime " system mode
|
&idummy, // cstime " system mode
|
||||||
&idummy, // priority (nice value + fifteen)
|
&idummy, // priority (nice value + fifteen)
|
||||||
&task->prio, // nice range from 19 to -19
|
&task->prio, // nice range from 19 to -19
|
||||||
&idummy, // hardcoded 0
|
&idummy, // hardcoded 0
|
||||||
|
|
||||||
&idummy, // itrealvalue time in jiffies to next SIGALRM send to this process
|
&idummy, // itrealvalue time in jiffies to next SIGALRM send to this process
|
||||||
&idummy, // starttime jiffies the process startet after system boot
|
&idummy, // starttime jiffies the process startet after system boot
|
||||||
(unsigned long long*)&task->vsz, // vsize in bytes
|
(unsigned long long *)&task->vsz, // vsize in bytes
|
||||||
(unsigned long long*)&task->rss, // rss (number of pages in real memory)
|
(unsigned long long *)&task->rss, // rss (number of pages in real memory)
|
||||||
dummy, // rlim limit in bytes for rss
|
dummy, // rlim limit in bytes for rss
|
||||||
|
|
||||||
dummy, // startcode
|
dummy, // startcode
|
||||||
dummy, // endcode
|
dummy, // endcode
|
||||||
&idummy, // startstack
|
&idummy, // startstack
|
||||||
dummy, // kstkesp value of esp (stack pointer)
|
dummy, // kstkesp value of esp (stack pointer)
|
||||||
dummy, // kstkeip value of EIP (instruction pointer)
|
dummy, // kstkeip value of EIP (instruction pointer)
|
||||||
|
|
||||||
dummy, // signal. bitmap of pending signals
|
dummy, // signal. bitmap of pending signals
|
||||||
dummy, // blocked: bitmap of blocked signals
|
dummy, // blocked: bitmap of blocked signals
|
||||||
dummy, // sigignore: bitmap of ignored signals
|
dummy, // sigignore: bitmap of ignored signals
|
||||||
dummy, // sigcatch: bitmap of catched signals
|
dummy, // sigcatch: bitmap of catched signals
|
||||||
dummy, // wchan
|
dummy, // wchan
|
||||||
|
|
||||||
dummy, // nswap
|
dummy, // nswap
|
||||||
dummy, // cnswap
|
dummy, // cnswap
|
||||||
dummy, // exit_signal
|
dummy, // exit_signal
|
||||||
&idummy, // CPU number last executed on
|
&idummy, // CPU number last executed on
|
||||||
dummy,
|
dummy,
|
||||||
|
|
||||||
dummy
|
dummy);
|
||||||
);
|
|
||||||
|
|
||||||
task->rss *= get_pagesize ();
|
task->rss *= get_pagesize ();
|
||||||
get_cpu_percent (task->pid, jiffies_user, &task->cpu_user, jiffies_system, &task->cpu_system);
|
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;
|
guint dummy;
|
||||||
|
|
||||||
snprintf(filename, sizeof (filename), "/proc/%d/status", pid);
|
snprintf (filename, sizeof (filename), "/proc/%d/status", pid);
|
||||||
if ((file = fopen (filename, "r")) == NULL)
|
if ((file = fopen (filename, "r")) == NULL)
|
||||||
return FALSE;
|
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
|
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;
|
break;
|
||||||
@@ -328,7 +322,7 @@ get_task_list (GArray *task_list)
|
|||||||
if ((dir = g_dir_open ("/proc", 0, NULL)) == NULL)
|
if ((dir = g_dir_open ("/proc", 0, NULL)) == NULL)
|
||||||
return FALSE;
|
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 ((pid = (GPid)g_ascii_strtoull (name, NULL, 0)) > 0)
|
||||||
{
|
{
|
||||||
@@ -354,11 +348,11 @@ pid_is_sleeping (GPid pid)
|
|||||||
gchar buffer[1024];
|
gchar buffer[1024];
|
||||||
gchar state[2];
|
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)
|
if ((file = fopen (filename, "r")) == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
while (fgets (buffer, sizeof(buffer), file) != NULL)
|
while (fgets (buffer, sizeof (buffer), file) != NULL)
|
||||||
{
|
{
|
||||||
if (sscanf (buffer, "State:\t%1s", state) > 0)
|
if (sscanf (buffer, "State:\t%1s", state) > 0)
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
/* Add includes for system functions needed */
|
/* Add includes for system functions needed */
|
||||||
/* Example:
|
/* Example:
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
@@ -52,9 +52,9 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
|
|||||||
static gboolean
|
static gboolean
|
||||||
get_task_details (GPid pid, Task *task)
|
get_task_details (GPid pid, Task *task)
|
||||||
{
|
{
|
||||||
memset(task, 0, sizeof(Task));
|
memset (task, 0, sizeof (Task));
|
||||||
g_snprintf (task->name, sizeof(task->name), "foo");
|
g_snprintf (task->name, sizeof (task->name), "foo");
|
||||||
g_snprintf (task->cmdline, sizeof(task->cmdline), "foo -bar");
|
g_snprintf (task->cmdline, sizeof (task->cmdline), "foo -bar");
|
||||||
task->uid = 1000;
|
task->uid = 1000;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -66,15 +66,9 @@ get_task_list (GArray *task_list)
|
|||||||
GPid pid = 0;
|
GPid pid = 0;
|
||||||
Task task;
|
Task task;
|
||||||
|
|
||||||
//while (/* read all PIDs */)
|
if (get_task_details (pid, &task))
|
||||||
{
|
{
|
||||||
// if (/* pid is valid */)
|
g_array_append_val (task_list, task);
|
||||||
{
|
|
||||||
if (get_task_details (pid, &task))
|
|
||||||
{
|
|
||||||
g_array_append_val (task_list, task);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_array_sort (task_list, task_pid_compare_fn);
|
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;
|
gint n;
|
||||||
|
|
||||||
if (!kc)
|
if (!kc)
|
||||||
init_stats();
|
init_stats ();
|
||||||
|
|
||||||
if (!(ksp = kstat_lookup (kc, "unix", 0, "system_pages")))
|
if (!(ksp = kstat_lookup (kc, "unix", 0, "system_pages")))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -167,7 +167,7 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
|
|||||||
get_cpu_percent (0, ticks_user, cpu_user, ticks_system, cpu_system);
|
get_cpu_percent (0, ticks_user, cpu_user, ticks_system, cpu_system);
|
||||||
*cpu_count = _cpu_count;
|
*cpu_count = _cpu_count;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@@ -177,7 +177,7 @@ get_task_details (GPid pid, Task *task)
|
|||||||
gchar filename[96];
|
gchar filename[96];
|
||||||
psinfo_t process;
|
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)
|
if ((file = fopen (filename, "r")) == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
@@ -187,12 +187,12 @@ get_task_details (GPid pid, Task *task)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(task, 0, sizeof(Task));
|
memset (task, 0, sizeof (Task));
|
||||||
task->pid = process.pr_pid;
|
task->pid = process.pr_pid;
|
||||||
task->ppid = process.pr_ppid;
|
task->ppid = process.pr_ppid;
|
||||||
g_strlcpy (task->name, process.pr_fname, sizeof(task->name));
|
g_strlcpy (task->name, process.pr_fname, sizeof (task->name));
|
||||||
snprintf (task->cmdline, sizeof(task->cmdline), "%s", process.pr_psargs);
|
snprintf (task->cmdline, sizeof (task->cmdline), "%s", process.pr_psargs);
|
||||||
snprintf (task->state, sizeof(task->state), "%c", process.pr_lwp.pr_sname);
|
snprintf (task->state, sizeof (task->state), "%c", process.pr_lwp.pr_sname);
|
||||||
task->vsz = (guint64)process.pr_size * 1024;
|
task->vsz = (guint64)process.pr_size * 1024;
|
||||||
task->rss = (guint64)process.pr_rssize * 1024;
|
task->rss = (guint64)process.pr_rssize * 1024;
|
||||||
task->prio = process.pr_lwp.pr_pri;
|
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)
|
if ((dir = g_dir_open ("/proc", 0, NULL)) == NULL)
|
||||||
return FALSE;
|
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 ((pid = (GPid)g_ascii_strtoull (name, NULL, 0)) > 0)
|
||||||
{
|
{
|
||||||
if (get_task_details (pid, &task))
|
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];
|
gchar state[2];
|
||||||
psinfo_t process;
|
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)
|
if ((file = fopen (filename, "r")) == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
@@ -249,7 +249,7 @@ pid_is_sleeping (GPid pid)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf (state, sizeof(state), "%c", process.pr_lwp.pr_sname);
|
snprintf (state, sizeof (state), "%c", process.pr_lwp.pr_sname);
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
|
||||||
return (state[0] == 'T') ? TRUE : FALSE;
|
return (state[0] == 'T') ? TRUE : FALSE;
|
||||||
|
|||||||
@@ -39,39 +39,39 @@ static gboolean full_cmdline;
|
|||||||
typedef struct _XtmTaskManagerClass XtmTaskManagerClass;
|
typedef struct _XtmTaskManagerClass XtmTaskManagerClass;
|
||||||
struct _XtmTaskManagerClass
|
struct _XtmTaskManagerClass
|
||||||
{
|
{
|
||||||
GObjectClass parent_class;
|
GObjectClass parent_class;
|
||||||
};
|
};
|
||||||
struct _XtmTaskManager
|
struct _XtmTaskManager
|
||||||
{
|
{
|
||||||
GObject parent;
|
GObject parent;
|
||||||
/*<private>*/
|
/*<private>*/
|
||||||
#ifdef HAVE_WNCK
|
#ifdef HAVE_WNCK
|
||||||
XtmAppManager * app_manager;
|
XtmAppManager *app_manager;
|
||||||
#endif
|
#endif
|
||||||
GtkTreeModel * model;
|
GtkTreeModel *model;
|
||||||
GArray * tasks;
|
GArray *tasks;
|
||||||
gushort cpu_count;
|
gushort cpu_count;
|
||||||
gfloat cpu_user;
|
gfloat cpu_user;
|
||||||
gfloat cpu_system;
|
gfloat cpu_system;
|
||||||
guint64 memory_total;
|
guint64 memory_total;
|
||||||
guint64 memory_available; /* free + cache + buffers + an-OS-specific-value */
|
guint64 memory_available; /* free + cache + buffers + an-OS-specific-value */
|
||||||
guint64 memory_free;
|
guint64 memory_free;
|
||||||
guint64 memory_cache;
|
guint64 memory_cache;
|
||||||
guint64 memory_buffers;
|
guint64 memory_buffers;
|
||||||
guint64 swap_total;
|
guint64 swap_total;
|
||||||
guint64 swap_free;
|
guint64 swap_free;
|
||||||
};
|
};
|
||||||
G_DEFINE_TYPE (XtmTaskManager, xtm_task_manager, G_TYPE_OBJECT)
|
G_DEFINE_TYPE (XtmTaskManager, xtm_task_manager, G_TYPE_OBJECT)
|
||||||
|
|
||||||
static void xtm_task_manager_finalize (GObject *object);
|
static void xtm_task_manager_finalize (GObject *object);
|
||||||
|
|
||||||
static void setting_changed (GObject *object, GParamSpec *pspec, XtmTaskManager *manager);
|
static void setting_changed (GObject *object, GParamSpec *pspec, XtmTaskManager *manager);
|
||||||
static void model_add_task (XtmTaskManager *manager, Task *task, glong timestamp);
|
static void model_add_task (XtmTaskManager *manager, Task *task, glong timestamp);
|
||||||
static void model_update_tree_iter (XtmTaskManager *manager, GtkTreeIter *iter, glong timestamp, gboolean update_cmd_line, Task *task);
|
static void model_update_tree_iter (XtmTaskManager *manager, GtkTreeIter *iter, glong timestamp, gboolean update_cmd_line, Task *task);
|
||||||
static void model_mark_tree_iter_as_removed (GtkTreeModel *model, GtkTreeIter *iter, glong timestamp);
|
static void model_mark_tree_iter_as_removed (GtkTreeModel *model, GtkTreeIter *iter, glong timestamp);
|
||||||
static void model_remove_tree_iter (GtkTreeModel *model, GtkTreeIter *iter);
|
static void model_remove_tree_iter (GtkTreeModel *model, GtkTreeIter *iter);
|
||||||
static gboolean task_list_find_for_pid (GArray *task_list, GPid pid, Task **task, guint *idx);
|
static gboolean task_list_find_for_pid (GArray *task_list, GPid pid, Task **task, guint *idx);
|
||||||
static glong __current_timestamp (void);
|
static glong __current_timestamp (void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -87,7 +87,8 @@ static void
|
|||||||
xtm_task_manager_init (XtmTaskManager *manager)
|
xtm_task_manager_init (XtmTaskManager *manager)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_WNCK
|
#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 ();
|
manager->app_manager = xtm_app_manager_new ();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -107,7 +108,8 @@ xtm_task_manager_finalize (GObject *object)
|
|||||||
XtmTaskManager *manager = XTM_TASK_MANAGER (object);
|
XtmTaskManager *manager = XTM_TASK_MANAGER (object);
|
||||||
g_array_free (manager->tasks, TRUE);
|
g_array_free (manager->tasks, TRUE);
|
||||||
#ifdef HAVE_WNCK
|
#ifdef HAVE_WNCK
|
||||||
if (manager->app_manager != NULL) {
|
if (manager->app_manager != NULL)
|
||||||
|
{
|
||||||
g_object_unref (manager->app_manager);
|
g_object_unref (manager->app_manager);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -132,38 +134,43 @@ pretty_cmdline (gchar *cmdline, gchar *comm)
|
|||||||
gsize csize, text_size = (gsize)strlen (text);
|
gsize csize, text_size = (gsize)strlen (text);
|
||||||
|
|
||||||
/* UTF-8 normalize. */
|
/* UTF-8 normalize. */
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
for (ch = text, text_max = (text + text_size);
|
for (ch = text, text_max = (text + text_size);
|
||||||
text_max > ch;
|
text_max > ch;
|
||||||
text_max = (text + text_size), ch = g_utf8_next_char(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) {
|
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);
|
text_size = (gsize)(ch - text);
|
||||||
(*ch) = 0;
|
(*ch) = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((gunichar)-1 == c) {
|
if ((gunichar)-1 == c)
|
||||||
|
{
|
||||||
(*ch) = ' ';
|
(*ch) = ' ';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
csize = (gsize)g_unichar_to_utf8(c, NULL);
|
csize = (gsize)g_unichar_to_utf8 (c, NULL);
|
||||||
|
|
||||||
if (!g_unichar_isdefined(c) ||
|
if (!g_unichar_isdefined (c) ||
|
||||||
!g_unichar_isprint(c) ||
|
!g_unichar_isprint (c) ||
|
||||||
(g_unichar_isspace(c) && (1 != csize || (' ' != (*ch) && ' ' != (*ch)))) ||
|
(g_unichar_isspace (c) && (1 != csize || (' ' != (*ch) && ' ' != (*ch)))) ||
|
||||||
g_unichar_ismark(c) ||
|
g_unichar_ismark (c) ||
|
||||||
g_unichar_istitle(c) ||
|
g_unichar_istitle (c) ||
|
||||||
g_unichar_iswide(c) ||
|
g_unichar_iswide (c) ||
|
||||||
g_unichar_iszerowidth(c) ||
|
g_unichar_iszerowidth (c) ||
|
||||||
g_unichar_iscntrl(c)) {
|
g_unichar_iscntrl (c))
|
||||||
|
{
|
||||||
if (text_max < (ch + csize))
|
if (text_max < (ch + csize))
|
||||||
break;
|
break;
|
||||||
memmove(ch, (ch + csize), (gsize)(text_max - (ch + csize)));
|
memmove (ch, (ch + csize), (gsize)(text_max - (ch + csize)));
|
||||||
text_size -= csize;
|
text_size -= csize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
text[text_size] = 0;
|
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)
|
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_UID_STR, uid_name,
|
||||||
XTM_PTV_COLUMN_TIMESTAMP, timestamp,
|
XTM_PTV_COLUMN_TIMESTAMP, timestamp,
|
||||||
-1);
|
-1);
|
||||||
g_free(uid_name);
|
g_free (uid_name);
|
||||||
model_update_tree_iter (manager, &iter, timestamp, TRUE, task);
|
model_update_tree_iter (manager, &iter, timestamp, TRUE, task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,22 +253,22 @@ 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_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);
|
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 (value, sizeof (value), (more_precision) ? "%.2f" : "%.0f", (task->cpu_user + task->cpu_system));
|
||||||
g_snprintf (cpu, sizeof(cpu), _("%s%%"), value);
|
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 (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 (group_cpu, sizeof (group_cpu), _("%s%%"), value);
|
||||||
|
|
||||||
/* Retrieve values for tweaking background/foreground color and updating content as needed */
|
/* Retrieve values for tweaking background/foreground color and updating content as needed */
|
||||||
gtk_tree_model_get (model, iter,
|
gtk_tree_model_get (model, iter,
|
||||||
XTM_PTV_COLUMN_TIMESTAMP, &old_timestamp,
|
XTM_PTV_COLUMN_TIMESTAMP, &old_timestamp,
|
||||||
XTM_PTV_COLUMN_STATE, &old_state,
|
XTM_PTV_COLUMN_STATE, &old_state,
|
||||||
XTM_PTV_COLUMN_BACKGROUND, &background,
|
XTM_PTV_COLUMN_BACKGROUND, &background,
|
||||||
XTM_PTV_COLUMN_FOREGROUND, &foreground,
|
XTM_PTV_COLUMN_FOREGROUND, &foreground,
|
||||||
#ifdef HAVE_WNCK
|
#ifdef HAVE_WNCK
|
||||||
XTM_PTV_COLUMN_ICON, &surface,
|
XTM_PTV_COLUMN_ICON, &surface,
|
||||||
#endif
|
#endif
|
||||||
-1);
|
-1);
|
||||||
|
|
||||||
#ifdef HAVE_WNCK
|
#ifdef HAVE_WNCK
|
||||||
if (surface != NULL)
|
if (surface != NULL)
|
||||||
@@ -346,9 +353,10 @@ task_list_find_for_pid (GArray *task_list, GPid pid, Task **task, guint *idx)
|
|||||||
{
|
{
|
||||||
Task *task_tmp = NULL, tkey;
|
Task *task_tmp = NULL, tkey;
|
||||||
|
|
||||||
if (task_list->data != NULL) {
|
if (task_list->data != NULL)
|
||||||
|
{
|
||||||
tkey.pid = pid;
|
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)
|
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)
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -386,8 +394,8 @@ xtm_task_manager_new (GtkTreeModel *model)
|
|||||||
|
|
||||||
void
|
void
|
||||||
xtm_task_manager_get_system_info (XtmTaskManager *manager, guint *num_processes, gfloat *cpu,
|
xtm_task_manager_get_system_info (XtmTaskManager *manager, guint *num_processes, gfloat *cpu,
|
||||||
guint64 *memory_used, guint64 *memory_total,
|
guint64 *memory_used, guint64 *memory_total,
|
||||||
guint64 *swap_used, guint64 *swap_total)
|
guint64 *swap_used, guint64 *swap_total)
|
||||||
|
|
||||||
{
|
{
|
||||||
g_return_if_fail (XTM_IS_TASK_MANAGER (manager));
|
g_return_if_fail (XTM_IS_TASK_MANAGER (manager));
|
||||||
@@ -397,7 +405,7 @@ xtm_task_manager_get_system_info (XtmTaskManager *manager, guint *num_processes,
|
|||||||
|
|
||||||
/* Set memory and swap usage */
|
/* Set memory and swap usage */
|
||||||
get_memory_usage (&manager->memory_total, &manager->memory_available, &manager->memory_free, &manager->memory_cache, &manager->memory_buffers,
|
get_memory_usage (&manager->memory_total, &manager->memory_available, &manager->memory_free, &manager->memory_cache, &manager->memory_buffers,
|
||||||
&manager->swap_total, &manager->swap_free);
|
&manager->swap_total, &manager->swap_free);
|
||||||
|
|
||||||
*memory_used = manager->memory_total - manager->memory_available;
|
*memory_used = manager->memory_total - manager->memory_available;
|
||||||
*memory_total = manager->memory_total;
|
*memory_total = manager->memory_total;
|
||||||
@@ -438,11 +446,11 @@ xtm_task_manager_task_aggregate_children (Task *task, GArray *task_list)
|
|||||||
|
|
||||||
for (guint i = 0; i < task_list->len; ++i)
|
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)
|
if (child_task->ppid != task->pid)
|
||||||
continue;
|
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_system += child_task->group_cpu_system;
|
||||||
task->group_cpu_user += child_task->group_cpu_user;
|
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)
|
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_system = -1;
|
||||||
task->group_cpu_user = -1;
|
task->group_cpu_user = -1;
|
||||||
task->group_vsz = -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)
|
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);
|
xtm_task_manager_task_aggregate_children (task, task_list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -506,7 +514,8 @@ xtm_task_manager_update_model (XtmTaskManager *manager)
|
|||||||
g_free (cpu_str);
|
g_free (cpu_str);
|
||||||
if (found)
|
if (found)
|
||||||
{
|
{
|
||||||
if ((timestamp - old_timestamp) > TIMESTAMP_DELTA) {
|
if ((timestamp - old_timestamp) > TIMESTAMP_DELTA)
|
||||||
|
{
|
||||||
G_DEBUG_FMT ("Remove old task %d", pid);
|
G_DEBUG_FMT ("Remove old task %d", pid);
|
||||||
model_remove_tree_iter (manager->model, &cur_iter);
|
model_remove_tree_iter (manager->model, &cur_iter);
|
||||||
}
|
}
|
||||||
@@ -534,12 +543,12 @@ xtm_task_manager_update_model (XtmTaskManager *manager)
|
|||||||
update_cmd_line = FALSE;
|
update_cmd_line = FALSE;
|
||||||
|
|
||||||
/* Update the model (with the rest) only if needed, this keeps the CPU cool */
|
/* 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;
|
need_update = TRUE;
|
||||||
/* Update command name if needed (can happen) */
|
/* Update command name if needed (can happen) */
|
||||||
update_cmd_line = (model_update_forced || g_strcmp0 (task->cmdline, task_new->cmdline));
|
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 */
|
else /* Update color if needed */
|
||||||
{
|
{
|
||||||
@@ -588,8 +597,8 @@ get_uid_name (guint uid)
|
|||||||
struct passwd *pw = NULL, pwd_buf;
|
struct passwd *pw = NULL, pwd_buf;
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
|
|
||||||
memset(buf, 0, sizeof(buf));
|
memset (buf, 0, sizeof (buf));
|
||||||
error = getpwuid_r(uid, &pwd_buf, buf, sizeof(buf), &pw);
|
error = getpwuid_r (uid, &pwd_buf, buf, sizeof (buf), &pw);
|
||||||
|
|
||||||
return (g_strdup ((0 == error && pw != NULL) ? pw->pw_name : "nobody"));
|
return (g_strdup ((0 == error && pw != NULL) ? pw->pw_name : "nobody"));
|
||||||
}
|
}
|
||||||
@@ -650,9 +659,9 @@ set_priority_to_pid (GPid pid, gint priority)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gint
|
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 */
|
/* About the constants used below, see for example: https://stackoverflow.com/a/596243 */
|
||||||
|
|||||||
@@ -28,23 +28,23 @@
|
|||||||
typedef struct _Task Task;
|
typedef struct _Task Task;
|
||||||
struct _Task
|
struct _Task
|
||||||
{
|
{
|
||||||
guint uid;
|
guint uid;
|
||||||
GPid pid;
|
GPid pid;
|
||||||
GPid ppid;
|
GPid ppid;
|
||||||
gchar name[256];
|
gchar name[256];
|
||||||
gchar cmdline[1024];
|
gchar cmdline[1024];
|
||||||
gchar state[16];
|
gchar state[16];
|
||||||
gfloat cpu_user;
|
gfloat cpu_user;
|
||||||
gfloat cpu_system;
|
gfloat cpu_system;
|
||||||
guint64 vsz;
|
guint64 vsz;
|
||||||
guint64 rss;
|
guint64 rss;
|
||||||
gint prio;
|
gint prio;
|
||||||
|
|
||||||
// Aggregated values
|
// Aggregated values
|
||||||
gfloat group_cpu_user;
|
gfloat group_cpu_user;
|
||||||
gfloat group_cpu_system;
|
gfloat group_cpu_system;
|
||||||
guint64 group_vsz;
|
guint64 group_vsz;
|
||||||
guint64 group_rss;
|
guint64 group_rss;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,32 +53,32 @@ struct _Task
|
|||||||
* memory_available = free + cache + buffers + an-OS-specific-value
|
* memory_available = free + cache + buffers + an-OS-specific-value
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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);
|
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);
|
||||||
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);
|
||||||
gboolean get_task_list (GArray *task_list);
|
gboolean get_task_list (GArray *task_list);
|
||||||
gboolean pid_is_sleeping (GPid pid);
|
gboolean pid_is_sleeping (GPid pid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GObject class used to update the graphical widgets.
|
* GObject class used to update the graphical widgets.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define XTM_TYPE_TASK_MANAGER (xtm_task_manager_get_type ())
|
#define XTM_TYPE_TASK_MANAGER (xtm_task_manager_get_type ())
|
||||||
#define XTM_TASK_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XTM_TYPE_TASK_MANAGER, XtmTaskManager))
|
#define XTM_TASK_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XTM_TYPE_TASK_MANAGER, XtmTaskManager))
|
||||||
#define XTM_TASK_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XTM_TYPE_TASK_MANAGER, XtmTaskManagerClass))
|
#define XTM_TASK_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XTM_TYPE_TASK_MANAGER, XtmTaskManagerClass))
|
||||||
#define XTM_IS_TASK_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XTM_TYPE_TASK_MANAGER))
|
#define XTM_IS_TASK_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XTM_TYPE_TASK_MANAGER))
|
||||||
#define XTM_IS_TASK_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XTM_TYPE_TASK_MANAGER))
|
#define XTM_IS_TASK_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XTM_TYPE_TASK_MANAGER))
|
||||||
#define XTM_TASK_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_TASK_MANAGER, XtmTaskManagerClass))
|
#define XTM_TASK_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_TASK_MANAGER, XtmTaskManagerClass))
|
||||||
|
|
||||||
typedef struct _XtmTaskManager XtmTaskManager;
|
typedef struct _XtmTaskManager XtmTaskManager;
|
||||||
|
|
||||||
GType xtm_task_manager_get_type (void);
|
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,
|
void xtm_task_manager_get_system_info (XtmTaskManager *manager, guint *num_processes, gfloat *cpu,
|
||||||
guint64 *memory_used, guint64 *memory_total,
|
guint64 *memory_used, guint64 *memory_total,
|
||||||
guint64 *swap_used, guint64 *swap_total);
|
guint64 *swap_used, guint64 *swap_total);
|
||||||
void xtm_task_manager_get_swap_usage (XtmTaskManager *manager, guint64 *swap_free, 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);
|
void xtm_task_manager_update_model (XtmTaskManager *manager);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper functions.
|
* Helper functions.
|
||||||
@@ -101,22 +101,22 @@ enum
|
|||||||
XTM_PRIORITY_VERY_HIGH,
|
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);
|
gboolean send_signal_to_pid (GPid pid, gint xtm_signal);
|
||||||
gint task_pid_compare_fn (gconstpointer a, gconstpointer b);
|
gint task_pid_compare_fn (gconstpointer a, gconstpointer b);
|
||||||
gboolean set_priority_to_pid (GPid pid, gint priority);
|
gboolean set_priority_to_pid (GPid pid, gint priority);
|
||||||
|
|
||||||
|
|
||||||
#ifndef __unused
|
#ifndef __unused
|
||||||
# define __unused __attribute__((__unused__))
|
#define __unused __attribute__ ((__unused__))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
# define G_DEBUG_FMT(fmt, args...) g_debug((fmt), ##args)
|
#define G_DEBUG_FMT(fmt, args...) g_debug ((fmt), ##args)
|
||||||
#else
|
#else
|
||||||
# define G_DEBUG_FMT(fmt, args...)
|
#define G_DEBUG_FMT(fmt, args...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gboolean xtm_gtk_widget_is_dark_mode (GtkWidget *widget);
|
gboolean xtm_gtk_widget_is_dark_mode (GtkWidget *widget);
|
||||||
|
|
||||||
#endif /* !TASK_MANAGER_H */
|
#endif /* !TASK_MANAGER_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user