File: main.c

package info (click to toggle)
xfce4-diskperf-plugin 2.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,152 kB
  • sloc: sh: 4,154; ansic: 1,509; makefile: 61
file content (1082 lines) | stat: -rw-r--r-- 39,510 bytes parent folder | download
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
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
/*
 * This file is part of Xfce (https://gitlab.xfce.org).
 *
 * Copyright (c) 2003-2004 Roger Seguin <roger_seguin@msn.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * 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 Library 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "config_gui.h"
#include "devperf.h"

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <gtk/gtk.h>
#include <libxfce4panel/libxfce4panel.h>
#include <libxfce4ui/libxfce4ui.h>
#include <libxfce4util/libxfce4util.h>

#include <errno.h>
#include <inttypes.h>
#include <math.h>
#include <memory.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>

#define BORDER      8
#define PLUGIN_NAME "DiskPerf"


/* Some platforms do not provide busy times as separate read and write
   data, but only a single value combining both */
#if  defined(__NetBSD__)
#define SEPARATE_BUSY_TIMES 0
#elif  defined(__sun__)
#define SEPARATE_BUSY_TIMES 0
#elif defined(__linux__)
#define SEPARATE_BUSY_TIMES 1
#else
#define SEPARATE_BUSY_TIMES 1
#endif


typedef GtkWidget *Widget_t;

typedef enum statistics_t {
    IO_TRANSFER, /* MB transferred per second */
    BUSY_TIME    /* Percentage of time the device has been busy */
} statistics_t;

enum {
    /* Monitor bar data */
    R_DATA,
    W_DATA,
    RW_DATA,
    NMONITORS
};

typedef enum monitor_bar_order_t {
    RW_ORDER,
    WR_ORDER
} monitor_bar_order_t;

typedef struct param_t {
    /* Configurable parameters */
    char            acDevice[128];
#if  !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__sun__)
    dev_t           st_rdev;
#endif
    int             fTitleDisplayed;
    char            acTitle[16];
    enum statistics_t
                    eStatistics;
    enum monitor_bar_order_t
                    eMonitorBarOrder;
    int             iMaxXferMBperSec;
    int             fRW_DataCombined;
    uint32_t        iPeriod_ms;
    GdkRGBA         aoColor[NMONITORS];
} param_t;

typedef struct color_selector_t {
    Widget_t        wPB;
    Widget_t        wDA;
} color_selector_t;

typedef struct conf_t {
    Widget_t        wTopLevel;
    struct gui_t    oGUI; /* Configuration/option dialog */
    struct color_selector_t
                    aoColorWidgets[NMONITORS]; /* Color selection dialog */
    struct param_t  oParam;
} conf_t;

typedef struct perfbar_t {
    /* Individual monitor bar */
    Widget_t       *pwBar; /* Link to monitor_t:awProgressBar */
} perfbar_t;

typedef struct monitor_t {
    /* Plugin monitor bars */
    Widget_t         wEventBox;
    Widget_t         wBox;
    Widget_t         wTitle;
    Widget_t         awProgressBar[2];      /* Physical (widget) bars */
    struct perfbar_t aoPerfBar[NMONITORS];  /* Virtual bars */
    struct devperf_t oPrevPerf;
} monitor_t;

typedef struct diskperf_t {
    XfcePanelPlugin  *plugin;
    guint            iTimerId; /* Cyclic update */
    struct conf_t    oConf;
    struct monitor_t oMonitor;
    GtkTooltip       *gtkTooltip;
    char             tooltipText[256];
} diskperf_t;

static int timerNeedsUpdate = 0;

/* Update combined or separate progress bars with actual data */
static void UpdateProgressBars(struct diskperf_t *p_poPlugin, double rw, double r, double w) {
    struct monitor_t *poMonitor = &p_poPlugin->oMonitor;
    struct param_t *poConf = &p_poPlugin->oConf.oParam;
    struct perfbar_t *poPerf = poMonitor->aoPerfBar;

    if (poConf->fRW_DataCombined)
        gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR
                                       (*(poPerf[RW_DATA].pwBar)),
                                       rw);
    else {
        gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR
                                       (*(poPerf[R_DATA].pwBar)),
                                       r);
        gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR
                                       (*(poPerf[W_DATA].pwBar)),
                                       w);
    }
}

/* Get the last disk perfomance data, compute the statistics and update
   the panel-docked monitor bars */
