Dwm的简单介绍


archlinux下dwm的初步安装

dwm

dwm(Dynamic Window Manager)是由suckless社区开发出的一款极其轻量的窗口管理器,与i3wm相似但是更加轻量,其源代码只有2000多行(C语言编写)。

安装

官方给出了安装包,但是这里建议通过git获取最新的源代码

git clone https://git.suckless.org/dwm

等待clone完成之后我们可以直接make clean install安装最原始的dwm,它的操作可以在/usr/local/man/man1/dwm.1中查看,当然我们也可以自己编辑config.h文件(源码的头文件)。
说起配置文件,让我想到了官方网站给出的patches(补丁),通过下载一些补丁可以让你的dwm变得更加强大(补丁源码两开花),我在大佬的推荐下打上了一些很基本的补丁,效果非常不错,在此简单介绍一下:

  • actualfullscreen 相比fullscreen的伪全屏,这个更加让人感到舒服,大家可以试着比较一下
  • alpha 使你的dwm状态栏拥有透明度,感觉不错嘛
  • autostart 让dwm可以在启动的时候自动执行脚本,我们可以写一些想要进入图形界面之后就需要运行的软件加入到脚本中比如连网程序、壁纸、输入法等等,这个脚本的位置在~/.dwm/autostart_blocking.sh~/.dwm/autostart.sh
    这里我只写了autostart.sh,如下
    #!/bin/bash
    feh --bg-fill ~/Media_data/Wallpapers/Wallpaper-22.png&
    picom&
    nm-applet&
    fcitx&
    其中fcitx已经通过fcitx-configtool配置好了,我们也可进入图形界面之后在配置
  • hide_vacant_tags 它可以把没有内容的标签页隐藏起来,桌面左端只显示有内容的标签页,既简洁有实用
  • vanitygaps 就是给各个小窗口之间添加间距的补丁,美观

打补丁的操作是在dwm文件目录下

patch < patches/dwm-vanitygaps-20200610-f09418b.diff

然后如果我们想要自定义一些快捷键的话,就直接修改源码config.h
这里贴下我的配置文件

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

