1
0

Compare commits

..

No commits in common. "f68f49273e70b3767b30c549dda04ddd4d25fc91" and "4bd78c94ba90d67a268c092231b85037c94a339a" have entirely different histories.

17 changed files with 51 additions and 110 deletions

View File

@ -9,7 +9,7 @@ Copyright 2016-2018 Ali H. Fardan <raiz@firemail.cc>
Copyright 2016 Jody Leonard <me@jodyleonard.com> Copyright 2016 Jody Leonard <me@jodyleonard.com>
Copyright 2016-2018 Quentin Rameau <quinq@fifth.space> Copyright 2016-2018 Quentin Rameau <quinq@fifth.space>
Copyright 2016 Mike Coddington <mike@coddington.us> Copyright 2016 Mike Coddington <mike@coddington.us>
Copyright 2016-2018 Ivan J. <parazyd@dyne.org> Copyright 2016-2018 parazyd <parazyd@dyne.org>
Copyright 2017 Tobias Stoeckmann <tobias@stoeckmann.org> Copyright 2017 Tobias Stoeckmann <tobias@stoeckmann.org>
Copyright 2017-2018 Laslo Hunhold <dev@frign.de> Copyright 2017-2018 Laslo Hunhold <dev@frign.de>
Copyright 2018 Darron Anderson <darronanderson@protonmail.com> Copyright 2018 Darron Anderson <darronanderson@protonmail.com>
@ -21,14 +21,12 @@ Copyright 2018 Ian Remmler <ian@remmler.org>
Copyright 2016-2019 Joerg Jung <jung@openbsd.org> Copyright 2016-2019 Joerg Jung <jung@openbsd.org>
Copyright 2019 Ryan Kes <alrayyes@gmail.com> Copyright 2019 Ryan Kes <alrayyes@gmail.com>
Copyright 2019 Cem Keylan <cem@ckyln.com> Copyright 2019 Cem Keylan <cem@ckyln.com>
Copyright 2019 Dimitris Papastamos <dsp@2f30.org> Copyright 2019 dsp <dsp@2f30.org>
Copyright 2019-2022 Ingo Feinerer <feinerer@logic.at> Copyright 2019-2022 Ingo Feinerer <feinerer@logic.at>
Copyright 2020 Alexandre Ratchov <alex@caoua.org> Copyright 2020 Alexandre Ratchov <alex@caoua.org>
Copyright 2020 Mart Lubbers <mart@martlubbers.net> Copyright 2020 Mart Lubbers <mart@martlubbers.net>
Copyright 2020 Daniel Moch <daniel@danielmoch.com> Copyright 2020 Daniel Moch <daniel@danielmoch.com>
Copyright 2022 Nickolas Raymond Kaczynski <nrk@disroot.org> Copyright 2022 NRK <nrk@disroot.org>
Copyright 2022 Patrick Iacob <iacobp@oregonstate.edu>
Copyright 2021-2022 Steven Ward <planet36@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above

View File

@ -7,7 +7,6 @@ include config.mk
REQ = util REQ = util
COM =\ COM =\
components/battery\ components/battery\
components/cat\
components/cpu\ components/cpu\
components/datetime\ components/datetime\
components/disk\ components/disk\
@ -44,15 +43,14 @@ slstatus: slstatus.o $(COM:=.o) $(REQ:=.o)
$(CC) -o $@ $(LDFLAGS) $(COM:=.o) $(REQ:=.o) slstatus.o $(LDLIBS) $(CC) -o $@ $(LDFLAGS) $(COM:=.o) $(REQ:=.o) slstatus.o $(LDLIBS)
clean: clean:
rm -f slstatus slstatus.o $(COM:=.o) $(REQ:=.o) slstatus-${VERSION}.tar.gz rm -f slstatus slstatus.o $(COM:=.o) $(REQ:=.o)
dist: dist:
rm -rf "slstatus-$(VERSION)" rm -rf "slstatus-$(VERSION)"
mkdir -p "slstatus-$(VERSION)/components" mkdir -p "slstatus-$(VERSION)/components"
cp -R LICENSE Makefile README config.mk config.def.h \ cp -R LICENSE Makefile README config.mk config.def.h \
arg.h slstatus.h slstatus.c $(REQ:=.c) $(REQ:=.h) \ arg.h slstatus.c $(COM:=.c) $(REQ:=.c) $(REQ:=.h) \
slstatus.1 "slstatus-$(VERSION)" slstatus.1 "slstatus-$(VERSION)"
cp -R $(COM:=.c) "slstatus-$(VERSION)/components"
tar -cf - "slstatus-$(VERSION)" | gzip -c > "slstatus-$(VERSION).tar.gz" tar -cf - "slstatus-$(VERSION)" | gzip -c > "slstatus-$(VERSION).tar.gz"
rm -rf "slstatus-$(VERSION)" rm -rf "slstatus-$(VERSION)"