static int DisplayPerf (struct diskperf_t *poPlugin)
{
    struct devperf_t  oPerf;
    struct param_t   *poConf = &poPlugin->oConf.oParam;
    struct monitor_t *poMonitor = &poPlugin->oMonitor;
#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__sun__)
    struct stat       oStat;
#endif
    uint64_t        iInterval_ns, rbytes, wbytes, iRBusy_ns, iWBusy_ns;
    const double    K = 1.0 * 1000 * 1000 * 1000 / 1024 / 1024;
    /* bytes/ns --> MiB/s */
    double          arPerf[NMONITORS], arBusy[NMONITORS], *prData, *pr;
    int             status, i;

    rbytes = wbytes = iRBusy_ns = iWBusy_ns = -1;
    memset (&oPerf, 0, sizeof (oPerf));
    oPerf.qlen = -1;
#if defined(__FreeBSD__) || defined (__NetBSD__) || defined(__OpenBSD__) || defined(__sun__)
    status = DevGetPerfData (poConf->acDevice, &oPerf);
#else
    if (poConf->st_rdev == 0)
        poConf->st_rdev = (stat (poConf->acDevice, &oStat) == -1 ? 0 : oStat.st_rdev);
    status = DevGetPerfData (&poConf->st_rdev, &oPerf);
#endif
    if (status == -1) {
        snprintf (poPlugin->tooltipText, G_N_ELEMENTS(poPlugin->tooltipText),
                  _("%s: Device statistics unavailable."), poConf->acTitle);
        UpdateProgressBars(poPlugin, 0, 0, 0);

        if(poPlugin->gtkTooltip)
            gtk_tooltip_set_text (poPlugin->gtkTooltip, poPlugin->tooltipText);

        return -1;
    }
    if (poMonitor->oPrevPerf.timestamp_ns) {
        iInterval_ns = oPerf.timestamp_ns - poMonitor->oPrevPerf.timestamp_ns;
        rbytes = oPerf.rbytes - poMonitor->oPrevPerf.rbytes;
        wbytes = oPerf.wbytes - poMonitor->oPrevPerf.wbytes;
        iRBusy_ns = oPerf.rbusy_ns - poMonitor->oPrevPerf.rbusy_ns;
        iWBusy_ns = oPerf.wbusy_ns - poMonitor->oPrevPerf.wbusy_ns;
    }
    else
        iInterval_ns = 0;
    poMonitor->oPrevPerf = oPerf;
    if (!iInterval_ns)
        return 1;

    arPerf[R_DATA] = K * rbytes / iInterval_ns;
    arPerf[W_DATA] = K * wbytes / iInterval_ns;
    arPerf[RW_DATA] = K * (rbytes + wbytes) / iInterval_ns;

    if (oPerf.qlen < 0)
        for (i = 0; i < NMONITORS; i++)
            arBusy[i] = 0;
    else {
        arBusy[R_DATA] = (double) 100.0 *iRBusy_ns / iInterval_ns;
        arBusy[W_DATA] = (double) 100.0 *iWBusy_ns / iInterval_ns;
        arBusy[RW_DATA] = (double) 100.0 *(iRBusy_ns + iWBusy_ns) / iInterval_ns;
        for (i = 0; i < NMONITORS; i++) {
            pr = arBusy + i;
            if (*pr > 100)
                *pr = 100;
        }
    }

    snprintf (poPlugin->tooltipText, G_N_ELEMENTS(poPlugin->tooltipText), _("%s\n"
              "----------------\n"
              "I/O (MiB/s)\n"
              "  Read: %3.2f\n"
              "  Write: %3.2f\n"
              "  Total: %3.2f\n"
              "Busy time (%c)\n"
#if SEPARATE_BUSY_TIMES
              "  Read: %d\n"
              "  Write: %d\n"
#endif
              "  Total: %d"),
              poConf->acTitle,
              arPerf[R_DATA],
              arPerf[W_DATA],
              arPerf[RW_DATA],
              '%',
#if SEPARATE_BUSY_TIMES
              (oPerf.qlen >= 0) ? (int) round(arBusy[R_DATA]) : -1,
              (oPerf.qlen >= 0) ? (int) round(arBusy[W_DATA]) : -1,
#endif
              (oPerf.qlen >= 0) ? (int) round(arBusy[RW_DATA]) : -1);

    if(poPlugin->gtkTooltip)
        gtk_tooltip_set_text (poPlugin->gtkTooltip, poPlugin->tooltipText);

    switch (poConf->eStatistics) {
        case BUSY_TIME:
            prData = arBusy;
            for (i = 0; i < NMONITORS; i++)
                prData[i] /= 100;
            break;
        case IO_TRANSFER:
        default:
            prData = arPerf;
            for (i = 0; i < NMONITORS; i++)
                prData[i] /= poConf->iMaxXferMBperSec;
            break;
    }
    for (i = 0; i < NMONITORS; i++) {
        pr = prData + i;
        if (*pr > 1)
            *pr = 1;
        else if (*pr < 0)
            *pr = 0;
    }
    UpdateProgressBars(poPlugin, prData[RW_DATA], prData[R_DATA], prData[W_DATA]);

    return 0;
}

static gboolean Timer (gpointer user_data)
{
    struct diskperf_t *poPlugin = user_data;

    DisplayPerf (poPlugin);
    return TRUE;
}

/* Recurrently update the panel-docked monitor bars through a timer */
static void SetTimer (diskperf_t *poPlugin)
{
    struct param_t *poConf = &poPlugin->oConf.oParam;

    if (timerNeedsUpdate) {
        if (G_LIKELY(poPlugin->iTimerId != 0)) {
            g_source_remove (poPlugin->iTimerId);
            poPlugin->iTimerId = 0;
        }
        timerNeedsUpdate = 0;
    }

    if (!poPlugin->iTimerId)
        poPlugin->iTimerId = g_timeout_add (poConf->iPeriod_ms, Timer, poPlugin);
}

