Compare commits

...

6 Commits

Author SHA1 Message Date
Michael Peters
b0260ea8e8 small updates 2022-09-15 21:35:57 -07:00
Michael Peters
fde9a1eaf2 add fix removeborder patch 2022-06-26 18:25:06 -05:00
Michael Peters
d6a5f8ab4d Fix noborders when sending client to empty monitor 2022-06-26 15:46:30 -05:00
Michael Peters
857ab9379f Merge branch 'master' into michael 2022-06-26 14:16:33 -05:00
Michael Peters
2268774348 config changes and gaming window updates 2022-06-26 14:15:59 -05:00
Hiltjo Posthuma
d3f93c7c1a sync latest drw.{c,h} changes from dmenu 2022-05-10 19:07:56 +02:00
6 changed files with 147 additions and 56 deletions

View File

@ -26,7 +26,7 @@ static const unsigned int borderalpha = OPAQUE;
static const char *colors[][3] = { static const char *colors[][3] = {
/* fg bg border */ /* fg bg border */
[SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, [SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
[SchemeSelMon] = { col_gray4, col_green, col_cyan }, // Colorscheme for the bar on the selected monitor [SchemeSelMon] = { col_gray4, col_green, col_cyan }, // Colorscheme for the bar on the selected monitor
[SchemeSel] = { col_gray4, col_cyan, col_cyan }, [SchemeSel] = { col_gray4, col_cyan, col_cyan },
[SchemeUrg] = { col_gray4, col_cyan, col_urgborder }, [SchemeUrg] = { col_gray4, col_cyan, col_urgborder },
}; };
@ -49,10 +49,14 @@ static const Rule rules[] = {
* WM_CLASS(STRING) = instance, class * WM_CLASS(STRING) = instance, class
* WM_NAME(STRING) = title * WM_NAME(STRING) = title
*/ */
/* class instance title tags mask isfloating isterminal noswallow monitor */ /* class instance title tags mask isfloating isterminal noswallow monitor */
{ "st-256color", NULL, NULL, 0, 0, 1, 0, -1 }, { "st-256color", NULL, NULL, 0, 0, 1, 0, -1 },
{ NULL, NULL, "Event Tester", 0, 0, 0, 1, -1 }, /* xev */ { "steam_app_1182480", NULL, NULL, 0, 1, 0, 0, -1 }, /* battlefield 4 origin launcher */
{ "Xephyr", NULL, NULL, 0, 0, 0, 1, -1 }, /* lightdm --test-mode */ { NULL, NULL, "cordis", 0, 0, 0, 1, -1 }, /* cordis / dev electron apps */
{ "nwjs", NULL, NULL, 0, 0, 0, 1, -1 }, /* NW.js apps */
{ NULL, NULL, "Tauri App", 0, 0, 0, 1, -1 }, /* Tauri Testing App */
{ NULL, NULL, "Event Tester", 0, 0, 0, 1, -1 }, /* xev */
{ "Xephyr", NULL, NULL, 0, 0, 0, 1, -1 }, /* lightdm --test-mode */
}; };
/* layout(s) */ /* layout(s) */
@ -97,18 +101,22 @@ static const Layout layouts[] = {
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ 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, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char *termcmd[] = { "st", NULL }; static const char *termcmd[] = { "st", NULL };
static const char *browsercmd[] = { "chromium", NULL };
static const char *discord_sandboxed_mute_cmd[] = { "pkill", "--oldest", "-SIGUSR2", "discord-sand", NULL }; /* For some reason, if we do discord-sandboxed, pgrep doesn't find the program */ static const char *discord_sandboxed_mute_cmd[] = { "pkill", "--oldest", "-SIGUSR2", "discord-sand", NULL }; /* For some reason, if we do discord-sandboxed, pgrep doesn't find the program */
static const char *screenshotcmd[] = { "/disks/ssd-860-1tb/scripts/screenshot.sh" }; static const char *screenshotcmd[] = { "/home/michael/scripts/screenshot" };
// See /usr/include/X11/keysymdef.h for a list of keycodes // See /usr/include/X11/keysymdef.h for a list of keycodes
static Key keys[] = { static Key keys[] = {
/* modifier key function argument */ /* modifier key function argument */
{ MODKEY, XK_p, spawn, {.v = dmenucmd } }, { MODKEY, XK_p, spawn, {.v = dmenucmd } },
{ MODKEY, XK_b, spawn, {.v = browsercmd } },
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
{ NULL, XK_Pause, spawn, {.v = discord_sandboxed_mute_cmd } }, { NULL, XK_Pause, spawn, {.v = discord_sandboxed_mute_cmd } },
{ NULL, XK_Print, spawn, {.v = screenshotcmd } }, { NULL, XK_Print, spawn, {.v = screenshotcmd } },
{ MODKEY, XK_b, togglebar, {0} }, { MODKEY|ShiftMask, XK_c, killclient, {0} },
{ MODKEY|ShiftMask, XK_b, togglebar, {0} },
{ MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_j, focusstack, {.i = +1 } },
{ MODKEY, XK_k, focusstack, {.i = -1 } }, { MODKEY, XK_k, focusstack, {.i = -1 } },
{ MODKEY, XK_i, incnmaster, {.i = +1 } }, { MODKEY, XK_i, incnmaster, {.i = +1 } },
@ -117,26 +125,26 @@ static Key keys[] = {
{ MODKEY, XK_l, setmfact, {.f = +0.05} }, { MODKEY, XK_l, setmfact, {.f = +0.05} },
{ MODKEY, XK_Return, zoom, {0} }, { MODKEY, XK_Return, zoom, {0} },
// Vanity Gaps Modifiers // Vanity Gaps Modifiers
{ MODKEY|Mod4Mask, XK_u, incrgaps, {.i = +1 } }, // { MODKEY|Mod4Mask, XK_u, incrgaps, {.i = +1 } },
{ MODKEY|Mod4Mask|ShiftMask, XK_u, incrgaps, {.i = -1 } }, // { MODKEY|Mod4Mask|ShiftMask, XK_u, incrgaps, {.i = -1 } },
{ MODKEY|Mod4Mask, XK_i, incrigaps, {.i = +1 } }, // { MODKEY|Mod4Mask, XK_i, incrigaps, {.i = +1 } },
{ MODKEY|Mod4Mask|ShiftMask, XK_i, incrigaps, {.i = -1 } }, // { MODKEY|Mod4Mask|ShiftMask, XK_i, incrigaps, {.i = -1 } },
{ MODKEY|Mod4Mask, XK_o, incrogaps, {.i = +1 } }, // { MODKEY|Mod4Mask, XK_o, incrogaps, {.i = +1 } },
{ MODKEY|Mod4Mask|ShiftMask, XK_o, incrogaps, {.i = -1 } }, // { MODKEY|Mod4Mask|ShiftMask, XK_o, incrogaps, {.i = -1 } },
{ MODKEY|Mod4Mask, XK_6, incrihgaps, {.i = +1 } }, // { MODKEY|Mod4Mask, XK_6, incrihgaps, {.i = +1 } },
{ MODKEY|Mod4Mask|ShiftMask, XK_6, incrihgaps, {.i = -1 } }, // { MODKEY|Mod4Mask|ShiftMask, XK_6, incrihgaps, {.i = -1 } },
{ MODKEY|Mod4Mask, XK_7, incrivgaps, {.i = +1 } }, // { MODKEY|Mod4Mask, XK_7, incrivgaps, {.i = +1 } },
{ MODKEY|Mod4Mask|ShiftMask, XK_7, incrivgaps, {.i = -1 } }, // { MODKEY|Mod4Mask|ShiftMask, XK_7, incrivgaps, {.i = -1 } },
{ MODKEY|Mod4Mask, XK_8, incrohgaps, {.i = +1 } }, // { MODKEY|Mod4Mask, XK_8, incrohgaps, {.i = +1 } },
{ MODKEY|Mod4Mask|ShiftMask, XK_8, incrohgaps, {.i = -1 } }, // { MODKEY|Mod4Mask|ShiftMask, XK_8, incrohgaps, {.i = -1 } },
{ MODKEY|Mod4Mask, XK_9, incrovgaps, {.i = +1 } }, // { MODKEY|Mod4Mask, XK_9, incrovgaps, {.i = +1 } },
{ MODKEY|Mod4Mask|ShiftMask, XK_9, incrovgaps, {.i = -1 } }, // { MODKEY|Mod4Mask|ShiftMask, XK_9, incrovgaps, {.i = -1 } },
{ MODKEY|Mod4Mask, XK_0, togglegaps, {0} }, { MODKEY|Mod4Mask, XK_0, togglegaps, {0} },
{ MODKEY|Mod4Mask|ShiftMask, XK_0, defaultgaps, {0} }, { MODKEY|Mod4Mask|ShiftMask, XK_0, defaultgaps, {0} },
{ MODKEY, XK_Tab, view, {0} }, { MODKEY, XK_Tab, view, {0} },
{ MODKEY|ShiftMask, XK_c, killclient, {0} },
// Layouts // Layouts
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, // []= tile { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, // []= tile

88
drw.c
View File

@ -255,12 +255,10 @@ drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int
int int
drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, 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 i, ty, ellipsis_x = 0;
int ty; unsigned int tmpw, ew, ellipsis_w = 0, ellipsis_len;
unsigned int ew;
XftDraw *d = NULL; XftDraw *d = NULL;
Fnt *usedfont, *curfont, *nextfont; Fnt *usedfont, *curfont, *nextfont;
size_t i, len;
int utf8strlen, utf8charlen, render = x || y || w || h; int utf8strlen, utf8charlen, render = x || y || w || h;
long utf8codepoint = 0; long utf8codepoint = 0;
const char *utf8str; const char *utf8str;
@ -268,13 +266,17 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
FcPattern *fcpattern; FcPattern *fcpattern;
FcPattern *match; FcPattern *match;
XftResult result; 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; return 0;
if (!render) { if (!render) {
w = ~w; w = invert ? invert : ~invert;
} else { } else {
XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel); XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel);
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
@ -284,8 +286,10 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
} }
usedfont = drw->fonts; usedfont = drw->fonts;
if (!ellipsis_width && render)
ellipsis_width = drw_fontset_getwidth(drw, "...");
while (1) { while (1) {
utf8strlen = 0; ew = ellipsis_len = utf8strlen = 0;
utf8str = text; utf8str = text;
nextfont = NULL; nextfont = NULL;
while (*text) { while (*text) {
@ -293,9 +297,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) { for (curfont = drw->fonts; curfont; curfont = curfont->next) {
charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint); charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint);
if (charexists) { 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; utf8strlen += utf8charlen;
text += utf8charlen; text += utf8charlen;
ew += tmpw;
} else { } else {
nextfont = curfont; nextfont = curfont;
} }
@ -303,36 +325,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; break;
else else
charexists = 0; charexists = 0;
} }
if (utf8strlen) { if (utf8strlen) {
drw_font_getexts(usedfont, utf8str, utf8strlen, &ew, NULL); if (render) {
/* shorten text if necessary */ ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent;
for (len = MIN(utf8strlen, sizeof(buf) - 1); len && ew > w; len--) XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg],
drw_font_getexts(usedfont, utf8str, len, &ew, NULL); usedfont->xfont, x, ty, (XftChar8 *)utf8str, utf8strlen);
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;
} }
x += ew;
w -= ew;
} }
if (render && overflow)
drw_text(drw, ellipsis_x, y, ellipsis_w, h, 0, "...", invert);
if (!*text) { if (!*text || overflow) {
break; break;
} else if (nextfont) { } else if (nextfont) {
charexists = 0; charexists = 0;
@ -342,6 +353,12 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
* character must be drawn. */ * character must be drawn. */
charexists = 1; 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(); fccharset = FcCharSetCreate();
FcCharSetAddChar(fccharset, utf8codepoint); FcCharSetAddChar(fccharset, utf8codepoint);
@ -370,6 +387,8 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
curfont->next = usedfont; curfont->next = usedfont;
} else { } else {
xfont_free(usedfont); xfont_free(usedfont);
nomatches.codepoint[++nomatches.idx % nomatches_len] = utf8codepoint;
no_match:
usedfont = drw->fonts; usedfont = drw->fonts;
} }
} }
@ -399,6 +418,15 @@ drw_fontset_getwidth(Drw *drw, const char *text)
return drw_text(drw, 0, 0, 0, 0, 0, text, 0); 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 void
drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h) drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h)
{ {

1
drw.h
View File

@ -38,6 +38,7 @@ void drw_free(Drw *drw);
Fnt *drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount); Fnt *drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount);
void drw_fontset_free(Fnt* set); void drw_fontset_free(Fnt* set);
unsigned int drw_fontset_getwidth(Drw *drw, const char *text); 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); void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h);
/* Colorscheme abstraction */ /* Colorscheme abstraction */

