前言 本篇博文会带你从零开始安装配置dwm 你也可以看看我的dwm配置,虽然说不是很完美,但是正常使用是没有什么问题的:
https://github.com/Aidens-fox/dwm
配置完成的效果
下载安装&启动dwm 在安装dwm之前我们需要安装一些必要的软件,比如xorg,编译工具等等sudo pacman -S base-devel git xorg-server xorg-xinit xorg-xrandr xorg-xsetroot xorg-xset xsel xorg-xkill libx11 libxft libxinerama xwallpaper 我们可以使用git工具来克隆dwm项目git clone https://git.suckless.org/dwm
其他的比如st,dmenu也需要克隆,不然进入后无法打开终端和软件启动器 st: git clone https://git.suckless.org/st dmenu: git clone https://git.suckless.org/dmenu
克隆完成后cd到项目目录编译安装dwm(st和dmenu也一样) `sudo make clean install
编译安装好后我们在.xinitrc文件添加:exec dwm 保存后只需要用在tty输入startx就可以启动 (注:exec dwm必须放在最后一行,不然无法启动)
配置dwm 我们cd到dwm目录下会发现有很多文件,其中config.def.h是我们修改配置的文件,虽然在第一次编译后产生的config.h文件也可以配置dwm,但是很多补丁添加快捷键都是修改在config.def.h上面,如果直接使用config.h来配置dwm可能就需要手动添加补丁的快捷键了,使用我比较习惯修改config.def.h在rm -rf config.h删除之前旧配置,不然再次编译安装就还是之前的配置
状态栏配置字体和位置&颜色 在默认配置中的状态栏字体是十分丑陋的,中文显示不友好,所有需要修改字体:
1 2 3 4 5 static const char *fonts[] = { "JetBrainsMono Nerd Font:size=15" , "Sarasa Mono SC:size=15" , "Noto Color Emoji:size=15" };
字体使用更纱黑体和jetbrains,notosudo pacman -S ttf-sarasa-gothic noto-fonts noto-fonts-emoji noto-fonts-cjk ttf-jetbrains-mono-nerd
状态栏默认的配色方案可能有一点难看,所有可以更改颜色
1 2 3 4 5 static const char col_gray1[] = "#282828" ; static const char col_gray2[] = "#282828" ; static const char col_gray3[] = "#ebdbb2" ; static const char col_gray4[] = "#ebdbb2" ; static const char col_cyan[] = "#5b623e" ;
本配色方案参考gruvbox
tags工作区默认显示的是1234,如果你觉得太普通也可以改成中国数字大写 `static const char *tags[] = { “壹”, “貳”, “叁”, “肆”, “伍”, “陸”, “柒”, “捌”, “玖” };
修改mod键 在dwm中默认是alt为mod键,我本人不太习惯,所以我把它更改为win键#define MODKEY Mod4Mask
亮度&音量快捷键支持 在config.h中添加下面内容,启用多媒体按键#include <X11/XF86keysym.h>
调节音量
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 static const char *up_vol[] = { "pactl" , "set-sink-volume" , "@DEFAULT_SINK@" , "+10%" , NULL };static const char *down_vol[] = { "pactl" , "set-sink-volume" , "@DEFAULT_SINK@" , "-10%" , NULL };static const char *mute_vol[] = { "pactl" , "set-sink-mute" , "@DEFAULT_SINK@" , "toggle" , NULL };... static const Key keys[] = { ... { 0 , XF86XK_AudioMute, spawn, {.v = mute_vol } }, { 0 , XF86XK_AudioLowerVolume, spawn, {.v = down_vol } }, { 0 , XF86XK_AudioRaiseVolume, spawn, {.v = up_vol } }, ... };
调节亮度(需要安装brightnessctl)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 static const char *brighter[] = { "brightnessctl" , "set" , "10%+" , NULL };static const char *dimmer[] = { "brightnessctl" , "set" , "10%-" , NULL };... static const Key keys[] = { ... { 0 , XF86XK_MonBrightnessDown, spawn, {.v = dimmer } }, { 0 , XF86XK_MonBrightnessUp, spawn, {.v = brighter } }, ... };
状态栏显示内容 我们可以通过xsetroot -name的方式来让状态栏显示我们需要的内容,在.xinitrc添加:
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 while true ; do light =$(brightnessctl -m | cut -d, -f4)bat_s =$(< /sys/class/power_supply/BAT0/status)bat =$(< /sys/class/power_supply/BAT0/capacity)time =$(date +" %Y-%m-%d-(0%u) %H:%M:%S" )audio_raw =$(wpctl get-volume @DEFAULT_AUDIO_SINK@)if [[ "$audio_raw " == *"[MUTED]" * || "$audio_raw " == *"[NO]" * ]]; then audio ="MUTED" else audio =$(echo "$audio_raw " | awk '{print ($2 * 100)"%"}' ) fi if [[ "$(< /sys/class/net/wlp0s20f3/operstate) " == "up" ]]; then net_icon ="*" else net_icon ="-" fi if ss -tln | grep :0000; then #"0000" 改成自己的代理端口 proxy_str ="+" else proxy_str ="-" fi if [[ "$bat_s " == "Discharging" ]]; then bat_icon =" " else bat_icon =" " fi xsetroot -name "[$proxy_str ][$net_icon ][ $audio ][$light ][$bat_icon $bat %][$time ]" sleep 1s done &
如果你觉得那么多东西塞在.xinitrc很乱,可以创建一个脚本文件,里面写入上面的内容,在.xinitrc只需要循环执行这个脚本就可以了 脚本内容:
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 #!/bin/zsh light=$(brightnessctl -m | cut -d, -f4) bat_s=$(< /sys/class/power_supply/BAT0/status) bat=$(< /sys/class/power_supply/BAT0/capacity) time =$(date +" %Y-%m-%d-(0%u) %H:%M:%S" )audio_raw=$(wpctl get-volume @DEFAULT_AUDIO_SINK@) if [[ "$audio_raw " == *"[MUTED]" * || "$audio_raw " == *"[NO]" * ]]; then audio="MUTED" else audio=$(echo "$audio_raw " | awk '{print ($2 * 100)"%"}' ) fi if [[ "$(< /sys/class/net/wlp0s20f3/operstate) " == "up" ]]; then net_icon="*" else net_icon="-" fi if ss -tln | grep :0000; then proxy_str="+" else proxy_str="-" fi if [[ "$bat_s " == "Discharging" ]]; then bat_icon=" " else bat_icon=" " fi xsetroot -name "[$proxy_str ][$net_icon ][ $audio ][$light ][$bat_icon$bat %][$time ]"
.xinit文件写入
1 2 3 4 5 while true ; do /home/用户名/脚本.sh sleep 1s done &
或者你也可以使用例如slstatus这样的软件,配置参考「slstatus 状态栏」使用参考 在suckless里git克隆下来源代码:git clone https://git.suckless.org/slstatus
克隆完成cd进入该目录,使用文本编辑器打开config.def.h文件,在下面的static const struct arg args[]部分添加:
1 2 3 4 5 6 7 static const struct arg args[] = { /* function format argument */ { cpu_perc, "[CPU:%s%% ]" , NULL }, { ram_perc, "[RAM:%s%] " , NULL }, { vol_perc, "[Volume:%s%] " , "/dev/mixer" }, { datetime, "%s " , "[%Y -%m -%d -(0%u ) %H :%M :%S ]" }, };
添加完成后保存再使用make编译安装:sudo make clean install
然后在.xinitrc里添加slstatus &
其他类似的软件自行google
自启动软件 我们编辑.xinitrc文件 在里面添加你需要自启动的软件,比如fcitx5exec fcitx5 &
打补丁 补丁是dwm的一大特色,我们可以到https://dwm.suckless.org/patches/去找补丁,然后在dwm目录下新建一个叫patches的文件夹 mkdir patches 把你想要的补丁下载下来,如attachaside,再安装补丁patch < patches/dwm-xxxxxxx.diff 卸载补丁patch -R < patches/dwm-xxxxxxxxx.diff
不过在打补丁的过程中可能会出现报错,这个时候就要查config.def.h.rej和dwm.c.rej文件来看看需要删除什么和添加什么,然后在重新编译基本就可以解决问题了
解决dwm浏览器无法弹出文件对话框 参考https://forum.archlinuxcn.org/t/topic/13788 把以下命令添加到.xinitrc文件中
1 dbus-update-activation-environment --systemd DISPLAY
关闭自动熄屏 在.xinitrc添加xset s off -dpms
添加一个壁纸 安装xwallpaper后在.xinitrc添加xwallpaper --zoom 壁纸.png
解决火焰截图无法截屏 参考https://bbs.archlinux.org/viewtopic.php?id=313917 在/.config/flameshot/flameshot.ini文件添加
1 2 [General] useX11LegacyScreenshot =true