将 i3 与多个显示器配合使用
i3 显示器
![](/data/attachment/album/201906/29/140556o3o9o3j77ju7j3m9.jpg)


你在 Linux 工作站上使用多个显示器吗？一次看到很多东西可能是有益的。但在我们的工作中通常有比实际显示器更多的窗口 —— 这是一件好事，因为一次看到太多东西可能会分散注意力。因此能够切换我们在单个显示器上看到的内容似乎很重要。


让我们来看看 i3，它是一个流行的平铺窗口管理器，可以与多个显示器配合使用。并且有许多其他窗口管理器没有的便利功能，它能够独立地在各个显示器上切换工作区。


### 快速介绍 i3


大约三年前，[Fedora Magazine 已经写了一篇关于 i3 的文章](https://fedoramagazine.org/getting-started-i3-window-manager/)。这是有史以来最受欢迎的文章之一！虽然情况并非总是如此，但 i3 非常稳定，而且那篇文章如今也很准确。所以，这次不会重复太多内容，本篇只涵盖了让 i3 启动和运行的极少内容，如果你是 i3 的新手，想要了解更多基础知识的话，欢迎你继续阅读。


要在系统上安装 i3，请运行以下命令：



```
$ sudo dnf install i3
```

完成后，注销，然后在登录屏幕上选择 i3 作为窗口管理器，然后重新登录。


当你第一次运行 i3 时，系统会询问你是否要继续进行自动配置 —— 在此处回答是。之后，你将被要求选择 “mod 键”。如果你不确定，只需接受默认值，即将 Windows/Super 键设置为 mod 键。你将主要使用此键用于窗口管理器中的快捷方式。


此时，你应该在底部看到一个小条和一个空白屏幕。我们来看看一些基本的快捷方式。


打开终端：



```
$mod + enter
```

切换到第二个工作区：



```
$mod + 2
```

通过以下两个步骤打开 firefox，首先：



```
$mod + d
```

然后输入 “firefox” 并按回车键。


将其移动到第一个工作区：



```
$mod + shift + 1
```

切换到第一个工作区：



```
$mod + 1
```

此时，你将并排看到一个终端和一个 firefox 窗口。要关闭窗口，请按：



```
$mod + shift + q
```

还有更多的快捷方式，但这些足够让你开始使用 i3。


要退出 i3（并退出登录）按：



```
$mod + shift + e
```

然后在右上角使用鼠标确认。


### 同时让多个屏幕工作


现在我们已经启动并运行了 i3，让我们把所有这些屏幕都用到！


为此，我们需要使用命令行，因为 i3 非常轻量级，并且没有 GUI 来管理其他屏幕。如果这听起来很难也不用担心，它实际上非常简单！


我们将使用的命令称为 `xrandr`。如果你的系统上没有 `xrandr`，请运行以下命令安装：



```
$ sudo dnf install xrandr
```

当它安装完毕后，让我们继续运行它：



```
$ xrandr
```

输出列出了所有可用输出设备，并通过显示支持的分辨率指示哪些输出连接了屏幕（通过电缆连接的显示器）。好消息是，我们不需要关心使它们工作的分辨率。


这个例子显示了笔记本电脑的主屏幕（名为 eDP1），以及连接到 HDMI-2 输出的第二个显示器，它位于笔记本电脑的右侧。要打开它，请运行以下命令：



```
$ xrandr --output HDMI-2 --auto --right-of eDP1
```

就是这样！你的屏幕现已激活。


![第二个屏幕激活。截屏上显示命令与文章中略有不同，它设置了更小的分辨率以使截屏适合阅读](/data/attachment/album/201906/29/140557ys7zigxtu5l2uhs3.png)


### 在多个屏幕上管理工作区


在多个屏幕上切换工作区和创建新工作区非常类似于只有一个屏幕的情况。新工作区会在当前处于活动状态（鼠标光标所在位置）的屏幕上创建。


因此，要切换到特定工作区（或在不存在的情况下创建新工作区），请按：



```
$mod + NUMBER
```

你可以独立切换各个显示器上的工作区！


![工作空间 2 在左侧屏幕，工作空间 4 在右侧屏幕](/data/attachment/album/201906/29/140558u1plf9f1h3kc7997.png)


![左侧屏幕切换为工作空间 3，右侧屏幕仍为工作空间 4](/data/attachment/album/201906/29/140559rzwppss8lpqwqkzb.png)


![右侧屏幕切换为工作空间 5，左侧屏幕仍为空间空间 3](/data/attachment/album/201906/29/140600wg61ndskgzzxvxgq.png)


### 在显示器之间移动工作区


我们可以通过以下命令将窗口移动到不同的工作区：



```
$mod + shift + NUMBER
```

我们也可以将工作区移动到不同的屏幕。但是，此操作没有默认快捷方式，因此我们必须先创建它。


要创建自定义快捷方式，你需要在你选择的文本编辑器中打开配置文件（本文使用 `vim`）：



```
$ vim ~/.config/i3/config
```

并将以下行添加到配置文件的最底部：



```
# Moving workspaces between screens
bindsym $mod+p move workspace to output right
```

保存、关闭并重新加载以使配置生效，按下：



```
$mod + shift + r
```

现在你可以将活跃的工作区移动到第二个显示器：



```
$mod + p
```

![打开火狐浏览器的工作空间 2 在左侧](/data/attachment/album/201906/29/140600vd0mg6gl8m646fz6.png)


![打开火狐浏览器的工作空间 2 移动到第二个屏幕](/data/attachment/album/201906/29/140601f0imk7smse5zemlu.png)


就是这些了！享受你的新多显示器体验，并了解更多 i3，欢迎阅读 Fedora Magazine 上之前关于 i3 的文章，或者查看官方 i3 文档。




---


via: <https://fedoramagazine.org/using-i3-with-multiple-monitors/>


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


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


OK
Are you using multiple monitors with your Linux workstation? Seeing many things at once might be beneficial. But there are often much more windows in our workflows than physical monitors — and that’s a good thing, because seeing too many things at once might be distracting. So being able to switch what we see on individual monitors seems crucial.

Let’s talk about i3 — a popular tiling window manager that works great with multiple monitors. And there is one handy feature that many other window managers don’t have — the ability to switch workspaces on individual monitors independently.

## Quick introduction to i3

The [Fedora Magazine has already covered i3](https://fedoramagazine.org/getting-started-i3-window-manager/) about three years ago. And it was one of the most popular articles ever published! Even though that’s not always the case, i3 is pretty stable and that article is still very accurate today. So — not to repeat ourselves too much — this article only covers the very minimum to get i3 up and running, and you’re welcome to go ahead and read it if you’re new to i3 and want to learn more about the basics.

To install i3 on your system, run the following command:

$ sudo dnf install i3

When that’s done, log out, and on the log in screen choose i3 as your window manager and log back in again.

When you run i3 for the first time, you’ll be asked if you wish to proceed with automatic configuration — answer yes here. After that, you’ll be asked to choose a “mod key”. If you’re not sure here, just accept the default which sets you Windows/Super key as the mod key. You’ll use this key for mostly all the shortcuts within the window manager.

At this point, you should see a little bar at the bottom and an empty screen. Let’s have a look at some of the basic shortcuts.

Open a terminal using:

$mod + enter

Switch to a second workspace using:

$mod + 2

Open firefox in two steps, first by:

$mod + d

… and then by typing “firefox” and pressing enter.

Move it to the first workspace by:

$mod + shift + 1

… and switch to the first workspace by:

$mod + 1

At this point, you’ll see a terminal and a firefox window side by side. To close a window, press:

$mod + shift + q

There are more shortcuts, but these should give you the minimum to get started with i3.

Ah! And to exit i3 (to log out) press:

$mod + shift + e

… and then confirm using your mouse at the top-right corner.

## Getting multiple screens to work

Now that we have i3 up and running, let’s put all those screens to work!

To do that, we’ll need to use the command line as i3 is very lightweight and doesn’t have gui to manage additional screens. But don’t worry if that sounds difficult — it’s actually quite straightforward!

The command we’ll use is called xrandr. If you don’t have xrandr on your system, install it by running:

$ sudo dnf install xrandr

When that’s installed, let’s just go ahead and run it:

$ xrandr

The output lists all the available outputs, and also indicated which have a screen attached to them (a monitor connected with a cable) by showing supported resolutions. Good news is that we don’t need to really care about the specific resolutions to make the them work.

This specific example shows a primary screen of a laptop (named eDP1), and a second monitor connected to the HDMI-2 output, physically positioned right of the laptop. To turn it on, run the following command:

$ xrandr --output HDMI-2 --auto --right-of eDP1

And that’s it! Your screen is now active.

![](https://fedoramagazine.org/wp-content/uploads/2019/06/0-1-1024x384.png)

## Managing workspaces on multiple screens

Switching workspaces and creating new ones on multiple screens is very similar to having just one screen. New workspaces get created on the screen that’s currently active — the one that has your mouse cursor on it.

So, to switch to a specific workspace (or to create a new one in case it doesn’t exist), press:

$mod + NUMBER

And you can switch workspaces on individual monitors independently!

![](https://fedoramagazine.org/wp-content/uploads/2019/06/1-1-1024x384.png)

![](https://fedoramagazine.org/wp-content/uploads/2019/06/1-2-1024x384.png)

![](https://fedoramagazine.org/wp-content/uploads/2019/06/1-3-1024x384.png)

## Moving workspaces between monitors

The same way we can move windows to different workspaces by the following command:

$mod + shift + NUMBER

… we can move workspaces to different screens as well. However, there is no default shortcut for this action — so we have to create it first.

To create a custom shortcut, you’ll need to open the configuration file in a text editor of your choice (this article uses *vim*):

$ vim ~/.config/i3/config

And add the following lines to the very bottom of the configuration file:

# Moving workspaces between screens

bindsym $mod+p move workspace to output right

Save, close, and to reload and apply the configuration, press:

$mod + shift + r

Now you’ll be able to move your active workspace to the second monitor by:

$mod + p

![](https://fedoramagazine.org/wp-content/uploads/2019/06/2-1-1024x384.png)

![](https://fedoramagazine.org/wp-content/uploads/2019/06/2-2-1024x384.png)

And that’s it! Enjoy your new multi-monitor experience, and to learn more about i3, you’re welcome to read the previous article about i3 on the Fedora Magazine, or consult the official i3 documentation.

## Kaspers

Nice guide your wrote here. Hopefully it’ll inspire people to make use of these tiling window managers. Have some experience with i3 myself, absolutely liked it. Moved a bit later to dwm.

## Ph0zzy

Do you know how is goint to work with sway?

## oyviaase

Sway manages the monitors itself so you need to specify your monitor layout in your Sway configuration file. An example from the github wiki is this

output HDMI1 pos 0 0 res 1920×1080

output eDP1 pos 1920 0 res 1600×900

https://github.com/swaywm/sway/wiki#multihead

## plaguedoctor

Sway has multiscreen support built in. How to set it up and use it is nicely explained in sway manpages. 🙂

## Curried

Great guide!

Any advice on dealing with multiple monitors and HiDPI? Resolution mismatch is ugly.

I use mons (https://github.com/Ventto/mons) to manage my monitors on my i3/arch laptop. A bit easier than pure xrandr as it’s arguments are very common arrangements. But the most I do is mirror my laptop on external monitors to work around the hidpi issue.

## John

sudo dnf install arandr

then run arandr

save the profile {it will generate a bash script which calls xrandr}

That’s you GUI solution 🙂

## Stephen

Was going to chime in with this a same thing.

arandr ++

😀

## Hiisi

The original article 3 years ago made me switch to i3wm. I have discovered how to use multiple screen just a few days ago. I wish this article were published a week earlier 🙂

## Shawn McCool

I made a mode like the resize mode. It can move workspaces to different outputs.

## Yazan Al Monshed

Great article !, Thank you

## LegacyHater

Just use sway ????

## Ryan Murphy

multiple graphics cards with multiple monitors? I haven’t been able to get xinerama to work and the second gpu is the only one with dvi

## Thomas

Does anyone have some hints on where to start when the above doesn’t work?

I love i3, but using it on multiple monitors has not been a good transition.

Everytime that I login to i3 I am greeted with nothing. No spinning cursor, my background colour is not loaded. I’ve used Arandr to setup a script to turn on the monitors and setup a keymapping to run it. On the first run it only enables one external monitor. The laptop and second monitor remain on the grey login screen background and don’t have the i3 toolbar along the bottom.

Usually the second time I run the script it enables all three windows, but not always…

I’m usually able to use the Arandr script I’ve setup to move all workspaces to just the laptop monitor when I need to undock, but the script to re-enable the external monitors fails more often than it works.

So far i3 helps me work efficiently enough that it’s still better to reboot my laptop during re-docking events. However, it’s a significant pain point. Would greatly appreciate any nudges along the path to debugging.

Unfortunately, I’m not sure where to even look for logs around this and google mostly returns articles at about this depth.

## Eduard Lucena

It’s weird, the initial setup is not tied to i3 directly, at least not in Fedora, since any versiona you have installed comes either with SDDM, GDM or LightDM and they are the responsible to setup your login screen (and the monitors). Now, after that, when you log in into i3wm, then you have the setup that was made by the DM, and if you need to change it, you should go with the ways explained in the article. At least, it works that way for me.

## Raphael Groner

Does it also work with Displaylink adapters?

## tarek

nice guide and thank you for this article

## Leslie Satenstein

Adam,

It is a very good informative article.

I am just beginning with I3, and ran into an issue.

My terminals open with white background and pale colors for text.

Do you know how to change the terminal background color? I am OK with navigating and creating keymappings.

## Paul Mellors

Depends on the terminal you’re using, it’s generally in the terminal settings themselves nothing really to do with i3

## Hiisi

Since I have gnome installed on my system I simply changed default terminal to gnome-terminal in i3′ config:

start a terminal

bindsym $mod+Return exec gnome-terminal

It has black background by default 🙂