Re: [hackers][slstatus][PATCH] Report average CPU frequency of cluster instead of single-core one

2020-11-30 Thread Aaron Marcher

Hi,

thanks for your patch!
What do you all think of adding this as a patch to the wiki?
Or is this rather something that more people wish of being included into 
the codebase?


Cheers!
Aaron

On 20-11-11 Wed, Platon Ryzhikov wrote:

This is especially useful for ARM SoCs with different cores

---
components/cpu.c | 27 +--
config.def.h |  4 +++-
2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/components/cpu.c b/components/cpu.c
index 9e28003..c326297 100644
--- a/components/cpu.c
+++ b/components/cpu.c
@@ -7,16 +7,31 @@

#if defined(__linux__)
const char *
-   cpu_freq(void)
+   cpu_freq(const char *range)
{
-   uintmax_t freq;
-
-   /* in kHz */
-   if (pscanf("/sys/devices/system/cpu/cpu0/cpufreq/"
-  "scaling_cur_freq", "%ju", ) != 1) {
+   uintmax_t freq, sum_freq;
+   static unsigned int i, cpu0, ncpus;
+
+   sum_freq = 0;
+   /* define first cpu in cluster and their number */
+   if (!range) {
+   cpu0 = 0;
+   ncpus = 1;
+   } else if (sscanf(range, "%u %u", , ) != 2) {
return NULL;
}

+   for (i = cpu0; i < cpu0 + ncpus; i += 1) {
+   /* in kHz */
+   if 
(pscanf(bprintf("/sys/devices/system/cpu/cpu%d/cpufreq/"
+  "scaling_cur_freq", i), "%ju", ) != 1) {
+   return NULL;
+   }
+   sum_freq += freq;
+   }
+
+   freq = (double)sum_freq/(double)ncpus;
+
return fmt_human(freq * 1000, 1000);
}

diff --git a/config.def.h b/config.def.h
index e06be66..6554bb3 100644
--- a/config.def.h
+++ b/config.def.h
@@ -19,7 +19,9 @@ static const char unknown_str[] = "n/a";
 * battery_remaining   battery remaining HH:MM battery name (BAT0)
 * NULL on OpenBSD/FreeBSD
 * cpu_perccpu usage in percentNULL
- * cpu_freqcpu frequency in MHzNULL
+ * cpu_freqcpu frequency in MHzstring "first_cpu ncpus"
+ * "0 2" means cpu0+cpu1
+ * NULL on OpenBSD/FreeBSD
 * datetimedate and time   format string (%F %T)
 * disk_free   free disk space in GB   mountpoint path (/)
 * disk_perc   disk usage in percent   mountpoint path (/)
--
2.29.2



--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][patch] Use ALSA for vol_perc on Linux

2020-11-30 Thread Aaron Marcher

Hi Thomas,

thanks for your patch.
With the OSS compatbility module ALSA sound card volume works perfectly 
fine in Linux without ALSA as an external dependency.
Thus I would suggest to add this as a patch to the wiki. What do you 
think?


Regards
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE

On 20-05-24 Sun, Thomas Vigouroux wrote:

Quoting Ivan Tham (2020-05-22 18:32:58)

If I recall correctly, it is something like:

const char* buf = NULL;

...

if (failure)
goto error;
...

buf = bprintf("%ld", (100 * (outvol - minv)) / (maxv - minv));

error:
snd_mixer_close(handle);
return buf;


Not sure if it is better like the other code I have seen but I think it reduces
the code duplication.


Yeah that's far better, I only have a little duplication left while returning 
to avoid compilation warnings (discarded const modifier).
Here is the updated patch :

diff --git a/components/volume.c b/components/volume.c
index 61cec90..f74c068 100644
--- a/components/volume.c
+++ b/components/volume.c
@@ -72,6 +72,50 @@

