wmSMPmon: Code formating cleanup

This commit is contained in:
Milan Čermák 2013-01-19 10:17:30 +01:00 committed by Carlos R. Mafra
parent cb8524e80a
commit d914561f0c
5 changed files with 601 additions and 615 deletions

View file

@ -13,66 +13,67 @@
# # # #
######################################################################*/ ######################################################################*/
# include "standards.h" #include "standards.h"
# include "general.h" #include "general.h"
/* /*
* The usual program end -- * The usual program end --
* called only by functions in this section. */ * called only by functions in this section. */
void bye_bye (int eno, const char *str) void bye_bye(int eno, const char *str)
{ {
fflush(stdout); fflush(stdout);
if (str) { if (str) {
if (eno) perror(str); if (eno)
else { perror(str);
fputs(str, stderr); else {
eno = 1; fputs(str, stderr);
} eno = 1;
} }
exit(eno); }
exit(eno);
} }
/* /*
* This routine simply formats whatever the caller wants and * This routine simply formats whatever the caller wants and
* returns a pointer to the resulting 'const char' string... */ * returns a pointer to the resulting 'const char' string... */
const char *fmtmk (const char *fmts, ...) const char *fmtmk(const char *fmts, ...)
{ {
static char buf[BIGBUFSIZ]; /* with help stuff, our buffer */ static char buf[BIGBUFSIZ]; /* with help stuff, our buffer */
va_list va; /* requirements exceed 1k */ va_list va; /* requirements exceed 1k */
va_start(va, fmts); va_start(va, fmts);
vsnprintf(buf, sizeof(buf), fmts, va); vsnprintf(buf, sizeof(buf), fmts, va);
va_end(va); va_end(va);
return (const char *)buf; return ((const char *)buf);
} }
/*
/* * Standard error handler to normalize the look of all err o/p */
* Standard error handler to normalize the look of all err o/p */ void std_err(const char *str)
void std_err (const char *str)
{ {
static char buf[SMLBUFSIZ]; static char buf[SMLBUFSIZ];
fflush(stdout); fflush(stdout);
/* we'll use our own buffer so callers can still use fmtmk() /* we'll use our own buffer so callers can still use fmtmk()
* and, yes the leading tab is not the standard convention, * and, yes the leading tab is not the standard convention,
* but the standard is wrong -- OUR msg won't get lost in * but the standard is wrong -- OUR msg won't get lost in
* screen clutter, like so many others! */ * screen clutter, like so many others! */
snprintf(buf, sizeof(buf), "\t%s: %s\n", Myname, str); snprintf(buf, sizeof(buf), "\t%s: %s\n", Myname, str);
/* not to worry, he'll change our exit code to 1 due to 'buf' */ /* not to worry, he'll change our exit code to 1 due to 'buf' */
bye_bye(0, buf); bye_bye(0, buf);
} }
/* /*
* Handle our own memory stuff without the risk of leaving the * Handle our own memory stuff without the risk of leaving the
* user's terminal in an ugly state should things go sour. */ * user's terminal in an ugly state should things go sour. */
void *alloc_c (unsigned numb) void *alloc_c(unsigned numb)
{ {
void * p; void * p;
if (!numb) ++numb; if (!numb)
if (!(p = calloc(1, numb))) ++numb;
std_err("failed memory allocate"); if (!(p = calloc(1, numb)))
return p; std_err("failed memory allocate");
return (p);
} }

View file

