Difference between revisions of "Sway"

From ArchWiki
Jump to navigation Jump to search
(→‎Statusbar: waybar is not the same as i3status)
(Undo revision 591072 by Aufkrawall (talk) - this has nothing to do with sway - see NetworkManager and Kwallet)
Tag: Undo
 
(33 intermediate revisions by 18 users not shown)
Line 2: Line 2:
 
[[Category:Dynamic WMs]]
 
[[Category:Dynamic WMs]]
 
[[ja:Sway]]
 
[[ja:Sway]]
 +
[[pt:Sway]]
 
''sway'' is a compositor for [[Wayland]] designed to be fully compatible with [[i3]]. According to [https://swaywm.org the official website]:
 
''sway'' is a compositor for [[Wayland]] designed to be fully compatible with [[i3]]. According to [https://swaywm.org the official website]:
 
: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.
 
: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.
Line 21: Line 22:
 
=== From a display manager ===
 
=== From a display manager ===
  
{{Note|Sway does not support display managers officially.}}
+
{{Note|Sway does not support display managers officially.[https://github.com/swaywm/sway/pull/3634#issuecomment-462779163]}}
  
 
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]].
 
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]].
 +
 +
It is also possible to start sway as a [https://github.com/swaywm/sway/wiki/Systemd-integration#running-sway-itself-as-a---user-service systemd user service] through the display manager.
 +
 +
Also you can use text-based session manager, see [[Display manager#Console]].
  
 
== Configuration ==
 
== Configuration ==
Line 34: Line 39:
  
 
{{hc|~/.config/sway/config|<nowiki>
 
{{hc|~/.config/sway/config|<nowiki>
  input * xkb_layout us,de,ru"
+
  input * xkb_layout "us,de,ru"
 
  input * xkb_variant "colemak,,typewriter"
 
  input * xkb_variant "colemak,,typewriter"
 
  input * xkb_options "grp:win_space_toggle"
 
  input * xkb_options "grp:win_space_toggle"
 
  input "MANUFACTURER1 Keyboard" xkb_model "pc101"
 
  input "MANUFACTURER1 Keyboard" xkb_model "pc101"
input "MANUFACTURER2 Keyboard" xkb_model "jp106"
 
 
</nowiki>}}
 
</nowiki>}}
  
Line 69: Line 73:
  
 
=== Wallpaper ===
 
=== Wallpaper ===
 +
 +
Since  release 1.1.1 the wallpaper part of the SwayWM project was moved to {{Pkg|swaybg}}, which is needed in order to run the output command.
  
 
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|"*"}}):
 
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|"*"}}):
  
 
{{hc|~/.config/sway/config|<nowiki>
 
{{hc|~/.config/sway/config|<nowiki>
  output "*" background /home/onny/pictures/fredwang_norway.jpg fill
+
  output "*" bg /home/onny/pictures/fredwang_norway.jpg fill
 
</nowiki>}}
 
</nowiki>}}
  
Line 109: Line 115:
 
=== Custom keybindings ===
 
=== Custom keybindings ===
  
[[Extra keyboard keys|Special keys]] on your keyboard can be used to execute commands, for example to control your volume or your monitor brightness:
+
[[Extra keyboard keys|Special keys]] on your keyboard can be used to execute commands, for example to control your volume, your monitor brightness or your media player:
  
 
{{hc|~/.config/sway/config|<nowiki>
 
{{hc|~/.config/sway/config|<nowiki>
bindsym XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ +5%
+
bindsym XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ +5%
bindsym XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -5%
+
bindsym XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -5%
bindsym XF86AudioMute exec pactl set-sink-mute @DEFAULT_SINK@ toggle
+
bindsym XF86AudioMute exec pactl set-sink-mute @DEFAULT_SINK@ toggle
bindsym XF86AudioMicMute exec pactl set-source-mute @DEFAULT_SOURCE@ toggle
+
bindsym XF86AudioMicMute exec pactl set-source-mute @DEFAULT_SOURCE@ toggle
bindsym XF86MonBrightnessDown exec brightnessctl set 5%-
+
bindsym XF86MonBrightnessDown exec brightnessctl set 5%-
bindsym XF86MonBrightnessUp exec brightnessctl set +5%
+
bindsym XF86MonBrightnessUp exec brightnessctl set +5%
 +
bindsym XF86AudioPlay exec playerctl play-pause
 +
bindsym XF86AudioNext exec playerctl next
 +
bindsym XF86AudioPrev exec playerctl previous
 
</nowiki>}}
 
</nowiki>}}
  
