Re: [dev] [dwm] New software: swm & infobary

From: Steffen Nurpmeso <steffen_AT_sdaoden.eu>
Date: Wed, 30 Oct 2024 01:36:43 +0100

Raymond Cole wrote in
 <stie6dk3objhzijnahbcsuaavxerov3rfc4qel5tbichotqtgn_AT_cyljpygbpqe3>:
 ...
 |Also look at infobar (nothing to do with Alex Jones, seriously). Read its
 |README about what it provides, and compare that to the fact that it's
 |a shell script under 400 lines, isn't it surprisingly small? And its
 |internal working is all about pipes and corporation with other programs.
 ...
 |What about infobar's purpose? I was at first unsatisfied with how most
 |others status program updates their results and that realtime updates
 |and clickability are often achieved hackishly. If you look at infobar's
 |solution to these problems I think you will agree that it's a good one.
 ...

P.S.: my linux.status-line.sh is 671 lines.
I start it in ~/.xinitrc:

  #command -v xclock >/dev/null 2>&1 && xclock &
  if command -v status-line.sh >/dev/null 2>&1; then
          status-line.sh xsetroot &
  fi
  ${S_TERM} ${S_TERM_TITLE} ed 2>/dev/null &
  command -v dwm >/dev/null 2>&1 && exec dwm
  command -v cwm >/dev/null 2>&1 && exec cwm
  command -v ahwm >/dev/null 2>&1 && exec ahwm
  exec ${S_TERM} ${S_TERM_TITLE} ROOT

