Compare commits
58 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
c796eda755 | ||
fb6d4c737d | |||
640490b125 | |||
cb79727525 | |||
d6ebef5d52 | |||
a60c07be3d | |||
408a31be30 | |||
f2fb808054 | |||
8d585297ec | |||
f5f2a5e086 | |||
7d757edb8b | |||
e0790b10c1 | |||
545cbda383 | |||
b8e3155196 | |||
f2e1738e6a | |||
4d9d5e5fb4 | |||
6beb5456da | |||
b76a6978b4 | |||
e7bca4a111 | |||
4456308b82 | |||
35125c582f | |||
|
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 |
1
LICENSE
1
LICENSE
@ -17,6 +17,7 @@ MIT/X Consortium License
|
||||
© 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"),
|
||||
|
10
Makefile
10
Makefile
@ -6,13 +6,7 @@ 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:
|
||||
${CC} -c ${CFLAGS} $<
|
||||
@ -48,4 +42,4 @@ uninstall:
|
||||
rm -f ${DESTDIR}${PREFIX}/bin/dwm\
|
||||
${DESTDIR}${MANPREFIX}/man1/dwm.1
|
||||
|
||||
.PHONY: all options clean dist install uninstall
|
||||
.PHONY: all clean dist install uninstall
|
||||
|
@ -1,25 +1,28 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
|
||||
/* appearance */
|
||||
static const unsigned int borderpx = 1; /* border pixel of windows */
|
||||
static const unsigned int borderpx = 2; /* 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] = {
|
||||
static const char *fonts[] = { "monospace:pixelsize=12:antialias=true:autohint=true" };
|
||||
|
||||
static const char col_black[] = "#000000";
|
||||
static const char col_darkgray[] = "#101010";
|
||||
static const char *const col_wired[] = {
|
||||
"#C3B495",
|
||||
"#CC838C",
|
||||
"#B66578",
|
||||
"#824856"
|
||||
};
|
||||
static const char *colors[][3] = {
|
||||
/* fg bg border */
|
||||
[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
|
||||
[SchemeSel] = { col_gray4, col_cyan, col_cyan },
|
||||
[SchemeNorm] = {col_wired[1], col_black, col_wired[0]},
|
||||
[SchemeSel] = {col_wired[1], col_darkgray, col_wired[2]},
|
||||
};
|
||||
|
||||
/* tagging */
|
||||
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
||||
static const char *tags[] = { "α", "β", "γ", "δ", "ε", "ζ" };
|
||||
|
||||
static const Rule rules[] = {
|
||||
/* xprop(1):
|
||||
@ -27,24 +30,27 @@ static const Rule rules[] = {
|
||||
* WM_NAME(STRING) = title
|
||||
*/
|
||||
/* class instance title tags mask isfloating monitor */
|
||||
{ "Gimp", NULL, NULL, 0, 1, -1 },
|
||||
{ "Firefox", NULL, NULL, 1 << 8, 0, -1 },
|
||||
{ NULL, NULL, NULL, 0, False, -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 int resizehints = 0; /* 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 */
|
||||
{ "[]=", tile }, /* first entry is default */
|
||||
{ "><>", NULL }, /* no layout function means floating behavior */
|
||||
{ "[M]", monocle },
|
||||
{ "TTT", bstack },
|
||||
{ "===", bstackhoriz },
|
||||
{ "-|_", gaplessgrid },
|
||||
};
|
||||
|
||||
/* key definitions */
|
||||
#define MODKEY Mod1Mask
|
||||
#define MODKEY Mod4Mask
|
||||
#define TAGKEYS(KEY,TAG) \
|
||||
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \
|
||||
{ MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
|
||||
@ -53,17 +59,40 @@ static const Layout layouts[] = {
|
||||
|
||||
/* helper for spawning shell commands in the pre dwm-5.0 fashion */
|
||||
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
|
||||
#define STCMD(cmd) { .v = (const char*[]){ "/usr/bin/st", "-e", cmd, NULL } }
|
||||
#define MPVSOCK(cmd) SHCMD("echo '" cmd "' | socat -u - ~/.mpvsock")
|
||||
|
||||
/* 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 *dmenucmd[] = { "dmenu_run", "-m", dmenumon, NULL };
|
||||
static const char *termcmd[] = { "st", NULL };
|
||||
static const char *lock[] = { "slock", 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 } },
|
||||
{ MODKEY, XK_b, togglebar, {0} },
|
||||
|
||||
/* general commands */
|
||||
{ MODKEY, XK_space, spawn, {.v = dmenucmd } },
|
||||
{ MODKEY, XK_c, spawn, {.v = termcmd } },
|
||||
{ MODKEY|ShiftMask, XK_l, spawn, {.v = lock } },
|
||||
|
||||
/* screenshots */
|
||||
{ 0, XK_Print, spawn, SHCMD("import -silent /tmp/scr-$(date +%T).jpg") },
|
||||
{ MODKEY, XK_Print, spawn, SHCMD("import -window root -silent /tmp/scr-$(date +%T).jpg") },
|
||||
|
||||
/* terminal software */
|
||||
{ MODKEY|ShiftMask, XK_v, spawn, STCMD("pulsemixer") },
|
||||
{ MODKEY, XK_f, spawn, STCMD("nnn") },
|
||||
|
||||
/* dmenu scripts */
|
||||
{ MODKEY, XK_y, spawn, SHCMD("~/Sources/Scripts/dmenu/passman/script.zsh") },
|
||||
|
||||
/* mpv controls */
|
||||
{ 0, XF86XK_AudioPlay, spawn, MPVSOCK("keypress space") },
|
||||
{ 0, XF86XK_AudioPrev, spawn, MPVSOCK("playlist-prev") },
|
||||
{ 0, XF86XK_AudioNext, spawn, MPVSOCK("playlist-next") },
|
||||
|
||||
{ MODKEY|ShiftMask, XK_b, togglebar, {0} },
|
||||
{ MODKEY, XK_j, focusstack, {.i = +1 } },
|
||||
{ MODKEY, XK_k, focusstack, {.i = -1 } },
|
||||
{ MODKEY, XK_i, incnmaster, {.i = +1 } },
|
||||
@ -73,10 +102,13 @@ static Key keys[] = {
|
||||
{ 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_t, setlayout, {.v = &layouts[0]} },
|
||||
{ MODKEY|ShiftMask, XK_f, setlayout, {.v = &layouts[1]} },
|
||||
{ MODKEY|ShiftMask, XK_m, setlayout, {.v = &layouts[2]} },
|
||||
{ MODKEY|ShiftMask, XK_u, setlayout, {.v = &layouts[3]} },
|
||||
{ MODKEY|ShiftMask, XK_o, setlayout, {.v = &layouts[4]} },
|
||||
{ MODKEY|ShiftMask, XK_g, setlayout, {.v = &layouts[5]} },
|
||||
{ MODKEY|ShiftMask, XK_d, setlayout, {0} },
|
||||
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
|
||||
{ MODKEY, XK_0, view, {.ui = ~0 } },
|
||||
{ MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
|
||||
@ -90,15 +122,12 @@ static Key keys[] = {
|
||||
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[] = {
|
||||
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.2
|
||||
VERSION = 6.5
|
||||
|
||||
# Customize below to fit your system
|
||||
|
||||
@ -19,13 +19,14 @@ 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_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -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 = ${LIBS}
|
||||
|
102
drw.c
102
drw.c
@ -133,19 +133,6 @@ xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern)
|
||||
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;
|
||||
@ -251,12 +238,10 @@ drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int
|
||||
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;
|
||||
int i, ty, ellipsis_x = 0;
|
||||
unsigned int tmpw, ew, ellipsis_w = 0, ellipsis_len;
|
||||
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;
|
||||
@ -264,13 +249,17 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
|
||||
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. */
|
||||
enum { nomatches_len = 64 };
|
||||
static struct { long codepoint[nomatches_len]; unsigned int idx; } nomatches;
|
||||
static unsigned int ellipsis_width = 0;
|
||||
|
||||
if (!drw || (render && !drw->scheme) || !text || !drw->fonts)
|
||||
if (!drw || (render && (!drw->scheme || !w)) || !text || !drw->fonts)
|
||||
return 0;
|
||||
|
||||
if (!render) {
|
||||
w = ~w;
|
||||
w = invert ? invert : ~invert;
|
||||
} else {
|
||||
XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel);
|
||||
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
|
||||
@ -282,8 +271,10 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
|
||||
}
|
||||
|
||||
usedfont = drw->fonts;
|
||||
if (!ellipsis_width && render)
|
||||
ellipsis_width = drw_fontset_getwidth(drw, "...");
|
||||
while (1) {
|
||||
utf8strlen = 0;
|
||||
ew = ellipsis_len = utf8strlen = 0;
|
||||
utf8str = text;
|
||||
nextfont = NULL;
|
||||
while (*text) {
|
||||
@ -291,9 +282,27 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
|
||||
for (curfont = drw->fonts; curfont; curfont = curfont->next) {
|
||||
charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint);
|
||||
if (charexists) {
|
||||
if (curfont == usedfont) {
|
||||
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) {
|
||||
utf8strlen += utf8charlen;
|
||||
text += utf8charlen;
|
||||
ew += tmpw;
|
||||
} else {
|
||||
nextfont = curfont;
|
||||
}
|
||||
@ -301,36 +310,25 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
|
||||
}
|
||||
}
|
||||
|
||||
if (!charexists || nextfont)
|
||||
if (overflow || !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 (render) {
|
||||
ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent;
|
||||
XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg],
|
||||
usedfont->xfont, x, ty, (XftChar8 *)utf8str, utf8strlen);
|
||||
}
|
||||
x += ew;
|
||||
w -= ew;
|
||||
}
|
||||
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;
|
||||
@ -340,6 +338,12 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
|
||||
* character must be drawn. */
|
||||
charexists = 1;
|
||||
|
||||
for (i = 0; i < nomatches_len; ++i) {
|
||||
/* avoid calling XftFontMatch if we know we won't find a match */
|
||||
if (utf8codepoint == nomatches.codepoint[i])
|
||||
goto no_match;
|
||||
}
|
||||
|
||||
fccharset = FcCharSetCreate();
|
||||
FcCharSetAddChar(fccharset, utf8codepoint);
|
||||
|
||||
@ -351,7 +355,6 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
|
||||
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);
|
||||
@ -368,6 +371,8 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
|
||||
curfont->next = usedfont;
|
||||
} else {
|
||||
xfont_free(usedfont);
|
||||
nomatches.codepoint[++nomatches.idx % nomatches_len] = utf8codepoint;
|
||||
no_match:
|
||||
usedfont = drw->fonts;
|
||||
}
|
||||
}
|
||||
@ -397,6 +402,15 @@ drw_fontset_getwidth(Drw *drw, const char *text)
|
||||
return drw_text(drw, 0, 0, 0, 0, 0, text, 0);
|
||||
}
|
||||
|
||||
unsigned int
|
||||
drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
void
|
||||
drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h)
|
||||
{
|
||||
|
1
drw.h
1
drw.h
@ -35,6 +35,7 @@ void drw_free(Drw *drw);
|
||||
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);
|
||||
|
||||
/* Colorscheme abstraction */
|
||||
|
397
dwm.c
397
dwm.c
@ -36,6 +36,7 @@
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xproto.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/XF86keysym.h>
|
||||
#ifdef XINERAMA
|
||||
#include <X11/extensions/Xinerama.h>
|
||||
#endif /* XINERAMA */
|
||||
@ -89,7 +90,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;
|
||||
@ -111,6 +112,7 @@ typedef struct {
|
||||
void (*arrange)(Monitor *);
|
||||
} Layout;
|
||||
|
||||
typedef struct Pertag Pertag;
|
||||
struct Monitor {
|
||||
char ltsymbol[16];
|
||||
float mfact;
|
||||
@ -130,6 +132,7 @@ struct Monitor {
|
||||
Monitor *next;
|
||||
Window barwin;
|
||||
const Layout *lt[2];
|
||||
Pertag *pertag;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
@ -185,7 +188,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);
|
||||
@ -205,11 +208,10 @@ 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);
|
||||
@ -234,13 +236,16 @@ static int xerror(Display *dpy, XErrorEvent *ee);
|
||||
static int xerrordummy(Display *dpy, XErrorEvent *ee);
|
||||
static int xerrorstart(Display *dpy, XErrorEvent *ee);
|
||||
static void zoom(const Arg *arg);
|
||||
static void bstack(Monitor *m);
|
||||
static void bstackhoriz(Monitor *m);
|
||||
static void gaplessgrid(Monitor *m);
|
||||
|
||||
/* variables */
|
||||
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;
|
||||
@ -272,6 +277,15 @@ static Window root, wmcheckwin;
|
||||
/* configuration, allows nested code to access above variables */
|
||||
#include "config.h"
|
||||
|
||||
struct Pertag {
|
||||
unsigned int curtag, prevtag; /* current and previous tag */
|
||||
int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
|
||||
float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */
|
||||
unsigned int sellts[LENGTH(tags) + 1]; /* selected layouts */
|
||||
const Layout *ltidxs[LENGTH(tags) + 1][2]; /* matrix of tags and layouts indexes */
|
||||
int showbars[LENGTH(tags) + 1]; /* display bar for the current tag */
|
||||
};
|
||||
|
||||
/* compile-time check if all tags fit into an unsigned int bit array. */
|
||||
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
|
||||
|
||||
@ -345,6 +359,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 */
|
||||
@ -432,13 +448,19 @@ buttonpress(XEvent *e)
|
||||
}
|
||||
if (ev->window == selmon->barwin) {
|
||||
i = x = 0;
|
||||
do
|
||||
unsigned int occ = 0;
|
||||
for(c = m->clients; c; c = c->next)
|
||||
occ |= c->tags;
|
||||
do {
|
||||
/* do not reserve space for vacant tags */
|
||||
if(!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
|
||||
continue;
|
||||
x += TEXTW(tags[i]);
|
||||
while (ev->x >= x && ++i < LENGTH(tags));
|
||||
} while (ev->x >= x && ++i < LENGTH(tags));
|
||||
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 - (int)TEXTW(stext))
|
||||
click = ClkStatusText;
|
||||
@ -487,6 +509,7 @@ cleanup(void)
|
||||
drw_cur_free(drw, cursor[i]);
|
||||
for (i = 0; i < LENGTH(colors); i++)
|
||||
free(scheme[i]);
|
||||
free(scheme);
|
||||
XDestroyWindow(dpy, wmcheckwin);
|
||||
drw_free(drw);
|
||||
XSync(dpy, False);
|
||||
@ -632,6 +655,7 @@ Monitor *
|
||||
createmon(void)
|
||||
{
|
||||
Monitor *m;
|
||||
unsigned int i;
|
||||
|
||||
m = ecalloc(1, sizeof(Monitor));
|
||||
m->tagset[0] = m->tagset[1] = 1;
|
||||
@ -642,6 +666,20 @@ createmon(void)
|
||||
m->lt[0] = &layouts[0];
|
||||
m->lt[1] = &layouts[1 % LENGTH(layouts)];
|
||||
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
|
||||
m->pertag = ecalloc(1, sizeof(Pertag));
|
||||
m->pertag->curtag = m->pertag->prevtag = 1;
|
||||
|
||||
for (i = 0; i <= LENGTH(tags); i++) {
|
||||
m->pertag->nmasters[i] = m->nmaster;
|
||||
m->pertag->mfacts[i] = m->mfact;
|
||||
|
||||
m->pertag->ltidxs[i][0] = m->lt[0];
|
||||
m->pertag->ltidxs[i][1] = m->lt[1];
|
||||
m->pertag->sellts[i] = m->sellt;
|
||||
|
||||
m->pertag->showbars[i] = m->showbar;
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
@ -702,6 +740,9 @@ drawbar(Monitor *m)
|
||||
unsigned int i, occ = 0, urg = 0;
|
||||
Client *c;
|
||||
|
||||
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]);
|
||||
@ -716,6 +757,9 @@ drawbar(Monitor *m)
|
||||
}
|
||||
x = 0;
|
||||
for (i = 0; i < LENGTH(tags); i++) {
|
||||
/* do not draw vacant tags */
|
||||
if(!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
|
||||
continue;
|
||||
w = TEXTW(tags[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);
|
||||
@ -725,7 +769,7 @@ drawbar(Monitor *m)
|
||||
urg & 1 << i);
|
||||
x += w;
|
||||
}
|
||||
w = blw = TEXTW(m->ltsymbol);
|
||||
w = TEXTW(m->ltsymbol);
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
|
||||
|
||||
@ -835,7 +879,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);
|
||||
@ -912,13 +956,11 @@ gettextprop(Window w, Atom atom, char *text, unsigned int size)
|
||||
text[0] = '\0';
|
||||
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) {
|
||||
strncpy(text, *list, size - 1);
|
||||
XFreeStringList(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);
|
||||
@ -951,23 +993,33 @@ 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);
|
||||
for (i = 0; i < LENGTH(keys); i++)
|
||||
if ((code = XKeysymToKeycode(dpy, keys[i].keysym)))
|
||||
for (j = 0; j < LENGTH(modifiers); j++)
|
||||
XGrabKey(dpy, code, keys[i].mod | modifiers[j], root,
|
||||
True, GrabModeAsync, GrabModeAsync);
|
||||
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++)
|
||||
/* skip modifier codes, we do that ourselves */
|
||||
if (keys[i].keysym == syms[(k - start) * skip])
|
||||
for (j = 0; j < LENGTH(modifiers); j++)
|
||||
XGrabKey(dpy, k,
|
||||
keys[i].mod | modifiers[j],
|
||||
root, True,
|
||||
GrabModeAsync, GrabModeAsync);
|
||||
XFree(syms);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
incnmaster(const Arg *arg)
|
||||
{
|
||||
selmon->nmaster = MAX(selmon->nmaster + arg->i, 0);
|
||||
selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->nmaster + arg->i, 0);
|
||||
arrange(selmon);
|
||||
}
|
||||
|
||||
@ -1040,14 +1092,12 @@ manage(Window w, XWindowAttributes *wa)
|
||||
applyrules(c);
|
||||
}
|
||||
|
||||
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;
|
||||
@ -1093,9 +1143,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);
|
||||
@ -1229,7 +1277,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);
|
||||
@ -1283,6 +1331,13 @@ resizeclient(Client *c, int x, int y, int w, int h)
|
||||
c->oldw = c->w; c->w = wc.width = w;
|
||||
c->oldh = c->h; c->h = wc.height = h;
|
||||
wc.border_width = c->bw;
|
||||
if (((nexttiled(c->mon->clients) == c && !nexttiled(c->next))
|
||||
|| &monocle == c->mon->lt[c->mon->sellt]->arrange)
|
||||
&& !c->isfullscreen && !c->isfloating) {
|
||||
c->w = wc.width += c->bw * 2;
|
||||
c->h = wc.height += c->bw * 2;
|
||||
wc.border_width = 0;
|
||||
}
|
||||
XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
|
||||
configure(c);
|
||||
XSync(dpy, False);
|
||||
@ -1502,9 +1557,9 @@ void
|
||||
setlayout(const Arg *arg)
|
||||
{
|
||||
if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
|
||||
selmon->sellt ^= 1;
|
||||
selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag] ^= 1;
|
||||
if (arg && arg->v)
|
||||
selmon->lt[selmon->sellt] = (Layout *)arg->v;
|
||||
selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] = (Layout *)arg->v;
|
||||
strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
|
||||
if (selmon->sel)
|
||||
arrange(selmon);
|
||||
@ -1523,7 +1578,7 @@ setmfact(const Arg *arg)
|
||||
f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
|
||||
if (f < 0.05 || f > 0.95)
|
||||
return;
|
||||
selmon->mfact = f;
|
||||
selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag] = f;
|
||||
arrange(selmon);
|
||||
}
|
||||
|
||||
@ -1533,9 +1588,16 @@ 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);
|
||||
@ -1597,7 +1659,6 @@ setup(void)
|
||||
focus(NULL);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
seturgent(Client *c, int urg)
|
||||
{
|
||||
@ -1629,27 +1690,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]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1702,7 +1761,7 @@ tile(Monitor *m)
|
||||
void
|
||||
togglebar(const Arg *arg)
|
||||
{
|
||||
selmon->showbar = !selmon->showbar;
|
||||
selmon->showbar = selmon->pertag->showbars[selmon->pertag->curtag] = !selmon->showbar;
|
||||
updatebarpos(selmon);
|
||||
XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
|
||||
arrange(selmon);
|
||||
@ -1741,9 +1800,33 @@ void
|
||||
toggleview(const Arg *arg)
|
||||
{
|
||||
unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
|
||||
int i;
|
||||
|
||||
if (newtagset) {
|
||||
selmon->tagset[selmon->seltags] = newtagset;
|
||||
|
||||
if (newtagset == ~0) {
|
||||
selmon->pertag->prevtag = selmon->pertag->curtag;
|
||||
selmon->pertag->curtag = 0;
|
||||
}
|
||||
|
||||
/* test if the user did not select the same tag */
|
||||
if (!(newtagset & 1 << (selmon->pertag->curtag - 1))) {
|
||||
selmon->pertag->prevtag = selmon->pertag->curtag;
|
||||
for (i = 0; !(newtagset & 1 << i); i++) ;
|
||||
selmon->pertag->curtag = i + 1;
|
||||
}
|
||||
|
||||
/* apply settings for this view */
|
||||
selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
|
||||
selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
|
||||
selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
|
||||
selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
|
||||
selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
|
||||
|
||||
if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
|
||||
togglebar(NULL);
|
||||
|
||||
focus(NULL);
|
||||
arrange(selmon);
|
||||
}
|
||||
@ -1774,6 +1857,7 @@ unmanage(Client *c, int destroyed)
|
||||
wc.border_width = c->oldbw;
|
||||
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);
|
||||
@ -1837,7 +1921,7 @@ updatebarpos(Monitor *m)
|
||||
}
|
||||
|
||||
void
|
||||
updateclientlist()
|
||||
updateclientlist(void)
|
||||
{
|
||||
Client *c;
|
||||
Monitor *m;
|
||||
@ -1871,42 +1955,42 @@ updategeom(void)
|
||||
memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo));
|
||||
XFree(info);
|
||||
nn = j;
|
||||
if (n <= nn) { /* new monitors available */
|
||||
for (i = 0; i < (nn - n); i++) {
|
||||
for (m = mons; m && m->next; m = m->next);
|
||||
if (m)
|
||||
m->next = createmon();
|
||||
else
|
||||
mons = createmon();
|
||||
|
||||
/* 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();
|
||||
else
|
||||
mons = createmon();
|
||||
}
|
||||
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)
|
||||
{
|
||||
dirty = 1;
|
||||
m->num = i;
|
||||
m->mx = m->wx = unique[i].x_org;
|
||||
m->my = m->wy = unique[i].y_org;
|
||||
m->mw = m->ww = unique[i].width;
|
||||
m->mh = m->wh = unique[i].height;
|
||||
updatebarpos(m);
|
||||
}
|
||||
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)
|
||||
{
|
||||
dirty = 1;
|
||||
m->num = i;
|
||||
m->mx = m->wx = unique[i].x_org;
|
||||
m->my = m->wy = unique[i].y_org;
|
||||
m->mw = m->ww = unique[i].width;
|
||||
m->mh = m->wh = unique[i].height;
|
||||
updatebarpos(m);
|
||||
}
|
||||
} else { /* less monitors available nn < n */
|
||||
for (i = nn; i < n; i++) {
|
||||
for (m = mons; m && m->next; m = m->next);
|
||||
while ((c = m->clients)) {
|
||||
dirty = 1;
|
||||
m->clients = c->next;
|
||||
detachstack(c);
|
||||
c->mon = mons;
|
||||
attach(c);
|
||||
attachstack(c);
|
||||
}
|
||||
if (m == selmon)
|
||||
selmon = mons;
|
||||
cleanupmon(m);
|
||||
/* removed monitors if n > nn */
|
||||
for (i = nn; i < n; i++) {
|
||||
for (m = mons; m && m->next; m = m->next);
|
||||
while ((c = m->clients)) {
|
||||
dirty = 1;
|
||||
m->clients = c->next;
|
||||
detachstack(c);
|
||||
c->mon = mons;
|
||||
attach(c);
|
||||
attachstack(c);
|
||||
}
|
||||
if (m == selmon)
|
||||
selmon = mons;
|
||||
cleanupmon(m);
|
||||
}
|
||||
free(unique);
|
||||
} else
|
||||
@ -1985,6 +2069,7 @@ updatesizehints(Client *c)
|
||||
} else
|
||||
c->maxa = c->mina = 0.0;
|
||||
c->isfixed = (c->maxw && c->maxh && c->maxw == c->minw && c->maxh == c->minh);
|
||||
c->hintsvalid = 1;
|
||||
}
|
||||
|
||||
void
|
||||
@ -2038,11 +2123,37 @@ updatewmhints(Client *c)
|
||||
void
|
||||
view(const Arg *arg)
|
||||
{
|
||||
int i;
|
||||
unsigned int tmptag;
|
||||
|
||||
if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
|
||||
return;
|
||||
selmon->seltags ^= 1; /* toggle sel tagset */
|
||||
if (arg->ui & TAGMASK)
|
||||
if (arg->ui & TAGMASK) {
|
||||
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
|
||||
selmon->pertag->prevtag = selmon->pertag->curtag;
|
||||
|
||||
if (arg->ui == ~0)
|
||||
selmon->pertag->curtag = 0;
|
||||
else {
|
||||
for (i = 0; !(arg->ui & 1 << i); i++) ;
|
||||
selmon->pertag->curtag = i + 1;
|
||||
}
|
||||
} else {
|
||||
tmptag = selmon->pertag->prevtag;
|
||||
selmon->pertag->prevtag = selmon->pertag->curtag;
|
||||
selmon->pertag->curtag = tmptag;
|
||||
}
|
||||
|
||||
selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
|
||||
selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
|
||||
selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
|
||||
selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
|
||||
selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
|
||||
|
||||
if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
|
||||
togglebar(NULL);
|
||||
|
||||
focus(NULL);
|
||||
arrange(selmon);
|
||||
}
|
||||
@ -2118,12 +2229,10 @@ 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) && !(c = nexttiled(c->next)))
|
||||
return;
|
||||
if (c == nexttiled(selmon->clients))
|
||||
if (!c || !(c = nexttiled(c->next)))
|
||||
return;
|
||||
pop(c);
|
||||
}
|
||||
|
||||
@ -2150,3 +2259,101 @@ main(int argc, char *argv[])
|
||||
XCloseDisplay(dpy);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static void
|
||||
bstack(Monitor *m) {
|
||||
int w, h, mh, mx, tx, ty, tw;
|
||||
unsigned int i, n;
|
||||
Client *c;
|
||||
|
||||
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
|
||||
if (n == 0)
|
||||
return;
|
||||
if (n > m->nmaster) {
|
||||
mh = m->nmaster ? m->mfact * m->wh : 0;
|
||||
tw = m->ww / (n - m->nmaster);
|
||||
ty = m->wy + mh;
|
||||
} else {
|
||||
mh = m->wh;
|
||||
tw = m->ww;
|
||||
ty = m->wy;
|
||||
}
|
||||
for (i = mx = 0, tx = m->wx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
|
||||
if (i < m->nmaster) {
|
||||
w = (m->ww - mx) / (MIN(n, m->nmaster) - i);
|
||||
resize(c, m->wx + mx, m->wy, w - (2 * c->bw), mh - (2 * c->bw), 0);
|
||||
mx += WIDTH(c);
|
||||
} else {
|
||||
h = m->wh - mh;
|
||||
resize(c, tx, ty, tw - (2 * c->bw), h - (2 * c->bw), 0);
|
||||
if (tw != m->ww)
|
||||
tx += WIDTH(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
bstackhoriz(Monitor *m) {
|
||||
int w, mh, mx, tx, ty, th;
|
||||
unsigned int i, n;
|
||||
Client *c;
|
||||
|
||||
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
|
||||
if (n == 0)
|
||||
return;
|
||||
if (n > m->nmaster) {
|
||||
mh = m->nmaster ? m->mfact * m->wh : 0;
|
||||
th = (m->wh - mh) / (n - m->nmaster);
|
||||
ty = m->wy + mh;
|
||||
} else {
|
||||
th = mh = m->wh;
|
||||
ty = m->wy;
|
||||
}
|
||||
for (i = mx = 0, tx = m->wx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
|
||||
if (i < m->nmaster) {
|
||||
w = (m->ww - mx) / (MIN(n, m->nmaster) - i);
|
||||
resize(c, m->wx + mx, m->wy, w - (2 * c->bw), mh - (2 * c->bw), 0);
|
||||
mx += WIDTH(c);
|
||||
} else {
|
||||
resize(c, tx, ty, m->ww - (2 * c->bw), th - (2 * c->bw), 0);
|
||||
if (th != m->wh)
|
||||
ty += HEIGHT(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gaplessgrid(Monitor *m) {
|
||||
unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch;
|
||||
Client *c;
|
||||
|
||||
for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) ;
|
||||
if(n == 0)
|
||||
return;
|
||||
|
||||
/* grid dimensions */
|
||||
for(cols = 0; cols <= n/2; cols++)
|
||||
if(cols*cols >= n)
|
||||
break;
|
||||
if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
|
||||
cols = 2;
|
||||
rows = n/cols;
|
||||
|
||||
/* window geometries */
|
||||
cw = cols ? m->ww / cols : m->ww;
|
||||
cn = 0; /* current column number */
|
||||
rn = 0; /* current row number */
|
||||
for(i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
|
||||
if(i/rows + 1 > cols - n%cols)
|
||||
rows = n/cols + 1;
|
||||
ch = rows ? m->wh / rows : m->wh;
|
||||
cx = m->wx + cn*cw;
|
||||
cy = m->wy + rn*ch;
|
||||
resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False);
|
||||
rn++;
|
||||
if(rn >= rows) {
|
||||
rn = 0;
|
||||
cn++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
23
util.c
23
util.c
@ -6,18 +6,9 @@
|
||||
|
||||
#include "util.h"
|
||||
|
||||
void *
|
||||
ecalloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
if (!(p = calloc(nmemb, size)))
|
||||
die("calloc:");
|
||||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
die(const char *fmt, ...) {
|
||||
die(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
@ -33,3 +24,13 @@ die(const char *fmt, ...) {
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void *
|
||||
ecalloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
if (!(p = calloc(nmemb, size)))
|
||||
die("calloc:");
|
||||
return p;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user