Sway: Difference between revisions

Phobos (talk | contribs)
mNo edit summary
Phobos (talk | contribs)
mNo edit summary
 
(7 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 28: Line 27:
}|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 the <code>foot</code> terminal, [[Swayidle]], [[Swaylock]], and <code>wmenu</code>, 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.  
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 94: Line 93:
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 [https://search.nixos.org/options?channel=unstable&show=services.greetd.settings&from=0&size=50&sort=relevance&type=packages&query=greetd greetd] is the most straightforward way to launch Sway.
Installing a greeter based on [[greetd]] is the most straightforward way to launch Sway.


Tuigreet does not even need a separate compositor to launch.
==== TUIGreet ====
Tuigreet is a simple and lightweight option that does not require a separate compositor to launch.


{{file|||<nowiki>
{{file|||<nowiki>
Line 110: Line 110:
};                                                                       
};                                                                       
</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 126:
     [[ "$(tty)" == /dev/tty1 ]] && sway
     [[ "$(tty)" == /dev/tty1 ]] && sway
'';
'';
</syntaxhighlight>When launched directly from the TTY sway won't inherit the user environment. This can 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>
</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"];
  wayland.windowManager.sway.systemd.variables = ["--all"];
</nowiki>}}
</nowiki>}}


== Configuration ==
== Configuration ==
Sway can be configured for specific users using Home-Manager or manually through configuration files. Default is <code>/etc/sway/config</code> and custom user configuration in <code>~/.config/sway/config</code>.
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 ===
Line 175: Line 179:
   };
   };
};|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]].
=== 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 337: Line 358:
</syntaxhighlight>
</syntaxhighlight>


=== Screen sharing with Firefox, Chromium ===
=== Screen sharing ===
<syntaxhighlight lang="nix">
{{File|3={ pkgs, ... }:
{ pkgs, ... }:
{
{
   # xdg portal + pipewire = screensharing
   # xdg portal + pipewire = screensharing
Line 351: Line 371:
     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.}}
</syntaxhighlight>
 
=== 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}}


=== Screen dimming with wl-gammarelay-rs ===
=== 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 programs.sway.extraPackages, then add the following to sway config:
<syntaxhighlight>
<syntaxhighlight>