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

2019-02-16 Thread Ingo Feinerer
Hi,

this might be bike-shedding but slstatus does not follow spacing rules as
outlined by the International System of Units. Basically the rules state that
there should be a space between a number and a unit of measurement (with a few
exceptions):
https://en.wikipedia.org/wiki/Space_(punctuation)#Unit_symbols_and_numbers

E.g., RAM is currently reported as 7.5Gi or CPU frequency as 500.0M,
contradicting the International System of Units spacing rules.

If this intentional (e.g., in order to minimize width) please ignore this diff.

Best regards,
Ingo



[hackers] [slstatus][PATCH] Follow International System of Units spacing rules

2019-02-16 Thread Ingo Feinerer
---
 util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util.c b/util.c
index 77324e8..85366bf 100644
--- a/util.c
+++ b/util.c
@@ -123,7 +123,7 @@ fmt_human(uintmax_t num, int base)
scaled /= base;
}
 
-   return bprintf("%.1f%s", scaled, prefix[i]);
+   return bprintf("%.1f %s", scaled, prefix[i]);
 }
 
 int
-- 
2.20.1




[hackers] [slstatus] Add OS-support notice to README || Aaron Marcher

2019-02-16 Thread git
commit 93daf4f35e2b72e64d4e0de79159a8c26241bfa2
Author: Aaron Marcher 
AuthorDate: Sat Feb 16 17:05:04 2019 +0100
Commit: Aaron Marcher 
CommitDate: Sat Feb 16 17:05:04 2019 +0100

Add OS-support notice to README

diff --git a/README b/README
index 38ec27a..d55f23b 100644
--- a/README
+++ b/README
@@ -32,6 +32,7 @@ Features
 
 Requirements
 
+Currently slstatus works on FreeBSD, Linux and OpenBSD.
 In order to build slstatus you need the Xlib header files.
 
 



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



[hackers] [slstatus] Add ram and swap components on FreeBSD || Michael Buch

2019-02-16 Thread git
commit a1ac203d16c379d7fc05765545af2977a7a3584d
Author: Michael Buch 
AuthorDate: Sat Feb 16 01:26:44 2019 +
Commit: Aaron Marcher 
CommitDate: Sat Feb 16 16:58:34 2019 +0100

Add ram and swap components on FreeBSD

diff --git a/components/ram.c b/components/ram.c
index 48144e4..47e6fda 100644
--- a/components/ram.c
+++ b/components/ram.c
@@ -156,4 +156,67 @@
 
return NULL;
}
+#elif defined(__FreeBSD__)
+   #include 
+   #include 
+   #include 
+   #include 
+
+   const char *
+   ram_free(void) {
+   struct vmtotal vm_stats;
+   int mib[] = {CTL_VM, VM_TOTAL};
+   size_t len;
+
+   len = sizeof(struct vmtotal);
+   if (sysctl(mib, 2, _stats, , NULL, 0) == -1
+   || !len)
+   return NULL;
+
+   return fmt_human(vm_stats.t_free * getpagesize(), 1024);
+   }
+
+   const char *
+   ram_total(void) {
+   long npages;
+   size_t len;
+
+   len = sizeof(npages);
+   if (sysctlbyname("vm.stats.vm.v_page_count", , , 
NULL, 0) == -1
+   || !len)
+   return NULL;
+
+   return fmt_human(npages * getpagesize(), 1024);
+   }
+
+   const char *
+   ram_perc(void) {
+   long npages;
+   long active;
+   size_t len;
+
+   len = sizeof(npages);
+   if (sysctlbyname("vm.stats.vm.v_page_count", , , 
NULL, 0) == -1
+   || !len)
+   return NULL;
+
+   if (sysctlbyname("vm.stats.vm.v_active_count", , , 
NULL, 0) == -1
+   || !len)
+   return NULL;
+
+   return bprintf("%d", active * 100 / npages);
+   }
+
+   const char *
+   ram_used(void) {
+   long active;
+   size_t len;
+
+   len = sizeof(active);
+   if (sysctlbyname("vm.stats.vm.v_active_count", , , 
NULL, 0) == -1
+   || !len)
+   return NULL;
+
+   return fmt_human(active * getpagesize(), 1024);
+   }
 #endif
