我是靠谱客的博主 勤恳雪碧,最近开发中收集的这篇文章主要介绍gtk linux任务管理器,【GTK】單文件實現任務管理器_Linux下GTK界面編程,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Linux下一般來說提到界面編程

JAVA自然是Eclipse

C++就大概是Qt了吧

那么C呢? 於是我去學了學UnixC和GTK,先放個可用代碼放着吧~

啊對了,配環境,沒錯配環境

sudo apt-get install vim #使用vim來編寫代碼,當然您可以使用任何自己喜歡的編輯器。

sudo apt-get install build-essential #這將安裝gcc/g++/gdb/make 等基本編程工具。

sudo apt-get install gnome-core-devel #這將安裝 libgtk2.0-dev libglib2.0-dev 等開發相關的庫文件。

sudo apt-get install pkg-config #用於在編譯GTK程序時自動找出頭文件及庫文件位置。

sudo apt-get install devhelp #這將安裝 devhelp GTK文檔查看程序。

sudo apt-get install libglib2.0-doc libgtk2.0-doc #這將安裝 gtk/glib 的API參考手冊及其它幫助文檔。

sudo apt-get install glade libglade2-dev #這將安裝基於GTK的界面構造程序。

有的獲取不到要去官網下載下來tar.gz自己解壓縮安裝哦~

解壓小貼士:

tar –xvf file.tar //解壓 tar包

tar -xzvf file.tar.gz //解壓tar.gz

tar -xjvf file.tar.bz2   //解壓 tar.bz2

tar –xZvf file.tar.Z   //解壓tar.Z

unrar e file.rar //解壓rar

unzip file.zip //解壓zip

東西都有了之后呢~

看看效果?

503f3c2d59b33b23c49e8bc9daa6b52c.png

d018ff6e3944ee22e60ee92d0be4b900.png

1791719fb5ee6feda02830b0a9555ccd.png

ca6f89dcca964275ec56c656074a25c1.png

效果看完了咱——

就來看看代碼研讀研讀吧~

// UnixC Based on GTK

// Compile Method: #gcc cdr –o cdos.c `pkg-config --cflags --libs gtk+-2.0

// Exec Method: ./cdr

// Author :okcd00 @ CSDN_2014

#include "cdhd.h"

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#define DENSITY 100 //No. Density of Graph

#define PMAX 100 //No. maxNum of Process

enum

{

NAME_COLUMN,

PID_COLUMN,

STATUS_COLUMN,

CPU_COLUMN,

MEMORY_COLUMN,

NP_COLUMNS

};

enum

{

MOD_COLUMN,

DEPEND_COLUMN,

NM_COLUMNS

};

//Declare of GtkWidget

GtkWidget *vbox;

GtkWidget *hbox;

GtkWidget *label;

GtkWidget *frame;

GtkWidget *window;

GtkWidget *menubar;

GtkWidget *notebook;

GtkWidget *main_vbox;

GtkWidget *mem_label;

GtkWidget *swap_label;

GtkWidget *info_label;

GtkWidget *status_bar;

GtkWidget *ptree_view;

GtkWidget *mtree_view;

GtkWidget *cpu_draw_area;

GtkWidget *mem_draw_area;

GtkWidget *scrolled_window;

GtkWidget *prefresh_button , *pdelete_button; //Refresh & Kill Button

// Global Varities

gint cpu_graph[DENSITY];//CPU Graphic Density

gint mem_graph[DENSITY];//RAM Graphic Density

gdouble rate = 0;//cpu Use_Rate

gdouble total = 0; //Curr. No.Process

gdouble fuser = 0;//Curr. CPUinfo

gdouble ftotal = 0;//Curr. CPUtotal

gdouble pfuser[PMAX]; //No. MaxProcess

GString *info;

GdkPixmap *cgraph = NULL;//pixmap_Pointer_CPU

GdkPixmap *mgraph = NULL;//pixmap_Pointer_RAM

//Others

GtkAccelGroup *accel_group;

GtkListStore *process_store;

GtkItemFactory *item_factory;

GtkCellRenderer *renderer;//Show each colTitle

GtkTreeViewColumn *column;//tree view's No.Column

//函數聲明

void about (GtkWidget *, gpointer);

void destroy_window (GtkWidget *, gpointer);

void sys_shutdown(GtkWidget *, gpointer);

void sys_reboot (GtkWidget *, gpointer);

void sys_halt (GtkWidget *, gpointer);

void about_author (GtkWidget *, gpointer);

gboolean handle_timeout (gpointer data);

gboolean load_graph_refresh (GtkWidget *widget);

gboolean get_cpu_rate (gpointer data);

void create_sys_status_page (void);

void create_process_page (void);

void create_sys_info_page (void);

void get_status_info (void);

void get_process_info (GtkListStore *);

void get_cpu_info (GString *);

void get_os_info (GString *);

void draw_cpu_load_graph (void);

void draw_mem_load_graph (void);

void prefresh_button_clicked (gpointer data);

void pdelete_button_clicked (gpointer data);

void mrefresh_button_clicked (gpointer data);

void mdelete_button_clicked (gpointer data);

gboolean cpu_configure_event (GtkWidget *, GdkEventConfigure *, gpointer);

gboolean cpu_expose_event (GtkWidget *, GdkEventExpose *, gpointer);

gboolean mem_configure_event (GtkWidget *, GdkEventConfigure *, gpointer);

gboolean mem_expose_event (GtkWidget *, GdkEventExpose *, gpointer);

gchar ABt[]="About us";

gchar ABc[]=" __<20125209>Chendian_&_<20125216>Xutianyuan_&_<20125212>Yangyeyu__ ";

void show_dialog (gchar *, gchar *);

static GtkItemFactoryEntry menu_items[] = {

{"/_File", NULL, NULL, 0, ""},

{"/File/Quit", "Q", destroy_window, 0, ""},

{"/_Option", NULL, NULL, 0, ""},

{"/Option/Shutdown", "U", sys_shutdown, 0 ,""},

{"/Option/Reboot", "R", sys_reboot, 0 ,""},

{"/Option/Halt", "H", sys_halt, 0 ,""},

{"/_About",NULL,NULL,0,""},

{"/About/AboutUs","B", about, 0, ""},

};

static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);//No.Menu

int main (int argc, char **argv)

{

gtk_set_locale ();//Set LocalEnvir Vars

gtk_init (&argc, &argv);

memset (cpu_graph, 50, sizeof (cpu_graph));//Alloc 50size

memset (mem_graph, 50, sizeof (mem_graph));//Alloc 50size

memset (pfuser, 0 ,sizeof (pfuser));

window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

gtk_window_set_title (GTK_WINDOW (window), "okcd00's Linux System Moniter");//Title

gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);//Default Window_Size

gtk_window_set_resizable (GTK_WINDOW (window), FALSE);//Lock the Window_Size

g_signal_connect(G_OBJECT(window), "destroy",

G_CALLBACK(destroy_window), NULL);

main_vbox =gtk_vbox_new (FALSE, 0);

gtk_widget_show (main_vbox);

gtk_container_add (GTK_CONTAINER (window), main_vbox);

accel_group = gtk_accel_group_new ();

item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR,"", accel_group);//Create Menu

gtk_item_factory_create_items (item_factory, nmenu_items,menu_items, NULL);

gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);

menubar = gtk_item_factory_get_widget (item_factory, "");

gtk_widget_show (menubar);

gtk_box_pack_start (GTK_BOX (main_vbox), menubar, FALSE, FALSE, 0);

notebook = gtk_notebook_new ();//New a notebook

gtk_widget_show (notebook);

gtk_box_pack_start (GTK_BOX (main_vbox), notebook, FALSE, FALSE, 0);

status_bar = gtk_statusbar_new ();//New a status_bar

gtk_widget_show (status_bar);

gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (status_bar),TRUE); //Can be Resized

