FreeBSD Wayland+Sway
备注
2024年底再次实践FreeBSD桌面,目标是在 MacBook Pro 15" Late 2013 构建 Wayland + Sway 桌面,并实现中文工作环境
wayland显示服务器协议 是新的显示服务器,与 X Window显示服务器协议 的主要区别如下
Wayland只是一种协议: Wayland使用不同的机制充当客户端之间的中介,从而消除了对X服务器的依赖
Xorg则包含了运行远程显示器的X11协议,X服务器接收连接并显示窗口;但是在Wayland中,则是由合成器(compositor)或窗口管理器(window manager)提供显示服务器,而不是传统的X服务器
由于Wayland不提供X服务器,并且期望compositor提供该支持,所以对于不支持Wayland的X11窗口管理器需要使用 -rootless
属性来启动 Xwayland
检查显卡
执行以下命令查询自己主机使用的显卡:
pciconf -lv|grep -B4 VGA
我的 MacBook Pro 15" Late 2013 显示输出是NVIDIA:
vgapci0@pci0:1:0:0: class=0x030000 rev=0xa1 hdr=0x00 vendor=0x10de device=0x0fe9 subvendor=0x106b subdevice=0x0130
vendor = 'NVIDIA Corporation'
device = 'GK107M [GeForce GT 750M Mac Edition]'
class = display
subclass = VGA
警告
一定要安装支持显卡芯片的NVIDIA驱动,对于非常古老的NVIDIA显卡,例如我的 MacBook Pro 15" Late 2013 是不能使用最新550版本驱动,会导致运行 sway
报错:
...
00:00:10.109 [wlr] [backend/backend.c:217] Found 0 GPUs, cannot create backed
00:00:10.109 [wlr] [backend/backend.c:386] Failed to open any DRM device
00:00:10.109 [sway/server.c:56] Unable to create backend
...
解决方法是安装指定版本 nvidia-driver
,例如 FreeBSD XFCE桌面 实践通过检查Xorg日志确认需要安装指定 470.xx
旧驱动
Tips
当前很多软件在Wayland可能有少量问题,并且完善支持的桌面较少
对于compositor,需要内核支持
evdev
驱动,该驱动已经在GENERIC
内核build in,但是如果定制内核没有buind inevdev
,则必须通过内核模块加载evdev
使用Wayland的用户必须位于
video
用户组:
admin
用户加入 video
组(举例)pw groupmod video -m admin
所有的compositor都可以和
graphics/drm-kmod
开源驱动一起工作,但是 NVIDIA 图形卡可能在使用专有驱动时会存在问题
安装
安装
wayland
和seated
:
wayland
和 seated
pkg install wayland seatd
安装比较简单,但是需要仔细看一下输出提示:
wayland
和 seated
的输出信息=====
Message from wayland-1.23.1:
--
Wayland requires XDG_RUNTIME_DIR to be defined to a path that will
contain "wayland-%d" unix(4) sockets. This is usually handled by
consolekit2 (via ck-launch-session) or pam_xdg (via login).
=====
Message from seatd-0.8.0_1:
--
libseat is used to get DRM master and input devices for non-root users.
On Wayland this is only necessary when starting a compositor under KMS
console (e.g., /dev/ttyv0 backed by /dev/dri/card0). Nested sessions like
"Wayland on X11" or "Wayland on Wayland" don't need extra configuration.
By default libseat tries to find the first working backend. To override
set LIBSEAT_BACKEND via environ(7). Available backends and try order:
* "seatd" - seatd-launch(1) or seatd rc.d(8) service
* "consolekit2" - ck-launch-session(1) or pam_ck_connector(8)
"seatd" backend requires membership in "video" group to be allowed to
use setuid bit in seatd-launch(1) or connect to seatd(1) socket.
# pw groupmod video -m <user>
$ exit # log out to refresh group permissions
For example, to start a wlroots-based compositor replace "sway" with
your compositor (e.g., "hikari", "wayfire", "labwc", "river") then run
$ seatd-launch sway
Alternatively, configure and run seatd(1) as system service
# sysrc seatd_enable=YES
# service seatd start
$ sway
To use ConsoleKit2 run
# pkg install consolekit2 basu
# sysrc -x seatd_enable
# service seatd stop
# sysrc dbus_enable=YES
# service dbus start
$ ck-launch-session sway
where "ck-launch-session" can be dropped after
# echo "session optional pam_ck_connector.so" >>/etc/pam.d/system
$ exit # log out to re-trigger PAM
Known issues:
- Garbage on console due to missing K_OFF, see
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=272095
在安装了协议(wayland)和支持(seated)包以后,compositor负责创建用户界面。所有使用Wayland的compositor都需要在环境中定义一个运行时目录(从FreeBSD 14.1开始,该目录会自动创建和定义),可以通过以下 Bash 命令创建:
XDG_RUNTIME_DIR
环境变量export XDG_RUNTIME_DIR=/var/run/user/`id -u`
注意,对于 csh
,可以在 ~/.cshrc
添加:
XDG_RUNTIME_DIR
环境变量,配置文件 ~/.cshrc
setenv XDG_RUNTIME_DIR /var/run/user/`id -u`
警告
原文中提到 ZFS 肯能会导致一些Wayland客户端问题,原因时这些客户端访问 runtime 目录的 posix_fallocate()
建议时将 /var/run
目录调整到 tmpfs
(参考 FreeBSD tmpfs )
修订
/boot/loader.conf
添加配置
tmpfs_load="YES"
配置了
/etc/fstab
:
/etc/fstab
添加tmpfs挂载tmpfs /tmptmpfs rw 0 0
上述配置我还没有实践 因为目前还没有遇到wayland客户端问题
设置
seated
在系统启动时启动:
seated
在系统启动时启动sysrc seatd_enable="YES"
service seatd start
seatd 守护进程有助于管理合成器中非 root 用户对共享系统设备的访问,包括显卡
sway
Sway compositor平铺合成器,安装可以通过以下命令完成:
pkg install sway swayidle swaylock-effects alacritty dmenu-wayland dmenu
安装后的输出信息:
=====
Message from freetype2-2.13.3:
--
The 2.7.x series now uses the new subpixel hinting mode (V40 port's option) as
the default, emulating a modern version of ClearType. This change inevitably
leads to different rendering results, and you might change port's options to
adapt it to your taste (or use the new "FREETYPE_PROPERTIES" environment
variable).
The environment variable "FREETYPE_PROPERTIES" can be used to control the
driver properties. Example:
FREETYPE_PROPERTIES=truetype:interpreter-version=35 \
cff:no-stem-darkening=1 \
autofitter:warping=1
This allows to select, say, the subpixel hinting mode at runtime for a given
application.
If LONG_PCF_NAMES port's option was enabled, the PCF family names may include
the foundry and information whether they contain wide characters. For example,
"Sony Fixed" or "Misc Fixed Wide", instead of "Fixed". This can be disabled at
run time with using pcf:no-long-family-names property, if needed. Example:
FREETYPE_PROPERTIES=pcf:no-long-family-names=1
How to recreate fontconfig cache with using such environment variable,
if needed:
# env FREETYPE_PROPERTIES=pcf:no-long-family-names=1 fc-cache -fsv
The controllable properties are listed in the section "Controlling FreeType
Modules" in the reference's table of contents
(/usr/local/share/doc/freetype2/reference/index.html, if documentation was installed).
=====
Message from duktape-lib-2.7.0:
--
===> NOTICE:
The duktape-lib port currently does not have a maintainer. As a result, it is
more likely to have unresolved issues, not be up-to-date, or even be removed in
the future. To volunteer to maintain this port, please create an issue at:
https://bugs.freebsd.org/bugzilla
More information about port maintainership is available at:
https://docs.freebsd.org/en/articles/contributing/#ports-contributing
=====
Message from libxkbcommon-1.7.0_1:
--
If arrow keys don't work under X11 switch to legacy rules e.g.,
For sh/bash/ksh/zsh run and (optionally) add into ~/.profile:
export XKB_DEFAULT_RULES=xorg
For csh/tcsh run and (optionally) add into ~/.login:
setenv XKB_DEFAULT_RULES xorg
=====
Message from sway-1.9_2:
--
Notes:
- sway(1) can use mac_priority(4) to avoid stutter during high load
基础配置:
mkdir ~/.config/sway
cp /usr/local/etc/sway/config ~/.config/sway
修订
~/.config/sway
配置文件,添加一些重要配置:
# Logo key. Use Mod1 for Alt.
input * xkb_rules evdev
set $mod Mod4
# Your preferred terminal emulator
# #set $term foot
set $term alacritty
set $lock swaylock -f -c 000000
### Output configuration
##
## Default wallpaper (more resolutions are available in /usr/local/share/backgrounds/sway/)
##output * bg /usr/local/share/backgrounds/sway/Sway_Wallpaper_Blue_1920x1080.png fill
output "My Workstation" mode 1366x768@60Hz position 1366 0
output * bg ~/wallpapers/mywallpaper.png stretch
### Idle 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'
### Key bindings
# Lock the screen manually
bindsym $mod+Shift+Return exec $lock
参考
Freebsd 14 Wayland and Wayfire using Nvidia on Dell XPS 15 介绍了需要
nvidia-driver nvidia-settings nvidia-drm-515-kmod libva-intel-driver libva-utils
似乎是一个成功案例可以借鉴