return bprintf("%d", m ? 0 : v * 100 / 255);
}
+#elif defined(__linux__)
+   #include 
+   #include 
+
+   const char *
+   vol_perc(const char * card)
+   {
+   long minv, maxv, outvol;
+   snd_mixer_t* handle;
+   snd_mixer_elem_t* elem;
+   snd_mixer_selem_id_t* sid;
+
+   static const char* mix_name = "Master";
+   static int mix_index = 0;
+
+   snd_mixer_selem_id_alloca();
+
+   /* sets simple-mixer index and name */
+   snd_mixer_selem_id_set_index(sid, mix_index);
+   snd_mixer_selem_id_set_name(sid, mix_name);
+
+   if (snd_mixer_open(, 0) < 0)
+   return NULL;
+
+   if (snd_mixer_attach(handle, card) < 0) goto error;
+
+   if (snd_mixer_selem_register(handle, NULL, NULL) < 0) goto 
error;
+
+   if (snd_mixer_load(handle) < 0) goto error;
+
+   elem = snd_mixer_find_selem(handle, sid);
+   if (!elem) goto error;
+
+   snd_mixer_selem_get_playback_volume_range(elem, , );
+
+   if(snd_mixer_selem_get_playback_volume(elem, 0, ) < 0) 
goto error;
+
+   snd_mixer_close(handle);
+   return bprintf("%ld", (100 * (outvol - minv)) / (maxv - minv));
+
+error:
+   snd_mixer_close(handle);
+   return NULL;
+   }
#else
#include 

diff --git a/config.def.h b/config.def.h
index e06be66..af2197c 100644
--- a/config.def.h
+++ b/config.def.h
@@ -58,6 +58,7 @@ static const char unknown_str[] = "n/a";
 * uptime  system uptime   NULL
 * usernameusername of current userNULL
 * vol_percOSS/ALSA volume in percent  mixer file (/dev/mixer)
+ * sound card name on 
Linux (default)
 * wifi_perc   WiFi signal in percent  interface name (wlan0)
 * wifi_essid  WiFi ESSID  interface name (wlan0)
 */
diff --git a/config.mk b/config.mk
index 3b32b7c..cd2a234 100644
--- a/config.mk
+++ b/config.mk
@@ -14,7 +14,7 @@ X11LIB = /usr/X11R6/lib
CPPFLAGS = -I$(X11INC) -D_DEFAULT_SOURCE
CFLAGS   = -std=c99 -pedantic -Wall -Wextra -Os
LDFLAGS  = -L$(X11LIB) -s
-LDLIBS   = -lX11
+LDLIBS   = -lX11 -lasound

# compiler and linker
CC = cc






Re: [hackers] [slstatus] : update vol_perc for OpenBSD

2020-11-30 Thread Aaron Marcher

Done :)

Cheers!

On 20-09-30 Wed, prx wrote:

* Ingo Feinerer  le [30-09-2020 15:11:29 +0200]:

On Wed, Sep 30, 2020 at 02:42:07PM +0200, prx wrote:
> Find attached a patch to support (not so new) sndiod OpenBSD.

FYI: https://lists.suckless.org/hackers/2005/17308.html


Nice, thanks a lot !
I totally missed that, and still was using

sndioctl output.level | awk -F = '{printf "%d\n",$2*100}'

in a run_command().

You patch should be imported IMHO.

Regards.





--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH] Use the sioctl_open(3) OpenBSD API to access audio controls

2020-11-30 Thread Aaron Marcher

Hi,

thanks for the great work! These changes are upstream now.

Regards,
Aaron

On 20-05-09 Sat, Ingo Feinerer wrote:

Starting with OpenBSD 6.7 regular users cannot access raw audio devices
anymore, for improved security. Instead use the sioctl_open(3) API to
access and manipulate audio controls exposed by sndiod(8). On the first
call a permanent connection is established with the running sndiod
daemon, and call-back functions are registered which are triggered when
audio controls are changed (e.g., a USB headset is attached) or when the
volume is modified. On subsequent calls we poll for changes; if there
are no volume changes this costs virtually nothing.

Joint work with Alexandre Ratchov.
---
LICENSE |   3 +-
components/volume.c | 210 +---
config.def.h|   1 +
config.mk   |   1 +
4 files changed, 163 insertions(+), 52 deletions(-)

diff --git a/LICENSE b/LICENSE
index 0eec587..c61489f 100644
--- a/LICENSE
+++ b/LICENSE
@@ -19,7 +19,8 @@ Copyright 2018 David Demelier 
Copyright 2018-2019 Michael Buch 
Copyright 2018 Ian Remmler 
Copyright 2016-2019 Joerg Jung 
-Copyright 2019 Ingo Feinerer 
+Copyright 2019-2020 Ingo Feinerer 
+Copyright 2020 Alexandre Ratchov 

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/components/volume.c b/components/volume.c
index 61cec90..b6665da 100644
--- a/components/volume.c
+++ b/components/volume.c
@@ -8,69 +8,177 @@
#include "../util.h"

