https://wiki.archlinux.org/api.php?action=feedcontributions&user=Knaick&feedformat=atomArchWiki - User contributions [en]2024-03-29T08:25:27ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Sway&diff=574539Sway2019-06-04T14:50:42Z<p>Knaick: /* Wallpaper */ Added Swaybg package dependency</p>
<hr />
<div>[[Category:Tiling WMs]]<br />
[[Category:Dynamic WMs]]<br />
[[ja:Sway]]<br />
''sway'' is a compositor for [[Wayland]] designed to be fully compatible with [[i3]]. According to [https://swaywm.org the official website]:<br />
:Sway is a tiling Wayland compositor and a drop-in replacement for the i3 window manager for X11. It works with your existing i3 configuration and supports most of i3's features, plus a few extras.<br />
<br />
== Installation ==<br />
<br />
''sway'' can be [[install]]ed with the {{Pkg|sway}} package. The development version can be installed using {{AUR|wlroots-git}} and {{AUR|sway-git}}. It's advisable to always update ''wlroots'' when you update ''sway'', due to tight dependencies.<br />
<br />
You may also install {{Pkg|swaylock}} and {{Pkg|swayidle}} to lock your screen and set up an idle manager.<br />
<br />
== Starting ==<br />
<br />
{{Tip|See [[Wayland#GUI libraries]] for appropriate environment variables to set for window decoration libraries.}}<br />
<br />
=== From a TTY ===<br />
<br />
To start Sway, simply type ''sway'' from a TTY.<br />
<br />
=== From a display manager ===<br />
<br />
{{Note|Sway does not support display managers officially.[https://github.com/swaywm/sway/pull/3634#issuecomment-462779163]}}<br />
<br />
The sway session is located at {{ic|/usr/share/wayland-sessions/sway.desktop}}. It is automatically recognized by modern display managers like [[GDM]] and [[SDDM]].<br />
<br />
Also you can use text-based session manager, see [[Display manager#Console]].<br />
<br />
== Configuration ==<br />
<br />
If you already use i3, then copy your i3 configuration to {{ic|~/.config/sway/config}} and it should work out of the box. Otherwise, copy the sample configuration file to {{ic|~/.config/sway/config}}. It is located at {{ic|/etc/sway/config}}, unless the {{ic|DFALLBACK_CONFIG_DIR}} flag has been set. See {{man|5|sway}} for information on the configuration.<br />
<br />
=== Keymap ===<br />
<br />
By default, sway starts with the US QWERTY keymap. To configure per-input:<br />
<br />
{{hc|~/.config/sway/config|<nowiki><br />
input * xkb_layout "us,de,ru"<br />
input * xkb_variant "colemak,,typewriter"<br />
input * xkb_options "grp:win_space_toggle"<br />
input "MANUFACTURER1 Keyboard" xkb_model "pc101"<br />
input "MANUFACTURER2 Keyboard" xkb_model "jp106"<br />
</nowiki>}}<br />
<br />
More details are available in {{man|7|xkeyboard-config}} and {{man|5|sway-input}}.<br />
<br />
The keymap can also be configured using environment variables ({{ic|XKB_DEFAULT_LAYOUT}}, {{ic|XKB_DEFAULT_VARIANT}}, etc.) when starting sway.<br />
<br />
=== Statusbar ===<br />
<br />
Installing the program {{Pkg|i3status}} is an easy way to get a practical, default statusline. All one has to do is add following snippet at the end of your sway config:<br />
<br />
{{hc|~/.config/sway/config|<nowiki><br />
bar {<br />
status_command i3status<br />
}<br />
</nowiki>}}<br />
<br />
If you want to achieve colored output of i3status, you can adjust following part in the i3status configuration:<br />
<br />
{{hc|~/.config/i3status/config|<nowiki><br />
general {<br />
colors = true<br />
interval = 5<br />
}<br />
</nowiki>}}<br />
<br />
In both examples, the system-wide installed configuration files has been copied over to the user directory and then modified. <br />
<br />
{{Tip|{{Pkg|waybar}} is an alternative to the bar included with sway (swaybar).}}<br />
<br />
=== Wallpaper ===<br />
<br />
Since release 1.1.1 the wallpaper part of the SwayWM project was moved to a different package called, swaybg , which is needed in order to run the output command .<br />
<br />
This line, which can be appended at the end of your sway configuration, sets a background image on all displays (output matches all with name {{ic|"*"}}):<br />
<br />
{{hc|~/.config/sway/config|<nowiki><br />
output "*" bg /home/onny/pictures/fredwang_norway.jpg fill<br />
</nowiki>}}<br />
<br />
Of course you have to replace the file name and path according to your wallpaper.<br />
<br />
=== Input devices ===<br />
<br />
Its possible to tweak specific input device configurations. For example to enable tap-to-click and natural scolling for a touchpad, add an input block:<br />
<br />
{{hc|~/.config/sway/config|<nowiki><br />
input "2:14:ETPS/2_Elantech_Touchpad" {<br />
tap enabled<br />
natural_scroll enabled<br />
}<br />
</nowiki>}}<br />
<br />
Where as the device identifier can be queried with:<br />
<br />
$ swaymsg -t get_inputs<br />
<br />
The output from the command, sometimes has a "\" to escape symbols like "/" (ie {{ic|"2:14:ETPS\/2_Elantech_Touchpad"}}) and it needs to be removed.<br />
<br />
More documentation and options like acceleration profiles can be found in {{man|5|sway-input}}.<br />
<br />
=== HiDPI ===<br />
<br />
Set your displays scale factor with the {{ic|output}} command in your config file. The scale factor can be fractional, but it is usually 2 for HiDPI screens.<br />
<br />
output <name> scale <factor><br />
<br />
You can find your display name with the following command:<br />
<br />
$ swaymsg -t get_outputs<br />
<br />
=== Custom keybindings ===<br />
<br />
[[Extra keyboard keys|Special keys]] on your keyboard can be used to execute commands, for example to control your volume or your monitor brightness:<br />
<br />
{{hc|~/.config/sway/config|<nowiki><br />
bindsym XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ +5%<br />
bindsym XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -5%<br />
bindsym XF86AudioMute exec pactl set-sink-mute @DEFAULT_SINK@ toggle<br />
bindsym XF86AudioMicMute exec pactl set-source-mute @DEFAULT_SOURCE@ toggle<br />
bindsym XF86MonBrightnessDown exec brightnessctl set 5%-<br />
bindsym XF86MonBrightnessUp exec brightnessctl set +5%<br />
</nowiki>}}<br />
<br />
To control brightness you can use {{AUR|brightnessctl}} or {{Pkg|light}}. For a list of utilities to control brightness and color correction see [[Backlight]].<br />
<br />
=== Xresources ===<br />
<br />
Copy {{ic|~/.Xresources}} to {{ic|~/.Xdefaults}} to use them in Sway.<br />
<br />
=== Run programs natively under Wayland (without Xwayland support) ===<br />
<br />
{{Accuracy|{{ic|xwayland disable}} is not necessary to run programs natively under Wayland, configuring the [[Wayland#GUI libraries|GUI libraries]] appropriately is enough. Keeping XWayland enabled is good for programs that don't work otherwise.}}<br />
<br />
First, be sure the toolkit or library of every program that is and will be installed [[Wayland#GUI_libraries|support Wayland]]. Then append the following line to your sway configuration file to disable Xwayland support:<br />
<br />
{{hc|~/.config/sway/config|<nowiki><br />
xwayland disable<br />
</nowiki>}}<br />
<br />
{{ Note| Some programs, like [[Firefox#Wayland|Firefox]], [[#Application launchers|bemenu]] or [[Wayland#Qt_5|Qt5]] based programs, also need specific environment variables set for them to run natively under Wayland. }}<br />
{{ Note| In a fresh Sway install, you need to change the default menu and terminal applications because they depend on Xwayland. }}<br />
<br />
== Tips and tricks ==<br />
<br />
=== Autostart on login ===<br />
<br />
To start sway from tty1 on login with default US keyboard, edit:<br />
<br />
{{hc|~/.bash_profile|<br />
<nowiki>if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then<br />
XKB_DEFAULT_LAYOUT=us exec sway<br />
fi</nowiki><br />
}}<br />
<br />
=== Backlight toggle ===<br />
<br />
To turn off (and on) your displays with a key (e.g. {{ic|Pause}}) bind the following in your Sway {{ic|config}}:<br />
<br />
#!/usr/bin/dash<br />
read lcd < /tmp/lcd<br />
if [ "$lcd" -eq "0" ]; then<br />
swaymsg "output * dpms on"<br />
echo 1 > /tmp/lcd<br />
else<br />
swaymsg "output * dpms off"<br />
echo 0 > /tmp/lcd<br />
fi<br />
<br />
=== Screen capture ===<br />
<br />
Capturing the screen can be done using {{Pkg|grim}} or {{AUR|swayshot}} for screenshots and {{AUR|wf-recorder-git}} for video. Optionally, {{Pkg|slurp}} can be used to select the part of the screen to capture.<br />
<br />
Take a screenshot of the whole screen:<br />
<br />
$ grim screenshot.png<br />
<br />
Take a screenshot of a part of the screen:<br />
<br />
$ grim -g "$(slurp)" screenshot.png<br />
<br />
Capture a video of the whole screen:<br />
<br />
$ wf-recorder -o recording.mp4<br />
<br />
Capture a video of a part of the screen:<br />
<br />
$ wf-recorder -g "$(slurp)"<br />
<br />
Example of usage with {{Pkg|grim}}, {{Pkg|slurp}} and {{Pkg|wl-clipboard}}, screenshot directly with Print button to clipboard. <br />
{{hc|~/.config/sway/config|<br />
<nowiki>bindsym --release Print exec grim -g \"$(slurp)" - | wl-copy</nowiki><br />
}}<br />
<br />
== Troubleshooting ==<br />
<br />
=== Application launchers ===<br />
<br />
i3-dmenu-desktop, {{Pkg|dmenu}}, and {{Pkg|rofi}} all function relatively well in Sway, but all run under XWayland and suffer from the same issue where they can become unresponsive if the cursor is moved to a native Wayland window. The reason for this issue is that Wayland clients/windows do not have access to input devices unless they have focus of the screen. The XWayland server is itself a client to the Wayland compositor, so one of its XWayland clients must have focus for it to access user input. However, once one of its clients has focus, it can gather input and make it available to all XWayland clients through the X11 protocol. Hence, moving the cursor to an XWayland window and pressing Escape should fix the issue, and sometimes running {{ic|pkill}} does too.<br />
<br />
{{Pkg|bemenu}} is a native Wayland dmenu replacement which can optionally be combined with {{AUR|j4-dmenu-desktop}} to provide a Wayland-native combination for launching desktop files (as i3-dmenu-desktop does):<br />
<br />
j4-dmenu-desktop --dmenu='bemenu -i --nb "#3f3f3f" --nf "#dcdccc" --fn "pango:DejaVu Sans Mono 12"' --term='termite'<br />
<br />
You may need to set {{ic|BEMENU_BACKEND}} environment variable to "wayland" if you choose not to disable XWayland.<br />
<br />
You can also build your own with a floating terminal and fzf as discussed in a [https://github.com/swaywm/sway/issues/1367 GitHub issue].<br />
<br />
=== VirtualBox ===<br />
<br />
Sway doesn't work well (or at all) under [[VirtualBox]].<br />
<br />
=== Sway socket not detected ===<br />
<br />
Using a {{ic|swaymsg}} argument, such as {{ic|swaymsg -t get_outputs}}, will sometimes return the message:<br />
<br />
sway socket not detected.<br />
ERROR: Unable to connect to<br />
<br />
when run inside a terminal multiplexer (such as gnu screen or tmux). This means {{ic|swaymsg}} could not connect to the socket provided in your {{ic|SWAYSOCK}}.<br />
<br />
To view what the current value of {{ic|SWAYSOCK}} is, type:<br />
<br />
$ env | fgrep SWAYSOCK<br />
SWAYSOCK=/run/user/1000/sway-ipc.1000.4981.sock<br />
<br />
To work around this problem, you may try attaching to a socket based on the running sway process:<br />
<br />
$ export SWAYSOCK=/run/user/$(id -u)/sway-ipc.$(id -u).$(pgrep -x sway).sock<br />
<br />
To avoid this error, run the command outside of a multiplexer.<br />
<br />
=== Unable to retrieve socket path ===<br />
<br />
Requesting messages from {{ic|swaymsg -t}} on a tty may return the following message:<br />
<br />
Unable to retrieve socket path<br />
<br />
{{ic|SWAYSOCK}} environment variable is set after launching Sway, therefore a workaround to this error is to request {{ic|swaymsg -t [message]}} in a terminal inside Sway.<br />
<br />
== See also ==<br />
<br />
* [https://github.com/SirCmpwn/sway GitHub project]<br />
* [https://github.com/swaywm/sway/wiki Sway official wiki]<br />
* [https://git.sr.ht/~sircmpwn/sway sr.ht git page]<br />
* [https://swaywm.org Website]<br />
* [https://drewdevault.com/2019/03/11/Sway-1.0-released.html Announcing the release of sway 1.0]</div>Knaick