/* Set the color of a single monitor bar */
static int SetSingleBarColor (struct diskperf_t *p_poPlugin, int p_iBar)
{
    gchar *css;
    struct diskperf_t *poPlugin = p_poPlugin;
    struct param_t    *poConf = &poPlugin->oConf.oParam;
    struct monitor_t  *poMonitor = &poPlugin->oMonitor;
    Widget_t          *pwBar;

    pwBar = poMonitor->aoPerfBar[p_iBar].pwBar;
#if GTK_CHECK_VERSION (3, 20, 0)
    css = g_strdup_printf("progressbar progress { background-color: %s; background-image: none; }",
#else
    css = g_strdup_printf(".progressbar progress { background-color: %s; background-image: none; }",
#endif
                                  gdk_rgba_to_string(&poConf->aoColor[p_iBar]));
    /* Setup Gtk style */
    DBG("setting css to %s for bar %d", css, p_iBar);
    gtk_css_provider_load_from_data (g_object_get_data(G_OBJECT(*pwBar), "css_provider"), css, strlen(css), NULL);
    g_free(css);
    return 0;
}

/* Set the monitor bar colors */
static int SetMonitorBarColor (struct diskperf_t *p_poPlugin)
{
    struct diskperf_t *poPlugin = p_poPlugin;
    struct param_t *poConf = &poPlugin->oConf.oParam;

    if (poConf->fRW_DataCombined)
        SetSingleBarColor (p_poPlugin, RW_DATA);
    else {
        SetSingleBarColor (p_poPlugin, R_DATA);
        SetSingleBarColor (p_poPlugin, W_DATA);
    }
    return 0;
}

/* Set order (Read-Write or Write-Read) and colors */
static int ResetMonitorBar (struct diskperf_t *p_poPlugin)
{
    struct diskperf_t *poPlugin = p_poPlugin;
    struct param_t *poConf = &poPlugin->oConf.oParam;
    struct monitor_t *poMonitor = &poPlugin->oMonitor;

    poMonitor->aoPerfBar[R_DATA].pwBar = poMonitor->awProgressBar + (poConf->eMonitorBarOrder == WR_ORDER);
    poMonitor->aoPerfBar[W_DATA].pwBar = poMonitor->awProgressBar + (poConf->eMonitorBarOrder == RW_ORDER);
    poMonitor->aoPerfBar[RW_DATA].pwBar = poMonitor->awProgressBar + 0;

    SetMonitorBarColor (poPlugin);

    return 0;
}

static gboolean
tooltip_cb (GtkWidget *widget, gint x, gint y, gboolean keyboard_tooltip, GtkTooltip *tooltip, gpointer user_data)
{
    struct diskperf_t *poPlugin = user_data;

    if (poPlugin->gtkTooltip != tooltip) {
        if (poPlugin->gtkTooltip) {
            g_object_unref (poPlugin->gtkTooltip);
            poPlugin->gtkTooltip = NULL;
        }
        poPlugin->gtkTooltip = tooltip;
        g_object_ref (tooltip);  /* TODO: Call g_object_unref() when the tooltip disappears from screen */
    }

    gtk_tooltip_set_text (tooltip, poPlugin->tooltipText);

    return TRUE;
}

/* Create the panel progressive bars */
static int CreateMonitorBars (struct diskperf_t *poPlugin, GtkOrientation p_iOrientation)
{
    GtkCssProvider   *css_provider;
    struct param_t   *poConf = &poPlugin->oConf.oParam;
    struct monitor_t *poMonitor = &poPlugin->oMonitor;
    Widget_t         *pwBar;
    int               i;

    poMonitor->wBox = gtk_box_new (p_iOrientation, 0);
    gtk_widget_show (poMonitor->wBox);

    gtk_container_add (GTK_CONTAINER (poMonitor->wEventBox), poMonitor->wBox);

    g_signal_connect (poMonitor->wEventBox, "query-tooltip", G_CALLBACK (tooltip_cb), poPlugin);
    gtk_widget_set_has_tooltip (poMonitor->wEventBox, TRUE);

    poMonitor->wTitle = gtk_label_new (poConf->acTitle);
    if (poConf->fTitleDisplayed)
        gtk_widget_show (poMonitor->wTitle);
    gtk_box_pack_start (GTK_BOX (poMonitor->wBox), GTK_WIDGET (poMonitor->wTitle), FALSE, FALSE, 2);

    for (i = 0; i < 2; i++) {
        pwBar = poMonitor->awProgressBar + i;
        *pwBar = GTK_WIDGET (gtk_progress_bar_new ());
        gtk_orientable_set_orientation (GTK_ORIENTABLE(*pwBar), !p_iOrientation);
        gtk_progress_bar_set_inverted (GTK_PROGRESS_BAR(*pwBar), p_iOrientation == GTK_ORIENTATION_HORIZONTAL);
        css_provider = gtk_css_provider_new ();
#if GTK_CHECK_VERSION (3, 20, 0)
        gtk_css_provider_load_from_data (css_provider, "\
            progressbar.horizontal trough { min-height: 4px; }\
            progressbar.horizontal progress { min-height: 4px; }\
            progressbar.vertical trough { min-width: 4px; }\
            progressbar.vertical progress { min-width: 4px; }",
#else
        gtk_css_provider_load_from_data (css_provider, "\
            .progressbar.horizontal trough { min-height: 4px; }\
            .progressbar.horizontal progress { min-height: 4px; }\
            .progressbar.vertical trough { min-width: 4px; }\
            .progressbar.vertical progress { min-width: 4px; }",
#endif
            -1, NULL);
        gtk_style_context_add_provider (
            GTK_STYLE_CONTEXT (gtk_widget_get_style_context (GTK_WIDGET (*pwBar))),
            GTK_STYLE_PROVIDER (css_provider),
            GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
        g_object_set_data(G_OBJECT(*pwBar), "css_provider", css_provider);

        if (i == 1 && poConf->fRW_DataCombined)
            gtk_widget_hide (GTK_WIDGET (*pwBar));
        else
            gtk_widget_show (GTK_WIDGET (*pwBar));

        gtk_box_pack_start (GTK_BOX (poMonitor->wBox), GTK_WIDGET (*pwBar), FALSE, FALSE, 0);
    }

    ResetMonitorBar (poPlugin);

    return 0;
}

/* Plugin API */
/* Create the diskperf */
static diskperf_t *diskperf_create_control (XfcePanelPlugin *plugin)
{
    struct diskperf_t *poPlugin;
    struct param_t *poConf;
    struct monitor_t *poMonitor;
#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__sun__)
    struct stat     oStat;
    int             status;
#endif

    poPlugin = g_new (diskperf_t, 1);
    memset (poPlugin, 0, sizeof (diskperf_t));
    poConf = &poPlugin->oConf.oParam;
    poMonitor = &poPlugin->oMonitor;

    poPlugin->plugin = plugin;
    
#if defined(__NetBSD__) || defined(__OpenBSD__)
    strncpy (poConf->acDevice, "wd0", 128);
    strncpy (poConf->acTitle, "wd0", 16);
#elif defined(__FreeBSD__)
    strncpy (poConf->acDevice, "ada0", 128);
    strncpy (poConf->acTitle, "ada0", 16);
#elif defined(__sun__)
    strncpy (poConf->acDevice, "sd0", 128);
    strncpy (poConf->acTitle, "sd0", 16);
#else
    strncpy (poConf->acDevice, "/dev/sda", 128);
    status = stat (poConf->acDevice, &oStat);
    poConf->st_rdev = (status == -1 ? 0 : oStat.st_rdev);
    strncpy (poConf->acTitle, "sda", 16);
#endif

    poConf->fTitleDisplayed = 1;

    gdk_rgba_parse (poConf->aoColor + R_DATA, "#0000FF");
    gdk_rgba_parse (poConf->aoColor + W_DATA, "#FF0000");
    gdk_rgba_parse (poConf->aoColor + RW_DATA, "#00FF00");

    poConf->iMaxXferMBperSec = 1024;
    poConf->fRW_DataCombined = 1;
    poConf->iPeriod_ms = 500;
    poConf->eStatistics = IO_TRANSFER;
    poConf->eMonitorBarOrder = RW_ORDER;
    poPlugin->iTimerId = 0;
    poPlugin->oMonitor.oPrevPerf.timestamp_ns = 0;

    poMonitor->wEventBox = gtk_event_box_new ();
    gtk_event_box_set_visible_window(GTK_EVENT_BOX(poMonitor->wEventBox), FALSE);
    gtk_event_box_set_above_child(GTK_EVENT_BOX(poMonitor->wEventBox), TRUE);
    gtk_widget_show (poMonitor->wEventBox);

    xfce_panel_plugin_add_action_widget (plugin, poMonitor->wEventBox);
    
    return poPlugin;
}

/* Plugin API */
static void diskperf_free (XfcePanelPlugin *plugin, diskperf_t *poPlugin)
{
    if (poPlugin->iTimerId)
        g_source_remove (poPlugin->iTimerId);
    g_free (poPlugin);
}

/* Configuration Keywords */
#define CONF_USE_LABEL          "UseLabel"
#define CONF_LABEL_TEXT         "Text"
#define CONF_DEVICE             "Device"
#define CONF_UPDATE_PERIOD      "UpdatePeriod"
#define CONF_STATISTICS         "Statistics"
#define CONF_XFER_RATE          "XferRate"
#define CONF_COMBINE_RW_DATA    "CombineRWdata"
#define CONF_MONITOR_BAR_ORDER  "MonitorBarOrder"
#define CONF_READ_COLOR         "ReadColor"
#define CONF_WRITE_COLOR        "WriteColor"
#define CONF_READ_WRITE_COLOR   "ReadWriteColor"

/* Plugin API */
/* Executed when the panel is started - Read the configuration
   previously stored in xml file */
static void diskperf_read_config (XfcePanelPlugin *plugin,
                                  diskperf_t *poPlugin)
{
    const char *value;
    char *file;
    XfceRc *rc;
    struct param_t *poConf = &poPlugin->oConf.oParam;
    struct monitor_t *poMonitor = &poPlugin->oMonitor;
    Widget_t       *pw2ndBar = poPlugin->oMonitor.awProgressBar + 1;
#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__sun__)
    struct stat     oStat;
    int             status;
#endif
    
    if (!(file = xfce_panel_plugin_lookup_rc_file (plugin)))
        return;
    
    rc = xfce_rc_simple_open (file, TRUE);
    g_free (file);

    if (!rc)
        return;
    
    if ((value = xfce_rc_read_entry (rc, (CONF_DEVICE), NULL))) {
        memset (poConf->acDevice, 0, sizeof (poConf->acDevice));
        strncpy (poConf->acDevice, value, sizeof (poConf->acDevice) - 1);
#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__sun__)
        status = stat (poConf->acDevice, &oStat);
        poConf->st_rdev = (status == -1 ? 0 : oStat.st_rdev);
#endif
    }

    poConf->fTitleDisplayed = xfce_rc_read_int_entry (rc, (CONF_USE_LABEL), 1);

    if (poConf->fTitleDisplayed)
        gtk_widget_show (GTK_WIDGET (poMonitor->wTitle));
    else
        gtk_widget_hide (GTK_WIDGET (poMonitor->wTitle));

    /* unset small if we are in deskbar mode and we want the title */
    if (poConf->fTitleDisplayed && xfce_panel_plugin_get_mode(poPlugin->plugin) == XFCE_PANEL_PLUGIN_MODE_DESKBAR)
      xfce_panel_plugin_set_small (XFCE_PANEL_PLUGIN (poPlugin->plugin), FALSE);
    else
      xfce_panel_plugin_set_small (XFCE_PANEL_PLUGIN (poPlugin->plugin), TRUE);

    if ((value = xfce_rc_read_entry (rc, (CONF_LABEL_TEXT), NULL))) {
        memset (poConf->acTitle, 0, sizeof (poConf->acTitle));
        strncpy (poConf->acTitle, value, sizeof (poConf->acTitle) - 1);
        gtk_label_set_text (GTK_LABEL (poMonitor->wTitle), poConf->acTitle);
    }

    poConf->iPeriod_ms = xfce_rc_read_int_entry (rc, (CONF_UPDATE_PERIOD), 500);
    poConf->eStatistics = xfce_rc_read_int_entry (rc, (CONF_STATISTICS), IO_TRANSFER);

    poConf->iMaxXferMBperSec = xfce_rc_read_int_entry (rc, (CONF_XFER_RATE), 1024);

    poConf->fRW_DataCombined = xfce_rc_read_int_entry (rc, (CONF_COMBINE_RW_DATA), 1);

    if (poConf->fRW_DataCombined)
        gtk_widget_hide (GTK_WIDGET (*pw2ndBar));
    else
        gtk_widget_show (GTK_WIDGET (*pw2ndBar));

    poConf->eMonitorBarOrder = xfce_rc_read_int_entry (rc, (CONF_MONITOR_BAR_ORDER), RW_ORDER);

    if ((value = xfce_rc_read_entry (rc, (CONF_READ_COLOR), NULL))) {
        gdk_rgba_parse (poConf->aoColor + R_DATA, value);
    }

    if ((value = xfce_rc_read_entry (rc, (CONF_WRITE_COLOR), NULL))) {
        gdk_rgba_parse (poConf->aoColor + W_DATA, value);
    }

    if ((value = xfce_rc_read_entry (rc, (CONF_READ_WRITE_COLOR), NULL))) {
        gdk_rgba_parse (poConf->aoColor + RW_DATA, value);
    }
    ResetMonitorBar (poPlugin);

    xfce_rc_close (rc);
}

/* Plugin API */
/* Write diskperf configuration into xml file */
static void diskperf_write_config (XfcePanelPlugin *plugin, 
                                   diskperf_t *poPlugin)
{
    struct param_t *poConf = &poPlugin->oConf.oParam;
    XfceRc *rc;
    char *file;

    if (!(file = xfce_panel_plugin_save_location (plugin, TRUE)))
        return;
    
    rc = xfce_rc_simple_open (file, FALSE);
    g_free (file);

    if (!rc)
        return;
    
    xfce_rc_write_entry (rc, CONF_DEVICE, poConf->acDevice);

    xfce_rc_write_int_entry (rc, CONF_USE_LABEL, poConf->fTitleDisplayed);

    xfce_rc_write_entry (rc, CONF_LABEL_TEXT, poConf->acTitle);

    xfce_rc_write_int_entry (rc, CONF_UPDATE_PERIOD, poConf->iPeriod_ms);

    xfce_rc_write_int_entry (rc, CONF_STATISTICS, poConf->eStatistics);

    xfce_rc_write_int_entry (rc, CONF_XFER_RATE, poConf->iMaxXferMBperSec);

    xfce_rc_write_int_entry (rc, CONF_COMBINE_RW_DATA, poConf->fRW_DataCombined);

    xfce_rc_write_int_entry (rc, CONF_MONITOR_BAR_ORDER, poConf->eMonitorBarOrder);

    xfce_rc_write_entry (rc, CONF_READ_COLOR, gdk_rgba_to_string(poConf->aoColor + R_DATA));
    xfce_rc_write_entry (rc, CONF_WRITE_COLOR, gdk_rgba_to_string(poConf->aoColor + W_DATA));
    xfce_rc_write_entry (rc, CONF_READ_WRITE_COLOR, gdk_rgba_to_string(poConf->aoColor + RW_DATA));

    xfce_rc_close (rc);
}

/* GUI callback setting the device name, whose performance will be
   displayed using the panel-docked monitor bars */
static void SetDevice (Widget_t p_wTF, void *p_pvPlugin)
{
    struct diskperf_t *poPlugin = (diskperf_t *) p_pvPlugin;
    struct param_t    *poConf = &poPlugin->oConf.oParam;
    const char        *pcDevice = gtk_entry_get_text (GTK_ENTRY (p_wTF));
#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__sun__)
    struct stat oStat;

    stat (pcDevice, &oStat);
    poConf->st_rdev = oStat.st_rdev;
#endif
    memset (poConf->acDevice, 0, sizeof (poConf->acDevice));
    strncpy (poConf->acDevice, pcDevice, sizeof (poConf->acDevice) - 1);
}

/* GUI callback turning on/off the monitor bar legend */
static void ToggleTitle (Widget_t p_w, void *p_pvPlugin)
{
    struct diskperf_t *poPlugin = (diskperf_t *) p_pvPlugin;
    struct param_t    *poConf = &poPlugin->oConf.oParam;
    struct monitor_t  *poMonitor = &poPlugin->oMonitor;

    poConf->fTitleDisplayed = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (p_w));
    if (poConf->fTitleDisplayed)
        gtk_widget_show (GTK_WIDGET (poMonitor->wTitle));
    else
        gtk_widget_hide (GTK_WIDGET (poMonitor->wTitle));

    /* unset small if we are in deskbar mode and we want the title */
    if (poConf->fTitleDisplayed && xfce_panel_plugin_get_mode(poPlugin->plugin) == XFCE_PANEL_PLUGIN_MODE_DESKBAR)
        xfce_panel_plugin_set_small (XFCE_PANEL_PLUGIN (poPlugin->plugin), FALSE);
    else
        xfce_panel_plugin_set_small (XFCE_PANEL_PLUGIN (poPlugin->plugin), TRUE);
}

/* GUI callback setting the legend of the monitor bars */
static void SetLabel (Widget_t p_wTF, void *p_pvPlugin)
{
    struct diskperf_t *poPlugin = (diskperf_t *) p_pvPlugin;
    struct param_t    *poConf = &poPlugin->oConf.oParam;
    struct monitor_t  *poMonitor = &poPlugin->oMonitor;
    const char        *acTitle = gtk_entry_get_text (GTK_ENTRY (p_wTF));

    memset (poConf->acTitle, 0, sizeof (poConf->acTitle));
    strncpy (poConf->acTitle, acTitle, sizeof (poConf->acTitle) - 1);
    gtk_label_set_text (GTK_LABEL (poMonitor->wTitle), poConf->acTitle);
}

/* GUI callback allowing to choose statistics to monitor */
static void ToggleStatistics (Widget_t p_w, void *p_pvPlugin)
{
    struct diskperf_t *poPlugin = (diskperf_t *) p_pvPlugin;
    struct param_t    *poConf = &poPlugin->oConf.oParam;
    struct gui_t      *poGUI = &poPlugin->oConf.oGUI;

    poConf->eStatistics = !(poConf->eStatistics);
    DBG ("%d", poConf->eStatistics);
    switch (poConf->eStatistics) {
        case BUSY_TIME:
            gtk_widget_hide (GTK_WIDGET (poGUI->wHBox_MaxIO));
            if (!SEPARATE_BUSY_TIMES) {
                poConf->fRW_DataCombined = 1;
                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (poGUI->wTB_RWcombined),
                                              poConf->fRW_DataCombined);
            }
            break;
        case IO_TRANSFER:
        default:
            gtk_widget_show (GTK_WIDGET (poGUI->wHBox_MaxIO));
    }
    gtk_widget_set_sensitive (GTK_WIDGET (poGUI->wTB_RWcombined),
                              (poConf->eStatistics != BUSY_TIME) || SEPARATE_BUSY_TIMES);
}

/* GUI callback allowing either to combine write + read data in a
   single monitor bar, or to keep them separate using 2 dedicated
   monitor bars */
static void ToggleRWintegration (Widget_t p_w, void *p_pvPlugin)
{
    struct diskperf_t *poPlugin = (diskperf_t *) p_pvPlugin;
    struct param_t    *poConf = &poPlugin->oConf.oParam;
    struct gui_t      *poGUI = &poPlugin->oConf.oGUI;
    Widget_t          *pw2ndBar = poPlugin->oMonitor.awProgressBar + 1;

    poConf->fRW_DataCombined = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (p_w));
    DBG ("%d", poConf->fRW_DataCombined);
    if (poConf->fRW_DataCombined) {
        gtk_widget_hide (GTK_WIDGET (poGUI->wTa_DualBars));
        gtk_widget_show (GTK_WIDGET (poGUI->wTa_SingleBar));
        gtk_widget_hide (GTK_WIDGET (*pw2ndBar));
    }
    else {
        gtk_widget_hide (GTK_WIDGET (poGUI->wTa_SingleBar));
        gtk_widget_show (GTK_WIDGET (poGUI->wTa_DualBars));
        gtk_widget_show (GTK_WIDGET (*pw2ndBar));
    }
    SetMonitorBarColor (poPlugin);
}