#if defined(__OpenBSD__)
-   #include 
+   #include 
+   #include 
+   #include 
+   #include 
+
+   struct control {
+   LIST_ENTRY(control) next;
+   unsigned intaddr;
+   #define CTRL_NONE   0
+   #define CTRL_LEVEL  1
+   #define CTRL_MUTE   2
+   unsigned inttype;
+   unsigned intmaxval;
+   unsigned intval;
+   };
+
+   static LIST_HEAD(, control) controls = LIST_HEAD_INITIALIZER(controls);
+   static struct pollfd *pfds;
+   static struct sioctl_hdl *hdl;
+   static int initialized;
+
+   /*
+* Call-back to obtain the description of all audio controls.
+*/
+   static void
+   ondesc(void *unused, struct sioctl_desc *desc, int val)
+   {
+   struct control *c, *ctmp;
+   unsigned int type = CTRL_NONE;
+
+   if (desc == NULL)
+   return;
+
+   /* Delete existing audio control with the same address. */
+   LIST_FOREACH_SAFE(c, , next, ctmp) {
+   if (desc->addr == c->addr) {
+   LIST_REMOVE(c, next);
+   free(c);
+   break;
+   }
+   }
+
+   /* Only match output.level and output.mute audio controls. */
+   if (desc->group[0] != 0 ||
+   strcmp(desc->node0.name, "output") != 0)
+   return;
+   if (desc->type == SIOCTL_NUM &&
+   strcmp(desc->func, "level") == 0)
+   type = CTRL_LEVEL;
+   else if (desc->type == SIOCTL_SW &&
+strcmp(desc->func, "mute") == 0)
+   type = CTRL_MUTE;
+   else
+   return;
+
+   c = malloc(sizeof(struct control));
+   if (c == NULL) {
+   warn("sndio: failed to allocate audio control\n");
+   return;
+   }
+
+   c->addr = desc->addr;
+   c->type = type;
+   c->maxval = desc->maxval;
+   c->val = val;
+   LIST_INSERT_HEAD(, c, next);
+   }
+
+   /*
+* Call-back invoked whenever an audio control changes.
+*/
+   static void
+   onval(void *unused, unsigned int addr, unsigned int val)
+   {
+   struct control *c;
+
+   LIST_FOREACH(c, , next) {
+   if (c->addr == addr)
+   break;
+   }
+   c->val = val;
+   }
+
+   static void
+   cleanup(void)
+   {
+   struct control *c;
+
+   if (hdl) {
+   sioctl_close(hdl);
+   hdl = NULL;
+   }
+
+   free(pfds);
+   pfds = NULL;
+
+   while (!LIST_EMPTY()) {
+   c = LIST_FIRST();
+   LIST_REMOVE(c, next);
+   free(c);
+   }
+   }
+
+   static int
+   init(void)
+   {
+   hdl = sioctl_open(SIO_DEVANY, SIOCTL_READ, 0);
+   if (hdl == NULL) {
+   warn("sndio: cannot 

Re: [hackers] [slstatus] : mpd status patch

2020-11-30 Thread Aaron Marcher

Hi,

thank you very much. Sorry for my late reply.
I think merging the patch and adding a dependency on mpd won't be the 
way to go. Maybe we should add it to the wiki as an optional patch?


Regards,
Aaron

On 20-09-28 Mon, prx wrote:

Hi,
I thought slstatus need some love. Find attached a patch that add mpd support.
A format string is required as argument.
Thanks to spoon [1] authors for inspiration and snippets.

I had to modify Makefile to support mpdclient library. Not sure it's
the best way to go.

Regards.

[1] : https://git.2f30.org/spoon






--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH] Handle SIGUSR1 for forced refreshes

2020-11-30 Thread Aaron Marcher

Merged. Thanks!

On 20-06-18 Thu, Mart Lubbers wrote:

At some point one might want to force a refresh for example after
checking email or changing the volume. Sending a SIGUSR1 achieves this
now
---
slstatus.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/slstatus.c b/slstatus.c
index 96fa5b6..499cd30 100644
--- a/slstatus.c
+++ b/slstatus.c
@@ -26,9 +26,8 @@ static Display *dpy;
static void
terminate(const int signo)
{
-   (void)signo;
-
-   done = 1;
+   if (signo != SIGUSR1)
+   done = 1;
}

static void
@@ -72,6 +71,7 @@ main(int argc, char *argv[])
   act.sa_handler = terminate;
   sigaction(SIGINT,  , NULL);
   sigaction(SIGTERM, , NULL);
+   sigaction(SIGUSR1, , NULL);

   if (!sflag && !(dpy = XOpenDisplay(NULL))) {
   die("XOpenDisplay: Failed to open display");
--
2.20.1




--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH] Fix temperature reporting on OpenBSD.

2020-11-30 Thread Aaron Marcher

A little bit late, but merged. Thanks!

On 19-10-31 Thu, dsp wrote:

Hey list!

On OpenBSD i noticed that if you set the temperature component to be printed
it will only show the first digit due to the integer division. So for example
a temperature of 54 C shows as 5. This patch first treats it as a float
before truncating the non decimal digits.

From 407f7477bc99fd493922ff73c9803bd1b5d1dfac Mon Sep 17 00:00:00 2001
From: spiros thanasoulas 
Date: Thu, 31 Oct 2019 20:36:04 -0600
Subject: [PATCH] On OpenBSD although the formula is correct due to integer
division a temperature of for example 54 celsius appears as 5. this patch
first treats it as a floating point op before retaining the non decimal
digits

---
components/temperature.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/components/temperature.c b/components/temperature.c
index 8462d0f..8e1f222 100644
--- a/components/temperature.c
+++ b/components/temperature.c
@@ -45,7 +45,7 @@
}

/* kelvin to celsius */
-   return bprintf("%d", (temp.value - 27315) / 1E6);
+   return bprintf("%d", (int)((float)(temp.value-27315) / 
1E6));
}
#elif defined(__FreeBSD__)
#include 
--
2.23.0



