Dwm configuration and installation linux - Debian/Ubuntu 2/4

Categories:  linux,
Labels:  OS, bash, install

Overview:

Part 1: Preparation

Part 2: Configuration

Part 3: There are a lot of options

Part 4: Installation


Part 2: Configuration

Copy the default config file to config.h then open it. Use whatever editor you prefer to modify config.h, but I would recommend using one that allows syntax highlighting to help you understand what you’re doing :)

    cp config.def.h config.h
    vim config.h

It’s pretty well commented, but we’ll take a look through it bit by bit:

    /* See LICENSE file for copyright and license details. */

    /* appearance */
    static const char font[]            = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*";
    static const char normbordercolor[] = "#cccccc";
    static const char normbgcolor[]     = "#cccccc";
    static const char normfgcolor[]     = "#000000";
    static const char selbordercolor[]  = "#0066ff";
    static const char selbgcolor[]      = "#0066ff";
    static const char selfgcolor[]      = "#ffffff";
    static const unsigned int borderpx  = 1;        /* border pixel of windows */
    static const unsigned int snap      = 32;       /* snap pixel */
    static const Bool showbar           = True;     /* False means no bar */
    static const Bool topbar            = True;     /* False means bottom bar */

You can define the font the way you would for an xterm. The bottom two lines define whether it will be hidden and where it will be. Easy huh?
The selected window has a one-pixel border by default, of color #0066ff (blue, I think) The background and foreground colors refer to the status bar.

    /* tagging */
    static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };

    static const Rule rules[] = {
        /* class      instance    title       tags mask     isfloating   monitor */
        { "Gimp",     NULL,       NULL,       0,            True,        -1 },
        { "Firefox",  NULL,       NULL,       1 << 8,       False,       -1 },
    };

Dwm has multiple desktops, but they’re called tags and work slightly differently. By default they are numbered 1-9, but you can rename them however you want, just put the names in quotes.
The rules define how certain windows get treated, e.g. Gimp is always floating (not tiled or monocle/fullscreen) as it doesn’t work properly otherwise.
The “tags mask” defines which tag the window appears on. Basically read the << as “+”, so 1 << 8 means Firefox will be on tag 9.
0 means any tag.

1
2
3
4
5
6
7
8
9
10
    /* layout(s) */
    static const float mfact      = 0.55; /* factor of master area size [0.05..0.95] */
    static const Bool resizehints = True; /* True means respect size hints in tiled resizals */

    static const Layout layouts[] = {
            /* symbol     arrange function */
            { "[]=",      tile },    /* first entry is default */
            { "><>",      NULL },    /* no layout function means floating behavior */
            { "[M]",      monocle },
    };

Dwm has three layouts: tiling, floating (normal ‘Windows’ mode) and monocle (fullscreen). Here you can set the default layout, and the funky little symbol that will appear in the status bar.
Above that you can select the amount of the screen that the master window takes up.

1
2
3
4
5
6
7
    /* key definitions */
    #define MODKEY Mod1Mask
    #define TAGKEYS(KEY,TAG) \
            { MODKEY,                       KEY,      view,           {.ui = 1 << TAG} }, \
            { MODKEY|ControlMask,           KEY,      toggleview,     {.ui = 1 << TAG} }, \
            { MODKEY|ShiftMask,             KEY,      tag,            {.ui = 1 << TAG} }, \
            { MODKEY|ControlMask|ShiftMask, KEY,      toggletag,      {.ui = 1 << TAG} },

By default the modifier key is Alt (“Mod1Mask”). You could change it to Super/Windows by using “Mod4Mask” if you preferred.
The TAGKEYS set what happens if you press the number for a tag along with a modifier, so Alt-3 will take you to tag 3, while Alt-Shift-3 will tag (attach) a window to tag 3.

    /* helper for spawning shell commands in the pre dwm-5.0 fashion */
    #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }

I think this part speaks for itself :)

Now we get to the guts of it, the commands:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
    /* commands */
    static const char *dmenucmd[] = { "dmenu_run", "-fn", font, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL };
    static const char *termcmd[]  = { "uxterm", NULL };

    static Key keys[] = {
            /* modifier                     key        function        argument */
            { MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
            { MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
            { MODKEY,                       XK_b,      togglebar,      {0} },
            { MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
            { MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
            { MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
            { MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
            { MODKEY,                       XK_Return, zoom,           {0} },
            { MODKEY,                       XK_Tab,    view,           {0} },
            { MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
            { MODKEY,                       XK_t,      setlayout,      {.v = &layouts[0]} },
            { MODKEY,                       XK_f,      setlayout,      {.v = &layouts[1]} },
            { MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
            { MODKEY,                       XK_space,  setlayout,      {0} },
            { MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
            { MODKEY,                       XK_0,      view,           {.ui = ~0 } },
            { MODKEY|ShiftMask,             XK_0,      tag,            {.ui = ~0 } },
            { MODKEY,                       XK_comma,  focusmon,       {.i = -1 } },
            { MODKEY,                       XK_period, focusmon,       {.i = +1 } },
            { MODKEY|ShiftMask,             XK_comma,  tagmon,         {.i = -1 } },
            { MODKEY|ShiftMask,             XK_period, tagmon,         {.i = +1 } },
            TAGKEYS(                        XK_1,                      0)
            TAGKEYS(                        XK_2,                      1)
            TAGKEYS(                        XK_3,                      2)
            TAGKEYS(                        XK_4,                      3)
            TAGKEYS(                        XK_5,                      4)
            TAGKEYS(                        XK_6,                      5)
            TAGKEYS(                        XK_7,                      6)
            TAGKEYS(                        XK_8,                      7)
            TAGKEYS(                        XK_9,                      8)
            { MODKEY|ShiftMask,             XK_q,      quit,           {0} },
    };

The first two commands in the long list spawn commands; note how those commands are defined above that, with each separate part of the command in quotes and with NULL at the end. So any commands you wanted to add would need to be defined under ‘commands’, then called in the ‘keys’ section.
XK_p means the button ’p’, etc.
If instead of ‘MODKEY’ you put ‘0’, that would mean ‘no modifier’.
‘focusstack’ means next or previous window, depending on the +1 or -1
‘setmfact’ means set the size of the master window in tiling mode
‘zoom’ is move a window to the master window in tiling mode
‘setlayout’ chooses a layout based on the order defined earlier, starting numbering from 0
The TAGKEYS select the tags - note that the tags as far as dwm is concerned number from 0-8.
Lastly, Alt-Shift-q quits dwm and takes you back to a tty.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    /* button definitions */
    /* click can be ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
    static Button buttons[] = {
            /* click                event mask      button          function        argument */
            { ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
            { ClkLtSymbol,          0,              Button3,        setlayout,      {.v = &layouts[2]} },
            { ClkWinTitle,          0,              Button2,        zoom,           {0} },
            { ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
            { ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
            { ClkClientWin,         MODKEY,         Button2,        togglefloating, {0} },
            { ClkClientWin,         MODKEY,         Button3,        resizemouse,    {0} },
            { ClkTagBar,            0,              Button1,        view,           {0} },
            { ClkTagBar,            0,              Button3,        toggleview,     {0} },
            { ClkTagBar,            MODKEY,         Button1,        tag,            {0} },
            { ClkTagBar,            MODKEY,         Button3,        toggletag,      {0} },
    };

Here you define what happens when you click in various places, with and without the mod keys.
‘ClkLtSymbol’ means ‘click layout symbol’.

Social Profiles

This web accept cryptocoin donations
BTC address, LTC, ETH, DASH, Uphold:
Why donations?