To control brightness you can use {{AUR|brightnessctl}} or {{Pkg|light}}. For a list of utilities to control brightness and color correction see [[Backlight]].
+
To control brightness you can use {{Pkg|brightnessctl}} or {{Pkg|light}}. For a list of utilities to control brightness and color correction see [[Backlight]].
  
 
=== Xresources ===
 
=== Xresources ===
Line 126: Line 135:
 
Copy {{ic|~/.Xresources}} to {{ic|~/.Xdefaults}} to use them in Sway.
 
Copy {{ic|~/.Xresources}} to {{ic|~/.Xdefaults}} to use them in Sway.
  
=== Run programs natively under Wayland (without Xwayland support) ===
+
=== Run programs natively under Wayland (without XWayland support) ===
  
 
{{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.}}
 
{{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.}}
  
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:
+
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:
  
 
{{hc|~/.config/sway/config|<nowiki>
 
{{hc|~/.config/sway/config|<nowiki>
Line 137: Line 146:
  
 
{{ 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. }}
 
{{ 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. }}
{{ Note| In a fresh Sway install, you need to change the default menu and terminal applications because they depend on Xwayland. }}
+
{{ Note| In a fresh Sway install, you need to change the default menu and terminal applications because they depend on XWayland. }}
  
 
== Tips and tricks ==
 
== Tips and tricks ==
Line 153: Line 162:
 
=== Backlight toggle ===
 
=== Backlight toggle ===
  
To turn off (and on) your displays with a key (e.g. {{ic|Pause}}) bind the following in your Sway {{ic|config}}:
+
To turn off (and on) your displays with a key (e.g. {{ic|Pause}}) bind the following script in your Sway {{ic|config}}:
  
#!/usr/bin/dash
+
{{bc|
read lcd < /tmp/lcd
+
#!/bin/sh
    if [ "$lcd" -eq "0" ]; then
+
read lcd < /tmp/lcd
        swaymsg "output * dpms on"
+
    if [ "$lcd" -eq "0" ]; then
        echo 1 > /tmp/lcd
+
        swaymsg "output * dpms on"
    else
+
        echo 1 > /tmp/lcd
        swaymsg "output * dpms off"
+
    else
        echo 0 > /tmp/lcd
+
        swaymsg "output * dpms off"
    fi
+
        echo 0 > /tmp/lcd
 +
    fi
 +
}}
  
 
=== Screen capture ===
 
=== Screen capture ===
Line 189: Line 200:
 
<nowiki>bindsym --release Print exec grim -g \"$(slurp)" - | wl-copy</nowiki>
 
<nowiki>bindsym --release Print exec grim -g \"$(slurp)" - | wl-copy</nowiki>
 
}}
 
}}
 +
 +
=== Control swaynag with the keyboard ===
 +
 +
Swaynag, the default warning/prompt program shipped with sway, only supports user interaction with the mouse. A helper program such as {{AUR|swaynagmode}} may be used to enable interaction via keyboard shortcuts.
 +
 +
Swaynagmode works by first launching swaynag, then listening for signals which trigger actions such as selecting the next button, dismissing the prompt, or accepting the selected button. These signals are sent by launching another instance of the swaynagmode script itself with a control argument, such as {{ic|swaynagmode --select right}} or {{ic|swaynagmode --confirm}}.
 +
 +
Swaynagmode by default triggers the sway mode {{ic|nag}} upon initialization, followed by {{ic|default}} on exit. This makes it easy to define keybindings in your sway configuration:
 +
 +
{{hc|~/.config/sway/config|
 +
set $nag exec swaynagmode
 +
mode "nag" {
 +
  bindsym {
 +
    Ctrl+d    mode "default"
 +
 +
    Ctrl+c    $nag --exit
 +
    q        $nag --exit
 +
    Escape    $nag --exit
 +
 +
    Return    $nag --confirm
 +
 +
    Tab      $nag --select prev
 +
    Shift+Tab $nag --select next
 +
 +
    Left      $nag --select next
 +
    Right    $nag --select prev
 +
 +
    Up        $nag --select next
 +
    Down      $nag --select prev
 +
  }
 +
}
 +
}}
 +
 +
Note that, beginning in sway version 1.2, mode names are case-sensitive.
 +
 +
You can configure sway to use swaynagmode with the configuration command {{ic|swaynag_command swaynagmode}}.
 +
 +
=== Change cursor theme and size ===
 +
 +
