feat:add_niri

This commit is contained in:
dichgrem
2025-10-13 14:22:46 +08:00
parent b9c9325ff0
commit bbe2cbfb5a
6 changed files with 408 additions and 1 deletions

View File

@@ -81,3 +81,8 @@ border=no
osd-bar=no
osd-bold=yes
osd-font-size=36
### Fix window size under Niri ###
keepaspect=no
geometry=
autofit-larger=100%

298
dotfiles/.config/niri/config.kdl vendored Normal file
View File

@@ -0,0 +1,298 @@
animations {
// Uncomment to turn off all animations.
// You can also put "off" into each individual animation to disable it.
// off
// Slow down all animations by this factor. Values below 1 speed them up instead.
// slowdown 3.0
// Individual animations.
workspace-switch {
spring damping-ratio=1.0 stiffness=1000 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=1.0 stiffness=800 epsilon=0.0001
}
window-movement {
spring damping-ratio=1.0 stiffness=800 epsilon=0.0001
}
window-resize {
spring damping-ratio=1.0 stiffness=800 epsilon=0.0001
}
config-notification-open-close {
spring damping-ratio=0.6 stiffness=1000 epsilon=0.001
}
screenshot-ui-open {
duration-ms 200
curve "ease-out-quad"
}
}
binds {
// App Launcher
Super+Space { spawn "fuzzel"; }
// Shortcuts
Super+Shift+Slash { show-hotkey-overlay; }
Super+E { spawn "nemo"; }
Super+B { spawn "floorp";}
Super+L { spawn "hyprlock";}
Super+M { spawn-sh "$HOME/.config/niri/switch_monitors.sh"; }
Ctrl+Super+Q { spawn "wlogout"; }
Super+Return { spawn "alacritty"; }
Super+S { screenshot; }
Super+Ctrl+S { screenshot-window; }
Super+Ctrl+Alt+Print { screenshot-screen; }
// Window actions
Super+F { fullscreen-window; }
Super+Q { close-window; }
// Workspace jumping
Super+1 { focus-workspace 1; }
Super+2 { focus-workspace 2; }
Super+3 { focus-workspace 3; }
Super+4 { focus-workspace 4; }
Super+5 { focus-workspace 5; }
Super+6 { focus-workspace 6; }
Super+7 { focus-workspace 7; }
Super+8 { focus-workspace 8; }
Super+9 { focus-workspace 9; }
Super+0 { focus-workspace 10; }
// Window movement between Workspace
Super+Shift+1 { move-window-to-workspace 1; }
Super+Shift+2 { move-window-to-workspace 2; }
Super+Shift+3 { move-window-to-workspace 3; }
Super+Shift+4 { move-window-to-workspace 4; }
Super+Shift+5 { move-window-to-workspace 5; }
Super+Shift+6 { move-window-to-workspace 6; }
Super+Shift+7 { move-window-to-workspace 7; }
Super+Shift+8 { move-window-to-workspace 8; }
Super+Shift+9 { move-window-to-workspace 9; }
Super+Shift+0 { move-window-to-workspace 10; }
// Window focus movement
/// Using familier keys
Alt+Tab { focus-column-right; }
Alt+Shift+Tab { focus-column-left; }
/// Using Arrow keys
Super+Left { focus-column-left; }
Super+Down { focus-window-down; }
Super+Up { focus-window-up; }
Super+Right { focus-column-right; }
/// Using Vim-like keys
Super+Shift+H { focus-column-left; }
Super+Shift+J { focus-window-down; }
Super+Shift+K { focus-window-up; }
Super+Shift+L { focus-column-right; }
// Window direction movement
/// Using Arrow keys
Super+Shift+Left { move-column-left; }
Super+Shift+Down { move-window-down; }
Super+Shift+Up { move-window-up; }
Super+Shift+Right { move-column-right; }
Super+Home { focus-column-first; }
Super+End { focus-column-last; }
Super+Ctrl+Home { move-column-to-first; }
Super+Ctrl+End { move-column-to-last; }
Super+Shift+Alt+Left { focus-monitor-left; }
Super+Shift+Alt+Down { focus-monitor-down; }
Super+Shift+Alt+Up { focus-monitor-up; }
Super+Shift+Alt+Right { focus-monitor-right; }
Super+Shift+Ctrl+Left { move-column-to-monitor-left; }
Super+Shift+Ctrl+Down { move-column-to-monitor-down; }
Super+Shift+Ctrl+Up { move-column-to-monitor-up; }
Super+Shift+Ctrl+Right { move-column-to-monitor-right; }
Super+Page_Down { focus-workspace-down; }
Super+Page_Up { focus-workspace-up; }
Super+U { focus-workspace-down; }
Super+I { focus-workspace-up; }
Super+Ctrl+Page_Down { move-column-to-workspace-down; }
Super+Ctrl+Page_Up { move-column-to-workspace-up; }
Super+Ctrl+U { move-column-to-workspace-down; }
Super+Ctrl+I { move-column-to-workspace-up; }
Super+Shift+Page_Down { move-workspace-down; }
Super+Shift+Page_Up { move-workspace-up; }
Super+Shift+U { move-workspace-down; }
Super+Shift+I { move-workspace-up; }
Super+WheelScrollDown cooldown-ms=150 { focus-workspace-down; }
Super+WheelScrollUp cooldown-ms=150 { focus-workspace-up; }
Super+Ctrl+WheelScrollDown cooldown-ms=150 { move-column-to-workspace-down; }
Super+Ctrl+WheelScrollUp cooldown-ms=150 { move-column-to-workspace-up; }
Super+WheelScrollRight { focus-column-right; }
Super+WheelScrollLeft { focus-column-left; }
Super+Ctrl+WheelScrollRight { move-column-right; }
Super+Ctrl+WheelScrollLeft { move-column-left; }
Super+Shift+WheelScrollDown { focus-column-right; }
Super+Shift+WheelScrollUp { focus-column-left; }
Super+Ctrl+Shift+WheelScrollDown { move-column-right; }
Super+Ctrl+Shift+WheelScrollUp { move-column-left; }
// Alternatively, there are commands to move just a single window:
// Super+Ctrl+1 { move-window-to-workspace 1; }
// Switches focus between the current and the previous workspace.
// Super+Tab { focus-workspace-previous; }
Super+Comma { consume-window-into-column; }
Super+Period { expel-window-from-column; }
Super+R { switch-preset-column-width; }
Super+Shift+R { reset-window-height; }
Super+Shift+F { maximize-column; }
Super+C { center-column; }
Super+Minus { set-column-width "-10%"; }
Super+Equal { set-column-width "+10%"; }
// Finer height adjustments when in column with other windows.
Super+Shift+Minus { set-window-height "-10%"; }
Super+Shift+Equal { set-window-height "+10%"; }
// Actions to switch layouts.
// Note: if you uncomment these, make sure you do NOT have
// a matching layout switch hotkey configured in xkb options above.
// Having both at once on the same hotkey will break the switching,
// since it will switch twice upon pressing the hotkey (once by xkb, once by niri).
// Super+Space { switch-layout "next"; }
// Super+Shift+Space { switch-layout "prev"; }
// The quit action will show a confirmation dialog to avoid accidental exits.
Super+Shift+E { quit; }
// Powers off the monitors. To turn them back on, do any input like
// moving the mouse or pressing any other key.
Super+Shift+P { power-off-monitors; }
// Volume control
XF86AudioLowerVolume allow-when-locked=true { spawn "swayosd-client" "--output-volume" "-2"; }
XF86AudioMute allow-when-locked=true { spawn "swayosd-client" "--output-volume" "mute-toggle"; }
XF86AudioRaiseVolume allow-when-locked=true { spawn "swayosd-client" "--output-volume" "+2"; }
XF86MonBrightnessDown allow-when-locked=true { spawn "swayosd-client" "--brightness" "-5"; }
XF86MonBrightnessUp allow-when-locked=true { spawn "swayosd-client" "--brightness" "+5"; }
// Volume control (bonus)
Ctrl+Alt+Down allow-when-locked=true { spawn "swayosd-client" "--output-volume" "-2"; }
Ctrl+Alt+Up allow-when-locked=true { spawn "swayosd-client" "--output-volume" "+2"; }
}
environment {
CURRENT_COMPOSITOR "niri"
DISPLAY ":0"
XDG_CURRENT_DESKTOP "niri"
XDG_SESSION_DESKTOP "niri"
}
hotkey-overlay {
skip-at-startup
}
input {
disable-power-key-handling
focus-follows-mouse
warp-mouse-to-focus
mouse {
accel-profile "flat"
scroll-factor 0.5
}
touchpad {
accel-profile "flat"
dwt
natural-scroll
scroll-factor 0.5
tap
}
}
prefer-no-csd
screenshot-path "~/Pictures/Screenshots/SCREENSHOT-%Y-%m-%d-%H:%M:%S.png"
spawn-at-startup "fcitx5" "-d" "-r"
spawn-at-startup "nm-applet"
spawn-at-startup "sh" "-c" "dbus-update-activation-environment --systemd --all && systemctl --user stop niri-session.target && systemctl --user start niri-session.target"
spawn-at-startup "swayosd-server"
spawn-at-startup "swww-daemon"
spawn-at-startup "sh" "-c" "sleep 1 && swww img $HOME/Git/DCGOS/dotfiles/.local/share/wallpapers/yohoho.jpg"
spawn-at-startup "swww" "restore"
spawn-at-startup "waybar"
window-rule {
block-out-from "screen-capture"
match app-id=r#"^org\.keepassxc\.KeePassXC$"#
match app-id=r#"^org\.gnome\.World\.Secrets$"#
// Use this instead if you want them visible on third-party screenshot tools.
// block-out-from "screencast"
}
window-rule {
clip-to-geometry true
geometry-corner-radius 10
}
layout {
center-focused-column "on-overflow"
border {
width 1
active-color "#313244FF"
inactive-color "#1e1e2eFF"
}
default-column-width { proportion 1.00; }
focus-ring {
off
active-color "#31324400"
inactive-color "#31324400"
width 3
}
gaps 2
preset-column-widths {
proportion 0.33333
proportion 0.5
proportion 0.66667
}
struts {
left 0.1
right 0.1
top 0
bottom 0
}
}

