Introduction
Introduction Statistics Contact Development Disclaimer Help
slstatus-icons-1.0.patch - sites - public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log
Files
Refs
---
slstatus-icons-1.0.patch (4055B)
---
1 From 9c5d98385f0400f2d423334fd40e321b6ac79528 Mon Sep 17 00:00:00 2001
2 From: sewn <[email protected]>
3 Date: Sat, 8 Feb 2025 16:46:25 +0300
4 Subject: [PATCH] implement icons for volume and battery
5
6 ---
7 components/battery.c | 19 +++++++++++++++++++
8 components/volume.c | 17 +++++++++++++++++
9 config.def.h | 4 ++++
10 slstatus.h | 2 ++
11 4 files changed, 42 insertions(+)
12
13 diff --git a/components/battery.c b/components/battery.c
14 index 1c753f9..7bfd874 100644
15 --- a/components/battery.c
16 +++ b/components/battery.c
17 @@ -1,10 +1,29 @@
18 /* See LICENSE file for copyright and license details. */
19 #include <stdio.h>
20 +#include <stdlib.h>
21 #include <string.h>
22
23 #include "../slstatus.h"
24 #include "../util.h"
25
26 +const char *
27 +battery_icon(const char *bat)
28 +{
29 + unsigned long ul_perc;
30 + const char *perc, *state;
31 + static const char *icons[][11] = {
32 + { "󰂎", "󰁺", "󰁻", "󰁼", "󰁽", "󰁾", "󰁿…
33 + { "󰢟", "󰢜", "󰂆", "󰂇", "󰂈", "󰢝", "󰂉…
34 + };
35 +
36 + if (!(perc = battery_perc(bat)) || !(state = battery_state(bat)…
37 + return NULL;
38 +
39 + ul_perc = strtoul(perc, NULL, 10);
40 +
41 + return bprintf("%s %d", icons[state[0] == '+'][ul_perc / 10], u…
42 +}
43 +
44 #if defined(__linux__)
45 /*
46 * https://www.kernel.org/doc/html/latest/power/power_supply_class.html
47 diff --git a/components/volume.c b/components/volume.c
48 index 6cec556..5c597b4 100644
49 --- a/components/volume.c
50 +++ b/components/volume.c
51 @@ -1,6 +1,7 @@
52 /* See LICENSE file for copyright and license details. */
53 #include <fcntl.h>
54 #include <stdio.h>
55 +#include <stdlib.h>
56 #include <string.h>
57 #include <sys/ioctl.h>
58 #include <unistd.h>
59 @@ -8,6 +9,22 @@
60 #include "../slstatus.h"
61 #include "../util.h"
62
63 +const char *
64 +vol_icon(const char *arg)
65 +{
66 + char *p;
67 + const char *perc;
68 + static const char *icons[] = { "󰕿", "󰖀", "󰕾" };
69 + unsigned long ul_perc;
70 +
71 + if (!(perc = vol_perc(arg)))
72 + return NULL;
73 + p = strrchr(perc, ' ');
74 + ul_perc = strtoul(p ? p + 1 : perc, NULL, 10);
75 +
76 + return bprintf("%s %d", p ? "󰝟" : icons[ul_perc / 34], ul_pe…
77 +}
78 +
79 #if defined(__OpenBSD__) | defined(__FreeBSD__)
80 #include <poll.h>
81 #include <sndio.h>
82 diff --git a/config.def.h b/config.def.h
83 index d805331..98dc3a0 100644
84 --- a/config.def.h
85 +++ b/config.def.h
86 @@ -12,6 +12,8 @@ static const char unknown_str[] = "n/a";
87 /*
88 * function description argument (exampl…
89 *
90 + * battery_icon battery_perc with an icon battery name (BA…
91 + * NULL on OpenBSD/…
92 * battery_perc battery percentage battery name (BA…
93 * NULL on OpenBSD/…
94 * battery_remaining battery remaining HH:MM battery name (BA…
95 @@ -58,6 +60,8 @@ static const char unknown_str[] = "n/a";
96 * uid UID of current user NULL
97 * uptime system uptime NULL
98 * username username of current user NULL
99 + * vol_icon vol_perc with an icon mixer file (/dev…
100 + * NULL on OpenBSD/…
101 * vol_perc OSS/ALSA volume in percent mixer file (/dev…
102 * NULL on OpenBSD/…
103 * wifi_essid WiFi ESSID interface name (…
104 diff --git a/slstatus.h b/slstatus.h
105 index 8ef5874..b60c573 100644
106 --- a/slstatus.h
107 +++ b/slstatus.h
108 @@ -4,6 +4,7 @@
109 const char *battery_perc(const char *);
110 const char *battery_remaining(const char *);
111 const char *battery_state(const char *);
112 +const char *battery_icon(const char *);
113
114 /* cat */
115 const char *cat(const char *path);
116 @@ -77,6 +78,7 @@ const char *uid(const char *unused);
117 const char *username(const char *unused);
118
119 /* volume */
120 +const char *vol_icon(const char *card);
121 const char *vol_perc(const char *card);
122
123 /* wifi */
124 --
125 2.48.1
126
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.