]> Dogcows Code - chaz/tint2/commitdiff
*add* use ACPI api for freebsd (thx to yamagi.burmeister)
authorAndreas Fink <andreas.fink85@googlemail.com>
Sat, 26 Jun 2010 16:19:18 +0000 (16:19 +0000)
committerAndreas Fink <andreas.fink85@googlemail.com>
Sat, 26 Jun 2010 16:19:18 +0000 (16:19 +0000)
ChangeLog
src/battery/battery.c

index 3d3bd07243e6c7c484ed722a91b5783706b80cf5..cc0222e2fea9335f086a022c584d6af213804c61 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-06-26
+- unhide tint2 panel when dragging something
+- battery FreeBSD uses the new ACPI API (thx to yamagi.burmeister)
+
 2010-06-16
 - Set _NET_WM_ICON_GEOMETRY for every task
 
index 4bbde3cb2763fb6e3a1b529435e50eae85acd367..b20b7d3193b911eaee818cf8f9a86c5fb893628f 100644 (file)
 #include <cairo-xlib.h>
 #include <pango/pangocairo.h>
 
-#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__OpenBSD__) || defined(__NetBSD__)
 #include <machine/apmvar.h>
 #include <err.h>
 #include <sys/ioctl.h>
 #include <unistd.h>
 #endif
 
+#if defined(__FreeBSD__)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif
+
 #include "window.h"
 #include "server.h"
 #include "area.h"
@@ -59,11 +64,10 @@ char *path_energy_full;
 char *path_current_now;
 char *path_status;
 
-#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__OpenBSD__) || defined(__NetBSD__)
 int apm_fd;
 #endif
 
-
 void update_batterys(void* arg)
 {
        int i;
@@ -103,7 +107,7 @@ void default_battery()
        path_energy_full = 0;
        path_current_now = 0;
        path_status = 0;
-#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__OpenBSD__) || defined(__NetBSD__)
        apm_fd = -1;
 #endif
 }
@@ -118,7 +122,7 @@ void cleanup_battery()
        if (path_status) g_free(path_status);
        if (battery_low_cmd) g_free(battery_low_cmd);
 
-#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__OpenBSD__) || defined(__NetBSD__)
        if ((apm_fd != -1) && (close(apm_fd) == -1))
                warn("cannot close /dev/apm");
 #endif
@@ -129,7 +133,7 @@ void init_battery()
 {
        if (!battery_enabled) return;
 
-#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__OpenBSD__) || defined(__NetBSD__)
        apm_fd = open("/dev/apm", O_RDONLY);
        if (apm_fd < 0) {
                warn("init_battery: failed to open /dev/apm.");
@@ -137,7 +141,7 @@ void init_battery()
                return;
        }
 
-#else
+#elif !defined(__FreeBSD__)
        // check battery
        GDir *directory = 0;
        GError *error = NULL;
@@ -258,17 +262,21 @@ void init_battery_panel(void *p)
 
 
 void update_battery() {
-#if !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__NetBSD__)
+#if !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__FreeBSD__)
        // unused on OpenBSD, silence compiler warnings
        FILE *fp;
        char tmp[25];
        int64_t current_now = 0;
+#endif
+#if defined(__FreeBSD__)
+       int sysctl_out =  0;
+       size_t len = 0;
 #endif
        int64_t energy_now = 0, energy_full = 0;
        int seconds = 0;
        int8_t new_percentage = 0;
 
-#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__OpenBSD__) || defined(__NetBSD__)
        struct apm_power_info info;
        if (ioctl(apm_fd, APM_IOC_GETPOWER, &(info)) < 0)
                warn("power update: APM_IOC_GETPOWER");
@@ -298,6 +306,45 @@ void update_battery() {
 
        new_percentage = info.battery_life;
 
+#elif defined(__FreeBSD__)
+       len = sizeof(sysctl_out);
+
+       if (sysctlbyname("hw.acpi.battery.state", &sysctl_out, &len, NULL, 0) != 0)
+               fprintf(stderr, "power update: no such sysctl");
+
+       // attemp to map the battery state to linux
+       battery_state.state = BATTERY_UNKNOWN;
+
+       switch(sysctl_out) {
+               case 1:
+                       battery_state.state = BATTERY_DISCHARGING;
+                       break;
+               case 2:
+                       battery_state.state = BATTERY_CHARGING;
+                       break;
+               default:
+                       battery_state.state = BATTERY_FULL;
+                       break;
+       }
+
+       // no mapping for freebsd
+       energy_full = 0;
+       energy_now = 0;
+
+       if (sysctlbyname("hw.acpi.battery.time", &sysctl_out, &len, NULL, 0) != 0)
+               seconds = -1;
+       else
+               seconds = sysctl_out * 60;
+
+       // charging or error
+       if (seconds < 0)
+               seconds = 0;
+
+       if (sysctlbyname("hw.acpi.battery.life", &sysctl_out, &len, NULL, 0) != 0)
+               new_percentage = -1;
+       else
+               new_percentage = sysctl_out;
+
 #else
        fp = fopen(path_status, "r");
        if(fp != NULL) {
This page took 0.032372 seconds and 4 git commands to generate.