Skip to content

Commit 7d42435

Browse files
committed
Merge with upstream; add FreeBSD RAM and Volume fix; add custom config
2 parents 9353cef + 84a2f11 commit 7d42435

19 files changed

+458
-93
lines changed

LICENSE

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ISC License
22

3-
Copyright 2016-2018 Aaron Marcher <[email protected]>
3+
Copyright 2016-2020 Aaron Marcher <[email protected]>
44

55
Copyright 2016 Roy Freytag <[email protected]>
66
Copyright 2016 Vincent Loupmon <[email protected]>
@@ -16,8 +16,16 @@ Copyright 2018 Darron Anderson <[email protected]>
1616
Copyright 2018 Josuah Demangeon <[email protected]>
1717
Copyright 2018 Tobias Tschinkowitz <[email protected]>
1818
Copyright 2018 David Demelier <[email protected]>
19-
Copyright 2018 Michael Buch <[email protected]>
19+
Copyright 2018-2019 Michael Buch <[email protected]>
2020
Copyright 2018 Ian Remmler <[email protected]>
21+
Copyright 2016-2019 Joerg Jung <[email protected]>
22+
Copyright 2019 Ryan Kes <[email protected]>
23+
Copyright 2019 Cem Keylan <[email protected]>
24+
Copyright 2019 dsp <[email protected]>
25+
Copyright 2019-2020 Ingo Feinerer <[email protected]>
26+
Copyright 2020 Alexandre Ratchov <[email protected]>
27+
Copyright 2020 Mart Lubbers <[email protected]>
28+
Copyright 2020 Daniel Moch <[email protected]>
2129

2230
Permission to use, copy, modify, and/or distribute this software for any
2331
purpose with or without fee is hereby granted, provided that the above

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ COM =\
2121
components/num_files\
2222
components/ram\
2323
components/run_command\
24+
components/separator\
2425
components/swap\
2526
components/temperature\
2627
components/uptime\

README

+68
Original file line numberDiff line numberDiff line change
@@ -1 +1,69 @@
1+
<<<<<<< HEAD
12
This is a FreeBSD port of the original slstatus utility
3+
=======
4+
slstatus - suckless status
5+
==========================
6+
slstatus is a suckless status monitor for window managers that use WM_NAME
7+
(e.g. dwm) or stdin to fill the status bar.
8+
9+
10+
Features
11+
--------
12+
- Battery percentage/state/time left
13+
- CPU usage
14+
- CPU frequency
15+
- Custom shell commands
16+
- Date and time
17+
- Disk status (free storage, percentage, total storage and used storage)
18+
- Available entropy
19+
- Username/GID/UID
20+
- Hostname
21+
- IP address (IPv4 and IPv6)
22+
- Kernel version
23+
- Keyboard indicators
24+
- Keymap
25+
- Load average
26+
- Network speeds (RX and TX)
27+
- Number of files in a directory (hint: Maildir)
28+
- Memory status (free memory, percentage, total memory and used memory)
29+
- Swap status (free swap, percentage, total swap and used swap)
30+
- Temperature
31+
- Uptime
32+
- Volume percentage
33+
- WiFi signal percentage and ESSID
34+
35+
36+
Requirements
37+
------------
38+
Currently slstatus works on FreeBSD, Linux and OpenBSD.
39+
In order to build slstatus you need the Xlib header files.
40+
41+
42+
Installation
43+
------------
44+
Edit config.mk to match your local setup (slstatus is installed into the
45+
/usr/local namespace by default).
46+
47+
Afterwards enter the following command to build and install slstatus (if
48+
necessary as root):
49+
50+
make clean install
51+
52+
53+
Running slstatus
54+
----------------
55+
See the man page for details.
56+
57+
58+
Configuration
59+
-------------
60+
slstatus can be customized by creating a custom config.h and (re)compiling the
61+
source code. This keeps it fast, secure and simple.
62+
63+
64+
Upcoming
65+
--------
66+
67+
A release (v1.0) will come soon... ;)
68+
After a long phase of inactivity, development has been continued!
69+
>>>>>>> 84a2f117a32f0796045941260cdc4b69852b41e0

TODO

-2
This file was deleted.

components/battery.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
} map[] = {
5353
{ "Charging", "+" },
5454
{ "Discharging", "-" },
55+
{ "Full", "o" },
5556
};
5657
size_t i;
5758
char path[PATH_MAX], state[12];
@@ -196,11 +197,7 @@
196197
return NULL;
197198
}
198199
#elif defined(__FreeBSD__)
199-
#include <dev/acpica/acpiio.h>
200-
#include <fcntl.h>
201-
#include <sys/ioctl.h>
202200
#include <sys/sysctl.h>
203-
#include <unistd.h>
204201

