Sway: Difference between revisions

add instructions on how to fix issues with systemd user services not getting the environment
Arnecc (talk | contribs)
No edit summary
 
(3 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 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 can work with an existing i3 configuration and supports most of i3's features, plus a few extras.  
[https://github.com/swaywm/sway/wiki/i3-Migration-Guide i3 migration guide]
[https://github.com/swaywm/sway/wiki/i3-Migration-Guide i3 migration guide]


Line 7: Line 7:
=== Using NixOS ===
=== Using NixOS ===
Here is a minimal configuration:
Here is a minimal configuration:
<syntaxhighlight lang="nix">
 
{ config, pkgs, lib, ... }:
{{File|3={ config, pkgs, lib, ... }:
{
{
   environment.systemPackages = with pkgs; [
   environment.systemPackages = with pkgs; [
Line 26: Line 26:
     wrapperFeatures.gtk = true;
     wrapperFeatures.gtk = true;
   };
   };
}
}|name=/etc/nixos/configuration.nix|lang=nix}}
</syntaxhighlight>By default, the Sway module in NixOS comes with a set of extra packages, including the <code>foot</code> terminal, <code>swayidle</code>, <code>swaylock</code>, and <code>wmenu</code>, which can be configured under  <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 and <code>slurp</code> for screenshot region selection. Additionally, for a more customizable bar implementation than <code>sway-bar</code>, <code>waybar</code> can be enabled with <code>programs.waybar.enable</code>.
 
By default, the Sway module in NixOS comes with a set of extra packages, including the <code>foot</code> terminal, <code>swayidle</code>, <code>swaylock</code>, and <code>wmenu</code>, which can be configured under  <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 and <code>slurp</code> for screenshot region selection. Additionally, for a more customizable bar implementation than <code>sway-bar</code>, <code>waybar</code> can be enabled with <code>programs.waybar.enable</code>.


The default Sway configuration is symlinked to <code>/etc/sway/config</code> and <code>/etc/sway/config.d/nixos.conf</code>. The latter file contains dbus and systemd configuration that is critical to using apps that depend on XDG desktop portals with Sway, and should be included in any custom configuration files.
The default Sway configuration is symlinked to <code>/etc/sway/config</code> and <code>/etc/sway/config.d/nixos.conf</code>. The latter file contains dbus and systemd configuration that is critical to using apps that depend on XDG desktop portals with Sway, and should be included in any custom configuration files.
Line 42: Line 43:
   
   
Then you can enable Sway in your home manager configuration. Here is a minimal example:
Then you can enable Sway in your home manager configuration. Here is a minimal example:
<syntaxhighlight lang="nix>
 
  wayland.windowManager.sway = {
{{File|3=wayland.windowManager.sway = {
     enable = true;
     enable = true;
     wrapperFeatures.gtk = true; # Fixes common issues with GTK 3 apps
     wrapperFeatures.gtk = true; # Fixes common issues with GTK 3 apps
Line 55: Line 56:
       ];
       ];
     };
     };
   };
   };|name=/etc/nixos/home.nix|lang=nix}}
</syntaxhighlight>


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 might need to active 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]


{{Note|
{{Note|
Line 253: Line 253:
hardware.graphics.enable = true;
hardware.graphics.enable = true;
</syntaxhighlight>
</syntaxhighlight>
=== Systemd user services missing environment variables (PATH, etc) ===
When sway is launched with out display manager systemd won't inherit the users environment variables. To fix this add the following to your home-manager configuration:
{{File|3=wayland.windowManager.sway.systemd.variables = ["--all"];|name=home.nix|lang=nix}}


=== Touchscreen input bound to the wrong monitor in multi-monitor setups ===
=== Touchscreen input bound to the wrong monitor in multi-monitor setups ===
Line 278: Line 282:
This occurs because GTK apps make blocking calls to freedesktop portals to be displayed. If Sway is not integrated with dbus and systemd, it will not be able to communicate via the <code>org.freedesktop.portal.Desktop</code> portal. To fix this, see the [[Sway#Using NixOS|description]] of default Sway configurations earlier. Adding the following to your sway configuration, if it is not already present, may resolve the issue:
This occurs because GTK apps make blocking calls to freedesktop portals to be displayed. If Sway is not integrated with dbus and systemd, it will not be able to communicate via the <code>org.freedesktop.portal.Desktop</code> portal. To fix this, see the [[Sway#Using NixOS|description]] of default Sway configurations earlier. Adding the following to your sway configuration, if it is not already present, may resolve the issue:
  include /etc/sway/config.d/*
  include /etc/sway/config.d/*
===dbus-issues: no icons in tray, can't open files from Nautilus with the right program===
If you're using Gnome-Apps like Nautilus on NixOS with Sway, you might run into issue with settings standard applications to open files from Nautilus (e.g. there being no way of linking PDF to your preferred PDF-reader). You might  also experience tray icons not showing up in your bar.
This is fixed by running <code>dbus-update-activation-environment --all</code> after starting your session. Make it permanent by adding <code>exec dbus-update-activation-environment --all</code> to your sway config file.


== Tips and tricks ==
== Tips and tricks ==