diff --git a/components/swap.c b/components/swap.c
index 97428de..2509db1 100644
--- a/components/swap.c
+++ b/components/swap.c
@@ -197,4 +197,88 @@
 
return fmt_human(used * 1024, 1024);
}
+#elif defined(__FreeBSD__)
+   #include 
+   #include 
+   #include 
+   #include 
+   #include 
+
+   static int getswapinfo(struct kvm_swap *swap_info, size_t size)
+   {
+   kvm_t *kd;
+
+   kd = kvm_openfiles(NULL, "/dev/null", NULL, 0, NULL);
+   if(kd == NULL) {
+   warn("kvm_openfiles '/dev/null':");
+   return 0;
+   }
+
+   if(kvm_getswapinfo(kd, swap_info, size, 0 /* Unused flags */) 
== -1) {
+   warn("kvm_getswapinfo:");
+   kvm_close(kd);
+   return 0;
+   }
+
+   kvm_close(kd);
+   return 1;
+   }
+
+   const char *
+   swap_free(void)
+   {
+   struct kvm_swap swap_info[1];
+   long used, total;
+
+   if(!getswapinfo(swap_info, 1))
+   return NULL;
+
+   total = swap_info[0].ksw_total;
+   used = swap_info[0].ksw_used;
+
+   return fmt_human((total - used) * getpagesize(), 1024);
+   }
+
+   const char *
+   swap_perc(void)
+   {
+   struct kvm_swap swap_info[1];
+   long used, total;
+
+   if(!getswapinfo(swap_info, 1))
+   return NULL;
+
+   total = swap_info[0].ksw_total;
+   used = swap_info[0].ksw_used;
+
+   return bprintf("%d", used * 100 / total);
+   }
+
+   const char *
+   swap_total(void)
+   {
+   struct kvm_swap swap_info[1];
+   long total;
+
+   if(!getswapinfo(swap_info, 1))
+   return NULL;
+
+   total = swap_info[0].ksw_total;
+
+   return fmt_human(total * getpagesize(), 1024);
+   }
+
+   const char *
+   swap_used(void)
+   {
+   struct kvm_swap swap_info[1];
+   long used;
+
+   if(!getswapinfo(swap_info, 1))
+   return NULL;
+
+   used = swap_info[0].ksw_used;
+
+   return fmt_human(used * getpagesize(), 1024);
+   }
 #endif



[hackers] [slstatus] cpu_perc: Check for division by zero || Ingo Feinerer

2019-02-16 Thread git
commit 10bdf01b715dcc994f3fe32a6881d5e0b2613a6c
Author: Ingo Feinerer 
AuthorDate: Thu Feb 14 19:25:51 2019 +0100
Commit: Aaron Marcher 
CommitDate: Sat Feb 16 16:56:55 2019 +0100

cpu_perc: Check for division by zero

diff --git a/components/cpu.c b/components/cpu.c
index d9bd018..9e28003 100644
--- a/components/cpu.c
+++ b/components/cpu.c
@@ -24,7 +24,7 @@
cpu_perc(void)
{
static long double a[7];
-   long double b[7];
+   long double b[7], sum;
 
memcpy(b, a, sizeof(b));
/* cpu user nice system idle iowait irq softirq */
@@ -37,13 +37,16 @@
return NULL;
}
 
+   sum = (b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6]) -
+ (a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6]);
+
+   if (sum == 0) {
+   return NULL;
+   }
+
return bprintf("%d", (int)(100 *
   ((b[0] + b[1] + b[2] + b[5] + b[6]) -
-   (a[0] + a[1] + a[2] + a[5] + a[6])) /
-  ((b[0] + b[1] + b[2] + b[3] + b[4] + b[5] +
-b[6]) -
-   (a[0] + a[1] + a[2] + a[3] + a[4] + a[5] +
-a[6];
+   (a[0] + a[1] + a[2] + a[5] + a[6])) / sum));
}
 #elif defined(__OpenBSD__)
#include 
@@ -75,7 +78,7 @@
{
int mib[2];
static uintmax_t a[CPUSTATES];
-   uintmax_t b[CPUSTATES];
+   uintmax_t b[CPUSTATES], sum;
size_t size;
 
mib[0] = CTL_KERN;
@@ -92,15 +95,18 @@
return NULL;
}
 