@ -31,8 +31,8 @@ static int meminfo_fd = -1;
static char buf[1024]; static char buf[1024];
/* assume no IO-wait stats (default kernel 2.4.x), /* assume no IO-wait stats (default kernel 2.4.x),
overridden if linux 2.5.x or 2.6.x */ overridden if linux 2.5.x or 2.6.x */
static const char *States_fmts = STATES_line2x4; static const char *States_fmts = STATES_line2x4;
@ -40,21 +40,21 @@ static const char *States_fmts = STATES_line2x4;
* that successive calls to the functions are more efficient. * that successive calls to the functions are more efficient.
* It also reads the current contents of the file into the global buf. * It also reads the current contents of the file into the global buf.
*/ */
#define FILE_TO_BUF(filename, fd) do{ \ #define FILE_TO_BUF(filename, fd) do { \
static int local_n; \ static int local_n; \
if (fd == -1 && (fd = open(filename, O_RDONLY)) == -1) { \ if (fd == -1 && (fd = open(filename, O_RDONLY)) == -1) {\
fprintf(stderr, BAD_OPEN_MESSAGE); \ fprintf(stderr, BAD_OPEN_MESSAGE); \
fflush(NULL); \ fflush(NULL); \
_exit(102); \ _exit(102); \
} \ } \
lseek(fd, 0L, SEEK_SET); \ lseek(fd, 0L, SEEK_SET); \
if ((local_n = read(fd, buf, sizeof buf - 1)) < 0) { \ if ((local_n = read(fd, buf, sizeof buf - 1)) < 0) {\
perror(filename); \ perror(filename); \
fflush(NULL); \ fflush(NULL); \
_exit(103); \ _exit(103); \
} \ } \
buf[local_n] = '\0'; \ buf[local_n] = '\0'; \
}while(0) } while(0)
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z) #define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
@ -66,41 +66,40 @@ static const char *States_fmts = STATES_line2x4;
/***********************************************/ /***********************************************/
unsigned int NumCpus_DoInit(void) unsigned int NumCpus_DoInit(void)
{ {
long smp_num_cpus; long smp_num_cpus;
int linux_version_code; int linux_version_code;
static struct utsname uts; static struct utsname uts;
int x = 0, y = 0, z = 0; /* cleared in case sscanf() < 3 */ int x = 0, y = 0, z = 0; /* cleared in case sscanf() < 3 */
if (uname(&uts) == -1) /* failure implies impending death */ if (uname(&uts) == -1) /* failure implies impending death */
exit(1); exit(1);
if (sscanf(uts.release, "%d.%d.%d", &x, &y, &z) < 3) if (sscanf(uts.release, "%d.%d.%d", &x, &y, &z) < 3)
fprintf(stderr, /* *very* unlikely to happen by accident */ fprintf(stderr, /* *very* unlikely to happen by accident */
"Non-standard uts for running kernel:\n" "Non-standard uts for running kernel:\n"
"release %s=%d.%d.%d gives version code %d\n", "release %s=%d.%d.%d gives version code %d\n",
uts.release, x, y, z, LINUX_VERSION(x,y,z)); uts.release, x, y, z, LINUX_VERSION(x,y,z));
linux_version_code = LINUX_VERSION(x, y, z); linux_version_code = LINUX_VERSION(x, y, z);
if (linux_version_code > LINUX_VERSION(2, 5, 41)) if (linux_version_code > LINUX_VERSION(2, 5, 41))
States_fmts = STATES_line2x5; States_fmts = STATES_line2x5;
if (linux_version_code >= LINUX_VERSION(2, 6, 0)) // grrr... only if (linux_version_code >= LINUX_VERSION(2, 6, 0)) {
// some 2.6.0-testX :-( // grrr... only some 2.6.0-testX :-(
States_fmts = STATES_line2x6; States_fmts = STATES_line2x6;
}
smp_num_cpus = sysconf(_SC_NPROCESSORS_CONF); // or _SC_NPROCESSORS_ONLN smp_num_cpus = sysconf(_SC_NPROCESSORS_CONF); // or _SC_NPROCESSORS_ONLN
if (smp_num_cpus < 1) if (smp_num_cpus < 1) {
{ smp_num_cpus = 1; /* SPARC glibc is buggy */
smp_num_cpus = 1; /* SPARC glibc is buggy */ }
}
if (smp_num_cpus > 255) if (smp_num_cpus > 255) {
{ /* we don't support more than 255 CPUs (well, in fact no more
/* we don't support more than 255 CPUs (well, in fact no more than two ate the moment... */
than two ate the moment... */ smp_num_cpus = 255;
smp_num_cpus = 255; }
}
return (int)smp_num_cpus; return (int)smp_num_cpus;
} }
/***********************************************************************/ /***********************************************************************/
@ -115,12 +114,14 @@ unsigned int NumCpus_DoInit(void)
* GNU Library General Public License for more details. * GNU Library General Public License for more details.
*/ */
typedef struct mem_table_struct { typedef struct mem_table_struct {
const char *name; /* memory type name */ const char *name; /* memory type name */
unsigned long *slot; /* slot in return struct */ unsigned long *slot; /* slot in return struct */
} mem_table_struct; } mem_table_struct;
static int compare_mem_table_structs(const void *a, const void *b){ static int compare_mem_table_structs(const void *a, const void *b)
return strcmp(((const mem_table_struct*)a)->name,((const mem_table_struct*)b)->name); {
return strcmp(((const mem_table_struct *) a)->name,
((const mem_table_struct *) b)->name);
} }
/* example data, following junk, with comments added: /* example data, following junk, with comments added:
@ -189,81 +190,84 @@ unsigned long kb_inactive;
unsigned long kb_mapped; unsigned long kb_mapped;
unsigned long kb_pagetables; unsigned long kb_pagetables;
static void meminfo(void){ static void meminfo(void)
char namebuf[16]; /* big enough to hold any row name */ {
mem_table_struct findme = { namebuf, NULL}; char namebuf[16]; /* big enough to hold any row name */
mem_table_struct *found; mem_table_struct findme = { namebuf, NULL};
char *head; mem_table_struct *found;
char *tail; char *head;
static const mem_table_struct mem_table[] = { char *tail;
{"Active", &kb_active}, // important static const mem_table_struct mem_table[] = {
{"Buffers", &kb_main_buffers}, // important {"Active", &kb_active}, // important
{"Cached", &kb_main_cached}, // important {"Buffers", &kb_main_buffers}, // important
{"Committed_AS", &kb_committed_as}, {"Cached", &kb_main_cached}, // important
{"Dirty", &kb_dirty}, // kB version of vmstat nr_dirty {"Committed_AS", &kb_committed_as},
{"HighFree", &kb_high_free}, {"Dirty", &kb_dirty}, // kB version of vmstat nr_dirty
{"HighTotal", &kb_high_total}, {"HighFree", &kb_high_free},
{"Inact_clean", &kb_inact_clean}, {"HighTotal", &kb_high_total},
{"Inact_dirty", &kb_inact_dirty}, {"Inact_clean", &kb_inact_clean},
{"Inact_laundry",&kb_inact_laundry}, {"Inact_dirty", &kb_inact_dirty},
{"Inact_target", &kb_inact_target}, {"Inact_laundry",&kb_inact_laundry},
{"Inactive", &kb_inactive}, // important {"Inact_target", &kb_inact_target},
{"LowFree", &kb_low_free}, {"Inactive", &kb_inactive}, // important
{"LowTotal", &kb_low_total}, {"LowFree", &kb_low_free},
{"Mapped", &kb_mapped}, // kB version of vmstat nr_mapped {"LowTotal", &kb_low_total},
{"MemFree", &kb_main_free}, // important {"Mapped", &kb_mapped}, // kB version of vmstat nr_mapped
{"MemShared", &kb_main_shared}, // important {"MemFree", &kb_main_free}, // important
{"MemTotal", &kb_main_total}, // important {"MemShared", &kb_main_shared}, // important
{"PageTables", &kb_pagetables}, // kB version of vmstat {"MemTotal", &kb_main_total}, // important
// nr_page_table_pages {"PageTables", &kb_pagetables}, // kB version of vmstat
{"ReverseMaps", &nr_reversemaps}, // same as vmstat // nr_page_table_pages
// nr_page_table_pages {"ReverseMaps", &nr_reversemaps}, // same as vmstat
{"Slab", &kb_slab}, // kB version of vmstat nr_slab // nr_page_table_pages
{"SwapCached", &kb_swap_cached}, {"Slab", &kb_slab}, // kB version of vmstat nr_slab
{"SwapFree", &kb_swap_free}, // important {"SwapCached", &kb_swap_cached},
{"SwapTotal", &kb_swap_total}, // important {"SwapFree", &kb_swap_free}, // important
{"Writeback", &kb_writeback}, // kB version of vmstat {"SwapTotal", &kb_swap_total}, // important
// nr_writeback {"Writeback", &kb_writeback}, // kB version of vmstat
}; // nr_writeback
const int mem_table_count = sizeof(mem_table)/sizeof(mem_table_struct); };
const int mem_table_count =
sizeof(mem_table) / sizeof(mem_table_struct);
FILE_TO_BUF(MEMINFO_FILE,meminfo_fd); FILE_TO_BUF(MEMINFO_FILE,meminfo_fd);
kb_inactive = ~0UL; kb_inactive = ~0UL;
head = buf; head = buf;
for(;;){ for(;;) {
tail = strchr(head, ':'); tail = strchr(head, ':');
if(!tail) break; if (!tail)
*tail = '\0'; break;
if(strlen(head) >= sizeof(namebuf)){ *tail = '\0';
head = tail+1; if (strlen(head) >= sizeof(namebuf)) {
goto nextline; head = tail + 1;
} goto nextline;
strcpy(namebuf,head); }
found = bsearch(&findme, mem_table, mem_table_count, strcpy(namebuf, head);
sizeof(mem_table_struct), compare_mem_table_structs found = bsearch(&findme, mem_table, mem_table_count,
); sizeof(mem_table_struct), compare_mem_table_structs);
head = tail+1; head = tail + 1;
if(!found) goto nextline; if (!found)
*(found->slot) = strtoul(head,&tail,10); goto nextline;
nextline: *(found->slot) = strtoul(head, &tail, 10);
tail = strchr(head, '\n'); nextline:
if(!tail) break; tail = strchr(head, '\n');
head = tail+1; if (!tail)
} break;
if(!kb_low_total){ /* low==main except with large-memory support */ head = tail + 1;
kb_low_total = kb_main_total; }
kb_low_free = kb_main_free; if (!kb_low_total) { /* low==main except with large-memory support */
} kb_low_total = kb_main_total;
if(kb_inactive==~0UL){ kb_low_free = kb_main_free;
kb_inactive = kb_inact_dirty + kb_inact_clean + kb_inact_laundry; }
} if (kb_inactive == ~0UL) {
kb_swap_used = kb_swap_total - kb_swap_free; kb_inactive = kb_inact_dirty + kb_inact_clean + kb_inact_laundry;
kb_main_used = kb_main_total - kb_main_free; }
kb_swap_used = kb_swap_total - kb_swap_free;
kb_main_used = kb_main_total - kb_main_free;
} }
/*************************************************************************/ /*************************************************************************/
/* /*
* This guy's modeled on libproc's 'five_cpu_numbers' function except * This guy's modeled on libproc's 'five_cpu_numbers' function except
@ -273,93 +277,98 @@ static void meminfo(void){
* cpus[Cpu_tot] == tics from the 1st /proc/stat line */ * cpus[Cpu_tot] == tics from the 1st /proc/stat line */
static CPU_t *cpus_refresh (CPU_t *cpus, unsigned int Cpu_tot) static CPU_t *cpus_refresh (CPU_t *cpus, unsigned int Cpu_tot)
{ {
static FILE *fp = NULL; static FILE *fp = NULL;
int i; int i;
// enough for a /proc/stat CPU line (not the intr line)
char buf[SMLBUFSIZ];
/* by opening this file once, we'll avoid the hit on minor page faults // enough for a /proc/stat CPU line (not the intr line)
(sorry Linux, but you'll have to close it for us) */ char buf[SMLBUFSIZ];
if (!fp) {
if (!(fp = fopen("/proc/stat", "r")))
std_err(fmtmk("Failed /proc/stat open: %s", strerror(errno)));
/* note: we allocate one more CPU_t than Cpu_tot so that the
last slot can hold tics representing the /proc/stat cpu
summary (the first line read) -- that slot supports our
View_CPUSUM toggle */
cpus = alloc_c((1 + Cpu_tot) * sizeof(CPU_t));
}
rewind(fp);
fflush(fp);
// first value the last slot with the cpu summary line /* by opening this file once, we'll avoid the hit on minor page faults
if (!fgets(buf, sizeof(buf), fp)) std_err("failed /proc/stat read"); (sorry Linux, but you'll have to close it for us) */
if (!fp) {
if (!(fp = fopen("/proc/stat", "r")))
std_err(fmtmk("Failed /proc/stat open: %s",
strerror(errno)));
/* note: we allocate one more CPU_t than Cpu_tot so that the
last slot can hold tics representing the /proc/stat cpu
summary (the first line read) -- that slot supports our
View_CPUSUM toggle */
cpus = alloc_c((1 + Cpu_tot) * sizeof(CPU_t));
}
rewind(fp);
fflush(fp);
cpus[Cpu_tot].x = 0; // FIXME: can't tell by kernel version number // first value the last slot with the cpu summary line
cpus[Cpu_tot].y = 0; // FIXME: can't tell by kernel version number if (!fgets(buf, sizeof(buf), fp))
if (4 > sscanf(buf, CPU_FMTS_JUST1, &cpus[Cpu_tot].u, &cpus[Cpu_tot].n, &cpus[Cpu_tot].s, &cpus[Cpu_tot].i, &cpus[Cpu_tot].w, &cpus[Cpu_tot].x, &cpus[Cpu_tot].y)) std_err("failed /proc/stat read");
std_err("failed /proc/stat read");
// and just in case we're 2.2.xx compiled without SMP support...
if (1 == Cpu_tot)
{
/* do it "manually", otherwise we overwrite charge and total */
cpus[0].u = cpus[1].u;
cpus[0].n = cpus[1].n;
cpus[0].s = cpus[1].s;
cpus[0].i = cpus[1].i;
cpus[0].w = cpus[1].w;
cpus[0].x = cpus[1].x;
cpus[0].y = cpus[1].y;
}
cpus[Cpu_tot].x = 0; // FIXME: can't tell by kernel version number
cpus[Cpu_tot].y = 0; // FIXME: can't tell by kernel version number
if (4 > sscanf(buf, CPU_FMTS_JUST1, &cpus[Cpu_tot].u, &cpus[Cpu_tot].n,
&cpus[Cpu_tot].s, &cpus[Cpu_tot].i, &cpus[Cpu_tot].w,
&cpus[Cpu_tot].x, &cpus[Cpu_tot].y))
std_err("failed /proc/stat read");
// and just in case we're 2.2.xx compiled without SMP support...
if (1 == Cpu_tot) {
/* do it "manually", otherwise we overwrite charge and total */
cpus[0].u = cpus[1].u;
cpus[0].n = cpus[1].n;
cpus[0].s = cpus[1].s;
cpus[0].i = cpus[1].i;
cpus[0].w = cpus[1].w;
cpus[0].x = cpus[1].x;
cpus[0].y = cpus[1].y;
}
// now value each separate cpu's tics // now value each separate cpu's tics
for (i = 0; 1 < Cpu_tot && i < Cpu_tot; i++) { for (i = 0; 1 < Cpu_tot && i < Cpu_tot; i++) {
if (!fgets(buf, sizeof(buf), fp))
if (!fgets(buf, sizeof(buf), fp)) std_err("failed /proc/stat read"); std_err("failed /proc/stat read");
cpus[i].x = 0; // FIXME: can't tell by kernel version number cpus[i].x = 0; // FIXME: can't tell by kernel version number
cpus[i].y = 0; // FIXME: can't tell by kernel version number cpus[i].y = 0; // FIXME: can't tell by kernel version number
if (4 > sscanf(buf, CPU_FMTS_MULTI, &cpus[i].u, &cpus[i].n, &cpus[i].s, &cpus[i].i, &cpus[i].w, &cpus[i].x, &cpus[i].y)) if (4 > sscanf(buf, CPU_FMTS_MULTI, &cpus[i].u,
std_err("failed /proc/stat read"); &cpus[i].n, &cpus[i].s, &cpus[i].i, &cpus[i].w,
} &cpus[i].x, &cpus[i].y))
return cpus; std_err("failed /proc/stat read");
}
return cpus;
} }
unsigned int *Get_CPU_Load(unsigned int *load, unsigned int Cpu_tot) unsigned int *Get_CPU_Load(unsigned int *load, unsigned int Cpu_tot)
{ {
static CPU_t *smpcpu = NULL; static CPU_t *smpcpu = NULL;
unsigned int j; unsigned int j;
register unsigned long charge, total = 0 ; register unsigned long charge, total = 0;
smpcpu = cpus_refresh(smpcpu, Cpu_tot); smpcpu = cpus_refresh(smpcpu, Cpu_tot);
for(j = 0 ; j < Cpu_tot ; j ++) for (j = 0; j < Cpu_tot; j ++) {
{ charge = smpcpu[j].u + smpcpu[j].s + smpcpu[j].n;
charge = smpcpu[j].u+smpcpu[j].s+smpcpu[j].n; total = charge + smpcpu[j].i;
total = charge + smpcpu[j].i;
/* scale cpu to a maximum of HAUTEUR */ /* scale cpu to a maximum of HAUTEUR */
load[j] = ((HAUTEUR * (charge - smpcpu[j].charge)) / (total - smpcpu[j].total + 0.001)) + 1 ; load[j] = ((HAUTEUR * (charge - smpcpu[j].charge)) /
smpcpu[j].total = total ; (total - smpcpu[j].total + 0.001)) + 1 ;
smpcpu[j].charge = charge ; smpcpu[j].total = total ;
} smpcpu[j].charge = charge ;
}
return load; return load;
} }
unsigned int Get_Memory(void) unsigned int Get_Memory(void)
{ {
meminfo(); meminfo();
return (kb_main_used - kb_main_cached) / (kb_main_total / 100) ; return ((kb_main_used - kb_main_cached) / (kb_main_total / 100));
/* should be between 0 and 100 now */ /* should be between 0 and 100 now */
} }
unsigned int Get_Swap(void) unsigned int Get_Swap(void)
{ {
/* returns swap usage as value between 0 and 100 OR 999 if no swap /* returns swap usage as value between 0 and 100
* present */ * OR 999 if no swap present */
meminfo(); meminfo();
return ( kb_swap_total == 0 ? 999 : kb_swap_used / (kb_swap_total / 100) ); return (kb_swap_total == 0 ? 999 : kb_swap_used / (kb_swap_total / 100));
} }

View file

@ -5,13 +5,14 @@
#include <sys/utsname.h> #include <sys/utsname.h>
/* These are the possible fscanf formats used in /proc/stat /* These are the possible fscanf formats used in /proc/stat
reads during history processing. reads during history processing.
( 5th number only for Linux 2.5.41 and above ) */ ( 5th number only for Linux 2.5.41 and above ) */
#define CPU_FMTS_JUST1 "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu" #define CPU_FMTS_JUST1 "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu"
#define CPU_FMTS_MULTI "cpu%*d %Lu %Lu %Lu %Lu %Lu %Lu %Lu" #define CPU_FMTS_MULTI "cpu%*d %Lu %Lu %Lu %Lu %Lu %Lu %Lu"
/* Summary Lines specially formatted string(s) -- see 'show_special' for syntax details + other cautions. */ /* Summary Lines specially formatted string(s) --
see 'show_special' for syntax details + other cautions. */
#define STATES_line2x4 "%s\03" \ #define STATES_line2x4 "%s\03" \
" %#5.1f%% \02user,\03 %#5.1f%% \02system,\03 %#5.1f%% \02nice,\03 %#5.1f%% \02idle\03\n" " %#5.1f%% \02user,\03 %#5.1f%% \02system,\03 %#5.1f%% \02nice,\03 %#5.1f%% \02idle\03\n"
#define STATES_line2x5 "%s\03" \ #define STATES_line2x5 "%s\03" \
@ -19,15 +20,15 @@
#define STATES_line2x6 "%s\03" \ #define STATES_line2x6 "%s\03" \
" %#4.1f%% \02us,\03 %#4.1f%% \02sy,\03 %#4.1f%% \02ni,\03 %#4.1f%% \02id,\03 %#4.1f%% \02wa,\03 %#4.1f%% \02hi,\03 %#4.1f%% \02si\03\n" " %#4.1f%% \02us,\03 %#4.1f%% \02sy,\03 %#4.1f%% \02ni,\03 %#4.1f%% \02id,\03 %#4.1f%% \02wa,\03 %#4.1f%% \02hi,\03 %#4.1f%% \02si\03\n"
/* These typedefs attempt to ensure consistent 'ticks' handling */ /* These typedefs attempt to ensure consistent 'ticks' handling */
typedef unsigned long long TIC_t; typedef unsigned long long TIC_t;
/* This structure stores a frame's cpu tics used in history /* This structure stores a frame's cpu tics used in history
calculations. It exists primarily for SMP support but serves calculations. It exists primarily for SMP support but serves
all environments. */ all environments. */
typedef struct CPU_t { typedef struct CPU_t {
TIC_t u, n, s, i, w, x, y; // as represented in /proc/stat TIC_t u, n, s, i, w, x, y; // as represented in /proc/stat
TIC_t charge, total; TIC_t charge, total;
} CPU_t; } CPU_t;
#endif /* SYSINFO_H */ #endif /* LINUX_SYSINFO_H */

View file

@ -1,7 +1,7 @@
/*************************************************************************** /***************************************************************************
wmSMPmon III - Window Maker system monitor wmSMPmon III - Window Maker system monitor
VERSION : 3.1 VERSION : 3.2
DATE : 2005-11-06 DATE : 2005-11-06
ORIGINAL AUTHORS : redseb <redseb@goupilfr.org> and ORIGINAL AUTHORS : redseb <redseb@goupilfr.org> and
PhiR <phir@gcu-squad.org> PhiR <phir@gcu-squad.org>
CONTRIBUTORS : Alain Schröder <alain@parkautomat.net> CONTRIBUTORS : Alain Schröder <alain@parkautomat.net>
@ -12,16 +12,15 @@ CURRENT MAINTAINER: Thomas Ribbrock <emgaron@gmx.net>
See file COPYING for information on distribution conditions. See file COPYING for information on distribution conditions.
***************************************************************************/ ***************************************************************************/
#include <string.h> #include <string.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/xpm.h> #include <X11/xpm.h>
#include <X11/extensions/shape.h> #include <X11/extensions/shape.h>
#include "../wmgeneral/wmgeneral.h" #include "../wmgeneral/wmgeneral.h"
#include "wmSMPmon_master.xpm" #include "wmSMPmon_master.xpm"
#include "wmSMPmon_mask.xbm" #include "wmSMPmon_mask.xbm"
#include "general.h" #include "general.h"
#include "standards.h" #include "standards.h"
#include "sysinfo-linux.h"
#define VERSION "3.2" #define VERSION "3.2"
@ -39,315 +38,290 @@ void usage(int cpus, const char *str);
/*###### MAIN PROGRAM ###################################################*/ /*###### MAIN PROGRAM ###################################################*/
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
XEvent Event ; XEvent Event;
unsigned int t0[TAILLE_T], /* history for CPU 0 -> Graph */ unsigned int t0[TAILLE_T], /* history for CPU 0 -> Graph */
t1[TAILLE_T], /* history for CPU 1 -> Graph */ t1[TAILLE_T], /* history for CPU 1 -> Graph */
tm[TAILLE_T], /* history for CPU 0+1 -> Graph */ tm[TAILLE_T], /* history for CPU 0+1 -> Graph */
c1 = DIV1, c1 = DIV1,
c2 = DIV2, c2 = DIV2,
etat = 1, etat = 1,
lecture = 1, lecture = 1,
delay = 250000, delay = 250000,
delta = 0, delta = 0,
load = 0, load = 0,
load0o = 0, load0o = 0,
load1o = 0, load1o = 0,
no_swap = FAUX, no_swap = FAUX,
draw_graph = VRAI, draw_graph = VRAI,
NumCPUs, /* number of CPUs */ NumCPUs, /* number of CPUs */
i = 0, /* counter */ i = 0, /* counter */
mem = 0, /* current memory/swap scaled to 0-100 */ mem = 0, /* current memory/swap scaled to 0-100 */
prec_mem = 0, /* memory from previous round */ prec_mem = 0, /* memory from previous round */
prec_swap = 0, /* swap from previous round */ prec_swap = 0, /* swap from previous round */
load_width = 3; /* width of load bar: 3 for SMP, 8 for UP */ load_width = 3; /* width of load bar: 3 for SMP, 8 for UP */
unsigned long load0t=0, load1t=0 ; unsigned long load0t = 0, load1t = 0;
unsigned int *CPU_Load; /* CPU load per CPU array */ unsigned int *CPU_Load; /* CPU load per CPU array */
unsigned int t_idx = 0; /* Index to load history tables */ unsigned int t_idx = 0; /* Index to load history tables */
/********** Initialisation **********/ /********** Initialisation **********/
NumCPUs = NumCpus_DoInit(); NumCPUs = NumCpus_DoInit();
CPU_Load = alloc_c((NumCPUs) * sizeof(int)); CPU_Load = alloc_c((NumCPUs) * sizeof(int));
if(NumCPUs == 1) if(NumCPUs == 1) {
{ load_width = 8;
load_width = 8; } else {
} load_width = 3;
else
{
load_width = 3;
}
Myname = strrchr(argv[0], '/');
if (Myname) ++Myname; else Myname = argv[0];
/* process command line args */
i = 1; /* skip program name (i=0) */
while(argc > i)
{
if(!strncmp(argv[i], "-r", 2))
{
i ++ ;
if(i == argc)
{
/* parameter missing! */
usage(NumCPUs, "no refresh rate given when using -r!");
}
else
{
delay = atol(argv[i]) ;
}
i ++ ;
continue;
}
if(!strncmp(argv[i], "-h", 2))
{
usage(NumCPUs, NULL) ;
}
if(!strncmp(argv[i], "-g", 2) && NumCPUs > 1)
{
/* we only support this on SMP systems */
i ++ ;
if(i == argc)
{
/* parameter missing! */
usage(NumCPUs, "no graph style given when using -g!");
}
else
{
etat = atoi(argv[i]) ;
}
if(1 > etat || etat > 3)
usage(NumCPUs, "Unknown graph style") ;
i ++ ;
continue;
}
if(!strncmp(argv[i], "-no-swap", 8))
{
puts(MSG_NO_SWAP) ;
no_swap = VRAI ;
i ++ ;
continue;
}
/* if we get here, we found an illegal option */
usage(NumCPUs, "Illegal option!");
}
/* open initial window */
if(NumCPUs == 1)
{
/* we only have a single CPU - change the mask accordingly
NOTE: The for loop was derived from the differences between
wmSMPmon_mask.xbm and wmSMPmon_mask-single.xbm.
wmSMPmon_mask-single.xbm as such is NOT used in this
program! */
for (i = 33; i <= 289; i = i+8)
{
wmSMPmon_mask_bits[i] = 0xDF;
}
}
openXwindow(argc,argv,wmSMPmon_master_xpm,wmSMPmon_mask_bits,wmSMPmon_mask_width,wmSMPmon_mask_height) ;
if(NumCPUs >= 2)
{
/* we have two CPUs -> draw separator between CPU load bars */
copyXPMArea(12, 4, 2, HAUTEUR + 2, 7, 4) ;
}
delay = delay / 2 ;
for(i = 0 ; i < TAILLE_T ; i ++) {
t0[i] = 0 ;
t1[i] = 0 ;
tm[i] = 0 ;
}
/* -no-swap option was given */
if(no_swap)
copyXPMArea(60, 63, 60, 10, 6, 50) ;
/* MAIN LOOP */
while(VRAI)
{
if(lecture)
{
CPU_Load = Get_CPU_Load(CPU_Load, NumCPUs);
load = CPU_Load[0];
for (i = 1; i < NumCPUs >> 1; i++) {
load += CPU_Load[i];
} }
load = load / i;
load0t = load0t + load;
if(load != load0o)
{
/* redraw only if cpu load changed */
delta = HAUTEUR - load ;
copyXPMArea(108, 0, load_width, HAUTEUR, 4, 5) ;
copyXPMArea(108, delta + 32, load_width, load, 4, 5 + delta) ;
load0o = load;
}
if(NumCPUs >= 2) Myname = strrchr(argv[0], '/');
{ if (Myname)
/* we have two CPUs -> do CPU 1 */ ++Myname;
load = 0; else
for (; i < NumCPUs; i++) { Myname = argv[0];
load += CPU_Load[i];
}
load = load / (NumCPUs >> 1);
if(load != load1o) /* process command line args */
{ i = 1; /* skip program name (i=0) */
/* redraw only if cpu load changed */ while (argc > i) {
delta = HAUTEUR - load ; if (!strncmp(argv[i], "-r", 2)) {
copyXPMArea(108, 0, 3, HAUTEUR, 9, 5) ; i++;
copyXPMArea(108, delta + 32, 3, load, 9, 5 + delta) ; if (i == argc) {
load1o = load; /* parameter missing! */
} usage(NumCPUs,
} "no refresh rate given when using -r!");
} else {
delay = atol(argv[i]) ;
}
i++;
continue;
}
if (!strncmp(argv[i], "-h", 2)) {
usage(NumCPUs, NULL);
}
if (!strncmp(argv[i], "-g", 2) && NumCPUs > 1) {
/* we only support this on SMP systems */
i++;
if (i == argc) {
/* parameter missing! */
usage(NumCPUs,
"no graph style given when using -g!");
} else {
etat = atoi(argv[i]);
}
/* we have to set load1t in any case to get the correct if (1 > etat || etat > 3)
graph below. With only one CPU, 'load' will still be usage(NumCPUs, "Unknown graph style");
CPU_Load[0], on a SMP system, it will be CPU_Load[1]. */ i++;
load1t = load1t + load ; continue;
}
if (!strncmp(argv[i], "-no-swap", 8)) {
puts(MSG_NO_SWAP);
no_swap = VRAI;
i++;
continue;
}
if(c1 > DIV1) /* if we get here, we found an illegal option */
{ usage(NumCPUs, "Illegal option!");
mem = Get_Memory(); }
if(mem != prec_mem) /* open initial window */
{ if (NumCPUs == 1) {
/* redraw only if mem changed */ /* we only have a single CPU - change the mask accordingly
copyXPMArea(30, 63, 30, 8, 29, 39) ; * NOTE: The for loop was derived from the differences between
copyXPMArea(0, 63, (mem * 30 / 100), 8, 29, 39) ; * wmSMPmon_mask.xbm and wmSMPmon_mask-single.xbm.
prec_mem = mem ; * wmSMPmon_mask-single.xbm as such is NOT used in this
} * program!
*/
for (i = 33; i <= 289; i = i+8) {
wmSMPmon_mask_bits[i] = 0xDF;
}
}
if(!no_swap) openXwindow(argc, argv, wmSMPmon_master_xpm, wmSMPmon_mask_bits,
{ wmSMPmon_mask_width, wmSMPmon_mask_height);
mem = Get_Swap();
if(mem != prec_swap) if(NumCPUs >= 2) {
{ /* we have two CPUs -> draw separator between CPU load bars */
/* redraw if there was a change */ copyXPMArea(12, 4, 2, HAUTEUR + 2, 7, 4);
if(mem == 999) }
{
/* swap is disabled => show "none" */
copyXPMArea(60, 63, 60, 10, 6, 50);
}
else
{
/* draw swap usage */
copyXPMArea(30, 63, 30, 8, 29, 50) ;
copyXPMArea(0, 63, (mem * 30 / 100), 8, 29, 50) ;
}
prec_swap = mem ;
}
}
c1 = 0;
}
if(c2 > DIV2) { delay = delay / 2 ;
if((t0[t_idx] = load0t / c2) > HAUTEUR)
t0[t_idx] = HAUTEUR ; for (i = 0; i < TAILLE_T; i ++) {
t0[t_idx] /= 2; t0[i] = 0;
if((t1[t_idx] = load1t / c2) > HAUTEUR) t1[i] = 0;
t1[t_idx] = HAUTEUR ; tm[i] = 0;
t1[t_idx] /= 2; }
if((tm[t_idx] = (load0t + load1t) / (2 * c2)) > HAUTEUR)
tm[t_idx] = HAUTEUR ; /* -no-swap option was given */
load0t = 0 ; if (no_swap)
load1t = 0 ; copyXPMArea(60, 63, 60, 10, 6, 50);
t_idx = (t_idx + 1) % TAILLE_T;
draw_graph = VRAI ; /* MAIN LOOP */
c2 = 0; while (VRAI) {
} if (lecture) {
if(draw_graph) CPU_Load = Get_CPU_Load(CPU_Load, NumCPUs);
{
/* draw graph */ load = CPU_Load[0];
switch(etat) for (i = 1; i < NumCPUs >> 1; i++) {
{ load += CPU_Load[i];
case 1 : }
copyXPMArea(64, 32, TAILLE_T, HAUTEUR, 15, 5) ; load = load / i;
for(i = 0, load = t_idx ; i < TAILLE_T ; i ++, load++) load0t = load0t + load;
copyXPMArea(116, 0, 1, tm[load % TAILLE_T], 15 + i, HAUTEUR + 5 - tm[load % TAILLE_T]) ; if (load != load0o) {
break ; /* redraw only if cpu load changed */
case 2 : delta = HAUTEUR - load;
copyXPMArea(64, 0, TAILLE_T, HAUTEUR, 15, 5) ; copyXPMArea(108, 0, load_width, HAUTEUR, 4, 5);
for(i = 0, load = t_idx ; i < TAILLE_T ; i ++, load++) { copyXPMArea(108, delta + 32, load_width, load,
copyXPMArea(116, 0, 1, t0[load % TAILLE_T], 15 + i, HAUTEUR/2 + 5 - t0[load % TAILLE_T]) ; 4, 5 + delta);
copyXPMArea(116, 0, 1, t1[load % TAILLE_T], 15 + i, HAUTEUR/2 + 21 - t1[load % TAILLE_T]) ; load0o = load;
} }
break ;
case 3 : if (NumCPUs >= 2) {
copyXPMArea(64, 0, TAILLE_T, HAUTEUR, 15, 5) ; /* we have two CPUs -> do CPU 1 */
for(i = 0, load = t_idx ; i < TAILLE_T ; i ++, load++) { load = 0;
copyXPMArea(116, 0, 1, t0[load % TAILLE_T], 15 + i, HAUTEUR/2 + 5 - t0[load % TAILLE_T]) ; for (; i < NumCPUs; i++) {
copyXPMArea(117, HAUTEUR/2 - t1[load % TAILLE_T], 1, t1[load % TAILLE_T], 15 + i, HAUTEUR/2 + 6) ; load += CPU_Load[i];
} }
break ; load = load / (NumCPUs >> 1);
}
draw_graph = FAUX ; if (load != load1o) {
} /* redraw only if cpu load changed */
c1 ++ ; delta = HAUTEUR - load;
c2 ++ ; copyXPMArea(108, 0, 3, HAUTEUR, 9, 5);
} copyXPMArea(108, delta + 32, 3, load,
lecture = 1 - lecture ; 9, 5 + delta);
RedrawWindow() ; load1o = load;
if(NumCPUs >= 2 && XCheckMaskEvent(display, ButtonPressMask, &Event)) }
{ }
/* changing graph style not supported on single CPU systems */
if(Event.type == ButtonPress) /* we have to set load1t in any case to get the correct
{ * graph below. With only one CPU, 'load' will still be
if((etat ++) >= 3) * CPU_Load[0], on a SMP system, it will be CPU_Load[1].
etat = 1 ; */
draw_graph = VRAI ; load1t = load1t + load;
}
} if (c1 > DIV1) {
usleep(delay); mem = Get_Memory();
}
if (mem != prec_mem) {
/* redraw only if mem changed */
copyXPMArea(30, 63, 30, 8, 29, 39);
copyXPMArea(0, 63, (mem * 30 / 100), 8,
29, 39);
prec_mem = mem;
}
if (!no_swap) {
mem = Get_Swap();
if (mem != prec_swap) {
/* redraw if there was a change */
if (mem == 999) {
/* swap is disabled => show "none" */
copyXPMArea(60, 63, 60, 10, 6, 50);
} else {
/* draw swap usage */
copyXPMArea(30, 63, 30, 8, 29, 50);
copyXPMArea(0, 63, (mem * 30 / 100), 8, 29, 50);
}
prec_swap = mem;
}
}
c1 = 0;
}
if (c2 > DIV2) {
if ((t0[t_idx] = load0t / c2) > HAUTEUR)
t0[t_idx] = HAUTEUR;
t0[t_idx] /= 2;
if ((t1[t_idx] = load1t / c2) > HAUTEUR)
t1[t_idx] = HAUTEUR;
t1[t_idx] /= 2;
if ((tm[t_idx] = (load0t + load1t) / (2 * c2)) > HAUTEUR)
tm[t_idx] = HAUTEUR;
load0t = 0;
load1t = 0;
t_idx = (t_idx + 1) % TAILLE_T;
draw_graph = VRAI;
c2 = 0;
}
if (draw_graph) {
/* draw graph */
switch (etat) {
case 1 :
copyXPMArea(64, 32, TAILLE_T, HAUTEUR, 15, 5);
for (i = 0, load = t_idx; i < TAILLE_T; i ++, load++)
copyXPMArea(116, 0, 1, tm[load % TAILLE_T], 15 + i, HAUTEUR + 5 - tm[load % TAILLE_T]);
break;
case 2 :
copyXPMArea(64, 0, TAILLE_T, HAUTEUR, 15, 5);
for (i = 0, load = t_idx; i < TAILLE_T; i ++, load++) {
copyXPMArea(116, 0, 1, t0[load % TAILLE_T], 15 + i, HAUTEUR/2 + 5 - t0[load % TAILLE_T]);
copyXPMArea(116, 0, 1, t1[load % TAILLE_T], 15 + i, HAUTEUR/2 + 21 - t1[load % TAILLE_T]);
}
break;
case 3 :
copyXPMArea(64, 0, TAILLE_T, HAUTEUR, 15, 5);
for (i = 0, load = t_idx; i < TAILLE_T; i ++, load++) {
copyXPMArea(116, 0, 1, t0[load % TAILLE_T], 15 + i, HAUTEUR/2 + 5 - t0[load % TAILLE_T]);
copyXPMArea(117, HAUTEUR/2 - t1[load % TAILLE_T], 1, t1[load % TAILLE_T], 15 + i, HAUTEUR/2 + 6);
}
break;
}
draw_graph = FAUX;
}
c1++;
c2++;
}
lecture = 1 - lecture ;
RedrawWindow();
if (NumCPUs >= 2 &&
XCheckMaskEvent(display, ButtonPressMask, &Event)) {
/* changing graph style not supported on single CPU systems */
if (Event.type == ButtonPress) {
if ((etat++) >= 3)
etat = 1;
draw_graph = VRAI;
}
}
usleep(delay);
}
} }
/*###### Usage Message ##################################################*/ /*###### Usage Message ##################################################*/
void usage(int cpus, const char *str) void usage(int cpus, const char *str)
{ {
fflush(stdout); fflush(stdout);
if (str) if (str) {
{ fprintf(stderr, "\nERROR: %s\n", str);
fprintf(stderr, "\nERROR: %s\n", str); }
}
fputs("\nwmSMPmon "VERSION" - display system load (", stderr); fputs("\nwmSMPmon "VERSION" - display system load (", stderr);
if(cpus == 1) if(cpus == 1) {
{ fputs("uniprocessor system)\n\n", stderr);
fputs("uniprocessor system)\n\n", stderr); } else {
} fputs("multiprocessor system)\n\n", stderr);
else }
{ fputs("Options : -h this help screen.\n"
fputs("(multiprocessor system)\n\n", stderr); " -r RATE refresh rate (in microseconds, default 250000).\n",
} stderr);
fputs("Options : -h this help screen.\n"
" -r RATE refresh rate (in microseconds, default 250000).\n", stderr);
if(cpus > 1) if(cpus > 1) {
{ fputs(" -g STYLE graph style (try 2 or 3, default is 1).\n",
fputs(" -g STYLE graph style (try 2 or 3, default is 1).\n", stderr); stderr);
} }
fputs(" -no-swap don't monitore swap size.\n\n" fputs(" -no-swap don't monitore swap size.\n\n"
"<redseb@goupilfr.org> http://goupilfr.org\n" "<redseb@goupilfr.org> http://goupilfr.org\n"
"<phir@gcu-squad.org> http://gcu-squad.org\n" "<phir@gcu-squad.org> http://gcu-squad.org\n"
"<emgaron@gmx.net> http://www.ribbrock.org\n", "<emgaron@gmx.net> http://www.ribbrock.org\n",
stderr) ; stderr);
exit(OK) ;
exit(OK);
} }