/* GUI callback allowing to swap Read/Write monitor bars */
static void ToggleRWorder (Widget_t p_w, void *p_pvPlugin)
{
    struct diskperf_t *poPlugin = (diskperf_t *) p_pvPlugin;
    struct param_t    *poConf = &poPlugin->oConf.oParam;

    poConf->eMonitorBarOrder = !(poConf->eMonitorBarOrder);
    DBG ("%d", poConf->eMonitorBarOrder);
    ResetMonitorBar (poPlugin);
    DisplayPerf (poPlugin);
}

/* GUI callback setting the maximum I/O transfer rate of the device */
static void SetXferRate (Widget_t p_wTF, void *p_pvPlugin)
{
    struct diskperf_t *poPlugin = (diskperf_t *) p_pvPlugin;
    struct param_t    *poConf = &poPlugin->oConf.oParam;
    const char        *pcXferRate = gtk_entry_get_text (GTK_ENTRY (p_wTF));

    poConf->iMaxXferMBperSec = atoi(pcXferRate);
    if (poConf->iMaxXferMBperSec > INT16_MAX - 2)
        poConf->iMaxXferMBperSec = INT16_MAX - 2;
    else if (poConf->iMaxXferMBperSec < 5)
        poConf->iMaxXferMBperSec = 5;
    DBG("XferRate set to %d Mib/s\n", poConf->iMaxXferMBperSec);
}

