1 --- matchbox-panel-0.9.2/applets/mb-applet-system-monitor.c.old 2005-03-20 18:43:31.000000000 +0100
2 +++ matchbox-panel-0.9.2/applets/mb-applet-system-monitor.c 2005-12-21 10:24:18.000000000 +0100
4 # define _(text) (text)
7 +#include <linux/version.h>
8 +#ifndef KERNEL_VERSION
9 +#define KERNEL_VERSION(a,b,c) (((a) << 16) | ((b) << 8) | (c))
15 @@ -112,71 +117,148 @@
17 int system_memory(void)
19 - u_int64_t my_mem_used, my_mem_max;
20 - u_int64_t my_swap_max;
22 - static int mem_delay = 0;
24 - static u_int64_t total, used, mfree, shared, buffers, cached,
25 - cache_total, cache_used;
27 - /* put this in permanent storage instead of stack */
28 - static char not_needed[2048];
30 - if (mem_delay-- <= 0) {
31 - if ((mem = fopen("/proc/meminfo", "r")) == NULL)
33 - fprintf(stderr, "mb-applet-system-monitor: failed to open /proc/meminfo. Exiting.\n");
39 - fgets(not_needed, 2048, mem);
42 - total: used: free: shared: buffers: cached:
45 - fscanf(mem, "%*s %Ld %Ld %Ld %Ld %Ld %Ld", &total, &used, &mfree,
46 - &shared, &buffers, &cached);
48 - fscanf(mem, "%*s %Ld %Ld", &cache_total, &cache_used);
55 - my_swap_max = cache_total;
57 - my_mem_used = cache_used + used - cached - buffers;
60 - if (my_mem_used > my_mem_max) {
61 - my_swap_used = my_mem_used - my_mem_max;
62 - my_mem_used = my_mem_max;
68 - msd.mem_used = my_mem_used;
69 - msd.mem_max = my_mem_max;
70 - //msd.swap_used = my_swap_used;
71 - //msd.swap_max = my_swap_max;
73 - msd.mem_percent = (100 * msd.mem_used) / msd.mem_max;
74 - //msd.swap_percent = (100 * msd.swap_used) / msd.swap_max;
76 - /* memory info changed - update things */
81 + #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
82 + u_int64_t total, mfree, buffers, cached, used, shared,
83 + cache_total, cache_free, cache_used;
85 + u_int64_t my_mem_used, my_mem_max;
86 + u_int64_t my_swap_max;
88 + static int mem_delay = 0;
91 + /* put this in permanent storage instead of stack */
92 + static char not_needed[2048];
94 + if (mem_delay-- <= 0) {
95 + if ((mem = fopen("/proc/meminfo", "r")) == NULL) {
96 + fprintf(stderr, "mb-applet-system-monitor: failed to open /proc/meminfo. Exiting.\n");
100 + fgets(not_needed, 2048, mem);
104 + fscanf (mem, "%*s %Ld %*s", &total);
105 + fscanf (mem, "%*s %Ld %*s", &mfree);
106 + fscanf (mem, "%*s %Ld %*s", &buffers);
107 + fscanf (mem, "%*s %Ld %*s", &cached);
108 + fscanf (mem, "%*s %Ld %*s", &shared);
109 + fscanf (mem, "%*s %Ld %*s", &used);
110 + fscanf (mem, "%*s %*Ld %*s");
111 + fscanf (mem, "%*s %*Ld %*s");
112 + fscanf (mem, "%*s %*Ld %*s");
113 + fscanf (mem, "%*s %*Ld %*s");
114 + fscanf (mem, "%*s %*Ld %*s");
115 + fscanf (mem, "%*s %Ld %*s", &cache_total);
116 + fscanf (mem, "%*s %Ld %*s", &cache_free);
120 + total = total * 1024;
121 + mfree = mfree * 1024;
122 + buffers = buffers * 1024;
123 + cached = cached * 1024;
124 + used = used * 1024;
125 + shared = shared * 1024;
126 + cache_total = cache_total * 1024;
127 + cache_used = cache_total - (cache_free * 1024);
132 + my_mem_max = total;
133 + my_swap_max = cache_total;
135 + my_mem_used = cache_used + used - cached - buffers;
138 + if (my_mem_used > my_mem_max) {
139 + my_swap_used = my_mem_used - my_mem_max;
140 + my_mem_used = my_mem_max;
146 + msd.mem_used = my_mem_used;
147 + msd.mem_max = my_mem_max;
148 + //msd.swap_used = my_swap_used;
149 + //msd.swap_max = my_swap_max;
151 + msd.mem_percent = (100 * msd.mem_used) / msd.mem_max;
152 + //msd.swap_percent = (100 * msd.swap_used) / msd.swap_max;
154 + /* memory info changed - update things */
160 + static u_int64_t total, used, mfree, shared, buffers, cached,
161 + cache_total, cache_used;
163 + u_int64_t my_mem_used, my_mem_max;
164 + u_int64_t my_swap_max;
166 + static int mem_delay = 0;
169 + /* put this in permanent storage instead of stack */
170 + static char not_needed[2048];
172 + if (mem_delay-- <= 0) {
173 + if ((mem = fopen("/proc/meminfo", "r")) == NULL) {
174 + fprintf(stderr, "mb-applet-system-monitor: failed to open /proc/meminfo. Exiting.\n");
178 + fgets(not_needed, 2048, mem);
181 + total: used: free: shared: buffers: cached:
183 + fscanf(mem, "%*s %Ld %Ld %Ld %Ld %Ld %Ld", &total, &used, &mfree,
184 + &shared, &buffers, &cached);
186 + fscanf(mem, "%*s %Ld %Ld", &cache_total, &cache_used);
193 + my_mem_max = total;
194 + my_swap_max = cache_total;
196 + my_mem_used = cache_used + used - cached - buffers;
199 + if (my_mem_used > my_mem_max) {
200 + my_swap_used = my_mem_used - my_mem_max;
201 + my_mem_used = my_mem_max;
207 + msd.mem_used = my_mem_used;
208 + msd.mem_max = my_mem_max;
209 + //msd.swap_used = my_swap_used;
210 + //msd.swap_max = my_swap_max;
212 + msd.mem_percent = (100 * msd.mem_used) / msd.mem_max;
213 + //msd.swap_percent = (100 * msd.swap_used) / msd.swap_max;
215 + /* memory info changed - update things */
225 paint_callback (MBTrayApp *app, Drawable drw )