gtk_box_pack_start (GTK_BOX (main_vbox), status_bar, TRUE, FALSE, 0);

gtk_timeout_add (2000, (GtkFunction)handle_timeout, NULL);

gtk_timeout_add (1000, (GtkFunction)load_graph_refresh, NULL); //graph refresh per second

gtk_timeout_add (1000, (GtkFunction)get_cpu_rate, NULL); //CPUrate refresh per second

create_process_page ();

create_sys_status_page ();

create_sys_info_page ();

gtk_widget_show_all (window);

gtk_main ();

return 0;

}

void about(GtkWidget *widget, gpointer data)

{

show_dialog(ABt,ABc);

}

void destroy_window (GtkWidget *widget, gpointer data)//QUIT

{

gtk_main_quit ();

}

void sys_shutdown (GtkWidget *widget, gpointer data)//Shotdown

{

system ("shutdown -r now");

}

void sys_reboot (GtkWidget *widget, gpointer data)//Restart the PC

{

system ("reboot");

}

void sys_halt (GtkWidget *widget, gpointer data)//Halt

{

system ("halt");

}

gboolean handle_timeout (gpointer data)//a series of operations by time

{

gint page_num;

page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));//Get Curr Page

switch (page_num) {

case 0:

gtk_list_store_clear (process_store);//Clear treeview

get_process_info (process_store);//Re-read Process_info

break;

default:

break;

}

return TRUE;

}

gboolean load_graph_refresh (GtkWidget *widget)

{

draw_cpu_load_graph ();

draw_mem_load_graph ();

return TRUE;

}

gboolean get_cpu_rate ( gpointer data)//Get CPU UseRate

{

int fd,i;

gchar buffer[256];

gchar *cpu_time[9];

gchar *tmp;

gchar *delim = " ";

gdouble cuser;

gdouble ctotal;

fd = open ("/proc/stat", O_RDONLY);//ReadFile

read (fd, buffer, sizeof (buffer));

close (fd);

tmp = strstr (buffer, "cpu0");//Buffer ended with "cpu0"

tmp--;

*tmp = '';

cpu_time[0] = strtok (buffer, delim);//split

for (i = 1; i < 9 ; i++) cpu_time[i] = strtok (NULL, delim);

cuser = atoi (cpu_time[1]);//Change str to long

ctotal = (cuser + atoi (cpu_time[2]) + atoi (cpu_time[3]) + atoi (cpu_time[4]));

total = ctotal - ftotal;

rate = (cuser - fuser) / total;

fuser = cuser;

ftotal = ctotal;

return TRUE;

}

void create_sys_status_page ()//create_sys_status_page

{

vbox = gtk_vbox_new (FALSE, 0);//Create colBox

gtk_widget_show (vbox);

gtk_container_add (GTK_CONTAINER (notebook), vbox);//Add it!

frame = gtk_frame_new ("CPU");//CreateFrame

gtk_widget_show (frame);

gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);//Add it!

cpu_draw_area = gtk_drawing_area_new ();//Add DrawPad

gtk_widget_show (cpu_draw_area);

gtk_drawing_area_size (GTK_DRAWING_AREA (cpu_draw_area), 400, 100);//Set DrawArea

gtk_container_add (GTK_CONTAINER (frame), cpu_draw_area);

g_signal_connect (cpu_draw_area, "expose_event",

G_CALLBACK (cpu_expose_event), NULL);

g_signal_connect (cpu_draw_area, "configure_event",

G_CALLBACK (cpu_configure_event), NULL);

frame = gtk_frame_new ("Memory");//CreateFrame

gtk_widget_show (frame);

gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 10);

mem_draw_area = gtk_drawing_area_new ();

gtk_widget_show (mem_draw_area);

gtk_drawing_area_size (GTK_DRAWING_AREA (mem_draw_area), 400, 100);//Set DrawArea

gtk_container_add (GTK_CONTAINER (frame), mem_draw_area);

