Apply .clang-format file
This commit is contained in:
@@ -122,7 +122,7 @@ app_get_pid(WnckApplication *application)
|
||||
static gint
|
||||
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
|
||||
@@ -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);
|
||||
|
||||
@@ -112,7 +112,8 @@ 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 ();
|
||||
@@ -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;
|
||||
|
||||
@@ -20,12 +20,14 @@
|
||||
|
||||
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_MODEL
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
GtkTreePath *path;
|
||||
GSequenceIter *list;
|
||||
@@ -73,7 +75,6 @@ static gboolean xtm_process_tree_model_iter_parent (GtkTreeModel *model, GtkTr
|
||||
|
||||
static void xtm_process_tree_model_row_changed (XtmProcessTreeModel *treemodel, GtkTreePath *path, GtkTreeIter *iter, GtkTreeModel *model);
|
||||
static void xtm_process_tree_model_row_inserted (XtmProcessTreeModel *treemodel, GtkTreePath *path, GtkTreeIter *iter, GtkTreeModel *model);
|
||||
//static void xtm_process_tree_model_row_has_child_toggled (XtmProcessTreeModel *treemodel, GtkTreePath *path, GtkTreeIter *iter, GtkTreeModel *model);
|
||||
static void xtm_process_tree_model_row_deleted (XtmProcessTreeModel *treemodel, GtkTreePath *path, GtkTreeModel *model);
|
||||
static void xtm_process_tree_model_rows_reordered (XtmProcessTreeModel *treemodel, GtkTreePath *path, GtkTreeIter *iter, gint *new_order, GtkTreeModel *model);
|
||||
|
||||
@@ -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 */
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
@@ -762,9 +765,11 @@ visible_func (GtkTreeModel *model, GtkTreeIter *iter, XtmProcessTreeView *treevi
|
||||
gboolean mach_filter = TRUE, match_uid = TRUE;
|
||||
guint uid;
|
||||
|
||||
if(treeview->cmd_filter) {
|
||||
if (treeview->cmd_filter)
|
||||
{
|
||||
gtk_tree_model_get (GTK_TREE_MODEL (model), iter, XTM_PTV_COLUMN_COMMAND, &cmdline, -1);
|
||||
if(cmdline) {
|
||||
if (cmdline)
|
||||
{
|
||||
cmdline_lower = g_ascii_strdown (cmdline, -1);
|
||||
key_lower = g_ascii_strdown (treeview->cmd_filter, -1);
|
||||
|
||||
@@ -778,7 +783,8 @@ visible_func (GtkTreeModel *model, GtkTreeIter *iter, XtmProcessTreeView *treevi
|
||||
if (!p)
|
||||
mach_filter = FALSE;
|
||||
}
|
||||
if (!treeview->show_all_processes_cached) {
|
||||
if (!treeview->show_all_processes_cached)
|
||||
{
|
||||
gtk_tree_model_get (GTK_TREE_MODEL (treeview->model), iter, XTM_PTV_COLUMN_UID, &uid, -1);
|
||||
if (treeview->owner_uid != uid)
|
||||
match_uid = FALSE;
|
||||
@@ -891,7 +897,8 @@ xtm_process_tree_view_get_model (XtmProcessTreeView *treeview)
|
||||
}
|
||||
|
||||
void
|
||||
xtm_process_tree_view_highlight_pid (XtmProcessTreeView *treeview, GPid pid) {
|
||||
xtm_process_tree_view_highlight_pid (XtmProcessTreeView *treeview, GPid pid)
|
||||
{
|
||||
GtkTreeModel *model;
|
||||
GtkTreePath *path;
|
||||
GtkTreeIter iter;
|
||||
@@ -937,7 +944,8 @@ xtm_process_tree_view_highlight_pid (XtmProcessTreeView *treeview, GPid pid) {
|
||||
if (tree && !valid)
|
||||
{
|
||||
// finding my way up again
|
||||
do {
|
||||
do
|
||||
{
|
||||
validParent = gtk_tree_model_iter_parent (model, &iter, &child_iter);
|
||||
child_iter = iter;
|
||||
valid = gtk_tree_model_iter_next (model, &iter);
|
||||
|
||||
@@ -74,12 +74,10 @@ 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));
|
||||
}
|
||||
@@ -102,21 +100,26 @@ Select_Window (Display *dpy, int screen)
|
||||
status = XGrabPointer (dpy, root, False,
|
||||
ButtonPressMask | ButtonReleaseMask, GrabModeSync,
|
||||
GrabModeAsync, root, cursor, CurrentTime);
|
||||
if (status != GrabSuccess) {
|
||||
if (status != GrabSuccess)
|
||||
{
|
||||
fprintf (stderr, "Can't grab the mouse.\n");
|
||||
return None;
|
||||
}
|
||||
|
||||
/* Let the user select a window... */
|
||||
while ((target_win == None) || (buttons != 0)) {
|
||||
while ((target_win == None) || (buttons != 0))
|
||||
{
|
||||
/* allow one more event */
|
||||
XAllowEvents (dpy, SyncPointer, CurrentTime);
|
||||
XWindowEvent (dpy, root, ButtonPressMask | ButtonReleaseMask, &event);
|
||||
switch (event.type) {
|
||||
switch (event.type)
|
||||
{
|
||||
case ButtonPress:
|
||||
if (target_win == None) {
|
||||
if (target_win == None)
|
||||
{
|
||||
target_win = event.xbutton.subwindow; /* window selected */
|
||||
if (target_win == None) target_win = root;
|
||||
if (target_win == None)
|
||||
target_win = root;
|
||||
}
|
||||
buttons++;
|
||||
break;
|
||||
@@ -133,7 +136,8 @@ Select_Window (Display *dpy, int screen)
|
||||
}
|
||||
|
||||
static void
|
||||
xwininfo_clicked_cb (GtkButton *button __unused, gpointer user_data) {
|
||||
xwininfo_clicked_cb (GtkButton *button __unused, gpointer user_data)
|
||||
{
|
||||
XtmProcessWindow *window = (XtmProcessWindow *)user_data;
|
||||
Window selected_window;
|
||||
Display *dpy;
|
||||
@@ -148,39 +152,46 @@ 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);
|
||||
|
||||
status = XGetWindowProperty(dpy, selected_window, atom_NET_WM_PID, 0, (~0L),
|
||||
status = XGetWindowProperty (dpy, selected_window, atom_NET_WM_PID, 0, ~0L,
|
||||
False, AnyPropertyType, &actual_type,
|
||||
&actual_format, &_nitems, &bytes_after,
|
||||
&prop);
|
||||
if (status == BadWindow) {
|
||||
if (status == BadWindow)
|
||||
{
|
||||
XTM_SHOW_MESSAGE (GTK_MESSAGE_INFO,
|
||||
_("Bad Window"), _("Window id 0x%lx does not exist!"), selected_window);
|
||||
} if (status != Success) {
|
||||
}
|
||||
if (status != Success)
|
||||
{
|
||||
XTM_SHOW_MESSAGE (GTK_MESSAGE_ERROR,
|
||||
_("XGetWindowProperty failed"), _("XGetWindowProperty failed!"));
|
||||
} else {
|
||||
if (_nitems > 0) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_nitems > 0)
|
||||
{
|
||||
memcpy (&pid, prop, sizeof (pid));
|
||||
xtm_process_tree_view_highlight_pid (XTM_PROCESS_TREE_VIEW (window->treeview), pid);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
XTM_SHOW_MESSAGE (GTK_MESSAGE_INFO,
|
||||
_("No PID found"), _("No PID found for window 0x%lx."), selected_window);
|
||||
}
|
||||
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;
|
||||
@@ -190,9 +201,7 @@ filter_entry_keyrelease_handler(GtkEntry *entry,
|
||||
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);
|
||||
gtk_entry_set_icon_sensitive (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY, has_text);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -247,10 +256,9 @@ xtm_process_window_unstick_view_event (GtkWidget *widget, GdkEvent *event, XtmPr
|
||||
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;
|
||||
@@ -266,7 +274,8 @@ xtm_process_window_unstick_view_cursor (GtkTreeView *tree_view, XtmProcessWindow
|
||||
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;
|
||||
@@ -301,14 +310,12 @@ xtm_process_window_init (XtmProcessWindow *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);
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
#define XTM_IS_PROCESS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XTM_TYPE_PROCESS_WINDOW))
|
||||
#define XTM_IS_PROCESS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XTM_TYPE_PROCESS_WINDOW))
|
||||
#define XTM_PROCESS_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_PROCESS_WINDOW, XtmProcessWindowClass))
|
||||
#define XTM_SHOW_MESSAGE(type, title, message, ...) { \
|
||||
#define XTM_SHOW_MESSAGE(type, title, message, ...) \
|
||||
{ \
|
||||
GtkWidget *dialog = gtk_message_dialog_new (NULL, 0, type, GTK_BUTTONS_OK, title); \
|
||||
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), message, ##__VA_ARGS__); \
|
||||
gtk_window_set_title (GTK_WINDOW (dialog), _("Task Manager")); \
|
||||
|
||||
@@ -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,13 +69,10 @@ 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);
|
||||
|
||||
@@ -134,7 +131,8 @@ show_about_dialog (GtkWidget *widget, gpointer user_data)
|
||||
"OpenSolaris",
|
||||
" \342\200\242 Mike Massonnet",
|
||||
" \342\200\242 Peter Tribble",
|
||||
NULL };
|
||||
NULL
|
||||
};
|
||||
const gchar *license =
|
||||
"This program is free software; you can redistribute it and/or modify\n"
|
||||
"it under the terms of the GNU General Public License as published by\n"
|
||||
|
||||
@@ -129,7 +129,6 @@ xtm_settings_class_init (XtmSettingsClass *klass)
|
||||
static void
|
||||
xtm_settings_init (XtmSettings *settings)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -47,7 +47,8 @@ char *state_abbrev[] = {
|
||||
"", "start", "run", "sleep", "stop", "zomb", "dead", "onproc"
|
||||
};
|
||||
|
||||
gboolean get_task_list (GArray *task_list)
|
||||
gboolean
|
||||
get_task_list (GArray *task_list)
|
||||
{
|
||||
int mib[6];
|
||||
size_t size;
|
||||
@@ -115,12 +116,14 @@ gboolean get_task_list (GArray *task_list)
|
||||
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) {
|
||||
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);
|
||||
@@ -130,7 +133,8 @@ gboolean get_task_list (GArray *task_list)
|
||||
mib[3] = KERN_PROC_ARGV;
|
||||
if (sysctl (mib, 4, args, &size, NULL, 0) == 0)
|
||||
break;
|
||||
if (errno != ENOMEM) { /* ESRCH: process disappeared */
|
||||
if (errno != ENOMEM)
|
||||
{ /* ESRCH: process disappeared */
|
||||
/* printf ("process with pid %d disappeared, errno=%d\n", t.pid, errno); */
|
||||
args[0] = '\0';
|
||||
args[1] = NULL;
|
||||
@@ -190,7 +194,8 @@ pid_is_sleeping (GPid pid)
|
||||
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;
|
||||
@@ -266,14 +271,17 @@ get_memory_usage (guint64 *memory_total, guint64 *memory_available, guint64 *mem
|
||||
if ((swdev = calloc (nswap, sizeof (*swdev))) == NULL)
|
||||
errx (1, "failed to allocate memory for swdev structures");
|
||||
|
||||
if (swapctl(SWAP_STATS, swdev, nswap) == -1) {
|
||||
if (swapctl (SWAP_STATS, swdev, nswap) == -1)
|
||||
{
|
||||
free (swdev);
|
||||
errx (1, "failed to get swap stats");
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
@@ -156,23 +156,29 @@ get_task_details (struct kinfo_proc *kp, Task *task)
|
||||
oid[3] = kp->ki_pid;
|
||||
bufsz = sizeof (buf);
|
||||
memset (buf, 0, sizeof (buf));
|
||||
if (sysctl(oid, 4, buf, &bufsz, 0, 0) == -1) {
|
||||
if (sysctl (oid, 4, buf, &bufsz, 0, 0) == -1)
|
||||
{
|
||||
/*
|
||||
* If the supplied buf is too short to hold the requested
|
||||
* 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 {
|
||||
do
|
||||
{
|
||||
g_strlcat (task->cmdline, p, sizeof (task->cmdline));
|
||||
g_strlcat (task->cmdline, " ", sizeof (task->cmdline));
|
||||
p += (strlen (p) + 1);
|
||||
|
||||
@@ -22,13 +22,7 @@ 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)
|
||||
{
|
||||
@@ -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)
|
||||
@@ -287,8 +282,7 @@ get_task_details (GPid pid, Task *task)
|
||||
&idummy, // CPU number last executed on
|
||||
dummy,
|
||||
|
||||
dummy
|
||||
);
|
||||
dummy);
|
||||
|
||||
task->rss *= get_pagesize ();
|
||||
get_cpu_percent (task->pid, jiffies_user, &task->cpu_user, jiffies_system, &task->cpu_system);
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
/* Add includes for system functions needed */
|
||||
/* Example:
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
@@ -66,16 +66,10 @@ get_task_list (GArray *task_list)
|
||||
GPid pid = 0;
|
||||
Task task;
|
||||
|
||||
//while (/* read all PIDs */)
|
||||
{
|
||||
// if (/* pid is valid */)
|
||||
{
|
||||
if (get_task_details (pid, &task))
|
||||
{
|
||||
g_array_append_val (task_list, task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_array_sort (task_list, task_pid_compare_fn);
|
||||
|
||||
|
||||
@@ -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,17 +134,21 @@ 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)) {
|
||||
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) {
|
||||
if ((gunichar)-2 == c)
|
||||
{
|
||||
text_size = (gsize)(ch - text);
|
||||
(*ch) = 0;
|
||||
break;
|
||||
}
|
||||
if ((gunichar)-1 == c) {
|
||||
if ((gunichar)-1 == c)
|
||||
{
|
||||
(*ch) = ' ';
|
||||
continue;
|
||||
}
|
||||
@@ -155,7 +161,8 @@ pretty_cmdline (gchar *cmdline, gchar *comm)
|
||||
g_unichar_istitle (c) ||
|
||||
g_unichar_iswide (c) ||
|
||||
g_unichar_iszerowidth (c) ||
|
||||
g_unichar_iscntrl(c)) {
|
||||
g_unichar_iscntrl (c))
|
||||
{
|
||||
if (text_max < (ch + csize))
|
||||
break;
|
||||
memmove (ch, (ch + csize), (gsize)(text_max - (ch + csize)));
|
||||
@@ -346,7 +353,8 @@ 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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -652,7 +661,7 @@ set_priority_to_pid (GPid pid, gint priority)
|
||||
gint
|
||||
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 */
|
||||
|
||||
Reference in New Issue
Block a user