[wiki] [sites] Update script_tags to use fifo || dadaurs

From: <git_AT_suckless.org>
Date: Thu, 30 Jul 2020 17:55:04 +0200

commit 3081dd9b1ca0c87d87216705798fc8e3b9524984
Author: dadaurs <david.wiedemann_AT_outlook.com>
Date: Thu Jul 30 17:52:55 2020 +0200

    Update script_tags to use fifo
    
    The patch now uses a named pipe instead of a file.
    
    Also updated readme as well as email address.

diff --git a/dwm.suckless.org/patches/script_tags/dwm-script_tags-6.2.diff b/dwm.suckless.org/patches/script_tags/dwm-script_tags-6.2.diff
index 9010ab8a..4ef5e2d0 100644
--- a/dwm.suckless.org/patches/script_tags/dwm-script_tags-6.2.diff
+++ b/dwm.suckless.org/patches/script_tags/dwm-script_tags-6.2.diff
_AT_@ -1,23 +1,42 @@
-diff -up dwmdiff/dwm-6.2/config.def.h dwm-6.2/config.def.h
---- dwmdiff/dwm-6.2/config.def.h 2019-02-02 13:55:28.000000000 +0100
-+++ dwm-6.2/config.def.h 2020-05-18 20:27:30.392698992 +0200
+diff --color -r -u dwm-6.2/config.def.h dwm_patched/config.def.h
+--- dwm-6.2/config.def.h 2019-02-02 13:55:28.000000000 +0100
++++ dwm_patched/config.def.h 2020-07-30 17:23:53.470898016 +0200
 _AT_@ -3,6 +3,9 @@
  /* appearance */
  static const unsigned int borderpx = 1; /* border pixel of windows */
  static const unsigned int snap = 32; /* snap pixel */
-+static const char *tagfile = "/tmp/dwm_tags";
-+static const int barheight = 25; /* 0 means bottom bar */
++static const char *tagfifo = "/tmp/dwm_tags"; /*fifo of bar information */
++static const int barheight = 25; /*height of bar*/
 +static const char *sepchar = ":";
  static const int showbar = 1; /* 0 means no bar */
  static const int topbar = 1; /* 0 means bottom bar */
  static const char *fonts[] = { "monospace:size=10" };
-Only in dwm-6.2: config.h
-Only in dwm-6.2: drw.o
-Only in dwm-6.2: dwm
-diff -up dwmdiff/dwm-6.2/dwm.c dwm-6.2/dwm.c
---- dwmdiff/dwm-6.2/dwm.c 2019-02-02 13:55:28.000000000 +0100
-+++ dwm-6.2/dwm.c 2020-05-18 20:26:52.791699537 +0200
-_AT_@ -695,51 +695,34 @@ dirtomon(int dir)
+Only in dwm_patched: drw.o
+diff --color -r -u dwm-6.2/dwm.c dwm_patched/dwm.c
+--- dwm-6.2/dwm.c 2019-02-02 13:55:28.000000000 +0100
++++ dwm_patched/dwm.c 2020-07-30 17:27:29.083891791 +0200
+_AT_@ -28,6 +28,7 @@
+ #include <stdlib.h>
+ #include <string.h>
+ #include <unistd.h>
++#include <fcntl.h>
+ #include <sys/types.h>
+ #include <sys/wait.h>
+ #include <X11/cursorfont.h>
+_AT_@ -387,8 +388,11 @@
+ if (m) {
+ arrangemon(m);
+ restack(m);
+- } else for (m = mons; m; m = m->next)
++ } else for (m = mons; m; m = m->next){
+ arrangemon(m);
++ }
++
++
+ }
+
+ void
+_AT_@ -695,51 +699,55 @@
  void
  drawbar(Monitor *m)
  {
_AT_@ -25,8 +44,9 @@ diff -up dwmdiff/dwm-6.2/dwm.c dwm-6.2/dwm.c
 - int boxs = drw->fonts->h / 9;
 - int boxw = drw->fonts->h / 6 + 2;
          unsigned int i, occ = 0, urg = 0;
-+ FILE *fd;
++ int fd;
          Client *c;
++ char str[1000]="";
  
 - /* draw status first so it can be overdrawn by tags later */
 - if (m == selmon) { /* status is only drawn on selected monitor */
_AT_@ -34,7 +54,9 @@ diff -up dwmdiff/dwm-6.2/dwm.c dwm-6.2/dwm.c
 - sw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
 - drw_text(drw, m->ww - sw, 0, sw, bh, 0, stext, 0);
 - }
-+ fd = fopen(tagfile,"w+");
++
++ mkfifo(tagfifo, 0666);
++ fd = open(tagfifo,O_WRONLY);
  
          for (c = m->clients; c; c = c->next) {
                  occ |= c->tags;
_AT_@ -65,29 +87,55 @@ diff -up dwmdiff/dwm-6.2/dwm.c dwm-6.2/dwm.c
 - } else {
 - drw_setscheme(drw, scheme[SchemeNorm]);
 - drw_rect(drw, x, 0, w, bh, 1, 1);
-- }
++ strcat(str,sepchar);
++
++ // Occupied and focused
++ if ( occ & 1 << i && m->tagset[m->seltags] & 1 << i ) {
++ /*fprintf(fd,"%%C %s %%f",tags[i]);*/
++ strcat(str,"%O ");
++ strcat(str,tags[i]);
++ strcat(str," %f");
++ //not occupied but still focused
++ } else if ( !( occ & 1 << i )&& m->tagset[m->seltags] & 1 << i ) {
++ strcat(str,"%E ");
++ strcat(str,tags[i]);
++ strcat(str," %f");
++ } else if ( occ & 1 << i && !( m->tagset[m->seltags] & 1 << i ) ) {
++ //occupied but not focused
++ strcat(str,"%o ");
++ strcat(str,tags[i]);
++ strcat(str," %f");
++ } else {
++ //not occupied not focused
++ strcat(str,"%e ");
++ strcat(str,tags[i]);
++ strcat(str," %f");
+ }
 - }
 - drw_map(drw, m->barwin, 0, 0, m->ww, bh);