To set the [[cursor theme]] and size:
 +
 +
{{hc|~/.config/sway/config|
 +
seat seat0 xcursor_theme ''my_cursor_theme'' ''my_cursor_size''
 +
}}
 +
 +
Where {{ic|''my_cursor_theme''}} can be set to or replaced by a specific value like {{ic|default}}, {{ic|Adwaita}} or {{ic|Simple-and-Soft}}, and {{ic|''my_cursor_size''}} a value like {{ic|48}}.
 +
 +
You can inspect their values with {{ic|echo $XCURSOR_SIZE}} and {{ic|echo $XCURSOR_THEME}}.
 +
 +
Note that you need to restart the application to see the changes.
 +
 +
{{Note|Wayland uses client-side cursors. It's possible that applications do not evaluate the values of {{ic|$XCURSOR_SIZE}} and {{ic|$XCURSOR_THEME}}.}}
  
 
== Troubleshooting ==
 
== Troubleshooting ==
Line 203: Line 266:
  
 
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].
 
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].
 +
 +
Also {{ic|krunner}} binary provided by {{Pkg|plasma-workspace}} package can serve as launcher, offering both XWayland and native Wayland support.
  
 
=== VirtualBox ===
 
=== VirtualBox ===
Line 235: Line 300:
  
 
{{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.
 
{{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.
 +
 +
=== Keybindings and keyboard layouts ===
 +
 +
By default, if you are using more than one keyboard layout, e.g. {{ic|<nowiki>input * xkb_layout "us,ru"</nowiki>}}, bindings may become broken when you switch on some secondary layout.
 +
 +
Thanks to https://github.com/swaywm/sway/pull/3058, all you need is to add {{ic|--to-code}} key to sensitive {{ic|bindsym}} lines like this:
 +
{{bc|<nowiki>
 +
bindsym --to-code {
 +
  $mod+$left focus left
 +
  $mod+$down focus down
 +
  $mod+$up focus up
 +
  $mod+$right focus right
 +
}</nowiki>
 +
}}
 +
 +
=== Java applications ===
 +
 +
Some Java-based applications will display blank screen when opened, for example any Intellij editor. To mitigate this, the application can be started with the {{ic|_JAVA_AWT_WM_NONREPARENTING}} environment variable set to 1.
 +
 +
If you start the application from a launcher like {{Pkg|rofi}} or {{Pkg|dmenu}}, you might want to modify the application desktop entry as shown in [[Desktop entries#Modify environment variables]].
  
 
== See also ==
 
== See also ==
  
* [https://github.com/SirCmpwn/sway GitHub project]
+
* [https://github.com/swaywm/sway GitHub project]
 
* [https://github.com/swaywm/sway/wiki Sway official wiki]
 
* [https://github.com/swaywm/sway/wiki Sway official wiki]
 
* [https://git.sr.ht/~sircmpwn/sway sr.ht git page]
 
* [https://git.sr.ht/~sircmpwn/sway sr.ht git page]
 
* [https://swaywm.org Website]
 
* [https://swaywm.org Website]
 
* [https://drewdevault.com/2019/03/11/Sway-1.0-released.html Announcing the release of sway 1.0]
 
* [https://drewdevault.com/2019/03/11/Sway-1.0-released.html Announcing the release of sway 1.0]

Latest revision as of 14:42, 7 December 2019

sway is a compositor for Wayland designed to be fully compatible with i3. According to the official website:

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.

Installation

sway can be installed with the sway package. The development version can be installed using wlroots-gitAUR and sway-gitAUR. It's advisable to always update wlroots when you update sway, due to tight dependencies.

You may also install swaylock and swayidle to lock your screen and set up an idle manager.

Starting

Tip: See Wayland#GUI libraries for appropriate environment variables to set for window decoration libraries.

From a TTY

To start Sway, simply type sway from a TTY.

From a display manager

Note: Sway does not support display managers officially.[1]

The sway session is located at /usr/share/wayland-sessions/sway.desktop. It is automatically recognized by modern display managers like GDM and SDDM.

It is also possible to start sway as a systemd user service through the display manager.

Also you can use text-based session manager, see Display manager#Console.

Configuration

If you already use i3, then copy your i3 configuration to ~/.config/sway/config and it should work out of the box. Otherwise, copy the sample configuration file to ~/.config/sway/config. It is located at /etc/sway/config, unless the DFALLBACK_CONFIG_DIR flag has been set. See sway(5) for information on the configuration.

Keymap

By default, sway starts with the US QWERTY keymap. To configure per-input:

~/.config/sway/config
 input * xkb_layout "us,de,ru"
 input * xkb_variant "colemak,,typewriter"
 input * xkb_options "grp:win_space_toggle"
 input "MANUFACTURER1 Keyboard" xkb_model "pc101"

More details are available in xkeyboard-config(7) and sway-input(5).

The keymap can also be configured using environment variables (XKB_DEFAULT_LAYOUT, XKB_DEFAULT_VARIANT, etc.) when starting sway.

Statusbar

Installing the program 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:

~/.config/sway/config
 bar {
  status_command i3status
 }

If you want to achieve colored output of i3status, you can adjust following part in the i3status configuration:

~/.config/i3status/config
general {
        colors = true
        interval = 5
}

In both examples, the system-wide installed configuration files has been copied over to the user directory and then modified.

Tip: waybar is an alternative to the bar included with sway (swaybar).

Wallpaper

Since release 1.1.1 the wallpaper part of the SwayWM project was moved to swaybg, which is needed in order to run the output command.

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 "*"):

~/.config/sway/config
 output "*" bg /home/onny/pictures/fredwang_norway.jpg fill

Of course you have to replace the file name and path according to your wallpaper.

Input devices

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:

~/.config/sway/config
input "2:14:ETPS/2_Elantech_Touchpad" {
    tap enabled
    natural_scroll enabled
}

Where as the device identifier can be queried with:

$ swaymsg -t get_inputs

The output from the command, sometimes has a "\" to escape symbols like "/" (ie "2:14:ETPS\/2_Elantech_Touchpad") and it needs to be removed.

More documentation and options like acceleration profiles can be found in sway-input(5).

HiDPI

Set your displays scale factor with the output command in your config file. The scale factor can be fractional, but it is usually 2 for HiDPI screens.

output <name> scale <factor>

You can find your display name with the following command:

$ swaymsg -t get_outputs

Custom keybindings

Special keys on your keyboard can be used to execute commands, for example to control your volume, your monitor brightness or your media player:

~/.config/sway/config
bindsym XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ +5%
bindsym XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -5%
bindsym XF86AudioMute exec pactl set-sink-mute @DEFAULT_SINK@ toggle
bindsym XF86AudioMicMute exec pactl set-source-mute @DEFAULT_SOURCE@ toggle
bindsym XF86MonBrightnessDown exec brightnessctl set 5%-
bindsym XF86MonBrightnessUp exec brightnessctl set +5%
bindsym XF86AudioPlay exec playerctl play-pause
bindsym XF86AudioNext exec playerctl next
bindsym XF86AudioPrev exec playerctl previous

To control brightness you can use brightnessctl or light. For a list of utilities to control brightness and color correction see Backlight.

Xresources

Copy ~/.Xresources to ~/.Xdefaults to use them in Sway.

Run programs natively under Wayland (without XWayland support)

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: xwayland disable is not necessary to run programs natively under Wayland, configuring the GUI libraries appropriately is enough. Keeping XWayland enabled is good for programs that don't work otherwise. (Discuss in Talk:Sway#)

First, be sure the toolkit or library of every program that is and will be installed support Wayland. Then append the following line to your sway configuration file to disable XWayland support:

~/.config/sway/config
xwayland disable
Note: Some programs, like Firefox, bemenu or Qt5 based programs, also need specific environment variables set for them to run natively under Wayland.
Note: In a fresh Sway install, you need to change the default menu and terminal applications because they depend on XWayland.

Tips and tricks

Autostart on login

To start sway from tty1 on login with default US keyboard, edit:

~/.bash_profile
if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then
  XKB_DEFAULT_LAYOUT=us exec sway
fi

Backlight toggle

To turn off (and on) your displays with a key (e.g. Pause) bind the following script in your Sway config:

#!/bin/sh
read lcd < /tmp/lcd
    if [ "$lcd" -eq "0" ]; then
        swaymsg "output * dpms on"
        echo 1 > /tmp/lcd
    else
        swaymsg "output * dpms off"
        echo 0 > /tmp/lcd
    fi

Screen capture

Capturing the screen can be done using grim or swayshotAUR for screenshots and wf-recorder-gitAUR for video. Optionally, slurp can be used to select the part of the screen to capture.

Take a screenshot of the whole screen:

$ grim screenshot.png

Take a screenshot of a part of the screen:

$ grim -g "$(slurp)" screenshot.png

Capture a video of the whole screen:

$ wf-recorder -o recording.mp4

Capture a video of a part of the screen:

$ wf-recorder -g "$(slurp)"

Example of usage with grim, slurp and wl-clipboard, screenshot directly with Print button to clipboard.

~/.config/sway/config
bindsym --release Print exec grim -g \"$(slurp)" - | wl-copy

Control swaynag with the keyboard

Swaynag, the default warning/prompt program shipped with sway, only supports user interaction with the mouse. A helper program such as swaynagmodeAUR may be used to enable interaction via keyboard shortcuts.

Swaynagmode works by first launching swaynag, then listening for signals which trigger actions such as selecting the next button, dismissing the prompt, or accepting the selected button. These signals are sent by launching another instance of the swaynagmode script itself with a control argument, such as swaynagmode --select right or swaynagmode --confirm.

Swaynagmode by default triggers the sway mode nag upon initialization, followed by default on exit. This makes it easy to define keybindings in your sway configuration:

~/.config/sway/config
set $nag exec swaynagmode
mode "nag" {
  bindsym {
    Ctrl+d    mode "default"

    Ctrl+c    $nag --exit
    q         $nag --exit
    Escape    $nag --exit

    Return    $nag --confirm

    Tab       $nag --select prev
    Shift+Tab $nag --select next

    Left      $nag --select next
    Right     $nag --select prev

    Up        $nag --select next
    Down      $nag --select prev
  }
}

Note that, beginning in sway version 1.2, mode names are case-sensitive.

You can configure sway to use swaynagmode with the configuration command swaynag_command swaynagmode.

Change cursor theme and size

To set the cursor theme and size:

~/.config/sway/config
seat seat0 xcursor_theme my_cursor_theme my_cursor_size

Where my_cursor_theme can be set to or replaced by a specific value like default, Adwaita or Simple-and-Soft, and my_cursor_size a value like 48.

You can inspect their values with echo $XCURSOR_SIZE and echo $XCURSOR_THEME.

Note that you need to restart the application to see the changes.

Note: Wayland uses client-side cursors. It's possible that applications do not evaluate the values of $XCURSOR_SIZE and $XCURSOR_THEME.

Troubleshooting

Application launchers

i3-dmenu-desktop, dmenu, and 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 pkill does too.

bemenu is a native Wayland dmenu replacement which can optionally be combined with j4-dmenu-desktopAUR to provide a Wayland-native combination for launching desktop files (as i3-dmenu-desktop does):

j4-dmenu-desktop --dmenu='bemenu -i --nb "#3f3f3f" --nf "#dcdccc" --fn "pango:DejaVu Sans Mono 12"' --term='termite'

You may need to set BEMENU_BACKEND environment variable to "wayland" if you choose not to disable XWayland.

You can also build your own with a floating terminal and fzf as discussed in a GitHub issue.

Also krunner binary provided by plasma-workspace package can serve as launcher, offering both XWayland and native Wayland support.

VirtualBox

Sway doesn't work well (or at all) under VirtualBox.

Sway socket not detected

Using a swaymsg argument, such as swaymsg -t get_outputs, will sometimes return the message:

sway socket not detected.
ERROR: Unable to connect to

when run inside a terminal multiplexer (such as gnu screen or tmux). This means swaymsg could not connect to the socket provided in your SWAYSOCK.

To view what the current value of SWAYSOCK is, type:

$ env | fgrep SWAYSOCK
SWAYSOCK=/run/user/1000/sway-ipc.1000.4981.sock

To work around this problem, you may try attaching to a socket based on the running sway process:

$ export SWAYSOCK=/run/user/$(id -u)/sway-ipc.$(id -u).$(pgrep -x sway).sock

To avoid this error, run the command outside of a multiplexer.

Unable to retrieve socket path

Requesting messages from swaymsg -t on a tty may return the following message:

Unable to retrieve socket path

SWAYSOCK environment variable is set after launching Sway, therefore a workaround to this error is to request swaymsg -t [message] in a terminal inside Sway.

Keybindings and keyboard layouts

By default, if you are using more than one keyboard layout, e.g. input * xkb_layout "us,ru", bindings may become broken when you switch on some secondary layout.

Thanks to https://github.com/swaywm/sway/pull/3058, all you need is to add --to-code key to sensitive bindsym lines like this:

bindsym --to-code {
  $mod+$left focus left
  $mod+$down focus down
  $mod+$up focus up
  $mod+$right focus right
}

Java applications

Some Java-based applications will display blank screen when opened, for example any Intellij editor. To mitigate this, the application can be started with the _JAVA_AWT_WM_NONREPARENTING environment variable set to 1.

If you start the application from a launcher like rofi or dmenu, you might want to modify the application desktop entry as shown in Desktop entries#Modify environment variables.

See also