i3初步使用

之前一直使用kde作为我的桌面环境,可不知为何突然间启动缓慢…之前有听说过i3大名,于是本菜鸡便尝试着试试i3

i3简介

i3(improved tiling wm)是一个应用于GNU/Linux和BSD上的平铺式窗口管理器,使用了灵活的BSD许可证.在官网https://i3wm.org/可以查阅相关资料与文档,观察i3的图标可以知道,该图标由3个i组成,整体上构成了W,而倒过来又是M,即i3wm,为设计师的创意点赞!

i3有如下优点:

  1. 易读,文档详尽的代码
  2. 支持多显示屏,以及多工作空间
  3. 使用树形数据结构管理窗口
  4. 完全可自定义的按键绑定
  5. 实施多种模式,类似于vim
  6. 为其他程序提供了IPC接口
  7. 完全的UTF-8
  8. 精英主义(没有过多的装饰,只有简单的窗口边界)

以上是官网所罗列的优点.不过对于我来说,i3最重要的优点只有两个:占用小(磁盘占用不过十几兆),速度快(几乎秒开)

在i3的使用中,有一个最核心的按键叫做修饰键(modifier),所有窗口层面的控制都需要依靠该按键来解决.它默认是Alt键,编号为Mod1.有一个更为可行的代替方案是Win键,编号为Mod4

安装i3

首先,安装i3软件包:

在arch上,i3是一系列包的组合,包括了i3最常用的一些组件,并使用i3的改进版:i3-gaps来代替默认的i3-wm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# zhanghuidinah @ study in ~ [17:35:20] 
$ sudo pacman -S i3
:: There are 5 members in group i3:
:: Repository community
1) i3-gaps 2) i3-wm 3) i3blocks 4) i3lock 5) i3status

Enter a selection (default=all): y
error: invalid number: y

Enter a selection (default=all):
warning: i3-gaps-4.15.0.1-2 is up to date -- reinstalling
warning: i3blocks-1.4-6 is up to date -- reinstalling
warning: i3lock-2.10-1 is up to date -- reinstalling
warning: i3status-2.12-1 is up to date -- reinstalling
resolving dependencies...
looking for conflicting packages...
warning: removing 'i3-wm' from target list because it conflicts with 'i3-gaps'

Packages (4) i3-gaps-4.15.0.1-2 i3blocks-1.4-6 i3lock-2.10-1 i3status-2.12-1

Total Installed Size: 1.77 MiB
Net Upgrade Size: 0.00 MiB

:: Proceed with installation? [Y/n] y

安装结束后,从原来的桌面环境中登出,再次登入时可以选择登入的桌面环境,选择i3即可

初次登入i3时,会自动弹出一个命令行窗口,向导以完成i3的初步配置(帮助创建i3的配置文件,位于$HOME/.config/i3/config)

常用命令

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
新建虚拟终端: $mod+Enter

关闭窗口: $mod+Shift+Q

打开程序启动器: $mod+D

新建窗口位于现窗口下方(默认为右方): $mod+V

移动焦点于其他窗口(左下上右): $mod+J/K/L/;

将焦点窗口移动至其他位置(左下上右): $mod+Shift+J/K/L/;

移动至其他工作空间: $mod+$num

将焦点窗口移动至其他工作空间: $mod+Shift+$num

关闭i3: $mod+Shift+E

重启i3: $mod+Shift+R

#工作空间布局
tiling模式(默认模式,平铺式窗口): $mod+E

stacking模式(工作空间里只显示一个活动的窗口,在工作空间上方得到一个窗口的列表): $mod+S

tabbed模式(与stacking模式类似,不过是类似浏览器式的标签页): $mod+W

resize模式(用于在tiling模式下调整各窗口的占用空间,使用J/K/L/;调整): $mod+R

命令行输入i3lock进入锁屏界面,需要输入用户密码解锁(可通过键位绑定快捷锁屏)

配置文件

i3的配置文件位于$HOME/.i3/config或者$HOME/.config/i3/config.如果没有该配置文件,可使用命令i3-config-wizard创建它,该命令也是i3初次运行时运行的命令

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# i3 config file (v4)
#
# Please see https://i3wm.org/docs/userguide.html for a complete reference!
#
# This config file uses keycodes (bindsym) and was written for the QWERTY
# layout.
#
# To get a config file with the same key positions, but for your current
# layout, use the i3-config-wizard
#

set $mod Mod4 # 设置$mod为Mod4,即<Win>键

# Font for window titles. Will also be used by the bar unless a different font
# is used in the bar {} block below.
font pango:monospace 12

# This font is widely installed, provides lots of unicode glyphs, right-to-left
# text rendering and scalability on retina/hidpi displays (thanks to pango).
#font pango:DejaVu Sans Mono 20

