1. X11 介绍
遍历x11相关的ubuntu package
https://packages.ubuntu.com/bionic/x11/
2. 桌面环境使用记录
X11 环境下我们通常说的桌面环境最基础的应该包含两个部分:
-
登录管理器
常见的有:
gdm, kdm, xdm, lightdm, slim
具体区别可以参考archlinux的wiki https://wiki.archlinux.org/index.php/display_manager
如果安装有多个登录管理器可以使用下面方式指定默认登录管理器
sudo dpkg-reconfigure gdm
-
桌面管理器
桌面管理器有很多种,可以通过下面的链接查看大众的评比结果
https://www.slant.co/topics/390/~best-window-managers-for-linux
gnome, kde, xfce等都属于桌面管理器,它们的窗口管理都是悬浮和分层来组织排放的,与windows的差异很小。而平铺式桌面管理器(tiling window manager)是桌面管理器中的一种小众类型,更专注于键盘控制,效率提升和定制化。下面分享自己经常使用的几种平铺式桌面管理器的使用记录。
2.1 Awesome
可以参考下面的配置文件
https://github.com/aggresss/dotfiles/blob/master/awesome/rc.lua_ubuntu18.04
使用说明
https://awesomewm.org/doc/manpages/awesome.1.html
默认配置文件 ~/.config/awesome/rc.lua
默认Modkey
为Mod4(win)
键。
下面是整理的 awesome 默认快捷键:
Window manager control
Mod4 + Control + R
Restart awesome.
Mod4 + Shift + Q
Quit awesome.
Mod4 + R
Run prompt.
Mod4 + X
Run Lua code prompt.
Mod4 + Return
Spawn terminal emulator.
Mod4 + W
Open main menu.
Clients
Mod4 + M
Maximize client.
Mod4 + N
Minimize client.
Mod4 + Control + n
Restore client.
Mod4 + F
Set client fullscreen.
Mod4 + Shift + C
Kill focused client.
Mod4 + T
Set client on-top.
Navigation
Mod4 + J
Focus next client.
Mod4 + K
Focus previous client.
Mod4 + U
Focus first urgent client.
Mod4 + Left
View previous tag.
Mod4 + Right
View next tag.
Mod4 + 1-9
Switch to tag 1-9.
Mod4 + Control + J
Focus next screen.
Mod4 + Control + K
Focus previous screen.
Mod4 + Escape
Focus previously selected tag set.
Layout modification
Mod4 + Shift + J
Switch client with next client.
Mod4 + Shift + K
Switch client with previous client.
Mod4 + O
Send client to next screen.
Mod4 + H
Decrease master width factor by 5%.
Mod4 + L
Increase master width factor by 5%.
Mod4 + Shift + H
Increase number of master windows by 1.
Mod4 + Shift + L
Decrease number of master windows by 1.
Mod4 + Control + H
Increase number of columns for non-master windows by 1.
Mod4 + Control + L
Decrease number of columns for non-master windows by 1.
Mod4 + space
Switch to next layout.
Mod4 + Shift + space
Switch to previous layout.
Mod4 + Control + space
Toggle client floating status.
Mod4 + Control + Return
Swap focused client with master.
Mod4 + Control + 1-9
Toggle tag view.
Mod4 + Shift + 1-9
Tag client with tag.
Mod4 + Shift + Control + 1-9
Toggle tag on client.
2.2 i3
默认配置文件 ~/.config/i3/config
~/.config/i3staus/config
默认Modkey
为Alt
键
下面整理了一些常用的默认快捷键:
Mod+ Enter
启动虚拟终端
Mod + A
焦点转义到父窗口上
Mod + S
堆叠布局
Mod + W
标签布局
Mod + E
默认布局
Mod + SpaceBar
焦点在平铺式/浮动式转换
Mod + D
启动 dmenu
Mod + H
水平分割窗口
Mod + V
垂直分割窗口
Mod + J
焦点往左窗口移
Mod + K
焦点往下窗口移
Mod + L
焦点往上窗口移
Mod + ;
焦点往右窗口移
Mod + Shift + Q
杀死当前窗口的进程
Mod + Shift + E
退出 i3
Mod + Shift + C
当场重新加载 i3config, 无需重启
Mod + Shift + R
重启 i3 (还重新加载了 i3config, 又没有退出过程)
Mod + Shift + J
窗口左移
Mod + Shift + K
窗口下移
Mod + Shift + L
窗口上移
Mod + Shift + :
窗口右移
Mod + Shift + SpaceBar
窗口在平铺式/浮动式转换
除了快捷键外,i3对多显示器的支持也很好,新建窗口的位置取决于新建窗口命令所在的监视器。
i3平铺式支持横向和纵向。支持多行或多列。支持窗口的重命名。
https://i3wm.org/docs/userguide.html
2.3 xmonad
默认启动后什么都没有,完全依赖快捷键操作
默认配置文件 ~/.xmonad/xmonad.hs
xmobar 配置
https://beginners-guide-to-xmonad.readthedocs.io/configure_xmobar.html
默认Modkey
为Alt
键
下面是整理的 xmonad 默认快捷键:
Mod + Shift + Return
Launch terminal
Mod + P
Launch dmenu
Mod + Shift + P
Launch gmrun
Mod + Shift + C
Close the focused window
Mod + Space
Rotate through the available layout algorithms
Mod + Shift + Space
Reset the layouts on the current workspace to default
Mod + N
Resize viewed windows to the correct size
Mod + Tab
Move focus to the next window
Mod + Shift + Tab
Move focus to the previous window
Mod + J
Move focus to the next window
Mod + K
Move focus to the previous window
Mod + M
Move focus to the master window
Mod + Return
Swap the focused window and the master window
Mod + Shift + J
Swap the focused window with the next window
Mod + Shift + K
Swap the focused window with the previous window
Mod + H
Shrink the master area
Mod + L
Expand the master area
Mod + T
Push window back into tiling
Mod + ,
Increment the number of windows in the master area
Mod + .
Deincrement the number of windows in the master area
Mod + Shift + Q
Quit xmonad
Mod + Q
Restart xmonad
Mod + Shift + /
Run xmessage with a summary of the default keybindings (useful for beginners)
Mod + [1..9]
Switch to workspace N
Mod + Shift + [1..9]
Move client to workspace N
Mod + {W, E, R}
Switch to physical/Xinerama screens 1, 2, or 3
Mod + Shift + {W, E, R}
Move client to screen 1, 2, or 3
Mod + Button1
Set the window to floating mode and move by dragging
Mod + Button2
Raise the window to the top of the stack
Mod + Button3
Set the window to floating mode and resize by dragging
下面是键盘映射图:
https://wiki.haskell.org/Xmonad
2.4 dwm
默认Modkey
为Alt
键
config.def.h文件的默认设置:
MODKEY + P
dmenu
MODKEY + Shift + Q
To quite dwm cleanly
MODKEY + Shift + C
To kill a window
MODKEY + Shift + Enter
Launch terminal
MODKEY + Shift + 1,2,3,...
Move current window to area 1,2,3…
MODKEY + 1,2,3,...
Switch to area 1,2,3…
MODKEY + 0
预览1-9所有内容
MODKEY + tab
Switch view area
MODKEY + J
激活下一个窗口
MODKEY + K
激活上一个窗口
MODKEY + H
左移边界
MODKEY + L
右移边界
MODKEY + I
分割Master窗口(+1)
MODKEY + D
还原Master窗口(-1)
MODKEY + B
隐藏/显示dmenu菜单
MODKEY + T
Alt + F
Alt + M
切換桌面布局方式
MODKEY + space
前後布局切換
MODKEY + Enter
切換Master窗口
下面是 dwm 的示意图,参考自:
http://www.cnblogs.com/wonux/articles/5206085.html
+------+----------------------------------+--------+
| tags | title | status +
+------+---------------------+------------+--------+
| | |
| | |
| | |
| | |
| master | stack |
| | |
| | |
| | |
| | |
+----------------------------+---------------------+
dwm结构非常简单,是研究桌面管理器的最佳选择
git clone https://git.suckless.org/dwm
/usr/share/xsessions/*.desktop
记录了有几种桌面系统被安装
apt-file list dwm 查看 dwm 安装文件
3. 有趣的小实验
实验环境 Ubuntu 18.04 , inittab 模式切换可以使用以下脚本,将脚本保存为 inittab.sh 后执行 sudo ./inittab.sh 3 && sudo reboot
可以进入为启动X server 的状态,执行 sudo ./inittab.sh 5 && sudo reboot
后可以恢复图形界面。
#!/bin/bash
# Change default runlevel on Debian systemd based system
# linux shell color support.
RED="\\033[31m"
GREEN="\\033[32m"
YELLOW="\\033[33m"
BLACK="\\033[0m"
if [ "X_$1" = "X_" ]; then
runlevel
elif [ $1 -ge 0 -a $1 -le 6 ]; then
sudo ln -sf /lib/systemd/system/runlevel$1.target /etc/systemd/system/default.target
else
echo -e "${RED} please input args 0-6 ${BLACK}"
fi
#end
3.1 xclock
在 X server 未启动的情况下启动一个 xclock 实验:
sudo xinit /usr/bin/xclock -- /usr/bin/X :0
xclock 相对于 X11 类似于 编程语言中的 Hello Wrold,经常拿它来验证 X11 服务的状态。
切换到shell界面使用 Ctrl + Alt + F1
恢复到xclock界面使用 Ctrl + Alt + F3
linux是一个多用户操作系统,它可以同时接受多个用户登录。linux还允许一个用户进行多次登录,这是因为linux和Unix一样,提供了虚拟控制台的访问方式,允许用户同时从不同的虚拟控制台进行多次登录。
虚拟控制台的选择可以通过Ctrl+Alt+F(1~6) 来实现
3.2 ssh 远程使用 X11
1.在 MacOS 中本地显示远程启动的X11程序界面
在 MacOS 中安装 XQuartz 然后通过 ssh 登录远程 Linux 系统,ssh 登录中增加参数 -X 例如 ssh -X 192.168.1.1
登录成功后 xclock 就可以在本地显示 xclock 界面。
2.远程登录 ssh 后,让 X11 程序显示在远程显示器上
当远程登录主机时,如果不加 -X 参数 运行 X11 程序时通常会出错,因为当前shell的 DISPLAY 变量没有被设置,这是增加 DISPLAY 变量可以让程序在远程主机的显示器上输出,例如下面的命令可以实现远程锁屏 env DISPLAY=:0 slock &