tConfigure for flaptop on OpenBSD - spoon - dwm status utility (2f30 fork) | |
git clone git://src.adamsgaard.dk/spoon | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit d500745cb3de6d6c475ccdccd96e7919bd56720e | |
parent 774975c0a33418ee74e7f215aa82c671334f514e | |
Author: Anders Damsgaard <[email protected]> | |
Date: Fri, 17 Apr 2020 21:18:09 +0200 | |
Configure for flaptop on OpenBSD | |
Diffstat: | |
M Makefile | 21 ++++++--------------- | |
M batt.c | 22 ++++++++-------------- | |
M count.c | 36 +++++++++++++++++------------… | |
A fileexists.c | 20 ++++++++++++++++++++ | |
M load.c | 4 ++-- | |
M spoon.c | 1 + | |
M wifi.c | 18 +++++++++--------- | |
7 files changed, 66 insertions(+), 56 deletions(-) | |
--- | |
diff --git a/Makefile b/Makefile | |
t@@ -1,32 +1,23 @@ | |
VERSION = 0.6 | |
PREFIX = /usr/local | |
SRC = spoon.c batt.c wifi.c cpu.c count.c temp.c date.c load.c file.c key.c\ | |
- netspeed.c strlcpy.c strlcat.c stub.c mix.c xkblayout.c mpd.c brightness… | |
+ netspeed.c strlcpy.c strlcat.c stub.c mix.c xkblayout.c mpd.c\ | |
+ brightness.c fileexists.c | |
OBJ = spoon.o batt.o wifi.o cpu.o count.o temp.o date.o load.o file.o key.o\ | |
- netspeed.o strlcpy.o strlcat.o stub.o brightness.o | |
+ netspeed.o strlcpy.o strlcat.o stub.o brightness.o fileexists.o | |
BIN = spoon | |
DISTFILES = $(SRC) arg.h types.h util.h config.def.h Makefile LICENSE configure | |
-include config.mk | |
+#include config.mk | |
-CPPFLAGS_OpenBSD = -I/usr/X11R6/include -I/usr/local/include | |
-LDFLAGS_OpenBSD = -L/usr/X11R6/lib -L/usr/local/lib | |
-CPPFLAGS_Linux = -I/usr/local/include | |
-CPPFLAGS = $(CPPFLAGS_$(UNAME)) | |
-LDFLAGS = $(LDFLAGS_$(UNAME)) | |
+CPPFLAGS = -I/usr/X11R6/include -I/usr/local/include | |
+LDFLAGS = -L/usr/X11R6/lib -L/usr/local/lib | |
LDLIBS = -lX11 | |
# To remove extra compile time dependencies for unwanted plugins | |
# comment out the following sections. The stub implementations | |
# from stub.c will be used instead. | |
OBJ += mix.o | |
-# if ALSA | |
-LDLIBS_Linux_mix = -lasound | |
-CPPFLAGS += -DUSE_TINYALSA=0 | |
-# else TinyALSA | |
-#LDLIBS_Linux_mix = -ltinyalsa | |
-#CPPFLAGS += -DUSE_TINYALSA=1 | |
-LDLIBS += $(LDLIBS_$(UNAME)_mix) | |
OBJ += xkblayout.o | |
LDLIBS += -lxkbfile | |
diff --git a/batt.c b/batt.c | |
t@@ -10,24 +10,17 @@ char *crit[] = { | |
}; | |
void | |
-battprint(char *buf, size_t len, int acon, int life) | |
+battprint(char *buf, size_t len, int acon, int life, int remain) | |
{ | |
char c; | |
static int frame = 0; | |
- c = acon ? '>' : '<'; | |
- if (!acon && life <= 5) | |
- snprintf(buf, len, "%s", crit[frame++ % LEN(crit)]); | |
- else if (life >= 80) | |
- snprintf(buf, len, "[////]="); | |
- else if (life >= 60) | |
- snprintf(buf, len, "[///%c]=", c); | |
- else if (life >= 40) | |
- snprintf(buf, len, "[//%c%c]=", c, c); | |
- else if (life >= 20) | |
- snprintf(buf, len, "[/%c%c%c]=", c, c, c); | |
+ c = acon ? '=' : ' '; | |
+ if (c == ' ') | |
+ snprintf(buf, len, "%d%% %d min", life, remain); | |
else | |
- snprintf(buf, len, "[%c%c%c%c]=", c, c, c, c); | |
+ snprintf(buf, len, "%d%%", life); | |
+ | |
} | |
#ifdef __OpenBSD__ | |
t@@ -60,7 +53,8 @@ battread(void *arg, char *buf, size_t len) | |
if (info.battery_state == APM_BATTERY_ABSENT) | |
snprintf(buf, len, "[no batt]"); | |
else | |
- battprint(buf, len, info.ac_state == APM_AC_ON, info.battery_l… | |
+ battprint(buf, len, info.ac_state == APM_AC_ON, | |
+ info.battery_life, info.minutes_left); | |
return 0; | |
} | |
#elif __linux__ | |
diff --git a/count.c b/count.c | |
t@@ -6,24 +6,28 @@ | |
int | |
countread(void *arg, char *buf, size_t len) | |
{ | |
- char *path = arg; | |
- unsigned long count = 0; | |
- struct dirent *e; | |
- DIR *d; | |
+ char *path = arg; | |
+ unsigned long count = 0; | |
+ struct dirent *e; | |
+ DIR *d; | |
- if ((d = opendir(path)) == NULL) { | |
- warn("open %s", path); | |
- return -1; | |
- } | |
+ if ((d = opendir(path)) == NULL) { | |
+ warn("open %s", path); | |
+ return -1; | |
+ } | |
- while ((e = readdir(d)) != NULL) { | |
- if (!strcmp(e->d_name, ".") || !strcmp(e->d_name, "..")) | |
- continue; | |
- ++count; | |
- } | |
- closedir(d); | |
+ while ((e = readdir(d)) != NULL) { | |
+ if (!strcmp(e->d_name, ".") || !strcmp(e->d_name, "..")) | |
+ continue; | |
+ ++count; | |
+ } | |
+ closedir(d); | |
- snprintf(buf, len, "%lu", count); | |
+ if (count > 0) | |
+ snprintf(buf, len, " m: %lu |", count); | |
+ else | |
+ snprintf(buf, len, ""); | |
+ | |
- return 0; | |
+ return 0; | |
} | |
diff --git a/fileexists.c b/fileexists.c | |
t@@ -0,0 +1,20 @@ | |
+#include <stdio.h> | |
+#include <err.h> | |
+#include <fcntl.h> | |
+#include <unistd.h> | |
+ | |
+int | |
+fileexists(void *arg, char *buf, size_t len) | |
+{ | |
+ char *path = arg; | |
+ ssize_t n; | |
+ int fd; | |
+ | |
+ fd = open(path, O_RDONLY); | |
+ if (fd == -1) | |
+ snprintf(buf, len, ""); | |
+ else | |
+ snprintf(buf, len, " R |"); | |
+ close(fd); | |
+ return 0; | |
+} | |
diff --git a/load.c b/load.c | |
t@@ -8,7 +8,7 @@ loadread(void *arg, char *buf, size_t len) | |
if (getloadavg(avgs, 3) < 0) | |
return -1; | |
- snprintf(buf, len, "%.2f %.2f %.2f", | |
- avgs[0], avgs[1], avgs[2]); | |
+ snprintf(buf, len, "%.2f", | |
+ avgs[0]); | |
return 0; | |
} | |
diff --git a/spoon.c b/spoon.c | |
t@@ -25,6 +25,7 @@ int keyread(void *, char *, size_t); | |
int netspeedread(void *, char *, size_t); | |
int brightnessread(void *, char *, size_t); | |
int countread(void *, char *, size_t); | |
+int fileexists(void *, char *, size_t); | |
struct ent { | |
char *fmt; | |
diff --git a/wifi.c b/wifi.c | |
t@@ -9,21 +9,21 @@ | |
#include "util.h" | |
void | |
-wifiprint(char *buf, size_t len, int quality) | |
+wifiprint(char *buf, size_t len, int quality, u_int8_t *ssid) | |
{ | |
char *icon; | |
if (quality == 100) | |
- icon = "::"; | |
+ icon = ":D"; | |
else if (quality >= 75) | |
- icon = ":."; | |
+ icon = ":)"; | |
else if (quality >= 50) | |
- icon = ".."; | |
+ icon = ":|"; | |
else if (quality >= 25) | |
- icon = ". "; | |
+ icon = ":("; | |
else | |
- icon = " "; | |
- snprintf(buf, len, "%s", icon); | |
+ icon = ":o"; | |
+ snprintf(buf, len, "%s %s", ssid, icon); | |
} | |
#ifdef __OpenBSD__ | |
t@@ -94,7 +94,7 @@ wifiread(void *arg, char *buf, size_t len) | |
DPRINTF_D(quality); | |
if (quality == -1) | |
return -1; | |
- wifiprint(buf, len, quality); | |
+ wifiprint(buf, len, quality, nr.nr_nwid); | |
return 0; | |
} | |
#elif __linux__ | |
t@@ -182,7 +182,7 @@ wifiread(void *arg, char *buf, size_t len) | |
DPRINTF_D(quality); | |
if (quality == -1) | |
return -1; | |
- wifiprint(buf, len, quality); | |
+ wifiprint(buf, len, quality, "asdf"); | |
return 0; | |
} | |
#endif |