Sway: Difference between revisions
mNo edit summary |
style fixes |
||
| (14 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
Sway is a tiling Wayland compositor and a drop-in replacement for the i3 window manager for X11. It can work with an existing i3 configuration and supports most of i3's features, plus a few extras. | [https://swaywm.org/ Sway] is a tiling [[Wayland]] compositor and a drop-in replacement for the [[i3]] window manager for X11. It can work with an existing i3 configuration and supports most of i3's features, plus a few extras. For users migrating from i3, see the [https://github.com/swaywm/sway/wiki/i3-Migration-Guide i3 migration guide]. | ||
[https://github.com/swaywm/sway/wiki/i3-Migration-Guide i3 migration guide] | |||
== Setup == | == Setup == | ||
| Line 11: | Line 10: | ||
{ | { | ||
environment.systemPackages = with pkgs; [ | environment.systemPackages = with pkgs; [ | ||
wl-clipboard # Copy/Paste functionality. | |||
mako # Notification utility. | |||
wl-clipboard # | |||
mako # | |||
]; | ]; | ||
# | # Enables Gnome Keyring to store secrets for applications. | ||
services.gnome.gnome-keyring.enable = true; | services.gnome.gnome-keyring.enable = true; | ||
# | # Enable Sway. | ||
programs.sway = { | programs.sway = { | ||
enable = true; | enable = true; | ||
| Line 28: | Line 24: | ||
}|name=/etc/nixos/configuration.nix|lang=nix}} | }|name=/etc/nixos/configuration.nix|lang=nix}} | ||
By default, the Sway module in NixOS comes with a set of extra packages, including | By default, the Sway module in NixOS comes with a set of extra packages, including [https://codeberg.org/dnkl/foot/ Foot] terminal, [[Swayidle]], [[Swaylock]], and [https://codeberg.org/adnano/wmenu/ wmenu], which may be configured under the <code>[https://search.nixos.org/options?show=programs.sway.extraPackages programs.sway.extraPackages]</code> option. You may also want to include <code>wl-clipboard</code> for clipboard functionality, as well as a screenshot utility such as [https://github.com/emersion/slurp Slurp] or [[Flameshot]] for screenshot region selection. | ||
Additionally, for a more customizable bar implementation than <code>sway-bar</code>, [[Waybar]] may be enabled with <code>programs.waybar.enable</code>. | Additionally, for a more customizable bar implementation than <code>sway-bar</code>, [[Waybar]] may be enabled with <code>programs.waybar.enable</code>. | ||
| Line 46: | Line 42: | ||
Then you may enable Sway in your Home Manager configuration. Here is a minimal example: | Then you may enable Sway in your Home Manager configuration. Here is a minimal example: | ||
{{File|3=wayland.windowManager.sway = { | {{File|3= | ||
wayland.windowManager.sway = { | |||
enable = true; | |||
wrapperFeatures.gtk = true; # Fixes common issues with GTK 3 apps | |||
config = rec { | |||
modifier = "Mod4"; | |||
# Use kitty as default terminal | |||
terminal = "kitty"; | |||
startup = [ | |||
# Launch Firefox on start | |||
{ command = "firefox"; } | |||
]; | |||
}; | |||
}; | |||
|name=/etc/nixos/home.nix|lang=nix}} | |||
See [https://nix-community.github.io/home-manager/options.xhtml#opt-wayland.windowManager.sway.enable Home Manager's Options for Sway] for a complete list of configuration options. | See [https://nix-community.github.io/home-manager/options.xhtml#opt-wayland.windowManager.sway.enable Home Manager's Options for Sway] for a complete list of configuration options. | ||
You may need to activate dbus manually from .zshrc to use i.e: dunst, see [https://discourse.nixos.org/t/dunst-crashes-if-run-as-service/27671/2 Dunst crashes if run as service] | You may need to activate dbus manually from .zshrc to use i.e: dunst, see [https://discourse.nixos.org/t/dunst-crashes-if-run-as-service/27671/2 Dunst crashes if run as service] | ||
=== Systemd services === | === Systemd services === | ||
Kanshi is an output configuration daemon. As explained above, we don't run Sway itself as a systemd service. There are auxiliary daemons that we do want to run as systemd services, for example Kanshi [https://gitlab.freedesktop.org/emersion/kanshi], which implements monitor hot swapping. It would be enabled as follows: | Kanshi is an output configuration daemon. As explained above, we don't run Sway itself as a systemd service. There are auxiliary daemons that we do want to run as systemd services, for example Kanshi [https://gitlab.freedesktop.org/emersion/kanshi], which implements monitor hot swapping. It would be enabled as follows: | ||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
# kanshi systemd service | |||
systemd.user.services.kanshi = { | |||
description = "kanshi daemon"; | |||
environment = { | |||
WAYLAND_DISPLAY="wayland-1"; | |||
DISPLAY = ":0"; | |||
}; | |||
serviceConfig = { | |||
Type = "simple"; | |||
ExecStart = ''${pkgs.kanshi}/bin/kanshi -c kanshi_config_file''; | |||
}; | }; | ||
}; | |||
</nowiki>}} | </nowiki>}} | ||
| Line 94: | Line 85: | ||
When you launch Sway, the systemd service is started. | When you launch Sway, the systemd service is started. | ||
=== Using greeter === | === Using a greeter === | ||
Installing a greeter based on [ | Installing a greeter based on [[greetd]] is the most straightforward way to launch Sway. | ||
Tuigreet does not | ==== TUIGreet ==== | ||
Tuigreet is a simple and lightweight option that does not require a separate compositor to launch. | |||
{{file|||<nowiki> | {{file|||<nowiki> | ||
| Line 110: | Line 102: | ||
}; | }; | ||
</nowiki>|name=/etc/nixos/configuration.nix|lang=nix}} | </nowiki>|name=/etc/nixos/configuration.nix|lang=nix}} | ||
==== Regreet ==== | |||
[https://github.com/rharish101/ReGreet Regreet] is a clean and customizable GTK-based greeter written in Rust. It will automatically find Sway and remembers the last picked option. Additional configuration options may be found under [https://search.nixos.org/options?&query=regreet programs.regreet]. | |||
{{File|3=programs.regreet.enable = true;|name=/etc/nixos/configuration.nix|lang=nix}} | |||
=== Automatic startup on boot === | === Automatic startup on boot === | ||
The snippet below will start Sway immediately on startup, without a greeter and '''without login prompt'''. Only consider using this in conjunction with [[Full Disk Encryption]] | The snippet below will start Sway immediately on startup, without a greeter and '''without a login prompt'''. Only consider using this in conjunction with [[Full Disk Encryption]]. | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
| Line 122: | Line 118: | ||
[[ "$(tty)" == /dev/tty1 ]] && sway | [[ "$(tty)" == /dev/tty1 ]] && sway | ||
''; | ''; | ||
</syntaxhighlight>When launched directly from the TTY | </syntaxhighlight>When launched directly from the TTY, Sway will not inherit the user environment. This may cause issues with systemd user services such as application launchers or [[Swayidle]]. To fix this, add the following to your Home Manager configuration:{{file|home.nix|nix|<nowiki> | ||
wayland.windowManager.sway.systemd.variables = ["--all"]; | |||
</nowiki>}} | </nowiki>}} | ||
=== Secret Service === | |||
It is recommended to enable a secret service provider such as [https://wiki.gnome.org/Projects/GnomeKeyring Gnome Keyring]. For more information on secret services check the [[Secret Service]] page. | |||
Install and enable: | |||
{{File|3=services.gnome.gnome-keyring.enable = true;|name=/etc/nixos/configuration.nix|lang=nix}} | |||
In order to unlock the keyring through logins from greeters and screen locking utilities you will need to enable them through PAM. | |||
{{File|3=security.pam.services = { | |||
greetd.enableGnomeKeyring = true; | |||
swaylock.enableGnomeKeyring = true; | |||
# If using a display manager such as GDM | |||
#gdm.enableGnomeKeyring = true; | |||
};|name=/etc/nixos/configuration.nix|lang=nix}} | |||
== Configuration == | == Configuration == | ||
Sway | Sway may be configured for specific users using Home Manager or manually through configuration files. The default location is <code>/etc/sway/config</code>, and custom user configuration in <code>~/.config/sway/config</code>. | ||
=== Keyboard layout === | === Keyboard layout === | ||
Changing layout for all keyboards to German (de):<syntaxhighlight | Changing layout for all keyboards to German (de): | ||
<syntaxhighlight> | |||
input * xkb_layout "de" | input * xkb_layout "de" | ||
</syntaxhighlight>The same thing accomplished in Home Manager:<syntaxhighlight lang="nix"> | </syntaxhighlight>The same thing accomplished in Home Manager:<syntaxhighlight lang="nix"> | ||
| Line 137: | Line 148: | ||
=== High-DPI scaling === | === High-DPI scaling === | ||
Changing scale for all screens to factor 1.5:<syntaxhighlight | Changing scale for all screens to factor 1.5:<syntaxhighlight> | ||
output * scale 1.5 | output * scale 1.5 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 175: | Line 186: | ||
}; | }; | ||
};|name=/etc/nixos/home.nix|lang=nix}}For an on screen display for audio and brightness, check [[swayosd]]. | };|name=/etc/nixos/home.nix|lang=nix}}For an on screen display for audio and brightness, check [[swayosd]]. | ||
=== Input === | |||
==== Touchpad ==== | |||
See the [https://www.mankier.com/5/sway-input sway-input man page] for options. | |||
{{File|3= | |||
wayland.windowManager.sway = { | |||
enable = true; | |||
config.input = { | |||
"type:touchpad" = { | |||
# Enables or disables tap for specified input device. | |||
tap = "enabled"; | |||
# Enables or disables natural (inverted) scrolling for the specified input device. | |||
natural_scroll = "enabled"; | |||
# Enables or disables disable-while-typing for the specified input device. | |||
dwt = "enabled"; | |||
}; | |||
}; | |||
}; | |||
|name=/etc/nixos/home.nix|lang=nix}} | |||
== Troubleshooting == | == Troubleshooting == | ||
| Line 199: | Line 230: | ||
{{File|3=home.pointerCursor = { | {{File|3=home.pointerCursor = { | ||
name = "Adwaita"; | |||
package = pkgs.adwaita-icon-theme; | |||
size = 24; | |||
x11 = { | |||
enable = true; | |||
defaultCursor = "Adwaita"; | |||
}; | |||
sway.enable = true; | |||
};|name=/etc/nixos/home.nix|lang=nix}} | };|name=/etc/nixos/home.nix|lang=nix}} | ||
| Line 216: | Line 246: | ||
<syntaxhighlight lang="nix> | <syntaxhighlight lang="nix> | ||
fonts = { | |||
packages = with pkgs; [ | |||
noto-fonts | |||
noto-fonts-cjk | |||
noto-fonts-emoji | |||
font-awesome | |||
source-han-sans | |||
source-han-sans-japanese | |||
source-han-serif-japanese | |||
]; | |||
fontconfig.defaultFonts = { | |||
serif = [ "Noto Serif" "Source Han Serif" ]; | |||
sansSerif = [ "Noto Sans" "Source Han Sans" ]; | |||
}; | }; | ||
}; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 240: | Line 268: | ||
<syntaxhighlight lang="nix> | <syntaxhighlight lang="nix> | ||
security.pam.services.swaylock = {}; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 277: | Line 305: | ||
Using [[Home Manager]] add the following to your Sway configuration: | Using [[Home Manager]] add the following to your Sway configuration: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
wayland.windowManager.sway = { | |||
[...] | |||
config = { | |||
[...] | |||
input = { | |||
[...] | |||
"type:touch" = { | |||
# Replace touchscreen_output_identifier with the identifier of your touchscreen. | |||
map_to_output = touchscreen_output_identifier; | |||
}; | |||
}; | |||
}; | |||
}; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 337: | Line 365: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== | === Screenshots === | ||
Screenshots using grim, slurp, and [https://github.com/XodTech/grimshot grimshot] for selection screenshots/full screen screenshots. | |||
{ pkgs, ... }: | |||
Install tools | |||
{{File|3=environment.systemPackages = with pkgs; [ | |||
grim | |||
slurp | |||
sway-contrib.grimshot | |||
];|name=/etc/nixos/configuration.nix|lang=nix}} | |||
Example Home Manager configuration. | |||
{{File|3=wayland.windowManager.sway = { | |||
enable = true; | |||
config = let | |||
modifier = config.wayland.windowManager.sway.config.modifier; | |||
in { | |||
modifier = "Mod4"; | |||
keybindings = lib.mkOptionDefault { | |||
# Super + Shift + S | |||
# Screenshot a selection that saves to ~/Screenshots and copies to clipboard. | |||
"${modifier}+Shift+s" = "exec selection=$(slurp) && grim -g \"$selection\" - {{!}} tee ~/Screenshots/$(date +%Y-%m-%d_%H-%M-%S).png {{!}} wl-copy"; | |||
# Print Screen Button | |||
# Screenshot the currently focused screen, save to ~/Screenshots and copy to clipboard. | |||
"Print" = "exec grimshot save output - {{!}} tee ~/Screenshots/$(date +%Y-%m-%d_%H-%M-%S).png {{!}} wl-copy"; | |||
}; | |||
}; | |||
};|name=/etc/nixos/home.nix|lang=nix}} | |||
=== Screen sharing === | |||
{{File|3={ pkgs, ... }: | |||
{ | { | ||
# xdg portal + pipewire = screensharing | # xdg portal + pipewire = screensharing | ||
| Line 351: | Line 408: | ||
pulse.enable = true; | pulse.enable = true; | ||
}; | }; | ||
} | }|name=/etc/nixos/configuration.nix|lang=nix}}{{Tip|Make sure that you do not have conflicting definitions for xdg.portal in Home Manager.}} | ||
=== Auto mounting === | |||
==== USB storage devices (e.g. Flash Drives) ==== | |||
You can use [https://github.com/coldfix/udiskie udiskie] to automatically mount external storage medias. | |||
You will need to install and enable [https://www.freedesktop.org/wiki/Software/udisks/ udisks2]. | |||
{{File|3=services.udisks2.enable = true;|name=/etc/nixos/configuration.nix|lang=nix}} | |||
Then, in Home Manager you can enable udiskie. | |||
{{File|3=services.udiskie.enable = true;|name=/etc/nixos/home.nix|lang=nix}} | |||
Udiskie will automatically mount attached USB storage media. | |||
See related info on [[USB storage devices]]. | |||
==== MTP (Android Phone Storage) ==== | |||
File managers that support [https://wiki.gnome.org/Projects/gvfs GVfs], such as [[Thunar]], can mount MTP devices using GVfs. See the page on [[MTP]] for related information. | |||
{{File|3=services.gvfs.enable = true;|name=/etc/nixos/configuration.nix|lang=nix}} | |||
=== SwayFX === | |||
[https://github.com/WillPower3309/swayfx SwayFX] is a fork of Sway that adds eye-candy effects, installing it is as simple as replacing your Sway package with SwayFX. Check the [[SwayFX]] page on the wiki for additional details. | |||
{{File|3=wayland.windowManager.sway = { | |||
enable = true; | |||
package = pkgs.swayfx; | |||
# Needed to build without errors. | |||
checkConfig = false; | |||
# SwayFX options must be configured through extraConfig. | |||
extraConfig = '' | |||
shadows enable | |||
corner_radius 11 | |||
blur_radius 7 | |||
blur_passes 2 | |||
''; | |||
};|name=/etc/nixos/home.nix|lang=nix}} | |||
=== Screen dimming with | === Screen dimming with wl-gammarelay-rs === | ||
Add <code>wl-gammarelay-rs</code> to programs.sway.extraPackages, then add the following to sway config: | Add <code>wl-gammarelay-rs</code> to <code>programs.sway.extraPackages</code>, then add the following to sway config: | ||
<syntaxhighlight> | <syntaxhighlight> | ||
# start daemon | # start daemon | ||