From cb6052a9d39791ac5e137c0de0e75879f4a8e01b Mon Sep 17 00:00:00 2001 From: TolaMironcenko Date: Thu, 4 Sep 2025 15:24:48 +0700 Subject: [PATCH] updated config --- bin/restart_slstatus | 5 + bin/startdwm.sh | 12 +- dwm/config.h | 9 +- slstatus/LICENSE | 7 +- slstatus/Makefile | 3 +- slstatus/README | 2 +- slstatus/components/ip.c | 26 ++++ slstatus/components/keymap.c | 4 +- slstatus/components/ram.c | 61 +++++--- slstatus/components/weather.c | 21 --- slstatus/components/wifi.c | 262 ++++++++++++++++++++++++++-------- slstatus/components/wttr.sh | 28 ---- slstatus/config.def.h | 1 + slstatus/config.h | 20 +-- slstatus/config.mk | 2 +- slstatus/slstatus.c | 1 + slstatus/slstatus.h | 3 +- slstatus/util.c | 17 +++ slstatus/util.h | 2 + 19 files changed, 331 insertions(+), 155 deletions(-) create mode 100755 bin/restart_slstatus delete mode 100644 slstatus/components/weather.c delete mode 100755 slstatus/components/wttr.sh diff --git a/bin/restart_slstatus b/bin/restart_slstatus new file mode 100755 index 0000000..8fc36b2 --- /dev/null +++ b/bin/restart_slstatus @@ -0,0 +1,5 @@ +#!/bin/sh + +killall slstatus +sleep 1 +slstatus & diff --git a/bin/startdwm.sh b/bin/startdwm.sh index 708f72f..56ca27c 100755 --- a/bin/startdwm.sh +++ b/bin/startdwm.sh @@ -1,13 +1,17 @@ #!/bin/sh -export GTK_THEME=Adwaita:dark -gsettings set org.gnome.desktop.interface gtk-theme Adwaita:dark -gsettings set org.gnome.desktop.interface icon-theme Papirus-Dark +export GTK_THEME=Colloid-Dark +gsettings set org.gnome.desktop.interface gtk-theme 'Colloid-Dark' +gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark' +gsettings set org.gnome.desktop.interface icon-theme 'WhiteSur-dark' +gsettings set org.gnome.desktop.interface cursor-theme 'Bibata-Modern-Ice' ~/dotfiles-dwm/bin/background.sh & setxkbmap "us,ru" -option 'grp:win_space_toggle' dunst & lxpolkit & +slstatus & xrdb -merge ~/dotfiles-dwm/Xresources - +~/.screenlayout/worklayout.sh +clipse -listen & exec dwm 2> ~/.dwm.log diff --git a/dwm/config.h b/dwm/config.h index 55e153c..7aa3b9e 100644 --- a/dwm/config.h +++ b/dwm/config.h @@ -62,13 +62,19 @@ static const Layout layouts[] = { static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ static const char *dmenucmd[] = { "dmenu_run", "-l", "10", "-x", "400", "-y", "300", "-z", "500", NULL }; static const char *powermenucmd[] = { "dmenu-powermenu", NULL }; -static const char *termcmd[] = { "xterm", NULL }; +static const char *termcmd[] = { "kitty", NULL }; +static const char *filemanagercmd[] = { "thunar", NULL }; +static const char *clipboardcmd[] = { "kitty", "clipse", NULL }; +static const char *browsercmd[] = { "firefox", NULL }; static const Key keys[] = { /* modifier key function argument */ { MODKEY, XK_p, spawn, {.v = dmenucmd } }, { MODKEY|ShiftMask, XK_p, spawn, {.v = powermenucmd} }, { MODKEY, XK_Return, spawn, {.v = termcmd } }, + { MODKEY, XK_s, spawn, {.v = filemanagercmd } }, + { MODKEY, XK_c, spawn, {.v = clipboardcmd } }, + { MODKEY|ShiftMask, XK_f, spawn, {.v = browsercmd } }, { MODKEY, XK_b, togglebar, {0} }, { MODKEY, XK_j, focusstackvis, {.i = +1 } }, { MODKEY, XK_k, focusstackvis, {.i = -1 } }, @@ -128,4 +134,3 @@ static const Button buttons[] = { { ClkTagBar, MODKEY, Button1, tag, {0} }, { ClkTagBar, MODKEY, Button3, toggletag, {0} }, }; - diff --git a/slstatus/LICENSE b/slstatus/LICENSE index 8bee9c8..3fcac59 100644 --- a/slstatus/LICENSE +++ b/slstatus/LICENSE @@ -1,6 +1,6 @@ ISC License -Copyright 2016-2022 Aaron Marcher +Copyright 2016-2025 Aaron Marcher Copyright 2016 Roy Freytag Copyright 2016 Vincent Loupmon @@ -21,7 +21,7 @@ Copyright 2018 Ian Remmler Copyright 2016-2019 Joerg Jung Copyright 2019 Ryan Kes Copyright 2019 Cem Keylan -Copyright 2019 Dimitris Papastamos +Copyright 2019 Spiros Thanasoulas Copyright 2019-2022 Ingo Feinerer Copyright 2020 Alexandre Ratchov Copyright 2020 Mart Lubbers @@ -29,6 +29,9 @@ Copyright 2020 Daniel Moch Copyright 2022 Nickolas Raymond Kaczynski Copyright 2022 Patrick Iacob Copyright 2021-2022 Steven Ward +Copyright 2025 Joakim Sindholt +Copyright 2025 Al +Copyright 2025 sewn Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/slstatus/Makefile b/slstatus/Makefile index 809a41f..7a18274 100644 --- a/slstatus/Makefile +++ b/slstatus/Makefile @@ -27,8 +27,7 @@ COM =\ components/uptime\ components/user\ components/volume\ - components/wifi \ - components/weather + components/wifi all: slstatus diff --git a/slstatus/README b/slstatus/README index 12d38bf..4d592bb 100644 --- a/slstatus/README +++ b/slstatus/README @@ -18,7 +18,7 @@ Features - Available entropy - Username/GID/UID - Hostname -- IP address (IPv4 and IPv6) +- IP address (IPv4 and IPv6), interface status - Kernel version - Keyboard indicators - Keymap diff --git a/slstatus/components/ip.c b/slstatus/components/ip.c index 9476549..2cdad46 100644 --- a/slstatus/components/ip.c +++ b/slstatus/components/ip.c @@ -1,6 +1,7 @@ /* See LICENSE file for copyright and license details. */ #include #include +#include #include #include #if defined(__OpenBSD__) @@ -59,3 +60,28 @@ ipv6(const char *interface) { return ip(interface, AF_INET6); } + +const char * +up(const char *interface) +{ + struct ifaddrs *ifaddr, *ifa; + + if (getifaddrs(&ifaddr) < 0) { + warn("getifaddrs:"); + return NULL; + } + + for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { + if (!ifa->ifa_addr) + continue; + + if (!strcmp(ifa->ifa_name, interface)) { + freeifaddrs(ifaddr); + return ifa->ifa_flags & IFF_UP ? "up" : "down"; + } + } + + freeifaddrs(ifaddr); + + return NULL; +} diff --git a/slstatus/components/keymap.c b/slstatus/components/keymap.c index f8a2a47..22224f3 100644 --- a/slstatus/components/keymap.c +++ b/slstatus/components/keymap.c @@ -29,8 +29,8 @@ get_layout(char *syms, int grp_num) int grp; layout = NULL; - tok = strtok(syms, "+:"); - for (grp = 0; tok && grp <= grp_num; tok = strtok(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])) { diff --git a/slstatus/components/ram.c b/slstatus/components/ram.c index 15c4b74..bf71dcf 100644 --- a/slstatus/components/ram.c +++ b/slstatus/components/ram.c @@ -11,36 +11,45 @@ ram_free(const char *unused) { uintmax_t free; + FILE *fp; - if (pscanf("/proc/meminfo", - "MemTotal: %ju kB\n" - "MemFree: %ju kB\n" - "MemAvailable: %ju kB\n", - &free, &free, &free) != 3) + if (!(fp = fopen("/proc/meminfo", "r"))) return NULL; + if (lscanf(fp, "MemFree:", "%ju kB", &free) != 1) { + fclose(fp); + return NULL; + } + + fclose(fp); return fmt_human(free * 1024, 1024); } const char * ram_perc(const char *unused) { - uintmax_t total, free, buffers, cached; + uintmax_t total, free, buffers, cached, shmem, sreclaimable; int percent; + FILE *fp; - if (pscanf("/proc/meminfo", - "MemTotal: %ju kB\n" - "MemFree: %ju kB\n" - "MemAvailable: %ju kB\n" - "Buffers: %ju kB\n" - "Cached: %ju kB\n", - &total, &free, &buffers, &buffers, &cached) != 5) + if (!(fp = fopen("/proc/meminfo", "r"))) return NULL; + if (lscanf(fp, "MemTotal:", "%ju kB", &total) != 1 || + lscanf(fp, "MemFree:", "%ju kB", &free) != 1 || + lscanf(fp, "Buffers:", "%ju kB", &buffers) != 1 || + lscanf(fp, "Cached:", "%ju kB", &cached) != 1 || + lscanf(fp, "Shmem:", "%ju kB", &shmem) != 1 || + lscanf(fp, "SReclaimable:", "%ju kB", &sreclaimable) != 1) { + fclose(fp); + return NULL; + } + fclose(fp); + if (total == 0) return NULL; - percent = 100 * ((total - free) - (buffers + cached)) / total; + percent = 100 * (total - free - buffers - cached - sreclaimable + shmem) / total; return bprintf("%d", percent); } @@ -59,18 +68,24 @@ const char * ram_used(const char *unused) { - uintmax_t total, free, buffers, cached, used; + uintmax_t total, free, buffers, cached, used, shmem, sreclaimable; + FILE *fp; - if (pscanf("/proc/meminfo", - "MemTotal: %ju kB\n" - "MemFree: %ju kB\n" - "MemAvailable: %ju kB\n" - "Buffers: %ju kB\n" - "Cached: %ju kB\n", - &total, &free, &buffers, &buffers, &cached) != 5) + if (!(fp = fopen("/proc/meminfo", "r"))) return NULL; - used = (total - free - buffers - cached); + if (lscanf(fp, "MemTotal:", "%ju kB", &total) != 1 || + lscanf(fp, "MemFree:", "%ju kB", &free) != 1 || + lscanf(fp, "Buffers:", "%ju kB", &buffers) != 1 || + lscanf(fp, "Cached:", "%ju kB", &cached) != 1 || + lscanf(fp, "Shmem:", "%ju kB", &shmem) != 1 || + lscanf(fp, "SReclaimable:", "%ju kB", &sreclaimable) != 1) { + fclose(fp); + return NULL; + } + fclose(fp); + + used = total - free - buffers - cached - sreclaimable + shmem; return fmt_human(used * 1024, 1024); } #elif defined(__OpenBSD__) diff --git a/slstatus/components/weather.c b/slstatus/components/weather.c deleted file mode 100644 index a19662b..0000000 --- a/slstatus/components/weather.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include - -#include "../slstatus.h" -#include "../util.h" - -#define WTTR_TEMP "/tmp/wttr" - -const char *weather() -{ - FILE *wttr = fopen(WTTR_TEMP, "r"); - char temp[10]; - memset(&temp, '\0', 10); - - fgets(temp, 10, wttr); - fclose(wttr); - - temp[strlen(temp)-1] = '\0'; - - return bprintf("%s", temp); -} diff --git a/slstatus/components/wifi.c b/slstatus/components/wifi.c index 4543d32..23af201 100644 --- a/slstatus/components/wifi.c +++ b/slstatus/components/wifi.c @@ -15,86 +15,232 @@ (2 * (rssi + 100))) #if defined(__linux__) - #include - #include + #include + #include + #include + #include + #include - #define NET_OPERSTATE "/sys/class/net/%s/operstate" + static int nlsock = -1; + static uint32_t seq = 1; + static char resp[4096]; - const char * - wifi_perc(const char *interface) + static char * + findattr(int attr, const char *p, const char *e, size_t *len) { - int cur; - size_t i; - char *p, *datastart; - char path[PATH_MAX]; - char status[5]; - FILE *fp; - - if (esnprintf(path, sizeof(path), NET_OPERSTATE, interface) < 0) - return NULL; - if (!(fp = fopen(path, "r"))) { - warn("fopen '%s':", path); - return NULL; + while (p < e) { + struct nlattr nla; + memcpy(&nla, p, sizeof(nla)); + if (nla.nla_type == attr) { + *len = nla.nla_len - NLA_HDRLEN; + return (char *)(p + NLA_HDRLEN); + } + p += NLA_ALIGN(nla.nla_len); } - p = fgets(status, 5, fp); - fclose(fp); - if (!p || strcmp(status, "up\n") != 0) - return NULL; + return NULL; + } - if (!(fp = fopen("/proc/net/wireless", "r"))) { - warn("fopen '/proc/net/wireless':"); - return NULL; + static uint16_t + nl80211fam(void) + { + static const char family[] = "nl80211"; + static uint16_t id; + ssize_t r; + size_t len; + char ctrl[NLMSG_HDRLEN+GENL_HDRLEN+NLA_HDRLEN+NLA_ALIGN(sizeof(family))] = {0}, *p = ctrl; + + if (id) + return id; + + memcpy(p, &(struct nlmsghdr){ + .nlmsg_len = sizeof(ctrl), + .nlmsg_type = GENL_ID_CTRL, + .nlmsg_flags = NLM_F_REQUEST, + .nlmsg_seq = seq++, + .nlmsg_pid = 0, + }, sizeof(struct nlmsghdr)); + p += NLMSG_HDRLEN; + memcpy(p, &(struct genlmsghdr){ + .cmd = CTRL_CMD_GETFAMILY, + .version = 1, + }, sizeof(struct genlmsghdr)); + p += GENL_HDRLEN; + memcpy(p, &(struct nlattr){ + .nla_len = NLA_HDRLEN+sizeof(family), + .nla_type = CTRL_ATTR_FAMILY_NAME, + }, sizeof(struct nlattr)); + p += NLA_HDRLEN; + memcpy(p, family, sizeof(family)); + + if (nlsock < 0) + nlsock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); + if (nlsock < 0) { + warn("socket 'AF_NETLINK':"); + return 0; } + if (send(nlsock, ctrl, sizeof(ctrl), 0) != sizeof(ctrl)) { + warn("send 'AF_NETLINK':"); + return 0; + } + r = recv(nlsock, resp, sizeof(resp), 0); + if (r < 0) { + warn("recv 'AF_NETLINK':"); + return 0; + } + if ((size_t)r <= sizeof(ctrl)) + return 0; + p = findattr(CTRL_ATTR_FAMILY_ID, resp + sizeof(ctrl), resp + r, &len); + if (p && len == 2) + memcpy(&id, p, 2); - for (i = 0; i < 3; i++) - if (!(p = fgets(buf, sizeof(buf) - 1, fp))) - break; + return id; + } - fclose(fp); - if (i < 2 || !p) - return NULL; + static int + ifindex(const char *interface) + { + static struct ifreq ifr; + static int ifsock = -1; - if (!(datastart = strstr(buf, interface))) - return NULL; - - datastart = (datastart+(strlen(interface)+1)); - sscanf(datastart + 1, " %*d %d %*d %*d\t\t %*d\t " - "%*d\t\t%*d\t\t %*d\t %*d\t\t %*d", &cur); - - /* 70 is the max of /proc/net/wireless */ - return bprintf("%d", (int)((float)cur / 70 * 100)); + if (ifsock < 0) + ifsock = socket(AF_UNIX, SOCK_DGRAM, 0); + if (ifsock < 0) { + warn("socket 'AF_UNIX':"); + return -1; + } + if (strcmp(ifr.ifr_name, interface) != 0) { + strcpy(ifr.ifr_name, interface); + if (ioctl(ifsock, SIOCGIFINDEX, &ifr) != 0) { + warn("ioctl 'SIOCGIFINDEX':"); + return -1; + } + } + return ifr.ifr_ifindex; } const char * wifi_essid(const char *interface) { - static char id[IW_ESSID_MAX_SIZE+1]; - int sockfd; - struct iwreq wreq; - - memset(&wreq, 0, sizeof(struct iwreq)); - wreq.u.essid.length = IW_ESSID_MAX_SIZE+1; - if (esnprintf(wreq.ifr_name, sizeof(wreq.ifr_name), "%s", - interface) < 0) - return NULL; - - if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - warn("socket 'AF_INET':"); + uint16_t fam = nl80211fam(); + ssize_t r; + size_t len; + char req[NLMSG_HDRLEN+GENL_HDRLEN+NLA_HDRLEN+NLA_ALIGN(4)] = {0}, *p = req; + int idx = ifindex(interface); + if (!fam) { + fprintf(stderr, "nl80211 family not found\n"); return NULL; } - wreq.u.essid.pointer = id; - if (ioctl(sockfd,SIOCGIWESSID, &wreq) < 0) { - warn("ioctl 'SIOCGIWESSID':"); - close(sockfd); + if (idx < 0) { + fprintf(stderr, "interface %s not found\n", interface); return NULL; } - close(sockfd); + memcpy(p, &(struct nlmsghdr){ + .nlmsg_len = sizeof(req), + .nlmsg_type = fam, + .nlmsg_flags = NLM_F_REQUEST, + .nlmsg_seq = seq++, + .nlmsg_pid = 0, + }, sizeof(struct nlmsghdr)); + p += NLMSG_HDRLEN; + memcpy(p, &(struct genlmsghdr){ + .cmd = NL80211_CMD_GET_INTERFACE, + .version = 1, + }, sizeof(struct genlmsghdr)); + p += GENL_HDRLEN; + memcpy(p, &(struct nlattr){ + .nla_len = NLA_HDRLEN+4, + .nla_type = NL80211_ATTR_IFINDEX, + }, sizeof(struct nlattr)); + p += NLA_HDRLEN; + memcpy(p, &(uint32_t){idx}, 4); - if (!strcmp(id, "")) + if (send(nlsock, req, sizeof(req), 0) != sizeof(req)) { + warn("send 'AF_NETLINK':"); return NULL; + } + r = recv(nlsock, resp, sizeof(resp), 0); + if (r < 0) { + warn("recv 'AF_NETLINK':"); + return NULL; + } - return id; + if ((size_t)r <= NLMSG_HDRLEN + GENL_HDRLEN) + return NULL; + p = findattr(NL80211_ATTR_SSID, resp + NLMSG_HDRLEN + GENL_HDRLEN, resp + r, &len); + if (p) + p[len] = 0; + + return p; + } + + const char * + wifi_perc(const char *interface) + { + static char strength[4]; + struct nlmsghdr hdr; + uint16_t fam = nl80211fam(); + ssize_t r; + size_t len; + char req[NLMSG_HDRLEN + GENL_HDRLEN + NLA_HDRLEN + NLA_ALIGN(4)] = {0}, *p = req, *e; + int idx = ifindex(interface); + + if (idx < 0) { + fprintf(stderr, "interface %s not found\n", interface); + return NULL; + } + + memcpy(p, &(struct nlmsghdr){ + .nlmsg_len = sizeof(req), + .nlmsg_type = fam, + .nlmsg_flags = NLM_F_REQUEST|NLM_F_DUMP, + .nlmsg_seq = seq++, + .nlmsg_pid = 0, + }, sizeof(struct nlmsghdr)); + p += NLMSG_HDRLEN; + memcpy(p, &(struct genlmsghdr){ + .cmd = NL80211_CMD_GET_STATION, + .version = 1, + }, sizeof(struct genlmsghdr)); + p += GENL_HDRLEN; + memcpy(p, &(struct nlattr){ + .nla_len = NLA_HDRLEN + 4, + .nla_type = NL80211_ATTR_IFINDEX, + }, sizeof(struct nlattr)); + p += NLA_HDRLEN; + memcpy(p, &idx, 4); + + if (send(nlsock, req, sizeof(req), 0) != sizeof(req)) { + warn("send 'AF_NETLINK':"); + return NULL; + } + + *strength = 0; + while (1) { + r = recv(nlsock, resp, sizeof(resp), 0); + if (r < 0) { + warn("recv 'AF_NETLINK':"); + return NULL; + } + if ((size_t)r < sizeof(hdr)) + return NULL; + + for (p = resp; p != resp + r && (size_t)(resp + r-p) >= sizeof(hdr); p = e) { + memcpy(&hdr, p, sizeof(hdr)); + e = resp + r - p < hdr.nlmsg_len ? resp + r : p + hdr.nlmsg_len; + + if (!*strength && hdr.nlmsg_len > NLMSG_HDRLEN+GENL_HDRLEN) { + p += NLMSG_HDRLEN+GENL_HDRLEN; + p = findattr(NL80211_ATTR_STA_INFO, p, e, &len); + if (p) + p = findattr(NL80211_STA_INFO_SIGNAL_AVG, p, e, &len); + if (p && len == 1) + snprintf(strength, sizeof(strength), "%d", RSSI_TO_PERC(*p)); + } + if (hdr.nlmsg_type == NLMSG_DONE) + return *strength ? strength : NULL; + } + } } #elif defined(__OpenBSD__) #include diff --git a/slstatus/components/wttr.sh b/slstatus/components/wttr.sh deleted file mode 100755 index c3175be..0000000 --- a/slstatus/components/wttr.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -# This function checks if wttr.in is available before the weather info is fetched -ck_curl() { - curl -sf ru.wttr.in > /dev/null -} - -ck_curl -if [ $? -eq 0 ] # $? means "output of the last command" -then - curl -s v2.wttr.in/tomsk?format="%t\n" > /tmp/wttr - wttr_net=1 -else # Non-zero output would appear both when the site \ - for (( cntr = 0; cntr < 3; cntr++ )) # is down and when you're physically offline - do - echo "Probing. " > /tmp/wttr - sleep 0.5 - echo "Probing.. " > /tmp/wttr - sleep 0.5 - echo "Probing..." > /tmp/wttr - sleep 0.5 # A wee bit of animation - done - ck_curl # Online check is rerun only once, if the first check fails. -fi # In case you're using wifi, and the cron job runs before \ - # it authenticates -if ! [ $wttr_net ] -then echo "Offline fr :'( " > /tmp/wttr -fi \ No newline at end of file diff --git a/slstatus/config.def.h b/slstatus/config.def.h index d805331..100093e 100644 --- a/slstatus/config.def.h +++ b/slstatus/config.def.h @@ -56,6 +56,7 @@ static const char unknown_str[] = "n/a"; * thermal zone on FreeBSD * (tz0, tz1, etc.) * uid UID of current user NULL + * up interface is running interface name (eth0) * uptime system uptime NULL * username username of current user NULL * vol_perc OSS/ALSA volume in percent mixer file (/dev/mixer) diff --git a/slstatus/config.h b/slstatus/config.h index 971754d..17307a7 100644 --- a/slstatus/config.h +++ b/slstatus/config.h @@ -56,6 +56,7 @@ static const char unknown_str[] = "n/a"; * thermal zone on FreeBSD * (tz0, tz1, etc.) * uid UID of current user NULL + * up interface is running interface name (eth0) * uptime system uptime NULL * username username of current user NULL * vol_perc OSS/ALSA volume in percent mixer file (/dev/mixer) @@ -64,13 +65,14 @@ static const char unknown_str[] = "n/a"; * wifi_perc WiFi signal in percent interface name (wlan0) */ static const struct arg args[] = { - /* function format argument */ - { battery_perc, "[%s%]", "BAT0" }, - { weather, "[%s]", NULL }, - { datetime, "[%s]", "%F %T" }, - { cpu_perc, "[ %s%]", NULL }, - { ram_perc, "[󰘚 %s%]", NULL }, - { disk_perc, "[ %s%]", "/" }, - { keymap, "[%s]", NULL }, - { wifi_perc, "[󱚻 %s%]", "wlp3s0" }, + /* function format argument */ + {cpu_perc, " CPU %s%%", NULL}, + {ram_perc, " │ 󰍛 RAM %s%%", NULL}, + {run_command, "%s", + "command -v pactl >/dev/null 2>&1 && printf \" │ 󰕾 VOL %s\" " + "\"$(pactl " + "get-sink-volume @DEFAULT_SINK@ 2>/dev/null | grep -o '[0-9]*%' | head " + "-1)\""}, + {datetime, " │ 󰃭 %s", "%a %b %d"}, + {datetime, " │ 󰥔 %s ", "%I:%M %p"}, }; diff --git a/slstatus/config.mk b/slstatus/config.mk index 07af883..a8f5c23 100644 --- a/slstatus/config.mk +++ b/slstatus/config.mk @@ -1,5 +1,5 @@ # slstatus version -VERSION = 1.0 +VERSION = 1.1 # customize below to fit your system diff --git a/slstatus/slstatus.c b/slstatus/slstatus.c index fd31313..16d88fe 100644 --- a/slstatus/slstatus.c +++ b/slstatus/slstatus.c @@ -58,6 +58,7 @@ main(int argc, char *argv[]) ARGBEGIN { case 'v': die("slstatus-"VERSION); + break; case '1': done = 1; /* FALLTHROUGH */ diff --git a/slstatus/slstatus.h b/slstatus/slstatus.h index 979d0c1..394281c 100644 --- a/slstatus/slstatus.h +++ b/slstatus/slstatus.h @@ -30,6 +30,7 @@ const char *hostname(const char *unused); /* ip */ const char *ipv4(const char *interface); const char *ipv6(const char *interface); +const char *up(const char *interface); /* kernel_release */ const char *kernel_release(const char *unused); @@ -82,5 +83,3 @@ const char *vol_perc(const char *card); /* wifi */ const char *wifi_essid(const char *interface); const char *wifi_perc(const char *interface); - -const char *weather(); \ No newline at end of file diff --git a/slstatus/util.c b/slstatus/util.c index bca9b2e..d33cf9d 100644 --- a/slstatus/util.c +++ b/slstatus/util.c @@ -139,3 +139,20 @@ pscanf(const char *path, const char *fmt, ...) return (n == EOF) ? -1 : n; } + +int +lscanf(FILE *fp, const char *key, const char *fmt, void *res) +{ + int n; + char line[256]; + + n = -1; + while (fgets(line, sizeof(line), fp)) + if (strncmp(line, key, strlen(key)) == 0) { + n = sscanf(line + strlen(key), fmt, res); + break; + } + + rewind(fp); + return (n == 1) ? 1 : -1; +} diff --git a/slstatus/util.h b/slstatus/util.h index cf4b027..7a960aa 100644 --- a/slstatus/util.h +++ b/slstatus/util.h @@ -1,5 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include +#include extern char buf[1024]; @@ -14,3 +15,4 @@ int esnprintf(char *str, size_t size, const char *fmt, ...); const char *bprintf(const char *fmt, ...); const char *fmt_human(uintmax_t num, int base); int pscanf(const char *path, const char *fmt, ...); +int lscanf(FILE *fp, const char *key, const char *fmt, void *res);