您尚未登录。

#1 2017-09-04 14:26:28

zplinux
会员
所在地: 江西省
注册时间: 2014-10-12
帖子: 154

平铺式窗口管理器 DWM 的简单配置

偶然看到这个几年前帖子,
http://bbs.archlinuxcn.org/viewtopic.php?id=1502
正巧我一直用的dwm,就针对这几个问题说一下,
时间太久了,也许对前面帖子的楼主帮助不大。

更改壁纸
dwm 似乎并不支持直接加载壁纸,
可以用其他工具辅助,我用的是 habak,
编辑~/.xinitrc ,增加如下一行:

habak -ms ~/pic/wallpaper.png &

使用 patch
这个我没找到比较好的方法,是参照官方网站手工修改打补丁的。
http://dwm.suckless.org/patches/
如果只需要一个补丁的话,可以用 patch 来实现,但多个补丁 ... 我就只能用苯办法实现了。

修改配色
这个比较简单,在 config.h 中直接修改即可:

static const char normbordercolor[] = "#444444";
static const char normbgcolor[]     = "#E0E0E0";
static const char normfgcolor[]     = "#101010";
static const char selbordercolor[]  = "#FFDD00";
static const char selbgcolor[]      = "#0066FF";
static const char selfgcolor[]      = "#F3F3F3";

状态栏
这个在官方网站也有表述。
http://dwm.suckless.org/dwmstatus/
我早些时候用的是 barm, 功能比较简单。
现在改用 slstatus 了,
在~/.xinitrc 里面实现了开机自动加载:

slstatus -d &

其他的没尝试过, 应该有更美观的。

终端窗口透明
我选用的是 st 作为终端窗口,打了透明度补丁:
http://st.suckless.org/patches/alpha/
然后安装了 xcompmgr,并在~/.xinitrc 里面实现了开机自动加载:

xcompmgr &

热键,及热键对应程序的修改
在 config.h 中根据已有的条目修改:
修改两处位置,一个是定义:

static const char *explorercmd[]    = { "thunar", NULL };

另一处是热键绑定:

static Button buttons[] = {... 
{ MODKEY,                     XK_F4,     spawn,      {.v = explorercmd } },
... 以下省略

具体例子可以看后面我的 config.h 配置。

我的桌面效果是这样的:
14d7ed5d13583abfd6d2a2d466344c8f55a70a.png

我的 config.h 配置是这样的:

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

/* appearance */
static const char *fonts[] = {
	"Helvetica Narrow:size=10"
};
static const char dmenufont[]       = "Inziu Iosevka SC:size=10";
static const char normbordercolor[] = "#444444";
static const char normbgcolor[]     = "#E0E0E0";
static const char normfgcolor[]     = "#101010";
static const char selbordercolor[]  = "#FFDD00";
static const char selbgcolor[]      = "#0066FF";
static const char selfgcolor[]      = "#F3F3F3";
static const unsigned int borderpx  = 1;        /* border pixel of windows */
static const unsigned int snap      = 32;       /* snap pixel */
static const unsigned int systraypinning  = 0;  /* 0: sloppy systray follows selected monitor, >0: pin systray to monitor X */
static const unsigned int systrayspacing  = 2;  /* systray spacing */
static const int systraypinningfailfirst  = 1;  /* 1: if pinning fails, display systray on the first monitor, 0: display systray on the last monitor*/
static const int showsystray              = 1;  /* 0 means no systray */
static const int showbar            = 1;        /* 0 means no bar */
static const int topbar             = 1;        /* 0 means bottom bar */
static const int focusoncross       = 0;          /* 0 means not focus on cross */

/* tagging */
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "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 */
    { "st",     NULL,    NULL,    0,          0,           -1 },
    { "Gimmage",  NULL,       NULL,   1 << 2   ,       0,           -1 },
    { "Thunar",  NULL,       NULL,   1 << 3   ,       0,           -1 },
    { "libreoffice",  NULL,       NULL,   1 << 4   ,       0,           -1 },
    { "Gimp",     NULL,       NULL,       1 << 6,       0,           -1 },
    { "Chromium",  NULL,       NULL,       1 << 8,       0,           -1 },
    { "Hexchat",  NULL,       NULL,       1 << 8,       0,           -1 },
};

/* layout(s) */
static const float mfact     = 0.5; /* factor of master area size [0.05..0.95] */
static const int nmaster     = 1;    /* number of clients in master area */
static const int resizehints = 0;    /* 1 means respect size hints in tiled resizals */

static const Layout layouts[] = {
	/* symbol     arrange function */
    { "[V]",      vtile },    /* first entry is default */
    { "[F]",      monocle },
    { "[T]",      tile },
	{ "[N]",      NULL },    /* no layout function means floating behavior */
};

