about summary refs log tree commit diff
path: root/home/wm/sway
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--home/wm/sway/default.nix113
-rw-r--r--home/wm/swaylock/config4
-rw-r--r--home/wm/swaylock/default.nix27
3 files changed, 144 insertions, 0 deletions
diff --git a/home/wm/sway/default.nix b/home/wm/sway/default.nix
new file mode 100644
index 0000000..ba70992
--- /dev/null
+++ b/home/wm/sway/default.nix
@@ -0,0 +1,113 @@
+{ config, lib, pkgs, ... }:
+let
+  isEnabled = config.my.home.wm.windowManager == "sway";
+  terminal = config.my.home.terminal.program;
+  modifier = "Mod4"; # `Super` key
+in {
+  config = lib.mkIf isEnabled {
+    home.packages = with pkgs; [
+      wlogout
+      brightnessctl
+      pulseaudio
+      grim
+      slurp
+      polkit_gnome
+      xsettingsd
+      swaylock
+      swayidle
+      wl-clipboard
+    ];
+
+    home.sessionVariables = {
+      MOZ_ENABLE_WAYLAND = true;
+      XDG_CURRENT_DESKTOP = "sway";
+      XDG_SESSION_TYPE = "wayland";
+    };
+
+    wayland.windowManager.sway = {
+      enable = true;
+      config = {
+        # FIXME: this should be a variable
+        terminal = "alacritty";
+        modifier = modifier;
+        menu = ''${pkgs.wofi}/bin/wofi -S drun -p "app:" -L 10'';
+        bars = [ ];
+        fonts = {
+          names = [ "Source Code Pro" ];
+          size = 10.0;
+        };
+        keybindings = lib.mkOptionDefault {
+          # control the volume
+          "XF86AudioRaiseVolume" =
+            "exec ${pkgs.pulseaudio}/bin/pactl set-sink-volume @DEFAULT_SINK@ +5%";
+          "XF86AudioLowerVolume" =
+            "exec ${pkgs.pulseaudio}/bin/pactl set-sink-volume @DEFAULT_SINK@ -5%";
+          "XF86AudioMute" =
+            "exec ${pkgs.pulseaudio}/bin/pactl set-sink-mute @DEFAULT_SINK@ toggle";
+          "XF86AudioMicMute" =
+            "exec ${pkgs.pulseaudio}/bin/pactl set-source-mute @DEFAULT_SOURCE@ toggle";
+
+          # control brightness
+          "XF86MonBrightnessDown" =
+            "exec ${pkgs.brightnessctl}/bin/brightnessctl set 5%-";
+          "XF86MonBrightnessUp" =
+            "exec ${pkgs.brightnessctl}/bin/brightnessctl set +5%";
+
+          # logout
+          "${modifier}+Escape" = "exec ${pkgs.wlogout}/bin/wlogout";
+
+          # screenshot
+          "${modifier}+s" =
+            "exec ${pkgs.grim}/bin/grim $(xdg-user-dir DOCUMENTS)/screenshots/$(date +'%Y-%m-%d-%H%M%S_screenshot.png')";
+          "${modifier}+Shift+s" =
+            "exec ${pkgs.slurp}/bin/slurp | ${pkgs.grim}/bin/grim -g - $(xdg-user-dir DOCUMENTS)/screenshots/$(date +'%Y-%m-%d-%H%M%S_screenshot.png')";
+
+          # File Manager
+          "${modifier}+p" = "exec ${pkgs.pcmanfm}/bin/pcmanfm";
+        };
+
+        # use `swaymsg -t get_tree' to get the title/name/ID of the applications
+        window = {
+          commands = [
+            {
+              criteria.class = ".blueman-manager-wrapped";
+              command = "floating enable";
+            }
+            {
+              criteria.class = "Pavucontrol";
+              command = "floating enable";
+            }
+          ];
+        };
+
+        input = {
+          "*" = {
+            "xkb_layout" = "us,fr";
+            # map capslock to ctrl, and switch layout using shift+caps
+            "xkb_options" = "ctrl:nocaps,grp:shift_caps_toggle";
+          };
+        };
+
+        assigns = {
+          "1" = [{ app_id = "emacs"; }];
+          "2" = [{ app_id = "Alacritty"; }];
+          "3" = [{ app_id = "firefox"; }];
+          "4" = [{ class = "Element"; }];
+        };
+
+        output = {
+          "*" = {
+            scale = "1.5";
+            bg = "#2E3440 solid_color";
+          };
+          # This is for aptos
+          "eDP-1" = { scale = "1.3"; };
+        };
+        startup = [{
+          command = ''
+            exec "systemctl --user import-environment; systemctl --user start sway-session.target"'';
+        }];
+      };
+    };
+  };
+}
diff --git a/home/wm/swaylock/config b/home/wm/swaylock/config
new file mode 100644
index 0000000..032695b
--- /dev/null
+++ b/home/wm/swaylock/config
@@ -0,0 +1,4 @@
+color=FFFFEA
+daemonize
+indicator-caps-lock
+hide-keyboard-layout
diff --git a/home/wm/swaylock/default.nix b/home/wm/swaylock/default.nix
new file mode 100644
index 0000000..3df802a
--- /dev/null
+++ b/home/wm/swaylock/default.nix
@@ -0,0 +1,27 @@
+{ config, lib, pkgs, ... }:
+let isEnabled = config.my.home.wm.windowManager == "sway";
+in {
+  config = lib.mkIf isEnabled {
+    xdg.configFile."swaylock/config" = { source = ./config; };
+
+    # https://github.com/nix-community/home-manager/pull/2610
+    # won't be needed for ever
+    systemd.user.services.swayidle = {
+      Unit.PartOf = [ "sway-session.target" ];
+      Install.WantedBy = [ "sway-session.target" ];
+
+      Service = {
+        Environment =
+          "PATH=${pkgs.bash}/bin:${config.wayland.windowManager.sway.package}/bin";
+        ExecStart = ''
+          ${pkgs.swayidle}/bin/swayidle -w \
+              timeout 300 "${pkgs.swaylock}/bin/swaylock" \
+              timeout 300 'swaymsg "output * dpms off"' \
+                  resume 'swaymsg "output * dpms on"' \
+              before-sleep "${pkgs.swaylock}/bin/swaylock"
+        '';
+        Restart = "on-failure";
+      };
+    };
+  };
+}