View file

@ -292,34 +292,31 @@ void createXBMfromXPM(char *xbm, char **xpm, int sx, int sy) {
int i,j,k; int i,j,k;
int width, height, numcol, depth; int width, height, numcol, depth;
int zero=0; int zero = 0;
unsigned char bwrite; unsigned char bwrite;
int bcount; int bcount;
int curpixel; int curpixel;
sscanf(*xpm, "%d %d %d %d", &width, &height, &numcol, &depth); sscanf(*xpm, "%d %d %d %d", &width, &height, &numcol, &depth);
for (k = 0; k != depth; k++) {
zero <<=8;
zero |= xpm[1][k];
}
for (k=0; k!=depth; k++) for (i = numcol + 1; i < numcol + sy + 1; i++) {
{
zero <<=8;
zero |= xpm[1][k];
}
for (i=numcol+1; i < numcol+sy+1; i++) {
bcount = 0; bcount = 0;
bwrite = 0; bwrite = 0;
for (j=0; j<sx*depth; j+=depth) { for (j = 0; j < sx * depth; j += depth) {
bwrite >>= 1; bwrite >>= 1;
curpixel=0; curpixel=0;
for (k=0; k!=depth; k++) for (k = 0; k != depth; k++) {
{ curpixel <<=8;
curpixel <<=8; curpixel |= xpm[i][j+k];
curpixel |= xpm[i][j+k]; }
}
if ( curpixel != zero ) { if (curpixel != zero) {
bwrite += 128; bwrite += 128;
} }
bcount++; bcount++;
@ -343,10 +340,10 @@ void createXBMfromXPM(char *xbm, char **xpm, int sx, int sy) {
|* dx,dy: first corner of target area *| |* dx,dy: first corner of target area *|
\***************************************************************************/ \***************************************************************************/
void copyXPMArea(int x, int y, int sx, int sy, int dx, int dy) { void copyXPMArea(int x, int y, int sx, int sy, int dx, int dy)
{
XCopyArea(display, wmgen.pixmap, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy); XCopyArea(display, wmgen.pixmap, wmgen.pixmap, NormalGC,
x, y, sx, sy, dx, dy);
} }
/***************************************************************************\ /***************************************************************************\
@ -359,9 +356,10 @@ void copyXPMArea(int x, int y, int sx, int sy, int dx, int dy) {
|* dx,dy: first corner of target area *| |* dx,dy: first corner of target area *|
\***************************************************************************/ \***************************************************************************/
void copyXBMArea(int x, int y, int sx, int sy, int dx, int dy) { void copyXBMArea(int x, int y, int sx, int sy, int dx, int dy)
{
XCopyArea(display, wmgen.mask, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy); XCopyArea(display, wmgen.mask, wmgen.pixmap, NormalGC,
x, y, sx, sy, dx, dy);
} }
@ -369,10 +367,10 @@ void copyXBMArea(int x, int y, int sx, int sy, int dx, int dy) {
|* setMaskXY *| |* setMaskXY *|
\***************************************************************************/ \***************************************************************************/
void setMaskXY(int x, int y) { void setMaskXY(int x, int y)
{
XShapeCombineMask(display, win, ShapeBounding, x, y, pixmask, ShapeSet); XShapeCombineMask(display, win, ShapeBounding, x, y, pixmask, ShapeSet);
XShapeCombineMask(display, iconwin, ShapeBounding, x, y, pixmask, ShapeSet); XShapeCombineMask(display, iconwin, ShapeBounding, x, y, pixmask, ShapeSet);
} }
/***************************************************************************\ /***************************************************************************\
@ -381,20 +379,20 @@ void setMaskXY(int x, int y) {
void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bits, int pixmask_width, int pixmask_height) { void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bits, int pixmask_width, int pixmask_height) {
unsigned int borderwidth = 1; unsigned int borderwidth = 1;
XClassHint classHint; XClassHint classHint;
char *display_name = NULL; char *display_name = NULL;
char *wname = argv[0]; char *wname = argv[0];
XTextProperty name; XTextProperty name;
XGCValues gcv; XGCValues gcv;
unsigned long gcm; unsigned long gcm;
char *geometry = NULL; char *geometry = NULL;
int dummy=0; int dummy=0;
int i, wx, wy; int i, wx, wy;
for (i=1; argv[i]; i++) { for (i = 1; argv[i]; i++) {
if (!strcmp(argv[i], "-display")) { if (!strcmp(argv[i], "-display")) {
display_name = argv[i+1]; display_name = argv[i+1];
i++; i++;
@ -407,7 +405,7 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit
if (!(display = XOpenDisplay(display_name))) { if (!(display = XOpenDisplay(display_name))) {
fprintf(stderr, "%s: can't open display %s\n", fprintf(stderr, "%s: can't open display %s\n",
wname, XDisplayName(display_name)); wname, XDisplayName(display_name));
exit(1); exit(1);
} }
screen = DefaultScreen(display); screen = DefaultScreen(display);
@ -427,16 +425,19 @@ void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bit
fore_pix = GetColor("black"); fore_pix = GetColor("black");
XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints, XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints,
&mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy); &mysizehints.x, &mysizehints.y, &mysizehints.width,
&mysizehints.height, &dummy);
mysizehints.width = 64; mysizehints.width = 64;
mysizehints.height = 64; mysizehints.height = 64;
win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y, win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y,
mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix); mysizehints.width, mysizehints.height, borderwidth,
fore_pix, back_pix);
iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y, iconwin = XCreateSimpleWindow(display, win,
mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix); mysizehints.x, mysizehints.y, mysizehints.width, mysizehints.height,
borderwidth, fore_pix, back_pix);
/* Activate hints */ /* Activate hints */
XSetWMNormalHints(display, win, &mysizehints); XSetWMNormalHints(display, win, &mysizehints);