Skip to content

Commit

Permalink
Manage sway as a module
Browse files Browse the repository at this point in the history
  • Loading branch information
arunoruto committed Sep 16, 2024
1 parent afdb98f commit 1d7069b
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 169 deletions.
1 change: 1 addition & 0 deletions modules/home-manager/pc/desktop/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
config = lib.mkIf config.desktop.enable {
gnome.enable = lib.mkDefault true;
hyprland.enable = lib.mkDefault true;
sway.enable = lib.mkDefault false;

home.packages = with pkgs; [
gimp
Expand Down
147 changes: 82 additions & 65 deletions modules/home-manager/pc/desktop/sway/default.nix
Original file line number Diff line number Diff line change
@@ -1,81 +1,98 @@
{pkgs, ...}: let
{
pkgs,
lib,
config,
...
}: let
image = "~/Pictures/wallpapers/anime/cafe-at-night.png";
lockscreen = "${pkgs.swaylock}/bin/swaylock --image ${image}";
in {
imports = [
./services.nix
./theme.nix
# ./theme.nix
./keybindings.nix
# ./swaync.nix
./swaylock.nix
];
wayland.windowManager.sway = {
enable = true;
# https://www.reddit.com/r/NixOS/comments/1c9n1qk/nixosrebuild_of_sway_failing_with_unable_to/
checkConfig = false;
config = rec {
modifier = "Mod4";
terminal = "wezterm";
fonts = {
names = ["FiraCode Nerd Font Mono"];
style = "Regular";
size = 10.0;
};
window = {
border = 2;
titlebar = false;
};
gaps = {
inner = 8;
outer = -5;
smartBorders = "on";
smartGaps = true;
};
input = {
"type:keyboard" = {
xkb_layout = "de";
xkb_variant = "nodeadkeys";

options.sway.enable = lib.mkEnableOption "Custom sway config";

config = lib.mkIf config.sway.enable {
sway = {
keybindings.enable = lib.mkDefault true;
services.enable = lib.mkDefault true;
lock.enable = lib.mkDefault true;
# notify.enable = lib.mkDefault true;
};

wayland.windowManager.sway = {
enable = true;
# https://www.reddit.com/r/NixOS/comments/1c9n1qk/nixosrebuild_of_sway_failing_with_unable_to/
checkConfig = false;
config = rec {
modifier = "Mod4";
terminal = "wezterm";
fonts = {
names = ["FiraCode Nerd Font Mono"];
style = "Regular";
size = 10.0;
};
"type:touchpad" = {
click_method = "clickfinger";
left_handed = "disabled";
tap = "enabled";
natural_scroll = "enabled";
dwt = "enabled";
accel_profile = "flat";
pointer_accel = "0.25";
window = {
border = 2;
titlebar = false;
};
};
output = {
"*" = {
# bg = "${image} fill";
scale = "1.25";
gaps = {
inner = 8;
outer = -5;
smartBorders = "on";
smartGaps = true;
};
};
keybindings = {
"${modifier}+Shift+l" = "exec ${lockscreen}";
};
bars = [
{
position = "top";
mode = "dock";
hiddenState = "hide";
command = "${pkgs.waybar}/bin/waybar";
#command = "${pkgs.sway}/bin/swaybar";
#statusCommand = "${pkgs.i3status}/bin/i3status";
workspaceButtons = true;
workspaceNumbers = false;
trayOutput = "primary";
fonts = {
names = ["FiraCode Nerd Font Mono"];
style = "Regular";
size = 11.0;
input = {
"type:keyboard" = {
xkb_layout = "de";
xkb_variant = "nodeadkeys";
};
}
];
"type:touchpad" = {
click_method = "clickfinger";
left_handed = "disabled";
tap = "enabled";
natural_scroll = "enabled";
dwt = "enabled";
accel_profile = "flat";
pointer_accel = "0.25";
};
};
output = {
"*" = {
# bg = "${image} fill";
scale = "1.25";
};
};
keybindings = {
"${modifier}+Shift+l" = "exec ${lockscreen}";
};
bars = [
{
position = "top";
mode = "dock";
hiddenState = "hide";
command = "${pkgs.waybar}/bin/waybar";
#command = "${pkgs.sway}/bin/swaybar";
#statusCommand = "${pkgs.i3status}/bin/i3status";
workspaceButtons = true;
workspaceNumbers = false;
trayOutput = "primary";
fonts = {
names = ["FiraCode Nerd Font Mono"];
style = "Regular";
size = 11.0;
};
}
];
};
extraConfig = ''
#blur enable
'';
};
extraConfig = ''
#blur enable
'';
};
}
161 changes: 83 additions & 78 deletions modules/home-manager/pc/desktop/sway/keybindings.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
config,
pkgs,
lib,
...
}: let
modifier = config.wayland.windowManager.sway.config.modifier;
Expand Down Expand Up @@ -34,84 +35,88 @@
ws9 = "number 9";
ws0 = "number 10";
in {
wayland.windowManager.sway = {
config = rec {
defaultWorkspace = "workspace ${ws1}";
keybindings = {
"${modifier}+Return" = "exec ${terminal}";
"${modifier}+Shift+q" = "kill";
"${modifier}+d" = "exec ${menu}";
#"${modifier}+Shift+l" = "exec ${lockscreen}";

"${modifier}+${left}" = "focus left";
"${modifier}+${down}" = "focus down";
"${modifier}+${up}" = "focus up";
"${modifier}+${right}" = "focus right";

"${modifier}+Shift+${left}" = "move left";
"${modifier}+Shift+${down}" = "move down";
"${modifier}+Shift+${up}" = "move up";
"${modifier}+Shift+${right}" = "move right";

"${modifier}+b" = "splith";
"${modifier}+v" = "splitv";
"${modifier}+f" = "fullscreen toggle";
"${modifier}+a" = "focus parent";

"${modifier}+s" = "layout stacking";
"${modifier}+w" = "layout tabbed";
"${modifier}+e" = "layout toggle split";

"${modifier}+Shift+space" = "floating toggle";
"${modifier}+space" = "focus mode_toggle";

"${modifier}+1" = "workspace ${ws1}";
"${modifier}+2" = "workspace ${ws2}";
"${modifier}+3" = "workspace ${ws3}";
"${modifier}+4" = "workspace ${ws4}";
"${modifier}+5" = "workspace ${ws5}";
"${modifier}+6" = "workspace ${ws6}";
"${modifier}+7" = "workspace ${ws7}";
"${modifier}+8" = "workspace ${ws8}";
"${modifier}+9" = "workspace ${ws9}";
"${modifier}+0" = "workspace ${ws0}";

"${modifier}+Shift+1" = "move container to workspace ${ws1}";
"${modifier}+Shift+2" = "move container to workspace ${ws2}";
"${modifier}+Shift+3" = "move container to workspace ${ws3}";
"${modifier}+Shift+4" = "move container to workspace ${ws4}";
"${modifier}+Shift+5" = "move container to workspace ${ws5}";
"${modifier}+Shift+6" = "move container to workspace ${ws6}";
"${modifier}+Shift+7" = "move container to workspace ${ws7}";
"${modifier}+Shift+8" = "move container to workspace ${ws8}";
"${modifier}+Shift+9" = "move container to workspace ${ws9}";
"${modifier}+Shift+0" = "move container to workspace ${ws0}";

"${modifier}+Shift+minus" = "move scratchpad";
"${modifier}+minus" = "scratchpad show";

"${modifier}+Shift+r" = "reload";
"${modifier}+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'";

"${modifier}+r" = "mode resize";

# Brightness
"XF86MonBrightnessDown" = "exec light -U 5";
"XF86MonBrightnessUp" = "exec light -A 5";

# Volume
"XF86AudioRaiseVolume" = "exec 'wpctl set-volume @DEFAULT_SINK@ 5%+ -l 1.0'";
"XF86AudioLowerVolume" = "exec 'wpctl set-volume @DEFAULT_SINK@ 5%-'";
"XF86AudioMute" = "exec 'wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle'";

# Media control
"XF86AudioPlay" = "exec playerctl play-pause";
"XF86AudioPause" = "exec playerctl play-pause";
"XF86AudioNext" = "exec playerctl next";
"XF86AudioPrev" = "exec playerctl previous";

# Screenshots
"Print" = ''exec grim -g "$(slurp -d)" - | wl-copy'';
options.sway.keybindings.enable = lib.mkEnableOption "Custom sway keybindings";

config = lib.mkIf config.sway.keybindings.enable {
wayland.windowManager.sway = {
config = rec {
defaultWorkspace = "workspace ${ws1}";
keybindings = {
"${modifier}+Return" = "exec ${terminal}";
"${modifier}+Shift+q" = "kill";
"${modifier}+d" = "exec ${menu}";
#"${modifier}+Shift+l" = "exec ${lockscreen}";

"${modifier}+${left}" = "focus left";
"${modifier}+${down}" = "focus down";
"${modifier}+${up}" = "focus up";
"${modifier}+${right}" = "focus right";

"${modifier}+Shift+${left}" = "move left";
"${modifier}+Shift+${down}" = "move down";
"${modifier}+Shift+${up}" = "move up";
"${modifier}+Shift+${right}" = "move right";

"${modifier}+b" = "splith";
"${modifier}+v" = "splitv";
"${modifier}+f" = "fullscreen toggle";
"${modifier}+a" = "focus parent";

"${modifier}+s" = "layout stacking";
"${modifier}+w" = "layout tabbed";
"${modifier}+e" = "layout toggle split";

"${modifier}+Shift+space" = "floating toggle";
"${modifier}+space" = "focus mode_toggle";

"${modifier}+1" = "workspace ${ws1}";
"${modifier}+2" = "workspace ${ws2}";
"${modifier}+3" = "workspace ${ws3}";
"${modifier}+4" = "workspace ${ws4}";
"${modifier}+5" = "workspace ${ws5}";
"${modifier}+6" = "workspace ${ws6}";
"${modifier}+7" = "workspace ${ws7}";
"${modifier}+8" = "workspace ${ws8}";
"${modifier}+9" = "workspace ${ws9}";
"${modifier}+0" = "workspace ${ws0}";

"${modifier}+Shift+1" = "move container to workspace ${ws1}";
"${modifier}+Shift+2" = "move container to workspace ${ws2}";
"${modifier}+Shift+3" = "move container to workspace ${ws3}";
"${modifier}+Shift+4" = "move container to workspace ${ws4}";
"${modifier}+Shift+5" = "move container to workspace ${ws5}";
"${modifier}+Shift+6" = "move container to workspace ${ws6}";
"${modifier}+Shift+7" = "move container to workspace ${ws7}";
"${modifier}+Shift+8" = "move container to workspace ${ws8}";
"${modifier}+Shift+9" = "move container to workspace ${ws9}";
"${modifier}+Shift+0" = "move container to workspace ${ws0}";

"${modifier}+Shift+minus" = "move scratchpad";
"${modifier}+minus" = "scratchpad show";

"${modifier}+Shift+r" = "reload";
"${modifier}+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'";

"${modifier}+r" = "mode resize";

# Brightness
"XF86MonBrightnessDown" = "exec light -U 5";
"XF86MonBrightnessUp" = "exec light -A 5";

# Volume
"XF86AudioRaiseVolume" = "exec 'wpctl set-volume @DEFAULT_SINK@ 5%+ -l 1.0'";
"XF86AudioLowerVolume" = "exec 'wpctl set-volume @DEFAULT_SINK@ 5%-'";
"XF86AudioMute" = "exec 'wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle'";

# Media control
"XF86AudioPlay" = "exec playerctl play-pause";
"XF86AudioPause" = "exec playerctl play-pause";
"XF86AudioNext" = "exec playerctl next";
"XF86AudioPrev" = "exec playerctl previous";

# Screenshots
"Print" = ''exec grim -g "$(slurp -d)" - | wl-copy'';
};
};
};
};
Expand Down
38 changes: 24 additions & 14 deletions modules/home-manager/pc/desktop/sway/services.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# {pkgs, ...}: let
{
pkgs,
lib,
config,
...
}:
# let
# flavor = "macchiato";
# catppuccin-rofi = builtins.fetchGit {
# url = "https://github.com/catppuccin/rofi";
Expand All @@ -10,19 +16,23 @@
# };
# in
{
programs.rofi = {
enable = true;
# font = "FiraCode Nerd Font Mono 14";
# theme = "${catppuccin-rofi}/basic/.local/share/rofi/themes/catppuccin-${flavor}.rasi";
};
options.sway.services.enable = lib.mkEnableOption "Custom sway services";

# services.mako = {
# enable = true;
# defaultTimeout = 10000;
# # extraConfig = builtins.readFile "${catppuccin-mako}/src/${flavor}";
# };
config = lib.mkIf config.sway.services.enable {
programs.rofi = {
enable = true;
# font = "FiraCode Nerd Font Mono 14";
# theme = "${catppuccin-rofi}/basic/.local/share/rofi/themes/catppuccin-${flavor}.rasi";
};

#services.wob = {
# enable = true;
#};
# services.mako = {
# enable = true;
# defaultTimeout = 10000;
# # extraConfig = builtins.readFile "${catppuccin-mako}/src/${flavor}";
# };

#services.wob = {
# enable = true;
#};
};
}
Loading

0 comments on commit 1d7069b

Please sign in to comment.