sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit 3081dd9b1ca0c87d87216705798fc8e3b9524984
parent 2d8059d726d4954e0f69461cd88aa116b0f9c18f
Author: dadaurs <david.wiedemann@outlook.com>
Date:   Thu, 30 Jul 2020 17:52:55 +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.

Diffstat:
Mdwm.suckless.org/patches/script_tags/dwm-script_tags-6.2.diff | 116++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
Cdwm.suckless.org/patches/script_tags/dwm-script_tags-6.2.diff -> dwm.suckless.org/patches/script_tags/dwm-script_tags-without_fifo.diff | 0
Mdwm.suckless.org/patches/script_tags/index.md | 44++++++++++++++++++++++++++++++++++++--------
3 files changed, 116 insertions(+), 44 deletions(-)

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 @@ -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 @@ -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 -@@ -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 +@@ -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> +@@ -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 +@@ -695,51 +699,55 @@ void drawbar(Monitor *m) { @@ -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 */ @@ -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; @@ -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,"\n"); -+ fclose(fd); ++ strcat(str,sepchar); ++ strcat(str,m->ltsymbol); ++ if(m->sel){ ++ strcat(str,sepchar); ++ strcat(str,m->sel->name); ++ } ++ strcat(str,"\n"); ++ write(fd,&str,strlen(str)+1); ++ close(fd); } void -@@ -1545,7 +1528,7 @@ setup(void) +@@ -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) +@@ -1545,7 +1553,7 @@ if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) die("no fonts could be loaded."); lrpad = drw->fonts->h; @@ -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); -@@ -1802,18 +1785,10 @@ void +@@ -1802,18 +1810,10 @@ updatebars(void) { Monitor *m; @@ -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-6.2.diff b/dwm.suckless.org/patches/script_tags/dwm-script_tags-without_fifo.diff diff --git a/dwm.suckless.org/patches/script_tags/index.md b/dwm.suckless.org/patches/script_tags/index.md @@ -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. @@ -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@gmail.com> +* David Wiedemann <david.wiedemann2 [at] gmail.com>