Browse Source

add dstat

master
Evan Burkey 4 months ago
parent
commit
59b1e2d8fd
  1. 1
      .gitignore
  2. 55
      dstat-0.7/Makefile
  3. 29
      dstat-0.7/README
  4. 174
      dstat-0.7/dstat.1
  5. 333
      dstat-0.7/dstat.c
  6. 37
      dwm/LICENSE
  7. 51
      dwm/Makefile
  8. 48
      dwm/README
  9. 115
      dwm/config.def.h
  10. 115
      dwm/config.h
  11. 38
      dwm/config.mk
  12. 436
      dwm/drw.c
  13. 57
      dwm/drw.h
  14. 176
      dwm/dwm.1
  15. 2152
      dwm/dwm.c
  16. BIN
      dwm/dwm.png
  17. 42
      dwm/transient.c
  18. 35
      dwm/util.c
  19. 8
      dwm/util.h

1
.gitignore

@ -0,0 +1 @@
*.o

55
dstat-0.7/Makefile

@ -0,0 +1,55 @@
# $Id: Makefile 44 2020-04-19 21:24:36Z umaxx $
# Copyright (c) 2016-2020 Joerg Jung <mail@umaxx.net>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
CC?=gcc
INSTALL?=install
RM?=rm -f
PREFIX?=/usr/local
BINDIR?=$(PREFIX)/bin
INCDIR?=$(PREFIX)/include
LIBDIR?=$(PREFIX)/lib
MANDIR?=$(PREFIX)/man
CFLAGS?=-Os
CFLAGS+=-ansi -pedantic -Wall -Wextra
CFLAGS+=-Isrc -I/usr/include -I$(INCDIR) -I/usr/X11R6/include
LDFLAGS+=-L/usr/lib -L$(LIBDIR) -L/usr/X11R6/lib
LIBS+=-lX11 -lsndio -lutil
OBJECTS=dstat.o
all: dstat
.c.o:
$(CC) -c $(CFLAGS) -o $@ $<
dstat: $(OBJECTS)
$(CC) $(LDFLAGS) -o dstat $(OBJECTS) $(LIBS)
clean:
$(RM) $(OBJECTS) dstat dstat.core
install: dstat
$(INSTALL) -m0755 dstat $(BINDIR)
$(INSTALL) -m0444 dstat.1 $(MANDIR)/man1
uninstall:
$(RM) $(BINDIR)/dstat $(MANDIR)/man1/dstat.1
.PHONY: all clean install uninstall

29
dstat-0.7/README

@ -0,0 +1,29 @@
dstat
Documentation and description of usage, can be found in dstat(1)
manual page.
Installation Requirements
A C-compiler (for example GCC) and Make is needed to build and
install dstat. Only supported platform is OpenBSD.
Installation from Source
Extract and install dstat:
# tar xzf dstat-n.n.tar.gz
# cd dstat-n.n/
# make install
Contributions
Thanks to the following people for contributing code, documentation,
or hints:
Stefan Verhaegh
Valère Monseur
xcko
Alexandre Ratchov

174
dstat-0.7/dstat.1

@ -0,0 +1,174 @@
.\" $Id: dstat.1 44 2020-04-19 21:24:36Z umaxx $
.\" Copyright (c) 2016-2020 Joerg Jung <mail@umaxx.net>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.Dd April 19, 2020
.Dt DSTAT 1
.Os
.Sh NAME
.Nm dstat
.Nd dwm status bar statistics
.Sh SYNOPSIS
.Nm dstat
.Ar if
.Nm dstat
.Cm version
.Sh DESCRIPTION
.Nm
is a lightweight utility to set the
.Xr dwm 1
status bar text.
.Nm
displays the current network throughput for the given interface
.Ar if ,
wireless signal quality, CPU usage, performance settings, battery status,
temperature, volume settings, as well as the current date and time on the
.Xr dwm 1
status bar.
.Pp
The arguments are as follows:
.Bl -tag -width "version"
.It Ar if
Specify the interface to collect the network statistics.
.It Cm version
Print the
.Cm version
and copyright information of
.Nm
to the standard output, then exit.
.El
.Pp
.Nm
is supposed to be started with the
.Xr dwm 1
session.
.Nm
updates the statistics shown on the
.Xr dwm 1
status bar every second using the results from
.Xr ioctl 2 ,
calls as well as calls to
.Xr apm 4 ,
.Xr getifaddrs 3 ,
.Xr sndio 7 ,
.Xr sysctl 2 ,
and
.Xr time 3 .
.Nm
displays a warning window if the estimated number of minutes for the remaining
battery life drops below 10 minutes.
.Sh EXIT STATUS
.Ex -std
.Sh EXAMPLES
Run
.Nm
using the urtwn0 network interface:
.Bd -literal -offset indent
$ dstat urtwn0 &
.Ed
.Pp
Print
.Cm version
and copyright information of
.Nm
to the standard output stream and exit successfully:
.Bd -literal -offset indent
$ dstat version
.Ed
.Ss Integrations
Pipe
.Nm
output to dzen2:
.Bd -literal -offset indent
$ dstat urtwn0 | dzen2 -fn "-*-terminus-medium-*-*-*-*-*-*-*-*-*-*-*"
.Ed
.Pp
Use
.Nm
output in
.Xr i3 1
via
.Xr i3bar 1
by adding the the following lines to the configuration:
.Bd -literal -offset indent
bar {
status_command dstat trunk0
}
.Ed
.Pp
Pipe
.Nm
output to
.Xr lemonbar 1 :
.Bd -literal -offset indent
$ dstat urtwn0 | lemonbar -d -f "-*-terminus-medium-*-*-*-*-*-*-*-*-*-*-*"
.Ed
.Pp
Use
.Nm
output in right status bar of
.Xr tmux 1
by adding the following configuration commands:
.Bd -literal -offset indent
set -g status-right-length 100
set -g status-right '#(dstat trunk0)'
.Ed
.Pp
Pipe
.Nm
output to xmobar:
.Bd -literal -offset indent
$ dstat urtwn0 | \\
> xmobar -b -f "-*-terminus-medium-*-*-*-*-*-*-*-*-*-*-*" \\
> -t "%StdinReader%" -c "[Run StdinReader]"
.Ed
.Pp
.Nm
can also be used with
.Xr tint2 1
by adding an executor to the panel items within the configuration,
like in the following:
.Bd -literal -offset indent
execp = new
execp_command = /usr/local/bin/dstat trunk0
execp_interval = 0
execp_continuous = 1
panel_items = TE
.Ed
.Sh SEE ALSO
.Xr dwm 1 ,
.Xr ioctl 2 ,
.Xr sysctl 2 ,
.Xr getifaddrs 3 ,
.Xr time 3 ,
.Xr apm 4 ,
.Xr sndio 7
.Sh STANDARDS
The
.Nm
utility is not compliant with any specification.
.Pp
Where portability is paramount, do not use it.
.Sh HISTORY
The first version of the
.Nm
utility was a shell script and appeared back in May 2013.
.Sh AUTHORS
.An -nosplit
.Nm
was written by
.An Joerg Jung Aq Mt mail@umaxx.net .
.Sh CAVEATS
Displayed wireless signal quality is rather coarse grained.
.Sh HOMEPAGE
.Lk https://www.umaxx.net/

