在Gentoo环境安装和使用Sway
我的 sway 实践记录
Sway有一些 USE flags 可以微调:
通过以下命令检查当前系统的USE flag:
emerge --info | grep ^USE
修订
/etc/portage/make.conf添加以下USE flag作为全局配置:
# These settings were set by the catalyst build script that automatically
# built this stage.
# Please consult /usr/share/portage/config/make.conf.example for a more
# detailed example.
COMMON_FLAGS="-march=native -O2 -pipe"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"
# If left undefined, Portage's default behavior is to set the MAKEOPTS value to the same number of threads returned by `nproc`
MAKEOPTS="-j8"
# NOTE: This stage was built with the bindist Use flag enabled
# This sets the language of build output to English.
# Please keep this setting intact when reporting bugs.
LC_MESSAGES=C
GENTOO_MIRRORS="http://mirrors.aliyun.com/gentoo http://distfiles.gentoo.org"
ACCEPT_LICENSE="-* @FREE @BINARY-REDISTRIBUTABLE"
USE="wayland man dbus elogind alsa pulseaudio ogg gtk -systemd -X -mesa -gnome -qt5 -qt6 -kde -fortran"
VIDEO_CARDS="intel"
ACCEPT_KEYWORDS="~amd64"
FEATURES="ccache"
CCACHE_DIR="/var/cache/ccache"
添加
/etc/portage/package.use/sway内容是针对单个应用的独立配置:
/etc/portage/package.use/sway 配置独立参数# 当sway启用wallpapers时需要安装swaybg,此时需要启用 gdk-pixbuf 来支持PNG之外的图片类型
gui-apps/swaybg gdk-pixbuf
gui-wm/sway swaybar swaynag wallpapers
# seatd 用于设置sway环境
sys-auth/seatd server
# foot终端支持cjk多字节语言(中文,日文,韩文)
dev-libs/libutf8proc cjk
我发现实际上不配置 /etc/portage/package.use/sway 也行,也是默认启用了 man swaybar swaynag : 不过 swaybar 功能只有简单的状态栏显示,要实现复杂的功能,例如 tray ,则需要安装 waybar
安装 sway :
emerge --ask gui-wm/sway
这里有一个提示:
The following USE changes are necessary to proceed:
(see "package.use" in the portage(5) man page for more details)
# required by gui-wm/sway-1.8.1::gentoo[wallpapers]
# required by gui-wm/sway (argument)
>=gui-apps/swaybg-1.2.0 gdk-pixbuf
# required by media-libs/mesa-23.1.6::gentoo
# required by gui-libs/wlroots-0.16.2-r1::gentoo
# required by gui-wm/sway-1.8.1::gentoo
# required by gui-wm/sway (argument)
>=media-libs/libglvnd-1.6.0 X
这个提示中 sway 的 wallpapers USE flag会触发:
wallpapers 的USE Flag会触发 swaybg 安装The following USE changes are necessary to proceed:
(see "package.use" in the portage(5) man page for more details)
# required by gui-wm/sway-1.8.1::gentoo[wallpapers]
# required by gui-wm/sway (argument)
>=gui-apps/swaybg-1.2.0 gdk-pixbuf
# required by media-libs/mesa-23.1.6::gentoo
# required by gui-libs/wlroots-0.16.2-r1::gentoo
# required by gui-wm/sway-1.8.1::gentoo
# required by gui-wm/sway (argument)
>=media-libs/libglvnd-1.6.0 X
如果USE flags 没有使用 -mesa 就会触发以下:
mesa 的USE Flag会触发 libglvnd 安装The following USE changes are necessary to proceed:
(see "package.use" in the portage(5) man page for more details)
# required by gui-wm/sway-1.8.1::gentoo[wallpapers]
# required by gui-wm/sway (argument)
>=gui-apps/swaybg-1.2.0 gdk-pixbuf
# required by media-libs/mesa-23.1.6::gentoo
# required by gui-libs/wlroots-0.16.2-r1::gentoo
# required by gui-wm/sway-1.8.1::gentoo
# required by gui-wm/sway (argument)
>=media-libs/libglvnd-1.6.0 X
配置
先将全局配置复制到个人目录下:
mkdir -p ~/.config/sway
cp /etc/sway/config ~/.config/sway/
启动 测试( 注意单纯sway命令会有环境配置问题,需要仔细设置 ):
swaysway
XDG_RUNTIME_DIR
启动
sway报错:
sway 报错XDG_RUNTIME_DIR is not set in the environment. Aborting
这是因为:
没有安装和配置
seatd没有设置好用户的环境变量
XDG_RUNTIME_DIR(也就是每个用户需要有独立分离的运行时目录)
解决方法一
解决方法:
安装
sys-auth/seatd并且配置用户huatai到对应组,以及启动服务:
seatdemerge --ask sys-auth/seatd
# 针对OpenRC配置
gpasswd -a huatai video
gpasswd -a huatai seat
rc-update add seatd default
rc-service seatd start
在上述添加用户到 seat 组时遇到报错:
gpasswd: group 'seat' does not exist in /etc/group
并且执行添加 seatd 服务也报错:
# rc-update add seatd default
* rc-update: service `seatd' does not exist`
原因参考 sys-auth/seatd does not come with initscript 需要为 seat 添加 server 和 builtin USE flag:
sys-auth/seatd 配置 USE flagecho "sys-auth/seatd server builtin" >> /etc/portage/package.use/sway
然后重新编译安装 seat
然后为用户
huatai配置~/.bashrc添加如下内容设置用户环境变量:
~/.bashrcexport XDG_RUNTIME_DIR="/tmp/user/"`id -u`
if [ ! -d $XDG_RUNTIME_DIR ]; then
mkdir -p $XDG_RUNTIME_DIR
chmod 0700 $XDG_RUNTIME_DIR
fi
还有一个类似脚本,可以参考:
~/.bashrc 的另一个脚本#!/bin/sh
if test -z "${XDG_RUNTIME_DIR}"; then
UID="$(id -u)"
export XDG_RUNTIME_DIR=/tmp/"${UID}"-runtime-dir
if ! test -d "${XDG_RUNTIME_DIR}"; then
mkdir "${XDG_RUNTIME_DIR}"
chmod 0700 "${XDG_RUNTIME_DIR}"
fi
fi
最后(手工)执行启动命令中添加
dbus-run-session:
dbus-run-session 启动 sway 这样能够正确获得 D-Bus session busdbus-run-session sway
解决方法二
备注
我理解 elogind 是为了帮助设置DBUS环境的,上文通过环境变量和脚本设置了 XDG_RUNTIME_DIR ,则这段不用执行
警告
我在尝试安装 waybar 发现要强制激活 systemd ,这个问题困扰我(我不想使用systemd),所以我改为激活 elogind 并关闭 systemd
然后我回滚前面的 解决方法一,尝试用解决方案二来设置 XDG 相关参数
也可能是解决 Gentoo Linux Sway fcitx中文输入 的方法
elogind 需要添加到 boot 运行级别:
/etc/portage/make.conf 添加:
systemd 启用 elogindUSE="elogind -systemd"
执行USE修订后重新更新系统
emerge --ask --changed-use --deep @world
elogind 来代替 systemd logindemerge --ask sys-auth/elogind
rc-update add elogind boot
备注
当 Gentoo D-Bus 使用了 USE="elogind" 参数,则系统启动 elogind 会自动触发启动 dbus
备注
当使用了 elogind 或 systemd ,则会自动设置 XDG_RUNTIME_DIR ,否则就要自己手工设置
没有 dbus-run-session 支持,sway 运行可能出现运行时错误
警告
我最终没有使用这段方案,即没有安装 elogind ,而是采用上文手工命令方式(方案一)
系统程序
安装和 sway 底层系统相关的一些基础实用程序:
swaylock
gui-apps/swaylock 用于锁定当前会话
swaylockemerge --ask gui-apps/swaylock
然后配置 ~/.config/sway/config 将 $mod + l 作为锁屏快捷键:
~/.config/sway/config 配置锁屏快捷键 # Lock sway
bindsym $mod+l exec swaylock --ignore-empty-password --show-failed-attempts \
--color 1e1e1e --inside-color cccccc --ring-color ffffff \
--inside-clear-color 11a8cd --ring-clear-color 29b8db \
--inside-ver-color 2472c8 --ring-ver-color 3b8eea \
--inside-wrong-color cd3131 --ring-wrong-color f14c4c
swayidle
gui-apps/swayidle 可以在系统进入idle一段时间后运行一个命令,典型的如锁定屏幕或者关闭显示屏:
emerge --ask gui-apps/swayidle
然后将 ~/.config/sway/config 中有关 swayidle 的功能恢复出来(去除行首的 # ):
~/.config/sway/config 中有关 swayidle 激活### Idle configuration
#
# Example configuration:
#
exec swayidle -w \
timeout 300 'swaylock -f -c 000000' \
timeout 600 'swaymsg "output * power off"' resume 'swaymsg "output * power 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.
应用程序
foat终端
补充安装
foot(因为默认配置中使用了foot作为终端):
emerge --ask gui-apps/foot
备注
我发现在安装 foot 的依赖包 dev-libs/libutf8proc 提供了一个 USE flag cjk 是用来支持Multi-byte character languages (Chinese, Japanese, Korean)
现在就能正常启动 sway 了,不过此时还不能充分发挥高分辨率屏幕特性,待继续优化...
终端模拟器
默认终端模拟器是 foot ,一个非常轻量级的终端, 但是可能对中文支持不好 (我这次实践开启了 cjk Gentoo Linux USE Flags 发现中文显示很好)
Gentoo的wiki中推荐 x11-terms/alacritty 是原生Wayland程序,而且使用 Rust 编写,性能卓越。
应用程序加载器
默认的应用程序加载器是 dmenu 但是这个程序依赖X,所以推荐使用 dev-libs/bemenu (原生Wayland)替代
waybar
支持众多功能:
libinput输入相关mpd支持 MPD(Music Player Daemon)tray支持托盘wifi支持wifi/rfkillnetwork网络... 好多功能,待配置
当前我简单编译,等下再开启更多参数
emerge --ask gui-apps/waybar
激活:
# 激活Waybar,隐藏builtin bar
bar {
status_command waybar
mode invisible
}
备注
waybar 使用了特定字体来显示一些图标,例如 wifi 图标,电池图标。如果没有安装字体,会导致显示框中显示的是一个乱码。检查 /etc/xdg/waybar/style.css 可以看到配置注释中说明 otf-font-awesome 字体是图标显示所必须的:
otf-font-awesome (这个字体具有 Global USE Flag otf )emerge --ask media-fonts/fontawesome
奇怪,还有一个图标没有显示出来
高分辨率
swaymsg可检查系统硬件,其中检查显示屏如下:
swaymsg -t get_outputs
例如我的笔记本显示:
Output eDP-1 'Apple Computer Inc Color LCD Unknown' (focused)
Current mode: 2880x1800 @ 59.990 Hz
Position: 0,0
Scale factor: 2.000000
Scale filter: nearest
Subpixel hinting: unknown
Transform: normal
Workspace: 1
Max render time: off
Adaptive sync: disabled
Available modes:
2880x1800 @ 59.990 Hz
1920x1200 @ 59.955 Hz
1920x1080 @ 60.000 Hz
1600x1200 @ 59.955 Hz
1680x1050 @ 59.998 Hz
1400x1050 @ 59.998 Hz
1280x1024 @ 59.950 Hz
1280x960 @ 59.995 Hz
1152x864 @ 59.972 Hz
1024x768 @ 59.949 Hz
800x600 @ 59.960 Hz
在
~/.config/sway/config可以添加多个显示器配置,例如以下是3个并排显示器配置,且第三个显示器垂直旋转:
# 配置左方的显示器,且物理规格稍微比主显示器大一些
output DP-1 resolution 3440x1440@165hz pos 2560 350
# 主显示器居中
output DP-2 resolution 2560x1440@74.971hz pos 0 250
# 可选显示器是垂直的
output DP-3 resolution 1920x1080@60hz pos 6000 0 transform 270