# Before i3 v4.8, we used to recommend this one as the default:
# font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
# The font above is very space-efficient, that is, it looks good, sharp and
# clear in small sizes. However, its unicode glyph coverage is limited, the old
# X core fonts rendering does not support right-to-left and this being a bitmap
# font, it doesn't scale on retina/hidpi displays.

# use these keys for focus, movement, and resize directions when reaching for
# the arrows is not convenient
set $up l
set $down k
set $left j
set $right semicolon

# use Mouse+$mod to drag floating windows to their wanted position
floating_modifier $mod

# start a terminal
bindsym $mod+Return exec i3-sensible-terminal # Win+回车键打开终端,默认终端为i3-sensible-terminal,可修改

# kill focused window
bindsym $mod+Shift+q kill

# start dmenu (a program launcher)
bindsym $mod+d exec dmenu_run
# There also is the (new) i3-dmenu-desktop which only displays applications
# shipping a .desktop file. It is a wrapper around dmenu, so you need that
# installed.
# bindsym $mod+d exec --no-startup-id i3-dmenu-desktop

# change focus
bindsym $mod+$left focus left
bindsym $mod+$down focus down
bindsym $mod+$up focus up
bindsym $mod+$right focus right

# alternatively, you can use the cursor keys:
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right

# move focused window
bindsym $mod+Shift+$left move left
bindsym $mod+Shift+$down move down
bindsym $mod+Shift+$up move up
bindsym $mod+Shift+$right move right

# alternatively, you can use the cursor keys:
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right

# split in horizontal orientation
bindsym $mod+h split h

# split in vertical orientation
bindsym $mod+v split v

# enter fullscreen mode for the focused container
bindsym $mod+f fullscreen toggle

# change container layout (stacked, tabbed, toggle split)
bindsym $mod+s layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+e layout toggle split

# toggle tiling / floating
bindsym $mod+Shift+space floating toggle

# change focus between tiling / floating windows
bindsym $mod+space focus mode_toggle

# focus the parent container
bindsym $mod+a focus parent

# focus the child container
#bindsym $mod+d focus child

# move the currently focused window to the scratchpad
bindsym $mod+Shift+minus move scratchpad

# Show the next scratchpad window or hide the focused scratchpad window.
# If there are multiple scratchpad windows, this command cycles through them.
bindsym $mod+minus scratchpad show

# Define names for default workspaces for which we configure key bindings later on.
# We use variables to avoid repeating the names in multiple places.
set $ws1 "1"
set $ws2 "2"
set $ws3 "3"
set $ws4 "4"
set $ws5 "5"
set $ws6 "6"
set $ws7 "7"
set $ws8 "8"
set $ws9 "9"
set $ws10 "10"


# switch to workspace
bindsym $mod+1 workspace $ws1
bindsym $mod+2 workspace $ws2
bindsym $mod+3 workspace $ws3
bindsym $mod+4 workspace $ws4
bindsym $mod+5 workspace $ws5
bindsym $mod+6 workspace $ws6
bindsym $mod+7 workspace $ws7
bindsym $mod+8 workspace $ws8
bindsym $mod+9 workspace $ws9
bindsym $mod+0 workspace $ws10

# move focused container to workspace
bindsym $mod+Shift+1 move container to workspace $ws1
bindsym $mod+Shift+2 move container to workspace $ws2
bindsym $mod+Shift+3 move container to workspace $ws3
bindsym $mod+Shift+4 move container to workspace $ws4
bindsym $mod+Shift+5 move container to workspace $ws5
bindsym $mod+Shift+6 move container to workspace $ws6
bindsym $mod+Shift+7 move container to workspace $ws7
bindsym $mod+Shift+8 move container to workspace $ws8
bindsym $mod+Shift+9 move container to workspace $ws9
bindsym $mod+Shift+0 move container to workspace $ws10

# reload the configuration file
bindsym $mod+Shift+c reload
# restart i3 inplace (preserves your layout/session, can be used to upgrade i3)
bindsym $mod+Shift+r restart
# exit i3 (logs you out of your X session)
bindsym $mod+Shift+e exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -b 'Yes, exit i3' 'i3-msg exit'"

# resize window (you can also use the mouse for that)
mode "resize" {
# These bindings trigger as soon as you enter the resize mode

# Pressing left will shrink the window’s width.
# Pressing right will grow the window’s width.
# Pressing up will shrink the window’s height.
# Pressing down will grow the window’s height.
bindsym $left resize shrink width 10 px or 10 ppt
bindsym $down resize grow height 10 px or 10 ppt
bindsym $up resize shrink height 10 px or 10 ppt
bindsym $right resize grow width 10 px or 10 ppt

# same bindings, but for the arrow keys
bindsym Left resize shrink width 10 px or 10 ppt
bindsym Down resize grow height 10 px or 10 ppt
bindsym Up resize shrink height 10 px or 10 ppt
bindsym Right resize grow width 10 px or 10 ppt

# back to normal: Enter or Escape or $mod+r
bindsym Return mode "default"
bindsym Escape mode "default"
bindsym $mod+r mode "default"
}

