mirror of
git://git.suckless.org/dwm
synced 2025-04-19 19:14:47 +01:00
Compare commits
82 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
cfb8627a80 | ||
|
fcb2476b69 | ||
|
8933ebcf50 | ||
|
5687f46964 | ||
|
061e9fe9a7 | ||
|
9f8855343c | ||
|
e81f17d4c1 | ||
|
348f6559ab | ||
|
712d6639ff | ||
|
89f9905714 | ||
|
ba56fe9fea | ||
|
50ad171eea | ||
|
970f376973 | ||
|
c2b748e793 | ||
|
84d7322113 | ||
|
5799dd1fca | ||
|
44adafe006 | ||
|
a859676ead | ||
|
e0dee91145 | ||
|
5e76e7e21d | ||
|
5b2e5e7a40 | ||
|
786f6e2a6f | ||
|
e03248a4d5 | ||
|
6613d9f9a1 | ||
|
9bffa845fa | ||
|
d3f93c7c1a | ||
|
cd0773cee9 | ||
|
8b48e30973 | ||
|
a83dc20310 | ||
|
a4771de5ba | ||
|
d93ff48803 | ||
|
8806b6e237 | ||
|
bece862a0f | ||
|
60e9a14998 | ||
|
d39e2f3441 | ||
|
8657affa2a | ||
|
a786211d6c | ||
|
716233534b | ||
|
138b405f0c | ||
|
67d76bdc68 | ||
|
61bb8b2241 | ||
|
bb2e7222ba | ||
|
f04cac6d6e | ||
|
f09418bbb6 | ||
|
ed3ab6b4fc | ||
|
f087d20e6e | ||
|
a8e9513783 | ||
|
c82db690cc | ||
|
cb3f58ad06 | ||
|
b69c870a30 | ||
|
e78b4a9207 | ||
|
3cd4023fb3 | ||
|
f40f86fa87 | ||
|
c3a2e016bb | ||
|
c8e9479186 | ||
|
10dfa65860 | ||
|
3bd8466e93 | ||
|
76c8c16d79 | ||
|
3cb34830eb | ||
|
db2236001c | ||
|
3756f7f6b8 | ||
|
99f78fa553 | ||
|
a9b6a312a7 | ||
|
6aa8e37efe | ||
|
ceac8c91ff | ||
|
5b238c8dab | ||
|
022d076054 | ||
|
2952b68db8 | ||
|
bb3bd6fec3 | ||
|
e63bf22948 | ||
|
5376947571 | ||
|
975c898376 | ||
|
a137a86a23 | ||
|
839c7f6939 | ||
|
7a59cd1457 | ||
|
24849acada | ||
|
ab9571bbc5 | ||
|
56a31dc4a7 | ||
|
7af4d439bd | ||
|
cd2d7549b3 | ||
|
3465bed290 | ||
|
4ec3a673ff |
44
BUGS
44
BUGS
@ -1,44 +0,0 @@
|
||||
---
|
||||
|
||||
18:17 < Biolunar> when i change my resolution in dwm (to a smaller one) and then back to the native, the top bar is not repainted. that's since 5.7.2, in 5.6 it worked fine
|
||||
18:19 < Biolunar> is it just happening to me or a (known) bug?
|
||||
18:24 < Biolunar> and in addition, mplayers fullscreen is limited to the small resolution after i changed it back to the native
|
||||
|
||||
reproducible with xrandr -s but not with --output and --mode, strange
|
||||
|
||||
---
|
||||
|
||||
yet another corner case:
|
||||
open a terminal, focus another monitor, but without moving the mouse
|
||||
pointer there
|
||||
if there is no client on the other monitor to get the focus, then the
|
||||
terminal will be unfocused but it will accept input
|
||||
|
||||
---
|
||||
|
||||
Donald Allen reported this:
|
||||
|
||||
starting emacs from dmenu in archlinux results in missing configure of emacs, but mod1-space or mod1-shift-space fix this problem. this problem is new and did not happen in 1.6 xorg servers
|
||||
|
||||
---
|
||||
|
||||
voltaic reports this:
|
||||
|
||||
When I use two monitors, one larger in resolution than the other, the
|
||||
bar is drawn using the smaller x-dimension on both screens. I think
|
||||
what's happening is that there are two bars drawn, but the short bar
|
||||
is always on top of the long bar such that I can't see the information
|
||||
under the short bar. If I switch to the small screen, hide the short
|
||||
bar, and then switch to the large screen, the long bar is drawn
|
||||
correctly.
|
||||
|
||||
A similar problem occurs when I have started dwm on a small resolution
|
||||
monitor (laptop screen) and then I switch to a large external display.
|
||||
When I do this, the bar itself is drawn for the original smaller
|
||||
resolution, but the information to be printed on the bar is
|
||||
right-aligned for a longer bar. So what I see is a bar that has the
|
||||
right hand side of it cut-off. See attached screenshot.
|
||||
|
||||
I am using standard options for xrandr such as --output VGA1 --auto, etc.
|
||||
|
||||
---
|
19
LICENSE
19
LICENSE
@ -1,18 +1,23 @@
|
||||
MIT/X Consortium License
|
||||
|
||||
© 2006-2014 Anselm R Garbe <anselm@garbe.us>
|
||||
© 2010-2014 Hiltjo Posthuma <hiltjo@codemadness.org>
|
||||
© 2007-2011 Peter Hartlich <sgkkr at hartlich dot com>
|
||||
© 2010-2011 Connor Lane Smith <cls@lubutu.com>
|
||||
© 2006-2019 Anselm R Garbe <anselm@garbe.ca>
|
||||
© 2006-2009 Jukka Salmi <jukka at salmi dot ch>
|
||||
© 2007-2009 Premysl Hruby <dfenze at gmail dot com>
|
||||
© 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>
|
||||
© 2009 Mate Nagy <mnagy at port70 dot net>
|
||||
© 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>
|
||||
© 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
|
||||
© 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>
|
||||
© 2020-2022 Chris Down <chris@chrisdown.name>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
|
53
Makefile
53
Makefile
@ -6,55 +6,40 @@ 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}"
|
||||
all: dwm
|
||||
|
||||
.c.o:
|
||||
@echo CC $<
|
||||
@${CC} -c ${CFLAGS} $<
|
||||
${CC} -c ${CFLAGS} $<
|
||||
|
||||
${OBJ}: config.h config.mk
|
||||
|
||||
config.h:
|
||||
@echo creating $@ from config.def.h
|
||||
@cp config.def.h $@
|
||||
cp config.def.h $@
|
||||
|
||||
dwm: ${OBJ}
|
||||
@echo CC -o $@
|
||||
@${CC} -o $@ ${OBJ} ${LDFLAGS}
|
||||
${CC} -o $@ ${OBJ} ${LDFLAGS}
|
||||
|
||||
clean:
|
||||
@echo cleaning
|
||||
@rm -f dwm ${OBJ} dwm-${VERSION}.tar.gz
|
||||
rm -f dwm ${OBJ} dwm-${VERSION}.tar.gz
|
||||
|
||||
dist: clean
|
||||
@echo creating dist tarball
|
||||
@mkdir -p dwm-${VERSION}
|
||||
@cp -R LICENSE TODO BUGS Makefile README config.def.h config.mk \
|
||||
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}
|
||||
tar -cf dwm-${VERSION}.tar dwm-${VERSION}
|
||||
gzip dwm-${VERSION}.tar
|
||||
rm -rf dwm-${VERSION}
|
||||
|
||||
install: all
|
||||
@echo installing executable file to ${DESTDIR}${PREFIX}/bin
|
||||
@mkdir -p ${DESTDIR}${PREFIX}/bin
|
||||
@cp -f dwm ${DESTDIR}${PREFIX}/bin
|
||||
@chmod 755 ${DESTDIR}${PREFIX}/bin/dwm
|
||||
@echo installing manual page to ${DESTDIR}${MANPREFIX}/man1
|
||||
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
|
||||
@sed "s/VERSION/${VERSION}/g" < dwm.1 > ${DESTDIR}${MANPREFIX}/man1/dwm.1
|
||||
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/dwm.1
|
||||
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:
|
||||
@echo removing executable file from ${DESTDIR}${PREFIX}/bin
|
||||
@rm -f ${DESTDIR}${PREFIX}/bin/dwm
|
||||
@echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
|
||||
@rm -f ${DESTDIR}${MANPREFIX}/man1/dwm.1
|
||||
rm -f ${DESTDIR}${PREFIX}/bin/dwm\
|
||||
${DESTDIR}${MANPREFIX}/man1/dwm.1
|
||||
|
||||
.PHONY: all options clean dist install uninstall
|
||||
.PHONY: all clean dist install uninstall
|
||||
|
3
README
3
README
@ -18,9 +18,6 @@ necessary as root):
|
||||
|
||||
make clean install
|
||||
|
||||
If you are going to use the default bluegray color scheme it is highly
|
||||
recommended to also install the bluegray files shipped in the dextra package.
|
||||
|
||||
|
||||
Running dwm
|
||||
-----------
|
||||
|
4
TODO
4
TODO
@ -1,4 +0,0 @@
|
||||
- add a flag to Key to execute the command on release (needed for commands
|
||||
affecting the keyboard grab, see scrot -s for example)
|
||||
- add updategeom() hook for external tools like dzen
|
||||
- consider onscreenkeyboard hooks for tablet deployment
|
31
config.def.h
31
config.def.h
@ -1,20 +1,22 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
|
||||
/* appearance */
|
||||
static const char *fonts[] = {
|
||||
"monospace:size=10"
|
||||
};
|
||||
static const char dmenufont[] = "monospace:size=10";
|
||||
static const char normbordercolor[] = "#444444";
|
||||
static const char normbgcolor[] = "#222222";
|
||||
static const char normfgcolor[] = "#bbbbbb";
|
||||
static const char selbordercolor[] = "#005577";
|
||||
static const char selbgcolor[] = "#005577";
|
||||
static const char selfgcolor[] = "#eeeeee";
|
||||
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" };
|
||||
@ -33,6 +35,7 @@ static const Rule rules[] = {
|
||||
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 int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
|
||||
|
||||
static const Layout layouts[] = {
|
||||
/* symbol arrange function */
|
||||
@ -54,10 +57,10 @@ static const Layout layouts[] = {
|
||||
|
||||
/* commands */
|
||||
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
|
||||
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL };
|
||||
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[] = {
|
||||
static const Key keys[] = {
|
||||
/* modifier key function argument */
|
||||
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
|
||||
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
|
||||
@ -95,8 +98,8 @@ static Key keys[] = {
|
||||
};
|
||||
|
||||
/* button definitions */
|
||||
/* click can be ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
|
||||
static Button buttons[] = {
|
||||
/* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
|
||||
static const Button buttons[] = {
|
||||
/* click event mask button function argument */
|
||||
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
|
||||
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
|
||||
|
@ -1,5 +1,5 @@
|
||||
# dwm version
|
||||
VERSION = 6.1
|
||||
VERSION = 6.5
|
||||
|
||||
# Customize below to fit your system
|
||||
|
||||
@ -19,16 +19,17 @@ FREETYPELIBS = -lfontconfig -lXft
|
||||
FREETYPEINC = /usr/include/freetype2
|
||||
# OpenBSD (uncomment)
|
||||
#FREETYPEINC = ${X11INC}/freetype2
|
||||
#MANPREFIX = ${PREFIX}/man
|
||||
|
||||
# includes and libs
|
||||
INCS = -I${X11INC} -I${FREETYPEINC}
|
||||
LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS}
|
||||
|
||||
# flags
|
||||
CPPFLAGS = -D_BSD_SOURCE -D_POSIX_C_SOURCE=2 -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
|
||||
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
|
||||
#CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
|
||||
CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os ${INCS} ${CPPFLAGS}
|
||||
LDFLAGS = -s ${LIBS}
|
||||
LDFLAGS = ${LIBS}
|
||||
|
||||
# Solaris
|
||||
#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
|
||||
|
394
drw.c
394
drw.c
@ -9,63 +9,48 @@
|
||||
#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)
|
||||
static int
|
||||
utf8decode(const char *s_in, long *u, int *err)
|
||||
{
|
||||
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 const unsigned char lens[] = {
|
||||
/* 0XXXX */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
/* 10XXX */ 0, 0, 0, 0, 0, 0, 0, 0, /* invalid */
|
||||
/* 110XX */ 2, 2, 2, 2,
|
||||
/* 1110X */ 3, 3,
|
||||
/* 11110 */ 4,
|
||||
/* 11111 */ 0, /* invalid */
|
||||
};
|
||||
static const unsigned char leading_mask[] = { 0x7F, 0x1F, 0x0F, 0x07 };
|
||||
static const unsigned int overlong[] = { 0x0, 0x80, 0x0800, 0x10000 };
|
||||
|
||||
static size_t
|
||||
utf8validate(long *u, size_t i)
|
||||
{
|
||||
if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF))
|
||||
const unsigned char *s = (const unsigned char *)s_in;
|
||||
int len = lens[*s >> 3];
|
||||
*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))
|
||||
*err = 1;
|
||||
if (len == 0)
|
||||
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);
|
||||
|
||||
long cp = s[0] & leading_mask[len - 1];
|
||||
for (int i = 1; i < len; ++i) {
|
||||
if (s[i] == '\0' || (s[i] & 0xC0) != 0x80)
|
||||
return i;
|
||||
cp = (cp << 6) | (s[i] & 0x3F);
|
||||
}
|
||||
/* out of range, surrogate, overlong encoding */
|
||||
if (cp > 0x10FFFF || (cp >> 11) == 0x1B || cp < overlong[len - 1])
|
||||
return len;
|
||||
|
||||
*err = 0;
|
||||
*u = cp;
|
||||
return len;
|
||||
}
|
||||
|
||||
Drw *
|
||||
drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h)
|
||||
{
|
||||
Drw *drw;
|
||||
Drw *drw = ecalloc(1, sizeof(Drw));
|
||||
|
||||
drw = ecalloc(1, sizeof(Drw));
|
||||
drw->dpy = dpy;
|
||||
drw->screen = screen;
|
||||
drw->root = root;
|
||||
@ -73,7 +58,6 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h
|
||||
drw->h = h;
|
||||
drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen));
|
||||
drw->gc = XCreateGC(dpy, root, 0, NULL);
|
||||
drw->fontcount = 0;
|
||||
XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
|
||||
|
||||
return drw;
|
||||
@ -82,6 +66,9 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h
|
||||
void
|
||||
drw_resize(Drw *drw, unsigned int w, unsigned int h)
|
||||
{
|
||||
if (!drw)
|
||||
return;
|
||||
|
||||
drw->w = w;
|
||||
drw->h = h;
|
||||
if (drw->drawable)
|
||||
@ -92,84 +79,57 @@ drw_resize(Drw *drw, unsigned int w, unsigned int h)
|
||||
void
|
||||
drw_free(Drw *drw)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < drw->fontcount; i++)
|
||||
drw_font_free(drw->fonts[i]);
|
||||
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_font_create instead.
|
||||
* drw_fontset_create instead.
|
||||
*/
|
||||
static Fnt *
|
||||
drw_font_xcreate(Drw *drw, const char *fontname, FcPattern *fontpattern)
|
||||
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 same
|
||||
* the same substitution results as using the pattern returned by
|
||||
/* 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.
|
||||
*/
|
||||
* 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: '%s'\n", fontname);
|
||||
fprintf(stderr, "error, cannot load font from name: '%s'\n", fontname);
|
||||
return NULL;
|
||||
}
|
||||
if (!(pattern = FcNameParse((FcChar8 *) fontname))) {
|
||||
fprintf(stderr, "error, cannot load font: '%s'\n", 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 pattern.\n");
|
||||
fprintf(stderr, "error, cannot load font from pattern.\n");
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
die("no font specified.\n");
|
||||
die("no font specified.");
|
||||
}
|
||||
|
||||
font = ecalloc(1, sizeof(Fnt));
|
||||
font->xfont = xfont;
|
||||
font->pattern = pattern;
|
||||
font->ascent = xfont->ascent;
|
||||
font->descent = xfont->descent;
|
||||
font->h = font->ascent + font->descent;
|
||||
font->h = xfont->ascent + xfont->descent;
|
||||
font->dpy = drw->dpy;
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
Fnt*
|
||||
drw_font_create(Drw *drw, const char *fontname)
|
||||
{
|
||||
return drw_font_xcreate(drw, fontname, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
drw_load_fonts(Drw* drw, const char *fonts[], size_t fontcount)
|
||||
{
|
||||
size_t i;
|
||||
Fnt *font;
|
||||
|
||||
for (i = 0; i < fontcount; i++) {
|
||||
if (drw->fontcount >= DRW_FONT_CACHE_SIZE) {
|
||||
die("font cache exhausted.\n");
|
||||
} else if ((font = drw_font_xcreate(drw, fonts[i], NULL))) {
|
||||
drw->fonts[drw->fontcount++] = font;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
drw_font_free(Fnt *font)
|
||||
static void
|
||||
xfont_free(Fnt *font)
|
||||
{
|
||||
if (!font)
|
||||
return;
|
||||
@ -179,150 +139,218 @@ drw_font_free(Fnt *font)
|
||||
free(font);
|
||||
}
|
||||
|
||||
Clr *
|
||||
drw_clr_create(Drw *drw, const char *clrname)
|
||||
Fnt*
|
||||
drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount)
|
||||
{
|
||||
Clr *clr;
|
||||
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;
|
||||
|
||||
clr = ecalloc(1, sizeof(Clr));
|
||||
if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
|
||||
DefaultColormap(drw->dpy, drw->screen),
|
||||
clrname, &clr->rgb))
|
||||
die("error, cannot allocate color '%s'\n", clrname);
|
||||
clr->pix = clr->rgb.pixel;
|
||||
clrname, dest))
|
||||
die("error, cannot allocate color '%s'", clrname);
|
||||
}
|
||||
|
||||
return clr;
|
||||
/* 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_clr_free(Clr *clr)
|
||||
drw_setfontset(Drw *drw, Fnt *set)
|
||||
{
|
||||
free(clr);
|
||||
if (drw)
|
||||
drw->fonts = set;
|
||||
}
|
||||
|
||||
void
|
||||
drw_setscheme(Drw *drw, ClrScheme *scheme)
|
||||
drw_setscheme(Drw *drw, Clr *scm)
|
||||
{
|
||||
drw->scheme = scheme;
|
||||
if (drw)
|
||||
drw->scheme = scm;
|
||||
}
|
||||
|
||||
void
|
||||
drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty, int invert)
|
||||
drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert)
|
||||
{
|
||||
if (!drw->scheme)
|
||||
if (!drw || !drw->scheme)
|
||||
return;
|
||||
XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->bg->pix : drw->scheme->fg->pix);
|
||||
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 + 1, h + 1);
|
||||
else if (empty)
|
||||
XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
|
||||
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, const char *text, int invert)
|
||||
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 tx, ty, th;
|
||||
Extnts tex;
|
||||
int ty, ellipsis_x = 0;
|
||||
unsigned int tmpw, ew, ellipsis_w = 0, ellipsis_len, hash, h0, h1;
|
||||
XftDraw *d = NULL;
|
||||
Fnt *curfont, *nextfont;
|
||||
size_t i, len;
|
||||
int utf8strlen, utf8charlen, render;
|
||||
Fnt *usedfont, *curfont, *nextfont;
|
||||
int utf8strlen, utf8charlen, utf8err, render = x || y || w || h;
|
||||
long utf8codepoint = 0;
|
||||
const char *utf8str;
|
||||
FcCharSet *fccharset;
|
||||
FcPattern *fcpattern;
|
||||
FcPattern *match;
|
||||
XftResult result;
|
||||
int charexists = 0;
|
||||
int charexists = 0, overflow = 0;
|
||||
/* keep track of a couple codepoints for which we have no match. */
|
||||
static unsigned int nomatches[128], ellipsis_width, invalid_width;
|
||||
static const char invalid[] = "<EFBFBD>";
|
||||
|
||||
if (!drw->scheme || !drw->fontcount)
|
||||
if (!drw || (render && (!drw->scheme || !w)) || !text || !drw->fonts)
|
||||
return 0;
|
||||
|
||||
if (!(render = x || y || w || h)) {
|
||||
w = ~w;
|
||||
if (!render) {
|
||||
w = invert ? invert : ~invert;
|
||||
} else {
|
||||
XSetForeground(drw->dpy, drw->gc, invert ?
|
||||
drw->scheme->fg->pix : drw->scheme->bg->pix);
|
||||
XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel);
|
||||
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
|
||||
if (w < lpad)
|
||||
return x + w;
|
||||
d = XftDrawCreate(drw->dpy, drw->drawable,
|
||||
DefaultVisual(drw->dpy, drw->screen),
|
||||
DefaultColormap(drw->dpy, drw->screen));
|
||||
x += lpad;
|
||||
w -= lpad;
|
||||
}
|
||||
|
||||
curfont = drw->fonts[0];
|
||||
usedfont = drw->fonts;
|
||||
if (!ellipsis_width && render)
|
||||
ellipsis_width = drw_fontset_getwidth(drw, "...");
|
||||
if (!invalid_width && render)
|
||||
invalid_width = drw_fontset_getwidth(drw, invalid);
|
||||
while (1) {
|
||||
utf8strlen = 0;
|
||||
ew = ellipsis_len = utf8err = utf8charlen = utf8strlen = 0;
|
||||
utf8str = text;
|
||||
nextfont = NULL;
|
||||
while (*text) {
|
||||
utf8charlen = utf8decode(text, &utf8codepoint, UTF_SIZ);
|
||||
for (i = 0; i < drw->fontcount; i++) {
|
||||
charexists = charexists || XftCharExists(drw->dpy, drw->fonts[i]->xfont, utf8codepoint);
|
||||
utf8charlen = utf8decode(text, &utf8codepoint, &utf8err);
|
||||
for (curfont = drw->fonts; curfont; curfont = curfont->next) {
|
||||
charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint);
|
||||
if (charexists) {
|
||||
if (drw->fonts[i] == curfont) {
|
||||
utf8strlen += utf8charlen;
|
||||
drw_font_getexts(curfont, text, utf8charlen, &tmpw, NULL);
|
||||
if (ew + ellipsis_width <= w) {
|
||||
/* keep track where the ellipsis still fits */
|
||||
ellipsis_x = x + ew;
|
||||
ellipsis_w = w - ew;
|
||||
ellipsis_len = utf8strlen;
|
||||
}
|
||||
|
||||
if (ew + tmpw > w) {
|
||||
overflow = 1;
|
||||
/* called from drw_fontset_getwidth_clamp():
|
||||
* it wants the width AFTER the overflow
|
||||
*/
|
||||
if (!render)
|
||||
x += tmpw;
|
||||
else
|
||||
utf8strlen = ellipsis_len;
|
||||
} else if (curfont == usedfont) {
|
||||
text += utf8charlen;
|
||||
utf8strlen += utf8err ? 0 : utf8charlen;
|
||||
ew += utf8err ? 0 : tmpw;
|
||||
} else {
|
||||
nextfont = drw->fonts[i];
|
||||
nextfont = curfont;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!charexists || (nextfont && nextfont != curfont))
|
||||
if (overflow || !charexists || nextfont || utf8err)
|
||||
break;
|
||||
else
|
||||
charexists = 0;
|
||||
}
|
||||
|
||||
if (utf8strlen) {
|
||||
drw_font_getexts(curfont, utf8str, utf8strlen, &tex);
|
||||
/* shorten text if necessary */
|
||||
for (len = MIN(utf8strlen, (sizeof buf) - 1); len && (tex.w > w - drw->fonts[0]->h || w < drw->fonts[0]->h); len--)
|
||||
drw_font_getexts(curfont, utf8str, len, &tex);
|
||||
|
||||
if (len) {
|
||||
memcpy(buf, utf8str, len);
|
||||
buf[len] = '\0';
|
||||
if (len < utf8strlen)
|
||||
for (i = len; i && i > len - 3; buf[--i] = '.');
|
||||
|
||||
if (render) {
|
||||
th = curfont->ascent + curfont->descent;
|
||||
ty = y + (h / 2) - (th / 2) + curfont->ascent;
|
||||
tx = x + (h / 2);
|
||||
XftDrawStringUtf8(d, invert ? &drw->scheme->bg->rgb : &drw->scheme->fg->rgb, curfont->xfont, tx, ty, (XftChar8 *)buf, len);
|
||||
ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent;
|
||||
XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg],
|
||||
usedfont->xfont, x, ty, (XftChar8 *)utf8str, utf8strlen);
|
||||
}
|
||||
x += tex.w;
|
||||
w -= tex.w;
|
||||
x += ew;
|
||||
w -= ew;
|
||||
}
|
||||
if (utf8err && (!render || invalid_width < w)) {
|
||||
if (render)
|
||||
drw_text(drw, x, y, w, h, 0, invalid, invert);
|
||||
x += invalid_width;
|
||||
w -= invalid_width;
|
||||
}
|
||||
if (render && overflow)
|
||||
drw_text(drw, ellipsis_x, y, ellipsis_w, h, 0, "...", invert);
|
||||
|
||||
if (!*text) {
|
||||
if (!*text || overflow) {
|
||||
break;
|
||||
} else if (nextfont) {
|
||||
charexists = 0;
|
||||
curfont = nextfont;
|
||||
usedfont = nextfont;
|
||||
} else {
|
||||
/* Regardless of whether or not a fallback font is found, the
|
||||
* character must be drawn.
|
||||
*/
|
||||
* character must be drawn. */
|
||||
charexists = 1;
|
||||
|
||||
if (drw->fontcount >= DRW_FONT_CACHE_SIZE)
|
||||
continue;
|
||||
hash = (unsigned int)utf8codepoint;
|
||||
hash = ((hash >> 16) ^ hash) * 0x21F0AAAD;
|
||||
hash = ((hash >> 15) ^ hash) * 0xD35A2D97;
|
||||
h0 = ((hash >> 15) ^ hash) % LENGTH(nomatches);
|
||||
h1 = (hash >> 17) % LENGTH(nomatches);
|
||||
/* avoid expensive XftFontMatch call when we know we won't find a match */
|
||||
if (nomatches[h0] == utf8codepoint || nomatches[h1] == utf8codepoint)
|
||||
goto no_match;
|
||||
|
||||
fccharset = FcCharSetCreate();
|
||||
FcCharSetAddChar(fccharset, utf8codepoint);
|
||||
|
||||
if (!drw->fonts[0]->pattern) {
|
||||
/* Refer to the comment in drw_font_xcreate for more
|
||||
* information. */
|
||||
die("the first font in the cache must be loaded from a font string.\n");
|
||||
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[0]->pattern);
|
||||
fcpattern = FcPatternDuplicate(drw->fonts->pattern);
|
||||
FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset);
|
||||
FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue);
|
||||
|
||||
@ -334,12 +362,16 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *tex
|
||||
FcPatternDestroy(fcpattern);
|
||||
|
||||
if (match) {
|
||||
curfont = drw_font_xcreate(drw, NULL, match);
|
||||
if (curfont && XftCharExists(drw->dpy, curfont->xfont, utf8codepoint)) {
|
||||
drw->fonts[drw->fontcount++] = curfont;
|
||||
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 {
|
||||
drw_font_free(curfont);
|
||||
curfont = drw->fonts[0];
|
||||
xfont_free(usedfont);
|
||||
nomatches[nomatches[h0] ? h1 : h0] = utf8codepoint;
|
||||
no_match:
|
||||
usedfont = drw->fonts;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -347,34 +379,49 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *tex
|
||||
if (d)
|
||||
XftDrawDestroy(d);
|
||||
|
||||
return x;
|
||||
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);
|
||||
}
|
||||
|
||||
void
|
||||
drw_font_getexts(Fnt *font, const char *text, unsigned int len, Extnts *tex)
|
||||
unsigned int
|
||||
drw_fontset_getwidth(Drw *drw, const char *text)
|
||||
{
|
||||
XGlyphInfo ext;
|
||||
|
||||
XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext);
|
||||
tex->h = font->h;
|
||||
tex->w = ext.xOff;
|
||||
if (!drw || !drw->fonts || !text)
|
||||
return 0;
|
||||
return drw_text(drw, 0, 0, 0, 0, 0, text, 0);
|
||||
}
|
||||
|
||||
unsigned int
|
||||
drw_font_getexts_width(Fnt *font, const char *text, unsigned int len)
|
||||
drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n)
|
||||
{
|
||||
Extnts tex;
|
||||
unsigned int tmp = 0;
|
||||
if (drw && drw->fonts && text && n)
|
||||
tmp = drw_text(drw, 0, 0, 0, 0, 0, text, n);
|
||||
return MIN(n, tmp);
|
||||
}
|
||||
|
||||
drw_font_getexts(font, text, len, &tex);
|
||||
void
|
||||
drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h)
|
||||
{
|
||||
XGlyphInfo ext;
|
||||
|
||||
return tex.w;
|
||||
if (!font || !text)
|
||||
return;
|
||||
|
||||
XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext);
|
||||
if (w)
|
||||
*w = ext.xOff;
|
||||
if (h)
|
||||
*h = font->h;
|
||||
}
|
||||
|
||||
Cur *
|
||||
@ -382,7 +429,9 @@ drw_cur_create(Drw *drw, int shape)
|
||||
{
|
||||
Cur *cur;
|
||||
|
||||
cur = ecalloc(1, sizeof(Cur));
|
||||
if (!drw || !(cur = ecalloc(1, sizeof(Cur))))
|
||||
return NULL;
|
||||
|
||||
cur->cursor = XCreateFontCursor(drw->dpy, shape);
|
||||
|
||||
return cur;
|
||||
@ -393,6 +442,7 @@ drw_cur_free(Drw *drw, Cur *cursor)
|
||||
{
|
||||
if (!cursor)
|
||||
return;
|
||||
|
||||
XFreeCursor(drw->dpy, cursor->cursor);
|
||||
free(cursor);
|
||||
}
|
||||
|
64
drw.h
64
drw.h
@ -1,29 +1,19 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#define DRW_FONT_CACHE_SIZE 32
|
||||
|
||||
typedef struct {
|
||||
unsigned long pix;
|
||||
XftColor rgb;
|
||||
} Clr;
|
||||
|
||||
typedef struct {
|
||||
Cursor cursor;
|
||||
} Cur;
|
||||
|
||||
typedef struct {
|
||||
typedef struct Fnt {
|
||||
Display *dpy;
|
||||
int ascent;
|
||||
int descent;
|
||||
unsigned int h;
|
||||
XftFont *xfont;
|
||||
FcPattern *pattern;
|
||||
struct Fnt *next;
|
||||
} Fnt;
|
||||
|
||||
typedef struct {
|
||||
Clr *fg;
|
||||
Clr *bg;
|
||||
Clr *border;
|
||||
} ClrScheme;
|
||||
enum { ColFg, ColBg, ColBorder }; /* Clr scheme index */
|
||||
typedef XftColor Clr;
|
||||
|
||||
typedef struct {
|
||||
unsigned int w, h;
|
||||
@ -32,43 +22,37 @@ typedef struct {
|
||||
Window root;
|
||||
Drawable drawable;
|
||||
GC gc;
|
||||
ClrScheme *scheme;
|
||||
size_t fontcount;
|
||||
Fnt *fonts[DRW_FONT_CACHE_SIZE];
|
||||
Clr *scheme;
|
||||
Fnt *fonts;
|
||||
} Drw;
|
||||
|
||||
typedef struct {
|
||||
unsigned int w;
|
||||
unsigned int h;
|
||||
} Extnts;
|
||||
|
||||
/* Drawable abstraction */
|
||||
Drw *drw_create(Display *, int, Window, unsigned int, unsigned int);
|
||||
void drw_resize(Drw *, unsigned int, unsigned int);
|
||||
void drw_free(Drw *);
|
||||
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_font_create(Drw *, const char *);
|
||||
void drw_load_fonts(Drw *, const char *[], size_t);
|
||||
void drw_font_free(Fnt *);
|
||||
void drw_font_getexts(Fnt *, const char *, unsigned int, Extnts *);
|
||||
unsigned int drw_font_getexts_width(Fnt *, const char *, unsigned int);
|
||||
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);
|
||||
unsigned int drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n);
|
||||
void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h);
|
||||
|
||||
/* Colour abstraction */
|
||||
Clr *drw_clr_create(Drw *, const char *);
|
||||
void drw_clr_free(Clr *);
|
||||
/* 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 *, int);
|
||||
void drw_cur_free(Drw *, Cur *);
|
||||
Cur *drw_cur_create(Drw *drw, int shape);
|
||||
void drw_cur_free(Drw *drw, Cur *cursor);
|
||||
|
||||
/* Drawing context manipulation */
|
||||
void drw_setfont(Drw *, Fnt *);
|
||||
void drw_setscheme(Drw *, ClrScheme *);
|
||||
void drw_setfontset(Drw *drw, Fnt *set);
|
||||
void drw_setscheme(Drw *drw, Clr *scm);
|
||||
|
||||
/* Drawing functions */
|
||||
void drw_rect(Drw *, int, int, unsigned int, unsigned int, int, int, int);
|
||||
int drw_text(Drw *, int, int, unsigned int, unsigned int, const char *, int);
|
||||
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 *, Window, int, int, unsigned int, unsigned int);
|
||||
void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h);
|
||||
|
28
dwm.1
28
dwm.1
@ -10,8 +10,9 @@ 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 contains the window which currently needs most attention, whereas the
|
||||
stacking area contains all other windows. In monocle layout all windows are
|
||||
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.
|
||||
@ -32,7 +33,7 @@ dwm draws a small border around windows to indicate the focus state.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B \-v
|
||||
prints version information to standard output, then exits.
|
||||
prints version information to stderr, then exits.
|
||||
.SH USAGE
|
||||
.SS Status bar
|
||||
.TP
|
||||
@ -59,6 +60,11 @@ click on a tag label adds/removes that tag to/from the focused window.
|
||||
Start
|
||||
.BR st(1).
|
||||
.TP
|
||||
.B Mod1\-p
|
||||
Spawn
|
||||
.BR dmenu(1)
|
||||
for launching other programs.
|
||||
.TP
|
||||
.B Mod1\-,
|
||||
Focus previous screen, if any.
|
||||
.TP
|
||||
@ -93,10 +99,10 @@ Focus next window.
|
||||
Focus previous window.
|
||||
.TP
|
||||
.B Mod1\-i
|
||||
Increase clients in master area.
|
||||
Increase number of windows in master area.
|
||||
.TP
|
||||
.B Mod1\-d
|
||||
Decrease clients in master area.
|
||||
Decrease number of windows in master area.
|
||||
.TP
|
||||
.B Mod1\-l
|
||||
Increase master area size.
|
||||
@ -152,7 +158,7 @@ code. This keeps it fast, secure and simple.
|
||||
.SH SEE ALSO
|
||||
.BR dmenu (1),
|
||||
.BR st (1)
|
||||
.SH BUGS
|
||||
.SH ISSUES
|
||||
Java applications which use the XToolkit/XAWT backend may draw grey windows
|
||||
only. The XToolkit/XAWT backend breaks ICCCM-compliance in recent JDK 1.5 and early
|
||||
JDK 1.6 versions, because it assumes a reparenting window manager. Possible workarounds
|
||||
@ -166,11 +172,5 @@ or
|
||||
(to pretend that a non-reparenting window manager is running that the
|
||||
XToolkit/XAWT backend can recognize) or when using OpenJDK setting the environment variable
|
||||
.BR _JAVA_AWT_WM_NONREPARENTING=1 .
|
||||
.P
|
||||
GTK 2.10.9+ versions contain a broken
|
||||
.BR Save\-As
|
||||
file dialog implementation,
|
||||
which requests to reconfigure its window size in an endless loop. However, its
|
||||
window is still respondable during this state, so you can simply ignore the flicker
|
||||
until a new GTK version appears, which will fix this bug, approximately
|
||||
GTK 2.10.12+ versions.
|
||||
.SH BUGS
|
||||
Send all bug reports with a patch to hackers@suckless.org.
|
||||
|
371
dwm.c
371
dwm.c
@ -50,17 +50,16 @@
|
||||
#define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
|
||||
* MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
|
||||
#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
|
||||
#define LENGTH(X) (sizeof X / sizeof X[0])
|
||||
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
|
||||
#define WIDTH(X) ((X)->w + 2 * (X)->bw)
|
||||
#define HEIGHT(X) ((X)->h + 2 * (X)->bw)
|
||||
#define TAGMASK ((1 << LENGTH(tags)) - 1)
|
||||
#define TEXTW(X) (drw_text(drw, 0, 0, 0, 0, (X), 0) + drw->fonts[0]->h)
|
||||
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
|
||||
|
||||
/* enums */
|
||||
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
|
||||
enum { SchemeNorm, SchemeSel, SchemeLast }; /* color schemes */
|
||||
enum { NetSupported, NetWMName, NetWMState,
|
||||
enum { SchemeNorm, SchemeSel }; /* color schemes */
|
||||
enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
|
||||
NetWMFullscreen, NetActiveWindow, NetWMWindowType,
|
||||
NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
|
||||
enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
|
||||
@ -89,7 +88,7 @@ struct Client {
|
||||
float mina, maxa;
|
||||
int x, y, w, h;
|
||||
int oldx, oldy, oldw, oldh;
|
||||
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
|
||||
int basew, baseh, incw, inch, maxw, maxh, minw, minh, hintsvalid;
|
||||
int bw, oldbw;
|
||||
unsigned int tags;
|
||||
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
|
||||
@ -152,7 +151,6 @@ static void buttonpress(XEvent *e);
|
||||
static void checkotherwm(void);
|
||||
static void cleanup(void);
|
||||
static void cleanupmon(Monitor *mon);
|
||||
static void clearurgent(Client *c);
|
||||
static void clientmessage(XEvent *e);
|
||||
static void configure(Client *c);
|
||||
static void configurenotify(XEvent *e);
|
||||
@ -170,6 +168,7 @@ static void focus(Client *c);
|
||||
static void focusin(XEvent *e);
|
||||
static void focusmon(const Arg *arg);
|
||||
static void focusstack(const Arg *arg);
|
||||
static Atom getatomprop(Client *c, Atom prop);
|
||||
static int getrootptr(int *x, int *y);
|
||||
static long getstate(Window w);
|
||||
static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
|
||||
@ -185,7 +184,7 @@ static void monocle(Monitor *m);
|
||||
static void motionnotify(XEvent *e);
|
||||
static void movemouse(const Arg *arg);
|
||||
static Client *nexttiled(Client *c);
|
||||
static void pop(Client *);
|
||||
static void pop(Client *c);
|
||||
static void propertynotify(XEvent *e);
|
||||
static void quit(const Arg *arg);
|
||||
static Monitor *recttomon(int x, int y, int w, int h);
|
||||
@ -203,12 +202,12 @@ static void setfullscreen(Client *c, int fullscreen);
|
||||
static void setlayout(const Arg *arg);
|
||||
static void setmfact(const Arg *arg);
|
||||
static void setup(void);
|
||||
static void seturgent(Client *c, int urg);
|
||||
static void showhide(Client *c);
|
||||
static void sigchld(int unused);
|
||||
static void spawn(const Arg *arg);
|
||||
static void tag(const Arg *arg);
|
||||
static void tagmon(const Arg *arg);
|
||||
static void tile(Monitor *);
|
||||
static void tile(Monitor *m);
|
||||
static void togglebar(const Arg *arg);
|
||||
static void togglefloating(const Arg *arg);
|
||||
static void toggletag(const Arg *arg);
|
||||
@ -216,15 +215,15 @@ static void toggleview(const Arg *arg);
|
||||
static void unfocus(Client *c, int setfocus);
|
||||
static void unmanage(Client *c, int destroyed);
|
||||
static void unmapnotify(XEvent *e);
|
||||
static int updategeom(void);
|
||||
static void updatebarpos(Monitor *m);
|
||||
static void updatebars(void);
|
||||
static void updateclientlist(void);
|
||||
static int updategeom(void);
|
||||
static void updatenumlockmask(void);
|
||||
static void updatesizehints(Client *c);
|
||||
static void updatestatus(void);
|
||||
static void updatewindowtype(Client *c);
|
||||
static void updatetitle(Client *c);
|
||||
static void updatewindowtype(Client *c);
|
||||
static void updatewmhints(Client *c);
|
||||
static void view(const Arg *arg);
|
||||
static Client *wintoclient(Window w);
|
||||
@ -239,7 +238,8 @@ static const char broken[] = "broken";
|
||||
static char stext[256];
|
||||
static int screen;
|
||||
static int sw, sh; /* X display screen geometry width, height */
|
||||
static int bh, blw = 0; /* bar geometry */
|
||||
static int bh; /* bar height */
|
||||
static int lrpad; /* sum of left and right padding for text */
|
||||
static int (*xerrorxlib)(Display *, XErrorEvent *);
|
||||
static unsigned int numlockmask = 0;
|
||||
static void (*handler[LASTEvent]) (XEvent *) = {
|
||||
@ -261,11 +261,11 @@ static void (*handler[LASTEvent]) (XEvent *) = {
|
||||
static Atom wmatom[WMLast], netatom[NetLast];
|
||||
static int running = 1;
|
||||
static Cur *cursor[CurLast];
|
||||
static ClrScheme scheme[SchemeLast];
|
||||
static Clr **scheme;
|
||||
static Display *dpy;
|
||||
static Drw *drw;
|
||||
static Monitor *mons, *selmon;
|
||||
static Window root;
|
||||
static Window root, wmcheckwin;
|
||||
|
||||
/* configuration, allows nested code to access above variables */
|
||||
#include "config.h"
|
||||
@ -343,6 +343,8 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact)
|
||||
if (*w < bh)
|
||||
*w = bh;
|
||||
if (resizehints || c->isfloating || !c->mon->lt[c->mon->sellt]->arrange) {
|
||||
if (!c->hintsvalid)
|
||||
updatesizehints(c);
|
||||
/* see last two sentences in ICCCM 4.1.2.3 */
|
||||
baseismin = c->basew == c->minw && c->baseh == c->minh;
|
||||
if (!baseismin) { /* temporarily remove base dimensions */
|
||||
@ -436,14 +438,16 @@ buttonpress(XEvent *e)
|
||||
if (i < LENGTH(tags)) {
|
||||
click = ClkTagBar;
|
||||
arg.ui = 1 << i;
|
||||
} else if (ev->x < x + blw)
|
||||
} else if (ev->x < x + TEXTW(selmon->ltsymbol))
|
||||
click = ClkLtSymbol;
|
||||
else if (ev->x > selmon->ww - TEXTW(stext))
|
||||
else if (ev->x > selmon->ww - (int)TEXTW(stext))
|
||||
click = ClkStatusText;
|
||||
else
|
||||
click = ClkWinTitle;
|
||||
} else if ((c = wintoclient(ev->window))) {
|
||||
focus(c);
|
||||
restack(selmon);
|
||||
XAllowEvents(dpy, ReplayPointer, CurrentTime);
|
||||
click = ClkClientWin;
|
||||
}
|
||||
for (i = 0; i < LENGTH(buttons); i++)
|
||||
@ -481,11 +485,10 @@ cleanup(void)
|
||||
cleanupmon(mons);
|
||||
for (i = 0; i < CurLast; i++)
|
||||
drw_cur_free(drw, cursor[i]);
|
||||
for (i = 0; i < SchemeLast; i++) {
|
||||
drw_clr_free(scheme[i].border);
|
||||
drw_clr_free(scheme[i].bg);
|
||||
drw_clr_free(scheme[i].fg);
|
||||
}
|
||||
for (i = 0; i < LENGTH(colors); i++)
|
||||
free(scheme[i]);
|
||||
free(scheme);
|
||||
XDestroyWindow(dpy, wmcheckwin);
|
||||
drw_free(drw);
|
||||
XSync(dpy, False);
|
||||
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
|
||||
@ -508,19 +511,6 @@ cleanupmon(Monitor *mon)
|
||||
free(mon);
|
||||
}
|
||||
|
||||
void
|
||||
clearurgent(Client *c)
|
||||
{
|
||||
XWMHints *wmh;
|
||||
|
||||
c->isurgent = 0;
|
||||
if (!(wmh = XGetWMHints(dpy, c->win)))
|
||||
return;
|
||||
wmh->flags &= ~XUrgencyHint;
|
||||
XSetWMHints(dpy, c->win, wmh);
|
||||
XFree(wmh);
|
||||
}
|
||||
|
||||
void
|
||||
clientmessage(XEvent *e)
|
||||
{
|
||||
@ -530,15 +520,13 @@ clientmessage(XEvent *e)
|
||||
if (!c)
|
||||
return;
|
||||
if (cme->message_type == netatom[NetWMState]) {
|
||||
if (cme->data.l[1] == netatom[NetWMFullscreen] || cme->data.l[2] == netatom[NetWMFullscreen])
|
||||
if (cme->data.l[1] == netatom[NetWMFullscreen]
|
||||
|| cme->data.l[2] == netatom[NetWMFullscreen])
|
||||
setfullscreen(c, (cme->data.l[0] == 1 /* _NET_WM_STATE_ADD */
|
||||
|| (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen)));
|
||||
} else if (cme->message_type == netatom[NetActiveWindow]) {
|
||||
if (!ISVISIBLE(c)) {
|
||||
c->mon->seltags ^= 1;
|
||||
c->mon->tagset[c->mon->seltags] = c->tags;
|
||||
}
|
||||
pop(c);
|
||||
if (c != selmon->sel && !c->isurgent)
|
||||
seturgent(c, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -565,6 +553,7 @@ void
|
||||
configurenotify(XEvent *e)
|
||||
{
|
||||
Monitor *m;
|
||||
Client *c;
|
||||
XConfigureEvent *ev = &e->xconfigure;
|
||||
int dirty;
|
||||
|
||||
@ -576,8 +565,12 @@ configurenotify(XEvent *e)
|
||||
if (updategeom() || dirty) {
|
||||
drw_resize(drw, sw, bh);
|
||||
updatebars();
|
||||
for (m = mons; m; m = m->next)
|
||||
for (m = mons; m; m = m->next) {
|
||||
for (c = m->clients; c; c = c->next)
|
||||
if (c->isfullscreen)
|
||||
resizeclient(c, m->mx, m->my, m->mw, m->mh);
|
||||
XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
|
||||
}
|
||||
focus(NULL);
|
||||
arrange(NULL);
|
||||
}
|
||||
@ -704,11 +697,21 @@ dirtomon(int dir)
|
||||
void
|
||||
drawbar(Monitor *m)
|
||||
{
|
||||
int x, xx, w, dx;
|
||||
int x, w, tw = 0;
|
||||
int boxs = drw->fonts->h / 9;
|
||||
int boxw = drw->fonts->h / 6 + 2;
|
||||
unsigned int i, occ = 0, urg = 0;
|
||||
Client *c;
|
||||
|
||||
dx = (drw->fonts[0]->ascent + drw->fonts[0]->descent + 2) / 4;
|
||||
if (!m->showbar)
|
||||
return;
|
||||
|
||||
/* draw status first so it can be overdrawn by tags later */
|
||||
if (m == selmon) { /* status is only drawn on selected monitor */
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
|
||||
drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
|
||||
}
|
||||
|
||||
for (c = m->clients; c; c = c->next) {
|
||||
occ |= c->tags;
|
||||
@ -718,36 +721,27 @@ drawbar(Monitor *m)
|
||||
x = 0;
|
||||
for (i = 0; i < LENGTH(tags); i++) {
|
||||
w = TEXTW(tags[i]);
|
||||
drw_setscheme(drw, m->tagset[m->seltags] & 1 << i ? &scheme[SchemeSel] : &scheme[SchemeNorm]);
|
||||
drw_text(drw, x, 0, w, bh, tags[i], urg & 1 << i);
|
||||
drw_rect(drw, x + 1, 1, dx, dx, m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
|
||||
occ & 1 << i, urg & 1 << i);
|
||||
drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
|
||||
drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
|
||||
if (occ & 1 << i)
|
||||
drw_rect(drw, x + boxs, boxs, boxw, boxw,
|
||||
m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
|
||||
urg & 1 << i);
|
||||
x += w;
|
||||
}
|
||||
w = blw = TEXTW(m->ltsymbol);
|
||||
drw_setscheme(drw, &scheme[SchemeNorm]);
|
||||
drw_text(drw, x, 0, w, bh, m->ltsymbol, 0);
|
||||
x += w;
|
||||
xx = x;
|
||||
if (m == selmon) { /* status is only drawn on selected monitor */
|
||||
w = TEXTW(stext);
|
||||
x = m->ww - w;
|
||||
if (x < xx) {
|
||||
x = xx;
|
||||
w = m->ww - xx;
|
||||
}
|
||||
drw_text(drw, x, 0, w, bh, stext, 0);
|
||||
} else
|
||||
x = m->ww;
|
||||
if ((w = x - xx) > bh) {
|
||||
x = xx;
|
||||
w = TEXTW(m->ltsymbol);
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
|
||||
|
||||
if ((w = m->ww - tw - x) > bh) {
|
||||
if (m->sel) {
|
||||
drw_setscheme(drw, m == selmon ? &scheme[SchemeSel] : &scheme[SchemeNorm]);
|
||||
drw_text(drw, x, 0, w, bh, m->sel->name, 0);
|
||||
drw_rect(drw, x + 1, 1, dx, dx, m->sel->isfixed, m->sel->isfloating, 0);
|
||||
drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
|
||||
drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
|
||||
if (m->sel->isfloating)
|
||||
drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
|
||||
} else {
|
||||
drw_setscheme(drw, &scheme[SchemeNorm]);
|
||||
drw_rect(drw, x, 0, w, bh, 1, 0, 1);
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
drw_rect(drw, x, 0, w, bh, 1, 1);
|
||||
}
|
||||
}
|
||||
drw_map(drw, m->barwin, 0, 0, m->ww, bh);
|
||||
@ -796,18 +790,17 @@ focus(Client *c)
|
||||
{
|
||||
if (!c || !ISVISIBLE(c))
|
||||
for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
|
||||
/* was if (selmon->sel) */
|
||||
if (selmon->sel && selmon->sel != c)
|
||||
unfocus(selmon->sel, 0);
|
||||
if (c) {
|
||||
if (c->mon != selmon)
|
||||
selmon = c->mon;
|
||||
if (c->isurgent)
|
||||
clearurgent(c);
|
||||
seturgent(c, 0);
|
||||
detachstack(c);
|
||||
attachstack(c);
|
||||
grabbuttons(c, 1);
|
||||
XSetWindowBorder(dpy, c->win, scheme[SchemeSel].border->pix);
|
||||
XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel);
|
||||
setfocus(c);
|
||||
} else {
|
||||
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
|
||||
@ -817,7 +810,7 @@ focus(Client *c)
|
||||
drawbars();
|
||||
}
|
||||
|
||||
/* there are some broken focus acquiring clients */
|
||||
/* there are some broken focus acquiring clients needing extra handling */
|
||||
void
|
||||
focusin(XEvent *e)
|
||||
{
|
||||
@ -836,8 +829,7 @@ focusmon(const Arg *arg)
|
||||
return;
|
||||
if ((m = dirtomon(arg->i)) == selmon)
|
||||
return;
|
||||
unfocus(selmon->sel, 0); /* s/1/0/ fixes input focus issues
|
||||
in gedit and anjuta */
|
||||
unfocus(selmon->sel, 0);
|
||||
selmon = m;
|
||||
focus(NULL);
|
||||
}
|
||||
@ -847,7 +839,7 @@ focusstack(const Arg *arg)
|
||||
{
|
||||
Client *c = NULL, *i;
|
||||
|
||||
if (!selmon->sel)
|
||||
if (!selmon->sel || (selmon->sel->isfullscreen && lockfullscreen))
|
||||
return;
|
||||
if (arg->i > 0) {
|
||||
for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next);
|
||||
@ -922,17 +914,14 @@ gettextprop(Window w, Atom atom, char *text, unsigned int size)
|
||||
if (!text || size == 0)
|
||||
return 0;
|
||||
text[0] = '\0';
|
||||
XGetTextProperty(dpy, w, &name, atom);
|
||||
if (!name.nitems)
|
||||
if (!XGetTextProperty(dpy, w, &name, atom) || !name.nitems)
|
||||
return 0;
|
||||
if (name.encoding == XA_STRING)
|
||||
if (name.encoding == XA_STRING) {
|
||||
strncpy(text, (char *)name.value, size - 1);
|
||||
else {
|
||||
if (XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success && n > 0 && *list) {
|
||||
} else if (XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success && n > 0 && *list) {
|
||||
strncpy(text, *list, size - 1);
|
||||
XFreeStringList(list);
|
||||
}
|
||||
}
|
||||
text[size - 1] = '\0';
|
||||
XFree(name.value);
|
||||
return 1;
|
||||
@ -946,7 +935,9 @@ grabbuttons(Client *c, int focused)
|
||||
unsigned int i, j;
|
||||
unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
|
||||
XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
|
||||
if (focused) {
|
||||
if (!focused)
|
||||
XGrabButton(dpy, AnyButton, AnyModifier, c->win, False,
|
||||
BUTTONMASK, GrabModeSync, GrabModeSync, None, None);
|
||||
for (i = 0; i < LENGTH(buttons); i++)
|
||||
if (buttons[i].click == ClkClientWin)
|
||||
for (j = 0; j < LENGTH(modifiers); j++)
|
||||
@ -954,9 +945,6 @@ grabbuttons(Client *c, int focused)
|
||||
buttons[i].mask | modifiers[j],
|
||||
c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
} else
|
||||
XGrabButton(dpy, AnyButton, AnyModifier, c->win, False,
|
||||
BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
|
||||
}
|
||||
}
|
||||
|
||||
@ -965,16 +953,26 @@ grabkeys(void)
|
||||
{
|
||||
updatenumlockmask();
|
||||
{
|
||||
unsigned int i, j;
|
||||
unsigned int i, j, k;
|
||||
unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
|
||||
KeyCode code;
|
||||
int start, end, skip;
|
||||
KeySym *syms;
|
||||
|
||||
XUngrabKey(dpy, AnyKey, AnyModifier, root);
|
||||
XDisplayKeycodes(dpy, &start, &end);
|
||||
syms = XGetKeyboardMapping(dpy, start, end - start + 1, &skip);
|
||||
if (!syms)
|
||||
return;
|
||||
for (k = start; k <= end; k++)
|
||||
for (i = 0; i < LENGTH(keys); i++)
|
||||
if ((code = XKeysymToKeycode(dpy, keys[i].keysym)))
|
||||
/* skip modifier codes, we do that ourselves */
|
||||
if (keys[i].keysym == syms[(k - start) * skip])
|
||||
for (j = 0; j < LENGTH(modifiers); j++)
|
||||
XGrabKey(dpy, code, keys[i].mod | modifiers[j], root,
|
||||
True, GrabModeAsync, GrabModeAsync);
|
||||
XGrabKey(dpy, k,
|
||||
keys[i].mod | modifiers[j],
|
||||
root, True,
|
||||
GrabModeAsync, GrabModeAsync);
|
||||
XFree(syms);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1038,6 +1036,13 @@ manage(Window w, XWindowAttributes *wa)
|
||||
|
||||
c = ecalloc(1, sizeof(Client));
|
||||
c->win = w;
|
||||
/* geometry */
|
||||
c->x = c->oldx = wa->x;
|
||||
c->y = c->oldy = wa->y;
|
||||
c->w = c->oldw = wa->width;
|
||||
c->h = c->oldh = wa->height;
|
||||
c->oldbw = wa->border_width;
|
||||
|
||||
updatetitle(c);
|
||||
if (XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) {
|
||||
c->mon = t->mon;
|
||||
@ -1046,26 +1051,18 @@ manage(Window w, XWindowAttributes *wa)
|
||||
c->mon = selmon;
|
||||
applyrules(c);
|
||||
}
|
||||
/* geometry */
|
||||
c->x = c->oldx = wa->x;
|
||||
c->y = c->oldy = wa->y;
|
||||
c->w = c->oldw = wa->width;
|
||||
c->h = c->oldh = wa->height;
|
||||
c->oldbw = wa->border_width;
|
||||
|
||||
if (c->x + WIDTH(c) > c->mon->mx + c->mon->mw)
|
||||
c->x = c->mon->mx + c->mon->mw - WIDTH(c);
|
||||
if (c->y + HEIGHT(c) > c->mon->my + c->mon->mh)
|
||||
c->y = c->mon->my + c->mon->mh - HEIGHT(c);
|
||||
c->x = MAX(c->x, c->mon->mx);
|
||||
/* only fix client y-offset, if the client center might cover the bar */
|
||||
c->y = MAX(c->y, ((c->mon->by == c->mon->my) && (c->x + (c->w / 2) >= c->mon->wx)
|
||||
&& (c->x + (c->w / 2) < c->mon->wx + c->mon->ww)) ? bh : c->mon->my);
|
||||
if (c->x + WIDTH(c) > c->mon->wx + c->mon->ww)
|
||||
c->x = c->mon->wx + c->mon->ww - WIDTH(c);
|
||||
if (c->y + HEIGHT(c) > c->mon->wy + c->mon->wh)
|
||||
c->y = c->mon->wy + c->mon->wh - HEIGHT(c);
|
||||
c->x = MAX(c->x, c->mon->wx);
|
||||
c->y = MAX(c->y, c->mon->wy);
|
||||
c->bw = borderpx;
|
||||
|
||||
wc.border_width = c->bw;
|
||||
XConfigureWindow(dpy, w, CWBorderWidth, &wc);
|
||||
XSetWindowBorder(dpy, w, scheme[SchemeNorm].border->pix);
|
||||
XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel);
|
||||
configure(c); /* propagates border_width, if size doesn't change */
|
||||
updatewindowtype(c);
|
||||
updatesizehints(c);
|
||||
@ -1106,9 +1103,7 @@ maprequest(XEvent *e)
|
||||
static XWindowAttributes wa;
|
||||
XMapRequestEvent *ev = &e->xmaprequest;
|
||||
|
||||
if (!XGetWindowAttributes(dpy, ev->window, &wa))
|
||||
return;
|
||||
if (wa.override_redirect)
|
||||
if (!XGetWindowAttributes(dpy, ev->window, &wa) || wa.override_redirect)
|
||||
return;
|
||||
if (!wintoclient(ev->window))
|
||||
manage(ev->window, &wa);
|
||||
@ -1182,8 +1177,6 @@ movemouse(const Arg *arg)
|
||||
|
||||
nx = ocx + (ev.xmotion.x - x);
|
||||
ny = ocy + (ev.xmotion.y - y);
|
||||
if (nx >= selmon->wx && nx <= selmon->wx + selmon->ww
|
||||
&& ny >= selmon->wy && ny <= selmon->wy + selmon->wh) {
|
||||
if (abs(selmon->wx - nx) < snap)
|
||||
nx = selmon->wx;
|
||||
else if (abs((selmon->wx + selmon->ww) - (nx + WIDTH(c))) < snap)
|
||||
@ -1195,7 +1188,6 @@ movemouse(const Arg *arg)
|
||||
if (!c->isfloating && selmon->lt[selmon->sellt]->arrange
|
||||
&& (abs(nx - c->x) > snap || abs(ny - c->y) > snap))
|
||||
togglefloating(NULL);
|
||||
}
|
||||
if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
|
||||
resize(c, nx, ny, c->w, c->h, 1);
|
||||
break;
|
||||
@ -1245,7 +1237,7 @@ propertynotify(XEvent *e)
|
||||
arrange(c->mon);
|
||||
break;
|
||||
case XA_WM_NORMAL_HINTS:
|
||||
updatesizehints(c);
|
||||
c->hintsvalid = 0;
|
||||
break;
|
||||
case XA_WM_HINTS:
|
||||
updatewmhints(c);
|
||||
@ -1528,7 +1520,7 @@ setlayout(const Arg *arg)
|
||||
drawbar(selmon);
|
||||
}
|
||||
|
||||
/* arg > 1.0 will set mfact absolutly */
|
||||
/* arg > 1.0 will set mfact absolutely */
|
||||
void
|
||||
setmfact(const Arg *arg)
|
||||
{
|
||||
@ -1537,7 +1529,7 @@ setmfact(const Arg *arg)
|
||||
if (!arg || !selmon->lt[selmon->sellt]->arrange)
|
||||
return;
|
||||
f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
|
||||
if (f < 0.1 || f > 0.9)
|
||||
if (f < 0.05 || f > 0.95)
|
||||
return;
|
||||
selmon->mfact = f;
|
||||
arrange(selmon);
|
||||
@ -1546,10 +1538,19 @@ setmfact(const Arg *arg)
|
||||
void
|
||||
setup(void)
|
||||
{
|
||||
int i;
|
||||
XSetWindowAttributes wa;
|
||||
Atom utf8string;
|
||||
struct sigaction sa;
|
||||
|
||||
/* clean up any zombies immediately */
|
||||
sigchld(0);
|
||||
/* do not transform children into zombies when they terminate */
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = SA_NOCLDSTOP | SA_NOCLDWAIT | SA_RESTART;
|
||||
sa.sa_handler = SIG_IGN;
|
||||
sigaction(SIGCHLD, &sa, NULL);
|
||||
|
||||
/* clean up any zombies (inherited from .xinitrc etc) immediately */
|
||||
while (waitpid(-1, NULL, WNOHANG) > 0);
|
||||
|
||||
/* init screen */
|
||||
screen = DefaultScreen(dpy);
|
||||
@ -1557,12 +1558,13 @@ setup(void)
|
||||
sh = DisplayHeight(dpy, screen);
|
||||
root = RootWindow(dpy, screen);
|
||||
drw = drw_create(dpy, screen, root, sw, sh);
|
||||
drw_load_fonts(drw, fonts, LENGTH(fonts));
|
||||
if (!drw->fontcount)
|
||||
die("no fonts could be loaded.\n");
|
||||
bh = drw->fonts[0]->h + 2;
|
||||
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
|
||||
die("no fonts could be loaded.");
|
||||
lrpad = drw->fonts->h;
|
||||
bh = drw->fonts->h + 2;
|
||||
updategeom();
|
||||
/* init atoms */
|
||||
utf8string = XInternAtom(dpy, "UTF8_STRING", False);
|
||||
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
|
||||
wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
|
||||
wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
|
||||
@ -1571,6 +1573,7 @@ setup(void)
|
||||
netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
|
||||
netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
|
||||
netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
|
||||
netatom[NetWMCheck] = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False);
|
||||
netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
|
||||
netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
|
||||
netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
|
||||
@ -1580,29 +1583,48 @@ setup(void)
|
||||
cursor[CurResize] = drw_cur_create(drw, XC_sizing);
|
||||
cursor[CurMove] = drw_cur_create(drw, XC_fleur);
|
||||
/* init appearance */
|
||||
scheme[SchemeNorm].border = drw_clr_create(drw, normbordercolor);
|
||||
scheme[SchemeNorm].bg = drw_clr_create(drw, normbgcolor);
|
||||
scheme[SchemeNorm].fg = drw_clr_create(drw, normfgcolor);
|
||||
scheme[SchemeSel].border = drw_clr_create(drw, selbordercolor);
|
||||
scheme[SchemeSel].bg = drw_clr_create(drw, selbgcolor);
|
||||
scheme[SchemeSel].fg = drw_clr_create(drw, selfgcolor);
|
||||
scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
|
||||
for (i = 0; i < LENGTH(colors); i++)
|
||||
scheme[i] = drw_scm_create(drw, colors[i], 3);
|
||||
/* init bars */
|
||||
updatebars();
|
||||
updatestatus();
|
||||
/* supporting window for NetWMCheck */
|
||||
wmcheckwin = XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0);
|
||||
XChangeProperty(dpy, wmcheckwin, netatom[NetWMCheck], XA_WINDOW, 32,
|
||||
PropModeReplace, (unsigned char *) &wmcheckwin, 1);
|
||||
XChangeProperty(dpy, wmcheckwin, netatom[NetWMName], utf8string, 8,
|
||||
PropModeReplace, (unsigned char *) "dwm", 3);
|
||||
XChangeProperty(dpy, root, netatom[NetWMCheck], XA_WINDOW, 32,
|
||||
PropModeReplace, (unsigned char *) &wmcheckwin, 1);
|
||||
/* EWMH support per view */
|
||||
XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
|
||||
PropModeReplace, (unsigned char *) netatom, NetLast);
|
||||
XDeleteProperty(dpy, root, netatom[NetClientList]);
|
||||
/* select for events */
|
||||
/* select events */
|
||||
wa.cursor = cursor[CurNormal]->cursor;
|
||||
wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask|PointerMotionMask
|
||||
|EnterWindowMask|LeaveWindowMask|StructureNotifyMask|PropertyChangeMask;
|
||||
wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask
|
||||
|ButtonPressMask|PointerMotionMask|EnterWindowMask
|
||||
|LeaveWindowMask|StructureNotifyMask|PropertyChangeMask;
|
||||
XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
|
||||
XSelectInput(dpy, root, wa.event_mask);
|
||||
grabkeys();
|
||||
focus(NULL);
|
||||
}
|
||||
|
||||
void
|
||||
seturgent(Client *c, int urg)
|
||||
{
|
||||
XWMHints *wmh;
|
||||
|
||||
c->isurgent = urg;
|
||||
if (!(wmh = XGetWMHints(dpy, c->win)))
|
||||
return;
|
||||
wmh->flags = urg ? (wmh->flags | XUrgencyHint) : (wmh->flags & ~XUrgencyHint);
|
||||
XSetWMHints(dpy, c->win, wmh);
|
||||
XFree(wmh);
|
||||
}
|
||||
|
||||
void
|
||||
showhide(Client *c)
|
||||
{
|
||||
@ -1621,27 +1643,25 @@ showhide(Client *c)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
sigchld(int unused)
|
||||
{
|
||||
if (signal(SIGCHLD, sigchld) == SIG_ERR)
|
||||
die("can't install SIGCHLD handler:");
|
||||
while (0 < waitpid(-1, NULL, WNOHANG));
|
||||
}
|
||||
|
||||
void
|
||||
spawn(const Arg *arg)
|
||||
{
|
||||
struct sigaction sa;
|
||||
|
||||
if (arg->v == dmenucmd)
|
||||
dmenumon[0] = '0' + selmon->num;
|
||||
if (fork() == 0) {
|
||||
if (dpy)
|
||||
close(ConnectionNumber(dpy));
|
||||
setsid();
|
||||
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = 0;
|
||||
sa.sa_handler = SIG_DFL;
|
||||
sigaction(SIGCHLD, &sa, NULL);
|
||||
|
||||
execvp(((char **)arg->v)[0], (char **)arg->v);
|
||||
fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[0]);
|
||||
perror(" failed");
|
||||
exit(EXIT_SUCCESS);
|
||||
die("dwm: execvp '%s' failed:", ((char **)arg->v)[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1681,10 +1701,12 @@ tile(Monitor *m)
|
||||
if (i < m->nmaster) {
|
||||
h = (m->wh - my) / (MIN(n, m->nmaster) - i);
|
||||
resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0);
|
||||
if (my + HEIGHT(c) < m->wh)
|
||||
my += HEIGHT(c);
|
||||
} else {
|
||||
h = (m->wh - ty) / (n - i);
|
||||
resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0);
|
||||
if (ty + HEIGHT(c) < m->wh)
|
||||
ty += HEIGHT(c);
|
||||
}
|
||||
}
|
||||
@ -1745,7 +1767,7 @@ unfocus(Client *c, int setfocus)
|
||||
if (!c)
|
||||
return;
|
||||
grabbuttons(c, 0);
|
||||
XSetWindowBorder(dpy, c->win, scheme[SchemeNorm].border->pix);
|
||||
XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel);
|
||||
if (setfocus) {
|
||||
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
|
||||
XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
|
||||
@ -1758,13 +1780,13 @@ unmanage(Client *c, int destroyed)
|
||||
Monitor *m = c->mon;
|
||||
XWindowChanges wc;
|
||||
|
||||
/* The server grab construct avoids race conditions. */
|
||||
detach(c);
|
||||
detachstack(c);
|
||||
if (!destroyed) {
|
||||
wc.border_width = c->oldbw;
|
||||
XGrabServer(dpy);
|
||||
XGrabServer(dpy); /* avoid race conditions */
|
||||
XSetErrorHandler(xerrordummy);
|
||||
XSelectInput(dpy, c->win, NoEventMask);
|
||||
XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); /* restore border */
|
||||
XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
|
||||
setclientstate(c, WithdrawnState);
|
||||
@ -1801,6 +1823,7 @@ updatebars(void)
|
||||
.background_pixmap = ParentRelative,
|
||||
.event_mask = ButtonPressMask|ExposureMask
|
||||
};
|
||||
XClassHint ch = {"dwm", "dwm"};
|
||||
for (m = mons; m; m = m->next) {
|
||||
if (m->barwin)
|
||||
continue;
|
||||
@ -1809,6 +1832,7 @@ updatebars(void)
|
||||
CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
|
||||
XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
|
||||
XMapRaised(dpy, m->barwin);
|
||||
XSetClassHint(dpy, m->barwin, &ch);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1826,7 +1850,7 @@ updatebarpos(Monitor *m)
|
||||
}
|
||||
|
||||
void
|
||||
updateclientlist()
|
||||
updateclientlist(void)
|
||||
{
|
||||
Client *c;
|
||||
Monitor *m;
|
||||
@ -1860,8 +1884,9 @@ updategeom(void)
|
||||
memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo));
|
||||
XFree(info);
|
||||
nn = j;
|
||||
if (n <= nn) {
|
||||
for (i = 0; i < (nn - n); i++) { /* new monitors available */
|
||||
|
||||
/* new monitors if nn > n */
|
||||
for (i = n; i < nn; i++) {
|
||||
for (m = mons; m && m->next; m = m->next);
|
||||
if (m)
|
||||
m->next = createmon();
|
||||
@ -1870,8 +1895,8 @@ updategeom(void)
|
||||
}
|
||||
for (i = 0, m = mons; i < nn && m; m = m->next, i++)
|
||||
if (i >= n
|
||||
|| (unique[i].x_org != m->mx || unique[i].y_org != m->my
|
||||
|| unique[i].width != m->mw || unique[i].height != m->mh))
|
||||
|| unique[i].x_org != m->mx || unique[i].y_org != m->my
|
||||
|| unique[i].width != m->mw || unique[i].height != m->mh)
|
||||
{
|
||||
dirty = 1;
|
||||
m->num = i;
|
||||
@ -1881,13 +1906,11 @@ updategeom(void)
|
||||
m->mh = m->wh = unique[i].height;
|
||||
updatebarpos(m);
|
||||
}
|
||||
} else {
|
||||
/* less monitors available nn < n */
|
||||
/* removed monitors if n > nn */
|
||||
for (i = nn; i < n; i++) {
|
||||
for (m = mons; m && m->next; m = m->next);
|
||||
while (m->clients) {
|
||||
while ((c = m->clients)) {
|
||||
dirty = 1;
|
||||
c = m->clients;
|
||||
m->clients = c->next;
|
||||
detachstack(c);
|
||||
c->mon = mons;
|
||||
@ -1898,12 +1921,10 @@ updategeom(void)
|
||||
selmon = mons;
|
||||
cleanupmon(m);
|
||||
}
|
||||
}
|
||||
free(unique);
|
||||
} else
|
||||
#endif /* XINERAMA */
|
||||
/* default monitor setup */
|
||||
{
|
||||
{ /* default monitor setup */
|
||||
if (!mons)
|
||||
mons = createmon();
|
||||
if (mons->mw != sw || mons->mh != sh) {
|
||||
@ -1976,8 +1997,16 @@ updatesizehints(Client *c)
|
||||
c->maxa = (float)size.max_aspect.x / size.max_aspect.y;
|
||||
} else
|
||||
c->maxa = c->mina = 0.0;
|
||||
c->isfixed = (c->maxw && c->minw && c->maxh && c->minh
|
||||
&& c->maxw == c->minw && c->maxh == c->minh);
|
||||
c->isfixed = (c->maxw && c->maxh && c->maxw == c->minw && c->maxh == c->minh);
|
||||
c->hintsvalid = 1;
|
||||
}
|
||||
|
||||
void
|
||||
updatestatus(void)
|
||||
{
|
||||
if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
|
||||
strcpy(stext, "dwm-"VERSION);
|
||||
drawbar(selmon);
|
||||
}
|
||||
|
||||
void
|
||||
@ -1989,14 +2018,6 @@ updatetitle(Client *c)
|
||||
strcpy(c->name, broken);
|
||||
}
|
||||
|
||||
void
|
||||
updatestatus(void)
|
||||
{
|
||||
if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
|
||||
strcpy(stext, "dwm-"VERSION);
|
||||
drawbar(selmon);
|
||||
}
|
||||
|
||||
void
|
||||
updatewindowtype(Client *c)
|
||||
{
|
||||
@ -2102,7 +2123,7 @@ xerrordummy(Display *dpy, XErrorEvent *ee)
|
||||
int
|
||||
xerrorstart(Display *dpy, XErrorEvent *ee)
|
||||
{
|
||||
die("dwm: another window manager is already running\n");
|
||||
die("dwm: another window manager is already running");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -2111,11 +2132,9 @@ zoom(const Arg *arg)
|
||||
{
|
||||
Client *c = selmon->sel;
|
||||
|
||||
if (!selmon->lt[selmon->sellt]->arrange
|
||||
|| (selmon->sel && selmon->sel->isfloating))
|
||||
if (!selmon->lt[selmon->sellt]->arrange || !c || c->isfloating)
|
||||
return;
|
||||
if (c == nexttiled(selmon->clients))
|
||||
if (!c || !(c = nexttiled(c->next)))
|
||||
if (c == nexttiled(selmon->clients) && !(c = nexttiled(c->next)))
|
||||
return;
|
||||
pop(c);
|
||||
}
|
||||
@ -2124,15 +2143,19 @@ int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if (argc == 2 && !strcmp("-v", argv[1]))
|
||||
die("dwm-"VERSION "\n");
|
||||
die("dwm-"VERSION);
|
||||
else if (argc != 1)
|
||||
die("usage: dwm [-v]\n");
|
||||
die("usage: dwm [-v]");
|
||||
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
|
||||
fputs("warning: no locale support\n", stderr);
|
||||
if (!(dpy = XOpenDisplay(NULL)))
|
||||
die("dwm: cannot open display\n");
|
||||
die("dwm: cannot open display");
|
||||
checkotherwm();
|
||||
setup();
|
||||
#ifdef __OpenBSD__
|
||||
if (pledge("stdio rpath proc exec", NULL) == -1)
|
||||
die("pledge");
|
||||
#endif /* __OpenBSD__ */
|
||||
scan();
|
||||
run();
|
||||
cleanup();
|
||||
|
38
util.c
38
util.c
@ -1,4 +1,5 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -6,28 +7,31 @@
|
||||
|
||||
#include "util.h"
|
||||
|
||||
void
|
||||
die(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int saved_errno;
|
||||
|
||||
saved_errno = errno;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (fmt[0] && fmt[strlen(fmt)-1] == ':')
|
||||
fprintf(stderr, " %s", strerror(saved_errno));
|
||||
fputc('\n', stderr);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void *
|
||||
ecalloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
if (!(p = calloc(nmemb, size)))
|
||||
perror(NULL);
|
||||
die("calloc:");
|
||||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
die(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
|
||||
fputc(' ', stderr);
|
||||
perror(NULL);
|
||||
}
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
5
util.h
5
util.h
@ -3,6 +3,7 @@
|
||||
#define MAX(A, B) ((A) > (B) ? (A) : (B))
|
||||
#define MIN(A, B) ((A) < (B) ? (A) : (B))
|
||||
#define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B))
|
||||
#define LENGTH(X) (sizeof (X) / sizeof (X)[0])
|
||||
|
||||
void die(const char *errstr, ...);
|
||||
void *ecalloc(size_t, size_t);
|
||||
void die(const char *fmt, ...);
|
||||
void *ecalloc(size_t nmemb, size_t size);
|
||||
|
Loading…
x
Reference in New Issue
Block a user