summaryrefslogtreecommitdiff
path: root/community/fbpanel/battery_fix.patch
blob: 3a86e3ca799735a9fe6d22f95f00c8dd3f519016 (plain)
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
*** fbpanel-6.1/plugins/battery/os_linux.c~	2010-04-08 12:35:26.000000000 +0200
--- fbpanel-6.1/plugins/battery/os_linux.c	2013-07-09 13:13:50.958994816 +0200
***************
*** 1,5 ****
--- 1,6 ----
  
  #include <string.h>
+ #include <stdlib.h>
  #include <ctype.h>
  
  #define LEN 100
***************
*** 120,129 ****
  }
  
  static gboolean
  battery_update_os_sys(battery_priv *c)
  {
      ENTER;
!     RET(FALSE);
  }
  
  static gboolean
--- 121,215 ----
  }
  
  static gboolean
+ read_sys(battery_priv *c, GString *path)
+ {
+     int len, dcap, rcap;
+     gchar *buf;
+     gboolean ret, exist, charging;
+ 
+     ENTER;
+     len = path->len;
+     
+     g_string_append(path, "/present");
+     ret = g_file_get_contents(path->str, &buf, 0, NULL);
+     DBG("reading %s %s\n", path->str, ret ? "ok" : "fail");
+     g_string_truncate(path, len);
+     if (!ret)
+         RET(FALSE);
+     exist = atoi(buf);
+     g_free(buf);
+     if (!exist)
+         RET(FALSE);
+ 
+     g_string_append(path, "/charge_full_design");
+     ret = g_file_get_contents(path->str, &buf, 0, NULL);
+     DBG("reading %s %s\n", path->str, ret ? "ok" : "fail");
+     g_string_truncate(path, len);
+     if (!ret)
+         RET(FALSE);
+     dcap = atoi(buf);
+     g_free(buf);
+     if (dcap <= 0)
+         RET(FALSE);
+ 
+     g_string_append(path, "/charge_now");
+     ret = g_file_get_contents(path->str, &buf, 0, NULL);
+     DBG("reading %s %s\n", path->str, ret ? "ok" : "fail");
+     g_string_truncate(path, len);
+     if (!ret)
+         RET(FALSE);
+     rcap = atoi(buf);
+     g_free(buf);
+     if (rcap <= 0)
+         RET(FALSE);
+ 
+     g_string_append(path, "/current_now");
+     ret = g_file_get_contents(path->str, &buf, 0, NULL);
+     DBG("reading %s %s\n", path->str, ret ? "ok" : "fail");
+     g_string_truncate(path, len);
+     if (!ret)
+         RET(FALSE);
+     charging = (atoi(buf) <= 0);
+     g_free(buf);
+ 
+     c->exist = exist;
+     c->charging = charging;
+     c->level = (int) ((gfloat) rcap * 100 / (gfloat) dcap);
+     RET(TRUE);
+ }
+ 
+ static gboolean
  battery_update_os_sys(battery_priv *c)
  {
+     GString *path;
+     int len;
+     GDir *dir;
+     gboolean ret = FALSE;
+     const gchar *file;
+     
      ENTER;
!     c->exist = FALSE;
!     path = g_string_sized_new(200);
!     g_string_append(path, "/sys/class/power_supply");
!     len = path->len;
!     if (!(dir = g_dir_open(path->str, 0, NULL))) {
!         DBG("can't open dir %s\n", path->str);
!         goto out;
!     }
!     while (!ret && (file = g_dir_read_name(dir))) {
!         g_string_append(path, "/");
!         g_string_append(path, file);
!         DBG("testing %s\n", path->str);
!         ret = g_file_test(path->str, G_FILE_TEST_IS_DIR);
!         if (ret) 
!             ret = read_sys(c, path);
!         g_string_truncate(path, len);
!     }    
!     g_dir_close(dir);
!         
! out:
!     g_string_free(path, TRUE);
!     RET(ret);
  }
  
  static gboolean