-+ fprintf(fd,"%s",sepchar);
-+ if ( occ & 1 << i && m->tagset[m->seltags] & 1 << i ) {
-+ fprintf(fd,"O%s",tags[i]);
-+ } else if ( !( occ & 1 << i )&& m->tagset[m->seltags] & 1 << i ) {
-+ fprintf(fd,"E%s",tags[i]);
-+ } else if ( occ & 1 << i && !( m->tagset[m->seltags] & 1 << i ) ) {
-+ fprintf(fd,"o%s",tags[i]);
-+ } else
-+ fprintf(fd,"e%s",tags[i]);
-+
-+ /*x += w;*/
 + }
-+ fprintf(fd,"%s",sepchar);
-+ fprintf(fd,"%s",m->ltsymbol);
-+ fprintf(fd,"
");
-+ fclose(fd);
++ strcat(str,sepchar);
++ strcat(str,m->ltsymbol);
++ if(m->sel){
++ strcat(str,sepchar);
++ strcat(str,m->sel->name);
++ }
++ strcat(str,"
");
++ write(fd,&str,strlen(str)+1);
++ close(fd);
  }
  
  void
-_AT_@ -1545,7 +1528,7 @@ setup(void)
+_AT_@ -1351,7 +1359,7 @@
+ XEvent ev;
+ XWindowChanges wc;
+
+- drawbar(m);
++ /*drawbar(m);*/
+ if (!m->sel)
+ return;
+ if (m->sel->isfloating || !m->lt[m->sellt]->arrange)
+_AT_@ -1545,7 +1553,7 @@
          if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
                  die("no fonts could be loaded.");
          lrpad = drw->fonts->h;
_AT_@ -96,7 +144,7 @@ diff -up dwmdiff/dwm-6.2/dwm.c dwm-6.2/dwm.c
          updategeom();
          /* init atoms */
          utf8string = XInternAtom(dpy, "UTF8_STRING", False);
-_AT_@ -1802,18 +1785,10 @@ void
+_AT_@ -1802,18 +1810,10 @@
  updatebars(void)
  {
          Monitor *m;
_AT_@ -115,7 +163,3 @@ diff -up dwmdiff/dwm-6.2/dwm.c dwm-6.2/dwm.c
                  XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
                  XMapRaised(dpy, m->barwin);
                  XSetClassHint(dpy, m->barwin, &ch);
-Only in dwm-6.2: dwm.o
-Only in dwm-6.2: dwm-script_tags-6.2.diff
-Only in dwm-6.2: test.diff
-Only in dwm-6.2: util.o
diff --git a/dwm.suckless.org/patches/script_tags/dwm-script_tags-without_fifo.diff b/dwm.suckless.org/patches/script_tags/dwm-script_tags-without_fifo.diff
new file mode 100644
index 00000000..9010ab8a
--- /dev/null
+++ b/dwm.suckless.org/patches/script_tags/dwm-script_tags-without_fifo.diff
_AT_@ -0,0 +1,121 @@
+diff -up dwmdiff/dwm-6.2/config.def.h dwm-6.2/config.def.h
+--- dwmdiff/dwm-6.2/config.def.h 2019-02-02 13:55:28.000000000 +0100
++++ dwm-6.2/config.def.h 2020-05-18 20:27:30.392698992 +0200
+_AT_@ -3,6 +3,9 @@
+ /* appearance */
+ static const unsigned int borderpx = 1; /* border pixel of windows */
+ static const unsigned int snap = 32; /* snap pixel */
++static const char *tagfile = "/tmp/dwm_tags";
++static const int barheight = 25; /* 0 means bottom bar */
++static const char *sepchar = ":";
+ static const int showbar = 1; /* 0 means no bar */
+ static const int topbar = 1; /* 0 means bottom bar */
+ static const char *fonts[] = { "monospace:size=10" };
+Only in dwm-6.2: config.h
+Only in dwm-6.2: drw.o
+Only in dwm-6.2: dwm
+diff -up dwmdiff/dwm-6.2/dwm.c dwm-6.2/dwm.c
+--- dwmdiff/dwm-6.2/dwm.c 2019-02-02 13:55:28.000000000 +0100
++++ dwm-6.2/dwm.c 2020-05-18 20:26:52.791699537 +0200
+_AT_@ -695,51 +695,34 @@ dirtomon(int dir)
+ void
+ drawbar(Monitor *m)
+ {
+- int x, w, sw = 0;
+- int boxs = drw->fonts->h / 9;
+- int boxw = drw->fonts->h / 6 + 2;
+ unsigned int i, occ = 0, urg = 0;
++ FILE *fd;
+ Client *c;
+
+- /* draw status first so it can be overdrawn by tags later */
+- if (m == selmon) { /* status is only drawn on selected monitor */
+- drw_setscheme(drw, scheme[SchemeNorm]);
+- sw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
+- drw_text(drw, m->ww - sw, 0, sw, bh, 0, stext, 0);
+- }
++ fd = fopen(tagfile,"w+");
+
+ for (c = m->clients; c; c = c->next) {
+ occ |= c->tags;
+ if (c->isurgent)
+ urg |= c->tags;
+ }
+- x = 0;
+ for (i = 0; i < LENGTH(tags); i++) {
+- w = TEXTW(tags[i]);
+- drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
+- drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
+- if (occ & 1 << i)
+- drw_rect(drw, x + boxs, boxs, boxw, boxw,
+- m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
+- urg & 1 << i);
+- x += w;
+- }
+- w = blw = TEXTW(m->ltsymbol);
+- drw_setscheme(drw, scheme[SchemeNorm]);
+- x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
+-
+- if ((w = m->ww - sw - x) > bh) {
+- if (m->sel) {
+- drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
+- drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
+- if (m->sel->isfloating)
+- drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
+- } else {
+- drw_setscheme(drw, scheme[SchemeNorm]);
+- drw_rect(drw, x, 0, w, bh, 1, 1);
+- }
+- }
+- drw_map(drw, m->barwin, 0, 0, m->ww, bh);
++ fprintf(fd,"%s",sepchar);
++ if ( occ & 1 << i && m->tagset[m->seltags] & 1 << i ) {
++ fprintf(fd,"O%s",tags[i]);
++ } else if ( !( occ & 1 << i )&& m->tagset[m->seltags] & 1 << i ) {
++ fprintf(fd,"E%s",tags[i]);
++ } else if ( occ & 1 << i && !( m->tagset[m->seltags] & 1 << i ) ) {
++ fprintf(fd,"o%s",tags[i]);
++ } else
++ fprintf(fd,"e%s",tags[i]);
++
++ /*x += w;*/
++ }
++ fprintf(fd,"%s",sepchar);
++ fprintf(fd,"%s",m->ltsymbol);
++ fprintf(fd,"
");
++ fclose(fd);
+ }
+
+ void
+_AT_@ -1545,7 +1528,7 @@ setup(void)
+ if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
+ die("no fonts could be loaded.");
+ lrpad = drw->fonts->h;
+- bh = drw->fonts->h + 2;
++ bh = barheight;
+ updategeom();
+ /* init atoms */
+ utf8string = XInternAtom(dpy, "UTF8_STRING", False);
+_AT_@ -1802,18 +1785,10 @@ void
+ updatebars(void)
+ {
+ Monitor *m;
+- XSetWindowAttributes wa = {
+- .override_redirect = True,
+- .background_pixmap = ParentRelative,
+- .event_mask = ButtonPressMask|ExposureMask
+- };
+ XClassHint ch = {"dwm", "dwm"};
+ for (m = mons; m; m = m->next) {
+ if (m->barwin)
+ continue;
+- m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen),
+- CopyFromParent, DefaultVisual(dpy, screen),
+- CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
+ XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
+ XMapRaised(dpy, m->barwin);
+ XSetClassHint(dpy, m->barwin, &ch);
+Only in dwm-6.2: dwm.o
+Only in dwm-6.2: dwm-script_tags-6.2.diff
+Only in dwm-6.2: test.diff
+Only in dwm-6.2: util.o
diff --git a/dwm.suckless.org/patches/script_tags/index.md b/dwm.suckless.org/patches/script_tags/index.md
index 11720cd3..df17da76 100644
--- a/dwm.suckless.org/patches/script_tags/index.md
+++ b/dwm.suckless.org/patches/script_tags/index.md
_AT_@ -6,7 +6,7 @@ Description
 This patch does two things:
 1) It removes the code that generates the bar, but still leaves a "toggleable" area.
 
-2) On X events, it writes all the tag and layout information to a user defined file.
+2) On X events, it writes all the tag and layout information to a user defined fifo.
 
 This allows any bar that reads stdin to be used in conjuction with dwm.
 
