From 2a9a32b3a0ce7c91b6b4b78afc1d42cec271de71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Bonithon?= Date: Sun, 5 May 2024 17:10:23 +0200 Subject: [PATCH] Apply .clang-format file --- src/app-manager.c | 49 ++++---- src/app-manager.h | 26 ++-- src/main.c | 60 +++++----- src/process-monitor.c | 72 +++++------ src/process-monitor.h | 24 ++-- src/process-statusbar.c | 104 ++++++++-------- src/process-statusbar.h | 16 +-- src/process-tree-model.c | 114 +++++++++--------- src/process-tree-model.h | 16 +-- src/process-tree-view.c | 118 +++++++++--------- src/process-tree-view.h | 22 ++-- src/process-window.c | 239 +++++++++++++++++++------------------ src/process-window.h | 43 +++---- src/settings-dialog.c | 20 ++-- src/settings-dialog.h | 2 +- src/settings.c | 13 +- src/settings.h | 80 ++++++------- src/task-manager-bsd.c | 174 ++++++++++++++------------- src/task-manager-freebsd.c | 34 +++--- src/task-manager-linux.c | 128 ++++++++++---------- src/task-manager-skel.c | 18 +-- src/task-manager-solaris.c | 22 ++-- src/task-manager.c | 149 ++++++++++++----------- src/task-manager.h | 82 ++++++------- 24 files changed, 826 insertions(+), 799 deletions(-) diff --git a/src/app-manager.c b/src/app-manager.c index 5be5ef3..d1b1cc2 100644 --- a/src/app-manager.c +++ b/src/app-manager.c @@ -22,28 +22,28 @@ typedef struct _XtmAppManagerClass XtmAppManagerClass; struct _XtmAppManagerClass { - GObjectClass parent_class; + GObjectClass parent_class; }; struct _XtmAppManager { - GObject parent; + GObject parent; /**/ - GArray * apps; + GArray *apps; }; 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 gint app_pid_compare_fn (gconstpointer a, gconstpointer b); +static GPid app_get_pid (WnckApplication *application); +static gint app_pid_compare_fn (gconstpointer a, gconstpointer b); -static void apps_add_application (GArray *apps, WnckApplication *application, GPid pid); -static void apps_remove_application (GArray *apps, WnckApplication *application); -static App * apps_lookup_pid (GArray *apps, GPid pid); -static App * apps_lookup_app (GArray *apps, WnckApplication *application); -static void application_opened (WnckScreen *screen, WnckApplication *application, XtmAppManager *manager); -static void application_closed (WnckScreen *screen, WnckApplication *application, XtmAppManager *manager); -static void scale_factor_changed (GdkMonitor *monitor); +static void apps_add_application (GArray *apps, WnckApplication *application, GPid pid); +static void apps_remove_application (GArray *apps, WnckApplication *application); +static App *apps_lookup_pid (GArray *apps, GPid pid); +static App *apps_lookup_app (GArray *apps, WnckApplication *application); +static void application_opened (WnckScreen *screen, WnckApplication *application, XtmAppManager *manager); +static void application_closed (WnckScreen *screen, WnckApplication *application, XtmAppManager *manager); +static void scale_factor_changed (GdkMonitor *monitor); @@ -103,7 +103,7 @@ xtm_app_manager_finalize (GObject *object) } static GPid -app_get_pid(WnckApplication *application) +app_get_pid (WnckApplication *application) { GPid pid; GList *windows; @@ -120,9 +120,9 @@ app_get_pid(WnckApplication *application) } static gint -app_pid_compare_fn(gconstpointer a, gconstpointer b) +app_pid_compare_fn (gconstpointer a, gconstpointer b) { - return (((const App*)a)->pid - ((const App*)b)->pid); + return ((const App *)a)->pid - ((const App *)b)->pid; } static void @@ -138,7 +138,7 @@ apps_add_application (GArray *apps, WnckApplication *application, GPid pid) app.application = application; app.pid = pid; - g_snprintf (app.name, sizeof(app.name), "%s", wnck_application_get_name (application)); + g_snprintf (app.name, sizeof (app.name), "%s", wnck_application_get_name (application)); monitor = gdk_display_get_monitor (gdk_display_get_default (), 0); if (monitor != NULL) @@ -153,14 +153,14 @@ apps_add_application (GArray *apps, WnckApplication *application, GPid pid) static void apps_remove_application (GArray *apps, WnckApplication *application) { - App *app = apps_lookup_pid(apps, app_get_pid (application)); + App *app = apps_lookup_pid (apps, app_get_pid (application)); if (app == NULL) - app = apps_lookup_app(apps, application); + app = apps_lookup_app (apps, application); if (app == NULL) return; cairo_surface_destroy (app->surface); - g_array_remove_index (apps, (guint)(((size_t)app - (size_t)apps->data) / sizeof(App))); + g_array_remove_index (apps, (guint)(((size_t)app - (size_t)apps->data) / sizeof (App))); } static App * @@ -173,7 +173,7 @@ apps_lookup_pid (GArray *apps, GPid pid) tapp.pid = pid; - return (bsearch(&tapp, apps->data, apps->len, sizeof(App), app_pid_compare_fn)); + return bsearch (&tapp, apps->data, apps->len, sizeof (App), app_pid_compare_fn); } static App * @@ -182,7 +182,8 @@ apps_lookup_app (GArray *apps, WnckApplication *application) App *tapp; guint i; - for (i = 0; i < apps->len; i++) { + for (i = 0; i < apps->len; i++) + { tapp = &g_array_index (apps, App, i); if (tapp->application == application) return (tapp); @@ -195,14 +196,14 @@ static void application_opened (WnckScreen *screen __unused, WnckApplication *application, XtmAppManager *manager) { GPid pid = app_get_pid (application); - G_DEBUG_FMT ("Application opened %p %d", (void*)application, pid); + G_DEBUG_FMT ("Application opened %p %d", (void *)application, pid); apps_add_application (manager->apps, application, pid); } static void application_closed (WnckScreen *screen __unused, WnckApplication *application, XtmAppManager *manager) { - G_DEBUG_FMT ("Application closed %p", (void*)application); + G_DEBUG_FMT ("Application closed %p", (void *)application); apps_remove_application (manager->apps, application); } diff --git a/src/app-manager.h b/src/app-manager.h index 42db3f8..8d67764 100644 --- a/src/app-manager.h +++ b/src/app-manager.h @@ -17,23 +17,23 @@ typedef struct _App App; struct _App { - WnckApplication * application; - GPid pid; - gchar name[1024]; - cairo_surface_t * surface; + WnckApplication *application; + GPid pid; + gchar name[1024]; + cairo_surface_t *surface; }; -#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_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_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_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_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_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)) typedef struct _XtmAppManager XtmAppManager; -GType xtm_app_manager_get_type (void); -XtmAppManager * xtm_app_manager_new (void); -App * xtm_app_manager_get_app_from_pid (XtmAppManager *manager, GPid pid); +GType xtm_app_manager_get_type (void); +XtmAppManager *xtm_app_manager_new (void); +App *xtm_app_manager_get_app_from_pid (XtmAppManager *manager, GPid pid); #endif /* !APP_MANAGER_H */ diff --git a/src/main.c b/src/main.c index 0beba87..bf967b0 100644 --- a/src/main.c +++ b/src/main.c @@ -35,7 +35,7 @@ static GOptionEntry main_entries[] = { { NULL, 0, 0, 0, NULL, NULL, NULL } }; -static void destroy_window (void); +static void destroy_window (void); static void @@ -62,9 +62,9 @@ status_icon_popup_menu (GtkStatusIcon *_status_icon, guint button, guint activat gtk_widget_show_all (menu); } -G_GNUC_BEGIN_IGNORE_DEPRECATIONS + G_GNUC_BEGIN_IGNORE_DEPRECATIONS gtk_menu_popup (GTK_MENU (menu), NULL, NULL, gtk_status_icon_position_menu, _status_icon, button, activate_time); -G_GNUC_END_IGNORE_DEPRECATIONS + G_GNUC_END_IGNORE_DEPRECATIONS } static void @@ -72,9 +72,9 @@ create_status_icon (void) { if (!status_icon_or_null) { -G_GNUC_BEGIN_IGNORE_DEPRECATIONS + G_GNUC_BEGIN_IGNORE_DEPRECATIONS GtkStatusIcon *status_icon = gtk_status_icon_new_from_icon_name ("org.xfce.taskmanager"); -G_GNUC_END_IGNORE_DEPRECATIONS + G_GNUC_END_IGNORE_DEPRECATIONS g_signal_connect (status_icon, "activate", G_CALLBACK (status_icon_activated), NULL); g_signal_connect (status_icon, "popup-menu", G_CALLBACK (status_icon_popup_menu), NULL); status_icon_or_null = status_icon; @@ -84,9 +84,9 @@ G_GNUC_END_IGNORE_DEPRECATIONS static gboolean status_icon_get_visible (void) { -G_GNUC_BEGIN_IGNORE_DEPRECATIONS + G_GNUC_BEGIN_IGNORE_DEPRECATIONS return status_icon_or_null && gtk_status_icon_get_visible (status_icon_or_null); -G_GNUC_END_IGNORE_DEPRECATIONS + G_GNUC_END_IGNORE_DEPRECATIONS } static void @@ -97,22 +97,23 @@ show_hide_status_icon (void) if (show_status_icon) { create_status_icon (); -G_GNUC_BEGIN_IGNORE_DEPRECATIONS + G_GNUC_BEGIN_IGNORE_DEPRECATIONS gtk_status_icon_set_visible (status_icon_or_null, TRUE); -G_GNUC_END_IGNORE_DEPRECATIONS + G_GNUC_END_IGNORE_DEPRECATIONS } else if (status_icon_get_visible ()) { -G_GNUC_BEGIN_IGNORE_DEPRECATIONS + G_GNUC_BEGIN_IGNORE_DEPRECATIONS gtk_status_icon_set_visible (status_icon_or_null, FALSE); -G_GNUC_END_IGNORE_DEPRECATIONS + G_GNUC_END_IGNORE_DEPRECATIONS } } static void destroy_window (void) { - if (gtk_main_level () > 0) { + if (gtk_main_level () > 0) + { if (timer_id > 0) g_source_remove (timer_id); gtk_main_quit (); @@ -146,17 +147,17 @@ collect_data (void) memory_percent = (memory_total != 0) ? ((memory_used * 100.0f) / (float)memory_total) : 0.0f; swap_percent = (swap_total != 0) ? ((swap_used * 100.0f) / (float)swap_total) : 0.0f; - used = g_format_size_full(memory_used, G_FORMAT_SIZE_IEC_UNITS); - total = g_format_size_full(memory_total, G_FORMAT_SIZE_IEC_UNITS); - g_snprintf (memory_info, sizeof(memory_info), "%.0f%% (%s / %s)", memory_percent, used, total); - g_free(used); - g_free(total); + used = g_format_size_full (memory_used, G_FORMAT_SIZE_IEC_UNITS); + total = g_format_size_full (memory_total, G_FORMAT_SIZE_IEC_UNITS); + g_snprintf (memory_info, sizeof (memory_info), "%.0f%% (%s / %s)", memory_percent, used, total); + g_free (used); + g_free (total); - used = g_format_size_full(swap_used, G_FORMAT_SIZE_IEC_UNITS); - total = g_format_size_full(swap_total, G_FORMAT_SIZE_IEC_UNITS); - g_snprintf (swap_info, sizeof(swap_info), "%.0f%% (%s / %s)", swap_percent, used, total); - g_free(used); - g_free(total); + used = g_format_size_full (swap_used, G_FORMAT_SIZE_IEC_UNITS); + total = g_format_size_full (swap_total, G_FORMAT_SIZE_IEC_UNITS); + g_snprintf (swap_info, sizeof (swap_info), "%.0f%% (%s / %s)", swap_percent, used, total); + g_free (used); + g_free (total); xtm_process_window_set_system_info (XTM_PROCESS_WINDOW (window), num_processes, cpu, memory_percent, memory_info, swap_percent, swap_info); @@ -165,15 +166,15 @@ collect_data (void) if (status_icon_get_visible ()) { - g_snprintf (tooltip, sizeof(tooltip), - _("Processes: %u\n" + g_snprintf (tooltip, sizeof (tooltip), + _("Processes: %u\n" "CPU: %.0f%%\n" "Memory: %s\n" "Swap: %s"), - num_processes, cpu, memory_info, swap_info); -G_GNUC_BEGIN_IGNORE_DEPRECATIONS + num_processes, cpu, memory_info, swap_info); + G_GNUC_BEGIN_IGNORE_DEPRECATIONS gtk_status_icon_set_tooltip_markup (GTK_STATUS_ICON (status_icon_or_null), tooltip); -G_GNUC_END_IGNORE_DEPRECATIONS + G_GNUC_END_IGNORE_DEPRECATIONS } xtm_task_manager_update_model (task_manager); @@ -207,7 +208,8 @@ refresh_rate_changed (void) init_timeout (); } -int main (int argc, char *argv[]) +int +main (int argc, char *argv[]) { XfconfChannel *channel; GApplication *app; @@ -293,7 +295,7 @@ int main (int argc, char *argv[]) g_object_unref (settings); if (status_icon_or_null != NULL) g_object_unref (status_icon_or_null); - xfconf_shutdown(); + xfconf_shutdown (); return 0; } diff --git a/src/process-monitor.c b/src/process-monitor.c index c6f3a62..89d3f1c 100644 --- a/src/process-monitor.c +++ b/src/process-monitor.c @@ -26,25 +26,25 @@ enum typedef struct _XtmProcessMonitorClass XtmProcessMonitorClass; struct _XtmProcessMonitorClass { - GtkDrawingAreaClass parent_class; + GtkDrawingAreaClass parent_class; }; struct _XtmProcessMonitor { - GtkDrawingArea parent; + GtkDrawingArea parent; /**/ - gfloat step_size; - gint type; - GArray * history; - GArray * history_swap; - gboolean dark_mode; + gfloat step_size; + gint type; + GArray *history; + GArray *history_swap; + gboolean dark_mode; }; G_DEFINE_TYPE (XtmProcessMonitor, xtm_process_monitor, GTK_TYPE_DRAWING_AREA) -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_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); -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_finalize (GObject *object); +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 gboolean xtm_process_monitor_draw (GtkWidget *widget, 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; g_object_class_install_property (class, PROP_STEP_SIZE, - g_param_spec_float ("step-size", "StepSize", "Step size", 0.1f, G_MAXFLOAT, 1, G_PARAM_CONSTRUCT|G_PARAM_READWRITE)); + g_param_spec_float ("step-size", "StepSize", "Step size", 0.1f, G_MAXFLOAT, 1, G_PARAM_CONSTRUCT | G_PARAM_READWRITE)); g_object_class_install_property (class, PROP_TYPE, g_param_spec_int ("type", "Type", "Type of graph to render", 0, G_MAXINT, 0, G_PARAM_READWRITE)); } @@ -102,16 +102,16 @@ xtm_process_monitor_get_property (GObject *object, guint property_id, GValue *va switch (property_id) { case PROP_STEP_SIZE: - g_value_set_float (value, monitor->step_size); - break; + g_value_set_float (value, monitor->step_size); + break; case PROP_TYPE: - g_value_set_int (value, monitor->type); - break; + g_value_set_int (value, monitor->type); + break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; } } @@ -122,16 +122,16 @@ xtm_process_monitor_set_property (GObject *object, guint property_id, const GVal switch (property_id) { case PROP_STEP_SIZE: - monitor->step_size = g_value_get_float (value); - break; + monitor->step_size = g_value_get_float (value); + break; case PROP_TYPE: - monitor->type = g_value_get_int (value); - break; + monitor->type = g_value_get_int (value); + break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; } } @@ -141,7 +141,7 @@ xtm_process_monitor_draw (GtkWidget *widget, cairo_t *cr) XtmProcessMonitor *monitor = XTM_PROCESS_MONITOR (widget); guint minimum_history_length; - minimum_history_length = (guint)(gtk_widget_get_allocated_width(widget) / monitor->step_size); + minimum_history_length = (guint)(gtk_widget_get_allocated_width (widget) / monitor->step_size); if (monitor->history->len < minimum_history_length) { g_array_set_size (monitor->history, minimum_history_length + 1); @@ -255,10 +255,10 @@ xtm_process_monitor_paint (XtmProcessMonitor *monitor, cairo_t *cr) { cairo_surface_t *graph_surface; gint width, height; - static const double dashed[] = {1.5}; + static const double dashed[] = { 1.5 }; gint i; - width = gtk_widget_get_allocated_width(GTK_WIDGET(monitor)); - height = gtk_widget_get_allocated_height(GTK_WIDGET(monitor)); + width = gtk_widget_get_allocated_width (GTK_WIDGET (monitor)); + height = gtk_widget_get_allocated_height (GTK_WIDGET (monitor)); /* Don't draw anything if the graph is too small */ if (height < 3) @@ -275,7 +275,7 @@ xtm_process_monitor_paint (XtmProcessMonitor *monitor, cairo_t *cr) /* Paint dashed lines at 25%, 50% and 75% */ xtm_process_monitor_cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.3, monitor->dark_mode); cairo_set_line_width (cr, 1.0); - cairo_set_dash(cr, dashed, 1.0, 0); + cairo_set_dash (cr, dashed, 1.0, 0); for (i = 25; i <= 75; i += 25) { cairo_move_to (cr, 1.5, i * height / 100 + 0.5); @@ -316,8 +316,8 @@ xtm_process_monitor_add_peak (XtmProcessMonitor *monitor, gfloat peak, gfloat pe g_array_remove_index (monitor->history_swap, monitor->history_swap->len - 1); } - if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET(monitor)))) - gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET(monitor)), NULL, FALSE); + if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET (monitor)))) + gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (monitor)), NULL, FALSE); } void @@ -325,8 +325,8 @@ xtm_process_monitor_set_step_size (XtmProcessMonitor *monitor, gfloat step_size) { g_return_if_fail (XTM_IS_PROCESS_MONITOR (monitor)); g_object_set (monitor, "step_size", step_size, NULL); - if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET(monitor)))) - gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET(monitor)), NULL, FALSE); + if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET (monitor)))) + gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (monitor)), NULL, FALSE); } void @@ -342,6 +342,6 @@ xtm_process_monitor_clear (XtmProcessMonitor *monitor) g_return_if_fail (XTM_IS_PROCESS_MONITOR (monitor)); g_array_set_size (monitor->history, 0); g_array_set_size (monitor->history_swap, 0); - if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET(monitor)))) - gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET(monitor)), NULL, FALSE); + if (GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET (monitor)))) + gdk_window_invalidate_rect (gtk_widget_get_window (GTK_WIDGET (monitor)), NULL, FALSE); } diff --git a/src/process-monitor.h b/src/process-monitor.h index c3fc2ac..6755a56 100644 --- a/src/process-monitor.h +++ b/src/process-monitor.h @@ -13,20 +13,20 @@ #include #include -#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_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_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_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_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_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)) typedef struct _XtmProcessMonitor XtmProcessMonitor; -GType xtm_process_monitor_get_type (void); -GtkWidget * xtm_process_monitor_new (void); -void xtm_process_monitor_add_peak (XtmProcessMonitor *monitor, gfloat peak, gfloat peak_swap); -void xtm_process_monitor_set_step_size (XtmProcessMonitor *monitor, gfloat step_size); -void xtm_process_monitor_set_type (XtmProcessMonitor *monitor, gint type); -void xtm_process_monitor_clear (XtmProcessMonitor *monitor); +GType xtm_process_monitor_get_type (void); +GtkWidget *xtm_process_monitor_new (void); +void xtm_process_monitor_add_peak (XtmProcessMonitor *monitor, gfloat peak, gfloat peak_swap); +void xtm_process_monitor_set_step_size (XtmProcessMonitor *monitor, gfloat step_size); +void xtm_process_monitor_set_type (XtmProcessMonitor *monitor, gint type); +void xtm_process_monitor_clear (XtmProcessMonitor *monitor); #endif /* !PROCESS_MONITOR_H */ diff --git a/src/process-statusbar.c b/src/process-statusbar.c index e8046f2..484d7d3 100644 --- a/src/process-statusbar.c +++ b/src/process-statusbar.c @@ -30,30 +30,30 @@ enum typedef struct _XtmProcessStatusbarClass XtmProcessStatusbarClass; struct _XtmProcessStatusbarClass { - GtkStatusbarClass parent_class; + GtkStatusbarClass parent_class; }; struct _XtmProcessStatusbar { - GtkHBox parent; + GtkHBox parent; /**/ - XtmSettings * settings; + XtmSettings *settings; - GtkWidget * label_num_processes; - GtkWidget * label_cpu; - GtkWidget * label_memory; - GtkWidget * label_swap; + GtkWidget *label_num_processes; + GtkWidget *label_cpu; + GtkWidget *label_memory; + GtkWidget *label_swap; - gfloat cpu; - gchar memory[64]; - gchar swap[64]; - guint num_processes; + gfloat cpu; + gchar memory[64]; + gchar swap[64]; + guint num_processes; - gboolean dark_mode; + gboolean dark_mode; }; G_DEFINE_TYPE (XtmProcessStatusbar, xtm_process_statusbar, GTK_TYPE_BOX) -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_finalize (GObject *object); +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->set_property = xtm_process_statusbar_set_property; g_object_class_install_property (class, PROP_CPU, - g_param_spec_float ("cpu", "CPU", "CPU usage", 0, 100, 0, G_PARAM_CONSTRUCT|G_PARAM_WRITABLE)); + g_param_spec_float ("cpu", "CPU", "CPU usage", 0, 100, 0, G_PARAM_CONSTRUCT | G_PARAM_WRITABLE)); g_object_class_install_property (class, PROP_MEMORY, - g_param_spec_string ("memory", "Memory", "Memory usage", "", G_PARAM_CONSTRUCT|G_PARAM_WRITABLE)); + g_param_spec_string ("memory", "Memory", "Memory usage", "", G_PARAM_CONSTRUCT | G_PARAM_WRITABLE)); g_object_class_install_property (class, PROP_SWAP, - g_param_spec_string ("swap", "Swap", "Swap usage", "", G_PARAM_CONSTRUCT|G_PARAM_WRITABLE)); + g_param_spec_string ("swap", "Swap", "Swap usage", "", G_PARAM_CONSTRUCT | G_PARAM_WRITABLE)); g_object_class_install_property (class, PROP_SHOW_SWAP, g_param_spec_boolean ("show-swap", "ShowSwap", "Show or hide swap usage", TRUE, G_PARAM_WRITABLE)); g_object_class_install_property (class, PROP_NUM_PROCESSES, - g_param_spec_uint ("num-processes", "NumProcesses", "Number of processes", 0, G_MAXUINT, 0, G_PARAM_CONSTRUCT|G_PARAM_WRITABLE)); + g_param_spec_uint ("num-processes", "NumProcesses", "Number of processes", 0, G_MAXUINT, 0, G_PARAM_CONSTRUCT | G_PARAM_WRITABLE)); } static void @@ -120,7 +120,7 @@ xtm_process_statusbar_init (XtmProcessStatusbar *statusbar) statusbar->label_cpu = gtk_label_new (NULL); 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 (); 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); @@ -132,7 +132,7 @@ xtm_process_statusbar_init (XtmProcessStatusbar *statusbar) statusbar->label_memory = gtk_label_new (NULL); 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); - context = gtk_widget_get_style_context (statusbar->label_memory); + context = gtk_widget_get_style_context (statusbar->label_memory); provider = gtk_css_provider_new (); 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); @@ -141,7 +141,7 @@ xtm_process_statusbar_init (XtmProcessStatusbar *statusbar) statusbar->label_swap = gtk_label_new (NULL); 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); - context = gtk_widget_get_style_context (statusbar->label_swap); + context = gtk_widget_get_style_context (statusbar->label_swap); provider = gtk_css_provider_new (); 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); @@ -186,47 +186,47 @@ xtm_process_statusbar_set_property (GObject *object, guint property_id, const GV switch (property_id) { case PROP_CPU: - statusbar->cpu = g_value_get_float (value); - float_value = rounded_float_value (statusbar->cpu, statusbar->settings); - text = g_strdup_printf (_("CPU: %s%%"), float_value); - gtk_label_set_text (GTK_LABEL (statusbar->label_cpu), text); - g_free (float_value); - g_free (text); - break; + statusbar->cpu = g_value_get_float (value); + float_value = rounded_float_value (statusbar->cpu, statusbar->settings); + text = g_strdup_printf (_("CPU: %s%%"), float_value); + gtk_label_set_text (GTK_LABEL (statusbar->label_cpu), text); + g_free (float_value); + g_free (text); + break; case PROP_MEMORY: - g_strlcpy(statusbar->memory, g_value_get_string (value), sizeof(statusbar->memory)); - text = g_strdup_printf (_("Memory: %s"), statusbar->memory); - gtk_label_set_text (GTK_LABEL (statusbar->label_memory), text); - gtk_widget_set_tooltip_text (statusbar->label_memory, text); - g_free (text); - break; + g_strlcpy (statusbar->memory, g_value_get_string (value), sizeof (statusbar->memory)); + text = g_strdup_printf (_("Memory: %s"), statusbar->memory); + gtk_label_set_text (GTK_LABEL (statusbar->label_memory), text); + gtk_widget_set_tooltip_text (statusbar->label_memory, text); + g_free (text); + break; case PROP_SWAP: - g_strlcpy(statusbar->swap, g_value_get_string (value), sizeof(statusbar->swap)); - text = g_strdup_printf (_("Swap: %s"), statusbar->swap); - gtk_label_set_text (GTK_LABEL (statusbar->label_swap), text); - gtk_widget_set_tooltip_text (statusbar->label_swap, text); - g_free (text); - break; + g_strlcpy (statusbar->swap, g_value_get_string (value), sizeof (statusbar->swap)); + text = g_strdup_printf (_("Swap: %s"), statusbar->swap); + gtk_label_set_text (GTK_LABEL (statusbar->label_swap), text); + gtk_widget_set_tooltip_text (statusbar->label_swap, text); + g_free (text); + break; case PROP_SHOW_SWAP: - if (g_value_get_boolean (value)) - gtk_widget_show (statusbar->label_swap); - else - gtk_widget_hide (statusbar->label_swap); - break; + if (g_value_get_boolean (value)) + gtk_widget_show (statusbar->label_swap); + else + gtk_widget_hide (statusbar->label_swap); + break; case PROP_NUM_PROCESSES: - statusbar->num_processes = g_value_get_uint (value); - text = g_strdup_printf (_("Processes: %d"), statusbar->num_processes); - gtk_label_set_text (GTK_LABEL (statusbar->label_num_processes), text); - g_free (text); - break; + statusbar->num_processes = g_value_get_uint (value); + text = g_strdup_printf (_("Processes: %d"), statusbar->num_processes); + gtk_label_set_text (GTK_LABEL (statusbar->label_num_processes), text); + g_free (text); + break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; } } diff --git a/src/process-statusbar.h b/src/process-statusbar.h index 539a627..2c5fa02 100644 --- a/src/process-statusbar.h +++ b/src/process-statusbar.h @@ -13,16 +13,16 @@ #include #include -#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_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_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_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_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_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)) typedef struct _XtmProcessStatusbar XtmProcessStatusbar; -GType xtm_process_statusbar_get_type (void); -GtkWidget * xtm_process_statusbar_new (void); +GType xtm_process_statusbar_get_type (void); +GtkWidget *xtm_process_statusbar_new (void); #endif /* !PROCESS_STATUSBAR_H */ diff --git a/src/process-tree-model.c b/src/process-tree-model.c index 2e91569..343fd5d 100644 --- a/src/process-tree-model.c +++ b/src/process-tree-model.c @@ -20,64 +20,65 @@ -enum { +enum +{ PROP_0, PROP_MODEL }; -typedef struct { - GtkTreeIter iter; - GtkTreePath * path; - GSequenceIter * list; - GNode * tree; +typedef struct +{ + GtkTreeIter iter; + GtkTreePath *path; + GSequenceIter *list; + GNode *tree; } XtmCrossLink; typedef struct _XtmProcessTreeModelClass XtmProcessTreeModelClass; struct _XtmProcessTreeModelClass { - GObjectClass parent_class; + GObjectClass parent_class; }; struct _XtmProcessTreeModel { - GObject parent; + GObject parent; /**/ - GtkTreeModel * model; - GNode * tree; - GSequence * list; - gint c_column; - gint p_column; - gint stamp; + GtkTreeModel *model; + GNode *tree; + GSequence *list; + gint c_column; + gint p_column; + 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_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_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_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_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec); -static GtkTreeModelFlags xtm_process_tree_model_get_flags (GtkTreeModel *model); -static gint xtm_process_tree_model_get_n_columns (GtkTreeModel *model); -static GType xtm_process_tree_model_get_column_type (GtkTreeModel *model, gint idx); -static gboolean xtm_process_tree_model_get_iter (GtkTreeModel *model, GtkTreeIter *iter, GtkTreePath *path); -static GtkTreePath * xtm_process_tree_model_get_path (GtkTreeModel *model, GtkTreeIter *iter); -static void xtm_process_tree_model_get_value (GtkTreeModel *model, GtkTreeIter *iter, gint column, GValue *value); -static gboolean xtm_process_tree_model_iter_next (GtkTreeModel *model, GtkTreeIter *iter); -static gboolean xtm_process_tree_model_iter_children (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *parent); -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 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 GtkTreeModelFlags xtm_process_tree_model_get_flags (GtkTreeModel *model); +static gint xtm_process_tree_model_get_n_columns (GtkTreeModel *model); +static GType xtm_process_tree_model_get_column_type (GtkTreeModel *model, gint idx); +static gboolean xtm_process_tree_model_get_iter (GtkTreeModel *model, GtkTreeIter *iter, GtkTreePath *path); +static GtkTreePath *xtm_process_tree_model_get_path (GtkTreeModel *model, GtkTreeIter *iter); +static void xtm_process_tree_model_get_value (GtkTreeModel *model, GtkTreeIter *iter, gint column, GValue *value); +static gboolean xtm_process_tree_model_iter_next (GtkTreeModel *model, GtkTreeIter *iter); +static gboolean xtm_process_tree_model_iter_children (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *parent); +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 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 void xtm_process_tree_model_row_changed (XtmProcessTreeModel *treemodel, GtkTreePath *path, GtkTreeIter *iter, GtkTreeModel *model); -static void xtm_process_tree_model_row_inserted (XtmProcessTreeModel *treemodel, GtkTreePath *path, GtkTreeIter *iter, GtkTreeModel *model); -//static void xtm_process_tree_model_row_has_child_toggled (XtmProcessTreeModel *treemodel, GtkTreePath *path, GtkTreeIter *iter, GtkTreeModel *model); -static void xtm_process_tree_model_row_deleted (XtmProcessTreeModel *treemodel, GtkTreePath *path, GtkTreeModel *model); -static void xtm_process_tree_model_rows_reordered (XtmProcessTreeModel *treemodel, GtkTreePath *path, GtkTreeIter *iter, gint *new_order, GtkTreeModel *model); +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_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_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; 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 @@ -369,9 +370,9 @@ xtm_process_tree_model_iter_parent (GtkTreeModel *model, GtkTreeIter *iter, GtkT struct find_node_struct { - GValue p_value; - XtmProcessTreeModel * treemodel; - GNode * parent; + GValue p_value; + XtmProcessTreeModel *treemodel; + GNode *parent; }; static gboolean @@ -380,7 +381,7 @@ find_node (GNode *node, gpointer data) XtmCrossLink *lnk = node->data; struct find_node_struct *found = data; gboolean same = FALSE; - GValue c_value = {0}; + GValue c_value = { 0 }; if (lnk == NULL) return FALSE; /* Use path for non-persistent models */ @@ -438,7 +439,7 @@ find_sibling (GNode *parent, GSequenceIter *child) GSequenceIter *prev; /* 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)) - { + { XtmCrossLink *lnk; child = prev; lnk = g_sequence_get (child); @@ -446,7 +447,7 @@ find_sibling (GNode *parent, GSequenceIter *child) { return lnk->tree; } - } + } return NULL; } @@ -458,8 +459,8 @@ xtm_process_tree_model_row_changed (XtmProcessTreeModel *treemodel, GtkTreePath XtmCrossLink *lnk, *c_link; GNode *node, *next_node, *old_parent; struct find_node_struct found; - GValue c_value = {0}; - GValue p_value = {0}; + GValue c_value = { 0 }; + GValue p_value = { 0 }; gboolean same = TRUE; gboolean signal_parent; @@ -476,7 +477,7 @@ xtm_process_tree_model_row_changed (XtmProcessTreeModel *treemodel, GtkTreePath s_iter.user_data3 = NULL; /* Use the root entry as fall-back if no parent could be found */ - memset(&found, 0, sizeof(found)); + memset (&found, 0, sizeof (found)); found.parent = treemodel->tree; found.treemodel = treemodel; gtk_tree_model_get_value (model, iter, treemodel->p_column, &found.p_value); @@ -608,7 +609,7 @@ static void do_path (gpointer data, gpointer user_data) { XtmCrossLink *lnk = data; - void (*func) (GtkTreePath*) = (void (*) (GtkTreePath*))user_data; + void (*func) (GtkTreePath *) = (void (*) (GtkTreePath *))user_data; /* Use path for non-persistent models */ g_return_if_fail (lnk->path); func (lnk->path); @@ -622,8 +623,8 @@ xtm_process_tree_model_row_inserted (XtmProcessTreeModel *treemodel, GtkTreePath XtmCrossLink *lnk, *c_link; GNode *node, *next_node; struct find_node_struct found; - GValue c_value = {0}; - GValue p_value = {0}; + GValue c_value = { 0 }; + GValue p_value = { 0 }; gboolean same; gboolean not_persist = TRUE; gboolean signal_parent; @@ -631,9 +632,9 @@ xtm_process_tree_model_row_inserted (XtmProcessTreeModel *treemodel, GtkTreePath g_return_if_fail (gtk_tree_path_get_depth (path) == 1); /* Take a reference on this node, to want to stay informed about any changes in this row */ - gtk_tree_model_ref_node(model, iter); + gtk_tree_model_ref_node (model, iter); - not_persist = ! (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_ITERS_PERSIST); + not_persist = !(gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_ITERS_PERSIST); s_iter.stamp = treemodel->stamp; s_iter.user_data2 = NULL; @@ -654,7 +655,7 @@ xtm_process_tree_model_row_inserted (XtmProcessTreeModel *treemodel, GtkTreePath g_sequence_foreach_range (g_sequence_iter_next (lnk->list), g_sequence_get_end_iter (treemodel->list), do_path, (gpointer)gtk_tree_path_next); - memset(&found, 0, sizeof(found)); + memset (&found, 0, sizeof (found)); found.parent = treemodel->tree; found.treemodel = treemodel; gtk_tree_model_get_value (model, iter, treemodel->p_column, &found.p_value); @@ -750,7 +751,7 @@ xtm_process_tree_model_row_deleted (XtmProcessTreeModel *treemodel, GtkTreePath g_return_if_fail (gtk_tree_path_get_depth (path) == 1); - not_persist = ! (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_ITERS_PERSIST); + not_persist = !(gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_ITERS_PERSIST); s_iter.stamp = treemodel->stamp; s_iter.user_data2 = NULL; @@ -852,7 +853,7 @@ reorder_children (GNode *parent, gpointer data) if (c_pos > 0) { /* move the items in between to keep order list in sync with the current tree */ - memmove ((new_order + i + 1), (new_order + i), ((guint)c_pos * sizeof(gint))); + memmove (new_order + i + 1, new_order + i, (guint)c_pos * sizeof (gint)); moved = TRUE; } /* Store the old position at the new location */ @@ -891,7 +892,7 @@ xtm_process_tree_model_rows_reordered (XtmProcessTreeModel *treemodel, GtkTreePa if (G_UNLIKELY (size == 0)) return; - not_persist = ! (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_ITERS_PERSIST); + not_persist = !(gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_ITERS_PERSIST); /* New list to hold the new order */ s_list = g_sequence_new (xtm_cross_link_free); @@ -933,7 +934,6 @@ xtm_process_tree_model_set_model (XtmProcessTreeModel *treemodel, GtkTreeModel * g_signal_connect_object (model, "row-changed", G_CALLBACK (xtm_process_tree_model_row_changed), treemodel, G_CONNECT_SWAPPED); g_signal_connect_object (model, "row-inserted", G_CALLBACK (xtm_process_tree_model_row_inserted), treemodel, G_CONNECT_SWAPPED); - //g_signal_connect_object (model, "row-has-child-toggled", G_CALLBACK (xtm_process_tree_model_row_has_child_toggled), treemodel, G_CONNECT_SWAPPED); g_signal_connect_object (model, "row-deleted", G_CALLBACK (xtm_process_tree_model_row_deleted), treemodel, G_CONNECT_SWAPPED); g_signal_connect_object (model, "rows-reordered", G_CALLBACK (xtm_process_tree_model_rows_reordered), treemodel, G_CONNECT_SWAPPED); } @@ -941,7 +941,7 @@ xtm_process_tree_model_set_model (XtmProcessTreeModel *treemodel, GtkTreeModel * GtkTreeModel * -xtm_process_tree_model_new (GtkTreeModel * model) +xtm_process_tree_model_new (GtkTreeModel *model) { /* Only support flat models to build a tree */ g_return_val_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY, NULL); diff --git a/src/process-tree-model.h b/src/process-tree-model.h index bbe8867..a999252 100644 --- a/src/process-tree-model.h +++ b/src/process-tree-model.h @@ -13,16 +13,16 @@ #include #include -#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_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_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_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_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_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)) typedef struct _XtmProcessTreeModel XtmProcessTreeModel; -GType xtm_process_tree_model_get_type (void); -GtkTreeModel * xtm_process_tree_model_new (GtkTreeModel * model); +GType xtm_process_tree_model_get_type (void); +GtkTreeModel *xtm_process_tree_model_new (GtkTreeModel *model); #endif /* !PROCESS_TREE_MODEL_H */ diff --git a/src/process-tree-view.c b/src/process-tree-view.c index 15d0e96..ec86fbb 100644 --- a/src/process-tree-view.c +++ b/src/process-tree-view.c @@ -44,38 +44,38 @@ enum typedef struct _XtmProcessTreeViewClass XtmProcessTreeViewClass; struct _XtmProcessTreeViewClass { - GtkTreeViewClass parent_class; + GtkTreeViewClass parent_class; }; struct _XtmProcessTreeView { - GtkTreeView parent; + GtkTreeView parent; /**/ - GtkListStore * model; - GtkTreeModel * model_filter; - gchar * cmd_filter; - GtkTreeModel * model_tree; - GtkTreeViewColumn * sort_column; - gushort columns_positions[N_COLUMNS]; - XtmSettings * settings; - guint owner_uid; - gboolean show_all_processes_cached; + GtkListStore *model; + GtkTreeModel *model_filter; + gchar *cmd_filter; + GtkTreeModel *model_tree; + GtkTreeViewColumn *sort_column; + gushort columns_positions[N_COLUMNS]; + XtmSettings *settings; + guint owner_uid; + gboolean show_all_processes_cached; }; 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_key_pressed (XtmProcessTreeView *treeview, GdkEventKey *event); -static void column_task_pack_cells (XtmProcessTreeView *treeview, GtkTreeViewColumn *column); -static void columns_changed (XtmProcessTreeView *treeview); -static void read_columns_positions (XtmProcessTreeView *treeview); -static void save_columns_positions (XtmProcessTreeView *treeview); -static void column_clicked (GtkTreeViewColumn *column, 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 void settings_changed (GObject *object, GParamSpec *pspec, 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_clicked (XtmProcessTreeView *treeview, GdkEventButton *event); +static gboolean treeview_key_pressed (XtmProcessTreeView *treeview, GdkEventKey *event); +static void column_task_pack_cells (XtmProcessTreeView *treeview, GtkTreeViewColumn *column); +static void columns_changed (XtmProcessTreeView *treeview); +static void read_columns_positions (XtmProcessTreeView *treeview); +static void save_columns_positions (XtmProcessTreeView *treeview); +static void column_clicked (GtkTreeViewColumn *column, 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 void settings_changed (GObject *object, GParamSpec *pspec, 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 void 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_FOREGROUND */ G_TYPE_LONG /* XTM_PTV_COLUMN_TIMESTAMP */ - ); + ); 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); @@ -143,7 +143,7 @@ xtm_process_tree_view_init (XtmProcessTreeView *treeview) treeview->cmd_filter = NULL; /* Create cell renderer for tree view columns */ - cell_text = gtk_cell_renderer_text_new(); + cell_text = gtk_cell_renderer_text_new (); cell_right_aligned = gtk_cell_renderer_text_new (); g_object_set (cell_right_aligned, "xalign", 1.0, NULL); @@ -417,7 +417,7 @@ save_columns_positions (XtmProcessTreeView *treeview) gchar columns_positions[COLUMNS_POSITIONS_STRLEN] = { 0 }; for (i = 0; i < N_COLUMNS; i++) - offset += (gulong)g_snprintf (&columns_positions[offset], (sizeof(columns_positions) - offset), "%d;", treeview->columns_positions[i]); + offset += (gulong)g_snprintf (&columns_positions[offset], (sizeof (columns_positions) - offset), "%d;", treeview->columns_positions[i]); g_object_set (treeview->settings, "columns-positions", columns_positions, NULL); } @@ -457,7 +457,8 @@ cb_send_signal (GtkMenuItem *mi, gpointer user_data) _("Error sending signal")); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("An error was encountered by sending a signal to the PID %d. " - "It is likely you don't have the required privileges."), pid); + "It is likely you don't have the required privileges."), + pid); gtk_window_set_title (GTK_WINDOW (dialog), _("Task Manager")); gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); gtk_dialog_run (GTK_DIALOG (dialog)); @@ -486,8 +487,10 @@ cb_set_priority (GtkMenuItem *mi, gpointer user_data) { GtkWidget *dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Error setting priority")); - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("An error was encountered by setting a priority to the PID %d. " - "It is likely you don't have the required privileges."), pid); + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), + _("An error was encountered by setting a priority to the PID %d. " + "It is likely you don't have the required privileges."), + pid); gtk_window_set_title (GTK_WINDOW (dialog), _("Task Manager")); gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); gtk_dialog_run (GTK_DIALOG (dialog)); @@ -610,7 +613,7 @@ build_context_menu (XtmProcessTreeView *treeview, GPid pid) g_signal_connect (mi, "activate", G_CALLBACK (cb_copy_command_line), treeview); /* Refer to treeview_key_pressed to see how the Ctrl-c press is handled */ accel_label = gtk_bin_get_child (GTK_BIN (mi)); - gtk_accel_label_set_accel(GTK_ACCEL_LABEL (accel_label), GDK_KEY_c, GDK_CONTROL_MASK); + gtk_accel_label_set_accel (GTK_ACCEL_LABEL (accel_label), GDK_KEY_c, GDK_CONTROL_MASK); gtk_widget_show_all (menu); @@ -685,7 +688,7 @@ treeview_key_pressed (XtmProcessTreeView *treeview, GdkEventKey *event) 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)), - window, &rect, GDK_GRAVITY_NORTH_WEST, GDK_GRAVITY_NORTH_WEST, NULL); + window, &rect, GDK_GRAVITY_NORTH_WEST, GDK_GRAVITY_NORTH_WEST, NULL); return TRUE; } else if (event->keyval == GDK_KEY_Delete) @@ -740,17 +743,17 @@ column_clicked (GtkTreeViewColumn *column, XtmProcessTreeView *treeview) treeview->sort_column = column; - g_object_set(treeview->settings, - "sort-column-id", GPOINTER_TO_INT(g_object_get_data(G_OBJECT(treeview->sort_column), "column-id")), - "sort-type", sort_type, - NULL); + g_object_set (treeview->settings, + "sort-column-id", GPOINTER_TO_INT (g_object_get_data (G_OBJECT (treeview->sort_column), "column-id")), + "sort-type", sort_type, + NULL); } void -xtm_process_tree_view_set_filter(XtmProcessTreeView *treeview, const gchar *cmd_filter) +xtm_process_tree_view_set_filter (XtmProcessTreeView *treeview, const gchar *cmd_filter) { - g_free(treeview->cmd_filter); - treeview->cmd_filter = g_strdup(cmd_filter); + g_free (treeview->cmd_filter); + treeview->cmd_filter = g_strdup (cmd_filter); gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (treeview->model_filter)); } @@ -759,12 +762,14 @@ static gboolean visible_func (GtkTreeModel *model, GtkTreeIter *iter, XtmProcessTreeView *treeview) { gchar *cmdline, *cmdline_lower, *key_lower, *p = NULL; - gboolean mach_filter = TRUE, match_uid = TRUE; + gboolean mach_filter = TRUE, match_uid = TRUE; guint uid; - if(treeview->cmd_filter) { + if (treeview->cmd_filter) + { gtk_tree_model_get (GTK_TREE_MODEL (model), iter, XTM_PTV_COLUMN_COMMAND, &cmdline, -1); - if(cmdline) { + if (cmdline) + { cmdline_lower = g_ascii_strdown (cmdline, -1); key_lower = g_ascii_strdown (treeview->cmd_filter, -1); @@ -775,10 +780,11 @@ visible_func (GtkTreeModel *model, GtkTreeIter *iter, XtmProcessTreeView *treevi g_free (cmdline); } - if(!p) + if (!p) mach_filter = FALSE; } - if (!treeview->show_all_processes_cached) { + if (!treeview->show_all_processes_cached) + { gtk_tree_model_get (GTK_TREE_MODEL (treeview->model), iter, XTM_PTV_COLUMN_UID, &uid, -1); if (treeview->owner_uid != uid) match_uid = FALSE; @@ -891,14 +897,15 @@ xtm_process_tree_view_get_model (XtmProcessTreeView *treeview) } void -xtm_process_tree_view_highlight_pid (XtmProcessTreeView *treeview, GPid pid) { - GtkTreeModel *model; - GtkTreePath *path; - GtkTreeIter iter; - gboolean valid; - gboolean tree; - GPid pid_iter; - GtkTreeIter child_iter; +xtm_process_tree_view_highlight_pid (XtmProcessTreeView *treeview, GPid pid) +{ + GtkTreeModel *model; + GtkTreePath *path; + GtkTreeIter iter; + gboolean valid; + gboolean tree; + GPid pid_iter; + GtkTreeIter child_iter; gboolean validParent; 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)) { - GtkTreeIter parent_iter = iter; + GtkTreeIter parent_iter = 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); if (tree && !valid) { - //finding my way up again - do { + // finding my way up again + do + { validParent = gtk_tree_model_iter_parent (model, &iter, &child_iter); child_iter = iter; valid = gtk_tree_model_iter_next (model, &iter); diff --git a/src/process-tree-view.h b/src/process-tree-view.h index f834c4a..f8950b9 100644 --- a/src/process-tree-view.h +++ b/src/process-tree-view.h @@ -46,19 +46,19 @@ enum XTM_PTV_N_COLUMNS, }; -#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_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_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_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_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_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)) typedef struct _XtmProcessTreeView XtmProcessTreeView; -GType xtm_process_tree_view_get_type (void); -GtkWidget * xtm_process_tree_view_new (void); -void xtm_process_tree_view_set_filter (XtmProcessTreeView *treeview, const gchar *cmd_filter); -GtkTreeModel * xtm_process_tree_view_get_model (XtmProcessTreeView *treeview); -void xtm_process_tree_view_highlight_pid (XtmProcessTreeView *treeview, GPid pid); +GType xtm_process_tree_view_get_type (void); +GtkWidget *xtm_process_tree_view_new (void); +void xtm_process_tree_view_set_filter (XtmProcessTreeView *treeview, const gchar *cmd_filter); +GtkTreeModel *xtm_process_tree_view_get_model (XtmProcessTreeView *treeview); +void xtm_process_tree_view_highlight_pid (XtmProcessTreeView *treeview, GPid pid); #endif /* !PROCESS_TREE_VIEW_H */ diff --git a/src/process-window.c b/src/process-window.c index d47c783..eaa020b 100644 --- a/src/process-window.c +++ b/src/process-window.c @@ -39,49 +39,47 @@ typedef struct _XtmProcessWindowClass XtmProcessWindowClass; struct _XtmProcessWindowClass { - GtkWidgetClass parent_class; + GtkWidgetClass parent_class; }; struct _XtmProcessWindow { - GtkWidget parent; + GtkWidget parent; /**/ - GtkBuilder * builder; - GtkWidget * window; - GtkWidget * filter_entry; - GtkWidget * filter_searchbar; - GtkWidget * cpu_monitor; - GtkWidget * mem_monitor; - GtkWidget * vpaned; - GtkWidget * treeview; - GtkWidget * statusbar; - GtkWidget * settings_button; - XtmSettings * settings; - XfconfChannel * channel; - gint width; - gint height; - gulong handler; - gboolean view_stuck; + GtkBuilder *builder; + GtkWidget *window; + GtkWidget *filter_entry; + GtkWidget *filter_searchbar; + GtkWidget *cpu_monitor; + GtkWidget *mem_monitor; + GtkWidget *vpaned; + GtkWidget *treeview; + GtkWidget *statusbar; + GtkWidget *settings_button; + XtmSettings *settings; + XfconfChannel *channel; + gint width; + gint height; + gulong handler; + gboolean view_stuck; }; G_DEFINE_TYPE (XtmProcessWindow, xtm_process_window, GTK_TYPE_WIDGET) -static void xtm_process_window_finalize (GObject *object); -static void xtm_process_window_hide (GtkWidget *widget); +static void xtm_process_window_finalize (GObject *object); +static void xtm_process_window_hide (GtkWidget *widget); -static void emit_destroy_signal (XtmProcessWindow *window); -static gboolean xtm_process_window_key_pressed (XtmProcessWindow *window, GdkEventKey *event); -static void monitor_update_step_size (XtmProcessWindow *window); +static void emit_destroy_signal (XtmProcessWindow *window); +static gboolean xtm_process_window_key_pressed (XtmProcessWindow *window, GdkEventKey *event); +static void monitor_update_step_size (XtmProcessWindow *window); static void -filter_entry_icon_pressed_cb (GtkEntry *entry, - gint position, - GdkEventButton *event __unused, - gpointer data __unused) +filter_entry_icon_pressed_cb (GtkEntry *entry, gint position, GdkEventButton *event __unused, gpointer data __unused) { - if (position == GTK_ENTRY_ICON_SECONDARY) { + if (position == GTK_ENTRY_ICON_SECONDARY) + { gtk_entry_set_text (entry, ""); - gtk_widget_grab_focus (GTK_WIDGET(entry)); + gtk_widget_grab_focus (GTK_WIDGET (entry)); } } @@ -92,49 +90,55 @@ Select_Window (Display *dpy, int screen) int status; Cursor cursor; XEvent event; - Window target_win = None, root = RootWindow(dpy,screen); + Window target_win = None, root = RootWindow (dpy, screen); int buttons = 0; /* Make the target cursor */ - cursor = XCreateFontCursor(dpy, XC_crosshair); + cursor = XCreateFontCursor (dpy, XC_crosshair); /* Grab the pointer using target cursor, letting it roam all over */ - status = XGrabPointer(dpy, root, False, - ButtonPressMask|ButtonReleaseMask, GrabModeSync, - GrabModeAsync, root, cursor, CurrentTime); - if (status != GrabSuccess) { - fprintf (stderr, "Can't grab the mouse.\n"); - return None; + status = XGrabPointer (dpy, root, False, + ButtonPressMask | ButtonReleaseMask, GrabModeSync, + GrabModeAsync, root, cursor, CurrentTime); + if (status != GrabSuccess) + { + fprintf (stderr, "Can't grab the mouse.\n"); + return None; } /* Let the user select a window... */ - while ((target_win == None) || (buttons != 0)) { - /* allow one more event */ - XAllowEvents(dpy, SyncPointer, CurrentTime); - XWindowEvent(dpy, root, ButtonPressMask|ButtonReleaseMask, &event); - switch (event.type) { - case ButtonPress: - if (target_win == None) { - target_win = event.xbutton.subwindow; /* window selected */ - if (target_win == None) target_win = root; - } - buttons++; - break; - case ButtonRelease: - if (buttons > 0) /* there may have been some down before we started */ - buttons--; - break; - } + while ((target_win == None) || (buttons != 0)) + { + /* allow one more event */ + XAllowEvents (dpy, SyncPointer, CurrentTime); + XWindowEvent (dpy, root, ButtonPressMask | ButtonReleaseMask, &event); + switch (event.type) + { + case ButtonPress: + if (target_win == None) + { + target_win = event.xbutton.subwindow; /* window selected */ + if (target_win == None) + target_win = root; + } + buttons++; + 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; } static void -xwininfo_clicked_cb (GtkButton *button __unused, gpointer user_data) { - XtmProcessWindow *window = (XtmProcessWindow *) user_data; +xwininfo_clicked_cb (GtkButton *button __unused, gpointer user_data) +{ + XtmProcessWindow *window = (XtmProcessWindow *)user_data; Window selected_window; Display *dpy; Atom atom_NET_WM_PID; @@ -148,51 +152,56 @@ xwininfo_clicked_cb (GtkButton *button __unused, gpointer user_data) { dpy = XOpenDisplay (NULL); selected_window = Select_Window (dpy, 0); - if (selected_window) { + if (selected_window) + { selected_window = XmuClientWindow (dpy, selected_window); } - atom_NET_WM_PID = XInternAtom(dpy, "_NET_WM_PID", False); + atom_NET_WM_PID = XInternAtom (dpy, "_NET_WM_PID", False); - status = XGetWindowProperty(dpy, selected_window, atom_NET_WM_PID, 0, (~0L), - False, AnyPropertyType, &actual_type, - &actual_format, &_nitems, &bytes_after, - &prop); - if (status == BadWindow) { - XTM_SHOW_MESSAGE(GTK_MESSAGE_INFO, - _("Bad Window"), _("Window id 0x%lx does not exist!"), selected_window); - } if (status != Success) { - XTM_SHOW_MESSAGE(GTK_MESSAGE_ERROR, - _("XGetWindowProperty failed"), _("XGetWindowProperty failed!")); - } else { - if (_nitems > 0) { - memcpy(&pid, prop, sizeof(pid)); - xtm_process_tree_view_highlight_pid(XTM_PROCESS_TREE_VIEW (window->treeview), pid); - } else { - XTM_SHOW_MESSAGE(GTK_MESSAGE_INFO, - _("No PID found"), _("No PID found for window 0x%lx."), selected_window); - } - g_free(prop); + status = XGetWindowProperty (dpy, selected_window, atom_NET_WM_PID, 0, ~0L, + False, AnyPropertyType, &actual_type, + &actual_format, &_nitems, &bytes_after, + &prop); + if (status == BadWindow) + { + XTM_SHOW_MESSAGE (GTK_MESSAGE_INFO, + _("Bad Window"), _("Window id 0x%lx does not exist!"), selected_window); + } + if (status != Success) + { + XTM_SHOW_MESSAGE (GTK_MESSAGE_ERROR, + _("XGetWindowProperty failed"), _("XGetWindowProperty failed!")); + } + else + { + if (_nitems > 0) + { + memcpy (&pid, prop, sizeof (pid)); + xtm_process_tree_view_highlight_pid (XTM_PROCESS_TREE_VIEW (window->treeview), pid); + } + else + { + XTM_SHOW_MESSAGE (GTK_MESSAGE_INFO, + _("No PID found"), _("No PID found for window 0x%lx."), selected_window); + } + g_free (prop); } - } #endif static void -filter_entry_keyrelease_handler(GtkEntry *entry, - XtmProcessTreeView *treeview) +filter_entry_keyrelease_handler (GtkEntry *entry, XtmProcessTreeView *treeview) { gchar *text; gboolean has_text; - text = gtk_editable_get_chars (GTK_EDITABLE(entry), 0, -1); - xtm_process_tree_view_set_filter(treeview, text); + text = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1); + xtm_process_tree_view_set_filter (treeview, text); g_free (text); - has_text = gtk_entry_get_text_length (GTK_ENTRY(entry)) > 0; - gtk_entry_set_icon_sensitive (GTK_ENTRY(entry), - GTK_ENTRY_ICON_SECONDARY, - has_text); + has_text = gtk_entry_get_text_length (GTK_ENTRY (entry)) > 0; + gtk_entry_set_icon_sensitive (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY, has_text); } static void @@ -212,7 +221,7 @@ xtm_process_window_class_init (XtmProcessWindowClass *klass) static void xtm_process_window_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer user_data) { - XtmProcessWindow *window = (XtmProcessWindow *) user_data; + XtmProcessWindow *window = (XtmProcessWindow *)user_data; g_return_if_fail (gtk_widget_is_toplevel (widget)); @@ -222,7 +231,7 @@ xtm_process_window_size_allocate (GtkWidget *widget, GtkAllocation *allocation, static void show_settings_dialog (GtkButton *button, gpointer user_data) { - XtmProcessWindow *window = (XtmProcessWindow *) user_data; + XtmProcessWindow *window = (XtmProcessWindow *)user_data; g_signal_handler_block (G_OBJECT (window->window), window->handler); xtm_settings_dialog_run (window->window); @@ -244,13 +253,12 @@ xtm_process_window_unstick_view_event (GtkWidget *widget, GdkEvent *event, XtmPr GdkScrollDirection dir; gdouble y; - if (! window->view_stuck) + if (!window->view_stuck) return FALSE; - if (event->type == GDK_SCROLL && ( - (gdk_event_get_scroll_direction (event, &dir) && dir == GDK_SCROLL_UP) - || (gdk_event_get_scroll_deltas (event, NULL, &y) && y <= 0) - )) + if (event->type == GDK_SCROLL && + ((gdk_event_get_scroll_direction (event, &dir) && dir == GDK_SCROLL_UP) || + (gdk_event_get_scroll_deltas (event, NULL, &y) && y <= 0))) return FALSE; window->view_stuck = FALSE; @@ -263,10 +271,11 @@ xtm_process_window_unstick_view_cursor (GtkTreeView *tree_view, XtmProcessWindow { GtkTreePath *cursor, *end; - if (! window->view_stuck) + if (!window->view_stuck) return; - if (gtk_tree_view_get_visible_range (tree_view, NULL, &end)) { + if (gtk_tree_view_get_visible_range (tree_view, NULL, &end)) + { gtk_tree_view_get_cursor (tree_view, &cursor, NULL); if (cursor != NULL && gtk_tree_path_compare (cursor, end) >= 0) window->view_stuck = FALSE; @@ -298,17 +307,15 @@ xtm_process_window_init (XtmProcessWindow *window) g_signal_connect_swapped (window->window, "destroy", G_CALLBACK (emit_destroy_signal), window); window->handler = g_signal_connect (window->window, "size-allocate", G_CALLBACK (xtm_process_window_size_allocate), window); - g_signal_connect_swapped (window->window, "key-press-event", G_CALLBACK(xtm_process_window_key_pressed), window); + g_signal_connect_swapped (window->window, "key-press-event", G_CALLBACK (xtm_process_window_key_pressed), window); button = GTK_WIDGET (gtk_builder_get_object (window->builder, "button-settings")); - g_signal_connect (G_OBJECT (button), "clicked", - G_CALLBACK (show_settings_dialog), window); + g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (show_settings_dialog), window); button = GTK_WIDGET (gtk_builder_get_object (window->builder, "button-identify")); #ifdef HAVE_LIBX11 if (GDK_IS_X11_DISPLAY (gdk_display_get_default ())) - g_signal_connect (G_OBJECT (button), "clicked", - G_CALLBACK (xwininfo_clicked_cb), window); + g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (xwininfo_clicked_cb), window); else #endif gtk_widget_hide (button); @@ -319,8 +326,8 @@ xtm_process_window_init (XtmProcessWindow *window) guint refresh_rate; g_object_get (window->settings, - "refresh-rate", &refresh_rate, - NULL); + "refresh-rate", &refresh_rate, + NULL); window->vpaned = GTK_WIDGET (gtk_builder_get_object (window->builder, "mainview-vpaned")); 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); } - window->filter_entry = GTK_WIDGET(gtk_builder_get_object (window->builder, "filter-entry")); - g_signal_connect (G_OBJECT(window->filter_entry), "icon-press", G_CALLBACK(filter_entry_icon_pressed_cb), NULL); - g_signal_connect (G_OBJECT(window->filter_entry), "changed", G_CALLBACK(filter_entry_keyrelease_handler), window->treeview); + window->filter_entry = GTK_WIDGET (gtk_builder_get_object (window->builder, "filter-entry")); + g_signal_connect (G_OBJECT (window->filter_entry), "icon-press", G_CALLBACK (filter_entry_icon_pressed_cb), NULL); + g_signal_connect (G_OBJECT (window->filter_entry), "changed", G_CALLBACK (filter_entry_keyrelease_handler), window->treeview); gtk_widget_set_tooltip_text (window->filter_entry, _("Filter on process name")); gtk_widget_grab_focus (window->filter_entry); @@ -452,22 +459,22 @@ xtm_process_window_key_pressed (XtmProcessWindow *window, GdkEventKey *event) gboolean ret = FALSE; if (event->keyval == GDK_KEY_Escape && - gtk_widget_is_focus(GTK_WIDGET (window->filter_entry))) + gtk_widget_is_focus (GTK_WIDGET (window->filter_entry))) { if (xfconf_channel_get_bool (window->channel, SETTING_SHOW_FILTER, FALSE)) - gtk_entry_set_text (GTK_ENTRY(window->filter_entry), ""); + gtk_entry_set_text (GTK_ENTRY (window->filter_entry), ""); else g_signal_emit_by_name (window, "delete-event", event, &ret, G_TYPE_BOOLEAN); } 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); ret = TRUE; } else if (event->keyval == GDK_KEY_f && (event->state & GDK_CONTROL_MASK)) { - gtk_widget_grab_focus (GTK_WIDGET(window->filter_entry)); + gtk_widget_grab_focus (GTK_WIDGET (window->filter_entry)); xfconf_channel_set_bool (window->channel, SETTING_SHOW_FILTER, TRUE); ret = TRUE; } @@ -501,7 +508,7 @@ xtm_process_window_show (GtkWidget *widget) g_return_if_fail (GTK_IS_WIDGET (XTM_PROCESS_WINDOW (widget)->window)); gtk_widget_show (XTM_PROCESS_WINDOW (widget)->window); gtk_window_present (GTK_WINDOW (XTM_PROCESS_WINDOW (widget)->window)); - GTK_WIDGET_CLASS (xtm_process_window_parent_class)->show(widget); + GTK_WIDGET_CLASS (xtm_process_window_parent_class)->show (widget); } static void @@ -514,7 +521,7 @@ xtm_process_window_hide (GtkWidget *widget) gtk_window_get_position (GTK_WINDOW (XTM_PROCESS_WINDOW (widget)->window), &winx, &winy); gtk_widget_hide (XTM_PROCESS_WINDOW (widget)->window); gtk_window_move (GTK_WINDOW (XTM_PROCESS_WINDOW (widget)->window), winx, winy); - GTK_WIDGET_CLASS (xtm_process_window_parent_class)->hide(widget); + GTK_WIDGET_CLASS (xtm_process_window_parent_class)->hide (widget); } GtkTreeModel * @@ -526,7 +533,7 @@ xtm_process_window_get_model (XtmProcessWindow *window) } void -xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processes, gfloat cpu, gfloat memory, gchar* memory_str, gfloat swap, gchar* swap_str) +xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processes, gfloat cpu, gfloat memory, gchar *memory_str, gfloat swap, gchar *swap_str) { gchar text[100]; gchar value[4]; @@ -537,12 +544,12 @@ xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processe g_object_set (window->statusbar, "num-processes", num_processes, "cpu", cpu, "memory", memory_str, "swap", swap_str, NULL); xtm_process_monitor_add_peak (XTM_PROCESS_MONITOR (window->cpu_monitor), cpu / 100.0f, -1.0); - g_snprintf (value, sizeof(value), "%.0f", cpu); - g_snprintf (text, sizeof(text), _("CPU: %s%%"), value); + g_snprintf (value, sizeof (value), "%.0f", cpu); + g_snprintf (text, sizeof (text), _("CPU: %s%%"), value); gtk_widget_set_tooltip_text (window->cpu_monitor, text); xtm_process_monitor_add_peak (XTM_PROCESS_MONITOR (window->mem_monitor), memory / 100.0f, swap / 100.0f); - g_snprintf (text, sizeof(text), _("Memory: %s"), memory_str); + g_snprintf (text, sizeof (text), _("Memory: %s"), memory_str); gtk_widget_set_tooltip_text (window->mem_monitor, text); } diff --git a/src/process-window.h b/src/process-window.h index b44a7a7..3f552a3 100644 --- a/src/process-window.h +++ b/src/process-window.h @@ -14,29 +14,30 @@ #include #include -#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_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_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XTM_TYPE_PROCESS_WINDOW)) -#define XTM_PROCESS_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_PROCESS_WINDOW, XtmProcessWindowClass)) -#define XTM_SHOW_MESSAGE(type, title, message, ...) { \ - GtkWidget *dialog = gtk_message_dialog_new (NULL, 0, type, GTK_BUTTONS_OK, title); \ - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), message , ## __VA_ARGS__ ); \ - gtk_window_set_title (GTK_WINDOW (dialog), _("Task Manager")); \ - gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); \ - gtk_dialog_run (GTK_DIALOG (dialog)); \ - gtk_widget_destroy (dialog); \ -} +#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_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_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XTM_TYPE_PROCESS_WINDOW)) +#define XTM_PROCESS_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_PROCESS_WINDOW, XtmProcessWindowClass)) +#define XTM_SHOW_MESSAGE(type, title, message, ...) \ + { \ + GtkWidget *dialog = gtk_message_dialog_new (NULL, 0, type, GTK_BUTTONS_OK, title); \ + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), message, ##__VA_ARGS__); \ + gtk_window_set_title (GTK_WINDOW (dialog), _("Task Manager")); \ + gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); \ + gtk_dialog_run (GTK_DIALOG (dialog)); \ + gtk_widget_destroy (dialog); \ + } typedef struct _XtmProcessWindow XtmProcessWindow; -GType xtm_process_window_get_type (void); -GtkWidget * xtm_process_window_new (void); -void xtm_process_window_settings_init (XtmProcessWindow *window, XfconfChannel *channel); -void xtm_process_window_show (GtkWidget *widget); -GtkTreeModel * xtm_process_window_get_model (XtmProcessWindow *window); -void xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processes, gfloat cpu, gfloat memory, gchar* memory_str, gfloat swap, gchar* swap_str); -void xtm_process_window_show_swap_usage (XtmProcessWindow *window, gboolean show_swap_usage); +GType xtm_process_window_get_type (void); +GtkWidget *xtm_process_window_new (void); +void xtm_process_window_settings_init (XtmProcessWindow *window, XfconfChannel *channel); +void xtm_process_window_show (GtkWidget *widget); +GtkTreeModel *xtm_process_window_get_model (XtmProcessWindow *window); +void xtm_process_window_set_system_info (XtmProcessWindow *window, guint num_processes, gfloat cpu, gfloat memory, gchar *memory_str, gfloat swap, gchar *swap_str); +void xtm_process_window_show_swap_usage (XtmProcessWindow *window, gboolean show_swap_usage); #endif /* !PROCESS_WINDOW_H */ diff --git a/src/settings-dialog.c b/src/settings-dialog.c index 787306a..18f3ea7 100644 --- a/src/settings-dialog.c +++ b/src/settings-dialog.c @@ -21,14 +21,14 @@ #include -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); typedef struct { - GtkWidget *combobox; - guint rate; + GtkWidget *combobox; + guint rate; } XtmRefreshRate; static void @@ -58,7 +58,7 @@ combobox_changed (GtkComboBox *combobox, XtmSettings *settings) { GtkTreeModel *model; GtkTreeIter iter; - GValue prop = { 0, }; + GValue prop = G_VALUE_INIT; gint rate; gtk_combo_box_get_active_iter (combobox, &iter); @@ -69,17 +69,14 @@ combobox_changed (GtkComboBox *combobox, XtmSettings *settings) } static gboolean -combobox_foreach (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer user_data) +combobox_foreach (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data) { XtmRefreshRate *refresh_rate = user_data; - GValue prop = { 0, }; + GValue prop = G_VALUE_INIT; gtk_tree_model_get_value (model, iter, 0, &prop); - if ((guint) g_value_get_int (&prop) == refresh_rate->rate) + if ((guint)g_value_get_int (&prop) == refresh_rate->rate) { gtk_combo_box_set_active_iter (GTK_COMBO_BOX (refresh_rate->combobox), iter); return TRUE; @@ -134,7 +131,8 @@ show_about_dialog (GtkWidget *widget, gpointer user_data) "OpenSolaris", " \342\200\242 Mike Massonnet", " \342\200\242 Peter Tribble", - NULL }; + NULL + }; const gchar *license = "This program is free software; you can redistribute it and/or modify\n" "it under the terms of the GNU General Public License as published by\n" diff --git a/src/settings-dialog.h b/src/settings-dialog.h index 4475452..517dde9 100644 --- a/src/settings-dialog.h +++ b/src/settings-dialog.h @@ -13,6 +13,6 @@ #include #include -void xtm_settings_dialog_run (GtkWidget *parent_window); +void xtm_settings_dialog_run (GtkWidget *parent_window); #endif /* !SETTINGS_DIALOG_H */ diff --git a/src/settings.c b/src/settings.c index a703393..2693e22 100644 --- a/src/settings.c +++ b/src/settings.c @@ -56,19 +56,19 @@ enum typedef struct _XtmSettingsClass XtmSettingsClass; struct _XtmSettingsClass { - GObjectClass parent_class; + GObjectClass parent_class; }; struct _XtmSettings { - GObject parent; + GObject parent; /**/ - GValue values[N_PROPS]; + GValue values[N_PROPS]; }; 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_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); -static void xtm_settings_finalize (GObject *object); +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_finalize (GObject *object); static void xtm_settings_class_init (XtmSettingsClass *klass) @@ -129,7 +129,6 @@ xtm_settings_class_init (XtmSettingsClass *klass) static void xtm_settings_init (XtmSettings *settings) { - } static void diff --git a/src/settings.h b/src/settings.h index 7bec391..3ed0eea 100644 --- a/src/settings.h +++ b/src/settings.h @@ -13,58 +13,58 @@ #include #include -#define DEFAULT_WINDOW_HEIGHT 600 -#define DEFAULT_WINDOW_WIDTH 400 +#define DEFAULT_WINDOW_HEIGHT 600 +#define DEFAULT_WINDOW_WIDTH 400 -#define CHANNEL "xfce4-taskmanager" +#define CHANNEL "xfce4-taskmanager" /* general settings */ -#define SETTING_SHOW_STATUS_ICON "/show-status-icon" -#define SETTING_PROMPT_TERMINATE_TASK "/prompt-terminate-task" -#define SETTING_WINDOW_MAXIMIZED "/window-maximized" -#define SETTING_WINDOW_WIDTH "/window-width" -#define SETTING_WINDOW_HEIGHT "/window-height" +#define SETTING_SHOW_STATUS_ICON "/show-status-icon" +#define SETTING_PROMPT_TERMINATE_TASK "/prompt-terminate-task" +#define SETTING_WINDOW_MAXIMIZED "/window-maximized" +#define SETTING_WINDOW_WIDTH "/window-width" +#define SETTING_WINDOW_HEIGHT "/window-height" /* interface settings */ -#define SETTING_SHOW_FILTER "/interface/show-filter" -#define SETTING_HANDLE_POSITION "/interface/handle-position" -#define SETTING_SHOW_LEGEND "/interface/show-legend" +#define SETTING_SHOW_FILTER "/interface/show-filter" +#define SETTING_HANDLE_POSITION "/interface/handle-position" +#define SETTING_SHOW_LEGEND "/interface/show-legend" -#define SETTING_SHOW_ALL_PROCESSES "/interface/show-all-processes" -#define SETTING_SHOW_APPLICATION_ICONS "/interface/show-application-icons" -#define SETTING_FULL_COMMAND_LINE "/interface/full-command-line" -#define SETTING_MORE_PRECISION "/interface/more-precision" -#define SETTING_PROCESS_TREE "/interface/process-tree" -#define SETTING_REFRESH_RATE "/interface/refresh-rate" +#define SETTING_SHOW_ALL_PROCESSES "/interface/show-all-processes" +#define SETTING_SHOW_APPLICATION_ICONS "/interface/show-application-icons" +#define SETTING_FULL_COMMAND_LINE "/interface/full-command-line" +#define SETTING_MORE_PRECISION "/interface/more-precision" +#define SETTING_PROCESS_TREE "/interface/process-tree" +#define SETTING_REFRESH_RATE "/interface/refresh-rate" /* column visibility */ -#define SETTING_COLUMN_PID "/columns/column-pid" -#define SETTING_COLUMN_PPID "/columns/column-ppid" -#define SETTING_COLUMN_STATE "/columns/column-state" -#define SETTING_COLUMN_VSZ "/columns/column-vsz" -#define SETTING_COLUMN_GROUP_VSZ "/columns/column-group-vsz" -#define SETTING_COLUMN_RSS "/columns/column-rss" -#define SETTING_COLUMN_GROUP_RSS "/columns/column-group-rss" -#define SETTING_COLUMN_UID "/columns/column-uid" -#define SETTING_COLUMN_CPU "/columns/column-cpu" -#define SETTING_COLUMN_GROUP_CPU "/columns/column-group-cpu" -#define SETTING_COLUMN_PRIORITY "/columns/column-priority" -#define SETTING_COLUMN_SORT_ID "/columns/sort-id" -#define SETTING_COLUMN_SORT_TYPE "/columns/sort-type" -#define SETTING_COLUMN_POSITIONS "/columns/positions" +#define SETTING_COLUMN_PID "/columns/column-pid" +#define SETTING_COLUMN_PPID "/columns/column-ppid" +#define SETTING_COLUMN_STATE "/columns/column-state" +#define SETTING_COLUMN_VSZ "/columns/column-vsz" +#define SETTING_COLUMN_GROUP_VSZ "/columns/column-group-vsz" +#define SETTING_COLUMN_RSS "/columns/column-rss" +#define SETTING_COLUMN_GROUP_RSS "/columns/column-group-rss" +#define SETTING_COLUMN_UID "/columns/column-uid" +#define SETTING_COLUMN_CPU "/columns/column-cpu" +#define SETTING_COLUMN_GROUP_CPU "/columns/column-group-cpu" +#define SETTING_COLUMN_PRIORITY "/columns/column-priority" +#define SETTING_COLUMN_SORT_ID "/columns/sort-id" +#define SETTING_COLUMN_SORT_TYPE "/columns/sort-type" +#define SETTING_COLUMN_POSITIONS "/columns/positions" -#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_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_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_TYPE_SETTINGS (xtm_settings_get_type ()) +#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_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_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_SETTINGS, XtmSettingsClass)) typedef struct _XtmSettings XtmSettings; -void xtm_settings_bind_xfconf (XtmSettings *settings, XfconfChannel *channel); -GType xtm_settings_get_type (void); -XtmSettings * xtm_settings_get_default (void); +void xtm_settings_bind_xfconf (XtmSettings *settings, XfconfChannel *channel); +GType xtm_settings_get_type (void); +XtmSettings *xtm_settings_get_default (void); diff --git a/src/task-manager-bsd.c b/src/task-manager-bsd.c index 6bfe7c8..d2f4707 100644 --- a/src/task-manager-bsd.c +++ b/src/task-manager-bsd.c @@ -43,11 +43,12 @@ #include extern int errno; -char *state_abbrev[] = { +char *state_abbrev[] = { "", "start", "run", "sleep", "stop", "zomb", "dead", "onproc" }; -gboolean get_task_list (GArray *task_list) +gboolean +get_task_list (GArray *task_list) { int mib[6]; size_t size; @@ -58,7 +59,7 @@ gboolean get_task_list (GArray *task_list) #endif Task t; char **args; - gchar* buf; + gchar *buf; int nproc, i; mib[0] = CTL_KERN; @@ -70,85 +71,88 @@ gboolean get_task_list (GArray *task_list) mib[2] = KERN_PROC_ALL; mib[3] = 0; #ifdef __OpenBSD__ - mib[4] = sizeof(struct kinfo_proc); + mib[4] = sizeof (struct kinfo_proc); #else - mib[4] = sizeof(struct kinfo_proc2); + mib[4] = sizeof (struct kinfo_proc2); #endif mib[5] = 0; - if (sysctl(mib, 6, NULL, &size, NULL, 0) < 0) + if (sysctl (mib, 6, NULL, &size, NULL, 0) < 0) #ifdef __OpenBSD__ - errx(1, "could not get kern.proc size"); + errx (1, "could not get kern.proc size"); #else - errx(1, "could not get kern.proc2 size"); + errx (1, "could not get kern.proc2 size"); #endif - size = 5 * size / 4; /* extra slop */ - if ((kp = malloc(size)) == NULL) - errx(1,"failed to allocate memory for proc structures"); + size = 5 * size / 4; /* extra slop */ + if ((kp = malloc (size)) == NULL) + errx (1, "failed to allocate memory for proc structures"); #ifdef __OpenBSD__ - mib[5] = (int)(size / sizeof(struct kinfo_proc)); + mib[5] = (int)(size / sizeof (struct kinfo_proc)); #else - mib[5] = (int)(size / sizeof(struct kinfo_proc2)); + mib[5] = (int)(size / sizeof (struct kinfo_proc2)); #endif - if (sysctl(mib, 6, kp, &size, NULL, 0) < 0) + if (sysctl (mib, 6, kp, &size, NULL, 0) < 0) #ifdef __OpenBSD__ - errx(1, "could not read kern.proc"); - nproc = (int)(size / sizeof(struct kinfo_proc)); + errx (1, "could not read kern.proc"); + nproc = (int)(size / sizeof (struct kinfo_proc)); #else - errx(1, "could not read kern.proc2"); - nproc = (int)(size / sizeof(struct kinfo_proc2)); + errx (1, "could not read kern.proc2"); + nproc = (int)(size / sizeof (struct kinfo_proc2)); #endif - for (i=0 ; i < nproc ; i++) + for (i = 0; i < nproc; i++) { #ifdef __OpenBSD__ struct kinfo_proc p = kp[i]; #else struct kinfo_proc2 p = kp[i]; #endif - memset(&t, 0, sizeof(t)); + memset (&t, 0, sizeof (t)); t.pid = p.p_pid; t.ppid = p.p_ppid; t.uid = p.p_uid; t.prio = p.p_priority - PZERO; t.vsz = p.p_vm_dsize + p.p_vm_ssize + p.p_vm_tsize; - t.vsz *= getpagesize(); - t.rss = p.p_vm_rssize * getpagesize(); - g_snprintf(t.state, sizeof t.state, "%s", state_abbrev[p.p_stat]); - g_strlcpy(t.name, p.p_comm, strlen(p.p_comm) + 1); + t.vsz *= getpagesize (); + t.rss = p.p_vm_rssize * getpagesize (); + g_snprintf (t.state, sizeof t.state, "%s", state_abbrev[p.p_stat]); + g_strlcpy (t.name, p.p_comm, strlen (p.p_comm) + 1); /* shamelessly stolen from top/machine.c */ - if (!P_ZOMBIE(&p)) { + if (!P_ZOMBIE (&p)) + { size = 1024; - if ((args = malloc(size)) == NULL) - errx(1,"failed to allocate memory for argv structures at %zu", size); - memset(args, 0, size); - for (;; size *= 2) { - if ((args = realloc(args, size)) == NULL) - errx(1,"failed to allocate memory (size=%zu) for argv structures of pid %d", size, t.pid); - memset(args, 0, size); + if ((args = malloc (size)) == NULL) + errx (1, "failed to allocate memory for argv structures at %zu", size); + memset (args, 0, size); + for (;; size *= 2) + { + if ((args = realloc (args, size)) == NULL) + errx (1, "failed to allocate memory (size=%zu) for argv structures of pid %d", size, t.pid); + memset (args, 0, size); mib[0] = CTL_KERN; mib[1] = KERN_PROC_ARGS; mib[2] = t.pid; mib[3] = KERN_PROC_ARGV; - if (sysctl(mib, 4, args, &size, NULL, 0) == 0) + if (sysctl (mib, 4, args, &size, NULL, 0) == 0) break; - if (errno != ENOMEM) { /* ESRCH: process disappeared */ - /* printf ("process with pid %d disappeared, errno=%d\n", t.pid, errno); */ - args[0] ='\0'; + if (errno != ENOMEM) + { /* ESRCH: process disappeared */ + /* printf ("process with pid %d disappeared, errno=%d\n", t.pid, errno); */ + args[0] = '\0'; args[1] = NULL; break; } } - buf = g_strjoinv(" ", args); - g_assert(g_utf8_validate(buf, -1, NULL)); - g_strlcpy(t.cmdline, buf, sizeof t.cmdline); - g_free(buf); - free(args); + buf = g_strjoinv (" ", args); + g_assert (g_utf8_validate (buf, -1, NULL)); + g_strlcpy (t.cmdline, buf, sizeof t.cmdline); + g_free (buf); + free (args); } t.cpu_user = (100.0f * ((gfloat)p.p_pctcpu / FSCALE)); t.cpu_system = 0.0f; /* TODO ? */ - g_array_append_val(task_list, t); + g_array_append_val (task_list, t); } - free(kp); + free (kp); g_array_sort (task_list, task_pid_compare_fn); @@ -161,10 +165,10 @@ pid_is_sleeping (GPid pid) int mib[6]; #ifdef __OpenBSD__ struct kinfo_proc kp; - size_t size = sizeof(struct kinfo_proc); + size_t size = sizeof (struct kinfo_proc); #else struct kinfo_proc2 kp; - size_t size = sizeof(struct kinfo_proc2); + size_t size = sizeof (struct kinfo_proc2); #endif mib[0] = CTL_KERN; @@ -176,30 +180,31 @@ pid_is_sleeping (GPid pid) mib[2] = KERN_PROC_PID; mib[3] = pid; #ifdef __OpenBSD__ - mib[4] = sizeof(struct kinfo_proc); + mib[4] = sizeof (struct kinfo_proc); #else - mib[4] = sizeof(struct kinfo_proc2); + mib[4] = sizeof (struct kinfo_proc2); #endif mib[5] = 1; - if (sysctl(mib, 6, &kp, &size, NULL, 0) < 0) + if (sysctl (mib, 6, &kp, &size, NULL, 0) < 0) #ifdef __OpenBSD__ - errx(1, "could not read kern.proc for pid %d", pid); + errx (1, "could not read kern.proc for pid %d", pid); #else - errx(1, "could not read kern.proc2 for pid %d", pid); + errx (1, "could not read kern.proc2 for pid %d", pid); #endif return (kp.p_stat == SSTOP ? TRUE : FALSE); } -gboolean get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system) +gboolean +get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system) { static gulong cur_user = 0, cur_system = 0, cur_total = 0; static gulong old_user = 0, old_system = 0, old_total = 0; - int mib[] = {CTL_KERN, KERN_CPTIME}; - glong cp_time[CPUSTATES]; - gsize size = sizeof( cp_time ); - if (sysctl(mib, 2, &cp_time, &size, NULL, 0) < 0) - errx(1,"failed to get kern.cptime"); + int mib[] = { CTL_KERN, KERN_CPTIME }; + glong cp_time[CPUSTATES]; + gsize size = sizeof (cp_time); + if (sysctl (mib, 2, &cp_time, &size, NULL, 0) < 0) + errx (1, "failed to get kern.cptime"); old_user = cur_user; old_system = cur_system; @@ -213,73 +218,76 @@ gboolean get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system *cpu_system = (old_total > 0) ? (((cur_system - old_system) * 100.0f) / (float)(cur_total - old_total)) : 0.0f; /* get #cpu */ - size = sizeof(&cpu_count); + size = sizeof (&cpu_count); mib[0] = CTL_HW; mib[1] = HW_NCPU; - if (sysctl(mib, 2, cpu_count, &size, NULL, 0) == -1) - errx(1,"failed to get cpu count"); + if (sysctl (mib, 2, cpu_count, &size, NULL, 0) == -1) + errx (1, "failed to get cpu count"); return TRUE; } /* vmtotal values in #pg */ -#define pagetok(nb) ((nb) * (getpagesize())) +#define pagetok(nb) ((nb) * (getpagesize ())) gboolean get_memory_usage (guint64 *memory_total, guint64 *memory_available, guint64 *memory_free, guint64 *memory_cache, guint64 *memory_buffers, guint64 *swap_total, guint64 *swap_free) { #ifdef __OpenBSD__ - int mib[] = {CTL_VM, VM_UVMEXP}; - struct uvmexp uvmexp; + int mib[] = { CTL_VM, VM_UVMEXP }; + struct uvmexp uvmexp; #else - int mib[] = {CTL_VM, VM_METER}; + int mib[] = { CTL_VM, VM_METER }; struct vmtotal vmtotal; #endif struct swapent *swdev; int nswap, i; size_t size; #ifdef __OpenBSD__ - size = sizeof(uvmexp); - if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0) - errx(1,"failed to get vm.uvmexp"); + size = sizeof (uvmexp); + if (sysctl (mib, 2, &uvmexp, &size, NULL, 0) < 0) + errx (1, "failed to get vm.uvmexp"); /* cheat : rm = tot used, add free to get total */ - *memory_free = pagetok((guint64)uvmexp.free); - *memory_total = pagetok((guint64)uvmexp.npages); + *memory_free = pagetok ((guint64)uvmexp.free); + *memory_total = pagetok ((guint64)uvmexp.npages); *memory_cache = 0; *memory_buffers = 0; /*pagetok(uvmexp.npages - uvmexp.free - uvmexp.active);*/ #else - size = sizeof(vmtotal); - if (sysctl(mib, 2, &vmtotal, &size, NULL, 0) < 0) - errx(1,"failed to get vm.meter"); + size = sizeof (vmtotal); + if (sysctl (mib, 2, &vmtotal, &size, NULL, 0) < 0) + errx (1, "failed to get vm.meter"); /* cheat : rm = tot used, add free to get total */ - *memory_total = pagetok(vmtotal.t_rm + vmtotal.t_free); - *memory_free = pagetok(vmtotal.t_free); + *memory_total = pagetok (vmtotal.t_rm + vmtotal.t_free); + *memory_free = pagetok (vmtotal.t_free); *memory_cache = 0; - *memory_buffers = pagetok(vmtotal.t_rm - vmtotal.t_arm); + *memory_buffers = pagetok (vmtotal.t_rm - vmtotal.t_arm); #endif *memory_available = *memory_free + *memory_cache + *memory_buffers; /* get swap stats */ *swap_total = *swap_free = 0; - if ((nswap = swapctl(SWAP_NSWAP, 0, 0)) == 0) + if ((nswap = swapctl (SWAP_NSWAP, 0, 0)) == 0) return TRUE; - if ((swdev = calloc(nswap, sizeof(*swdev))) == NULL) - errx(1,"failed to allocate memory for swdev structures"); + if ((swdev = calloc (nswap, sizeof (*swdev))) == NULL) + errx (1, "failed to allocate memory for swdev structures"); - if (swapctl(SWAP_STATS, swdev, nswap) == -1) { - free(swdev); - errx(1,"failed to get swap stats"); + if (swapctl (SWAP_STATS, swdev, nswap) == -1) + { + free (swdev); + errx (1, "failed to get swap stats"); } /* Total things up */ - for (i = 0; i < nswap; i++) { - if (swdev[i].se_flags & SWF_ENABLE) { + for (i = 0; i < nswap; i++) + { + if (swdev[i].se_flags & SWF_ENABLE) + { *swap_free += (swdev[i].se_nblks - swdev[i].se_inuse); *swap_total += swdev[i].se_nblks; } } *swap_total *= DEV_BSIZE; *swap_free *= DEV_BSIZE; - free(swdev); + free (swdev); return TRUE; } diff --git a/src/task-manager-freebsd.c b/src/task-manager-freebsd.c index 14c671f..9983f1b 100644 --- a/src/task-manager-freebsd.c +++ b/src/task-manager-freebsd.c @@ -71,7 +71,7 @@ get_memory_usage (guint64 *memory_total, guint64 *memory_available, guint64 *mem { /* Get memory usage */ { - *memory_total = get_mem_by_bytes ("hw.physmem");; + *memory_total = get_mem_by_bytes ("hw.physmem"); *memory_free = get_mem_by_pages ("vm.stats.vm.v_free_count"); *memory_cache = get_mem_by_pages ("vm.stats.vm.v_inactive_count"); *memory_buffers = get_mem_by_bytes ("vfs.bufspace"); @@ -139,7 +139,7 @@ get_task_details (struct kinfo_proc *kp, Task *task) size_t bufsz; int i, oid[4]; - memset(task, 0, sizeof(Task)); + memset (task, 0, sizeof (Task)); task->pid = kp->ki_pid; task->ppid = kp->ki_ppid; task->cpu_user = 100.0f * ((float)kp->ki_pctcpu / FSCALE); @@ -148,39 +148,45 @@ get_task_details (struct kinfo_proc *kp, Task *task) task->rss = ((guint64)kp->ki_rssize * (guint64)getpagesize ()); task->uid = kp->ki_uid; task->prio = kp->ki_nice; - g_strlcpy (task->name, kp->ki_comm, sizeof(task->name)); + g_strlcpy (task->name, kp->ki_comm, sizeof (task->name)); oid[0] = CTL_KERN; oid[1] = KERN_PROC; oid[2] = KERN_PROC_ARGS; oid[3] = kp->ki_pid; - bufsz = sizeof(buf); - memset(buf, 0, sizeof(buf)); - if (sysctl(oid, 4, buf, &bufsz, 0, 0) == -1) { + bufsz = sizeof (buf); + memset (buf, 0, sizeof (buf)); + if (sysctl (oid, 4, buf, &bufsz, 0, 0) == -1) + { /* * If the supplied buf is too short to hold the requested * value the sysctl returns with ENOMEM. The buf is filled * with the truncated value and the returned bufsz is equal * to the requested len. */ - if (errno != ENOMEM || bufsz != sizeof(buf)) { + if (errno != ENOMEM || bufsz != sizeof (buf)) + { bufsz = 0; - } else { + } + else + { buf[(bufsz - 1)] = 0; } } - if (0 != bufsz) { + if (0 != bufsz) + { p = buf; - do { - g_strlcat (task->cmdline, p, sizeof(task->cmdline)); - g_strlcat (task->cmdline, " ", sizeof(task->cmdline)); - p += (strlen(p) + 1); + do + { + g_strlcat (task->cmdline, p, sizeof (task->cmdline)); + g_strlcat (task->cmdline, " ", sizeof (task->cmdline)); + p += (strlen (p) + 1); } while (p < buf + bufsz); } else { - g_strlcpy (task->cmdline, kp->ki_comm, sizeof(task->cmdline)); + g_strlcpy (task->cmdline, kp->ki_comm, sizeof (task->cmdline)); } i = 0; diff --git a/src/task-manager-linux.c b/src/task-manager-linux.c index d1c2548..c7ecb4d 100644 --- a/src/task-manager-linux.c +++ b/src/task-manager-linux.c @@ -22,19 +22,13 @@ get_memory_usage (guint64 *memory_total, guint64 *memory_available, guint64 *mem { FILE *file; gchar *filename = "/proc/meminfo"; - guint64 mem_total = 0, - mem_free = 0, - mem_avail = 0, - mem_cached = 0, - mem_buffers = 0, - swp_total = 0, - swp_free = 0; + guint64 mem_total = 0, mem_free = 0, mem_avail = 0, mem_cached = 0, mem_buffers = 0, swp_total = 0, swp_free = 0; if ((file = fopen (filename, "r")) != NULL) { gint found = 0; gchar buffer[256]; - while (found < 7 && fgets (buffer, sizeof(buffer), file) != NULL) + while (found < 7 && fgets (buffer, sizeof (buffer), file) != NULL) { found += !mem_total ? sscanf (buffer, "MemTotal:\t%lu kB", &mem_total) : 0; found += !mem_free ? sscanf (buffer, "MemFree:\t%lu kB", &mem_free) : 0; @@ -75,7 +69,7 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system) if ((file = fopen (filename, "r")) == NULL) return FALSE; - if (fgets (buffer, sizeof(buffer), file) == NULL) + if (fgets (buffer, sizeof (buffer), file) == NULL) { fclose (file); return FALSE; @@ -85,7 +79,7 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system) if (_cpu_count == 0) { - while (fgets (buffer, sizeof(buffer), file) != NULL) + while (fgets (buffer, sizeof (buffer), file) != NULL) { if (buffer[0] != 'c' && buffer[1] != 'p' && buffer[2] != 'u') break; @@ -117,7 +111,8 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system) return TRUE; } -static inline int get_pagesize (void) +static inline int +get_pagesize (void) { static int pagesize = 0; if (pagesize == 0) @@ -137,7 +132,7 @@ get_task_cmdline (Task *task) gint i; gint c; - snprintf (filename, sizeof(filename), "/proc/%i/cmdline", task->pid); + snprintf (filename, sizeof (filename), "/proc/%i/cmdline", task->pid); if ((file = fopen (filename, "r")) == NULL) return FALSE; @@ -145,8 +140,8 @@ get_task_cmdline (Task *task) for (i = 0; (c = fgetc (file)) != EOF && i < (gint)sizeof (task->cmdline) - 1; i++) task->cmdline[i] = (c == '\0') ? ' ' : (gchar)c; task->cmdline[i] = '\0'; - if (i > 0 && task->cmdline[i-1] == ' ') - task->cmdline[i-1] = '\0'; + if (i > 0 && task->cmdline[i - 1] == ' ') + task->cmdline[i - 1] = '\0'; fclose (file); /* Kernel processes don't have a cmdline nor an exec path */ @@ -155,8 +150,8 @@ get_task_cmdline (Task *task) size_t len = strlen (task->name); g_strlcpy (&task->cmdline[1], task->name, len + 1); task->cmdline[0] = '['; - task->cmdline[len+1] = ']'; - task->cmdline[len+2] = '\0'; + task->cmdline[len + 1] = ']'; + task->cmdline[len + 2] = '\0'; } return TRUE; @@ -201,17 +196,17 @@ get_task_details (GPid pid, Task *task) gchar filename[96]; gchar buffer[1024]; - snprintf (filename, sizeof(filename), "/proc/%d/stat", pid); + snprintf (filename, sizeof (filename), "/proc/%d/stat", pid); if ((file = fopen (filename, "r")) == NULL) return FALSE; - if (fgets (buffer, sizeof(buffer), file) == NULL) + if (fgets (buffer, sizeof (buffer), file) == NULL) { fclose (file); return FALSE; } fclose (file); - memset(task, 0, sizeof(Task)); + memset (task, 0, sizeof (Task)); /* Scanning the short process name is unreliable with scanf when it contains * spaces, retrieve it manually and fill the buffer */ @@ -238,57 +233,56 @@ get_task_details (GPid pid, Task *task) gint idummy; gulong jiffies_user = 0, jiffies_system = 0; - sscanf(buffer, "%i %255s %1s %i %i %i %i %i %255s %255s %255s %255s %255s %lu %lu %i %i %i %d %i %i %i %llu %llu %255s %255s %255s %i %255s %255s %255s %255s %255s %255s %255s %255s %255s %255s %i %255s %255s", - &task->pid, // processid - dummy, // processname - task->state, // processstate - &task->ppid, // parentid - &idummy, // processs groupid + sscanf (buffer, "%i %255s %1s %i %i %i %i %i %255s %255s %255s %255s %255s %lu %lu %i %i %i %d %i %i %i %llu %llu %255s %255s %255s %i %255s %255s %255s %255s %255s %255s %255s %255s %255s %255s %i %255s %255s", + &task->pid, // processid + dummy, // processname + task->state, // processstate + &task->ppid, // parentid + &idummy, // processs groupid - &idummy, // session id - &idummy, // tty id - &idummy, // tpgid the process group ID of the process running on tty of the process - dummy, // flags - dummy, // minflt minor faults the process has maid + &idummy, // session id + &idummy, // tty id + &idummy, // tpgid the process group ID of the process running on tty of the process + dummy, // flags + dummy, // minflt minor faults the process has maid - dummy, // cminflt - dummy, // majflt - dummy, // cmajflt - &jiffies_user, // utime the number of jiffies that this process has scheduled in user mode - &jiffies_system,// stime " system mode + dummy, // cminflt + dummy, // majflt + dummy, // cmajflt + &jiffies_user, // utime the number of jiffies that this process has scheduled in user mode + &jiffies_system, // stime " system mode - &idummy, // cutime " waited for children in user mode - &idummy, // cstime " system mode - &idummy, // priority (nice value + fifteen) - &task->prio, // nice range from 19 to -19 - &idummy, // hardcoded 0 + &idummy, // cutime " waited for children in user mode + &idummy, // cstime " system mode + &idummy, // priority (nice value + fifteen) + &task->prio, // nice range from 19 to -19 + &idummy, // hardcoded 0 - &idummy, // itrealvalue time in jiffies to next SIGALRM send to this process - &idummy, // starttime jiffies the process startet after system boot - (unsigned long long*)&task->vsz, // vsize in bytes - (unsigned long long*)&task->rss, // rss (number of pages in real memory) - dummy, // rlim limit in bytes for rss + &idummy, // itrealvalue time in jiffies to next SIGALRM send to this process + &idummy, // starttime jiffies the process startet after system boot + (unsigned long long *)&task->vsz, // vsize in bytes + (unsigned long long *)&task->rss, // rss (number of pages in real memory) + dummy, // rlim limit in bytes for rss - dummy, // startcode - dummy, // endcode - &idummy, // startstack - dummy, // kstkesp value of esp (stack pointer) - dummy, // kstkeip value of EIP (instruction pointer) + dummy, // startcode + dummy, // endcode + &idummy, // startstack + dummy, // kstkesp value of esp (stack pointer) + dummy, // kstkeip value of EIP (instruction pointer) - dummy, // signal. bitmap of pending signals - dummy, // blocked: bitmap of blocked signals - dummy, // sigignore: bitmap of ignored signals - dummy, // sigcatch: bitmap of catched signals - dummy, // wchan + dummy, // signal. bitmap of pending signals + dummy, // blocked: bitmap of blocked signals + dummy, // sigignore: bitmap of ignored signals + dummy, // sigcatch: bitmap of catched signals + dummy, // wchan - dummy, // nswap - dummy, // cnswap - dummy, // exit_signal - &idummy, // CPU number last executed on - dummy, + dummy, // nswap + dummy, // cnswap + dummy, // exit_signal + &idummy, // CPU number last executed on + dummy, - dummy - ); + dummy); task->rss *= get_pagesize (); get_cpu_percent (task->pid, jiffies_user, &task->cpu_user, jiffies_system, &task->cpu_system); @@ -298,11 +292,11 @@ get_task_details (GPid pid, Task *task) { guint dummy; - snprintf(filename, sizeof (filename), "/proc/%d/status", pid); + snprintf (filename, sizeof (filename), "/proc/%d/status", pid); if ((file = fopen (filename, "r")) == NULL) return FALSE; - while (fgets (buffer, sizeof(buffer), file) != NULL) + while (fgets (buffer, sizeof (buffer), file) != NULL) { if (sscanf (buffer, "Uid:\t%u\t%u\t%u\t%u", &dummy, &task->uid, &dummy, &dummy) == 1) // UIDs in order: real, effective, saved set, and filesystem break; @@ -328,7 +322,7 @@ get_task_list (GArray *task_list) if ((dir = g_dir_open ("/proc", 0, NULL)) == NULL) return FALSE; - while ((name = g_dir_read_name(dir)) != NULL) + while ((name = g_dir_read_name (dir)) != NULL) { if ((pid = (GPid)g_ascii_strtoull (name, NULL, 0)) > 0) { @@ -354,11 +348,11 @@ pid_is_sleeping (GPid pid) gchar buffer[1024]; gchar state[2]; - snprintf (filename, sizeof(filename), "/proc/%i/status", pid); + snprintf (filename, sizeof (filename), "/proc/%i/status", pid); if ((file = fopen (filename, "r")) == NULL) return FALSE; - while (fgets (buffer, sizeof(buffer), file) != NULL) + while (fgets (buffer, sizeof (buffer), file) != NULL) { if (sscanf (buffer, "State:\t%1s", state) > 0) break; diff --git a/src/task-manager-skel.c b/src/task-manager-skel.c index 847b3c9..b9b4045 100644 --- a/src/task-manager-skel.c +++ b/src/task-manager-skel.c @@ -11,8 +11,8 @@ /* Add includes for system functions needed */ /* Example: #include -#include #include +#include */ #ifdef HAVE_CONFIG_H @@ -52,9 +52,9 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system) static gboolean get_task_details (GPid pid, Task *task) { - memset(task, 0, sizeof(Task)); - g_snprintf (task->name, sizeof(task->name), "foo"); - g_snprintf (task->cmdline, sizeof(task->cmdline), "foo -bar"); + memset (task, 0, sizeof (Task)); + g_snprintf (task->name, sizeof (task->name), "foo"); + g_snprintf (task->cmdline, sizeof (task->cmdline), "foo -bar"); task->uid = 1000; return TRUE; @@ -66,15 +66,9 @@ get_task_list (GArray *task_list) GPid pid = 0; Task task; - //while (/* read all PIDs */) + if (get_task_details (pid, &task)) { - // if (/* pid is valid */) - { - if (get_task_details (pid, &task)) - { - g_array_append_val (task_list, task); - } - } + g_array_append_val (task_list, task); } g_array_sort (task_list, task_pid_compare_fn); diff --git a/src/task-manager-solaris.c b/src/task-manager-solaris.c index f5ab701..4f4c1df 100644 --- a/src/task-manager-solaris.c +++ b/src/task-manager-solaris.c @@ -43,7 +43,7 @@ get_memory_usage (guint64 *memory_total, guint64 *memory_available, guint64 *mem gint n; if (!kc) - init_stats(); + init_stats (); if (!(ksp = kstat_lookup (kc, "unix", 0, "system_pages"))) return FALSE; @@ -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); *cpu_count = _cpu_count; - return TRUE; + return TRUE; } static gboolean @@ -177,7 +177,7 @@ get_task_details (GPid pid, Task *task) gchar filename[96]; psinfo_t process; - snprintf (filename, sizeof(filename), "/proc/%d/psinfo", pid); + snprintf (filename, sizeof (filename), "/proc/%d/psinfo", pid); if ((file = fopen (filename, "r")) == NULL) return FALSE; @@ -187,12 +187,12 @@ get_task_details (GPid pid, Task *task) return FALSE; } - memset(task, 0, sizeof(Task)); + memset (task, 0, sizeof (Task)); task->pid = process.pr_pid; task->ppid = process.pr_ppid; - g_strlcpy (task->name, process.pr_fname, sizeof(task->name)); - snprintf (task->cmdline, sizeof(task->cmdline), "%s", process.pr_psargs); - snprintf (task->state, sizeof(task->state), "%c", process.pr_lwp.pr_sname); + g_strlcpy (task->name, process.pr_fname, sizeof (task->name)); + snprintf (task->cmdline, sizeof (task->cmdline), "%s", process.pr_psargs); + snprintf (task->state, sizeof (task->state), "%c", process.pr_lwp.pr_sname); task->vsz = (guint64)process.pr_size * 1024; task->rss = (guint64)process.pr_rssize * 1024; task->prio = process.pr_lwp.pr_pri; @@ -215,12 +215,12 @@ get_task_list (GArray *task_list) if ((dir = g_dir_open ("/proc", 0, NULL)) == NULL) return FALSE; - while ((name = g_dir_read_name(dir)) != NULL) + while ((name = g_dir_read_name (dir)) != NULL) { if ((pid = (GPid)g_ascii_strtoull (name, NULL, 0)) > 0) { if (get_task_details (pid, &task)) - g_array_append_val(task_list, task); + g_array_append_val (task_list, task); } } @@ -239,7 +239,7 @@ pid_is_sleeping (GPid pid) gchar state[2]; psinfo_t process; - snprintf (filename, sizeof(filename), "/proc/%d/psinfo", pid); + snprintf (filename, sizeof (filename), "/proc/%d/psinfo", pid); if ((file = fopen (filename, "r")) == NULL) return FALSE; @@ -249,7 +249,7 @@ pid_is_sleeping (GPid pid) return FALSE; } - snprintf (state, sizeof(state), "%c", process.pr_lwp.pr_sname); + snprintf (state, sizeof (state), "%c", process.pr_lwp.pr_sname); fclose (file); return (state[0] == 'T') ? TRUE : FALSE; diff --git a/src/task-manager.c b/src/task-manager.c index 127a15e..0b18eeb 100644 --- a/src/task-manager.c +++ b/src/task-manager.c @@ -39,39 +39,39 @@ static gboolean full_cmdline; typedef struct _XtmTaskManagerClass XtmTaskManagerClass; struct _XtmTaskManagerClass { - GObjectClass parent_class; + GObjectClass parent_class; }; struct _XtmTaskManager { - GObject parent; + GObject parent; /**/ #ifdef HAVE_WNCK - XtmAppManager * app_manager; + XtmAppManager *app_manager; #endif - GtkTreeModel * model; - GArray * tasks; - gushort cpu_count; - gfloat cpu_user; - gfloat cpu_system; - guint64 memory_total; - guint64 memory_available; /* free + cache + buffers + an-OS-specific-value */ - guint64 memory_free; - guint64 memory_cache; - guint64 memory_buffers; - guint64 swap_total; - guint64 swap_free; + GtkTreeModel *model; + GArray *tasks; + gushort cpu_count; + gfloat cpu_user; + gfloat cpu_system; + guint64 memory_total; + guint64 memory_available; /* free + cache + buffers + an-OS-specific-value */ + guint64 memory_free; + guint64 memory_cache; + guint64 memory_buffers; + guint64 swap_total; + guint64 swap_free; }; 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 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_mark_tree_iter_as_removed (GtkTreeModel *model, GtkTreeIter *iter, glong timestamp); -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 glong __current_timestamp (void); +static void setting_changed (GObject *object, GParamSpec *pspec, XtmTaskManager *manager); +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_mark_tree_iter_as_removed (GtkTreeModel *model, GtkTreeIter *iter, glong timestamp); +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 glong __current_timestamp (void); @@ -87,7 +87,8 @@ static void xtm_task_manager_init (XtmTaskManager *manager) { #ifdef HAVE_WNCK - if (GDK_IS_X11_DISPLAY (gdk_display_get_default ())) { + if (GDK_IS_X11_DISPLAY (gdk_display_get_default ())) + { manager->app_manager = xtm_app_manager_new (); } #endif @@ -107,7 +108,8 @@ xtm_task_manager_finalize (GObject *object) XtmTaskManager *manager = XTM_TASK_MANAGER (object); g_array_free (manager->tasks, TRUE); #ifdef HAVE_WNCK - if (manager->app_manager != NULL) { + if (manager->app_manager != NULL) + { g_object_unref (manager->app_manager); } #endif @@ -132,38 +134,43 @@ pretty_cmdline (gchar *cmdline, gchar *comm) gsize csize, text_size = (gsize)strlen (text); /* UTF-8 normalize. */ - do { + do + { for (ch = text, text_max = (text + text_size); - text_max > ch; - text_max = (text + text_size), ch = g_utf8_next_char(ch)) { - c = g_utf8_get_char_validated(ch, -1); /* If use (text_max - ch) - result is worse. */ - if ((gunichar)-2 == c) { + text_max > ch; + text_max = (text + text_size), ch = g_utf8_next_char (ch)) + { + c = g_utf8_get_char_validated (ch, -1); /* If use (text_max - ch) - result is worse. */ + if ((gunichar)-2 == c) + { text_size = (gsize)(ch - text); (*ch) = 0; break; } - if ((gunichar)-1 == c) { + if ((gunichar)-1 == c) + { (*ch) = ' '; continue; } - csize = (gsize)g_unichar_to_utf8(c, NULL); + csize = (gsize)g_unichar_to_utf8 (c, NULL); - if (!g_unichar_isdefined(c) || - !g_unichar_isprint(c) || - (g_unichar_isspace(c) && (1 != csize || (' ' != (*ch) && ' ' != (*ch)))) || - g_unichar_ismark(c) || - g_unichar_istitle(c) || - g_unichar_iswide(c) || - g_unichar_iszerowidth(c) || - g_unichar_iscntrl(c)) { + if (!g_unichar_isdefined (c) || + !g_unichar_isprint (c) || + (g_unichar_isspace (c) && (1 != csize || (' ' != (*ch) && ' ' != (*ch)))) || + g_unichar_ismark (c) || + g_unichar_istitle (c) || + g_unichar_iswide (c) || + g_unichar_iszerowidth (c) || + g_unichar_iscntrl (c)) + { if (text_max < (ch + csize)) break; - memmove(ch, (ch + csize), (gsize)(text_max - (ch + csize))); + memmove (ch, (ch + csize), (gsize)(text_max - (ch + csize))); text_size -= csize; } } text[text_size] = 0; - } while (!g_utf8_validate(text, (gssize)text_size, NULL)); + } while (!g_utf8_validate (text, (gssize)text_size, NULL)); if (!full_cmdline && text_size > 3) { @@ -203,7 +210,7 @@ model_add_task (XtmTaskManager *manager, Task *task, glong timestamp) XTM_PTV_COLUMN_UID_STR, uid_name, XTM_PTV_COLUMN_TIMESTAMP, timestamp, -1); - g_free(uid_name); + g_free (uid_name); model_update_tree_iter (manager, &iter, timestamp, TRUE, task); } @@ -246,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_rss = g_format_size_full (task->group_rss, G_FORMAT_SIZE_IEC_UNITS); - g_snprintf (value, sizeof(value), (more_precision) ? "%.2f" : "%.0f", (task->cpu_user + task->cpu_system)); - g_snprintf (cpu, sizeof(cpu), _("%s%%"), value); + g_snprintf (value, sizeof (value), (more_precision) ? "%.2f" : "%.0f", (task->cpu_user + task->cpu_system)); + g_snprintf (cpu, sizeof (cpu), _("%s%%"), value); - g_snprintf (value, sizeof(value), (more_precision) ? "%.2f" : "%.0f", (task->group_cpu_user + task->group_cpu_system)); - g_snprintf (group_cpu, sizeof(group_cpu), _("%s%%"), value); + g_snprintf (value, sizeof (value), (more_precision) ? "%.2f" : "%.0f", (task->group_cpu_user + task->group_cpu_system)); + g_snprintf (group_cpu, sizeof (group_cpu), _("%s%%"), value); /* Retrieve values for tweaking background/foreground color and updating content as needed */ gtk_tree_model_get (model, iter, - XTM_PTV_COLUMN_TIMESTAMP, &old_timestamp, - XTM_PTV_COLUMN_STATE, &old_state, - XTM_PTV_COLUMN_BACKGROUND, &background, - XTM_PTV_COLUMN_FOREGROUND, &foreground, + XTM_PTV_COLUMN_TIMESTAMP, &old_timestamp, + XTM_PTV_COLUMN_STATE, &old_state, + XTM_PTV_COLUMN_BACKGROUND, &background, + XTM_PTV_COLUMN_FOREGROUND, &foreground, #ifdef HAVE_WNCK - XTM_PTV_COLUMN_ICON, &surface, + XTM_PTV_COLUMN_ICON, &surface, #endif - -1); + -1); #ifdef HAVE_WNCK 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; - if (task_list->data != NULL) { + if (task_list->data != NULL) + { tkey.pid = pid; - task_tmp = bsearch(&tkey, task_list->data, task_list->len, sizeof(Task), task_pid_compare_fn); + task_tmp = bsearch (&tkey, task_list->data, task_list->len, sizeof (Task), task_pid_compare_fn); } if (NULL != task) @@ -359,7 +367,7 @@ task_list_find_for_pid (GArray *task_list, GPid pid, Task **task, guint *idx) { if (NULL != task_tmp) { - (*idx) = (guint)(((size_t)task_tmp - (size_t)task_list->data) / sizeof(Task)); + (*idx) = (guint)(((size_t)task_tmp - (size_t)task_list->data) / sizeof (Task)); } else { @@ -386,8 +394,8 @@ xtm_task_manager_new (GtkTreeModel *model) void xtm_task_manager_get_system_info (XtmTaskManager *manager, guint *num_processes, gfloat *cpu, - guint64 *memory_used, guint64 *memory_total, - guint64 *swap_used, guint64 *swap_total) + guint64 *memory_used, guint64 *memory_total, + guint64 *swap_used, guint64 *swap_total) { 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 */ 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_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) { - Task *child_task = &g_array_index(task_list, Task, i); + Task *child_task = &g_array_index (task_list, Task, i); if (child_task->ppid != task->pid) continue; - xtm_task_manager_task_aggregate_children(child_task, task_list); + xtm_task_manager_task_aggregate_children (child_task, task_list); task->group_cpu_system += child_task->group_cpu_system; task->group_cpu_user += child_task->group_cpu_user; @@ -456,7 +464,7 @@ xtm_task_manager_aggregate_children (GArray *task_list) { for (guint i = 0; i < task_list->len; ++i) { - Task *task = &g_array_index(task_list, Task, i); + Task *task = &g_array_index (task_list, Task, i); task->group_cpu_system = -1; task->group_cpu_user = -1; task->group_vsz = -1; @@ -465,7 +473,7 @@ xtm_task_manager_aggregate_children (GArray *task_list) for (guint i = 0; i < task_list->len; ++i) { - Task *task = &g_array_index(task_list, Task, i); + Task *task = &g_array_index (task_list, Task, i); xtm_task_manager_task_aggregate_children (task, task_list); } } @@ -506,7 +514,8 @@ xtm_task_manager_update_model (XtmTaskManager *manager) g_free (cpu_str); if (found) { - if ((timestamp - old_timestamp) > TIMESTAMP_DELTA) { + if ((timestamp - old_timestamp) > TIMESTAMP_DELTA) + { G_DEBUG_FMT ("Remove old task %d", pid); model_remove_tree_iter (manager->model, &cur_iter); } @@ -534,12 +543,12 @@ xtm_task_manager_update_model (XtmTaskManager *manager) update_cmd_line = FALSE; /* Update the model (with the rest) only if needed, this keeps the CPU cool */ - if (model_update_forced || 0 != memcmp(task, task_new, sizeof(Task))) + if (model_update_forced || 0 != memcmp (task, task_new, sizeof (Task))) { need_update = TRUE; /* Update command name if needed (can happen) */ update_cmd_line = (model_update_forced || g_strcmp0 (task->cmdline, task_new->cmdline)); - memcpy(task, task_new, sizeof(Task)); + memcpy (task, task_new, sizeof (Task)); } else /* Update color if needed */ { @@ -588,8 +597,8 @@ get_uid_name (guint uid) struct passwd *pw = NULL, pwd_buf; char buf[4096]; - memset(buf, 0, sizeof(buf)); - error = getpwuid_r(uid, &pwd_buf, buf, sizeof(buf), &pw); + memset (buf, 0, sizeof (buf)); + error = getpwuid_r (uid, &pwd_buf, buf, sizeof (buf), &pw); return (g_strdup ((0 == error && pw != NULL) ? pw->pw_name : "nobody")); } @@ -650,9 +659,9 @@ set_priority_to_pid (GPid pid, gint priority) } gint -task_pid_compare_fn(gconstpointer a, gconstpointer b) +task_pid_compare_fn (gconstpointer a, gconstpointer b) { - return (((const Task*)a)->pid - ((const Task*)b)->pid); + return ((const Task *)a)->pid - ((const Task *)b)->pid; } /* About the constants used below, see for example: https://stackoverflow.com/a/596243 */ diff --git a/src/task-manager.h b/src/task-manager.h index 5a5504b..0fc7a45 100644 --- a/src/task-manager.h +++ b/src/task-manager.h @@ -28,23 +28,23 @@ typedef struct _Task Task; struct _Task { - guint uid; - GPid pid; - GPid ppid; - gchar name[256]; - gchar cmdline[1024]; - gchar state[16]; - gfloat cpu_user; - gfloat cpu_system; - guint64 vsz; - guint64 rss; - gint prio; + guint uid; + GPid pid; + GPid ppid; + gchar name[256]; + gchar cmdline[1024]; + gchar state[16]; + gfloat cpu_user; + gfloat cpu_system; + guint64 vsz; + guint64 rss; + gint prio; // Aggregated values - gfloat group_cpu_user; - gfloat group_cpu_system; - guint64 group_vsz; - guint64 group_rss; + gfloat group_cpu_user; + gfloat group_cpu_system; + guint64 group_vsz; + guint64 group_rss; }; /** @@ -53,32 +53,32 @@ struct _Task * 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_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system); -gboolean get_task_list (GArray *task_list); -gboolean pid_is_sleeping (GPid pid); +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_task_list (GArray *task_list); +gboolean pid_is_sleeping (GPid pid); /** * GObject class used to update the graphical widgets. */ -#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_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_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_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_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_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)) typedef struct _XtmTaskManager XtmTaskManager; -GType xtm_task_manager_get_type (void); -XtmTaskManager * xtm_task_manager_new (GtkTreeModel *model); -void xtm_task_manager_get_system_info (XtmTaskManager *manager, guint *num_processes, gfloat *cpu, - guint64 *memory_used, guint64 *memory_total, - guint64 *swap_used, guint64 *swap_total); -void xtm_task_manager_get_swap_usage (XtmTaskManager *manager, guint64 *swap_free, guint64 *swap_total); -const GArray * xtm_task_manager_get_task_list (XtmTaskManager *manager); -void xtm_task_manager_update_model (XtmTaskManager *manager); +GType xtm_task_manager_get_type (void); +XtmTaskManager *xtm_task_manager_new (GtkTreeModel *model); +void xtm_task_manager_get_system_info (XtmTaskManager *manager, guint *num_processes, gfloat *cpu, + guint64 *memory_used, guint64 *memory_total, + guint64 *swap_used, guint64 *swap_total); +void xtm_task_manager_get_swap_usage (XtmTaskManager *manager, guint64 *swap_free, guint64 *swap_total); +const GArray *xtm_task_manager_get_task_list (XtmTaskManager *manager); +void xtm_task_manager_update_model (XtmTaskManager *manager); /** * Helper functions. @@ -101,22 +101,22 @@ enum XTM_PRIORITY_VERY_HIGH, }; -gchar * get_uid_name (guint uid); -gboolean send_signal_to_pid (GPid pid, gint xtm_signal); -gint task_pid_compare_fn (gconstpointer a, gconstpointer b); -gboolean set_priority_to_pid (GPid pid, gint priority); +gchar *get_uid_name (guint uid); +gboolean send_signal_to_pid (GPid pid, gint xtm_signal); +gint task_pid_compare_fn (gconstpointer a, gconstpointer b); +gboolean set_priority_to_pid (GPid pid, gint priority); #ifndef __unused -# define __unused __attribute__((__unused__)) +#define __unused __attribute__ ((__unused__)) #endif #ifdef DEBUG -# define G_DEBUG_FMT(fmt, args...) g_debug((fmt), ##args) +#define G_DEBUG_FMT(fmt, args...) g_debug ((fmt), ##args) #else -# define G_DEBUG_FMT(fmt, args...) +#define G_DEBUG_FMT(fmt, args...) #endif -gboolean xtm_gtk_widget_is_dark_mode (GtkWidget *widget); +gboolean xtm_gtk_widget_is_dark_mode (GtkWidget *widget); #endif /* !TASK_MANAGER_H */