Merge branch 'R41z-master'
This commit is contained in:
commit
6518f41b1f
12 changed files with 424 additions and 513 deletions
|
@ -6,3 +6,4 @@ Thanks you very much for your great help!
|
||||||
- [Vlaix](https://github.com/Vlaix)
|
- [Vlaix](https://github.com/Vlaix)
|
||||||
- [pfannkuckengesicht](https://github.com/pfannkuchengesicht)
|
- [pfannkuckengesicht](https://github.com/pfannkuchengesicht)
|
||||||
- [sahne](https://github.com/sahne)
|
- [sahne](https://github.com/sahne)
|
||||||
|
- [Ali H. Fardan](http://raiz.duckdns.org)
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
include config.mk
|
include config.mk
|
||||||
|
|
||||||
|
NAME=slstatus
|
||||||
|
|
||||||
SRC = ${NAME}.c
|
SRC = ${NAME}.c
|
||||||
OBJ = ${SRC:.c=.o}
|
OBJ = ${SRC:.c=.o}
|
||||||
|
|
||||||
|
|
45
README.md
45
README.md
|
@ -1,29 +1,29 @@
|
||||||
slstatus
|
slstatus
|
||||||
========
|
========
|
||||||
|
|
||||||
**slstatus** is a suckless and lightweight status monitor for window managers which use WM_NAME as statusbar (e.g. DWM). It is written in pure C without any system() calls and only reads from files most of the time. It is meant as a better alternative to Bash scripts (inefficient) and Conky (bloated for this use).
|
**slstatus** is a suckless and lightweight status monitor for window managers that use WM_NAME as statusbar (e.g. DWM). It is written in pure C without any system calls and only reads from files most of the time. It is meant to be a better alternative to Bash scripts (inefficient) and Conky (bloated for this use).
|
||||||
|
|
||||||
If you write a bash script that shows system information in WM_NAME, it executes a huge amount of external command (top, free etc.) every few seconds. This results in high system resource usage. slstatus solves this problem by only using C libraries and/or reading from files in sysfs / procfs.
|
If you write a bash script that shows system information in WM_NAME, it executes a huge amount of external commands (top, free etc.) every few seconds. This results in high system resource usage. slstatus solves this problem by only using C libraries and/or reading from files in sysfs/procfs.
|
||||||
|
|
||||||
Looking at the LOC (lines of code) in the [Conky project](https://github.com/brndnmtthws/conky) is very interesting: *28.346 lines C++, 219 lines Python and 110 lines Lua*. slstatus currently has about **600 lines of clean, well commented C code** and even includes additional possibilities as it can be customized and extended very easily. Configuring it by editing config.h (a C header file) is very secure and fast as no config files are parsed at runtime.
|
Looking at the LOC (lines of code) of the [Conky project](https://github.com/brndnmtthws/conky), very interesting: *28.346 lines C++, 219 lines Python and 110 lines Lua*. slstatus currently has about **800 lines of clean documented C code** and even includes additional possibilities as it can be customized and extended very easily. Configure it by customizing the config.h (C header file) which is secure and fast as no config files are parsed at runtime.
|
||||||
|
|
||||||
The following information is included:
|
The following information is included:
|
||||||
|
|
||||||
- battery percentage
|
- Battery percentage
|
||||||
- cpu usage (in percent)
|
- CPU usage (in percent)
|
||||||
- custom shell commands
|
- Custom shell commands
|
||||||
- date and time
|
- Date and time
|
||||||
- disk numbers (free storage, percentage, total storage and used storage)
|
- Disk[s] status (free storage, percentage, total storage and used storage)
|
||||||
- available entropy
|
- Available entropy
|
||||||
- username/gid/uid of current user
|
- username/gid/uid
|
||||||
- hostname
|
- Hostname
|
||||||
- ip addresses
|
- IP addresses
|
||||||
- load average
|
- Load average
|
||||||
- ram numbers (free ram, percentage, total ram and used ram)
|
- Memory status (free memory, percentage, total memory and used memory)
|
||||||
- temperature
|
- Temperature
|
||||||
- uptime
|
- Uptime
|
||||||
- volume percentage + mute status (alsa)
|
- Volume percentage + mute status (alsa)
|
||||||
- wifi signal percentage and essid
|
- WiFi signal percentage and essid
|
||||||
|
|
||||||
Multiple entries per function are supported and everything can be reordered and customized via the C header file config.h (similar to DWM).
|
Multiple entries per function are supported and everything can be reordered and customized via the C header file config.h (similar to DWM).
|
||||||
|
|
||||||
|
@ -31,17 +31,18 @@ Multiple entries per function are supported and everything can be reordered and
|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
|
|
||||||
Before you continue, please be sure that a C compiler, GNU make and `alsa-lib` (for volume percentage) are installed. Then copy config.def.h to config.h and edit it to your needs. Recompile and install it after every change via `sudo make install`!
|
Before you continue, please be sure that a C compiler (preferrably gcc), GNU make and `alsa-lib` (for volume percentage) are installed. Then copy config.def.h to config.h and customize it to fit your needs. Recompile and install it after modifications:
|
||||||
|
|
||||||
|
$ make clean all
|
||||||
|
# make install
|
||||||
|
|
||||||
### Starting
|
### Starting
|
||||||
|
|
||||||
Put the following code in your ~/.xinitrc (or similar):
|
Write the following code to your ~/.xinitrc (or any other initialization script):
|
||||||
|
|
||||||
```
|
|
||||||
while true; do
|
while true; do
|
||||||
slstatus
|
slstatus
|
||||||
done &
|
done &
|
||||||
```
|
|
||||||
|
|
||||||
The loop is needed that the program runs after suspend to ram.
|
The loop is needed that the program runs after suspend to ram.
|
||||||
|
|
||||||
|
|
1
TODO.md
1
TODO.md
|
@ -2,3 +2,4 @@ Todo
|
||||||
====
|
====
|
||||||
|
|
||||||
- slstatus icon (in that cool dwm icon style)
|
- slstatus icon (in that cool dwm icon style)
|
||||||
|
- include status_reset in the makefile
|
||||||
|
|
19
concat.h
Normal file
19
concat.h
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Thanks to lloyd for contribution
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern char concat[8192];
|
||||||
|
|
||||||
|
extern void
|
||||||
|
ccat(const unsigned short int count, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
unsigned short int i;
|
||||||
|
concat[0] = '\0';
|
||||||
|
|
||||||
|
va_start(ap, count);
|
||||||
|
for(i = 0; i < count; i++)
|
||||||
|
strlcat(concat, va_arg(ap, char *), sizeof(concat));
|
||||||
|
va_end(ap);
|
||||||
|
return;
|
||||||
|
}
|
25
config.def.h
25
config.def.h
|
@ -1,18 +1,15 @@
|
||||||
/* See LICENSE file for copyright and license details. */
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
|
||||||
/* alsa sound */
|
/* alsa sound */
|
||||||
static const char channel[] = "Master";
|
#define ALSA_CHANNEL "Master"
|
||||||
|
|
||||||
/* battery */
|
/* battery */
|
||||||
static const char batterypath[] = "/sys/class/power_supply/";
|
#define BATTERY_PATH "/sys/class/power_supply/"
|
||||||
static const char batterynow[] = "energy_now";
|
#define BATTERY_NOW "energy_now"
|
||||||
static const char batteryfull[] = "energy_full_design";
|
#define BATTERY_FULL "energy_full_design"
|
||||||
|
|
||||||
/* bar update interval in seconds (smallest value = 1) */
|
|
||||||
static unsigned int update_interval = 1;
|
|
||||||
|
|
||||||
/* text to show if no value can be retrieved */
|
/* text to show if no value can be retrieved */
|
||||||
static const char unknowntext[] = "n/a";
|
#define UNKNOWN_STR "n/a"
|
||||||
|
|
||||||
/* statusbar
|
/* statusbar
|
||||||
- battery_perc (battery percentage) [argument: battery name]
|
- battery_perc (battery percentage) [argument: battery name]
|
||||||
|
@ -41,12 +38,8 @@ static const char unknowntext[] = "n/a";
|
||||||
- wifi_essid (wifi essid) [argument: wifi card interface name] */
|
- wifi_essid (wifi essid) [argument: wifi card interface name] */
|
||||||
static const struct arg args[] = {
|
static const struct arg args[] = {
|
||||||
/* function format argument */
|
/* function format argument */
|
||||||
{ wifi_perc, "wifi %4s | ", "wlp3s0" },
|
{ cpu_perc, "[ CPU %4s ]", NULL },
|
||||||
{ battery_perc, "bat %4s | ", "BAT0" },
|
{ ram_perc, "[ Mem %3s ]", NULL },
|
||||||
{ cpu_perc, "cpu %4s ", NULL },
|
{ disk_perc, "[ HDD %3s ]", "/" },
|
||||||
{ temp, "%3s | ", "/sys/devices/platform/coretemp.0/hwmon/hwmon2/temp1_input" },
|
{ datetime, "[ %s ]", "%F %T" },
|
||||||
{ ram_perc, "ram %3s | ", NULL },
|
|
||||||
{ vol_perc, "vol %4s | ", "default" },
|
|
||||||
{ disk_perc, "ssd %3s | ", "/" },
|
|
||||||
{ datetime, "%s", "%y-%m-%d %H:%M:%S" },
|
|
||||||
};
|
};
|
||||||
|
|
15
config.mk
15
config.mk
|
@ -1,30 +1,19 @@
|
||||||
NAME = slstatus
|
|
||||||
VERSION = 1.0
|
VERSION = 1.0
|
||||||
|
|
||||||
# Customize below to fit your system
|
|
||||||
|
|
||||||
# paths
|
|
||||||
PREFIX = /usr/local
|
PREFIX = /usr/local
|
||||||
MANPREFIX = ${PREFIX}/share/man
|
MANPREFIX = ${PREFIX}/share/man
|
||||||
|
|
||||||
X11INC = /usr/X11R6/include
|
X11INC = /usr/X11R6/include
|
||||||
X11LIB = /usr/X11R6/lib
|
X11LIB = /usr/X11R6/lib
|
||||||
|
|
||||||
# includes and libs
|
|
||||||
INCS = -I. -I/usr/include -I${X11INC}
|
INCS = -I. -I/usr/include -I${X11INC}
|
||||||
LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lasound
|
LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lasound
|
||||||
|
|
||||||
# flags
|
# flags
|
||||||
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_GNU_SOURCE
|
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_GNU_SOURCE
|
||||||
CFLAGS = -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
|
CFLAGS = -std=c99 -pedantic -Wno-unused-function -Wall -Wextra -O0 ${INCS} ${CPPFLAGS}
|
||||||
#CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
|
|
||||||
LDFLAGS = ${LIBS}
|
LDFLAGS = ${LIBS}
|
||||||
#LDFLAGS = -s ${LIBS}
|
|
||||||
|
|
||||||
# Solaris
|
|
||||||
#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
|
|
||||||
#LDFLAGS = ${LIBS}
|
|
||||||
|
|
||||||
# compiler and linker
|
|
||||||
CC = cc
|
CC = cc
|
||||||
|
LD = ld
|
||||||
|
|
||||||
|
|
7
loop.sh
Executable file
7
loop.sh
Executable file
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
slstatus
|
||||||
|
status_reset
|
||||||
|
done
|
701
slstatus.c
701
slstatus.c
File diff suppressed because it is too large
Load diff
10
status_reset.c
Normal file
10
status_reset.c
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main(void)
|
||||||
|
{
|
||||||
|
Display *dpy = XOpenDisplay(NULL);
|
||||||
|
XStoreName(dpy, DefaultRootWindow(dpy), NULL);
|
||||||
|
XCloseDisplay(dpy);
|
||||||
|
return (0);
|
||||||
|
}
|
55
strlcat.h
Normal file
55
strlcat.h
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/* $OpenBSD: strlcat.c,v 1.16 2015/08/31 02:53:57 guenther Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Appends src to string dst of size dsize (unlike strncat, dsize is the
|
||||||
|
* full size of dst, not space left). At most dsize-1 characters
|
||||||
|
* will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
|
||||||
|
* Returns strlen(src) + MIN(dsize, strlen(initial dst)).
|
||||||
|
* If retval >= dsize, truncation occurred.
|
||||||
|
*/
|
||||||
|
size_t
|
||||||
|
strlcat(char *dst, const char *src, size_t dsize)
|
||||||
|
{
|
||||||
|
const char *odst = dst;
|
||||||
|
const char *osrc = src;
|
||||||
|
size_t n = dsize;
|
||||||
|
size_t dlen;
|
||||||
|
|
||||||
|
/* Find the end of dst and adjust bytes left but don't go past end. */
|
||||||
|
while (n-- != 0 && *dst != '\0')
|
||||||
|
dst++;
|
||||||
|
dlen = dst - odst;
|
||||||
|
n = dsize - dlen;
|
||||||
|
|
||||||
|
if (n-- == 0)
|
||||||
|
return(dlen + strlen(src));
|
||||||
|
while (*src != '\0') {
|
||||||
|
if (n != 0) {
|
||||||
|
*dst++ = *src;
|
||||||
|
n--;
|
||||||
|
}
|
||||||
|
src++;
|
||||||
|
}
|
||||||
|
*dst = '\0';
|
||||||
|
|
||||||
|
return(dlen + (src - osrc)); /* count does not include NUL */
|
||||||
|
}
|
50
strlcpy.h
Normal file
50
strlcpy.h
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/* $OpenBSD: strlcpy.c,v 1.13 2015/08/31 02:53:57 guenther Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copy string src to buffer dst of size dsize. At most dsize-1
|
||||||
|
* chars will be copied. Always NUL terminates (unless dsize == 0).
|
||||||
|
* Returns strlen(src); if retval >= dsize, truncation occurred.
|
||||||
|
*/
|
||||||
|
size_t
|
||||||
|
strlcpy(char *dst, const char *src, size_t dsize)
|
||||||
|
{
|
||||||
|
const char *osrc = src;
|
||||||
|
size_t nleft = dsize;
|
||||||
|
|
||||||
|
/* Copy as many bytes as will fit. */
|
||||||
|
if (nleft != 0) {
|
||||||
|
while (--nleft != 0) {
|
||||||
|
if ((*dst++ = *src++) == '\0')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Not enough room in dst, add NUL and traverse rest of src. */
|
||||||
|
if (nleft == 0) {
|
||||||
|
if (dsize != 0)
|
||||||
|
*dst = '\0'; /* NUL-terminate dst */
|
||||||
|
while (*src++)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(src - osrc - 1); /* count does not include NUL */
|
||||||
|
}
|
Loading…
Reference in a new issue