finish work, now on to testing

This commit is contained in:
Luca Bilke 2023-02-05 15:12:35 +01:00
parent 079a50c7cb
commit a442c9b501
5 changed files with 602 additions and 493 deletions

View file

@ -1,6 +0,0 @@
TODO: https://github.com/szatanjl/dwm/commit/1529909466206016f2101457bbf37c67195714c8
TODO: continue reworking keybinds, add layout binds, remove binds related to gaps, add stack binds
TODO: add remaining systray vars to config.h
FIX: barschemes needs constants as colors
FIX: remove dmenumon/dmenucmd references in dwm.c or come up with a better solution

276
config.h
View file

@ -1,8 +1,7 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#define BROWSER "librewolf" #define BROWSER "librewolf"
#define TERMINAL "kitty" #define TERMINAL "kitty"
#define PLAYER "firefox" /* this is currently only passed to playerctl as the client to control */ #define PLAYERCTL "firefox" /* this is currently only passed to playerctl as the client to control */
/* appearance */ /* appearance */
static const unsigned int borderpx = 2; static const unsigned int borderpx = 2;
@ -10,33 +9,66 @@ static const unsigned int snap = 20;
static const int showbar = 1; static const int showbar = 1;
static const int topbar = 1; static const int topbar = 1;
static const int swallowfloating = 0; static const int swallowfloating = 0;
static const unsigned int systraypinning = 0;
static const unsigned int systrayonleft = 0;
static const unsigned int systrayspacing = 2;
static const int systraypinningfailfirst = 1;
static const int showsystray = 1; static const int showsystray = 1;
static const int systrayonleft = 0; static const char *fonts[] = {
static char *fonts[] = {
"monospace:pixelsize=14", "monospace:pixelsize=14",
"monospace:pixelsize=20", "monospace:pixelsize=20",
"monospace:pixelsize=30", "monospace:pixelsize=30",
}; };
static char *colors[] = { static char color0[] = "#000000";
[0] = "#000000", [1] = "#7f0000", [2] = "#007f00", [3] = "#7f7f00", static char color1[] = "#7f0000";
[4] = "#00007f", [5] = "#7f007f", [6] = "#007f7f", [7] = "#cccccc", static char color2[] = "#007f00";
[8] = "#333333", [9] = "#ff0000", [10] = "#00ff00", [11] = "#ffff00", static char color3[] = "#7f7f00";
[12] = "#0000ff", [13] = "#ff00ff", [14] = "#00ffff", [15] = "#ffffff", static char color4[] = "#00007f";
/* Extra Colors (not accessible with SGR escapes) */ static char color5[] = "#7f007f";
[16] = "#222222", [17] = "#444444", static char color6[] = "#007f7f";
static char color7[] = "#cccccc";
static char color8[] = "#333333";
static char color9[] = "#ff0000";
static char color10[] = "#00ff00";
static char color11[] = "#ffff00";
static char color12[] = "#0000ff";
static char color13[] = "#ff00ff";
static char color14[] = "#00ffff";
static char color15[] = "#ffffff";
static char bordernorm[] = "#222222";
static char bordersel[] = "#444444";
static char *barschemes[][3] = {
/* fg bg border */
[SchemeNorm] = { color15, color0, bordernorm },
[SchemeSel] = { color15, color4, bordersel },
[SchemeStatus] = { color7, color0, "#000000" }, // Statusbar right
[SchemeTagsSel] = { color0, color4, "#000000" }, // Tagbar left selected
[SchemeTagsNorm] = { color7, color0, "#000000" }, // Tagbar left unselected
[SchemeInfoSel] = { color7, color0, "#000000" }, // infobar middle selected
[SchemeInfoNorm] = { color7, color0, "#000000" }, // infobar middle unselected
}; };
static char *barschemes[][3] = { // static const char *colors[] = {
/* fg bg border */ // [0] = "#000000", [1] = "#7f0000", [2] = "#007f00", [3] = "#7f7f00",
[SchemeNorm] = {colors[15], colors[0], colors[16]}, // [4] = "#00007f", [5] = "#7f007f", [6] = "#007f7f", [7] = "#cccccc",
[SchemeSel] = {colors[15], colors[4], colors[17]}, // [8] = "#333333", [9] = "#ff0000", [10] = "#00ff00", [11] = "#ffff00",
[SchemeStatus] = {colors[7], colors[0], "#000000"}, // Statusbar right // [12] = "#0000ff", [13] = "#ff00ff", [14] = "#00ffff", [15] = "#ffffff",
[SchemeTagsSel] = {colors[0], colors[4], "#000000"}, // Tagbar left selected // /* Extra Colors (not accessible with SGR escapes) */
[SchemeTagsNorm] = {colors[7], colors[0], "#000000"}, // Tagbar left unselected // [16] = "#222222", [17] = "#444444",
[SchemeInfoSel] = {colors[7], colors[0], "#000000"}, // infobar middle selected // };
[SchemeInfoNorm] = {colors[7], colors[0], "#000000"}, // infobar middle unselected //
}; // static char *barschemes[][3] = {
// /* fg bg border */
// [SchemeNorm] = {colors[15], colors[0], colors[16]},
// [SchemeSel] = {colors[15], colors[4], colors[17]},
// [SchemeStatus] = {colors[7], colors[0], "#000000"}, // Statusbar right
// [SchemeTagsSel] = {colors[0], colors[4], "#000000"}, // Tagbar left selected
// [SchemeTagsNorm] = {colors[7], colors[0], "#000000"}, // Tagbar left unselected
// [SchemeInfoSel] = {colors[7], colors[0], "#000000"}, // infobar middle selected
// [SchemeInfoNorm] = {colors[7], colors[0], "#000000"}, // infobar middle unselected
// };
/* tagging */ /* tagging */
static const char *tags[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9"}; static const char *tags[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9"};
@ -68,11 +100,11 @@ static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen win
static const Layout layouts[] = { static const Layout layouts[] = {
/* symbol arrange function */ /* symbol arrange function */
{ "[]=", tile }, { "[]=", tile },
{ "[M]", monocle },
{ "TTT", bstack }, { "TTT", bstack },
{ ":::", gaplessgrid },
{ "===", bstackhoriz },
{ "|M|", centeredmaster }, { "|M|", centeredmaster },
{ ":::", gaplessgrid },
{ "[M]", monocle },
{ "===", bstackhoriz },
{ ">M>", centeredfloatingmaster }, { ">M>", centeredfloatingmaster },
{ "><>", NULL }, /* Floating */ { "><>", NULL }, /* Floating */
}; };
@ -84,14 +116,6 @@ static const Layout layouts[] = {
{ MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \ { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
{ MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \ { MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \
{ MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} }, { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} },
#define STACKKEYS(MOD,ACTION) \
{MOD, XK_j, ACTION##stack, {.i = INC(+1)}}, \
{MOD, XK_k, ACTION##stack, {.i = INC(-1)}}, \
{MOD, XK_tab, ACTION##stack, {.i = 0}}, \
{MOD, XK_v, ACTION##stack, {.i = PREVSEL}}, \
// {MOD, XK_a, ACTION##stack, {.i = 1}}, \
// {MOD, XK_z, ACTION##stack, {.i = 2}}, \
// {MOD, XK_x, ACTION##stack, {.i = -1}},
/* helper for spawning shell commands in the pre dwm-5.0 fashion */ /* helper for spawning shell commands in the pre dwm-5.0 fashion */
#define SHCMD(cmd) { .v = (const char *[]) { "/bin/sh", "-c", cmd, NULL } } #define SHCMD(cmd) { .v = (const char *[]) { "/bin/sh", "-c", cmd, NULL } }
@ -105,24 +129,24 @@ static const char *spmix[] = { "m", "/bin/sh", "-c", "$TERMINAL --name spmix -e
/* Xresources preferences to load at startup */ /* Xresources preferences to load at startup */
ResourcePref resources[] = { ResourcePref resources[] = {
{ "color0", STRING, &colors[0] }, { "color0", STRING, &color0 },
{ "color1", STRING, &colors[1] }, { "color1", STRING, &color1 },
{ "color2", STRING, &colors[2] }, { "color2", STRING, &color2 },
{ "color3", STRING, &colors[3] }, { "color3", STRING, &color3 },
{ "color4", STRING, &colors[4] }, { "color4", STRING, &color4 },
{ "color5", STRING, &colors[5] }, { "color5", STRING, &color5 },
{ "color6", STRING, &colors[6] }, { "color6", STRING, &color6 },
{ "color7", STRING, &colors[7] }, { "color7", STRING, &color7 },
{ "color8", STRING, &colors[8] }, { "color8", STRING, &color8 },
{ "color9", STRING, &colors[9] }, { "color9", STRING, &color9 },
{ "color10", STRING, &colors[10] }, { "color10", STRING, &color10 },
{ "color11", STRING, &colors[11] }, { "color11", STRING, &color11 },
{ "color12", STRING, &colors[12] }, { "color12", STRING, &color12 },
{ "color13", STRING, &colors[13] }, { "color13", STRING, &color13 },
{ "color14", STRING, &colors[14] }, { "color14", STRING, &color14 },
{ "color15", STRING, &colors[15] }, { "color15", STRING, &color15 },
{ "bordernorm", STRING, &colors[16] }, { "bordernorm", STRING, &bordernorm },
{ "bordersel", STRING, &colors[17] }, { "bordersel", STRING, &bordersel },
}; };
#include <X11/XF86keysym.h> #include <X11/XF86keysym.h>
@ -154,82 +178,84 @@ static const Key keys[] = {
TAGKEYS( XK_9, 8) TAGKEYS( XK_9, 8)
{ MODKEY, XK_0, view, {.ui = ~0} }, { MODKEY, XK_0, view, {.ui = ~0} },
{ MODKEY | ShiftMask, XK_0, tag, {.ui = ~0} }, { MODKEY | ShiftMask, XK_0, tag, {.ui = ~0} },
// { MODKEY, XK_ssharp, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY, XK_bracketleft, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_ssharp, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY | ShiftMask, XK_bracketleft, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY, XK_acute, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY, XK_bracketright, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_acute, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY | ShiftMask, XK_bracketright, spawn, {.v = (const char *[]){NULL}} },
{ MODKEY, XK_BackSpace, spawn, {.v = (const char *[]){"sysact", NULL}} }, { MODKEY, XK_BackSpace, spawn, {.v = (const char *[]){"sysact", NULL}} },
{ MODKEY | ShiftMask, XK_BackSpace, spawn, {.v = (const char *[]){"sysact", NULL}} }, { MODKEY | ShiftMask, XK_BackSpace, spawn, {.v = (const char *[]){"sysact", NULL}} },
/* XK_Tab is bound in STACKKEYS*/ { MODKEY, XK_Tab, focusstack, {.i = 0} },
{ MODKEY|ShiftMask, XK_Tab, view, {0} }, { MODKEY | ShiftMask, XK_Tab, pushstack, {.i = 0} },
{ MODKEY, XK_q, killclient, {0} }, { MODKEY, XK_apostrophe, killclient, {0} },
// { MODKEY | ShiftMask, XK_q, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY | ShiftMask, XK_apostrophe, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY, XK_w, spawn, {.v = (const char *[]){NULL}} }, { MODKEY, XK_comma, focusmon, {.i = -1} },
// { MODKEY | ShiftMask, XK_w, spawn, {.v = (const char *[]){NULL}} }, { MODKEY | ShiftMask, XK_comma, tagmon, {.i = -1} },
{ MODKEY, XK_e, togglescratch, {.v = splf} }, { MODKEY, XK_period, focusmon, {.i = +1} },
// { MODKEY | ShiftMask, XK_e, spawn, {.v = (const char *[]){NULL}} }, { MODKEY | ShiftMask, XK_period, tagmon, {.i = +1} },
{ MODKEY, XK_p, togglefullscr, {0} },
// { MODKEY | ShiftMask, XK_p, setlayout, {.v = (const char *[]){NULL}} },
// { MODKEY, XK_y, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_y, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY, XK_f, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_f, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY, XK_g, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_g, spawn, {.v = (const char *[]){NULL}} },
{ MODKEY, XK_c, incnmaster, {.i = -1} },
{ MODKEY | ShiftMask, XK_c, resetnmaster, {0} },
{ MODKEY, XK_r, incnmaster, {.i = +1} }, { MODKEY, XK_r, incnmaster, {.i = +1} },
{ MODKEY | ShiftMask, XK_r, incnmaster, {.i = -1} }, { MODKEY | ShiftMask, XK_r, resetnmaster, {0} },
// { MODKEY, XK_t, spawn, {.v = (const char *[]){NULL}} }, { MODKEY, XK_l, setmfact, {.f = +0.05} },
// { MODKEY | ShiftMask, XK_t, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY | ShiftMask, XK_l, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY, XK_z, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY, XK_slash, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_z, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY | ShiftMask, XK_slash, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY, XK_equal, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_equal, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY, XK_a, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_a, spawn, {.v = (const char *[]){NULL}} },
{ MODKEY, XK_o, togglescratch, {.v = sphtop} },
{ MODKEY | ShiftMask, XK_o, spawn, {.v = (const char *[]){TERMINAL, "-e", "htop", NULL}} },
{ MODKEY, XK_e, togglescratch, {.v = splf} },
{ MODKEY | ShiftMask, XK_e, spawn, {.v = (const char *[]){TERMINAL, "-d", "~", "-e", "lf", NULL}} },
{ MODKEY, XK_u, spawn, {.v = (const char *[]){BROWSER, NULL}} }, { MODKEY, XK_u, spawn, {.v = (const char *[]){BROWSER, NULL}} },
{ MODKEY | ShiftMask, XK_u, spawn, {.v = (const char *[]){TERMINAL, "-e", "sudo", "nmtui", NULL}} }, { MODKEY | ShiftMask, XK_u, spawn, {.v = (const char *[]){TERMINAL, "-e", "sudo", "nmtui", NULL}} },
// { MODKEY, XK_i, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY, XK_i, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_i, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY | ShiftMask, XK_i, spawn, {.v = (const char *[]){NULL}} },
{ MODKEY, XK_o, togglescratch, {.v = sphtop} }, // { MODKEY, XK_d, spawn, {.v = (const char *[]){NULL}} },
{ MODKEY | ShiftMask, XK_o, spawn, {.v = (const char *[]){TERMINAL, "-e", "htop", NULL}} }, // { MODKEY | ShiftMask, XK_d, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY, XK_p, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_p, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY, XK_udiaeresis, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_udiaeresis, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY, XK_plus, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_plus, spawn, {.v = (const char *[]){NULL}} },
{ MODKEY, XK_a, togglegaps, {0} },
{ MODKEY | ShiftMask, XK_a, defaultgaps, {0} },
// { MODKEY, XK_s, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_s, spawn, {.v = (const char *[]){NULL}} },
{ MODKEY, XK_d, spawn, {.v = (const char *[]){"dmenu_run", NULL}} },
{ MODKEY | ShiftMask, XK_d, spawn, {.v = (const char *[]){NULL}} },
{ MODKEY, XK_f, togglefullscr, {0} },
// { MODKEY | ShiftMask, XK_f, setlayout, {.v = (const char *[]){NULL}} },
// { MODKEY, XK_g, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_g, spawn, {.v = (const char *[]){NULL}} },
{ MODKEY, XK_h, setmfact, {.f = -0.05} }, { MODKEY, XK_h, setmfact, {.f = -0.05} },
// { MODKEY | ShiftMask, XK_h, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY | ShiftMask, XK_h, spawn, {.v = (const char *[]){NULL}} },
/* XK_j and XK_k are bound in STACKKEYS */ { MODKEY, XK_t, spawn, {.v = (const char *[]){"dmenu_run", NULL}} },
{ MODKEY, XK_l, setmfact, {.f = +0.05} }, { MODKEY | ShiftMask, XK_t, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_l, spawn, {.v = (const char *[]){NULL}} }, { MODKEY, XK_n, setlayout, {.v = &layouts[0]} },
// { MODKEY, XK_odiaeresis, spawn, {.v = (const char *[]){NULL}} }, { MODKEY | ShiftMask, XK_n, setlayout, {.v = &layouts[1]} },
// { MODKEY | ShiftMask, XK_odiaeresis, spawn, {.v = (const char *[]){NULL}} }, { MODKEY, XK_s, setlayout, {.v = &layouts[2]} },
// { MODKEY, XK_adiaeresis, spawn, {.v = (const char *[]){NULL}} }, { MODKEY | ShiftMask, XK_s, setlayout, {.v = &layouts[3]} },
// { MODKEY | ShiftMask, XK_adiaeresis, spawn, {.v = (const char *[]){NULL}} }, { MODKEY, XK_minus, setlayout, {.v = &layouts[4]} },
{ MODKEY, XK_numbersign, togglescratch, {.v = spqalc} }, { MODKEY | ShiftMask, XK_minus, setlayout, {.v = &layouts[5]} },
// { MODKEY | ShiftMask, XK_numbersign, spawn, {.v = (const char *[]){NULL}} },
{ MODKEY, XK_backslash, togglescratch, {.v = spqalc} }, { MODKEY, XK_backslash, togglescratch, {.v = spqalc} },
// { MODKEY | ShiftMask, XK_backslash, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY | ShiftMask, XK_backslash, spawn, {.v = (const char *[]){NULL}} },
{ MODKEY, XK_Return, spawn, {.v = (const char *[]){TERMINAL, "-d", "~", NULL}} }, { MODKEY, XK_Return, spawn, {.v = (const char *[]){TERMINAL, "-d", "~", NULL}} },
{ MODKEY | ShiftMask, XK_Return, spawn, {.v = (const char *[]){"samedir", NULL}} }, { MODKEY | ShiftMask, XK_Return, spawn, {.v = (const char *[]){"samedir", NULL}} },
// { MODKEY, XK_y, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY, XK_semicolon, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_y, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY | ShiftMask, XK_semicolon, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY, XK_q, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_q, spawn, {.v = (const char *[]){NULL}} },
{ MODKEY, XK_j, focusstack, {.i = INC(+1)} },
{ MODKEY | ShiftMask, XK_j, pushstack, {.i = INC(+1)} },
{ MODKEY, XK_k, focusstack, {.i = INC(-1)} },
{ MODKEY | ShiftMask, XK_k, pushstack, {.i = INC(-1)} },
// { MODKEY, XK_x, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY, XK_x, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_x, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY | ShiftMask, XK_x, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY, XK_c, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_c, spawn, {.v = (const char *[]){NULL}} },
/* XK_v is bound in STACKKEYS */
{ MODKEY, XK_b, togglebar, {0} }, { MODKEY, XK_b, togglebar, {0} },
// { MODKEY | ShiftMask, XK_b, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY | ShiftMask, XK_b, spawn, {.v = (const char *[]){NULL}} },
{ MODKEY, XK_n, spawn, {.v = (const char *[]){TERMINAL, "-e", "nvim", "-c", "VimwikiIndex", NULL}} }, { MODKEY, XK_m, spawn, {.v = (const char *[]){BROWSER, "listen.tidal.de", NULL }} },
// { MODKEY | ShiftMask, XK_n, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY, XK_m, spawn, {.v = (const char *[]){NULL}} },
{ MODKEY | ShiftMask, XK_m, spawn, SHCMD("pamixer -t; kill -44 $(pidof dwmblocks)") }, { MODKEY | ShiftMask, XK_m, spawn, SHCMD("pamixer -t; kill -44 $(pidof dwmblocks)") },
{ MODKEY, XK_comma, spawn, {.v = (const char *[]){"playerctl", "-p", PLAYER, "previous", NULL}} }, { MODKEY, XK_w, spawn, {.v = (const char *[]){"ferdium", NULL}} },
{ MODKEY | ShiftMask, XK_comma, spawn, {.v = (const char *[]){"playerctl", "-p", PLAYER, "position", "0", NULL}} }, // { MODKEY | ShiftMask, XK_w, spawn, {.v = (const char *[]){NULL}} },
{ MODKEY, XK_period, spawn, {.v = (const char *[]){"playerctl", "-p", PLAYER, "previous", NULL}} }, { MODKEY, XK_v, focusstack, {.i = PREVSEL} },
// { MODKEY | ShiftMask, XK_period, spawn, {.v = (const char *[]){NULL}} }, { MODKEY | ShiftMask, XK_v, pushstack, {.i = PREVSEL} },
// { MODKEY, XK_minus, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY, XK_z, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_minus, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY | ShiftMask, XK_z, spawn, {.v = (const char *[]){NULL}} },
{ MODKEY, XK_space, zoom, {0} }, { MODKEY, XK_space, zoom, {0} },
{ MODKEY | ShiftMask, XK_space, togglefloating, {0} }, { MODKEY | ShiftMask, XK_space, togglefloating, {0} },
{ 0, XK_Print, spawn, SHCMD("maim ~/Photos/Screenshots/pic-full-$(date '+%y%m%d-%H%M-%S').png") }, { 0, XK_Print, spawn, SHCMD("maim ~/Photos/Screenshots/pic-full-$(date '+%y%m%d-%H%M-%S').png") },
@ -244,33 +270,33 @@ static const Key keys[] = {
// { MODKEY | ShiftMask, XK_Insert, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY | ShiftMask, XK_Insert, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY, XK_Home, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY, XK_Home, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_Home, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY | ShiftMask, XK_Home, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY, XK_Page_Up, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_Page_Up, spawn, {.v = (const char *[]){NULL}} },
{ MODKEY, XK_Delete, spawn, {.v = (const char *[]){"dmenurecord", "kill", NULL}} }, { MODKEY, XK_Delete, spawn, {.v = (const char *[]){"dmenurecord", "kill", NULL}} },
// { MODKEY | ShiftMask, XK_Delete, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY | ShiftMask, XK_Delete, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY, XK_End, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY, XK_End, spawn, {.v = (const char *[]){NULL}} },
{ MODKEY | ShiftMask, XK_End, quit, {0} }, { MODKEY | ShiftMask, XK_End, quit, {0} },
// { MODKEY, XK_Page_Up, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_Page_Up, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY, XK_Page_Down, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY, XK_Page_Down, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY | ShiftMask, XK_Page_Down, spawn, {.v = (const char *[]){NULL}} }, // { MODKEY | ShiftMask, XK_Page_Down, spawn, {.v = (const char *[]){NULL}} },
{ MODKEY, XK_Left, focusmon, {.i = -1} }, { MODKEY, XK_Left, spawn, {.v = (const char *[]){"playerctl", "-p", PLAYERCTL, "previous", NULL}} },
{ MODKEY | ShiftMask, XK_Left, tagmon, {.i = -1} }, { MODKEY | ShiftMask, XK_Left, spawn, {.v = (const char *[]){"playerctl", "-p", PLAYERCTL, "position", "0", NULL}} },
{ MODKEY, XK_Right, focusmon, {.i = +1} }, { MODKEY, XK_Right, spawn, {.v = (const char *[]){"playerctl", "-p", PLAYERCTL, "next", NULL}} },
{ MODKEY | ShiftMask, XK_Right, tagmon, {.i = +1} }, // { MODKEY | ShiftMask, XK_Right, spawn, {.v = (const char *[]){NULL}} },
// { MODKEY, XK_Up, spawn, {.v = (const char *[]){NULL}} }, { MODKEY, XK_Up, spawn, SHCMD("pamixer --allow-boost -i 5; pkill -RTMIN+10 dwmblocks") },
// { MODKEY | ShiftMask, XK_Up, spawn, {.v = (const char *[]){NULL}} }, { MODKEY | ShiftMask, XK_Up, spawn, SHCMD("pamixer --allow-boost -i 20; pkill -RTMIN+10 dwmblocks") },
// { MODKEY, XK_Down, spawn, {.v = (const char *[]){NULL}} }, { MODKEY, XK_Down, spawn, SHCMD("pamixer --allow-boost -d 5; pkill -RTMIN+10 dwmblocks") },
// { MODKEY | ShiftMask, XK_Down, spawn, {.v = (const char *[]){NULL}} }, { MODKEY | ShiftMask, XK_Down, spawn, SHCMD("pamixer --allow-boost -d 20; pkill -RTMIN+10 dwmblocks") },
{ 0, XF86XK_AudioMute, spawn, SHCMD("pamixer -t; pkill -RTMIN+10 dwmblocks") }, { 0, XF86XK_AudioMute, spawn, SHCMD("pamixer -t; pkill -RTMIN+10 dwmblocks") },
{ 0, XF86XK_AudioRaiseVolume, spawn, SHCMD("pamixer --allow-boost -i 5; pkill -RTMIN+10 dwmblocks") }, { 0, XF86XK_AudioRaiseVolume, spawn, SHCMD("pamixer --allow-boost -i 5; pkill -RTMIN+10 dwmblocks") },
{ 0, XF86XK_AudioLowerVolume, spawn, SHCMD("pamixer --allow-boost -d 5; pkill -RTMIN+10 dwmblocks") }, { 0, XF86XK_AudioLowerVolume, spawn, SHCMD("pamixer --allow-boost -d 5; pkill -RTMIN+10 dwmblocks") },
{ 0, XF86XK_AudioPrev, spawn, {.v = (const char *[]){"playerctl", "-p", PLAYER, "previous", NULL}} }, { 0, XF86XK_AudioPrev, spawn, {.v = (const char *[]){"playerctl", "-p", PLAYERCTL, "previous", NULL}} },
{ 0, XF86XK_AudioNext, spawn, {.v = (const char *[]){"playerctl", "-p", PLAYER, "next", NULL}} }, { 0, XF86XK_AudioNext, spawn, {.v = (const char *[]){"playerctl", "-p", PLAYERCTL, "next", NULL}} },
{ 0, XF86XK_AudioPause, spawn, {.v = (const char *[]){"playerctl", "-p", PLAYER, "pause", NULL}} }, { 0, XF86XK_AudioPause, spawn, {.v = (const char *[]){"playerctl", "-p", PLAYERCTL, "pause", NULL}} },
{ 0, XF86XK_AudioPlay, spawn, {.v = (const char *[]){"playerctl", "-p", PLAYER, "play", NULL}} }, { 0, XF86XK_AudioPlay, spawn, {.v = (const char *[]){"playerctl", "-p", PLAYERCTL, "play", NULL}} },
{ 0, XF86XK_AudioStop, spawn, {.v = (const char *[]){"playerctl", "-p", PLAYER, "stop", NULL}} }, { 0, XF86XK_AudioStop, spawn, {.v = (const char *[]){"playerctl", "-p", PLAYERCTL, "stop", NULL}} },
{ 0, XF86XK_AudioRewind, spawn, {.v = (const char *[]){"playerctl", "-p", PLAYER, "position", "10-", NULL}} }, { 0, XF86XK_AudioRewind, spawn, {.v = (const char *[]){"playerctl", "-p", PLAYERCTL, "position", "10-", NULL}} },
{ 0, XF86XK_AudioForward, spawn, {.v = (const char *[]){"playerctl", "-p", PLAYER, "position", "10+", NULL}} }, { 0, XF86XK_AudioForward, spawn, {.v = (const char *[]){"playerctl", "-p", PLAYERCTL, "position", "10+", NULL}} },
// { 0, XF86XK_AudioMedia, spawn, {.v = (const char *[]){NULL}} }, // { 0, XF86XK_AudioMedia, spawn, {.v = (const char *[]){NULL}} },
{ 0, XF86XK_AudioMicMute, spawn, SHCMD("pactl set-source-mute @DEFAULT_SOURCE@ toggle") }, { 0, XF86XK_AudioMicMute, spawn, SHCMD("pactl set-source-mute @DEFAULT_SOURCE@ toggle") },
{ 0, XF86XK_PowerOff, spawn, {.v = (const char *[]){"sysact", NULL}} }, { 0, XF86XK_PowerOff, spawn, {.v = (const char *[]){"sysact", NULL}} },

669
drw.c
View file

@ -1,450 +1,411 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#include <X11/Xft/Xft.h>
#include <X11/Xlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <X11/Xlib.h>
#include <X11/Xft/Xft.h>
#include "drw.h" #include "drw.h"
#include "util.h" #include "util.h"
#define UTF_INVALID 0xFFFD #define UTF_INVALID 0xFFFD
#define UTF_SIZ 4 #define UTF_SIZ 4
static const unsigned char utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; 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 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 utfmin[UTF_SIZ + 1] = {0, 0, 0x80, 0x800, 0x10000};
static const long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; static const long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF};
static long static long utf8decodebyte(const char c, size_t *i) {
utf8decodebyte(const char c, size_t *i) for (*i = 0; *i < (UTF_SIZ + 1); ++(*i))
{ if (((unsigned char)c & utfmask[*i]) == utfbyte[*i])
for (*i = 0; *i < (UTF_SIZ + 1); ++(*i)) return (unsigned char)c & ~utfmask[*i];
if (((unsigned char)c & utfmask[*i]) == utfbyte[*i]) return 0;
return (unsigned char)c & ~utfmask[*i];
return 0;
} }
static size_t static size_t utf8validate(long *u, size_t i) {
utf8validate(long *u, size_t i) if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF))
{ *u = UTF_INVALID;
if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF)) for (i = 1; *u > utfmax[i]; ++i)
*u = UTF_INVALID; ;
for (i = 1; *u > utfmax[i]; ++i) return i;
;
return i;
} }
static size_t static size_t utf8decode(const char *c, long *u, size_t clen) {
utf8decode(const char *c, long *u, size_t clen) size_t i, j, len, type;
{ long udecoded;
size_t i, j, len, type;
long udecoded;
*u = UTF_INVALID; *u = UTF_INVALID;
if (!clen) if (!clen)
return 0; return 0;
udecoded = utf8decodebyte(c[0], &len); udecoded = utf8decodebyte(c[0], &len);
if (!BETWEEN(len, 1, UTF_SIZ)) if (!BETWEEN(len, 1, UTF_SIZ))
return 1; return 1;
for (i = 1, j = 1; i < clen && j < len; ++i, ++j) { for (i = 1, j = 1; i < clen && j < len; ++i, ++j) {
udecoded = (udecoded << 6) | utf8decodebyte(c[i], &type); udecoded = (udecoded << 6) | utf8decodebyte(c[i], &type);
if (type) if (type)
return j; return j;
} }
if (j < len) if (j < len)
return 0; return 0;
*u = udecoded; *u = udecoded;
utf8validate(u, len); utf8validate(u, len);
return len; return len;
} }
Drw * Drw *drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) {
drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) Drw *drw = ecalloc(1, sizeof(Drw));
{
Drw *drw = ecalloc(1, sizeof(Drw));
drw->dpy = dpy; drw->dpy = dpy;
drw->screen = screen; drw->screen = screen;
drw->root = root; drw->root = root;
drw->w = w; drw->w = w;
drw->h = h; drw->h = h;
drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen)); drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen));
drw->gc = XCreateGC(dpy, root, 0, NULL); drw->gc = XCreateGC(dpy, root, 0, NULL);
XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter); XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
return drw; return drw;
} }
void void drw_resize(Drw *drw, unsigned int w, unsigned int h) {
drw_resize(Drw *drw, unsigned int w, unsigned int h) if (!drw)
{ return;
if (!drw)
return;
drw->w = w; drw->w = w;
drw->h = h; drw->h = h;
if (drw->drawable) if (drw->drawable)
XFreePixmap(drw->dpy, drw->drawable); XFreePixmap(drw->dpy, drw->drawable);
drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen)); drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen));
} }
void void drw_free(Drw *drw) {
drw_free(Drw *drw) XFreePixmap(drw->dpy, drw->drawable);
{ XFreeGC(drw->dpy, drw->gc);
XFreePixmap(drw->dpy, drw->drawable); drw_fontset_free(drw->fonts);
XFreeGC(drw->dpy, drw->gc); free(drw);
drw_fontset_free(drw->fonts);
free(drw);
} }
/* This function is an implementation detail. Library users should use /* This function is an implementation detail. Library users should use
* drw_fontset_create instead. * drw_fontset_create instead.
*/ */
static Fnt * static Fnt *xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern) {
xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern) Fnt *font;
{ XftFont *xfont = NULL;
Fnt *font; FcPattern *pattern = NULL;
XftFont *xfont = NULL;
FcPattern *pattern = NULL;
if (fontname) { if (fontname) {
/* Using the pattern found at font->xfont->pattern does not yield the /* Using the pattern found at font->xfont->pattern does not yield the
* same substitution results as using the pattern returned by * same substitution results as using the pattern returned by
* FcNameParse; using the latter results in the desired fallback * FcNameParse; using the latter results in the desired fallback
* behaviour whereas the former just results in missing-character * behaviour whereas the former just results in missing-character
* rectangles being drawn, at least with some fonts. */ * rectangles being drawn, at least with some fonts. */
if (!(xfont = XftFontOpenName(drw->dpy, drw->screen, fontname))) { if (!(xfont = XftFontOpenName(drw->dpy, drw->screen, fontname))) {
fprintf(stderr, "error, cannot load font from name: '%s'\n", fontname); fprintf(stderr, "error, cannot load font from name: '%s'\n", fontname);
return NULL; return NULL;
} }
if (!(pattern = FcNameParse((FcChar8 *) fontname))) { if (!(pattern = FcNameParse((FcChar8 *)fontname))) {
fprintf(stderr, "error, cannot parse font name to pattern: '%s'\n", fontname); fprintf(stderr, "error, cannot parse font name to pattern: '%s'\n", fontname);
XftFontClose(drw->dpy, xfont); XftFontClose(drw->dpy, xfont);
return NULL; return NULL;
} }
} else if (fontpattern) { } else if (fontpattern) {
if (!(xfont = XftFontOpenPattern(drw->dpy, fontpattern))) { if (!(xfont = XftFontOpenPattern(drw->dpy, fontpattern))) {
fprintf(stderr, "error, cannot load font from pattern.\n"); fprintf(stderr, "error, cannot load font from pattern.\n");
return NULL; return NULL;
} }
} else { } else {
die("no font specified."); die("no font specified.");
} }
font = ecalloc(1, sizeof(Fnt)); font = ecalloc(1, sizeof(Fnt));
font->xfont = xfont; font->xfont = xfont;
font->pattern = pattern; font->pattern = pattern;
font->h = xfont->ascent + xfont->descent; font->h = xfont->ascent + xfont->descent;
font->dpy = drw->dpy; font->dpy = drw->dpy;
return font; return font;
} }
static void static void xfont_free(Fnt *font) {
xfont_free(Fnt *font) if (!font)
{ return;
if (!font) if (font->pattern)
return; FcPatternDestroy(font->pattern);
if (font->pattern) XftFontClose(font->dpy, font->xfont);
FcPatternDestroy(font->pattern); free(font);
XftFontClose(font->dpy, font->xfont);
free(font);
} }
Fnt* Fnt *drw_fontset_create(Drw *drw, const char *fonts[], size_t fontcount) {
drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount) Fnt *cur, *ret = NULL;
{ size_t i;
Fnt *cur, *ret = NULL;
size_t i;
if (!drw || !fonts) if (!drw || !fonts)
return NULL; return NULL;
for (i = 1; i <= fontcount; i++) { for (i = 1; i <= fontcount; i++) {
if ((cur = xfont_create(drw, fonts[fontcount - i], NULL))) { if ((cur = xfont_create(drw, fonts[fontcount - i], NULL))) {
cur->next = ret; cur->next = ret;
ret = cur; ret = cur;
} }
} }
return (drw->fonts = ret); return (drw->fonts = ret);
} }
void void drw_fontset_free(Fnt *font) {
drw_fontset_free(Fnt *font) if (font) {
{ drw_fontset_free(font->next);
if (font) { xfont_free(font);
drw_fontset_free(font->next); }
xfont_free(font);
}
} }
void void drw_clr_create(Drw *drw, Clr *dest, const char *clrname) {
drw_clr_create(Drw *drw, Clr *dest, const char *clrname) if (!drw || !dest || !clrname)
{ return;
if (!drw || !dest || !clrname)
return;
if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen), if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
DefaultColormap(drw->dpy, drw->screen), DefaultColormap(drw->dpy, drw->screen), clrname, dest))
clrname, dest)) die("error, cannot allocate color '%s'", clrname);
die("error, cannot allocate color '%s'", clrname);
dest->pixel |= 0xff << 24;
} }
/* Wrapper to create color schemes. The caller has to call free(3) on the /* Wrapper to create color schemes. The caller has to call free(3) on the
* returned color scheme when done using it. */ * returned color scheme when done using it. */
Clr * Clr *drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount) {
drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount) size_t i;
{ Clr *ret;
size_t i;
Clr *ret;
/* need at least two colors for a scheme */ /* need at least two colors for a scheme */
if (!drw || !clrnames || clrcount < 2 || !(ret = ecalloc(clrcount, sizeof(XftColor)))) if (!drw || !clrnames || clrcount < 2 || !(ret = ecalloc(clrcount, sizeof(XftColor))))
return NULL; return NULL;
for (i = 0; i < clrcount; i++) for (i = 0; i < clrcount; i++)
drw_clr_create(drw, &ret[i], clrnames[i]); drw_clr_create(drw, &ret[i], clrnames[i]);
return ret; return ret;
} }
void void drw_setfontset(Drw *drw, Fnt *set) {
drw_setfontset(Drw *drw, Fnt *set) if (drw)
{ drw->fonts = set;
if (drw)
drw->fonts = set;
} }
void void drw_setscheme(Drw *drw, Clr *scm) {
drw_setscheme(Drw *drw, Clr *scm) if (drw)
{ drw->scheme = scm;
if (drw)
drw->scheme = scm;
} }
void void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert) {
drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert) if (!drw || !drw->scheme)
{ return;
if (!drw || !drw->scheme) XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme[ColBg].pixel : drw->scheme[ColFg].pixel);
return; if (filled)
XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme[ColBg].pixel : drw->scheme[ColFg].pixel); XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
if (filled) else
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w - 1, h - 1);
else
XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w - 1, h - 1);
} }
int int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad,
drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert) const char *text, int invert) {
{ int i, ty, ellipsis_x = 0;
int i, ty, ellipsis_x = 0; unsigned int tmpw, ew, ellipsis_w = 0, ellipsis_len;
unsigned int tmpw, ew, ellipsis_w = 0, ellipsis_len; XftDraw *d = NULL;
XftDraw *d = NULL; Fnt *usedfont, *curfont, *nextfont;
Fnt *usedfont, *curfont, *nextfont; 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; FcCharSet *fccharset;
FcCharSet *fccharset; FcPattern *fcpattern;
FcPattern *fcpattern; FcPattern *match;
FcPattern *match; XftResult result;
XftResult result; int charexists = 0, overflow = 0;
int charexists = 0, overflow = 0; /* keep track of a couple codepoints for which we have no match. */
/* keep track of a couple codepoints for which we have no match. */ enum { nomatches_len = 64 };
enum { nomatches_len = 64 }; static struct {
static struct { long codepoint[nomatches_len]; unsigned int idx; } nomatches; long codepoint[nomatches_len];
static unsigned int ellipsis_width = 0; unsigned int idx;
} nomatches;
static unsigned int ellipsis_width = 0;
if (!drw || (render && (!drw->scheme || !w)) || !text || !drw->fonts) if (!drw || (render && (!drw->scheme || !w)) || !text || !drw->fonts)
return 0; return 0;
if (!render) { if (!render) {
w = invert ? invert : ~invert; 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);
d = XftDrawCreate(drw->dpy, drw->drawable, d = XftDrawCreate(drw->dpy, drw->drawable, DefaultVisual(drw->dpy, drw->screen),
DefaultVisual(drw->dpy, drw->screen), DefaultColormap(drw->dpy, drw->screen));
DefaultColormap(drw->dpy, drw->screen)); x += lpad;
x += lpad; w -= lpad;
w -= lpad; }
}
usedfont = drw->fonts; usedfont = drw->fonts;
if (!ellipsis_width && render) if (!ellipsis_width && render)
ellipsis_width = drw_fontset_getwidth(drw, "..."); ellipsis_width = drw_fontset_getwidth(drw, "...");
while (1) { while (1) {
ew = ellipsis_len = utf8strlen = 0; ew = ellipsis_len = utf8strlen = 0;
utf8str = text; utf8str = text;
nextfont = NULL; nextfont = NULL;
while (*text) { while (*text) {
utf8charlen = utf8decode(text, &utf8codepoint, UTF_SIZ); utf8charlen = utf8decode(text, &utf8codepoint, UTF_SIZ);
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) {
drw_font_getexts(curfont, text, utf8charlen, &tmpw, NULL); drw_font_getexts(curfont, text, utf8charlen, &tmpw, NULL);
if (ew + ellipsis_width <= w) { if (ew + ellipsis_width <= w) {
/* keep track where the ellipsis still fits */ /* keep track where the ellipsis still fits */
ellipsis_x = x + ew; ellipsis_x = x + ew;
ellipsis_w = w - ew; ellipsis_w = w - ew;
ellipsis_len = utf8strlen; ellipsis_len = utf8strlen;
} }
if (ew + tmpw > w) { if (ew + tmpw > w) {
overflow = 1; overflow = 1;
/* called from drw_fontset_getwidth_clamp(): /* called from drw_fontset_getwidth_clamp():
* it wants the width AFTER the overflow * it wants the width AFTER the overflow
*/ */
if (!render) if (!render)
x += tmpw; x += tmpw;
else else
utf8strlen = ellipsis_len; utf8strlen = ellipsis_len;
} else if (curfont == usedfont) { } else if (curfont == usedfont) {
utf8strlen += utf8charlen; utf8strlen += utf8charlen;
text += utf8charlen; text += utf8charlen;
ew += tmpw; ew += tmpw;
} else { } else {
nextfont = curfont; nextfont = curfont;
} }
break; break;
} }
} }
if (overflow || !charexists || nextfont) if (overflow || !charexists || nextfont)
break; break;
else else
charexists = 0; charexists = 0;
} }
if (utf8strlen) { if (utf8strlen) {
if (render) { if (render) {
ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent; ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent;
XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg], XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg], usedfont->xfont, x, ty,
usedfont->xfont, x, ty, (XftChar8 *)utf8str, utf8strlen); (XftChar8 *)utf8str, utf8strlen);
} }
x += ew; x += ew;
w -= ew; w -= ew;
} }
if (render && overflow) if (render && overflow)
drw_text(drw, ellipsis_x, y, ellipsis_w, h, 0, "...", invert); drw_text(drw, ellipsis_x, y, ellipsis_w, h, 0, "...", invert);
if (!*text || overflow) { if (!*text || overflow) {
break; break;
} else if (nextfont) { } else if (nextfont) {
charexists = 0; charexists = 0;
usedfont = nextfont; usedfont = nextfont;
} else { } else {
/* Regardless of whether or not a fallback font is found, the /* Regardless of whether or not a fallback font is found, the
* character must be drawn. */ * character must be drawn. */
charexists = 1; charexists = 1;
for (i = 0; i < nomatches_len; ++i) { for (i = 0; i < nomatches_len; ++i) {
/* avoid calling XftFontMatch if we know we won't find a match */ /* avoid calling XftFontMatch if we know we won't find a match */
if (utf8codepoint == nomatches.codepoint[i]) if (utf8codepoint == nomatches.codepoint[i])
goto no_match; goto no_match;
} }
fccharset = FcCharSetCreate(); fccharset = FcCharSetCreate();
FcCharSetAddChar(fccharset, utf8codepoint); FcCharSetAddChar(fccharset, utf8codepoint);
if (!drw->fonts->pattern) { if (!drw->fonts->pattern) {
/* Refer to the comment in xfont_create for more information. */ /* Refer to the comment in xfont_create for more information. */
die("the first font in the cache must be loaded from a font string."); die("the first font in the cache must be loaded from a font string.");
} }
fcpattern = FcPatternDuplicate(drw->fonts->pattern); fcpattern = FcPatternDuplicate(drw->fonts->pattern);
FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset); FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset);
FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue); FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue);
FcConfigSubstitute(NULL, fcpattern, FcMatchPattern); FcConfigSubstitute(NULL, fcpattern, FcMatchPattern);
FcDefaultSubstitute(fcpattern); FcDefaultSubstitute(fcpattern);
match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result); match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result);
FcCharSetDestroy(fccharset); FcCharSetDestroy(fccharset);
FcPatternDestroy(fcpattern); FcPatternDestroy(fcpattern);
if (match) { if (match) {
usedfont = xfont_create(drw, NULL, match); usedfont = xfont_create(drw, NULL, match);
if (usedfont && XftCharExists(drw->dpy, usedfont->xfont, utf8codepoint)) { if (usedfont && XftCharExists(drw->dpy, usedfont->xfont, utf8codepoint)) {
for (curfont = drw->fonts; curfont->next; curfont = curfont->next) for (curfont = drw->fonts; curfont->next; curfont = curfont->next)
; /* NOP */ ; /* NOP */
curfont->next = usedfont; curfont->next = usedfont;
} else { } else {
xfont_free(usedfont); xfont_free(usedfont);
nomatches.codepoint[++nomatches.idx % nomatches_len] = utf8codepoint; nomatches.codepoint[++nomatches.idx % nomatches_len] = utf8codepoint;
no_match: no_match:
usedfont = drw->fonts; usedfont = drw->fonts;
} }
} }
} }
} }
if (d) if (d)
XftDrawDestroy(d); XftDrawDestroy(d);
return x + (render ? w : 0); return x + (render ? w : 0);
} }
void void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) {
drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) if (!drw)
{ return;
if (!drw)
return;
XCopyArea(drw->dpy, drw->drawable, win, drw->gc, x, y, w, h, x, y); XCopyArea(drw->dpy, drw->drawable, win, drw->gc, x, y, w, h, x, y);
XSync(drw->dpy, False); XSync(drw->dpy, False);
} }
unsigned int unsigned int drw_fontset_getwidth(Drw *drw, const char *text) {
drw_fontset_getwidth(Drw *drw, const char *text) if (!drw || !drw->fonts || !text)
{ return 0;
if (!drw || !drw->fonts || !text) return drw_text(drw, 0, 0, 0, 0, 0, text, 0);
return 0;
return drw_text(drw, 0, 0, 0, 0, 0, text, 0);
} }
unsigned int unsigned int drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n) {
drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n) unsigned int tmp = 0;
{ if (drw && drw->fonts && text && n)
unsigned int tmp = 0; tmp = drw_text(drw, 0, 0, 0, 0, 0, text, n);
if (drw && drw->fonts && text && n) return MIN(n, tmp);
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,
drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h) unsigned int *h) {
{ XGlyphInfo ext;
XGlyphInfo ext;
if (!font || !text) if (!font || !text)
return; return;
XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext); XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext);
if (w) if (w)
*w = ext.xOff; *w = ext.xOff;
if (h) if (h)
*h = font->h; *h = font->h;
} }
Cur * Cur *drw_cur_create(Drw *drw, int shape) {
drw_cur_create(Drw *drw, int shape) Cur *cur;
{
Cur *cur;
if (!drw || !(cur = ecalloc(1, sizeof(Cur)))) if (!drw || !(cur = ecalloc(1, sizeof(Cur))))
return NULL; return NULL;
cur->cursor = XCreateFontCursor(drw->dpy, shape); cur->cursor = XCreateFontCursor(drw->dpy, shape);
return cur; return cur;
} }
void void drw_cur_free(Drw *drw, Cur *cursor) {
drw_cur_free(Drw *drw, Cur *cursor) if (!cursor)
{ return;
if (!cursor)
return;
XFreeCursor(drw->dpy, cursor->cursor); XFreeCursor(drw->dpy, cursor->cursor);
free(cursor); free(cursor);
} }

