xdbe replaced with more generic pixmap based buffering but there are 3 major bugs:
[monky] / src / entropy.c
1 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
2  * vim: ts=4 sw=4 noet ai cindent syntax=c
3  *
4  * Conky, a system monitor, based on torsmo
5  *
6  * Any original torsmo code is licensed under the BSD license
7  *
8  * All code written since the fork of torsmo is licensed under the GPL
9  *
10  * Please see COPYING for details
11  *
12  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
13  * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
14  *      (see AUTHORS)
15  * All rights reserved.
16  *
17  * This program is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  * You should have received a copy of the GNU General Public License
27  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
28  *
29  */
30
31 #include "config.h"
32 #include "conky.h"
33 #include "text_object.h"
34
35 /* check for OS and include appropriate headers */
36 #if defined(__linux__)
37 #include "linux.h"
38 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
39 #include "freebsd.h"
40 #elif defined(__OpenBSD__)
41 #include "openbsd.h"
42 #endif
43
44 static struct {
45         unsigned int avail;
46         unsigned int poolsize;
47 } entropy = {
48         .avail = 0,
49         .poolsize = 0,
50 };
51
52 int update_entropy(void)
53 {
54         get_entropy_avail(&entropy.avail);
55         get_entropy_poolsize(&entropy.poolsize);
56         return 0;
57 }
58
59 void print_entropy_avail(struct text_object *obj, char *p, int p_max_size)
60 {
61         (void)obj;
62         snprintf(p, p_max_size, "%u", entropy.avail);
63 }
64
65 void print_entropy_perc(struct text_object *obj, char *p, int p_max_size)
66 {
67         (void)obj;
68         percent_print(p, p_max_size, entropy.avail *
69                         100 / entropy.poolsize);
70 }
71
72 void print_entropy_poolsize(struct text_object *obj, char *p, int p_max_size)
73 {
74         (void)obj;
75         snprintf(p, p_max_size, "%u", entropy.poolsize);
76 }
77
78 void print_entropy_bar(struct text_object *obj, char *p, int p_max_size)
79 {
80         double ratio;
81
82         (void)obj;
83
84         ratio = (double) entropy.avail /
85                 (double) entropy.poolsize;
86         new_bar(obj, p, p_max_size, (int) (ratio * 255.0f));
87 }