lsw

lists window titles of X clients to stdout
git clone git://git.suckless.org/lsw
Log | Files | Refs | README | LICENSE

commit 490ecea1bdc260bbe9e91e9cf621c81d89d9e621
Author: arg@suckless.org <unknown>
Date:   Tue, 10 Oct 2006 09:07:36 +0200

initial commit

Diffstat:
ALICENSE | 22++++++++++++++++++++++
AMakefile | 49+++++++++++++++++++++++++++++++++++++++++++++++++
AREADME | 24++++++++++++++++++++++++
Aconfig.mk | 24++++++++++++++++++++++++
Alsw.c | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 192 insertions(+), 0 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,22 @@ +MIT/X Consortium License + +(C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> +(C)opyright MMVI Sander van Dijk <a dot h dot vandijk at gmail dot 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/Makefile b/Makefile @@ -0,0 +1,49 @@ +# lsw - list window names +# (C)opyright MMVI Anselm R. Garbe + +include config.mk + +SRC = lsw.c +OBJ = ${SRC:.c=.o} + +all: options lsw + @echo finished + +options: + @echo lsw build options: + @echo "CFLAGS = ${CFLAGS}" + @echo "LDFLAGS = ${LDFLAGS}" + @echo "CC = ${CC}" + +.c.o: + @echo CC $< + @${CC} -c ${CFLAGS} $< + +lsw: ${OBJ} + @echo LD $@ + @${CC} -o $@ ${OBJ} ${LDFLAGS} + @strip $@ + +clean: + @echo cleaning + @rm -f lsw ${OBJ} lsw-${VERSION}.tar.gz + +dist: clean + @echo creating dist tarball + @mkdir -p lsw-${VERSION} + @cp -R LICENSE Makefile README config.mk ${SRC} lsw-${VERSION} + @tar -cf lsw-${VERSION}.tar lsw-${VERSION} + @gzip lsw-${VERSION}.tar + @rm -rf lsw-${VERSION} + +install: all + @echo installing executable file to ${DESTDIR}${PREFIX}/bin + @mkdir -p ${DESTDIR}${PREFIX}/bin + @cp -f lsw ${DESTDIR}${PREFIX}/bin + @chmod 755 ${DESTDIR}${PREFIX}/bin/lsw + +uninstall: + @echo removing executable file from ${DESTDIR}${PREFIX}/bin + @rm -f ${DESTDIR}${PREFIX}/bin/lsw + +.PHONY: all options clean dist install uninstall diff --git a/README b/README @@ -0,0 +1,24 @@ +lsw - list window titles +======================== +Prints all window titles of DISPLAY to standard output. + + +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 +----------- +Simply invoke the 'lsw' command. diff --git a/config.mk b/config.mk @@ -0,0 +1,24 @@ +# lsw version +VERSION = 0.1 + +# Customize below to fit your system + +# paths +PREFIX = /usr/local +MANPREFIX = ${PREFIX}/share/man + +X11INC = /usr/X11R6/include +X11LIB = /usr/X11R6/lib + +# includes and libs +INCS = -I/usr/lib -I${X11INC} +LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 + +# flags +CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" +LDFLAGS = ${LIBS} +#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" +#LDFLAGS = -g ${LIBS} + +# compiler +CC = cc diff --git a/lsw.c b/lsw.c @@ -0,0 +1,73 @@ +/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> + * See LICENSE file for license details. + */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <X11/Xatom.h> +#include <X11/Xlib.h> +#include <X11/Xutil.h> + +static char buf[1024]; +static Atom netwmname; +static Display *dpy; +static Window root; + +static void +getname(Window w) { + char **list = NULL; + int n; + XTextProperty prop; + + prop.nitems = 0; + buf[0] = 0; + XGetTextProperty(dpy, w, &prop, netwmname); + if(!prop.nitems) + XGetWMName(dpy, w, &prop); + if(!prop.nitems) + return; + if(prop.encoding == XA_STRING) + strncpy(buf, (char *)prop.value, sizeof(buf)); + else { + if(XmbTextPropertyToTextList(dpy, &prop, &list, &n) >= Success + && n > 0 && *list) + { + strncpy(buf, *list, sizeof(buf)); + XFreeStringList(list); + } + } + XFree(prop.value); +} + +int +main(int argc, char *argv[]) { + unsigned int i, num; + Window *wins, d1, d2; + XWindowAttributes wa; + + if((argc) > 1 && !strncmp(argv[1], "-v", 3)) { + fputs("lsw-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); + exit(EXIT_SUCCESS); + } + if(!(dpy = XOpenDisplay(0))) { + fputs("wtool: cannot open display\n", stderr); + exit(EXIT_FAILURE); + } + root = RootWindow(dpy, DefaultScreen(dpy)); + netwmname = XInternAtom(dpy, "_NET_WM_NAME", False); + if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) { + for(i = 0; i < num; i++) { + if(!XGetWindowAttributes(dpy, wins[i], &wa)) + continue; + if(wa.override_redirect) + continue; + getname(wins[i]); + if(buf[0]) + fprintf(stdout, "%s\n", buf); + } + } + if(wins) + XFree(wins); + XCloseDisplay(dpy); + return 0; +}