+   sum = (a[CP_USER] + a[CP_NICE] + a[CP_SYS] + a[CP_INTR] + 
a[CP_IDLE]) -
+ (b[CP_USER] + b[CP_NICE] + b[CP_SYS] + b[CP_INTR] + 
b[CP_IDLE]);
+
+   if (sum == 0) {
+   return NULL;
+   }
+
return bprintf("%d", 100 *
   ((a[CP_USER] + a[CP_NICE] + a[CP_SYS] +
 a[CP_INTR]) -
(b[CP_USER] + b[CP_NICE] + b[CP_SYS] +
-b[CP_INTR])) /
-  ((a[CP_USER] + a[CP_NICE] + a[CP_SYS] +
-a[CP_INTR] + a[CP_IDLE]) -
-   (b[CP_USER] + b[CP_NICE] + b[CP_SYS] +
-b[CP_INTR] + b[CP_IDLE])));
+b[CP_INTR])) / sum);
}
 #elif defined(__FreeBSD__)
#include 
@@ -129,7 +135,7 @@
{
size_t size;
static long a[CPUSTATES];
-   long b[CPUSTATES];
+   long b[CPUSTATES], sum;
 
size = sizeof(a);
memcpy(b, a, sizeof(b));
@@ -142,14 +148,17 @@
return NULL;
}
 
+   sum = (a[CP_USER] + a[CP_NICE] + a[CP_SYS] + a[CP_INTR] + 
a[CP_IDLE]) -
+ (b[CP_USER] + b[CP_NICE] + b[CP_SYS] + b[CP_INTR] + 
b[CP_IDLE]);
+
+   if (sum == 0) {
+   return NULL;
+   }
+
return bprintf("%d", 100 *
   ((a[CP_USER] + a[CP_NICE] + a[CP_SYS] +
 a[CP_INTR]) -
(b[CP_USER] + b[CP_NICE] + b[CP_SYS] +
-b[CP_INTR])) /
-  ((a[CP_USER] + a[CP_NICE] + a[CP_SYS] +
-a[CP_INTR] + a[CP_IDLE]) -
-   (b[CP_USER] + b[CP_NICE] + b[CP_SYS] +
-b[CP_INTR] + b[CP_IDLE])));
+b[CP_INTR])) / sum);
}
 #endif



Re: [hackers] [dwm][PATCH] An alternative gaps implementation.