333
dstat-0.7/dstat.c

@ -0,0 +1,333 @@
/* $Id: dstat.c 44 2020-04-19 21:24:36Z umaxx $
* Copyright (c) 2016-2020 Joerg Jung <jung@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <ifaddrs.h>
#include <limits.h>
#include <poll.h>
#include <sndio.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/param.h>
#include <sys/sched.h>
#include <sys/resource.h>
#include <sys/sensors.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <net/if.h>
#include <net/if_media.h>
#include <net80211/ieee80211.h>
#include <net80211/ieee80211_ioctl.h>
#include <machine/apmvar.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xos.h>
#include <X11/Xutil.h>
#include <util.h>
#define D_V "0.7"
#define D_YR "2015-2020"
#define D_BUF 64
#define d_max(a,b) (MAX(a,b))
#define d_warn(s) (warn(s), s)
static const char *d_bar(unsigned char p) {
const char *s[] = { "", "", "", "", "", "", "", "", "" };
return s[((8 * p) / 100)];
}
static const char *d_dots(unsigned char q) {
const char *s[] = { " ", " .", "..", ".:", "::" };
return s[((4 * q) / 100)];
}
static char *d_fmt(char *s, size_t sz, const char *fmt, ...) {
va_list va;
int r;
va_start(va, fmt), r = vsnprintf(s, sz, fmt, va), va_end(va);
if (r < 0 || (size_t)r >= sz)
return d_warn("vsnprintf failed");
return s;
}
static char *d_wifi(const char *ifn) {
static char s[D_BUF];
struct ieee80211_bssid bssid;
struct ieee80211_nodereq nr;
int fd, q;
memset(&bssid, 0, sizeof(bssid)), memset(&nr, 0, sizeof(nr));
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
return d_warn("socket failed");
d_fmt(bssid.i_name, sizeof(bssid.i_name), "%s", ifn);
if ((ioctl(fd, SIOCG80211BSSID, &bssid)) == -1)
return close(fd), (errno == ENOTTY ? "" : d_warn("ioctl failed"));
d_fmt(nr.nr_ifname, sizeof(nr.nr_ifname), "%s", ifn);
memmove(&nr.nr_macaddr, bssid.i_bssid, sizeof(nr.nr_macaddr));
if ((ioctl(fd, SIOCG80211NODE, &nr)) == -1 && nr.nr_rssi)
return close(fd), d_warn("ioctl failed");
if (nr.nr_max_rssi)
q = IEEE80211_NODEREQ_RSSI(&nr);
else
q = nr.nr_rssi >= -50 ? 100 : (nr.nr_rssi <= -100 ? 0 :
(2 * (nr.nr_rssi + 100)));
return close(fd), d_fmt(s, sizeof(s), "[%s]", d_dots(q));
}
static char *d_net(const char *ifn) {
static char s[D_BUF];
static uint64_t in, out;
struct ifaddrs *ifas, *ifa;
struct if_data *ifd;
uint64_t ib = 0, ob = 0;
char is[FMT_SCALED_STRSIZE], os[FMT_SCALED_STRSIZE], f = 0, *w;
if (getifaddrs(&ifas) == -1)
return d_warn("getifaddrs failed");
for (ifa = ifas; ifa; ifa = ifa->ifa_next)
if (!strcmp(ifa->ifa_name, ifn) &&
(ifd = (struct if_data *)ifa->ifa_data))
ib += ifd->ifi_ibytes, ob += ifd->ifi_obytes, f = 1;
freeifaddrs(ifas);
if (!f)
return "interface failed";
if (fmt_scaled(in ? ib - in : 0, is) == -1 ||
fmt_scaled(out ? ob - out : 0, os) == -1)
return d_warn("fmt_scaled failed");
return (in = ib, out = ob, w = d_wifi(ifn), strlen(w) ?
d_fmt(s, sizeof(s), "↑ %s/s ↓ %s/s %s", os, is, w) :
d_fmt(s, sizeof(s), "↑ %s/s ↓ %s/s", os, is));
}
static char *d_perf(void) {
static char s[D_BUF];
int mib[2] = { CTL_HW, HW_CPUSPEED }, frq, p;
size_t sz = sizeof(frq);
if (sysctl(mib, 2, &frq, &sz, NULL, 0) == -1)
return d_warn("sysctl failed");
mib[1] = HW_SETPERF, sz = sizeof(p);
if (sysctl(mib, 2, &p, &sz, NULL, 0) == -1)
return d_warn("sysctl failed");
return d_fmt(s, sizeof(s), "%0.1fGHz [%d%%]", frq / (double)1000, p);
}
static char *d_cpu(void) {
static char s[D_BUF];
static long cpu[CPUSTATES];
int mib[2] = { CTL_KERN, KERN_CPTIME }, p;
long c[CPUSTATES];
size_t sz = sizeof(c);
if (sysctl(mib, 2, &c, &sz, NULL, 0) == -1)
return d_warn("sysctl failed");
p = (c[CP_USER] - cpu[CP_USER] + c[CP_SYS] - cpu[CP_SYS] +
c[CP_NICE] - cpu[CP_NICE]) / (double)
(c[CP_USER] - cpu[CP_USER] + c[CP_SYS] - cpu[CP_SYS] +
c[CP_NICE] - cpu[CP_NICE] + c[CP_IDLE] - cpu[CP_IDLE]) * 100;
memmove(cpu, c, sizeof(cpu));
return d_fmt(s, sizeof(s), "CPU %d%% %s %s", p, d_bar(p), d_perf());
}
static void d_win(Display *d, XFontStruct *f) {
const char *m = "Battery is low.", *n = "dstat";
int s = DefaultScreen(d), ww = 128, wh = 64;
Window w = XCreateSimpleWindow(d, RootWindow(d, s), DisplayWidth(d, s) / 2,
DisplayHeight(d, s) / 2, ww, wh, 1, BlackPixel(d, s), 0x202020L);
Atom ad = XInternAtom(d, "WM_DELETE_WINDOW", False),
an = XInternAtom(d, "_NET_WM_NAME", False),
ai = XInternAtom(d, "_NET_WM_ICON_NAME", False),
au = XInternAtom(d, "UTF8_STRING", False);
XGCValues gcv;
GC gc = XCreateGC(d, w, 0, &gcv);
XEvent e;
XChangeProperty(d, w, an, au, 8, 0, (unsigned char *)n, strlen(n));
XChangeProperty(d, w, ai, au, 8, 0, (unsigned char *)n, strlen(n));
XSetTransientForHint(d, w, RootWindow(d, s));
XSetWMProtocols(d , w, &ad, 1);
XSelectInput(d, w, ExposureMask);
XSetFont(d, gc, f->fid);
XSetForeground(d, gc, 0xc0c0c0L);
XMapWindow(d, w);
for (;;) {
XNextEvent(d, &e);
if (e.type == Expose)
XDrawString(d, w, gc, (ww - XTextWidth(f, m, strlen(m))) / 2,
(wh + f->ascent + f->descent) / 2, m, strlen(m));
else if (e.type == ClientMessage)
break;
}
XFreeGC(d, gc);
XDestroyWindow(d, w);
}
static char *d_bat(int fd, Display *d, XFontStruct *f) {
static char s[D_BUF], w;
struct apm_power_info api;
if (ioctl(fd, APM_IOC_GETPOWER, &api) == -1)
return d_warn("ioctl failed");
if (!w && api.ac_state != APM_AC_ON && api.minutes_left <= 10)
d_win(d, f), w = 1;
return (api.ac_state == APM_AC_ON) ? (w = 0,
d_fmt(s, sizeof(s), "⚡ %d%% %s [A/C]",
api.battery_life, d_bar(api.battery_life))) :
d_fmt(s, sizeof(s), "⚡ %d%% %s [%u:%02u]",
api.battery_life, d_bar(api.battery_life),
api.minutes_left / 60, api.minutes_left % 60);
}
static char *d_temp(void) {
static char s[D_BUF];
struct sensordev sd;
struct sensor sn;
size_t sd_sz = sizeof(sd), sn_sz = sizeof(sn);
int mib[5] = { CTL_HW, HW_SENSORS, 0, SENSOR_TEMP, 0 };
int64_t t = -1;
for (mib[2] = 0; ; mib[2]++) {
if (sysctl(mib, 3, &sd, &sd_sz, NULL, 0) == -1) {
if (errno == ENXIO)
continue;
else if (errno == ENOENT)
break;
return d_warn("sysctl failed");
}
for (mib[4] = 0; mib[4] < sd.maxnumt[SENSOR_TEMP]; mib[4]++) {
if (sysctl(mib, 5, &sn, &sn_sz, NULL, 0) == -1) {
if (errno == ENXIO)
continue;
else if (errno == ENOENT)
break;
return d_warn("sysctl failed");
}
if (sn_sz && !(sn.flags & SENSOR_FINVALID))
t = d_max(sn.value, t);
}
}
return t == -1 ? "temperature failed" :
d_fmt(s, sizeof(s), "T %.1f°C", (t - 273150000) / 1000000.0);
}
static void d_desc(void *arg, struct sioctl_desc *sd, int val) {
unsigned int (*ctls)[3] = (unsigned int(*)[3])arg;
int i;
if (!sd || strcmp(sd->group, "") || strcmp(sd->node0.name, "output"))
return;
for (i = 0; ctls[i][0] && i < D_BUF && ctls[i][0] != sd->addr; i++)
;
if (i < D_BUF && sd->type == SIOCTL_NUM && !strcmp(sd->func, "level"))
ctls[i][0] = sd->addr, ctls[i][1] = sd->maxval, ctls[i][2] = val;
else if (i < D_BUF && sd->type == SIOCTL_SW && !strcmp(sd->func, "mute"))
ctls[i][0] = sd->addr, ctls[i][1] = -1, ctls[i][2] = val;
}
static void d_val(void *arg, unsigned int addr, unsigned int val) {
unsigned int (*ctls)[3] = (unsigned int(*)[3])arg;
int i;
for (i = 0; ctls[i][0] && i < D_BUF && ctls[i][0] != addr; i++)
;
if (ctls[i][0] == addr)
ctls[i][2] = val;
}
static char *d_vol(struct sioctl_hdl *h, unsigned int (*ctls)[3]) {
static char s[D_BUF];
static struct pollfd pfds[D_BUF];
int n, i, v;
if (sioctl_nfds(h) <= D_BUF && (n = sioctl_pollfd(h, pfds, 0)) > 0 &&
poll(pfds, n, 0) > 0)
sioctl_revents(h, pfds);
for (i = 0, v = 0; ctls[i][0] && i < D_BUF && v != -1; i++)
v = ctls[i][1] == (unsigned int)-1 && ctls[i][2] == 1 ? -1 :
d_max((int)(ctls[i][2] * 100 / ctls[i][1]), v);
return v == -1 ? "♫ mute" : d_fmt(s, sizeof(s), "♫ %d%% %s", v, d_bar(v));
}
static char *d_time(void) {
static char s[D_BUF];
struct tm *tm;
time_t ts;
if ((ts = time(NULL)) == ((time_t) - 1))
return d_warn("time failed");
if (!(tm = localtime(&ts)))
return d_warn("localtime failed");
if (!strftime(s, sizeof(s), "%H:%M", tm))
return d_warn("strftime failed");
return s;
}
static void d_run(const char *ifn) {
Display *d;
XFontStruct *f;
struct sioctl_hdl *h;
unsigned int ctls[D_BUF][3] = { { 0 } };
int a = -1;
char s[LINE_MAX];
if (!(d = XOpenDisplay(NULL)))
err(1, "XOpenDisplay failed");
if (!(f = XLoadQueryFont(d, "-*-terminus-medium-*")) &&
!(f = XLoadQueryFont(d, "fixed")))
err(1, "XLoadQueryFont failed");
if (!(h = sioctl_open(SIO_DEVANY, SIOCTL_READ, 0)) ||
!sioctl_ondesc(h, d_desc, ctls) || !sioctl_onval(h, d_val, ctls))
errx(1, "sioctl failed");
if ((a = open("/dev/apm", O_RDONLY)) == -1)
err(1, "open failed");
for (;;) {
XStoreName(d, DefaultRootWindow(d),
d_fmt(s, sizeof(s), "%s %s %s %s %s",
d_net(ifn), d_cpu(),
d_temp(), d_vol(h, ctls), d_time()));
printf("%s\n", s);
XSync(d, False), sleep(1);
}
close(a);
sioctl_close(h);
XUnloadFont(d, f->fid);
XCloseDisplay(d);
}
int main(int argc, char *argv[]) {
if (argc == 2 && !strcmp(argv[1], "version")) {
puts("dstat "D_V" (c) "D_YR" Joerg Jung");
return 0;
}
if (argc != 2)
errx(1, "usage: dstat <if>\n%14sdstat version", "");
if (setpriority(PRIO_PROCESS, getpid(), 10))
err(1, "setpriority failed");
if (setvbuf(stdout, NULL, _IONBF, 0)) /* unbuffered pipe output to others */
err(1, "setvbuf failed");
d_run(argv[1]);
return 0;
}

