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

From: Jeremy <jer_AT_jer.cx>
Date: Mon, 4 Nov 2024 00:06:17 -0800

On 10/25/24 08:11AM, Raymond Cole wrote:
> May someone check them out and share opinions?
>

I like this
if [ "$butt" -eq 1 ]; then

I did my bar a similar way, except each widget is a script responsible for its own formatting, like:
mpc status -f '%artist% ~ %title%' | if read -r song && read -r state rest; then
        case "$state" in
                '[playing]') echo "$song ►";;
                *) echo "$song ◼";;
        esac
else
        echo "◼"
fi; mpc idle >/dev/null

And then the main bar program loops each script. Only problem is when
I fuck myself & create 900000 processes for no reason then my bar stops
working.

I did a shorter version of fifolog(conccat) without line-delimiting a
little while back - see below.

Jeremy

---
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/select.h>
int
main(int argc, char **argv)
{
	int i, j, n, w, eof;
	fd_set rs;
	char buf[BUFSIZ];
	for (i = 1; i < argc; i++) {
		// close any "accidently" open file descriptors
		close((i+2)+(argc-1));
		if ((n = open(argv[i], O_RDONLY)) == -1) {
			fprintf(stderr, "pselect: %s\n", strerror(errno));
			return 1;
		}
	}
	for (eof = 0; !eof;) {
		FD_ZERO(&rs);
		for (i = 3; i < argc+2; i++) {
			FD_SET(i+(argc-1), &rs);
		}
		if ((n = select(i+argc, &rs, NULL, NULL, NULL)) == -1) {
			fprintf(stderr, "pselect: %s\n", strerror(errno));
			return 1;
		}
		for (i = 3; i < argc+2; i++) {
			if (!FD_ISSET(i+(argc-1), &rs)) {
				continue;
			}
			if ((n = read(i+(argc-1), &buf[0], sizeof(buf))) == -1) {
				fprintf(stderr, "failed reading from fd %d: %s\n", i+(argc-1), strerror(errno));
				return 1;
			} else if (n == 0) {
				eof = 1;
			}
			for (j = 0; j < n; j += w) {
				if ((w = write(i, &buf[j], n-j)) == -1 || w == 0) {
					fprintf(stderr, "failed: %s\n", strerror(errno));
					return -1;
				}
			}
		}
	}
}
Received on Mon Nov 04 2024 - 09:06:17 CET

This archive was generated by hypermail 2.3.0 : Mon Nov 04 2024 - 09:12:10 CET