1 --- matchbox-panel-0.9.2/applets/mb-applet-system-monitor.c.orig 2006-02-07 20:08:09.000000000 +0200
2 +++ matchbox-panel-0.9.2/applets/mb-applet-system-monitor.c 2006-02-07 20:53:20.000000000 +0200
4 # define _(text) (text)
12 MBPixbufImage *ImgIcon = NULL, *ImgIconScaled = NULL, *ImgGraph = NULL;
14 int GraphHeight = 0, GraphWidth = 0;
17 +static int kernelver = 0;
19 +/* returns 1 if the kernel version is 2.6, 0 otherwise */
20 +int kernel_version(void)
25 + if ((version = fopen("/proc/version", "r")) == NULL)
27 + fprintf(stderr, "mb-applet-system-monitor: failed to open /proc/version. Exiting\n");
30 + fscanf(version, "%*s %*s %f", &v_nr);
41 /* returns current CPU load in percent, 0 to 100 */
45 int system_memory(void)
47 - u_int64_t my_mem_used, my_mem_max;
48 - u_int64_t my_swap_max;
50 - static int mem_delay = 0;
52 - static u_int64_t total, used, mfree, shared, buffers, cached,
53 - cache_total, cache_used;
55 - /* put this in permanent storage instead of stack */
56 - static char not_needed[2048];
58 - if (mem_delay-- <= 0) {
59 - if ((mem = fopen("/proc/meminfo", "r")) == NULL)
60 + u_int64_t total, mfree, buffers, cached, used, shared,
61 + cache_total, cache_free, cache_used, uneeded = 0;
63 + u_int64_t my_mem_used, my_mem_max;
64 + u_int64_t my_swap_max;
66 + static int mem_delay = 0;
69 + /* put this in permanent storage instead of stack */
70 + static char not_needed[2048];
72 + if (mem_delay-- <= 0)
74 + if ((mem = fopen("/proc/meminfo", "r")) == NULL)
76 fprintf(stderr, "mb-applet-system-monitor: failed to open /proc/meminfo. Exiting.\n");
82 - fgets(not_needed, 2048, mem);
85 - total: used: free: shared: buffers: cached:
88 - fscanf(mem, "%*s %Ld %Ld %Ld %Ld %Ld %Ld", &total, &used, &mfree,
89 - &shared, &buffers, &cached);
91 - fscanf(mem, "%*s %Ld %Ld", &cache_total, &cache_used);
98 - my_swap_max = cache_total;
100 - my_mem_used = cache_used + used - cached - buffers;
103 - if (my_mem_used > my_mem_max) {
104 - my_swap_used = my_mem_used - my_mem_max;
105 - my_mem_used = my_mem_max;
111 - msd.mem_used = my_mem_used;
112 - msd.mem_max = my_mem_max;
113 - //msd.swap_used = my_swap_used;
114 - //msd.swap_max = my_swap_max;
116 + fgets(not_needed, 2048, mem);
118 - msd.mem_percent = (100 * msd.mem_used) / msd.mem_max;
119 - //msd.swap_percent = (100 * msd.swap_used) / msd.swap_max;
120 +/*if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)*/
122 - /* memory info changed - update things */
131 + fscanf (mem, "%*s %Ld %*s", &total);
132 + fscanf (mem, "%*s %Ld %*s", &mfree);
133 + fscanf (mem, "%*s %Ld %*s", &buffers);
134 + fscanf (mem, "%*s %Ld %*s", &cached);
135 + fscanf (mem, "%*s %Ld %*s", &shared);
136 + fscanf (mem, "%*s %Ld %*s", &used);
137 + fscanf (mem, "%*s %Ld %*s", &uneeded);
138 + fscanf (mem, "%*s %Ld %*s", &uneeded);
139 + fscanf (mem, "%*s %Ld %*s", &uneeded);
140 + fscanf (mem, "%*s %Ld %*s", &uneeded);
141 + fscanf (mem, "%*s %Ld %*s", &uneeded);
142 + fscanf (mem, "%*s %Ld %*s", &cache_total);
143 + fscanf (mem, "%*s %Ld %*s", &cache_free);
145 + total = total * 1024;
146 + mfree = mfree * 1024;
147 + buffers = buffers * 1024;
148 + cached = cached * 1024;
149 + used = used * 1024;
150 + shared = shared * 1024;
151 + cache_total = cache_total * 1024;
152 + cache_used = cache_total - (cache_free * 1024);
157 + total: used: free: shared: buffers: cached:
159 + fscanf(mem, "%*s %Ld %Ld %Ld %Ld %Ld %Ld", &total, &used, &mfree,
160 + &shared, &buffers, &cached);
161 + fscanf(mem, "%*s %Ld %Ld", &cache_total, &cache_used);
169 + my_mem_max = total;
170 + my_swap_max = cache_total;
171 + my_mem_used = cache_used + used - cached - buffers;
172 + msd.mem_used = my_mem_used;
173 + msd.mem_max = my_mem_max;
174 + msd.mem_percent = (100 * msd.mem_used) / msd.mem_max;
176 + /* memory info changed - update things */
185 paint_callback (MBTrayApp *app, Drawable drw )
191 + kernelver = kernel_version();