--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH] Full battery indicator

2020-11-30 Thread Aaron Marcher

Hi,

thanks for that suggestion. Applied to master.

Regards,
Aaron

On 19-10-02 Wed, Cem Keylan wrote:

I thought slstatus needed a full battery indicator.
When you reach full charge the symbol would change
to a question mark "?" as "Full" was not defined,
now it changes to an "o" instead.
---
components/battery.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/components/battery.c b/components/battery.c
index 07b6ac1..f2b0f14 100644
--- a/components/battery.c
+++ b/components/battery.c
@@ -52,6 +52,7 @@
} map[] = {
{ "Charging","+" },
{ "Discharging", "-" },
+   { "Full","o" },
};
size_t i;
char path[PATH_MAX], state[12];
--
2.23.0




--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH] separator module

2020-11-30 Thread Aaron Marcher

Thank you very much, applied to master.

On 19-03-30 Sat, Ryan Kes wrote:

---
Makefile   |  1 +
components/separator.c | 10 ++
config.def.h   |  1 +
slstatus.h |  3 +++
4 files changed, 15 insertions(+)
create mode 100644 components/separator.c

diff --git a/Makefile b/Makefile
index 945b5e3..2f93b87 100644
--- a/Makefile
+++ b/Makefile
@@ -21,6 +21,7 @@ COM =\
components/num_files\
components/ram\
components/run_command\
+   components/separator\
components/swap\
components/temperature\
components/uptime\
diff --git a/components/separator.c b/components/separator.c
new file mode 100644
index 000..40fec52
--- /dev/null
+++ b/components/separator.c
@@ -0,0 +1,10 @@
+/* See LICENSE file for copyright and license details. */
+#include 
+
+#include "../util.h"
+
+const char *
+separator(const char *separator)
+{
+return separator;
+}
diff --git a/config.def.h b/config.def.h
index e06be66..0895f6a 100644
--- a/config.def.h
+++ b/config.def.h
@@ -45,6 +45,7 @@ static const char unknown_str[] = "n/a";
 * ram_total   total memory size in GB NULL
 * ram_usedused memory in GB   NULL
 * run_command custom shell commandcommand (echo foo)