14
README
View File

@ -1,15 +1,12 @@
slstatus - suckless status slstatus - suckless status
========================== ==========================
slstatus is a small tool for providing system status information to other slstatus is a suckless status monitor for window managers that use WM_NAME
programs over the EWMH property of the root window (used by dwm(1)) or (e.g. dwm) or stdin to fill the status bar.
standard input/output. It is designed to be as efficient as possible by
only issuing the minimum of system calls required.
Features Features
-------- --------
- Battery percentage/state/time left - Battery percentage/state/time left
- Cat (read file)
- CPU usage - CPU usage
- CPU frequency - CPU frequency
- Custom shell commands - Custom shell commands
@ -63,3 +60,10 @@ Configuration
------------- -------------
slstatus can be customized by creating a custom config.h and (re)compiling the slstatus can be customized by creating a custom config.h and (re)compiling the
source code. This keeps it fast, secure and simple. source code. This keeps it fast, secure and simple.
Upcoming
--------
A release (v1.0) will come soon... ;)
After a long phase of inactivity, development has been continued!

View File

@ -6,9 +6,6 @@
#include "../util.h" #include "../util.h"
#if defined(__linux__) #if defined(__linux__)
/*
* https://www.kernel.org/doc/html/latest/power/power_supply_class.html
*/
#include <limits.h> #include <limits.h>
#include <stdint.h> #include <stdint.h>
#include <unistd.h> #include <unistd.h>
@ -17,8 +14,8 @@
#define POWER_SUPPLY_STATUS "/sys/class/power_supply/%s/status" #define POWER_SUPPLY_STATUS "/sys/class/power_supply/%s/status"
#define POWER_SUPPLY_CHARGE "/sys/class/power_supply/%s/charge_now" #define POWER_SUPPLY_CHARGE "/sys/class/power_supply/%s/charge_now"
#define POWER_SUPPLY_ENERGY "/sys/class/power_supply/%s/energy_now" #define POWER_SUPPLY_ENERGY "/sys/class/power_supply/%s/energy_now"
#define POWER_SUPPLY_CURRENT "/sys/class/power_supply/%s/current_now" #define POWER_SUPPLY_CURRENT "/sys/class/power_supply/%s/current"
#define POWER_SUPPLY_POWER "/sys/class/power_supply/%s/power_now" #define POWER_SUPPLY_POWER "/sys/class/power_supply/%s/power"
static const char * static const char *
pick(const char *bat, const char *f1, const char *f2, char *path, pick(const char *bat, const char *f1, const char *f2, char *path,
@ -38,15 +35,15 @@
const char * const char *
battery_perc(const char *bat) battery_perc(const char *bat)
{ {
int cap_perc; int perc;
char path[PATH_MAX]; char path[PATH_MAX];
if (esnprintf(path, sizeof(path), POWER_SUPPLY_CAPACITY, bat) < 0) if (esnprintf(path, sizeof(path), POWER_SUPPLY_CAPACITY, bat) < 0)
return NULL; return NULL;
if (pscanf(path, "%d", &cap_perc) != 1) if (pscanf(path, "%d", &perc) != 1)
return NULL; return NULL;
return bprintf("%d", cap_perc); return bprintf("%d", perc);
} }
const char * const char *
@ -200,14 +197,14 @@
const char * const char *
battery_perc(const char *unused) battery_perc(const char *unused)
{ {
int cap_perc; int cap;
size_t len; size_t len;
len = sizeof(cap_perc); len = sizeof(cap);
if (sysctlbyname(BATTERY_LIFE, &cap_perc, &len, NULL, 0) < 0 || !len) if (sysctlbyname(BATTERY_LIFE, &cap, &len, NULL, 0) < 0 || !len)
return NULL; return NULL;
return bprintf("%d", cap_perc); return bprintf("%d", cap);
} }
const char * const char *

View File

@ -1,32 +0,0 @@
/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <string.h>
#include "../slstatus.h"
#include "../util.h"
const char *
cat(const char *path)
{
char *f;
FILE *fp;
if (!(fp = fopen(path, "r"))) {
warn("fopen '%s':", path);
return NULL;
}
f = fgets(buf, sizeof(buf) - 1, fp);
if (fclose(fp) < 0) {
warn("fclose '%s':", path);
return NULL;
}
if (!f)
return NULL;
if ((f = strrchr(buf, '\n')))
f[0] = '\0';
return buf[0] ? buf : NULL;
}

View File

@ -29,7 +29,7 @@ disk_perc(const char *path)
} }
return bprintf("%d", (int)(100 * return bprintf("%d", (int)(100 *
(1 - ((double)fs.f_bavail / (double)fs.f_blocks)))); (1.0f - ((float)fs.f_bavail / (float)fs.f_blocks))));
} }
const char * const char *