205202
const char *
206203
battery_perc(const char *unused)

components/cpu.c

+35-27
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
cpu_perc(void)
2525
{
2626
static long double a[7];
27-
long double b[7];
27+
long double b[7], sum;
2828

2929
memcpy(b, a, sizeof(b));
3030
/* cpu user nice system idle iowait irq softirq */
@@ -37,13 +37,16 @@
3737
return NULL;
3838
}
3939

40+
sum = (b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6]) -
41+
(a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6]);
42+
43+
if (sum == 0) {
44+
return NULL;
45+
}
46+
4047
return bprintf("%d", (int)(100 *
41-
((b[0] + b[1] + b[2] + b[5] + b[6]) -
42-
(a[0] + a[1] + a[2] + a[5] + a[6])) /
43-
((b[0] + b[1] + b[2] + b[3] + b[4] + b[5] +
44-
b[6]) -
45-
(a[0] + a[1] + a[2] + a[3] + a[4] + a[5] +
46-
a[6]))));
48+
((b[0] + b[1] + b[2] + b[5] + b[6]) -
49+
(a[0] + a[1] + a[2] + a[5] + a[6])) / sum));
4750
}
4851
#elif defined(__OpenBSD__)
4952
#include <sys/param.h>
@@ -53,8 +56,7 @@
5356
const char *
5457
cpu_freq(void)
5558
{
56-
int mib[2];
57-
uintmax_t freq;
59+
int freq, mib[2];
5860
size_t size;
5961

6062
mib[0] = CTL_HW;
@@ -76,7 +78,7 @@
7678
{
7779
int mib[2];
7880
static uintmax_t a[CPUSTATES];
79-
uintmax_t b[CPUSTATES];
81+
uintmax_t b[CPUSTATES], sum;
8082
size_t size;
8183

8284
mib[0] = CTL_KERN;
@@ -93,15 +95,18 @@
9395
return NULL;
9496
}
9597

98+
sum = (a[CP_USER] + a[CP_NICE] + a[CP_SYS] + a[CP_INTR] + a[CP_IDLE]) -
99+
(b[CP_USER] + b[CP_NICE] + b[CP_SYS] + b[CP_INTR] + b[CP_IDLE]);
100+
101+
if (sum == 0) {
102+
return NULL;
103+
}
104+
96105
return bprintf("%d", 100 *
97-
((a[CP_USER] + a[CP_NICE] + a[CP_SYS] +
98-
a[CP_INTR]) -
99-
(b[CP_USER] + b[CP_NICE] + b[CP_SYS] +
100-
b[CP_INTR])) /
101-
((a[CP_USER] + a[CP_NICE] + a[CP_SYS] +
102-
a[CP_INTR] + a[CP_IDLE]) -
103-
(b[CP_USER] + b[CP_NICE] + b[CP_SYS] +
104-
b[CP_INTR] + b[CP_IDLE])));
106+
((a[CP_USER] + a[CP_NICE] + a[CP_SYS] +
107+
a[CP_INTR]) -
108+
(b[CP_USER] + b[CP_NICE] + b[CP_SYS] +
109+
b[CP_INTR])) / sum);
105110
}
106111
#elif defined(__FreeBSD__)
107112
#include <sys/param.h>
@@ -130,7 +135,7 @@
130135
{
131136
size_t size;
132137
static long a[CPUSTATES];
133-
long b[CPUSTATES];
138+
long b[CPUSTATES], sum;
134139

135140
size = sizeof(a);
136141
memcpy(b, a, sizeof(b));
@@ -143,14 +148,17 @@
143148
return NULL;
144149
}
145150

151+
sum = (a[CP_USER] + a[CP_NICE] + a[CP_SYS] + a[CP_INTR] + a[CP_IDLE]) -
152+
(b[CP_USER] + b[CP_NICE] + b[CP_SYS] + b[CP_INTR] + b[CP_IDLE]);
153+
154+
if (sum == 0) {
155+
return NULL;
156+
}
157+
146158
return bprintf("%d", 100 *
147-
((a[CP_USER] + a[CP_NICE] + a[CP_SYS] +
148-
a[CP_INTR]) -
149-
(b[CP_USER] + b[CP_NICE] + b[CP_SYS] +
150-
b[CP_INTR])) /
151-
((a[CP_USER] + a[CP_NICE] + a[CP_SYS] +
152-
a[CP_INTR] + a[CP_IDLE]) -
153-
(b[CP_USER] + b[CP_NICE] + b[CP_SYS] +
154-
b[CP_INTR] + b[CP_IDLE])));
159+
((a[CP_USER] + a[CP_NICE] + a[CP_SYS] +
160+
a[CP_INTR]) -
161+
(b[CP_USER] + b[CP_NICE] + b[CP_SYS] +
162+
b[CP_INTR])) / sum);
155163
}
156164
#endif

