从autorandr迁移到kanshi:Wayland用户的终极显示配置工具升级指南
【免费下载链接】kanshiDynamic display configuration (mirror)项目地址: https://gitcode.com/gh_mirrors/ka/kanshi
kanshi是一款专为Wayland用户设计的动态显示配置工具,作为autorandr的Wayland替代品,它能自动检测并应用显示输出配置,让多显示器切换变得简单高效。本文将详细介绍如何从autorandr无缝迁移到kanshi,帮助你快速掌握这款强大工具的使用方法。
📌 为什么选择kanshi?autorandr用户的痛点解决
autorandr作为X11下的经典显示配置工具,在Wayland环境中存在诸多限制。而kanshi专为Wayland设计,具有以下优势:
- 原生Wayland支持:基于wlr-output-management协议,完美适配sway等Wayland compositor
- 自动配置切换:当显示器连接状态变化时,自动激活匹配的配置文件
- 简洁配置语法:使用类似sway的输出配置语法,易于理解和编写
🚀 快速安装kanshi的两种方法
方法一:通过包管理器安装(推荐)
大多数Linux发行版已将kanshi纳入官方仓库,可直接通过包管理器安装:
# Debian/Ubuntu sudo apt install kanshi # Arch Linux sudo pacman -S kanshi # Fedora sudo dnf install kanshi方法二:从源码编译安装
如果你的发行版没有提供kanshi包,可以从源码编译:
git clone https://gitcode.com/gh_mirrors/ka/kanshi cd kanshi meson build ninja -C build sudo ninja -C build install⚙️ 从autorandr迁移配置文件
配置文件位置对比
| 工具 | 配置文件路径 |
|---|---|
| autorandr | ~/.config/autorandr/ |
| kanshi | ~/.config/kanshi/config |
配置语法转换示例
autorandr的配置通常分散在多个目录中,而kanshi使用单一配置文件,采用"profile"块的方式组织不同场景的显示设置。
autorandr配置示例(通常位于~/.config/autorandr/laptop/setup):
xrandr --output eDP1 --primary --mode 1920x1080 --pos 0x0 --rotate normal --output DP1 --off对应的kanshi配置(位于~/.config/kanshi/config):
profile laptop { output eDP-1 enable primary mode 1920x1080 position 0,0 output DP-1 disable }📝 编写kanshi配置文件的完整指南
基本结构
kanshi配置文件由一个或多个profile块组成,每个profile块定义一组显示输出设置:
profile <可选名称> { <output指令...> <exec指令...> }常用output指令
启用/禁用显示器
output eDP-1 enable # 启用内置显示器 output DP-1 disable # 禁用DP接口显示器设置分辨率和刷新率
output HDMI-A-1 mode 1920x1080 # 设置分辨率 output HDMI-A-1 mode 1920x1080@60Hz # 设置分辨率和刷新率调整位置和方向
output DP-1 position 1920,0 # 放置在主显示器右侧 output DP-1 transform 270 # 旋转270度设置缩放
output eDP-1 scale 1.5 # 缩放1.5倍高级配置示例
多显示器工作区配置:
profile multihead { output eDP-1 enable primary mode 1920x1080 position 0,0 output DP-1 enable mode 2560x1440 position 1920,0 output HDMI-A-1 enable mode 1920x1080 position 4480,0 exec swaymsg "workspace 1, move workspace to output eDP-1" exec swaymsg "workspace 2, move workspace to output DP-1" }笔记本模式配置:
profile laptop { output eDP-1 enable primary mode 1920x1080 scale 1.25 output "*" disable # 禁用所有其他显示器 }🔧 启动和管理kanshi服务
手动启动
kanshi作为系统服务自动启动
对于sway用户,可以在~/.config/sway/config中添加:
exec kanshi其他桌面环境用户可以创建systemd服务:
# 文件: ~/.config/systemd/user/kanshi.service [Unit] Description=Dynamic output configuration for Wayland [Service] ExecStart=/usr/bin/kanshi [Install] WantedBy=default.target启用并启动服务:
systemctl --user enable --now kanshi重新加载配置
修改配置文件后,无需重启kanshi,只需发送SIGHUP信号即可:
pkill -SIGHUP kanshi💡 实用技巧与常见问题解决
如何获取显示器名称和支持的模式?
使用swaymsg命令可以获取显示器信息:
swaymsg -t get_outputs配置不生效怎么办?
- 检查配置文件语法是否正确
- 确认显示器名称是否与配置文件中一致
- 查看kanshi运行日志排查问题:
kanshi -v
如何设置默认配置?
没有命名的profile将作为默认配置:
# 默认配置 profile { output eDP-1 enable primary mode 1920x1080 } # 其他命名配置 profile external { output eDP-1 disable output DP-1 enable mode 2560x1440 }🎯 总结:开启Wayland显示配置新体验
通过本文的指南,你已经掌握了从autorandr迁移到kanshi的全部要点。kanshi作为Wayland环境下的专业显示配置工具,以其简洁的配置语法和自动切换功能,为多显示器用户提供了高效便捷的解决方案。
无论是日常办公还是多场景切换,kanshi都能让你的显示配置管理变得轻松自如。立即尝试,体验Wayland下的显示配置新方式!
配置文件参考:~/.config/kanshi/config 官方文档:kanshi(5) 工具手册:kanshi(1)
【免费下载链接】kanshiDynamic display configuration (mirror)项目地址: https://gitcode.com/gh_mirrors/ka/kanshi
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考