[wiki] [sites] added dwmstatus volume display implementation || Andrew Milkovich

From: <git_AT_suckless.org>
Date: Wed, 23 Jan 2013 14:20:44 +0100

commit f7dfbe64f24dbf738f78e6b619c36c7a2bd80bcf
Author: Andrew Milkovich <amilkovich_AT_gmail.com>
Date: Wed Jan 23 05:20:37 2013 -0800

    added dwmstatus volume display implementation

diff --git a/dwm.suckless.org/dwmstatus/p1c0-dwmstatus-volume.c b/dwm.suckless.org/dwmstatus/p1c0-dwmstatus-volume.c
new file mode 100644
index 0000000..308b51c
--- /dev/null
+++ b/dwm.suckless.org/dwmstatus/p1c0-dwmstatus-volume.c
_AT_@ -0,0 +1,229 @@
+/* made by p1c0 2013-1-23.
+**
+** Compile with:
+** gcc -Wall -pedantic -std=c99 -lX11 status.c
+**
+** Notes:
+** bind volume keys in dwm config.h
+**
+** static const char *volup[] = { "dwmstatus", "volume", "up", NULL};
+** static const char *voldown[] = { "dwmstatus", "volume", "down", NULL};
+**
+** static Key keys[] = {
+** { 0, XF86XK_AudioRaiseVolume, spawn, {.v = volup } },
+** { 0, XF86XK_AudioLowerVolume, spawn, {.v = voldown } },
+** //{ MODKEY, XK_F11, spawn, {.v = voldown } },
+** //{ MODKEY, XK_F12, spawn, {.v = volup } },
+** };
+*/
+
+#define _BSD_SOURCE
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <strings.h>
+#include <sys/time.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <X11/Xlib.h>
+
+char *tzargentina = "America/Buenos_Aires";
+char *tzutc = "UTC";
+char *tzberlin = "Europe/Berlin";
+char *tzla = "America/Los_Angeles";
+
+static Display *dpy;
+
+char *
+smprintf(char *fmt, ...)
+{
+ va_list fmtargs;
+ char *ret;
+ int len;
+
+ va_start(fmtargs, fmt);
+ len = vsnprintf(NULL, 0, fmt, fmtargs);
+ va_end(fmtargs);
+
+ ret = malloc(++len);
+ if (ret == NULL) {
+ perror("malloc");
+ exit(1);
+ }
+
+ va_start(fmtargs, fmt);
+ vsnprintf(ret, len, fmt, fmtargs);
+ va_end(fmtargs);
+
+ return ret;
+}
+
+void
+settz(char *tzname)
+{
+ setenv("TZ", tzname, 1);
+}
+
+char *
+mktimes(char *fmt, char *tzname)
+{
+ char buf[129];
+ time_t tim;
+ struct tm *timtm;
+
+ memset(buf, 0, sizeof(buf));
+ settz(tzname);
+ tim = time(NULL);
+ timtm = localtime(&tim);
+ if (timtm == NULL) {
+ perror("localtime");
+ exit(1);
+ }
+
+ if (!strftime(buf, sizeof(buf)-1, fmt, timtm)) {
+ fprintf(stderr, "strftime == 0
");
+ exit(1);
+ }
+
+ return smprintf("%s", buf);
+}
+
+void
+setstatus(char *str)
+{
+ XStoreName(dpy, DefaultRootWindow(dpy), str);
+ XSync(dpy, False);
+}
+
+char *
+loadavg(void)
+{
+ double avgs[3];
+
+ if (getloadavg(avgs, 3) < 0) {
+ perror("getloadavg");
+ exit(1);
+ }
+
+ return smprintf("%.2f %.2f %.2f", avgs[0], avgs[1], avgs[2]);
+}
+
+char*
+runcmd(char* cmd) {
+ FILE* fp = popen(cmd, "r");
+ if (fp == NULL) return NULL;
+ char ln[30];
+ fgets(ln, sizeof(ln)-1, fp);
+ pclose(fp);
+ ln[strlen(ln)-1]='
Received on Wed Jan 23 2013 - 14:20:44 CET

This archive was generated by hypermail 2.3.0 : Wed Jan 23 2013 - 14:24:06 CET