/* Set the update period - To be used by the timer */
static void SetPeriod (Widget_t p_wSc, void *p_pvPlugin)
{
    struct diskperf_t *poPlugin = (diskperf_t *) p_pvPlugin;
    struct param_t    *poConf = &poPlugin->oConf.oParam;
    float              r;

    timerNeedsUpdate = 1;
    r = gtk_spin_button_get_value (GTK_SPIN_BUTTON (p_wSc));
    poConf->iPeriod_ms = round(r * 1000);
    DBG("Update period rounded to %dms\n", poConf->iPeriod_ms);
}

static void ChooseColor (Widget_t p_wPB, void *p_pvPlugin)
{
    struct diskperf_t *poPlugin = (diskperf_t *) p_pvPlugin;
    struct param_t    *poConf = &poPlugin->oConf.oParam;
    struct gui_t      *poGUI = &poPlugin->oConf.oGUI;
    GdkRGBA            poColor;
    int                iPerfBar;

    if (p_wPB == poGUI->wPB_Rcolor)
        iPerfBar = R_DATA;
    else if (p_wPB == poGUI->wPB_Wcolor)
        iPerfBar = W_DATA;
    else if (p_wPB == poGUI->wPB_RWcolor)
        iPerfBar = RW_DATA;
    else
        return;

    gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(p_wPB), &poColor);
    DBG("color changed to %s for monitor %d", gdk_rgba_to_string(&poColor), iPerfBar);
    poConf->aoColor[iPerfBar] = poColor;
    SetMonitorBarColor (poPlugin);
}