50
dotfiles/.config/niri/switch_monitors.sh vendored Executable file
View File

@@ -0,0 +1,50 @@
#!/usr/bin/env bash
# ~/.config/niri/switch_monitors.sh
# 切换 Niri 下显示模式:内屏 → 外屏 → 扩展
STATE_FILE="/tmp/niri_monitor_mode"
INTERNAL="eDP-1"
EXTERNAL="DP-1"
MODES=("internal_only" "external_only" "extended")
# 读取上次模式
if [[ -f "$STATE_FILE" ]]; then
LAST_MODE=$(cat "$STATE_FILE")
else
LAST_MODE="extended"
fi
# 下一个模式
NEXT_INDEX=0
for i in "${!MODES[@]}"; do
if [[ "${MODES[$i]}" == "$LAST_MODE" ]]; then
NEXT_INDEX=$(((i + 1) % ${#MODES[@]}))
break
fi
done
NEXT_MODE="${MODES[$NEXT_INDEX]}"
# 应用模式
case "$NEXT_MODE" in
internal_only)
wlr-randr --output "$EXTERNAL" --off
wlr-randr --output "$INTERNAL" --on --mode 2560x1600 --pos 0,0 --scale 1.25
notify-send "显示模式" "仅内屏"
;;
external_only)
wlr-randr --output "$EXTERNAL" --on --mode 2560x1440@144 --pos 0,0 --scale 1.25
wlr-randr --output "$INTERNAL" --off
notify-send "显示模式" "仅外屏"
;;
extended)
wlr-randr --output "$INTERNAL" --on
notify-send "显示模式" "扩展模式"
;;
esac
echo "$NEXT_MODE" > "$STATE_FILE"
# 刷新 Niri 布局(防止残影)
sleep 0.5
niri msg reload-layout >/dev/null 2>&1 || true

