Difference between revisions of "Sway"

From ArchWiki
Jump to navigation Jump to search
(Update application launchers section)
(Undo revision 587840 by Jyeno (talk) - the instructions were correct, binding Insert is a very bad example)
Tag: Undo
 
(72 intermediate revisions by 37 users not shown)
Line 2: Line 2:
 
[[Category:Dynamic WMs]]
 
[[Category:Dynamic WMs]]
 
[[ja:Sway]]
 
[[ja:Sway]]
''sway'' is a compositor for [[Wayland]] designed to be fully compatible with [[i3]]. According to [http://swaywm.org the official website]:
+
[[pt:Sway]]
:Sway is a drop-in replacement for the i3 window manager, but for Wayland instead of X11. It works with your existing i3 configuration and supports most of i3's features, and a few extras.
+
''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.
== Status ==
 
 
 
Sway is a work-in-progress so caution is advised. However, the project's creator, [https://drewdevault.com/ Drew DeVault] (aka SirCmpwn) has deemed it ready for regular use.
 
 
 
A detailed accounting of what features have been implemented and what features are still outstanding can be found at the following links:
 
*[https://github.com/SirCmpwn/sway/issues/2#issue-99897933 i3 feature support]
 
*[https://github.com/SirCmpwn/sway/issues/98 IPC feature support]
 
*[https://github.com/SirCmpwn/sway/issues/343 i3bar compatibility]
 
*[https://github.com/SirCmpwn/sway/issues/307 Airblader fork features]
 
  
 
== Installation ==
 
== Installation ==
  
''sway'' can be [[install]]ed with the {{Pkg|sway}} package. This will install the stable (but abandoned) ''0.15'' version which is based on the (also abandoned) [https://github.com/Cloudef/wlc wlc] library.
+
''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.
 
 
At the time of writing, ''sway 1.0-beta'' (based on the new [https://github.com/swaywm/wlroots wlroots] library) is under active development and quite stable.
 
Install the following two [[Arch User Repository]] packages instead: {{AUR|wlroots-git}} and {{AUR|sway-git}}.
 
  
It's advisable to always update ''wlroots'' when you update ''sway'', due to tight dependencies.
+
You may also install {{Pkg|swaylock}} and {{Pkg|swayidle}} to lock your screen and set up an idle manager.
  
 
== Starting ==
 
== Starting ==
Line 34: 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 44: Line 36:
 
=== Keymap ===
 
=== Keymap ===
  
By default, sway starts with the US QWERTY keymap. You can override this behaviour by starting sway with:
+
By default, sway starts with the US QWERTY keymap. To configure per-input:
  
$ export XKB_DEFAULT_LAYOUT=gb; export XKB_DEFAULT_VARIANT=colemak; export XKB_DEFAULT_MODEL=pc101; sway
+
{{hc|~/.config/sway/config|<nowiki>
 
+
input * xkb_layout "us,de,ru"
This will launch sway with the keyboard set to the Colemak variant of the British keymap with the 101-key keyboard model.
+
input * xkb_variant "colemak,,typewriter"
 
+
input * xkb_options "grp:win_space_toggle"
See [[alias]] to simplify starting from a tty and [[Desktop entries#Modify environment variables]] to start [[#From a display manager]].
+
  input "MANUFACTURER1 Keyboard" xkb_model "pc101"
 
+
input "MANUFACTURER2 Keyboard" xkb_model "jp106"
If none of the above worked, you could add:
+
</nowiki>}}
 
 
  export XKB_DEFAULT_LAYOUT=gb; export XKB_DEFAULT_VARIANT=colemak; export XKB_DEFAULT_MODEL=pc101
 
 
 
to either your {{ic|.bash_profile}} or {{ic|.zprofile}} (or similar).
 
 
 
If you want multiple keyboard layouts at startup edit {{ic|.bash_profile}} and add, for example US English and German layouts, switchable by {{ic|Mod+Space}}:
 
  
{{hc|~/.bash_profile|
+
More details are available in {{man|7|xkeyboard-config}} and {{man|5|sway-input}}.
<nowiki>if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then
 
  export XKB_DEFAULT_LAYOUT=us,de
 
  export XKB_DEFAULT_OPTIONS=grp:win_space_toggle
 
  exec sway
 
fi</nowiki>
 
}}
 
  
Another option for switching keyboard layout is {{ic|Alt}}+{{ic|Shift}}: {{ic|grp:alt_shift_toggle}}.
+
The keymap can also be configured using environment variables ({{ic|XKB_DEFAULT_LAYOUT}}, {{ic|XKB_DEFAULT_VARIANT}}, etc.) when starting sway.
  
 
=== Statusbar ===
 
=== Statusbar ===
  
Installing the program {{Pkg|i3status}} is an easy way to get a practical, default statusbar. All one has to do is add following snippet at the end of your sway config:
+
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:
  
 
{{hc|~/.config/sway/config|<nowiki>
 
{{hc|~/.config/sway/config|<nowiki>
Line 89: Line 69:
 
</nowiki>}}
 
</nowiki>}}
  
In both examples, the system-wide installed configuration files has been copied over to the user directory and then modified.
+
In both examples, the system-wide installed configuration files has been copied over to the user directory and then modified.  
 +
 
 +
{{Tip|{{Pkg|waybar}} is an alternative to the bar included with sway (swaybar).}}
  
 
=== 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 114: Line 98:
 
Where as the device identifier can be queried with:
 
Where as the device identifier can be queried with:
  
  swaymsg -t get_inputs
+
  $ swaymsg -t get_inputs
  
 
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.
 
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.
Line 122: Line 106:
 
=== HiDPI ===
 
=== HiDPI ===
  
Set your displays scale factor with the {{ic|output}} command in your config file. The scale factor must be an integer, and is usually 2 for HiDPI screens.
+
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.
  
 
  output <name> scale <factor>
 
  output <name> scale <factor>
Line 128: Line 112:
 
You can find your display name with the following command:
 
You can find your display name with the following command:
  
  swaymsg -t get_outputs
+
  $ swaymsg -t get_outputs
  
 
=== 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 $(pacmd list-sinks |awk '/* index:/{print $3}') +5%
+
bindsym XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ +5%
bindsym XF86AudioLowerVolume exec pactl set-sink-volume $(pacmd list-sinks |awk '/* index:/{print $3}') -5%
+
bindsym XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -5%
bindsym XF86AudioMute exec pactl set-sink-mute $(pacmd list-sinks |awk '/* index:/{print $3}') toggle
+
bindsym XF86AudioMute exec pactl set-sink-mute @DEFAULT_SINK@ toggle
bindsym XF86MonBrightnessDown exec brightnessctl set 5%-
+
bindsym XF86AudioMicMute exec pactl set-source-mute @DEFAULT_SOURCE@ toggle
bindsym XF86MonBrightnessUp exec brightnessctl set +5%
+
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
 
</nowiki>}}
 
</nowiki>}}
  
To control brightness you can use {{AUR|brightnessctl}}. 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 ===
  
 
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) ===
 +
 +
{{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:
 +
 +
{{hc|~/.config/sway/config|<nowiki>
 +
xwayland disable
 +
</nowiki>}}
 +
 +
{{ 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. }}
  
 
== Tips and tricks ==
 
== Tips and tricks ==
Line 174: Line 175:
 
     fi
 
     fi
  
== Known issues ==
+
=== Screen capture ===
 +
 
 +
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.
 +
 
 +
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 {{Pkg|grim}}, {{Pkg|slurp}} and {{Pkg|wl-clipboard}}, screenshot directly with Print button to clipboard.
 +
{{hc|~/.config/sway/config|
 +
<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}}.
 +
 
 +
== Troubleshooting ==
  
 
=== Application launchers ===
 
=== Application launchers ===
  
i3-dmenu-desktop, j4-dmenu-desktop, dmenu, and rofi all function relatively well in Sway, but all run under XWayland and suffer from the safe issue where they can become unresponsive if the cursor is moved to a native Wayland window. Moving the cursor to an XWayland window and pressing Escape should fix the issue, and sometimes running {{ic|pkill}} does too.
+
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.
 +
 
 +
{{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):
 +
 
 +
j4-dmenu-desktop --dmenu='bemenu -i --nb "#3f3f3f" --nf "#dcdccc" --fn "pango:DejaVu Sans Mono 12"' --term='termite'
  
One alternative is bemenu, which is a native Wayland dmenu replacement.
+
You may need to set {{ic|BEMENU_BACKEND}} environment variable to "wayland" if you choose not to disable XWayland.
  
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.
+
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].
  
 
=== VirtualBox ===
 
=== VirtualBox ===
Line 188: Line 254:
 
Sway doesn't work well (or at all) under [[VirtualBox]].
 
Sway doesn't work well (or at all) under [[VirtualBox]].
  
=== Sway Socket Not Detected ===
+
=== Sway socket not detected ===
  
 
Using a {{ic|swaymsg}} argument, such as {{ic|swaymsg -t get_outputs}}, will sometimes return the message:
 
Using a {{ic|swaymsg}} argument, such as {{ic|swaymsg -t get_outputs}}, will sometimes return the message:
Line 202: Line 268:
 
  SWAYSOCK=/run/user/1000/sway-ipc.1000.4981.sock
 
  SWAYSOCK=/run/user/1000/sway-ipc.1000.4981.sock
  
To work around this problem, you may try attaching to the first available sway socket, and retrying your command:
+
To work around this problem, you may try attaching to a socket based on the running sway process:
  
  $ export SWAYSOCK=$(ls /run/user/*/sway-ipc.*.sock | head -n 1)
+
  $ 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.
 
To avoid this error, run the command outside of a multiplexer.
  
=== Incorrect Monitor Resolution ===
+
=== Unable to retrieve socket path ===
 +
 
 +
Requesting messages from {{ic|swaymsg -t}} on a tty may return the following message:
 +
 
 +
Unable to retrieve socket path
 +
 
 +
{{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 ===
  
Config options such as {{ic|output "HDMI-A-1" res 1280x1024}} may not successfully change the resolution. The compositor {{Pkg|wlc}} is responsible for setting the resolution, and attempts to figure out monitor resolution from the TTY.
+
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.
  
You may be able to alter your TTY resolution (thus also altering the WLC and Sway resolution) by passing a kernel parameter such as {{ic|1=video=HDMI-A-1:1280x1024:e}} or with with custom edid binaries ([[Kernel_mode_setting|see Kernel Mode Setting]]).
+
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]
* [http://swaywm.org Website]
+
* [https://github.com/swaywm/sway/wiki Sway official wiki]
 +
* [https://git.sr.ht/~sircmpwn/sway sr.ht git page]
 +
* [https://swaywm.org Website]
 +
* [https://drewdevault.com/2019/03/11/Sway-1.0-released.html Announcing the release of sway 1.0]

Latest revision as of 17:00, 5 November 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"
 input "MANUFACTURER2 Keyboard" xkb_model "jp106"

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 in your Sway config:

#!/usr/bin/dash
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.

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.

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