g_signal_connect (mem_draw_area, "expose_event",

G_CALLBACK (mem_expose_event), NULL);

g_signal_connect (mem_draw_area, "configure_event",

G_CALLBACK (mem_configure_event), NULL);

mem_label = gtk_label_new ("");//RAM Label

gtk_widget_show (mem_label);

gtk_box_pack_start (GTK_BOX (vbox), mem_label, FALSE, FALSE, 0);

swap_label = gtk_label_new ("");//Exchange Label

gtk_widget_show (swap_label);

gtk_box_pack_start (GTK_BOX (vbox), swap_label, FALSE, FALSE, 10);

label = gtk_label_new ("Status");//Add Title

gtk_widget_show (label);

gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook),

gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), 1), label);

}

void create_process_page ()

{

int i;

gchar *col_name[5] = { "NAME", "PID" , "STATUS", "CPU" , "MEMORY"};

vbox = gtk_vbox_new (FALSE, 0);

gtk_widget_show (vbox);

gtk_container_add (GTK_CONTAINER (notebook), vbox);

scrolled_window = gtk_scrolled_window_new (NULL, NULL);

gtk_widget_set_size_request (scrolled_window, 300, 300);

gtk_widget_show (scrolled_window);

gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);

//Process info

process_store = gtk_list_store_new (NP_COLUMNS,

G_TYPE_STRING,

G_TYPE_STRING,

G_TYPE_STRING,

G_TYPE_STRING,

G_TYPE_STRING);

ptree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (process_store));

//Add tree_view Show ProcessTree

g_object_unref (G_OBJECT (process_store));

gtk_widget_show (ptree_view);

gtk_container_add (GTK_CONTAINER (scrolled_window), ptree_view);//Tree in scrolled_window

for (i = 0; i < 5; i++) {

renderer = gtk_cell_renderer_text_new ();//Add cell_renderer_text to Show Text

column = gtk_tree_view_column_new_with_attributes (col_name[i],

renderer,"text",i,NULL);

gtk_tree_view_append_column (GTK_TREE_VIEW (ptree_view), column);

}

get_process_info (process_store); //Getinfo and show

hbox = gtk_hbox_new (FALSE, 0);//add parreling box

gtk_widget_show (hbox);

gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 0);//Add to colBox

prefresh_button = gtk_button_new ();//Create Refresh Button

gtk_widget_show (prefresh_button);

gtk_widget_set_size_request (prefresh_button, 70, 30);//Set Button Size

gtk_button_set_label (GTK_BUTTON (prefresh_button), "refresh");//SetText

g_signal_connect (G_OBJECT (prefresh_button),"clicked",

G_CALLBACK(prefresh_button_clicked),

NULL);//Function

gtk_box_pack_start (GTK_BOX (hbox), prefresh_button, TRUE, FALSE, 0);//Add to hBox

pdelete_button = gtk_button_new ();//Create Kill Button

gtk_widget_show (pdelete_button);

gtk_widget_set_size_request (pdelete_button, 70, 30);

gtk_button_set_label (GTK_BUTTON (pdelete_button), "kill");

g_signal_connect (G_OBJECT (pdelete_button),"clicked",

G_CALLBACK(pdelete_button_clicked),

NULL);//Func:pdelete_button_clicked

gtk_box_pack_start (GTK_BOX (hbox), pdelete_button, TRUE, FALSE, 0);//Add to hBox

label = gtk_label_new ("Processes");

gtk_widget_show (label);

gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook),

gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), 0), label);

}

void create_sys_info_page (void)//Add Page

{

vbox = gtk_vbox_new (FALSE, 0);

gtk_widget_show (vbox);

gtk_container_add (GTK_CONTAINER(notebook), vbox);

frame = gtk_frame_new ("CPU Information:");

gtk_widget_show (frame);

gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 10);

info = g_string_new ("");

get_cpu_info (info);//info: Save CPUinfo

info_label = gtk_label_new (info->str);//info_label Show infoString