37
dwm/LICENSE

@ -0,0 +1,37 @@
MIT/X Consortium License
© 2006-2019 Anselm R Garbe <anselm@garbe.ca>
© 2006-2009 Jukka Salmi <jukka at salmi dot ch>
© 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
© 2007-2011 Peter Hartlich <sgkkr at hartlich dot com>
© 2007-2009 Szabolcs Nagy <nszabolcs at gmail dot com>
© 2007-2009 Christof Musik <christof at sendfax dot de>
© 2007-2009 Premysl Hruby <dfenze at gmail dot com>
© 2007-2008 Enno Gottox Boland <gottox at s01 dot de>
© 2008 Martin Hurton <martin dot hurton at gmail dot com>
© 2008 Neale Pickett <neale dot woozle dot org>
© 2009 Mate Nagy <mnagy at port70 dot net>
© 2010-2016 Hiltjo Posthuma <hiltjo@codemadness.org>
© 2010-2012 Connor Lane Smith <cls@lubutu.com>
© 2011 Christoph Lohmann <20h@r-36.net>
© 2015-2016 Quentin Rameau <quinq@fifth.space>
© 2015-2016 Eric Pruitt <eric.pruitt@gmail.com>
© 2016-2017 Markus Teich <markus.teich@stusta.mhn.de>
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.

