From 687bb8fd718edb0d8cbebb0bd301086055069647 Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Fri, 21 Aug 2026 08:08:09 -0500 Subject: [PATCH] feat(window-manager): add Niri window manager support and declarative config - Enable `programs.niri` on the desktop host configuration and update the server specialisation. - Add declarative Niri configuration files (`config.kdl` and `custom.kdl`) with custom keybindings, window rules, and DMS integration. - Mount Niri configuration files via Home Manager and introduce the `niri-session` systemd user target. --- hosts/desktop/configuration.nix | 4 +- modules/user/config/niri/config.kdl | 323 ++++++++++++++++++++++++++++ modules/user/config/niri/custom.kdl | 44 ++++ modules/user/graphical.nix | 16 +- 4 files changed, 385 insertions(+), 2 deletions(-) create mode 100644 modules/user/config/niri/config.kdl create mode 100644 modules/user/config/niri/custom.kdl diff --git a/hosts/desktop/configuration.nix b/hosts/desktop/configuration.nix index c16fe2e..97db31b 100644 --- a/hosts/desktop/configuration.nix +++ b/hosts/desktop/configuration.nix @@ -50,8 +50,9 @@ ]; }; - # Host-specific graphical compositor (Hyprland window manager for desktop) + # Host graphical compositors (Niri as primary, Hyprland as secondary/fallback) programs = { + niri.enable = true; hyprland.enable = true; nix-ld = { enable = true; @@ -67,6 +68,7 @@ specialisation.server.configuration = { # 1. Disable display manager and window manager services.greetd.enable = lib.mkForce false; + programs.niri.enable = lib.mkForce false; programs.hyprland.enable = lib.mkForce false; programs.dms-shell.enable = lib.mkForce false; programs.dms-greeter.enable = lib.mkForce false; diff --git a/modules/user/config/niri/config.kdl b/modules/user/config/niri/config.kdl new file mode 100644 index 0000000..e467dca --- /dev/null +++ b/modules/user/config/niri/config.kdl @@ -0,0 +1,323 @@ +// This config is in the KDL format: https://kdl.dev +// "/-" comments out the following node. +// Check the wiki for a full description of the configuration: +// https://github.com/YaLTeR/niri/wiki/Configuration:-Introduction +config-notification { + disable-failed +} +// Outputs from existing configuration +/-output "eDP-1" { + // Uncomment this line to disable this output. + // off + + // Resolution and, optionally, refresh rate of the output. + // The format is "x" or "x@". + // If the refresh rate is omitted, niri will pick the highest refresh rate + // for the resolution. + // If the mode is omitted altogether or is invalid, niri will pick one automatically. + // Run `niri msg outputs` while inside a niri instance to list all outputs and their modes. + mode "1920x1080@120.030" + + // You can use integer or fractional scale, for example use 1.5 for 150% scale. + scale 2 + + // Transform allows to rotate the output counter-clockwise, valid values are: + // normal, 90, 180, 270, flipped, flipped-90, flipped-180 and flipped-270. + transform "normal" + + // Position of the output in the global coordinate space. + // This affects directional monitor actions like "focus-monitor-left", and cursor movement. + // The cursor can only move between directly adjacent outputs. + // Output scale and rotation has to be taken into account for positioning: + // outputs are sized in logical, or scaled, pixels. + // For example, a 3840×2160 output with scale 2.0 will have a logical size of 1920×1080, + // so to put another output directly adjacent to it on the right, set its x to 1920. + // If the position is unset or results in an overlap, the output is instead placed + // automatically. + position x=1280 y=0 +} + + +gestures { + hot-corners { + off + } +} + +// Input device configuration. +// Find the full list of options on the wiki: +// https://github.com/YaLTeR/niri/wiki/Configuration:-Input +input { + keyboard { + xkb { + options "compose:ralt" + // You can set rules, model, layout, variant and options. + // For more information, see xkeyboard-config(7). + + // For example: + // layout "us,ru" + // options "grp:win_space_toggle,compose:ralt,ctrl:nocaps" + + // If this section is empty, niri will fetch xkb settings + // from org.freedesktop.locale1. You can control these using + // localectl set-x11-keymap. + } + + // Enable numlock on startup, omitting this setting disables it. + numlock + } + + // Next sections include libinput settings. + // Omitting settings disables them, or leaves them at their default values. + // All commented-out settings here are examples, not defaults. + touchpad { + // off + tap + // dwt + // dwtp + // drag false + // drag-lock + natural-scroll + // accel-speed 0.2 + // accel-profile "flat" + // scroll-method "two-finger" + // disabled-on-external-mouse + } + + mouse { + // off + // natural-scroll + // accel-speed 0.2 + // accel-profile "flat" + // scroll-method "no-scroll" + } + + trackpoint { + // off + // natural-scroll + // accel-speed 0.2 + // accel-profile "flat" + // scroll-method "on-button-down" + // scroll-button 273 + // scroll-button-lock + // middle-emulation + } + + // Uncomment this to make the mouse warp to the center of newly focused windows. + warp-mouse-to-focus + + // Focus windows and outputs automatically when moving the mouse into them. + // Setting max-scroll-amount="0%" makes it work only on windows already fully on screen. + // focus-follows-mouse max-scroll-amount="0%" + focus-follows-mouse +} +// You can configure outputs by their name, which you can find +// by running `niri msg outputs` while inside a niri instance. +// The built-in laptop monitor is usually called "eDP-1". +// Find more information on the wiki: +// https://github.com/YaLTeR/niri/wiki/Configuration:-Outputs +// Remember to uncomment the node by removing "/-"! + +// Settings that influence how windows are positioned and sized. +// Find more information on the wiki: +// https://github.com/YaLTeR/niri/wiki/Configuration:-Layout +layout { + // Set gaps around windows in logical pixels. + background-color "transparent" + // When to center a column when changing focus, options are: + // - "never", default behavior, focusing an off-screen column will keep at the left + // or right edge of the screen. + // - "always", the focused column will always be centered. + // - "on-overflow", focusing a column will center it if it doesn't fit + // together with the previously focused column. + center-focused-column "never" + // You can customize the widths that "switch-preset-column-width" (Mod+R) toggles between. + preset-column-widths { + // Proportion sets the width as a fraction of the output width, taking gaps into account. + // For example, you can perfectly fit four windows sized "proportion 0.25" on an output. + // The default preset widths are 1/3, 1/2 and 2/3 of the output. + proportion 0.33333 + proportion 0.5 + proportion 0.66667 + // Fixed sets the width in logical pixels exactly. + // fixed 1920 + } + // You can also customize the heights that "switch-preset-window-height" (Mod+Shift+R) toggles between. + // preset-window-heights { } + // You can change the default width of the new windows. + default-column-width { proportion 0.5; } + // If you leave the brackets empty, the windows themselves will decide their initial width. + // default-column-width {} + // By default focus ring and border are rendered as a solid background rectangle + // behind windows. That is, they will show up through semitransparent windows. + // This is because windows using client-side decorations can have an arbitrary shape. + // + // If you don't like that, you should uncomment `prefer-no-csd` below. + // Niri will draw focus ring and border *around* windows that agree to omit their + // client-side decorations. + // + // Alternatively, you can override it with a window rule called + // `draw-border-with-background`. + border { + off + width 4 + active-color "#707070" // Neutral gray + inactive-color "#d0d0d0" // Light gray + urgent-color "#cc4444" // Softer red + } + shadow { + softness 30 + spread 5 + offset x=0 y=5 + color "#0007" + } + struts { + } +} +layer-rule { + match namespace="^quickshell$" + place-within-backdrop true +} +overview { + workspace-shadow { + off + } +} +// Add lines like this to spawn processes at startup. +// Note that running niri as a session supports xdg-desktop-autostart, +// which may be more convenient to use. +// See the binds section below for more spawn examples. +// This line starts waybar, a commonly used bar for Wayland compositors. +environment { + XDG_CURRENT_DESKTOP "niri" +} +hotkey-overlay { + skip-at-startup +} +prefer-no-csd +screenshot-path "~/Pictures/Screenshots/Screenshot from %Y-%m-%d %H-%M-%S.png" +animations { + workspace-switch { + spring damping-ratio=0.80 stiffness=523 epsilon=0.0001 + } + window-open { + duration-ms 150 + curve "ease-out-expo" + } + window-close { + duration-ms 150 + curve "ease-out-quad" + } + horizontal-view-movement { + spring damping-ratio=0.85 stiffness=423 epsilon=0.0001 + } + window-movement { + spring damping-ratio=0.75 stiffness=323 epsilon=0.0001 + } + window-resize { + spring damping-ratio=0.85 stiffness=423 epsilon=0.0001 + } + config-notification-open-close { + spring damping-ratio=0.65 stiffness=923 epsilon=0.001 + } + screenshot-ui-open { + duration-ms 200 + curve "ease-out-quad" + } + overview-open-close { + spring damping-ratio=0.85 stiffness=800 epsilon=0.0001 + } +} +// Window rules let you adjust behavior for individual windows. +// Find more information on the wiki: +// https://github.com/YaLTeR/niri/wiki/Configuration:-Window-Rules +// Work around WezTerm's initial configure bug +// by setting an empty default-column-width. +window-rule { + // This regular expression is intentionally made as specific as possible, + // since this is the default config, and we want no false positives. + // You can get away with just app-id="wezterm" if you want. + match app-id=r#"^org\.wezfurlong\.wezterm$"# + default-column-width {} +} +window-rule { + match app-id=r#"^org\.gnome\."# + draw-border-with-background false + geometry-corner-radius 12 + clip-to-geometry true +} +window-rule { + match app-id=r#"^gnome-control-center$"# + match app-id=r#"^pavucontrol$"# + match app-id=r#"^nm-connection-editor$"# + default-column-width { proportion 0.5; } + open-floating false +} +window-rule { + match app-id=r#"^org\.gnome\.Calculator$"# + match app-id=r#"^gnome-calculator$"# + match app-id=r#"^galculator$"# + match app-id=r#"^blueman-manager$"# + match app-id=r#"^org\.gnome\.Nautilus$"# + match app-id=r#"xdg-desktop-portal"# + open-floating true +} +window-rule { + match app-id=r#"^steam$"# title=r#"^notificationtoasts_\d+_desktop$"# + default-floating-position x=10 y=10 relative-to="bottom-right" + open-focused false +} +window-rule { + match app-id=r#"^org\.wezfurlong\.wezterm$"# + match app-id="Alacritty" + match app-id="zen" + match app-id="com.mitchellh.ghostty" + match app-id="kitty" + draw-border-with-background false +} +window-rule { + match app-id=r#"firefox$"# title="^Picture-in-Picture$" + match app-id=r#"zen$"# title="^Picture-in-Picture$" + match app-id=r#"chromium|google-chrome|brave-browser"# title="^Picture in picture$" + open-floating true + default-floating-position x=20 y=20 relative-to="bottom-right" +} +window-rule { + match app-id="zoom" + open-floating true +} +// Open dms windows as floating by default +window-rule { + match app-id=r#"org.quickshell$"# + match app-id=r#"com.danklinux.dms$"# + open-floating true +} +debug { + honor-xdg-activation-with-invalid-serial +} + +// Override to disable super+tab +recent-windows { + binds { + Alt+Tab { next-window scope="output"; } + Alt+Shift+Tab { previous-window scope="output"; } + Alt+grave { next-window filter="app-id"; } + Alt+Shift+grave { previous-window filter="app-id"; } + } +} + +// --------------------------------------------------------------------- +// DankMaterialShell (DMS) Runtime Integration +// Note: Files in the 'dms/' directory are automatically generated and +// updated at runtime by DankMaterialShell (DMS). They are excluded from git. +// 'optional=true' allows Niri to boot cleanly on fresh systems before DMS creates them. +// --------------------------------------------------------------------- +include optional=true "dms/colors.kdl" +include optional=true "dms/layout.kdl" +include optional=true "dms/alttab.kdl" +include optional=true "dms/binds.kdl" +include optional=true "dms/outputs.kdl" +include optional=true "dms/cursor.kdl" + +// Custom user overrides & personal keybindings +include "custom.kdl" diff --git a/modules/user/config/niri/custom.kdl b/modules/user/config/niri/custom.kdl new file mode 100644 index 0000000..fb16b3c --- /dev/null +++ b/modules/user/config/niri/custom.kdl @@ -0,0 +1,44 @@ +// ----------------------------------------------------- +// Custom Keybindings (Niri Port) +// ----------------------------------------------------- + +binds { + // === Core Application Launchers === + Mod+Return hotkey-overlay-title="Alacritty Terminal" { spawn "alacritty"; } + Mod+B hotkey-overlay-title="Firefox Browser" { spawn "firefox"; } + Mod+O hotkey-overlay-title="Obsidian Notes" { spawn "flatpak" "run" "md.obsidian.Obsidian"; } + + // === Active Window Management === + // Force kill active window process via Niri IPC (JSON parsed) + Mod+Shift+Q hotkey-overlay-title="Force Kill Active Window" { + spawn "bash" "-c" "niri msg -j focused-window | jq -r '.pid // empty' | xargs -r kill -9"; + } + + // === Pixel-Based Window Resizing === + // Niri strictly controls width via columns and height via windows + Mod+Alt+Right hotkey-overlay-title="Width +100px" { set-column-width "+100"; } + Mod+Alt+Left hotkey-overlay-title="Width -100px" { set-column-width "-100"; } + Mod+Alt+Down hotkey-overlay-title="Height +100px" { set-window-height "+100"; } + Mod+Alt+Up hotkey-overlay-title="Height -100px" { set-window-height "-100"; } + + // === Screenshot Utility (Niri Native Actions) === + Mod+S hotkey-overlay-title="Screenshot: Area (Interactive)" { screenshot; } + Mod+Shift+S hotkey-overlay-title="Screenshot: Active Window" { screenshot-window; } + Mod+Alt+S hotkey-overlay-title="Screenshot: Full Screen" { screenshot-screen; } + Mod+Ctrl+Alt+S hotkey-overlay-title="Screenshot: Full Screen" { screenshot-screen; } + + // === Color Picker === + Mod+Shift+C hotkey-overlay-title="Color Picker (Eyedropper)" { + spawn "bash" "-c" "color=$(niri msg pick-color) && [ -n \"$color\" ] && echo -n \"$color\" | wl-copy && notify-send -a 'Niri' 'Color Picker' \"Copied $color to clipboard\""; + } + + // === Dynamic Screen Sharing / Cast Targets === + Mod+Alt+W hotkey-overlay-title="Cast: Target Focused Window" { set-dynamic-cast-window; } + Mod+Alt+M hotkey-overlay-title="Cast: Target Focused Monitor" { set-dynamic-cast-monitor; } + Mod+Alt+C hotkey-overlay-title="Cast: Clear Target" { clear-dynamic-cast-target; } + + // === Config Management === + Mod+Ctrl+Shift+R hotkey-overlay-title="Reload Niri Config" { + spawn "bash" "-c" "niri msg action load-config-file && notify-send -a 'Niri' 'Configuration' 'Niri config reloaded successfully'"; + } +} diff --git a/modules/user/graphical.nix b/modules/user/graphical.nix index 77482b6..3daf6f7 100644 --- a/modules/user/graphical.nix +++ b/modules/user/graphical.nix @@ -84,8 +84,12 @@ home.file.".config/zed/settings.json".source = ./config/zed/settings.json; home.file.".config/zed/themes".source = ./config/zed/themes; + # Declarative configuration files for Niri window manager + home.file.".config/niri/config.kdl".source = ./config/niri/config.kdl; + home.file.".config/niri/custom.kdl".source = ./config/niri/custom.kdl; + # ⚙️ Systemd user session targets for window managers - # This target allows user services (like background daemons, screenshot helpers) to bind + # These targets allow user services (like DMS daemons, screenshot helpers) to bind # to the graphical workspace startup cycle correctly. systemd.user.targets.hyprland-session = { Unit = { @@ -96,4 +100,14 @@ After = [ "graphical-session-pre.target" ]; }; }; + + systemd.user.targets.niri-session = { + Unit = { + Description = "Niri graphical session"; + Documentation = [ "man:systemd.special(7)" ]; + BindsTo = [ "graphical-session.target" ]; + Wants = [ "graphical-session-pre.target" ]; + After = [ "graphical-session-pre.target" ]; + }; + }; }