/* appearance */
static const unsigned int borderpx  = 2;        /* border pixel of windows */
static const unsigned int snap      = 32;       /* snap pixel */
static const unsigned int gappih    = 5;       /* horiz inner gap between windows */
static const unsigned int gappiv    = 5;       /* vert inner gap between windows */
static const unsigned int gappoh    = 5;       /* horiz outer gap between windows and screen edge */
static const unsigned int gappov    = 5;       /* vert outer gap between windows and screen edge */
static const int smartgaps          = 1;        /* 1 means no outer gap when there is only one window */
static const int showbar            = 1;        /* 0 means no bar */
static const int topbar             = 0;        /* 0 means bottom bar */
static const char *fonts[]          = { "Hack Nerd Font:size=18" };     /*换成了我自己下载的字体*/
static const char dmenufont[]       = "Hack Nerd Font:size=18";
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[]        = "#37374f";    /*状态栏颜色*/
static const char col_border[]        = "#42a5f5";    /*窗口边框颜色*/
static const unsigned int baralpha = 0xd0;
static const unsigned int borderalpha = OPAQUE;
static const char *colors[][3]      = {
    /*               fg         bg         border   */
    [SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
    [SchemeSel]  = { col_gray4, col_cyan,  col_border  },    /*选中窗口时边框的颜色*/
};
static const unsigned int alphas[][3]      = {
    /*               fg      bg        border     */
    [SchemeNorm] = { OPAQUE, baralpha, borderalpha },
    [SchemeSel]  = { OPAQUE, baralpha, borderalpha },
};

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

static const Rule rules[] = {
    /* xprop(1):
     *    WM_CLASS(STRING) = instance, class
     *    WM_NAME(STRING) = title
     */
    /*   class                    instance     title    tags mask    isfloating   monitor */
    { "netease-cloud-music",     NULL,       NULL,       0,         True,         -1 },        /*网易云音乐浮动启动*/
    { "Firefox",                   NULL,       NULL,       1 << 8,    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 Layout layouts[] = {
    /* symbol     arrange function */
    { "[]=",      tile },    /* first entry is default */
    { "><>",      NULL },    /* no layout function means floating behavior */
    { "[M]",      monocle },
};

/* key definitions */
#define MODKEY Mod4Mask
#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} },

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

/* 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 *termcmd[]  = { "st", NULL };
static const char *music[]  = { "netease-cloud-music", NULL };    /*网易云音乐快捷键启动*/
static const char *firefox[]  = { "firefox", NULL };    /*火狐浏览器快捷键启动*/
static const char *scrot[]  = { "scrot", NULL };    /*自定义截图键,执行命令scrot*/
static const char *sound_add[]  = { "/home/haoleng/.dwm/script/amixer_add.sh", NULL };  /*音量调节脚本*/
static const char *sound_sub[]  = { "/home/haoleng/.dwm/script/amixer_sub.sh", NULL };    /*音量调节脚本*/

static Key keys[] = {
    /* modifier                     key        function        argument */
    { MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
    { MODKEY,                         XK_Return, spawn,          {.v = termcmd } },
    { MODKEY,                              XK_m,        spawn,          {.v = music } },        /* 定义快捷键 */
    { MODKEY,                              XK_o,        spawn,          {.v = firefox } },
    { MODKEY,                              XK_equal,  spawn,          {.v = scrot } },
    { MODKEY,                          XK_Up,        spawn,          {.v = sound_add } },
    { MODKEY,                          XK_Down,   spawn,          {.v = sound_sub } },
    { MODKEY,                       XK_b,      togglebar,      {0} },
    { MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
    { MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
    { MODKEY,                       XK_i,      incnmaster,     {.i = +1 } },
    { MODKEY,                       XK_d,      incnmaster,     {.i = -1 } },
    { MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
    { MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
    { MODKEY|Mod1Mask,              XK_h,      incrgaps,       {.i = +1 } },
    { MODKEY|Mod1Mask,              XK_l,      incrgaps,       {.i = -1 } },
    { MODKEY|Mod1Mask|ShiftMask,    XK_h,      incrogaps,      {.i = +1 } },
    { MODKEY|Mod1Mask|ShiftMask,    XK_l,      incrogaps,      {.i = -1 } },
    { MODKEY|Mod1Mask|ControlMask,  XK_h,      incrigaps,      {.i = +1 } },
    { MODKEY|Mod1Mask|ControlMask,  XK_l,      incrigaps,      {.i = -1 } },
    { MODKEY|Mod1Mask,              XK_0,      togglegaps,     {0} },
    { MODKEY|Mod1Mask|ShiftMask,    XK_0,      defaultgaps,    {0} },
     { MODKEY|Mod1Mask,              XK_Right,  incrihgaps,     {.i = +1 } },
     { MODKEY|Mod1Mask,              XK_Left,   incrihgaps,     {.i = -1 } },
     { MODKEY|ControlMask,           XK_Right,  incrivgaps,     {.i = +1 } },
     { MODKEY|ControlMask,           XK_Left,   incrivgaps,     {.i = -1 } },
     { MODKEY|Mod4Mask,              XK_Right,  incrohgaps,     {.i = +1 } },
     { MODKEY|Mod4Mask,              XK_Left,   incrohgaps,     {.i = -1 } },
     { MODKEY|ShiftMask,             XK_Right,  incrovgaps,     {.i = +1 } },
     { MODKEY|ShiftMask,             XK_Left,   incrovgaps,     {.i = -1 } },
    { MODKEY,                        XK_BackSpace,       zoom,     {0} },
    { MODKEY,                       XK_Tab,    view,           {0} },
    { MODKEY,                       XK_q,      killclient,     {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_space,  setlayout,      {0} },
    { MODKEY,                        XK_space,  togglefloating, {0} },
    { MODKEY,                       XK_f,      togglefullscr,  {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} },
};

/* button definitions */
/* click can be ClkTagBar, 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} },
};

上面的配置文件都十分好理解,我们完全可以直接修改很多东西,然后再在dwm目录运行make clean install,在xinitrc中将exec dwm添加到最后就可以startx进入dwm界面了。

状态栏

我的状态栏十分粗糙,只是在~/.xinitrc中添加了一点东西
如下

# N卡驱动相关的
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto

# 状态栏显示
while true;
do
WELCOME=$(echo " 📑 No Pains,No Gains! ")
MEMORY=$( free -m |grep '^Mem' |awk '{print "📏 "$3"MB |"}')
DATE=$( date +"📆 %F ⏰ %R ")
    xsetroot -name "$WELCOME $MEMORY $DATE"
     sleep 4s
done &

# 启动dwm
exec dwm

一点小问题

  • 在dwm下运行Android-studio会出现问题,这时候我的办法是打开终端,运行
    export _JAVA_AWT_WM_NONREPARENTING=1
    # 然后再通过命令启动android-studio
    # 在该终端下直接android-studio+回车
    android-studio 🔚
    今天刚装上dwm,写点的笔记,以便日后查阅.

Author: Haoleng
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Haoleng !
 Current
Dwm的简单介绍 Dwm的简单介绍
linux的Xwindow环境下的简洁窗口管理器
2020-07-12
Next 
Alacritty Alacritty
Archlinux下的Alacritty终端的配置github地址 Alacritty是一个免费的开源,快速,跨平台的终端仿真器,它使用GPU ( 图形处理单元 )进行渲染,实现了Linux中许多其他终端仿真器所不具备的某些优化。Ala
2020-06-20
  TOC