Fedora 下 sway 的配置

Posted on Apr 7, 2025

背景和安装

再一次用回了 Fedora,这次使用了 sway 作为自己的桌面。Fedora 自己就有一个 sway spin,在安装的时候选择 sway 环境就可以直接安装一个几乎配置好了的 sway 桌面,几乎能满足大部分使用需求。

自定义配置

我是笔记本用户,Fedora 默认的 sway 配置还是有很多痛点,还需要一一修改。首先我们需要复制一份配置文件到用户目录,在上面的基础上修改:

mkdir -p ~/.config/sway/config.d
cp /etc/sway/config ~/.config/sway

除此之外,还可以复制好默认的 waybar 配置,或者是在互联网上寻找一个 waybar 配置。

输入法

我采用 fcitx5 作为输入法,安装包 fcitx5fcitx5-chinese-addons,配置如下:

# ~/.config/sway/config.d/90-fcitx5.config
# requires: fcitx5
exec_always --no-startup-id  fcitx5 -date

第一次使用之前记得先配置 fcitx5,加入自己需要的输入法。

笔记本合盖关闭屏幕

加入如下配置文件以实现合上笔记本盖就自动关闭笔记本屏幕(外接屏幕不影响):

# ~/.config/sway/config.d/60-bindings-lid.conf 
set $laptop eDP-1
bindswitch --reload --locked lid:on output $laptop disable
bindswitch --reload --locked lid:off output $laptop enable

当然,需要给屏幕替换为对应的屏幕,可以通过 swaymsg -t get_outputs 查看屏幕名称。

截屏

我使用 grimshot 来进行截屏,加入如下配置文件:

# ~/.config/sway/config.d/60-bindings-screenshot.conf 
# Requires:     grimshot

bindsym {
    # Capture the currently active output
    Print       exec grimshot save output
    # Capture the currently active window
    Alt+Print   exec grimshot save active
    # Select and capture a custom rectangular area
    Ctrl+Print  exec grimshot save area
    $mod+Shift+S exec grimshot save area
}

这样,Print 截取整个屏幕,Alt+Print$mod+Shift+S 截取制定区域。

剪切板

我使用 clipman 管理剪切板,安装包 clipman,加入如下文件:

# ~/.config/sway/config.d/95-clipman.conf 
# requires: clipman
exec wl-paste -t text --watch clipman store --no-persist

并设置好快捷键:

# ~/.config/sway/config
# clipboard
bindsym $mod+Shift+v exec clipman pick -t rofi

使用 $mod+Shift+v 即可调出剪切板记录,回车选择就能复制到目前的剪切板。注意:这个配置的剪切板没有持久化储存,并且 clipman 不能储存图片。

emoji 选择键

笔记本的 Fn+F8 在 windows 下的行为是打开 emoji 选择器。这个组合实际上是快捷键 Win+.。我使用 rofimoji 作为 emoji 选择器,安装包 rofimoji,并设置好快捷键:

# ~/.config/sway/config
# emoji picker
bindsym $mod+Period exec rofi -modi "emoji:rofimoji" -show emoji

触控板

默认配置的触控板并不好用,可以如下修改配置:

# ~/.config/sway/config
input type:touchpad {
    dwt enabled
    tap enabled
    natural_scroll enabled
}

这个配置实现了下面几点:

  • 在打字的时候关闭触控板
  • 允许轻触触控板(而不是按下触控板)
  • 自然滚动

性能切换

笔记本需要在适当的时候切换性能模式。可以先安装包 power-profiles-daemon 并启用服务,在 waybar 上做一个切换性能配置的按钮:

# ~/.config/waybar/config.jsonc
"power-profiles-daemon": {
  "format": "{icon}",
  "tooltip-format": "Power profile: {profile}\nDriver: {driver}",
  "tooltip": true,
  "format-icons": {
    "default": "",
    "performance": "",
    "balanced": "",
    "power-saver": ""
  }
}

记得将这个 module 加入你的状态栏的某个位置。