added patches
This commit is contained in:
parent
f68f49273e
commit
8c6890f943
13 changed files with 395 additions and 205 deletions
86
components/backlight.c
Normal file
86
components/backlight.c
Normal file
|
@ -0,0 +1,86 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "../util.h"
|
||||
|
||||
#if defined(__linux__)
|
||||
#include <limits.h>
|
||||
|
||||
#define BRIGHTNESS_MAX "/sys/class/backlight/%s/max_brightness"
|
||||
#define BRIGHTNESS_CUR "/sys/class/backlight/%s/brightness"
|
||||
|
||||
const char *
|
||||
backlight_perc(const char *card)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
int max, cur;
|
||||
|
||||
if (esnprintf(path, sizeof (path), BRIGHTNESS_MAX, card) < 0 ||
|
||||
pscanf(path, "%d", &max) != 1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (esnprintf(path, sizeof (path), BRIGHTNESS_CUR, card) < 0 ||
|
||||
pscanf(path, "%d", &cur) != 1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (max == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return bprintf("%d%%", cur * 100 / max);
|
||||
}
|
||||
#elif defined(__OpenBSD__)
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <dev/wscons/wsconsio.h>
|
||||
|
||||
const char *
|
||||
backlight_perc(const char *unused)
|
||||
{
|
||||
int fd, err;
|
||||
struct wsdisplay_param wsd_param = {
|
||||
.param = WSDISPLAYIO_PARAM_BRIGHTNESS
|
||||
};
|
||||
|
||||
if ((fd = open("/dev/ttyC0", O_RDONLY)) < 0) {
|
||||
warn("could not open /dev/ttyC0");
|
||||
return NULL;
|
||||
}
|
||||
if ((err = ioctl(fd, WSDISPLAYIO_GETPARAM, &wsd_param)) < 0) {
|
||||
warn("ioctl 'WSDISPLAYIO_GETPARAM' failed");
|
||||
return NULL;
|
||||
}
|
||||
return bprintf("%d", wsd_param.curval * 100 / wsd_param.max);
|
||||
}
|
||||
#elif defined(__FreeBSD__)
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/backlight.h>
|
||||
|
||||
#define FBSD_BACKLIGHT_DEV "/dev/backlight/%s"
|
||||
|
||||
const char *
|
||||
backlight_perc(const char *card)
|
||||
{
|
||||
char buf[256];
|
||||
struct backlight_props props;
|
||||
int fd;
|
||||
|
||||
snprintf(buf, sizeof(buf), FBSD_BACKLIGHT_DEV, card);
|
||||
if ((fd = open(buf, O_RDWR)) == -1) {
|
||||
warn("could not open %s", card);
|
||||
return NULL;
|
||||
}
|
||||
if (ioctl(fd, BACKLIGHTGETSTATUS, &props) == -1){
|
||||
warn("Cannot query the backlight device");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return bprintf("%d", props.brightness);
|
||||
}
|
||||
#endif
|
|
@ -1,10 +1,29 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../slstatus.h"
|
||||
#include "../util.h"
|
||||
|
||||
const char *
|
||||
battery_icon(const char *bat)
|
||||
{
|
||||
unsigned long ul_perc;
|
||||
const char *perc, *state;
|
||||
static const char *icons[][11] = {
|
||||
{ "", "", "", "", "", "", "", "", "", "", "" },
|
||||
{ "", "", "", "", "", "", "", "", "", "", "" },
|
||||
};
|
||||
|
||||
if (!(perc = battery_perc(bat)) || !(state = battery_state(bat)))
|
||||
return NULL;
|
||||
|
||||
ul_perc = strtoul(perc, NULL, 10);
|
||||
|
||||
return bprintf("%s %d", icons[state[0] == '+'][ul_perc / 10], ul_perc);
|
||||
}
|
||||
|
||||
#if defined(__linux__)
|
||||
/*
|
||||
* https://www.kernel.org/doc/html/latest/power/power_supply_class.html
|
||||
|
|
30
components/kanji.c
Normal file
30
components/kanji.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
/* Written by Madison Lynch <madi@mxdi.xyz> */
|
||||
#include <time.h>
|
||||
|
||||
static const char *symbols[] = {
|
||||
"日", // Sunday
|
||||
"月", // Monday
|
||||
"火", // Tuesday
|
||||
"水", // Wednesday
|
||||
"木", // Thursday
|
||||
"金", // Friday
|
||||
"土" // Saturday
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the appropriate Japanese Kanji character correlating with the current
|
||||
* day of the week.
|
||||
*
|
||||
* @param unused (NULL)
|
||||
* @return the appropriate Kanji character (char)
|
||||
* @author Madison Lynch
|
||||
*/
|
||||
const char *
|
||||
kanji(const char *unused) {
|
||||
const time_t current_time = time(NULL);
|
||||
const unsigned int weekday = localtime(
|
||||
¤t_time
|
||||
)->tm_wday;
|
||||
|
||||
return (weekday < sizeof(symbols) / sizeof(char *)) ? symbols[weekday] : "?";
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
#include "../slstatus.h"
|
||||
#include "../util.h"
|
||||
|
||||
/*
|
||||
* fmt consists of uppercase or lowercase 'c' for caps lock and/or 'n' for num
|
||||
* lock, each optionally followed by '?', in the order of indicators desired.
|
||||
* If followed by '?', the letter with case preserved is included in the output
|
||||
* if the corresponding indicator is on. Otherwise, the letter is always
|
||||
* included, lowercase when off and uppercase when on.
|
||||
*/
|
||||
const char *
|
||||
keyboard_indicators(const char *fmt)
|
||||
{
|
||||
Display *dpy;
|
||||
XKeyboardState state;
|
||||
size_t fmtlen, i, n;
|
||||
int togglecase, isset;
|
||||
char key;
|
||||
|
||||
if (!(dpy = XOpenDisplay(NULL))) {
|
||||
warn("XOpenDisplay: Failed to open display");
|
||||
return NULL;
|
||||
}
|
||||
XGetKeyboardControl(dpy, &state);
|
||||
XCloseDisplay(dpy);
|
||||
|
||||
fmtlen = strnlen(fmt, 4);
|
||||
for (i = n = 0; i < fmtlen; i++) {
|
||||
key = tolower(fmt[i]);
|
||||
if (key != 'c' && key != 'n')
|
||||
continue;
|
||||
|
||||
togglecase = (i + 1 >= fmtlen || fmt[i + 1] != '?');
|
||||
isset = (state.led_mask & (1 << (key == 'n')));
|
||||
|
||||
if (togglecase)
|
||||
buf[n++] = isset ? toupper(key) : key;
|
||||
else if (isset)
|
||||
buf[n++] = fmt[i];
|
||||
}
|
||||
|
||||
buf[n] = 0;
|
||||
return buf;
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
/* 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;
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
/* See LICENSE file for copyright and license details. */
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
@ -8,6 +9,22 @@
|
|||
#include "../slstatus.h"
|
||||
#include "../util.h"
|
||||
|
||||
const char *
|
||||
vol_icon(const char *arg)
|
||||
{
|
||||
char *p;
|
||||
const char *perc;
|
||||
static const char *icons[] = { "", "", "" };
|
||||
unsigned long ul_perc;
|
||||
|
||||
if (!(perc = vol_perc(arg)))
|
||||
return NULL;
|
||||
p = strrchr(perc, ' ');
|
||||
ul_perc = strtoul(p ? p + 1 : perc, NULL, 10);
|
||||
|
||||
return bprintf("%s %d", p ? "" : icons[ul_perc / 34], ul_perc);
|
||||
}
|
||||
|
||||
#if defined(__OpenBSD__) | defined(__FreeBSD__)
|
||||
#include <poll.h>
|
||||
#include <sndio.h>
|
||||
|
@ -182,6 +199,68 @@
|
|||
|
||||
return bprintf("%d", value);
|
||||
}
|
||||
#elif defined(ALSA)
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
static const char *devname = "default";
|
||||
const char *
|
||||
vol_perc(const char *mixname)
|
||||
{
|
||||
snd_mixer_t *mixer = NULL;
|
||||
snd_mixer_selem_id_t *mixid = NULL;
|
||||
snd_mixer_elem_t *elem = NULL;
|
||||
long min = 0, max = 0, volume = -1;
|
||||
int err, sw1, sw2;
|
||||
|
||||
if ((err = snd_mixer_open(&mixer, 0))) {
|
||||
warn("snd_mixer_open: %d", err);
|
||||
return NULL;
|
||||
}
|
||||
if ((err = snd_mixer_attach(mixer, devname))) {
|
||||
warn("snd_mixer_attach(mixer, \"%s\"): %d", devname, err);
|
||||
goto cleanup;
|
||||
}
|
||||
if ((err = snd_mixer_selem_register(mixer, NULL, NULL))) {
|
||||
warn("snd_mixer_selem_register(mixer, NULL, NULL): %d", err);
|
||||
goto cleanup;
|
||||
}
|
||||
if ((err = snd_mixer_load(mixer))) {
|
||||
warn("snd_mixer_load(mixer): %d", err);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
snd_mixer_selem_id_alloca(&mixid);
|
||||
snd_mixer_selem_id_set_name(mixid, mixname);
|
||||
snd_mixer_selem_id_set_index(mixid, 0);
|
||||
|
||||
elem = snd_mixer_find_selem(mixer, mixid);
|
||||
if (!elem) {
|
||||
warn("snd_mixer_find_selem(mixer, \"%s\") == NULL", mixname);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((err = snd_mixer_selem_get_playback_volume_range(elem, &min, &max))) {
|
||||
warn("snd_mixer_selem_get_playback_volume_range(): %d", err);
|
||||
goto cleanup;
|
||||
}
|
||||
if ((err = snd_mixer_selem_get_playback_volume(elem, SND_MIXER_SCHN_MONO, &volume))) {
|
||||
warn("snd_mixer_selem_get_playback_volume(): %d", err);
|
||||
}
|
||||
if ((err = snd_mixer_selem_get_playback_switch(elem, 0, &sw1))) {
|
||||
warn("snd_mixer_selem_get_playback_switch(): %d", err);
|
||||
}
|
||||
if ((err = snd_mixer_selem_get_playback_switch(elem, 1, &sw2))) {
|
||||
warn("snd_mixer_selem_get_playback_switch(): %d", err);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
snd_mixer_free(mixer);
|
||||
snd_mixer_detach(mixer, devname);
|
||||
snd_mixer_close(mixer);
|
||||
|
||||
return volume == -1 ? NULL : bprintf("%s%.0f",
|
||||
!(sw1 || sw2) ? "muted " : "", (volume-min)*100./(max-min));
|
||||
}
|
||||
#else
|
||||
#include <sys/soundcard.h>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue