试试动态窗口管理器 dwm 吧
dwm
![](/data/attachment/album/201908/16/182917m5zy54vvy5zwbeyp.png)


如果你崇尚效率和极简主义，并且正在为你的 Linux 桌面寻找新的窗口管理器，那么你应该尝试一下<ruby> 动态窗口管理器 <rt>  dynamic window manager </rt></ruby> dwm。以不到 2000 标准行的代码写就的 dwm，是一个速度极快而功能强大，且可高度定制的窗口管理器。


你可以在平铺、单片和浮动布局之间动态选择，使用标签将窗口组织到多个工作区，并使用键盘快捷键快速导航。本文将帮助你开始使用 dwm。


### 安装


要在 Fedora 上安装 dwm，运行：



```
$ sudo dnf install dwm dwm-user
```

`dwm` 包会安装窗口管理器本身，`dwm-user` 包显著简化了配置，本文稍后将对此进行说明。


此外，为了能够在需要时锁定屏幕，我们还将安装 `slock`，这是一个简单的 X 显示锁屏。



```
$ sudo dnf install slock
```

当然，你可以根据你的个人喜好使用其它的锁屏。


### 快速入门


要启动 dwm，在登录屏选择 “dwm-user” 选项。


![](/data/attachment/album/201908/16/182929bc33e3pbrpx3ey4r.png)


登录后，你将看到一个非常简单的桌面。事实上，顶部唯一的一个面板列出了代表工作空间的 9 个标签和一个代表窗户布局的 `[]=` 符号。


#### 启动应用


在查看布局之前，首先启动一些应用程序，以便你可以随时使用布局。可以通过按 `Alt+p` 并键入应用程序的名称，然后回车来启动应用程序。还有一个快捷键 `Alt+Shift+Enter` 用于打开终端。


现在有一些应用程序正在运行了，请查看布局。


#### 布局


默认情况下有三种布局：平铺布局，单片布局和浮动布局。


平铺布局由条形图上的 `[]=` 表示，它将窗口组织为两个主要区域：左侧为主区域，右侧为堆叠区。你可以按 `Alt+t` 激活平铺布局。


![](/data/attachment/album/201908/16/182940dt6go8b2k66qt9q1.png)


平铺布局背后的想法是，主窗口放在主区域中，同时仍然可以看到堆叠区中的其他窗口。你可以根据需要在它们之间快速切换。


要在两个区域之间交换窗口，请将鼠标悬停在堆叠区中的一个窗口上，然后按 `Alt+Enter` 将其与主区域中的窗口交换。


![](/data/attachment/album/201908/16/182952rv2xc7k2o8tcz7oo.png)


单片布局由顶部栏上的 `[N]` 表示，可以使你的主窗口占据整个屏幕。你可以按 `Alt+m` 切换到它。


最后，浮动布局可让你自由移动和调整窗口大小。它的快捷方式是 `Alt+f`，顶栏上的符号是 `><>`。


#### 工作区和标签


每个窗口都分配了一个顶部栏中列出的标签（1-9）。要查看特定标签，请使用鼠标单击其编号或按 `Alt+1..9`。你甚至可以使用鼠标右键单击其编号，一次查看多个标签。


通过使用鼠标突出显示后，并按 `Alt+Shift+1..9`，窗口可以在不同标签之间移动。


### 配置


为了使 dwm 尽可能简约，它不使用典型的配置文件。而是你需要修改代表配置的 C 语言头文件，并重新编译它。但是不要担心，在 Fedora 中你只需要简单地编辑主目录中的一个文件，而其他一切都会在后台发生，这要归功于 Fedora 的维护者提供的 `dwm-user` 包。


首先，你需要使用类似于以下的命令将文件复制到主目录中：



```
$ mkdir ~/.dwm
$ cp /usr/src/dwm-VERSION-RELEASE/config.def.h ~/.dwm/config.h
```

你可以通过运行 `man dwm-start` 来获取确切的路径。


其次，只需编辑 `~/.dwm/config.h` 文件。例如，让我们配置一个新的快捷方式：通过按 `Alt+Shift+L` 来锁定屏幕。


考虑到我们已经安装了本文前面提到的 `slock` 包，我们需要在文件中添加以下两行以使其工作：


在 `/* commands */` 注释下，添加：



```
static const char *slockcmd[] = { "slock", NULL };
```

添加下列行到 `static Key keys[]` 中：



```
{ MODKEY|ShiftMask, XK_l, spawn, {.v = slockcmd } },
```

最终，它应该看起来如下：



```
...
 /* 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 *slockcmd[] = { "slock", NULL };

 static Key keys[] = {
     /* modifier                     key        function        argument */
     { MODKEY|ShiftMask,             XK_l,      spawn,          {.v = slockcmd } },
     { MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
     { MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
 ...
```

保存文件。


最后，按 `Alt+Shift+q` 注销，然后重新登录。`dwm-user` 包提供的脚本将识别你已更改主目录中的`config.h` 文件，并会在登录时重新编译 dwm。因为 dwm 非常小，它快到你甚至都不会注意到它重新编译了。


你现在可以尝试按 `Alt+Shift+L` 锁定屏幕，然后输入密码并按回车键再次登录。


### 总结


如果你崇尚极简主义并想要一个非常快速而功能强大的窗口管理器，dwm 可能正是你一直在寻找的。但是，它可能不适合初学者，你可能需要做许多其他配置才能按照你的喜好进行配置。


要了解有关 dwm 的更多信息，请参阅该项目的主页： <https://dwm.suckless.org/>。




---


via: <https://fedoramagazine.org/lets-try-dwm-dynamic-window-manger/>


作者：[Adam Šamalík](https://fedoramagazine.org/author/asamalik/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[wxy](https://github.com/wxy) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
If you like efficiency and minimalism, and are looking for a new window manager for your Linux desktop, you should try *dwm* — dynamic window manager. Written in under 2000 standard lines of code, dwm is extremely fast yet powerful and highly customizable window manager.

You can dynamically choose between tiling, monocle and floating layouts, organize your windows into multiple workspaces using tags, and quickly navigate through using keyboard shortcuts. This article helps you get started using dwm.

**Installation**

To install dwm on Fedora, run:

$ sudo dnf install dwm dwm-user

The *dwm* package installs the window manager itself, and the *dwm-user* package significantly simplifies configuration which will be explained later in this article.

Additionally, to be able to lock the screen when needed, we’ll also install *slock* — a simple X display locker.

$ sudo dnf install slock

However, you can use a different one based on your personal preference.

**Quick start**

To start dwm, choose the *dwm-user* option on the login screen.

![](https://fedoramagazine.org/wp-content/uploads/2019/03/choosing-dwm-1024x469.png)

After you log in, you’ll see a very simple desktop. In fact, the only thing there will be a bar at the top listing our nine tags that represent workspaces and a *[]=* symbol that represents the layout of your windows.

### Launching applications

Before looking into the layouts, first launch some applications so you can play with the layouts as you go. Apps can be started by pressing *Alt+p* and typing the name of the app followed by *Enter*. There’s also a shortcut *Alt+Shift+Enter* for opening a terminal.

Now that some apps are running, have a look at the layouts.

### Layouts

There are three layouts available by default: the tiling layout, the monocle layout, and the floating layout.

The tiling layout, represented by *[]=* on the bar, organizes windows into two main areas: master on the left, and stack on the right. You can activate the tiling layout by pressing *Alt+t.*

![](https://fedoramagazine.org/wp-content/uploads/2019/03/dwm-desktop-1024x593.png)

The idea behind the tiling layout is that you have your primary window in the master area while still seeing the other ones in the stack. You can quickly switch between them as needed.

To swap windows between the two areas, hover your mouse over one in the stack area and press *Alt+Enter* to swap it with the one in the master area.

![](https://fedoramagazine.org/wp-content/uploads/2019/03/Screenshot-2019-03-15-at-11.12.32-1024x592.png)

The monocle layout, represented by *[N]* on the top bar, makes your primary window take the whole screen. You can switch to it by pressing *Alt+m*.

Finally, the floating layout lets you move and resize your windows freely. The shortcut for it is *Alt+f* and the symbol on the top bar is *><>*.

### Workspaces and tags

Each window is assigned to a tag (1-9) listed at the top bar. To view a specific tag, either click on its number using your mouse or press *Alt+1..9.* You can even view multiple tags at once by clicking on their number using the secondary mouse button.

Windows can be moved between different tags by highlighting them using your mouse, and pressing *Alt+Shift+1..9.*

**Configuration**

To make dwm as minimalistic as possible, it doesn’t use typical configuration files. Instead, you modify a C header file representing the configuration, and recompile it. But don’t worry, in Fedora it’s as simple as just editing one file in your home directory and everything else happens in the background thanks to the *dwm-user* package provided by the maintainer in Fedora.

First, you need to copy the file into your home directory using a command similar to the following:

$ mkdir ~/.dwm

$ cp /usr/src/dwm-VERSION-RELEASE/config.def.h ~/.dwm/config.h

You can get the exact path by running *man dwm-start.*

Second, just edit the *~/.dwm/config.h* file. As an example, let’s configure a new shortcut to lock the screen by pressing *Alt+Shift+L*.

Considering we’ve installed the *slock* package mentioned earlier in this post, we need to add the following two lines into the file to make it work:

Under the */* commands */ *comment, add:

static const char *slockcmd[] = { "slock", NULL };

And the following line into *static Key keys[]*:

{ MODKEY|ShiftMask, XK_l, spawn, {.v = slockcmd } },

In the end, it should look like as follows: (added lines are highlighted)

...

/* 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 *slockcmd[] = { "slock", NULL };

static Key keys[] = {

/* modifier key function argument */{ MODKEY|ShiftMask, XK_l, spawn, {.v = slockcmd } },{ MODKEY, XK_p, spawn, {.v = dmenucmd } },

{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },

...

Save the file.

Finally, just log out by pressing *Alt+Shift+q* and log in again. The scripts provided by the *dwm-user* package will recognize that you have changed the *config.h* file in your home directory and recompile dwm on login. And becuse dwm is so tiny, it’s fast enough you won’t even notice it.

You can try locking your screen now by pressing *Alt+Shift+L*, and then logging back in again by typing your password and pressing enter.

**Conclusion**

If you like minimalism and want a very fast yet powerful window manager, dwm might be just what you’ve been looking for. However, it probably isn’t for beginners. There might be a lot of additional configuration you’ll need to do in order to make it just as you like it.

To learn more about dwm, see the project’s homepage at [https://dwm.suckless.org/](https://dwm.suckless.org/).

## Kerel

Any people favoring dwm over i3wm?

## Adam Šamalík

I think it depends on what you want. i3 is probably easier to configure and customize, there are more resources for it also. dwm on the other hand is really tiny and lets you build a much lighter setup. I used both and I liked both for different reasons.

## Kostas

Looks like an nice window manager. If i want to try it out on a headless system, like Fedora Server, the only other requirement is to install X.org ?

## Saša

If you’re not going to compile it yourself, yes. If you compile it yourself, you’ll need additional libraries for compilation. I’ve been using fedora minimal install with suckless tools for a few months and I am loving it. If you’re interested in making your own suckless setup from scratch take a look at my configuration (https://github.com/saleone/configs). There is an Ansible playbook that you can run right after the base system is installed to set up everything (but you should adjust it based on your computer and needs).

## Adam Šamalík

Nice! Did you try the dwm-user package? It recompiles dwm automatically on login when you change the config.h in your home. It’s really cool.

## Saša

I haven’t tried it. I’ve made my own changes to dwm source and applied a few patches from their website which do not only affect config.h file (autostart, layouts per tag, …). It’s much easier for me to copy my repo than to apply series of patches even if I could change the dwm source with dwm-user package. Doing manual compilation is just one more step, and that is just calling

, so its not a big deal, you still have to log out.

## Adam Šamalík

Not sure if I remember exactly, but when I was building a custom desktop from Fedora minimal I installed X, input and video drivers, xinit, and dwm. My laptop had an integrated intel graphics. I think these were the packages:

xorg-x11-server-Xorg

xorg-x11-drv-evdev

xorg-x11-drv-intel

xinit

dwm

dwm-user

And then I created ~/.xinitrc and added “dwm-user” to it.

Sorry I don’t have that sytem around anymore, would have looked otherwise. Good luck!

## Ilia

Oh, it is my favorite tiling vm.

## Adam Šamalík

I really like it too for how tiny it is.

## Jayanth Varma B

Really impressed by this window manager. If all goes fine I am going to make a shift from XFCE4 to dwm.

## Adam Šamalík

Glad you like it. Good luck!

## owczarz

Haha 🙂 I just have switched from XFCE to i3 😀

Congrats on your decision 🙂

## Gustavo Murillo

I don’t know if this is added by default, but if it’s not you The next line should be added to the dwm session:

dbus-update-activation-environment –systemd DBUS_SESSION_BUS_ADDRESS DISPLAY XAUTHORITY &

If it’s not set some applications don’t launch or take time to launch. Like gnome-terminal and nautilus.

I add it in .xinitrc and launch with xinit, the maintainer should make a patch with this if it’s not already set.

## Adam Šamalík

I think it’s meant to be really minimalistic with as little dependencies as possible, an also flexible — like potentially running without dbus. That’s probably why there’s as little default settings as possible. As I understand it, it’s targeted at advanced users anyway and it might be expected that you need to do things in .xinitrc to make it run the way you like it. But I’m sure the maintainer will give you a better answer than me. 🙂

## Pierre Stassen

Hi, nice to see an article on dwm!

I use it and I love it, but on Fedora it feels like a little step backwards because it’s a window manager for X. On the other hand Sway, the i3-based alternative for Wayland, is not working flawless.

## Lena Kelly

Manger?

## Paul W. Frields

@Lena: Thanks, fixed!