如何通过Compton配置实现屏幕旋转
小樊
39
2025-12-14 02:52:10
Compton 与屏幕旋转的正确方式
核心结论
- Compton 本身不负责屏幕旋转,旋转应由 xrandr(X11)或桌面环境/显示管理器完成。Compton 的职责是窗口合成(阴影、透明度、VSync 等)。因此,实现旋转的正确路径是:用 xrandr 改变输出方向,然后让 Compton 重新绘制。若使用 Wayland,xrandr 不适用,应在系统显示设置中旋转。
在 xorg 下的推荐做法
- 步骤 1:确认输出名称
运行:xrandr,查看你的显示器输出名(如 HDMI1、DP1、eDP1 等)。
- 步骤 2:用 xrandr 旋转并立即生效
示例:
- xrandr --output HDMI1 --rotate right
- xrandr --output HDMI1 --rotate left
- xrandr --output HDMI1 --rotate inverted
- xrandr --output HDMI1 --rotate normal
- 步骤 3:让 Compton 适配旋转(避免画面错位/撕裂)
方式 A(推荐):重启 Compton,使其重新读取帧缓冲与变换
- pkill compton && compton --backend glx --vsync opengl-swc &
方式 B:若你的版本支持,在配置中启用 glx-rotate(仅对部分构建/驱动有效)
- 在 ~/.config/compton.conf 中加入:glx-rotate = “normal”;(或 left/right/inverted),然后重启 Compton。注意:该选项并非所有构建都提供,且依赖 OpenGL 与驱动支持,不如直接用 xrandr 可靠。
在窗口管理器中绑定快捷键
- 以 i3 为例(~/.config/i3/config):
- 定义变量:set $rotate_mode “normal”
- 绑定按键(示例:Alt+Shift+R/L/U/D):
- bindsym Mod1+Shift+R exec “xrandr --output HDMI1 --rotate right”
- bindsym Mod1+Shift+L exec “xrandr --output HDMI1 --rotate left”
- bindsym Mod1+Shift+U exec “xrandr --output HDMI1 --rotate inverted”
- bindsym Mod1+Shift+D exec “xrandr --output HDMI1 --rotate normal”
提示:将 HDMI1 替换为你的实际输出名;其他窗口管理器(如 Openbox)可用类似思路在键盘绑定中执行 xrandr 命令。
常见问题与排查
- 旋转后画面撕裂或错位:优先重启 Compton(方式 A),或确认启用 VSync 与合适的 backend=glx。
- 快捷键无效:检查输出名是否正确;某些笔记本需同时设置内建屏与外接屏。
- 使用 Wayland:请在系统“显示”设置中旋转,xrandr 与 Compton 的 X11 方案不适用。
- 找不到 glx-rotate:该选项并非通用,存在构建差异;以 xrandr 为主、Compton 重启为辅更稳妥。