wmname

sets/prints window manager name similiar to hostname(1)
git clone git://git.suckless.org/wmname
Log | Files | Refs | README | LICENSE

commit b0a608b5385f53252de9508f250592880ef479e9
parent 5fcac5aad79988fd242f475ef278278167a7cd33
Author: Anselm R Garbe <garbeam@gmail.com>
Date:   Tue, 17 Jun 2008 10:29:33 +0100

updated
Diffstat:
LICENSE | 18+++++++++---------
Makefile | 28++++++++++++++--------------
README | 21+++++++++++----------
config.mk | 11+++++------
setwmname.c | 44--------------------------------------------
wmname.c | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 92 insertions(+), 83 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -6,16 +6,16 @@ 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 +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 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 +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 @@ -1,14 +1,14 @@ -# set wm name - sets the WM name +# wmname - prints/sets the WM name include config.mk -SRC = setwmname.c +SRC = wmname.c OBJ = ${SRC:.c=.o} -all: options setwmname +all: options wmname options: - @echo setwmname build options: + @echo wmname build options: @echo "CFLAGS = ${CFLAGS}" @echo "LDFLAGS = ${LDFLAGS}" @echo "CC = ${CC}" @@ -20,31 +20,31 @@ options: ${OBJ}: config.mk -setwmname: ${OBJ} +wmname: ${OBJ} @echo LD $@ @${LD} -o $@ ${OBJ} ${LDFLAGS} @strip $@ clean: @echo cleaning - @rm -f setwmname ${OBJ} setwmname-${VERSION}.tar.gz + @rm -f wmname ${OBJ} wmname-${VERSION}.tar.gz dist: clean @echo creating dist tarball - @mkdir -p setwmname-${VERSION} - @cp -R LICENSE Makefile README config.mk ${SRC} setwmname-${VERSION} - @tar -cf setwmname-${VERSION}.tar setwmname-${VERSION} - @gzip setwmname-${VERSION}.tar - @rm -rf setwmname-${VERSION} + @mkdir -p wmname-${VERSION} + @cp -R LICENSE Makefile README config.mk ${SRC} wmname-${VERSION} + @tar -cf wmname-${VERSION}.tar wmname-${VERSION} + @gzip wmname-${VERSION}.tar + @rm -rf wmname-${VERSION} install: all @echo installing executable file to ${DESTDIR}${PREFIX}/bin @mkdir -p ${DESTDIR}${PREFIX}/bin - @cp -f setwmname ${DESTDIR}${PREFIX}/bin - @chmod 755 ${DESTDIR}${PREFIX}/bin/setwmname + @cp -f wmname ${DESTDIR}${PREFIX}/bin + @chmod 755 ${DESTDIR}${PREFIX}/bin/wmname uninstall: @echo removing executable file from ${DESTDIR}${PREFIX}/bin - @rm -f ${DESTDIR}${PREFIX}/bin/setwmname + @rm -f ${DESTDIR}${PREFIX}/bin/wmname .PHONY: all options clean dist install uninstall diff --git a/README b/README @@ -1,24 +1,25 @@ -setwmname - sets the WM name -============================ -Sets the EWMH WM name property to a specified name. +wmname - prints/sets the WM name +================================ +Prints/sets the EWMH WM name property. Requirements ------------ -In order to build setwmname you need the Xlib header files. +In order to build wmname you need the Xlib header files. Installation ------------ -Edit config.mk to match your local setup (swarp is installed into +Edit config.mk to match your local setup (wmname is installed into the /usr/local namespace by default). -Afterwards enter the following command to build and install swarp (if -necessary as root): +Afterwards enter the following command to build and install wmname +(if necessary as root): make clean install -Running setwmname ------------------ -Simply invoke 'setwmname <name>'. +Running wmname +-------------- +Run 'wmname' to print the current WM name. Run 'wmname <name>' to set it. This +is pretty much similiar to hostname(1). diff --git a/config.mk b/config.mk @@ -1,5 +1,5 @@ -# setwmname version -VERSION = 0.1 +# wmname version +VERSION = 0.2 # Customize below to fit your system @@ -15,10 +15,9 @@ INCS = -I. -I/usr/include -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} +CPPFLAGS = -DVERSION=\"${VERSION}\" +CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} +LDFLAGS = -s ${LIBS} # compiler and linker CC = cc diff --git a/setwmname.c b/setwmname.c @@ -1,44 +0,0 @@ -/* See LICENSE file for details. */ -#include <stdarg.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <X11/Xlib.h> -#include <X11/Xatom.h> -#include <X11/Xutil.h> - -void -eprint(const char *errstr, ...) { - va_list ap; - - va_start(ap, errstr); - vfprintf(stderr, errstr, ap); - va_end(ap); - exit(EXIT_FAILURE); -} - -int -main(int argc, char **argv) { - Display *dpy; - Window root, dummy; - Atom netwmcheck, netwmname, utf8_string; - - if(argc == 2) { - if(!strncmp(argv[1], "-v", 3)) - eprint("setwmname-"VERSION", © 2008 Anselm R Garbe\n", stdout); - } - else - eprint("usage: setwmname <name> [-v]\n"); - - if(!(dpy = XOpenDisplay(0))) - eprint("setwmname: cannot open display\n"); - root = DefaultRootWindow(dpy); - netwmcheck = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False); - netwmname = XInternAtom(dpy, "_NET_WM_NAME", False); - utf8_string = XInternAtom(dpy, "UTF8_STRING", False); - XChangeProperty(dpy, root, netwmcheck, XA_WINDOW, 32, PropModeReplace, (unsigned char *)&root, 1); - XChangeProperty(dpy, root, netwmname, utf8_string, 8, PropModeReplace, (unsigned char *)argv[1], strlen(argv[1])); - XSync(dpy, False); - XCloseDisplay(dpy); - return 0; -} diff --git a/wmname.c b/wmname.c @@ -0,0 +1,53 @@ +/* See LICENSE file for details. */ +#include <stdarg.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <X11/Xlib.h> +#include <X11/Xatom.h> +#include <X11/Xutil.h> + +void +eprint(const char *errstr, ...) { + va_list ap; + + va_start(ap, errstr); + vfprintf(stderr, errstr, ap); + va_end(ap); + exit(EXIT_FAILURE); +} + +int +main(int argc, char **argv) { + int status, format; + unsigned char *data = NULL; + unsigned long n, extra; + Display *dpy; + Window root; + Atom netwmcheck, netwmname, utf8_string, real; + + if(argc > 2) + eprint("usage: setwmname [name] [-v]\n"); + else if(argc == 2 && !strncmp(argv[1], "-v", 3)) + eprint("setwmname-"VERSION", © 2008 Anselm R Garbe\n", stdout); + + if(!(dpy = XOpenDisplay(0))) + eprint("setwmname: cannot open display\n"); + root = DefaultRootWindow(dpy); + netwmcheck = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False); + netwmname = XInternAtom(dpy, "_NET_WM_NAME", False); + utf8_string = XInternAtom(dpy, "UTF8_STRING", False); + if(argc == 1) { + status = XGetWindowProperty(dpy, root, netwmname, 0L, 32L, False, utf8_string, &real, &format, &n, &extra, (unsigned char **) &data); + if(status == Success && data != NULL) + fprintf(stdout, "%s\n", data); + XFree(data); + } + else { + XChangeProperty(dpy, root, netwmcheck, XA_WINDOW, 32, PropModeReplace, (unsigned char *)&root, 1); + XChangeProperty(dpy, root, netwmname, utf8_string, 8, PropModeReplace, (unsigned char *)argv[1], strlen(argv[1])); + } + XSync(dpy, False); + XCloseDisplay(dpy); + return 0; +}