Skip to content

Instantly share code, notes, and snippets.

@shawnyeager
Last active November 14, 2025 12:16
Show Gist options
  • Select an option

  • Save shawnyeager/e6e45966779076368a77592a9497956f to your computer and use it in GitHub Desktop.

Select an option

Save shawnyeager/e6e45966779076368a77592a9497956f to your computer and use it in GitHub Desktop.
Omarchy Dynamic Monitor Management

Omarchy Dynamic Monitor Management

Disable laptop displays when external monitor is connected OR lid is closed. Works automatically with hotplug detection.

The Setup

Three files:

  1. monitor-manager.sh - Script with laptop display configs and logic
  2. monitors.conf - Defines all displays + runs script on reload/lid events
  3. autoexec.conf - Runs script on startup + sets up hotplug detection

Installation

Find your display descriptions

First, identify your displays:

hyprctl monitors | grep description

Example output:

description: BOE NE135A1M-NY1
description: ASUSTek COMPUTER INC PA27JCV T5LMSV003436

1. Create the script

Save to ~/.config/hypr/scripts/monitor-manager.sh:

#!/bin/bash

# ===== CONFIGURATION =====
# Asus ProArt 27" 5K
EXTERNAL_DESC="ASUSTek COMPUTER INC PA27JCV"

# Framework 13, ThinkPad X1 Carbon Gen 8
LAPTOP_DISPLAYS=(
    "BOE NE135A1M-NY1"          # Framework 13
    "AU Optronics 0x573D"       # ThinkPad X1 Carbon Gen 8
)

LAPTOP_CONFIGS=(
    "2880x1920@120, auto, 2, vrr, 1"    # Framework 13
    "1920x1080@60, auto, 1.25"          # ThinkPad X1 Carbon Gen 8
)
# =========================

# Check lid state
LID_CLOSED=false
if grep -q closed /proc/acpi/button/lid/*/state 2>/dev/null; then
    LID_CLOSED=true
fi

# Check for external
EXTERNAL_CONNECTED=false
if hyprctl monitors | grep -q "$EXTERNAL_DESC"; then
    EXTERNAL_CONNECTED=true
fi

# Disable if external connected OR lid closed
if $EXTERNAL_CONNECTED || $LID_CLOSED; then
    for display in "${LAPTOP_DISPLAYS[@]}"; do
        hyprctl keyword monitor "desc:$display, disable" 2>/dev/null
    done
else
    for i in "${!LAPTOP_DISPLAYS[@]}"; do
        hyprctl keyword monitor "desc:${LAPTOP_DISPLAYS[$i]}, ${LAPTOP_CONFIGS[$i]}" 2>/dev/null
    done
fi

Make it executable:

chmod +x ~/.config/hypr/scripts/monitor-manager.sh

2. Update monitors.conf

Define all displays and run script on every reload:

# Laptop displays - defined properly for when they should be enabled
monitor = desc:BOE NE135A1M-NY1, 2880x1920@120, auto, 2, vrr, 1
monitor = desc:AU Optronics 0x573D, 1920x1080@60, auto, 1.25

# External monitor
env = GDK_SCALE, 2
env = xx_color_management_v4, true
monitorv2 {
    output = desc:ASUSTek COMPUTER INC PA27JCV T5LMSV003436
    mode = 5120x2880@60
    position = auto
    scale = 2
}

# Run script after any reload to re-apply correct display state
exec = ~/.config/hypr/scripts/monitor-manager.sh

# Lid switches trigger script
bindl = , switch:on:Lid Switch, exec, ~/.config/hypr/scripts/monitor-manager.sh
bindl = , switch:off:Lid Switch, exec, ~/.config/hypr/scripts/monitor-manager.sh

3. Update autoexec.conf

# Run on startup
exec-once = ~/.config/hypr/scripts/monitor-manager.sh

# Hotplug detection (requires: pacman -S socat)
exec-once = socat -u UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock - | while read -r line; do [[ "$line" =~ ^monitor ]] && ~/.config/hypr/scripts/monitor-manager.sh; done

How It Works

Script runs on:

  • Startup (via autoexec.conf)
  • Any config reload (via exec in monitors.conf)
  • Lid open/close (via monitors.conf bindings)
  • Monitor plug/unplug (via socat listener)

Logic:

  • External connected OR lid closed → disable laptop displays
  • Otherwise → enable laptop displays

The exec line ensures correct display state is re-applied whenever Hyprland reloads config for any reason.

Works across both Framework and ThinkPad - only applies configs for displays that are present.

@endersonmaia
Copy link

I was using this, but it doesn't works when opening the lid after sleep/suspend. So I disabled it for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment