Files
sway-dotfile/power-management.md
2026-04-13 11:47:42 +08:00

57 lines
1.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Sway 电源自动管理配置
## 功能说明
实现 Sway 环境下根据电源状态自动切换性能模式:
- **插电源**`throughput-performance` (高性能)
- **用电池**`laptop-battery-powersave` (节能降频)
仅在 Sway 会话生效,不影响 Plasma 的电源管理。
## 实现方式
### 1. 自动切换脚本
`/usr/local/bin/tuned-auto-switch.sh`
```bash
#!/bin/bash
# Only run if Sway is running
pgrep -x sway > /dev/null || exit 0
if [ "$(cat /sys/class/power_supply/AC*/online)" = "1" ]; then
tuned-adm profile throughput-performance
else
tuned-adm profile laptop-battery-powersave
fi
```
### 2. Systemd 服务
`/etc/systemd/system/tuned-power-switch@.service`
```ini
[Unit]
Description=Switch tuned profile on power change
[Service]
Type=oneshot
ExecStart=/usr/local/bin/tuned-auto-switch.sh
```
### 3. Udev 规则
`/etc/udev/rules.d/99-tuned-power.rules`
```
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", TAG+="systemd", ENV{SYSTEMD_WANTS}="tuned-power-switch@$kernel.service"
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", TAG+="systemd", ENV{SYSTEMD_WANTS}="tuned-power-switch@$kernel.service"
```
## 验证
查看当前配置:
```bash
tuned-adm active
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
```
监控切换日志:
```bash
journalctl -f
```