Upload files to ".suckless/slstatus/components"
This commit is contained in:
parent
66d01ab833
commit
48668eaba4
5 changed files with 234 additions and 0 deletions
86
.suckless/slstatus/components/keymap.c
Normal file
86
.suckless/slstatus/components/keymap.c
Normal file
|
@ -0,0 +1,86 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <X11/XKBlib.h>
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
#include "../slstatus.h"
|
||||
#include "../util.h"
|
||||
|
||||
static int
|
||||
valid_layout_or_variant(char *sym)
|
||||
{
|
||||
size_t i;
|
||||
/* invalid symbols from xkb rules config */
|
||||
static const char *invalid[] = { "evdev", "inet", "pc", "base" };
|
||||
|
||||
for (i = 0; i < LEN(invalid); i++)
|
||||
if (!strncmp(sym, invalid[i], strlen(invalid[i])))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static char *
|
||||
get_layout(char *syms, int grp_num)
|
||||
{
|
||||
char *tok, *layout;
|
||||
int grp;
|
||||
|
||||
layout = NULL;
|
||||
tok = strtok(syms, "+:_");
|
||||
for (grp = 0; tok && grp <= grp_num; tok = strtok(NULL, "+:_")) {
|
||||
if (!valid_layout_or_variant(tok)) {
|
||||
continue;
|
||||
} else if (strlen(tok) == 1 && isdigit(tok[0])) {
|
||||
/* ignore :2, :3, :4 (additional layout groups) */
|
||||
continue;
|
||||
}
|
||||
layout = tok;
|
||||
grp++;
|
||||
}
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
const char *
|
||||
keymap(const char *unused)
|
||||
{
|
||||
Display *dpy;
|
||||
XkbDescRec *desc;
|
||||
XkbStateRec state;
|
||||
char *symbols;
|
||||
const char *layout;
|
||||
|
||||
layout = NULL;
|
||||
|
||||
if (!(dpy = XOpenDisplay(NULL))) {
|
||||
warn("XOpenDisplay: Failed to open display");
|
||||
return NULL;
|
||||
}
|
||||
if (!(desc = XkbAllocKeyboard())) {
|
||||
warn("XkbAllocKeyboard: Failed to allocate keyboard");
|
||||
goto end;
|
||||
}
|
||||
if (XkbGetNames(dpy, XkbSymbolsNameMask, desc)) {
|
||||
warn("XkbGetNames: Failed to retrieve key symbols");
|
||||
goto end;
|
||||
}
|
||||
if (XkbGetState(dpy, XkbUseCoreKbd, &state)) {
|
||||
warn("XkbGetState: Failed to retrieve keyboard state");
|
||||
goto end;
|
||||
}
|
||||
if (!(symbols = XGetAtomName(dpy, desc->names->symbols))) {
|
||||
warn("XGetAtomName: Failed to get atom name");
|
||||
goto end;
|
||||
}
|
||||
layout = bprintf("%s", get_layout(symbols, state.group));
|
||||
XFree(symbols);
|
||||
end:
|
||||
XkbFreeKeyboard(desc, XkbSymbolsNameMask, 1);
|
||||
if (XCloseDisplay(dpy))
|
||||
warn("XCloseDisplay: Failed to close display");
|
||||
|
||||
return layout;
|
||||
}
|
BIN
.suckless/slstatus/components/keymap.o
Normal file
BIN
.suckless/slstatus/components/keymap.o
Normal file
Binary file not shown.
19
.suckless/slstatus/components/load_avg.c
Normal file
19
.suckless/slstatus/components/load_avg.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../slstatus.h"
|
||||
#include "../util.h"
|
||||
|
||||
const char *
|
||||
load_avg(const char *unused)
|
||||
{
|
||||
double avgs[3];
|
||||
|
||||
if (getloadavg(avgs, 3) < 0) {
|
||||
warn("getloadavg: Failed to obtain load average");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return bprintf("%.2f %.2f %.2f", avgs[0], avgs[1], avgs[2]);
|
||||
}
|
BIN
.suckless/slstatus/components/load_avg.o
Normal file
BIN
.suckless/slstatus/components/load_avg.o
Normal file
Binary file not shown.
129
.suckless/slstatus/components/netspeeds.c
Normal file
129
.suckless/slstatus/components/netspeeds.c
Normal file
|
@ -0,0 +1,129 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../slstatus.h"
|
||||
#include "../util.h"
|
||||
|
||||
#if defined(__linux__)
|
||||
#include <stdint.h>
|
||||
|
||||
#define NET_RX_BYTES "/sys/class/net/%s/statistics/rx_bytes"
|
||||
#define NET_TX_BYTES "/sys/class/net/%s/statistics/tx_bytes"
|
||||
|
||||
const char *
|
||||
netspeed_rx(const char *interface)
|
||||
{
|
||||
uintmax_t oldrxbytes;
|
||||
static uintmax_t rxbytes;
|
||||
extern const unsigned int interval;
|
||||
char path[PATH_MAX];
|
||||
|
||||
oldrxbytes = rxbytes;
|
||||
|
||||
if (esnprintf(path, sizeof(path), NET_RX_BYTES, interface) < 0)
|
||||
return NULL;
|
||||
if (pscanf(path, "%ju", &rxbytes) != 1)
|
||||
return NULL;
|
||||
if (oldrxbytes == 0)
|
||||
return NULL;
|
||||
|
||||
return fmt_human((rxbytes - oldrxbytes) * 1000 / interval,
|
||||
1024);
|
||||
}
|
||||
|
||||
const char *
|
||||
netspeed_tx(const char *interface)
|
||||
{
|
||||
uintmax_t oldtxbytes;
|
||||
static uintmax_t txbytes;
|
||||
extern const unsigned int interval;
|
||||
char path[PATH_MAX];
|
||||
|
||||
oldtxbytes = txbytes;
|
||||
|
||||
if (esnprintf(path, sizeof(path), NET_TX_BYTES, interface) < 0)
|
||||
return NULL;
|
||||
if (pscanf(path, "%ju", &txbytes) != 1)
|
||||
return NULL;
|
||||
if (oldtxbytes == 0)
|
||||
return NULL;
|
||||
|
||||
return fmt_human((txbytes - oldtxbytes) * 1000 / interval,
|
||||
1024);
|
||||
}
|
||||
#elif defined(__OpenBSD__) | defined(__FreeBSD__)
|
||||
#include <ifaddrs.h>
|
||||
#include <net/if.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
const char *
|
||||
netspeed_rx(const char *interface)
|
||||
{
|
||||
struct ifaddrs *ifal, *ifa;
|
||||
struct if_data *ifd;
|
||||
uintmax_t oldrxbytes;
|
||||
static uintmax_t rxbytes;
|
||||
extern const unsigned int interval;
|
||||
int if_ok = 0;
|
||||
|
||||
oldrxbytes = rxbytes;
|
||||
|
||||
if (getifaddrs(&ifal) < 0) {
|
||||
warn("getifaddrs failed");
|
||||
return NULL;
|
||||
}
|
||||
rxbytes = 0;
|
||||
for (ifa = ifal; ifa; ifa = ifa->ifa_next)
|
||||
if (!strcmp(ifa->ifa_name, interface) &&
|
||||
(ifd = (struct if_data *)ifa->ifa_data))
|
||||
rxbytes += ifd->ifi_ibytes, if_ok = 1;
|
||||
|
||||
freeifaddrs(ifal);
|
||||
if (!if_ok) {
|
||||
warn("reading 'if_data' failed");
|
||||
return NULL;
|
||||
}
|
||||
if (oldrxbytes == 0)
|
||||
return NULL;
|
||||
|
||||
return fmt_human((rxbytes - oldrxbytes) * 1000 / interval,
|
||||
1024);
|
||||
}
|
||||
|
||||
const char *
|
||||
netspeed_tx(const char *interface)
|
||||
{
|
||||
struct ifaddrs *ifal, *ifa;
|
||||
struct if_data *ifd;
|
||||
uintmax_t oldtxbytes;
|
||||
static uintmax_t txbytes;
|
||||
extern const unsigned int interval;
|
||||
int if_ok = 0;
|
||||
|
||||
oldtxbytes = txbytes;
|
||||
|
||||
if (getifaddrs(&ifal) < 0) {
|
||||
warn("getifaddrs failed");
|
||||
return NULL;
|
||||
}
|
||||
txbytes = 0;
|
||||
for (ifa = ifal; ifa; ifa = ifa->ifa_next)
|
||||
if (!strcmp(ifa->ifa_name, interface) &&
|
||||
(ifd = (struct if_data *)ifa->ifa_data))
|
||||
txbytes += ifd->ifi_obytes, if_ok = 1;
|
||||
|
||||
freeifaddrs(ifal);
|
||||
if (!if_ok) {
|
||||
warn("reading 'if_data' failed");
|
||||
return NULL;
|
||||
}
|
||||
if (oldtxbytes == 0)
|
||||
return NULL;
|
||||
|
||||
return fmt_human((txbytes - oldtxbytes) * 1000 / interval,
|
||||
1024);
|
||||
}
|
||||
#endif
|
Loading…
Add table
Reference in a new issue