nix-home/home/modules/programs/my-sway/default.nix

415 lines
13 KiB
Nix
Raw Normal View History

{ pkgs, lib, options, config, osConfig, ... }:
2022-04-19 23:36:11 +00:00
with lib;
let
cfg = config.programs.my-sway;
2022-11-25 13:45:17 +00:00
swayCfg = config.wayland.windowManager.sway;
2022-04-19 23:36:11 +00:00
mod = "Mod4";
# List of workspaces
workspaces = [
"1:🌏 web"
"2:💬 chat"
"3: code"
"4:🎶 music"
"5:🔧 extra"
"6:🧰 6"
"7:🔩 7"
"8:🛠 8"
"9:🔨 9"
"10:🎲 misc"
2022-04-19 23:36:11 +00:00
];
2024-01-19 13:55:20 +00:00
extraWorkspaces = {
mail = "📧 Email";
};
2022-04-19 23:36:11 +00:00
wsAttrs = builtins.listToAttrs (
map
(i: { name = toString (remainder i 10); value = builtins.elemAt workspaces (i - 1); })
(range 1 11)
);
remainder = x: y: x - (builtins.div x y) * y;
range = from: to:
let
f = cur: if cur == to then [ ] else [ cur ] ++ f (cur + 1);
in
f from;
screenshotScript = pkgs.writeScriptBin "screenshot" ''
#! ${pkgs.fish}/bin/fish
2023-03-04 10:13:16 +00:00
${pkgs.grim}/bin/grim -g (${pkgs.slurp}/bin/slurp) - | ${pkgs.wl-clipboard}/bin/wl-copy
'';
2022-05-31 15:23:55 +00:00
2023-07-27 05:46:43 +00:00
screenshotEditScript = pkgs.writeScriptBin "screenshot" ''
#! ${pkgs.fish}/bin/fish
${pkgs.grim}/bin/grim -g (${pkgs.slurp}/bin/slurp) - | ${pkgs.swappy}/bin/swappy -f -
'';
2025-01-15 11:45:31 +00:00
playerctl = "${pkgs.playerctl}/bin/playerctl";
2022-04-19 23:36:11 +00:00
in
{
2023-01-25 14:43:11 +00:00
# imports = [ ./ibus.nix ];
2022-04-25 18:16:46 +00:00
2022-04-19 23:36:11 +00:00
options.programs.my-sway = {
enable = mkEnableOption "Enable the sway configuration";
fontSize = mkOption {
type = types.float;
description = "The default font size";
};
enableTouchpad = mkOption {
type = types.bool;
description = "Whether to enable the touchpad";
default = true;
};
wallpaper = mkOption {
type = types.oneOf [ types.path types.str ];
description = "Path to the wallpaper to be used";
default = config.linux.graphical.wallpaper;
2022-04-19 23:36:11 +00:00
};
terminal = mkOption {
type = types.str;
description = "The command to the terminal emulator to be used";
default = lib.getExe config.linux.graphical.defaults.terminal.package;
2022-04-19 23:36:11 +00:00
};
2022-10-17 15:32:12 +00:00
browser = mkOption {
type = types.str;
description = "The command for the browser";
default = lib.getExe config.linux.graphical.defaults.webBrowser.package;
2022-10-17 15:32:12 +00:00
};
2022-05-03 14:30:53 +00:00
2025-01-15 11:45:31 +00:00
enableLaptop = lib.mkOption {
type = lib.types.bool;
description = "Whether to enable laptop-specific stuff";
default = true;
};
2022-11-08 14:35:13 +00:00
lockCmd = mkOption {
type = types.str;
description = "The screen lock command";
default = "${pkgs.swaylock}/bin/swaylock"
+ (if cfg.wallpaper == "" then "" else " -i ${cfg.wallpaper} -s fill")
+ " -l -k";
};
2025-01-15 11:45:31 +00:00
};
2025-01-16 17:10:23 +00:00
config.systemd.user.targets.sway-session = mkIf cfg.enable {
Unit.Before = [ "tray.target" "xwayland.target" "xdg-desktop-portal.service" "xdg-desktop-autostart.target" ];
Unit.Upholds = [ "waybar.service" ];
Unit.Wants = [ "xdg-desktop-autostart.target" ];
2025-01-16 17:10:23 +00:00
};
2025-01-15 11:45:31 +00:00
# Enable waybar
config.programs.my-waybar = mkIf cfg.enable {
enable = true;
fontSize = mkDefault cfg.fontSize;
enableLaptopBars = mkDefault cfg.enableLaptop;
terminal = mkDefault cfg.terminal;
2022-04-19 23:36:11 +00:00
};
config.systemd.user.services.swaync.Install.WantedBy = mkIf cfg.enable [ "sway-session.target" ];
2022-04-19 23:36:11 +00:00
config.wayland.windowManager.sway = mkIf cfg.enable {
enable = true;
2023-12-01 21:05:54 +00:00
systemd.enable = true;
systemd.variables = options.wayland.windowManager.sway.systemd.variables.default ++ [
"PATH" # for portals
2024-06-11 21:42:57 +00:00
"XDG_DATA_DIRS" # For extra icons
"XDG_DATA_HOME" # For extra icons
] ++ lib.optionals osConfig.services.desktopManager.plasma6.enable [
"XDG_MENU_PREFIX"
];
# systemd.extraCommands = options.wayland.windowManager.sway.systemd.extraCommands.default
# ++ [
# "systemctl --user restart xdg-desktop-portal.service"
# ];
2022-04-19 23:36:11 +00:00
checkConfig = false; # Not working atm
2022-04-19 23:36:11 +00:00
config = {
### Inputs
#
# Touchpad
input."type=touchpad" = {
events = if cfg.enableTouchpad then "enabled" else "disabled";
};
# TODO: Keyboard
### Outputs
#
# Wallpaper
output."*".bg = if cfg.wallpaper == "" then "#000000 solid_color" else "${cfg.wallpaper} fill";
2022-05-04 14:23:09 +00:00
### Seats
#
# Cursor
seat."*".xcursor_theme = "${config.home.pointerCursor.name} ${toString config.home.pointerCursor.size}";
2022-05-04 14:23:09 +00:00
2022-04-19 23:36:11 +00:00
### Programs
#
# Terminal
terminal = cfg.terminal;
2022-04-25 15:54:36 +00:00
menu = "${pkgs.dmenu}/bin/dmenu_path | ${pkgs.bemenu}/bin/bemenu | ${pkgs.findutils}/bin/xargs swaymsg exec --";
2022-04-19 23:36:11 +00:00
# Startup
startup = [
# # Dex for autostart
# { command = "${pkgs.dex}/bin/dex -ae sway"; }
# # Waybar
# { command = "systemctl --user restart waybar"; always = true; }
2024-05-28 20:02:11 +00:00
# IME
{ command = "fcitx5"; }
2024-06-25 18:24:48 +00:00
];
2022-04-19 23:36:11 +00:00
### Keybindings
#
# Main modifier
modifier = mod;
2022-11-25 13:45:17 +00:00
keybindings = {
### Default Bindings
#
## App management
"${mod}+Return" = "exec ${swayCfg.config.terminal}";
"${mod}+Shift+q" = "kill";
"${mod}+d" = "exec ${swayCfg.config.menu}";
## Windowing
# Focus
"${mod}+${swayCfg.config.left}" = "focus left";
"${mod}+${swayCfg.config.down}" = "focus down";
"${mod}+${swayCfg.config.up}" = "focus up";
"${mod}+${swayCfg.config.right}" = "focus right";
"${mod}+Left" = "focus left";
"${mod}+Down" = "focus down";
"${mod}+Up" = "focus up";
"${mod}+Right" = "focus right";
# Move
"${mod}+Shift+${swayCfg.config.left}" = "move left";
"${mod}+Shift+${swayCfg.config.down}" = "move down";
"${mod}+Shift+${swayCfg.config.up}" = "move up";
"${mod}+Shift+${swayCfg.config.right}" = "move right";
"${mod}+Shift+Left" = "move left";
"${mod}+Shift+Down" = "move down";
"${mod}+Shift+Up" = "move up";
"${mod}+Shift+Right" = "move right";
# Toggles
"${mod}+f" = "fullscreen toggle";
"${mod}+a" = "focus parent";
# Layouts
"${mod}+s" = "layout stacking";
"${mod}+w" = "layout tabbed";
"${mod}+e" = "layout toggle split";
# Floating
"${mod}+Shift+space" = "floating toggle";
# Scratchpad
"${mod}+Shift+minus" = "move scratchpad";
# Resize
"${mod}+r" = "mode resize";
"${mod}+minus" = "scratchpad show";
## Reload and exit
"${mod}+Shift+c" = "reload";
"${mod}+Shift+e" =
"exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -b 'Yes, exit sway' 'swaymsg exit'";
2023-03-15 13:02:15 +00:00
# Launcher
2023-06-06 20:36:45 +00:00
"${mod}+space" = "exec rofi -show drun";
"${mod}+tab" = "exec ${./rofi-window.py}";
2024-11-13 10:41:20 +00:00
"${mod}+shift+p" = "exec rofi-rbw-script";
2022-11-25 13:45:17 +00:00
} // {
2022-10-31 11:05:14 +00:00
## Splits
"${mod}+v" = "split v";
"${mod}+Shift+v" = "split h";
## Run
"${mod}+r" = "exec ${config.wayland.windowManager.sway.config.menu}";
"${mod}+Shift+r" = "mode resize";
## Screenshot
"Print" = "exec ${screenshotScript}/bin/screenshot";
2023-07-27 05:46:43 +00:00
"Shift+Print" = "exec ${screenshotEditScript}/bin/screenshot";
2022-10-31 11:05:14 +00:00
## Locking
2022-11-08 14:35:13 +00:00
"${mod}+semicolon" = "exec ${cfg.lockCmd}";
2022-10-31 11:05:14 +00:00
## Multimedia
"XF86AudioPrev" = "exec ${playerctl} previous";
"XF86AudioPlay" = "exec ${playerctl} play-pause";
"Shift+XF86AudioPlay" = "exec ${playerctl} stop";
"XF86AudioNext" = "exec ${playerctl} next";
"XF86AudioRecord" = "exec ${pkgs.alsa-utils}/bin/amixer -q set Capture toggle";
"XF86AudioMute" = "exec ${pkgs.alsa-utils}/bin/amixer -q set Master toggle";
"XF86AudioLowerVolume" = "exec ${pkgs.alsa-utils}/bin/amixer -q set Master 3%-";
"XF86AudioRaiseVolume" = "exec ${pkgs.alsa-utils}/bin/amixer -q set Master 3%+";
2022-11-25 13:45:17 +00:00
## Backlight
"XF86MonBrightnessDown" = "exec ${pkgs.brightnessctl}/bin/brightnessctl s 10%-";
"XF86MonBrightnessUp" = "exec ${pkgs.brightnessctl}/bin/brightnessctl s 10%+";
"Shift+XF86MonBrightnessDown" = "exec ${pkgs.brightnessctl}/bin/brightnessctl -d kbd_backlight s 25%-";
"Shift+XF86MonBrightnessUp" = "exec ${pkgs.brightnessctl}/bin/brightnessctl -d kbd_backlight s 25%+";
2022-10-31 11:05:14 +00:00
} //
# Map the workspaces
(builtins.listToAttrs (lib.flatten (map
(key: [
{
2022-10-31 11:05:14 +00:00
name = "${mod}+${key}";
value = "workspace ${builtins.getAttr key wsAttrs}";
}
{
2022-10-31 11:05:14 +00:00
name = "${mod}+Shift+${key}";
value = "move to workspace ${builtins.getAttr key wsAttrs}";
}
2022-10-31 11:05:14 +00:00
])
(builtins.attrNames wsAttrs))
)) //
2024-01-19 13:55:20 +00:00
{
# Extra workspaces
"${mod}+asciicircum" = "workspace ${extraWorkspaces.mail}";
"${mod}+shift+asciicircum" = "move to workspace ${extraWorkspaces.mail}";
} //
2022-10-31 11:05:14 +00:00
# Move workspaces between outputs
{
"${mod}+ctrl+h" = "move workspace to output left";
"${mod}+ctrl+l" = "move workspace to output right";
2022-11-25 13:45:17 +00:00
};
2022-04-19 23:36:11 +00:00
### Fonts
#
fonts = {
names = [ "monospace" "FontAwesome5Free" ];
size = cfg.fontSize;
};
### Workspaces
#
# Default workspace
defaultWorkspace = "workspace ${builtins.elemAt workspaces 0}";
# Back and Forth
workspaceAutoBackAndForth = true;
### Windows
#
# Border
2022-09-11 13:41:59 +00:00
window.border = 4;
2022-04-19 23:36:11 +00:00
# Assigning windows to workspaces
assigns = {
"${builtins.elemAt workspaces 0}" = [
2024-11-13 15:42:34 +00:00
{ app_id = "^firefox$"; }
{ app_id = "^librewolf$"; }
{ app_id = "^zen$"; }
2022-04-19 23:36:11 +00:00
];
"${builtins.elemAt workspaces 1}" = [
2023-04-11 09:54:24 +00:00
{ class = "^((d|D)iscord|((A|a)rm(c|C)ord))$"; }
2023-12-01 21:28:23 +00:00
{ class = "VencordDesktop"; }
{ app_id = "VencordDesktop"; }
2024-03-13 11:20:42 +00:00
{ class = "vesktop"; }
{ app_id = "vesktop"; }
2024-11-13 15:42:34 +00:00
{ class = "Slack"; }
2022-04-19 23:36:11 +00:00
];
2024-01-19 13:55:20 +00:00
${extraWorkspaces.mail} = [
2023-06-06 19:27:19 +00:00
{ app_id = "thunderbird"; }
2024-01-19 13:55:20 +00:00
{ app_id = "evolution"; }
2023-03-24 10:25:59 +00:00
];
2022-04-19 23:36:11 +00:00
};
# Commands
window.commands = [
{ criteria = { title = ".*"; }; command = "inhibit_idle fullscreen"; }
2024-01-20 11:45:59 +00:00
] ++ (
# Floating assignments
let
criterias = [
{ app_id = ".*float.*"; }
2024-06-06 19:15:38 +00:00
{ app_id = "org\\.freedesktop\\.impl\\.portal\\.desktop\\..*"; }
2024-01-20 11:45:59 +00:00
{ class = ".*float.*"; }
{ title = "Extension: .*Bitwarden.*"; }
];
toCommand = criteria: { inherit criteria; command = "floating enable"; };
in
map toCommand criterias
);
# Focus
2022-04-19 23:36:11 +00:00
focus.followMouse = true;
2022-04-25 15:54:36 +00:00
focus.mouseWarping = true;
2022-04-19 23:36:11 +00:00
focus.newWindow = "urgent";
# Gaps
2023-03-25 10:40:36 +00:00
gaps.outer = 4;
2022-04-19 23:36:11 +00:00
gaps.inner = 4;
2023-07-08 16:53:05 +00:00
gaps.smartBorders = "on";
2023-09-20 08:07:37 +00:00
gaps.smartGaps = false;
2022-04-19 23:36:11 +00:00
### Bars
# Let systemd manage it
bars = [ ];
2022-04-19 23:36:11 +00:00
};
### Misc
#
# xwayland
xwayland = true;
# swaynag
swaynag.enable = true;
# Environment Variables
extraSessionCommands = ''
export QT_QPA_PLATFORM=wayland
export QT_WAYLAND_DISABLE_WINDOWDECORATION="1"
2024-05-28 20:02:11 +00:00
export QT_IM_MODULE=fcitx
2024-06-08 15:01:10 +00:00
export GTK_IM_MODULE=fcitx # Til text-input is merged
2024-06-02 16:03:23 +00:00
# export NIXOS_OZONE_WL=1 # Until text-input is merged
2022-09-12 18:31:15 +00:00
'' + (if config.services.gnome-keyring.enable then ''
# gnome-keyring
if type gnome-keyring-daemon >/dev/null; then
eval `gnome-keyring-daemon`
export SSH_AUTH_SOCK
fi
'' else "") + lib.optionalString osConfig.services.desktopManager.plasma6.enable ''
export XDG_MENU_PREFIX=plasma-
'';
2022-04-19 23:36:11 +00:00
# Extra
wrapperFeatures.base = true;
wrapperFeatures.gtk = true;
2022-04-25 15:54:36 +00:00
2022-11-08 14:35:13 +00:00
extraConfig =
2025-01-15 11:45:31 +00:00
(if cfg.enableLaptop then ''
2022-11-08 14:35:13 +00:00
# Lock screen on lid close
2022-11-25 13:45:17 +00:00
bindswitch lid:off exec ${cfg.lockCmd}
# Gesture bindings
bindgesture swipe:3:right workspace prev
bindgesture swipe:3:left workspace next
bindgesture swipe:3:up exec ${./rofi-window.py}
2023-03-23 10:17:12 +00:00
'' else "") + ''
2023-03-23 10:27:08 +00:00
## swayfx stuff
# Rounded corners
2023-03-23 10:17:12 +00:00
corner_radius 5
2023-07-08 16:53:05 +00:00
smart_corner_radius on
2023-03-23 10:27:08 +00:00
# Shadows
2023-03-23 10:17:12 +00:00
shadows on
shadow_blur_radius 5
2023-03-23 10:27:08 +00:00
# Dimming
2023-03-23 10:17:12 +00:00
default_dim_inactive 0.0
for_window [app_id="kitty"] dim_inactive 0.05
titlebar_separator enable
# Blur
2023-04-19 11:48:13 +00:00
for_window [app_id=".*kitty.*"] blur enable
blur_xray disable
'' + ''
# Enable portal stuff
exec ${pkgs.writeShellScript "start-portals.sh" ''
''}
2023-03-23 10:17:12 +00:00
'';
2022-04-19 23:36:11 +00:00
};
2022-11-08 14:35:13 +00:00
config.services.swayidle = mkIf cfg.enable {
enable = true;
systemdTarget = "sway-session.target";
2022-11-08 14:35:13 +00:00
timeouts = [
# Lock after 15 minutes of idle
2024-03-30 13:19:14 +00:00
# { timeout = 15 * 60; command = cfg.lockCmd; }
2022-11-08 14:35:13 +00:00
];
events = [
{ event = "lock"; command = cfg.lockCmd; }
{ event = "before-sleep"; command = cfg.lockCmd; }
];
2022-11-08 14:35:13 +00:00
};
2022-04-19 23:36:11 +00:00
config.home.packages = mkIf cfg.enable (with pkgs; [
# Needed for QT_QPA_PLATFORM
2024-06-03 19:42:44 +00:00
kdePackages.qtwayland
2022-04-19 23:36:11 +00:00
# For waybar
font-awesome
]);
2024-11-13 10:41:20 +00:00
2023-06-06 20:36:45 +00:00
config.programs.rofi = mkIf cfg.enable {
2024-11-13 10:41:20 +00:00
font = lib.mkForce "monospace ${toString cfg.fontSize}";
2023-06-06 20:36:45 +00:00
};
2022-04-19 23:36:11 +00:00
}
2023-02-25 20:43:29 +00:00