Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Zerodya/08e25e1d6e9909499f3282c92b02ca23 to your computer and use it in GitHub Desktop.
Save Zerodya/08e25e1d6e9909499f3282c92b02ca23 to your computer and use it in GitHub Desktop.
without an HDMI Dummy Plug
#!/bin/bash
# Your main monitor (change this)
MONITOR="DP-3"
# Create headless virtual display
hyprctl output create headless
# Disable the monitor
hyprctl keyword monitor $MONITOR,disable
#!/bin/bash
# Your main monitor (change this)
MONITOR="DP-3"
# Turn monitor back on (you may want to change these options)
hyprctl keyword monitor $MONITOR,highrr,auto,1
# Get name of headless display
HEADLESS=$(hyprctl -j monitors | jq -r '.[] | select(.name | test("HEADLESS-"; "i")).name')
# Remove headless virtual display
hyprctl output remove "$HEADLESS"

Turn off your monitor in Hyprland when streaming with Sunshine (without an HDMI Dummy Plug)

I often use Sunshine to stream my PC games to my Android phone using Moonlight, but one thing that always bothered me is that I cannot turn my monitor off while streaming or else no video would be sent to Moonlight.

To solve this I would need to:

  1. Use an HDMI Dummy Plug to get a fake monitor
  2. Move video content from the real monitor to the fake monitor
  3. Stream the fake monitor
  4. Turn off the real monitor

(And do these steps in reverse when ending the stream)

However I don't plan on buying a Dummy Plug, so I'm going to use a virtual display which is implemented in Hyprland via hyprctl output.

My scripts:

ScreenOFF

This script is used before streaming via Sunshine

#!/bin/bash

# Your main monitor (change this)
MONITOR="DP-3"

# Create headless virtual display
hyprctl output create headless

# Disable the monitor
hyprctl keyword monitor $MONITOR,disable

ScreenON

This script is used after Sunshine stream ends

#!/bin/bash

# Your main monitor (change this)
MONITOR="DP-3"

# Turn monitor back on (you may want to change these options)
hyprctl keyword monitor $MONITOR,highrr,auto,1

# Get name of headless display 
HEADLESS=$(hyprctl -j monitors | jq -r '.[] | select(.name | test("HEADLESS-"; "i")).name')

# Remove headless virtual display
hyprctl output remove "$HEADLESS"
  • Note that getting the name of the headless display is required here since Hyprland will name it HEADLESS-2 the first time you create it, but will increment the number each time a new one is created in the current session (HEADLESS-3, HEADLESS-4, ...)

Sunshine

You should make Sunshine automatically run these scripts before and after the stream. To do so:

Edit your Sunshine application > go to Command Preparations > click on Add commands >

  • Add the full path of your screenOFF script in the Do Command field: /home/user/scripts/screenOFF
  • Add the full path of your screenON script in the Undo Command field: /home/user/scripts/screenON

Notes

  • Sunshine may crash while streaming and the screenON script will never be executed, leaving you with a blank monitor and no connection to your computer. Therefore, it is highly recommended that you bind screenON in your hyprland.conf like so:
    # Turn monitor on
    bind = $mainMod SHIFT, F1, exec, ~/scripts/screenON
    
  • Hyprland headless displays are limited to 1920x1080 resolution AFAIK

References:

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