51
dwm/Makefile

@ -0,0 +1,51 @@
# dwm - dynamic window manager
# See LICENSE file for copyright and license details.
include config.mk
SRC = drw.c dwm.c util.c
OBJ = ${SRC:.c=.o}
all: options dwm
options:
@echo dwm build options:
@echo "CFLAGS = ${CFLAGS}"
@echo "LDFLAGS = ${LDFLAGS}"
@echo "CC = ${CC}"
.c.o:
${CC} -c ${CFLAGS} $<
${OBJ}: config.h config.mk
config.h:
cp config.def.h $@
dwm: ${OBJ}
${CC} -o $@ ${OBJ} ${LDFLAGS}
clean:
rm -f dwm ${OBJ} dwm-${VERSION}.tar.gz
dist: clean
mkdir -p dwm-${VERSION}
cp -R LICENSE Makefile README config.def.h config.mk\
dwm.1 drw.h util.h ${SRC} dwm.png transient.c dwm-${VERSION}
tar -cf dwm-${VERSION}.tar dwm-${VERSION}
gzip dwm-${VERSION}.tar
rm -rf dwm-${VERSION}
install: all
mkdir -p ${DESTDIR}${PREFIX}/bin
cp -f dwm ${DESTDIR}${PREFIX}/bin
chmod 755 ${DESTDIR}${PREFIX}/bin/dwm
mkdir -p ${DESTDIR}${MANPREFIX}/man1
sed "s/VERSION/${VERSION}/g" < dwm.1 > ${DESTDIR}${MANPREFIX}/man1/dwm.1
chmod 644 ${DESTDIR}${MANPREFIX}/man1/dwm.1
uninstall:
rm -f ${DESTDIR}${PREFIX}/bin/dwm\
${DESTDIR}${MANPREFIX}/man1/dwm.1
.PHONY: all options clean dist install uninstall

