birdwm

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 830b882924687865a48009b61845ab43007a1253
parent b9e752d997b035e29d95369231e20233f11c125f
Author: grouse <bdmfegys@duck.com>
Date:   Fri, 29 Dec 2023 11:41:06 -0500

add lsw script with modified make flags to extras

Diffstat:
Aextras/lsw/LICENSE | 22++++++++++++++++++++++
Aextras/lsw/Makefile | 40++++++++++++++++++++++++++++++++++++++++
Aextras/lsw/README | 24++++++++++++++++++++++++
Aextras/lsw/config.mk | 30++++++++++++++++++++++++++++++
Aextras/lsw/lsw.1 | 11+++++++++++
Aextras/lsw/lsw.c | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 200 insertions(+), 0 deletions(-)

diff --git a/extras/lsw/LICENSE b/extras/lsw/LICENSE @@ -0,0 +1,22 @@ +MIT/X Consortium License + +© 2006-2014 Anselm R Garbe <anselm@garbe.us> +© 2011 Connor Lane Smith <cls@lubutu.com> + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/extras/lsw/Makefile b/extras/lsw/Makefile @@ -0,0 +1,40 @@ +# lsw - list window names +# See LICENSE file for copyright and license details. +.POSIX: + +include config.mk + +SRC = lsw.c +OBJ = ${SRC:.c=.o} + +all: lsw + +.c.o: + ${CC} -c ${CFLAGS} $< + +lsw: ${OBJ} + ${CC} -o $@ ${OBJ} ${LDFLAGS} + +clean: + rm -f lsw ${OBJ} lsw-${VERSION}.tar.gz + +dist: clean + mkdir -p lsw-${VERSION} + cp -R LICENSE Makefile README config.mk lsw.1 ${SRC} lsw-${VERSION} + tar -cf lsw-${VERSION}.tar lsw-${VERSION} + gzip lsw-${VERSION}.tar + rm -rf lsw-${VERSION} + +install: all + mkdir -p ${DESTDIR}${PREFIX}/bin + cp -f lsw ${DESTDIR}${PREFIX}/bin + chmod 755 ${DESTDIR}${PREFIX}/bin/lsw + mkdir -p ${DESTDIR}${MANPREFIX}/man1 + sed "s/VERSION/${VERSION}/g" < lsw.1 > ${DESTDIR}${MANPREFIX}/man1/lsw.1 + chmod 644 ${DESTDIR}${MANPREFIX}/man1/lsw.1 + +uninstall: + rm -f ${DESTDIR}${PREFIX}/bin/lsw + rm -f ${DESTDIR}${MANPREFIX}/man1/lsw.1 + +.PHONY: all options clean dist install uninstall diff --git a/extras/lsw/README b/extras/lsw/README @@ -0,0 +1,24 @@ +lsw - list windows +================== +lsw prints the title and XID of windows to stdout. + + +Requirements +------------ +In order to build lsw you need the Xlib header files. + + +Installation +------------ +Edit config.mk to match your local setup (lsw is installed into +the /usr/local namespace by default). + +Afterwards enter the following command to build and install lsw (if +necessary as root): + + make clean install + + +Running lsw +----------- +See the man page for details. diff --git a/extras/lsw/config.mk b/extras/lsw/config.mk @@ -0,0 +1,30 @@ +# lsw version +VERSION = 0.3 + +# paths +PREFIX = /usr/local +MANPREFIX = ${PREFIX}/share/man + +X11INC = /usr/X11R6/include +X11LIB = /usr/X11R6/lib + +# includes and libs +INCS = -I${X11INC} +LIBS = -L${X11LIB} -lX11 + +# compiler and linker +ifeq ($(shell which tcc), $(shell false)) + CC = cc +else + CC = tcc +endif + +# flags +ifeq ($(CC), tcc) + CFLAGS = -pedantic -Wall -Os ${INCS} ${CPPFLAGS} +else + CFLAGS = -ansi -pedantic -Wall -Os ${INCS} ${CPPFLAGS} +endif +CPPFLAGS = -DVERSION=\"${VERSION}\" +LDFLAGS = -s ${LIBS} + diff --git a/extras/lsw/lsw.1 b/extras/lsw/lsw.1 @@ -0,0 +1,11 @@ +.TH LSW 1 lsw\-VERSION +.SH NAME +lsw \- list windows +.SH SYNOPSIS +.B lsw +.RI [ window ...] +.SH DESCRIPTION +.B lsw +prints the title and XID of each child of each +.IR window . +If none are given the root window is used. diff --git a/extras/lsw/lsw.c b/extras/lsw/lsw.c @@ -0,0 +1,73 @@ +/* See LICENSE file for copyright and license details. */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> + +static Atom netwmname; +static Display *dpy; + +static char * +getname(Window win) +{ + static char buf[BUFSIZ]; + char **list; + int n; + XTextProperty prop; + + if (!XGetTextProperty(dpy, win, &prop, netwmname) || !prop.nitems) { + if (!XGetWMName(dpy, win, &prop) || !prop.nitems) + return ""; + } + if (!XmbTextPropertyToTextList(dpy, &prop, &list, &n) && n > 0) { + strncpy(buf, list[0], sizeof(buf)); + XFreeStringList(list); + } else { + strncpy(buf, (char *)prop.value, sizeof(buf)); + } + XFree(prop.value); + buf[sizeof(buf) - 1] = '\0'; + + return buf; +} + +static void +lsw(Window win) +{ + unsigned int n; + Window *wins, *w, dw; + XWindowAttributes wa; + + if (!XQueryTree(dpy, win, &dw, &dw, &wins, &n) || !n) + return; + for (w = &wins[n-1]; w >= &wins[0]; w--) { + if (XGetWindowAttributes(dpy, *w, &wa) + && !wa.override_redirect && wa.map_state == IsViewable) + printf("0x%07lx %s\n", *w, getname(*w)); + } + XFree(wins); +} + +int +main(int argc, char *argv[]) +{ + int i; + + if (!(dpy = XOpenDisplay(NULL))) { + fprintf(stderr, "%s: cannot open display\n", argv[0]); + exit(EXIT_FAILURE); + } + netwmname = XInternAtom(dpy, "_NET_WM_NAME", False); + + if (argc < 2) { + lsw(DefaultRootWindow(dpy)); + } else { + for (i = 1; i < argc; i++) + lsw(strtol(argv[i], NULL, 0)); + } + + XCloseDisplay(dpy); + + return EXIT_SUCCESS; +}