51
home/wayland/niri.nix Normal file
View File

@@ -0,0 +1,51 @@
{
hostname,
lib,
pkgs,
...
}: let
inherit (import ../../hosts/${hostname}/env.nix) WM;
in
with lib;
mkIf (WM == "niri") {
systemd.user.targets.niri-session = {
Unit = {
Description = "niri compositor session";
Documentation = "man:systemd.special(7)";
};
Target = {
After = "graphical-session-pre.target";
BindsTo = "graphical-session.target";
Wants = "graphical-session-pre.target";
DefaultDependencies = false;
};
};
systemd.user.services.xdg-desktop-portal-gnome = {
Unit = {
Description = "Portal service (GNOME implementation)";
};
Service = {
Type = "dbus";
BusName = "org.freedesktop.impl.portal.desktop.gnome";
ExecStart = "${pkgs.xdg-desktop-portal-gnome}/libexec/xdg-desktop-portal-gnome";
};
};
home.packages = with pkgs; [
niri
xwayland-satellite
];
xdg.portal = {
config = {
common = {
default = [
"gnome"
"gtk"
];
};
};
extraPortals = [
pkgs.xdg-desktop-portal-gtk
pkgs.xdg-desktop-portal-gnome
];
};
}

View File

@@ -54,6 +54,6 @@
### For Hyprland see https://wiki.hyprland.org/Configuring/XWayland/#hidpi-xwayland
### For sway see https://github.com/swaywm/sway/wiki#hidpi
WM = "Hyprland";
WM = "niri";
### Possible options: Hyprland ; niri ; sway
}

View File

@@ -69,6 +69,9 @@ in {
libvirt
lm_sensors
# Niri
wlr-randr
# Dev
go
gcc