温馨提示×

Debian下Compton如何启用

小樊
46
2025-11-07 02:58:43
栏目: 智能运维

在Debian系统下启用Compton的步骤

1. 安装Compton

首先确保系统已更新,然后通过APT包管理器安装Compton(Debian官方源自带,无需额外添加PPA):

sudo apt update && sudo apt install compton -y

安装完成后,Compton的可执行文件位于/usr/bin/compton

2. 配置Compton

Compton的默认配置文件路径为~/.config/compton.conf(用户级配置,优先级高于系统级)。若文件不存在,可手动创建:

mkdir -p ~/.config
touch ~/.config/compton.conf

使用文本编辑器(如nano)打开配置文件,添加以下基础配置(可根据需求调整):

# 启用窗口阴影(排除GTK窗口以避免视觉冲突)
shadow = true
shadow-exclude = { "class_g" = "GtkWindow"; "class_g" = "GtkDialog"; };

# 设置阴影参数(模糊半径、偏移量)
shadow-radius = 5;
shadow-dx = 2;
shadow-dy = 2;

# 关闭窗口透明度(提升性能,如需开启可设为true)
opacity = false;

# 使用glx后端(需显卡支持OpenGL,性能优于xrender)
backend = "glx";

# 启用垂直同步(避免画面撕裂)
vsync = true;

保存并退出编辑器(Ctrl+XYEnter)。

3. 手动启动Compton

配置完成后,可通过以下命令立即启动Compton(测试效果):

compton --config ~/.config/compton.conf

若未指定配置文件路径,Compton会使用默认配置(通常位于/etc/compton.conf)。

4. 设置开机自启

为了让Compton随系统启动自动运行,需创建systemd服务文件:

sudo nano /etc/systemd/system/compton.service

添加以下内容(替换你的用户名为实际登录用户名):

[Unit]
Description=Compton Window Compositor
After=display-manager.service  # 确保在显示管理器启动后运行

[Service]
ExecStart=/usr/bin/compton --config ~/.config/compton.conf
Restart=always  # 崩溃后自动重启
User=你的用户名  # 以普通用户身份运行(避免权限问题)

[Install]
WantedBy=multi-user.target  # 多用户模式下启动

保存并退出后,执行以下命令启用并启动服务:

sudo systemctl daemon-reload  # 重新加载systemd配置
sudo systemctl enable compton  # 设置开机自启
sudo systemctl start compton   # 立即启动服务

通过systemctl status compton可查看服务状态(若显示“active (running)”则表示启动成功)。

注意事项

  • 显卡驱动:确保已安装正确的显卡驱动(如NVIDIA专有驱动),并支持OpenGL(glx后端需要);
  • 性能优化:若出现卡顿,可关闭阴影(shadow = false)或透明度(opacity = false),或改用xrender后端(兼容性更好但性能略低);
  • 日志排查:若启动失败,可查看日志文件(~/.cache/compton.log)定位问题。

0