48
dwm/README

@ -0,0 +1,48 @@
dwm - dynamic window manager
============================
dwm is an extremely fast, small, and dynamic window manager for X.
Requirements
------------
In order to build dwm you need the Xlib header files.
Installation
------------
Edit config.mk to match your local setup (dwm is installed into
the /usr/local namespace by default).
Afterwards enter the following command to build and install dwm (if
necessary as root):
make clean install
Running dwm
-----------
Add the following line to your .xinitrc to start dwm using startx:
exec dwm
In order to connect dwm to a specific display, make sure that
the DISPLAY environment variable is set correctly, e.g.:
DISPLAY=foo.bar:1 exec dwm
(This will start dwm on display :1 of the host foo.bar.)
In order to display status info in the bar, you can do something
like this in your .xinitrc:
while xsetroot -name "`date` `uptime | sed 's/.*,//'`"
do
sleep 1
done &
exec dwm
Configuration
-------------
The configuration of dwm is done by creating a custom config.h
and (re)compiling the source code.

115
dwm/config.def.h

@ -0,0 +1,115 @@
/* See LICENSE file for copyright and license details. */
/* appearance */
static const unsigned int borderpx = 1; /* border pixel of windows */
static const unsigned int snap = 32; /* snap pixel */
static const int showbar = 1; /* 0 means no bar */
static const int topbar = 1; /* 0 means bottom bar */
static const char *fonts[] = { "monospace:size=10" };
static const char dmenufont[] = "monospace:size=10";
static const char col_gray1[] = "#222222";
static const char col_gray2[] = "#444444";
static const char col_gray3[] = "#bbbbbb";
static const char col_gray4[] = "#eeeeee";
static const char col_cyan[] = "#005577";
static const char *colors[][3] = {
/* fg bg border */
[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
[SchemeSel] = { col_gray4, col_cyan, col_cyan },
};
/* tagging */
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
static const Rule rules[] = {
/* xprop(1):
* WM_CLASS(STRING) = instance, class
* WM_NAME(STRING) = title
*/
/* class instance title tags mask isfloating monitor */
{ "Gimp", NULL, NULL, 0, 1, -1 },
{ "Firefox", NULL, NULL, 1 << 8, 0, -1 },
};
/* layout(s) */
static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
static const int nmaster = 1; /* number of clients in master area */
static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
static const Layout layouts[] = {
/* symbol arrange function */
{ "[]=", tile }, /* first entry is default */
{ "><>", NULL }, /* no layout function means floating behavior */
{ "[M]", monocle },
};
/* key definitions */
#define MODKEY Mod1Mask
#define TAGKEYS(KEY,TAG) \
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \
{ MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
{ MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \
{ MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} },
/* helper for spawning shell commands in the pre dwm-5.0 fashion */
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
/* commands */
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char *termcmd[] = { "st", NULL };
static Key keys[] = {
/* modifier key function argument */
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
{ MODKEY, XK_b, togglebar, {0} },
{ MODKEY, XK_j, focusstack, {.i = +1 } },
{ MODKEY, XK_k, focusstack, {.i = -1 } },
{ MODKEY, XK_i, incnmaster, {.i = +1 } },
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
{ MODKEY, XK_Return, zoom, {0} },
{ MODKEY, XK_Tab, view, {0} },
{ MODKEY|ShiftMask, XK_c, killclient, {0} },
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
{ MODKEY, XK_space, setlayout, {0} },
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
{ MODKEY, XK_0, view, {.ui = ~0 } },
{ MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
{ MODKEY, XK_comma, focusmon, {.i = -1 } },
{ MODKEY, XK_period, focusmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
TAGKEYS( XK_1, 0)
TAGKEYS( XK_2, 1)
TAGKEYS( XK_3, 2)
TAGKEYS( XK_4, 3)
TAGKEYS( XK_5, 4)
TAGKEYS( XK_6, 5)
TAGKEYS( XK_7, 6)
TAGKEYS( XK_8, 7)
TAGKEYS( XK_9, 8)
{ MODKEY|ShiftMask, XK_q, quit, {0} },
};
/* button definitions */
/* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
static Button buttons[] = {
/* click event mask button function argument */
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
{ ClkWinTitle, 0, Button2, zoom, {0} },
{ ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
{ ClkClientWin, MODKEY, Button2, togglefloating, {0} },
{ ClkClientWin, MODKEY, Button3, resizemouse, {0} },
{ ClkTagBar, 0, Button1, view, {0} },
{ ClkTagBar, 0, Button3, toggleview, {0} },
{ ClkTagBar, MODKEY, Button1, tag, {0} },
{ ClkTagBar, MODKEY, Button3, toggletag, {0} },
};

115
dwm/config.h

@ -0,0 +1,115 @@
/* See LICENSE file for copyright and license details. */
/* appearance */
static const unsigned int borderpx = 1; /* border pixel of windows */
static const unsigned int snap = 32; /* snap pixel */
static const int showbar = 1; /* 0 means no bar */
static const int topbar = 1; /* 0 means bottom bar */
static const char *fonts[] = { "monospace:size=10" };
static const char dmenufont[] = "monospace:size=10";
static const char col_gray1[] = "#222222";
static const char col_gray2[] = "#444444";
static const char col_gray3[] = "#bbbbbb";
static const char col_gray4[] = "#eeeeee";
static const char col_cyan[] = "#005577";
static const char *colors[][3] = {
/* fg bg border */
[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
[SchemeSel] = { col_gray4, col_cyan, col_cyan },
};
/* tagging */
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
static const Rule rules[] = {
/* xprop(1):
* WM_CLASS(STRING) = instance, class
* WM_NAME(STRING) = title
*/
/* class instance title tags mask isfloating monitor */
{ "Gimp", NULL, NULL, 0, 1, -1 },
{ "Firefox", NULL, NULL, 1 << 8, 0, -1 },
};
/* layout(s) */
static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
static const int nmaster = 1; /* number of clients in master area */
static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
static const Layout layouts[] = {
/* symbol arrange function */
{ "[]=", tile }, /* first entry is default */
{ "><>", NULL }, /* no layout function means floating behavior */
{ "[M]", monocle },
};
/* key definitions */
#define MODKEY Mod1Mask
#define TAGKEYS(KEY,TAG) \
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \
{ MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
{ MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \
{ MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} },
/* helper for spawning shell commands in the pre dwm-5.0 fashion */
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
/* commands */
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char *termcmd[] = { "st", NULL };
static Key keys[] = {
/* modifier key function argument */
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
{ MODKEY, XK_b, togglebar, {0} },
{ MODKEY, XK_j, focusstack, {.i = +1 } },
{ MODKEY, XK_k, focusstack, {.i = -1 } },
{ MODKEY, XK_i, incnmaster, {.i = +1 } },
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
{ MODKEY, XK_Return, zoom, {0} },
{ MODKEY, XK_Tab, view, {0} },
{ MODKEY|ShiftMask, XK_c, killclient, {0} },
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
{ MODKEY, XK_space, setlayout, {0} },
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
{ MODKEY, XK_0, view, {.ui = ~0 } },
{ MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
{ MODKEY, XK_comma, focusmon, {.i = -1 } },
{ MODKEY, XK_period, focusmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
TAGKEYS( XK_1, 0)
TAGKEYS( XK_2, 1)
TAGKEYS( XK_3, 2)
TAGKEYS( XK_4, 3)
TAGKEYS( XK_5, 4)
TAGKEYS( XK_6, 5)
TAGKEYS( XK_7, 6)
TAGKEYS( XK_8, 7)
TAGKEYS( XK_9, 8)
{ MODKEY|ShiftMask, XK_q, quit, {0} },
};
/* button definitions */
/* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
static Button buttons[] = {
/* click event mask button function argument */
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
{ ClkWinTitle, 0, Button2, zoom, {0} },
{ ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
{ ClkClientWin, MODKEY, Button2, togglefloating, {0} },
{ ClkClientWin, MODKEY, Button3, resizemouse, {0} },
{ ClkTagBar, 0, Button1, view, {0} },
{ ClkTagBar, 0, Button3, toggleview, {0} },
{ ClkTagBar, MODKEY, Button1, tag, {0} },
{ ClkTagBar, MODKEY, Button3, toggletag, {0} },
};

38
dwm/config.mk

@ -0,0 +1,38 @@
# dwm version
VERSION = 6.2
# Customize below to fit your system
# paths
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man
X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib
# Xinerama, comment if you don't want it
XINERAMALIBS = -lXinerama
XINERAMAFLAGS = -DXINERAMA
# freetype
FREETYPELIBS = -lfontconfig -lXft
FREETYPEINC = /usr/include/freetype2
# OpenBSD (uncomment)
#FREETYPEINC = ${X11INC}/freetype2
# includes and libs
INCS = -I${X11INC} -I${FREETYPEINC}
LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS}
# flags
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
#CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os ${INCS} ${CPPFLAGS}
LDFLAGS = ${LIBS}
# Solaris
#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
#LDFLAGS = ${LIBS}
# compiler and linker
CC = cc

436
dwm/drw.c

@ -0,0 +1,436 @@
/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xft/Xft.h>
#include "drw.h"
#include "util.h"
#define UTF_INVALID 0xFFFD
#define UTF_SIZ 4
static const unsigned char utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0};
static const unsigned char utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8};
static const long utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000};
static const long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF};
static long
utf8decodebyte(const char c, size_t *i)
{
for (*i = 0; *i < (UTF_SIZ + 1); ++(*i))
if (((unsigned char)c & utfmask[*i]) == utfbyte[*i])
return (unsigned char)c & ~utfmask[*i];
return 0;
}
static size_t
utf8validate(long *u, size_t i)
{
if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF))
*u = UTF_INVALID;
for (i = 1; *u > utfmax[i]; ++i)
;
return i;
}
static size_t
utf8decode(const char *c, long *u, size_t clen)
{
size_t i, j, len, type;
long udecoded;
*u = UTF_INVALID;
if (!clen)
return 0;
udecoded = utf8decodebyte(c[0], &len);
if (!BETWEEN(len, 1, UTF_SIZ))
return 1;
for (i = 1, j = 1; i < clen && j < len; ++i, ++j) {
udecoded = (udecoded << 6) | utf8decodebyte(c[i], &type);
if (type)
return j;
}
if (j < len)
return 0;
*u = udecoded;
utf8validate(u, len);
return len;
}
Drw *
drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h)
{
Drw *drw = ecalloc(1, sizeof(Drw));
drw->dpy = dpy;
drw->screen = screen;
drw->root = root;
drw->w = w;
drw->h = h;
drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen));
drw->gc = XCreateGC(dpy, root, 0, NULL);
XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
return drw;
}
void
drw_resize(Drw *drw, unsigned int w, unsigned int h)
{
if (!drw)
return;
drw->w = w;
drw->h = h;
if (drw->drawable)
XFreePixmap(drw->dpy, drw->drawable);
drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen));
}
void
drw_free(Drw *drw)
{
XFreePixmap(drw->dpy, drw->drawable);
XFreeGC(drw->dpy, drw->gc);
drw_fontset_free(drw->fonts);
free(drw);
}
/* This function is an implementation detail. Library users should use
* drw_fontset_create instead.
*/
static Fnt *
xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern)
{
Fnt *font;
XftFont *xfont = NULL;
FcPattern *pattern = NULL;
if (fontname) {
/* Using the pattern found at font->xfont->pattern does not yield the
* same substitution results as using the pattern returned by
* FcNameParse; using the latter results in the desired fallback
* behaviour whereas the former just results in missing-character
* rectangles being drawn, at least with some fonts. */
if (!(xfont = XftFontOpenName(drw->dpy, drw->screen, fontname))) {
fprintf(stderr, "error, cannot load font from name: '%s'\n", fontname);
return NULL;
}
if (!(pattern = FcNameParse((FcChar8 *) fontname))) {
fprintf(stderr, "error, cannot parse font name to pattern: '%s'\n", fontname);
XftFontClose(drw->dpy, xfont);
return NULL;
}
} else if (fontpattern) {
if (!(xfont = XftFontOpenPattern(drw->dpy, fontpattern))) {
fprintf(stderr, "error, cannot load font from pattern.\n");
return NULL;
}
} else {
die("no font specified.");
}
/* Do not allow using color fonts. This is a workaround for a BadLength
* error from Xft with color glyphs. Modelled on the Xterm workaround. See
* https://bugzilla.redhat.com/show_bug.cgi?id=1498269
* https://lists.suckless.org/dev/1701/30932.html
* https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=916349
* and lots more all over the internet.
*/
FcBool iscol;
if(FcPatternGetBool(xfont->pattern, FC_COLOR, 0, &iscol) == FcResultMatch && iscol) {
XftFontClose(drw->dpy, xfont);
return NULL;
}
font = ecalloc(1, sizeof(Fnt));
font->xfont = xfont;
font->pattern = pattern;
font->h = xfont->ascent + xfont->descent;
font->dpy = drw->dpy;
return font;
}
static void
xfont_free(Fnt *font)
{
if (!font)
return;
if (font->pattern)
FcPatternDestroy(font->pattern);
XftFontClose(font->dpy, font->xfont);
free(font);
}
Fnt*
drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount)
{
Fnt *cur, *ret = NULL;
size_t i;
if (!drw || !fonts)
return NULL;
for (i = 1; i <= fontcount; i++) {
if ((cur = xfont_create(drw, fonts[fontcount - i], NULL))) {
cur->next = ret;
ret = cur;
}
}
return (drw->fonts = ret);
}
void
drw_fontset_free(Fnt *font)
{
if (font) {
drw_fontset_free(font->next);
xfont_free(font);
}
}
void
drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
{
if (!drw || !dest || !clrname)
return;
if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
DefaultColormap(drw->dpy, drw->screen),
clrname, dest))
die("error, cannot allocate color '%s'", clrname);
}
/* Wrapper to create color schemes. The caller has to call free(3) on the
* returned color scheme when done using it. */
Clr *
drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
{
size_t i;
Clr *ret;
/* need at least two colors for a scheme */
if (!drw || !clrnames || clrcount < 2 || !(ret = ecalloc(clrcount, sizeof(XftColor))))
return NULL;
for (i = 0; i < clrcount; i++)
drw_clr_create(drw, &ret[i], clrnames[i]);
return ret;
}
void
drw_setfontset(Drw *drw, Fnt *set)
{
if (drw)
drw->fonts = set;
}
void
drw_setscheme(Drw *drw, Clr *scm)
{
if (drw)
drw->scheme = scm;
}
void
drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert)
{
if (!drw || !drw->scheme)
return;
XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme[ColBg].pixel : drw->scheme[ColFg].pixel);
if (filled)
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
else
XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w - 1, h - 1);
}
int
drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert)
{
char buf[1024];
int ty;
unsigned int ew;
XftDraw *d = NULL;
Fnt *usedfont, *curfont, *nextfont;
size_t i, len;
int utf8strlen, utf8charlen, render = x || y || w || h;
long utf8codepoint = 0;
const char *utf8str;
FcCharSet *fccharset;
FcPattern *fcpattern;
FcPattern *match;
XftResult result;
int charexists = 0;
if (!drw || (render && !drw->scheme) || !text || !drw->fonts)
return 0;
if (!render) {
w = ~w;
} else {
XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel);
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
d = XftDrawCreate(drw->dpy, drw->drawable,
DefaultVisual(drw->dpy, drw->screen),
DefaultColormap(drw->dpy, drw->screen));
x += lpad;
w -= lpad;
}
usedfont = drw->fonts;
while (1) {
utf8strlen = 0;
utf8str = text;
nextfont = NULL;
while (*text) {
utf8charlen = utf8decode(text, &utf8codepoint, UTF_SIZ);
for (curfont = drw->fonts; curfont; curfont = curfont->next) {
charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint);
if (charexists) {
if (curfont == usedfont) {
utf8strlen += utf8charlen;
text += utf8charlen;
} else {
nextfont = curfont;
}
break;
}
}
if (!charexists || nextfont)
break;
else
charexists = 0;
}
if (utf8strlen) {
drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL);
/* shorten text if necessary */
for (len = MIN(utf8strlen, sizeof(buf) - 1); len && ew > w; len--)
drw_font_getexts(usedfont, utf8str, len, &ew, NULL);
if (len) {
memcpy(buf, utf8str, len);
buf[len] = '\0';
if (len < utf8strlen)
for (i = len; i && i > len - 3; buf[--i] = '.')
; /* NOP */
if (render) {
ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent;
XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg],
usedfont->xfont, x, ty, (XftChar8 *)buf, len);
}
x += ew;
w -= ew;
}
}
if (!*text) {
break;
} else if (nextfont) {
charexists = 0;
usedfont = nextfont;
} else {
/* Regardless of whether or not a fallback font is found, the
* character must be drawn. */
charexists = 1;
fccharset = FcCharSetCreate();
FcCharSetAddChar(fccharset, utf8codepoint);
if (!drw->fonts->pattern) {
/* Refer to the comment in xfont_create for more information. */
die("the first font in the cache must be loaded from a font string.");
}
fcpattern = FcPatternDuplicate(drw->fonts->pattern);
FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset);
FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue);
FcPatternAddBool(fcpattern, FC_COLOR, FcFalse);
FcConfigSubstitute(NULL, fcpattern, FcMatchPattern);
FcDefaultSubstitute(fcpattern);
match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result);
FcCharSetDestroy(fccharset);
FcPatternDestroy(fcpattern);
if (match) {
usedfont = xfont_create(drw, NULL, match);
if (usedfont && XftCharExists(drw->dpy, usedfont->xfont, utf8codepoint)) {
for (curfont = drw->fonts; curfont->next; curfont = curfont->next)
; /* NOP */
curfont->next = usedfont;
} else {
xfont_free(usedfont);
usedfont = drw->fonts;
}
}
}
}
if (d)
XftDrawDestroy(d);
return x + (render ? w : 0);
}
void
drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h)
{
if (!drw)
return;
XCopyArea(drw->dpy, drw->drawable, win, drw->gc, x, y, w, h, x, y);
XSync(drw->dpy, False);
}
unsigned int
drw_fontset_getwidth(Drw *drw, const char *text)
{
if (!drw || !drw->fonts || !text)
return 0;
return drw_text(drw, 0, 0, 0, 0, 0, text, 0);
}
void
drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h)
{
XGlyphInfo ext;
if (!font || !text)
return;
XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext);
if (w)
*w = ext.xOff;
if (h)
*h = font->h;
}
Cur *
drw_cur_create(Drw *drw, int shape)
{
Cur *cur;
if (!drw || !(cur = ecalloc(1, sizeof(Cur))))
return NULL;
cur->cursor = XCreateFontCursor(drw->dpy, shape);
return cur;
}
void
drw_cur_free(Drw *drw, Cur *cursor)
{
if (!cursor)
return;
XFreeCursor(drw->dpy, cursor->cursor);
free(cursor);
}

