Created
May 4, 2026 16:50
-
-
Save neogeographica/d56f408d0d712fe334215fe843e2b2bf to your computer and use it in GitHub Desktop.
workaround for idle monitors not sleeping in COSMIC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Personal workaround for https://github.com/pop-os/cosmic-greeter/issues/19 , where using an HDMI monitor as part of a dual monitor setup prevents either monitor from sleeping. | |
| When screen is locked (explicitly or from idleness), disable second (HDMI) monitor. Re-enable monitor on screen unlock. | |
| Notes: | |
| watchlock.sh runs under zsh. It could certainly be rewritten to run under bash if desired; the only tricky part to get correct is the glob expansion for the lock file. | |
| In watchlock.sh, the ID for my HDMI monitor is hardcoded (HDMI-A-3). | |
| watchlock.sh will not trigger on logout/login. See comments in the script about why. Since I almost never log out from this system, that's OK for this workaround. | |
| watchlock.service should be placed in the ~/.config/systemd/user directory. | |
| If watchlock.sh is not in a PATH directory (as seen by systemd user services), then watchlock.sh needs to use a full absolute path for the value of ExecStart. | |
| Enable and start the service with: | |
| systemctl enable watchlock --user | |
| systemctl start watchlock --user |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Unit] | |
| Description=Sleep second monitor during lock | |
| [Service] | |
| ExecStart=watchlock.sh | |
| Restart=on-failure | |
| RestartSec=3 | |
| [Install] | |
| WantedBy=graphical-session.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env zsh | |
| setopt extendedglob | |
| screenlock= | |
| while true | |
| do | |
| old_screenlock=$screenlock | |
| screenlock=false | |
| if [[ -n $XDG_RUNTIME_DIR/cosmic-greeter-*.lock(#qN) ]] | |
| then | |
| screenlock=true | |
| # This else clause (to handle logout) doesn't work because when logged out, | |
| # cosmic-randr fails with "Error: WaylandConnection(NoCompositor)". | |
| # else | |
| # if loginctl show-user cosmic-greeter &> /dev/null | |
| # then | |
| # screenlock=true | |
| # fi | |
| fi | |
| if [[ $old_screenlock != $screenlock ]] | |
| then | |
| if [[ $screenlock == true ]] | |
| then | |
| echo "watchlock: disabling second monitor" | |
| cosmic-randr disable HDMI-A-3 | |
| else | |
| echo "watchlock: enabling second monitor" | |
| cosmic-randr enable HDMI-A-3 | |
| fi | |
| fi | |
| sleep 2 | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment