ArchLinux Wayland 安裝Sway

1. 先安裝 NVIDIA 驅動

2. 啟用 DRM Kernel Mode Setting(最重要!)

確認目前狀態

cat /sys/module/nvidia_drm/parameters/modeset

應該顯示 Y(新版驅動預設已開)

3. 安裝 Sway 與必要套件

    sudo pacman -S sway swaybg swaylock swayidle
    sudo pacman -S waybar wofi foot wl-clipboard xorg-xwayland
名稱 功能
sway 核心:Wayland 平鋪式視窗管理器(Compositor),整個 Sway 桌面的主程式。
swaybg 設定桌面背景(Wallpaper)。沒有它就無法輕鬆設定桌布。
swaylock Sway 專用的螢幕鎖定程式(鎖屏)。
swayidle 螢幕閒置管理工具(例如:多久後自動鎖定、關閉螢幕、進入休眠)。
waybar 狀態列(Status Bar),顯示時間、電量、音量、 workspaces、工作狀態等。類似 i3blocks + polybar 的功能。
wofi Wayland 下的應用程式啟動器(Launcher)。類似 rofi / dmenu,用來快速開啟程式。
foot 輕量、高效能的 Wayland 原生終端機(Terminal Emulator)。Sway 預設推薦使用。
wl-clipboard Wayland 下的剪貼簿工具(wl-copy 和 wl-paste)。讓你可以在終端機中使用複製貼上。
xorg-xwayland 非常重要:讓舊的 X11 應用程式也能在 Sway(Wayland)上運行。沒有它很多老程式會打不開。

推薦再裝的套件

sudo pacman -S grim slurp    # 截圖工具
sudo pacman -S pipewire wireplumber pavucontrol # 音訊
sudo pacman -S xdg-desktop-portal-gtk xdg-desktop-portal-wlr  # 檔案選擇器、螢幕分享

4. 啟動 Sway(關鍵步驟)

推薦先在終端測試 sway --unsupported-gpu
修改桌面檔(用 Display Manager 時)

sudo vim /usr/share/wayland-sessions/sway.desktop

[Desktop Entry]
Name=Sway
Comment=An i3-compatible Wayland compositor
Exec=sway --unsupported-gpu
Type=Application
DesktopNames=sway;wlroots

6. 基本設定檔入門

複製範本,詳細文檔見本文底部。

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

改變config 檔案使用 UTF-8 編碼

# 把你的設定檔轉成 UTF-8
iconv -f GBK -t UTF-8 ~/.config/sway/config -o ~/.config/sway/config.tmp

# 備份原本檔案後覆蓋
mv ~/.config/sway/config ~/.config/sway/config.bak
mv ~/.config/sway/config.tmp ~/.config/sway/config

設定 locale(很重要):bash

# 永久設定(推薦)
echo "export LANG=zh_TW.UTF-8" >> ~/.bashrc
echo "export LC_ALL=zh_TW.UTF-8" >> ~/.bashrc
source ~/.bashrc

7. 應用配置

修改壁紙

在~/.config/sway/config中設置

    output * bg /usr/share/wallpapers/Nexus/contents/images_dark/5120x2880.png fill

自動切換主題,夜間模式

  1. 安裝必要套件
sudo pacman -S darkman wlsunset xdg-desktop-portal xdg-desktop-portal-gtk
# 可選:GTK/Qt 主題(推薦 Adwaita 系列支援 dark/light 切換)
sudo pacman -S gnome-themes-extra adwaita-icon-theme

darkman:負責自動在日出/日落切換主題。
wlsunset:Wayland 的 Night Light(類似 Redshift)。
xdg-desktop-portal-gtk:讓 GTK 應用能正確讀取 dark mode 設定。

  1. 設定 darkman(核心自動切換)
mkdir -p ~/.config/darkman
cat > ~/.config/darkman/config.yaml << EOF
# lat: 25.0   # 替換成你的緯度(台灣約 23-25)
# lng: 121.5  # 替換成你的經度
usegeoclue: true   # 或 false + 手動 lat/lng
portal: true
dbusserver: true
EOF

啟用並開機自啟:

systemctl --user enable --now darkman.service
  1. 建立切換腳本(最重要)
mkdir -p ~/.local/share/{dark-mode.d,light-mode.d}

~/.local/share/dark-mode.d/01-sway(夜間模式):

#!/bin/sh
# Sway 顏色 / Waybar / 壁紙
#swaymsg "output * bg #1a1b26 solid_color"   # 或用 swaybg 切換壁紙
swaybg -i /usr/share/wallpapers/Nexus/contents/images_dark/5120x2880.png  -m fill & PID=$! && sleep 0.1 && pkill -f swaybg -x -u $USER -o $PID

# GTK
gsettings set org.gnome.desktop.interface gtk-theme 'Adwaita-dark'
gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'

# Waybar(如果使用)
# pkill -USR1 waybar   # 讓 waybar 重新載入 config(需在 waybar config 裡區分 light/dark)

# 其他應用(可自行擴充)
# foot 終端:可寫入不同 config 並重載

~/.local/share/light-mode.d/01-sway(日間模式):

#!/bin/sh
#swaymsg "output * bg #f0f0f0 solid_color"
swaybg -i /usr/share/wallpapers/Nexus/contents/images/5120x2880.png  -m fill & PID=$! && sleep 0.1 && pkill -f swaybg -x -u $USER -o $PID

gsettings set org.gnome.desktop.interface gtk-theme 'Adwaita'
gsettings set org.gnome.desktop.interface color-scheme 'prefer-light'

# pkill -USR1 waybar

給予執行權限:bash

chmod +x ~/.local/share/{dark-mode.d,light-mode.d}/*
  1. Night Light(藍光濾鏡) - wlsunset

在 ~/.config/sway/config 加入:

# Night Light
exec wlsunset -l 32.0 -L 118.8 -t 4500 -T 6500   # 調整你的經緯度、低溫/高溫
# 手動切換快捷鍵
bindsym $mod+Shift+D exec darkman toggle
  1. 測試
darkman set dark     # 強制切夜間
darkman set light    # 強制切日間
darkman get          # 查詢目前模式
darkman toggle

去掉窗口標題欄

在~/.config/sway/config中設置

default_border pixel 1
default_floating_border pixel 1
hide_edge_borders both

網絡面板

    sudo pacman -S nm-connection-editor

在~/.config/sway/config中設置

    exec nm-applet --indicator

foot 配置

foot使用zsh

cp /etc/xdg/foot/foot.ini  ~/.config/foot/
vim ~/.config/foot/foot.ini

加入

    shell=/usr/bin/zsh

Wofi

在~/.config/sway/config中設置

    set $menu wofi --show

創建文件 ~/.config/wofi/config

# 推薦使用 drun 模式(顯示 .desktop 應用,支援圖示)
mode=drun

allow_images=true
insensitive=true
image_size=42

# 基本設定
width=600
height=400
location=center          # 位置:center / top / bottom 等
orientation=vertical
prompt=搜尋應用程式...

# 其他常用選項
lines=10
filter_rate=100
terminal=foot            # 預設終端機

創建~/.config/wofi/style.css

window {
    margin: 10px;
    border: 2px solid #89b4fa;     /* 邊框顏色 */
    border-radius: 12px;
    background-color: rgba(30, 30, 46, 0.95);
}

#input {
    border-radius: 8px;
    margin: 8px;
    padding: 8px;
    background-color: #1e1e2e;
    color: #cdd6f4;
    font-size: 14px;
}

#inner-box {
    margin: 5px;
}

#entry {
    padding: 8px 12px;
    border-radius: 8px;
    color: #cdd6f4;
}

#entry:selected {
    background-color: #89b4fa;
    color: #1e1e2e;
    font-weight: bold;
}

#text {
    color: inherit;
}

#img {
    margin-right: 10px;
}

配置中文輸入法

pacman -S fcitx5 fcitx5-chinese-addons fcitx5-qt fcitx5-gtk fcitx5-config-qt qt5-wayland
sudo pacman -S fcitx5-rime librime # Rime(中州韻)
yay -S rime-ice-git   # 推薦!目前最受歡迎的「霧凇拼音」方案

配置sway config

# Rime / Fcitx5
set $fcitx5_env GTK_IM_MODULE=fcitx QT_IM_MODULE=fcitx XMODIFIERS=@im=fcitx SDL_IM_MODULE=fcitx

exec --no-startup-id fcitx5 -d --replace

修改文件 ~/.local/share/fcitx5/rime/default.custom.yaml

patch:
  switcher/hotkeys:
    - "Control+grave"  # 仅保留 Ctrl+`
    # - "F4"           # 注释掉或删除这行以禁用 F4
  menu/page_size: 5           # 设置候选字数量
  schema_list:
    - schema: rime_ice    # 主要方案(霧凇拼音)
   # - schema: luna_pinyin # 可保留傳統拼音做備用
  switches:
    - name: simplification
      reset: 1

配置輸入法

    fcitx5-configtool

部署 Rime

    fcitx5 -r   # 或在 fcitx5-configtool 中點「重新部署」

修改主題

sudo pacman -S fcitx5-breeze

在Input Method Settings中的Addons下Classic User Interface 中設置theme

Sway 顯示太小(HiDPI)

查看swaymsg -t get_outputs輸出
類似 eDP-1、HDMI-A-1、DP-1 等名稱

修改 ~/.config/sway/config

# ==================== 顯示器縮放 ====================
# 把 eDP-1 改成你實際的輸出名稱
output eDP-1 scale 1.25        # 常用:1.25 / 1.5 / 1.75 / 2

# 如果有多螢幕,可以分別設定
# output HDMI-A-1 scale 1

使用Waybar

修改sway config文件
註釋掉原來的bar{...}, 增加 exec waybar或用 swaybar_command waybar

# 開合waybar
bindsym $mod+b exec "pkill -USR1 waybar"

exec waybar
# 或
bar {
   swaybar_command waybar
}

修改clock,
如果clock不能正常显示,使用custom/clock

 "clock": {
        "format": "{:%Y-%m-%d %H:%M}",
        "tooltip-format": "<tt><small>{calendar}</small></tt>",
        "calendar": {
            "mode": "month",
            "mode-mon-col": 3,
            "weeks-pos": "right",
            "on-scroll": 1,
            "on-click-right": "mode"
        },
        "actions": {
            "on-click-right": "mode",
            "on-scroll-up": "shift_up",
            "on-scroll-down": "shift_down"
        }
    },
	  "custom/clock": {
        "exec": "echo '  '$(date +'%H:%M')'  '",
        "interval": 5,
        "calendar": {
            "mode": "month",
            "format": {
                "today": "<span color='#ff6699'><b>{}</b></span>"
            }
        }
    },

默認custom/media 模块需要手動下載文件,安裝依賴,
建議使用內置的 MPRIS 模块

增加以下mpris模塊,並用"mpris"替換掉"custom/media"

"mpris": {
    "format": "{player_icon} {dynamic}",
    "format-paused": "{status_icon} <i>{dynamic}</i>",
    "player-icons": {
        "default": "▶",
        "spotify": ""
    },
    "status-icons": {
        "paused": "⏸"
    },
    "max-length": 40
}

定時睡眠

# 閒置 120 秒(2分鐘)後鎖定螢幕,再過 300 秒(5分鐘總計)後關閉熒幕,再過900秒後讓系統進入睡眠

exec swayidle -w \
     timeout 120 'swaylock -f -c 000000' \
     timeout 300 'swaymsg "output * power off"' resume 'swaymsg "output * power on"' \
     timeout 900 'systemctl suspend' \
     before-sleep 'pgrep swaylock || swaylock -f -c 000000'

# 設定 $mod + Shift + h 為休眠
# 建議搭配 swaylock 鎖定螢幕,確保資料安全
#bindsym $mod+Shift+h exec swaylock --daemonize && systemctl hibernate

截圖

    sudo pacman -S sway-contrib grim
# Screenshot
set $screenshot /usr/share/sway-contrib/grimshot
bindsym {
    # Capture the currently active output
    $mod+Print       exec $screenshot --notify save output
    # Capture the currently active window
    $mod+Shift+Print   exec $screenshot --notify save active
    # Select and capture a custom rectangular area
    $mod+Ctrl+Print  exec $screenshot --notify save area
}

在啓動sway前加入環境變量

    vim /usr/share/wayland-sessions/sway.desktop
[Desktop Entry]
Name=Sway
Comment=An i3-compatible Wayland compositor
Exec=env QT_QPA_PLATFORMTHEME=qt5ct sway --unsupported-gpu
Type=Application
DesktopNames=sway;wlroots

在sway中Dolphin的默認開啓爲空,雙擊打開失效

安裝

sudo pacman -S archlinux-xdg-menu

運行以下,打開Dolphin雙擊是否正常

XDG_MENU_PREFIX=arch- kbuildsycoca6

kbuildsycoca6 running...
"applications.menu"  not found in  QList("/home/df/.config/menus", "/etc/xdg/menus")

cp /etc/xdg/menus/arch-applications.menu ~/.config/menus/applications.menu
ln -fs /etc/xdg/menus/arch-applications.menu ~/.config/menus/applications.menu

永久設置,配置sway config 加入

vim ~/.config/sway/config

exec env XDG_MENU_PREFIX=arch- kbuildsycoca6

sway增加環境變量

  1. 修改 /etc/environment

  2. 修改sway.desktop,增加 QT_QPA_PLATFORMTHEME=qt6ct

vim /usr/share/wayland-sessions/sway.desktop
[Desktop Entry]
Name=Sway
Comment=An i3-compatible Wayland compositor
Exec=QT_QPA_PLATFORMTHEME=qt6ct sway --unsupported-gpu
Type=Application
DesktopNames=sway;wlroots

config文件內容 ~/.config/sway/config

# Default config for sway
#
# Copy this to ~/.config/sway/config and edit it to your liking.
#
# Read `man 5 sway` for a complete reference.

### Variables
#
# Logo key. Use Mod1 for Alt.
set $mod Mod4
# Home row direction keys, like vim
set $left h
set $down j
set $up k
set $right l
# Your preferred terminal emulator
set $term konsole #foot
# Your preferred application launcher
#set $menu wmenu-run
set $menu wofi --show

### Output configuration
#
# Default wallpaper (more resolutions are available in /usr/share/backgrounds/sway/)
#output * bg /usr/share/backgrounds/sway/Sway_Wallpaper_Blue_1920x1080.png fill
output * bg /usr/share/wallpapers/Nexus/contents/images_dark/5120x2880.png fill
#
# Example configuration:
#
#   output HDMI-A-1 resolution 1920x1080 position 1920,0
#
# You can get the names of your outputs by running: swaymsg -t get_outputs

output eDP-1 scale 1.25
# output HDMI-A-1 scale 1

# Rime / Fcitx5
set $fcitx5_env GTK_IM_MODULE=fcitx QT_IM_MODULE=fcitx XMODIFIERS=@im=fcitx SDL_IM_MODULE=fcitx

exec --no-startup-id fcitx5 -d --replace

exec env QT_QPA_PLATFORMTHEME=qt6ct
exec env XDG_MENU_PREFIX=arch- kbuildsycoca6

### Idle configuration
#
# Example configuration:
#
# exec swayidle -w \
#          timeout 300 'swaylock -f -c 000000' \
#          timeout 600 'swaymsg "output * power off"' resume 'swaymsg "output * power on"' \
#          before-sleep 'swaylock -f -c 000000'
#
# This will lock your screen after 300 seconds of inactivity, then turn off
# your displays after another 300 seconds, and turn your screens back on when
# resumed. It will also lock your screen before your computer goes to sleep.

### Input configuration
#
# Example configuration:
#
#   input type:touchpad {
#       dwt enabled
#       tap enabled
#       natural_scroll enabled
#       middle_emulation enabled
#   }
#
#   input type:keyboard {
#       xkb_layout "eu"
#   }
#
input * {
    xkb_layout us
}

# You can also configure each device individually.
# Read `man 5 sway-input` for more information about this section.

