From 86d27b80d8d97d35392a541f09e19286d8309a98 Mon Sep 17 00:00:00 2001 From: Thomas Syms Date: Thu, 2 Oct 2025 18:36:46 -0300 Subject: [PATCH] feat: refactor Niri configuration by removing deprecated services and scripts, and updating display management to use niri-native scripts --- .../optional/desktops/niri/zenbook-screen.nix | 119 ++++++++---------- hosts/common/optional/niri.nix | 4 - hosts/common/optional/niri/fuzzel.nix | 8 -- hosts/common/optional/niri/swayidle.nix | 13 -- hosts/common/optional/niri/swaylock.nix | 9 -- hosts/common/optional/niri/waybar.nix | 23 ---- hosts/nixos/Bellerophon/duo-configuration.nix | 48 +++---- .../Bellerophon/hardware-configuration.nix | 33 +++-- 8 files changed, 100 insertions(+), 157 deletions(-) delete mode 100644 hosts/common/optional/niri/fuzzel.nix delete mode 100644 hosts/common/optional/niri/swayidle.nix delete mode 100644 hosts/common/optional/niri/swaylock.nix delete mode 100644 hosts/common/optional/niri/waybar.nix diff --git a/home/panotaka/common/optional/desktops/niri/zenbook-screen.nix b/home/panotaka/common/optional/desktops/niri/zenbook-screen.nix index de702a5..61c964b 100644 --- a/home/panotaka/common/optional/desktops/niri/zenbook-screen.nix +++ b/home/panotaka/common/optional/desktops/niri/zenbook-screen.nix @@ -1,8 +1,4 @@ -{ - pkgs, - lib, - ... -}: let +{pkgs, ...}: let # Configuration variables from your script preferred_resolution = "2880x1800"; refresh_rate = "120"; @@ -41,6 +37,7 @@ ''; # Inline scripts adapted for niri + # Stage 3: Configuration - applies the display setup zenbook-top = pkgs.writeShellScriptBin "zenbook-top" '' echo "[DEBUG] zenbook-top: Setting to top screen only" echo "[DEBUG] Configuring eDP-1..." @@ -48,8 +45,10 @@ ${pkgs.niri}/bin/niri msg output eDP-1 mode ${preferred_resolution}@${refresh_rate} || echo "[ERROR] Failed to set eDP-1 mode" ${pkgs.niri}/bin/niri msg output eDP-1 scale ${ui_scale} || echo "[ERROR] Failed to set eDP-1 scale" ${pkgs.niri}/bin/niri msg output eDP-1 position set 0 0 || echo "[ERROR] Failed to set eDP-1 position" - echo "[DEBUG] Turning off eDP-2..." + echo "[DEBUG] Disabling eDP-2..." ${pkgs.niri}/bin/niri msg output eDP-2 off || echo "[ERROR] Failed to turn off eDP-2" + # Force disable by setting power mode off (if supported) + ${pkgs.niri}/bin/niri msg output eDP-2 disable 2>/dev/null || echo "[DEBUG] disable command not available, using off" echo "[DEBUG] zenbook-top: Complete" ''; @@ -60,6 +59,8 @@ ${pkgs.niri}/bin/niri msg output eDP-2 scale ${ui_scale} ${pkgs.niri}/bin/niri msg output eDP-2 position set 0 0 ${pkgs.niri}/bin/niri msg output eDP-1 off + # Force disable by setting power mode off (if supported) + ${pkgs.niri}/bin/niri msg output eDP-1 disable 2>/dev/null || echo "[DEBUG] disable command not available, using off" ''; zenbook-both = pkgs.writeShellScriptBin "zenbook-both" '' @@ -101,9 +102,10 @@ ${pkgs.niri}/bin/niri msg output eDP-2 position set ${y_offset} 0 ''; - zenbook-normal = pkgs.writeShellScriptBin "zenbook-normal" '' + # Stage 2: Detection - determines which configuration to apply + zenbook-detect = pkgs.writeShellScriptBin "zenbook-detect" '' # Simple keyboard detection based on the original duo script - echo "[DEBUG] zenbook-normal: Starting detection" + echo "[DEBUG] zenbook-detect: Starting detection" echo "[DEBUG] Running lsusb to find keyboard..." ${pkgs.usbutils}/bin/lsusb > /tmp/zenbook-lsusb.log echo "[DEBUG] lsusb output saved to /tmp/zenbook-lsusb.log" @@ -122,6 +124,11 @@ fi ''; + # Legacy alias for compatibility + zenbook-normal = pkgs.writeShellScriptBin "zenbook-normal" '' + ${zenbook-detect}/bin/zenbook-detect + ''; + zenbook-toggle = pkgs.writeShellScriptBin "zenbook-toggle" '' # Check current state and toggle enabled_count=$(${pkgs.niri}/bin/niri msg outputs | grep -c "eDP.*" || echo "0") @@ -132,34 +139,50 @@ fi ''; - # Simple event-driven display management (based on original duo script) + # Stage 1: Watch service - monitors for changes and triggers detection zenbook-watch-displays = pkgs.writeShellScriptBin "zenbook-watch-displays" '' echo "[DEBUG] zenbook-watch-displays: Starting" - echo "[DEBUG] Running initial setup" - # Run initial setup - ${zenbook-normal}/bin/zenbook-normal + echo "[DEBUG] Running initial detection" + # Run initial detection + ${zenbook-detect}/bin/zenbook-detect echo "[DEBUG] Starting USB device monitoring on /dev/bus/usb/*/" + # Track last run time to debounce rapid-fire events + last_run=0 + debounce_seconds=3 + # Watch for USB device changes (keyboard attach/detach) while ${pkgs.inotify-tools}/bin/inotifywait -e attrib /dev/bus/usb/*/; do - echo "[DEBUG] USB device change detected at $(date)" - sleep 0.5 - ${zenbook-normal}/bin/zenbook-normal + current_time=$(date +%s) + time_diff=$((current_time - last_run)) + + if [ $time_diff -ge $debounce_seconds ]; then + echo "[DEBUG] USB device change detected at $(date) (debounced)" + sleep 0.5 + ${zenbook-detect}/bin/zenbook-detect + last_run=$current_time + else + echo "[DEBUG] USB device change ignored (debounce: $time_diff < $debounce_seconds seconds)" + fi done ''; + + # Legacy wrapper - calls detect directly zenbook-set-displays = pkgs.writeShellScriptBin "zenbook-set-displays" '' sleep 0.5 - ${zenbook-normal}/bin/zenbook-normal + ${zenbook-detect}/bin/zenbook-detect ''; # Simplified auto-run display setup on startup (based on original duo approach) zenbook-autostart = pkgs.writeShellScriptBin "zenbook-autostart" '' echo "Running initial display setup" sleep 1 - ${zenbook-set-displays}/bin/zenbook-set-displays + ${zenbook-detect}/bin/zenbook-detect ''; in { # Zenbook dual-screen display configuration for niri + # NOTE: We only configure eDP-1 statically and let scripts manage eDP-2 dynamically + # This allows the off command to actually work programs.niri.settings = { outputs = { "eDP-1" = { @@ -175,23 +198,11 @@ in { }; variable-refresh-rate = true; }; - "eDP-2" = { - mode = { - width = 2880; - height = 1800; - refresh = 120.0; - }; - scale = 1.5; - position = { - x = 0; - y = 1200; - }; - variable-refresh-rate = true; - }; + # eDP-2 is managed dynamically by zenbook-detect scripts }; - # Keybind to run zenbook-set-displays via UWSM - binds."Mod+Z".action.spawn = ["uwsm" "app" "--" "${zenbook-set-displays}/bin/zenbook-set-displays"]; + # Keybind to run zenbook-detect via UWSM + binds."Mod+Z".action.spawn = ["uwsm" "app" "--" "${zenbook-detect}/bin/zenbook-detect"]; }; # Migrate to systemd user services for UWSM integration @@ -249,40 +260,19 @@ in { }; }; - # Monitor udev events for display changes - zenbook-udev-monitor = { - Unit = { - Description = "ZenBook Duo udev Display Monitor"; - After = ["graphical-session.target"]; - PartOf = ["graphical-session.target"]; - }; - Service = { - Type = "simple"; - ExecStart = "${pkgs.writeShellScript "zenbook-udev-loop" '' - ${pkgs.udev}/bin/udevadm monitor --udev --subsystem-match=drm | while read line; do - if echo "$line" | grep -q "change"; then - sleep 2 - ${zenbook-set-displays}/bin/zenbook-set-displays - fi - done - ''}"; - Restart = "always"; - RestartSec = "5"; - }; - Install = { - WantedBy = ["graphical-session.target"]; - }; - }; + # DISABLED: udev monitor - not needed with inotify approach + # zenbook-udev-monitor service removed to prevent conflicts }; - # Hook into swayidle for unlock/resume events (if using swayidle) - services.swayidle.timeouts = lib.mkAfter [ - { - timeout = 1; - command = "${zenbook-set-displays}/bin/zenbook-set-displays"; - resumeCommand = "${zenbook-set-displays}/bin/zenbook-set-displays"; - } - ]; + # DISABLED: swayidle hook was running zenbook-detect every second, causing conflicts + # The zenbook-inotify-monitor service handles USB detection automatically + # services.swayidle.timeouts = lib.mkAfter [ + # { + # timeout = 1; + # command = "${zenbook-detect}/bin/zenbook-detect"; + # resumeCommand = "${zenbook-detect}/bin/zenbook-detect"; + # } + # ]; # Add the scripts to home packages home.packages = [ @@ -292,6 +282,7 @@ in { zenbook-both zenbook-left-up zenbook-right-up + zenbook-detect zenbook-normal zenbook-toggle zenbook-watch-displays diff --git a/hosts/common/optional/niri.nix b/hosts/common/optional/niri.nix index a51bd10..62bf5db 100644 --- a/hosts/common/optional/niri.nix +++ b/hosts/common/optional/niri.nix @@ -5,10 +5,6 @@ }: { imports = [ inputs.niri.nixosModules.niri - (import ./niri/waybar.nix) - (import ./niri/swayidle.nix) - (import ./niri/fuzzel.nix) - (import ./niri/swaylock.nix) ]; programs.niri.enable = true; diff --git a/hosts/common/optional/niri/fuzzel.nix b/hosts/common/optional/niri/fuzzel.nix deleted file mode 100644 index 5f1ad7d..0000000 --- a/hosts/common/optional/niri/fuzzel.nix +++ /dev/null @@ -1,8 +0,0 @@ -{pkgs, ...}: { - environment.systemPackages = with pkgs; [fuzzel]; - - # Provide a simple system-wide wrapper script in /etc/profile.d or /etc to make fuzzel available - environment.etc."profile.d/fuzzel.sh".text = '' - export PATH="${pkgs.fuzzel}/bin:$PATH" - ''; -} diff --git a/hosts/common/optional/niri/swayidle.nix b/hosts/common/optional/niri/swayidle.nix deleted file mode 100644 index bb4b1e3..0000000 --- a/hosts/common/optional/niri/swayidle.nix +++ /dev/null @@ -1,13 +0,0 @@ -{pkgs, ...}: { - # Install swayidle and configure a systemd user service for idle locking - environment.systemPackages = with pkgs; [swayidle swaylock inotify-tools]; - - systemd.user.services.swayidle = { - description = "swayidle for Niri sessions"; - wantedBy = ["default.target"]; - serviceConfig = { - ExecStart = "${pkgs.swayidle}/bin/swayidle -w 'timeout 300 ${pkgs.swaylock}/bin/swaylock -f' resume 'swaymsg resume'"; - Restart = "on-failure"; - }; - }; -} diff --git a/hosts/common/optional/niri/swaylock.nix b/hosts/common/optional/niri/swaylock.nix deleted file mode 100644 index 6dfd611..0000000 --- a/hosts/common/optional/niri/swaylock.nix +++ /dev/null @@ -1,9 +0,0 @@ -{pkgs, ...}: { - environment.systemPackages = with pkgs; [swaylock imagemagick]; - - # Provide a system-level helper in /etc/profile.d to point to a lock wrapper - environment.etc."profile.d/lockwrapper.sh".text = '' - #!/bin/sh - export LOCK_WRAPPER="${pkgs.swaylock}/bin/swaylock" - ''; -} diff --git a/hosts/common/optional/niri/waybar.nix b/hosts/common/optional/niri/waybar.nix deleted file mode 100644 index 47798b7..0000000 --- a/hosts/common/optional/niri/waybar.nix +++ /dev/null @@ -1,23 +0,0 @@ -{pkgs, ...}: { - # Install waybar system-wide and provide a systemd user service to start it for graphical users - environment.systemPackages = with pkgs; [waybar jq wl-clipboard]; - - systemd.user.services.waybar = { - description = "Waybar for Niri sessions"; - wantedBy = ["default.target"]; - serviceConfig = { - ExecStart = "${pkgs.waybar}/bin/waybar"; - Restart = "on-failure"; - RestartSec = 2; - }; - }; - - # Optionally provide a default system-level config in /etc/xdg/waybar/config - environment.etc."xdg/waybar/config".text = '' - { - "modules-left": ["workspace"], - "modules-center": [], - "modules-right": ["clock"] - } - ''; -} diff --git a/hosts/nixos/Bellerophon/duo-configuration.nix b/hosts/nixos/Bellerophon/duo-configuration.nix index b2f3694..b123094 100644 --- a/hosts/nixos/Bellerophon/duo-configuration.nix +++ b/hosts/nixos/Bellerophon/duo-configuration.nix @@ -33,29 +33,31 @@ in { }; }; - systemd.user.services.watchDisplays = { - description = "set screens on keyboard event"; - wantedBy = ["default.target"]; - after = ["graphical-session.target"]; + # DISABLED: Old gnome-monitor-config approach - now using niri-native zenbook-screen.nix + # systemd.user.services.watchDisplays = { + # description = "set screens on keyboard event"; + # wantedBy = ["default.target"]; + # after = ["graphical-session.target"]; - path = [pkgs.gnome-monitor-config pkgs.usbutils pkgs.inotify-tools]; - serviceConfig = { - preStart = "${patchedDuoScript} normal"; - ExecStart = "${patchedDuoScript} watch-displays"; - Restart = "always"; - RestartSec = 5; - }; - }; + # path = [pkgs.gnome-monitor-config pkgs.usbutils pkgs.inotify-tools]; + # serviceConfig = { + # preStart = "${patchedDuoScript} normal"; + # ExecStart = "${patchedDuoScript} watch-displays"; + # Restart = "always"; + # RestartSec = 5; + # }; + # }; - systemd.user.services.watchRotation = { - description = "rotate screens"; - wantedBy = ["default.target"]; - after = ["graphical-session.target"]; - path = [pkgs.gnome-monitor-config pkgs.iio-sensor-proxy]; - serviceConfig = { - ExecStart = "${patchedDuoScript} watch-rotation"; - Restart = "always"; - RestartSec = 5; - }; - }; + # DISABLED: Old rotation script - conflicts with niri + # systemd.user.services.watchRotation = { + # description = "rotate screens"; + # wantedBy = ["default.target"]; + # after = ["graphical-session.target"]; + # path = [pkgs.gnome-monitor-config pkgs.iio-sensor-proxy]; + # serviceConfig = { + # ExecStart = "${patchedDuoScript} watch-rotation"; + # Restart = "always"; + # RestartSec = 5; + # }; + # }; } diff --git a/hosts/nixos/Bellerophon/hardware-configuration.nix b/hosts/nixos/Bellerophon/hardware-configuration.nix index 1d8959c..748d973 100644 --- a/hosts/nixos/Bellerophon/hardware-configuration.nix +++ b/hosts/nixos/Bellerophon/hardware-configuration.nix @@ -14,27 +14,34 @@ boot.initrd.availableKernelModules = ["xhci_pci" "thunderbolt" "vmd" "nvme" "usbhid"]; boot.initrd.kernelModules = []; - boot.kernelPackages = pkgs.linuxPackages_zen; + boot.kernelPackages = pkgs.linuxPackages_latest; boot.kernelModules = ["kvm-intel" "evdi" "intel_vpu"]; boot.kernelParams = [ "i915.enable_guc=3" #"i915.enable_psr=0" + # Suppress rfkill/WLAN toggle events from asus-wmi + "asus_nb_wmi.wapf=4" ]; boot.kernelPatches = [ - /* - { - name = "zenbook-asus-wmi"; - patch = ./zenbook-asus-wmi.patch; - } - */ - /* - { - name = "zenbook-duo-suppress-rfkill-on-kbd-connect"; - patch = ./zenbook-duo-suppress-rfkill-on-kbd-connect.patch; - } - */ + # Both patches are malformed/outdated and don't apply to current kernel versions + # Using alternative approach with extraModprobeConfig below ]; + # Suppress rfkill events from keyboard attach/detach + services.udev.extraRules = '' + # Zenbook Duo - suppress rfkill/airplane mode key events on keyboard connect/disconnect + SUBSYSTEM=="input", ATTRS{name}=="Asus WMI hotkeys", ENV{KEY_RFKILL}="0", ENV{KEY_WLAN}="0" + ''; + + # Hardware database override to disable rfkill key on ASUS WMI hotkeys + services.udev.extraHwdb = '' + evdev:name:Asus WMI hotkeys:dmi:* + KEYBOARD_KEY_88=unknown + KEYBOARD_KEY_5d=unknown + KEYBOARD_KEY_5e=unknown + KEYBOARD_KEY_5f=unknown + ''; + # Enables DHCP on each ethernet and wireless interface. In case of scripted networking # (the default) this is the recommended approach. When using systemd-networkd it's # still possible to use this option, but it's recommended to use it in conjunction