From 5bda6519cd0c6b24c36132b0a6d495c5654c9025 Mon Sep 17 00:00:00 2001 From: traxys Date: Sun, 10 Apr 2022 18:48:52 +0200 Subject: [PATCH] implement sway for i3-sway switch --- wm/default.nix | 8 +- wm/i3.nix | 49 +----- wm/i3like-utils.nix | 47 ++++++ wm/i3like.nix | 2 +- wm/sway.nix | 377 ++++++++++++++++---------------------------- 5 files changed, 198 insertions(+), 285 deletions(-) create mode 100644 wm/i3like-utils.nix diff --git a/wm/default.nix b/wm/default.nix index 17fab2f..d6d79d0 100644 --- a/wm/default.nix +++ b/wm/default.nix @@ -16,7 +16,7 @@ terminal = { enable = true; - kind = "kitty"; + kind = "foot"; colors = { background = "000000"; @@ -48,7 +48,7 @@ wm = let mod = config.wm.modifier; in { enable = true; - kind = "i3"; + kind = "sway"; modifier = "Mod4"; font = { @@ -91,6 +91,8 @@ { command = "firefox"; } { command = "element-desktop"; } { command = "thunderbird"; } + { command = "systemctl --user import-environment DISPLAY WAYLAND_DISPLAY SWAYSOCK"; } + { command = "hash dbus-update-activation-environment 2>/dev/null && dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK"; } ]; workspaces = { @@ -126,6 +128,8 @@ }; keybindings = { + "${mod}+Shift+l" = "exec ${pkgs.swaylock-fancy}/bin/swaylock-fancy"; + # Media Keys "XF86AudioRaiseVolume" = "exec ${pkgs.pulseaudio}/bin/pactl set-sink-volume @DEFAULT_SINK@ '+10%'"; "XF86AudioLowerVolume" = "exec ${pkgs.pulseaudio}/bin/pactl set-sink-volume @DEFAULT_SINK@ '-10%'"; diff --git a/wm/i3.nix b/wm/i3.nix index b671a4f..caeb697 100644 --- a/wm/i3.nix +++ b/wm/i3.nix @@ -4,39 +4,7 @@ with builtins; with lib; let cfg = config.wm; - - addKeyIf = cond: keybinds: newkey: if cond then newkey // keybinds else keybinds; - keybindSolo = keys: submod: addKeyIf submod.enable keys { - "${submod.keybind}" = "exec ${submod.command}"; - }; - keydefs = [ cfg.printScreen cfg.menu cfg.exit ]; - keybindingsKeydef = foldl' keybindSolo cfg.keybindings keydefs; - - mod = cfg.modifier; - ws_def = cfg.workspaces.definitions; - get_ws = ws: getAttr ws ws_def; - workspaceFmt = name: - let key = (get_ws name).key; in - { - "${mod}+${key}" = "workspace ${name}"; - "${mod}+${cfg.workspaces.moveModifier}+${key}" = "move container to workspace ${name}"; - }; - - keybindings = (foldl' (x: y: x // y) { } (map workspaceFmt (attrNames ws_def))) - // keybindingsKeydef; - - workspaceAssign = name: - { - workspace = name; - output = (get_ws name).output; - }; - - workspaceOutputAssign = map workspaceAssign (filter (ws: (get_ws ws).output != null) (attrNames ws_def)); - - classAssign = name: { - "${name}" = map (app: { class = "${app}"; }) ((get_ws name).assign); - }; - assigns = foldl' (x: y: x // y) { } (map classAssign (attrNames ws_def)); + common = import ./i3like-utils.nix { inherit config; }; startupNotifications = if cfg.notifications.enable then [{ @@ -117,17 +85,14 @@ in enable = true; windowManager.i3 = { enable = true; - config = let mkFont = mod: { - names = [ mod.name ]; - style = mod.style; - size = mod.size; - }; in - { - inherit keybindings startup workspaceOutputAssign assigns; - fonts = mkFont cfg.font; + config = { + keybindings = common.keybindings; + workspaceOutputAssign = common.workspaceOutputAssign; + assigns = common.assigns; + fonts = common.mkFont cfg.font; modifier = cfg.modifier; bars = [{ - fonts = mkFont cfg.bar.font; + fonts = common.mkFont cfg.bar.font; statusCommand = "${config.programs.i3status-rust.package}/bin/i3status-rs ${config.home.homeDirectory}/.config/i3status-rust/config-bottom.toml"; }]; }; diff --git a/wm/i3like-utils.nix b/wm/i3like-utils.nix new file mode 100644 index 0000000..075aaab --- /dev/null +++ b/wm/i3like-utils.nix @@ -0,0 +1,47 @@ +{ config }: + +with builtins; +let + cfg = config.wm; + addKeyIf = cond: keybinds: newkey: if cond then newkey // keybinds else keybinds; + + keybindSolo = keys: submod: addKeyIf submod.enable keys { + "${submod.keybind}" = "exec ${submod.command}"; + }; + keydefs = [ cfg.printScreen cfg.menu cfg.exit ]; + keybindingsKeydef = foldl' keybindSolo cfg.keybindings keydefs; + + mod = cfg.modifier; + ws_def = cfg.workspaces.definitions; + get_ws = ws: getAttr ws ws_def; + workspaceFmt = name: + let key = (get_ws name).key; in + { + "${mod}+${key}" = "workspace ${name}"; + "${mod}+${cfg.workspaces.moveModifier}+${key}" = "move container to workspace ${name}"; + }; + + workspaceAssign = name: + { + workspace = name; + output = (get_ws name).output; + }; + + classAssign = name: { + "${name}" = map (app: { class = "${app}"; }) ((get_ws name).assign); + }; +in +{ + mkFont = mod: { + names = [ mod.name ]; + style = mod.style; + size = mod.size; + }; + + keybindings = (foldl' (x: y: x // y) { } (map workspaceFmt (attrNames ws_def))) + // keybindingsKeydef; + + workspaceOutputAssign = map workspaceAssign (filter (ws: (get_ws ws).output != null) (attrNames ws_def)); + + assigns = foldl' (x: y: x // y) { } (map classAssign (attrNames ws_def)); +} diff --git a/wm/i3like.nix b/wm/i3like.nix index 459bc10..678ee19 100644 --- a/wm/i3like.nix +++ b/wm/i3like.nix @@ -3,7 +3,7 @@ with builtins; with lib; { - imports = [ ./i3.nix ]; + imports = [ ./i3.nix ./sway.nix ]; options = { wm = { diff --git a/wm/sway.nix b/wm/sway.nix index c29f41d..1e8ab5b 100644 --- a/wm/sway.nix +++ b/wm/sway.nix @@ -1,257 +1,154 @@ { config, lib, pkgs, ... }: +with lib; +with builtins; +let + cfg = config.wm; + common = import ./i3like-utils.nix { inherit config; }; + + startupNotifications = + if cfg.notifications.enable then [{ + command = "${pkgs.mako}/bin/mako"; + always = true; + }] else [ ]; + + startup = startupNotifications ++ cfg.startup; +in { - imports = [ ./terminal ]; + config = mkIf (cfg.enable && cfg.kind == "sway") { - home.packages = with pkgs; [ - sway - ]; + home.packages = with pkgs; [ + sway + ]; - gtk = { - enable = true; - font = { - name = "DejaVu Sans"; + home.sessionVariables = { + MOZ_ENABLE_WAYLAND = "1"; + XDG_CURRENT_DESKTOP = "sway"; + LIBSEAT_BACKEND = "logind"; }; - theme = { - package = pkgs.gnome.gnome-themes-extra; - name = "Adwaita"; - }; - }; - home.sessionVariables = { - MOZ_ENABLE_WAYLAND = "1"; - XDG_CURRENT_DESKTOP = "sway"; - LIBSEAT_BACKEND = "logind"; - }; - - terminal = { - enable = true; - kind = "foot"; - - colors = { - background = "000000"; - foreground = "ffffff"; - - black = { - normal = "000000"; - bright = "545454"; - }; - red = { normal = "ff5555"; }; - green = { normal = "55ff55"; }; - yellow = { normal = "ffff55"; }; - blue = { normal = "5555ff"; }; - magenta = { normal = "ff55ff"; }; - cyan = { normal = "55ffff"; }; - white = { - normal = "bbbbbb"; - bright = "ffffff"; + programs = { + mako = mkIf cfg.notifications.enable { + enable = true; + font = cfg.notifications.font; + margin = "20,20,5,5"; + defaultTimeout = cfg.notifications.defaultTimeout; }; - selectionForeground = "000000"; - }; - font = { - family = "Hack Nerd Font Mono"; - size = 7; - }; - }; - - programs = { - mako = { - enable = true; - font = "hack nerd font 10"; - margin = "20,20,5,5"; - ignoreTimeout = true; - defaultTimeout = 7000; - }; - - waybar = { - enable = true; - style = builtins.readFile ./waybar.css; - settings = [ - { - layer = "top"; - position = "bottom"; - modules-left = [ - "network#wifi" - "sway/workspaces" - "sway/mode" - ]; - modules-center = [ "sway/window" ]; - modules-right = [ - "cpu" - "memory" - "disk#home" - "disk#root" - "battery" - "clock" - "tray" - ]; - modules = { - "sway/workspaces" = { - persistent_workspaces = { - "" = [ ]; - "" = [ ]; - "1:" = [ ]; - }; - numeric-first = true; - }; - "network#wifi" = { - interface = "wlp1s0"; - format-wifi = "{essid} ({signalStrength}%) "; - }; - cpu = { - format = "﬙ {load}"; - }; - memory = { - format = " {used:.0f}G/{total:.0f}G"; - }; - "sway/window" = { - max-length = 50; - }; - "disk#home" = { - path = "/home"; - format = " {free}"; - }; - "disk#root" = { - path = "/"; - format = " {percentage_free}%"; - }; - "battery" = { - format = "{capacity}% {icon}"; - format-icons = [ "" "" "" "" "" ]; - }; - "clock" = { - format-alt = "{:%a, %d. %b %H:%M}"; - }; - }; - } - ]; - }; - }; - - wayland.windowManager.sway = { - enable = true; - config = { - modifier = "Mod4"; - bars = [{ - command = "waybar"; - }]; - input = - let - inputs = config.extraInfo.inputs; - inputsCfg = [ - (if inputs.keyboard != null then { - name = inputs.keyboard; - value = - { - xkb_layout = "us"; - xkb_variant = "dvp"; - xkb_options = "compose:102"; + waybar = { + enable = true; + style = builtins.readFile ./waybar.css; + settings = [ + { + layer = "top"; + position = "bottom"; + modules-left = [ + "network#wifi" + "sway/workspaces" + "sway/mode" + ]; + modules-center = [ "sway/window" ]; + modules-right = [ + "cpu" + "memory" + "disk#home" + "disk#root" + "battery" + "clock" + "tray" + ]; + modules = { + "sway/workspaces" = { + persistent_workspaces = { + "" = [ ]; + "" = [ ]; + "1:" = [ ]; }; - - } else null) - (if inputs.touchpad != null then { - name = inputs.touchpad; - value = { dwt = "disable"; }; - } else null) - ]; - in - builtins.listToAttrs inputsCfg; - fonts = { - names = [ "Hack Nerd Font" ]; - style = "Regular"; - size = 13.0; + numeric-first = true; + }; + "network#wifi" = { + interface = "wlp1s0"; + format-wifi = "{essid} ({signalStrength}%) "; + }; + cpu = { + format = "﬙ {load}"; + }; + memory = { + format = " {used:.0f}G/{total:.0f}G"; + }; + "sway/window" = { + max-length = 50; + }; + "disk#home" = { + path = "/home"; + format = " {free}"; + }; + "disk#root" = { + path = "/"; + format = " {percentage_free}%"; + }; + "battery" = { + format = "{capacity}% {icon}"; + format-icons = [ "" "" "" "" "" ]; + }; + "clock" = { + format-alt = "{:%a, %d. %b %H:%M}"; + }; + }; + } + ]; }; - window = { - titlebar = true; - }; - startup = [ - { command = "systemctl --user import-environment DISPLAY WAYLAND_DISPLAY SWAYSOCK"; } - { command = "hash dbus-update-activation-environment 2>/dev/null && dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK"; } - { command = "${pkgs.mako}/bin/mako"; } - { command = "wdumpkeys >> ~/.keydump"; } - ]; - menu = "${pkgs.wofi}/bin/wofi --show drun,run --allow-images"; - keybindings = - let - mod = config.wayland.windowManager.sway.config.modifier; - menu = config.wayland.windowManager.sway.config.menu; - terminal = config.wayland.windowManager.sway.config.terminal; - ws1 = "1:"; - ws2 = "2:"; - ws3 = "3"; - ws4 = "4:"; - ws5 = "5"; - ws6 = "6"; - ws7 = "7"; - ws8 = "8"; - ws9 = ""; - ws10 = ""; - in - { - "Print" = "exec ${pkgs.grim}/bin/grim -g \"$(${pkgs.slurp}/bin/slurp)\" - | ${pkgs.wl-clipboard}/bin/wl-copy -t image/png"; - "${mod}+Shift+semicolon" = "kill"; - "${mod}+e" = "exec ${menu}"; - "${mod}+Return" = "exec ${terminal}"; - "${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'"; - "XF86AudioMute" = "exec ${pkgs.pulseaudio}/bin/pactl set-sink-mute 50 toggle"; - - "${mod}+u" = "fullscreen toggle"; - "${mod}+comma" = "layout tabbed"; - "${mod}+p" = "mode resize"; - - "${mod}+h" = "focus left"; - "${mod}+t" = "focus down"; - "${mod}+n" = "focus up"; - "${mod}+s" = "focus right"; - "${mod}+Left" = "focus left"; - "${mod}+Down" = "focus down"; - "${mod}+Up" = "focus up"; - "${mod}+Right" = "focus right"; - "${mod}+Shift+H" = "move left"; - "${mod}+Shift+T" = "move down"; - "${mod}+Shift+N" = "move up"; - "${mod}+Shift+S" = "move right"; - "${mod}+Shift+Left" = "move left"; - "${mod}+Shift+Down" = "move down"; - "${mod}+Shift+Up" = "move up"; - "${mod}+Shift+Right" = "move right"; - - # Workspaces - "${mod}+ampersand" = "workspace ${ws1}"; - "${mod}+bracketleft" = "workspace ${ws2}"; - "${mod}+braceleft" = "workspace ${ws3}"; - "${mod}+braceright" = "workspace ${ws4}"; - "${mod}+parenleft" = "workspace ${ws5}"; - "${mod}+equal" = "workspace ${ws6}"; - "${mod}+asterisk" = "workspace ${ws7}"; - "${mod}+parenright" = "workspace ${ws8}"; - "${mod}+w" = "workspace ${ws9}"; - "${mod}+m" = "workspace ${ws10}"; - "${mod}+Shift+ampersand" = "move container to workspace ${ws1}"; - "${mod}+Shift+bracketleft" = "move container to workspace ${ws2}"; - "${mod}+Shift+braceleft" = "move container to workspace ${ws3}"; - "${mod}+Shift+braceright" = "move container to workspace ${ws4}"; - "${mod}+Shift+parenleft" = "move container to workspace ${ws5}"; - "${mod}+Shift+equal" = "move container to workspace ${ws6}"; - "${mod}+Shift+asterisk" = "move container to workspace ${ws7}"; - "${mod}+Shift+parenright" = "move container to workspace ${ws8}"; - "${mod}+Shift+w" = "move container to workspace ${ws9}"; - "${mod}+Shift+m" = "move container to workspace ${ws10}"; - - "${mod}+Shift+J" = "reload"; - "${mod}+Shift+p" = "restart"; - "${mod}+Shift+l" = "exec ${pkgs.swaylock-fancy}/bin/swaylock-fancy"; - }; }; - }; + wm.printScreen.command = mkDefault "${pkgs.grim}/bin/grim -g \"$(${pkgs.slurp}/bin/slurp)\" - | ${pkgs.wl-clipboard}/bin/wl-copy -t image/png"; + wm.menu.command = mkDefault "${pkgs.wofi}/bin/wofi --show drun,run --allow-images"; + wm.exit.command = mkDefault "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'"; - home.file = { - ".config/wofi/" = { - source = ./wofi; - recursive = true; + wayland.windowManager.sway = { + enable = true; + config = { + inherit startup; + modifier = cfg.modifier; + bars = [{ + command = "waybar"; + }]; + input = + let + inputs = config.extraInfo.inputs; + inputsCfg = [ + (if inputs.keyboard != null then { + name = inputs.keyboard; + value = + { + xkb_layout = "us"; + xkb_variant = "dvp"; + xkb_options = "compose:102"; + }; + + } else null) + (if inputs.touchpad != null then { + name = inputs.touchpad; + value = { dwt = "disable"; }; + } else null) + ]; + in + builtins.listToAttrs inputsCfg; + fonts = common.mkFont cfg.font; + window = { + titlebar = true; + }; + keybindings = common.keybindings; + workspaceOutputAssign = common.workspaceOutputAssign; + assigns = common.assigns; + }; + + }; + + home.file = { + ".config/wofi/" = { + source = ./wofi; + recursive = true; + }; }; }; }