2019-02-16 Thread Hiltjo Posthuma
On Sat, Feb 16, 2019 at 01:28:06PM +0100, Maciej Sumalvico wrote:
> In addition to what the "gaps" patch does, this also adds:
> - outer gaps,
> - a gap between a master and stack area,
> - a function and keybindings to increase/decrease/disable gaps.
> ---
>  config.def.h |  4 
>  dwm.c| 29 +
>  2 files changed, 25 insertions(+), 8 deletions(-)
> 
> diff --git a/config.def.h b/config.def.h
> index 1c0b587..38d2f6c 100644
> --- a/config.def.h
> +++ b/config.def.h
> @@ -2,6 +2,7 @@
>  
>  /* appearance */
>  static const unsigned int borderpx  = 1;/* border pixel of windows */
> +static const unsigned int gappx = 5;/* gaps between windows */
>  static const unsigned int snap  = 32;   /* snap pixel */
>  static const int showbar= 1;/* 0 means no bar */
>  static const int topbar = 1;/* 0 means bottom bar */
> @@ -84,6 +85,9 @@ static Key keys[] = {
>   { MODKEY,   XK_period, focusmon,   {.i = +1 } },
>   { MODKEY|ShiftMask, XK_comma,  tagmon, {.i = -1 } },
>   { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
> + { MODKEY,   XK_minus,  setgaps,{.i = -1 } },
> + { MODKEY,   XK_equal,  setgaps,{.i = +1 } },
> + { MODKEY|ShiftMask, XK_equal,  setgaps,{.i = 0  } },
>   TAGKEYS(XK_1,  0)
>   TAGKEYS(XK_2,  1)
>   TAGKEYS(XK_3,  2)
> diff --git a/dwm.c b/dwm.c
> index 4465af1..4363627 100644
> --- a/dwm.c
> +++ b/dwm.c
> @@ -119,6 +119,7 @@ struct Monitor {
>   int by;   /* bar geometry */
>   int mx, my, mw, mh;   /* screen size */
>   int wx, wy, ww, wh;   /* window area  */
> + int gappx;/* gaps between windows */
>   unsigned int seltags;
>   unsigned int sellt;
>   unsigned int tagset[2];
> @@ -199,6 +200,7 @@ static void sendmon(Client *c, Monitor *m);
>  static void setclientstate(Client *c, long state);
>  static void setfocus(Client *c);
>  static void setfullscreen(Client *c, int fullscreen);
> +static void setgaps(const Arg *arg);
>  static void setlayout(const Arg *arg);
>  static void setmfact(const Arg *arg);
>  static void setup(void);
> @@ -638,6 +640,7 @@ createmon(void)
>   m->nmaster = nmaster;
>   m->showbar = showbar;
>   m->topbar = topbar;
> + m->gappx = gappx;
>   m->lt[0] = [0];
>   m->lt[1] = [1 % LENGTH(layouts)];
>   strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
> @@ -1497,6 +1500,16 @@ setfullscreen(Client *c, int fullscreen)
>   }
>  }
>  
> +void
> +setgaps(const Arg *arg)
> +{
> + if ((arg->i == 0) || (selmon->gappx + arg->i < 0))
> + selmon->gappx = 0;
> + else
> + selmon->gappx += arg->i;
> + arrange(selmon);
> +}
> +
>  void
>  setlayout(const Arg *arg)
>  {
> @@ -1683,16 +1696,16 @@ tile(Monitor *m)
>   if (n > m->nmaster)
>   mw = m->nmaster ? m->ww * m->mfact : 0;
>   else
> - mw = m->ww;
> - for (i = my = ty = 0, c = nexttiled(m->clients); c; c = 
> nexttiled(c->next), i++)
> + mw = m->ww - m->gappx;
> + for (i = 0, my = ty = m->gappx, c = nexttiled(m->clients); c; c = 
> nexttiled(c->next), i++)
>   if (i < m->nmaster) {
> - h = (m->wh - my) / (MIN(n, m->nmaster) - i);
> - resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - 
> (2*c->bw), 0);
> - my += HEIGHT(c);
> + h = (m->wh - my) / (MIN(n, m->nmaster) - i) - m->gappx;
> + resize(c, m->wx + m->gappx, m->wy + my, mw - (2*c->bw) 
> - m->gappx, h - (2*c->bw), 0);
> + my += HEIGHT(c) + m->gappx;
>   } else {
> - h = (m->wh - ty) / (n - i);
> - resize(c, m->wx + mw, m->wy + ty, m->ww - mw - 
> (2*c->bw), h - (2*c->bw), 0);
> - ty += HEIGHT(c);
> + h = (m->wh - ty) / (n - i) - m->gappx;
> + resize(c, m->wx + mw + m->gappx, m->wy + ty, m->ww - mw 
> - (2*c->bw) - 2*m->gappx, h - (2*c->bw), 0);
> + ty += HEIGHT(c) + m->gappx;
>   }
>  }
>  
> -- 
> 2.20.1
> 
> 

Just upload it to the sites repository.
For the patch guidelines see also: https://suckless.org/hacking/

-- 
Kind regards,
Hiltjo



[hackers] [dwm][PATCH] An alternative gaps implementation.

2019-02-16 Thread Maciej Sumalvico
In addition to what the "gaps" patch does, this also adds:
- outer gaps,
- a gap between a master and stack area,
- a function and keybindings to increase/decrease/disable gaps.
---
 config.def.h |  4 
 dwm.c| 29 +
 2 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/config.def.h b/config.def.h
index 1c0b587..38d2f6c 100644
--- a/config.def.h
+++ b/config.def.h
@@ -2,6 +2,7 @@
 
 /* appearance */
 static const unsigned int borderpx  = 1;/* border pixel of windows */
+static const unsigned int gappx = 5;/* gaps between windows */
 static const unsigned int snap  = 32;   /* snap pixel */
 static const int showbar= 1;/* 0 means no bar */
 static const int topbar = 1;/* 0 means bottom bar */
