运行sway窗口管理器
安装
Kali Linux 环境安装
sway
:
sudo apt install sway wofi
Kali Linux 默认使用的图形登陆管理器可以自动管理 sway
的登陆会话,并且会正确设置 wayland显示服务器协议 显示服务,所以只需要在图形登陆管理器中选择 sway
登陆就是这个平铺WM了。
我最终改为 Raspberry Pi OS
工作环境,采用精简安装,没有安装窗口管理器。那么最方便自动启动 sway
的方法是在环境配置(例如 ~/.zshrc
)添加以下内容:
if [ -z $DISPLAY ] && [ "$(tty)" = "/dev/tty1" ]; then
exec sway
fi
这样启动到字符终端就会立即启动 sway
,而 sway
图形管理器退出后会立即再次启动 tty
,也就是再次自动登陆到 sway
使用设置
sway窗口管理器使用fcitx5 输入法可以非常完美使用中文,但是需要注意
默认
foot
终端虽然能够输入中文,但是无法现实中文候选字词,所以改为qterminal
(默认 Kali Linux 的 xfce 配套终端模拟器,轻量级且功能完备)就可以正常输入中文chromium
无法输入中文(显示运行没有问题),不过好在firefox
使用中文输入正常,所以我同时采用这2个浏览器取长补短
配置定制,先将全局配置复制到个人目录下:
mkdir -p ~/.config/sway
cp /etc/sway/config ~/.config/sway/
我的配置:
# Default config for sway
#
# Copy this to ~/.config/sway/config and edit it to your liking.
#
# Read `man 5 sway` for a complete reference.
### Variables
#
# Logo key. Use Mod1 for Alt.
# 我尝试过使用 Alt ,但是有些应用默认内置了 Alt 作为快捷键,可能会有冲突
set $mod Mod4
# Home row direction keys, like vim
# 结合 $mod + 移动键可以快速在4个方向上移动聚焦窗口
set $left h
set $down j
set $up k
set $right l
# Your preferred terminal emulator
# 将默认foot终端修改成qtermianl可以支持fcitx中文输入
#set $term foot
set $term qterminal
# Your preferred application launcher
# Note: pass the final command to swaymsg so that the resulting window can be opened
# on the original workspace that the command was run on.
set $menu dmenu_path | dmenu | xargs swaymsg exec --
include /etc/sway/config-vars.d/*
### Output configuration
#
# Default wallpaper (more resolutions are available in /usr/share/backgrounds/sway/)
output * bg /usr/share/backgrounds/sway/Sway_Wallpaper_Blue_1920x1080.png fill
#
# Example configuration:
#
# output HDMI-A-1 resolution 1920x1080 position 1920,0
#
# You can get the names of your outputs by running: swaymsg -t get_outputs
### Idle configuration
#
# Example configuration:
#
# exec swayidle -w \
# timeout 300 'swaylock -f -c 000000' \
# timeout 600 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"' \
# before-sleep 'swaylock -f -c 000000'
#
# This will lock your screen after 300 seconds of inactivity, then turn off
# your displays after another 300 seconds, and turn your screens back on when
# resumed. It will also lock your screen before your computer goes to sleep.
exec_always fcitx5 -d --replace
### Input configuration
#
# Example configuration:
#
# input "2:14:SynPS/2_Synaptics_TouchPad" {
# dwt enabled
# tap enabled
# natural_scroll enabled
# middle_emulation enabled
# }
#
# You can get the names of your inputs by running: swaymsg -t get_inputs
# Read `man 5 sway-input` for more information about this section.
### Key bindings
#
# Basics:
#
# Start a terminal
bindsym $mod+Return exec $term
# Start chromium with wayland
bindsym $mod+o exec chromium --enable-features=UseOzonePlatform --ozone-platform=wayland --proxy-server="http://192.168.10.9:3128"
# Start firefox
bindsym $mod+i exec firefox
# Kill focused window
bindsym $mod+Shift+q kill
# Start your launcher
bindsym $mod+d exec $menu
# Drag floating windows by holding down $mod and left mouse button.
# Resize them with right mouse button + $mod.
# Despite the name, also works for non-floating windows.
# Change normal to inverse to use left mouse button for resizing and right
# mouse button for dragging.
floating_modifier $mod normal
# Reload the configuration file
bindsym $mod+Shift+c reload
# Exit sway (logs you out of your Wayland session)
bindsym $mod+Shift+e exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -B 'Yes, exit sway' 'swaymsg exit'
#
# Moving around:
#
# Move your focus around
bindsym $mod+$left focus left
bindsym $mod+$down focus down
bindsym $mod+$up focus up
bindsym $mod+$right focus right
# Or use $mod+[up|down|left|right]
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right
# Move the focused window with the same, but add Shift
bindsym $mod+Shift+$left move left
bindsym $mod+Shift+$down move down
bindsym $mod+Shift+$up move up
bindsym $mod+Shift+$right move right
# Ditto, with arrow 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
#
# Workspaces:
#
# Switch to workspace
bindsym $mod+1 workspace number 1
bindsym $mod+2 workspace number 2
bindsym $mod+3 workspace number 3
bindsym $mod+4 workspace number 4
bindsym $mod+5 workspace number 5
bindsym $mod+6 workspace number 6
bindsym $mod+7 workspace number 7
bindsym $mod+8 workspace number 8
bindsym $mod+9 workspace number 9
bindsym $mod+0 workspace number 10
# Move focused container to workspace
bindsym $mod+Shift+1 move container to workspace number 1
bindsym $mod+Shift+2 move container to workspace number 2
bindsym $mod+Shift+3 move container to workspace number 3
bindsym $mod+Shift+4 move container to workspace number 4
bindsym $mod+Shift+5 move container to workspace number 5
bindsym $mod+Shift+6 move container to workspace number 6
bindsym $mod+Shift+7 move container to workspace number 7
bindsym $mod+Shift+8 move container to workspace number 8
bindsym $mod+Shift+9 move container to workspace number 9
bindsym $mod+Shift+0 move container to workspace number 10
# Note: workspaces can have any name you want, not just numbers.
# We just use 1-10 as the default.
#
# Layout stuff:
#
# You can "split" the current object of your focus with
# $mod+b or $mod+v, for horizontal and vertical splits
# respectively.
bindsym $mod+b splith
bindsym $mod+v splitv
# Switch the current container between different layout styles
bindsym $mod+s layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+e layout toggle split
# Make the current focus fullscreen
bindsym $mod+f fullscreen
# Toggle the current focus between tiling and floating mode
bindsym $mod+Shift+space floating toggle
# Swap focus between the tiling area and the floating area
bindsym $mod+space focus mode_toggle
# Move focus to the parent container
bindsym $mod+a focus parent
#
# Scratchpad:
#
# Sway has a "scratchpad", which is a bag of holding for windows.
# You can send windows there and get them back later.
# 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
#
# Resizing containers:
#
mode "resize" {
# left will shrink the containers width
# right will grow the containers width
# up will shrink the containers height
# down will grow the containers height
bindsym $left resize shrink width 10px
bindsym $down resize grow height 10px
bindsym $up resize shrink height 10px
bindsym $right resize grow width 10px
# Ditto, with arrow keys
bindsym Left resize shrink width 10px
bindsym Down resize grow height 10px
bindsym Up resize shrink height 10px
bindsym Right resize grow width 10px
# Return to default mode
bindsym Return mode "default"
bindsym Escape mode "default"
}
bindsym $mod+r mode "resize"
#
# Status Bar:
#
# Read `man 5 sway-bar` for more information about this section.
bar {
position top
# When the status_command prints a new line to stdout, swaybar updates.
# The default just shows the current date and time.
status_command while date +'%Y-%m-%d %I:%M:%S %p'; do sleep 1; done
colors {
statusline #ffffff
background #323232
inactive_workspace #32323200 #32323200 #5c5c5c
}
}
include /etc/sway/config.d/*
GTK应用默认启用wayland所以无需配置,但是QT5应用应用需要设置环境变量引导程序启用Wayland - 配置
/etc/environment
添加
QT_QPA_PLATFORM=wayland
问题和解决方法
由于 sway
使用了前沿的 wayland显示服务器协议 图形显示服务,所以有些应用可能无法native支持,或者需要特殊运行参数
firefox可以直接运行在纯
wayland
的sway
环境chromium需要指定参数(上文中 sway 配置中采用快捷键绑定启动参数):
chromium --enable-features=UseOzonePlatform --ozone-platform=wayland
配置linux系统级代理 但是chromium不生效,所以在启动参数上添加
--proxy-server
参数,所以chromium参数如下( 参考 Configure Proxy for Chromium and Google Chrome From Command Line on Linux ):chromium --enable-features=UseOzonePlatform --ozone-platform=wayland --proxy-server="http://192.168.10.9:3128"
如果使用socks5代理,则类似参数 --proxy-server="socks5://127.0.0.1:1080"
。更为方便的方法是使用 结合SSH Tunnel和AutoProxy插件翻墙 方案中的 Proxy SwitchyOmega
chromium不能使用 小企鹅输入法fcitx 输入中文,但是firefox可以,暂时采用双浏览器还没有解决这个问题
audacious
启动需要传递-Q
参数(QT界面),使用默认的-G
(GTK界面)无法打开display音乐播放需要使用 MPD(Music Player Daemon) 服务,特别需要注意默认配置不能使用HDMI输出,需要定制
mpd.conf
配置VLC可能是最好的视频播放软件,但是我的 sway - i3兼容Wayland compositor 环境运行在 树莓派Raspberry Pi 400 需要配置正确的音频设备
ALSA
以及正确的视频设备 wayland显示服务器协议 :音频输出输出:
Output module: ALSA audio output
Device: bcm2835 HDMI 1,bcm2835 HDMI 1 Default Audio Device
视频设备输出:
Output: Wayland shared memory video output
Fullscreen Video Device: HDMI-A-1
这是我的 树莓派Raspberry Pi 400 硬件环境配置,你的设备可能不同,请尝试对应的硬件设备配置。
浏览器
qutebrowser 是基于QT5的使用vim键盘方式控制浏览器
Konqueror 是KDE默认浏览器,功能包含了浏览器和文件管理器功能: 缺点是太沉重了,如果不是使用KDE环境则过于复杂
Falkon 也是KDE开发的浏览器,功能精简,经过验证我发现这个浏览器兼容性好(因为引擎就是chromium的精简QTWebkit核心)而且占用资源少,是理想的 sway - i3兼容Wayland compositor 配套浏览器
Otter Browser 基于QT5的继承Opera 12的浏览器,但是这个浏览器没有收录在软件仓库,需要源代码编译安装,太过折腾
最终我在 移动开发:树莓派开发环境构建 中采用 Falkon
作为主力浏览器
$mod + d
不能唤起菜单
单独在终端执行
dmenu
命令提示:cannot open display
这说明没有支持 native wayland 图形显示服务( dmenu
可以运行在 XWayland
环境 )
参考 arch linux: sway : sway wiki 提供 已知兼容sway应用启动器列表 ,网上有人推荐使用 bemenu ,并且Arch Linux案例也推荐使用 bemenu
。不过,arch linux的仓库是直接提供 bemenu
,但是 kali linux(ubuntu) 软件仓库只提供 wofi
,其他启动器需要自己编译
假如使用 bemenu
在修订 ~/.config/sway/config
(我没有尝试)
j4-dmenu-desktop --dmenu='bemenu -i --nb "#3f3f3f" --nf "#dcdccc" --fn "pango:DejaVu Sans Mono 12"' --term='termite'
我使用系统自带 wofi
sudo apt install wofi
然后配置设置(注释掉默认的 $menu
配置):
#set $menu dmenu_path | dmenu | xargs swaymsg exec --
set $menu wofi --show=drun --lines=5 --prompt=""
重新加载
sway
配置:Shift + mod4 + c
,然后就可以通过mod4 + d
加载应用加载器,非常类似macOS环境的Spotlight搜索功能加载应用程序。
Firefox
在 Firefox 的 about:supprt
页面可以观察Firefox是否已经完全切换到 native wayland :
Window Protocol
应该是wayland
,如果显示xwayland
则建议设置环境变朗set -x MOZ_ENABLE_WAYLAND 1
然后在启动Firefox观察
Chroium
配置 ~/.config/chromium-flags.conf
添加以下行:
--enable-features=UseOzonePlatform
--ozone-platform=wayland
可以使chromium 运行在wayland模式。
参考
Full Wayland Setup on Arch Linux 这篇文档非常详细介绍了Wayland的配置以及系列软件,工作配置可做借鉴
Working with Wayland and Sway 介绍sway桌面使用经验