Compare commits
23 Commits
4bd78c94ba
...
f68f49273e
Author | SHA1 | Date | |
---|---|---|---|
|
f68f49273e | ||
|
86c7a84c23 | ||
|
483169021b | ||
|
e0c155e9ab | ||
|
ee586cfea9 | ||
|
c919def84f | ||
|
034c591a95 | ||
|
305aa5138a | ||
|
1ae616190c | ||
|
581d937e51 | ||
|
c225c43151 | ||
|
984f45719e | ||
|
c432c981df | ||
|
87c3dd2c36 | ||
|
d77f216fae | ||
|
40f13be551 | ||
|
c75cb9ad7a | ||
|
89f8476110 | ||
|
0e2ff8dc10 | ||
|
e22d447684 | ||
|
173b03417d | ||
|
982eb223a0 | ||
|
57c6e7340d |
8
LICENSE
8
LICENSE
@ -9,7 +9,7 @@ Copyright 2016-2018 Ali H. Fardan <raiz@firemail.cc>
|
||||
Copyright 2016 Jody Leonard <me@jodyleonard.com>
|
||||
Copyright 2016-2018 Quentin Rameau <quinq@fifth.space>
|
||||
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-2018 Laslo Hunhold <dev@frign.de>
|
||||
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 2019 Ryan Kes <alrayyes@gmail.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 2020 Alexandre Ratchov <alex@caoua.org>
|
||||
Copyright 2020 Mart Lubbers <mart@martlubbers.net>
|
||||
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
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
|
6
Makefile
6
Makefile
@ -7,6 +7,7 @@ include config.mk
|
||||
REQ = util
|
||||
COM =\
|
||||
components/battery\
|
||||
components/cat\
|
||||
components/cpu\
|
||||
components/datetime\
|
||||
components/disk\
|
||||
@ -43,14 +44,15 @@ slstatus: slstatus.o $(COM:=.o) $(REQ:=.o)
|
||||
$(CC) -o $@ $(LDFLAGS) $(COM:=.o) $(REQ:=.o) slstatus.o $(LDLIBS)
|
||||
|
||||
clean:
|
||||
rm -f slstatus slstatus.o $(COM:=.o) $(REQ:=.o)
|
||||
rm -f slstatus slstatus.o $(COM:=.o) $(REQ:=.o) slstatus-${VERSION}.tar.gz
|
||||
|
||||
dist:
|
||||
rm -rf "slstatus-$(VERSION)"
|
||||
mkdir -p "slstatus-$(VERSION)/components"
|
||||
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)"
|
||||
cp -R $(COM:=.c) "slstatus-$(VERSION)/components"
|
||||
tar -cf - "slstatus-$(VERSION)" | gzip -c > "slstatus-$(VERSION).tar.gz"
|
||||
rm -rf "slstatus-$(VERSION)"
|
||||
|
||||
|
14
README
14
README
@ -1,12 +1,15 @@
|
||||
slstatus - suckless status
|
||||
==========================
|
||||
slstatus is a suckless status monitor for window managers that use WM_NAME
|
||||
(e.g. dwm) or stdin to fill the status bar.
|
||||
slstatus is a small tool for providing system status information to other
|
||||
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
|
||||
--------
|
||||
- Battery percentage/state/time left
|
||||
- Cat (read file)
|
||||
- CPU usage
|
||||
- CPU frequency
|
||||
- Custom shell commands
|
||||
@ -60,10 +63,3 @@ Configuration
|
||||
-------------
|
||||
slstatus can be customized by creating a custom config.h and (re)compiling the
|
||||
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!
|
||||
|
@ -6,6 +6,9 @@
|
||||
#include "../util.h"
|
||||
|
||||
#if defined(__linux__)
|
||||
/*
|
||||
* https://www.kernel.org/doc/html/latest/power/power_supply_class.html
|
||||
*/
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
@ -14,8 +17,8 @@
|
||||
#define POWER_SUPPLY_STATUS "/sys/class/power_supply/%s/status"
|
||||
#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_CURRENT "/sys/class/power_supply/%s/current"
|
||||
#define POWER_SUPPLY_POWER "/sys/class/power_supply/%s/power"
|
||||
#define POWER_SUPPLY_CURRENT "/sys/class/power_supply/%s/current_now"
|
||||
#define POWER_SUPPLY_POWER "/sys/class/power_supply/%s/power_now"
|
||||
|
||||
static const char *
|
||||
pick(const char *bat, const char *f1, const char *f2, char *path,
|
||||
@ -35,15 +38,15 @@
|
||||
const char *
|
||||
battery_perc(const char *bat)
|
||||
{
|
||||
int perc;
|
||||
int cap_perc;
|
||||
char path[PATH_MAX];
|
||||
|
||||
if (esnprintf(path, sizeof(path), POWER_SUPPLY_CAPACITY, bat) < 0)
|
||||
return NULL;
|
||||
if (pscanf(path, "%d", &perc) != 1)
|
||||
if (pscanf(path, "%d", &cap_perc) != 1)
|
||||
return NULL;
|
||||
|
||||
return bprintf("%d", perc);
|
||||
return bprintf("%d", cap_perc);
|
||||
}
|
||||
|
||||
const char *
|
||||
@ -197,14 +200,14 @@
|
||||
const char *
|
||||
battery_perc(const char *unused)
|
||||
{
|
||||
int cap;
|
||||
int cap_perc;
|
||||
size_t len;
|
||||
|
||||
len = sizeof(cap);
|
||||
if (sysctlbyname(BATTERY_LIFE, &cap, &len, NULL, 0) < 0 || !len)
|
||||
len = sizeof(cap_perc);
|
||||
if (sysctlbyname(BATTERY_LIFE, &cap_perc, &len, NULL, 0) < 0 || !len)
|
||||
return NULL;
|
||||
|
||||
return bprintf("%d", cap);
|
||||
return bprintf("%d", cap_perc);
|
||||
}
|
||||
|
||||
const char *
|
||||
|
32
components/cat.c
Normal file
32
components/cat.c
Normal 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;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ disk_perc(const char *path)
|
||||
}
|
||||
|
||||
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 *
|
||||
|
@ -22,7 +22,8 @@
|
||||
const char *
|
||||
entropy(const char *unused)
|
||||
{
|
||||
// https://www.unicode.org/charts/PDF/U2200.pdf
|
||||
/* Unicode Character 'INFINITY' (U+221E) */
|
||||
return "\xe2\x88\x9e";
|
||||
return "\u221E";
|
||||
}
|
||||
#endif
|
||||
|
@ -50,7 +50,8 @@ keymap(const char *unused)
|
||||
Display *dpy;
|
||||
XkbDescRec *desc;
|
||||
XkbStateRec state;
|
||||
char *symbols, *layout;
|
||||
char *symbols;
|
||||
const char *layout;
|
||||
|
||||
layout = NULL;
|
||||
|
||||
@ -74,7 +75,7 @@ keymap(const char *unused)
|
||||
warn("XGetAtomName: Failed to get atom name");
|
||||
goto end;
|
||||
}
|
||||
layout = (char *)bprintf("%s", get_layout(symbols, state.group));
|
||||
layout = bprintf("%s", get_layout(symbols, state.group));
|
||||
XFree(symbols);
|
||||
end:
|
||||
XkbFreeKeyboard(desc, XkbSymbolsNameMask, 1);
|
||||
|
@ -10,23 +10,23 @@ const char *
|
||||
num_files(const char *path)
|
||||
{
|
||||
struct dirent *dp;
|
||||
DIR *fd;
|
||||
DIR *dir;
|
||||
int num;
|
||||
|
||||
if (!(fd = opendir(path))) {
|
||||
if (!(dir = opendir(path))) {
|
||||
warn("opendir '%s':", path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
num = 0;
|
||||
while ((dp = readdir(fd))) {
|
||||
while ((dp = readdir(dir))) {
|
||||
if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
|
||||
continue; /* skip self and parent */
|
||||
|
||||
num++;
|
||||
}
|
||||
|
||||
closedir(fd);
|
||||
closedir(dir);
|
||||
|
||||
return bprintf("%d", num);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ uptime(const char *unused)
|
||||
struct timespec uptime;
|
||||
|
||||
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);
|
||||
return NULL;
|
||||
}
|
||||
|
11
config.def.h
11
config.def.h
@ -14,16 +14,17 @@ static const char unknown_str[] = "n/a";
|
||||
*
|
||||
* battery_perc battery percentage battery name (BAT0)
|
||||
* 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)
|
||||
* 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_perc cpu usage in percent NULL
|
||||
* datetime date and time format string (%F %T)
|
||||
* disk_free free disk space in GB 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 (/)
|
||||
* entropy available entropy NULL
|
||||
* gid GID of current user NULL
|
||||
@ -59,8 +60,8 @@ static const char unknown_str[] = "n/a";
|
||||
* username username of current user NULL
|
||||
* vol_perc OSS/ALSA volume in percent mixer file (/dev/mixer)
|
||||
* NULL on OpenBSD/FreeBSD
|
||||
* wifi_perc WiFi signal in percent interface name (wlan0)
|
||||
* wifi_essid WiFi ESSID interface name (wlan0)
|
||||
* wifi_perc WiFi signal in percent interface name (wlan0)
|
||||
*/
|
||||
static const struct arg args[] = {
|
||||
/* function format argument */
|
||||
|
@ -1,5 +1,5 @@
|
||||
# slstatus version
|
||||
VERSION = 0
|
||||
VERSION = 1.0
|
||||
|
||||
# customize below to fit your system
|
||||
|
||||
@ -11,7 +11,7 @@ X11INC = /usr/X11R6/include
|
||||
X11LIB = /usr/X11R6/lib
|
||||
|
||||
# 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
|
||||
LDFLAGS = -L$(X11LIB) -s
|
||||
# OpenBSD: add -lsndio
|
||||
|
27
slstatus.1
27
slstatus.1
@ -1,22 +1,29 @@
|
||||
.Dd 2020-06-23
|
||||
.Dd 2023-04-23
|
||||
.Dt SLSTATUS 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm slstatus
|
||||
.Nd suckless status monitor
|
||||
.Nd suckless status
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl s
|
||||
.Op Fl 1
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
is a suckless status monitor for window managers that use WM_NAME (e.g. dwm) or
|
||||
stdin to fill the status bar.
|
||||
is a small tool for providing system status information to other programs
|
||||
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,
|
||||
.Nm
|
||||
outputs to WM_NAME.
|
||||
.Sh OPTIONS
|
||||
.Bl -tag -width Ds
|
||||
.It Fl v
|
||||
Print version information to stderr, then exit.
|
||||
.It Fl s
|
||||
Write to stdout instead of WM_NAME.
|
||||
.It Fl 1
|
||||
@ -26,3 +33,15 @@ Write once to stdout and quit.
|
||||
.Nm
|
||||
can be customized by creating a custom config.h and (re)compiling the source
|
||||
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
|
||||
|
@ -41,7 +41,7 @@ difftimespec(struct timespec *res, struct timespec *a, struct timespec *b)
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
die("usage: %s [-s] [-1]", argv0);
|
||||
die("usage: %s [-v] [-s] [-1]", argv0);
|
||||
}
|
||||
|
||||
int
|
||||
@ -56,6 +56,8 @@ main(int argc, char *argv[])
|
||||
|
||||
sflag = 0;
|
||||
ARGBEGIN {
|
||||
case 'v':
|
||||
die("slstatus-"VERSION);
|
||||
case '1':
|
||||
done = 1;
|
||||
/* FALLTHROUGH */
|
||||
|
@ -2,8 +2,11 @@
|
||||
|
||||
/* battery */
|
||||
const char *battery_perc(const char *);
|
||||
const char *battery_state(const char *);
|
||||
const char *battery_remaining(const char *);
|
||||
const char *battery_state(const char *);
|
||||
|
||||
/* cat */
|
||||
const char *cat(const char *path);
|
||||
|
||||
/* cpu */
|
||||
const char *cpu_freq(const char *unused);
|
||||
@ -70,12 +73,12 @@ const char *uptime(const char *unused);
|
||||
|
||||
/* user */
|
||||
const char *gid(const char *unused);
|
||||
const char *username(const char *unused);
|
||||
const char *uid(const char *unused);
|
||||
const char *username(const char *unused);
|
||||
|
||||
/* volume */
|
||||
const char *vol_perc(const char *card);
|
||||
|
||||
/* wifi */
|
||||
const char *wifi_perc(const char *interface);
|
||||
const char *wifi_essid(const char *interface);
|
||||
const char *wifi_perc(const char *interface);
|
||||
|
3
util.c
3
util.c
@ -13,9 +13,6 @@ char *argv0;
|
||||
static void
|
||||
verr(const char *fmt, va_list ap)
|
||||
{
|
||||
if (argv0 && strncmp(fmt, "usage", sizeof("usage") - 1))
|
||||
fprintf(stderr, "%s: ", argv0);
|
||||
|
||||
vfprintf(stderr, fmt, ap);
|
||||
|
||||
if (fmt[0] && fmt[strlen(fmt) - 1] == ':') {
|
||||
|
Loading…
Reference in New Issue
Block a user