@@ -84,6 +85,9 @@ static Key keys[] = {
{ MODKEY,   XK_period, focusmon,   {.i = +1 } },
{ MODKEY|ShiftMask, XK_comma,  tagmon, {.i = -1 } },
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
+   { MODKEY,   XK_minus,  setgaps,{.i = -1 } },
+   { MODKEY,   XK_equal,  setgaps,{.i = +1 } },
+   { MODKEY|ShiftMask, XK_equal,  setgaps,{.i = 0  } },
TAGKEYS(XK_1,  0)
TAGKEYS(XK_2,  1)
TAGKEYS(XK_3,  2)
diff --git a/dwm.c b/dwm.c
index 4465af1..4363627 100644
--- a/dwm.c
+++ b/dwm.c
@@ -119,6 +119,7 @@ struct Monitor {
int by;   /* bar geometry */
int mx, my, mw, mh;   /* screen size */
int wx, wy, ww, wh;   /* window area  */
+   int gappx;/* gaps between windows */
unsigned int seltags;
unsigned int sellt;
unsigned int tagset[2];
@@ -199,6 +200,7 @@ static void sendmon(Client *c, Monitor *m);
 static void setclientstate(Client *c, long state);
 static void setfocus(Client *c);
 static void setfullscreen(Client *c, int fullscreen);
+static void setgaps(const Arg *arg);
 static void setlayout(const Arg *arg);
 static void setmfact(const Arg *arg);
 static void setup(void);
@@ -638,6 +640,7 @@ createmon(void)
m->nmaster = nmaster;
m->showbar = showbar;
m->topbar = topbar;
+   m->gappx = gappx;
m->lt[0] = [0];
m->lt[1] = [1 % LENGTH(layouts)];
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
@@ -1497,6 +1500,16 @@ setfullscreen(Client *c, int fullscreen)
}
 }
 
+void
+setgaps(const Arg *arg)
+{
+   if ((arg->i == 0) || (selmon->gappx + arg->i < 0))
+   selmon->gappx = 0;
+   else
+   selmon->gappx += arg->i;
+   arrange(selmon);
+}
+
 void
 setlayout(const Arg *arg)
 {
@@ -1683,16 +1696,16 @@ tile(Monitor *m)
if (n > m->nmaster)
mw = m->nmaster ? m->ww * m->mfact : 0;
else
-   mw = m->ww;
-   for (i = my = ty = 0, c = nexttiled(m->clients); c; c = 
nexttiled(c->next), i++)
+   mw = m->ww - m->gappx;
+   for (i = 0, my = ty = m->gappx, c = nexttiled(m->clients); c; c = 
nexttiled(c->next), i++)
if (i < m->nmaster) {
-   h = (m->wh - my) / (MIN(n, m->nmaster) - i);
-   resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - 
(2*c->bw), 0);
-   my += HEIGHT(c);
+   h = (m->wh - my) / (MIN(n, m->nmaster) - i) - m->gappx;
+   resize(c, m->wx + m->gappx, m->wy + my, mw - (2*c->bw) 
- m->gappx, h - (2*c->bw), 0);
+   my += HEIGHT(c) + m->gappx;
} else {
-   h = (m->wh - ty) / (n - i);
-   resize(c, m->wx + mw, m->wy + ty, m->ww - mw - 
(2*c->bw), h - (2*c->bw), 0);
-   ty += HEIGHT(c);
+   h = (m->wh - ty) / (n - i) - m->gappx;
+   resize(c, m->wx + mw + m->gappx, m->wy + ty, m->ww - mw 
- (2*c->bw) - 2*m->gappx, h - (2*c->bw), 0);
+   ty += HEIGHT(c) + m->gappx;
}
 }
 
-- 
2.20.1




[hackers] [dmenu][PATCH] Capture KeyRelease without processing

2019-02-16 Thread Ivan Tham
Most IME uses keyboard shortcuts to switch to next keyboard input such
as LCTRL + LSHIFT, so need to unmask this event for processing by XIM.
---
 dmenu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/dmenu.c b/dmenu.c
index 3bfd74d..c21ca7a 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -658,7 +658,7 @@ setup(void)
/* create menu window */
swa.override_redirect = True;
swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
-   swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
+   swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | 
VisibilityChangeMask;
win = XCreateWindow(dpy, parentwin, x, y, mw, mh, 0,
CopyFromParent, CopyFromParent, CopyFromParent,
CWOverrideRedirect | CWBackPixel | CWEventMask, 
);
-- 
2.20.1