/* 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} },

/* helper for spawning shell commands in the pre dwm-5.0 fashion */
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/bash", "-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", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL };
static const char *termcmd[]  = { "st", NULL };
static const char *poweroffcmd[]    = { "st", "-e", "sudo", "poweroff", NULL };
static const char *rebootcmd[]      = { "st", "-e", "sudo", "reboot", NULL };
static const char *updatecmd[]      = { "st", "-e", "sudo", "pacman", "-Syu", "--ignore", "dwm", "--noconfirm", NULL };
static const char *volumecmd[]    = { "st", "-e", "alsamixer", NULL };
static const char *printscreencmd[] = { "scrot", NULL };
static const char *printscreendelaycmd[] = { "scrot", "-d 3", NULL };
static const char *explorercmd[]    = { "thunar", NULL };
static const char *picviewcmd[]    = { "gimmage", NULL };
static const char *officecmd[]      = { "libreoffice", NULL };
static const char *notecmd[]        = { "keepnote", NULL };
static const char *pdfviewcmd[]    = { "evince", NULL };
static const char *imagecmd[]    = { "gimp", NULL };
static const char *webcmd[]         = { "chromium", NULL };
static const char *videocmd[]       = { "parole", NULL };
static const char *chatcmd[]          = { "hexchat", NULL };
static const char *clearcmd[]          = { "bleachbit", NULL };
static const char *clearrootcmd[]          = { "sudo", "bleachbit", NULL };

static Key keys[] = {
	/* modifier                     key        function        argument */
    { MODKEY,                     XK_Return, spawn,      {.v = termcmd } },
    { MODKEY,                     XK_Print,  spawn,      {.v = printscreencmd } },
    { MODKEY|ShiftMask,           XK_Print,  spawn,      {.v = printscreendelaycmd } },
    { MODKEY,                     XK_space,  setlayout,  {0} },
    { MODKEY|ShiftMask,           XK_space,  togglefloating,  {0} },
    { MODKEY,                     XK_Tab,    zoom,       {0} },
    { MODKEY|ShiftMask,           XK_Tab,    view,       {0} },
    { MODKEY,                     XK_a,      view,       {.ui = ~0 } },
    { MODKEY,                     XK_b,      togglebar,  {0} },
    { MODKEY,                     XK_q,      quit,       {0} },
    { MODKEY,                     XK_w,      spawn,      {.v = volumecmd } },
    { MODKEY,                     XK_r,      spawn,      {.v = rebootcmd } },
    { MODKEY,                     XK_d,      spawn,      {.v = poweroffcmd } },
    { 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_o,      incnmaster, {.i = +1 } },
    { MODKEY,                     XK_p,      incnmaster, {.i = -1 } },
    { MODKEY,                     XK_v,      setlayout,  {.v = &layouts[0]} },
    { MODKEY,                     XK_f,      setlayout,  {.v = &layouts[1]} },
    { MODKEY,                     XK_t,      setlayout,  {.v = &layouts[2]} },
    { MODKEY,                     XK_c,      killclient, {0} },
    { MODKEY,                     XK_m,      spawn,      {.v = dmenucmd } },
    { MODKEY,                     XK_u,      spawn,      {.v = updatecmd } },
    { MODKEY,                     XK_F1,     spawn,      {.v = notecmd } },
    { MODKEY,                     XK_F2,     spawn,      {.v = pdfviewcmd } },
    { MODKEY,                     XK_F3,     spawn,      {.v = picviewcmd } },
    { MODKEY,                     XK_F4,     spawn,      {.v = explorercmd } },
    { MODKEY,                     XK_F5,     spawn,      {.v = officecmd } },
    { MODKEY,                     XK_F7,     spawn,      {.v = imagecmd } },
    { MODKEY,                     XK_F8,     spawn,      {.v = videocmd } },
    { MODKEY,                     XK_F9,     spawn,      {.v = webcmd } },
    { MODKEY,                     XK_F10,     spawn,      {.v = chatcmd } },
    { MODKEY,                     XK_F12,    spawn,      {.v = clearcmd } },
    { MODKEY|ShiftMask,           XK_F12,    spawn,      {.v = clearrootcmd } },
    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)
};

/* 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} },
};

曾经用过 CentOS,怀念 Gnome2 的桌面!现在投奔 ArchLinux 阵营,深深地被它 K.I.S.S 理念所吸引了……

离线

#2 2017-09-04 17:46:09

血族使天
会员
注册时间: 2013-01-12
帖子: 110

Re: 平铺式窗口管理器 DWM 的简单配置

说真的,我觉得一个桌面环境把配置写在源码里真的是很神奇啊,每次更改配置都要重新编译吗?这样做有什么好处呢?性能?

离线

#3 2017-09-04 18:53:16

zplinux
会员
所在地: 江西省
注册时间: 2014-10-12
帖子: 154

Re: 平铺式窗口管理器 DWM 的简单配置

血族使天 说:

说真的,我觉得一个桌面环境把配置写在源码里真的是很神奇啊,每次更改配置都要重新编译吗?这样做有什么好处呢?性能?

也许是性能吧,我也说不上来,
感觉功能够用了, 配置也简单明了, 就一直在用它。


曾经用过 CentOS,怀念 Gnome2 的桌面!现在投奔 ArchLinux 阵营,深深地被它 K.I.S.S 理念所吸引了……

离线

#4 2017-09-04 21:11:22

依云
a.k.a. 百合仙子
所在地: 一个等待妹纸出现的地方
注册时间: 2011-08-21
帖子: 4,384
个人网站

Re: 平铺式窗口管理器 DWM 的简单配置

血族使天 说:

说真的,我觉得一个桌面环境把配置写在源码里真的是很神奇啊,每次更改配置都要重新编译吗?这样做有什么好处呢?性能?

不用写解析器。

离线

页脚