From 50866b5efe8c2b9e121469584584a41d6a7424df Mon Sep 17 00:00:00 2001 From: David Carter Date: Sat, 12 Nov 2005 03:41:55 +0000 Subject: [PATCH] fix stale static process pointer in top.c and add nodename to X window git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@402 7f574dfc-610e-0410-a909-a81674777703 --- src/common.c | 1 + src/conky.c | 8 ++++---- src/conky.h | 4 ++-- src/top.c | 11 ++++++----- src/x11.c | 17 ++++++++++++----- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/common.c b/src/common.c index a7d91144..745ec2bc 100644 --- a/src/common.c +++ b/src/common.c @@ -206,6 +206,7 @@ void update_stuff() update_mail_count(); + #if defined(__linux__) if (NEED(INFO_I8K)) update_i8k(); diff --git a/src/conky.c b/src/conky.c index ff26c602..8f309396 100644 --- a/src/conky.c +++ b/src/conky.c @@ -1073,13 +1073,13 @@ static void free_text_objects() break; case OBJ_top: if (info.first_process) { - free_all_processes(info.first_process); + free_all_processes(); info.first_process = NULL; } break; case OBJ_top_mem: if (info.first_process) { - free_all_processes(info.first_process); + free_all_processes(); info.first_process = NULL; } break; @@ -5178,13 +5178,13 @@ int main(int argc, char **argv) wm_class_name, text_width + border_margin * 2 + 1, text_height + border_margin * 2 + 1, - on_bottom, fixed_pos, set_transparent, background_colour); + on_bottom, fixed_pos, set_transparent, background_colour, info.uname_s.nodename); #else init_window (own_window, text_width + border_margin * 2 + 1, text_height + border_margin * 2 + 1, - on_bottom, set_transparent, background_colour); + on_bottom, set_transparent, background_colour, info.uname_s.nodename); #endif diff --git a/src/conky.h b/src/conky.h index b7f78d28..f1f5eb7d 100644 --- a/src/conky.h +++ b/src/conky.h @@ -269,9 +269,9 @@ extern struct conky_window window; void init_X11(); #if defined OWN_WINDOW -void init_window(int use_own_window, char* wm_class_name, int width, int height, int on_bottom, int fixed_pos, int set_trans, int back_colour); +void init_window(int use_own_window, char* wm_class_name, int width, int height, int on_bottom, int fixed_pos, int set_trans, int back_colour, char * nodename); #else -void init_window(int use_own_window, int width, int height, int on_bottom, int set_trans, int back_colour); +void init_window(int use_own_window, int width, int height, int on_bottom, int set_trans, int back_colour, char * nodename); #endif void create_gc(); void set_transparent_background(Window win); diff --git a/src/top.c b/src/top.c index dc201f73..26350ebd 100644 --- a/src/top.c +++ b/src/top.c @@ -20,9 +20,9 @@ struct process *get_first_process() -void free_all_processes(struct process *pr) +void free_all_processes() { - struct process *next = NULL; + struct process *next = NULL, *pr = first_process; while (pr) { next = pr->next; if (pr->name) { @@ -31,6 +31,7 @@ void free_all_processes(struct process *pr) free(pr); pr = next; } + first_process = NULL; } static struct process *find_process(pid_t pid) @@ -398,14 +399,14 @@ inline static void calc_cpu_each(unsigned long total) /* Find the top processes */ /******************************************/ -// static int tot_struct; //for debugging..uncomment this and the 2 printfs in the next two functs +//static int tot_struct; //for debugging..uncomment this and the 2 printfs in the next two functs /* * free a sp_process structure */ void free_sp(struct sorted_process * sp) { free(sp); - //printf("free: %d structs\n",--tot_struct ); +// printf("free: %d structs\n",--tot_struct ); } /* @@ -417,7 +418,7 @@ struct sorted_process * malloc_sp(struct process * proc) { sp->greater = NULL; sp->less = NULL; sp->proc = proc; - //printf("malloc: %d structs\n", ++tot_struct); +// printf("malloc: %d structs\n", ++tot_struct); return(sp); } diff --git a/src/x11.c b/src/x11.c index ebdeb7bc..6b1ab00c 100644 --- a/src/x11.c +++ b/src/x11.c @@ -17,6 +17,8 @@ #include #endif +#include + #ifdef XDBE int use_xdbe; #endif @@ -25,6 +27,8 @@ int use_xdbe; int use_xft = 0; #endif +#define WINDOW_NAME_FMT "%s - conky" + /* some basic X11 stuff */ Display *display; int display_width; @@ -171,9 +175,9 @@ inline void set_transparent_background(Window win) } #if defined OWN_WINDOW -void init_window(int own_window, char* wm_class_name, int w, int h, int l, int fixed_pos, int set_trans, int back_colour) +void init_window(int own_window, char* wm_class_name, int w, int h, int l, int fixed_pos, int set_trans, int back_colour, char * nodename) #else -void init_window(int own_window, int w, int h, int l, int set_trans, int back_colour) +void init_window(int own_window, int w, int h, int l, int set_trans, int back_colour, char * nodename) #endif { /* There seems to be some problems with setting transparent background (on @@ -181,6 +185,8 @@ void init_window(int own_window, int w, int h, int l, int set_trans, int back_co * happens but I bet the bug is somewhere here. */ set_transparent = set_trans; background_colour = back_colour; + char * window_name = NULL; + int num_chars = 0; #ifdef OWN_WINDOW if (own_window) { @@ -213,9 +219,10 @@ void init_window(int own_window, int w, int h, int l, int set_trans, int back_co &class_hints); /*set_transparent_background(window.window);*/ - - XStoreName(display, window.window, "conky"); - + window_name = (char *) malloc(strlen(WINDOW_NAME_FMT) + strlen(nodename)+1); + sprintf(window_name, WINDOW_NAME_FMT, nodename); + XStoreName(display, window.window, window_name); + free(window_name); XClearWindow(display, window.window); if (!fixed_pos)