### Key bindings
#
# Basics:
#
    # Start a terminal
    bindsym $mod+Return exec $term

    # Kill focused window
    #bindsym $mod+Shift+q kill
    bindsym $mod+q kill

    # Start your launcher
    bindsym $mod+d exec $menu

    # Drag floating windows by holding down $mod and left mouse button.
    # Resize them with right mouse button + $mod.
    # Despite the name, also works for non-floating windows.
    # Change normal to inverse to use left mouse button for resizing and right
    # mouse button for dragging.
    floating_modifier $mod normal

    # Reload the configuration file
    bindsym $mod+Shift+c reload

    # Exit sway (logs you out of your Wayland session)
    bindsym $mod+Shift+e exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -B 'Yes, exit sway' 'swaymsg exit'
#
# Moving around:
#
    # Move your focus around
    bindsym $mod+$left focus left
    bindsym $mod+$down focus down
    bindsym $mod+$up focus up
    bindsym $mod+$right focus right
    # Or use $mod+[up|down|left|right]
    bindsym $mod+Left focus left
    bindsym $mod+Down focus down
    bindsym $mod+Up focus up
    bindsym $mod+Right focus right

    # Move the focused window with the same, but add Shift
    bindsym $mod+Shift+$left move left
    bindsym $mod+Shift+$down move down
    bindsym $mod+Shift+$up move up
    bindsym $mod+Shift+$right move right
    # Ditto, with arrow keys
    bindsym $mod+Shift+Left move left
    bindsym $mod+Shift+Down move down
    bindsym $mod+Shift+Up move up
    bindsym $mod+Shift+Right move right
#
# Workspaces:
#
    # Switch to workspace
    bindsym $mod+1 workspace number 1
    bindsym $mod+2 workspace number 2
    bindsym $mod+3 workspace number 3
    bindsym $mod+4 workspace number 4
    bindsym $mod+5 workspace number 5
    bindsym $mod+6 workspace number 6
    bindsym $mod+7 workspace number 7
    bindsym $mod+8 workspace number 8
    bindsym $mod+9 workspace number 9
    bindsym $mod+0 workspace number 10
    # Move focused container to workspace
    bindsym $mod+Shift+1 move container to workspace number 1
    bindsym $mod+Shift+2 move container to workspace number 2
    bindsym $mod+Shift+3 move container to workspace number 3
    bindsym $mod+Shift+4 move container to workspace number 4
    bindsym $mod+Shift+5 move container to workspace number 5
    bindsym $mod+Shift+6 move container to workspace number 6
    bindsym $mod+Shift+7 move container to workspace number 7
    bindsym $mod+Shift+8 move container to workspace number 8
    bindsym $mod+Shift+9 move container to workspace number 9
    bindsym $mod+Shift+0 move container to workspace number 10
    # Note: workspaces can have any name you want, not just numbers.
    # We just use 1-10 as the default.
    # 前後切換工作區(非常實用)
    bindsym $mod+comma workspace prev
    bindsym $mod+period workspace next
#
# Layout stuff:
#
    # You can "split" the current object of your focus with
    # $mod+b or $mod+v, for horizontal and vertical splits
    # respectively.
    bindsym $mod+b splith
    bindsym $mod+v splitv

    # Switch the current container between different layout styles
    bindsym $mod+s layout stacking
    bindsym $mod+w layout tabbed
    bindsym $mod+e layout toggle split

    # Make the current focus fullscreen
    bindsym $mod+f fullscreen

    # Toggle the current focus between tiling and floating mode
    bindsym $mod+Shift+space floating toggle

    # Swap focus between the tiling area and the floating area
    bindsym $mod+space focus mode_toggle

    # Move focus to the parent container
    bindsym $mod+a focus parent
#
# Scratchpad:
#
    # Sway has a "scratchpad", which is a bag of holding for windows.
    # You can send windows there and get them back later.

    # Move the currently focused window to the scratchpad
    bindsym $mod+Shift+minus move scratchpad

    # Show the next scratchpad window or hide the focused scratchpad window.
    # If there are multiple scratchpad windows, this command cycles through them.
    bindsym $mod+minus scratchpad show
