Custom statusbar
The statusbar is created since a separate widget class and has three different labels (settable through properties) for CPU, memory and number of processes. This makes it more convenient to change one or another value and it gives a nicer look.
This commit is contained in:
@@ -18,6 +18,7 @@ xfce4_taskmanager_SOURCES = \
|
|||||||
main.c \
|
main.c \
|
||||||
process-window.c process-window.h \
|
process-window.c process-window.h \
|
||||||
process-tree-view.c process-tree-view.h \
|
process-tree-view.c process-tree-view.h \
|
||||||
|
process-statusbar.c process-statusbar.h \
|
||||||
settings.c settings.h \
|
settings.c settings.h \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
|
|||||||
145
src/process-statusbar.c
Normal file
145
src/process-statusbar.c
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2010 Mike Massonnet, <mmassonnet@xfce.org>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <glib-object.h>
|
||||||
|
#include <glib/gi18n.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
#include "process-statusbar.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PROP_CPU = 1,
|
||||||
|
PROP_MEMORY,
|
||||||
|
PROP_NUM_PROCESSES,
|
||||||
|
};
|
||||||
|
typedef struct _XtmProcessStatusbarClass XtmProcessStatusbarClass;
|
||||||
|
struct _XtmProcessStatusbarClass
|
||||||
|
{
|
||||||
|
GtkStatusbarClass parent_class;
|
||||||
|
};
|
||||||
|
struct _XtmProcessStatusbar
|
||||||
|
{
|
||||||
|
GtkStatusbar parent;
|
||||||
|
/*<private>*/
|
||||||
|
GtkWidget * label_num_processes;
|
||||||
|
GtkWidget * label_cpu;
|
||||||
|
GtkWidget * label_memory;
|
||||||
|
|
||||||
|
gushort cpu;
|
||||||
|
guint64 memory;
|
||||||
|
guint num_processes;
|
||||||
|
};
|
||||||
|
G_DEFINE_TYPE (XtmProcessStatusbar, xtm_process_statusbar, GTK_TYPE_STATUSBAR)
|
||||||
|
|
||||||
|
static void xtm_process_statusbar_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
xtm_process_statusbar_class_init (XtmProcessStatusbarClass *klass)
|
||||||
|
{
|
||||||
|
GObjectClass *class = G_OBJECT_CLASS (klass);
|
||||||
|
xtm_process_statusbar_parent_class = g_type_class_peek_parent (klass);
|
||||||
|
class->set_property = xtm_process_statusbar_set_property;
|
||||||
|
g_object_class_install_property (class, PROP_CPU,
|
||||||
|
g_param_spec_uint ("cpu", "CPU", "CPU usage", 0, 100, 0, G_PARAM_CONSTRUCT|G_PARAM_WRITABLE));
|
||||||
|
g_object_class_install_property (class, PROP_MEMORY,
|
||||||
|
g_param_spec_uint64 ("memory", "Memory", "Memory usage", 0, G_MAXUINT64, 0, G_PARAM_CONSTRUCT|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));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
xtm_process_statusbar_init (XtmProcessStatusbar *statusbar)
|
||||||
|
{
|
||||||
|
GtkWidget *area, *hbox;
|
||||||
|
|
||||||
|
#if GTK_CHECK_VERSION(2,20,0)
|
||||||
|
area = gtk_statusbar_get_message_area (GTK_STATUSBAR (statusbar));
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
GtkShadowType shadow_type;
|
||||||
|
GtkWidget *frame;
|
||||||
|
|
||||||
|
gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow-type", &shadow_type, NULL);
|
||||||
|
frame = gtk_frame_new (NULL);
|
||||||
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), shadow_type);
|
||||||
|
gtk_box_pack_start (GTK_BOX (statusbar), frame, TRUE, TRUE, 0);
|
||||||
|
|
||||||
|
area = gtk_hbox_new (FALSE, 0);
|
||||||
|
gtk_container_add (GTK_CONTAINER (frame), area);
|
||||||
|
gtk_widget_show_all (frame);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
hbox = gtk_hbox_new (FALSE, 24);
|
||||||
|
gtk_box_pack_start (GTK_BOX (area), hbox, TRUE, TRUE, 0);
|
||||||
|
|
||||||
|
statusbar->label_num_processes = gtk_label_new (NULL);
|
||||||
|
gtk_box_pack_start (GTK_BOX (hbox), statusbar->label_num_processes, FALSE, FALSE, 0);
|
||||||
|
|
||||||
|
statusbar->label_cpu = gtk_label_new (NULL);
|
||||||
|
gtk_box_pack_start (GTK_BOX (hbox), statusbar->label_cpu, FALSE, FALSE, 0);
|
||||||
|
|
||||||
|
statusbar->label_memory = gtk_label_new (NULL);
|
||||||
|
gtk_box_pack_start (GTK_BOX (hbox), statusbar->label_memory, FALSE, FALSE, 0);
|
||||||
|
|
||||||
|
gtk_widget_show_all (hbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
xtm_process_statusbar_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
XtmProcessStatusbar *statusbar = XTM_PROCESS_STATUSBAR (object);
|
||||||
|
gchar *text;
|
||||||
|
|
||||||
|
switch (property_id)
|
||||||
|
{
|
||||||
|
case PROP_CPU:
|
||||||
|
statusbar->cpu = g_value_get_uint (value);
|
||||||
|
text = g_strdup_printf (_("CPU: %d%%"), statusbar->cpu);
|
||||||
|
gtk_label_set_text (GTK_LABEL (statusbar->label_cpu), text);
|
||||||
|
g_free (text);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_MEMORY:
|
||||||
|
statusbar->memory = g_value_get_uint64 (value);
|
||||||
|
text = g_strdup_printf (_("Memory: %d%%"), statusbar->memory);
|
||||||
|
gtk_label_set_text (GTK_LABEL (statusbar->label_memory), text);
|
||||||
|
g_free (text);
|
||||||
|
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;
|
||||||
|
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
GtkWidget *
|
||||||
|
xtm_process_statusbar_new ()
|
||||||
|
{
|
||||||
|
return g_object_new (XTM_TYPE_PROCESS_STATUSBAR, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
32
src/process-statusbar.h
Normal file
32
src/process-statusbar.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2010 Mike Massonnet, <mmassonnet@xfce.org>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PROCESS_STATUSBAR_H
|
||||||
|
#define PROCESS_STATUSBAR_H
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <glib-object.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
#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 ();
|
||||||
|
|
||||||
|
#endif /* !PROCESS_STATUSBAR_H */
|
||||||
@@ -19,15 +19,10 @@
|
|||||||
#include "process-window.h"
|
#include "process-window.h"
|
||||||
#include "process-window_ui.h"
|
#include "process-window_ui.h"
|
||||||
#include "process-tree-view.h"
|
#include "process-tree-view.h"
|
||||||
|
#include "process-statusbar.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
PROP_CPU = 1,
|
|
||||||
PROP_MEMORY,
|
|
||||||
PROP_NUM_PROCESSES,
|
|
||||||
};
|
|
||||||
typedef struct _XtmProcessWindowClass XtmProcessWindowClass;
|
typedef struct _XtmProcessWindowClass XtmProcessWindowClass;
|
||||||
typedef struct _XtmProcessWindowPriv XtmProcessWindowPriv;
|
typedef struct _XtmProcessWindowPriv XtmProcessWindowPriv;
|
||||||
struct _XtmProcessWindowClass
|
struct _XtmProcessWindowClass
|
||||||
@@ -46,12 +41,6 @@ struct _XtmProcessWindowPriv
|
|||||||
GtkWidget * window;
|
GtkWidget * window;
|
||||||
GtkWidget * treeview;
|
GtkWidget * treeview;
|
||||||
GtkWidget * statusbar;
|
GtkWidget * statusbar;
|
||||||
guint statusbar_context_id;
|
|
||||||
|
|
||||||
gushort cpu;
|
|
||||||
guint64 memory;
|
|
||||||
guint num_processes;
|
|
||||||
|
|
||||||
XtmSettings * settings;
|
XtmSettings * settings;
|
||||||
};
|
};
|
||||||
#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), XTM_TYPE_PROCESS_WINDOW, XtmProcessWindowPriv))
|
#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), XTM_TYPE_PROCESS_WINDOW, XtmProcessWindowPriv))
|
||||||
@@ -67,7 +56,6 @@ static void emit_destroy_signal (XtmProcessWindow *window);
|
|||||||
static void show_menu_execute_task (XtmProcessWindow *window);
|
static void show_menu_execute_task (XtmProcessWindow *window);
|
||||||
static void show_menu_information (XtmProcessWindow *window);
|
static void show_menu_information (XtmProcessWindow *window);
|
||||||
static void show_about_dialog (XtmProcessWindow *window);
|
static void show_about_dialog (XtmProcessWindow *window);
|
||||||
static void update_status_bar (XtmProcessWindow *window);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -118,8 +106,9 @@ xtm_process_window_init (XtmProcessWindow *window)
|
|||||||
gtk_widget_show (window->priv->treeview);
|
gtk_widget_show (window->priv->treeview);
|
||||||
gtk_container_add (GTK_CONTAINER (gtk_builder_get_object (window->priv->builder, "scrolledwindow")), window->priv->treeview);
|
gtk_container_add (GTK_CONTAINER (gtk_builder_get_object (window->priv->builder, "scrolledwindow")), window->priv->treeview);
|
||||||
|
|
||||||
window->priv->statusbar = GTK_WIDGET (gtk_builder_get_object (window->priv->builder, "process-statusbar"));
|
window->priv->statusbar = xtm_process_statusbar_new ();
|
||||||
window->priv->statusbar_context_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (window->priv->statusbar), "System information");
|
gtk_widget_show (window->priv->statusbar);
|
||||||
|
gtk_box_pack_start (GTK_BOX (gtk_builder_get_object (window->priv->builder, "process-vbox")), window->priv->statusbar, FALSE, FALSE, 0);
|
||||||
|
|
||||||
button = GTK_WIDGET (gtk_builder_get_object (window->priv->builder, "toolbutton-execute"));
|
button = GTK_WIDGET (gtk_builder_get_object (window->priv->builder, "toolbutton-execute"));
|
||||||
g_signal_connect_swapped (button, "clicked", G_CALLBACK (show_menu_execute_task), window);
|
g_signal_connect_swapped (button, "clicked", G_CALLBACK (show_menu_execute_task), window);
|
||||||
@@ -169,18 +158,6 @@ xtm_process_window_get_property (GObject *object, guint property_id, GValue *val
|
|||||||
|
|
||||||
switch (property_id)
|
switch (property_id)
|
||||||
{
|
{
|
||||||
case PROP_CPU:
|
|
||||||
g_value_set_uint (value, priv->cpu);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PROP_MEMORY:
|
|
||||||
g_value_set_uint64 (value, priv->memory);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PROP_NUM_PROCESSES:
|
|
||||||
g_value_set_uint (value, priv->num_processes);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||||
break;
|
break;
|
||||||
@@ -197,18 +174,18 @@ xtm_process_window_set_property (GObject *object, guint property_id, const GValu
|
|||||||
case PROP_CPU:
|
case PROP_CPU:
|
||||||
priv->cpu = g_value_get_uint (value);
|
priv->cpu = g_value_get_uint (value);
|
||||||
// TODO update_cpu_monitor ();
|
// TODO update_cpu_monitor ();
|
||||||
update_status_bar (XTM_PROCESS_WINDOW (object));
|
g_object_set (priv->statusbar, "cpu", priv->cpu, NULL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_MEMORY:
|
case PROP_MEMORY:
|
||||||
priv->memory = g_value_get_uint64 (value);
|
priv->memory = g_value_get_uint64 (value);
|
||||||
// TODO update_memory_monitor ();
|
// TODO update_memory_monitor ();
|
||||||
update_status_bar (XTM_PROCESS_WINDOW (object));
|
g_object_set (priv->statusbar, "memory", priv->memory, NULL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_NUM_PROCESSES:
|
case PROP_NUM_PROCESSES:
|
||||||
priv->num_processes = g_value_get_uint (value);
|
priv->num_processes = g_value_get_uint (value);
|
||||||
update_status_bar (XTM_PROCESS_WINDOW (object));
|
g_object_set (priv->statusbar, "num_processes", priv->num_processes, NULL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -380,17 +357,6 @@ show_about_dialog (XtmProcessWindow *window)
|
|||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
update_status_bar (XtmProcessWindow *window)
|
|
||||||
{
|
|
||||||
gchar *text = NULL;
|
|
||||||
|
|
||||||
text = g_strdup_printf (_("Processes: %d \t CPU: %d%% \t Memory: %d%%"),
|
|
||||||
window->priv->num_processes, window->priv->cpu, window->priv->memory);
|
|
||||||
gtk_statusbar_pop (GTK_STATUSBAR (window->priv->statusbar), window->priv->statusbar_context_id);
|
|
||||||
gtk_statusbar_push (GTK_STATUSBAR (window->priv->statusbar), window->priv->statusbar_context_id, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -131,15 +131,7 @@
|
|||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkStatusbar" id="process-statusbar">
|
<placeholder/>
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="spacing">2</property>
|
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="expand">False</property>
|
|
||||||
<property name="pack_type">end</property>
|
|
||||||
<property name="position">2</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
|||||||
Reference in New Issue
Block a user