Sway/zh-cn
Sway (contracted from S irCmpwn's Way land compositor) 是一个 基于 wlroots 的开源 Wayland compositor 合成器,旨在与 i3 兼容。
安装
USE flags
USE flags for gui-wm/sway i3-compatible Wayland window manager
+filecaps
|
Use Linux file capabilities to control privilege rather than set*id (this is orthogonal to USE=caps which uses capabilities at runtime e.g. libcap) |
+man
|
Build and install man pages |
+swaybar
|
Install 'swaybar': sway's status bar component |
+swaynag
|
Install 'swaynag': shows a message with buttons |
X
|
Enable support for X11 applications (XWayland) |
tray
|
Enable support for StatusNotifierItem tray specification |
wallpapers
|
Install sway's default wallpaper image |
Emerge
root
#
emerge --ask gui-wm/sway
配置
要查看所有可用的配置选项:
user
$
man 5 sway
文件
运行 Sway 的每个用户都可以编辑配置文件,以便运行自定义的 Sway 会话。Gentoo 系统将此默认文件存放在 /etc/sway/config :
user
$
mkdir -p ~/.config/sway/
user
$
cp /etc/sway/config ~/.config/sway/
终端
Sway 的默认配置文件使用 foot terminal emulator (可在 gui-apps/foot 中找到)。最好安装这个终端模拟器,以便在Sway 运行时,有一个可用的终端。
root
#
emerge --ask gui-apps/foot
其他流行的选择包括
x11-terms/alacritty
或
x11-terms/kitty
,为了与 Wayland 原生兼容,请把
KITTY_ENABLE_WAYLAND
环境变量设置为
1
。
另一个轻量级的替代方案是 st ,但它不是Wayland原生的。
显示器配置
显示器配置可以通过以下方法查询:
user
$
swaymsg -t get_outputs
Output DP-1 'HP Inc. HP X34 6CM2261GK2' (focused)
Current mode: 3440x1440 @ 165.000 Hz
Position: 0,0
Scale factor: 1.000000
Scale filter: nearest
Subpixel hinting: unknown
Transform: normal
Workspace: 1
Max render time: off
Adaptive sync: disabled
Available modes:
3440x1440 @ 165.000 Hz
...
Output DP-2 'LG Electronics LG HDR QHD 110NTTQ0U193'
Current mode: 2560x1440 @ 59.951 Hz
Position: 3440,0
Scale factor: 1.000000
Scale filter: nearest
Subpixel hinting: unknown
Transform: normal
Workspace: 2
Max render time: off
Adaptive sync: disabled
Available modes:
2560x1440 @ 59.951 Hz
2560x1440 @ 74.971 Hz
...
Output DP-3 'Ancor Communications Inc VE247 E3LMQS103610'
Current mode: 1920x1080 @ 60.000 Hz
Position: 6000,0
Scale factor: 1.000000
Scale filter: nearest
Subpixel hinting: unknown
Transform: normal
Workspace: 3
Max render time: off
Adaptive sync: disabled
Available modes:
1920x1080 @ 60.000 Hz
结果已缩短为仅包含所需的分辨率。如果默认位置配置不正确,可以通过修改 ~/.config/sway/config 进行调整。
~/.config/sway/config
Configure the left display which is physically slightly larger than the primary display
output DP-1 resolution 3440x1440@165hz pos 2560 350
~/.config/sway/config
Configure primary display which is centered
output DP-2 resolution 2560x1440@74.971hz pos 0 250
~/.config/sway/config
Configure alternate display which is vertical
output DP-3 resolution 1920x1080@60hz pos 6000 0 transform 270
输入设备
可以使用以下方法查询输入设备:
user
$
swaymsg -t get_inputs
Input device: Logitech G502 HERO Gaming Mouse Keyboard Type: Mouse Identifier: 1133:49291:Logitech_G502_HERO_Gaming_Mouse_Keyboard Product ID: 49291 Vendor ID: 1133 Libinput Send Events: enabled Input device: Logitech G502 HERO Gaming Mouse Keyboard Type: Keyboard Identifier: 1133:49291:Logitech_G502_HERO_Gaming_Mouse_Keyboard Product ID: 49291 Vendor ID: 1133 Active Keyboard Layout: English (US) Libinput Send Events: enabled Input device: Logitech G502 HERO Gaming Mouse Type: Mouse Identifier: 1133:49291:Logitech_G502_HERO_Gaming_Mouse Product ID: 49291 Vendor ID: 1133 Libinput Send Events: enabled
~/.config/sway/config
禁用鼠标加速, 降低指针速度
input "1133:49291:Logitech_G502_HERO_Gaming_Mouse" {
accel_profile "flat"
pointer_accel -0.1
}
~/.config/sway/config
启用触摸板, 点击以单击
input type:touchpad {
tap enabled
}
Tapping with 1 finger left clicks, 2 right clicks, and 3 middle clicks. This can be adjusted with
tap_button_map
.
应用程序启动器
Sway 可与各种应用程序启动器搭配使用。默认情况下,它使用 gui-apps/wmenu 。
配置sway以安装使用 gui-apps/bemenu :
root
#
emerge --ask dev-libs/bemenu
~/.config/sway/config
将Sway配置为使用bemenu.
set $menu bemenu-run --no-exec | xargs -r swaymsg exec --
~/.config/sway/config
Configure sway to use bemenu, with an empty prompt.
set $menu bemenu-run --no-exec -p "" | xargs -r swaymsg exec --
--line-height
(
-H
) 设置为 26 可以使菜单高度与 waybar 匹配。
默认情况下,sway 会尝试使用 gui-apps/wmenu ,它可以通过以下方式安装:
root
#
emerge --ask gui-apps/wmenu
The default configuration attempts to use dmenu_path which is part of the x11-misc/dmenu package.
配置Sway以简单的使用wmenu
~/.config/sway/config
Configure Sway to use wmenu
set $menu wmenu-run | xargs swaymsg exec --
~/.config/sway/config
Configure Sway to use wmenu with no prompt
set $menu wmenu-run -p "" | xargs swaymsg exec --
状态栏
除了sway自带的状态栏之外, 一个高度可自定义的状态栏 Waybar 可以在sway上使用:
root
#
emerge --ask gui-apps/waybar
在Sway中使用Waybar有两种简单的办法:将Waybar作为bar子命令执行;或者作为常规命令执行。当Sway启动时(或者Sway退出并重启时),两者的行为相同,但它们在Sway的重新加载方面有所不同。将Waybar或者任何其他状态栏作为bar子命令执行将在Sway重新加载时重新启动状态栏; 使用
exec_always
而不是
exec
并不能解决这个问题,它只会使每次重新加载Sway时出现更多的状态栏。
如果你希望通过重载Sway的方式快速测试状态栏配置,则应该使用bar 子命令的方式。
~/.config/sway/config
通过 bar子命令启用Waybar
bar {
# Execute Waybar; Waybar restarts when Sway reloads.
status_command waybar
# Hide Sway's builtin status bar.
mode invisible
}
~/.config/sway/config
通过常规命令启用Waybar
# Execute Waybar; Waybar does not restart when Sway reloads.
exec waybar
屏幕亮度
调整屏幕背光亮度有多种选择,甚至可以通过写入 /sys/class/backlight/<device>/brightness 来完成。
acpilight
或者, sys-power/acpilight 也可以通过 xbacklight 兼容命令完成相同的亮度变化:
~/.config/sway/config
Set the keyboard shortcuts for screen brightness support
bindsym XF86MonBrightnessDown exec xbacklight -dec 2
bindsym XF86MonBrightnessUp exec xbacklight -inc 4
brightnessctl
app-misc/brightnessctl 在 ::guru 中,它可以简单地用来调整背光:
~/.config/sway/config
Add brightnessctl keybinds
bindsym XF86MonBrightnessDown exec brightnessctl set 5%-
bindsym XF86MonBrightnessUp exec brightnessctl set 5%+
light
The github page for dev-libs/light currently (2023-09) states: "This project is considered orphaned since the 8th of March, 2023. Use is heavily discouraged until such a time that it is adopted by another developer." . The package currently remains in the Gentoo ebuild repository , but users may want to take the message from the dev into consideration.
dev-libs/light can be used to adjust backlights and brightness. Here is an example config:
~/.config/sway/config
Set the keyboard shortcuts for screen brightness support
bindsym XF86MonBrightnessDown exec light -U 2
bindsym XF86MonBrightnessUp exec light -A 4
通知
gui-apps/mako 可以用作通知守护程序:
~/.config/sway/config
在启动Sway时启用mako
exec mako
音量
The
XF86AudioRaiseVolume
and
XF86AudioLowerVolume
keycode are generally present and used to adjust the system volume. This must be bound and set depending on the audio backend.
Pipewire
如果使用 PipeWire , 则可以使用以下配置来更改音量(使用 Wireplumber ):
~/.config/sway/config
Set the keyboard shortcuts to change sound volume for PipeWire
bindsym XF86AudioMute exec wpctl set-mute @DEFAULT_SINK@ toggle
bindsym XF86AudioRaiseVolume exec wpctl set-volume @DEFAULT_SINK@ 5%+
bindsym XF86AudioLowerVolume exec wpctl set-volume @DEFAULT_SINK@ 5%-
bindsym XF86AudioMicMute exec wpctl set-mute @DEFAULT_SOURCE@ toggle
Pulseaudio
If pulseaudio is being used, the following configuration can be used for changing sound volume:
~/.config/sway/config
Set the keyboard shortcuts to change sound volume for pulseaudio
bindsym XF86AudioMute exec pactl set-sink-mute @DEFAULT_SINK@ toggle
bindsym XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ +5%
bindsym XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -5%
bindsym XF86AudioMicMute exec pactl set-source-mute @DEFAULT_SOURCE@ toggle
ALSA
If ALSA is being used, the following configuration can be used for changing the sound volume:
~/.config/sway/config
Set the keyboard shortcuts to change sound volume for ALSA
bindsym XF86AudioRaiseVolume exec amixer -Mq set Speaker 5%+
bindsym XF86AudioLowerVolume exec amixer -Mq set Speaker 5%-
sndio
If media-sound/sndio is being used, the following configuration can be used for changing the sound volume:
~/.config/sway/config
Set the keyboard shortcuts to change sound volume for sndio
bindsym XF86AudioRaiseVolume exec sndioctl -f snd/default output.level=+0.05
bindsym XF86AudioLowerVolume exec sndioctl -f snd/default output.level=-0.05
获取屏幕截图
简单的办法:使用slurpshot
( Slurpshot ) is a script to simplify taking screenshots. It uses native wayland apps only and enables selecting specific windows only, as well as previewing and printing screenshots withous saving them. First install dependencies:
root
#
emerge --ask gui-apps/grim gui-apps/slurp app-misc/jq dev-libs/bemenu
Put the slurpshot script somewhere in your PATH, for example to ~/bin, make it executable and just set one keybind:
~/.config/sway/config
Set the keyboard shortcuts for slurpshot support
#
# Screen capture
#
bindsym Print exec slurpshot
Manual approach
To add screenshot support, use the
grim
utility (found in the
gui-apps/grim
package). The abbreviation
grim
is defined as
Gr
ab
Im
ages. This utility is tailored to the specifics of the Wayland protocol. In order to install grim, use the following command:
root
#
emerge --ask gui-apps/grim
To add support for determining the boundaries of the selected screen area, the slurp utility, found in the gui-apps/slurp package, is used in combination with the grim utility. To install slurp, use the command:
root
#
emerge --ask gui-apps/slurp
To add clipboard support wl-clipboard is used, found in gui-apps/wl-clipboard . To install wl-clipboard, use the command:
root
#
emerge --ask gui-apps/wl-clipboard
Next, edit the configuration file to add support for keyboard shortcuts to perform a screenshot operation:
~/.config/sway/config
Set the keyboard shortcuts for screenshot support
#
# Screen capture
#
set $ps1 Print
set $ps2 Control+Print
set $ps3 Alt+Print
set $ps4 Alt+Control+Print
set $psf $(xdg-user-dir PICTURES)/ps_$(date +"%Y%m%d%H%M%S").png
bindsym $ps1 exec grim - | wl-copy
bindsym $ps2 exec grim -g "$(slurp)" - | wl-copy
bindsym $ps3 exec grim $psf
bindsym $ps4 exec grim -g "$(slurp)" $psf
Please note that the
Print
or
Ctrl
+
Print
keys combination creates a screenshot in the
wl-copy
buffer. This allows pasting the image directly from the clipboard, without having to save to a file on disk.
For the Alt + Print or Alt + Ctrl + Print keyboard shortcuts, the method of automatically saving the image file in the Pictures user directory is used.
Snipping tool like behavior
The following captures an area of the screen to the clipboard when mod + shift + S is pressed:
~/.config/sway/config
Similar function to the snipping tool
bindsym $mod+shift+s exec grim -g "$(slurp)" - | wl-copy
-g tells grim to crop to a region, and $(slurp) obtains the region. The screenshot is output to stdout where wl-copy copies the file to the clipboard.
设置随机壁纸
可以从文件夹中随机提取并设置壁纸: [1]
~/.config/sway/config
Set a random wallpaper from a folder
set $wallpapers_path $HOME/Pictures/Wallpapers
output * bg $(find $wallpapers_path -type f | shuf -n 1) fill
Swaylock
gui-apps/swaylock 可以用于锁定当前会话。
root
#
emerge --ask gui-apps/swaylock
~/.config/sway/config
Lock the session when
$mod
+
l
is pressed
bindsym $mod+l exec swaylock --ignore-empty-password --show-failed-attempts --color 1e1e1e
~/.config/sway/config
With colors
man swaylock
for more info
bindsym $mod+l exec swaylock --ignore-empty-password --show-failed-attempts \
--color 1e1e1e --inside-color cccccc --ring-color ffffff \
--inside-clear-color 11a8cd --ring-clear-color 29b8db \
--inside-ver-color 2472c8 --ring-ver-color 3b8eea \
--inside-wrong-color cd3131 --ring-wrong-color f14c4c
If the account is locked out, swaylock will not indicate this, and will simply fail. Switching to another TTY and attempting login can help diagnose this
Swayidle
gui-apps/swayidle runs a command after a certain idle time, typically to lock and/or power off the screen.
root
#
emerge --ask gui-apps/swayidle
~/.config/sway/config
Power off all displays after 15 minutes of idle
exec swayidle -w \
timeout 900 'swaymsg "output * power off"' \
resume 'swaymsg "output * power on"'
高DPI
To adjust sway's rendering for HiDPI displays (4K and above), the name of the display to be adjusted must be obtained. After a sway session is running, issue the following:
user
$
swaymsg -t get_outputs
The
swaymsg
USE flag must be enabled for the
swaymsg
command to be available on the system.
The
output
statement in the sway configuration file will accept a
scale
parameter to adjust the scaling of the high resolution display.
Xresources
~/.config/sway/config
Reload
~/.Xresources
on sway reload
exec_always test -f ~/.Xresources && xrdb -merge ~/.Xresources
GTK 配置
暗色模式
GTK4
GTK4 暗色模式可以通过运行以下命令来启用:
user
$
gsettings set org.gnome.desktop.interface color-scheme prefer-dark
GTK3
GTK3 暗色模式可以通过配置文件启用:
~/.config/gtk-3.0/config.ini
Enable gtk3 dark mode
[Settings]
gtk-application-prefer-dark-theme = true
GTK2
GTK2 does not have a dark mode toggle, a dark theme must be selected:
~/.gtkrc-2.0
Enable gtk2 dark mode
gtk-theme-name = "Adwaita-dark"
GTK3 Themes and Fonts
Currently setting a GTK font and theme should be done by editing sway's configuration file (see Sway's wiki as well):
~/.config/sway/config
Set the font and theme for GTK applications
set $gnome-schema org.gnome.desktop.interface
exec_always {
gsettings set $gnome-schema gtk-theme 'theme name'
gsettings set $gnome-schema icon-theme 'icon theme name'
gsettings set $gnome-schema cursor-theme 'cursor theme name'
gsettings set $gnome-schema font-name 'Sans 10'
}
If encountering problems setting the mouse cursor with certain applications (including sway), this may help:
~/.config/sway/config
Set the cursor theme
seat seat0 xcursor_theme custom_cursor_theme custom_cursor_size
Replace custom_cursor_theme and custom_cursor_size . Adwaita and 24 are pretty much default on all Linux distributions.
自动浮动窗口
By default, Sway opens new windows in tiling mode. The following configuration snippet makes many common windows which should float, float:
for_window [window_role = "pop-up"] floating enable
for_window [window_role = "bubble"] floating enable
for_window [window_role = "dialog"] floating enable
for_window [window_type = "dialog"] floating enable
for_window [window_role = "task_dialog"] floating enable
for_window [window_type = "menu"] floating enable
for_window [app_id = "floating"] floating enable
for_window [app_id = "floating_update"] floating enable, resize set width 1000px height 600px
for_window [class = "(?i)pinentry"] floating enable
for_window [title = "Administrator privileges required"] floating enable
Firefox Tweaks
for_window [title = "About Mozilla Firefox"] floating enable
for_window [window_role = "About"] floating enable
for_window [app_id="firefox" title="Library"] floating enable, border pixel 1, sticky enable
for_window [title = "Firefox - Sharing Indicator"] kill
for_window [title = "Firefox — Sharing Indicator"] kill
Steam Tweaks
for_window [class="^Steam$" title="^Friends$"] floating enable
for_window [class="^Steam$" title="Steam - News"] floating enable
for_window [class="^Steam$" title=".* - Chat"] floating enable
for_window [class="^Steam$" title="^Settings$"] floating enable
for_window [class="^Steam$" title=".* - event started"] floating enable
for_window [class="^Steam$" title=".* CD key"] floating enable
for_window [class="^Steam$" title="^Steam - Self Updater$"] floating enable
for_window [class="^Steam$" title="^Screenshot Uploader$"] floating enable
for_window [class="^Steam$" title="^Steam Guard - Computer Authorization Required$"] floating enable
for_window [title="^Steam Keyboard$"] floating enable
Service
OpenRC
root
#
rc-update add elogind boot
用法
启动Sway
Starting Sway with dbus requires that XDG_RUNTIME_DIR is set. elogind or systemd will set this if used. Omitting the dbus-run-session may cause runtime errors .
从 TTY 自动启动 Sway
To start Sway on login to the first TTY:
~/.bashrc
Launch Sway after logging into the first TTY
if [ -z "${WAYLAND_DISPLAY}" ] && [ "${XDG_VTNR}" -eq 1 ]; then
dbus-run-session sway
fi
Automatic login on tty1
To enable automatic login on tty1,
--skip-login
and
--login-options
can be added to tty1's
agetty
instance defined in
/etc/inittab
:
/etc/inittab
Automatically login as Larry on tty1
c1:12345:respawn:/sbin/agetty --noclear 38400 tty1 linux --skip-login --login-options larry
Starting Sway manually
user
$
dbus-run-session sway
通过一个脚本启动 Sway
This method uses a script to forcibly take over a virtual terminal and launch Sway in it. The typical use case is to launch Sway automatically on boot.
Sway is not supposed to be launched this way, the script may need some tuning to work.
/usr/sbin/sway_launcher
Sway Launcher
#!/bin/sh
# Launch sway with a specific user, from a specific Virtual Terminal (vt)
# Two arguments are expected: a username (e.g., larry) and the id of a free vt (e.g., 7)
# prepare the tty for the user. vtX uses /dev/ttyX
chown "$1" "/dev/tty${2}"
chmod 600 "/dev/tty${2}"
# setup a clean environment for the user, take over the target vt, then launch sway
su --login --command "openvt --switch --console ${2} -- sway >\${HOME}/.sway_autolauncher.log 2>&1" "$1"
# this script returns immediately
This script has a few limitations:
- XDG_RUNTIME_DIR is expected to be defined and valid, see the section above.
-
Without the
--switchoption for openvt, sway will freeze when trying to switch to a different VT ( Ctrl + Alt + Fn ), whether this is a bug or not is unknown. - The VT is not cleared when Sway exits, clear it by calling deallocvt.
- Similarly the TTY's owner and mode are not changed back to their default values when Sway exits.
Launching this script on boot can be done with the local service:
/etc/local.d/sway.start
Launch Sway on boot
#!/bin/sh
sway_launcher larry 7
Starting Sway without elogind or systemd
Systems that are configured with neither systemd nor elogind will need to create a shell script (or use some other means) to set the XDG_RUNTIME_DIR variable.
The environment variable can be defined in the usual configuration files. For example, if Larry the cow (Larry) sets the XDG_RUNTIME_DIR variable in his shell's configuration file and he has chosen that the directory will be in /tmp :
/home/larry/.bash_profile
Set the
XDG_RUNTIME_DIR
variable
#!/bin/sh
if test -z "${XDG_RUNTIME_DIR}"; then
export XDG_RUNTIME_DIR=/tmp/"${UID}"-runtime-dir
if ! test -d "${XDG_RUNTIME_DIR}"; then
mkdir "${XDG_RUNTIME_DIR}"
chmod 0700 "${XDG_RUNTIME_DIR}"
fi
fi
With the XDG_RUNTIME_DIR defined, sway can be launched as usual:
user
$
dbus-run-session sway
If issues are encountered, check Sway issues on GitHub before contacting the Sway community on IRC ( #sway ( webchat )) or opening a new Gentoo bug .
Movement
All key combinations will be defined in the ~/.config/sway/config configuration file.
The
Super
key is defined as the
$mod
value by default. On most keyboards this will be the Windows key.
Sway has a Vi -like interface. h (left), j (down), k (up), and l (right) can be used for movement, in addition to the arrow keys.
Focus can be moved with mod + direction key , windows can be moved with mod + shift + direction key :
~/.config/sway/config
Default movement definitions
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right
See man 5 sway-input for more information.
Useful binds
~/.config/sway/config
Cycle between workspaces with
mod
+
control
+
left arrow
and
mod
+
control
+
right arrow
bindsym $mod+control+Right workspace next
bindsym $mod+control+Left workspace prev
Layouts
By default, Sway uses a tiling layout. Layout modes can be switched with the following default binds:
- mod + b - Horizontal split
- mod + v - Vertical split
- mod + s - Stacking
- mod + w - Tabbed
- mod + e - Toggle split
- mod + shift + space - Toggle floating
~/.config/sway/config
Default layout definitions
bindsym $mod+b splith
bindsym $mod+v splitv
bindsym $mod+s layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+e layout toggle split
bindsym $mod+Shift+space floating toggle
终端
The default key combination to open a terminal emulator is $mod + Enter .
Foot Server
Foot is a minimal Wayland terminal emulator that can be configured to run as a server, reducing resource usage.
~/.config/sway/config
Start the Foot server with Sway
exec foot -s
~/.config/sway/config
Set the default terminal to be a foot client
set $term footclient
If starting the foot server with Sway, it may not start fast enough to also auto-start a service, exec swaymsg "workspace 2; exec $term {command}" may be slow enough to mitigate this
添加功能
Sway is designed to be extended, adding additional features is easy:
~/.config/sway/config
Start htop when
control
+
shift
+
esc
is pressed
bindsym control+shift+escape exec $term htop
If using foot, the app_id , which is set with -a , can be set to make it float automatically:
~/.config/sway/config
Start htop floating when
control
+
shift
+
esc
is pressed
bindsym control+shift+escape exec $term -a 'flying-foot' htop
for_window [app_id="flying-foot"] floating enable
Moving left and right with non-existing workspaces
Sway can switch to the left (
prev
) or right (
next
) workspace as long as there exists a workspace to switch to in that direction; this includes moving containers to those workspaces:
~/.config/sway/config
set $super mod4
bindsym $super+alt+left workspace prev
bindsym $super+alt+right workspace next
bindsym $super+control+alt+left move container to workspace prev, workspace prev
bindsym $super+control+alt+right move container to workspace next, workspace next
To be able to switch to non-existing workspaces, we can create a script to tell Sway to switch to a specific workspace:
~/.config/sway/config
set $super mod4
set $num_of_workspaces 10
bindsym $super+alt+left exec swaymsg -pt get_workspaces | gawk -f ~/.config/sway/workspace.gawk -v move_type="left" -v num_of_workspaces=$num_of_workspaces
bindsym $super+alt+right exec swaymsg -pt get_workspaces | gawk -f ~/.config/sway/workspace.gawk -v move_type="right" -v num_of_workspaces=$num_of_workspaces
bindsym $super+control+alt+left exec swaymsg -pt get_workspaces | gawk -f ~/.config/sway/workspace.gawk -v move_type="container_left" -v num_of_workspaces=$num_of_workspaces
bindsym $super+control+alt+right exec swaymsg -pt get_workspaces | gawk -f ~/.config/sway/workspace.gawk -v move_type="container_right" -v num_of_workspaces=$num_of_workspaces
~/.config/sway/workspace.gawk
#!/bin/gawk -f
$3 == "(focused)" {
switch(move_type) {
case "left":
if ($2 == 1)
$2=num_of_workspaces+1
system("sway workspace "$2-1)
exit
case "right":
if ($2 == num_of_workspaces)
$2=0
system("sway workspace "$2+1)
exit
case "container_left":
if ($2 == 1)
$2=num_of_workspaces+1
system("sway move container to workspace "$2-1", workspace "$2-1)
exit
case "container_right":
if ($2 == num_of_workspaces)
$2=0
system("sway move container to workspace "$2+1", workspace "$2+1)
exit
}
}
故障排除
Screen sharing does not work
Make sure the package gui-libs/xdg-desktop-portal-wlr is installed. By default, it is autostarted by D-Bus but it fails to run because it needs environment variables exported by Sway, and the D-Bus session is started before Sway. To fix, update the D-Bus environment by adding the following line to the beginning of Sway's config:
~/.config/sway/config
exec --no-startup-id dbus-update-activation-environment --all
Also see this link to see if PipeWire is working properly. Ensure XDG_CURRENT_DESKTOP=sway. If using systemd and wireplumber, you may have to enable wireplumber. service ; wireplumber. socket may not be enough.
Failed to connect to user bus
[swaybar/tray/tray.c:42] Failed to connect to user bus: No such file or directory
- Forum topic [swaybar/tray/tray.c:42] Failed to connect to user bus: No such file or directory => Use dbus-run-session sway
- Forum topic sway(bar) with tray support
- https://github.com/swaywm/sway/issues/1415
Warning: no icon themes loaded
[swaybar/tray/icon.c:348] Warning: no icon themes loaded
It is looking for x11-themes/hicolor-icon-theme
No backend was able to open a seat
[ERROR] [wlr] [libseat] [libseat/libseat.c:78] No backend was able to open a seat
It is looking for a seat management daemon such as sys-auth/seatd or sys-auth/elogind . Also check whether setting XDG_RUNTIME_DIR is required.
Applications forget logins
Some applications (e. g. net-misc/nextcloud-client ) use a Secret-Service-Agent to save credentials for login. If applications ask for account credentials every run, an incorrectly configured Secret-Service-Agent might be the reason.
First, emerge gnome-base/gnome-keyring .
root
#
emerge --ask gnome-base/gnome-keyring
Then, enable the
gnome-keyring
USE flag.
/etc/portage/package.use
# Sway Secret-Service-Agent
*/* gnome-keyring
Update the system to apply the new USE flag.
root
#
emerge -avuDN @world
To run and unlock the Agent's storage when logging into a Sway session, edit these two files.
~/.config/sway/config
exec dbus-update-activation-environment --all
exec gnome-keyring-daemon --start --components=secrets
exec export $(gnome-keyring-daemon)
/etc/pam.d/login
auth optional pam_gnome_keyring.so
password optional pam_gnome_keyring.so
session optional pam_gnome_keyring.so auto_start
另请参阅
- i3 — a minimalist tiling window manager , completely written from scratch.
- Wayland — a replacement for the X11 window system protocol and architecture with the aim to be easier to develop, extend, and maintain
- Weston — a reference implementation of a Wayland compositor .
引用
- ↑ https://github.com/swaywm/sway/issues/1269
- ↑ https://github.com/Madic-/Sway-DE/blob/master/config/sway/sway.d/06_floating.conf
- ↑ https://github.com/Madic-/Sway-DE/blob/master/config/sway/sway.d/06_floating.conf
- ↑ https://github.com/Madic-/Sway-DE/blob/master/config/sway/sway.d/06_floating.conf
- ↑ https://github.com/Madic-/Sway-DE/blob/master/config/sway/sway.d/06_floating.conf
- ↑ https://github.com/swaywm/sway#running