feat: refactor Niri configuration by removing deprecated services and scripts, and updating display management to use niri-native scripts
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user