/* Called back when the configuration/options window is closed */
static void UpdateConf (diskperf_t *poPlugin)
{
    struct conf_t *poConf = &poPlugin->oConf;
    struct gui_t  *poGUI = &poConf->oGUI;

    SetDevice (poGUI->wTF_Device, poPlugin);
    SetLabel (poGUI->wTF_Title, poPlugin);
    SetXferRate (poGUI->wTF_MaxXfer, poPlugin);
    DisplayPerf (poPlugin);
    SetTimer (poPlugin);
}

/* Check disk performance statistics availability */
/* Return 0 on success, -1 otherwise */
static int CheckStatsAvailability (void)
{
    const char *pcStatFile = 0;
    int         status;

    status = DevCheckStatAvailability (&pcStatFile);
    if (!status)
        return 0;
    if (status < 0) {
        status *= -1;
        xfce_dialog_show_error (NULL, NULL,
            _("%s\n"
            "%s: %s (%d)\n\n"
            "This monitor will not work!\n"
            "Please remove it."),
            PLUGIN_NAME, (pcStatFile ? pcStatFile : ""),
            strerror (status), status);
        return -1;
    }
    switch (status) {
        case NO_EXTENDED_STATS:
            xfce_dialog_show_error (NULL, NULL,
                _("%s: No disk extended statistics found!\n"
                "Either old kernel (< 2.4.20) or not\n"
                "compiled with CONFIG_BLK_STATS turned on.\n\n"
                "This monitor will not work!\n"
                "Please remove it."), PLUGIN_NAME);
            break;
        default:
            xfce_dialog_show_error (NULL, NULL,
                _("%s: Unknown error\n\n"
                "This monitor will not work!\n"
                "Please remove it."), PLUGIN_NAME);
    }
    return -1;
}