#
# Resizing containers:
#
mode "resize" {
    # left will shrink the containers width
    # right will grow the containers width
    # up will shrink the containers height
    # down will grow the containers height
    bindsym $left resize shrink width 10px
    bindsym $down resize grow height 10px
    bindsym $up resize shrink height 10px
    bindsym $right resize grow width 10px

    # Ditto, with arrow keys
    bindsym Left resize shrink width 10px
    bindsym Down resize grow height 10px
    bindsym Up resize shrink height 10px
    bindsym Right resize grow width 10px

    # Return to default mode
    bindsym Return mode "default"
    bindsym Escape mode "default"
}
bindsym $mod+r mode "resize"
#
# Utilities:
#
    # Special keys to adjust volume via PulseAudio
    bindsym --locked XF86AudioMute exec pactl set-sink-mute \@DEFAULT_SINK@ toggle
    bindsym --locked XF86AudioLowerVolume exec pactl set-sink-volume \@DEFAULT_SINK@ -5%
    bindsym --locked XF86AudioRaiseVolume exec pactl set-sink-volume \@DEFAULT_SINK@ +5%
    bindsym --locked XF86AudioMicMute exec pactl set-source-mute \@DEFAULT_SOURCE@ toggle

    # Special keys to control media via playerctl
    bindsym --locked XF86AudioPlay exec playerctl play-pause
    bindsym --locked XF86AudioPause exec playerctl play-pause
    bindsym --locked XF86AudioPrev exec playerctl previous
    bindsym --locked XF86AudioNext exec playerctl next
    bindsym --locked XF86AudioStop exec playerctl stop

    # Special keys to adjust brightness via brightnessctl
    bindsym --locked XF86MonBrightnessDown exec brightnessctl set 5%-
    bindsym --locked XF86MonBrightnessUp exec brightnessctl set 5%+

    # Special key to take a screenshot with grim
    bindsym Print exec grim

#
# Status Bar:
#
# Read `man 5 sway-bar` for more information about this section.
#bar {
#    position top
#
#    # When the status_command prints a new line to stdout, swaybar updates.
#    # The default just shows the current date and time.
#    status_command while date +'%Y-%m-%d %X'; do sleep 1; done
#
#    colors {
#        statusline #ffffff
#        background #323232
#        inactive_workspace #32323200 #32323200 #5c5c5c
#    }
#}

# waybar使用
# 開合waybar
bindsym $mod+Shift+b exec "pkill -USR1 waybar"
bar {
   swaybar_command waybar
}
# exec waybar

# 閒置 300 秒(5分鐘)後鎖定螢幕,再過 600 秒(16分鐘總計)後讓系統進入睡眠
exec swayidle -w \
     timeout 120 'swaylock -f -c 000000' \
     timeout 300 'swaymsg "output * power off"' resume 'swaymsg "output * power on"' \
     timeout 900 'systemctl suspend' \
     before-sleep 'pgrep swaylock || swaylock -f -c 000000'

# 設定 $mod + Shift + h 為休眠
# 建議搭配 swaylock 鎖定螢幕,確保資料安全
#bindsym $mod+Shift+h exec swaylock --daemonize && systemctl hibernate

set $screenshot /usr/bin/grimshot
### Screenshot
bindsym {
    # Capture the currently active output
    $mod+Print       exec $screenshot --notify save output
    # Capture the currently active window
    $mod+Shift+Print   exec $screenshot --notify save active
    # Select and capture a custom rectangular area
    $mod+Ctrl+Print  exec $screenshot --notify save area
}

# 无标题栏
default_border pixel 1
default_floating_border pixel 1
hide_edge_borders both

# 網絡
exec nm-applet --indicator

# Night Light
exec wlsunset -l 32.0 -L 118.8 -t 4500 -T 6500   # 調整你的經緯度、低溫/高溫
bindsym $mod+Shift+D exec darkman toggle

# kde connnected
exec kdeconnectd

include /etc/sway/config.d/*


posted @ 2026-06-10 09:53  jokerpoker  阅读(2)  评论(0)    收藏  举报