+ * separator   string to echo  NULL
 * swap_free   free swap in GB NULL
 * swap_perc   swap usage in percent   NULL
 * swap_total  total swap size in GB   NULL
diff --git a/slstatus.h b/slstatus.h
index 08f610a..b0f2564 100644
--- a/slstatus.h
+++ b/slstatus.h
@@ -56,6 +56,9 @@ const char *ram_used(void);
/* run_command */
const char *run_command(const char *cmd);

+/* separator */
+const char *separator(const char *separator);
+
/* swap */
const char *swap_free(void);
const char *swap_perc(void);
--
2.21.0




--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus] Follow International System of Units spacing rules

2019-02-17 Thread Aaron Marcher

Hi Ingo,

Following standards sounds like a good idea. I merged the patch.

Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH] Add ram and swap components on FreeBSD

2019-02-16 Thread Aaron Marcher

Hi Michael,

by now everything is ported to FreeBSD! :-)
Thank you very much for your motivation and work of porting slstatus to 
FreeBSD!


Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH] cpu_perc: Check for division by zero

2019-02-16 Thread Aaron Marcher

Hi Ingo,

great that you noticed the bug and thanks for the patch! Applied it 
right now.


Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH] wifi component on FreeBSD

2019-02-13 Thread Aaron Marcher

Hi Michael,

thanks for your patch!

Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH] Add FreeBSD support for netspeeds, entropy and ip components

2019-02-05 Thread Aaron Marcher

Hi Michael,

the entropy function on OpenBSD is kind of a easter egg. Could you look 
into "really" porting it to FreeBSD?
Thank you very much for your motivation of porting slstatus to FreeBSD.  
I merged the other patches already.


Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [dev][slstatus] FreeBSD port?

2019-02-01 Thread Aaron Marcher

Hi Michael,

I think mainline support for FreeBSD in slstatus is a good idea. Thank 
you very much for your contributions, I will merge them soon.


Regards,
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH] Add flexible formatting to keyboard_indicators.

2018-06-04 Thread Aaron Marcher

Ian,

thanks for your work, merged.

Regards,
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH] Add flexible formatting to keyboard_indicators.

2018-06-01 Thread Aaron Marcher

Ian,

thank you very much for your work! I have a few things to comment before 
we can merge the patch:



+/*
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.
+ */


I am not sure if keyboard_indicators.c is the correct place for the 
comment? Maybe config.def.h is better? However it is pretty long.

You could also add something like "see keyboard_indicators.c for
additional documentation".
Additionally, for a minimum, add a comment for the argument and an 
example in config.def.h (like for the other components).



+   size_t fmtlen;
+   size_t i;
+   size_t n = 0;
+   int togglecase;
+   int isset;
+   char key;


These can be simplified by creating one-liners for vars of the same 
type. Additionally according to the coding style vars should be only 
declared but not assigned at the beginning of a block.



+   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];


Additionally, according we decided to add braces for blocks always, also 
for single line statements.


Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH] backlight: implemented openbsd support

2018-05-24 Thread Aaron Marcher

Hi,

i have implemented basic support for the backlight function on 
OpenBSD. The problem here is that /dev/ttyC0 permission is 600 
(root:wheel) so a user cannot read from the device without changing 
the permission or running slstatus as root.


Running slstatus as root is no real option - however there are not that 
much alternatives to reading from /dev/ttyC0. Linking against xcb-xrandr 
is bloated and appearently doesn't work for every setup.
A possible workaround would be to set the group permissions of 
/dev/ttyC0 in /etc/rc.local or crontab automatically - which is not 
perfect.
The question that comes up to my mind is: Do we need the backlight 
component? I can literally "see" the current brightness of my screen.  
Tell me what you think and we will come up with a sane solution.


Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH keymap v2] Add keymap component

2018-05-23 Thread Aaron Marcher

Michael,

Thank you, merged.

Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH keymap 1/2] Add keymap component

2018-05-22 Thread Aaron Marcher

Michael,

Thank you very much for your great work. However I have a few things for 
you to change.



-   components/backlight\



-/* backlight */
-const char *backlight_perc(const char *);
-


Why are you removing backlight from Makefile and slstatus.h?


