1
0

Compare commits

...

23 Commits

Author SHA1 Message Date
drkhsh
f68f49273e Release stable 1.0 version 2023-07-04 20:47:18 +02:00
drkhsh
86c7a84c23 Add back version flag to prepare for release 2023-05-15 19:16:12 +02:00
drkhsh
483169021b Fix release tarball to prepare for release
Correctly copies components to sub-directory, adds all required files
2023-05-15 19:11:39 +02:00
drkhsh
e0c155e9ab README: Sync description from manpage 2023-04-23 23:48:47 +02:00
drkhsh
ee586cfea9 manpage: Quality improvements
Adds signals section to the manpage and generally improves contents and
wording
2023-04-23 23:43:14 +02:00
drkhsh
c919def84f More LICENSE updates
Regarding 305aa5138a
2022-12-19 22:04:07 +01:00
drkhsh
034c591a95 Revert "config.mk: Fix PREFIX assignment"
"?=" is not POSIX, packagers should use "make PREFIX=".
This reverts commit c225c43151.
2022-12-19 19:26:57 +01:00
drkhsh
305aa5138a Update LICENSE
Real names should be used if possible, as the license is legally binding
2022-12-19 19:26:18 +01:00
drkhsh
1ae616190c Update LICENSE 2022-12-19 02:44:21 +01:00
planet36
581d937e51 entropy: Use Unicode escape sequence in string
Signed-off-by: drkhsh <me@drkhsh.at>
2022-12-19 02:44:21 +01:00
planet36
c225c43151 config.mk: Fix PREFIX assignment
Signed-off-by: drkhsh <me@drkhsh.at>
2022-12-19 02:44:21 +01:00
planet36
984f45719e num_files: opendir() returns a directory stream
opendir() returns a directory stream, not a file descriptor

Co-authored-by: drkhsh <me@drkhsh.at>
Signed-off-by: drkhsh <me@drkhsh.at>
2022-12-19 02:44:21 +01:00
planet36
c432c981df Make LEN macro consistent with other suckless repos
Signed-off-by: drkhsh <me@drkhsh.at>
2022-12-19 02:44:21 +01:00
planet36
87c3dd2c36 battery: Consistent naming for capacity percentage
https://www.kernel.org/doc/html/latest/power/power_supply_class.html

Co-authored-by: drkhsh <me@drkhsh.at>
Signed-off-by: drkhsh <me@drkhsh.at>
2022-12-19 02:44:21 +01:00
planet36
d77f216fae Sort functions by name
Co-authored-by: drkhsh <me@drkhsh.at>
Signed-off-by: drkhsh <me@drkhsh.at>
2022-12-19 02:44:21 +01:00
planet36
40f13be551 uptime: Use sizeof instead of repeating the size
Signed-off-by: drkhsh <me@drkhsh.at>
2022-12-19 02:44:21 +01:00
planet36
c75cb9ad7a keymap: Variable "layout" should be const
Signed-off-by: drkhsh <me@drkhsh.at>
2022-12-19 02:44:21 +01:00
planet36
89f8476110 disk: Cast fsblkcnt_t to double instead of float
Signed-off-by: drkhsh <me@drkhsh.at>
2022-12-19 02:44:21 +01:00
planet36
0e2ff8dc10 verr: Remove special "usage" case
In function verr, remove special case for "usage"
string

Co-authored-by: drkhsh <me@drkhsh.at>
Signed-off-by: drkhsh <me@drkhsh.at>
2022-12-19 02:44:21 +01:00
planet36
e22d447684 config.def.h: Remove stray double quote in comment
Signed-off-by: drkhsh <me@drkhsh.at>
2022-12-19 02:44:21 +01:00
drkhsh
173b03417d Update README 2022-12-19 02:44:21 +01:00
Patrick Iacob
982eb223a0 battery: Fix remaining on Linux
The current version displays the remaining time as 'n/a'.

Fixes this regression introduced in 69b2487650
where current_now and power_now were incorrectly replaced with current and
power when they were moved to a macro.
2022-12-01 09:04:32 +01:00
drkhsh
57c6e7340d New component: cat
Generically reads an arbitrary file natively.

Saves a few layers of execution in comparison to using `run_command`
with an argument like `cat ./file`.
2022-11-24 00:01:52 +01:00
17 changed files with 110 additions and 51 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 parazyd <parazyd@dyne.org> Copyright 2016-2018 Ivan J. <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,12 +21,14 @@ 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 dsp <dsp@2f30.org> Copyright 2019 Dimitris Papastamos <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 NRK <nrk@disroot.org> Copyright 2022 Nickolas Raymond Kaczynski <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,6 +7,7 @@ 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\
@ -43,14 +44,15 @@ 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) rm -f slstatus slstatus.o $(COM:=.o) $(REQ:=.o) slstatus-${VERSION}.tar.gz
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.c $(COM:=.c) $(REQ:=.c) $(REQ:=.h) \ arg.h slstatus.h slstatus.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,12 +1,15 @@
slstatus - suckless status slstatus - suckless status
========================== ==========================
slstatus is a suckless status monitor for window managers that use WM_NAME slstatus is a small tool for providing system status information to other
(e.g. dwm) or stdin to fill the status bar. programs over the EWMH property of the root window (used by dwm(1)) or
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
@ -60,10 +63,3 @@ 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,6 +6,9 @@
#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>
@ -14,8 +17,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" #define POWER_SUPPLY_CURRENT "/sys/class/power_supply/%s/current_now"
#define POWER_SUPPLY_POWER "/sys/class/power_supply/%s/power" #define POWER_SUPPLY_POWER "/sys/class/power_supply/%s/power_now"
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,
@ -35,15 +38,15 @@
const char * const char *
battery_perc(const char *bat) battery_perc(const char *bat)
{ {
int perc; int cap_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", &perc) != 1) if (pscanf(path, "%d", &cap_perc) != 1)
return NULL; return NULL;
return bprintf("%d", perc); return bprintf("%d", cap_perc);
} }
const char * const char *
@ -197,14 +200,14 @@
const char * const char *
battery_perc(const char *unused) battery_perc(const char *unused)
{ {
int cap; int cap_perc;
size_t len; size_t len;
len = sizeof(cap); len = sizeof(cap_perc);
if (sysctlbyname(BATTERY_LIFE, &cap, &len, NULL, 0) < 0 || !len) if (sysctlbyname(BATTERY_LIFE, &cap_perc, &len, NULL, 0) < 0 || !len)
return NULL; return NULL;
return bprintf("%d", cap); return bprintf("%d", cap_perc);
} }
const char * const char *