108
dwm.c
View file

@ -174,6 +174,7 @@ typedef struct {
void (*arrange)(Monitor *); void (*arrange)(Monitor *);
} Layout; } Layout;
typedef struct Pertag Pertag;
struct Monitor { struct Monitor {
char ltsymbol[16]; char ltsymbol[16];
float mfact; float mfact;
@ -193,6 +194,7 @@ struct Monitor {
Monitor *next; Monitor *next;
Window barwin; Window barwin;
const Layout *lt[2]; const Layout *lt[2];
Pertag *pertag;
}; };
typedef struct { typedef struct {
@ -281,6 +283,7 @@ static void pushstack(const Arg *arg);
static void quit(const Arg *arg); static void quit(const Arg *arg);
static Monitor *recttomon(int x, int y, int w, int h); static Monitor *recttomon(int x, int y, int w, int h);
static void removesystrayicon(Client *i); static void removesystrayicon(Client *i);
static void resetnmaster(const Arg *arg);
static void resize(Client *c, int x, int y, int w, int h, int interact); static void resize(Client *c, int x, int y, int w, int h, int interact);
static void resizebarwin(Monitor *m); static void resizebarwin(Monitor *m);
static void resizeclient(Client *c, int x, int y, int w, int h); static void resizeclient(Client *c, int x, int y, int w, int h);
@ -388,6 +391,20 @@ static xcb_connection_t *xcon;
/* configuration, allows nested code to access above variables */ /* configuration, allows nested code to access above variables */
#include "config.h" #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 */
};
static char *colors[] = {
color0, color1, color2, color3, color4, color5, color6, color7,
color8, color9, color10, color11, color12, color13, color14, color15,
};
/* compile-time check if all tags fit into an unsigned int bit array. */ /* compile-time check if all tags fit into an unsigned int bit array. */
struct NumTags { struct NumTags {
char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; char limitexceeded[LENGTH(tags) > 31 ? -1 : 1];
@ -1063,6 +1080,7 @@ void configurerequest(XEvent *e) {
Monitor *createmon(void) { Monitor *createmon(void) {
Monitor *m; Monitor *m;
unsigned int i;
m = ecalloc(1, sizeof(Monitor)); m = ecalloc(1, sizeof(Monitor));
m->tagset[0] = m->tagset[1] = 1; m->tagset[0] = m->tagset[1] = 1;
@ -1073,6 +1091,20 @@ Monitor *createmon(void) {
m->lt[0] = &layouts[0]; m->lt[0] = &layouts[0];
m->lt[1] = &layouts[1 % LENGTH(layouts)]; m->lt[1] = &layouts[1 % LENGTH(layouts)];
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol); 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; return m;
} }
@ -1600,7 +1632,8 @@ void grabkeys(void) {
} }
void incnmaster(const Arg *arg) { 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); arrange(selmon);
} }
@ -1928,6 +1961,11 @@ void removesystrayicon(Client *i) {
free(i); free(i);
} }
void resetnmaster(const Arg *arg) {
selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = 1;
arrange(selmon);
}
void resize(Client *c, int x, int y, int w, int h, int interact) { void resize(Client *c, int x, int y, int w, int h, int interact) {
if (applysizehints(c, &x, &y, &w, &h, interact)) if (applysizehints(c, &x, &y, &w, &h, interact))
resizeclient(c, x, y, w, h); resizeclient(c, x, y, w, h);
@ -2190,9 +2228,10 @@ void setfullscreen(Client *c, int fullscreen) {
void setlayout(const Arg *arg) { void setlayout(const Arg *arg) {
if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) 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) 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); strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
if (selmon->sel) if (selmon->sel)
arrange(selmon); arrange(selmon);
@ -2209,7 +2248,7 @@ void setmfact(const Arg *arg) {
f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0; f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
if (f < 0.05 || f > 0.95) if (f < 0.05 || f > 0.95)
return; return;
selmon->mfact = f; selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag] = f;
arrange(selmon); arrange(selmon);
} }
@ -2276,6 +2315,7 @@ void setup(void) {
scheme[i] = drw_scm_create(drw, barschemes[i], 3); scheme[i] = drw_scm_create(drw, barschemes[i], 3);
barclrs = ecalloc(LENGTH(colors), sizeof(Clr)); barclrs = ecalloc(LENGTH(colors), sizeof(Clr));
for (i = 0; i < LENGTH(colors); i++) for (i = 0; i < LENGTH(colors); i++)
drw_clr_create(drw, &barclrs[i], colors[i]); drw_clr_create(drw, &barclrs[i], colors[i]);
@ -2345,8 +2385,6 @@ void sigterm(int unused) {
} }
void spawn(const Arg *arg) { void spawn(const Arg *arg) {
if (arg->v == dmenucmd)
dmenumon[0] = '0' + selmon->num;
if (fork() == 0) { if (fork() == 0) {
if (dpy) if (dpy)
close(ConnectionNumber(dpy)); close(ConnectionNumber(dpy));
@ -2441,7 +2479,7 @@ void tile(Monitor *m) {
} }
void togglebar(const Arg *arg) { void togglebar(const Arg *arg) {
selmon->showbar = !selmon->showbar; selmon->showbar = selmon->pertag->showbars[selmon->pertag->curtag] = !selmon->showbar;
updatebarpos(selmon); updatebarpos(selmon);
resizebarwin(selmon); resizebarwin(selmon);
if (showsystray) { if (showsystray) {
@ -2510,9 +2548,35 @@ void toggletag(const Arg *arg) {
void toggleview(const Arg *arg) { void toggleview(const Arg *arg) {
unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK); unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
int i;
if (newtagset) { if (newtagset) {
selmon->tagset[selmon->seltags] = 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); focus(NULL);
arrange(selmon); arrange(selmon);
} }
@ -2924,11 +2988,39 @@ void updatewmhints(Client *c) {
} }
void view(const Arg *arg) { void view(const Arg *arg) {
int i;
unsigned int tmptag;
if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
return; return;
selmon->seltags ^= 1; /* toggle sel tagset */ selmon->seltags ^= 1; /* toggle sel tagset */
if (arg->ui & TAGMASK) if (arg->ui & TAGMASK) {
selmon->tagset[selmon->seltags] = 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); focus(NULL);
arrange(selmon); arrange(selmon);
} }

View file

@ -0,0 +1,36 @@
diff -r -u a/config.def.h b/config.def.h
--- a/config.def.h 2022-01-07 06:42:18.000000000 -0500
+++ b/config.def.h 2022-01-23 16:03:42.521951418 -0500
@@ -69,6 +69,7 @@
{ MODKEY, XK_k, focusstack, {.i = -1 } },
{ MODKEY, XK_i, incnmaster, {.i = +1 } },
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
+ { MODKEY, XK_o, resetnmaster, {0} },
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
{ MODKEY, XK_Return, zoom, {0} },
diff -r -u a/dwm.c b/dwm.c
--- a/dwm.c 2022-01-23 16:06:01.221948285 -0500
+++ b/dwm.c 2022-01-23 16:05:35.949948855 -0500
@@ -191,6 +191,7 @@
static void propertynotify(XEvent *e);
static void quit(const Arg *arg);
static Monitor *recttomon(int x, int y, int w, int h);
+static void resetnmaster(const Arg *arg);
static void resize(Client *c, int x, int y, int w, int h, int interact);
static void resizeclient(Client *c, int x, int y, int w, int h);
static void resizemouse(const Arg *arg);
@@ -1296,6 +1297,13 @@
}
void
+resetnmaster(const Arg *arg)
+{
+ selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = 1;
+ arrange(selmon);
+}
+
+void
resize(Client *c, int x, int y, int w, int h, int interact)
{
if (applysizehints(c, &x, &y, &w, &h, interact))