but eventually "kill -HUP" it so it (until next sig) updates the
tmux status line instead. (I hide dwms status line, but not by
default. I am too stupid for tags, all monocle.) Currently i see

  [P+36°<38° | 0>1#4 | MS:4.7/9.2 | RF:W~B~ wlp1s0~~111 | P,96%~~ | B:2% V:13% | 10-30 01:22]

Nothing to click though. Am not root anyway.
But i can also run it like so (need to fake COLUMNS)

  $ COLUMNS=241 ~/sec.arena/configs.git/misc/linux.status-line.sh a
  = STYLE<> CUT<> SMALL=0 MODS<battery_status brivol loadavg mem model net xdate>
  . PowerPlug:
    + ADP0 P 1730243904
  . Battery:
    + BAT0 96% 96% 37840000 36630000 "Normal" "Not charging" 1730243904
  . Power and Battery: would *not* examine state directly
    + PowerPlug 0 online: 1
    + Battery 0 capacity at 100%, capacity_level=Full, status=Full
  . Brightness: 2%, Volume: 13%
  . loadavg 0>3/244#4
  . Mem: total=7866 free=4764 available=7234 Swap: total=9215 free=9215
  . Memory/Swap 4.7[7.2]<7.8/9.2<9.2
  . CPU 1 temperature 38/100
  . CPU 2 temperature 38/100
  . CPU 3 temperature 38/100
  . CPU 4 temperature 37/100
  . CPU 5 temperature 36/100
  . P+5:36°<1:38°
  . rfkill state: WLAN=~ Bluetooth=~
  . Netdev lo up/down/x=- addr 127.0.0.1, rec 72 MiB, snd 72 MiB loopback
  . Netdev wlp1s0 up/down/x=~~ addr \o/, rec 98 MiB, snd 13 MiB ether
  . Netdev wgppp up/down/x=- addr 192.0.2.2, rec 4 MiB, snd 1 MiB none wireguard
  . Netdev vm up/down/x=- addr 203.0.113.1, rec 0 MiB, snd 0 MiB ether veth
  . Netdev browse up/down/x=- addr 203.0.113.64, rec 2 MiB, snd 51 MiB ether veth
  . Netdev priwse up/down/x=- addr 203.0.113.66, rec 0 MiB, snd 0 MiB ether veth
  . Netdev secweb up/down/x=- addr 203.0.113.68, rec 0 MiB, snd 0 MiB ether veth
  . Date 2024-10-30 00:59 (epoch 1730246398, interval 2/30)
  _AT_P,100%== | B:2% V:13% | 0>3/244#4 | MS:4.7[7.2]<7.8/9.2<9.2 | P+5:36°<1:38° | RF:W~B~ lo-72/72,wlp1s0~~98/13,wgppp-4/1,vm-0/0,browse-2/51,priwse-0/0,secweb-0/0 | 2024-10-30 00:59

It may colourize the tmux status line in green, yellow or red if
it finds things problematic. For some time, until the condition
disappears, it has a concurrent child and talks via pipe, which
controls that.

But other than that, i let acpid2 and udev driven scripts perform
adjustments and place status in files in /run/:

  /run/.sys-backlight /run/.sys-battery /run/.sys-cpu
  /run/.sys-power /run/.sys-volume

and also user scrips can use read(1) to fetch prepared data.
(There is also more stuff like that.)
This is better than pipes and running amixer and sed to dig that
mess. (Sometimes we do nonetheless, ie, if the battery loads;
this is because events seem pretty unreliable.)
Ie also run all=$(ip -json -details -statistics address show) for
network data, and i hope pattern matching is not so slow.

Btw i have also a super simple ignfocus patch, the last chunk of
which is i think useless, and i generally wonder.
I need it because i use xmessage to announce volume etc changes
also, and i hate that takes the focus.

Other than that your swm looks pretty clean from a fast glance.
You could also have used cwm as a base and throw some things off.
I must say i now like doing dwm with its dmenu, but it is not much
smaller than cwm and CPU time could even be more, but that i had
to check. Key bindings via config file is definitely a good
thing and such, and the code doing that is not much heavier than
dwm's array loop. But well. Two seconds CPU since Monday
evening.


    ignfocus
---
 config.def.h |  6 +++---
 dwm.c        | 15 +++++++++++----
 2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/config.def.h b/config.def.h
index 9efa7744b3..941b787234 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -26,9 +26,9 @@ static const Rule rules[] = {
 	 *	WM_CLASS(STRING) = instance, class
 	 *	WM_NAME(STRING) = title
 	 */
-	/* class      instance    title       tags mask     isfloating   monitor */
-	{ "Gimp",     NULL,       NULL,       0,            1,           -1 },
-	{ "Firefox",  NULL,       NULL,       1 << 8,       0,           -1 },
+	/* class      instance    title       tags mask     isfloating   monitor  ignfocus */
+	{ "Gimp",     NULL,       NULL,       0,            1,           -1,      0},
+	{ "firefox",  NULL,       NULL,       1 << 8,       0,           -1,      0},
 };
 
 /* layout(s) */
diff --git a/dwm.c b/dwm.c
index 5ce3f3c0fa..891a7ed93f 100644
--- a/dwm.c
+++ b/dwm.c
_AT_@ -92,7 +92,7 @@ struct Client {
 	int basew, baseh, incw, inch, maxw, maxh, minw, minh, hintsvalid;
 	int bw, oldbw;
 	unsigned int tags;
-	int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
+	int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, ignfocus;
 	Client *next;
 	Client *snext;
 	Monitor *mon;
_AT_@ -139,6 +139,7 @@ typedef struct {
 	unsigned int tags;
 	int isfloating;
 	int monitor;
+	int ignfocus;
 } Rule;
 
 /* function declarations */
_AT_@ -299,6 +300,7 @@ applyrules(Client *c)
 		&& (!r->instance || strstr(instance, r->instance)))
 		{
 			c->isfloating = r->isfloating;
+			c->ignfocus = r->ignfocus;
 			c->tags |= r->tags;
 			for (m = mons; m && m->num != r->monitor; m = m->next);
 			if (m)
_AT_@ -803,7 +805,11 @@ focus(Client *c)
 		attachstack(c);
 		grabbuttons(c, 1);
 		XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel);
-		setfocus(c);
+		if (c->ignfocus <= 0) {
+			if (!c->ignfocus)
+				setfocus(c);
+			c->ignfocus = 0;
+		}
 	} else {
 		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
 		XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
_AT_@ -1234,8 +1240,9 @@ propertynotify(XEvent *e)
 		switch(ev->atom) {
 		default: break;
 		case XA_WM_TRANSIENT_FOR:
-			if (!c->isfloating && (XGetTransientForHint(dpy, c->win, &trans)) &&
-				(c->isfloating = (wintoclient(trans)) != NULL))
+			if (!c->ignfocus && !c->isfloating &&
+					(XGetTransientForHint(dpy, c->win, &trans)) &&
+					(c->isfloating = (wintoclient(trans)) != NULL))
 				arrange(c->mon);
 			break;
 		case XA_WM_NORMAL_HINTS:
--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)
|
|And in Fall, feel "The Dropbear Bard"s ball(s).
|
|The banded bear
|without a care,
|Banged on himself fore'er and e'er
|
|Farewell, dear collar bear
Received on Wed Oct 30 2024 - 01:36:43 CET

This archive was generated by hypermail 2.3.0 : Wed Oct 30 2024 - 01:48:09 CET