141 lines
5.4 KiB
Nix
141 lines
5.4 KiB
Nix
{pkgs, ...}: let
|
|
# Configuration variables from your script
|
|
preferred_resolution = "2880x1800";
|
|
refresh_rate = "120";
|
|
ui_scale = "1.5";
|
|
y_offset = "1200";
|
|
vrr_mode = "1"; # 0 = off, 1 = on, 2 = fullscreen only
|
|
|
|
# Inline scripts adapted from your bash script
|
|
zenbook-top = pkgs.writeShellScriptBin "zenbook-top" ''
|
|
echo "Setting to top screen only"
|
|
${pkgs.hyprland}/bin/hyprctl keyword monitor "eDP-1,${preferred_resolution}@${refresh_rate},0x0,${ui_scale},vrr,${vrr_mode}"
|
|
${pkgs.hyprland}/bin/hyprctl keyword monitor "eDP-2,disable"
|
|
'';
|
|
|
|
zenbook-bottom = pkgs.writeShellScriptBin "zenbook-bottom" ''
|
|
echo "Setting to bottom screen only"
|
|
${pkgs.hyprland}/bin/hyprctl keyword monitor "eDP-2,${preferred_resolution}@${refresh_rate},0x0,${ui_scale},vrr,${vrr_mode}"
|
|
${pkgs.hyprland}/bin/hyprctl keyword monitor "eDP-1,disable"
|
|
'';
|
|
|
|
zenbook-both = pkgs.writeShellScriptBin "zenbook-both" ''
|
|
echo "Setting to both screens"
|
|
${pkgs.hyprland}/bin/hyprctl keyword monitor "eDP-1,${preferred_resolution}@${refresh_rate},0x0,${ui_scale},vrr,${vrr_mode}"
|
|
${pkgs.hyprland}/bin/hyprctl keyword monitor "eDP-2,${preferred_resolution}@${refresh_rate},0x${y_offset},${ui_scale},vrr,${vrr_mode}"
|
|
'';
|
|
|
|
zenbook-left-up = pkgs.writeShellScriptBin "zenbook-left-up" ''
|
|
echo "Setting to left-right layout"
|
|
${pkgs.hyprland}/bin/hyprctl keyword monitor "eDP-2,${preferred_resolution}@${refresh_rate},0x0,${ui_scale},vrr,${vrr_mode}"
|
|
${pkgs.hyprland}/bin/hyprctl keyword monitor "eDP-1,${preferred_resolution}@${refresh_rate},${y_offset}x0,${ui_scale},vrr,${vrr_mode}"
|
|
'';
|
|
|
|
zenbook-right-up = pkgs.writeShellScriptBin "zenbook-right-up" ''
|
|
echo "Setting to right-left layout"
|
|
${pkgs.hyprland}/bin/hyprctl keyword monitor "eDP-1,${preferred_resolution}@${refresh_rate},0x0,${ui_scale},vrr,${vrr_mode}"
|
|
${pkgs.hyprland}/bin/hyprctl keyword monitor "eDP-2,${preferred_resolution}@${refresh_rate},${y_offset}x0,${ui_scale},vrr,${vrr_mode}"
|
|
'';
|
|
|
|
zenbook-normal = pkgs.writeShellScriptBin "zenbook-normal" ''
|
|
# Check if lid is closed
|
|
lid_closed=false
|
|
if grep -q closed /proc/acpi/button/lid/*/state 2>/dev/null; then
|
|
lid_closed=true
|
|
fi
|
|
|
|
# Check if keyboard is attached (USB dock detection)
|
|
keyboard_attached=false
|
|
if ${pkgs.usbutils}/bin/lsusb | grep 0b05:1b2c; then
|
|
keyboard_attached=true
|
|
fi
|
|
|
|
if [ "$lid_closed" = true ] && [ "$keyboard_attached" = true ]; then
|
|
echo "Lid closed and keyboard attached — disabling both screens"
|
|
${pkgs.hyprland}/bin/hyprctl keyword monitor "eDP-1,disable"
|
|
${pkgs.hyprland}/bin/hyprctl keyword monitor "eDP-2,disable"
|
|
elif [ "$lid_closed" = true ]; then
|
|
echo "Lid closed — disabling top screen"
|
|
${pkgs.hyprland}/bin/hyprctl keyword monitor "eDP-1,disable"
|
|
${pkgs.hyprland}/bin/hyprctl keyword monitor "eDP-2,${preferred_resolution}@${refresh_rate},0x0,${ui_scale},vrr,${vrr_mode}"
|
|
elif [ "$keyboard_attached" = true ]; then
|
|
echo "Keyboard attached — disabling bottom screen"
|
|
${pkgs.hyprland}/bin/hyprctl keyword monitor "eDP-1,${preferred_resolution}@${refresh_rate},0x0,${ui_scale},vrr,${vrr_mode}"
|
|
${pkgs.hyprland}/bin/hyprctl keyword monitor "eDP-2,disable"
|
|
else
|
|
echo "Normal mode — enabling both screens"
|
|
${zenbook-both}/bin/zenbook-both
|
|
fi
|
|
'';
|
|
|
|
zenbook-toggle = pkgs.writeShellScriptBin "zenbook-toggle" ''
|
|
# Check current state and toggle
|
|
enabled_count=$(${pkgs.hyprland}/bin/hyprctl monitors | grep -c "eDP.*" || echo "0")
|
|
if [ "$enabled_count" -eq 1 ]; then
|
|
${zenbook-both}/bin/zenbook-both
|
|
else
|
|
${zenbook-top}/bin/zenbook-top
|
|
fi
|
|
'';
|
|
|
|
# Event-driven display management (from your original script)
|
|
zenbook-watch-displays = pkgs.writeShellScriptBin "zenbook-watch-displays" ''
|
|
${zenbook-normal}/bin/zenbook-normal
|
|
while ${pkgs.inotify-tools}/bin/inotifywait -e attrib /dev/bus/usb/*/; do
|
|
${zenbook-normal}/bin/zenbook-normal
|
|
done
|
|
'';
|
|
|
|
zenbook-set-displays = pkgs.writeShellScriptBin "zenbook-set-displays" ''
|
|
sleep 1
|
|
${zenbook-normal}/bin/zenbook-normal
|
|
'';
|
|
|
|
# Auto-run display setup on startup
|
|
zenbook-autostart = pkgs.writeShellScriptBin "zenbook-autostart" ''
|
|
# Initial display setup
|
|
${zenbook-normal}/bin/zenbook-normal
|
|
|
|
# Start USB monitoring in background
|
|
${zenbook-watch-displays}/bin/zenbook-watch-displays &
|
|
'';
|
|
in {
|
|
# Zenbook dual-screen display configuration
|
|
wayland.windowManager.hyprland.settings = {
|
|
# Monitor configuration for Zenbook dual screens
|
|
monitor = [
|
|
# Primary display (eDP-1) - top screen
|
|
"eDP-1,${preferred_resolution}@${refresh_rate},0x0,${ui_scale},vrr,${vrr_mode}"
|
|
# Secondary display (eDP-2) - bottom screen positioned below primary
|
|
"eDP-2,${preferred_resolution}@${refresh_rate},0x${y_offset},${ui_scale},vrr,${vrr_mode}"
|
|
# Fallback for any other monitors
|
|
",preferred,auto,1"
|
|
];
|
|
|
|
# VRR and performance optimizations
|
|
misc = {
|
|
# Enable Variable Frame Rate to save power when screen is static
|
|
vfr = true;
|
|
};
|
|
|
|
# Auto-start the event-driven display management
|
|
exec-once = [
|
|
"${zenbook-autostart}/bin/zenbook-autostart"
|
|
];
|
|
};
|
|
|
|
# Add the scripts to home packages
|
|
home.packages = [
|
|
zenbook-top
|
|
zenbook-bottom
|
|
zenbook-both
|
|
zenbook-left-up
|
|
zenbook-right-up
|
|
zenbook-normal
|
|
zenbook-toggle
|
|
zenbook-watch-displays
|
|
zenbook-set-displays
|
|
zenbook-autostart
|
|
];
|
|
}
|