tint2 + graph

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
diff -ruN tint2.orig/CMakeLists.txt tint2.mine/CMakeLists.txt
--- tint2.orig/CMakeLists.txt 2011-09-19 12:38:01.000000000 +0200
+++ tint2.mine/CMakeLists.txt 2011-09-19 12:46:47.169791175 +0200
@@ -27,6 +27,7 @@
src
src/battery
src/clock
+ src/graphs
src/systray
src/taskbar
src/launcher
@@ -45,6 +46,7 @@
src/server.c
src/tint.c
src/clock/clock.c
+ src/graphs/graphs.c
src/systray/systraybar.c
src/launcher/launcher.c
src/launcher/xsettings-client.c
diff -ruN tint2.orig/src/config.c tint2.mine/src/config.c
--- tint2.orig/src/config.c 2011-09-19 12:38:00.000000000 +0200
+++ tint2.mine/src/config.c 2011-09-19 12:59:08.365524951 +0200
@@ -44,6 +44,7 @@
#include "systraybar.h"
#include "launcher.h"
#include "clock.h"
+#include "graphs.h"
#include "config.h"
#include "window.h"
#include "tooltip.h"
@@ -127,7 +128,7 @@
// monitor specified by name, not by index
int i, j;
for (i=0; i<server.nb_monitor; ++i) {
- if (server.monitor[i].names == 0)
+ if (server.monitor[i].names == 0)
// xrandr can't identify monitors
continue;
j = 0;
@@ -220,6 +221,8 @@
}
if (panel_items_order[j] == 'C')
clock_enabled = 1;
+ if (panel_items_order[j] == 'G')
+ graphs_enabled = 1;
}
}
else if (strcmp (key, "panel_margin") == 0) {
@@ -341,7 +344,7 @@
g_free( panel_items_order );
panel_items_order = tmp;
}
- else
+ else
panel_items_order = g_strdup("C");
}
if (strlen(value) > 0) {
@@ -401,6 +404,78 @@
clock_rclick_command = strdup(value);
}
+ /* Graphs */
+ else if (strcmp(key, "graphs_items") == 0) {
+ int j;
+ for (j = 0; j < strlen(value); j++) {
+ if (value[j] == 'C' && graphs_cpu_pos == -1) {
+ graphs_cpu_pos = graphs_ncurves;
+ graphs_curves_per_pos[graphs_ngraphs] = 2;
+ graphs_ngraphs++;
+ graphs_ncurves+=2;
+ }
+ else if (value[j] == 'M' && graphs_mem_pos == -1) {
+ graphs_mem_pos = graphs_ncurves;
+ graphs_curves_per_pos[graphs_ngraphs] = 2;
+ graphs_ngraphs++;
+ graphs_ncurves+=2;
+ }
+ else if (value[j] == 'N' && graphs_net_pos == -1) {
+ graphs_net_pos = graphs_ncurves;
+ graphs_curves_per_pos[graphs_ngraphs] = 2;
+ graphs_ngraphs++;
+ graphs_ncurves+=2;
+ }
+ }
+ }
+ else if (strcmp(key, "graphs_use_bars") == 0) {
+ graphs_use_bars = atoi(value);
+ }
+ else if (strcmp(key, "graphs_graph_width") == 0) {
+ int w = atoi(value);
+ graphs_graph_width = (w <= 200 && w >= 10) ? w : 50;
+ }
+ else if (strcmp(key, "graphs_netiface") == 0) {
+ if (strlen(value) > 0)
+ graphs_netiface = strdup(value);
+ }
+ else if (strcmp(key, "graphs_netmaxup") == 0) {
+ int s = atoi(value);
+ graphs_netmaxup = s;
+ }
+ else if (strcmp(key, "graphs_netmaxdown") == 0) {
+ int s = atoi(value);
+ graphs_netmaxdown = s;
+ }
+ else if (strncmp (key, "graphs_color", 12) == 0) {
+ int idx = key[12]-48;
+ if (idx >= 0 && idx < MAXCURVES) {
+ extract_values(value, &value1, &value2, &value3);
+ get_color (value1, panel_config.graphs.g[idx].color);
+ if (value2) panel_config.graphs.g[idx].alpha = (atoi (value2) / 100.0);
+ else panel_config.graphs.g[idx].alpha = 0.5;
+ }
+ }
+ else if (strcmp (key, "graphs_padding") == 0) {
+ extract_values(value, &value1, &value2, &value3);
+ panel_config.graphs.area.paddingxlr = panel_config.graphs.area.paddingx = atoi (value1);
+ if (value2) panel_config.graphs.area.paddingy = atoi (value2);
+ if (value3) panel_config.graphs.area.paddingx = atoi (value3);
+ }
+ else if (strcmp (key, "graphs_background_id") == 0) {
+ int id = atoi (value);
+ id = (id < backgrounds->len && id >= 0) ? id : 0;
+ panel_config.graphs.area.bg = &g_array_index(backgrounds, Background, id);
+ }
+ else if (strcmp(key, "graphs_lclick_command") == 0) {
+ if (strlen(value) > 0)
+ graphs_lclick_command = strdup(value);
+ }
+ else if (strcmp(key, "graphs_rclick_command") == 0) {
+ if (strlen(value) > 0)
+ graphs_rclick_command = strdup(value);
+ }
+
/* Taskbar */
else if (strcmp (key, "taskbar_mode") == 0) {
if (strcmp (value, "multi_desktop") == 0) panel_mode = MULTI_DESKTOP;
@@ -752,7 +827,7 @@
}
}
fclose (fp);
-
+
// append Taskbar item
if (new_config_file == 0) {
taskbar_enabled = 1;
@@ -761,7 +836,7 @@
g_free(panel_items_order);
panel_items_order = tmp;
}
- else
+ else
panel_items_order = g_strdup("T");
}
diff -ruN tint2.orig/src/graphs/graphs.c tint2.mine/src/graphs/graphs.c
--- tint2.orig/src/graphs/graphs.c 1970-01-01 01:00:00.000000000 +0100
+++ tint2.mine/src/graphs/graphs.c 2011-09-19 13:54:02.833338438 +0200
@@ -0,0 +1,426 @@
+/**************************************************************************
+*
+* Tint2 : graphs
+*
+* Copyright (C) 2011 Francisco J. Vazquez (fjvazquezaraujo@gmail.com)
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License version 2
+* as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+**************************************************************************/
+
+#include <string.h>
+#include <stdio.h>
+#include <cairo.h>
+#include <cairo-xlib.h>
+#include <pango/pangocairo.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include "window.h"
+#include "server.h"
+#include "panel.h"
+#include "graphs.h"
+#include "timer.h"
+#include "common.h"
+
+#define CPU_SAMPLE_COUNT 5
+#define NET_SAMPLE_COUNT 5
+
+int graphs_enabled;
+int graphs_ngraphs;
+int graphs_ncurves;
+int graphs_cpu_pos;
+int graphs_mem_pos;
+int graphs_net_pos;
+int graphs_curves_per_pos[MAXGRAPHS];
+int graphs_use_bars;
+int graphs_graph_width;
+int graphs_cpu_nsamples_avg;
+int graphs_net_nsamples_avg;
+char *graphs_netiface;
+int graphs_netmaxup;
+int graphs_netmaxdown;
+char *graphs_lclick_command;
+char *graphs_rclick_command;
+
+float **graph_values; // circular array list
+static int pos_x = 0; // current position in graph_values
+static timeout* graphs_timeout;
+
+
+void default_graphs()
+{
+ graphs_enabled = 0;
+ graphs_ngraphs = 0;
+ graphs_ncurves = 0;
+ graphs_cpu_pos = -1;
+ graphs_mem_pos = -1;
+ graphs_net_pos = -1;
+ graphs_use_bars = 0;
+ graphs_graph_width = 50;
+ graphs_cpu_nsamples_avg = 1;
+ graphs_net_nsamples_avg = 2;
+ graphs_netiface = 0;
+ graphs_netmaxup = 0;
+ graphs_netmaxdown = 0;
+ graphs_timeout = 0;
+ graphs_lclick_command = 0;
+ graphs_rclick_command = 0;
+}
+
+void cleanup_graphs()
+{
+ if (graphs_netiface) g_free(graphs_netiface);
+ if (graphs_lclick_command) g_free(graphs_lclick_command);
+ if (graphs_rclick_command) g_free(graphs_rclick_command);
+ if (graphs_timeout) stop_timeout(graphs_timeout);
+ int i;
+ for (i = 0; i < graphs_ncurves; i++)
+ {
+ free(graph_values[i]);
+ }
+ free(graph_values);
+}
+
+int update_cpugraph()
+{
+ if (graphs_cpu_pos == -1) return 0;
+
+ struct cpu_info {
+ unsigned long long last_total;
+ unsigned long long last_active_total, last_wait_total;
+ int cur_idx;
+ double active[CPU_SAMPLE_COUNT], wait[CPU_SAMPLE_COUNT];
+ float active_perc, wait_perc;
+ };
+ static struct cpu_info cpu = { .cur_idx=0 };
+
+ FILE *fp;
+ if ((fp = fopen("/proc/stat", "r")) == NULL) {
+ return 0;
+ }
+ char buf[256];
+ while (!feof(fp)) {
+ if (fgets(buf, 255, fp) == NULL) {
+ break;
+ }
+ if (strncmp(buf, "cpu", 3) == 0) {
+ unsigned long long cpu_user;
+ unsigned long long cpu_system;
+ unsigned long long cpu_nice;
+ unsigned long long cpu_idle;
+ unsigned long long cpu_iowait;
+ unsigned long long cpu_irq;
+ unsigned long long cpu_softirq;
+ unsigned long long cpu_steal;
+ unsigned long long cpu_total;
+ unsigned long long cpu_active_total;
+ unsigned long long cpu_wait_total;
+ sscanf(buf, "%*s %llu %llu %llu %llu %llu %llu %llu %llu",
+ &cpu_user, &cpu_nice, &cpu_system, &cpu_idle,
+ &cpu_iowait, &cpu_irq, &cpu_softirq, &cpu_steal);
+ cpu_total = cpu_user + cpu_nice + cpu_system + cpu_idle +
+ cpu_iowait + cpu_irq + cpu_softirq + cpu_steal;
+ cpu_active_total = cpu_user + cpu_nice + cpu_system + cpu_steal;
+ cpu_wait_total = cpu_total - cpu_active_total - cpu_idle;
+ double time = (cpu_total - cpu.last_total);
+ cpu.active[cpu.cur_idx] = (cpu_active_total - cpu.last_active_total) / time;
+ cpu.wait[cpu.cur_idx] = (cpu_wait_total - cpu.last_wait_total) / time;
+ cpu.last_total = cpu_total;
+ cpu.last_active_total = cpu_active_total;
+ cpu.last_wait_total = cpu_wait_total;
+ double curtmp1 = 0;
+ double curtmp2 = 0;
+ int i;
+ // Average the samples
+ for (i = 0; i < graphs_cpu_nsamples_avg; i++) {
+ int idx2 = (cpu.cur_idx + CPU_SAMPLE_COUNT - i) % CPU_SAMPLE_COUNT;
+ curtmp1 += cpu.active[idx2];
+ curtmp2 += cpu.wait[idx2];
+ }
+ cpu.active_perc = curtmp1 / (float) graphs_cpu_nsamples_avg;
+ cpu.wait_perc = curtmp2 / (float) graphs_cpu_nsamples_avg;
+ cpu.cur_idx = (cpu.cur_idx + 1) % CPU_SAMPLE_COUNT;
+ break; // Ignore the rest
+ }
+ }
+ fclose(fp);
+
+ graph_values[graphs_cpu_pos][pos_x] = cpu.active_perc;
+ graph_values[graphs_cpu_pos+1][pos_x] = cpu.active_perc + cpu.wait_perc;
+
+ return 0;
+}
+
+int update_memgraph()
+{
+ if (graphs_mem_pos == -1) return 0;
+
+ long long unsigned int memtotal = 0, memfree = 0, buffers = 0, cached = 0;
+
+ FILE *fp;
+ if ((fp = fopen("/proc/meminfo", "r")) == NULL) {
+ return 0;
+ }
+ char buf[256];
+ while (!feof(fp)) {
+ if (fgets(buf, 255, fp) == NULL) {
+ break;
+ }
+ if (strncmp(buf, "MemTotal:", 9) == 0) {
+ sscanf(buf, "%*s %llu", &memtotal);
+ } else if (strncmp(buf, "MemFree:", 8) == 0) {
+ sscanf(buf, "%*s %llu", &memfree);
+ } else if (strncmp(buf, "Buffers:", 8) == 0) {
+ sscanf(buf, "%*s %llu", &buffers);
+ } else if (strncmp(buf, "Cached:", 7) == 0) {
+ sscanf(buf, "%*s %llu", &cached);
+ }
+ }
+ fclose(fp);
+
+ long long unsigned int used = memtotal - memfree;
+ long long unsigned int bufcach = buffers + cached;
+
+ graph_values[graphs_mem_pos][pos_x] = (used - bufcach) / (float) memtotal;
+ graph_values[graphs_mem_pos+1][pos_x] = used / (float) memtotal;
+
+ return 0;
+}
+
+int update_netgraph()
+{
+ if (graphs_net_pos == -1 || graphs_netiface == NULL) return 0;
+
+ struct net_stat {
+ long long last_down, last_up;
+ int cur_idx;
+ long long down[NET_SAMPLE_COUNT], up[NET_SAMPLE_COUNT];
+ double down_rate, up_rate;
+ double max_down, max_up;
+ };
+ static struct net_stat net = { .cur_idx=0, .max_down=0, .max_up=0 };
+
+ double max(double v1, double v2) { return v1 > v2 ? v1 : v2; }
+ double min(double v1, double v2) { return v1 < v2 ? v1 : v2; }
+
+ FILE *fp;
+ if (!(fp = fopen("/proc/net/dev", "r"))) {
+ return 0;
+ }
+ char buf[256];
+ // Ignore first two lines
+ fgets(buf, 255, fp);
+ fgets(buf, 255, fp);
+ static int first_run = 1;
+ while (!feof(fp)) {
+ if (fgets(buf, 255, fp) == NULL) {
+ break;
+ }
+ char *p = buf;
+ while (isspace((int) *p)) p++;
+ char *curdev = p;
+ while (*p && *p != ':') p++;
+ if (*p == '\0') continue;
+ *p = '\0';
+
+ if (strcmp(curdev, graphs_netiface)) continue;
+
+ long long down, up;
+ sscanf(p+1, "%lld %*d %*d %*d %*d %*d %*d %*d %lld", &down, &up);
+ if (down < net.last_down) net.last_down = 0; // Overflow
+ if (up < net.last_up) net.last_up = 0; // Overflow
+ net.down[net.cur_idx] = (down - net.last_down);
+ net.up[net.cur_idx] = (up - net.last_up);
+ net.last_down = down;
+ net.last_up = up;
+ if (first_run) {
+ first_run = 0;
+ break;
+ }
+
+ unsigned int curtmp1 = 0;
+ unsigned int curtmp2 = 0;
+ // Average the samples
+ int i;
+ for (i = 0; i < graphs_net_nsamples_avg; i++) {
+ curtmp1 += net.down[(net.cur_idx + NET_SAMPLE_COUNT - i) %
+ NET_SAMPLE_COUNT];
+ curtmp2 += net.up[(net.cur_idx + NET_SAMPLE_COUNT - i) %
+ NET_SAMPLE_COUNT];
+ }
+ net.down_rate = curtmp1 / (double) graphs_net_nsamples_avg;
+ net.up_rate = curtmp2 / (double) graphs_net_nsamples_avg;
+ if (graphs_netmaxdown > 0)
+ {
+ net.down_rate /= (float) graphs_netmaxdown;
+ net.down_rate = min(1.0, net.down_rate);
+ }
+ else
+ {
+ // Normalize by maximum speed (a priori unknown,
+ // so we must do this all the time).
+ if (net.max_down < net.down_rate)
+ {
+ for (i = 0; i < graphs_graph_width; i++)
+ {
+ graph_values[graphs_net_pos][i] *= (net.max_down /
+ net.down_rate);
+ }
+ net.max_down = net.down_rate;
+ net.down_rate = 1.0;
+ }
+ else if (net.max_down != 0) net.down_rate /= net.max_down;
+ }
+ if (graphs_netmaxup > 0)
+ {
+ net.up_rate /= (float) graphs_netmaxup;
+ net.up_rate = min(1.0, net.up_rate);
+ }
+ else
+ {
+ if (net.max_up < net.up_rate)
+ {
+ for (i = 0; i < graphs_graph_width; i++)
+ {
+ graph_values[graphs_net_pos+1][i] *= (net.max_up /
+ net.up_rate);
+ }
+ net.max_up = net.up_rate;
+ net.up_rate = 1.0;
+ }
+ else if (net.max_up != 0) net.up_rate /= net.max_up;
+ }
+ net.cur_idx = (net.cur_idx + 1) % NET_SAMPLE_COUNT;
+ break; // Ignore the rest
+ }
+ fclose(fp);
+
+ graph_values[graphs_net_pos][pos_x] = net.down_rate;
+ graph_values[graphs_net_pos+1][pos_x] = net.up_rate;
+
+ return 0;
+}
+
+void update_graphs(void* arg)
+{
+ update_cpugraph();
+ update_memgraph();
+ update_netgraph();
+ int i;
+ for (i=0 ; i < nb_panel ; i++)
+ panel1[i].graphs.area.redraw = 1;
+ panel_refresh = 1;
+}
+
+void init_graphs()
+{
+ if (!graphs_enabled || !graphs_ngraphs)
+ return;
+
+ graphs_timeout = add_timeout(10, 1000, update_graphs, 0);
+ int i;
+ graph_values = (float **) malloc(graphs_ncurves * sizeof(float *));
+ for (i = 0; i < graphs_ncurves; i++)
+ {
+ unsigned int gsize = graphs_graph_width * sizeof(float);
+ graph_values[i] = malloc(gsize);
+ memset(graph_values[i], 0, gsize);
+ }
+}
+
+void init_graphs_panel(void *p)
+{
+ if (!graphs_enabled || !graphs_ngraphs)
+ return;
+
+ Panel *panel =(Panel*)p;
+ Graphs *graphs = &panel->graphs;
+
+ if (graphs->area.bg == 0)
+ graphs->area.bg = &g_array_index(backgrounds, Background, 0);
+ graphs->area.parent = p;
+ graphs->area.panel = p;
+ graphs->area._draw_foreground = draw_graphs;
+ graphs->area.size_mode = SIZE_BY_CONTENT;
+ graphs->area._resize = resize_graphs;
+
+ graphs->area.resize = 1;
+ graphs->area.on_screen = 1;
+}
+
+
+void draw_graphs (void *obj, cairo_t *c)
+{
+ Graphs *graphs = obj;
+
+ cairo_set_line_width (c, 1.0);
+ int i, i2, g, cv;
+ int x = graphs->area.paddingxlr + graphs->area.bg->border.width + 1;
+ int y1 = graphs->area.height - graphs->area.bg->border.width - graphs->area.paddingy;
+ for (g = 0, cv = 0; g < graphs_ngraphs; g++)
+ {
+ for (i2 = 0; i2 < graphs_curves_per_pos[g]; i2++, cv++)
+ {
+ cairo_set_source_rgba (c, graphs->g[cv].color[0], graphs->g[cv].color[1],
+ graphs->g[cv].color[2], graphs->g[cv].alpha);
+ for (i = 0; i < graphs_graph_width; i++)
+ {
+ int idx = (pos_x + 1 + i + graphs_graph_width) % graphs_graph_width;
+ int y2 = y1 - graph_values[cv][idx] * (y1 - graphs->area.bg->border.width -
+ graphs->area.paddingy);
+ if (graphs_use_bars) cairo_move_to (c, x + i, y1);
+ cairo_line_to (c, x + i, y2);
+ }
+ cairo_stroke (c);
+ }
+ x += graphs->area.paddingx + graphs_graph_width;
+ }
+ pos_x = (pos_x + 1) % graphs_graph_width;
+}
+
+
+int resize_graphs (void *obj)
+{
+ Graphs *graphs = obj;
+ int ret = 0;
+
+ graphs->area.redraw = 1;
+
+ if (panel_horizontal) {
+ int new_size = (2*graphs->area.paddingxlr) + (2*graphs->area.bg->border.width) +
+ graphs_ngraphs * (graphs_graph_width) +
+ (graphs_ngraphs - 1) * (graphs->area.paddingx);
+ if (new_size != graphs->area.width) {
+ graphs->area.width = new_size + 1;
+ ret = 1;
+ }
+ }
+
+ return ret;
+}
+
+
+void graphs_action(int button)
+{
+ char *command = 0;
+ switch (button) {
+ case 1:
+ command = graphs_lclick_command;
+ break;
+ case 3:
+ command = graphs_rclick_command;
+ break;
+ }
+ tint_exec(command);
+}
+
diff -ruN tint2.orig/src/graphs/graphs.h tint2.mine/src/graphs/graphs.h
--- tint2.orig/src/graphs/graphs.h 1970-01-01 01:00:00.000000000 +0100
+++ tint2.mine/src/graphs/graphs.h 2011-09-19 13:36:45.158311161 +0200
@@ -0,0 +1,52 @@
+/**************************************************************************
+* Copyright (C) 2011 Francisco J. Vazquez (fjvazquezaraujo@gmail.com)
+*
+**************************************************************************/
+
+#ifndef GRAPHS_H
+#define GRAPHS_H
+
+#include <sys/time.h>
+#include "common.h"
+#include "area.h"
+
+#define MAXGRAPHS 3
+#define MAXCURVES 6
+
+typedef struct Graphs {
+ // always start with area
+ Area area;
+
+ char *netdev;
+ Color g[MAXCURVES];
+} Graphs;
+
+extern int graphs_enabled;
+extern int graphs_ngraphs;
+extern int graphs_ncurves;
+extern int graphs_cpu_pos;
+extern int graphs_mem_pos;
+extern int graphs_net_pos;
+extern int graphs_curves_per_pos[MAXGRAPHS];
+extern int graphs_use_bars;
+extern int graphs_graph_width;
+extern char *graphs_netiface;
+extern int graphs_netmaxup;
+extern int graphs_netmaxdown;
+extern char *graphs_lclick_command;
+extern char *graphs_rclick_command;
+
+void default_graphs();
+
+void cleanup_graphs();
+
+void init_graphs();
+void init_graphs_panel(void *panel);
+
+void draw_graphs (void *obj, cairo_t *c);
+
+int resize_graphs (void *obj);
+
+void graphs_action(int button);
+
+#endif
diff -ruN tint2.orig/src/panel.c tint2.mine/src/panel.c
--- tint2.orig/src/panel.c 2011-09-19 12:38:00.000000000 +0200
+++ tint2.mine/src/panel.c 2011-09-19 12:46:47.171791151 +0200
@@ -141,6 +141,7 @@
init_systray();
init_launcher();
init_clock();
+ init_graphs();
#ifdef ENABLE_BATTERY
init_battery();
#endif
@@ -178,6 +179,8 @@
init_launcher_panel(p);
if (panel_items_order[k] == 'T')
init_taskbar_panel(p);
+ if (panel_items_order[k] == 'G')
+ init_graphs_panel(p);
#ifdef ENABLE_BATTERY
if (panel_items_order[k] == 'B')
init_battery_panel(p);
@@ -398,6 +401,8 @@
for (j=0 ; j < p->nb_desktop ; j++)
p->area.list = g_slist_append(p->area.list, &p->taskbar[j]);
}
+ if (panel_items_order[k] == 'G')
+ p->area.list = g_slist_append(p->area.list, &p->graphs);
#ifdef ENABLE_BATTERY
if (panel_items_order[k] == 'B')
p->area.list = g_slist_append(p->area.list, &p->battery);
@@ -676,6 +681,20 @@
}
+int click_graphs(Panel *panel, int x, int y)
+{
+ Graphs gr = panel->graphs;
+ if (panel_horizontal) {
+ if (gr.area.on_screen && x >= gr.area.posx && x <= (gr.area.posx + gr.area.width))
+ return TRUE;
+ } else {
+ if (gr.area.on_screen && y >= gr.area.posy && y <= (gr.area.posy + gr.area.height))
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
int click_clock(Panel *panel, int x, int y)
{
Clock clk = panel->clock;
diff -ruN tint2.orig/src/panel.h tint2.mine/src/panel.h
--- tint2.orig/src/panel.h 2011-09-19 12:38:00.000000000 +0200
+++ tint2.mine/src/panel.h 2011-09-19 12:46:47.171791151 +0200
@@ -16,6 +16,7 @@
#include "common.h"
#include "clock.h"
+#include "graphs.h"
#include "task.h"
#include "taskbar.h"
#include "systraybar.h"
@@ -103,6 +104,8 @@
// clock
Clock clock;
+ Graphs graphs;
+
// --------------------------------------------------
// battery
#ifdef ENABLE_BATTERY
@@ -151,6 +154,7 @@
Launcher *click_launcher (Panel *panel, int x, int y);
LauncherIcon *click_launcher_icon (Panel *panel, int x, int y);
int click_padding(Panel *panel, int x, int y);
+int click_graphs(Panel *panel, int x, int y);
int click_clock(Panel *panel, int x, int y);
Area* click_area(Panel *panel, int x, int y);
diff -ruN tint2.orig/src/tint.c tint2.mine/src/tint.c
--- tint2.orig/src/tint.c 2011-09-19 12:38:00.000000000 +0200
+++ tint2.mine/src/tint.c 2011-09-19 12:46:47.172791139 +0200
@@ -65,6 +65,7 @@
default_battery();
#endif
default_clock();
+ default_graphs();
default_launcher();
default_taskbar();
default_tooltip();
@@ -160,6 +161,7 @@
cleanup_systray();
cleanup_tooltip();
cleanup_clock();
+ cleanup_graphs();
cleanup_launcher();
#ifdef ENABLE_BATTERY
cleanup_battery();
@@ -427,6 +429,14 @@
break;
}
+ if ( click_graphs(panel, e->xbutton.x, e->xbutton.y)) {
+ graphs_action(e->xbutton.button);
+ if (panel_layer == BOTTOM_LAYER)
+ XLowerWindow (server.dsp, panel->main_win);
+ task_drag = 0;
+ return;
+ }
+
if ( click_clock(panel, e->xbutton.x, e->xbutton.y)) {
clock_action(e->xbutton.button);
if (panel_layer == BOTTOM_LAYER)