gtk_widget_show (info_label);

gtk_container_add (GTK_CONTAINER(frame), info_label);

frame = gtk_frame_new ("OS Information:");

gtk_widget_show (frame);

gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 30);

info = g_string_new ("");

get_os_info (info);//info: Save CPUinfo

info_label = gtk_label_new (info->str);//info_label Show infoString

gtk_widget_show (info_label);

gtk_container_add (GTK_CONTAINER(frame), info_label);

label = gtk_label_new ("SysInfo");

gtk_widget_show (label);

gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook),

gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook),2), label);

}

//IMPORTANT 2014.12.28

void get_process_info (GtkListStore *store)

{

DIR *dir;

int fd, i,num = 0;

GtkTreeIter iter;

struct dirent *entry;

gdouble mem;

gdouble srate;

gdouble pcuser[PMAX];

gchar *info[26];

gchar buffer[128];

gchar dir_buf[256];

gchar *delim = " ";

gchar mem_buffer[16];

gchar rate_buffer[16];

gchar state[2][10]={"running", "sleeping"};

dir = opendir ("/proc");// Open/proc, dir: pointer to Return

while ((entry = readdir (dir)) != NULL ) {

if ((entry->d_name[0] >= '0') && (entry->d_name[0] <= '9')) {

sprintf (dir_buf, "/proc/%s/stat", entry->d_name);//ReadFile

fd = open (dir_buf, O_RDONLY);

read (fd, buffer, sizeof (buffer));

close (fd);

info[0] = strtok (buffer, delim);//Delim split

for (i = 1; i < 26 ; i++) info[i] = strtok (NULL, delim);

info[1]++;

info[1] = strtok(info[1], ")");

switch(info[2][0])

{

case 'R': info[2] = state[0];break;

case 'S': info[2] = state[1];break;

}

pcuser[num] = atoi (info[13]);

srate = (pcuser[num]-pfuser[num]) / (2 * total);//Percent Calc

if(srate<0||srate>1){srate=0;}

sprintf (rate_buffer, "%.2f%%",100 * srate);

mem = atoi (info[22]);//Process' Using Percent

mem = mem / (1024 * 1024);

sprintf (mem_buffer, "%-.2f MB",mem);

gtk_list_store_append (store, &iter);

gtk_list_store_set (store, &iter,

NAME_COLUMN,info[1],

PID_COLUMN,info[0],

STATUS_COLUMN,info[2],

CPU_COLUMN,rate_buffer,

MEMORY_COLUMN,mem_buffer,

-1);

pfuser[num] = pcuser[num];

num = (num + 1 ) % PMAX;

}

}

closedir (dir);

}

void get_cpu_info(GString *string)