+   for (i = 0; i < sizeof(EXCLUDES)/sizeof(EXCLUDES[0]); ++i)
+   if (strstr(sym, EXCLUDES[i]))
+   return 0;


According to coding style: "Use block for single statement ifs".


+/* Given a xkb_symbols string (syms) retrieve
+ * and populate the provided layout and variant
+ * strings
+ */


I think this specific comment is unnecessary as the function explains 
itself.



+   char *token,
+*copy,
+*delims = "+:";


I don't think that the newlines are necessary here, it can be put in one 
line. Additionally the indentation is wrong. And try to only declare 
variables at the beginning of a block and initialize them later.



+   if (IsLayoutOrVariant(token)
+   && !(strlen(token) == 1 && isdigit(token[0]))) {


Indentation is wrong here, tabs to the last indent and spaces for 
alignment afterwards.



+const char *
+keymap(void)
+{
+   static char layout[LAYOUT_MAX];
+   


Whitespace error here.


+   desc = XkbAllocKeyboard();
+   if (!desc) {


This can be put into one if clause, no need for two lines.

Additionally, can you send one patch instead of a series regarding your 
"Free strduped string"?


Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [PATCH slstatus V3] Add basic backlight percentage support

2018-05-22 Thread Aaron Marcher

David,

thanks for your latest patch. I merged it.

Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus] [PATCH] Remove o-flag as it is redundant

2018-05-21 Thread Aaron Marcher

I'd love if you can show me how `slstatus -s | head -n 10` can work.


$ slstatus -s | head -n 10
∿ n/a n/a% | B ?80 | V  62% | C n/a% 52°C | M  6% | 2018-05-22 00:31:38
∿ n/a n/a% | B ?80 | V  62% | C   0% 52°C | M  6% | 2018-05-22 00:31:39
∿ n/a n/a% | B ?80 | V  62% | C   0% 52°C | M  6% | 2018-05-22 00:31:40
∿ n/a n/a% | B ?80 | V  62% | C   0% 52°C | M  6% | 2018-05-22 00:31:41
∿ n/a n/a% | B ?80 | V  62% | C   0% 52°C | M  6% | 2018-05-22 00:31:42
∿ n/a n/a% | B ?80 | V  62% | C   0% 52°C | M  6% | 2018-05-22 00:31:43
∿ n/a n/a% | B ?80 | V  62% | C   0% 52°C | M  6% | 2018-05-22 00:31:44
∿ n/a n/a% | B ?80 | V  62% | C   0% 52°C | M  6% | 2018-05-22 00:31:45
∿ n/a n/a% | B ?80 | V  62% | C   0% 52°C | M  6% | 2018-05-22 00:31:46
∿ n/a n/a% | B ?80 | V  62% | C   0% 52°C | M  6% | 2018-05-22 00:31:47
[1]30928 broken pipe  slstatus -s |
  30929 done head -n 10
$

What's the problem?

Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus] [PATCH] Remove o-flag as it is redundant

2018-05-21 Thread Aaron Marcher

Laslo,


Just by the Unix-principle, the o-flag for slstatus is not necessary.
It looks like yet another case of "cat -v".

For more arguments, see the commit description.


I agree, imho we can remove the -o flag as we should adhere to the UNIX 
philosophy.
But I am open for discussion and I will wait for other opinions before 
merging.


Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [PATCH slstatus V2] Add basic backlight percentage support

2018-05-21 Thread Aaron Marcher

David,


Do you mean in bprintf call, so like this: bprintf("%d", ...) ?


Yes, thanks.

The problem is that util.h actually requires stddef.h (it uses size_t 
which is is defined there). I think that include should eventually be 
moved there.


Okay then move it to util.h in your patch, forgot that.

So even if I add support for FreeBSD you'll refuse it? I know the 
code, I've already implemented I just need to get a FreeBSD laptop to 
ensure it still works though :)


For now, yes. But please keep your awesome work saved so that we can add 
it when we port slstatus eventually to FreeBSD! For now, Linux and 
OpenBSD should be fully ported.


Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [PATCH slstatus V2] Add basic backlight percentage support

2018-05-21 Thread Aaron Marcher

David,

Thank you very much for your great work!
works great so far but I have just a few things for you to change.

- Remove the "%" sign from the return
- Fix the indention and spacing between the #ifdefs (see other 
  components)