6
dwm.c
View File

@ -1345,11 +1345,11 @@ resizeclient(Client *c, int x, int y, int w, int h)
c->oldh = c->h; c->h = wc.height = h; c->oldh = c->h; c->h = wc.height = h;
wc.border_width = c->bw; wc.border_width = c->bw;
for (n = 0, nbc = nexttiled(selmon->clients); nbc; nbc = nexttiled(nbc->next), n++); for (n = 0, nbc = nexttiled(c->mon->clients); nbc; nbc = nexttiled(nbc->next), n++);
if (c->isfloating || selmon->lt[selmon->sellt]->arrange == NULL) { if (c->isfloating || c->mon->lt[c->mon->sellt]->arrange == NULL) {
} else { } else {
if (selmon->lt[selmon->sellt]->arrange == monocle || n == 1) { if (c->mon->lt[c->mon->sellt]->arrange == monocle || n == 1) {
wc.border_width = 0; wc.border_width = 0;
c->w = wc.width += c->bw * 2; c->w = wc.width += c->bw * 2;
c->h = wc.height += c->bw * 2; c->h = wc.height += c->bw * 2;

View File

@ -0,0 +1,23 @@
#include <time.h>
#include <stdio.h>
void debug_print(char *str)
{
time_t t = time(NULL);
char *t_str = ctime(&t);
FILE *fp;
fp = fopen("/home/michael/dwm-debug.txt", "a");
fprintf(fp, "%s: %s", t_str, str);
fclose(fp);
}
void resize() {
char s[2048];
sprintf(s, "resize client. name: %s, mon: %p, selmon: %p\n\tx: %d, y: %d, w: %d, h: %d\n\tn: %d, flt: %d, arrange: %p\n\tismonocle: %d\n",
c->name, c->mon, selmon,
x, y, w, h,
n, c->isfloating, c->mon->lt[c->mon->sellt]->arrange,
c->mon->lt[c->mon->sellt]->arrange == monocle
);
debug_print(s);
}

View File

@ -0,0 +1,31 @@
diff --git a/dwm.c b/dwm.c
index 4465af1..f869429 100644
--- a/dwm.c
+++ b/dwm.c
@@ -1276,12 +1276,26 @@ void
resizeclient(Client *c, int x, int y, int w, int h)
{
XWindowChanges wc;
+ unsigned int n;
+ Client *nbc;
c->oldx = c->x; c->x = wc.x = x;
c->oldy = c->y; c->y = wc.y = y;
c->oldw = c->w; c->w = wc.width = w;
c->oldh = c->h; c->h = wc.height = h;
wc.border_width = c->bw;
+
+ for (n = 0, nbc = nexttiled(c->mon->clients); nbc; nbc = nexttiled(nbc->next), n++);
+
+ if (c->isfloating || c->mon->lt[c->mon->sellt]->arrange == NULL) {
+ } else {
+ if (c->mon->lt[c->mon->sellt]->arrange == monocle || n == 1) {
+ wc.border_width = 0;
+ c->w = wc.width += c->bw * 2;
+ c->h = wc.height += c->bw * 2;
+ }
+ }
+
XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
configure(c);
XSync(dpy, False);