57
dwm/drw.h

@ -0,0 +1,57 @@
/* See LICENSE file for copyright and license details. */
typedef struct {
Cursor cursor;
} Cur;
typedef struct Fnt {
Display *dpy;
unsigned int h;
XftFont *xfont;
FcPattern *pattern;
struct Fnt *next;
} Fnt;
enum { ColFg, ColBg, ColBorder }; /* Clr scheme index */
typedef XftColor Clr;
typedef struct {
unsigned int w, h;
Display *dpy;
int screen;
Window root;
Drawable drawable;
GC gc;
Clr *scheme;
Fnt *fonts;
} Drw;
/* Drawable abstraction */
Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h);
void drw_resize(Drw *drw, unsigned int w, unsigned int h);
void drw_free(Drw *drw);
/* Fnt abstraction */
Fnt *drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount);
void drw_fontset_free(Fnt* set);
unsigned int drw_fontset_getwidth(Drw *drw, const char *text);
void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h);
/* Colorscheme abstraction */
void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
/* Cursor abstraction */
Cur *drw_cur_create(Drw *drw, int shape);
void drw_cur_free(Drw *drw, Cur *cursor);
/* Drawing context manipulation */
void drw_setfontset(Drw *drw, Fnt *set);
void drw_setscheme(Drw *drw, Clr *scm);
/* Drawing functions */
void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert);
int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert);
/* Map functions */
void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h);

176
dwm/dwm.1

@ -0,0 +1,176 @@
.TH DWM 1 dwm\-VERSION
.SH NAME
dwm \- dynamic window manager
.SH SYNOPSIS
.B dwm
.RB [ \-v ]
.SH DESCRIPTION
dwm is a dynamic window manager for X. It manages windows in tiled, monocle
and floating layouts. Either layout can be applied dynamically, optimising the
environment for the application in use and the task performed.
.P
In tiled layouts windows are managed in a master and stacking area. The master
area on the left contains one window by default, and the stacking area on the
right contains all other windows. The number of master area windows can be
adjusted from zero to an arbitrary number. In monocle layout all windows are
maximised to the screen size. In floating layout windows can be resized and
moved freely. Dialog windows are always managed floating, regardless of the
layout applied.
.P
Windows are grouped by tags. Each window can be tagged with one or multiple
tags. Selecting certain tags displays all windows with these tags.
.P
Each screen contains a small status bar which displays all available tags, the
layout, the title of the focused window, and the text read from the root window
name property, if the screen is focused. A floating window is indicated with an
empty square and a maximised floating window is indicated with a filled square
before the windows title. The selected tags are indicated with a different
color. The tags of the focused window are indicated with a filled square in the