_AT_@ -24,29 +24,57 @@ Each tagname is prefixed with a character describing the state of that tag.
 
 There are 4 different states:
 
-state 'e': tag is empty and not focused
+state '%e': tag is empty and not focused
 
-state 'E': tag is empty and focused
+state '%E': tag is empty and focused
 
-state 'o': tag is occupied and not focused
+state '%o': tag is occupied and not focused
 
-state 'O': tag is occupied and focused
+state '%O': tag is occupied and focused
+
+Each tag name is also suffixed with %f, this makes scripting the output a bit easier.
+
+All of these predefined strings are easily modified in dwm.c.
 
 The different tags with respective tag information are separated by the sepchar variable defined in config.h.
 
 A simple example would be:
 
+Attention
+-----------
+
+Because of how named pipes work, dwm will stall if no process is reading from the fifo.
+If one does not want to use any bar, one can call
 ```
-echo /tmp/dwm_tags| entr cat /tmp/dwm_tags | lemonbar
+tail -f /tmp/dwm_tags &
 ```
+from .xinitrc or in another tty.
+
+
+Example
+-----------
+The script I currently use in conjunction with lemonbar is:
+```
+tail -f /tmp/dwm_tags 2>/dev/null | while IFS= read -r line; do
+ sed\
+ -e "s/%O/%{F#FFFFFF}%{B#292c2e}/g"\
+ -e "s/%o/%{F#FFFFFF}%{B#5F819D}/g"\
+ -e "s/%O/%{F#292c2e}%{B#FFFFFF}/g"\
+ -e "s/%E/%{F#292c2e}%{B#FFFFFF}/g"\
+ -e 's/%f/%{F}%{B}/g' <<< $line
+done | lemonbar -d -B "#292c2e" -F "#FFFFFF" -g x25
+
+```
+
 
 Download
 -----------
-* [dwm-script_tags-6.2.diff](dwm-script_tags-6.2.diff) (18.05.2020)
+* [dwm-script_tags-6.2.diff](dwm-script_tags-6.2.diff) (30.07.2020)
+* Old version without fifo, wouldn't recommend it:[dwm-script_tags-without_fifo.diff](dwm-script_tags-without_fifo.diff)
 
 Authors
 -----------
-* David Wiedemann <david.wiedemann2_AT_gmail.com>
+* David Wiedemann <david.wiedemann2 [at] gmail.com>
 
 
 
Received on Thu Jul 30 2020 - 17:55:04 CEST

This archive was generated by hypermail 2.3.0 : Thu Jul 30 2020 - 18:00:47 CEST