Commit Diff


commit - 332f5fe858c1fb024b6ee392b36103d612ceca90
commit + 11c68cc712bbc3a5be658dd8732423d8df33d1b3
blob - f80ea33f21e43dc969ea6bdef370d1e39752305a
blob + ebfd357ef37692f05bac7c3234d1ae32c1bb6c45
--- Makefile
+++ Makefile
@@ -10,7 +10,8 @@ SRC_BS		= bedstatus/bedstatus.c
 HDR_BS		= bedstatus/bedstatus.h				\
 		  bedstatus/unsupported.c			\
 		  bedstatus/openbsd.c				\
-		  bedstatus/linux.c
+		  bedstatus/linux.c				\
+		  bedstatus/freebsd.c
 
 SRC_DMENU	= dmenu/dmenu.c dmenu/drw.c dmenu/util.c
 HDR_DMENU	= dmenu/arg.h dmenu/config.h dmenu/drw.h dmenu/util.h master.h
blob - 5fdb4318a251885318534184ef7c1be70aef7704
blob + a5f15156a29a442b0e07bf31164d61f2515d5aab
--- bedstatus/bedstatus.c
+++ bedstatus/bedstatus.c
@@ -1,3 +1,6 @@
+#ifdef __FreeBSD__
+# define __BSD_VISIBLE 1
+#endif
 #include <X11/Xlib.h>
 #include <unistd.h>
 #include <stdarg.h>
@@ -10,6 +13,8 @@
 # include "openbsd.c"
 #elif defined(__linux__)
 # include "linux.c"
+#elif defined(__FreeBSD__)
+# include "freebsd.c"
 #else
 # include "unsupported.c"
 #endif
blob - /dev/null
blob + 110b0ba3170c97e2afb8fb16e641de7a01dc2c71 (mode 644)
--- /dev/null
+++ bedstatus/freebsd.c
@@ -0,0 +1,69 @@
+// This code is heavily borrowed from FreeBSD's top
+#include <sys/resource.h>
+#include <sys/sysctl.h>
+#include <unistd.h>
+#include <string.h>
+#include "bedstatus.h"
+
+#define SYSCTL(name, x) (xsysctl (name, x, sizeof (*(x))))
+
+struct cpu_times {
+	long times[CPUSTATES];	
+};
+
+static long pagesize;
+static int ncpu;
+static struct cpu_times *old = NULL, *new, *diff;
+
+static bool xsysctl (const char *name, void *ptr, size_t len)
+{
+	size_t len2 = len;
+
+	return sysctlbyname (name, ptr, &len2, NULL, 0) >= 0 && len == len2;
+}
+
+static bool mem_usage (uint64_t *usage)
+{
+	int active;
+
+	if (!SYSCTL ("vm.stats.vm.v_active_count", &active))
+		return false;
+
+	*usage = (uint64_t)active * pagesize;
+
+	return true;
+}
+
+static bool cpu_usage (int *usage)
+{
+	int len;
+
+	if (old == NULL)
+		return false;
+
+
+	return false;
+}
+
+static bool bat_perc (int *perc)
+{
+	return SYSCTL ("hw.acpi.battery.life", perc);
+}
+
+void init_backend (void)
+{
+	pagesize = getpagesize ();
+	if (SYSCTL ("kern.smp.maxcpus", &ncpu)) {
+		old = calloc (ncpu, sizeof (struct cpu_times));
+		new = calloc (ncpu, sizeof (struct cpu_times));
+		diff = calloc (ncpu, sizeof (struct cpu_times));
+	}
+}
+
+void update_status (struct status *st)
+{
+	memset (st, 0, sizeof (*st));
+	st->has_mem_usage = mem_usage (&st->mem_usage);
+	st->has_cpu_usage = cpu_usage (&st->cpu_usage);
+	st->has_bat_perc = bat_perc (&st->bat_perc);
+}