bindsym $mod+r mode "resize"

# Start i3bar to display a workspace bar (plus the system information i3status
# finds out, if available)

bar {
status_command i3status
}

new_window pixel 0

hide_edge_borders both

#######################################################################
# automatically start i3-config-wizard to offer the user to create a
# keysym-based config which used their favorite modifier (alt or windows)
#
# i3-config-wizard will not launch if there already is a config file
# in ~/.i3/config.
#
# Please remove the following exec line:
#######################################################################
# ssign [class="konsole"] $ws1
assign [class="Google-chrome"] $ws10

#exec --no-startup-id xcompmgr &
exec --no-startup-id compton -f
exec --no-startup-id fcitx
exec --no-startup-id feh --bg-scale "/home/zhanghuidinah/Pictures/yiluxier.jpg"
#exec --no-startup-id nm-applet &
exec --no-startup-id bash /home/zhanghuidinah/shell/Touchpadoff.sh

exec konsole
exec google-chrome-stable

杂项

添加开启i3自起程序

在配置文件中使用exec命令即可

1
2
3
4
5
# 启动i3时执行,重启i3时不执行
exec --no-startup-id fcitx

# 无论何时都执行
exec_always --no-startup-id fcitx

添加背景图片

使用feh(需要下载)并打开i3时自起

1
exec --no-startup-id feh --bg-scale "/home/zhanghuidinah/Pictures/BG_1.jpg"

配置显示器

可以使用xrandr命令配置,不过一个更加方便的图形化配置程序叫做arandr(需要下载)

在图形化界面配置完后,可将其导出为一个xrandr脚本,并将其写入至i3配置文件中

使用i3无法调节音量,亮度?

在配置文件中添加如下行:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Pulse Audio controls
bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume 0 +5% #increase sound volume
bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume 0 -5% #decrease sound volume
bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute 0 toggle # mute sound

# Sreen brightness controls
bindsym XF86MonBrightnessUp exec xbacklight -inc 20 # increase screen brightness
bindsym XF86MonBrightnessDown exec xbacklight -dec 20 # decrease screen brightness

# Touchpad controls
bindsym XF86TouchpadToggle exec /some/path/toggletouchpad.sh # toggle touchpad

# Media player controls
bindsym XF86AudioPlay exec playerctl play
bindsym XF86AudioPause exec playerctl pause
bindsym XF86AudioNext exec playerctl next
bindsym XF86AudioPrev exec playerctl previous

更改工作空间名称,并将应用程序开启于指定工作空间中

修改i3配置文件,更改工作空间名称:

1
2
# 使用快捷键跳转至"brower"工作空间
bindsym $mod+1 workspace "brower"

获取应用程序的class名:

1
]# xprop

随后鼠标将变成”X”状,点击应用程序,即可获取到其class名

再次修改i3配置文件:

1
assign [class="Google-chrome"] "brower"

使用特殊字符(emoji)美化工作空间名称

去awesome的github界面下载web字体:https://github.com/FortAwesome/Font-Awesome/releases

解压,然后将里面的有brand并且以ttf结尾的字体文件复制至~/.fonts文件夹中

https://fontawesome.com/cheatsheet查找需要的图标字体,并复制到i3配置文件中的工作空间名称中.例如:

1
set $ws10 "Chrome "

一开始是乱码,需要重启i3后才能生效

i3默认没有中文输入法

在配置文件中添加启动输入法程序,如fcitx,fcitx-sogou,ibus等等

1
exec --no-startup-id fcitx

禁用触控版

执行如下命令:

1
2
]# synclient TouchpadOff=1
]# synclient Clickpad=0

还有一个更快捷的方式是将命令写成脚本,使用键盘快捷键控制.例如许多笔记本有Fn键禁用触控版(我的没有):

toggletouchpad.sh脚本:

1
2
3
4
5
6
#!/bin/bash
if synclient -l | grep "TouchpadOff .*=.*0" ; then
synclient TouchpadOff=1 ;
else
synclient TouchpadOff=0 ;
fi

将其写入至配置文件中:

1
bindsym XF86TouchpadToggle exec /some/path/toggletouchpad.sh

参考文档

Distortion_3022:i3wm的使用说明

i3党走起,oh-my-i3,带给你一个不一样的i3wm

Alex Booker的i3wm配置视频 推荐!

0%