1
0
Fork 0

Merge branch 'R41z-master'

This commit is contained in:
Aaron Marcher 2016-09-09 19:07:25 +02:00 committed by Aaron Marcher (drkhsh)
commit 6518f41b1f
12 changed files with 424 additions and 513 deletions

View file

@ -6,3 +6,4 @@ Thanks you very much for your great help!
- [Vlaix](https://github.com/Vlaix)
- [pfannkuckengesicht](https://github.com/pfannkuchengesicht)
- [sahne](https://github.com/sahne)
- [Ali H. Fardan](http://raiz.duckdns.org)

View file

@ -2,6 +2,8 @@
include config.mk
NAME=slstatus
SRC = ${NAME}.c
OBJ = ${SRC:.c=.o}

View file

@ -1,29 +1,29 @@
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:
- battery percentage
- cpu usage (in percent)
- custom shell commands
- date and time
- disk numbers (free storage, percentage, total storage and used storage)
- available entropy
- username/gid/uid of current user
- hostname
- ip addresses
- load average
- ram numbers (free ram, percentage, total ram and used ram)
- temperature
- uptime
- volume percentage + mute status (alsa)
- wifi signal percentage and essid
- Battery percentage
- CPU usage (in percent)
- Custom shell commands
- Date and time
- Disk[s] status (free storage, percentage, total storage and used storage)
- Available entropy
- username/gid/uid
- Hostname
- IP addresses
- Load average
- Memory status (free memory, percentage, total memory and used memory)
- Temperature
- Uptime
- Volume percentage + mute status (alsa)
- 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).
@ -31,17 +31,18 @@ Multiple entries per function are supported and everything can be reordered and
### 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
Put the following code in your ~/.xinitrc (or similar):
Write the following code to your ~/.xinitrc (or any other initialization script):
```
while true; do
slstatus
done &
```
The loop is needed that the program runs after suspend to ram.

View file

@ -2,3 +2,4 @@ Todo
====
- slstatus icon (in that cool dwm icon style)
- include status_reset in the makefile

19
concat.h Normal file
View 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;
}

View file

@ -1,18 +1,15 @@
/* See LICENSE file for copyright and license details. */
/* alsa sound */
static const char channel[] = "Master";
#define ALSA_CHANNEL "Master"
/* battery */
static const char batterypath[] = "/sys/class/power_supply/";
static const char batterynow[] = "energy_now";
static const char batteryfull[] = "energy_full_design";
/* bar update interval in seconds (smallest value = 1) */
static unsigned int update_interval = 1;
#define BATTERY_PATH "/sys/class/power_supply/"
#define BATTERY_NOW "energy_now"
#define BATTERY_FULL "energy_full_design"
/* text to show if no value can be retrieved */
static const char unknowntext[] = "n/a";
#define UNKNOWN_STR "n/a"
/* statusbar
- 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] */
static const struct arg args[] = {
/* function format argument */
{ wifi_perc, "wifi %4s | ", "wlp3s0" },
{ battery_perc, "bat %4s | ", "BAT0" },
{ cpu_perc, "cpu %4s ", NULL },
{ temp, "%3s | ", "/sys/devices/platform/coretemp.0/hwmon/hwmon2/temp1_input" },
{ ram_perc, "ram %3s | ", NULL },
{ vol_perc, "vol %4s | ", "default" },
{ disk_perc, "ssd %3s | ", "/" },
{ datetime, "%s", "%y-%m-%d %H:%M:%S" },
{ cpu_perc, "[ CPU %4s ]", NULL },
{ ram_perc, "[ Mem %3s ]", NULL },
{ disk_perc, "[ HDD %3s ]", "/" },
{ datetime, "[ %s ]", "%F %T" },
};

View file

@ -1,30 +1,19 @@
NAME = slstatus
VERSION = 1.0
# Customize below to fit your system
# paths
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man
X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib
# includes and libs
INCS = -I. -I/usr/include -I${X11INC}
LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lasound
# flags
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_GNU_SOURCE
CFLAGS = -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
#CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
CFLAGS = -std=c99 -pedantic -Wno-unused-function -Wall -Wextra -O0 ${INCS} ${CPPFLAGS}
LDFLAGS = ${LIBS}
#LDFLAGS = -s ${LIBS}
# Solaris
#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
#LDFLAGS = ${LIBS}
# compiler and linker
CC = cc
LD = ld

7
loop.sh Executable file
View file

@ -0,0 +1,7 @@
#!/bin/sh
while true
do
slstatus
status_reset
done

File diff suppressed because it is too large Load diff

10
status_reset.c Normal file
View 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
View 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
View 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 */
}