32
components/cat.c Normal file
View File

@ -0,0 +1,32 @@
/* 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.0f - ((float)fs.f_bavail / (float)fs.f_blocks)))); (1 - ((double)fs.f_bavail / (double)fs.f_blocks))));
} }
const char * const char *

View File

@ -22,7 +22,8 @@
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 "\xe2\x88\x9e"; return "\u221E";
} }
#endif #endif

View File

@ -50,7 +50,8 @@ keymap(const char *unused)
Display *dpy; Display *dpy;
XkbDescRec *desc; XkbDescRec *desc;
XkbStateRec state; XkbStateRec state;
char *symbols, *layout; char *symbols;
const char *layout;
layout = NULL; layout = NULL;
@ -74,7 +75,7 @@ keymap(const char *unused)
warn("XGetAtomName: Failed to get atom name"); warn("XGetAtomName: Failed to get atom name");
goto end; goto end;
} }
layout = (char *)bprintf("%s", get_layout(symbols, state.group)); layout = 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 *fd; DIR *dir;
int num; int num;
if (!(fd = opendir(path))) { if (!(dir = opendir(path))) {
warn("opendir '%s':", path); warn("opendir '%s':", path);
return NULL; return NULL;
} }
num = 0; num = 0;
while ((dp = readdir(fd))) { while ((dp = readdir(dir))) {
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(fd); closedir(dir);
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, 256, "clock_gettime %d", UPTIME_FLAG); snprintf(warn_buf, sizeof(warn_buf), "clock_gettime %d", UPTIME_FLAG);
warn(warn_buf); warn(warn_buf);
return NULL; return NULL;
} }

View File

@ -14,16 +14,17 @@ 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_state battery charging state battery name (BAT0)
* NULL on OpenBSD/FreeBSD
* battery_remaining battery remaining HH:MM battery name (BAT0) * battery_remaining battery remaining HH:MM battery name (BAT0)
* NULL on OpenBSD/FreeBSD * NULL on OpenBSD/FreeBSD
* cpu_perc cpu usage in percent NULL * battery_state battery charging state battery name (BAT0)
* NULL on OpenBSD/FreeBSD
* cat read arbitrary file path
* cpu_freq cpu frequency in MHz NULL * cpu_freq cpu frequency in MHz NULL
* cpu_perc cpu usage in percent 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
@ -59,8 +60,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_perc WiFi signal in percent interface name (wlan0)
* wifi_essid WiFi ESSID interface name (wlan0) * wifi_essid WiFi ESSID interface name (wlan0)
* wifi_perc WiFi signal in percent 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 = 0 VERSION = 1.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 CPPFLAGS = -I$(X11INC) -D_DEFAULT_SOURCE -DVERSION=\"${VERSION}\"
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,22 +1,29 @@
.Dd 2020-06-23 .Dd 2023-04-23
.Dt SLSTATUS 1 .Dt SLSTATUS 1
.Os .Os
.Sh NAME .Sh NAME
.Nm slstatus .Nm slstatus
.Nd suckless status monitor .Nd suckless status
.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 suckless status monitor for window managers that use WM_NAME (e.g. dwm) or is a small tool for providing system status information to other programs
stdin to fill the status bar. over the EWMH
.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
@ -26,3 +33,15 @@ 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 [-s] [-1]", argv0); die("usage: %s [-v] [-s] [-1]", argv0);
} }
int int
@ -56,6 +56,8 @@ 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,8 +2,11 @@
/* battery */ /* battery */
const char *battery_perc(const char *); const char *battery_perc(const char *);
const char *battery_state(const char *);
const char *battery_remaining(const char *); const char *battery_remaining(const char *);
const char *battery_state(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);
@ -70,12 +73,12 @@ const char *uptime(const char *unused);
/* user */ /* user */
const char *gid(const char *unused); const char *gid(const char *unused);
const char *username(const char *unused);
const char *uid(const char *unused); const char *uid(const char *unused);
const char *username(const char *unused);
/* volume */ /* volume */
const char *vol_perc(const char *card); const char *vol_perc(const char *card);
/* wifi */ /* wifi */
const char *wifi_perc(const char *interface);
const char *wifi_essid(const char *interface); const char *wifi_essid(const char *interface);
const char *wifi_perc(const char *interface);

3
util.c
View File

@ -13,9 +13,6 @@ 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)) #define LEN(x) (sizeof(x) / sizeof((x)[0]))
extern char *argv0; extern char *argv0;