storename

Trivial utility for setting the root window's name in X11
Log | Files | Refs

commit d9ec2da15317ee8382c14ef23b41c171fcd16f0d
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Mon, 20 Mar 2023 11:06:19 -0700

Add storename project from 2021

I probably wrote the program mid to late 2021. The Makefile was
written just now.

Diffstat:
AMakefile | 22++++++++++++++++++++++
Astorename.1 | 25+++++++++++++++++++++++++
Astorename.c | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 102 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile @@ -0,0 +1,22 @@ +cc = ${CC} +cflags = ${CFLAGS} -I/usr/X11R6/include +ldflags = ${LDFLAGS} -L/usr/X11R6/lib -lX11 + +.c.o: + ${cc} ${cflags} -c -o $@ $< + +storename: storename.o + ${cc} ${ldflags} -o $@ storename.o + +install: storename + cp storename ${prefix}/bin + cp storename.1 ${prefix}/man/man1 + +uninstall: + rm -f ${prefix}/bin/storename + rm -f ${prefix}/man/man1/storename.1 + +clean: + rm -f storename storename.o + +.PHONY: install uninstall clean diff --git a/storename.1 b/storename.1 @@ -0,0 +1,25 @@ +.\" Copyright 2021 Jacob R. Edwards +.Dd July 22, 2021 +.Dt STORENAME 1 +.Os +.Sh NAME +.Nm storename +.Nd Store input as root X window name +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +The +.Nm +utility sets the root X window name to each line of input as it +reads it. +.Sh EXIT STATUS +.Ex -std +.Sh EXAMPLES +Store the current date and time as the root window name: +.Pp +.Dl $ while sleep 1; do date; done | storename +.Sh SEE ALSO +.Xr dwm 1 , +.Xr status 1 +.Sh AUTHORS +.An Jacob R. Edwards diff --git a/storename.c b/storename.c @@ -0,0 +1,55 @@ +/* + * Copyright 2021 Jacob R. Edwards + * License: GPLv3 + * Compile: + * cc -o storename -L/usr/X11R6/lib -I/usr/X11R6/include storename.c -lX11 + * + * The storename utility stores each line of input as the default + * root window's name until EOF is encountered. + */ + +#include <X11/Xlib.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#ifdef __OpenBSD__ +#include <unistd.h> +#endif + +void +die(char *s) +{ + perror(s); + exit(1); +} + +int +main(void) +{ + Display *display; + char *buf; + size_t size; + ssize_t len; + + display = XOpenDisplay(NULL); + if (display == NULL) + die("unable to open display"); + +#ifdef __OpenBSD__ + if (pledge("stdio", NULL) == -1) + die("pledge"); +#endif + + while ((len = getline(&buf, &size, stdin)) != -1) { + if (buf[len - 1] == '\n') + buf[len - 1] = 0; + XStoreName(display, DefaultRootWindow(display), buf); + XFlush(display); + } + + XCloseDisplay(display); + if (ferror(stdin)) + die("stdin"); + return 0; +}