View File

@ -22,8 +22,7 @@
const char * const char *
entropy(const char *unused) entropy(const char *unused)
{ {
// https://www.unicode.org/charts/PDF/U2200.pdf
/* Unicode Character 'INFINITY' (U+221E) */ /* Unicode Character 'INFINITY' (U+221E) */
return "\u221E"; return "\xe2\x88\x9e";
} }
#endif #endif

View File

@ -50,8 +50,7 @@ keymap(const char *unused)
Display *dpy; Display *dpy;
XkbDescRec *desc; XkbDescRec *desc;
XkbStateRec state; XkbStateRec state;
char *symbols; char *symbols, *layout;
const char *layout;
layout = NULL; layout = NULL;
@ -75,7 +74,7 @@ keymap(const char *unused)
warn("XGetAtomName: Failed to get atom name"); warn("XGetAtomName: Failed to get atom name");
goto end; goto end;
} }
layout = bprintf("%s", get_layout(symbols, state.group)); layout = (char *)bprintf("%s", get_layout(symbols, state.group));
XFree(symbols); XFree(symbols);
end: end:
XkbFreeKeyboard(desc, XkbSymbolsNameMask, 1); XkbFreeKeyboard(desc, XkbSymbolsNameMask, 1);

View File

@ -10,23 +10,23 @@ const char *
num_files(const char *path) num_files(const char *path)
{ {
struct dirent *dp; struct dirent *dp;
DIR *dir; DIR *fd;
int num; int num;
if (!(dir = opendir(path))) { if (!(fd = opendir(path))) {
warn("opendir '%s':", path); warn("opendir '%s':", path);
return NULL; return NULL;
} }
num = 0; num = 0;
while ((dp = readdir(dir))) { while ((dp = readdir(fd))) {
if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
continue; /* skip self and parent */ continue; /* skip self and parent */
num++; num++;
} }
closedir(dir); closedir(fd);
return bprintf("%d", num); return bprintf("%d", num);
} }

View File