{

int i=0,j=0;

FILE *file=NULL;

gchar buffer[120];

gchar cpu_info[3][88];

gchar *tmp = NULL;

file = fopen("/proc/cpuinfo", "r");

while(!feof(file))

{

fgets(buffer, 120, file);

if(tmp = strstr(buffer, "model name"))

{

tmp+=13;

sprintf(cpu_info[i], "CPU %d:t%s", i++, tmp);

}

}

fclose(file);

while(j

return;

}

void get_os_info (GString *string)//Get OSinfo

{

int fd,i;

gchar buffer[128];

gchar *tmp,*start,*stop;

gchar *os_info[8];

gchar *delim = " ";

fd = open ("/proc/version", O_RDONLY);//Read OS infoFile

read(fd, buffer, sizeof (buffer));

start = buffer;

stop = strstr (buffer, "#");

stop--;

stop--;

os_info[0] = strtok (buffer, delim);

for (i = 1; i < 8; i++) {

os_info[i] = strtok (NULL, delim);

}

g_string_append (string, "Ostttt:");

g_string_append (string, os_info[0]);

g_string_append_c (string, 'n');

g_string_append (string, "Releasett:");

g_string_append (string, os_info[2]);

g_string_append_c (string, 'n');

g_string_append (string, "Domaintt:");

g_string_append (string, os_info[3]);

g_string_append_c (string, 'n');

g_string_append (string, "Gcc versiont:");

g_string_append (string, os_info[6]);

g_string_append_c (string, ' ');

g_string_append (string, os_info[7]);

g_string_append_c (string, 'n');

}

void draw_cpu_load_graph ()

{

if (cgraph == NULL)

return;

int i;

gchar buffer[64];

gint width,height,current,step;

guint context_id;

sprintf (buffer, "CPU using rate:%.2f%%",100 * rate);

context_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (status_bar),"cpu");

gtk_statusbar_push (GTK_STATUSBAR (status_bar), context_id, buffer);

//Clear PastGraph

gdk_draw_rectangle (GDK_DRAWABLE (cgraph), window->style->white_gc, TRUE, 0, 0,

cpu_draw_area->allocation.width,

cpu_draw_area->allocation.height);

width = cpu_draw_area->allocation.width;//Get Size

height = cpu_draw_area->allocation.height;

current = (int)(rate*(double)height);//Adjust Height

cpu_graph[DENSITY-1] = height - current; //Move Direction

for ( i = 0 ; i < DENSITY - 1 ; i ++) {

cpu_graph[i] = cpu_graph[i+1];

}

step = width/DENSITY;//stepsets

GdkGC *gc = gdk_gc_new(GDK_DRAWABLE(cgraph));

GdkColor color;

gdk_color_parse("#FFFF00", &color);

gdk_gc_set_foreground(gc, &color);

for (i = DENSITY - 1; i >= 1 ; i -- ) {

gdk_draw_line (cgraph, gc, i * step, cpu_graph[i],

(i - 1) * step, cpu_graph[i-1] );

}

gtk_widget_queue_draw (cpu_draw_area);//ReDraw

}

void draw_mem_load_graph ()

{

if (mgraph == NULL) return;

int fd,i;

gint width,height,current,step;

gint mem_total,mem_free;

gchar buffer[540];

gchar mem_tmp[19][20];

gchar *start,*stop,*tmp;

GString *string;

fd = open ("/proc/meminfo", O_RDONLY);

read (fd, buffer, sizeof (buffer));

stop = buffer;

close(fd);

for (i = 0; i < 19; i++)

{

start = strstr (stop, ":");

start++;

stop = strstr (start, "kB");

stop--;

tmp = mem_tmp[i];

while (start != stop) *tmp++ = *start++;

*tmp = '';

}

mem_total = atoi (mem_tmp[0]);

mem_free = atoi (mem_tmp[1]);

string = g_string_new ("");//Refresh info_Num

g_string_append (string, "Total Memory :");

g_string_append (string, mem_tmp[0]);

g_string_append (string, " kB");

g_string_append (string, " ");

g_string_append (string, "Free Memory :");

g_string_append (string, mem_tmp[1]);

g_string_append (string, " kB");

g_string_append_c (string, 'n');

gtk_label_set_text (GTK_LABEL (mem_label), string->str);

g_string_free (string, TRUE);

string = g_string_new ("");

g_string_append (string, "Total Swap :");

g_string_append (string, mem_tmp[11]);

g_string_append (string, " kB");

g_string_append (string, " ");

g_string_append (string, "Free Swap :");

g_string_append (string, mem_tmp[12]);

g_string_append (string, " kB");

g_string_append_c (string, 'n');

gtk_label_set_text (GTK_LABEL (swap_label), string->str);

g_string_free (string, TRUE);

//ClearGraph

gdk_draw_rectangle (mgraph, window->style->white_gc, TRUE, 0, 0,

mem_draw_area->allocation.width,

mem_draw_area->allocation.height);

width = mem_draw_area->allocation.width;//GetSize

height = mem_draw_area->allocation.height;

current = ((float)(mem_total-mem_free)/(float)mem_total) * height;//Adjust Size

mem_graph[DENSITY-1] = height - current; //Move Dir

for ( i = 0 ; i < DENSITY - 1 ; i ++) {

mem_graph[i] = mem_graph[i+1];

}

step = width / DENSITY;

GdkGC *gc = gdk_gc_new(GDK_DRAWABLE(mgraph));

GdkColor color;

gdk_color_parse("#0000EE", &color);

gdk_gc_set_foreground(gc, &color);

for (i = DENSITY - 1; i >= 1 ; i -- ) {

gdk_draw_line (mgraph, gc, i * step,

mem_graph[i], (i - 1) * step, mem_graph[i-1]);

}

gtk_widget_queue_draw ( mem_draw_area);

}