- Move  in the Linux block as there is no other block to 
  share code with
- Add backlight_perc to config.def.h documentation (with acpi_video0 as 
  example)

- Add backlight_perc to README

Also: for now we will add only OpenBSD support as FreeBSD is no port 
goal for version 1.


Regards,
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] slstatus keymap patch idea

2018-05-20 Thread Aaron Marcher

Michael,


I’ve been using slstatus for a while and am really enjoying it.


Thanks!


Was thinking of adding a patch to the current slstatus for a keymap
indicator component. Is it worth adding this feature now or later
after the release as a custom patch?


I thought about the same thing a few days ago and I like the idea of 
adding it natively to slstatus. Adding it before the release is fine.


I guess it could be replicated by a run_command using setxkbmap but 
would be nice as a separate component out of the box.


Implementing it using Xlib is more elegant.

Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [PATCH slstatus] Add basic backlight percentage support

2018-05-20 Thread Aaron Marcher

David,


Done and done.


do you send an updated patch with the check for != 1 for pscanf and the 
division by zero here or should I add it after applying?


Good catch, what do you recommend if max is 0? Resetting to 100? Or to 
return NULL to indicate an error?


I am not quite sure but if the max is 0 we should return NULL as 
something is weird.


Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [PATCH slstatus] Support energy_now/power_now in battery_remaining

2018-05-20 Thread Aaron Marcher

David,

thanks for the patch. I applied it.

Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH] ip: fixed memory leak

2018-05-20 Thread Aaron Marcher

Tobias,

thank you very much!

Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH] netspeeds: added error condition for openbsd

2018-05-19 Thread Aaron Marcher

Tobias,

thanks, applied!

Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH] added battery_remaining function

2018-05-18 Thread Aaron Marcher

Tobias,


What do you think?


Thank you very much for your patch. Good work! Applied it. I will work 
now on the Linux function.
Also thank you for moving the common code to load_apm_power_info(). It 
is a lot simpler now. I hope it is OK for you if I modified your commit 
message to explain that too, as the patch by itself is not that 
readbale.


Regards,
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH] suggestion: add user defined format callback

2018-05-17 Thread Aaron Marcher

Tobias,

What do you think about a callback function where the user could 
define more precisely how formatting is done (like adding symbols for

percentages etc.)


I really like the idea and your proof of concept. Thanks for coming up 
with this!
However I'd suggest to implement this more general and flexible in some 
way. Maybe we could create different general formatting functions which 
apply for example to percentage.
Also, I am not sure if it would be better to add these functions 
post-first-release.

What do you think?

Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH] added comment for temp function (openbsd)

2018-05-17 Thread Aaron Marcher

Tobias,

Somehow the patch failes to apply with `git am` with the message "git 
diff header lacks filename information when removing 1 leading 
pathname component". I would like to avoid applying it using "git 
apply" as this strips you as the author. Could you resend it again?


I read the patch again now and somehow a line was wrong:

diff --git config.def.h config.def.h

Instead it should be:

diff --git a/config.def.h b/config.def.h


Changed that, applied and pushed. Thank you.

Regards,
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH] added comment for temp function (openbsd)

2018-05-17 Thread Aaron Marcher

Tobias,

Thank you for the small change.
Somehow the patch failes to apply with `git am` with the message "git 
diff header lacks filename information when removing 1 leading pathname 
component". I would like to avoid applying it using "git apply" as this 
strips you as the author. Could you resend it again?


As a side note, please try to separate the commit message and the email 
message in the patches you send to the mailing list. For the last 
patches I always had to modify the message with `git commit --amend` as 
it should not contain your intended message for the list.


Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][patch] corrected calculations for disk space

2018-05-17 Thread Aaron Marcher

Tobias,


i checked the complete functionality now for openbsd and had just some
different values for my disk space (compared it to df(1)).


Thank you, I applied the patch!
I think on Linux some values differ to, I will have to further investige 
later though.


Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][patch] added wifi functionality for openbsd

2018-05-16 Thread Aaron Marcher

Tobias,


just added wifi functionality for openbsd (display ESSID and signal
strength percentage)


Good work! Thank you very much.
I applied the patch and commited some minor fixes to the added codebase 
afterwards.


Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][patch] corrected calculation for swap on openbsd

2018-05-16 Thread Aaron Marcher