/* Called back when the About button in clicked */
static void About (Widget_t w, void *unused)
{
    /* List of authors (in alphabetical order) */
    const gchar *auth[] = {
        "Benedikt Meurer <benedikt.meurer@unix-ag.uni-siegen.de>",
        "Jan Ziak <0xe2.0x9a.0x9b@xfce.org>",
        "Peter Tribble <peter.tribble@gmail.com>",
        "Roger Seguin <roger_seguin@msn.com>",
        NULL
    };
    GdkPixbuf *icon;

    icon = xfce_panel_pixbuf_from_source("drive-harddisk", NULL, 32);
    gtk_show_about_dialog(NULL,
        "logo", icon,
        "license", xfce_get_license_text (XFCE_LICENSE_TEXT_BSD),
        "version", PACKAGE_VERSION,
        "program-name", PACKAGE_NAME,
        "comments", _("Diskperf monitor displays instantaneous disk I/O transfer rates and busy times"),
        "website", "https://docs.xfce.org/panel-plugins/xfce4-diskperf-plugin",
        "copyright", _("Copyright (c) 2003, 2004 Roger Seguin"),
        "authors", auth, NULL);
    if(icon)
        g_object_unref(G_OBJECT(icon));
}

static void diskperf_dialog_response (GtkWidget *dlg, int response, 
                                      diskperf_t *diskperf)
{
    UpdateConf (diskperf);
    gtk_widget_destroy (dlg);
    xfce_panel_plugin_unblock_menu (diskperf->plugin);
    diskperf_write_config (diskperf->plugin, diskperf);
}

/* Plugin API */
/* Create/pop up the configuration/options GUI */
static void diskperf_create_options (XfcePanelPlugin *plugin,
                                     diskperf_t *poPlugin)
{
    GtkWidget *dlg, *vbox;
    struct param_t *poConf = &poPlugin->oConf.oParam;
    struct gui_t   *poGUI = &poPlugin->oConf.oGUI;
    char            acBuffer[16];
    Widget_t       *apwColorPB[NMONITORS];
    int             i;

    (void) CheckStatsAvailability ();

    xfce_panel_plugin_block_menu (plugin);
    
    dlg = xfce_titled_dialog_new_with_buttons (_("Disk Performance Monitor"),
                                               GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (plugin))),
                                               GTK_DIALOG_DESTROY_WITH_PARENT,
                                               "gtk-close", GTK_RESPONSE_OK,
                                               NULL);

    gtk_window_set_resizable (GTK_WINDOW (dlg), FALSE);
    
    g_signal_connect (G_OBJECT (dlg), "response", G_CALLBACK (diskperf_dialog_response), poPlugin);

    gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_CENTER);
    gtk_window_set_icon_name (GTK_WINDOW (dlg), "drive-harddisk");
    
    vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 18);
    gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
    gtk_widget_show(vbox);
    gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area(GTK_DIALOG (dlg))), vbox, TRUE, TRUE, 0);
    
    poPlugin->oConf.wTopLevel = dlg;

    CreateConfigGUI (vbox, poGUI);

    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (poGUI->wTB_Title), poConf->fTitleDisplayed);
    g_signal_connect (GTK_WIDGET (poGUI->wTB_Title), "toggled", G_CALLBACK (ToggleTitle), poPlugin);

    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (poGUI->wRB_IO), poConf->eStatistics == IO_TRANSFER);
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (poGUI->wRB_BusyTime), poConf->eStatistics == BUSY_TIME);
    if (poConf->eStatistics == IO_TRANSFER)
        gtk_widget_show (GTK_WIDGET (poGUI->wHBox_MaxIO));
    else {
        gtk_widget_hide (GTK_WIDGET (poGUI->wHBox_MaxIO));
        if (!SEPARATE_BUSY_TIMES)
            poConf->fRW_DataCombined = 1;
    }
    g_signal_connect (GTK_WIDGET (poGUI->wRB_IO), "toggled", G_CALLBACK (ToggleStatistics), poPlugin);

    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (poGUI->wTB_RWcombined), poConf->fRW_DataCombined);
    gtk_widget_set_sensitive (GTK_WIDGET (poGUI->wTB_RWcombined),
                              (poConf->eStatistics != BUSY_TIME) || SEPARATE_BUSY_TIMES);
    if (poConf->fRW_DataCombined) {
        gtk_widget_hide (GTK_WIDGET (poGUI->wTa_DualBars));
        gtk_widget_show (GTK_WIDGET (poGUI->wTa_SingleBar));
    }
    else {
        gtk_widget_hide (GTK_WIDGET (poGUI->wTa_SingleBar));
        gtk_widget_show (GTK_WIDGET (poGUI->wTa_DualBars));
    }
    g_signal_connect (GTK_WIDGET (poGUI->wTB_RWcombined), "toggled",
                      G_CALLBACK (ToggleRWintegration), poPlugin);

    gtk_entry_set_text (GTK_ENTRY (poGUI->wTF_Device), poConf->acDevice);
    g_signal_connect (GTK_WIDGET (poGUI->wTF_Device), "activate", G_CALLBACK (SetDevice), poPlugin);

    gtk_entry_set_text (GTK_ENTRY (poGUI->wTF_Title), poConf->acTitle);
    g_signal_connect (GTK_WIDGET (poGUI->wTF_Title), "activate", G_CALLBACK (SetLabel), poPlugin);

    snprintf (acBuffer, G_N_ELEMENTS (acBuffer), "%d", poConf->iMaxXferMBperSec);
    gtk_entry_set_text (GTK_ENTRY (poGUI->wTF_MaxXfer), acBuffer);
    g_signal_connect (GTK_WIDGET (poGUI->wTF_MaxXfer), "activate", G_CALLBACK (SetXferRate), poPlugin);

    gtk_spin_button_set_value (GTK_SPIN_BUTTON (poGUI->wSc_Period), ((double) poConf->iPeriod_ms) / 1000);
    g_signal_connect (GTK_WIDGET (poGUI->wSc_Period), "value_changed", G_CALLBACK (SetPeriod), poPlugin);

    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (poGUI->wRB_ReadWriteOrder),
                                  poConf->eMonitorBarOrder == RW_ORDER);
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (poGUI->wRB_WriteReadOrder),
                                  poConf->eMonitorBarOrder == WR_ORDER);
    g_signal_connect (GTK_WIDGET (poGUI->wRB_ReadWriteOrder), "toggled",
                      G_CALLBACK (ToggleRWorder), poPlugin);

    apwColorPB[R_DATA] = &poGUI->wPB_Rcolor;
    apwColorPB[W_DATA] = &poGUI->wPB_Wcolor;
    apwColorPB[RW_DATA] = &poGUI->wPB_RWcolor;
    for (i = 0; i < NMONITORS; i++) {
        gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(*(apwColorPB[i])), poConf->aoColor + i);
        g_signal_connect (GTK_WIDGET (*(apwColorPB[i])), "color-set", G_CALLBACK (ChooseColor), poPlugin);
    }

    gtk_widget_show (dlg);
}

