Intelligent Linux display manager that automatically configures multiple monitors based on laptop lid status and connected displays. Supports seamless switching between various display scenarios with smart resolution detection.
Working with multiple monitors on Linux can be frustrating. Every time you dock your laptop, undock it, or close the lid, you need to manually reconfigure your displays. Common problems include:
- Displays not activating at the correct resolution
- Wrong monitor being set as primary
- Wrong monitor position.
- Laptop screen staying on when the lid is closed
- Manual xrandr commands needed for each configuration change
- Inconsistent behavior when switching between docked and undocked setups
- Time wasted configuring displays multiple times per day
This script solves these issues by automatically detecting your setup and applying the optimal configuration every time.
- Automatic configuration based on connected displays and laptop lid status
- Supports up to 3 external monitors plus laptop display
- Smart resolution selection (prefers 2560x1440, falls back to 1920x1080)
- Comprehensive logging for troubleshooting
- Desktop notifications for configuration changes
- Can run automatically at startup
The script handles seven different display configurations:
- Laptop display only
- Laptop + 1 external monitor (external as primary)
- Laptop + 2 external monitors
- Laptop + 3 external monitors
- 1 external monitor only (lid closed)
- 2 external monitors only (lid closed)
- 3 external monitors only (lid closed)
Create the directory and download the script:
cd /home/yourusername
mkdir -p .screenlayout
cd .screenlayout
wget https://raw.githubusercontent.com/danilomeireles/linux-auto-display-setup/main/display-setup.sh
Make it executable:
chmod +x display-setup.sh
Run the script:
./display-setup.sh
- The script will detect your current display configuration automatically
- Check the log file (
~/.screenlayout/display-setup.log
) for detailed execution information - If you encounter permission issues, ensure the script is executable with
chmod +x
To run the script automatically at login:
- Open "Startup Applications Preferences" (search for it in Activities)
- Click the "Add" button to create a new startup item
- Fill in the following details:
- Name: Display Setup Script
- Command:
sleep 10 && /home/yourusername/.screenlayout/display-setup.sh
- Comment: Automatic display configuration at startup
- Click "Add" to save the configuration
Replace yourusername
with your actual username. The 10-second delay ensures the display system is fully initialized before the script runs.
- The 10-second delay ensures the display system is fully initialized
- Adjust the sleep duration if you experience timing issues (try 15 seconds if needed)
- To disable: Open "Startup Applications" and uncheck or remove the entry
- Log files are created in the same directory as the script
- If the script doesn't run at startup, check the log file for error messages
You can customize the preferred resolutions by editing these variables in the script:
PREFERRED_RESOLUTION="2560x1440"
FALLBACK_RESOLUTION="1920x1080"
The script creates detailed logs at ~/.screenlayout/display-setup.log
with timestamps and execution details:
[2024-01-15 09:30:45] [INFO] Display Setup Script Started
[2024-01-15 09:30:45] [INFO] Display Detection Results:
[2024-01-15 09:30:45] [INFO] Laptop Display: eDP-1
[2024-01-15 09:30:45] [INFO] External Displays: DP-1 DP-2
[2024-01-15 09:30:45] [INFO] External Display Count: 2
[2024-01-15 09:30:45] [INFO] Selected Scenario: 6 - 2 external monitors only (lid closed)
[2024-01-15 09:30:46] [INFO] Display configuration successful: 2 external monitors (laptop OFF)
Check the logs to troubleshoot issues:
tail -f ~/.screenlayout/display-setup.log
Script doesn't run at startup: Check the startup application command path, increase the sleep delay to 15 seconds, and verify the script is executable.
Wrong display configuration: Check logs for detection issues and verify monitor connections are secure.
Lid detection not working: The script uses best-effort lid detection. Some systems may not support all detection methods, but monitor positioning should still work correctly.
Permission issues: Ensure the script is executable:
chmod +x ~/.screenlayout/display-setup.sh
For verbose debugging output:
bash -x ~/.screenlayout/display-setup.sh
- Linux system with X11
- xrandr utility (usually pre-installed)
- notify-send for desktop notifications (optional)
Contributions are welcome. Please fork the repository, create a feature branch, make your changes, and submit a pull request.
This project is licensed under the MIT License.
If this script helps improve your multi-monitor workflow, please consider giving it a star!