Tobias,

thanks again for your patch. Great to have you on board as a 
contributor.


Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][patch] consistent calculation of ram_* on openbsd

2018-05-16 Thread Aaron Marcher

Tobias,

thank you for your patches.

Regards,
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus][PATCH] volume: Cast SOUND_MIXER_READ_DEVMASK to int to avoid warning.

2018-05-02 Thread Aaron Marcher

Thanks, applied.

Cheers!

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [PATCH] Do not use valid in cpu_freq|io_wait

2018-04-16 Thread Aaron Marcher

David,

On the first call to the cpu_freq|cpu_iowait user may see an initial 
n/a result

because NULL is returned but the value has been parsed correctly.

Example:

[CPU n/a%] [RAM 52%] [ 2018-04-16 15:55:19 ]
[CPU  16%] [RAM 52%] [ 2018-04-16 15:55:20 ]
[CPU   2%] [RAM 52%] [ 2018-04-16 15:55:21 ]


thanks for your patch but I did not quite understand it.


-   if (!valid) {
+   if (!valid)
valid = 1;
-   return NULL;
-   }


First of all, that change removes the "return" statement which makes the 
code totally useless.


Secondly, returning "unknown_str" for the first run of cpu_*() makes 
totally sense as those are average values between two executions.


Regards,
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus] battery_perc: Port to OpenBSD. || Aaron Marcher

2018-03-19 Thread Aaron Marcher

Hello,


If you're going to do this for every module for every OS you're
planning on supporting, this is a bad start imho.


Well, i will only support Linux and OpenBSD - and almost half of the 
modules is POSIX-compliant anyway.



What would you think about rather separating objects to their OS
directory and chose which to build/link at make time?


Will adding an additional separation layer or even directory structure 
with duplicate code actually improve the readbility of the program? 
Performance-wise it is the same.


Regards,
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



Re: [hackers] [slstatus] Simplify Makefile

2017-09-18 Thread Aaron Marcher

Dear Laslo, dear Quentin,


why not just the following? Thanks for bringing the topic up; for some
reason I had in mind that it was necessary to list the dependencies
explicitly.


I will merge this patch as it has the required dependency on slstatus.o 
and it is generally simpler.

Thank you very much!

Regards,
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x09e71697435bf54b
Fingerprint: 57D2 5F2C 9402 A6BD FEF9 B3B6 09E7 1697 435B F54B



Re: [hackers] [slstatus] Fix missing config.h in Makefile

2017-09-18 Thread Aaron Marcher

Hi Quentin,

thank you very much. Forgot that.

Regards,
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x09e71697435bf54b
Fingerprint: 57D2 5F2C 9402 A6BD FEF9 B3B6 09E7 1697 435B F54B



[hackers] [slstatus] announcement

2016-10-09 Thread Aaron Marcher

Fellow hackers,

my name is Aaron Marcher but I am better known as drkhsh. I started using 
suckless software about two years ago. Since then I have been using dwm, st and 
all the other great programs. About a year ago I joined IRC. I never posted to 
the mailing list so thats the reason for this short introduction about myself.


Now to the actual content: I always wanted some statusbar in dwm. I started with 
some shell script as pointed out in the wiki but it grew and used a lot of 
resources. So I started to hack something in C. That project, which was 
initially forked by "dwmstatus" and only intended to be used by me grew and 
became something bigger. I started to write it, so that it can be easily used by 
other people. Multiple entries per function (e.g. multiple batteries) are

supported and everything can be reordered and customized via a C header file
(similar to other suckless programs).

The following information is included:
- Battery percentage/state
- CPU usage (in percent)
- Custom shell commands
- Date and time
- Disk[s] status (free storage, percentage, total storage and used storage)
- Available entropy
- Username/GID/UID
- Hostname
- IP addresses
- Load averages
- Memory status (free memory, percentage, total memory and used memory)
- Temperature
- Uptime
- Volume percentage (ALSA)
- WiFi signal percentage and ESSID

Currently I am working on porting it to BSD as it is only made for Linux at the 
moment.


Repo: https://git.nulltime.net/slstatus

Regards,
Aaron Marcher

--
web: https://www.nulltime.net/ or http://nulltime5w3shrrc.onion/
gpg: 0x435BF54B