[wiki] [sites] added another dwmstatus || profil

From: <hg_AT_suckless.org>
Date: Thu, 29 Dec 2011 02:20:54 +0100 (CET)

changeset: 807:9b99bf4c9656
tag: tip
user: profil <profil_AT_libs.se>
date: Thu Dec 29 02:20:41 2011 +0100
files: dwm.suckless.org/dwmstatus/index.md dwm.suckless.org/dwmstatus/profil-dwmstatus-1.0.c
description:
added another dwmstatus


diff -r e9b663dae07a -r 9b99bf4c9656 dwm.suckless.org/dwmstatus/index.md
--- a/dwm.suckless.org/dwmstatus/index.md Wed Dec 28 17:21:00 2011 +0100
+++ b/dwm.suckless.org/dwmstatus/index.md Thu Dec 29 02:20:41 2011 +0100
_AT_@ -14,6 +14,14 @@
 
 This is a barebone project you can use for changing it to your needs.
 
+User submitted versions
+-----------------------
+
+Please add your own version of dwmstatus here.
+
+* [profil-dwmstatus-1.0.c](profil-dwmstatus-1.0.c) - cpufreq, battery percent and date/time
+
+
 Helper functions
 ----------------
 
diff -r e9b663dae07a -r 9b99bf4c9656 dwm.suckless.org/dwmstatus/profil-dwmstatus-1.0.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dwm.suckless.org/dwmstatus/profil-dwmstatus-1.0.c Thu Dec 29 02:20:41 2011 +0100
_AT_@ -0,0 +1,128 @@
+/* made by profil 2011-12-29.
+**
+** Compile with:
+** gcc -Wall -pedantic -std=c99 -lX11 status.c
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+#include <X11/Xlib.h>
+
+static Display *dpy;
+
+void setstatus(char *str) {
+ XStoreName(dpy, DefaultRootWindow(dpy), str);
+ XSync(dpy, False);
+}
+
+float getfreq(char *file) {
+ FILE *fd;
+ char *freq;
+ float ret;
+
+ freq = malloc(10);
+ fd = fopen(file, "r");
+ if(fd == NULL) {
+ fprintf(stderr, "Cannot open '%s' for reading.\n", file);
+ exit(1);
+ }
+
+ fgets(freq, 10, fd);
+ fclose(fd);
+
+ ret = atof(freq)/1000000;
+ free(freq);
+ return ret;
+}
+
+char *getdatetime() {
+ char *buf;
+ time_t result;
+ struct tm *resulttm;
+
+ if((buf = malloc(sizeof(char)*65)) == NULL) {
+ fprintf(stderr, "Cannot allocate memory for buf.\n");
+ exit(1);
+ }
+ result = time(NULL);
+ resulttm = localtime(&result);
+ if(resulttm == NULL) {
+ fprintf(stderr, "Error getting localtime.\n");
+ exit(1);
+ }
+ if(!strftime(buf, sizeof(char)*65-1, "%a %b %d %H:%M:%S", resulttm)) {
+ fprintf(stderr, "strftime is 0.\n");
+ exit(1);
+ }
+
+ return buf;
+}
+
+int getbattery() {
+ FILE *fd;
+ int energy_now, energy_full, voltage_now;
+
+ fd = fopen("/sys/class/power_supply/BAT0/energy_now", "r");
+ if(fd == NULL) {
+ fprintf(stderr, "Error opening energy_now.\n");
+ return -1;
+ }
+ fscanf(fd, "%d", &energy_now);
+ fclose(fd);
+
+
+ fd = fopen("/sys/class/power_supply/BAT0/energy_full", "r");
+ if(fd == NULL) {
+ fprintf(stderr, "Error opening energy_full.\n");
+ return -1;
+ }
+ fscanf(fd, "%d", &energy_full);
+ fclose(fd);
+
+
+ fd = fopen("/sys/class/power_supply/BAT0/voltage_now", "r");
+ if(fd == NULL) {
+ fprintf(stderr, "Error opening voltage_now.\n");
+ return -1;
+ }
+ fscanf(fd, "%d", &voltage_now);
+ fclose(fd);
+
+
+ return ((float)energy_now * 1000 / (float)voltage_now) * 100 / ((float)energy_full * 1000 / (float)voltage_now);
+}
+
+int main(void) {
+ char *status;
+ float cpu0, cpu1;
+ char *datetime;
+ int bat0;
+
+
+ if (!(dpy = XOpenDisplay(NULL))) {
+ fprintf(stderr, "Cannot open display.\n");
+ return 1;
+ }
+
+ if((status = malloc(200)) == NULL)
+ exit(1);
+
+
+ for (;;sleep(1)) {
+ cpu0 = getfreq("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq");
+ cpu1 = getfreq("/sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq");
+ datetime = getdatetime();
+ bat0 = getbattery();
+ snprintf(status, 200, "%0.2f, %0.2f | %d%% | %s", cpu0, cpu1, bat0, datetime);
+
+ free(datetime);
+ setstatus(status);
+ }
+
+ free(status);
+ XCloseDisplay(dpy);
+
+ return 0;
+}
+
Received on Thu Dec 29 2011 - 02:20:54 CET

This archive was generated by hypermail 2.3.0 : Thu Sep 13 2012 - 19:31:55 CEST