@ -22,7 +22,7 @@ uptime(const char *unused)
struct timespec uptime; struct timespec uptime;
if (clock_gettime(UPTIME_FLAG, &uptime) < 0) { if (clock_gettime(UPTIME_FLAG, &uptime) < 0) {
snprintf(warn_buf, sizeof(warn_buf), "clock_gettime %d", UPTIME_FLAG); snprintf(warn_buf, 256, "clock_gettime %d", UPTIME_FLAG);
warn(warn_buf); warn(warn_buf);
return NULL; return NULL;
} }

View File

@ -14,17 +14,16 @@ static const char unknown_str[] = "n/a";
* *
* battery_perc battery percentage battery name (BAT0) * battery_perc battery percentage battery name (BAT0)
* NULL on OpenBSD/FreeBSD * NULL on OpenBSD/FreeBSD
* battery_remaining battery remaining HH:MM battery name (BAT0)
* NULL on OpenBSD/FreeBSD
* battery_state battery charging state battery name (BAT0) * battery_state battery charging state battery name (BAT0)
* NULL on OpenBSD/FreeBSD * NULL on OpenBSD/FreeBSD
* cat read arbitrary file path * battery_remaining battery remaining HH:MM battery name (BAT0)
* cpu_freq cpu frequency in MHz NULL * NULL on OpenBSD/FreeBSD
* cpu_perc cpu usage in percent NULL * cpu_perc cpu usage in percent NULL
* cpu_freq cpu frequency in MHz NULL
* datetime date and time format string (%F %T) * datetime date and time format string (%F %T)
* disk_free free disk space in GB mountpoint path (/) * disk_free free disk space in GB mountpoint path (/)
* disk_perc disk usage in percent mountpoint path (/) * disk_perc disk usage in percent mountpoint path (/)
* disk_total total disk space in GB mountpoint path (/) * disk_total total disk space in GB mountpoint path (/")
* disk_used used disk space in GB mountpoint path (/) * disk_used used disk space in GB mountpoint path (/)
* entropy available entropy NULL * entropy available entropy NULL
* gid GID of current user NULL * gid GID of current user NULL
@ -60,8 +59,8 @@ static const char unknown_str[] = "n/a";
* username username of current user NULL * username username of current user NULL
* vol_perc OSS/ALSA volume in percent mixer file (/dev/mixer) * vol_perc OSS/ALSA volume in percent mixer file (/dev/mixer)
* NULL on OpenBSD/FreeBSD * NULL on OpenBSD/FreeBSD
* wifi_essid WiFi ESSID interface name (wlan0)
* wifi_perc WiFi signal in percent interface name (wlan0) * wifi_perc WiFi signal in percent interface name (wlan0)
* wifi_essid WiFi ESSID interface name (wlan0)
*/ */
static const struct arg args[] = { static const struct arg args[] = {
/* function format argument */ /* function format argument */

View File

@ -1,5 +1,5 @@
# slstatus version # slstatus version
VERSION = 1.0 VERSION = 0
# customize below to fit your system # customize below to fit your system
@ -11,7 +11,7 @@ X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib X11LIB = /usr/X11R6/lib
# flags # flags
CPPFLAGS = -I$(X11INC) -D_DEFAULT_SOURCE -DVERSION=\"${VERSION}\" CPPFLAGS = -I$(X11INC) -D_DEFAULT_SOURCE
CFLAGS = -std=c99 -pedantic -Wall -Wextra -Wno-unused-parameter -Os CFLAGS = -std=c99 -pedantic -Wall -Wextra -Wno-unused-parameter -Os
LDFLAGS = -L$(X11LIB) -s LDFLAGS = -L$(X11LIB) -s
# OpenBSD: add -lsndio # OpenBSD: add -lsndio

View File

@ -1,29 +1,22 @@
.Dd 2023-04-23 .Dd 2020-06-23
.Dt SLSTATUS 1 .Dt SLSTATUS 1
.Os .Os
.Sh NAME .Sh NAME
.Nm slstatus .Nm slstatus
.Nd suckless status .Nd suckless status monitor
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl s .Op Fl s
.Op Fl 1 .Op Fl 1
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm .Nm
is a small tool for providing system status information to other programs is a suckless status monitor for window managers that use WM_NAME (e.g. dwm) or
over the EWMH stdin to fill the status bar.
.Em WM_NAME
property of the root window (used by
.Xr dwm 1 ) or standard input/output. It is designed to be as efficient as possible by
only issuing the minimum of system calls required.
.P
By default, By default,
.Nm .Nm
outputs to WM_NAME. outputs to WM_NAME.
.Sh OPTIONS .Sh OPTIONS
.Bl -tag -width Ds .Bl -tag -width Ds
.It Fl v
Print version information to stderr, then exit.
.It Fl s .It Fl s
Write to stdout instead of WM_NAME. Write to stdout instead of WM_NAME.
.It Fl 1 .It Fl 1
@ -33,15 +26,3 @@ Write once to stdout and quit.
.Nm .Nm
can be customized by creating a custom config.h and (re)compiling the source can be customized by creating a custom config.h and (re)compiling the source
code. This keeps it fast, secure and simple. code. This keeps it fast, secure and simple.
.Sh SIGNALS
.Nm
responds to the following signals:
.Pp
.Bl -tag -width TERM -compact
.It USR1
Triggers an instant redraw.
.El
.Sh AUTHORS
See the LICENSE file for the authors.
.Sh SEE ALSO
.Xr dwm 1

View File

@ -41,7 +41,7 @@ difftimespec(struct timespec *res, struct timespec *a, struct timespec *b)
static void static void
usage(void) usage(void)
{ {
die("usage: %s [-v] [-s] [-1]", argv0); die("usage: %s [-s] [-1]", argv0);
} }
int int
@ -56,8 +56,6 @@ main(int argc, char *argv[])
sflag = 0; sflag = 0;
ARGBEGIN { ARGBEGIN {
case 'v':
die("slstatus-"VERSION);
case '1': case '1':
done = 1; done = 1;
/* FALLTHROUGH */ /* FALLTHROUGH */

View File

@ -2,11 +2,8 @@
/* battery */ /* battery */
const char *battery_perc(const char *); const char *battery_perc(const char *);
const char *battery_remaining(const char *);
const char *battery_state(const char *); const char *battery_state(const char *);
const char *battery_remaining(const char *);
/* cat */
const char *cat(const char *path);
/* cpu */ /* cpu */
const char *cpu_freq(const char *unused); const char *cpu_freq(const char *unused);
@ -73,12 +70,12 @@ const char *uptime(const char *unused);
/* user */ /* user */
const char *gid(const char *unused); const char *gid(const char *unused);
const char *uid(const char *unused);
const char *username(const char *unused); const char *username(const char *unused);
const char *uid(const char *unused);
/* volume */ /* volume */
const char *vol_perc(const char *card); const char *vol_perc(const char *card);
/* wifi */ /* wifi */
const char *wifi_essid(const char *interface);
const char *wifi_perc(const char *interface); const char *wifi_perc(const char *interface);
const char *wifi_essid(const char *interface);

3
util.c
View File

@ -13,6 +13,9 @@ char *argv0;
static void static void
verr(const char *fmt, va_list ap) verr(const char *fmt, va_list ap)
{ {
if (argv0 && strncmp(fmt, "usage", sizeof("usage") - 1))
fprintf(stderr, "%s: ", argv0);
vfprintf(stderr, fmt, ap); vfprintf(stderr, fmt, ap);
if (fmt[0] && fmt[strlen(fmt) - 1] == ':') { if (fmt[0] && fmt[strlen(fmt) - 1] == ':') {

2
util.h
View File

@ -3,7 +3,7 @@
extern char buf[1024]; extern char buf[1024];
#define LEN(x) (sizeof(x) / sizeof((x)[0])) #define LEN(x) (sizeof (x) / sizeof *(x))
extern char *argv0; extern char *argv0;