void prefresh_button_clicked (gpointer data)

{

gtk_list_store_clear (process_store);

get_process_info (process_store);

}

void pdelete_button_clicked (gpointer data)

{

GtkTreeSelection *selection;

GtkTreeModel *model;

GtkTreeIter iter;

gchar *pid;

pid_t pid_num;

selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ptree_view));//Get Selection

if (gtk_tree_selection_get_selected(selection, &model, &iter)) {

gtk_tree_model_get (model, &iter, PID_COLUMN, &pid, -1);//Get PID

pid_num = atoi (pid);

if(kill (pid_num, SIGTERM) == -1 ) {

gchar *title = "ERROR";

gchar *content = "Termination Failed,Check UID";

show_dialog (title, content);

}

gtk_list_store_clear (process_store);

get_process_info (process_store);

}

}

gboolean cpu_configure_event (GtkWidget *widget, GdkEventConfigure *event, gpointer data)

{

if (cgraph) {

g_object_unref (cgraph);

}

//Pixmap Create

cgraph = gdk_pixmap_new (widget->window,

widget->allocation.width, widget->allocation.height,-1);

//RePaint in Pixmap

gdk_draw_rectangle (cgraph, widget->style->white_gc, TRUE, 0, 0,

widget->allocation.width, widget->allocation.height);

return TRUE;

}

gboolean cpu_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer data)

{

gdk_draw_drawable (widget->window,

widget->style->fg_gc[GTK_WIDGET_STATE (widget)],

cgraph,

event->area.x, event->area.y,

event->area.x, event->area.y,

event->area.width, event->area.height);

return TRUE;

}

//Graph Refreshing

gboolean mem_configure_event (GtkWidget *widget, GdkEventConfigure *event, gpointer data)

{

if (mgraph) {

g_object_unref (mgraph);

}

mgraph = gdk_pixmap_new (widget->window,

widget->allocation.width, widget->allocation.height,-1);

gdk_draw_rectangle (mgraph, widget->style->white_gc, TRUE, 0, 0,

widget->allocation.width, widget->allocation.height);

return TRUE;

}

gboolean mem_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer data)

{

gdk_draw_drawable (widget->window,

widget->style->fg_gc[GTK_WIDGET_STATE (widget)],

mgraph,

event->area.x, event->area.y,

event->area.x, event->area.y,

event->area.width, event->area.height);

return TRUE;

}

void show_dialog (gchar *title, gchar *content)

{

GtkWidget *dialog;

GtkWidget *label;

dialog = gtk_dialog_new_with_buttons (title,

GTK_WINDOW (window),

GTK_DIALOG_DESTROY_WITH_PARENT,

GTK_STOCK_CLOSE,

GTK_RESPONSE_NONE,

NULL);

gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);

g_signal_connect_swapped (dialog,

"response",

G_CALLBACK (gtk_widget_destroy),

dialog);

label = gtk_label_new (content);

gtk_widget_show (label);

gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),

label);

gtk_widget_show (dialog);

}

最后

以上就是勤恳雪碧为你收集整理的gtk linux任务管理器,【GTK】單文件實現任務管理器_Linux下GTK界面編程的全部内容,希望文章能够帮你解决gtk linux任务管理器,【GTK】單文件實現任務管理器_Linux下GTK界面編程所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(38)

评论列表共有 0 条评论

立即
投稿
返回
顶部