components/entropy.c

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
return bprintf("%ju", num);
1919
}
2020
#elif defined(__OpenBSD__) | defined(__FreeBSD__)
21-
// Entropy information not needed on BSD systems since they use PRNGs
22-
// for /dev/random
2321
const char *
2422
entropy(void)
2523
{

components/ram.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
#include <vm/vm_param.h>
164164

165165
const char *
166-
ram_free(void) {
166+
ram_free(void) {
167167
struct vmtotal vm_stats;
168168
int mib[] = {CTL_VM, VM_TOTAL};
169169
size_t len;
@@ -172,34 +172,34 @@
172172
if (sysctl(mib, 2, &vm_stats, &len, NULL, 0) == -1
173173
|| !len)
174174
return NULL;
175-
175+
176176
return fmt_human(vm_stats.t_free * getpagesize(), 1024);
177177
}
178178

179179
const char *
180-
ram_total(void) {
181-
long npages;
180+
ram_total(void) {
181+
unsigned int npages;
182182
size_t len;
183183

184184
len = sizeof(npages);
185185
if (sysctlbyname("vm.stats.vm.v_page_count", &npages, &len, NULL, 0) == -1
186186
|| !len)
187187
return NULL;
188-
188+
189189
return fmt_human(npages * getpagesize(), 1024);
190190
}
191191

192192
const char *
193193
ram_perc(void) {
194-
long npages;
195-
long active;
194+
unsigned int npages;
195+
unsigned int active;
196196
size_t len;
197197

198198
len = sizeof(npages);
199199
if (sysctlbyname("vm.stats.vm.v_page_count", &npages, &len, NULL, 0) == -1
200200
|| !len)
201201
return NULL;
202-
202+
203203
if (sysctlbyname("vm.stats.vm.v_active_count", &active, &len, NULL, 0) == -1
204204
|| !len)
205205
return NULL;
@@ -209,7 +209,7 @@
209209

210210
const char *
211211
ram_used(void) {
212-
long active;
212+
unsigned int active;
213213
size_t len;
214214

215215
len = sizeof(active);

components/separator.c

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* See LICENSE file for copyright and license details. */
2+
#include <stdio.h>
3+
4+
#include "../util.h"
5+
6+
const char *
7+
separator(const char *separator)
8+
{
9+
return separator;
10+
}

components/temperature.c

+22-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,28 @@
4545
}
4646

4747
/* kelvin to celsius */
48-
return bprintf("%d", (temp.value - 273150000) / 1E6);
48+
return bprintf("%d", (int)((float)(temp.value-273150000) / 1E6));
49+
}
50+
#elif defined(__FreeBSD__)
51+
#include <stdio.h>
52+
#include <stdlib.h>
53+
#include <sys/sysctl.h>
54+
55+
const char *
56+
temp(const char *zone)
57+
{
58+
char buf[256];
59+
int temp;
60+
size_t len;
61+
62+
len = sizeof(temp);
63+
snprintf(buf, sizeof(buf), "hw.acpi.thermal.%s.temperature", zone);
64+
if (sysctlbyname(buf, &temp, &len, NULL, 0) == -1
65+
|| !len)
66+
return NULL;
67+
68+
/* kelvin to decimal celcius */
69+
return bprintf("%d.%d", (temp - 2731) / 10, abs((temp - 2731) % 10));
4970
}
5071
#elif defined(__FreeBSD__)
5172
#include <stdio.h>

components/uptime.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
const char *
1717
uptime(void)
1818
{
19-
char buf[256];
19+
char warn_buf[256];
2020
uintmax_t h, m;
2121
struct timespec uptime;
2222

2323
if (clock_gettime(UPTIME_FLAG, &uptime) < 0) {
24-
snprintf(buf, 256, "clock_gettime %d", UPTIME_FLAG);
25-
warn(buf);
24+
snprintf(warn_buf, 256, "clock_gettime %d", UPTIME_FLAG);
25+
warn(warn_buf);
2626
return NULL;
2727
}
2828

0 commit comments

Comments
 (0)