/* Plugin API */
/* Set the size of the panel-docked monitor bars */
static gboolean diskperf_set_size (XfcePanelPlugin *plugin, int p_size, diskperf_t *poPlugin)
{
    int              i, size1, size2;
    Widget_t         *pwBar;
    struct monitor_t *poMonitor = &poPlugin->oMonitor;

    DBG ("%d", p_size);
    gtk_container_set_border_width (GTK_CONTAINER (poMonitor->wBox), p_size > 26 ? 2 : 1);
    if (xfce_panel_plugin_get_orientation (plugin) == GTK_ORIENTATION_HORIZONTAL) {
        size1 = 8;
        size2 = -1;
        gtk_widget_set_size_request (GTK_WIDGET (plugin), -1, p_size);
    }
    else {
        size1 = -1;
        size2 = 8;
        gtk_widget_set_size_request (GTK_WIDGET (plugin), p_size, -1);
    }
    for (i = 0; i < 2; i++) {
        pwBar = poPlugin->oMonitor.awProgressBar + i;
        gtk_widget_set_size_request (GTK_WIDGET (*pwBar), size1, size2);
    }

    return TRUE;
}

/* Plugin API */
/* Invoked when the panel changes mode */
static void diskperf_set_mode (XfcePanelPlugin *plugin,
                               XfcePanelPluginMode p_iMode,
                               diskperf_t *poPlugin)
{
    struct monitor_t *poMonitor = &poPlugin->oMonitor;
    int i;
    Widget_t *pwBar;
    GtkOrientation p_iOrientation;

    DBG ("%d", p_iMode);

    p_iOrientation =
      (p_iMode == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL) ?
      GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;

    gtk_orientable_set_orientation(GTK_ORIENTABLE(poMonitor->wBox), p_iOrientation);

    for (i = 0; i < 2; i++) {
        pwBar = poPlugin->oMonitor.awProgressBar + i;
        gtk_orientable_set_orientation (GTK_ORIENTABLE(*pwBar), !p_iOrientation);
        gtk_progress_bar_set_inverted (GTK_PROGRESS_BAR(*pwBar),
                                       p_iOrientation == GTK_ORIENTATION_HORIZONTAL);
    }
    gtk_label_set_angle (GTK_LABEL (poMonitor->wTitle),
                         (p_iMode != XFCE_PANEL_PLUGIN_MODE_VERTICAL) ? 0 : 270);
    /* unset small if we are in deskbar mode and we want the title */
    if (poPlugin->oConf.oParam.fTitleDisplayed && p_iMode == XFCE_PANEL_PLUGIN_MODE_DESKBAR)
        xfce_panel_plugin_set_small (XFCE_PANEL_PLUGIN (plugin), FALSE);
    else
        xfce_panel_plugin_set_small (XFCE_PANEL_PLUGIN (plugin), TRUE);

    diskperf_set_size (plugin, xfce_panel_plugin_get_size (plugin), poPlugin);
}

static void diskperf_construct (XfcePanelPlugin *plugin)
{
    diskperf_t *diskperf = diskperf_create_control (plugin);
    xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");

    g_signal_connect (plugin, "free-data", G_CALLBACK (diskperf_free), diskperf);
    g_signal_connect (plugin, "save", G_CALLBACK (diskperf_write_config), diskperf);
    g_signal_connect (plugin, "size-changed", G_CALLBACK (diskperf_set_size), diskperf);
    g_signal_connect (plugin, "mode-changed", G_CALLBACK (diskperf_set_mode), diskperf);
    xfce_panel_plugin_set_small (plugin, TRUE);

    xfce_panel_plugin_menu_show_about (plugin);
    g_signal_connect (plugin, "about", G_CALLBACK (About), NULL);

    xfce_panel_plugin_menu_show_configure (plugin);
    g_signal_connect (plugin, "configure-plugin", G_CALLBACK (diskperf_create_options), diskperf);

    gtk_container_add (GTK_CONTAINER (plugin), diskperf->oMonitor.wEventBox);

    CreateMonitorBars (diskperf, xfce_panel_plugin_get_orientation (plugin));
    
    diskperf_read_config (plugin, diskperf);
    DevPerfInit();
    
    DisplayPerf (diskperf);
    SetTimer (diskperf);
}

XFCE_PANEL_PLUGIN_REGISTER (diskperf_construct);